@chanmeng666/archlang-3d 0.2.0 → 0.4.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.
@@ -0,0 +1,227 @@
1
+ import { y as ReplayEvent, z as ReplayState } from './strip-Nt7eJ-4E.js';
2
+
3
+ /**
4
+ * The replay's end camera as plain maths (card A3, look notes round 1): the viewer and the tests
5
+ * read the same functions, so "the end frame fills the canvas" is a property a test can check
6
+ * without a browser. Millimetres, the exporters' axes (X plan x, Y up, Z plan y). No three.js here:
7
+ * the conventions copy three.js's `lookAt` for a camera (it looks down its local −Z; right =
8
+ * up × back, true up = back × right, world up +Y).
9
+ */
10
+
11
+ type Vec3 = [number, number, number];
12
+ interface Box {
13
+ lo: Vec3;
14
+ hi: Vec3;
15
+ }
16
+ /** Where the end camera looks from: elevation and azimuth in degrees, vertical field of view. */
17
+ interface Orbit {
18
+ elevation: number;
19
+ azimuth: number;
20
+ fov: number;
21
+ /** Canvas width / height. */
22
+ aspect: number;
23
+ }
24
+ interface EndCamera {
25
+ target: Vec3;
26
+ /** Distance from the target to the camera (mm). */
27
+ dist: number;
28
+ }
29
+ /**
30
+ * The fraction of each half-axis the building may use: a margin of 6 % of the frame on each side
31
+ * of the binding axis.
32
+ */
33
+ declare const FILL = 0.88;
34
+ declare function corners(b: Box): Vec3[];
35
+ /**
36
+ * The projected extent of `box` in normalised device coordinates (−1…1 on each axis) for a camera
37
+ * at `cam` with orbit `o`.
38
+ */
39
+ declare function projectBox(box: Box, cam: EndCamera, o: Orbit): {
40
+ x: [number, number];
41
+ y: [number, number];
42
+ };
43
+ /**
44
+ * The end camera that fills the frame with `box`: the 8 corners are projected through the end
45
+ * orbit and the distance is solved so the binding corner sits at `FILL` of the half-frame; the
46
+ * target is then re-centred on the projected box (perspective makes the near half larger) and the
47
+ * distance solved again. A fixed number of rounds, so the result is a pure function of its input.
48
+ */
49
+ declare function fitEndCamera(box: Box, o: Orbit): EndCamera;
50
+ /** The share of the binding axis the projected box fills (1 = edge to edge). */
51
+ declare function coverage(box: Box, cam: EndCamera, o: Orbit): number;
52
+ /** The end camera's lens and bearing. */
53
+ declare const END_FOV = 30;
54
+ declare const END_AZIMUTH = -32;
55
+ /**
56
+ * The end camera's elevation: 45° for every view. The combined view of a taller building needs it so
57
+ * the exploded gaps show the floors below (see `timeline.ts`'s header); a one-storey view took it
58
+ * too (card A9, by delegation, the owner may veto on a look): at 30° the near walls hid the floor,
59
+ * the inner doors and most furniture of `studio`. The storey count stays a parameter so a later
60
+ * look can split the two again without a signature change.
61
+ */
62
+ declare const endElevation: (_storeys: number) => number;
63
+ /**
64
+ * The scene's box (mm) from the payload's nodes: positions in micrometres, each node lifted by its
65
+ * `lift` (the combined view's exploded storeys). A demolished wall's ghost (`part` "demolish") is not
66
+ * the building and is left out of a fit (`timeline.ts`'s header), unless nothing else is there;
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).
70
+ */
71
+ declare function boxOfNodes(nodes: ReadonlyArray<{
72
+ positions: readonly number[];
73
+ lift?: number;
74
+ part?: string;
75
+ }>, opts?: {
76
+ ghosts?: boolean;
77
+ settle?: number;
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;
86
+ /** The perspective camera's lens at the start of the dolly (a near-orthographic top-down view). */
87
+ declare const START_FOV = 1.5;
88
+ /**
89
+ * One fitted camera per stop: stop k fills the frame with storeys 0…k (the combined view; a node's
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.
95
+ */
96
+ declare function cameraStops(nodes: ReadonlyArray<{
97
+ key: string;
98
+ positions: readonly number[];
99
+ lift?: number;
100
+ part?: string;
101
+ }>, events: readonly ReplayEvent[], o: Orbit): EndCamera[];
102
+ /** The fitted camera at a (fractional) stop: between two stops, a straight blend of the two. */
103
+ declare function cameraAtStop(fits: readonly EndCamera[], stop: number): EndCamera;
104
+ /** The perspective camera of one frame: where it aims, from how far, with which lens and bearing. */
105
+ interface FrameCamera {
106
+ target: Vec3;
107
+ dist: number;
108
+ fov: number;
109
+ elevation: number;
110
+ azimuth: number;
111
+ }
112
+ /**
113
+ * The perspective camera at state `s` (the viewer's `seek`): from straight down over the drawing's
114
+ * centre (`cx`, `cz`; `oh` the drawing's height in the frame) it tilts to the end orbit and dollies
115
+ * to the fitted camera of the current stop.
116
+ */
117
+ declare function frameCamera(s: Pick<ReplayState, "tilt" | "dolly" | "stop">, fits: readonly EndCamera[], view: {
118
+ cx: number;
119
+ cz: number;
120
+ oh: number;
121
+ elevation: number;
122
+ }): FrameCamera;
123
+ /**
124
+ * The first frame frames the core drawing's viewBox exactly, letterboxed as the image is: its
125
+ * centre (`cx`, `cz`) and the height (`oh`) and width (`ow`) it spans in the frame, in plan mm.
126
+ */
127
+ declare function drawingFrame(viewBox: readonly [number, number, number, number], aspect: number): {
128
+ cx: number;
129
+ cz: number;
130
+ ow: number;
131
+ oh: number;
132
+ };
133
+ /**
134
+ * The free camera (card CR4, decision CR-D2): the views a viewer offers beside the replay's own
135
+ * camera, as plain maths like the end camera's, so a test reads them without a browser. Each preset
136
+ * is a pure function of the scene (`ViewScene`); the viewer draws it through the same placement as
137
+ * the replay's frames (`cameraPosition`, then three.js's `lookAt`).
138
+ */
139
+ type PresetName = "iso" | "top" | "north" | "east" | "south" | "west";
140
+ declare const PRESET_NAMES: readonly PresetName[];
141
+ /** What a preset reads: the replay's event table and fitted stops, the drawing's frame, the box. */
142
+ interface ViewScene {
143
+ events: readonly ReplayEvent[];
144
+ fits: readonly EndCamera[];
145
+ /** The first frame's framing (`drawingFrame`) and the end elevation, as `frameCamera` takes them. */
146
+ frame: {
147
+ cx: number;
148
+ cz: number;
149
+ oh: number;
150
+ elevation: number;
151
+ };
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
+ */
156
+ box: Box;
157
+ /** Canvas width / height. */
158
+ aspect: number;
159
+ }
160
+ /**
161
+ * The bearing each elevation looks from, relative to the plan's axes (not its `north`): north is the
162
+ * plan's top edge (plan −y, the exporters' −Z), east its right edge (+X). `backOf` puts the camera at
163
+ * (sin az, ·, cos az) from the target, so azimuth 0 stands south of the plan.
164
+ */
165
+ declare const ELEVATION_AZIMUTH: {
166
+ readonly north: 180;
167
+ readonly east: 90;
168
+ readonly south: 0;
169
+ readonly west: -90;
170
+ };
171
+ /**
172
+ * The free camera's elevation range, degrees: from the horizon through its target (an elevation
173
+ * view) to straight down (the top view). The orbit's pivot is never below the building's lowest
174
+ * point (`pivotAbove`) and never drops (panning keeps to its horizontal plane), so the camera never
175
+ * goes below the building.
176
+ */
177
+ declare const ELEVATION_RANGE: {
178
+ readonly min: 0;
179
+ readonly max: 90;
180
+ };
181
+ /**
182
+ * The point the orbit turns about when it takes a camera at `position` aimed at `target`: the target
183
+ * itself, or, where the target lies below `minY` (a fitted target is re-centred across the view and
184
+ * can sink under the slab: the end camera of a deep plan does), the point of the same line of sight
185
+ * at height `minY`. The view does not move (the aim is the same ray), only the pivot.
186
+ */
187
+ declare function pivotAbove(position: Vec3, target: Vec3, minY: number): Vec3;
188
+ /**
189
+ * A preset camera. `iso` IS the replay's end camera (`frameCamera` at t = 1, the very numbers the
190
+ * end frame is drawn from), so returning to it draws the end frame byte for byte; the other presets
191
+ * are fitted to the standing building like the stops (`fitEndCamera`, the end lens): `top` from
192
+ * straight down with the plan's top edge up, each elevation level with the target.
193
+ */
194
+ declare function presetCamera(name: PresetName, v: ViewScene): FrameCamera;
195
+ /**
196
+ * The camera the orbit takes from a replay frame: the frame's aim and bearing, and its framing at the
197
+ * target (the view height there), through the end lens. So a take in the top-down phase (a 1.5°,
198
+ * near-orthographic lens under the core's drawing) turns a top view at the end lens over the same
199
+ * area, and a take mid-dolly keeps what the frame showed. A frame already at the end lens (the end
200
+ * frame, every stop) is returned as it is.
201
+ */
202
+ declare function takenLens(f: FrameCamera): FrameCamera;
203
+ /**
204
+ * How far the free camera may dolly, as multiples of the whole building's fitted distance (the
205
+ * last stop): in until an eighth of the building's span fills the frame (a corner, one room), out
206
+ * until it stands at a third of its fitted size.
207
+ */
208
+ declare const ZOOM: {
209
+ readonly in: 8;
210
+ readonly out: 3;
211
+ };
212
+ /**
213
+ * The free camera's distance limits for lens `fov`: the view heights at the target that the end
214
+ * lens has at `ZOOM`'s distances, so a camera taken mid-dolly (a narrower lens) zooms over the same
215
+ * framings.
216
+ */
217
+ declare function distanceLimits(fits: readonly EndCamera[], fov: number): {
218
+ min: number;
219
+ max: number;
220
+ };
221
+ /** Where the free camera's target may pan: the sphere round everything drawn (the clip box). */
222
+ declare function targetBounds(box: Box): {
223
+ centre: Vec3;
224
+ radius: number;
225
+ };
226
+
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 };
@@ -3571,12 +3571,14 @@ function floorLifts(floors, overlaps) {
3571
3571
  }
3572
3572
 
3573
3573
  // package.json
3574
- var version = "0.2.0";
3574
+ var version = "0.4.0";
3575
3575
 
3576
3576
  // src/scene3d/build.ts
3577
+ import * as core2 from "@chanmeng666/archlang";
3577
3578
  import {
3578
3579
  doorLeaves,
3579
- doorSwing
3580
+ doorSwing,
3581
+ entryEdges
3580
3582
  } from "@chanmeng666/archlang";
3581
3583
 
3582
3584
  // src/curves.ts
@@ -3673,12 +3675,32 @@ var fenceOf = (f) => ({
3673
3675
  points: f.points.map(umPoint),
3674
3676
  closed: f.closed
3675
3677
  });
3678
+ var OPPOSITE = { top: "bottom", bottom: "top", left: "right", right: "left" };
3679
+ function stairPieces(s) {
3680
+ const treadCount3 = core2.treadCount;
3681
+ if (typeof treadCount3 !== "function") return void 0;
3682
+ const flight = (at, size, tail2) => ({
3683
+ at: umPoint(at),
3684
+ size: { w: um2(size.w), h: um2(size.h) },
3685
+ foot: s.dir === "up" ? tail2 : OPPOSITE[tail2],
3686
+ treads: treadCount3(tail2 === "top" || tail2 === "bottom" ? size.h : size.w)
3687
+ });
3688
+ if (s.flights && s.landings) {
3689
+ return {
3690
+ flights: s.flights.map((f) => flight(f.at, f.size, f.tail)),
3691
+ landings: s.landings.map((l) => ({ at: umPoint(l.at), size: { w: um2(l.size.w), h: um2(l.size.h) } }))
3692
+ };
3693
+ }
3694
+ const tail = entryEdges(s)[0];
3695
+ return tail ? { flights: [flight(s.at, s.size, tail)], landings: [] } : void 0;
3696
+ }
3676
3697
  var stairOf = (s) => ({
3677
3698
  id: s.id,
3678
3699
  source: source(s),
3679
3700
  box: box(s),
3680
3701
  dir: s.dir,
3681
- width: um2(s.width)
3702
+ width: um2(s.width),
3703
+ ...stairPieces(s)
3682
3704
  });
3683
3705
  function wallsAndOpenings(ir, byId, tol) {
3684
3706
  const own = wallOwnership(ir.walls, (loops) => tessellateLoops(loops, tol));
@@ -3843,7 +3865,11 @@ function levelOf(s, ledger, tol, mirrored) {
3843
3865
  openings,
3844
3866
  furniture: of("furniture").map((f) => furnitureOf(f, mirrored, ledger)),
3845
3867
  stairs: of("stair").map(stairOf),
3846
- voids: of("void").map(box),
3868
+ // A core `void … polygon` (an L) carries the rectangles its hole is made of (`parts`): each is
3869
+ // one box, ids `<id>#<k>` (unique per collection), `source` still naming the void.
3870
+ voids: of("void").flatMap(
3871
+ (v) => v.parts ? v.parts.map((p, k) => ({ ...box({ ...v, at: p.at, size: p.size }), id: `${v.id}#${k}` })) : [box(v)]
3872
+ ),
3847
3873
  columns: of("column").map(box),
3848
3874
  outdoor: of("outdoor").map(outdoorOf),
3849
3875
  fences: of("fence").map(fenceOf),
@@ -3936,6 +3962,9 @@ var object = (required, optional = {}) => (v, p, out) => {
3936
3962
  if (!(k in required) && !(k in optional)) fail(out, `${p}/${k}`, "is not a Scene3D field");
3937
3963
  }
3938
3964
  };
3965
+ var treadCount2 = (v, p, out) => {
3966
+ if (!Number.isInteger(v) || v < 1) fail(out, p, "must be an integer of at least 1");
3967
+ };
3939
3968
  var pt = array(integer, 2, 2);
3940
3969
  var ring2 = array(pt, 3);
3941
3970
  var polygon2 = object({ outer: ring2 }, { holes: array(ring2) });
@@ -3987,7 +4016,23 @@ var LEVEL_COLLECTIONS = {
3987
4016
  { room: string, mirror: oneOf(true) }
3988
4017
  )
3989
4018
  ),
3990
- stairs: array(object({ id, source: source2, box: box2, dir: oneOf("up", "down"), width: integer })),
4019
+ stairs: array(
4020
+ object(
4021
+ { id, source: source2, box: box2, dir: oneOf("up", "down"), width: integer },
4022
+ {
4023
+ flights: array(
4024
+ object({
4025
+ at: pt,
4026
+ size: sized("w", "h"),
4027
+ foot: oneOf("top", "bottom", "left", "right"),
4028
+ treads: treadCount2
4029
+ }),
4030
+ 1
4031
+ ),
4032
+ landings: array(object({ at: pt, size: sized("w", "h") }))
4033
+ }
4034
+ )
4035
+ ),
3991
4036
  voids: array(box2),
3992
4037
  columns: array(box2),
3993
4038
  outdoor: array(object({ id, source: source2, surface: string, polygon: polygon2 }, { rail: array(string) })),
@@ -46,6 +46,7 @@ var PALETTE = {
46
46
  soil: m("#5f4b3b", 1),
47
47
  water: m("#a3c6d0", 0.1, 0, 0.7)
48
48
  };
49
+ var STAIR_MATERIAL = "wood";
49
50
  var KIND_PALETTE = {
50
51
  slab: m("#bdb6ab", 0.9),
51
52
  column: m("#e6e1d8", 0.85),
@@ -56,7 +57,10 @@ var KIND_PALETTE = {
56
57
  opening: m("#e6e1d8", 0.85),
57
58
  furniture: m("#d6cec1", 0.9),
58
59
  roof: m("#9c958a", 0.9),
59
- "wall:demolish": m("#c8553d", 0.9, 0, 0.3)
60
+ "wall:demolish": m("#c8553d", 0.9, 0, 0.3),
61
+ // A stair (card X3): the core gives it no material, so the ledgered default (`STAIR_MATERIAL`,
62
+ // `stair-material-default`): that slot's own entry, never a second copy of its colour.
63
+ stair: PALETTE[STAIR_MATERIAL]
60
64
  };
61
65
  var WALL_CAP_SRGB = "#8f877d";
62
66
  var FLOOR_FINISHES = ["timber", "tile", "neutral"];
@@ -127,7 +131,7 @@ var PHASE = {
127
131
  tilted: 0.78,
128
132
  /** Every wall has risen; fixtures rise from here. */
129
133
  wallsUp: 0.84,
130
- /** Everything has risen. */
134
+ /** Everything has risen; several storeys combined settle from here to the end (`stateAt`). */
131
135
  done: 0.96
132
136
  };
133
137
  var FIXTURE_FAMILIES = /* @__PURE__ */ new Set([
@@ -160,6 +164,8 @@ function groupOf(n) {
160
164
  return n.extras.category === "exterior" ? 1 : 2;
161
165
  case "roof":
162
166
  return 3;
167
+ case "stair":
168
+ return 3;
163
169
  case "door":
164
170
  return 0;
165
171
  case "window":
@@ -305,16 +311,24 @@ function stateAt(events, t) {
305
311
  const b = starts[k];
306
312
  if (u > a) stop = k - 1 + (b > a ? ease((u - a) / (b - a)) : 1);
307
313
  }
314
+ let settle = 0;
315
+ if (ends.length > 1) {
316
+ const from = settleFrom(ends);
317
+ settle = from < 1 ? ease((u - from) / (1 - from)) : u >= 1 ? 1 : 0;
318
+ if (settle > 0) stop = ends.length - 1 + settle;
319
+ }
308
320
  return {
309
321
  // The tilt is done by the first stop, so every stop sees the end orbit its camera was fitted for
310
322
  // (one storey: `first` is 1 and the tilt keeps PHASE's own timing).
311
323
  tilt: ease((u - PHASE.rise) / (Math.min(PHASE.tilted, first) - PHASE.rise)),
312
324
  dolly: ease((u - PHASE.rise) / (first - PHASE.rise)),
313
325
  stop,
326
+ settle,
314
327
  svg,
315
328
  nodes
316
329
  };
317
330
  }
331
+ var settleFrom = (ends) => Math.max(PHASE.done, ...ends);
318
332
  function keyFrames(events) {
319
333
  const first = (s) => events.filter((e) => e.stage === s && !e.hidden).reduce((m3, e) => m3 === void 0 || e.appear < m3 ? e.appear : m3, void 0);
320
334
  const out = [];
@@ -456,7 +470,7 @@ function boxOfNodes(nodes, opts = {}) {
456
470
  const hi = [-Infinity, -Infinity, -Infinity];
457
471
  const standing = opts.ghosts ? nodes : nodes.filter((n) => n.part !== "demolish");
458
472
  for (const n of standing.length > 0 ? standing : nodes) {
459
- const lift = n.lift ?? 0;
473
+ const lift = opts.settle === void 0 ? n.lift ?? 0 : settledLift(n.lift, opts.settle);
460
474
  for (let i = 0; i < n.positions.length; i += 3) {
461
475
  const p = [
462
476
  n.positions[i] / 1e3,
@@ -471,13 +485,16 @@ function boxOfNodes(nodes, opts = {}) {
471
485
  }
472
486
  return { lo, hi };
473
487
  }
488
+ var settledLift = (lift, settle) => (lift ?? 0) * (1 - settle);
489
+ var stopCount = (events) => Math.max(1, ...events.map((e) => (e.storey ?? 0) + 1));
474
490
  var START_FOV = 1.5;
475
491
  function cameraStops(nodes, events, o) {
476
492
  const storeyOf = new Map(events.map((e) => [e.key, e.storey ?? 0]));
477
- const stops = Math.max(1, ...events.map((e) => (e.storey ?? 0) + 1));
493
+ const stops = stopCount(events);
478
494
  const fits = [];
479
495
  for (let k = 0; k < stops; k++)
480
496
  fits.push(fitEndCamera(boxOfNodes(nodes.filter((n) => (storeyOf.get(n.key) ?? 0) <= k)), o));
497
+ if (stops > 1) fits.push(fitEndCamera(boxOfNodes(nodes, { settle: 1 }), o));
481
498
  return fits;
482
499
  }
483
500
  function cameraAtStop(fits, stop) {
@@ -516,10 +533,42 @@ function drawingFrame(viewBox, aspect) {
516
533
  const ow = Math.max(vw, vh * aspect);
517
534
  return { cx: vx + vw / 2, cz: vy + vh / 2, ow, oh: ow / aspect };
518
535
  }
536
+ var PRESET_NAMES = ["iso", "top", "north", "east", "south", "west"];
537
+ var ELEVATION_AZIMUTH = { north: 180, east: 90, south: 0, west: -90 };
538
+ var ELEVATION_RANGE = { min: 0, max: 90 };
539
+ function pivotAbove(position, target, minY) {
540
+ if (target[1] >= minY || position[1] <= minY) return target;
541
+ const s = (position[1] - minY) / (position[1] - target[1]);
542
+ return [position[0] + (target[0] - position[0]) * s, minY, position[2] + (target[2] - position[2]) * s];
543
+ }
544
+ function presetCamera(name, v) {
545
+ if (name === "iso") return frameCamera(stateAt(v.events, 1), v.fits, v.frame);
546
+ const bearing = name === "top" ? { elevation: ELEVATION_RANGE.max, azimuth: ELEVATION_AZIMUTH.south } : { elevation: ELEVATION_RANGE.min, azimuth: ELEVATION_AZIMUTH[name] };
547
+ const fit = fitEndCamera(v.box, { ...bearing, fov: END_FOV, aspect: v.aspect });
548
+ return { target: fit.target, dist: fit.dist, fov: END_FOV, ...bearing };
549
+ }
550
+ function takenLens(f) {
551
+ if (f.fov === END_FOV) return f;
552
+ return { ...f, fov: END_FOV, dist: f.dist * Math.tan(rad(f.fov) / 2) / Math.tan(rad(END_FOV) / 2) };
553
+ }
554
+ var ZOOM = { in: 8, out: 3 };
555
+ function distanceLimits(fits, fov) {
556
+ const whole = fits[fits.length - 1].dist;
557
+ const k = Math.tan(rad(END_FOV) / 2) / Math.tan(rad(fov) / 2);
558
+ return { min: whole * k / ZOOM.in, max: whole * k * ZOOM.out };
559
+ }
560
+ function targetBounds(box) {
561
+ const d = [box.hi[0] - box.lo[0], box.hi[1] - box.lo[1], box.hi[2] - box.lo[2]];
562
+ return {
563
+ centre: [(box.lo[0] + box.hi[0]) / 2, (box.lo[1] + box.hi[1]) / 2, (box.lo[2] + box.hi[2]) / 2],
564
+ radius: Math.hypot(d[0], d[1], d[2]) / 2
565
+ };
566
+ }
519
567
 
520
568
  export {
521
569
  MATERIAL_SLOTS,
522
570
  PALETTE,
571
+ STAIR_MATERIAL,
523
572
  KIND_PALETTE,
524
573
  WALL_CAP_SRGB,
525
574
  FLOOR_FINISHES,
@@ -554,9 +603,20 @@ export {
554
603
  END_AZIMUTH,
555
604
  endElevation,
556
605
  boxOfNodes,
606
+ settledLift,
607
+ stopCount,
557
608
  START_FOV,
558
609
  cameraStops,
559
610
  cameraAtStop,
560
611
  frameCamera,
561
- drawingFrame
612
+ drawingFrame,
613
+ PRESET_NAMES,
614
+ ELEVATION_AZIMUTH,
615
+ ELEVATION_RANGE,
616
+ pivotAbove,
617
+ presetCamera,
618
+ takenLens,
619
+ ZOOM,
620
+ distanceLimits,
621
+ targetBounds
562
622
  };
@@ -0,0 +1,143 @@
1
+ import {
2
+ FLOOR_FINISHES,
3
+ endElevation,
4
+ explodeLifts,
5
+ slotGroups,
6
+ storeysOf,
7
+ timeline
8
+ } from "./chunk-EQBMPXB5.js";
9
+
10
+ // src/replay/view-dom.ts
11
+ var PRESET_LABELS = [
12
+ ["iso", "Iso", "Iso view: the replay's end view"],
13
+ ["top", "Top", "Top view, the plan's top edge up"],
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
+ ];
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
+ var VIEW_CONTROLS_LABEL = "an interactive 3D view: drag or use the arrow keys to turn it, scroll or + and \u2212 to zoom";
21
+ function viewToolbar(view, opts = {}) {
22
+ const bar = document.createElement("div");
23
+ bar.className = "archlang-views";
24
+ bar.setAttribute("role", "toolbar");
25
+ bar.setAttribute("aria-label", "3D view");
26
+ const button = (text, label, onClick) => {
27
+ const b = document.createElement("button");
28
+ b.type = "button";
29
+ if (opts.buttonClass) b.className = opts.buttonClass;
30
+ b.textContent = text;
31
+ b.setAttribute("aria-label", label);
32
+ b.addEventListener("click", onClick);
33
+ return b;
34
+ };
35
+ const presetButtons = [];
36
+ const storeyButtons = [];
37
+ const press = () => {
38
+ for (const [name, b] of presetButtons) b.setAttribute("aria-pressed", String(view.camera === name));
39
+ for (const [i, b] of storeyButtons.entries()) b.setAttribute("aria-pressed", String(i + 1 === view.shown));
40
+ };
41
+ for (const [name, text, label] of PRESET_LABELS) {
42
+ const b = button(text, label, () => view.preset(name));
43
+ b.dataset.preset = name;
44
+ presetButtons.push([name, b]);
45
+ bar.append(b);
46
+ }
47
+ bar.append(button("Reset", "Reset the view: the replay's own camera, every storey shown", () => view.reset()));
48
+ if (view.storeys > 1) {
49
+ const group = document.createElement("span");
50
+ group.className = "archlang-views-storeys";
51
+ group.setAttribute("role", "group");
52
+ group.setAttribute("aria-label", "Storeys shown");
53
+ group.append("Storeys ");
54
+ for (let k = 1; k <= view.storeys; k++) {
55
+ const all = k === view.storeys;
56
+ const b = button(
57
+ all ? "All" : k === 1 ? "1" : `1\u2013${k}`,
58
+ all ? "Show every storey" : `Show storeys 1 to ${k}, hide the ones above`,
59
+ () => view.showStoreys(k)
60
+ );
61
+ b.dataset.storeys = String(k);
62
+ storeyButtons.push(b);
63
+ group.append(b);
64
+ }
65
+ bar.append(group);
66
+ }
67
+ view.onChange(press);
68
+ press();
69
+ const hint = document.createElement("span");
70
+ hint.className = "archlang-views-hint";
71
+ if (opts.hintId) hint.id = opts.hintId;
72
+ hint.textContent = VIEW_HINT;
73
+ bar.append(hint);
74
+ return bar;
75
+ }
76
+
77
+ // src/replay/payload.ts
78
+ var PREVIEW_LEAD = "Same source, plan and 3D preview.";
79
+ 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.";
80
+ var PREVIEW_LIMITS = "3D preview: walls, openings, floors, stairs and furniture in flat colours; no pitched roofs yet, and no sections, elevations or BIM.";
81
+ var PREVIEW_ABOUT_URL = "https://archlang.uk/3d";
82
+ function viewBoxOf(svg) {
83
+ const m = /viewBox="([-\d.\s]+)"/.exec(svg);
84
+ const v = (m?.[1] ?? "").trim().split(/\s+/).map(Number);
85
+ if (v.length !== 4 || v.some((x) => !Number.isFinite(x))) throw new Error("the drawing has no numeric viewBox");
86
+ return v;
87
+ }
88
+ function replayPayload(mesh, opts) {
89
+ const lifts = explodeLifts(mesh);
90
+ return {
91
+ title: opts.title,
92
+ theme: opts.theme ?? "light",
93
+ width: opts.width ?? 1920,
94
+ height: opts.height ?? 1080,
95
+ seconds: opts.seconds ?? 15,
96
+ svg: opts.svg,
97
+ viewBox: viewBoxOf(opts.svg),
98
+ elevation: endElevation(storeysOf(mesh).length),
99
+ ...opts.facts ? { facts: opts.facts } : {},
100
+ nodes: mesh.nodes.filter((n) => !n.hidden).map((n) => {
101
+ const positions = [];
102
+ const indices = [];
103
+ const slotted = n.shells.some((s) => s.slot !== void 0);
104
+ const groups = slotted ? slotGroups(n.shells) : [{ slot: "body", shells: n.shells }];
105
+ const runs = [];
106
+ for (const g of groups) {
107
+ const start = indices.length;
108
+ for (const s of g.shells) {
109
+ const base = positions.length / 3;
110
+ positions.push(...s.positions);
111
+ for (const i of s.indices) indices.push(base + i);
112
+ }
113
+ runs.push({ slot: g.slot, count: indices.length - start });
114
+ }
115
+ const lift = lifts.get(n.level) ?? 0;
116
+ const finish = FLOOR_FINISHES.find((f) => f === n.extras.finish);
117
+ return {
118
+ key: n.key,
119
+ kind: n.kind,
120
+ ...n.part ? { part: n.part } : {},
121
+ ...lift !== 0 ? { lift } : {},
122
+ positions,
123
+ indices,
124
+ ...slotted ? { groups: runs } : {},
125
+ ...n.kind === "floor" && finish ? { finish } : {}
126
+ };
127
+ }),
128
+ events: timeline(mesh)
129
+ };
130
+ }
131
+
132
+ export {
133
+ PRESET_LABELS,
134
+ VIEW_HINT,
135
+ VIEW_CONTROLS_LABEL,
136
+ viewToolbar,
137
+ PREVIEW_LEAD,
138
+ PREVIEW_LABEL,
139
+ PREVIEW_LIMITS,
140
+ PREVIEW_ABOUT_URL,
141
+ viewBoxOf,
142
+ replayPayload
143
+ };