@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.
Files changed (83) hide show
  1. package/AGENTS.md +24 -10
  2. package/CHANGELOG.md +404 -0
  3. package/EXAMPLES.md +40 -38
  4. package/README.md +193 -67
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2250 -512
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1847 -434
  9. package/lib/beams.mjs +256 -52
  10. package/lib/belts.mjs +66 -15
  11. package/lib/board-work.mjs +12 -0
  12. package/lib/bought.mjs +309 -53
  13. package/lib/buildpage.mjs +179 -29
  14. package/lib/carried.mjs +201 -0
  15. package/lib/clone.mjs +194 -42
  16. package/lib/design.mjs +649 -121
  17. package/lib/drive.mjs +187 -63
  18. package/lib/edit.mjs +899 -191
  19. package/lib/errors.mjs +16 -3
  20. package/lib/explain.mjs +62 -13
  21. package/lib/fasten.mjs +2702 -507
  22. package/lib/fittings.mjs +715 -121
  23. package/lib/fixings.mjs +21 -9
  24. package/lib/framebuild.mjs +790 -175
  25. package/lib/framecheck.mjs +1901 -368
  26. package/lib/framegen.mjs +100 -22
  27. package/lib/frameheat.mjs +225 -42
  28. package/lib/frameprint.mjs +513 -108
  29. package/lib/frames.mjs +81 -17
  30. package/lib/framesize.mjs +792 -120
  31. package/lib/frametip.mjs +235 -0
  32. package/lib/gait.mjs +135 -23
  33. package/lib/grip.mjs +62 -13
  34. package/lib/guides.mjs +1403 -230
  35. package/lib/host.mjs +123 -21
  36. package/lib/inplace.mjs +171 -36
  37. package/lib/jigs.mjs +360 -78
  38. package/lib/joins.mjs +697 -118
  39. package/lib/jsonedit.mjs +88 -26
  40. package/lib/kept.mjs +84 -0
  41. package/lib/kit.mjs +438 -68
  42. package/lib/layout.mjs +2 -1
  43. package/lib/links.mjs +149 -42
  44. package/lib/list.mjs +326 -64
  45. package/lib/live-guard.mjs +68 -0
  46. package/lib/live-shape.mjs +96 -24
  47. package/lib/live.mjs +189 -59
  48. package/lib/loads.mjs +579 -130
  49. package/lib/machine.mjs +372 -74
  50. package/lib/magnets.mjs +162 -44
  51. package/lib/measured.mjs +417 -94
  52. package/lib/mesh.mjs +526 -119
  53. package/lib/meshcmd.mjs +215 -60
  54. package/lib/motors.mjs +1021 -213
  55. package/lib/motorsvg.mjs +114 -32
  56. package/lib/names.mjs +3 -1
  57. package/lib/optimise.mjs +978 -283
  58. package/lib/order.mjs +519 -112
  59. package/lib/panels.mjs +482 -94
  60. package/lib/parts.mjs +78 -23
  61. package/lib/pins.mjs +163 -44
  62. package/lib/plates.mjs +223 -35
  63. package/lib/player.mjs +37 -9
  64. package/lib/power.mjs +64 -13
  65. package/lib/preview.mjs +83 -16
  66. package/lib/profilemeasure.mjs +572 -129
  67. package/lib/rules.mjs +15 -5
  68. package/lib/sandbox-hooks.mjs +77 -19
  69. package/lib/sandbox-run.mjs +117 -18
  70. package/lib/sandbox.mjs +509 -60
  71. package/lib/schema.mjs +42 -11
  72. package/lib/seats.mjs +227 -49
  73. package/lib/services.mjs +261 -52
  74. package/lib/sheet.mjs +851 -178
  75. package/lib/slotnuts.mjs +213 -34
  76. package/lib/targets/gist.mjs +4 -1
  77. package/lib/targets.mjs +22 -4
  78. package/lib/task.mjs +376 -79
  79. package/lib/versions.mjs +111 -28
  80. package/lib/wires.mjs +228 -45
  81. package/lib/workspace.mjs +197 -12
  82. package/package.json +19 -19
  83. package/schemas/assembly.schema.json +2 -2
package/lib/services.mjs CHANGED
@@ -14,12 +14,16 @@ import { boughtSets } from './bought.mjs';
14
14
  const MOUNT_KEYS = ['on', 'turn', 'offset', 'standoff', 'load', 'nut', 'head', 'screw'];
15
15
  const RUN_KEYS = ['along', 'from', 'to', 'pitch', 'cable'];
16
16
  const shown = (v) => (v === undefined ? 'nothing' : JSON.stringify(v));
17
- const mm = (x) => String(+Number(x).toFixed(2)), r3 = (x) => +x.toFixed(3);
17
+ const mm = (x) => String(+Number(x).toFixed(2)),
18
+ r3 = (x) => +x.toFixed(3);
18
19
 
19
20
  // a slotted place on a beam by its face's name (top, top.2) and the beam's model, refused by name
20
21
  function slotPlace(what, id, B, name) {
21
22
  const q = B.places.find((x) => x.name === name || (x.face === name && x.index === 1));
22
- if (!q) throw new Error(`${what}: ${id} has no face "${name}": it has ${[...new Set(B.places.map((x) => x.face))].join(', ')}`);
23
+ if (!q)
24
+ throw new Error(
25
+ `${what}: ${id} has no face "${name}": it has ${[...new Set(B.places.map((x) => x.face))].join(', ')}`,
26
+ );
23
27
  if (!q.slot) throw new Error(`${what}: ${id}'s ${name} face is closed: a mount or a clip goes into a slot`);
24
28
  return q;
25
29
  }
@@ -36,86 +40,260 @@ const faceOf = (B, q) => (B.places.filter((x) => x.face === q.face).length > 1 ?
36
40
  * @returns {{ a: object, mounts: object[], runs: object[] }}
37
41
  */
38
42
  export function expandServices(a, num, context = framesContext(), material = 'pla') {
39
- const items = a.items || [], mounted = items.filter((it) => it.mount != null), runs0 = (a.wires || []).some((w) => (w.via ?? []).some((v) => v && typeof v === 'object'));
43
+ const items = a.items || [],
44
+ mounted = items.filter((it) => it.mount != null),
45
+ runs0 = (a.wires || []).some((w) => (w.via ?? []).some((v) => v && typeof v === 'object'));
40
46
  if (!mounted.length && !runs0) return { a, mounts: [], runs: [] };
41
- const beams = new Map(items.filter((it) => it.beam).map((it) => [it.id, it])), ids = new Set(items.map((it) => it.id)), models = new Map();
42
- const modelOf = (id) => { if (!models.has(id)) models.set(id, beamOf(beams.get(id), num, context).model); return models.get(id); };
43
- const free = (base) => { let n = base, k = 2; while (ids.has(n)) n = `${base}-${k++}`; ids.add(n); return n; };
47
+ const beams = new Map(items.filter((it) => it.beam).map((it) => [it.id, it])),
48
+ ids = new Set(items.map((it) => it.id)),
49
+ models = new Map();
50
+ const modelOf = (id) => {
51
+ if (!models.has(id)) models.set(id, beamOf(beams.get(id), num, context).model);
52
+ return models.get(id);
53
+ };
54
+ const free = (base) => {
55
+ let n = base,
56
+ k = 2;
57
+ while (ids.has(n)) n = `${base}-${k++}`;
58
+ ids.add(n);
59
+ return n;
60
+ };
44
61
  const beamOfAddress = (what, ref, key) => {
45
- const s = String(ref ?? ''), i = s.indexOf('.');
46
- if (i < 0) throw new Error(`${what}: ${key} is a beam's slotted face${key === 'on' ? ' and a distance, as rail.top@200' : ', as rail.top'} (got ${shown(ref)})`);
47
- const id = s.slice(0, i), rest = s.slice(i + 1);
48
- if (!beams.has(id)) throw new Error(`${what}: ${key} names a beam item of this assembly, and ${id} is ${items.some((x) => x.id === id) ? 'not a beam' : 'not an item'} (beams: ${[...beams.keys()].join(', ') || 'none'})`);
62
+ const s = String(ref ?? ''),
63
+ i = s.indexOf('.');
64
+ if (i < 0)
65
+ throw new Error(
66
+ `${what}: ${key} is a beam's slotted face${key === 'on' ? ' and a distance, as rail.top@200' : ', as rail.top'} (got ${shown(ref)})`,
67
+ );
68
+ const id = s.slice(0, i),
69
+ rest = s.slice(i + 1);
70
+ if (!beams.has(id))
71
+ throw new Error(
72
+ `${what}: ${key} names a beam item of this assembly, and ${id} is ${items.some((x) => x.id === id) ? 'not a beam' : 'not an item'} (beams: ${[...beams.keys()].join(', ') || 'none'})`,
73
+ );
49
74
  return { id, rest, B: modelOf(id) };
50
75
  };
51
- const added = [], fasten = [], fits = [], mounts = [], runs = [], plates = [], replaced = new Map(), ahead = new Map();
76
+ const added = [],
77
+ fasten = [],
78
+ fits = [],
79
+ mounts = [],
80
+ runs = [],
81
+ plates = [],
82
+ replaced = new Map(),
83
+ ahead = new Map();
52
84
  for (const it of mounted) {
53
- const what = `item ${it.id}`, M = it.mount;
54
- if (!M || typeof M !== 'object' || Array.isArray(M)) throw new Error(`${what}: mount is { "on": "rail.top@200" }, an address on a beam's slotted face (got ${shown(M)})`);
55
- for (const k of Object.keys(M)) if (!MOUNT_KEYS.includes(k)) throw new Error(`${what}: a mount has no "${k}": it takes ${MOUNT_KEYS.join(', ')}`);
56
- if (!it.bought) throw new Error(`${what}: mount holds a bought board or supply by the holes its rule set gives: give "bought"`);
85
+ const what = `item ${it.id}`,
86
+ M = it.mount;
87
+ if (!M || typeof M !== 'object' || Array.isArray(M))
88
+ throw new Error(
89
+ `${what}: mount is { "on": "rail.top@200" }, an address on a beam's slotted face (got ${shown(M)})`,
90
+ );
91
+ for (const k of Object.keys(M))
92
+ if (!MOUNT_KEYS.includes(k)) throw new Error(`${what}: a mount has no "${k}": it takes ${MOUNT_KEYS.join(', ')}`);
93
+ if (!it.bought)
94
+ throw new Error(`${what}: mount holds a bought board or supply by the holes its rule set gives: give "bought"`);
57
95
  const part = boughtSets().get(it.bought);
58
- if (!['board', 'supply', 'encoder'].includes(part)) throw new Error(`${what}: mount holds a bought board or supply, and ${it.bought} is ${part ? `a ${part}` : 'no bought part'}`);
59
- if (it.at != null || it.rotate != null || it.repeat != null) throw new Error(`${what}: a mounted item is placed by its mount: leave out at, rotate and repeat`);
60
- const { id: bid, rest, B } = beamOfAddress(what, M.on, 'on'), [face, dist] = rest.split('@');
61
- if (dist == null) throw new Error(`${what}: on is a beam's face and a distance along it, as ${bid}.${face}@200 (got ${shown(M.on)})`);
62
- try { beamAnchor(B, rest); } catch (e) { throw new Error(`${what}: on: ${String(e.message).replace(/^beamAnchor: /, '')}`); }
63
- const q = slotPlace(what, bid, B, face), mid = free(`${it.id}-mount`);
64
- const spec = { kind: 'device-mount', profile: B.profile.name, face: faceOf(B, q), device: it.bought, ...(it.variant != null ? { variant: it.variant } : {}),
65
- ...(M.turn != null ? { turn: M.turn } : {}), ...(M.offset != null ? { offset: num(M.offset) } : {}), ...(M.standoff != null ? { standoff: num(M.standoff) } : {}), ...(M.load != null ? { load: num(M.load) } : {}),
66
- ...(M.nut != null ? { nut: M.nut } : {}), ...(M.head != null ? { head: M.head } : {}), ...(M.screw != null ? { screw: M.screw } : {}) };
67
- const m = fittingModel(spec, context, material, what), D = m.device;
96
+ if (!['board', 'supply', 'encoder'].includes(part))
97
+ throw new Error(
98
+ `${what}: mount holds a bought board or supply, and ${it.bought} is ${part ? `a ${part}` : 'no bought part'}`,
99
+ );
100
+ if (it.at != null || it.rotate != null || it.repeat != null)
101
+ throw new Error(`${what}: a mounted item is placed by its mount: leave out at, rotate and repeat`);
102
+ const { id: bid, rest, B } = beamOfAddress(what, M.on, 'on'),
103
+ [face, dist] = rest.split('@');
104
+ if (dist == null)
105
+ throw new Error(
106
+ `${what}: on is a beam's face and a distance along it, as ${bid}.${face}@200 (got ${shown(M.on)})`,
107
+ );
108
+ try {
109
+ beamAnchor(B, rest);
110
+ } catch (e) {
111
+ throw new Error(`${what}: on: ${String(e.message).replace(/^beamAnchor: /, '')}`);
112
+ }
113
+ const q = slotPlace(what, bid, B, face),
114
+ mid = free(`${it.id}-mount`);
115
+ const spec = {
116
+ kind: 'device-mount',
117
+ profile: B.profile.name,
118
+ face: faceOf(B, q),
119
+ device: it.bought,
120
+ ...(it.variant != null ? { variant: it.variant } : {}),
121
+ ...(M.turn != null ? { turn: M.turn } : {}),
122
+ ...(M.offset != null ? { offset: num(M.offset) } : {}),
123
+ ...(M.standoff != null ? { standoff: num(M.standoff) } : {}),
124
+ ...(M.load != null ? { load: num(M.load) } : {}),
125
+ ...(M.nut != null ? { nut: M.nut } : {}),
126
+ ...(M.head != null ? { head: M.head } : {}),
127
+ ...(M.screw != null ? { screw: M.screw } : {}),
128
+ };
129
+ const m = fittingModel(spec, context, material, what),
130
+ D = m.device;
68
131
  ahead.set(it.id, { id: mid, fitting: spec, at: `${bid}.${rest}`, mountOf: it.id }); // (listed just before its device: of two parts as near the base, the earlier goes on first)
69
- fasten.push({ screw: `${m.thread} ${m.head}`, through: [mid], into: `${bid}.${q.name}`, at: m.screws.map((_, k) => `${mid}.b${k + 1}`), nut: m.screws[0].nutKind, note: `${it.id}'s mount into ${bid}`, mountOf: it.id });
132
+ fasten.push({
133
+ screw: `${m.thread} ${m.head}`,
134
+ through: [mid],
135
+ into: `${bid}.${q.name}`,
136
+ at: m.screws.map((_, k) => `${mid}.b${k + 1}`),
137
+ nut: m.screws[0].nutKind,
138
+ note: `${it.id}'s mount into ${bid}`,
139
+ mountOf: it.id,
140
+ });
70
141
  const at = D.holes.map((_, k) => `${mid}.d${k + 1}`);
71
- fasten.push(m.fix === 'tapped'
72
- ? { screw: `${D.thread} ${D.head}`, through: [mid], into: it.id, at, note: `${it.id} on its mount, from under it`, mountOf: it.id }
73
- : { screw: `${D.thread} ${D.head}`, through: [it.id], into: mid, at, note: `${it.id} on its mount`, mountOf: it.id });
142
+ fasten.push(
143
+ m.fix === 'tapped'
144
+ ? {
145
+ screw: `${D.thread} ${D.head}`,
146
+ through: [mid],
147
+ into: it.id,
148
+ at,
149
+ note: `${it.id} on its mount, from under it`,
150
+ mountOf: it.id,
151
+ }
152
+ : {
153
+ screw: `${D.thread} ${D.head}`,
154
+ through: [it.id],
155
+ into: mid,
156
+ at,
157
+ note: `${it.id} on its mount`,
158
+ mountOf: it.id,
159
+ },
160
+ );
74
161
  replaced.set(it.id, { ...it, at: `${mid}.device` });
75
162
  // the stretch of the slot its plate covers (either way along, as its outline reaches): a run's clips keep off it
76
- const reachX = Math.max(...m.outline.map((pt) => Math.abs(pt[0]))), d0 = num(dist), at0 = d0 < 0 ? B.length + d0 : d0;
163
+ const reachX = Math.max(...m.outline.map((pt) => Math.abs(pt[0]))),
164
+ d0 = num(dist),
165
+ at0 = d0 < 0 ? B.length + d0 : d0;
77
166
  plates.push({ mount: mid, item: it.id, beam: bid, slot: q.name, lo: r3(at0 - reachX), hi: r3(at0 + reachX) });
78
- mounts.push({ id: it.id, mount: mid, beam: bid, on: M.on, set: it.bought, variant: it.variant ?? null, fix: m.fix, holes: D.holes.length, thread: D.thread, length: D.length, grams: m.grams, margin: m.margin });
167
+ mounts.push({
168
+ id: it.id,
169
+ mount: mid,
170
+ beam: bid,
171
+ on: M.on,
172
+ set: it.bought,
173
+ variant: it.variant ?? null,
174
+ fix: m.fix,
175
+ holes: D.holes.length,
176
+ thread: D.thread,
177
+ length: D.length,
178
+ grams: m.grams,
179
+ margin: m.margin,
180
+ });
79
181
  }
80
182
  // wires: each run along a slot becomes clips, and the wire goes through each clip's cable anchor in turn
81
183
  const wires = (a.wires || []).map((w, wi) => {
82
184
  if (!(w.via ?? []).some((v) => v && typeof v === 'object')) return w;
83
185
  const via = [];
84
186
  for (const v of w.via) {
85
- if (!v || typeof v !== 'object') { via.push(v); continue; }
187
+ if (!v || typeof v !== 'object') {
188
+ via.push(v);
189
+ continue;
190
+ }
86
191
  const what = `wire ${w.id || wi + 1}`;
87
- if (Array.isArray(v)) throw new Error(`${what}: a run in via is { "along": "rail.top", "from": 20, "to": 380 } (got ${shown(v)})`);
88
- for (const k of Object.keys(v)) if (!RUN_KEYS.includes(k)) throw new Error(`${what}: a run along a slot has no "${k}": it takes ${RUN_KEYS.join(', ')}`);
192
+ if (Array.isArray(v))
193
+ throw new Error(`${what}: a run in via is { "along": "rail.top", "from": 20, "to": 380 } (got ${shown(v)})`);
194
+ for (const k of Object.keys(v))
195
+ if (!RUN_KEYS.includes(k))
196
+ throw new Error(`${what}: a run along a slot has no "${k}": it takes ${RUN_KEYS.join(', ')}`);
89
197
  const { id: bid, rest, B } = beamOfAddress(what, v.along, 'along');
90
- if (rest.includes('@')) throw new Error(`${what}: along names the face (${bid}.${rest.split('@')[0]}); the run's ends are from and to, in mm from end a`);
198
+ if (rest.includes('@'))
199
+ throw new Error(
200
+ `${what}: along names the face (${bid}.${rest.split('@')[0]}); the run's ends are from and to, in mm from end a`,
201
+ );
91
202
  const q = slotPlace(what, bid, B, rest);
92
- if (v.from == null || v.to == null) throw new Error(`${what}: a run along ${v.along} gives from and to, in mm from ${bid}'s end a`);
93
- const from = num(v.from), to = num(v.to), L = B.length;
94
- for (const [k, x] of [['from', from], ['to', to]]) if (!(Number.isFinite(x) && x >= 0 && x <= L)) throw new Error(`${what}: a run's ${k} is from 0 to ${mm(L)} mm along ${bid} (got ${shown(v[k])})`);
203
+ if (v.from == null || v.to == null)
204
+ throw new Error(`${what}: a run along ${v.along} gives from and to, in mm from ${bid}'s end a`);
205
+ const from = num(v.from),
206
+ to = num(v.to),
207
+ L = B.length;
208
+ for (const [k, x] of [
209
+ ['from', from],
210
+ ['to', to],
211
+ ])
212
+ if (!(Number.isFinite(x) && x >= 0 && x <= L))
213
+ throw new Error(`${what}: a run's ${k} is from 0 to ${mm(L)} mm along ${bid} (got ${shown(v[k])})`);
95
214
  let clips;
96
- try { clips = runClips(Math.abs(to - from), v.pitch != null ? { pitch: num(v.pitch) } : {}); } catch (e) { throw new Error(`${what}: ${String(e.message).replace(/^runClips: /, '')}`); }
97
- const sgn = to >= from ? 1 : -1, cable = v.cable != null ? num(v.cable) : SERVICE_DEFAULTS.cable.value, list = [];
215
+ try {
216
+ clips = runClips(Math.abs(to - from), v.pitch != null ? { pitch: num(v.pitch) } : {});
217
+ } catch (e) {
218
+ throw new Error(`${what}: ${String(e.message).replace(/^runClips: /, '')}`);
219
+ }
220
+ const sgn = to >= from ? 1 : -1,
221
+ cable = v.cable != null ? num(v.cable) : SERVICE_DEFAULTS.cable.value,
222
+ list = [];
98
223
  // a mount on the same slot: no clip under its plate; one each side of it instead, and the wire said to go round it
99
- const cw = fittingModel({ kind: 'cable-clip', profile: B.profile.name, face: faceOf(B, q), cable }, context, material, what).width, keep = cw / 2 + SERVICE_DEFAULTS.gap.value;
100
- const rlo = Math.min(from, to), rhi = Math.max(from, to), round = plates.filter((pl) => pl.beam === bid && pl.slot === q.name && pl.lo - keep < rhi && pl.hi + keep > rlo).map((pl) => ({ ...pl, lo: r3(pl.lo - keep), hi: r3(pl.hi + keep) }));
224
+ const cw = fittingModel(
225
+ { kind: 'cable-clip', profile: B.profile.name, face: faceOf(B, q), cable },
226
+ context,
227
+ material,
228
+ what,
229
+ ).width,
230
+ keep = cw / 2 + SERVICE_DEFAULTS.gap.value;
231
+ const rlo = Math.min(from, to),
232
+ rhi = Math.max(from, to),
233
+ round = plates
234
+ .filter((pl) => pl.beam === bid && pl.slot === q.name && pl.lo - keep < rhi && pl.hi + keep > rlo)
235
+ .map((pl) => ({ ...pl, lo: r3(pl.lo - keep), hi: r3(pl.hi + keep) }));
101
236
  let ds = clips.at.map((s) => r3(from + sgn * s));
102
237
  if (round.length) {
103
238
  ds = ds.filter((d) => !round.some((pl) => d > pl.lo && d < pl.hi));
104
- for (const pl of round) for (const e of [pl.lo, pl.hi]) if (e >= rlo - 1e-9 && e <= rhi + 1e-9 && !round.some((o) => e > o.lo + 1e-9 && e < o.hi - 1e-9) && !ds.some((d) => Math.abs(d - e) < cw)) ds.push(e);
239
+ for (const pl of round)
240
+ for (const e of [pl.lo, pl.hi])
241
+ if (
242
+ e >= rlo - 1e-9 &&
243
+ e <= rhi + 1e-9 &&
244
+ !round.some((o) => e > o.lo + 1e-9 && e < o.hi - 1e-9) &&
245
+ !ds.some((d) => Math.abs(d - e) < cw)
246
+ )
247
+ ds.push(e);
105
248
  ds.sort((x, y) => sgn * (x - y));
106
- if (!ds.length) throw new Error(`${what}: a run along ${bid}.${q.name} from ${mm(from)} to ${mm(to)} mm lies under ${round.map((pl) => pl.mount).join(' and ')}: no clip has room there; run it along another face`);
249
+ if (!ds.length)
250
+ throw new Error(
251
+ `${what}: a run along ${bid}.${q.name} from ${mm(from)} to ${mm(to)} mm lies under ${round.map((pl) => pl.mount).join(' and ')}: no clip has room there; run it along another face`,
252
+ );
107
253
  }
108
254
  for (const d of ds) {
109
255
  const cid = free(`${w.id || `w${wi + 1}`}-clip`);
110
- added.push({ id: cid, fitting: { kind: 'cable-clip', profile: B.profile.name, face: faceOf(B, q), cable }, at: `${bid}.${q.name}@${d}`, runOf: w.id || `w${wi + 1}` });
111
- fits.push({ a: cid, b: bid, fastens: true, note: `${cid}: snapped into ${bid}'s ${q.name} slot, its barbs under the lips` }); // (no screw: its barbs hold it)
112
- via.push(`${cid}.cable`); list.push(cid);
256
+ added.push({
257
+ id: cid,
258
+ fitting: { kind: 'cable-clip', profile: B.profile.name, face: faceOf(B, q), cable },
259
+ at: `${bid}.${q.name}@${d}`,
260
+ runOf: w.id || `w${wi + 1}`,
261
+ });
262
+ fits.push({
263
+ a: cid,
264
+ b: bid,
265
+ fastens: true,
266
+ note: `${cid}: snapped into ${bid}'s ${q.name} slot, its barbs under the lips`,
267
+ }); // (no screw: its barbs hold it)
268
+ via.push(`${cid}.cable`);
269
+ list.push(cid);
113
270
  }
114
- runs.push({ wire: w.id || `w${wi + 1}`, along: `${bid}.${q.name}`, from, to, length: r3(Math.abs(to - from)), clips: list, count: list.length, pitch: clips.pitch, round: round.map((pl) => ({ mount: pl.mount, item: pl.item, from: pl.lo, to: pl.hi })), most: v.pitch != null ? num(v.pitch) : SERVICE_DEFAULTS.pitch.value, cable });
271
+ runs.push({
272
+ wire: w.id || `w${wi + 1}`,
273
+ along: `${bid}.${q.name}`,
274
+ from,
275
+ to,
276
+ length: r3(Math.abs(to - from)),
277
+ clips: list,
278
+ count: list.length,
279
+ pitch: clips.pitch,
280
+ round: round.map((pl) => ({ mount: pl.mount, item: pl.item, from: pl.lo, to: pl.hi })),
281
+ most: v.pitch != null ? num(v.pitch) : SERVICE_DEFAULTS.pitch.value,
282
+ cable,
283
+ });
115
284
  }
116
285
  return { ...w, via };
117
286
  });
118
- const out = { ...a, items: [...items.flatMap((it) => [...(ahead.has(it.id) ? [ahead.get(it.id)] : []), replaced.get(it.id) ?? it]), ...added], ...(fasten.length ? { fasten: [...(a.fasten || []), ...fasten] } : {}), ...(runs.length ? { wires } : {}), ...(fits.length ? { fits: [...(a.fits || []), ...fits] } : {}) };
287
+ const out = {
288
+ ...a,
289
+ items: [
290
+ ...items.flatMap((it) => [...(ahead.has(it.id) ? [ahead.get(it.id)] : []), replaced.get(it.id) ?? it]),
291
+ ...added,
292
+ ],
293
+ ...(fasten.length ? { fasten: [...(a.fasten || []), ...fasten] } : {}),
294
+ ...(runs.length ? { wires } : {}),
295
+ ...(fits.length ? { fits: [...(a.fits || []), ...fits] } : {}),
296
+ };
119
297
  return { a: out, mounts, runs };
120
298
  }
121
299
 
@@ -125,8 +303,39 @@ export function expandServices(a, num, context = framesContext(), material = 'pl
125
303
  * @param {object} s a built assembly @param {Function} f the findings' sink
126
304
  */
127
305
  export function serviceFindings(s, f) {
128
- for (const m of s.mounts ?? []) f('info', `${m.id}: on a printed mount (${m.mount}) at ${m.on}, held by its ${m.holes} ${m.fix === 'tapped' ? `tapped ${m.thread} holes from ${m.set}'s rule set, screwed up from under the mount` : `holes from ${m.set}'s rule set, ${m.thread} screws down into the mount`}; the mount ${mm(m.grams)} g, ${mm(m.margin)}× its load`, null, { code: 'service.mount', refs: { item: m.id, mount: m.mount, beam: m.beam, set: m.set }, values: { holes: m.holes, length: m.length, grams: m.grams, margin: m.margin } });
129
- for (const r of s.runs ?? []) f('info', `${r.wire}: ${mm(r.length)} mm along ${r.along} from ${mm(r.from)} to ${mm(r.to)} mm, held by ${r.count} cable clip${r.count > 1 ? 's' : ''} ${r.count > 1 ? (r.round?.length ? `no more than ${mm(r.most)} mm apart but across ${r.round.map((x) => `${x.mount} (${mm(x.to - x.from)} mm, a clip each side)`).join(' and ')},` : `${mm(r.pitch)} mm apart (no more than ${mm(r.most)})`) : ''} for a ${mm(r.cable)} mm bundle`.trimEnd(), null, { code: 'wire.run', refs: { wire: r.wire, along: r.along, clips: r.clips }, values: { length: r.length, clips: r.count, pitch: r.pitch } });
306
+ for (const m of s.mounts ?? [])
307
+ f(
308
+ 'info',
309
+ `${m.id}: on a printed mount (${m.mount}) at ${m.on}, held by its ${m.holes} ${m.fix === 'tapped' ? `tapped ${m.thread} holes from ${m.set}'s rule set, screwed up from under the mount` : `holes from ${m.set}'s rule set, ${m.thread} screws down into the mount`}; the mount ${mm(m.grams)} g, ${mm(m.margin)}× its load`,
310
+ null,
311
+ {
312
+ code: 'service.mount',
313
+ refs: { item: m.id, mount: m.mount, beam: m.beam, set: m.set },
314
+ values: { holes: m.holes, length: m.length, grams: m.grams, margin: m.margin },
315
+ },
316
+ );
317
+ for (const r of s.runs ?? [])
318
+ f(
319
+ 'info',
320
+ `${r.wire}: ${mm(r.length)} mm along ${r.along} from ${mm(r.from)} to ${mm(r.to)} mm, held by ${r.count} cable clip${r.count > 1 ? 's' : ''} ${r.count > 1 ? (r.round?.length ? `no more than ${mm(r.most)} mm apart but across ${r.round.map((x) => `${x.mount} (${mm(x.to - x.from)} mm, a clip each side)`).join(' and ')},` : `${mm(r.pitch)} mm apart (no more than ${mm(r.most)})`) : ''} for a ${mm(r.cable)} mm bundle`.trimEnd(),
321
+ null,
322
+ {
323
+ code: 'wire.run',
324
+ refs: { wire: r.wire, along: r.along, clips: r.clips },
325
+ values: { length: r.length, clips: r.count, pitch: r.pitch },
326
+ },
327
+ );
130
328
  // a run under a mount's plate: its clips are set either side, and the wire cannot lie in the slot under the plate
131
- for (const r of s.runs ?? []) for (const x of r.round ?? []) f('warn', `${r.wire}: its run along ${r.along} passes ${x.mount} (${x.item}'s mount) from ${mm(x.from)} to ${mm(x.to)} mm: no clip goes under the plate, so one is set each side of it, and the wire must go round the mount there: run it along another face, or end the run before the mount`, `${r.wire}: round ${x.mount}`, { code: 'wire.run', refs: { wire: r.wire, along: r.along, mount: x.mount, item: x.item }, values: { from: x.from, to: x.to } });
329
+ for (const r of s.runs ?? [])
330
+ for (const x of r.round ?? [])
331
+ f(
332
+ 'warn',
333
+ `${r.wire}: its run along ${r.along} passes ${x.mount} (${x.item}'s mount) from ${mm(x.from)} to ${mm(x.to)} mm: no clip goes under the plate, so one is set each side of it, and the wire must go round the mount there: run it along another face, or end the run before the mount`,
334
+ `${r.wire}: round ${x.mount}`,
335
+ {
336
+ code: 'wire.run',
337
+ refs: { wire: r.wire, along: r.along, mount: x.mount, item: x.item },
338
+ values: { from: x.from, to: x.to },
339
+ },
340
+ );
132
341
  }