@rulecad/cad 0.8.0 → 0.10.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 (102) hide show
  1. package/AGENTS.md +45 -16
  2. package/CHANGELOG.md +724 -0
  3. package/EXAMPLES.md +61 -54
  4. package/README.md +376 -98
  5. package/TUTORIAL.md +2 -2
  6. package/bin/cad.mjs +2664 -541
  7. package/lib/animate.mjs +173 -49
  8. package/lib/assembly.mjs +1883 -435
  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/cache-file.mjs +105 -0
  15. package/lib/carried.mjs +201 -0
  16. package/lib/clone.mjs +194 -42
  17. package/lib/code-text.mjs +28 -0
  18. package/lib/design-imports.mjs +127 -0
  19. package/lib/design.mjs +871 -147
  20. package/lib/designshapes.mjs +142 -0
  21. package/lib/drive.mjs +187 -63
  22. package/lib/edit.mjs +922 -192
  23. package/lib/errors.mjs +16 -3
  24. package/lib/estimates.mjs +51 -0
  25. package/lib/explain.mjs +62 -13
  26. package/lib/fasten.mjs +2708 -507
  27. package/lib/fe-key.mjs +29 -0
  28. package/lib/fittings.mjs +721 -122
  29. package/lib/fixings.mjs +38 -13
  30. package/lib/framebuild.mjs +790 -175
  31. package/lib/framecheck.mjs +1901 -368
  32. package/lib/framegen.mjs +108 -22
  33. package/lib/frameheat.mjs +225 -42
  34. package/lib/frameprint.mjs +513 -108
  35. package/lib/frames.mjs +86 -18
  36. package/lib/framesize.mjs +719 -120
  37. package/lib/frametip.mjs +235 -0
  38. package/lib/gait.mjs +135 -23
  39. package/lib/grip.mjs +62 -13
  40. package/lib/guides.mjs +1403 -230
  41. package/lib/host.mjs +129 -23
  42. package/lib/inplace.mjs +171 -36
  43. package/lib/jigs.mjs +360 -78
  44. package/lib/joins.mjs +697 -118
  45. package/lib/jsonedit.mjs +88 -26
  46. package/lib/kept.mjs +84 -0
  47. package/lib/kit.mjs +439 -69
  48. package/lib/layout.mjs +2 -1
  49. package/lib/links.mjs +149 -42
  50. package/lib/list.mjs +334 -64
  51. package/lib/live-guard.mjs +68 -0
  52. package/lib/live-shape.mjs +96 -24
  53. package/lib/live.mjs +189 -59
  54. package/lib/loads.mjs +597 -136
  55. package/lib/machine.mjs +372 -74
  56. package/lib/magnets.mjs +162 -44
  57. package/lib/measured.mjs +1080 -117
  58. package/lib/mesh.mjs +526 -119
  59. package/lib/meshcmd.mjs +215 -60
  60. package/lib/motors.mjs +1002 -214
  61. package/lib/motorsvg.mjs +114 -32
  62. package/lib/names.mjs +18 -1
  63. package/lib/optimise.mjs +991 -287
  64. package/lib/order.mjs +515 -114
  65. package/lib/panels.mjs +482 -94
  66. package/lib/parts.mjs +81 -23
  67. package/lib/pins.mjs +163 -44
  68. package/lib/plates.mjs +223 -35
  69. package/lib/player.mjs +37 -9
  70. package/lib/power.mjs +64 -13
  71. package/lib/preview.mjs +83 -16
  72. package/lib/profilemeasure.mjs +572 -129
  73. package/lib/rules.mjs +17 -6
  74. package/lib/sandbox-hooks.mjs +179 -27
  75. package/lib/sandbox-lock.mjs +225 -0
  76. package/lib/sandbox-preload.mjs +2 -2
  77. package/lib/sandbox-run.mjs +122 -25
  78. package/lib/sandbox.mjs +667 -75
  79. package/lib/schema.mjs +42 -11
  80. package/lib/seats.mjs +227 -49
  81. package/lib/services.mjs +261 -52
  82. package/lib/sheet.mjs +963 -179
  83. package/lib/slotnuts.mjs +213 -34
  84. package/lib/targets/gist.mjs +4 -1
  85. package/lib/targets.mjs +22 -4
  86. package/lib/task.mjs +376 -79
  87. package/lib/versions.mjs +285 -39
  88. package/lib/wires.mjs +228 -45
  89. package/lib/workspace.mjs +200 -14
  90. package/package.json +19 -19
  91. package/schemas/assembly.schema.json +2 -2
  92. package/schemas/project.schema.json +6 -0
  93. package/templates/coupons/MEASURE.md +109 -0
  94. package/templates/coupons/assemblies/fixings-test.json +20 -0
  95. package/templates/coupons/assemblies/slot-test.json +11 -0
  96. package/templates/coupons/objects/fixings-coupon.js +88 -0
  97. package/templates/coupons/objects/fixings-coupon.json +26 -0
  98. package/templates/coupons/objects/holds-coupon.js +130 -0
  99. package/templates/coupons/objects/holds-coupon.json +42 -0
  100. package/templates/coupons/objects/slot-coupon.js +89 -0
  101. package/templates/coupons/objects/slot-coupon.json +29 -0
  102. package/templates/coupons/project.json +10 -0
package/lib/fixings.mjs CHANGED
@@ -2,39 +2,64 @@
2
2
  // the workspace's own thread sets before the kit's, the project's printer, and the design's booleans (v.ops); where a
3
3
  // call names no material, the project's is taken for what a thread is in or a head sits on (a hole, engagement,
4
4
  // stripping, seating: never a screw's own steel). What each call found is kept, so cad check says what every hole
5
- // and seat was drawn to. No files are read here: the sandbox's runner uses it as the build does.
5
+ // and seat was drawn to. In an object that is not printed (a reference: a bought circuit board, drilled by its maker),
6
+ // a hole is drawn to its rule's figure as it stands, with no hole compensation. No files are read here: the sandbox's
7
+ // runner uses it as the build does.
6
8
  import { fixingsFor } from '@rulecad/fixings';
7
9
 
8
10
  // The functions whose material is the part's (the plastic a pilot is formed in, what a thread or a head bears on)
9
11
  const IN_PART = ['hole', 'holeModel', 'engagement', 'stripping', 'seating'];
12
+ // The functions that draw a hole to a figure and add the printer's hole compensation to it, which take printed: false
13
+ const HOLES = ['hole', 'holeModel'];
10
14
  const isOptions = (o) => o && typeof o === 'object' && !Array.isArray(o);
11
15
 
12
16
  /**
13
17
  * @rulecad/fixings bound to a design's project, with what its calls found.
14
- * @param {{ sets?: object, printer?: object, material?: string | null, ops?: object }} context sets: the workspace's rule
15
- * sets by name (threads, materials); printer: the printer's rule set ({ name, rules }); material: the project's; ops: v.ops
18
+ * @param {{ sets?: object, printer?: object, material?: string | null, ops?: object, printed?: boolean }} context sets:
19
+ * the workspace's rule sets by name (threads, materials); printer: the printer's rule set ({ name, rules }); material:
20
+ * the project's; ops: v.ops; printed: false for an object that is not printed (a reference), whose holes then get no
21
+ * hole compensation unless a call says printed itself
16
22
  * @returns {{ fixings: Record<string, Function>, found: () => object[], used: () => boolean }} fixings: v.fixings;
17
23
  * found: the findings of every model made, each said once (values.count where it came up again); used: whether the design called any of it
18
24
  */
19
- export function designFixings({ sets, printer, material, ops } = {}) {
20
- const bound = fixingsFor({ ...(sets && Object.keys(sets).length ? { sets } : {}), ...(printer ? { printer } : {}), ...(ops ? { ops } : {}) });
21
- const found = new Map(); let calls = 0;
25
+ export function designFixings({ sets, printer, material, ops, printed = true } = {}) {
26
+ const bound = fixingsFor({
27
+ ...(sets && Object.keys(sets).length ? { sets } : {}),
28
+ ...(printer ? { printer } : {}),
29
+ ...(ops ? { ops } : {}),
30
+ });
31
+ const found = new Map();
32
+ let calls = 0;
22
33
  const keep = (r) => {
23
34
  const list = Array.isArray(r) ? r : (r?.model ?? r)?.findings;
24
- if (Array.isArray(list)) for (const x of list) {
25
- if (!x || typeof x.text !== 'string' || typeof x.level !== 'string') continue;
26
- const k = `${x.level}|${x.code}|${x.text}`, had = found.get(k);
27
- if (had) had.values = { ...had.values, count: (had.values?.count ?? 1) + 1 }; else found.set(k, { ...x });
28
- }
35
+ if (Array.isArray(list))
36
+ for (const x of list) {
37
+ if (!x || typeof x.text !== 'string' || typeof x.level !== 'string') continue;
38
+ const k = `${x.level}|${x.code}|${x.text}`,
39
+ had = found.get(k);
40
+ if (had) had.values = { ...had.values, count: (had.values?.count ?? 1) + 1 };
41
+ else found.set(k, { ...x });
42
+ }
29
43
  return r;
30
44
  };
31
45
  const fixings = {};
32
46
  for (const [k, f] of Object.entries(bound)) {
33
- if (typeof f !== 'function') { fixings[k] = f; continue; }
47
+ if (typeof f !== 'function') {
48
+ fixings[k] = f;
49
+ continue;
50
+ }
34
51
  const lead = k === 'lengthFor' ? 2 : 1; // (lengthFor takes the stack first: its options come third)
35
52
  fixings[k] = (...a) => {
36
53
  calls++;
37
- if (material && IN_PART.includes(k) && (a[lead] === undefined || isOptions(a[lead])) && a[lead]?.material == null) a[lead] = { material, ...a[lead] };
54
+ if (material && IN_PART.includes(k) && (a[lead] === undefined || isOptions(a[lead])) && a[lead]?.material == null)
55
+ a[lead] = { material, ...a[lead] };
56
+ if (
57
+ printed === false &&
58
+ HOLES.includes(k) &&
59
+ (a[lead] === undefined || isOptions(a[lead])) &&
60
+ a[lead]?.printed == null
61
+ )
62
+ a[lead] = { printed: false, ...a[lead] };
38
63
  return keep(f(...a));
39
64
  };
40
65
  }