@rulecad/cad 0.8.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/AGENTS.md +24 -10
- package/CHANGELOG.md +404 -0
- package/EXAMPLES.md +40 -38
- package/README.md +193 -67
- package/TUTORIAL.md +2 -2
- package/bin/cad.mjs +2250 -512
- package/lib/animate.mjs +173 -49
- package/lib/assembly.mjs +1847 -434
- package/lib/beams.mjs +256 -52
- package/lib/belts.mjs +66 -15
- package/lib/board-work.mjs +12 -0
- package/lib/bought.mjs +309 -53
- package/lib/buildpage.mjs +179 -29
- package/lib/carried.mjs +201 -0
- package/lib/clone.mjs +194 -42
- package/lib/design.mjs +649 -121
- package/lib/drive.mjs +187 -63
- package/lib/edit.mjs +899 -191
- package/lib/errors.mjs +16 -3
- package/lib/explain.mjs +62 -13
- package/lib/fasten.mjs +2702 -507
- package/lib/fittings.mjs +715 -121
- package/lib/fixings.mjs +21 -9
- package/lib/framebuild.mjs +790 -175
- package/lib/framecheck.mjs +1901 -368
- package/lib/framegen.mjs +100 -22
- package/lib/frameheat.mjs +225 -42
- package/lib/frameprint.mjs +513 -108
- package/lib/frames.mjs +81 -17
- package/lib/framesize.mjs +792 -120
- package/lib/frametip.mjs +235 -0
- package/lib/gait.mjs +135 -23
- package/lib/grip.mjs +62 -13
- package/lib/guides.mjs +1403 -230
- package/lib/host.mjs +123 -21
- package/lib/inplace.mjs +171 -36
- package/lib/jigs.mjs +360 -78
- package/lib/joins.mjs +697 -118
- package/lib/jsonedit.mjs +88 -26
- package/lib/kept.mjs +84 -0
- package/lib/kit.mjs +438 -68
- package/lib/layout.mjs +2 -1
- package/lib/links.mjs +149 -42
- package/lib/list.mjs +326 -64
- package/lib/live-guard.mjs +68 -0
- package/lib/live-shape.mjs +96 -24
- package/lib/live.mjs +189 -59
- package/lib/loads.mjs +579 -130
- package/lib/machine.mjs +372 -74
- package/lib/magnets.mjs +162 -44
- package/lib/measured.mjs +417 -94
- package/lib/mesh.mjs +526 -119
- package/lib/meshcmd.mjs +215 -60
- package/lib/motors.mjs +1021 -213
- package/lib/motorsvg.mjs +114 -32
- package/lib/names.mjs +3 -1
- package/lib/optimise.mjs +978 -283
- package/lib/order.mjs +519 -112
- package/lib/panels.mjs +482 -94
- package/lib/parts.mjs +78 -23
- package/lib/pins.mjs +163 -44
- package/lib/plates.mjs +223 -35
- package/lib/player.mjs +37 -9
- package/lib/power.mjs +64 -13
- package/lib/preview.mjs +83 -16
- package/lib/profilemeasure.mjs +572 -129
- package/lib/rules.mjs +15 -5
- package/lib/sandbox-hooks.mjs +77 -19
- package/lib/sandbox-run.mjs +117 -18
- package/lib/sandbox.mjs +509 -60
- package/lib/schema.mjs +42 -11
- package/lib/seats.mjs +227 -49
- package/lib/services.mjs +261 -52
- package/lib/sheet.mjs +851 -178
- package/lib/slotnuts.mjs +213 -34
- package/lib/targets/gist.mjs +4 -1
- package/lib/targets.mjs +22 -4
- package/lib/task.mjs +376 -79
- package/lib/versions.mjs +111 -28
- package/lib/wires.mjs +228 -45
- package/lib/workspace.mjs +197 -12
- package/package.json +19 -19
- package/schemas/assembly.schema.json +2 -2
package/lib/frames.mjs
CHANGED
|
@@ -5,6 +5,7 @@ import fs from 'node:fs';
|
|
|
5
5
|
import path from 'node:path';
|
|
6
6
|
import crypto from 'node:crypto';
|
|
7
7
|
import * as frames from '@rulecad/frames';
|
|
8
|
+
import { readOwnText } from './host.mjs';
|
|
8
9
|
|
|
9
10
|
// The workspace's own profile, slot, slot nut, material, thread and bought fitting sets, and its joins set (cad measure
|
|
10
11
|
// --profile writes a draft profile there, with its outline in rules/outlines/; cad measured writes a measured figure
|
|
@@ -17,30 +18,82 @@ let seen = null;
|
|
|
17
18
|
*/
|
|
18
19
|
export function framesContext(dir) {
|
|
19
20
|
const out = path.join(dir, 'outlines');
|
|
20
|
-
const stamp = (d) => {
|
|
21
|
+
const stamp = (d) => {
|
|
22
|
+
try {
|
|
23
|
+
return fs
|
|
24
|
+
.readdirSync(d)
|
|
25
|
+
.filter((f) => f.endsWith('.json'))
|
|
26
|
+
.sort()
|
|
27
|
+
.map((f) => `${f}:${fs.statSync(path.join(d, f)).mtimeMs}`)
|
|
28
|
+
.join('|');
|
|
29
|
+
} catch {
|
|
30
|
+
return '';
|
|
31
|
+
}
|
|
32
|
+
};
|
|
21
33
|
const key = `${dir}|${stamp(dir)}|${stamp(out)}`;
|
|
22
34
|
if (seen?.key === key) return seen.context;
|
|
23
|
-
const sets = {},
|
|
24
|
-
|
|
25
|
-
|
|
35
|
+
const sets = {},
|
|
36
|
+
outlines = {},
|
|
37
|
+
text = [];
|
|
38
|
+
for (const [d, into] of [
|
|
39
|
+
[dir, sets],
|
|
40
|
+
[out, outlines],
|
|
41
|
+
]) {
|
|
42
|
+
let files = [];
|
|
43
|
+
try {
|
|
44
|
+
files = fs
|
|
45
|
+
.readdirSync(d)
|
|
46
|
+
.filter((f) => f.endsWith('.json'))
|
|
47
|
+
.sort();
|
|
48
|
+
} catch {
|
|
49
|
+
// (no such folder: no sets from it)
|
|
50
|
+
}
|
|
26
51
|
for (const f of files) {
|
|
27
52
|
try {
|
|
28
|
-
const raw =
|
|
53
|
+
const raw = readOwnText(path.join(d, f)), // (a set linked in from outside the workspace is not read)
|
|
54
|
+
s = JSON.parse(raw);
|
|
29
55
|
// (a plastic's or a metal's set has no part: it is a material by its density, and the beam coupon measures into it)
|
|
30
|
-
if (
|
|
31
|
-
|
|
56
|
+
if (
|
|
57
|
+
into === sets
|
|
58
|
+
? s?.rules &&
|
|
59
|
+
typeof s.rules === 'object' &&
|
|
60
|
+
(['profile', 'slot', 'slot_nut', 'material', 'thread', 'fitting', 'joins'].includes(s.part) ||
|
|
61
|
+
(s.part == null && typeof s.rules.density?.value === 'number'))
|
|
62
|
+
: Array.isArray(s?.loops)
|
|
63
|
+
) {
|
|
64
|
+
into[s.name ?? f.slice(0, -5)] = s;
|
|
65
|
+
text.push(raw);
|
|
66
|
+
}
|
|
67
|
+
} catch {
|
|
68
|
+
// (a broken set is cad rules check's to name)
|
|
69
|
+
}
|
|
32
70
|
}
|
|
33
71
|
}
|
|
34
|
-
const context = {
|
|
72
|
+
const context = {
|
|
73
|
+
sets,
|
|
74
|
+
outlines,
|
|
75
|
+
hash: crypto.createHash('sha256').update(text.join('\n')).digest('hex').slice(0, 24),
|
|
76
|
+
};
|
|
35
77
|
seen = { key, context };
|
|
36
78
|
return context;
|
|
37
79
|
}
|
|
38
80
|
|
|
39
81
|
// profileModel's third argument for a profile by name: the workspace's sets, and its measured outline if it has one
|
|
40
82
|
export const givenFor = (context, profile, given = {}) => {
|
|
41
|
-
const name =
|
|
83
|
+
const name =
|
|
84
|
+
typeof profile === 'string'
|
|
85
|
+
? context.sets?.[profile]
|
|
86
|
+
? profile
|
|
87
|
+
: context.sets?.[`profile-${profile}`]
|
|
88
|
+
? `profile-${profile}`
|
|
89
|
+
: null
|
|
90
|
+
: null;
|
|
42
91
|
const outline = name && context.outlines?.[name];
|
|
43
|
-
return {
|
|
92
|
+
return {
|
|
93
|
+
...given,
|
|
94
|
+
sets: { ...(context.sets || {}), ...(given.sets || {}) },
|
|
95
|
+
...(outline && !given.outline ? { outline } : {}),
|
|
96
|
+
};
|
|
44
97
|
};
|
|
45
98
|
|
|
46
99
|
/**
|
|
@@ -53,13 +106,24 @@ export const givenFor = (context, profile, given = {}) => {
|
|
|
53
106
|
export function designFrames(context = {}) {
|
|
54
107
|
const bound = { ...frames };
|
|
55
108
|
// (a name is looked up in given.sets before the kit's, with or without its profile- prefix)
|
|
56
|
-
bound.profileModel = (which, change = {}, given = {}) =>
|
|
57
|
-
|
|
58
|
-
bound.
|
|
59
|
-
|
|
109
|
+
bound.profileModel = (which, change = {}, given = {}) =>
|
|
110
|
+
frames.profileModel(which, change, givenFor(context, which, given));
|
|
111
|
+
bound.slotModel = (which, change = {}, given = {}) =>
|
|
112
|
+
frames.slotModel(which, change, { ...given, sets: { ...(context.sets || {}), ...(given.sets || {}) } });
|
|
113
|
+
bound.beamModel = (profile, o = {}) =>
|
|
114
|
+
frames.beamModel(typeof profile === 'string' ? bound.profileModel(profile, {}, o.given) : profile, {
|
|
115
|
+
...o,
|
|
116
|
+
given: givenFor(context, profile, o.given),
|
|
117
|
+
});
|
|
118
|
+
bound.beam = (m, o = {}) =>
|
|
119
|
+
frames.beam(
|
|
120
|
+
m?.kind === 'beam' || m?.kind === 'profile' ? m : typeof m === 'string' ? bound.profileModel(m, {}, o.given) : m,
|
|
121
|
+
o,
|
|
122
|
+
);
|
|
60
123
|
// (a printed carrier drawn from the workspace's slot, as measured by caliper on the slot coupon)
|
|
61
|
-
bound.carrierModel = (where, o = {}) =>
|
|
62
|
-
|
|
124
|
+
bound.carrierModel = (where, o = {}) =>
|
|
125
|
+
frames.carrierModel(where, { ...o, given: givenFor(context, where, o?.given) });
|
|
126
|
+
bound.carrier = (m, o = {}) =>
|
|
127
|
+
frames.carrier(m, m?.kind === 'slot-carrier' ? o : { ...o, given: givenFor(context, m, o?.given) });
|
|
63
128
|
return bound;
|
|
64
129
|
}
|
|
65
|
-
|