@chanmeng666/archlang-3d 0.3.0 → 0.5.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 CHANGED
@@ -2,6 +2,98 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.5.0] - 2026-11-11
6
+
7
+ The core peer range stays `^1.57.0`. The rooted `import` below works with any core in it; with
8
+ 1.58.0 or later a refused module reports the core's own refusal code.
9
+
10
+ ### Breaking
11
+
12
+ - `archlang3d build`, `check` and `view` can now refuse a plan they built under 0.4.0: an `import`
13
+ outside both the working directory and the plan's own directory, one that is not a `.arch` file,
14
+ or one over 1 MiB is refused (exit 2, the refusal under `E3D_PLAN_ERRORS`; Fixed, below). The
15
+ CLI has no flag to widen the root: run it from a directory that contains the module. A program
16
+ can pass a wider root as the second argument of `makeNodeWorld(baseDir, root)` from
17
+ `@chanmeng666/archlang-3d/node`. Nothing widens the `.arch` or 1 MiB rule.
18
+
19
+ ### Added
20
+
21
+ - For a host page whose canvas follows its container (the playground's 3D stage):
22
+ `handle.resize(width, height)` gives the canvas a new drawing size and redraws the last frame at
23
+ it, the same frame a fresh mount at that size draws; `view.spin(degrees)` turns the view about
24
+ its pivot by one step the host chooses (a turntable), taking the view as a drag does; and
25
+ `viewToolbar(view, { compact: true })` puts Reset first and the six presets in a `View ▾`
26
+ popover, every button keeping its name, `data-*` and `aria-pressed`. All three are opt-in: a
27
+ host that never calls them, and the single-file replay HTML, draw and show exactly what they did.
28
+ - `viewToolbar(view, { storeys: false })` leaves out the "Storeys shown" buttons, for a host with
29
+ its own storey control (the playground). On by default: the replay HTML's toolbar is unchanged.
30
+
31
+ ### Changed
32
+
33
+ - The line every surface carries (`PREVIEW_LABEL`) now says what "checked against the plan" means:
34
+ every 3D element comes from the plan's elements, and every solid is closed. The package
35
+ description says the same; the npm page shows the new README at the next publish.
36
+ - A `winders` landing (core 1.58.0) is built as a level landing for now: its tapered steps are not
37
+ built yet.
38
+
39
+ ### Fixed
40
+
41
+ - An `import` is rooted like the core CLI's: `makeNodeWorld(baseDir, root?)` (and so `archlang3d build`, `check` and `view`) reads a module only from under `root` (default: the working directory) or `baseDir`, with links and junctions followed, only a `.arch` file, and only up to 1 MiB. A refused module is the core's `E_IMPORT_OUTSIDE_ROOT`, `E_IMPORT_NOT_ARCH` or `E_IMPORT_TOO_LARGE` at the `import` (reported through `E3D_PLAN_ERRORS`); with a core older than 1.58 the refusal reads as `E_IMPORT_NOT_FOUND`; the file is still never read. Before, any path an `import` named was read.
42
+
43
+ ## [0.4.0] - 2026-11-06
44
+
45
+ The core peer range is now `^1.57.0` (was `^1.45.0`): 1.57.0 is the first core that exports
46
+ `treadCount`, which the stairs read. With an older core (npm warns of the peer range) everything
47
+ else works as before and no stair is built (`stair-no-flights`).
48
+
49
+ ### Added
50
+
51
+ - Stairs. A straight stair and a turning stair (flights and landings) are built as stepped solids,
52
+ read from the core's own stair: each flight's rectangle, the edge it is climbed from and the
53
+ number of treads the plan draws on it (the core's new `treadCount` export), so the treads stand
54
+ on the drawing's tread lines. A stair climbs to the floor of the storey above in equal risers, one
55
+ per tread plus one at the head of each flight; a landing stands at the height its flight ends on.
56
+ The flight is as wide as the stair's `width`, centred as the plan centres it, and solid down to
57
+ its floor. The void in the floor above stays where the plan puts it.
58
+ - A stair is built once, on the storey it climbs from: a `dir up` stair climbs from its own
59
+ storey, and the `dir down` stop above it is the same stair. A `dir down` stair with no stair of
60
+ its id below is built from the storey below. A `dir up` stair on the top storey climbs that
61
+ storey's height; a `dir down` stair on the lowest storey is not built. Each case is in the
62
+ ledger.
63
+ - Stairs are oak, from the palette's `wood` (the core gives a stair no material), and the ledger
64
+ says so (`stair-material-default`), with the solid form (`stair-solid-default`) and each stair's
65
+ riser count (`stair-risers-from-treads`). In the GLB a stair is a `stair:<id>` node under its
66
+ storey, in a `stair` material, its facts (direction, width, flights, risers, rise) in
67
+ `extras.archlang`. In the replay it rises after its storey's walls. `build --json` counts stairs
68
+ per storey.
69
+ - Scene3D: a stair carries `flights` (each `at`, `size`, `foot` and `treads`) and `landings`. Both
70
+ are optional, so a Scene3D written before 0.4.0 still validates; its stairs are not built
71
+ (`stair-no-flights`). New exports: `stairSolid`, `stairRisers`, `StairSolid`, `STAIR_MATERIAL`.
72
+
73
+ ### Changed
74
+
75
+ - A replay of several storeys ends with the storeys assembled: they still rise one by one, each
76
+ lifted 3 m clear of the one below, and once everything is up they come down to their real heights
77
+ while the camera moves to frame the assembled building. The end frame, the Iso view and Reset show
78
+ the storeys stacked; hiding the storeys above one is the cutaway. Every earlier frame is unchanged.
79
+ `ReplayState` gains `settle` (0 while exploded, 1 at the end) and its `stop` runs on to the storey
80
+ count during the settle; `cameraStops` returns one more fit for several storeys (the assembled
81
+ building, last); `boxOfNodes` takes `settle`. New exports: `settledLift`, `stopCount`. A one-storey
82
+ replay is the same in every frame.
83
+ - The preview's label is the line every ArchLang surface uses: "Same source, plan and 3D preview.
84
+ The 3D preview is extruded from the same .arch file by the separate archlang-3d package, and
85
+ checked against the plan." (`PREVIEW_LABEL`; its first sentence is `PREVIEW_LEAD`). The replay
86
+ HTML also carries the limits line (`PREVIEW_LIMITS`): walls, openings, floors, stairs and furniture
87
+ in flat colours; no pitched roofs yet, and no sections, elevations or BIM. `PREVIEW_ABOUT_URL`
88
+ is the page that says what the preview shows.
89
+ - The side views' buttons are named "View from north" (east, south, west) instead of "North
90
+ elevation" and so on: the 3D preview draws no elevations. The buttons still read N, E, S and W.
91
+ - The ledger row `m1-omits-stairs-outdoor-fences` is now `m1-omits-outdoor-fences`, written once
92
+ for outdoor surfaces and once for fences, which are still not built.
93
+ - `PREVIEW_ABOUT_URL`, the page that says what the 3D preview shows and does not, is the docs
94
+ site's `https://archlang.uk/3d` (it was this package's npm page). The playground's "What it
95
+ shows" link follows it. The replay HTML does not carry the link, so its bytes are unchanged.
96
+
5
97
  ## [0.3.0] - 2026-11-05
6
98
 
7
99
  ### Added
package/README.md CHANGED
@@ -5,7 +5,10 @@
5
5
  your source and the core's drawing as they are.
6
6
 
7
7
  From a plan it writes a replay (one HTML file: the plan draws itself, then the walls rise) and a GLB
8
- for any glTF viewer.
8
+ for any glTF viewer. Same source, plan and 3D preview. The 3D preview is extruded from the same .arch file by the separate archlang-3d package, and checked against the plan: every 3D element comes from the plan's elements, and every solid is closed.
9
+
10
+ 3D preview: walls, openings, floors, stairs and furniture in flat colours; no pitched roofs yet,
11
+ and no sections, elevations or BIM.
9
12
 
10
13
  ## Install
11
14
 
@@ -13,7 +16,7 @@ for any glTF viewer.
13
16
  npm install @chanmeng666/archlang-3d @chanmeng666/archlang
14
17
  ```
15
18
 
16
- Needs Node 20 or newer. The core, `@chanmeng666/archlang`, is a peer dependency at `^1.45.0`. To
19
+ Needs Node 20 or newer. The core, `@chanmeng666/archlang`, is a peer dependency at `^1.57.0`. To
17
20
  follow along, take a plan from the examples the core ships:
18
21
 
19
22
  ```sh
@@ -29,7 +32,15 @@ npx archlang3d view plan.arch --replay -o plan.html
29
32
  `plan.html` opens offline. three.js 0.186.1 is inside the file with its licence notice, and nothing
30
33
  is fetched from a network. `--theme dark` and `--storey <n>` change what it shows.
31
34
 
32
- To render a video as well, add a browser and `ffmpeg` on your `PATH`:
35
+ A plan of several storeys rises storey by storey, each lifted clear of the one below so the floor
36
+ underneath stays in view, and at the end the storeys come down to stand on each other at their real
37
+ heights.
38
+
39
+ The view turns freely: drag to rotate, scroll or pinch to zoom, right-drag or two fingers to pan,
40
+ and the buttons give Iso, Top, the views from north, east, south and west, and Reset (and, with several storeys, hide the
41
+ storeys above one). Moving the view pauses the playback.
42
+
43
+ To make a video as well, add a browser and `ffmpeg` on your `PATH`:
33
44
 
34
45
  ```sh
35
46
  npx playwright-core install chromium
package/dist/browser.d.ts CHANGED
@@ -1,8 +1,8 @@
1
- import { P as PresetName, V as Vec3 } from './camera-CLNYQ1Xv.js';
1
+ import { P as PresetName, V as Vec3 } from './camera-DVOiag0F.js';
2
2
  import { ReplayPayload } from './replay.js';
3
- export { PREVIEW_LABEL, ReplayNode, ReplayOptions, replayPayload, viewBoxOf } from './replay.js';
4
- import { S as StripItem } from './strip-CN_dTKqy.js';
5
- export { R as ReplayFacts, s as stripAt } from './strip-CN_dTKqy.js';
3
+ export { PREVIEW_ABOUT_URL, PREVIEW_LABEL, PREVIEW_LEAD, PREVIEW_LIMITS, ReplayNode, ReplayOptions, replayPayload, viewBoxOf } from './replay.js';
4
+ import { S as StripItem } from './strip-Nt7eJ-4E.js';
5
+ export { R as ReplayFacts, s as stripAt } from './strip-Nt7eJ-4E.js';
6
6
 
7
7
  interface ReplayHandle {
8
8
  /** Render the frame at replay time `t` (clamped to [0, 1]) into the canvas, synchronously. */
@@ -15,6 +15,14 @@ interface ReplayHandle {
15
15
  dispose: () => void;
16
16
  /** The camera the user moves (card CR4); present when mounted with `interactive: true`. */
17
17
  view?: ViewControl;
18
+ /**
19
+ * Give the canvas a new drawing size (a host whose canvas follows its container, playground card
20
+ * PG1) and redraw the last frame at it. Everything the frame reads from the size (the drawing's
21
+ * frame, the cameras' aspect, the stops' framing, the presets) is worked out again as a mount at
22
+ * that size works it out, so after `resize(w, h)` the frame at `t` is the frame a fresh mount at
23
+ * `w`×`h` draws at `t`. Never called, nothing changes: the payload's size is the canvas's.
24
+ */
25
+ resize: (width: number, height: number) => void;
18
26
  }
19
27
 
20
28
  /** Who holds the camera: the replay, a preset, or the user's own orbit. */
@@ -60,6 +68,13 @@ interface ViewControl {
60
68
  restore: (s: ViewState) => void;
61
69
  /** Hear when `camera` or `shown` changes (a drag, a preset, a seek, a restore); returns the unsubscribe. */
62
70
  onChange: (fn: () => void) => () => void;
71
+ /**
72
+ * Turn the view `degrees` about its pivot, as a drag across would (a host's turntable, playground
73
+ * card PG1), and draw it. The host chooses each step; nothing here reads a clock. The first step
74
+ * takes the view from the replay or a preset (the camera becomes "free", `onTake`), from the
75
+ * frame on the canvas. A host that never calls it draws exactly what it drew before.
76
+ */
77
+ spin: (degrees: number) => void;
63
78
  }
64
79
  interface MountOptions {
65
80
  /**
@@ -89,7 +104,10 @@ declare function mountReplay(out: HTMLCanvasElement, p: ReplayPayload, strip?: H
89
104
  * the canvas.
90
105
  */
91
106
 
92
- /** Each preset's button text and its accessible name. */
107
+ /**
108
+ * Each preset's button text and its accessible name. The side views are "View from north" and so
109
+ * on, never "elevation": the 3D preview draws no elevations (the PS-D12 limits line).
110
+ */
93
111
  declare const PRESET_LABELS: ReadonlyArray<readonly [PresetName, string, string]>;
94
112
  declare const VIEW_HINT = "Drag to turn, right-drag to pan, scroll to zoom; on the focused view, arrow keys turn and + / \u2212 zoom.";
95
113
  /**
@@ -102,8 +120,22 @@ interface ToolbarOptions {
102
120
  buttonClass?: string;
103
121
  /** An id for the hint line, so the canvas can point at it (`aria-describedby`). */
104
122
  hintId?: string;
123
+ /**
124
+ * The compact form, for a host that lays the toolbar over its canvas (playground card PG1): Reset
125
+ * first ("⟲ Reset"), then a "View ▾" button whose popover holds the preset buttons, then the
126
+ * storeys and the hint. Every button keeps its text, accessible name, `data-*` and `aria-pressed`;
127
+ * only where the presets sit changes. Off by default: the row the replay HTML shows.
128
+ */
129
+ compact?: boolean;
130
+ /**
131
+ * The "Storeys shown" cut-away buttons (a plan of more than one storey). On by default: the row
132
+ * the replay HTML shows. `false` leaves them out, for a host with its own storey control that
133
+ * already chooses which storeys the view shows (the playground's storey switcher, card PG5b), so
134
+ * the page has one storey control, not two. `view.showStoreys` is unchanged either way.
135
+ */
136
+ storeys?: boolean;
105
137
  }
106
- /** The toolbar for `view`: preset buttons, Reset, the storeys (more than one), the hint. */
138
+ /** The toolbar for `view`: preset buttons, Reset, the storeys (more than one, unless `storeys: false`), the hint. */
107
139
  declare function viewToolbar(view: ViewControl, opts?: ToolbarOptions): HTMLElement;
108
140
 
109
141
  /** The strip's DOM half, apart from `strip.ts` so that the types of `.` and `./node` need no DOM lib. */
package/dist/browser.js CHANGED
@@ -1,12 +1,15 @@
1
1
  import {
2
2
  PRESET_LABELS,
3
+ PREVIEW_ABOUT_URL,
3
4
  PREVIEW_LABEL,
5
+ PREVIEW_LEAD,
6
+ PREVIEW_LIMITS,
4
7
  VIEW_CONTROLS_LABEL,
5
8
  VIEW_HINT,
6
9
  replayPayload,
7
10
  viewBoxOf,
8
11
  viewToolbar
9
- } from "./chunk-WBA4LABI.js";
12
+ } from "./chunk-4SQ5YKKX.js";
10
13
  import {
11
14
  ELEVATION_RANGE,
12
15
  END_AZIMUTH,
@@ -24,12 +27,14 @@ import {
24
27
  frameCamera,
25
28
  pivotAbove,
26
29
  presetCamera,
30
+ settledLift,
27
31
  slotColour,
28
32
  stateAt,
33
+ stopCount,
29
34
  stripAt,
30
35
  takenLens,
31
36
  targetBounds
32
- } from "./chunk-VPYTRKMK.js";
37
+ } from "./chunk-EQBMPXB5.js";
33
38
 
34
39
  // src/replay/mount.ts
35
40
  import {
@@ -94,7 +99,8 @@ var THEMES = {
94
99
  "window:frame": "#5d86a8",
95
100
  "window:glass": "#86c5ee",
96
101
  "wall:demolish": "#e07a5f",
97
- furniture: "#3f6a8f"
102
+ furniture: "#3f6a8f",
103
+ stair: "#5d86a8"
98
104
  }
99
105
  }
100
106
  };
@@ -113,8 +119,8 @@ var FOOTPRINT_MM = 12;
113
119
  function mountReplay(out, p, strip, opts = {}) {
114
120
  const theme = THEMES[p.theme];
115
121
  const furniture = theme.colors.furniture;
116
- const W = p.width;
117
- const H = p.height;
122
+ let W = p.width;
123
+ let H = p.height;
118
124
  const gl = document.createElement("canvas");
119
125
  gl.width = W;
120
126
  gl.height = H;
@@ -215,11 +221,11 @@ function mountReplay(out, p, strip, opts = {}) {
215
221
  }
216
222
  g.visible = false;
217
223
  scene.add(g);
218
- nodes.set(n.key, { g, flat: Math.min(1, FOOTPRINT_MM / Math.max(1e-6, topY - base)) });
224
+ nodes.set(n.key, { g, flat: Math.min(1, FOOTPRINT_MM / Math.max(1e-6, topY - base)), base, lift: n.lift ?? 0 });
219
225
  }
220
226
  const [vx, vy, vw, vh] = p.viewBox;
221
- const aspect = W / H;
222
- const { cx, cz, ow, oh } = drawingFrame(p.viewBox, aspect);
227
+ let aspect = W / H;
228
+ let { cx, cz, ow, oh } = drawingFrame(p.viewBox, aspect);
223
229
  const box = boxOfNodes(p.nodes, { ghosts: true });
224
230
  const lo = new Vector3(...box.lo);
225
231
  const hi = new Vector3(...box.hi);
@@ -229,15 +235,16 @@ function mountReplay(out, p, strip, opts = {}) {
229
235
  ortho.position.set(cx, top + 5e4, cz);
230
236
  ortho.lookAt(cx, 0, cz);
231
237
  const persp = new PerspectiveCamera(START_FOV, aspect, 10, 1e9);
232
- const orbit = { elevation: p.elevation, azimuth: END_AZIMUTH, fov: END_FOV, aspect };
233
- const fits = cameraStops(p.nodes, p.events, orbit);
238
+ const fitsAt = (a) => cameraStops(p.nodes, p.events, { elevation: p.elevation, azimuth: END_AZIMUTH, fov: END_FOV, aspect: a });
239
+ let fits = fitsAt(aspect);
234
240
  const size = hi.clone().sub(lo);
235
241
  const mid = lo.clone().add(hi).multiplyScalar(0.5);
236
- const reach = Math.max(...fits.map((f) => mid.distanceTo(new Vector3(...f.target))));
237
- const radius = Math.max(
238
- size.length() * 0.75 + reach + Math.hypot(mid.x - (vx + vw / 2), mid.z - (vy + vh / 2)),
239
- 1e3
240
- );
242
+ const radiusOver = (cams) => {
243
+ const reach = Math.max(...cams.map((f) => mid.distanceTo(new Vector3(...f.target))));
244
+ return Math.max(size.length() * 0.75 + reach + Math.hypot(mid.x - (vx + vw / 2), mid.z - (vy + vh / 2)), 1e3);
245
+ };
246
+ let radius = radiusOver(fits.slice(0, stopCount(p.events)));
247
+ let endRadius = radiusOver(fits);
241
248
  const rad = (d) => d * Math.PI / 180;
242
249
  const img = new Image();
243
250
  const ready = new Promise((resolve) => {
@@ -246,14 +253,15 @@ function mountReplay(out, p, strip, opts = {}) {
246
253
  });
247
254
  img.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(p.svg)))}`;
248
255
  let disposed = false;
249
- const frameView = { cx, cz, oh, elevation: p.elevation };
256
+ let frameView = { cx, cz, oh, elevation: p.elevation };
250
257
  const storeyOf = new Map(p.events.map((e) => [e.key, e.storey ?? 0]));
251
258
  const storeys = Math.max(1, ...p.events.filter((e) => !e.hidden).map((e) => (e.storey ?? 0) + 1));
252
259
  let shown = storeys;
253
260
  let holder = "replay";
254
261
  let tNow = 0;
262
+ let drawn = false;
255
263
  const halfDiagonal = size.length() / 2;
256
- const reachFrom = (target) => Math.max(radius, mid.distanceTo(target) + halfDiagonal);
264
+ const reachFrom = (target) => Math.max(endRadius, mid.distanceTo(target) + halfDiagonal);
257
265
  function place(f, r) {
258
266
  const { fov, dist, elevation, azimuth } = f;
259
267
  const target = new Vector3(...f.target);
@@ -267,7 +275,13 @@ function mountReplay(out, p, strip, opts = {}) {
267
275
  persp.position.set(...cameraPosition([target.x, target.y, target.z], dist, { elevation, azimuth }));
268
276
  persp.lookAt(target);
269
277
  }
270
- const viewScene = { events: p.events, fits, frame: frameView, box: boxOfNodes(p.nodes), aspect };
278
+ let viewScene = {
279
+ events: p.events,
280
+ fits,
281
+ frame: frameView,
282
+ box: boxOfNodes(p.nodes, { settle: 1 }),
283
+ aspect
284
+ };
271
285
  const presets = /* @__PURE__ */ new Map();
272
286
  const presetOf = (name) => {
273
287
  const known = presets.get(name);
@@ -289,12 +303,14 @@ function mountReplay(out, p, strip, opts = {}) {
289
303
  };
290
304
  function draw(t) {
291
305
  tNow = t;
306
+ drawn = true;
292
307
  if (strip && p.facts) paintStrip(strip, stripAt(p.facts, p.events, Math.min(1, Math.max(0, t))));
293
308
  const s = stateAt(p.events, t);
294
- for (const [key2, { g, flat }] of nodes) {
309
+ for (const [key2, { g, flat, base, lift }] of nodes) {
295
310
  const st = s.nodes.get(key2);
296
311
  g.visible = st?.visible === true && (storeyOf.get(key2) ?? 0) < shown;
297
312
  g.scale.y = Math.max(flat, st?.rise ?? 0);
313
+ if (lift !== 0) g.position.y = base + settledLift(lift, s.settle);
298
314
  }
299
315
  let cam = ortho;
300
316
  if (holder === "free" && controls) {
@@ -309,7 +325,7 @@ function mountReplay(out, p, strip, opts = {}) {
309
325
  place(f, reachFrom(new Vector3(...f.target)));
310
326
  cam = persp;
311
327
  } else if (s.tilt > 0 || s.dolly > 0) {
312
- place(frameCamera(s, fits, frameView), radius);
328
+ place(frameCamera(s, fits, frameView), s.settle > 0 ? endRadius : radius);
313
329
  cam = persp;
314
330
  }
315
331
  renderer.render(scene, cam);
@@ -479,6 +495,17 @@ function mountReplay(out, p, strip, opts = {}) {
479
495
  listeners.add(fn);
480
496
  return () => listeners.delete(fn);
481
497
  },
498
+ // One undamped step, so each call lands on its frame at once; the orbit's own `change` takes
499
+ // the view (the first step) and draws. Never under a press: the user's drag holds the view.
500
+ spin: (degrees) => {
501
+ if (disposed || dragging || !Number.isFinite(degrees) || degrees === 0) return;
502
+ prime();
503
+ const damped = c.enableDamping;
504
+ c.enableDamping = false;
505
+ c.rotateLeft(rad(degrees));
506
+ c.update();
507
+ c.enableDamping = damped;
508
+ },
482
509
  get shown() {
483
510
  return shown;
484
511
  },
@@ -503,6 +530,37 @@ function mountReplay(out, p, strip, opts = {}) {
503
530
  }
504
531
  };
505
532
  }
533
+ function resize(width, height) {
534
+ if (disposed) return;
535
+ const w = Math.max(1, Math.round(width));
536
+ const h = Math.max(1, Math.round(height));
537
+ if (w === W && h === H) return;
538
+ W = w;
539
+ H = h;
540
+ gl.width = W;
541
+ gl.height = H;
542
+ out.width = W;
543
+ out.height = H;
544
+ renderer.setSize(W, H, false);
545
+ aspect = W / H;
546
+ ({ cx, cz, ow, oh } = drawingFrame(p.viewBox, aspect));
547
+ ortho.left = -ow / 2;
548
+ ortho.right = ow / 2;
549
+ ortho.top = oh / 2;
550
+ ortho.bottom = -oh / 2;
551
+ ortho.position.set(cx, top + 5e4, cz);
552
+ ortho.lookAt(cx, 0, cz);
553
+ ortho.updateProjectionMatrix();
554
+ persp.aspect = aspect;
555
+ persp.updateProjectionMatrix();
556
+ fits = fitsAt(aspect);
557
+ radius = radiusOver(fits.slice(0, stopCount(p.events)));
558
+ endRadius = radiusOver(fits);
559
+ frameView = { cx, cz, oh, elevation: p.elevation };
560
+ viewScene = { ...viewScene, fits, frame: frameView, aspect };
561
+ presets.clear();
562
+ if (drawn) draw(tNow);
563
+ }
506
564
  function dispose() {
507
565
  if (disposed) return;
508
566
  halt();
@@ -512,11 +570,14 @@ function mountReplay(out, p, strip, opts = {}) {
512
570
  renderer.dispose();
513
571
  renderer.forceContextLoss();
514
572
  }
515
- return { seek, frameHash, ready, dispose, ...view ? { view } : {} };
573
+ return { seek, frameHash, ready, dispose, resize, ...view ? { view } : {} };
516
574
  }
517
575
  export {
518
576
  PRESET_LABELS,
577
+ PREVIEW_ABOUT_URL,
519
578
  PREVIEW_LABEL,
579
+ PREVIEW_LEAD,
580
+ PREVIEW_LIMITS,
520
581
  VIEW_CONTROLS_LABEL,
521
582
  VIEW_HINT,
522
583
  mountReplay,
@@ -1,4 +1,4 @@
1
- import { w as ReplayEvent, x as ReplayState } from './strip-CN_dTKqy.js';
1
+ import { y as ReplayEvent, z as ReplayState } from './strip-Nt7eJ-4E.js';
2
2
 
3
3
  /**
4
4
  * The replay's end camera as plain maths (card A3, look notes round 1): the viewer and the tests
@@ -65,6 +65,8 @@ declare const endElevation: (_storeys: number) => number;
65
65
  * `lift` (the combined view's exploded storeys). A demolished wall's ghost (`part` "demolish") is not
66
66
  * the building and is left out of a fit (`timeline.ts`'s header), unless nothing else is there;
67
67
  * `ghosts: true` keeps it, for a box that must hold everything drawn (the viewer's clip range).
68
+ * `settle` (`ReplayState.settle`) lowers each lift to `settledLift(lift, settle)`: 1 is the
69
+ * assembled building, every storey at the height it stands at (the end frame's).
68
70
  */
69
71
  declare function boxOfNodes(nodes: ReadonlyArray<{
70
72
  positions: readonly number[];
@@ -72,13 +74,24 @@ declare function boxOfNodes(nodes: ReadonlyArray<{
72
74
  part?: string;
73
75
  }>, opts?: {
74
76
  ghosts?: boolean;
77
+ settle?: number;
75
78
  }): Box;
79
+ /**
80
+ * A node's lift (mm) at settle `settle` (`ReplayState.settle`): the whole lift while the storeys are
81
+ * exploded, none once they have settled. The viewer draws a node at this lift.
82
+ */
83
+ declare const settledLift: (lift: number | undefined, settle: number) => number;
84
+ /** How many camera stops the rise has: one per storey of the event table (one storey: one). */
85
+ declare const stopCount: (events: readonly ReplayEvent[]) => number;
76
86
  /** The perspective camera's lens at the start of the dolly (a near-orthographic top-down view). */
77
87
  declare const START_FOV = 1.5;
78
88
  /**
79
89
  * One fitted camera per stop: stop k fills the frame with storeys 0…k (the combined view; a node's
80
- * storey is its event's), the last stop with the whole building. One storey: one stop. Each stop is
81
- * fitted for the end orbit, which `stateAt` has reached by the time of the first stop.
90
+ * storey is its event's), the last stop with the whole building, exploded. One storey: one stop.
91
+ * Several storeys add one fit after the stops: the assembled building (every lift settled), the
92
+ * camera the settle ends on (`stateAt`'s `settle`), so the last fit is always the whole building as
93
+ * the end frame shows it. Each is fitted for the end orbit, which `stateAt` has reached by the time
94
+ * of the first stop.
82
95
  */
83
96
  declare function cameraStops(nodes: ReadonlyArray<{
84
97
  key: string;
@@ -136,7 +149,10 @@ interface ViewScene {
136
149
  oh: number;
137
150
  elevation: number;
138
151
  };
139
- /** The standing building (`boxOfNodes`, ghosts left out): the box the last stop is fitted to. */
152
+ /**
153
+ * The standing building as the end frame shows it (`boxOfNodes`, ghosts left out, `settle: 1`):
154
+ * the box the last fit is fitted to (`cameraStops`).
155
+ */
140
156
  box: Box;
141
157
  /** Canvas width / height. */
142
158
  aspect: number;
@@ -208,4 +224,4 @@ declare function targetBounds(box: Box): {
208
224
  radius: number;
209
225
  };
210
226
 
211
- export { type Box as B, ELEVATION_AZIMUTH as E, FILL as F, type Orbit as O, type PresetName as P, START_FOV as S, type Vec3 as V, ZOOM as Z, ELEVATION_RANGE as a, END_AZIMUTH as b, END_FOV as c, type EndCamera as d, type FrameCamera as e, PRESET_NAMES as f, type ViewScene as g, boxOfNodes as h, cameraAtStop as i, cameraStops as j, corners as k, coverage as l, distanceLimits as m, drawingFrame as n, endElevation as o, fitEndCamera as p, frameCamera as q, pivotAbove as r, presetCamera as s, projectBox as t, takenLens as u, targetBounds as v };
227
+ export { type Box as B, ELEVATION_AZIMUTH as E, FILL as F, type Orbit as O, type PresetName as P, START_FOV as S, type Vec3 as V, ZOOM as Z, ELEVATION_RANGE as a, END_AZIMUTH as b, END_FOV as c, type EndCamera as d, type FrameCamera as e, PRESET_NAMES as f, type ViewScene as g, boxOfNodes as h, cameraAtStop as i, cameraStops as j, corners as k, coverage as l, distanceLimits as m, drawingFrame as n, endElevation as o, fitEndCamera as p, frameCamera as q, pivotAbove as r, presetCamera as s, projectBox as t, settledLift as u, stopCount as v, takenLens as w, targetBounds as x };
@@ -5,16 +5,16 @@ import {
5
5
  slotGroups,
6
6
  storeysOf,
7
7
  timeline
8
- } from "./chunk-VPYTRKMK.js";
8
+ } from "./chunk-EQBMPXB5.js";
9
9
 
10
10
  // src/replay/view-dom.ts
11
11
  var PRESET_LABELS = [
12
12
  ["iso", "Iso", "Iso view: the replay's end view"],
13
13
  ["top", "Top", "Top view, the plan's top edge up"],
14
- ["north", "N", "North elevation: from the plan's top edge"],
15
- ["east", "E", "East elevation: from the plan's right edge"],
16
- ["south", "S", "South elevation: from the plan's bottom edge"],
17
- ["west", "W", "West elevation: from the plan's left edge"]
14
+ ["north", "N", "View from north: level, from the plan's top edge"],
15
+ ["east", "E", "View from east: level, from the plan's right edge"],
16
+ ["south", "S", "View from south: level, from the plan's bottom edge"],
17
+ ["west", "W", "View from west: level, from the plan's left edge"]
18
18
  ];
19
19
  var VIEW_HINT = "Drag to turn, right-drag to pan, scroll to zoom; on the focused view, arrow keys turn and + / \u2212 zoom.";
20
20
  var VIEW_CONTROLS_LABEL = "an interactive 3D view: drag or use the arrow keys to turn it, scroll or + and \u2212 to zoom";
@@ -38,14 +38,68 @@ function viewToolbar(view, opts = {}) {
38
38
  for (const [name, b] of presetButtons) b.setAttribute("aria-pressed", String(view.camera === name));
39
39
  for (const [i, b] of storeyButtons.entries()) b.setAttribute("aria-pressed", String(i + 1 === view.shown));
40
40
  };
41
+ let shut = (_refocus) => {
42
+ };
41
43
  for (const [name, text, label] of PRESET_LABELS) {
42
- const b = button(text, label, () => view.preset(name));
44
+ const b = button(text, label, () => {
45
+ view.preset(name);
46
+ shut(true);
47
+ });
43
48
  b.dataset.preset = name;
44
49
  presetButtons.push([name, b]);
45
- bar.append(b);
46
50
  }
47
- bar.append(button("Reset", "Reset the view: the replay's own camera, every storey shown", () => view.reset()));
48
- if (view.storeys > 1) {
51
+ const resetLabel = "Reset the view: the replay's own camera, every storey shown";
52
+ if (opts.compact) {
53
+ bar.classList.add("archlang-views-compact");
54
+ bar.append(button("\u27F2 Reset", resetLabel, () => view.reset()));
55
+ const wrap = document.createElement("span");
56
+ wrap.className = "archlang-views-menu";
57
+ const pop = document.createElement("span");
58
+ pop.className = "archlang-views-presets";
59
+ pop.id = `${opts.hintId ?? "archlang-views"}-presets`;
60
+ pop.setAttribute("role", "group");
61
+ pop.setAttribute("aria-label", "Preset views");
62
+ pop.hidden = true;
63
+ pop.append(...presetButtons.map(([, b]) => b));
64
+ const toggle = button(
65
+ "View \u25BE",
66
+ "View presets: iso, top, and from north, east, south and west",
67
+ () => pop.hidden ? open() : shut(false)
68
+ );
69
+ toggle.setAttribute("aria-expanded", "false");
70
+ toggle.setAttribute("aria-controls", pop.id);
71
+ const away = (e) => {
72
+ if (!wrap.contains(e.target)) shut(false);
73
+ };
74
+ const open = () => {
75
+ pop.hidden = false;
76
+ toggle.setAttribute("aria-expanded", "true");
77
+ document.addEventListener("pointerdown", away, true);
78
+ (presetButtons.find(([n]) => view.camera === n)?.[1] ?? presetButtons[0]?.[1])?.focus();
79
+ };
80
+ shut = (refocus) => {
81
+ if (pop.hidden) return;
82
+ pop.hidden = true;
83
+ toggle.setAttribute("aria-expanded", "false");
84
+ document.removeEventListener("pointerdown", away, true);
85
+ if (refocus) toggle.focus();
86
+ };
87
+ wrap.addEventListener("keydown", (e) => {
88
+ if (e.key !== "Escape" || pop.hidden) return;
89
+ e.preventDefault();
90
+ e.stopPropagation();
91
+ shut(true);
92
+ });
93
+ wrap.addEventListener("focusout", (e) => {
94
+ if (!wrap.contains(e.relatedTarget)) shut(false);
95
+ });
96
+ wrap.append(toggle, pop);
97
+ bar.append(wrap);
98
+ } else {
99
+ bar.append(...presetButtons.map(([, b]) => b));
100
+ bar.append(button("Reset", resetLabel, () => view.reset()));
101
+ }
102
+ if (view.storeys > 1 && opts.storeys !== false) {
49
103
  const group = document.createElement("span");
50
104
  group.className = "archlang-views-storeys";
51
105
  group.setAttribute("role", "group");
@@ -75,7 +129,10 @@ function viewToolbar(view, opts = {}) {
75
129
  }
76
130
 
77
131
  // src/replay/payload.ts
78
- var PREVIEW_LABEL = "Preview \u2014 from the separate archlang-3d package. ArchLang itself draws plans.";
132
+ var PREVIEW_LEAD = "Same source, plan and 3D preview.";
133
+ var PREVIEW_LABEL = "Same source, plan and 3D preview. The 3D preview is extruded from the same .arch file by the separate archlang-3d package, and checked against the plan: every 3D element comes from the plan's elements, and every solid is closed.";
134
+ var PREVIEW_LIMITS = "3D preview: walls, openings, floors, stairs and furniture in flat colours; no pitched roofs yet, and no sections, elevations or BIM.";
135
+ var PREVIEW_ABOUT_URL = "https://archlang.uk/3d";
79
136
  function viewBoxOf(svg) {
80
137
  const m = /viewBox="([-\d.\s]+)"/.exec(svg);
81
138
  const v = (m?.[1] ?? "").trim().split(/\s+/).map(Number);
@@ -131,7 +188,10 @@ export {
131
188
  VIEW_HINT,
132
189
  VIEW_CONTROLS_LABEL,
133
190
  viewToolbar,
191
+ PREVIEW_LEAD,
134
192
  PREVIEW_LABEL,
193
+ PREVIEW_LIMITS,
194
+ PREVIEW_ABOUT_URL,
135
195
  viewBoxOf,
136
196
  replayPayload
137
197
  };