@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.
Files changed (55) hide show
  1. package/CHANGELOG.md +199 -0
  2. package/LANGUAGE.md +90 -42
  3. package/dist/assembly.d.cts +20 -1
  4. package/dist/assembly.d.ts +20 -1
  5. package/dist/cli.js +2236 -375
  6. package/dist/colors.d.cts +4 -0
  7. package/dist/colors.d.ts +4 -0
  8. package/dist/effects.d.cts +2 -2
  9. package/dist/effects.d.ts +2 -2
  10. package/dist/evaluator.d.cts +9 -1
  11. package/dist/evaluator.d.ts +9 -1
  12. package/dist/export/mesh.d.cts +16 -3
  13. package/dist/export/mesh.d.ts +16 -3
  14. package/dist/export/model.d.cts +4 -2
  15. package/dist/export/model.d.ts +4 -2
  16. package/dist/export/pages.d.cts +23 -0
  17. package/dist/export/pages.d.ts +23 -0
  18. package/dist/geometry.d.cts +20 -0
  19. package/dist/geometry.d.ts +20 -0
  20. package/dist/hardware.d.cts +2 -0
  21. package/dist/hardware.d.ts +2 -0
  22. package/dist/highlight.cjs +1 -1
  23. package/dist/highlight.js +1 -1
  24. package/dist/index.cjs +1308 -77
  25. package/dist/index.d.cts +4 -2
  26. package/dist/index.d.ts +4 -2
  27. package/dist/index.js +1308 -77
  28. package/dist/instructions.d.cts +27 -0
  29. package/dist/instructions.d.ts +27 -0
  30. package/dist/language.cjs +1281 -50
  31. package/dist/language.js +1281 -50
  32. package/dist/libraries.cjs +1262 -36
  33. package/dist/libraries.js +1262 -36
  34. package/dist/lights.d.cts +38 -0
  35. package/dist/lights.d.ts +38 -0
  36. package/dist/png.d.cts +14 -0
  37. package/dist/png.d.ts +14 -0
  38. package/dist/render.d.cts +5 -0
  39. package/dist/render.d.ts +5 -0
  40. package/dist/signatures.cjs +75 -4
  41. package/dist/signatures.js +75 -4
  42. package/dist/text.d.cts +23 -0
  43. package/dist/text.d.ts +23 -0
  44. package/dist/verify/types.d.cts +6 -0
  45. package/dist/verify/types.d.ts +6 -0
  46. package/docs/3d-files.md +29 -8
  47. package/docs/cli.md +12 -1
  48. package/docs/customizer.md +13 -0
  49. package/docs/javascript.md +6 -1
  50. package/docs/layers.md +24 -1
  51. package/docs/library.md +454 -16
  52. package/docs/parts-and-sheets.md +205 -28
  53. package/docs/verification.md +1 -1
  54. package/docs/versions.md +2 -2
  55. package/package.json +1 -1
package/dist/libraries.js CHANGED
@@ -1,11 +1,11 @@
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
- import{createHash as b1}from"node:crypto";import{existsSync as I,mkdirSync as w1,readdirSync as Y,readFileSync as T,rmSync as Q,statSync as v1,writeFileSync as _}from"node:fs";import{dirname as J,isAbsolute as Z,join as f,relative as L1,resolve as O,sep as y1}from"node:path";import{gunzipSync as A1,gzipSync as k1}from"node:zlib";var p1=(a,c=!0)=>`line ${a.line}${c?`, column ${a.col}`:""}${a.file?` in <${a.file}>`:""}`;var y=class extends Error{constructor(l,e){super(e?`${l} (${p1(e)})`:l);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=l,e&&(this.line=e.line,this.col=e.col,this.file=e.file)}addFrame(l,e,n){let t=this.trace.find(s=>s.name===e&&s.line===n.line&&s.col===n.col&&s.file===n.file);t?t.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:l,name:e,line:n.line,col:n.col,...n.file&&{file:n.file},count:1})}},g1=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function s1(a,c){let l=[],e=[],n=0,t=1,s=0,h=()=>({line:t,col:n-s+1,offset:n,...c&&{file:c}}),i=r=>{for(let v=0;v<r;v++)a[n]===`
3
- `&&(t++,s=n+1),n++};for(;n<a.length;){let r=a[n];if(r===" "||r===" "||r==="\r"||r===`
4
- `){i(1);continue}if(r==="/"&&a[n+1]==="/"){let o=a.indexOf(`
5
- `,n),m=o<0?a.length:o,p=/^[ \t]*$/.test(a.slice(a.lastIndexOf(`
6
- `,n-1)+1,n));e.push({text:a.slice(n+2,m).trim(),line:t,block:!1,own:p,start:n,end:m}),n=m;continue}if(r==="/"&&a[n+1]==="*"){let o=h(),m=a.indexOf("*/",n+2);if(m<0)throw new y("Unclosed block comment",o);e.push({text:a.slice(n+2,m).trim(),line:o.line,block:!0,own:!0,start:n,end:m+2}),i(m+2-n);continue}let v=h();if(/[0-9]/.test(r)||r==="."&&/[0-9]/.test(a[n+1]??"")){let o=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(a.slice(n));l.push({type:"num",value:o[0],pos:v,end:n+o[0].length}),i(o[0].length);continue}if(/[A-Za-z_$]/.test(r)){let o=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(a.slice(n));l.push({type:"id",value:o[0],pos:v,end:n+o[0].length}),i(o[0].length);continue}if(r==='"'){let o="";for(i(1);n<a.length&&a[n]!=='"';){if(a[n]==="\\"){let m=a[n+1];if(m==="n")o+=`
7
- `;else if(m==="t")o+=" ";else if(m==="u"){let p=a.slice(n+2,n+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new y("Bad \\u escape",h());o+=String.fromCharCode(parseInt(p,16)),i(4)}else o+=m;i(2);continue}if(a[n]===`
8
- `)throw new y("Unclosed string",v);o+=a[n],i(1)}if(n>=a.length)throw new y("Unclosed string",v);i(1),l.push({type:"str",value:o,pos:v,end:n});continue}if(r==="<"&&/^<[A-Za-z0-9_./\\: -]+>/.test(a.slice(n))){let o=l[l.length-1];if(o&&o.type==="id"&&(o.value==="use"||o.value==="include")){let m=/^<([A-Za-z0-9_./\\: -]+)>/.exec(a.slice(n));l.push({type:"str",value:m[1],pos:v,end:n+m[0].length}),i(m[0].length);continue}}let M=g1.find(o=>a.startsWith(o,n));if(!M)throw new y(`Unexpected character "${r}"`,v);l.push({type:"punct",value:M,pos:v,end:n+M.length}),i(M.length)}return l.push({type:"eof",value:"",pos:h(),end:n}),{tokens:l,comments:e}}var D=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function h1(a,c){let{tokens:l,comments:e}=s1(a,c),n=new N(l),t=[];for(;!n.at("eof");)t.push(...n.statement());return{program:{body:t},comments:e}}var N=class a{constructor(c){this.tokens=c;this.i=0}peek(c=0){return this.tokens[Math.min(this.i+c,this.tokens.length-1)]}at(c,l,e=0){let n=this.peek(e);return n.type===c&&(l===void 0||n.value===l)}isP(c,l=0){return this.at("punct",c,l)}isK(c,l=0){return this.at("id",c,l)}next(){return this.tokens[this.i++]}fail(c,l=this.peek()){let e=l.type==="eof"?"end of file":`"${l.value}"`;throw new y(`${c}, found ${e}`,l.pos)}expectP(c){return this.isP(c)||this.fail(`Expected "${c}"`),this.next()}separator(c){this.isP(c)||(this.isP(",")||this.fail(`Expected "," or "${c}"`),this.next())}ident(){let c=this.peek();return(c.type!=="id"||D.has(c.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let c=this.stmt();for(let l of c)l.end=this.last();return c}stmt(){let c=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:c.pos}]}if(this.isK("module")){this.next();let s=this.ident(),h=this.params();return[{kind:"module",name:s.value,params:h,body:this.body(),pos:c.pos,namePos:s.pos}]}if(this.isK("function")&&this.at("id",void 0,1)){this.next();let s=this.ident(),h=this.params();this.expectP("=");let i=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:h,body:i,pos:c.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:c.value==="include",pos:c.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:c.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:c.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let h=this.body(),i=[];return this.isK("else")&&(this.next(),i=this.body()),[{kind:"if",cond:s,then:h,else:i,pos:c.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:c.pos}];if(c.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let h=this.peek().pos.offset,i=this.expr(),r=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:i,span:[h,r],pos:c.pos}]}let l=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(l=this.next().value);let e=this.peek();(e.type!=="id"||D.has(e.value))&&this.fail("Expected a statement"),this.next();let n=this.args(),t=this.body();return[{kind:"call",name:e.value,args:n,children:t,modifier:l,pos:e.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let c=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),c.push(...this.statement());return this.next(),c}return this.statement()}params(){this.expectP("(");let c=[];for(;!this.isP(")");){let l=this.ident(),e=null;this.isP("=")&&(this.next(),e=this.expr()),c.push({name:l.value,default:e,pos:l.pos}),this.separator(")")}return this.next(),c}args(){this.expectP("(");let c=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let l=this.next();this.next(),c.push({name:l.value,value:this.expr(),pos:l.pos})}else c.push({name:null,value:this.expr()});this.separator(")")}return this.next(),c}assigns(){this.expectP("(");let c=[];for(;!this.isP(")");){let l=this.ident();this.expectP("="),c.push({name:l.value,value:this.expr(),pos:l.pos}),this.separator(")")}return this.next(),c}expr(){let c=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let e=this.params(),n=this.expr();return{kind:"lambda",params:e,body:n,pos:c.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let e=this.assigns(),n=this.expr();return{kind:"let",assigns:e,body:n,pos:c.pos,end:this.last()}}if(this.at("id")&&(c.value==="assert"||c.value==="echo")&&this.isP("(",1)){let e=this.i;this.next();let n={kind:"call",callee:{kind:"var",name:c.value,pos:c.pos},args:this.args(),pos:c.pos};if(this.startsValue())return{kind:"chain",check:n,body:this.expr(),pos:c.pos};this.i=e}let l=this.binary(0);if(this.isP("?")){this.next();let e=this.expr();this.expectP(":");let n=this.expr();return{kind:"ternary",cond:l,then:e,else:n,pos:c.pos}}return l}static{this.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]]}binary(c){if(c>=a.LEVELS.length)return this.unary();let l=this.binary(c+1);for(;this.at("punct")&&a.LEVELS[c].includes(this.peek().value);){let e=this.next(),n=this.binary(c+1);l={kind:"binary",op:e.value,left:l,right:n,pos:e.pos}}return l}startsValue(){let c=this.peek();return c.type==="num"||c.type==="str"||c.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 c=this.next();return{kind:"unary",op:c.value,arg:this.unary(),pos:c.pos}}return this.power()}power(){let c=this.postfix();if(this.isP("^")){let l=this.next();return{kind:"binary",op:"^",left:c,right:this.unary(),pos:l.pos}}return c}postfix(){let c=this.primary();for(;;){let l=this.peek();if(this.isP("("))c={kind:"call",callee:c,args:this.args(),pos:c.pos};else if(this.isP("[")){this.next();let e=this.expr();this.expectP("]"),c={kind:"index",target:c,index:e,pos:l.pos}}else if(this.isP("."))this.next(),c={kind:"member",target:c,name:this.ident().value,pos:l.pos};else return c}}primary(){let c=this.peek();if(c.type==="num"){this.next();let l=/(mm|cm|m|in|ft)$/.exec(c.value);return l?{kind:"num",value:Number(c.value.slice(0,-l[1].length)),unit:l[1],pos:c.pos}:{kind:"num",value:Number(c.value),pos:c.pos}}if(c.type==="str")return this.next(),{kind:"str",value:c.value,pos:c.pos};if(c.type==="id")return c.value==="true"||c.value==="false"?(this.next(),{kind:"bool",value:c.value==="true",pos:c.pos}):c.value==="undef"?(this.next(),{kind:"undef",pos:c.pos}):(D.has(c.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:c.value,pos:c.pos});if(this.isP("(")){this.next();let l=this.expr();return this.expectP(")"),l}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let c=this.expectP("{"),l=[];for(;!this.isP("}");){let e=this.ident();if(l.some(n=>n.name===e.value))throw new y(`Field ${e.value} is given twice`,e.pos);if(this.expectP("="),l.push({name:e.value,value:this.expr(),pos:e.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:l,pos:c.pos}}list(){let c=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:c.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 l=this.expr();if(this.isP(":")){this.next();let n=null,t=this.expr();return this.isP(":")&&(this.next(),n=t,t=this.expr()),this.expectP("]"),{kind:"range",start:l,step:n,end:t,pos:c.pos}}let e=[{kind:"item",expr:l}];return this.listRest(e,c.pos)}return this.listRest([],c.pos)}listRest(c,l){if(c.length){if(this.isP("]"))return this.next(),{kind:"list",items:c,pos:l};this.separator("]")}for(;!this.isP("]");)c.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:c,pos:l}}listItem(){let c=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let l=this.assigns(),e=this.listItem();return{kind:"for",assigns:l,body:e,pos:c.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let l=this.expr();this.expectP(")");let e=this.listItem(),n=null;return this.isK("else")&&(this.next(),n=this.listItem()),{kind:"if",cond:l,then:e,else:n}}if(this.isK("let")&&this.isP("(",1)){this.next();let l=this.assigns(),e=this.listItem();return{kind:"let",assigns:l,body:e,pos:c.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 l=this.listItem();return this.expectP(")"),l}return{kind:"item",expr:this.expr()}}};var i1={"kerf/box":`// kerf/box: finger-jointed boxes.
2
+ import{createHash as b1}from"node:crypto";import{existsSync as I,mkdirSync as w1,readdirSync as Y,readFileSync as T,rmSync as Q,statSync as d1,writeFileSync as x}from"node:fs";import{dirname as J,isAbsolute as Z,join as v,relative as y1,resolve as O,sep as k1}from"node:path";import{gunzipSync as L1,gzipSync as A1}from"node:zlib";var z1=(l,c=!0)=>`line ${l.line}${c?`, column ${l.col}`:""}${l.file?` in <${l.file}>`:""}`;var k=class extends Error{constructor(a,n){super(n?`${a} (${z1(n)})`:a);this.echoes=[];this.warnings=[];this.trace=[];this.traceMore=0;this.name="KerfError",this.reason=a,n&&(this.line=n.line,this.col=n.col,this.file=n.file)}addFrame(a,n,e){let t=this.trace.find(s=>s.name===n&&s.line===e.line&&s.col===e.col&&s.file===e.file);t?t.count++:this.trace.length>=50?this.traceMore++:this.trace.push({kind:a,name:n,line:e.line,col:e.col,...e.file&&{file:e.file},count:1})}},g1=["<=",">=","==","!=","&&","||","+","-","*","/","%","^","<",">","!","?",":","=",".",",",";","(",")","[","]","{","}","#"];function s1(l,c){let a=[],n=[],e=0,t=1,s=0,i=()=>({line:t,col:e-s+1,offset:e,...c&&{file:c}}),r=o=>{for(let d=0;d<o;d++)l[e]===`
3
+ `&&(t++,s=e+1),e++};for(;e<l.length;){let o=l[e];if(o===" "||o===" "||o==="\r"||o===`
4
+ `){r(1);continue}if(o==="/"&&l[e+1]==="/"){let h=l.indexOf(`
5
+ `,e),m=h<0?l.length:h,z=/^[ \t]*$/.test(l.slice(l.lastIndexOf(`
6
+ `,e-1)+1,e));n.push({text:l.slice(e+2,m).trim(),line:t,block:!1,own:z,start:e,end:m}),e=m;continue}if(o==="/"&&l[e+1]==="*"){let h=i(),m=l.indexOf("*/",e+2);if(m<0)throw new k("Unclosed block comment",h);n.push({text:l.slice(e+2,m).trim(),line:h.line,block:!0,own:!0,start:e,end:m+2}),r(m+2-e);continue}let d=i();if(/[0-9]/.test(o)||o==="."&&/[0-9]/.test(l[e+1]??"")){let h=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(l.slice(e));a.push({type:"num",value:h[0],pos:d,end:e+h[0].length}),r(h[0].length);continue}if(/[A-Za-z_$]/.test(o)){let h=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(l.slice(e));a.push({type:"id",value:h[0],pos:d,end:e+h[0].length}),r(h[0].length);continue}if(o==='"'){let h="";for(r(1);e<l.length&&l[e]!=='"';){if(l[e]==="\\"){let m=l[e+1];if(m==="n")h+=`
7
+ `;else if(m==="t")h+=" ";else if(m==="u"){let z=l.slice(e+2,e+6);if(!/^[0-9a-fA-F]{4}$/.test(z))throw new k("Bad \\u escape",i());h+=String.fromCharCode(parseInt(z,16)),r(4)}else h+=m;r(2);continue}if(l[e]===`
8
+ `)throw new k("Unclosed string",d);h+=l[e],r(1)}if(e>=l.length)throw new k("Unclosed string",d);r(1),a.push({type:"str",value:h,pos:d,end:e});continue}if(o==="<"){let h=a[a.length-1];if(h&&h.type==="id"&&(h.value==="use"||h.value==="include")){let m=/^<([^<>\r\n]+)>/.exec(l.slice(e,e+4097));if(m){a.push({type:"str",value:m[1],pos:d,end:e+m[0].length}),r(m[0].length);continue}}}let u=g1.find(h=>l.startsWith(h,e));if(!u)throw new k(`Unexpected character "${o}"`,d);a.push({type:"punct",value:u,pos:d,end:e+u.length}),r(u.length)}return a.push({type:"eof",value:"",pos:i(),end:e}),{tokens:a,comments:n}}var D=new Set(["module","function","if","else","for","let","each","use","include","true","false","undef"]);function i1(l,c){let{tokens:a,comments:n}=s1(l,c),e=new W(a),t=[];for(;!e.at("eof");)t.push(...e.statement());return{program:{body:t},comments:n}}var W=class l{constructor(c){this.tokens=c;this.i=0}peek(c=0){return this.tokens[Math.min(this.i+c,this.tokens.length-1)]}at(c,a,n=0){let e=this.peek(n);return e.type===c&&(a===void 0||e.value===a)}isP(c,a=0){return this.at("punct",c,a)}isK(c,a=0){return this.at("id",c,a)}next(){return this.tokens[this.i++]}fail(c,a=this.peek()){let n=a.type==="eof"?"end of file":`"${a.value}"`;throw new k(`${c}, found ${n}`,a.pos)}expectP(c){return this.isP(c)||this.fail(`Expected "${c}"`),this.next()}separator(c){this.isP(c)||(this.isP(",")||this.fail(`Expected "," or "${c}"`),this.next())}ident(){let c=this.peek();return(c.type!=="id"||D.has(c.value))&&this.fail("Expected a name"),this.next()}last(){return this.tokens[this.i-1].end}statement(){let c=this.stmt();for(let a of c)a.end=this.last();return c}stmt(){let c=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:c.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:c.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 r=this.expr();return this.expectP(";"),[{kind:"function",name:s.value,params:i,body:r,pos:c.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:c.value==="include",pos:c.pos}]}if(this.isK("for"))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:c.pos}];if(this.isK("intersection_for")&&this.isP("(",1))return this.next(),[{kind:"for",assigns:this.assigns(),body:this.body(),pos:c.pos,intersect:!0}];if(this.isK("if")){this.next(),this.expectP("(");let s=this.expr();this.expectP(")");let i=this.body(),r=[];return this.isK("else")&&(this.next(),r=this.body()),[{kind:"if",cond:s,then:i,else:r,pos:c.pos}]}if(this.isK("let")&&this.isP("(",1))return this.next(),[{kind:"let",assigns:this.assigns(),body:this.body(),pos:c.pos}];if(c.type==="id"&&this.isP("=",1)){let s=this.ident().value;this.next();let i=this.peek().pos.offset,r=this.expr(),o=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:r,span:[i,o],pos:c.pos}]}let a=null;(this.isP("*")||this.isP("!")||this.isP("#")||this.isP("%"))&&(a=this.next().value);let n=this.peek();(n.type!=="id"||D.has(n.value))&&this.fail("Expected a statement"),this.next();let e=this.args(),t=this.body();return[{kind:"call",name:n.value,args:e,children:t,modifier:a,pos:n.pos}]}body(){if(this.isP(";"))return this.next(),[];if(this.isP("{")){this.next();let c=[];for(;!this.isP("}");)this.at("eof")&&this.fail('Expected "}"'),c.push(...this.statement());return this.next(),c}return this.statement()}params(){this.expectP("(");let c=[];for(;!this.isP(")");){let a=this.ident(),n=null;this.isP("=")&&(this.next(),n=this.expr()),c.push({name:a.value,default:n,pos:a.pos}),this.separator(")")}return this.next(),c}args(){this.expectP("(");let c=[];for(;!this.isP(")");){if(this.at("id")&&this.isP("=",1)){let a=this.next();this.next(),c.push({name:a.value,value:this.expr(),pos:a.pos})}else c.push({name:null,value:this.expr()});this.separator(")")}return this.next(),c}assigns(){this.expectP("(");let c=[];for(;!this.isP(")");){let a=this.ident();this.expectP("="),c.push({name:a.value,value:this.expr(),pos:a.pos}),this.separator(")")}return this.next(),c}expr(){let c=this.peek();if(this.isK("function")&&this.isP("(",1)){this.next();let n=this.params(),e=this.expr();return{kind:"lambda",params:n,body:e,pos:c.pos,end:this.last()}}if(this.isK("let")&&this.isP("(",1)){this.next();let n=this.assigns(),e=this.expr();return{kind:"let",assigns:n,body:e,pos:c.pos,end:this.last()}}if(this.at("id")&&(c.value==="assert"||c.value==="echo")&&this.isP("(",1)){let n=this.i;this.next();let e={kind:"call",callee:{kind:"var",name:c.value,pos:c.pos},args:this.args(),pos:c.pos};if(this.startsValue())return{kind:"chain",check:e,body:this.expr(),pos:c.pos};this.i=n}let a=this.binary(0);if(this.isP("?")){this.next();let n=this.expr();this.expectP(":");let e=this.expr();return{kind:"ternary",cond:a,then:n,else:e,pos:c.pos}}return a}static{this.LEVELS=[["||"],["&&"],["==","!="],["<","<=",">",">="],["+","-"],["*","/","%"]]}binary(c){if(c>=l.LEVELS.length)return this.unary();let a=this.binary(c+1);for(;this.at("punct")&&l.LEVELS[c].includes(this.peek().value);){let n=this.next(),e=this.binary(c+1);a={kind:"binary",op:n.value,left:a,right:e,pos:n.pos}}return a}startsValue(){let c=this.peek();return c.type==="num"||c.type==="str"||c.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 c=this.next();return{kind:"unary",op:c.value,arg:this.unary(),pos:c.pos}}return this.power()}power(){let c=this.postfix();if(this.isP("^")){let a=this.next();return{kind:"binary",op:"^",left:c,right:this.unary(),pos:a.pos}}return c}postfix(){let c=this.primary();for(;;){let a=this.peek();if(this.isP("("))c={kind:"call",callee:c,args:this.args(),pos:c.pos};else if(this.isP("[")){this.next();let n=this.expr();this.expectP("]"),c={kind:"index",target:c,index:n,pos:a.pos}}else if(this.isP("."))this.next(),c={kind:"member",target:c,name:this.ident().value,pos:a.pos};else return c}}primary(){let c=this.peek();if(c.type==="num"){this.next();let a=/(mm|cm|m|in|ft)$/.exec(c.value);return a?{kind:"num",value:Number(c.value.slice(0,-a[1].length)),unit:a[1],pos:c.pos}:{kind:"num",value:Number(c.value),pos:c.pos}}if(c.type==="str")return this.next(),{kind:"str",value:c.value,pos:c.pos};if(c.type==="id")return c.value==="true"||c.value==="false"?(this.next(),{kind:"bool",value:c.value==="true",pos:c.pos}):c.value==="undef"?(this.next(),{kind:"undef",pos:c.pos}):(D.has(c.value)&&this.fail("Expected a value"),this.next(),{kind:"var",name:c.value,pos:c.pos});if(this.isP("(")){this.next();let a=this.expr();return this.expectP(")"),a}if(this.isP("["))return this.list();if(this.isP("{"))return this.record();this.fail("Expected a value")}record(){let c=this.expectP("{"),a=[];for(;!this.isP("}");){let n=this.ident();if(a.some(e=>e.name===n.value))throw new k(`Field ${n.value} is given twice`,n.pos);if(this.expectP("="),a.push({name:n.value,value:this.expr(),pos:n.pos}),!this.isP(","))break;this.next()}return this.expectP("}"),{kind:"record",fields:a,pos:c.pos}}list(){let c=this.expectP("[");if(this.isP("]"))return this.next(),{kind:"list",items:[],pos:c.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 a=this.expr();if(this.isP(":")){this.next();let e=null,t=this.expr();return this.isP(":")&&(this.next(),e=t,t=this.expr()),this.expectP("]"),{kind:"range",start:a,step:e,end:t,pos:c.pos}}let n=[{kind:"item",expr:a}];return this.listRest(n,c.pos)}return this.listRest([],c.pos)}listRest(c,a){if(c.length){if(this.isP("]"))return this.next(),{kind:"list",items:c,pos:a};this.separator("]")}for(;!this.isP("]");)c.push(this.listItem()),this.separator("]");return this.next(),{kind:"list",items:c,pos:a}}listItem(){let c=this.peek();if(this.isK("for")&&this.isP("(",1)){this.next();let a=this.assigns(),n=this.listItem();return{kind:"for",assigns:a,body:n,pos:c.pos,end:this.last()}}if(this.isK("if")&&this.isP("(",1)){this.next(),this.expectP("(");let a=this.expr();this.expectP(")");let n=this.listItem(),e=null;return this.isK("else")&&(this.next(),e=this.listItem()),{kind:"if",cond:a,then:n,else:e}}if(this.isK("let")&&this.isP("(",1)){this.next();let a=this.assigns(),n=this.listItem();return{kind:"let",assigns:a,body:n,pos:c.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 a=this.listItem();return this.expectP(")"),a}return{kind:"item",expr:this.expr()}}};var r1={"kerf/box":`// kerf/box: finger-jointed boxes.
9
9
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
10
10
 
11
11
  // Box from its outer size [width, depth, height] in the current material.
@@ -194,6 +194,112 @@ module grid_dividers(size, cols = 2, rows = 2, clearance = 0.15, gap = 0.5, scoo
194
194
  slotted_divider(d - 2 * gap, h, rows > 1 ? [for (i = [1:rows - 1]) d * i / rows - gap] : [],
195
195
  "bottom", clearance, scoops ? rows : 0);
196
196
  }
197
+ `,"kerf/drawers":`// kerf/drawers: a carcass of small numbered drawers in a grid, as for an
198
+ // advent calendar, behind a fa\xE7ade of any shape.
199
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
200
+ //
201
+ // The carcass is a finger-jointed box open at the front, shelves and
202
+ // walls halved into each other inside it, and a drawer in each cell
203
+ // with its number engraved on the front and a notch or hole to pull it by.
204
+ // Drawn in the assembly with the carcass's front left bottom corner at the
205
+ // origin, the drawers facing -y.
206
+
207
+ use <kerf/dividers>
208
+
209
+ // The outer size [width, height, depth] of a carcass of \`cols\` by \`rows\`
210
+ // cells, each cell [w, h] inside, \`depth\` deep
211
+ function drawers_size(cols, rows, cell, depth) =
212
+ [cols * cell[0] + (cols + 1) * $thickness, rows * cell[1] + (rows + 1) * $thickness, depth];
213
+
214
+ // The number on each drawer, row by row from the top left: \`numbers\` if
215
+ // given, else 1 up, in an order shuffled by \`shuffle\` (a seed) when given
216
+ function drawers_numbers(n, numbers, shuffle) =
217
+ !is_undef(numbers) ? numbers
218
+ : is_undef(shuffle) ? [for (i = [1:n]) i]
219
+ : let (keys = rands(0, 1, n, shuffle))
220
+ [for (k = sort([for (i = [0:n - 1]) [keys[i], i + 1]])) k[1]];
221
+
222
+ // A carcass of \`cols\` by \`rows\` drawers, each cell \`cell\` = [w, h] inside
223
+ // and \`depth\` deep. Drawers run on the shelves \`ease\` mm clear all round,
224
+ // and pull out \`open\` of their depth in the assembled view. \`pull\` is
225
+ // "notch" (a dip in the front's top edge), "hole" (a finger hole) or
226
+ // "none"; numbers are engraved on the fronts unless \`numbers\` is false.
227
+ // Children are a fa\xE7ade, drawn on the carcass's front from its bottom left
228
+ // corner: the drawers' openings are cut through it and it is glued on.
229
+ 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 = "") {
230
+ t = $thickness;
231
+ function n(s) = label == "" ? s : str(label, " ", s);
232
+ size = drawers_size(cols, rows, cell, depth);
233
+ W = size[0];
234
+ H = size[1];
235
+ D = depth;
236
+ assert(cell[1] > 3 * t + 6, str("drawers(): a cell must be more than ", 3 * t + 6, " mm high for this thickness"));
237
+ assert(cell[0] > 4 * t + 6, str("drawers(): a cell must be more than ", 4 * t + 6, " mm wide for this thickness"));
238
+ assert(open >= 0 && open <= 0.6, "drawers(): open must be from 0 to 0.6, so the drawers stay in");
239
+ facade = $children > 0;
240
+ labels = numbers == false ? [] : drawers_numbers(cols * rows, numbers, shuffle);
241
+ step("Glue up the carcass") {
242
+ part(n("carcass floor"), at = [0, 0, 0]) finger_rect([W, D], ["flat", "out", "out", "out"]);
243
+ part(n("carcass top"), at = [0, 0, H - t]) finger_rect([W, D], ["flat", "out", "out", "out"]);
244
+ part(n("carcass back"), at = [0, D, 0], rotate = [90, 0, 0]) finger_rect([W, H], ["in", "out", "in", "out"]);
245
+ part(n("carcass side"), qty = 2, at = [[0, 0, 0], [W - t, 0, 0]], rotate = [90, 0, 90])
246
+ finger_rect([D, H], ["in", "in", "in", "flat"]);
247
+ }
248
+ // Shelves and walls halve into each other: each shelf slotted from the
249
+ // back, each wall from the front, half the depth; they stop 0.3 mm short
250
+ // of the carcass all round
251
+ g = 0.3;
252
+ inner = D - t - g;
253
+ walls = [for (i = [1:cols - 1]) i * (cell[0] + t) + t / 2];
254
+ shelves = [for (j = [1:rows - 1]) j * (cell[1] + t) + t / 2];
255
+ step("Slot the shelves and walls together and slide them in") {
256
+ if (rows > 1)
257
+ part(n("shelf"), qty = rows - 1, at = [for (z = shelves) [t + g, 0, z - t / 2]])
258
+ slotted_divider(W - 2 * t - 2 * g, inner, cols > 1 ? [for (x = walls) x - t - g] : [], "top", clearance);
259
+ if (cols > 1)
260
+ part(n("wall"), qty = cols - 1, at = [for (x = walls) [x + t / 2, 0, t + g]], rotate = [0, -90, 0])
261
+ slotted_divider(H - 2 * t - 2 * g, inner, rows > 1 ? [for (z = shelves) z - t - g] : [], "bottom", clearance);
262
+ }
263
+ if (facade)
264
+ step("Glue on the front")
265
+ part(n("front"), at = [0, 0, 0], rotate = [90, 0, 0])
266
+ difference() {
267
+ children();
268
+ for (i = [0:cols - 1], j = [0:rows - 1])
269
+ // The drawer's front, ease / 2 clear all round
270
+ translate([t + i * (cell[0] + t) + ease / 2, t + j * (cell[1] + t) - ease / 2])
271
+ rect([cell[0] - ease, cell[1]]);
272
+ }
273
+ // Each drawer's box, its front flush with the carcass or the fa\xE7ade
274
+ dw = cell[0] - 2 * ease;
275
+ dh = cell[1] - ease;
276
+ dd = D - t - 2;
277
+ y0 = (facade ? -t : 0) - open * dd;
278
+ step("Glue up each drawer and slide it in")
279
+ for (j = [0:rows - 1], i = [0:cols - 1]) {
280
+ k = (rows - 1 - j) * cols + i;
281
+ x = t + i * (cell[0] + t) + ease;
282
+ z = t + j * (cell[1] + t);
283
+ num = len(labels) ? labels[k] : undef;
284
+ name = str(n("drawer"), " ", is_undef(num) ? k + 1 : num);
285
+ part(str(name, " floor"), at = [x, y0, z]) finger_rect([dw, dd], "out");
286
+ part(str(name, " front"), at = [x, y0 + t, z], rotate = [90, 0, 0]) {
287
+ difference() {
288
+ finger_rect([dw, dh], ["in", "out", "flat", "out"]);
289
+ if (pull == "notch") translate([dw / 2, dh]) circle(d = min(18, dw / 2, (dh - t) * 0.8));
290
+ if (pull == "hole") translate([dw / 2, dh * 0.72]) circle(d = min(12, dh * 0.3, dw / 3));
291
+ }
292
+ if (!is_undef(num))
293
+ engrave() translate([dw / 2, pull == "hole" ? dh * 0.36 : dh * 0.42])
294
+ text(str(num), size = is_undef(font_size) ? min(dh * 0.45, dw * 0.4) : font_size,
295
+ fit = [dw * 0.7, pull == "hole" ? dh * 0.4 : dh * 0.5], halign = "center", valign = "center");
296
+ }
297
+ part(str(name, " back"), at = [x, y0 + dd, z], rotate = [90, 0, 0])
298
+ finger_rect([dw, dh], ["in", "out", "flat", "out"]);
299
+ part(str(name, " side"), qty = 2, at = [[x, y0, z], [x + dw - t, y0, z]], rotate = [90, 0, 90])
300
+ finger_rect([dd, dh], ["in", "in", "flat", "in"]);
301
+ }
302
+ }
197
303
  `,"kerf/enclosure":`// kerf/enclosure: boxes with a screwed-on lid, for electronics and parts
198
304
  // you need to get back to.
199
305
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
@@ -275,6 +381,589 @@ module vents(size, slot = 3, pitch = 6) {
275
381
  translate([0, ends]) circle(d = slot, $fn = 24);
276
382
  }
277
383
  }
384
+ `,"kerf/figures":`// kerf/figures: layered characters for ornaments, standees, scenes and
385
+ // cards: Christmas, Easter, Halloween and nativity figures and animals.
386
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
387
+ // The figures are drawn for this library; none is copied from other art.
388
+ //
389
+ // A figure is built in layers, as layered wood art is. The "outline" is a
390
+ // backer of its whole silhouette, a border wider than the rest. On it lie
391
+ // the coloured pieces of its "clothes" (a coat, for an animal) and its
392
+ // "face" (skin, bellies, beaks, ears), side by side with a thin gap between
393
+ // them, so the backer shows as lines. On those lie the "details": eyes,
394
+ // noses, buttons. Each layer comes in one or more colours.
395
+ //
396
+ // Each figure is drawn 100 units tall, standing on y = 0 and centred on
397
+ // x = 0, as a list of pieces in painter's order: each piece of clothes or
398
+ // face loses what the pieces after it cover. A piece is [layer, colour,
399
+ // shapes], the shapes a list of:
400
+ // ["c", x, y, r] a circle
401
+ // ["e", x, y, rx, ry, angle] an ellipse, turned by angle
402
+ // ["k", x1, y1, x2, y2, r1, r2] a round-ended stroke from one end
403
+ // to the other, r1 wide at the first
404
+ // and r2 (r1 if left out) at the last
405
+ // ["r", x, y, w, h, r, angle] a rectangle round its centre, its
406
+ // corners rounded by r
407
+ // ["p", points] a polygon
408
+ // ["s", points] a closed smooth curve through points
409
+ // ["a", x, y, r, a0, a1, w] an arc w wide, as a smile
410
+ // ["m", shapes] the shapes and their mirror image
411
+ // ["h", shapes] the hull of the shapes
412
+ // ["-", shapes, minus] the shapes less the minus shapes
413
+
414
+ // The casts of figures
415
+ function figure_casts() = ["christmas", "easter", "halloween", "nativity", "animals"];
416
+
417
+ // The names of the figures, every one or those of one cast
418
+ function figure_names(cast) =
419
+ assert(is_undef(cast) || len([for (c = figure_casts()) if (c == cast) c]) > 0,
420
+ str("Unknown cast \\"", cast, "\\". Known: ", join(figure_casts(), ", ")))
421
+ [for (f = FIGURES) if (is_undef(cast) || f[1] == cast) f[0]];
422
+
423
+ // A figure's entry: [name, cast, outline colour, pieces]
424
+ function figure_entry(name) =
425
+ let (k = lower(name), hit = [for (f = FIGURES) if (f[0] == k) f])
426
+ len(hit) ? hit[0] : assert(false, str("Unknown figure \\"", name, "\\". Known: ", join(figure_names(), ", ")));
427
+
428
+ // The parts a figure is built of, as [layer, colour], bottom up: the
429
+ // outline, then each colour of clothes and face, then of details
430
+ function figure_layers(name) =
431
+ let (
432
+ e = figure_entry(name),
433
+ pieces = e[3],
434
+ middle = figure_unique([for (p = pieces) if (p[0] != "details") [p[0], p[1]]]),
435
+ top = figure_unique([for (p = pieces) if (p[0] == "details") [p[0], p[1]]])
436
+ )
437
+ concat([["outline", e[2]]], middle, top);
438
+
439
+ // The list without repeats, in the order first seen
440
+ function figure_unique(list) =
441
+ [for (i = [0:len(list) - 1]) if (len([for (j = [0:i - 1]) if (i > 0 && list[j] == list[i]) 1]) == 0) list[i]];
442
+
443
+ // The shapes of a figure's piece list, in its own units
444
+ module figure_shapes(shapes) {
445
+ for (q = shapes) {
446
+ if (q[0] == "c") translate([q[1], q[2]]) circle(r = q[3]);
447
+ else if (q[0] == "e") translate([q[1], q[2]]) rotate(is_undef(q[5]) ? 0 : q[5]) ellipse(r = [q[3], q[4]]);
448
+ else if (q[0] == "k")
449
+ hull() {
450
+ translate([q[1], q[2]]) circle(r = q[5]);
451
+ translate([q[3], q[4]]) circle(r = is_undef(q[6]) ? q[5] : q[6]);
452
+ }
453
+ else if (q[0] == "r")
454
+ translate([q[1], q[2]]) rotate(is_undef(q[6]) ? 0 : q[6])
455
+ 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));
456
+ else if (q[0] == "p") polygon(q[1]);
457
+ else if (q[0] == "s") polygon(spline_points(q[1], closed = true));
458
+ else if (q[0] == "a")
459
+ 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)]]);
460
+ else if (q[0] == "m") {
461
+ figure_shapes(q[1]);
462
+ mirror([1, 0]) figure_shapes(q[1]);
463
+ } else if (q[0] == "h") hull() figure_shapes(q[1]);
464
+ else if (q[0] == "-")
465
+ difference() {
466
+ figure_shapes(q[1]);
467
+ figure_shapes(q[2]);
468
+ }
469
+ }
470
+ }
471
+
472
+ // One layer of a figure: "outline", "clothes", "face" or "details", in
473
+ // every colour or only \`color\`. The outline is \`height\` mm tall, standing
474
+ // on y = 0 and centred on x = 0, \`border\` mm wider all round than the
475
+ // pieces on it; pieces of clothes and face keep \`gap\` mm apart, as do
476
+ // details, and lose any sliver narrower than \`min_width\` mm.
477
+ module figure_layer(name, layer, height = 100, color, border = 2, gap = 0.6, min_width = 1.6) {
478
+ e = figure_entry(name);
479
+ pieces = e[3];
480
+ n = len(pieces);
481
+ middle = [for (k = [0:n - 1]) if (pieces[k][0] != "details") k];
482
+ assert(len([for (l = ["outline", "clothes", "face", "details"]) if (l == layer) l]) > 0,
483
+ str("figure_layer(): layer must be \\"outline\\", \\"clothes\\", \\"face\\" or \\"details\\", got ", layer));
484
+ assert(is_num(height) && height > 2 * border + 1, "figure_layer(): height must be more than twice the border");
485
+ measure() {
486
+ for (k = [0:n - 1]) figure_shapes(pieces[k][2]);
487
+ let (b = $bounds, s = (height - 2 * border) / (b[3] - b[1]), at = [-(b[0] + b[2]) / 2, -b[1]]) {
488
+ if (layer == "outline") {
489
+ offset(r = border) translate([0, border]) scale(s) translate(at)
490
+ for (k = [0:n - 1]) figure_shapes(pieces[k][2]);
491
+ } else {
492
+ // Each piece loses what the pieces after it on its layer cover, a
493
+ // gap wider, and anything narrower than min_width; details stay on
494
+ // the clothes and face
495
+ same = [for (k = [0:n - 1]) if ((pieces[k][0] == "details") == (layer == "details")) k];
496
+ for (k = same)
497
+ if ((layer == "details" || pieces[k][0] == layer) && (is_undef(color) || pieces[k][1] == color))
498
+ offset(r = min_width / 2) offset(r = -min_width / 2)
499
+ difference() {
500
+ intersection() {
501
+ translate([0, border]) scale(s) translate(at) figure_shapes(pieces[k][2]);
502
+ if (layer == "details")
503
+ offset(delta = -gap) translate([0, border]) scale(s) translate(at)
504
+ for (j = middle) figure_shapes(pieces[j][2]);
505
+ }
506
+ offset(delta = gap) translate([0, border]) scale(s) translate(at)
507
+ for (j = same) if (j > k) figure_shapes(pieces[j][2]);
508
+ }
509
+ }
510
+ }
511
+ }
512
+ }
513
+
514
+ // A figure cut from one sheet, \`height\` mm tall: its outline cut, the
515
+ // lines between its coloured pieces scored and its details engraved
516
+ module figure(name, height = 100, border = 2, gap = 0.6) {
517
+ figure_layer(name, "outline", height, border = border, gap = gap);
518
+ score() for (l = ["clothes", "face"]) outline() figure_layer(name, l, height, border = border, gap = gap);
519
+ engrave() figure_layer(name, "details", height, border = border, gap = gap);
520
+ }
521
+
522
+ // A figure as layered parts, \`height\` mm tall: the outline at \`at\`, turned
523
+ // by \`rotate\`, its clothes and face glued on it and its details on those,
524
+ // one part for each colour of each layer, painted that colour. The parts
525
+ // are named after \`label\` (the figure's name), as "bunny face pink".
526
+ module figure_parts(name, height = 100, at = [0, 0, 0], rotate = [0, 0, 0], label, border = 2, gap = 0.6, qty = 1) {
527
+ base = is_undef(label) ? lower(name) : label;
528
+ layers = figure_layers(name);
529
+ middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
530
+ part(str(base, " outline"), qty = qty, at = at, rotate = rotate, paint = layers[0][1])
531
+ figure_layer(name, "outline", height, border = border, gap = gap);
532
+ // A part too small to cut at this height is left out
533
+ for (l = middle)
534
+ measure() {
535
+ figure_layer(name, l[0], height, l[1], border = border, gap = gap);
536
+ if (!is_undef($bounds))
537
+ part(str(base, " ", l[0], " ", l[1]), qty = qty, glue = str(base, " outline"), paint = l[1], pieces = "any")
538
+ figure_layer(name, l[0], height, l[1], border = border, gap = gap);
539
+ }
540
+ figure_details(name, height, base, qty, border, gap);
541
+ }
542
+
543
+ // A figure's details as painted parts named after \`base\`, glued on the
544
+ // first of its clothes and face parts, from the \`k\`-th, that is big enough
545
+ // to cut at this height
546
+ module figure_details(name, height, base, qty = 1, border = 2, gap = 0.6, k = 0) {
547
+ layers = figure_layers(name);
548
+ middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
549
+ if (k < len(middle))
550
+ measure() {
551
+ figure_layer(name, middle[k][0], height, middle[k][1], border = border, gap = gap);
552
+ if (is_undef($bounds)) figure_details(name, height, base, qty, border, gap, k + 1);
553
+ else
554
+ for (l = layers)
555
+ if (l[0] == "details")
556
+ measure() {
557
+ figure_layer(name, "details", height, l[1], border = border, gap = gap);
558
+ if (!is_undef($bounds))
559
+ part(str(base, " details ", l[1]), qty = qty, glue = str(base, " ", middle[k][0], " ", middle[k][1]), paint = l[1], pieces = "any")
560
+ figure_layer(name, "details", height, l[1], border = border, gap = gap);
561
+ }
562
+ }
563
+ }
564
+
565
+ // The figures: [name, cast, outline colour, pieces], each piece [layer,
566
+ // colour, shapes] in painter's order
567
+ FIGURES = [
568
+ // Christmas
569
+ ["santa", "christmas", "dark brown", [
570
+ ["clothes", "black", [["m", [["r", -8, 4, 12, 8, 3, 0]]]]],
571
+ ["clothes", "red", [
572
+ ["h", [["c", -16, 13, 4], ["c", 16, 13, 4], ["c", -12, 42, 8], ["c", 12, 42, 8]]],
573
+ ["m", [["k", -15, 44, -24, 26, 6, 5]]]
574
+ ]],
575
+ ["face", "white", [["r", 0, 12, 40, 6, 3, 0], ["r", 0, 32, 6, 30, 2, 0]]],
576
+ ["clothes", "black", [["r", 0, 31, 36, 5, 0, 0], ["m", [["c", -25, 21, 4.5]]]]],
577
+ ["face", "white", [["m", [["r", -24, 26.5, 11, 4.5, 2, -20]]]]],
578
+ ["face", "skin", [["e", 0, 63, 11, 9.5, 0]]],
579
+ ["face", "white", [["s", [[-13, 61], [-11, 52], [-6, 46], [0, 44], [6, 46], [11, 52], [13, 61], [0, 58]]]]],
580
+ ["clothes", "red", [["h", [["c", -12, 74, 2.5], ["c", 12, 74, 2.5], ["c", 16, 92, 2]]]]],
581
+ ["face", "white", [["r", 0, 72, 30, 6.5, 3.2, 0], ["c", 17, 93, 5]]],
582
+ ["details", "black", [["m", [["c", -4.5, 65.5, 1.8]]]]],
583
+ ["details", "white", [["m", [["e", -4.2, 58.5, 4.5, 2.3, 12]]]]],
584
+ ["details", "pink", [["c", 0, 61.5, 2.3]]],
585
+ ["details", "yellow", [["r", 0, 31, 7, 6, 1, 0]]]
586
+ ]],
587
+ ["elf", "christmas", "dark brown", [
588
+ ["clothes", "red", [["m", [["r", -6, 10, 6, 16, 2, 0]]]]],
589
+ ["clothes", "dark brown", [["m", [["k", -9, 3.5, -15, 6, 3.5, 2]]]]],
590
+ ["clothes", "green", [
591
+ ["h", [["c", -10, 42, 6], ["c", 10, 42, 6], ["c", -14, 22, 5], ["c", 14, 22, 5]]],
592
+ ["p", [[-19, 22], [-16, 13], [-11, 19], [-6, 13], [-1, 19], [4, 13], [9, 19], [14, 13], [19, 22]]],
593
+ ["m", [["k", -14, 44, -21, 28, 5, 4.5]]]
594
+ ]],
595
+ ["clothes", "black", [["r", 0, 29, 32, 4.5, 0, 0]]],
596
+ ["face", "skin", [["m", [["c", -22, 25, 4.2]]]]],
597
+ ["face", "skin", [["m", [["p", [[-9, 64], [-20, 70], [-9, 57]]]]], ["c", 0, 61, 11]]],
598
+ ["clothes", "green", [["h", [["c", -11, 70, 2.2], ["c", 11, 70, 2.2], ["c", 21, 89, 1.8]]]]],
599
+ ["clothes", "red", [["r", 0, 69, 27, 5, 2.5, 0], ["c", 22, 90, 3.5]]],
600
+ ["details", "black", [["m", [["c", -4.5, 62, 1.8]]]]],
601
+ ["details", "pink", [["m", [["e", -7, 57.5, 2.6, 1.8, 0]]], ["c", 0, 59, 1.8]]],
602
+ ["details", "yellow", [["r", 0, 29, 6, 5.5, 1, 0]]]
603
+ ]],
604
+ ["gnome", "christmas", "dark brown", [
605
+ ["clothes", "dark brown", [["m", [["e", -8, 4, 8, 4, 0]]]]],
606
+ ["clothes", "blue", [["h", [["c", -13, 9, 4], ["c", 13, 9, 4], ["c", -10, 32, 6], ["c", 10, 32, 6]]]]],
607
+ ["face", "white", [["s", [[-15, 48], [15, 48], [13, 32], [7, 18], [0, 12], [-7, 18], [-13, 32]]]]],
608
+ ["clothes", "red", [["p", [[-18, 46], [18, 46], [8, 82], [1, 97], [-3, 86]]]]],
609
+ ["face", "skin", [["e", 0, 45.5, 6, 5, 0]]],
610
+ ["details", "white", [["c", -6, 60, 1.8], ["c", 4, 68, 1.8], ["c", -2, 77, 1.8], ["c", 8, 55, 1.8]]]
611
+ ]],
612
+ ["angel", "christmas", "dark brown", [
613
+ ["clothes", "white", [["m", [["e", -18, 50, 12, 20, -25]]]]],
614
+ ["clothes", "light blue", [
615
+ ["h", [["c", -6, 46, 6], ["c", 6, 46, 6], ["c", -19, 4, 3], ["c", 19, 4, 3]]]
616
+ ]],
617
+ ["clothes", "light blue", [["m", [["k", -8, 47, -4, 33, 4.5, 4]]]]],
618
+ ["face", "skin", [["c", 0, 31, 4.2]]],
619
+ ["face", "yellow", [["c", 0, 64, 12.5], ["m", [["e", -9, 56, 4.5, 8, 0]]]]],
620
+ ["face", "skin", [["e", 0, 61, 8.5, 9, 0]]],
621
+ ["clothes", "gold", [["-", [["e", 0, 79, 11, 3.8, 0]], [["e", 0, 79, 7, 1.6, 0]]]]],
622
+ ["details", "black", [["m", [["c", -3.5, 62, 1.6]]]]],
623
+ ["details", "pink", [["m", [["e", -6, 58, 2.2, 1.5, 0]]]]],
624
+ ["details", "white", [["c", 0, 24, 2], ["c", -6, 14, 2], ["c", 6, 14, 2]]]
625
+ ]],
626
+ ["reindeer", "christmas", "dark brown", [
627
+ ["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]]]]],
628
+ ["clothes", "dark brown", [["m", [["r", -8, 4, 8, 8, 2.5, 0]]]]],
629
+ ["clothes", "light brown", [
630
+ ["e", 0, 24, 15, 18, 0],
631
+ ["m", [["r", -8, 9, 7, 12, 2.5, 0]]],
632
+ ["m", [["e", -16, 67, 7.5, 3.5, 25]]],
633
+ ["e", 0, 58, 13, 15, 0]
634
+ ]],
635
+ ["face", "pink", [["m", [["e", -16, 67, 4.5, 1.8, 25]]]]],
636
+ ["face", "beige", [["e", 0, 21, 9, 11, 0], ["e", 0, 49, 9, 7, 0]]],
637
+ ["clothes", "green", [["r", 0, 40, 26, 6, 3, 0], ["r", 9, 33, 6, 12, 2, -10]]],
638
+ ["details", "black", [["m", [["c", -5, 59, 2]]]]],
639
+ ["details", "red", [["c", 0, 51.5, 4]]]
640
+ ]],
641
+ ["gingerbread", "christmas", "dark brown", [
642
+ ["clothes", "light brown", [
643
+ ["c", 0, 75, 15],
644
+ ["r", 0, 39, 26, 36, 6, 0],
645
+ ["k", -24, 52, 24, 52, 7, 7],
646
+ ["m", [["k", -8, 30, -15, 7, 7, 7]]]
647
+ ]],
648
+ ["details", "white", [
649
+ ["m", [["a", -27, 52, 5, -60, 60, 2], ["a", -15, 8, 5, 25, 155, 2]]],
650
+ ["a", 0, 73, 6, 210, 330, 2]
651
+ ]],
652
+ ["details", "black", [["m", [["c", -5, 78, 2]]]]],
653
+ ["details", "red", [["c", 0, 49, 2.8], ["c", 0, 31, 2.8]]],
654
+ ["details", "green", [["c", 0, 40, 2.8]]],
655
+ ["details", "pink", [["m", [["c", -9, 72, 2]]]]]
656
+ ]],
657
+ ["snowman", "christmas", "dark brown", [
658
+ ["clothes", "dark brown", [["m", [["k", -13, 54, -29, 65, 1.9, 1.4], ["k", -24, 62, -27, 69, 1.4, 1.2]]]]],
659
+ ["clothes", "white", [["c", 0, 21, 21], ["c", 0, 51, 15], ["c", 0, 76, 11]]],
660
+ ["clothes", "red", [["r", 0, 66, 25, 6, 3, 0], ["r", 8, 57, 6, 14, 2, -10]]],
661
+ ["clothes", "black", [["r", 0, 85, 26, 3.5, 1.5, 0], ["r", 0, 93, 16, 14, 1.5, 0]]],
662
+ ["clothes", "red", [["r", 0, 88.5, 16, 3, 0, 0]]],
663
+ ["details", "black", [["m", [["c", -4, 78, 1.8]]], ["c", 0, 53, 2], ["c", 0, 45, 2], ["c", 0, 26, 2.4]]],
664
+ ["details", "orange", [["p", [[0, 76], [0, 72.5], [11, 73.5]]]]],
665
+ ["details", "pink", [["m", [["c", -7, 73.5, 1.6]]]]]
666
+ ]],
667
+
668
+ // Easter
669
+ ["bunny", "easter", "dark grey", [
670
+ ["clothes", "light grey", [
671
+ ["m", [["k", -9, 64, -15, 93, 6.5, 5.5]]],
672
+ ["m", [["e", -11, 5, 10, 5.5, 0]]],
673
+ ["e", 0, 26, 19, 21, 0],
674
+ ["e", 0, 53, 21, 17, 0]
675
+ ]],
676
+ ["face", "pink", [["m", [["k", -10, 71, -14.5, 90, 3, 2.5]]]]],
677
+ ["face", "white", [["m", [["e", -5, 46, 7, 5.5, 0]]], ["e", 0, 24, 12.5, 13, 0]]],
678
+ ["face", "light blue", [["e", 0, 21, 9, 11.5, 0]]],
679
+ ["clothes", "light grey", [["m", [["e", -10, 25, 5, 8, -40]]]]],
680
+ ["details", "black", [["m", [["c", -8, 56, 2.6]]]]],
681
+ ["details", "pink", [["e", 0, 50.5, 3, 2.2, 0]]],
682
+ ["details", "yellow", [["m", [["c", -4.5, 15, 1.5]]], ["c", 0, 12.5, 1.5]]]
683
+ ]],
684
+ ["chick", "easter", "dark brown", [
685
+ ["clothes", "yellow", [
686
+ ["e", 0, 36, 25, 24, 0],
687
+ ["c", 0, 62, 18],
688
+ ["k", 0, 78, -4, 89, 3, 1.8],
689
+ ["k", 0, 78, 4.5, 87, 3, 1.6]
690
+ ]],
691
+ ["clothes", "yellow", [["m", [["e", -22, 40, 6.5, 11, 30]]]]],
692
+ ["face", "orange", [["h", [["c", -4.5, 59.5, 1.6], ["c", 4.5, 59.5, 1.6], ["c", 0, 53, 1.6]]]]],
693
+ ["face", "white", [["p", concat(
694
+ [for (a = [180:10:360]) [27 * cos(a), 27 + 26 * sin(a)]],
695
+ [for (i = [0:8]) [27 - i * 6.75, i % 2 == 0 ? 27 : 34]]
696
+ )]]],
697
+ ["details", "black", [["m", [["c", -7, 66, 2.6]]]]],
698
+ ["details", "pink", [["m", [["e", -12.5, 58.5, 3.2, 2.2, 0]]]]]
699
+ ]],
700
+ ["lamb", "easter", "dark grey", [
701
+ ["face", "dark grey", [["m", [["r", -10, 9, 6.5, 18, 2.5, 0]]]]],
702
+ ["clothes", "cream", [
703
+ ["e", 0, 33, 23, 16, 0],
704
+ for (a = [0:30:330]) ["c", 21 * cos(a), 33 + 15 * sin(a), 6.5]
705
+ ]],
706
+ ["face", "skin", [["m", [["e", -15.5, 61, 8, 3.8, -25]]], ["e", 0, 57, 11.5, 13.5, 0]]],
707
+ ["clothes", "cream", [["c", -6.5, 70, 5.5], ["c", 0, 73, 5.5], ["c", 6.5, 70, 5.5]]],
708
+ ["details", "black", [["m", [["c", -5, 58, 2.3]]]]],
709
+ ["details", "pink", [["e", 0, 50, 3, 2, 0], ["m", [["c", -8, 52.5, 1.8]]]]]
710
+ ]],
711
+
712
+ // Halloween
713
+ ["ghost", "halloween", "dark grey", [
714
+ ["clothes", "white", [
715
+ ["h", [["c", 0, 68, 22], ["r", 0, 28, 44, 8, 0, 0]]],
716
+ for (x = [-16.5, -5.5, 5.5, 16.5]) ["c", x, 24, 5.5],
717
+ ["m", [["e", -23, 46, 8, 4, 35]]]
718
+ ]],
719
+ ["details", "black", [["m", [["e", -7.5, 64, 3, 4.5, 0]]], ["e", 0, 51, 4, 5.5, 0]]],
720
+ ["details", "pink", [["m", [["e", -13, 57, 3, 2, 0]]]]]
721
+ ]],
722
+ ["witch", "halloween", "dark brown", [
723
+ ["clothes", "black", [["m", [["e", -6, 4, 6, 3.5, 0]]]]],
724
+ ["clothes", "purple", [["h", [["c", -6, 44, 6], ["c", 6, 44, 6], ["c", -18, 8, 3], ["c", 18, 8, 3]]]]],
725
+ ["clothes", "purple", [["m", [["k", -9, 46, -21, 30, 5, 4]]]]],
726
+ ["face", "light green", [["m", [["c", -22, 27, 3.8]]]]],
727
+ ["face", "light green", [["c", 0, 62, 10]]],
728
+ ["face", "orange", [["m", [["e", -10.5, 56, 4, 10, 10]]]]],
729
+ ["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]]]]],
730
+ ["clothes", "purple", [["r", 0, 75.5, 21, 4.5, 0, 0]]],
731
+ ["details", "black", [["m", [["c", -4, 63, 1.8]]]]],
732
+ ["details", "pink", [["m", [["e", -6.5, 58.5, 2.2, 1.5, 0]]]]],
733
+ ["details", "yellow", [["r", 0, 75.5, 5, 4, 0.8, 0]]]
734
+ ]],
735
+ ["pumpkin", "halloween", "dark brown", [
736
+ ["clothes", "green", [["k", 0, 66, 4, 82, 4, 2.8]]],
737
+ ["clothes", "orange", [["m", [["e", -15, 34, 17, 32, 0]]]]],
738
+ ["clothes", "orange", [["e", 0, 34, 15, 34, 0]]],
739
+ ["details", "black", [
740
+ ["m", [["p", [[-14, 40], [-4, 40], [-9, 49]]]]],
741
+ ["p", [[-3, 33], [3, 33], [0, 37]]],
742
+ ["p", [[-17, 25], [-12, 22], [-8, 25], [-4, 20], [0, 24], [4, 20], [8, 25], [12, 22], [17, 25], [12, 15], [-12, 15]]]
743
+ ]]
744
+ ]],
745
+ ["bat", "halloween", "dark grey", [
746
+ ["clothes", "black", [
747
+ ["m", [["p", [[-4, 52], [-15, 64], [-26, 64], [-36, 56], [-31, 52], [-28, 45], [-22, 48], [-18, 41], [-12, 46], [-6, 41]]]]],
748
+ ["e", 0, 48, 9.5, 14, 0],
749
+ ["c", 0, 63, 9.5],
750
+ ["m", [["p", [[-8.5, 66], [-8, 77], [-2, 70]]]]]
751
+ ]],
752
+ ["face", "purple", [["e", 0, 45, 5.5, 8.5, 0]]],
753
+ ["details", "yellow", [["m", [["c", -3.8, 64, 2.2]]]]],
754
+ ["details", "pink", [["m", [["c", -6.5, 59.5, 1.4]]]]]
755
+ ]],
756
+ ["skeleton", "halloween", "dark grey", [
757
+ ["clothes", "black", [
758
+ ["m", [["r", -6, 10, 8, 20, 3, 0]]],
759
+ ["h", [["c", -9, 45, 5], ["c", 9, 45, 5], ["c", -10, 21, 5], ["c", 10, 21, 5]]],
760
+ ["m", [["k", -13, 47, -19, 28, 4.5, 4]]]
761
+ ]],
762
+ ["face", "white", [
763
+ ["r", 0, 32, 3, 24, 1.5, 0],
764
+ ["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]]],
765
+ ["e", 0, 20, 7, 3.2, 0],
766
+ ["m", [["r", -6, 10, 2.8, 15, 1.4, 0], ["k", -14, 45, -18.5, 30, 1.4]]]
767
+ ]],
768
+ ["face", "white", [["c", 0, 66, 13], ["r", 0, 54, 14, 8, 3, 0]]],
769
+ ["details", "black", [["m", [["c", -5, 66, 3.6]]], ["p", [[-1.6, 59.5], [1.6, 59.5], [0, 62.5]]]]]
770
+ ]],
771
+
772
+ // Nativity
773
+ ["mary", "nativity", "dark brown", [
774
+ ["clothes", "blue", [["h", [["c", 0, 64, 13.5], ["c", -18, 4, 3], ["c", 18, 4, 3]]]]],
775
+ ["clothes", "white", [["h", [["c", 0, 46, 6], ["c", -9, 4, 3], ["c", 9, 4, 3]]]]],
776
+ ["face", "dark brown", [["e", 0, 63, 10, 11.5, 0]]],
777
+ ["face", "skin", [["e", 0, 61, 7.5, 8.5, 0], ["e", 0, 36, 5, 4, 0]]],
778
+ ["details", "black", [["m", [["c", -3, 62, 1.4]]]]],
779
+ ["details", "pink", [["m", [["e", -5, 58, 1.8, 1.2, 0]]]]]
780
+ ]],
781
+ ["joseph", "nativity", "dark brown", [
782
+ ["clothes", "light brown", [["r", 22, 42, 3.2, 84, 1.6, 0]]],
783
+ ["clothes", "brown", [["h", [["c", -9, 46, 6], ["c", 9, 46, 6], ["c", -17, 4, 3], ["c", 17, 4, 3]]]]],
784
+ ["clothes", "green", [["p", [[-15, 50], [-6, 52], [12, 6], [3, 4]]]]],
785
+ ["clothes", "brown", [["k", 7, 49, 18, 45, 4.5, 4]]],
786
+ ["face", "skin", [["c", 20, 45, 4]]],
787
+ ["face", "beige", [["e", 0, 65, 11, 12.5, 0], ["m", [["r", -9, 54, 5, 14, 2, 0]]]]],
788
+ ["face", "skin", [["e", 0, 62, 7.5, 8, 0]]],
789
+ ["face", "dark brown", [["-", [["e", 0, 58, 8, 9, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
790
+ ["clothes", "red", [["r", 0, 71, 21, 3.5, 1.5, 0]]],
791
+ ["details", "black", [["m", [["c", -3.2, 63.5, 1.4]]]]]
792
+ ]],
793
+ ["baby", "nativity", "dark brown", [
794
+ ["clothes", "light brown", [["m", [["r", -17, 5, 4, 10, 1, 0]]], ["p", [[-26, 22], [26, 22], [19, 7], [-19, 7]]]]],
795
+ ["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]]]]],
796
+ ["clothes", "white", [["e", -4, 27, 15, 6, 0]]],
797
+ ["clothes", "cream", [["r", -9, 27, 2.5, 11, 1, 0], ["r", -1, 27, 2.5, 12, 1, 0]]],
798
+ ["face", "skin", [["c", 15, 29, 6]]],
799
+ ["details", "black", [["c", 13, 30, 1.1], ["c", 17.5, 30, 1.1]]],
800
+ ["details", "pink", [["c", 12, 27.5, 1.3], ["c", 19, 27.5, 1.3]]]
801
+ ]],
802
+ ["shepherd", "nativity", "dark brown", [
803
+ ["clothes", "light brown", [["r", 24, 41, 3, 80, 1.5, 0], ["a", 20, 81, 4, 0, 180, 3]]],
804
+ ["clothes", "brown", [["h", [["c", -8, 46, 6], ["c", 8, 46, 6], ["c", -16, 4, 3], ["c", 16, 4, 3]]]]],
805
+ ["clothes", "cream", [["p", [[-14, 50], [14, 50], [11, 36], [-11, 36]]]]],
806
+ ["clothes", "brown", [["k", 6, 48, 20, 44, 4.5, 4]]],
807
+ ["face", "skin", [["c", 22, 44, 4]]],
808
+ ["face", "beige", [["e", 0, 65, 11, 12.5, 0], ["m", [["r", -9, 54, 5, 14, 2, 0]]]]],
809
+ ["face", "skin", [["e", 0, 62, 7.5, 8, 0]]],
810
+ ["clothes", "blue", [["r", 0, 71, 21, 3.5, 1.5, 0]]],
811
+ ["details", "black", [["m", [["c", -3.2, 63, 1.4]]]]],
812
+ ["details", "pink", [["m", [["e", -5, 59, 1.8, 1.2, 0]]]]]
813
+ ]],
814
+ ["caspar", "nativity", "dark brown", [
815
+ ["clothes", "purple", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
816
+ ["clothes", "gold", [["r", 0, 25, 6, 44, 2, 0]]],
817
+ ["clothes", "purple", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
818
+ ["face", "skin", [["m", [["c", -6, 33, 3.5]]]]],
819
+ ["clothes", "gold", [["r", 0, 33, 11, 9, 1.5, 0]]],
820
+ ["face", "skin", [["e", 0, 62, 8.5, 9.5, 0]]],
821
+ ["face", "white", [["-", [["e", 0, 57, 9, 9.5, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
822
+ ["clothes", "gold", [["p", [[-9, 69], [9, 69], [10, 80], [5, 75], [0, 82], [-5, 75], [-10, 80]]]]],
823
+ ["details", "red", [["c", 0, 33, 2]]],
824
+ ["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]]
825
+ ]],
826
+ ["melchior", "nativity", "dark brown", [
827
+ ["clothes", "red", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
828
+ ["clothes", "gold", [["r", 0, 6, 34, 5, 2, 0]]],
829
+ ["clothes", "red", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
830
+ ["face", "peach", [["m", [["c", -6, 33, 3.5]]]]],
831
+ ["clothes", "gold", [["h", [["c", -4, 30, 2], ["c", 4, 30, 2], ["c", 0, 39, 3.5]]]]],
832
+ ["face", "peach", [["e", 0, 62, 8.5, 9.5, 0]]],
833
+ ["face", "dark brown", [["-", [["e", 0, 57, 9, 9.5, 0]], [["r", 0, 66, 20, 12, 0, 0]]]]],
834
+ ["clothes", "gold", [["p", [[-9, 69], [9, 69], [11, 82], [4.5, 76], [0, 84], [-4.5, 76], [-11, 82]]]]],
835
+ ["details", "green", [["c", 0, 72.5, 1.8]]],
836
+ ["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]]
837
+ ]],
838
+ ["balthasar", "nativity", "dark brown", [
839
+ ["clothes", "green", [["h", [["c", -9, 46, 7], ["c", 9, 46, 7], ["c", -19, 4, 3], ["c", 19, 4, 3]]]]],
840
+ ["clothes", "gold", [["m", [["r", -12, 25, 3.5, 42, 1.5, 6]]]]],
841
+ ["clothes", "green", [["m", [["k", -12, 47, -5, 34, 5, 4.5]]]]],
842
+ ["face", "brown", [["m", [["c", -6, 33, 3.5]]]]],
843
+ ["clothes", "gold", [["e", 0, 34, 6, 7, 0]]],
844
+ ["face", "brown", [["e", 0, 62, 8.5, 9.5, 0]]],
845
+ ["clothes", "white", [["h", [["c", -9, 70, 3.5], ["c", 9, 70, 3.5], ["c", 0, 80, 7]]]]],
846
+ ["details", "red", [["c", 0, 72, 2]]],
847
+ ["details", "black", [["m", [["c", -3.5, 63.5, 1.5]]]]],
848
+ ["details", "pink", [["e", 0, 57, 2.6, 1.3, 0]]]
849
+ ]],
850
+ ["ox", "nativity", "dark brown", [
851
+ ["clothes", "cream", [["m", [["k", -14, 70, -26, 74, 3, 2], ["k", -26, 74, -27, 82, 2, 1.4]]]]],
852
+ ["clothes", "brown", [
853
+ ["m", [["r", -12, 7, 8, 14, 2.5, 0]]],
854
+ ["e", 0, 28, 22, 18, 0],
855
+ ["m", [["e", -19, 62, 8, 4, 15]]],
856
+ ["e", 0, 58, 15, 16, 0]
857
+ ]],
858
+ ["face", "pink", [["m", [["e", -19, 62, 4.5, 2, 15]]]]],
859
+ ["face", "beige", [["e", 0, 47, 12, 8, 0], ["c", 0, 69, 4]]],
860
+ ["clothes", "dark brown", [["m", [["r", -12, 3, 8, 6, 2, 0]]]]],
861
+ ["details", "black", [["m", [["c", -6.5, 60, 2.2]]]]],
862
+ ["details", "dark brown", [["m", [["e", -4, 46.5, 1.8, 2.4, 0]]]]]
863
+ ]],
864
+ ["donkey", "nativity", "dark brown", [
865
+ ["clothes", "grey", [
866
+ ["m", [["r", -11, 8, 7, 16, 2.5, 0]]],
867
+ ["e", 0, 28, 19, 17, 0],
868
+ ["m", [["k", -7, 66, -12, 92, 5, 3.5]]],
869
+ ["e", 0, 56, 12, 16, 0]
870
+ ]],
871
+ ["face", "light grey", [["m", [["k", -7.5, 70, -11.5, 88, 2.4, 1.6]]]]],
872
+ ["face", "white", [["e", 0, 45, 10, 8, 0], ["e", 0, 24, 10, 10, 0]]],
873
+ ["clothes", "dark grey", [["m", [["r", -11, 3, 7, 6, 2, 0]]], ["k", 0, 64, 0, 74, 3, 2.5]]],
874
+ ["details", "black", [["m", [["c", -6, 58, 2.2]]]]],
875
+ ["details", "dark grey", [["m", [["e", -3.5, 44, 1.6, 2.2, 0]]]]]
876
+ ]],
877
+ ["sheep", "nativity", "dark grey", [
878
+ ["face", "black", [["m", [["r", -11, 9, 6, 18, 2.5, 0]]]]],
879
+ ["clothes", "white", [
880
+ ["e", 0, 35, 26, 18, 0],
881
+ for (a = [0:30:330]) ["c", 24 * cos(a), 35 + 17 * sin(a), 7]
882
+ ]],
883
+ ["face", "black", [["m", [["e", -16, 64, 8, 3.6, -25]]], ["e", 0, 59, 11, 14, 0]]],
884
+ ["clothes", "white", [["c", -6.5, 72, 5.5], ["c", 0, 75, 5.5], ["c", 6.5, 72, 5.5]]],
885
+ ["details", "white", [["m", [["c", -5, 60, 2.2]]]]],
886
+ ["details", "pink", [["e", 0, 51.5, 3, 2, 0]]]
887
+ ]],
888
+
889
+ // Animals
890
+ ["bear", "animals", "dark brown", [
891
+ ["clothes", "brown", [
892
+ ["m", [["e", -13, 8, 9, 7.5, 0]]],
893
+ ["e", 0, 28, 20, 20, 0],
894
+ ["m", [["e", -18, 34, 6, 10, -30]]],
895
+ ["m", [["c", -14, 75, 6.5]]],
896
+ ["c", 0, 62, 17]
897
+ ]],
898
+ ["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]]],
899
+ ["details", "black", [["m", [["c", -6, 65, 2.4]]], ["e", 0, 58.5, 3.2, 2.4, 0]]],
900
+ ["details", "pink", [["m", [["e", -11, 57, 2.4, 1.6, 0]]]]]
901
+ ]],
902
+ ["fox", "animals", "dark brown", [
903
+ ["clothes", "orange", [["e", 20, 18, 9, 18, 35]]],
904
+ ["face", "white", [["e", 27, 30, 5, 6, 35]]],
905
+ ["clothes", "orange", [
906
+ ["h", [["c", -10, 12, 7], ["c", 10, 12, 7], ["c", 0, 40, 10]]],
907
+ ["m", [["p", [[-16, 66], [-18, 86], [-5, 72]]]]],
908
+ ["p", [[-19, 66], [19, 66], [16, 56], [0, 44], [-16, 56]]]
909
+ ]],
910
+ ["face", "dark brown", [["m", [["p", [[-13.5, 70.5], [-15, 79], [-9.5, 73]]]]]]],
911
+ ["face", "white", [["p", [[-12, 58], [0, 46], [12, 58], [0, 55]]], ["e", 0, 28, 7, 12, 0]]],
912
+ ["clothes", "dark brown", [["m", [["e", -7, 4, 4.5, 3, 0]]]]],
913
+ ["details", "black", [["m", [["e", -6.5, 60, 1.8, 2.4, 0]]], ["c", 0, 47.5, 2.4]]]
914
+ ]],
915
+ ["cat", "animals", "dark grey", [
916
+ ["clothes", "grey", [["k", 14, 6, 26, 30, 3.5, 3], ["c", 26, 34, 4]]],
917
+ ["clothes", "grey", [
918
+ ["h", [["c", -11, 9, 7], ["c", 11, 9, 7], ["c", 0, 38, 10]]],
919
+ ["m", [["p", [[-15, 60], [-15, 77], [-4, 66]]]]],
920
+ ["e", 0, 57, 15, 12.5, 0]
921
+ ]],
922
+ ["face", "pink", [["m", [["p", [[-13, 63], [-13.3, 72.5], [-7, 66]]]]]]],
923
+ ["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]]]]],
924
+ ["details", "light green", [["m", [["e", -6.5, 59, 2.4, 2.8, 0]]]]],
925
+ ["details", "pink", [["p", [[-1.8, 55.5], [1.8, 55.5], [0, 53.5]]]]]
926
+ ]],
927
+ ["dog", "animals", "dark brown", [
928
+ ["clothes", "tan", [["k", 14, 6, 25, 20, 3.5, 3]]],
929
+ ["clothes", "tan", [
930
+ ["h", [["c", -11, 9, 7], ["c", 11, 9, 7], ["c", 0, 38, 10]]],
931
+ ["e", 0, 58, 15, 13.5, 0]
932
+ ]],
933
+ ["clothes", "brown", [["m", [["e", -15, 56, 5.5, 12, -15]]]]],
934
+ ["face", "white", [["e", 0, 51, 7.5, 6, 0], ["e", 0, 26, 6.5, 11, 0], ["m", [["e", -7, 4, 4, 3, 0]]]]],
935
+ ["clothes", "red", [["r", 0, 43, 19, 4, 2, 0]]],
936
+ ["details", "black", [["m", [["c", -6, 61, 2.2]]], ["e", 0, 54, 3, 2.2, 0]]],
937
+ ["details", "yellow", [["c", 0, 39.5, 2.4]]]
938
+ ]],
939
+ ["owl", "animals", "dark brown", [
940
+ ["clothes", "brown", [
941
+ ["e", 0, 40, 22, 30, 0],
942
+ ["m", [["p", [[-18, 60], [-20, 78], [-8, 66]]]]]
943
+ ]],
944
+ ["face", "light brown", [["e", 0, 30, 14, 18, 0]]],
945
+ ["clothes", "brown", [["m", [["e", -18, 36, 7, 15, 12]]]]],
946
+ ["face", "beige", [["m", [["c", -8.5, 58, 9]]]]],
947
+ ["face", "orange", [["p", [[-3, 53], [3, 53], [0, 47]]], ["m", [["e", -6, 9.5, 4.5, 3, 0]]]]],
948
+ ["details", "black", [["m", [["c", -8.5, 58, 4]]]]],
949
+ ["details", "brown", [
950
+ for (p = [[-6, 32], [0, 34], [6, 32], [-3, 26], [3, 26], [0, 19]]) ["a", p[0], p[1], 3, 200, 340, 1.8]
951
+ ]]
952
+ ]],
953
+ ["deer", "animals", "dark brown", [
954
+ ["clothes", "light brown", [
955
+ ["m", [["r", -8, 10, 6, 20, 2.5, 0]]],
956
+ ["e", 0, 32, 15, 16, 0],
957
+ ["m", [["e", -15, 70, 9, 4.5, 30]]],
958
+ ["e", 0, 62, 11, 14, 0]
959
+ ]],
960
+ ["face", "pink", [["m", [["e", -15, 70, 5.5, 2.2, 30]]]]],
961
+ ["face", "beige", [["e", 0, 53, 7, 6, 0], ["e", 0, 28, 8, 10, 0]]],
962
+ ["clothes", "dark brown", [["m", [["r", -8, 2.5, 6, 5, 1.5, 0]]]]],
963
+ ["details", "black", [["m", [["c", -5, 63, 2.2]]], ["e", 0, 56, 2.6, 2, 0]]],
964
+ ["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]]]
965
+ ]]
966
+ ];
278
967
  `,"kerf/fit":`// kerf/fit: drawings scaled to a size and placed by a point of their box.
279
968
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
280
969
  //
@@ -1171,17 +1860,72 @@ module narrow_hinge(size, spacing = 1.5, bridge = 1.5) {
1171
1860
  if (i % 2 == 0) line([x, -1], [x, h - bridge]); else line([x, bridge], [x, h + 1]);
1172
1861
  }
1173
1862
 
1863
+ // The points a strip's middle follows round the corner at \`p\`, coming from
1864
+ // \`a\` and going on to \`b\`: an arc of radius \`r\` inside (the middle of the
1865
+ // sheet tangent to both sides) where both sides are at least \`straight\`
1866
+ // long, else \`p\` itself. A corner too tight for its sides rounds to the
1867
+ // radius that fits half of each.
1868
+ function strip_corner(a, p, b, straight = 10, r = undef) =
1869
+ let (
1870
+ R = (is_undef(r) ? 2 * $thickness : r) + $thickness / 2,
1871
+ u = p - a, v = b - p, lu = norm(u), lv = norm(v),
1872
+ h0 = atan2(u[1], u[0]), d0 = atan2(v[1], v[0]) - h0,
1873
+ turn = d0 > 180 ? d0 - 360 : d0 < -180 ? d0 + 360 : d0
1874
+ )
1875
+ lu < straight || lv < straight || abs(turn) <= 0.01 || abs(turn) >= 179.99 ? [p]
1876
+ : let (
1877
+ // How far back the arc starts from the corner, and its radius
1878
+ set = min(R * tan(abs(turn) / 2), lu / 2, lv / 2),
1879
+ rad = set / tan(abs(turn) / 2),
1880
+ side = turn > 0 ? 1 : -1,
1881
+ c = p - set * u / lu + side * rad * [-sin(h0), cos(h0)],
1882
+ m = max(ceil(abs(turn) / 5), ceil(rad * abs(turn) * PI / 180 / (max(straight, 1) / 2)))
1883
+ ) [for (k = [0:m]) let (g = h0 + turn * k / m) c + side * rad * [sin(g), -cos(g)]];
1884
+
1885
+ // \`path\` with each sharp corner, where two segments at least \`straight\`
1886
+ // long meet, rounded as strip_corner() rounds it: the path a strip that
1887
+ // bends round radius \`r\` there follows. The strip is as long as this path,
1888
+ // and ends where it does.
1889
+ function strip_path(path, straight = 10, r = undef) =
1890
+ let (
1891
+ pts = [for (i = [0:len(path) - 1]) if (i == 0 || norm(path[i] - path[i - 1]) > 1e-9) path[i]],
1892
+ n = len(pts),
1893
+ 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]])
1894
+ )
1895
+ // Two arcs on one short side meet at its middle: that point once, so no
1896
+ // segment is too short to have a heading
1897
+ [for (i = [0:len(all) - 1]) if (i == 0 || norm(all[i] - all[i - 1]) > 1e-6) all[i]];
1898
+
1899
+ // A closed outline with its sharp corners rounded as strip_path() rounds a
1900
+ // path's, each judged by its whole sides: the loop a strip round it follows
1901
+ function strip_loop(outline, straight = 10, r = undef) =
1902
+ let (
1903
+ n0 = len(outline),
1904
+ o = norm(outline[n0 - 1] - outline[0]) < 1e-9 ? slice(outline, 0, n0 - 1) : outline,
1905
+ pts = [for (i = [0:len(o) - 1]) if (i == 0 || norm(o[i] - o[i - 1]) > 1e-9) o[i]],
1906
+ m = len(pts),
1907
+ all = [for (i = [0:m - 1]) each strip_corner(pts[(i + m - 1) % m], pts[i], pts[(i + 1) % m], straight, r)],
1908
+ k = len(all)
1909
+ )
1910
+ // Two arcs on one short side meet at its middle: that point once
1911
+ [for (i = [0:k - 1]) if (norm(all[i] - all[(i + k - 1) % k]) > 1e-6) all[i]];
1912
+
1174
1913
  // The bends of a strip that follows \`path\`, a list of [x, y] points along
1175
1914
  // its middle: [s0, s1, angle] for each curve, measured along the path,
1176
1915
  // turning left positive. Segments shorter than \`straight\` are curve, the
1177
- // rest straight; a sharp corner bends round radius \`r\`.
1916
+ // rest straight; a sharp corner bends round radius \`r\`. A curve whose
1917
+ // radius changes, as a tight fillet running into a wide arc, is several
1918
+ // bends end to end, one for each stretch of much the same radius.
1178
1919
  function strip_bends(path, straight = 10, r = undef) =
1179
1920
  let (
1180
1921
  rr = is_undef(r) ? 2 * $thickness : r,
1181
- n = len(path),
1182
- segs = [for (i = [0:n - 2]) norm(path[i + 1] - path[i])],
1922
+ // Sharp corners rounded; a point repeated, as where a straight run and
1923
+ // an arc share their end, has no heading of its own and is left out
1924
+ pts = strip_path(path, straight, r),
1925
+ n = len(pts),
1926
+ segs = [for (i = [0:n - 2]) norm(pts[i + 1] - pts[i])],
1183
1927
  at = [for (i = [0:n - 1]) i == 0 ? 0 : sum([for (k = [0:i - 1]) segs[k]])],
1184
- head = [for (i = [0:n - 2]) atan2(path[i + 1][1] - path[i][1], path[i + 1][0] - path[i][0])],
1928
+ head = [for (i = [0:n - 2]) atan2(pts[i + 1][1] - pts[i][1], pts[i + 1][0] - pts[i][0])],
1185
1929
  turn = [for (i = [1:n - 2]) let (d = head[i] - head[i - 1]) d > 180 ? d - 360 : d < -180 ? d + 360 : d],
1186
1930
  // Each corner as [s0, s1, angle]: a short segment's turn spreads over
1187
1931
  // it, a sharp corner's over a bend of radius rr
@@ -1192,7 +1936,23 @@ function strip_bends(path, straight = 10, r = undef) =
1192
1936
  s1 = short_out ? at[i] + segs[i] / 2 : at[i] + half)
1193
1937
  [s0, s1, turn[i - 1]]]
1194
1938
  )
1195
- strip_merge(corners);
1939
+ strip_join(corners);
1940
+
1941
+ // Joins bends that touch or overlap into one where they turn the same way
1942
+ // at much the same rate (within a quarter), so each bend keeps close to
1943
+ // one radius. Two that overlap but don't join meet halfway through the
1944
+ // overlap.
1945
+ function strip_join(list, i = 0, cur = undef, out = []) =
1946
+ i == len(list) ? (is_undef(cur) ? out : concat(out, [cur]))
1947
+ : is_undef(cur) ? strip_join(list, i + 1, list[i], out)
1948
+ : let (nx = list[i]) nx[0] > cur[1] + 0.01 ? strip_join(list, i + 1, nx, concat(out, [cur]))
1949
+ : let (p = cur[2] / (cur[1] - cur[0]), q = nx[2] / (nx[1] - nx[0]),
1950
+ alike = p * q > 0 && max(abs(p), abs(q)) <= 1.25 * min(abs(p), abs(q)))
1951
+ // Alike, or one within the other: one bend
1952
+ alike || nx[0] <= cur[0] || nx[1] <= cur[1]
1953
+ ? strip_join(list, i + 1, [cur[0], max(cur[1], nx[1]), cur[2] + nx[2]], out)
1954
+ : nx[0] >= cur[1] ? strip_join(list, i + 1, nx, concat(out, [cur]))
1955
+ : let (m = (nx[0] + cur[1]) / 2) strip_join(list, i + 1, [m, nx[1], nx[2]], concat(out, [[cur[0], m, cur[2]]]));
1196
1956
 
1197
1957
  // Joins bends that touch or overlap into one
1198
1958
  function strip_merge(list, i = 0, cur = undef, out = []) =
@@ -1210,14 +1970,16 @@ function strip_merge(list, i = 0, cur = undef, out = []) =
1210
1970
  // own slots for the tabs. The 3D view shows the strip bent.
1211
1971
  module flex_strip(path, width, name = "strip", tabs = true, straight = 10, r = undef, spacing = 1.5, bridge = 3, narrow = false) {
1212
1972
  t = $thickness;
1213
- L = path_length(path);
1973
+ L = path_length(strip_path(path, straight, r));
1214
1974
  bends = strip_bends(path, straight, r);
1975
+ // The hinges are cut over each stretch of bends end to end
1976
+ spans = strip_merge(bends);
1215
1977
  h0 = heading_at(path, 0);
1216
1978
  p0 = path[0] - t / 2 * [-sin(h0), cos(h0)];
1217
- runs = [for (k = [0:len(bends)]) [k == 0 ? 0 : bends[k - 1][1], k == len(bends) ? L : bends[k][0]]];
1979
+ runs = [for (k = [0:len(spans)]) [k == 0 ? 0 : spans[k - 1][1], k == len(spans) ? L : spans[k][0]]];
1218
1980
  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]]]) {
1219
1981
  rect([L, width]);
1220
- for (b = bends) translate([b[0], 0])
1982
+ for (b = spans) translate([b[0], 0])
1221
1983
  if (narrow) narrow_hinge([b[1] - b[0], width], spacing, bridge);
1222
1984
  else living_hinge([b[1] - b[0], width], spacing = spacing, bridge = bridge);
1223
1985
  if (tabs)
@@ -1229,6 +1991,134 @@ module flex_strip(path, width, name = "strip", tabs = true, straight = 10, r = u
1229
1991
  }
1230
1992
  }
1231
1993
  }
1994
+
1995
+ // The part of \`path\` from s0 to s1 along it, its ends where those fall
1996
+ function path_part(path, s0, s1) =
1997
+ let (at = concat([0], scan([for (i = [0:len(path) - 2]) norm(path[i + 1] - path[i])], 0, function(a, x) a + x)))
1998
+ 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)]);
1999
+
2000
+ // A closed outline as a path round it that starts and ends at the point
2001
+ // of it nearest \`join\`, or with join undef the middle of its longest side
2002
+ function wall_path(outline, join = undef) =
2003
+ let (
2004
+ n = len(outline),
2005
+ pts = norm(outline[n - 1] - outline[0]) < 1e-9 ? slice(outline, 0, n - 1) : outline,
2006
+ m = len(pts),
2007
+ near = [for (i = [0:m - 1]) let (a = pts[i], b = pts[(i + 1) % m], d = b - a,
2008
+ 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)]],
2009
+ k = fold([for (i = [0:m - 1]) i], 0, function(b, i) near[i][1] < near[b][1] ? i : b),
2010
+ ring = concat([near[k][0]], [for (i = [1:m]) pts[(k + i) % m]], [near[k][0]])
2011
+ )
2012
+ [for (i = [0:len(ring) - 1]) if (i == 0 || norm(ring[i] - ring[i - 1]) > 1e-9) ring[i]];
2013
+
2014
+ // Where to split a strip L long into n pieces no longer than max_length:
2015
+ // near even spacing, at the middle of a straight run where one is near,
2016
+ // else at the middle of a segment of the path, where its bends end
2017
+ function wall_splits(L, n, max_length, mids, halves, k = 1, prev = 0, out = []) =
2018
+ k >= n ? out
2019
+ : let (t = k * L / n,
2020
+ // Where this cut may go: no piece longer than max_length, this one or
2021
+ // those still to come
2022
+ lo = max(prev + 1, L - (n - k) * max_length), hi = prev + max_length,
2023
+ fits = function(list) [for (c = list) if (c >= lo && c <= hi) c],
2024
+ nearest = function(list) fold(list, list[0], function(b, x) abs(x - t) < abs(b - t) ? x : b),
2025
+ ok = fits(mids), half = fits(halves),
2026
+ c = len(ok) ? nearest(ok) : len(half) ? nearest(half) : clamp(t, lo, hi))
2027
+ wall_splits(L, n, max_length, mids, halves, k + 1, c, concat(out, [c]));
2028
+
2029
+ // The names of the pieces of the strip wall() makes
2030
+ function wall_strip_names(name, pieces) = pieces == 1 ? [str(name, " strip")] : [for (k = [1:pieces]) str(name, " strip ", k)];
2031
+
2032
+ // How many pieces wall() cuts its strip into
2033
+ 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));
2034
+
2035
+ // A wall round a closed outline: a front plate, a back plate \`depth\`
2036
+ // behind it and a strip between them that follows the outline, bent on
2037
+ // living hinges where it curves and tabbed into slots in both plates where
2038
+ // it runs straight. The strip's ends meet at the point of the outline
2039
+ // nearest \`join\`; a strip longer than \`max_length\` is cut into pieces no
2040
+ // longer, split where it runs straight when it can, so each fits the bed.
2041
+ //
2042
+ // The first child, when given, is the front plate, drawn as the outline
2043
+ // is; the second the back plate. Without them each plate is the outline
2044
+ // grown by \`rim\` (half a thickness and 3 mm). Where the strip's ends meet
2045
+ // they are \`seam\` apart, so pieces bent on their hinges don't press on
2046
+ // each other. The parts are
2047
+ // str(name, " front"), str(name, " back") and str(name, " strip"), or
2048
+ // " strip 1", " strip 2" and so on for a strip in pieces. It stands
2049
+ // upright as placed by \`at\` and \`rotate\`: the outline is seen from the
2050
+ // front, the back plate behind it.
2051
+ 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]) {
2052
+ t = $thickness;
2053
+ grow = is_undef(rim) ? t / 2 + 3 : rim;
2054
+ path = wall_path(strip_loop(outline, straight, r), join);
2055
+ L = path_length(path);
2056
+ n = max(1, ceil(L / max_length));
2057
+ spans = strip_merge(strip_bends(path, straight, r));
2058
+ runs = [for (k = [0:len(spans)]) [k == 0 ? 0 : spans[k - 1][1], k == len(spans) ? L : spans[k][0]]];
2059
+ mids = [for (run = runs) if (run[1] - run[0] >= 2 * straight) (run[0] + run[1]) / 2];
2060
+ at_ = concat([0], scan([for (i = [0:len(path) - 2]) norm(path[i + 1] - path[i])], 0, function(a, x) a + x));
2061
+ halves = [for (i = [0:len(path) - 2]) (at_[i] + at_[i + 1]) / 2];
2062
+ cuts = concat([0], wall_splits(L, n, max_length, mids, halves), [L]);
2063
+ names = wall_strip_names(name, n);
2064
+ pieces = [for (k = [0:n - 1]) path_part(path, cuts[k] + seam / 2, cuts[k + 1] - seam / 2)];
2065
+ // The pieces with tabs, as flex_strip() puts them on runs over 16 mm
2066
+ tabbed = !tabs ? [] : [for (k = [0:n - 1]) let (sp = strip_merge(strip_bends(pieces[k], straight, r)), l = path_length(pieces[k]),
2067
+ 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]];
2068
+ place(at = at, rotate = rotate) {
2069
+ part(str(name, " front"), slots = tabbed) {
2070
+ if ($children > 0) children(0);
2071
+ else offset(delta = grow) polygon(outline);
2072
+ }
2073
+ part(str(name, " back"), at = [0, 0, -depth - t], slots = tabbed) {
2074
+ if ($children > 1) children(1);
2075
+ else offset(delta = grow) polygon(outline);
2076
+ }
2077
+ for (k = [0:n - 1])
2078
+ flex_strip(pieces[k], depth, name = names[k], tabs = tabs, straight = straight, r = r, spacing = spacing, bridge = bridge, narrow = narrow);
2079
+ }
2080
+ }
2081
+ `,"kerf/inlay":`// kerf/inlay: inlays of another wood, stock or colour: the shapes cut out
2082
+ // of one part (or engraved into it as pockets) and cut again as inserts
2083
+ // that press into them.
2084
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
2085
+ //
2086
+ // KerfScript takes the kerf off every cut, so a hole and an insert of the
2087
+ // same shape come out the same size; each insert is \`press\` mm bigger all
2088
+ // round so it holds.
2089
+
2090
+ // A part with inlays. Its first child is the part's shape; each child
2091
+ // after it is an inlay's shape. The inlays are cut through the part, or
2092
+ // with \`depth\` engraved that deep on the layer "pocket" (set that layer's
2093
+ // power for the depth). Each inlay is an insert of its own, named "name
2094
+ // inlay 1" up, \`press\` mm bigger all round, of materials[i] (stock of its
2095
+ // own, on a sheet of its own) or painted paints[i]; a pocket's insert is
2096
+ // \`depth\` thick. In the assembled view a through insert sits in its hole
2097
+ // and a pocket's on the surface over it.
2098
+ module inlaid(name, depth, press = 0.05, materials, paints, at = [0, 0, 0], rotate = [0, 0, 0]) {
2099
+ n = $children;
2100
+ assert(n >= 2, "inlaid(): give the part's shape, then one shape for each inlay");
2101
+ part(name, at = at, rotate = rotate) {
2102
+ if (is_undef(depth))
2103
+ difference() {
2104
+ children(0);
2105
+ for (i = [1:n - 1]) children(i);
2106
+ }
2107
+ else {
2108
+ children(0);
2109
+ layer("pocket", mode = "fill", color = "#555555") for (i = [1:n - 1]) children(i);
2110
+ }
2111
+ }
2112
+ for (i = [1:n - 1])
2113
+ let (
2114
+ m = is_undef(materials) || i - 1 >= len(materials) ? undef : materials[i - 1],
2115
+ c = is_undef(paints) || i - 1 >= len(paints) ? undef : paints[i - 1],
2116
+ t = is_undef(depth) ? $thickness : depth
2117
+ )
2118
+ material(thickness = t, name = is_undef(m) ? $material : m)
2119
+ part(str(name, " inlay ", i), glue = name, at = [0, 0, is_undef(depth) ? -t : 0], paint = c, press_fit = is_undef(depth))
2120
+ offset(delta = press) children(i);
2121
+ }
1232
2122
  `,"kerf/joints":`// kerf/joints: joints between parts.
1233
2123
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1234
2124
 
@@ -1323,6 +2213,59 @@ module halved_pair(name, at = [0, 0, 0], cap = undef, feet = [], side_feet = und
1323
2213
  }
1324
2214
  }
1325
2215
  }
2216
+ `,"kerf/layered":`// kerf/layered: multilayer pieces from one drawing, as layered ornaments,
2217
+ // mandalas, wreaths and signs are made.
2218
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
2219
+ //
2220
+ // The children are the art's layers, back to front. Each becomes a part of
2221
+ // its own, glued on the one behind it and painted its colour; each layer
2222
+ // is at least the outline of everything in front of it, \`border\` mm
2223
+ // wider, so every layer is held up and shows as a rim round the next.
2224
+
2225
+ // A layer's colour: the one given for it, else from a palette that goes
2226
+ // from dark at the back to light at the front
2227
+ function layered_color(colors, k, n) =
2228
+ !is_undef(colors) && k < len(colors) ? colors[k]
2229
+ : ["dark brown", "brown", "light brown", "tan", "beige", "cream", "white"][
2230
+ min(6, round(k * 6 / max(1, n - 1)))];
2231
+
2232
+ // Layered art from its children, the layers back to front: one part a
2233
+ // layer, named "name layer 1" up from the back, each glued on the one
2234
+ // behind it and painted colors[k]. Each layer is its own drawing joined
2235
+ // with everything in front of it grown by \`border\` mm. \`shadow\` adds a
2236
+ // layer at the back that much wider still, in \`shadow_color\`; \`hole\` =
2237
+ // [x, y, d] cuts a hole d across through every layer, to hang it by. The
2238
+ // back layer goes at \`at\`, turned by \`rotate\`.
2239
+ module layered(name = "layered", colors, border = 2, shadow = 0, shadow_color = "dark grey", hole, at = [0, 0, 0], rotate = [0, 0, 0]) {
2240
+ n = $children;
2241
+ assert(n >= 1, "layered(): give the layers as children, back to front");
2242
+ module through() if (!is_undef(hole)) translate([hole[0], hole[1]]) circle(d = hole[2]);
2243
+ first = shadow > 0 ? str(name, " shadow") : str(name, " layer 1");
2244
+ if (shadow > 0)
2245
+ part(first, at = at, rotate = rotate, paint = shadow_color)
2246
+ difference() {
2247
+ offset(r = shadow) union() {
2248
+ children(0);
2249
+ if (n > 1) offset(r = border) union() for (j = [1:n - 1]) children(j);
2250
+ }
2251
+ through();
2252
+ }
2253
+ // Layer k: its drawing, and everything in front of it grown by the border
2254
+ for (k = [0:n - 1])
2255
+ let (
2256
+ pname = str(name, " layer ", k + 1),
2257
+ host = k == 0 ? (shadow > 0 ? first : undef) : str(name, " layer ", k)
2258
+ )
2259
+ part(pname, at = is_undef(host) ? at : undef, rotate = is_undef(host) ? rotate : undef,
2260
+ glue = host, paint = layered_color(colors, k, n), pieces = "any")
2261
+ difference() {
2262
+ union() {
2263
+ children(k);
2264
+ if (k < n - 1) offset(r = border) union() for (j = [k + 1:n - 1]) children(j);
2265
+ }
2266
+ through();
2267
+ }
2268
+ }
1326
2269
  `,"kerf/linkage":`// kerf/linkage: where the joints of a linkage are at a crank angle.
1327
2270
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1328
2271
  //
@@ -1542,6 +2485,167 @@ module ring_stack(diameters, hole, name = "ring", count = undef, feet = true, cl
1542
2485
  translate([-(t + clearance) / 2, -t - 1]) rect([t + clearance, h / 2 + t + 1]);
1543
2486
  }
1544
2487
  }
2488
+ `,"kerf/scene":`// kerf/scene: scene boxes and dioramas: a floor with rails, standees with
2489
+ // feet that stand in any rail, layered figures standing in them, and
2490
+ // snow-drip and wave edges.
2491
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
2492
+ //
2493
+ // A floor (or a shelf) has rails: slots running across it, front to back
2494
+ // in rows. Every standee has 8 mm feet that go into any rail, so a scene
2495
+ // is changed by taking the standees out and putting others in. Standees
2496
+ // are drawn standing on y = 0, centred on x = 0; their feet go below.
2497
+
2498
+ use <kerf/figures>
2499
+
2500
+ // Where a floor's rails run, front to back: \`rows\` of them across a floor
2501
+ // \`depth\` deep, the first 8 mm from the front and the last 7 mm from the
2502
+ // back
2503
+ function scene_rows(depth, rows = 6) =
2504
+ assert(is_num(depth) && depth > 15, "scene_rows(): depth must be more than 15")
2505
+ rows == 1 ? [depth / 2] : [for (i = [0:rows - 1]) 8 + i * (depth - 15) / (rows - 1)];
2506
+
2507
+ // The rails of a floor \`width\` wide and \`depth\` deep, as slots to cut from
2508
+ // it: each \`$thickness + clearance\` wide, running across the floor and
2509
+ // stopping \`margin\` short of each side
2510
+ module scene_rails(width, depth, rows = 6, clearance = 0.1, margin = 6) {
2511
+ w = $thickness + clearance;
2512
+ for (y = scene_rows(depth, rows)) translate([margin, y - w / 2]) rect([width - 2 * margin, w]);
2513
+ }
2514
+
2515
+ // A floor with its rails, \`width\` by \`depth\`, its front edge on y = 0
2516
+ module scene_floor(width, depth, rows = 6, clearance = 0.1, margin = 6, r = 0) {
2517
+ difference() {
2518
+ rect([width, depth], r = r);
2519
+ scene_rails(width, depth, rows, clearance, margin);
2520
+ }
2521
+ }
2522
+
2523
+ // Where a standee's feet go across it, from its middle: one for a standee
2524
+ // under 28 mm wide, two a quarter of the width either side otherwise, and
2525
+ // three for a full-width one, as a backdrop
2526
+ function standee_feet(width, full = false) =
2527
+ full ? [-width / 3, 0, width / 3] : width < 28 ? [0] : [-width / 4, width / 4];
2528
+
2529
+ // The mound a standee stands on: 4.5 mm under a standee under 28 mm wide,
2530
+ // so it stands clear of the floor's edge, else none
2531
+ function standee_mound(width) = width < 28 ? 4.5 : 0;
2532
+
2533
+ // A standee: its children, a drawing, stood on a mound \`mound\` mm high
2534
+ // (by default as standee_mound() says) with \`tab\` mm feet below y = 0 that
2535
+ // go \`floor\` mm (the floor's thickness, $thickness) into a rail, spread
2536
+ // over the width it stands on as standee_feet() says; without a mound, a
2537
+ // ground line 2 mm high joins what stands on the floor. With
2538
+ // \`clip\`, a polygon's points, the drawing and mound are clipped to it and
2539
+ // the feet left whole, as for a standee in a round case.
2540
+ module standee(mound, full = false, tab = 8, floor, clip) {
2541
+ t = is_undef(floor) ? $thickness : floor;
2542
+ measure() {
2543
+ children();
2544
+ let (
2545
+ b = $bounds,
2546
+ w = b[2] - b[0],
2547
+ cx = (b[0] + b[2]) / 2,
2548
+ m = is_undef(mound) ? standee_mound(w) : mound
2549
+ ) {
2550
+ intersection() {
2551
+ union() {
2552
+ translate([0, m - b[1]]) children();
2553
+ if (m > 0) translate([b[0], 0]) rect([w, m + 0.5], r = min(m / 2, w / 4));
2554
+ }
2555
+ if (!is_undef(clip)) polygon(clip);
2556
+ }
2557
+ // The feet go where the drawing meets the floor: spread over the
2558
+ // width it stands on, each a whole tab inside it where it is wide
2559
+ // enough
2560
+ measure() {
2561
+ intersection() {
2562
+ union() {
2563
+ translate([0, m - b[1]]) children();
2564
+ if (m > 0) translate([b[0], 0]) rect([w, m + 0.5], r = min(m / 2, w / 4));
2565
+ }
2566
+ translate([b[0] - 1, -1]) rect([w + 2, 2]);
2567
+ }
2568
+ let (f = $bounds, fw = f[2] - f[0], fc = (f[0] + f[2]) / 2) {
2569
+ // A ground line 2 mm high joins legs and feet that meet the
2570
+ // floor apart
2571
+ if (m == 0) translate([f[0], 0]) rect([fw, 2]);
2572
+ for (x = standee_feet(fw, full))
2573
+ let (at = fw < tab ? fc : clamp(fc + x, f[0] + tab / 2, f[2] - tab / 2))
2574
+ translate([at - tab / 2, -t]) rect([tab, t + 0.5]);
2575
+ }
2576
+ }
2577
+ }
2578
+ }
2579
+ }
2580
+
2581
+ // A layered figure from kerf/figures standing in a rail: its backer a
2582
+ // standee with feet (and a mound when narrow), its other layers glued on
2583
+ // the front. \`at\` is where its feet go: [x, the rail's y, the floor's top
2584
+ // z]; \`turn\` turns it about its feet. Each colour is a painted part, named
2585
+ // after \`label\`.
2586
+ module scene_figure(name, height = 60, at = [0, 0, 0], turn = 0, label, mound, floor, border = 2, gap = 0.6) {
2587
+ base = is_undef(label) ? lower(name) : label;
2588
+ t = is_undef(floor) ? $thickness : floor;
2589
+ layers = figure_layers(name);
2590
+ middle = [for (l = layers) if (l[0] == "clothes" || l[0] == "face") l];
2591
+ measure() {
2592
+ figure_layer(name, "outline", height, border = border, gap = gap);
2593
+ let (b = $bounds, m = is_undef(mound) ? standee_mound(b[2] - b[0]) : mound) {
2594
+ // Its thickness stands in the rail, centred on it
2595
+ part(str(base, " outline"), at = [at[0] - $thickness / 2 * sin(turn), at[1] + $thickness / 2 * cos(turn), at[2]],
2596
+ rotate = [90, 0, turn], paint = layers[0][1])
2597
+ standee(m, floor = t) figure_layer(name, "outline", height, border = border, gap = gap);
2598
+ for (l = middle)
2599
+ measure() {
2600
+ figure_layer(name, l[0], height, l[1], border = border, gap = gap);
2601
+ if (!is_undef($bounds))
2602
+ part(str(base, " ", l[0], " ", l[1]), glue = str(base, " outline"), at = [0, m, 0], paint = l[1], pieces = "any")
2603
+ figure_layer(name, l[0], height, l[1], border = border, gap = gap);
2604
+ }
2605
+ figure_details(name, height, base, 1, border, gap);
2606
+ }
2607
+ }
2608
+ }
2609
+
2610
+ // A layered figure on a base of its own, to stand on a shelf: a base
2611
+ // plate \`base\` [w, d] mm with one rail, the figure's feet in it
2612
+ module figure_base(name, height = 80, base = [60, 20], at = [0, 0, 0], label, clearance = 0.1, r = 3) {
2613
+ label_ = is_undef(label) ? lower(name) : label;
2614
+ part(str(label_, " base"), at = [at[0] - base[0] / 2, at[1] - base[1] / 2, at[2]])
2615
+ difference() {
2616
+ rect(base, r = r);
2617
+ translate([6, base[1] / 2 - ($thickness + clearance) / 2]) rect([base[0] - 12, $thickness + clearance]);
2618
+ }
2619
+ scene_figure(name, height, at = [at[0], at[1], at[2] + $thickness], label = label_);
2620
+ }
2621
+
2622
+ // An edge that drips, as snow along a roof or icing on a cake: a strip
2623
+ // \`width\` wide and \`height\` tall above y = 0, with \`n\` round drips hanging
2624
+ // below it up to \`depth\` mm, their lengths and places varied by \`seed\`
2625
+ module drip_edge(width, height = 6, depth = 8, n, seed = 1) {
2626
+ k = is_undef(n) ? max(2, round(width / 12)) : n;
2627
+ len_ = rands(0.35, 1, k, seed);
2628
+ shift = rands(-0.25, 0.25, k, seed + 1);
2629
+ r = min(width / k / 4, depth / 3);
2630
+ rect([width, height]);
2631
+ for (i = [0:k - 1])
2632
+ let (x = width * (i + 0.5 + shift[i]) / k)
2633
+ hull() {
2634
+ translate([x, height / 2]) circle(r = r);
2635
+ translate([x, -depth * len_[i] + r]) circle(r = r);
2636
+ }
2637
+ }
2638
+
2639
+ // An edge of waves, as water or a frill: a strip \`width\` wide and \`height\`
2640
+ // tall above y = 0, its bottom edge \`n\` waves \`depth\` mm deep
2641
+ module wave_edge(width, height = 6, depth = 4, n) {
2642
+ k = is_undef(n) ? max(1, round(width / 20)) : n;
2643
+ steps = 24 * k;
2644
+ polygon(concat(
2645
+ [[0, height], [width, height]],
2646
+ [for (i = [0:steps]) let (x = width * (1 - i / steps)) [x, -depth / 2 + depth / 2 * cos(360 * k * x / width)]]
2647
+ ));
2648
+ }
1545
2649
  `,"kerf/shapes":`// kerf/shapes: basic shapes by name, sized to a box.
1546
2650
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1547
2651
  //
@@ -1866,8 +2970,9 @@ module speech_bubble(size = [40, 30], r, tail) {
1866
2970
  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]]);
1867
2971
  }
1868
2972
  }
1869
- `,"kerf/sizes":`// kerf/sizes: paper, card and photo sizes, in millimetres, for holders,
1870
- // folders, frames and boxes made to fit them.
2973
+ `,"kerf/sizes":`// kerf/sizes: paper, card, photo and banknote sizes, and the sizes of
2974
+ // bought parts and everyday things, in millimetres, for holders, folders,
2975
+ // frames and boxes made to fit them.
1871
2976
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1872
2977
 
1873
2978
  // Paper sizes as [width, height], portrait: "A0" to "A8", "B4" to "B6",
@@ -1880,7 +2985,8 @@ function paper_size(name) = let (s = lookup_size(name, PAPER_SIZES))
1880
2985
  // Card sizes as [width, height], landscape: "business" (85 x 55, Europe),
1881
2986
  // "us business" (88.9 x 50.8), "credit" (85.6 x 53.98, ID-1), "japan"
1882
2987
  // (91 x 55), "playing" (63 x 88), "bridge" (56 x 87), "tarot" (70 x 120),
1883
- // "postcard" (148 x 105), "us postcard" (152.4 x 101.6).
2988
+ // "postcard" (148 x 105), "us postcard" (152.4 x 101.6), "gift card"
2989
+ // (85.6 x 53.98, as a credit card).
1884
2990
  function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
1885
2991
  is_undef(s) ? assert(false, str("Unknown card size \\"", name, "\\". Known: ", size_names(CARD_SIZES))) : s;
1886
2992
 
@@ -1890,15 +2996,39 @@ function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
1890
2996
  function photo_size(name) = let (s = lookup_size(lookup_alias(name, PHOTO_ALIASES), PHOTO_SIZES))
1891
2997
  is_undef(s) ? assert(false, str("Unknown photo size \\"", name, "\\". Known: ", size_names(PHOTO_SIZES))) : s;
1892
2998
 
1893
- // A bought part's sizes by name, as a record: \`body\` [width, depth,
1894
- // height], and for parts with one, the \`shaft\` diameter, the \`shaft_length\`
1895
- // it stands out of the body and the \`hole\` to cut for it. Retail sizes vary:
1896
- // measure yours. "music-18" (an 18-note wind-up music box movement, shaft
1897
- // the winding key's), "quartz-clock" (a 56 mm quartz clock movement with
1898
- // the 16.5 mm shaft for dials up to 8 mm thick), "marble-16" and "marble-25".
2999
+ // Banknote sizes as [width, height], landscape: "usd" (every US note),
3000
+ // "cad" (every Canadian note), "eur 5" to "eur 200", "gbp 5" to "gbp 50",
3001
+ // "aud 5" to "aud 100".
3002
+ function note_size(name) = let (s = lookup_size(name, NOTE_SIZES))
3003
+ is_undef(s) ? assert(false, str("Unknown banknote \\"", name, "\\". Known: ", size_names(NOTE_SIZES))) : s;
3004
+
3005
+ // A bought part's or an everyday thing's sizes by name, as a record: \`body\`
3006
+ // [width, depth, height]; for a round one its \`diameter\` and \`height\` (an
3007
+ // egg's \`length\`); for parts with one, the \`shaft\` diameter, the
3008
+ // \`shaft_length\` it stands out of the body and the \`hole\` to cut for it.
3009
+ // Retail sizes vary: measure yours.
3010
+ // Movements: "music-18" (an 18-note wind-up music box movement, shaft the
3011
+ // winding key's), "quartz-clock" (a 56 mm quartz clock movement with the
3012
+ // 16.5 mm shaft for dials up to 8 mm thick).
3013
+ // Lights: "tealight", "maxi tealight", "led tealight", "led puck",
3014
+ // "fairy lights" (the battery box of a string of them, with its \`wire\`).
3015
+ // Eggs and bottles: "hen egg", "chocolate egg", "wine bottle" (with its
3016
+ // \`neck\`).
3017
+ // Small parts: "magnet 6x2", "magnet 10x3", "magnet 12x3" (discs),
3018
+ // "key ring 25", "battery box 2aa", "battery box 3aa", "coin cell holder",
3019
+ // "key fob", "marble-16", "marble-25".
3020
+ // Boxes: "tissue box", "tissue cube".
1899
3021
  function part_size(name) = let (s = lookup_size(name, PART_SIZES))
1900
3022
  is_undef(s) ? assert(false, str("Unknown part \\"", name, "\\". Known: ", size_names(PART_SIZES))) : s;
1901
3023
 
3024
+ // The names in one of the tables, as a list, for a customizer menu:
3025
+ // "paper", "card", "photo", "note" (banknotes) or "part"
3026
+ function size_list(kind) =
3027
+ let (t = kind == "paper" ? PAPER_SIZES : kind == "card" ? CARD_SIZES : kind == "photo" ? PHOTO_SIZES
3028
+ : kind == "note" ? NOTE_SIZES : kind == "part" ? PART_SIZES : undef)
3029
+ assert(!is_undef(t), str("size_list(): kind must be \\"paper\\", \\"card\\", \\"photo\\", \\"note\\" or \\"part\\", got ", kind))
3030
+ [for (e = t) e[0]];
3031
+
1902
3032
  // A size turned to lie wider than tall
1903
3033
  function landscape(size) = size[0] >= size[1] ? size : [size[1], size[0]];
1904
3034
  // A size turned to stand taller than wide
@@ -1916,7 +3046,15 @@ PAPER_SIZES = [
1916
3046
  CARD_SIZES = [
1917
3047
  ["business", [85, 55]], ["us business", [88.9, 50.8]], ["credit", [85.6, 53.98]],
1918
3048
  ["japan", [91, 55]], ["playing", [63, 88]], ["bridge", [56, 87]], ["tarot", [70, 120]],
1919
- ["postcard", [148, 105]], ["us postcard", [152.4, 101.6]]
3049
+ ["postcard", [148, 105]], ["us postcard", [152.4, 101.6]], ["gift card", [85.6, 53.98]]
3050
+ ];
3051
+ NOTE_SIZES = [
3052
+ ["usd", [155.96, 66.29]], ["cad", [152.4, 69.85]],
3053
+ ["eur 5", [120, 62]], ["eur 10", [127, 67]], ["eur 20", [133, 72]],
3054
+ ["eur 50", [140, 77]], ["eur 100", [147, 77]], ["eur 200", [153, 77]],
3055
+ ["gbp 5", [125, 65]], ["gbp 10", [132, 69]], ["gbp 20", [139, 73]], ["gbp 50", [146, 77]],
3056
+ ["aud 5", [130, 65]], ["aud 10", [137, 65]], ["aud 20", [144, 65]],
3057
+ ["aud 50", [151, 65]], ["aud 100", [158, 65]]
1920
3058
  ];
1921
3059
  PHOTO_SIZES = [
1922
3060
  ["4x6", [152.4, 101.6]], ["5x7", [177.8, 127]], ["8x10", [254, 203.2]],
@@ -1932,7 +3070,25 @@ PART_SIZES = [
1932
3070
  ["music-18", {body = [50, 44, 20], shaft = 3.5, hole = 6}],
1933
3071
  ["quartz-clock", {body = [56, 56, 16], shaft = 7.6, shaft_length = 16.5, hole = 8, dial = 8}],
1934
3072
  ["marble-16", {body = [16, 16, 16]}],
1935
- ["marble-25", {body = [25, 25, 25]}]
3073
+ ["marble-25", {body = [25, 25, 25]}],
3074
+ ["tealight", {body = [39, 39, 16], diameter = 39, height = 16, hole = 40}],
3075
+ ["maxi tealight", {body = [59, 59, 24], diameter = 59, height = 24, hole = 60}],
3076
+ ["led tealight", {body = [38, 38, 36], diameter = 38, height = 36, hole = 40}],
3077
+ ["led puck", {body = [70, 70, 25], diameter = 70, height = 25, hole = 72}],
3078
+ ["fairy lights", {body = [62, 37, 22], wire = 2}],
3079
+ ["hen egg", {body = [44, 44, 57], diameter = 44, length = 57}],
3080
+ ["chocolate egg", {body = [40, 40, 60], diameter = 40, length = 60}],
3081
+ ["wine bottle", {body = [76, 76, 300], diameter = 76, height = 300, neck = 30}],
3082
+ ["magnet 6x2", {body = [6, 6, 2], diameter = 6, height = 2, hole = 6.2}],
3083
+ ["magnet 10x3", {body = [10, 10, 3], diameter = 10, height = 3, hole = 10.2}],
3084
+ ["magnet 12x3", {body = [12, 12, 3], diameter = 12, height = 3, hole = 12.2}],
3085
+ ["key ring 25", {body = [25, 25, 2.5], diameter = 25, height = 2.5}],
3086
+ ["battery box 2aa", {body = [68, 35, 18]}],
3087
+ ["battery box 3aa", {body = [68, 48, 18]}],
3088
+ ["coin cell holder", {body = [25, 21, 6]}],
3089
+ ["key fob", {body = [60, 35, 15]}],
3090
+ ["tissue box", {body = [240, 120, 90]}],
3091
+ ["tissue cube", {body = [115, 115, 130]}]
1936
3092
  ];
1937
3093
 
1938
3094
  // The size of that name in a table of [name, size], ignoring case
@@ -1944,6 +3100,65 @@ function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = ali
1944
3100
  len(hit) ? hit[0] : name;
1945
3101
  // The names in a table, for messages
1946
3102
  function size_names(table) = join([for (e = table) e[0]], ", ");
3103
+ `,"kerf/sphere":`// kerf/sphere: slot-together balls and domes, as 3D baubles, globes and
3104
+ // lantern domes.
3105
+ // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
3106
+ //
3107
+ // A ball is half-disc fins standing round an upright axis, like the
3108
+ // segments of an orange, held by flat rings slotted onto them with halving
3109
+ // joints. The fins stop short of the axis, so they never meet each other.
3110
+
3111
+ // The heights of a ball's rings above its centre: the equator alone, or
3112
+ // \`rings\` spread between 60 degrees south and north; for a dome, from 10
3113
+ // to 70 degrees north
3114
+ function ball_rings(d, rings = 1, dome = false) =
3115
+ let (R = d / 2)
3116
+ dome ? (rings <= 1 ? [R * sin(10)] : [for (i = [0:rings - 1]) R * sin(10 + 60 * i / (rings - 1))])
3117
+ : rings <= 1 ? [0] : [for (i = [0:rings - 1]) R * sin(-60 + 120 * i / (rings - 1))];
3118
+
3119
+ // A ball \`d\` across, its centre at \`at\`: \`fins\` half-disc fins round its
3120
+ // upright axis and \`rings\` flat rings \`width\` wide slotted onto them. A
3121
+ // dome is the top half, standing on its lowest ring. \`hollow\` cuts the
3122
+ // fins away within that radius of the centre, to make room for a scene
3123
+ // inside; \`floor\` makes the lowest ring a whole disc for it to stand on,
3124
+ // with a rail along x across the hollow for a standee's feet.
3125
+ // \`loop\` (a diameter) puts a hole near the top of each fin for a ribbon
3126
+ // to hang it by. Parts are named after \`label\`: "ball fin", "ball ring 1".
3127
+ 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) {
3128
+ R = d / 2;
3129
+ t = $thickness;
3130
+ core = 1.2 * t;
3131
+ assert(fins >= 3, "ball(): fins must be 3 or more");
3132
+ assert(width < R / 2, "ball(): the rings must be narrower than a quarter of the ball");
3133
+ heights = ball_rings(d, rings, dome);
3134
+ hx = core + loop / 2 + 2;
3135
+ part(str(label, " fin"), qty = fins,
3136
+ at = [for (k = [0:fins - 1]) let (a = 360 * k / fins) at + [-t / 2 * sin(a), t / 2 * cos(a), 0]],
3137
+ rotate = [for (k = [0:fins - 1]) [90, 0, 360 * k / fins]],
3138
+ halving = [str(label, " ring*")], clearance = clearance)
3139
+ difference() {
3140
+ intersection() {
3141
+ circle(r = R);
3142
+ translate([core, dome ? 0 : -R]) rect([R, dome ? R : 2 * R]);
3143
+ }
3144
+ if (hollow > 0) circle(r = hollow);
3145
+ if (loop > 0) translate([hx, sqrt(R * R - (hx + loop / 2) * (hx + loop / 2)) - loop / 2 - 2]) circle(d = loop);
3146
+ }
3147
+ for (i = [0:len(heights) - 1])
3148
+ let (h = heights[i], r = sqrt(R * R - h * h))
3149
+ part(str(label, " ring ", i + 1), at = at + [0, 0, h - t / 2])
3150
+ // As many corners as a multiple of the fins, so every fin crosses
3151
+ // a ring alike and takes the same slot
3152
+ difference() {
3153
+ circle(r = r, $fn = fins * ceil(120 / fins));
3154
+ if (!(floor && i == 0)) circle(r = r - width, $fn = fins * ceil(120 / fins));
3155
+ // A floor in a hollow ball has a rail across its middle, where no
3156
+ // fin reaches, for a standee from kerf/scene
3157
+ if (floor && i == 0 && hollow > 12)
3158
+ translate([-(hollow - 6), -(t + clearance) / 2]) rect([2 * (hollow - 6), t + clearance]);
3159
+ }
3160
+ if (loop > 0) hardware("ribbon", at + [0, 0, R - 6], at + [0, 0, R + 25], [6, 0.4], label = str(label, " ribbon"));
3161
+ }
1947
3162
  `,"kerf/stand":`// kerf/stand: a sign, a photo or a calendar standing in a base.
1948
3163
  // Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
1949
3164
  //
@@ -2015,15 +3230,26 @@ module stand_slots(width, count = undef, tab = undef, lean = 0, clearance = 0.1)
2015
3230
  // closed and its holes filled, with the drawing's detail engraved on it:
2016
3231
  // a pictogram drawn as separate strokes (a moon and stars, yarn) cut out
2017
3232
  // in one piece. bridge = w also joins pieces too far apart to close, by
2018
- // strips w wide.
2019
- module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef) {
3233
+ // strips w wide. min_width = w grows every line narrower than w to w, so
3234
+ // a symbol drawn small can be cut.
3235
+ module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef, min_width = undef) {
2020
3236
  assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
2021
3237
  s = symbol_entry(name);
2022
3238
  vb = box == "grid" ? s[5] : s[2];
2023
3239
  k = size / max(vb[2], vb[3]);
2024
- module drawn() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
3240
+ module art() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
2025
3241
  scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
2026
3242
  path(s[4], fill = fill, close = true);
3243
+ // With min_width, every line narrower than it grows to it: what an
3244
+ // opening by that width removes, grown by half of it either side
3245
+ module drawn() if (is_undef(min_width) || min_width <= 0) art();
3246
+ else union() {
3247
+ art();
3248
+ offset(r = min_width / 2) difference() {
3249
+ art();
3250
+ offset(r = min_width / 2) offset(r = -min_width / 2) art();
3251
+ }
3252
+ }
2027
3253
  r = is_undef(close) ? size / 30 : close;
2028
3254
  module silhouette() if (is_undef(bridge)) fill_holes() close(r) drawn();
2029
3255
  else join_islands(bridge) fill_holes() close(r) drawn();
@@ -3014,10 +4240,10 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
3014
4240
  if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
3015
4241
  if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
3016
4242
  }
3017
- `};var P="0.3";var u="kerf.json",k="kerf.lock",A="kerf_libraries",x=20<<20,R=2e3,X=/^[a-z0-9][a-z0-9_-]{0,63}$/,C1=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/,H1=/^(readme|licen[cs]e|copying|notice|changelog)(\.[a-z]+)?$/i,W=class extends Error{},c1=a=>{try{return v1(a).isFile()}catch{return!1}},C=a=>{try{return v1(a).isDirectory()}catch{return!1}},S=(a,c)=>a&&Object.prototype.hasOwnProperty.call(a,c)?a[c]:void 0,d=a=>{throw new W(a)};function o1(a,c){return(typeof a!="string"||!X.test(a))&&d(`${c} "${a}" is not a library name: use lowercase letters, digits, - and _`),a==="kerf"&&d(`${c}: "kerf" is the standard library's name`),a}function l1(a,c){(!a||typeof a!="object"||Array.isArray(a))&&d(`${c} must hold a JSON object`);let l=a;for(let n of["name","version","description","license","language"])l[n]!==void 0&&typeof l[n]!="string"&&d(`${c}: "${n}" must be a string`);l.name!==void 0&&o1(l.name,`${c}: name`),l.version!==void 0&&!C1.test(l.version)&&d(`${c}: "version" must look like 1.2.0, not "${l.version}"`),l.language!==void 0&&!/^\d+\.\d+$/.test(l.language)&&d(`${c}: "language" must look like ${P}, not "${l.language}"`),l.sheet!==void 0&&!(Array.isArray(l.sheet)&&l.sheet.length===2&&l.sheet.every(n=>typeof n=="number"&&Number.isFinite(n)&&n>0))&&d(`${c}: "sheet" must be [width, height] in mm, like [600, 400]`);let e=l.libraries??{};(!e||typeof e!="object"||Array.isArray(e))&&d(`${c}: "libraries" must be an object of name: source`);for(let[n,t]of Object.entries(e))o1(n,`${c}: library`),typeof t!="string"&&d(`${c}: the source of ${n} must be a string`);return{...l,libraries:{...e}}}function a1(a,c){let l;try{l=T(a,"utf8")}catch{return d(`${c} was not found`)}try{return JSON.parse(l)}catch(e){return d(`${c} is not valid JSON: ${e.message}`)}}function H(a,c=u){return l1(a1(f(a,u),c),c)}function d1(a){if(!I(f(a,k)))return;let c=a1(f(a,k),k);(c?.lockVersion!==1||!c.libraries||typeof c.libraries!="object")&&d(`${k} is not a kerf.lock this kerf can read. Delete it and run kerf install.`);for(let[l,e]of Object.entries(c.libraries))(!e||["source","resolved","integrity"].some(n=>typeof e[n]!="string"))&&d(`${k}: the entry for ${l} is damaged. Remove it and run kerf install.`);return c}function f1(a){for(let c=O(a);;){if(c1(f(c,u)))return c;let l=J(c);if(l===c)return;c=l}}function n1(a){try{return H(a).name}catch{return}}function V1(a,c,l=c1){let e=(s,h)=>[f(s,h),f(s,h+".kerf")].find(i=>l(i));if(Z(c))return[c,c+".kerf"].find(s=>l(s));let n=c.indexOf("/"),t=n>0?f1(a):void 0;if(t){let s=c.slice(0,n);if(s===n1(t))return e(t,c.slice(n+1));if(C(f(t,A,s)))return e(f(t,A),c)}return e(a,c)}function Y1(a){let c=J(O(a));return l=>{let e=V1(c,l);return e===void 0?void 0:T(e,"utf8")}}function Q1(a,c=200){let l=f1(a);if(!l)return[];let e=[],n=(h,i)=>{for(let r of[...M1(h,3)].sort()){if(e.length>=c)return;r.endsWith(".kerf")&&e.push(i+r.slice(0,-5))}},t=n1(l);t&&n(l,t+"/");let s=f(l,A);if(C(s))for(let h of Y(s).sort())X.test(h)&&C(f(s,h))&&n(f(s,h),h+"/");return e}function M1(a,c=1/0){let l=[],e=(n,t,s)=>{let h;try{h=Y(n,{withFileTypes:!0})}catch{return}for(let i of h){if(i.name.startsWith(".")||i.name==="node_modules"||i.name===A)continue;let r=t?`${t}/${i.name}`:i.name;i.isDirectory()?s<c&&e(f(n,i.name),r,s+1):i.isFile()&&(l.push(r),l.length>R&&d(`${a} has more than ${R} files`))}};return e(a,"",0),l}function G(a,c=()=>!0){let l=new Map;for(let e of M1(a))c(e)&&l.set(e,T(f(a,...e.split("/"))));return l}var e1=a=>a===u||a.endsWith(".kerf")||!a.includes("/")&&H1.test(a);function F(a){let c=b1("sha256");for(let l of[...a.keys()].sort()){let e=Buffer.from(a.get(l).toString("utf8").replace(/\r\n/g,`
3018
- `));c.update(`${l}\0${e.length}\0`),c.update(e)}return"sha256-"+c.digest("base64")}function r1(a){return a.kind==="folder"?"folder:"+(process.platform==="win32"?a.path.toLowerCase():a.path):a.kind==="github"?`github:${a.owner}/${a.repo}`.toLowerCase()+`@${a.ref}`:a.url}function E(a,c){let l=/^github:([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:@(\S+))?$/.exec(a);if(l)return{kind:"github",owner:l[1],repo:l[2],ref:l[3]??"HEAD"};if(/^https?:\/\//i.test(a)){let n;try{n=new URL(a)}catch{return d(`${a} is not a link`)}return n.protocol==="http:"&&!["localhost","127.0.0.1","[::1]"].includes(n.hostname)&&d(`Use https:// to download ${a}`),{kind:"url",url:a}}let e=a.startsWith("file:")?a.slice(5):a;return e.startsWith("./")||e.startsWith("../")||Z(e)?{kind:"folder",path:O(c,e)}:d(`"${a}" is not a library source. Use github:owner/repo@tag, an https:// link to a .tar.gz, or a folder like ./my-library`)}async function q1(a,c){let l;try{l=await c(a)}catch(h){let i=h;return d(`Could not download ${a}: ${i.cause?.message??i.message}`)}l.ok||d(`Could not download ${a}: HTTP ${l.status}`+(l.status===404?". Check the name and the tag, and that it is public.":""));let e=()=>d(`${a} is larger than ${x>>20} MB`);if(Number(l.headers?.get("content-length"))>x&&e(),!l.body){let h=Buffer.from(await l.arrayBuffer());return h.length>x?e():h}let n=l.body.getReader(),t=[],s=0;for(;;){let{done:h,value:i}=await n.read();if(h||!i)break;s+=i.length,s>x&&(await n.cancel().catch(()=>{}),e()),t.push(i)}return Buffer.concat(t)}function x1(a,c){let l;try{l=A1(a,{maxOutputLength:5*x})}catch{return d(`${c} is not a .tar.gz file`)}let e=new Map,n,t={},s;for(let h=0;h+512<=l.length;){let i=l.subarray(h,h+512);if(i.every(g=>g===0))break;let r=(g,L)=>{let w=i.subarray(g,g+L),V=w.indexOf(0);return w.subarray(0,V<0?L:V).toString("utf8")},v=parseInt(r(124,12).trim()||"0",8);v>=0||d(`${c} is damaged`);let M=r(156,1)||"0",o=l.subarray(h+512,h+512+v);if(h+=512+Math.ceil(v/512)*512,M==="x"||M==="g"){let g=_1(o);M==="g"?n=g.comment??n:t=g;continue}if(M==="L"){s=o.toString("utf8").replace(/\0+$/,"");continue}let m=r(345,155),p=t.path??s??(m?m+"/":"")+r(0,100);t={},s=void 0,(M==="0"||M==="7")&&e.set(p,Buffer.from(o)),e.size>R&&d(`${c} has more than ${R} files`)}return{files:e,commit:n}}function _1(a){let c={};for(let l=0;l<a.length;){let e=a.indexOf(32,l),n=parseInt(a.subarray(l,e).toString(),10);if(!(n>0)||e<0)break;let t=a.subarray(e+1,l+n-1).toString("utf8"),s=t.indexOf("=");s>0&&(c[t.slice(0,s)]=t.slice(s+1)),l+=n}return c}function m1(a,c){let l=new Map;for(let[t,s]of a){let h=t.replace(/^\.\//,""),i=h.split("/");(Z(h)||h.includes("\\")||h.includes(":")||i.some(r=>r===".."||r===""))&&d(`${c} holds a file outside its folder: ${t}`),l.set(h,s)}let e="";if(!l.has(u)){let t=new Set([...l.keys()].map(s=>s.split("/")[0]));t.size===1&&(e=[...t][0]+"/")}let n=new Map;for(let[t,s]of l){if(!t.startsWith(e))continue;let h=t.slice(e.length);h.split("/").some(i=>i.startsWith(".")||i===A||i==="node_modules")||e1(h)&&n.set(h,s)}return n.has(u)||d(`${c} has no kerf.json at its top. Is it a KerfScript library?`),n}var S1=(a,c)=>{let[l,e]=a.split(".").map(Number),[n,t]=c.split(".").map(Number);return l>n||l===n&&e>t};async function z1(a,c,l,e,n){let t=E(a,c),s,h;if(t.kind==="folder")c1(f(t.path,u))||d(`${a}: no kerf.json in ${t.path}. Is it a KerfScript library?`),s=m1(G(t.path,e1),a),h=L1(l,t.path).split(y1).join("/")||".",!h.startsWith(".")&&!Z(h)&&(h="./"+h);else{let r=t.kind==="github"?`https://github.com/${t.owner}/${t.repo}/archive/${t.ref}.tar.gz`:t.url,v=n.get(r)??await q1(r,e);n.set(r,v);let M=x1(v,a);s=m1(M.files,a),h=t.kind==="github"&&/^[0-9a-f]{40}$/.test(M.commit??"")?`https://github.com/${t.owner}/${t.repo}/archive/${M.commit}.tar.gz`:r}let i=l1(JSON.parse(s.get(u).toString("utf8")),`the kerf.json of ${a}`);return i.name||d(`${a}: its kerf.json has no "name", so it is not a library`),i.language&&S1(i.language,P)&&d(`${i.name} needs KerfScript language ${i.language} or later, and this kerf has ${P}. Update kerf.`),{manifest:i,files:s,resolved:h,integrity:F(s)}}function T1(a,c){Q(a,{recursive:!0,force:!0});for(let[l,e]of c){let n=f(a,...l.split("/"));w1(J(n),{recursive:!0}),_(n,e)}}var $1=a=>{let c=[...a].sort(([l],[e])=>l<e?-1:1);return JSON.stringify({lockVersion:1,libraries:Object.fromEntries(c)},null,2)+`
3019
- `};async function j1(a,c={}){let l=c.fetch??globalThis.fetch,e=c.log??(()=>{}),n=c.cache??new Map,t=H(a),s=d1(a),h=new Map,i=Object.entries(t.libraries).map(([o,m])=>({name:o,source:m,base:a,from:u})),r=f(a,A);for(;i.length;){let{name:o,source:m,base:p,from:g}=i.shift(),L=E(m,p),w=L.kind==="folder",V=w?`${m} (${L.path})`:m,$=h.get(o);if($){$.at!==r1(L)&&!S(t.libraries,o)&&d(`${g} uses ${o} from ${V}, and ${$.from} uses it from ${$.shown}. Add ${o} to kerf.json with the source to use.`);continue}let B=S(s?.libraries,o),b=B?.source===m&&(!w||O(a,B.resolved)===L.path)?B:void 0;c.frozen&&!b&&d(`kerf.lock does not pin ${o} from ${m}. Run kerf install without --frozen.`);let j=f(r,o),q;if(b&&!w&&C(j)&&F(G(j))===b.integrity)q=b;else{let z=await z1(b&&!w?b.resolved:m,w?p:a,a,l,n);z.manifest.name!==o&&d(`${m} is the library "${z.manifest.name}", so ${g} must call it ${z.manifest.name}, not ${o}`),b&&z.integrity!==b.integrity&&(!w||c.frozen)&&d(w?`${o} in ${m} changed since kerf.lock pinned it. Run kerf install without --frozen.`:`${o} from ${b.resolved} no longer matches kerf.lock. If you trust the change, remove ${o} from kerf.lock and run kerf install again.`),T1(j,z.files),q={source:m,...z.manifest.version?{version:z.manifest.version}:{},resolved:z.resolved,integrity:z.integrity},(!b||b.integrity!==z.integrity||!w)&&e(`${b?"Restored":"Installed"} ${o}${q.version?" "+q.version:""} from ${m}`)}h.set(o,{entry:q,at:r1(L),shown:V,from:g});let t1=L.kind==="folder"?L.path:void 0;for(let[z,K]of Object.entries(H(j,`${A}/${o}/${u}`).libraries))E(K,a).kind==="folder"&&!t1&&d(`${o} uses ${z} from the folder ${K}: a published library needs github: or https: sources`),i.push({name:z,source:K,base:t1??a,from:o})}let v=$1(new Map([...h].map(([o,m])=>[o,m.entry]))),M=I(f(a,k))?T(f(a,k),"utf8"):"";if(c.frozen&&v!==M.replace(/\r\n/g,`
3020
- `)&&d("kerf.lock is out of date. Run kerf install without --frozen."),C(r))for(let o of Y(r,{withFileTypes:!0}))o.isDirectory()&&X.test(o.name)&&!h.has(o.name)&&(Q(f(r,o.name),{recursive:!0,force:!0}),e(`Removed ${o.name}`));return v!==M.replace(/\r\n/g,`
3021
- `)&&_(f(a,k),v),JSON.parse(v)}function J1(a){let c=H(a),l=d1(a),e=Object.keys(c.libraries);if(!l)return e.length?["kerf.lock is missing. Run kerf install."]:[];let n=[],t=new Set,s=[...e];for(;s.length;){let h=s.shift();if(t.has(h))continue;t.add(h);let i=S(l.libraries,h);if(!i){n.push(`${h} is not in kerf.lock. Run kerf install.`);continue}e.includes(h)&&i.source!==c.libraries[h]&&n.push(`kerf.json takes ${h} from ${c.libraries[h]}, and kerf.lock from ${i.source}. Run kerf install.`);let r=f(a,A,h);if(!C(r)){n.push(`${h} is not in ${A}. Run kerf install.`);continue}F(G(r))!==i.integrity&&n.push(`The files in ${A}/${h} differ from kerf.lock. Run kerf install.`);try{s.push(...Object.keys(H(r).libraries))}catch(v){n.push(v.message)}}for(let h of Object.keys(l.libraries))t.has(h)||n.push(`kerf.lock pins ${h}, which nothing uses any more.`);return n}function P1(a,c){let l=f(a,u),e=I(l)?a1(l,u):{};l1(e,u);let n={...e.libraries??{}};return c(n),e.libraries=n,{file:l,before:I(l)?T(l,"utf8"):void 0,raw:e}}async function u1(a,c,l){let{file:e,before:n,raw:t}=P1(a,c);_(e,JSON.stringify(t,null,2)+`
3022
- `);try{return await j1(a,l)}catch(s){throw n===void 0?Q(e,{force:!0}):_(e,n),s}}async function X1(a,c,l={}){let e=new Map,t=(await z1(c,a,a,l.fetch??globalThis.fetch,e)).manifest.name;t===n1(a)&&d(`This project is the library ${t}; it cannot use itself`);let s=await u1(a,h=>void(h[t]=c),{...l,cache:e});return{name:t,lock:s}}async function c0(a,c,l={}){return u1(a,e=>{S(e,c)===void 0&&d(`kerf.json has no library named ${c}`),delete e[c]},l)}function U(a,c=[]){if(Array.isArray(a))for(let l of a)U(l,c);else if(a&&typeof a=="object"){let l=a;if(l.kind==="use"&&typeof l.path=="string")c.push({path:l.path,line:l.pos.line});else for(let e of Object.values(l))U(e,c)}return c}function I1(a){let c=[];for(let[l,e]of a){let n=Buffer.alloc(512),t=l,s="";if(Buffer.byteLength(t)>100){let i=l.lastIndexOf("/",155);(i<0||Buffer.byteLength(l.slice(i+1))>100)&&d(`${l}: the path is too long to pack`),s=l.slice(0,i),t=l.slice(i+1)}n.write(t,0,100),n.write("0000644\0",100),n.write("0000000\0",108),n.write("0000000\0",116),n.write(e.length.toString(8).padStart(11,"0")+"\0",124),n.write("00000000000\0",136),n.fill(32,148,156),n.write("0",156),n.write("ustar\0",257),n.write("00",263),n.write(s,345,155);let h=0;for(let i of n)h+=i;n.write(h.toString(8).padStart(6,"0")+"\0 ",148),c.push(n,e,Buffer.alloc((512-e.length%512)%512))}return c.push(Buffer.alloc(1024)),k1(Buffer.concat(c),{level:9})}function l0(a,c){let l=H(a),e=l.name??d('kerf.json needs a "name" to pack a library'),n=l.version??d('kerf.json needs a "version", like 1.0.0'),t=G(a,e1),s=[];for(let[v,M]of Object.entries(l.libraries))E(M,a).kind==="folder"&&s.push(`kerf.json: ${v} comes from a folder; a published library needs github: or https: sources`);let h=v=>t.has(v)||t.has(v+".kerf");for(let[v,M]of t){if(!v.endsWith(".kerf"))continue;let o;try{o=h1(M.toString("utf8"),`${e}/${v}`).program}catch(m){s.push(`${v}: ${m.message}`);continue}for(let m of U(o)){let p=m.path.split("/")[0];Object.prototype.hasOwnProperty.call(i1,m.path)||p===e&&h(m.path.slice(e.length+1))||m.path.includes("/")&&S(l.libraries,p)!==void 0||s.push(`${v}, line ${m.line}: <${m.path}> will not be found once the library is installed`+(h(m.path)?`. Write <${e}/${m.path}> for the library's own file.`:"."))}}[...t.keys()].some(v=>v.endsWith(".kerf"))||s.push("There are no .kerf files to pack"),s.length&&d(s.join(`
3023
- `));let i=[...t.keys()].sort().map(v=>[`${e}/${v}`,t.get(v)]),r=c??f(a,`${e}-${n}.tar.gz`);return _(r,I1(i)),{file:r,name:e,version:n,files:t.size,integrity:F(t)}}export{A as FOLDER,k as LOCK,W as LibraryError,u as MANIFEST,X1 as add,J1 as check,f1 as findProject,j1 as install,Q1 as installedPaths,F as integrity,V1 as libraryFile,l0 as pack,d1 as readLock,H as readManifest,c0 as remove,Y1 as resolver};
4243
+ `};var P="0.3";var M="kerf.json",A="kerf.lock",L="kerf_libraries",q=20<<20,R=2e3,X=/^[a-z0-9][a-z0-9_-]{0,63}$/,C1=/^\d+\.\d+\.\d+(?:-[0-9A-Za-z.-]+)?$/,H1=/^(readme|licen[cs]e|copying|notice|changelog)(\.[a-z]+)?$/i,N=class extends Error{},c1=l=>{try{return d1(l).isFile()}catch{return!1}},C=l=>{try{return d1(l).isDirectory()}catch{return!1}},S=(l,c)=>l&&Object.prototype.hasOwnProperty.call(l,c)?l[c]:void 0,f=l=>{throw new N(l)};function h1(l,c){return(typeof l!="string"||!X.test(l))&&f(`${c} "${l}" is not a library name: use lowercase letters, digits, - and _`),l==="kerf"&&f(`${c}: "kerf" is the standard library's name`),l}function a1(l,c){(!l||typeof l!="object"||Array.isArray(l))&&f(`${c} must hold a JSON object`);let a=l;for(let e of["name","version","description","license","language"])a[e]!==void 0&&typeof a[e]!="string"&&f(`${c}: "${e}" must be a string`);a.name!==void 0&&h1(a.name,`${c}: name`),a.version!==void 0&&!C1.test(a.version)&&f(`${c}: "version" must look like 1.2.0, not "${a.version}"`),a.language!==void 0&&!/^\d+\.\d+$/.test(a.language)&&f(`${c}: "language" must look like ${P}, not "${a.language}"`),a.sheet!==void 0&&!(Array.isArray(a.sheet)&&a.sheet.length===2&&a.sheet.every(e=>typeof e=="number"&&Number.isFinite(e)&&e>0))&&f(`${c}: "sheet" must be [width, height] in mm, like [600, 400]`);let n=a.libraries??{};(!n||typeof n!="object"||Array.isArray(n))&&f(`${c}: "libraries" must be an object of name: source`);for(let[e,t]of Object.entries(n))h1(e,`${c}: library`),typeof t!="string"&&f(`${c}: the source of ${e} must be a string`);return{...a,libraries:{...n}}}function l1(l,c){let a;try{a=T(l,"utf8")}catch{return f(`${c} was not found`)}try{return JSON.parse(a)}catch(n){return f(`${c} is not valid JSON: ${n.message}`)}}function H(l,c=M){return a1(l1(v(l,M),c),c)}function f1(l){if(!I(v(l,A)))return;let c=l1(v(l,A),A);(c?.lockVersion!==1||!c.libraries||typeof c.libraries!="object")&&f(`${A} is not a kerf.lock this kerf can read. Delete it and run kerf install.`);for(let[a,n]of Object.entries(c.libraries))(!n||["source","resolved","integrity"].some(e=>typeof n[e]!="string"))&&f(`${A}: the entry for ${a} is damaged. Remove it and run kerf install.`);return c}function v1(l){for(let c=O(l);;){if(c1(v(c,M)))return c;let a=J(c);if(a===c)return;c=a}}function e1(l){try{return H(l).name}catch{return}}function V1(l,c,a=c1){let n=(s,i)=>[v(s,i),v(s,i+".kerf")].find(r=>a(r));if(Z(c))return[c,c+".kerf"].find(s=>a(s));let e=c.indexOf("/"),t=e>0?v1(l):void 0;if(t){let s=c.slice(0,e);if(s===e1(t))return n(t,c.slice(e+1));if(C(v(t,L,s)))return n(v(t,L),c)}return n(l,c)}function Y1(l){let c=J(O(l));return a=>{let n=V1(c,a);return n===void 0?void 0:T(n,"utf8")}}function Q1(l,c=200){let a=v1(l);if(!a)return[];let n=[],e=(i,r)=>{for(let o of[...u1(i,3)].sort()){if(n.length>=c)return;o.endsWith(".kerf")&&n.push(r+o.slice(0,-5))}},t=e1(a);t&&e(a,t+"/");let s=v(a,L);if(C(s))for(let i of Y(s).sort())X.test(i)&&C(v(s,i))&&e(v(s,i),i+"/");return n}function u1(l,c=1/0){let a=[],n=(e,t,s)=>{let i;try{i=Y(e,{withFileTypes:!0})}catch{return}for(let r of i){if(r.name.startsWith(".")||r.name==="node_modules"||r.name===L)continue;let o=t?`${t}/${r.name}`:r.name;r.isDirectory()?s<c&&n(v(e,r.name),o,s+1):r.isFile()&&(a.push(o),a.length>R&&f(`${l} has more than ${R} files`))}};return n(l,"",0),a}function G(l,c=()=>!0){let a=new Map;for(let n of u1(l))c(n)&&a.set(n,T(v(l,...n.split("/"))));return a}var n1=l=>l===M||l.endsWith(".kerf")||!l.includes("/")&&H1.test(l);function F(l){let c=b1("sha256");for(let a of[...l.keys()].sort()){let n=Buffer.from(l.get(a).toString("utf8").replace(/\r\n/g,`
4244
+ `));c.update(`${a}\0${n.length}\0`),c.update(n)}return"sha256-"+c.digest("base64")}function o1(l){return l.kind==="folder"?"folder:"+(process.platform==="win32"?l.path.toLowerCase():l.path):l.kind==="github"?`github:${l.owner}/${l.repo}`.toLowerCase()+`@${l.ref}`:l.url}function E(l,c){let a=/^github:([\w.-]+)\/([\w.-]+?)(?:\.git)?(?:@(\S+))?$/.exec(l);if(a)return{kind:"github",owner:a[1],repo:a[2],ref:a[3]??"HEAD"};if(/^https?:\/\//i.test(l)){let e;try{e=new URL(l)}catch{return f(`${l} is not a link`)}return e.protocol==="http:"&&!["localhost","127.0.0.1","[::1]"].includes(e.hostname)&&f(`Use https:// to download ${l}`),{kind:"url",url:l}}let n=l.startsWith("file:")?l.slice(5):l;return n.startsWith("./")||n.startsWith("../")||Z(n)?{kind:"folder",path:O(c,n)}:f(`"${l}" is not a library source. Use github:owner/repo@tag, an https:// link to a .tar.gz, or a folder like ./my-library`)}async function _1(l,c){let a;try{a=await c(l)}catch(i){let r=i;return f(`Could not download ${l}: ${r.cause?.message??r.message}`)}a.ok||f(`Could not download ${l}: HTTP ${a.status}`+(a.status===404?". Check the name and the tag, and that it is public.":""));let n=()=>f(`${l} is larger than ${q>>20} MB`);if(Number(a.headers?.get("content-length"))>q&&n(),!a.body){let i=Buffer.from(await a.arrayBuffer());return i.length>q?n():i}let e=a.body.getReader(),t=[],s=0;for(;;){let{done:i,value:r}=await e.read();if(i||!r)break;s+=r.length,s>q&&(await e.cancel().catch(()=>{}),n()),t.push(r)}return Buffer.concat(t)}function q1(l,c){let a;try{a=L1(l,{maxOutputLength:5*q})}catch{return f(`${c} is not a .tar.gz file`)}let n=new Map,e,t={},s;for(let i=0;i+512<=a.length;){let r=a.subarray(i,i+512);if(r.every(g=>g===0))break;let o=(g,y)=>{let w=r.subarray(g,g+y),V=w.indexOf(0);return w.subarray(0,V<0?y:V).toString("utf8")},d=parseInt(o(124,12).trim()||"0",8);d>=0||f(`${c} is damaged`);let u=o(156,1)||"0",h=a.subarray(i+512,i+512+d);if(i+=512+Math.ceil(d/512)*512,u==="x"||u==="g"){let g=x1(h);u==="g"?e=g.comment??e:t=g;continue}if(u==="L"){s=h.toString("utf8").replace(/\0+$/,"");continue}let m=o(345,155),z=t.path??s??(m?m+"/":"")+o(0,100);t={},s=void 0,(u==="0"||u==="7")&&n.set(z,Buffer.from(h)),n.size>R&&f(`${c} has more than ${R} files`)}return{files:n,commit:e}}function x1(l){let c={};for(let a=0;a<l.length;){let n=l.indexOf(32,a),e=parseInt(l.subarray(a,n).toString(),10);if(!(e>0)||n<0)break;let t=l.subarray(n+1,a+e-1).toString("utf8"),s=t.indexOf("=");s>0&&(c[t.slice(0,s)]=t.slice(s+1)),a+=e}return c}function m1(l,c){let a=new Map;for(let[t,s]of l){let i=t.replace(/^\.\//,""),r=i.split("/");(Z(i)||i.includes("\\")||i.includes(":")||r.some(o=>o===".."||o===""))&&f(`${c} holds a file outside its folder: ${t}`),a.set(i,s)}let n="";if(!a.has(M)){let t=new Set([...a.keys()].map(s=>s.split("/")[0]));t.size===1&&(n=[...t][0]+"/")}let e=new Map;for(let[t,s]of a){if(!t.startsWith(n))continue;let i=t.slice(n.length);i.split("/").some(r=>r.startsWith(".")||r===L||r==="node_modules")||n1(i)&&e.set(i,s)}return e.has(M)||f(`${c} has no kerf.json at its top. Is it a KerfScript library?`),e}var S1=(l,c)=>{let[a,n]=l.split(".").map(Number),[e,t]=c.split(".").map(Number);return a>e||a===e&&n>t};async function p1(l,c,a,n,e){let t=E(l,c),s,i;if(t.kind==="folder")c1(v(t.path,M))||f(`${l}: no kerf.json in ${t.path}. Is it a KerfScript library?`),s=m1(G(t.path,n1),l),i=y1(a,t.path).split(k1).join("/")||".",!i.startsWith(".")&&!Z(i)&&(i="./"+i);else{let o=t.kind==="github"?`https://github.com/${t.owner}/${t.repo}/archive/${t.ref}.tar.gz`:t.url,d=e.get(o)??await _1(o,n);e.set(o,d);let u=q1(d,l);s=m1(u.files,l),i=t.kind==="github"&&/^[0-9a-f]{40}$/.test(u.commit??"")?`https://github.com/${t.owner}/${t.repo}/archive/${u.commit}.tar.gz`:o}let r=a1(JSON.parse(s.get(M).toString("utf8")),`the kerf.json of ${l}`);return r.name||f(`${l}: its kerf.json has no "name", so it is not a library`),r.language&&S1(r.language,P)&&f(`${r.name} needs KerfScript language ${r.language} or later, and this kerf has ${P}. Update kerf.`),{manifest:r,files:s,resolved:i,integrity:F(s)}}function T1(l,c){Q(l,{recursive:!0,force:!0});for(let[a,n]of c){let e=v(l,...a.split("/"));w1(J(e),{recursive:!0}),x(e,n)}}var j1=l=>{let c=[...l].sort(([a],[n])=>a<n?-1:1);return JSON.stringify({lockVersion:1,libraries:Object.fromEntries(c)},null,2)+`
4245
+ `};async function $1(l,c={}){let a=c.fetch??globalThis.fetch,n=c.log??(()=>{}),e=c.cache??new Map,t=H(l),s=f1(l),i=new Map,r=Object.entries(t.libraries).map(([h,m])=>({name:h,source:m,base:l,from:M})),o=v(l,L);for(;r.length;){let{name:h,source:m,base:z,from:g}=r.shift(),y=E(m,z),w=y.kind==="folder",V=w?`${m} (${y.path})`:m,j=i.get(h);if(j){j.at!==o1(y)&&!S(t.libraries,h)&&f(`${g} uses ${h} from ${V}, and ${j.from} uses it from ${j.shown}. Add ${h} to kerf.json with the source to use.`);continue}let B=S(s?.libraries,h),b=B?.source===m&&(!w||O(l,B.resolved)===y.path)?B:void 0;c.frozen&&!b&&f(`kerf.lock does not pin ${h} from ${m}. Run kerf install without --frozen.`);let $=v(o,h),_;if(b&&!w&&C($)&&F(G($))===b.integrity)_=b;else{let p=await p1(b&&!w?b.resolved:m,w?z:l,l,a,e);p.manifest.name!==h&&f(`${m} is the library "${p.manifest.name}", so ${g} must call it ${p.manifest.name}, not ${h}`),b&&p.integrity!==b.integrity&&(!w||c.frozen)&&f(w?`${h} in ${m} changed since kerf.lock pinned it. Run kerf install without --frozen.`:`${h} from ${b.resolved} no longer matches kerf.lock. If you trust the change, remove ${h} from kerf.lock and run kerf install again.`),T1($,p.files),_={source:m,...p.manifest.version?{version:p.manifest.version}:{},resolved:p.resolved,integrity:p.integrity},(!b||b.integrity!==p.integrity||!w)&&n(`${b?"Restored":"Installed"} ${h}${_.version?" "+_.version:""} from ${m}`)}i.set(h,{entry:_,at:o1(y),shown:V,from:g});let t1=y.kind==="folder"?y.path:void 0;for(let[p,K]of Object.entries(H($,`${L}/${h}/${M}`).libraries))E(K,l).kind==="folder"&&!t1&&f(`${h} uses ${p} from the folder ${K}: a published library needs github: or https: sources`),r.push({name:p,source:K,base:t1??l,from:h})}let d=j1(new Map([...i].map(([h,m])=>[h,m.entry]))),u=I(v(l,A))?T(v(l,A),"utf8"):"";if(c.frozen&&d!==u.replace(/\r\n/g,`
4246
+ `)&&f("kerf.lock is out of date. Run kerf install without --frozen."),C(o))for(let h of Y(o,{withFileTypes:!0}))h.isDirectory()&&X.test(h.name)&&!i.has(h.name)&&(Q(v(o,h.name),{recursive:!0,force:!0}),n(`Removed ${h.name}`));return d!==u.replace(/\r\n/g,`
4247
+ `)&&x(v(l,A),d),JSON.parse(d)}function J1(l){let c=H(l),a=f1(l),n=Object.keys(c.libraries);if(!a)return n.length?["kerf.lock is missing. Run kerf install."]:[];let e=[],t=new Set,s=[...n];for(;s.length;){let i=s.shift();if(t.has(i))continue;t.add(i);let r=S(a.libraries,i);if(!r){e.push(`${i} is not in kerf.lock. Run kerf install.`);continue}n.includes(i)&&r.source!==c.libraries[i]&&e.push(`kerf.json takes ${i} from ${c.libraries[i]}, and kerf.lock from ${r.source}. Run kerf install.`);let o=v(l,L,i);if(!C(o)){e.push(`${i} is not in ${L}. Run kerf install.`);continue}F(G(o))!==r.integrity&&e.push(`The files in ${L}/${i} differ from kerf.lock. Run kerf install.`);try{s.push(...Object.keys(H(o).libraries))}catch(d){e.push(d.message)}}for(let i of Object.keys(a.libraries))t.has(i)||e.push(`kerf.lock pins ${i}, which nothing uses any more.`);return e}function P1(l,c){let a=v(l,M),n=I(a)?l1(a,M):{};a1(n,M);let e={...n.libraries??{}};return c(e),n.libraries=e,{file:a,before:I(a)?T(a,"utf8"):void 0,raw:n}}async function M1(l,c,a){let{file:n,before:e,raw:t}=P1(l,c);x(n,JSON.stringify(t,null,2)+`
4248
+ `);try{return await $1(l,a)}catch(s){throw e===void 0?Q(n,{force:!0}):x(n,e),s}}async function X1(l,c,a={}){let n=new Map,t=(await p1(c,l,l,a.fetch??globalThis.fetch,n)).manifest.name;t===e1(l)&&f(`This project is the library ${t}; it cannot use itself`);let s=await M1(l,i=>void(i[t]=c),{...a,cache:n});return{name:t,lock:s}}async function c0(l,c,a={}){return M1(l,n=>{S(n,c)===void 0&&f(`kerf.json has no library named ${c}`),delete n[c]},a)}function U(l,c=[]){if(Array.isArray(l))for(let a of l)U(a,c);else if(l&&typeof l=="object"){let a=l;if(a.kind==="use"&&typeof a.path=="string")c.push({path:a.path,line:a.pos.line});else for(let n of Object.values(a))U(n,c)}return c}function I1(l){let c=[];for(let[a,n]of l){let e=Buffer.alloc(512),t=a,s="";if(Buffer.byteLength(t)>100){let r=a.lastIndexOf("/",155);(r<0||Buffer.byteLength(a.slice(r+1))>100)&&f(`${a}: the path is too long to pack`),s=a.slice(0,r),t=a.slice(r+1)}e.write(t,0,100),e.write("0000644\0",100),e.write("0000000\0",108),e.write("0000000\0",116),e.write(n.length.toString(8).padStart(11,"0")+"\0",124),e.write("00000000000\0",136),e.fill(32,148,156),e.write("0",156),e.write("ustar\0",257),e.write("00",263),e.write(s,345,155);let i=0;for(let r of e)i+=r;e.write(i.toString(8).padStart(6,"0")+"\0 ",148),c.push(e,n,Buffer.alloc((512-n.length%512)%512))}return c.push(Buffer.alloc(1024)),A1(Buffer.concat(c),{level:9})}function a0(l,c){let a=H(l),n=a.name??f('kerf.json needs a "name" to pack a library'),e=a.version??f('kerf.json needs a "version", like 1.0.0'),t=G(l,n1),s=[];for(let[d,u]of Object.entries(a.libraries))E(u,l).kind==="folder"&&s.push(`kerf.json: ${d} comes from a folder; a published library needs github: or https: sources`);let i=d=>t.has(d)||t.has(d+".kerf");for(let[d,u]of t){if(!d.endsWith(".kerf"))continue;let h;try{h=i1(u.toString("utf8"),`${n}/${d}`).program}catch(m){s.push(`${d}: ${m.message}`);continue}for(let m of U(h)){let z=m.path.split("/")[0];Object.prototype.hasOwnProperty.call(r1,m.path)||z===n&&i(m.path.slice(n.length+1))||m.path.includes("/")&&S(a.libraries,z)!==void 0||s.push(`${d}, line ${m.line}: <${m.path}> will not be found once the library is installed`+(i(m.path)?`. Write <${n}/${m.path}> for the library's own file.`:"."))}}[...t.keys()].some(d=>d.endsWith(".kerf"))||s.push("There are no .kerf files to pack"),s.length&&f(s.join(`
4249
+ `));let r=[...t.keys()].sort().map(d=>[`${n}/${d}`,t.get(d)]),o=c??v(l,`${n}-${e}.tar.gz`);return x(o,I1(r)),{file:o,name:n,version:e,files:t.size,integrity:F(t)}}export{L as FOLDER,A as LOCK,N as LibraryError,M as MANIFEST,X1 as add,J1 as check,v1 as findProject,$1 as install,Q1 as installedPaths,F as integrity,V1 as libraryFile,a0 as pack,f1 as readLock,H as readManifest,c0 as remove,Y1 as resolver};