@mylasertools/kerfscript 0.7.0 → 0.9.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +103 -0
- package/LANGUAGE.md +201 -84
- package/README.md +2 -2
- package/dist/assembly.d.cts +2 -1
- package/dist/assembly.d.ts +2 -1
- package/dist/ast.d.cts +6 -0
- package/dist/ast.d.ts +6 -0
- package/dist/bores.d.cts +5 -0
- package/dist/bores.d.ts +5 -0
- package/dist/cli.js +2098 -285
- package/dist/customizer.d.cts +1 -0
- package/dist/customizer.d.ts +1 -0
- package/dist/evaluator.d.cts +9 -0
- package/dist/evaluator.d.ts +9 -0
- package/dist/functions.d.cts +2 -0
- package/dist/functions.d.ts +2 -0
- package/dist/geometry.d.cts +11 -0
- package/dist/geometry.d.ts +11 -0
- package/dist/halving.d.cts +8 -0
- package/dist/halving.d.ts +8 -0
- package/dist/highlight.cjs +2 -1
- package/dist/highlight.js +2 -1
- package/dist/index.cjs +474 -58
- package/dist/index.d.cts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +474 -58
- package/dist/language.cjs +462 -46
- package/dist/language.js +462 -46
- package/dist/libraries.cjs +435 -19
- package/dist/libraries.js +435 -19
- package/dist/plot.d.cts +16 -0
- package/dist/plot.d.ts +16 -0
- package/dist/signatures.cjs +189 -5
- package/dist/signatures.js +189 -5
- package/dist/verify/solids.d.cts +2 -1
- package/dist/verify/solids.d.ts +2 -1
- package/dist/verify/types.d.cts +2 -0
- package/dist/verify/types.d.ts +2 -0
- package/docs/cli.md +1 -0
- package/docs/compatibility.md +0 -8
- package/docs/customizer.md +18 -0
- package/docs/library.md +248 -5
- package/docs/parts-and-sheets.md +86 -18
- package/docs/versions.md +2 -2
- 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
|
|
3
|
-
`&&(t++,
|
|
2
|
+
import{createHash as b1}from"node:crypto";import{existsSync as I,mkdirSync as w1,readdirSync as Q,readFileSync as T,rmSync as J,statSync as m1,writeFileSync as _}from"node:fs";import{dirname as Y,isAbsolute as Z,join as M,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=o=>{for(let m=0;m<o;m++)a[n]===`
|
|
3
|
+
`&&(t++,s=n+1),n++};for(;n<a.length;){let o=a[n];if(o===" "||o===" "||o==="\r"||o===`
|
|
4
4
|
`){i(1);continue}if(o==="/"&&a[n+1]==="/"){let r=a.indexOf(`
|
|
5
5
|
`,n),v=r<0?a.length:r,p=/^[ \t]*$/.test(a.slice(a.lastIndexOf(`
|
|
6
|
-
`,n-1)+1,n));e.push({text:a.slice(n+2,v).trim(),line:t,block:!1,own:p,start:n,end:v}),n=v;continue}if(o==="/"&&a[n+1]==="*"){let r=
|
|
7
|
-
`;else if(v==="t")r+=" ";else if(v==="u"){let p=a.slice(n+2,n+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new
|
|
8
|
-
`)throw new
|
|
6
|
+
`,n-1)+1,n));e.push({text:a.slice(n+2,v).trim(),line:t,block:!1,own:p,start:n,end:v}),n=v;continue}if(o==="/"&&a[n+1]==="*"){let r=h(),v=a.indexOf("*/",n+2);if(v<0)throw new y("Unclosed block comment",r);e.push({text:a.slice(n+2,v).trim(),line:r.line,block:!0,own:!0,start:n,end:v+2}),i(v+2-n);continue}let m=h();if(/[0-9]/.test(o)||o==="."&&/[0-9]/.test(a[n+1]??"")){let r=/^(?:\d+\.?\d*|\.\d+)(?:[eE][+-]?\d+)?(?:(?:mm|cm|m|in|ft)(?![A-Za-z0-9_]))?/.exec(a.slice(n));l.push({type:"num",value:r[0],pos:m,end:n+r[0].length}),i(r[0].length);continue}if(/[A-Za-z_$]/.test(o)){let r=/^[A-Za-z_$][A-Za-z0-9_]*/.exec(a.slice(n));l.push({type:"id",value:r[0],pos:m,end:n+r[0].length}),i(r[0].length);continue}if(o==='"'){let r="";for(i(1);n<a.length&&a[n]!=='"';){if(a[n]==="\\"){let v=a[n+1];if(v==="n")r+=`
|
|
7
|
+
`;else if(v==="t")r+=" ";else if(v==="u"){let p=a.slice(n+2,n+6);if(!/^[0-9a-fA-F]{4}$/.test(p))throw new y("Bad \\u escape",h());r+=String.fromCharCode(parseInt(p,16)),i(4)}else r+=v;i(2);continue}if(a[n]===`
|
|
8
|
+
`)throw new y("Unclosed string",m);r+=a[n],i(1)}if(n>=a.length)throw new y("Unclosed string",m);i(1),l.push({type:"str",value:r,pos:m,end:n});continue}if(o==="<"&&/^<[A-Za-z0-9_./-]+>/.test(a.slice(n))){let r=l[l.length-1];if(r&&r.type==="id"&&(r.value==="use"||r.value==="include")){let v=/^<([A-Za-z0-9_./-]+)>/.exec(a.slice(n));l.push({type:"str",value:v[1],pos:m,end:n+v[0].length}),i(v[0].length);continue}}let z=g1.find(r=>a.startsWith(r,n));if(!z)throw new y(`Unexpected character "${o}"`,m);l.push({type:"punct",value:z,pos:m,end:n+z.length}),i(z.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(),o=this.expectP(";").pos.offset;return[{kind:"assign",name:s,value:i,span:[h,o],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.
|
|
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.
|
|
@@ -97,6 +97,62 @@ module joint_test(kerfs = [0.1, 0.15, 0.2], size = [40, 20], finger = undef, lab
|
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
}
|
|
100
|
+
`,"kerf/cones":`// kerf/cones: cones and cut-off cones cut flat, to roll up from thin sheet.
|
|
101
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
102
|
+
//
|
|
103
|
+
// A cone rolled from paper, card, veneer or thin plastic is a ring sector
|
|
104
|
+
// when flat. Gramophone horns, lampshades, funnels and party hats all start
|
|
105
|
+
// as one. The sector's apex is at the origin and it opens from +x
|
|
106
|
+
// anticlockwise; the glue tab runs along its far edge.
|
|
107
|
+
|
|
108
|
+
// The flat pattern of a cone of radius r1 at one end, r2 at the other and h
|
|
109
|
+
// high: [outer radius, inner radius, angle in degrees, slant length]. A
|
|
110
|
+
// cylinder (r1 == r2) has no apex: it gives [undef, undef, 0, h] and is a
|
|
111
|
+
// rectangle 2 * PI * r1 wide.
|
|
112
|
+
function cone_pattern(r1, r2, h) =
|
|
113
|
+
let (
|
|
114
|
+
big = max(r1, r2),
|
|
115
|
+
small = min(r1, r2),
|
|
116
|
+
s = sqrt(h * h + pow(big - small, 2))
|
|
117
|
+
)
|
|
118
|
+
big == small ? [undef, undef, 0, h]
|
|
119
|
+
: [s * big / (big - small), s * small / (big - small), 360 * (big - small) / s, s];
|
|
120
|
+
|
|
121
|
+
// A cone or cut-off cone cut flat: rolled up so the far edge lies on the
|
|
122
|
+
// glue tab, it has radius r1 at one end, r2 at the other, and is h high.
|
|
123
|
+
// \`tab\` adds a glue tab that wide along the far edge, its fold scored; a
|
|
124
|
+
// cylinder becomes a rectangle with the tab on its right.
|
|
125
|
+
module cone_flat(r1, r2, h, tab = 0, steps = 0) {
|
|
126
|
+
p = cone_pattern(r1, r2, h);
|
|
127
|
+
if (is_undef(p[0])) {
|
|
128
|
+
w = 2 * PI * r1;
|
|
129
|
+
rect([w, h]);
|
|
130
|
+
if (tab > 0) {
|
|
131
|
+
polygon([[w, 0], [w + tab, min(tab, h / 4)], [w + tab, h - min(tab, h / 4)], [w, h]]);
|
|
132
|
+
score() line([w, 0], [w, h]);
|
|
133
|
+
}
|
|
134
|
+
} else {
|
|
135
|
+
a = p[2];
|
|
136
|
+
n = steps > 0 ? steps : max(8, ceil(a / 3));
|
|
137
|
+
arc_pts = function(r) [for (i = [0:n]) [r * cos(a * i / n), r * sin(a * i / n)]];
|
|
138
|
+
polygon(concat(arc_pts(p[0]), p[1] > 0 ? reverse(arc_pts(p[1])) : [[0, 0]]));
|
|
139
|
+
if (tab > 0) {
|
|
140
|
+
// The tab beyond the far edge, its ends cut in so it hides when rolled
|
|
141
|
+
ux = cos(a);
|
|
142
|
+
uy = sin(a);
|
|
143
|
+
nx = -uy;
|
|
144
|
+
ny = ux;
|
|
145
|
+
c = min(tab, p[3] / 4);
|
|
146
|
+
polygon([
|
|
147
|
+
[p[1] * ux, p[1] * uy],
|
|
148
|
+
[p[0] * ux, p[0] * uy],
|
|
149
|
+
[(p[0] - c) * ux + tab * nx, (p[0] - c) * uy + tab * ny],
|
|
150
|
+
[(p[1] + (p[1] > 0 ? c : tab)) * ux + tab * nx, (p[1] + (p[1] > 0 ? c : tab)) * uy + tab * ny],
|
|
151
|
+
]);
|
|
152
|
+
score() line([p[1] * ux, p[1] * uy], [p[0] * ux, p[0] * uy]);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
}
|
|
100
156
|
`,"kerf/dividers":`// kerf/dividers: dividers that slot into each other like an egg crate.
|
|
101
157
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
102
158
|
|
|
@@ -219,6 +275,70 @@ module vents(size, slot = 3, pitch = 6) {
|
|
|
219
275
|
translate([0, ends]) circle(d = slot, $fn = 24);
|
|
220
276
|
}
|
|
221
277
|
}
|
|
278
|
+
`,"kerf/fit":`// kerf/fit: drawings scaled to a size and placed by a point of their box.
|
|
279
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
280
|
+
//
|
|
281
|
+
// For any drawing whose size you don't know beforehand: an imported SVG
|
|
282
|
+
// path, a silhouette, a symbol, a line of text. Each measures its children
|
|
283
|
+
// and moves or scales them, keeping their layers, so cut, score and
|
|
284
|
+
// engrave stay together. They are for drawings, not for parts: scaling a
|
|
285
|
+
// part would scale its joints and leave its thickness.
|
|
286
|
+
|
|
287
|
+
// The fractions of a box an anchor names, [0, 0] the bottom left and
|
|
288
|
+
// [1, 1] the top right: "center", "left", "right", "top", "bottom",
|
|
289
|
+
// "top-left", "top-right", "bottom-left", "bottom-right", or [fx, fy]
|
|
290
|
+
function anchor_point(anchor) =
|
|
291
|
+
is_list(anchor) ? anchor
|
|
292
|
+
: let (
|
|
293
|
+
a = lower(anchor),
|
|
294
|
+
fx = contains(a, "left") ? 0 : contains(a, "right") ? 1 : 0.5,
|
|
295
|
+
fy = contains(a, "bottom") ? 0 : contains(a, "top") ? 1 : 0.5
|
|
296
|
+
)
|
|
297
|
+
assert(
|
|
298
|
+
len([for (w = split(a, "-")) if (w != "center" && w != "left" && w != "right" && w != "top" && w != "bottom") w]) == 0,
|
|
299
|
+
str("Unknown anchor \\"", anchor, "\\": use center, left, right, top, bottom or a corner such as top-left")
|
|
300
|
+
)
|
|
301
|
+
[fx, fy];
|
|
302
|
+
|
|
303
|
+
// The children moved so the point of their box that \`anchor\` names is at
|
|
304
|
+
// the origin: align("bottom-left") puts their box's corner there, and
|
|
305
|
+
// align() centres them.
|
|
306
|
+
module align(anchor = "center") {
|
|
307
|
+
f = anchor_point(anchor);
|
|
308
|
+
measure() {
|
|
309
|
+
children();
|
|
310
|
+
if (!is_undef($bounds))
|
|
311
|
+
translate([-($bounds[0] + f[0] * ($bounds[2] - $bounds[0])), -($bounds[1] + f[1] * ($bounds[3] - $bounds[1]))])
|
|
312
|
+
children();
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
// The children scaled to \`size\` = [w, h] (or one number for a square):
|
|
317
|
+
// mode = "contain" keeps their proportions and fits them inside, "stretch"
|
|
318
|
+
// fills the size exactly. A drawing with no width or no height (a line)
|
|
319
|
+
// is scaled by the other side. They are then placed by \`anchor\` as
|
|
320
|
+
// align() does, the box's bottom left at the origin by default.
|
|
321
|
+
module fit(size, mode = "contain", anchor = "bottom-left") {
|
|
322
|
+
s = is_list(size) ? size : [size, size];
|
|
323
|
+
assert(s[0] > 0 && s[1] > 0, "fit(): size must be more than 0");
|
|
324
|
+
assert(mode == "contain" || mode == "stretch", "fit(): mode is \\"contain\\" or \\"stretch\\"");
|
|
325
|
+
f = anchor_point(anchor);
|
|
326
|
+
measure() {
|
|
327
|
+
children();
|
|
328
|
+
if (!is_undef($bounds)) {
|
|
329
|
+
w = $bounds[2] - $bounds[0];
|
|
330
|
+
h = $bounds[3] - $bounds[1];
|
|
331
|
+
kx = w > 0 ? s[0] / w : undef;
|
|
332
|
+
ky = h > 0 ? s[1] / h : undef;
|
|
333
|
+
k = mode == "stretch"
|
|
334
|
+
? [is_undef(kx) ? 1 : kx, is_undef(ky) ? 1 : ky]
|
|
335
|
+
: let (one = is_undef(kx) ? ky : is_undef(ky) ? kx : min(kx, ky)) [one, one];
|
|
336
|
+
if (!is_undef(k[0]))
|
|
337
|
+
translate([-f[0] * w * k[0], -f[1] * h * k[1]])
|
|
338
|
+
scale(k) translate([-$bounds[0], -$bounds[1]]) children();
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
}
|
|
222
342
|
`,"kerf/gears":`// kerf/gears: gears, racks, lantern gears and cams for moving models.
|
|
223
343
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
224
344
|
//
|
|
@@ -370,6 +490,209 @@ module tappets(n, r, w = 10, hub = 14, bore = 6, square = false) {
|
|
|
370
490
|
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
371
491
|
}
|
|
372
492
|
}
|
|
493
|
+
|
|
494
|
+
// Cams from a lift curve. The follower rides on the cam's top (+y) and
|
|
495
|
+
// moves straight up and down; turned anticlockwise by \`a\` degrees (rotate =
|
|
496
|
+
// [0, 0, a]), the cam lifts it lift(a) above the base circle. \`lift\` is a
|
|
497
|
+
// function of the angle, 0 to 360, that comes back to where it started.
|
|
498
|
+
|
|
499
|
+
// A smooth rise of \`height\` from angle a0 to a1 (cycloidal: it starts and
|
|
500
|
+
// stops gently): 0 before a0, height after a1. Add and take away rises to
|
|
501
|
+
// make dwells, rises and falls: two pecks then a rest is
|
|
502
|
+
// function(a) cam_rise(a, 0, 40, 8) - cam_rise(a, 40, 80, 8) + cam_rise(a, 100, 140, 8) - cam_rise(a, 140, 180, 8).
|
|
503
|
+
function cam_rise(a, a0, a1, height) =
|
|
504
|
+
a <= a0 ? 0
|
|
505
|
+
: a >= a1 ? height
|
|
506
|
+
: let (u = (a - a0) / (a1 - a0)) height * (u - sin(360 * u) / (2 * PI));
|
|
507
|
+
|
|
508
|
+
// The cam's pitch curve: where the follower's tip (or its roller's centre)
|
|
509
|
+
// sits, in the cam's own turn, \`steps\` points round
|
|
510
|
+
function cam_pitch(lift, base_r, roller_d = 0, steps = 180) =
|
|
511
|
+
[for (i = [0:steps - 1])
|
|
512
|
+
let (f = i * 360 / steps, a = (450 - f) % 360, r = base_r + roller_d / 2 + lift(a))
|
|
513
|
+
[r * cos(f), r * sin(f)]];
|
|
514
|
+
|
|
515
|
+
// How high the follower's tip (or its roller's centre) is above the cam's
|
|
516
|
+
// axle when the cam is turned to \`angle\`, to place the follower
|
|
517
|
+
function cam_follower(lift, base_r, angle, roller_d = 0) =
|
|
518
|
+
base_r + roller_d / 2 + lift(((angle % 360) + 360) % 360);
|
|
519
|
+
|
|
520
|
+
// The steepest pressure angle over a turn, in degrees: how hard the cam
|
|
521
|
+
// pushes the follower sideways. Keep it under about 30, by a bigger base
|
|
522
|
+
// circle or a longer rise.
|
|
523
|
+
function cam_pressure(lift, base_r, roller_d = 0, steps = 360) =
|
|
524
|
+
max([for (i = [0:steps - 1])
|
|
525
|
+
let (
|
|
526
|
+
a = i * 360 / steps,
|
|
527
|
+
r = base_r + roller_d / 2 + lift(a),
|
|
528
|
+
slope = (lift((a + 0.5) % 360) - lift((a + 359.5) % 360)) / (PI / 180)
|
|
529
|
+
)
|
|
530
|
+
atan(abs(slope) / r)]);
|
|
531
|
+
|
|
532
|
+
// A cam that lifts a follower lift(a) at angle a, with a hole for its
|
|
533
|
+
// axle. A "knife" follower rides the pitch curve itself; a "roller" one of
|
|
534
|
+
// diameter roller_d rolls on a profile inside it. Check cam_pressure().
|
|
535
|
+
module cam(lift, base_r, follower = "knife", roller_d = 0, bore = 6, steps = 180, square = false) {
|
|
536
|
+
assert(follower == "knife" || follower == "roller", "follower must be \\"knife\\" or \\"roller\\"");
|
|
537
|
+
assert(follower == "knife" || roller_d > 0, "a roller follower needs roller_d");
|
|
538
|
+
difference() {
|
|
539
|
+
if (follower == "roller") offset(r = -roller_d / 2) polygon(cam_pitch(lift, base_r, roller_d, steps));
|
|
540
|
+
else polygon(cam_pitch(lift, base_r, 0, steps));
|
|
541
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
542
|
+
}
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
// A Geneva drive: a driver turning all the time steps a wheel of \`slots\`
|
|
546
|
+
// slots on by one slot each turn, and locks it between steps. The driver's
|
|
547
|
+
// axle is at the origin and the wheel's at [distance, 0]. Cut the wheel and
|
|
548
|
+
// the locking disc from the same sheet, side by side in one plane, and the
|
|
549
|
+
// crank above them; a dowel pin of pin_d through the crank's outer hole
|
|
550
|
+
// runs in the wheel's slots.
|
|
551
|
+
|
|
552
|
+
// The radius of the circle the driver's pin turns on
|
|
553
|
+
function geneva_pin_radius(slots, distance) = distance * sin(180 / slots);
|
|
554
|
+
// The wheel's outer radius
|
|
555
|
+
function geneva_wheel_radius(slots, distance, pin_d) =
|
|
556
|
+
sqrt(pow(distance * cos(180 / slots), 2) + pow(pin_d / 2, 2));
|
|
557
|
+
// The locking disc's radius
|
|
558
|
+
function geneva_lock_radius(slots, distance, pin_d) = geneva_pin_radius(slots, distance) - pin_d;
|
|
559
|
+
|
|
560
|
+
// How far the wheel has turned when the driver has turned \`angle\`
|
|
561
|
+
// anticlockwise from its pin pointing at the wheel: it turns clockwise,
|
|
562
|
+
// 360 / slots each turn of the driver, and stands still between steps
|
|
563
|
+
function geneva_turn(slots, distance, angle) =
|
|
564
|
+
let (
|
|
565
|
+
k = floor((angle + 180) / 360),
|
|
566
|
+
t = angle - 360 * k,
|
|
567
|
+
rc = geneva_pin_radius(slots, distance),
|
|
568
|
+
on = 90 - 180 / slots,
|
|
569
|
+
step = abs(t) <= on ? atan2(-rc * sin(t), distance - rc * cos(t))
|
|
570
|
+
: t < 0 ? 180 / slots : -180 / slots
|
|
571
|
+
)
|
|
572
|
+
step - k * 360 / slots;
|
|
573
|
+
|
|
574
|
+
// The wheel, centred on the origin, a slot along -x (towards the driver
|
|
575
|
+
// when geneva_turn() is 0)
|
|
576
|
+
module geneva_wheel(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
|
|
577
|
+
rc = geneva_pin_radius(slots, distance);
|
|
578
|
+
ro = geneva_wheel_radius(slots, distance, pin_d);
|
|
579
|
+
rl = geneva_lock_radius(slots, distance, pin_d);
|
|
580
|
+
w = pin_d + clearance;
|
|
581
|
+
inner = distance - rc - clearance;
|
|
582
|
+
assert(rl > 0, "the pin is too thick to leave a locking disc: make the distance longer or the pin thinner");
|
|
583
|
+
assert(inner - w / 2 > bore / 2 + 3, "the slots reach the axle: use more slots, a longer distance or a smaller bore");
|
|
584
|
+
difference() {
|
|
585
|
+
circle(r = ro);
|
|
586
|
+
for (j = [0:slots - 1]) rotate(180 + j * 360 / slots) {
|
|
587
|
+
hull() {
|
|
588
|
+
translate([inner, 0]) circle(d = w);
|
|
589
|
+
translate([ro + 1, -w / 2]) rect([1, w]);
|
|
590
|
+
}
|
|
591
|
+
// The locking arc between this slot and the next
|
|
592
|
+
rotate(180 / slots) translate([distance, 0]) circle(r = rl + clearance);
|
|
593
|
+
}
|
|
594
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
595
|
+
}
|
|
596
|
+
}
|
|
597
|
+
|
|
598
|
+
// The locking disc that turns with the driver, its relief facing the pin's
|
|
599
|
+
// side (+x): cut away wherever the wheel's rim passes while the pin is in a
|
|
600
|
+
// slot, so the wheel turns then
|
|
601
|
+
module geneva_lock(slots, distance, pin_d = 6, bore = 6, clearance = 0.2, square = false) {
|
|
602
|
+
assert(geneva_lock_radius(slots, distance, pin_d) > bore / 2 + 3, "the locking disc is too small for its axle: make the distance longer, the pin thinner or the bore smaller");
|
|
603
|
+
ro = geneva_wheel_radius(slots, distance, pin_d);
|
|
604
|
+
assert(distance - ro - clearance >= bore / 2 + 2, str("the wheel passes within ", round(10 * (distance - ro - clearance)) / 10, " mm of the driver's axle: use a bore of at most ", floor(20 * (distance - ro - clearance - 2)) / 10, " mm or fewer slots"));
|
|
605
|
+
difference() {
|
|
606
|
+
circle(r = geneva_lock_radius(slots, distance, pin_d));
|
|
607
|
+
// Everywhere the wheel's rim passes while the pin is in a slot
|
|
608
|
+
on = 90 - 180 / slots;
|
|
609
|
+
n = max(2, ceil(2 * on / 3));
|
|
610
|
+
for (i = [0:n - 1]) hull() for (t = [-on + 2 * on * i / n, -on + 2 * on * (i + 1) / n])
|
|
611
|
+
translate([distance * cos(t), distance * sin(t)]) circle(r = ro + clearance);
|
|
612
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
613
|
+
}
|
|
614
|
+
}
|
|
615
|
+
|
|
616
|
+
// The crank above the locking disc that carries the pin, along +x
|
|
617
|
+
module geneva_crank(slots, distance, pin_d = 6, bore = 6, width = 0, square = false) {
|
|
618
|
+
rc = geneva_pin_radius(slots, distance);
|
|
619
|
+
w = width > 0 ? width : max(pin_d, bore) + 8;
|
|
620
|
+
difference() {
|
|
621
|
+
hull() {
|
|
622
|
+
circle(d = w);
|
|
623
|
+
translate([rc, 0]) circle(d = pin_d + 8);
|
|
624
|
+
}
|
|
625
|
+
translate([rc, 0]) circle(d = pin_d);
|
|
626
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
|
|
630
|
+
// A ratchet wheel of \`teeth\` teeth, radius r at their tips, \`depth\` deep,
|
|
631
|
+
// centred on the origin with a hole for its axle. It turns anticlockwise
|
|
632
|
+
// freely; a pawl() stops it turning back.
|
|
633
|
+
module ratchet(teeth, r, depth, bore = 6, square = false) {
|
|
634
|
+
p = 360 / teeth;
|
|
635
|
+
difference() {
|
|
636
|
+
polygon([for (k = [0:teeth - 1], j = [0, 1])
|
|
637
|
+
j == 0 ? [r * cos(k * p), r * sin(k * p)]
|
|
638
|
+
: [(r - depth) * cos((k + 1) * p), (r - depth) * sin((k + 1) * p)]]);
|
|
639
|
+
if (square) rect([bore, bore], center = true); else circle(d = bore);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
|
|
643
|
+
// The angle of the tooth face a pawl rests on, nearest \`at\` degrees
|
|
644
|
+
function pawl_face(teeth, at = 90) = round(at / (360 / teeth)) * 360 / teeth;
|
|
645
|
+
|
|
646
|
+
// How far the pawl leans out from the wheel's edge, in degrees: past the
|
|
647
|
+
// teeth's slope, so it clears them
|
|
648
|
+
function pawl_lean(teeth, r, depth) = atan(depth / ((r - depth / 2) * 2 * PI / teeth)) + 15;
|
|
649
|
+
|
|
650
|
+
// The shortest pawl of this width that clears the teeth: its tip edge,
|
|
651
|
+
// along the tooth face, must end before its far end does
|
|
652
|
+
function pawl_min_length(teeth, r, depth, width = 8) =
|
|
653
|
+
width * (0.5 + tan(pawl_lean(teeth, r, depth))) + 2;
|
|
654
|
+
|
|
655
|
+
// The pawl's outline round the wheel's centre: its tip on the root by the
|
|
656
|
+
// tooth face, its far end, and back along the face. Its pivot is the
|
|
657
|
+
// middle of its far end. A length of 0 picks 0.8 * r, or longer if the
|
|
658
|
+
// pawl must be to clear the teeth; pawl() refuses a length given shorter
|
|
659
|
+
// than pawl_min_length().
|
|
660
|
+
function pawl_points(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
|
|
661
|
+
let (
|
|
662
|
+
f = pawl_face(teeth, at),
|
|
663
|
+
g = pawl_lean(teeth, r, depth),
|
|
664
|
+
shortest = pawl_min_length(teeth, r, depth, width),
|
|
665
|
+
L = length > 0 ? length : max(r * 0.8, shortest),
|
|
666
|
+
n = [cos(f), sin(f)],
|
|
667
|
+
tc = [sin(f), -cos(f)],
|
|
668
|
+
u = cos(g) * tc + sin(g) * n,
|
|
669
|
+
v = cos(g) * n - sin(g) * tc,
|
|
670
|
+
T = (r - depth + clearance) * n + clearance * tc
|
|
671
|
+
)
|
|
672
|
+
[T, T + (L - width / 2) * u, T + (L - width / 2) * u + width * v, T + width / cos(g) * n];
|
|
673
|
+
|
|
674
|
+
// Where a pawl()'s pivot is, round the wheel's centre
|
|
675
|
+
function pawl_pivot(teeth, r, depth, length = 0, width = 8, at = 90, clearance = 0.2) =
|
|
676
|
+
let (p = pawl_points(teeth, r, depth, length, width, at, clearance)) (p[1] + p[2]) / 2;
|
|
677
|
+
|
|
678
|
+
// A pawl for a ratchet() of the same sizes, drawn where it works round
|
|
679
|
+
// the wheel's centre: give it the wheel's placement. Its tip rests against
|
|
680
|
+
// the tooth face nearest \`at\` degrees, and it turns on a pin through the
|
|
681
|
+
// hole at pawl_pivot(). Gravity, a rubber band or a spring wire holds it
|
|
682
|
+
// down on the teeth.
|
|
683
|
+
module pawl(teeth, r, depth, length = 0, width = 8, bore = 3, at = 90, clearance = 0.2) {
|
|
684
|
+
shortest = pawl_min_length(teeth, r, depth, width);
|
|
685
|
+
assert(length == 0 || length >= shortest, str("a pawl ", width, " mm wide must be at least ", ceil(2 * shortest) / 2, " mm long to clear the teeth: make it longer or narrower"));
|
|
686
|
+
p = pawl_points(teeth, r, depth, length, width, at, clearance);
|
|
687
|
+
H = (p[1] + p[2]) / 2;
|
|
688
|
+
difference() {
|
|
689
|
+
union() {
|
|
690
|
+
polygon(p);
|
|
691
|
+
translate(H) circle(d = width);
|
|
692
|
+
}
|
|
693
|
+
translate(H) circle(d = bore);
|
|
694
|
+
}
|
|
695
|
+
}
|
|
373
696
|
`,"kerf/geo":`// kerf/geo: the world's land, for maps, globes and country-shaped pieces.
|
|
374
697
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
375
698
|
// The land data is Natural Earth's 1:110m land (public domain,
|
|
@@ -1000,6 +1323,60 @@ module halved_pair(name, at = [0, 0, 0], cap = undef, feet = [], side_feet = und
|
|
|
1000
1323
|
}
|
|
1001
1324
|
}
|
|
1002
1325
|
}
|
|
1326
|
+
`,"kerf/linkage":`// kerf/linkage: where the joints of a linkage are at a crank angle.
|
|
1327
|
+
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1328
|
+
//
|
|
1329
|
+
// Each function gives the joint points of a linkage drawn flat, so a part
|
|
1330
|
+
// placed on a link and the link's length come from the same numbers. Use
|
|
1331
|
+
// them to place moving parts at a drive angle, and to check a linkage closes
|
|
1332
|
+
// over a whole turn.
|
|
1333
|
+
|
|
1334
|
+
// Where a circle of radius ra round a meets one of radius rb round b: the
|
|
1335
|
+
// point left of the line from a to b (side = 1) or right of it (side = -1).
|
|
1336
|
+
// undef when the circles don't meet: the links are too short or too long.
|
|
1337
|
+
function circle_meet(a, ra, b, rb, side = 1) =
|
|
1338
|
+
let (
|
|
1339
|
+
dx = b[0] - a[0],
|
|
1340
|
+
dy = b[1] - a[1],
|
|
1341
|
+
d = sqrt(dx * dx + dy * dy),
|
|
1342
|
+
along = d > 0 ? (ra * ra - rb * rb + d * d) / (2 * d) : 0,
|
|
1343
|
+
h2 = ra * ra - along * along
|
|
1344
|
+
)
|
|
1345
|
+
d == 0 || h2 < -1e-9 ? undef
|
|
1346
|
+
: let (h = sqrt(max(0, h2)), ux = dx / d, uy = dy / d)
|
|
1347
|
+
[a[0] + along * ux - side * h * uy, a[1] + along * uy + side * h * ux];
|
|
1348
|
+
|
|
1349
|
+
// A crank of radius r turning round the origin drives a slider along the
|
|
1350
|
+
// line y = offset through a connecting rod of length l. At the crank's
|
|
1351
|
+
// angle it gives [crank pin, slider pin]; undef if the rod can't reach.
|
|
1352
|
+
function slider_crank(r, l, angle, offset = 0) =
|
|
1353
|
+
let (
|
|
1354
|
+
pin = [r * cos(angle), r * sin(angle)],
|
|
1355
|
+
dy = offset - pin[1]
|
|
1356
|
+
)
|
|
1357
|
+
abs(dy) > l ? undef : [pin, [pin[0] + sqrt(l * l - dy * dy), offset]];
|
|
1358
|
+
|
|
1359
|
+
// How far the slider of slider_crank() travels from end to end
|
|
1360
|
+
function slider_stroke(r, l, offset = 0) =
|
|
1361
|
+
sqrt(pow(l + r, 2) - offset * offset) - sqrt(pow(l - r, 2) - offset * offset);
|
|
1362
|
+
|
|
1363
|
+
// A four-bar linkage: the crank turns round the origin, the rocker round
|
|
1364
|
+
// [ground, 0], and the coupler joins their ends. At the crank's angle it
|
|
1365
|
+
// gives [crank end, rocker end], the rocker end on the side \`side\` of the
|
|
1366
|
+
// line from the crank end to the rocker's pivot; undef where the links
|
|
1367
|
+
// can't close.
|
|
1368
|
+
function four_bar(ground, crank, coupler, rocker, angle, side = 1) =
|
|
1369
|
+
let (b = [crank * cos(angle), crank * sin(angle)], c = circle_meet(b, coupler, [ground, 0], rocker, side))
|
|
1370
|
+
is_undef(c) ? undef : [b, c];
|
|
1371
|
+
|
|
1372
|
+
// True when the crank of a four-bar linkage turns all the way round
|
|
1373
|
+
// (Grashof's rule, with the crank the shortest link)
|
|
1374
|
+
function four_bar_turns(ground, crank, coupler, rocker) =
|
|
1375
|
+
let (s = min(ground, crank, coupler, rocker), l = max(ground, crank, coupler, rocker))
|
|
1376
|
+
crank == s && s + l <= ground + crank + coupler + rocker - s - l;
|
|
1377
|
+
|
|
1378
|
+
// The angle in degrees of the line from a to b, from +x
|
|
1379
|
+
function link_angle(a, b) = atan2(b[1] - a[1], b[0] - a[0]);
|
|
1003
1380
|
`,"kerf/lock":`// kerf/lock: a lock with a key, for boxes, diaries, chests and money boxes.
|
|
1004
1381
|
// Copyright (c) 2026 MyLaserTools. AGPL-3.0-only or MyLaserTools commercial licence.
|
|
1005
1382
|
//
|
|
@@ -1184,11 +1561,20 @@ function card_size(name) = let (s = lookup_size(name, CARD_SIZES))
|
|
|
1184
1561
|
is_undef(s) ? assert(false, str("Unknown card size \\"", name, "\\". Known: ", size_names(CARD_SIZES))) : s;
|
|
1185
1562
|
|
|
1186
1563
|
// Photo print sizes as [width, height], landscape: "4x6", "5x7", "8x10",
|
|
1187
|
-
// "10x15" (cm), "13x18" (cm),
|
|
1188
|
-
// "
|
|
1189
|
-
function photo_size(name) = let (s = lookup_size(name, PHOTO_SIZES))
|
|
1564
|
+
// "10x15" (cm), "13x18" (cm), and instant film: "instant mini", "instant
|
|
1565
|
+
// square", "instant wide" and "instant classic".
|
|
1566
|
+
function photo_size(name) = let (s = lookup_size(lookup_alias(name, PHOTO_ALIASES), PHOTO_SIZES))
|
|
1190
1567
|
is_undef(s) ? assert(false, str("Unknown photo size \\"", name, "\\". Known: ", size_names(PHOTO_SIZES))) : s;
|
|
1191
1568
|
|
|
1569
|
+
// A bought part's sizes by name, as a record: \`body\` [width, depth,
|
|
1570
|
+
// height], and for parts with one, the \`shaft\` diameter, the \`shaft_length\`
|
|
1571
|
+
// it stands out of the body and the \`hole\` to cut for it. Retail sizes vary:
|
|
1572
|
+
// measure yours. "music-18" (an 18-note wind-up music box movement, shaft
|
|
1573
|
+
// the winding key's), "quartz-clock" (a 56 mm quartz clock movement with
|
|
1574
|
+
// the 16.5 mm shaft for dials up to 8 mm thick), "marble-16" and "marble-25".
|
|
1575
|
+
function part_size(name) = let (s = lookup_size(name, PART_SIZES))
|
|
1576
|
+
is_undef(s) ? assert(false, str("Unknown part \\"", name, "\\". Known: ", size_names(PART_SIZES))) : s;
|
|
1577
|
+
|
|
1192
1578
|
// A size turned to lie wider than tall
|
|
1193
1579
|
function landscape(size) = size[0] >= size[1] ? size : [size[1], size[0]];
|
|
1194
1580
|
// A size turned to stand taller than wide
|
|
@@ -1210,13 +1596,28 @@ CARD_SIZES = [
|
|
|
1210
1596
|
];
|
|
1211
1597
|
PHOTO_SIZES = [
|
|
1212
1598
|
["4x6", [152.4, 101.6]], ["5x7", [177.8, 127]], ["8x10", [254, 203.2]],
|
|
1213
|
-
["10x15", [150, 100]], ["13x18", [180, 130]], ["
|
|
1214
|
-
["
|
|
1599
|
+
["10x15", [150, 100]], ["13x18", [180, 130]], ["instant mini", [54, 86]],
|
|
1600
|
+
["instant square", [72, 86]], ["instant wide", [108, 86]], ["instant classic", [88, 107]]
|
|
1601
|
+
];
|
|
1602
|
+
// Older names that still work, left out of the list of known names
|
|
1603
|
+
PHOTO_ALIASES = [
|
|
1604
|
+
["instax mini", "instant mini"], ["instax square", "instant square"],
|
|
1605
|
+
["instax wide", "instant wide"], ["polaroid", "instant classic"]
|
|
1606
|
+
];
|
|
1607
|
+
PART_SIZES = [
|
|
1608
|
+
["music-18", {body = [50, 44, 20], shaft = 3.5, hole = 6}],
|
|
1609
|
+
["quartz-clock", {body = [56, 56, 16], shaft = 7.6, shaft_length = 16.5, hole = 8, dial = 8}],
|
|
1610
|
+
["marble-16", {body = [16, 16, 16]}],
|
|
1611
|
+
["marble-25", {body = [25, 25, 25]}]
|
|
1215
1612
|
];
|
|
1216
1613
|
|
|
1217
1614
|
// The size of that name in a table of [name, size], ignoring case
|
|
1218
1615
|
function lookup_size(name, table) = let (k = lower(name), hit = [for (e = table) if (lower(e[0]) == k) e[1]])
|
|
1219
1616
|
len(hit) ? hit[0] : undef;
|
|
1617
|
+
// The name an older name stands for in a table of [old, new], or the name
|
|
1618
|
+
// itself
|
|
1619
|
+
function lookup_alias(name, aliases) = let (k = lower(name), hit = [for (e = aliases) if (lower(e[0]) == k) e[1]])
|
|
1620
|
+
len(hit) ? hit[0] : name;
|
|
1220
1621
|
// The names in a table, for messages
|
|
1221
1622
|
function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
1222
1623
|
`,"kerf/symbols":`// kerf/symbols: 867 pictograms by name, for engraving and cutting.
|
|
@@ -1231,14 +1632,29 @@ function size_names(table) = join([for (e = table) e[0]], ", ");
|
|
|
1231
1632
|
// symbol_names() lists them: "heart", "star", "paw", "tree" and the like.
|
|
1232
1633
|
// box = "grid" sizes and places it by its icon set's grid (24 x 24 for
|
|
1233
1634
|
// Material Design Icons) instead, so icons of one set line up as drawn.
|
|
1234
|
-
|
|
1635
|
+
// solid = true cuts it as one silhouette, gaps narrower than 2 * close
|
|
1636
|
+
// closed and its holes filled, with the drawing's detail engraved on it:
|
|
1637
|
+
// a pictogram drawn as separate strokes (a moon and stars, yarn) cut out
|
|
1638
|
+
// in one piece. bridge = w also joins pieces too far apart to close, by
|
|
1639
|
+
// strips w wide.
|
|
1640
|
+
module symbol(name, size = 10, center = true, fill = "nonzero", box = "drawn", solid = false, close = undef, bridge = undef) {
|
|
1235
1641
|
assert(box == "drawn" || box == "grid", "box is \\"drawn\\" or \\"grid\\"");
|
|
1236
1642
|
s = symbol_entry(name);
|
|
1237
1643
|
vb = box == "grid" ? s[5] : s[2];
|
|
1238
1644
|
k = size / max(vb[2], vb[3]);
|
|
1239
|
-
translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
1645
|
+
module drawn() translate(center ? [0, 0] : [vb[2] * k / 2, vb[3] * k / 2])
|
|
1240
1646
|
scale([k, -k]) translate([-vb[0] - vb[2] / 2, -vb[1] - vb[3] / 2])
|
|
1241
1647
|
path(s[4], fill = fill, close = true);
|
|
1648
|
+
r = is_undef(close) ? size / 30 : close;
|
|
1649
|
+
module silhouette() if (is_undef(bridge)) fill_holes() close(r) drawn();
|
|
1650
|
+
else join_islands(bridge) fill_holes() close(r) drawn();
|
|
1651
|
+
if (solid) {
|
|
1652
|
+
silhouette();
|
|
1653
|
+
engrave() difference() {
|
|
1654
|
+
silhouette();
|
|
1655
|
+
drawn();
|
|
1656
|
+
}
|
|
1657
|
+
} else drawn();
|
|
1242
1658
|
}
|
|
1243
1659
|
|
|
1244
1660
|
// [width, height] of what a symbol draws when it is \`size\` across its
|
|
@@ -2219,10 +2635,10 @@ module tab_rect(size, edges = true, count = undef, width = undef) {
|
|
|
2219
2635
|
if (e[2]) translate([w, h]) rotate(180) tabs(w, count, width);
|
|
2220
2636
|
if (e[3]) translate([0, h]) rotate(270) tabs(h, count, width);
|
|
2221
2637
|
}
|
|
2222
|
-
`};var P="0.3";var u="kerf.json",
|
|
2223
|
-
`));c.update(`${l}\0${e.length}\0`),c.update(e)}return"sha256-"+c.digest("base64")}function o1(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
|
|
2224
|
-
`};async function $1(a,c={}){let l=c.fetch??globalThis.fetch,e=c.log??(()=>{}),n=c.cache??new Map,t=
|
|
2225
|
-
`)&&
|
|
2226
|
-
`)&&
|
|
2227
|
-
`);try{return await $1(a,l)}catch(
|
|
2228
|
-
`));let i=[...t.keys()].sort().map(m=>[`${e}/${m}`,t.get(m)]),o=c??
|
|
2638
|
+
`};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 m1(a).isFile()}catch{return!1}},C=a=>{try{return m1(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 r1(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&&r1(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))r1(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(M(a,u),c),c)}function d1(a){if(!I(M(a,k)))return;let c=a1(M(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 M1(a){for(let c=O(a);;){if(c1(M(c,u)))return c;let l=Y(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)=>[M(s,h),M(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?M1(a):void 0;if(t){let s=c.slice(0,n);if(s===n1(t))return e(t,c.slice(n+1));if(C(M(t,A,s)))return e(M(t,A),c)}return e(a,c)}function Q1(a){let c=Y(O(a));return l=>{let e=V1(c,l);return e===void 0?void 0:T(e,"utf8")}}function J1(a,c=200){let l=M1(a);if(!l)return[];let e=[],n=(h,i)=>{for(let o of[...z1(h,3)].sort()){if(e.length>=c)return;o.endsWith(".kerf")&&e.push(i+o.slice(0,-5))}},t=n1(l);t&&n(l,t+"/");let s=M(l,A);if(C(s))for(let h of Q(s).sort())X.test(h)&&C(M(s,h))&&n(M(s,h),h+"/");return e}function z1(a,c=1/0){let l=[],e=(n,t,s)=>{let h;try{h=Q(n,{withFileTypes:!0})}catch{return}for(let i of h){if(i.name.startsWith(".")||i.name==="node_modules"||i.name===A)continue;let o=t?`${t}/${i.name}`:i.name;i.isDirectory()?s<c&&e(M(n,i.name),o,s+1):i.isFile()&&(l.push(o),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 z1(a))c(e)&&l.set(e,T(M(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,`
|
|
2639
|
+
`));c.update(`${l}\0${e.length}\0`),c.update(e)}return"sha256-"+c.digest("base64")}function o1(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 o=(g,L)=>{let w=i.subarray(g,g+L),V=w.indexOf(0);return w.subarray(0,V<0?L:V).toString("utf8")},m=parseInt(o(124,12).trim()||"0",8);m>=0||d(`${c} is damaged`);let z=o(156,1)||"0",r=l.subarray(h+512,h+512+m);if(h+=512+Math.ceil(m/512)*512,z==="x"||z==="g"){let g=_1(r);z==="g"?n=g.comment??n:t=g;continue}if(z==="L"){s=r.toString("utf8").replace(/\0+$/,"");continue}let v=o(345,155),p=t.path??s??(v?v+"/":"")+o(0,100);t={},s=void 0,(z==="0"||z==="7")&&e.set(p,Buffer.from(r)),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 v1(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(o=>o===".."||o===""))&&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 f1(a,c,l,e,n){let t=E(a,c),s,h;if(t.kind==="folder")c1(M(t.path,u))||d(`${a}: no kerf.json in ${t.path}. Is it a KerfScript library?`),s=v1(G(t.path,e1),a),h=L1(l,t.path).split(y1).join("/")||".",!h.startsWith(".")&&!Z(h)&&(h="./"+h);else{let o=t.kind==="github"?`https://github.com/${t.owner}/${t.repo}/archive/${t.ref}.tar.gz`:t.url,m=n.get(o)??await q1(o,e);n.set(o,m);let z=x1(m,a);s=v1(z.files,a),h=t.kind==="github"&&/^[0-9a-f]{40}$/.test(z.commit??"")?`https://github.com/${t.owner}/${t.repo}/archive/${z.commit}.tar.gz`:o}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){J(a,{recursive:!0,force:!0});for(let[l,e]of c){let n=M(a,...l.split("/"));w1(Y(n),{recursive:!0}),_(n,e)}}var j1=a=>{let c=[...a].sort(([l],[e])=>l<e?-1:1);return JSON.stringify({lockVersion:1,libraries:Object.fromEntries(c)},null,2)+`
|
|
2640
|
+
`};async function $1(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(([r,v])=>({name:r,source:v,base:a,from:u})),o=M(a,A);for(;i.length;){let{name:r,source:v,base:p,from:g}=i.shift(),L=E(v,p),w=L.kind==="folder",V=w?`${v} (${L.path})`:v,j=h.get(r);if(j){j.at!==o1(L)&&!S(t.libraries,r)&&d(`${g} uses ${r} from ${V}, and ${j.from} uses it from ${j.shown}. Add ${r} to kerf.json with the source to use.`);continue}let B=S(s?.libraries,r),b=B?.source===v&&(!w||O(a,B.resolved)===L.path)?B:void 0;c.frozen&&!b&&d(`kerf.lock does not pin ${r} from ${v}. Run kerf install without --frozen.`);let $=M(o,r),q;if(b&&!w&&C($)&&F(G($))===b.integrity)q=b;else{let f=await f1(b&&!w?b.resolved:v,w?p:a,a,l,n);f.manifest.name!==r&&d(`${v} is the library "${f.manifest.name}", so ${g} must call it ${f.manifest.name}, not ${r}`),b&&f.integrity!==b.integrity&&(!w||c.frozen)&&d(w?`${r} in ${v} changed since kerf.lock pinned it. Run kerf install without --frozen.`:`${r} from ${b.resolved} no longer matches kerf.lock. If you trust the change, remove ${r} from kerf.lock and run kerf install again.`),T1($,f.files),q={source:v,...f.manifest.version?{version:f.manifest.version}:{},resolved:f.resolved,integrity:f.integrity},(!b||b.integrity!==f.integrity||!w)&&e(`${b?"Restored":"Installed"} ${r}${q.version?" "+q.version:""} from ${v}`)}h.set(r,{entry:q,at:o1(L),shown:V,from:g});let t1=L.kind==="folder"?L.path:void 0;for(let[f,K]of Object.entries(H($,`${A}/${r}/${u}`).libraries))E(K,a).kind==="folder"&&!t1&&d(`${r} uses ${f} from the folder ${K}: a published library needs github: or https: sources`),i.push({name:f,source:K,base:t1??a,from:r})}let m=j1(new Map([...h].map(([r,v])=>[r,v.entry]))),z=I(M(a,k))?T(M(a,k),"utf8"):"";if(c.frozen&&m!==z.replace(/\r\n/g,`
|
|
2641
|
+
`)&&d("kerf.lock is out of date. Run kerf install without --frozen."),C(o))for(let r of Q(o,{withFileTypes:!0}))r.isDirectory()&&X.test(r.name)&&!h.has(r.name)&&(J(M(o,r.name),{recursive:!0,force:!0}),e(`Removed ${r.name}`));return m!==z.replace(/\r\n/g,`
|
|
2642
|
+
`)&&_(M(a,k),m),JSON.parse(m)}function Y1(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 o=M(a,A,h);if(!C(o)){n.push(`${h} is not in ${A}. Run kerf install.`);continue}F(G(o))!==i.integrity&&n.push(`The files in ${A}/${h} differ from kerf.lock. Run kerf install.`);try{s.push(...Object.keys(H(o).libraries))}catch(m){n.push(m.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=M(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)+`
|
|
2643
|
+
`);try{return await $1(a,l)}catch(s){throw n===void 0?J(e,{force:!0}):_(e,n),s}}async function X1(a,c,l={}){let e=new Map,t=(await f1(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[m,z]of Object.entries(l.libraries))E(z,a).kind==="folder"&&s.push(`kerf.json: ${m} comes from a folder; a published library needs github: or https: sources`);let h=m=>t.has(m)||t.has(m+".kerf");for(let[m,z]of t){if(!m.endsWith(".kerf"))continue;let r;try{r=h1(z.toString("utf8"),`${e}/${m}`).program}catch(v){s.push(`${m}: ${v.message}`);continue}for(let v of U(r)){let p=v.path.split("/")[0];Object.prototype.hasOwnProperty.call(i1,v.path)||p===e&&h(v.path.slice(e.length+1))||v.path.includes("/")&&S(l.libraries,p)!==void 0||s.push(`${m}, line ${v.line}: <${v.path}> will not be found once the library is installed`+(h(v.path)?`. Write <${e}/${v.path}> for the library's own file.`:"."))}}[...t.keys()].some(m=>m.endsWith(".kerf"))||s.push("There are no .kerf files to pack"),s.length&&d(s.join(`
|
|
2644
|
+
`));let i=[...t.keys()].sort().map(m=>[`${e}/${m}`,t.get(m)]),o=c??M(a,`${e}-${n}.tar.gz`);return _(o,I1(i)),{file:o,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,Y1 as check,M1 as findProject,$1 as install,J1 as installedPaths,F as integrity,V1 as libraryFile,l0 as pack,d1 as readLock,H as readManifest,c0 as remove,Q1 as resolver};
|