@rulecad/cad 0.7.8 → 0.7.9

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 (2) hide show
  1. package/lib/live.mjs +11 -5
  2. package/package.json +1 -1
package/lib/live.mjs CHANGED
@@ -59,8 +59,8 @@ function views(d, { nx, ny, nz = 1 }) {
59
59
  const page = (title) => `<!doctype html><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1">
60
60
  <title>${title}</title>
61
61
  <style>body{font:15px system-ui;background:#111;color:#eee;margin:16px;max-width:900px}canvas{background:#000;border-radius:6px}.chart{width:100%}#hint{color:#888;font-size:12px;text-align:center;margin:-4px 0 8px}#model{height:50vh;margin-bottom:8px;border-radius:6px;overflow:hidden;background:#000;cursor:grab;touch-action:none}#views{display:flex;gap:8px;align-items:flex-end}figure{flex:1;min-width:0;margin:0;text-align:center}figure canvas{width:100%;height:40vh;object-fit:contain;background:none}figcaption{color:#aaa;font-size:13px;text-align:center}
62
- #chart{height:160px;touch-action:none}#scrub{display:flex;gap:8px;align-items:center}#scrub input{flex:1}#live{background:#357}table{border-collapse:collapse;margin:10px 0;width:100%}td{padding:3px 8px 3px 0;vertical-align:top}td:first-child{color:#999;white-space:nowrap;width:1%}button{font:inherit;padding:8px 16px;border-radius:6px;border:0;background:#d33;color:#fff}button:disabled{background:#555}#state{margin:10px 0}</style>
63
- <h2>${title}</h2><div id="state">waiting for the first step…</div><div id="model" hidden></div><div id="hint" hidden>drag to turn it · double-tap to stop or start it turning</div><div id="views"></div><canvas class="chart" id="chart" width="900" height="160"></canvas><div id="scrub"><input type="range" id="at" min="0" max="0" value="0"><button id="live" disabled>Live</button></div><table id="facts"></table>
62
+ #chart{height:160px;touch-action:none}#scrub{display:flex;gap:8px;align-items:center;position:sticky;bottom:0;z-index:2;background:#111;padding:10px 0;border-top:1px solid #222}#scrub input{flex:1;height:32px}#at-step{color:#aaa;font-size:13px;min-width:5.5em}#live{background:#357}table{border-collapse:collapse;margin:10px 0;width:100%}td{padding:3px 8px 3px 0;vertical-align:top}td:first-child{color:#999;white-space:nowrap;width:1%}button{font:inherit;padding:8px 16px;border-radius:6px;border:0;background:#d33;color:#fff}button:disabled{background:#555}#state{margin:10px 0}</style>
63
+ <h2>${title}</h2><div id="state">waiting for the first step…</div><div id="model" hidden></div><div id="hint" hidden>drag to turn it · double-tap to stop or start it turning</div><div id="views"></div><canvas class="chart" id="chart" width="900" height="160"></canvas><div id="scrub"><span id="at-step"></span><input type="range" id="at" min="0" max="0" value="0"><button id="live" disabled>Live</button></div><table id="facts"></table>
64
64
  <p><button id="stop">Stop the run</button> <span id="note"></span></p>
65
65
  <script>
66
66
  const views = document.getElementById('views'), facts = document.getElementById('facts'), state = document.getElementById('state'), stop = document.getElementById('stop');
@@ -78,6 +78,7 @@ function table() {
78
78
  ...(f.volume != null ? [['Material', fig(f.volume * 100) + '% of the space']] : []), ...(f.stress != null ? [['Peak stress', fig(f.stress) + ' MPa']] : []),
79
79
  ['Cells', [f.grid.nx, f.grid.ny, f.grid.nz].filter(Boolean).join(' × ') + (f.grid.h ? ' of ' + f.grid.h + ' mm' : '') + ' (' + (f.grid.nx * f.grid.ny * (f.grid.nz || 1)).toLocaleString('en-GB') + ')'],
80
80
  ] : [];
81
+ document.getElementById('at-step').textContent = f ? 'step ' + f.step : '';
81
82
  facts.innerHTML = [...(finished ? [['Result', finished]] : []), ...rows, ...about].map(([k, v]) => '<tr><td>' + esc(k) + '</td><td>' + esc(v) + '</td></tr>').join('');
82
83
  }
83
84
  function draw(f) {
@@ -107,7 +108,9 @@ function plot() {
107
108
  c.font = '12px system-ui'; c.fillStyle = '#6cf'; c.fillText('compliance, N·mm: ' + fig(history.compliance[0]) + ' to ' + fig(history.compliance.at(-1)), 8, 14);
108
109
  c.fillStyle = '#fc6'; c.textAlign = 'right'; c.fillText('change (log scale): ' + fig(history.change[0]) + ' to ' + fig(history.change.at(-1)), w - 8, 14); c.textAlign = 'left';
109
110
  }
110
- function show(f) { draw(f); plot(); table(); window.model3d?.(shown, f.grid); }
111
+ // The 3D view's step: remembered, so the 3D script picks it up when it loads (it loads after the first steps arrive)
112
+ const want3d = (n, grid) => { window.wanted3d = [n, grid]; window.model3d?.(n, grid); };
113
+ function show(f) { draw(f); plot(); table(); want3d(shown, f.grid); }
111
114
  let lastModel = 0; // while following, a new surface at most every two seconds
112
115
  // Scrubbing: any earlier step, fetched when asked for; the newest only while following
113
116
  let asked = 0;
@@ -126,7 +129,7 @@ events.onmessage = (e) => { const m = JSON.parse(e.data); if (m.about) about = m
126
129
  if (m.done) { finished = m.done; stop.disabled = true; events.close(); }
127
130
  at.max = Math.max(0, history.compliance.length - 1);
128
131
  if (m.frame) newest = m.frame;
129
- if (follow) { shown = Number(at.max); at.value = shown; if (newest) draw(newest); if (Date.now() - lastModel > 2000 || finished) { lastModel = Date.now(); window.model3d?.(shown, newest.grid); } }
132
+ if (follow) { shown = Number(at.max); at.value = shown; if (newest) draw(newest); if (Date.now() - lastModel > 2000 || finished) { lastModel = Date.now(); want3d(shown, newest.grid); } }
130
133
  if (finished) state.textContent = finished;
131
134
  plot(); table(); };
132
135
  stop.onclick = async () => { stop.disabled = true; await fetch('stop', { method: 'POST' }); document.getElementById('note').textContent = 'stopping after this step'; };
@@ -152,7 +155,9 @@ function setup() {
152
155
  const w = box.clientWidth, h = box.clientHeight;
153
156
  if (w && (c.width !== Math.round(w * devicePixelRatio) || c.height !== Math.round(h * devicePixelRatio))) { renderer.setPixelRatio(devicePixelRatio); renderer.setSize(w, h); camera.aspect = w / h; camera.updateProjectionMatrix(); }
154
157
  if (spin) yaw += 0.004;
155
- const d = size / Math.sin(camera.fov * Math.PI / 360) * 0.8; // the part seldom fills its grid's corners camera.position.set(d * Math.cos(tilt) * Math.cos(yaw), d * Math.cos(tilt) * Math.sin(yaw), d * Math.sin(tilt)); camera.lookAt(0, 0, 0);
158
+ // Far enough to fit the grid's half-diagonal in view, less a little: the part seldom fills its grid's corners
159
+ const d = size / Math.sin(camera.fov * Math.PI / 360) * 0.8;
160
+ camera.position.set(d * Math.cos(tilt) * Math.cos(yaw), d * Math.cos(tilt) * Math.sin(yaw), d * Math.sin(tilt)); camera.lookAt(0, 0, 0);
156
161
  renderer.render(scene, camera); requestAnimationFrame(tick);
157
162
  };
158
163
  tick();
@@ -181,6 +186,7 @@ async function load(n, grid) {
181
186
  }
182
187
  }
183
188
  window.model3d = (n, grid) => { if (!box.hidden && grid) load(n, grid); };
189
+ if (window.wanted3d) window.model3d(...window.wanted3d);
184
190
  </script>`;
185
191
 
186
192
  const THREE = path.dirname(createRequire(import.meta.url).resolve('three')); // three's build files, for the 3D view
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rulecad/cad",
3
- "version": "0.7.8",
3
+ "version": "0.7.9",
4
4
  "description": "The cad command: JSCAD designs from traceable rules, checked for printing and fit, versioned by what fits, shared as links and exported as Bambu 3MF.",
5
5
  "type": "module",
6
6
  "bin": {