@chanmeng666/archlang-3d 0.4.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 +38 -0
- package/README.md +1 -1
- package/dist/browser.d.ts +30 -1
- package/dist/browser.js +56 -12
- package/dist/{chunk-KF5ME6KH.js → chunk-4SQ5YKKX.js} +59 -5
- package/dist/{chunk-VS4OAVPD.js → chunk-L2CX7KWM.js} +1 -1
- package/dist/{chunk-RPGAMA3G.js → chunk-OWZWBKMI.js} +95 -28
- package/dist/{chunk-EG7UT2HG.js → chunk-WCWLYIVD.js} +1 -1
- package/dist/cli.js +4 -4
- package/dist/index.js +2 -2
- package/dist/node.d.ts +11 -3
- package/dist/node.js +3 -3
- package/dist/replay.d.ts +8 -1
- package/dist/viewer.iife.js +34 -34
- package/package.json +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,44 @@
|
|
|
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
|
+
|
|
5
43
|
## [0.4.0] - 2026-11-06
|
|
6
44
|
|
|
7
45
|
The core peer range is now `^1.57.0` (was `^1.45.0`): 1.57.0 is the first core that exports
|
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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. 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.
|
|
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
9
|
|
|
10
10
|
3D preview: walls, openings, floors, stairs and furniture in flat colours; no pitched roofs yet,
|
|
11
11
|
and no sections, elevations or BIM.
|
package/dist/browser.d.ts
CHANGED
|
@@ -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
|
/**
|
|
@@ -105,8 +120,22 @@ interface ToolbarOptions {
|
|
|
105
120
|
buttonClass?: string;
|
|
106
121
|
/** An id for the hint line, so the canvas can point at it (`aria-describedby`). */
|
|
107
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;
|
|
108
137
|
}
|
|
109
|
-
/** 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. */
|
|
110
139
|
declare function viewToolbar(view: ViewControl, opts?: ToolbarOptions): HTMLElement;
|
|
111
140
|
|
|
112
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
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
replayPayload,
|
|
10
10
|
viewBoxOf,
|
|
11
11
|
viewToolbar
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-4SQ5YKKX.js";
|
|
13
13
|
import {
|
|
14
14
|
ELEVATION_RANGE,
|
|
15
15
|
END_AZIMUTH,
|
|
@@ -119,8 +119,8 @@ var FOOTPRINT_MM = 12;
|
|
|
119
119
|
function mountReplay(out, p, strip, opts = {}) {
|
|
120
120
|
const theme = THEMES[p.theme];
|
|
121
121
|
const furniture = theme.colors.furniture;
|
|
122
|
-
|
|
123
|
-
|
|
122
|
+
let W = p.width;
|
|
123
|
+
let H = p.height;
|
|
124
124
|
const gl = document.createElement("canvas");
|
|
125
125
|
gl.width = W;
|
|
126
126
|
gl.height = H;
|
|
@@ -224,8 +224,8 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
224
224
|
nodes.set(n.key, { g, flat: Math.min(1, FOOTPRINT_MM / Math.max(1e-6, topY - base)), base, lift: n.lift ?? 0 });
|
|
225
225
|
}
|
|
226
226
|
const [vx, vy, vw, vh] = p.viewBox;
|
|
227
|
-
|
|
228
|
-
|
|
227
|
+
let aspect = W / H;
|
|
228
|
+
let { cx, cz, ow, oh } = drawingFrame(p.viewBox, aspect);
|
|
229
229
|
const box = boxOfNodes(p.nodes, { ghosts: true });
|
|
230
230
|
const lo = new Vector3(...box.lo);
|
|
231
231
|
const hi = new Vector3(...box.hi);
|
|
@@ -235,16 +235,16 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
235
235
|
ortho.position.set(cx, top + 5e4, cz);
|
|
236
236
|
ortho.lookAt(cx, 0, cz);
|
|
237
237
|
const persp = new PerspectiveCamera(START_FOV, aspect, 10, 1e9);
|
|
238
|
-
const
|
|
239
|
-
|
|
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);
|
|
240
240
|
const size = hi.clone().sub(lo);
|
|
241
241
|
const mid = lo.clone().add(hi).multiplyScalar(0.5);
|
|
242
242
|
const radiusOver = (cams) => {
|
|
243
243
|
const reach = Math.max(...cams.map((f) => mid.distanceTo(new Vector3(...f.target))));
|
|
244
244
|
return Math.max(size.length() * 0.75 + reach + Math.hypot(mid.x - (vx + vw / 2), mid.z - (vy + vh / 2)), 1e3);
|
|
245
245
|
};
|
|
246
|
-
|
|
247
|
-
|
|
246
|
+
let radius = radiusOver(fits.slice(0, stopCount(p.events)));
|
|
247
|
+
let endRadius = radiusOver(fits);
|
|
248
248
|
const rad = (d) => d * Math.PI / 180;
|
|
249
249
|
const img = new Image();
|
|
250
250
|
const ready = new Promise((resolve) => {
|
|
@@ -253,12 +253,13 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
253
253
|
});
|
|
254
254
|
img.src = `data:image/svg+xml;base64,${btoa(unescape(encodeURIComponent(p.svg)))}`;
|
|
255
255
|
let disposed = false;
|
|
256
|
-
|
|
256
|
+
let frameView = { cx, cz, oh, elevation: p.elevation };
|
|
257
257
|
const storeyOf = new Map(p.events.map((e) => [e.key, e.storey ?? 0]));
|
|
258
258
|
const storeys = Math.max(1, ...p.events.filter((e) => !e.hidden).map((e) => (e.storey ?? 0) + 1));
|
|
259
259
|
let shown = storeys;
|
|
260
260
|
let holder = "replay";
|
|
261
261
|
let tNow = 0;
|
|
262
|
+
let drawn = false;
|
|
262
263
|
const halfDiagonal = size.length() / 2;
|
|
263
264
|
const reachFrom = (target) => Math.max(endRadius, mid.distanceTo(target) + halfDiagonal);
|
|
264
265
|
function place(f, r) {
|
|
@@ -274,7 +275,7 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
274
275
|
persp.position.set(...cameraPosition([target.x, target.y, target.z], dist, { elevation, azimuth }));
|
|
275
276
|
persp.lookAt(target);
|
|
276
277
|
}
|
|
277
|
-
|
|
278
|
+
let viewScene = {
|
|
278
279
|
events: p.events,
|
|
279
280
|
fits,
|
|
280
281
|
frame: frameView,
|
|
@@ -302,6 +303,7 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
302
303
|
};
|
|
303
304
|
function draw(t) {
|
|
304
305
|
tNow = t;
|
|
306
|
+
drawn = true;
|
|
305
307
|
if (strip && p.facts) paintStrip(strip, stripAt(p.facts, p.events, Math.min(1, Math.max(0, t))));
|
|
306
308
|
const s = stateAt(p.events, t);
|
|
307
309
|
for (const [key2, { g, flat, base, lift }] of nodes) {
|
|
@@ -493,6 +495,17 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
493
495
|
listeners.add(fn);
|
|
494
496
|
return () => listeners.delete(fn);
|
|
495
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
|
+
},
|
|
496
509
|
get shown() {
|
|
497
510
|
return shown;
|
|
498
511
|
},
|
|
@@ -517,6 +530,37 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
517
530
|
}
|
|
518
531
|
};
|
|
519
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
|
+
}
|
|
520
564
|
function dispose() {
|
|
521
565
|
if (disposed) return;
|
|
522
566
|
halt();
|
|
@@ -526,7 +570,7 @@ function mountReplay(out, p, strip, opts = {}) {
|
|
|
526
570
|
renderer.dispose();
|
|
527
571
|
renderer.forceContextLoss();
|
|
528
572
|
}
|
|
529
|
-
return { seek, frameHash, ready, dispose, ...view ? { view } : {} };
|
|
573
|
+
return { seek, frameHash, ready, dispose, resize, ...view ? { view } : {} };
|
|
530
574
|
}
|
|
531
575
|
export {
|
|
532
576
|
PRESET_LABELS,
|
|
@@ -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, () =>
|
|
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
|
-
|
|
48
|
-
if (
|
|
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");
|
|
@@ -76,7 +130,7 @@ function viewToolbar(view, opts = {}) {
|
|
|
76
130
|
|
|
77
131
|
// src/replay/payload.ts
|
|
78
132
|
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.";
|
|
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.";
|
|
80
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.";
|
|
81
135
|
var PREVIEW_ABOUT_URL = "https://archlang.uk/3d";
|
|
82
136
|
function viewBoxOf(svg) {
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ARCHLANG_3D_VERSION,
|
|
3
3
|
validateScene3D
|
|
4
|
-
} from "./chunk-
|
|
4
|
+
} from "./chunk-WCWLYIVD.js";
|
|
5
5
|
import {
|
|
6
6
|
PREVIEW_LABEL,
|
|
7
7
|
PREVIEW_LIMITS,
|
|
8
8
|
VIEW_CONTROLS_LABEL,
|
|
9
9
|
replayPayload
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-4SQ5YKKX.js";
|
|
11
11
|
import {
|
|
12
12
|
FINISH_PALETTE,
|
|
13
13
|
FLOOR_FINISHES,
|
|
@@ -18,16 +18,96 @@ import {
|
|
|
18
18
|
slotGroups
|
|
19
19
|
} from "./chunk-EQBMPXB5.js";
|
|
20
20
|
|
|
21
|
-
// src/
|
|
22
|
-
import { readFileSync
|
|
23
|
-
import { resolve } from "node:path";
|
|
21
|
+
// src/world.ts
|
|
22
|
+
import { readFileSync, realpathSync, statSync } from "node:fs";
|
|
23
|
+
import { dirname, isAbsolute, relative, resolve } from "node:path";
|
|
24
|
+
import { utf8ByteLength } from "@chanmeng666/archlang";
|
|
25
|
+
var MODULE_CAP_BYTES = 1024 * 1024;
|
|
26
|
+
function isWithin(root, child) {
|
|
27
|
+
const rel = relative(root, child);
|
|
28
|
+
if (rel === "") return true;
|
|
29
|
+
return rel !== ".." && !rel.startsWith("../") && !rel.startsWith("..\\") && !isAbsolute(rel);
|
|
30
|
+
}
|
|
31
|
+
var realOrNull = (p) => {
|
|
32
|
+
try {
|
|
33
|
+
return realpathSync(p);
|
|
34
|
+
} catch {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
};
|
|
38
|
+
function nearestRealAncestor(p) {
|
|
39
|
+
for (let at = dirname(p); ; at = dirname(at)) {
|
|
40
|
+
const real = realOrNull(at);
|
|
41
|
+
if (real !== null) return real;
|
|
42
|
+
if (dirname(at) === at) return null;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
function makeNodeWorld(baseDir, root = process.cwd()) {
|
|
46
|
+
const roots = [resolve(root), resolve(baseDir)].flatMap((r) => {
|
|
47
|
+
const real = realOrNull(r);
|
|
48
|
+
return real === null ? [] : [{ lexical: r, real }];
|
|
49
|
+
});
|
|
50
|
+
const refusals = /* @__PURE__ */ new Map();
|
|
51
|
+
const outside = (path) => ({
|
|
52
|
+
code: "E_IMPORT_OUTSIDE_ROOT",
|
|
53
|
+
message: `Imported module "${path}" is outside the import root (the working directory) and the plan's own directory; run archlang3d from a directory that contains it`
|
|
54
|
+
});
|
|
55
|
+
const notArch = (path) => ({
|
|
56
|
+
code: "E_IMPORT_NOT_ARCH",
|
|
57
|
+
message: `Imported module "${path}" is not an .arch file`
|
|
58
|
+
});
|
|
59
|
+
const inRoot = (abs) => roots.some((r) => isWithin(r.lexical, abs) || isWithin(r.real, abs));
|
|
60
|
+
const inRealRoot = (real) => roots.some((r) => isWithin(r.real, real));
|
|
61
|
+
const isArch = (p) => /\.arch$/i.test(p);
|
|
62
|
+
const attempt = (path) => {
|
|
63
|
+
if (path.includes("\0")) return null;
|
|
64
|
+
const abs = resolve(baseDir, path);
|
|
65
|
+
if (!inRoot(abs)) return outside(path);
|
|
66
|
+
if (!isArch(abs)) return notArch(path);
|
|
67
|
+
const real = realOrNull(abs);
|
|
68
|
+
if (real === null) {
|
|
69
|
+
const ancestor = nearestRealAncestor(abs);
|
|
70
|
+
return ancestor !== null && inRealRoot(ancestor) ? null : outside(path);
|
|
71
|
+
}
|
|
72
|
+
if (!inRealRoot(real)) return outside(path);
|
|
73
|
+
if (!isArch(real)) return notArch(path);
|
|
74
|
+
const st = statSync(real);
|
|
75
|
+
if (!st.isFile()) return null;
|
|
76
|
+
const tooLarge = () => ({
|
|
77
|
+
code: "E_IMPORT_TOO_LARGE",
|
|
78
|
+
message: `Imported module "${path}" is larger than ${String(MODULE_CAP_BYTES)} bytes`
|
|
79
|
+
});
|
|
80
|
+
if (st.size > MODULE_CAP_BYTES) return tooLarge();
|
|
81
|
+
const text = readFileSync(real, "utf8");
|
|
82
|
+
return utf8ByteLength(text) > MODULE_CAP_BYTES ? tooLarge() : text;
|
|
83
|
+
};
|
|
84
|
+
const world = {
|
|
85
|
+
read(path) {
|
|
86
|
+
let r;
|
|
87
|
+
try {
|
|
88
|
+
r = attempt(path);
|
|
89
|
+
} catch {
|
|
90
|
+
r = null;
|
|
91
|
+
}
|
|
92
|
+
if (typeof r === "string") {
|
|
93
|
+
refusals.delete(path);
|
|
94
|
+
return r;
|
|
95
|
+
}
|
|
96
|
+
if (r) refusals.set(path, r);
|
|
97
|
+
else refusals.delete(path);
|
|
98
|
+
return null;
|
|
99
|
+
},
|
|
100
|
+
refusal: (path) => refusals.get(path)
|
|
101
|
+
};
|
|
102
|
+
return world;
|
|
103
|
+
}
|
|
24
104
|
|
|
25
105
|
// src/replay/html.ts
|
|
26
|
-
import { existsSync, readFileSync } from "node:fs";
|
|
106
|
+
import { existsSync, readFileSync as readFileSync2 } from "node:fs";
|
|
27
107
|
import { createRequire } from "node:module";
|
|
28
|
-
import { dirname, join } from "node:path";
|
|
108
|
+
import { dirname as dirname2, join } from "node:path";
|
|
29
109
|
import { fileURLToPath } from "node:url";
|
|
30
|
-
var HERE =
|
|
110
|
+
var HERE = dirname2(fileURLToPath(import.meta.url));
|
|
31
111
|
var require2 = createRequire(import.meta.url);
|
|
32
112
|
var bundled;
|
|
33
113
|
async function loadViewer() {
|
|
@@ -35,7 +115,7 @@ async function loadViewer() {
|
|
|
35
115
|
const { bundleViewer } = await null;
|
|
36
116
|
return bundleViewer(join(HERE, "viewer.ts"));
|
|
37
117
|
}
|
|
38
|
-
return
|
|
118
|
+
return readFileSync2(join(HERE, "viewer.iife.js"), "utf8");
|
|
39
119
|
}
|
|
40
120
|
function viewerScript() {
|
|
41
121
|
bundled ??= loadViewer().catch((e) => {
|
|
@@ -45,15 +125,15 @@ function viewerScript() {
|
|
|
45
125
|
return bundled;
|
|
46
126
|
}
|
|
47
127
|
function threeLicence() {
|
|
48
|
-
let dir =
|
|
128
|
+
let dir = dirname2(require2.resolve("three"));
|
|
49
129
|
while (!existsSync(join(dir, "package.json")) || !existsSync(join(dir, "LICENSE"))) {
|
|
50
|
-
const up =
|
|
130
|
+
const up = dirname2(dir);
|
|
51
131
|
if (up === dir) throw new Error("three.js's LICENSE was not found beside its package.json");
|
|
52
132
|
dir = up;
|
|
53
133
|
}
|
|
54
|
-
const version = JSON.parse(
|
|
134
|
+
const version = JSON.parse(readFileSync2(join(dir, "package.json"), "utf8")).version;
|
|
55
135
|
return `three.js ${version}
|
|
56
|
-
${
|
|
136
|
+
${readFileSync2(join(dir, "LICENSE"), "utf8")}`;
|
|
57
137
|
}
|
|
58
138
|
var escapeHtml = (s) => s.replace(/[&<>"]/g, (c) => ({ "&": "&", "<": "<", ">": ">", '"': """ })[c]);
|
|
59
139
|
async function replayHtml(mesh, opts) {
|
|
@@ -487,20 +567,8 @@ async function checkGlb(glb, mesh) {
|
|
|
487
567
|
return out;
|
|
488
568
|
}
|
|
489
569
|
|
|
490
|
-
// src/node.ts
|
|
491
|
-
function makeNodeWorld(baseDir) {
|
|
492
|
-
return {
|
|
493
|
-
read: (p) => {
|
|
494
|
-
try {
|
|
495
|
-
return readFileSync2(resolve(baseDir, p), "utf8");
|
|
496
|
-
} catch {
|
|
497
|
-
return null;
|
|
498
|
-
}
|
|
499
|
-
}
|
|
500
|
-
};
|
|
501
|
-
}
|
|
502
|
-
|
|
503
570
|
export {
|
|
571
|
+
makeNodeWorld,
|
|
504
572
|
viewerScript,
|
|
505
573
|
replayHtml,
|
|
506
574
|
SWIFTSHADER_ARGS,
|
|
@@ -520,6 +588,5 @@ export {
|
|
|
520
588
|
checkNaming,
|
|
521
589
|
glbJson,
|
|
522
590
|
checkValidator,
|
|
523
|
-
checkGlb
|
|
524
|
-
makeNodeWorld
|
|
591
|
+
checkGlb
|
|
525
592
|
};
|
package/dist/cli.js
CHANGED
|
@@ -3,7 +3,7 @@ import {
|
|
|
3
3
|
DOOR_POSES,
|
|
4
4
|
adaptPlan,
|
|
5
5
|
buildMesh
|
|
6
|
-
} from "./chunk-
|
|
6
|
+
} from "./chunk-L2CX7KWM.js";
|
|
7
7
|
import {
|
|
8
8
|
SWIFTSHADER_ARGS,
|
|
9
9
|
checkGlb,
|
|
@@ -13,12 +13,12 @@ import {
|
|
|
13
13
|
renderReplay,
|
|
14
14
|
replayHtml,
|
|
15
15
|
writeGlb
|
|
16
|
-
} from "./chunk-
|
|
16
|
+
} from "./chunk-OWZWBKMI.js";
|
|
17
17
|
import {
|
|
18
18
|
ARCHLANG_3D_VERSION,
|
|
19
19
|
replayFacts
|
|
20
|
-
} from "./chunk-
|
|
21
|
-
import "./chunk-
|
|
20
|
+
} from "./chunk-WCWLYIVD.js";
|
|
21
|
+
import "./chunk-4SQ5YKKX.js";
|
|
22
22
|
import {
|
|
23
23
|
storeysOf,
|
|
24
24
|
timeline,
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
slabRegion,
|
|
10
10
|
stairRisers,
|
|
11
11
|
stairSolid
|
|
12
|
-
} from "./chunk-
|
|
12
|
+
} from "./chunk-L2CX7KWM.js";
|
|
13
13
|
import {
|
|
14
14
|
ARCHLANG_3D_VERSION,
|
|
15
15
|
FLOOR_LIFT_UM,
|
|
@@ -44,7 +44,7 @@ import {
|
|
|
44
44
|
umPoint,
|
|
45
45
|
validateScene3D,
|
|
46
46
|
wallOwnership
|
|
47
|
-
} from "./chunk-
|
|
47
|
+
} from "./chunk-WCWLYIVD.js";
|
|
48
48
|
import {
|
|
49
49
|
ELEVATION_AZIMUTH,
|
|
50
50
|
ELEVATION_RANGE,
|
package/dist/node.d.ts
CHANGED
|
@@ -5,6 +5,17 @@ import { ReplayOptions } from './replay.js';
|
|
|
5
5
|
export { PREVIEW_ABOUT_URL, PREVIEW_LABEL, PREVIEW_LEAD, PREVIEW_LIMITS, replayPayload, viewBoxOf } from './replay.js';
|
|
6
6
|
export { F as FactsOptions, r as replayFacts } from './facts-BRIFxHL_.js';
|
|
7
7
|
|
|
8
|
+
/**
|
|
9
|
+
* A World that reads an `import`ed module relative to `baseDir` (the plan's own directory). It is
|
|
10
|
+
* ROOTED: a module is read only when its real path (symbolic links and junctions followed) lies
|
|
11
|
+
* under `root` (default: the working directory) or under `baseDir`, ends in `.arch`, and is at most
|
|
12
|
+
* {@link MODULE_CAP_BYTES}. A refused module reads as `null` and `refusal` names the code
|
|
13
|
+
* (`E_IMPORT_OUTSIDE_ROOT`, `E_IMPORT_NOT_ARCH`, `E_IMPORT_TOO_LARGE`), which the core reports at
|
|
14
|
+
* the `import`; a module missing inside the roots is the core's `E_IMPORT_NOT_FOUND`. A path whose
|
|
15
|
+
* written form leaves the roots is refused before the file system is touched.
|
|
16
|
+
*/
|
|
17
|
+
declare function makeNodeWorld(baseDir: string, root?: string): World;
|
|
18
|
+
|
|
8
19
|
/** The viewer and the parts of three.js it uses, as one minified browser script (read once). */
|
|
9
20
|
declare function viewerScript(): Promise<string>;
|
|
10
21
|
/** A replay of `mesh` as one self-contained HTML document. */
|
|
@@ -132,7 +143,4 @@ declare function checkValidator(glb: Uint8Array): Promise<CheckResult>;
|
|
|
132
143
|
/** Every check a GLB alone allows (`archlang3d check model.glb`); given its Mesh3D, the node sets are compared. */
|
|
133
144
|
declare function checkGlb(glb: Uint8Array, mesh?: Mesh3D): Promise<CheckResult[]>;
|
|
134
145
|
|
|
135
|
-
/** A World that reads an `import`ed module relative to `baseDir`; a missing file reads as `null`. */
|
|
136
|
-
declare function makeNodeWorld(baseDir: string): World;
|
|
137
|
-
|
|
138
146
|
export { type CheckId, type CheckResult, GLB_GENERATOR, type GlbNode, type KeyFrame, ReplayOptions, SWIFTSHADER_ARGS, type VideoOptions, type VideoReport, bodyMaterialName, checkGlb, checkNaming, checkScene, checkShells, checkValidator, glbJson, glbLeaks, glbNodeName, levelNodeName, makeNodeWorld, nodeExtras, openEdges, readGlbNodes, renderReplay, replayHtml, signedVolume, viewerScript, writeGlb };
|
package/dist/node.js
CHANGED
|
@@ -20,10 +20,10 @@ import {
|
|
|
20
20
|
signedVolume,
|
|
21
21
|
viewerScript,
|
|
22
22
|
writeGlb
|
|
23
|
-
} from "./chunk-
|
|
23
|
+
} from "./chunk-OWZWBKMI.js";
|
|
24
24
|
import {
|
|
25
25
|
replayFacts
|
|
26
|
-
} from "./chunk-
|
|
26
|
+
} from "./chunk-WCWLYIVD.js";
|
|
27
27
|
import {
|
|
28
28
|
PREVIEW_ABOUT_URL,
|
|
29
29
|
PREVIEW_LABEL,
|
|
@@ -31,7 +31,7 @@ import {
|
|
|
31
31
|
PREVIEW_LIMITS,
|
|
32
32
|
replayPayload,
|
|
33
33
|
viewBoxOf
|
|
34
|
-
} from "./chunk-
|
|
34
|
+
} from "./chunk-4SQ5YKKX.js";
|
|
35
35
|
import {
|
|
36
36
|
stripAt
|
|
37
37
|
} from "./chunk-EQBMPXB5.js";
|
package/dist/replay.d.ts
CHANGED
|
@@ -51,9 +51,16 @@ interface ReplayPayload {
|
|
|
51
51
|
* PS-D11, `docs/plans/public-surfaces/3d.md` §2; it replaced decision D5's label). `PREVIEW_LEAD`
|
|
52
52
|
* is its first sentence, which a host may set in bold. The plan's full line adds "You can also
|
|
53
53
|
* download it as a validated GLB." where a surface offers the download.
|
|
54
|
+
*
|
|
55
|
+
* What "checked against the plan" means, as the line says it: every 3D element comes from the
|
|
56
|
+
* plan's elements (each Scene3D record carries the `source` naming its plan element, required by
|
|
57
|
+
* the schema, V-SCH-01 in `check/verify.ts`; the slab and a default roof come from the storey's
|
|
58
|
+
* rooms and walls; V-GLTF-02 holds the GLB's nodes to the Mesh3D's, each named `<kind>:<id>`), and
|
|
59
|
+
* every solid is closed (V-GEO-02, `openEdges` in `check/verify.ts`: every shell closed,
|
|
60
|
+
* consistently wound, of positive volume). `build` writes nothing when a check fails.
|
|
54
61
|
*/
|
|
55
62
|
declare const PREVIEW_LEAD = "Same source, plan and 3D preview.";
|
|
56
|
-
declare const 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.";
|
|
63
|
+
declare const 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.";
|
|
57
64
|
/**
|
|
58
65
|
* The limits line, always near a 3D view (PS-D12). It states what the package builds today
|
|
59
66
|
* (`3d.md` §3): change it when the package changes.
|