@chanmeng666/archlang-3d 0.0.0-stage → 0.1.1

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,54 @@
1
+ import {
2
+ endElevation,
3
+ explodeLifts,
4
+ storeysOf,
5
+ timeline
6
+ } from "./chunk-CTFMM64C.js";
7
+
8
+ // src/replay/payload.ts
9
+ var PREVIEW_LABEL = "Preview \u2014 from the separate archlang-3d package. ArchLang itself draws plans.";
10
+ function viewBoxOf(svg) {
11
+ const m = /viewBox="([-\d.\s]+)"/.exec(svg);
12
+ const v = (m?.[1] ?? "").trim().split(/\s+/).map(Number);
13
+ if (v.length !== 4 || v.some((x) => !Number.isFinite(x))) throw new Error("the drawing has no numeric viewBox");
14
+ return v;
15
+ }
16
+ function replayPayload(mesh, opts) {
17
+ const lifts = explodeLifts(mesh);
18
+ return {
19
+ title: opts.title,
20
+ theme: opts.theme ?? "light",
21
+ width: opts.width ?? 1920,
22
+ height: opts.height ?? 1080,
23
+ seconds: opts.seconds ?? 15,
24
+ svg: opts.svg,
25
+ viewBox: viewBoxOf(opts.svg),
26
+ elevation: endElevation(storeysOf(mesh).length),
27
+ ...opts.facts ? { facts: opts.facts } : {},
28
+ nodes: mesh.nodes.filter((n) => !n.hidden).map((n) => {
29
+ const positions = [];
30
+ const indices = [];
31
+ for (const s of n.shells) {
32
+ const base = positions.length / 3;
33
+ positions.push(...s.positions);
34
+ for (const i of s.indices) indices.push(base + i);
35
+ }
36
+ const lift = lifts.get(n.level) ?? 0;
37
+ return {
38
+ key: n.key,
39
+ kind: n.kind,
40
+ ...n.part ? { part: n.part } : {},
41
+ ...lift !== 0 ? { lift } : {},
42
+ positions,
43
+ indices
44
+ };
45
+ }),
46
+ events: timeline(mesh)
47
+ };
48
+ }
49
+
50
+ export {
51
+ PREVIEW_LABEL,
52
+ viewBoxOf,
53
+ replayPayload
54
+ };