@chanmeng666/archlang-3d 0.8.1 → 0.9.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,30 @@
2
2
 
3
3
  ## [Unreleased]
4
4
 
5
+ ## [0.9.0] - 2026-11-17
6
+
7
+ The core peer range stays `^1.61.0` (`MIN_CORE`): nothing below reads a core export that 1.61.0 lacks.
8
+
9
+ ### Added
10
+
11
+ - `writeGlb` from a new entry, `@chanmeng666/archlang-3d/glb`, which carries no Node module, so a
12
+ browser can write a plan's GLB bytes (a `Uint8Array`) without Node: the same function and the same
13
+ bytes as `./node`'s `writeGlb` and `archlang3d build`, with `GLB_GENERATOR`, `bodyMaterialName`,
14
+ `glbNodeName`, `levelNodeName` and `nodeExtras`. `./node` still exports all of them, and `.` and
15
+ `./browser` are unchanged, so glTF-Transform reaches neither. The checks (glTF-Validator) stay in
16
+ `./node`. The entry needs no bundler configuration: glTF-Transform (with `property-graph`) is
17
+ now inlined into `dist/` at build, its unused Node reader (a lazy `import("node:fs")`, which
18
+ webpack refuses for a browser target) shaken out, so `./glb` imports no Node module and no other
19
+ package. `./node` and the CLI share that one copy; `@gltf-transform/core` stays a dependency at
20
+ the same exact pin, though `dist/` no longer imports it.
21
+
22
+ ### Fixed
23
+
24
+ - The no-browser path of `view` no longer leaves its scratch directory in the temp folder:
25
+ `renderReplay` now removes it however it ends, including when no browser starts. The removal
26
+ retries a busy directory (seen on Windows), and a failed removal never replaces the render's
27
+ result or its error.
28
+
5
29
  ## [0.8.1] - 2026-11-15
6
30
 
7
31
  The core peer range stays `^1.61.0` (`MIN_CORE`): nothing below reads a core export that 1.61.0 lacks.
package/README.md CHANGED
@@ -86,10 +86,29 @@ if (!result.ok) throw new Error(result.refusal.code); // E3D_PLAN_ERRORS, E3D_NO
86
86
  writeFileSync("plan.glb", await writeGlb(buildMesh(result.scene)));
87
87
  ```
88
88
 
89
+ In a browser, `writeGlb` comes from `./glb` and returns the same bytes, with no file system
90
+ (`./glb` is new in 0.9.0):
91
+
92
+ ```js
93
+ import { adaptPlan, buildMesh } from "@chanmeng666/archlang-3d";
94
+ import { writeGlb } from "@chanmeng666/archlang-3d/glb";
95
+
96
+ const result = adaptPlan(source);
97
+ if (result.ok) {
98
+ const bytes = await writeGlb(buildMesh(result.scene)); // a Uint8Array
99
+ const url = URL.createObjectURL(new Blob([bytes], { type: "model/gltf-binary" }));
100
+ }
101
+ ```
102
+
103
+ The checks `build` runs (glTF-Validator among them) need Node and stay in `./node`. `./glb` needs no
104
+ bundler configuration: glTF-Transform, which writes the GLB, is built into the package with its
105
+ unused Node reader removed, so the entry imports no Node module and no other package.
106
+
89
107
  | Entry | For | Holds |
90
108
  |---|---|---|
91
109
  | `@chanmeng666/archlang-3d` | Node and browsers | `adaptPlan`, Scene3D, `buildMesh`, the replay's timeline |
92
110
  | `@chanmeng666/archlang-3d/browser` | browsers, with three.js | `mountReplay(canvas, payload)`, `replayPayload` |
111
+ | `@chanmeng666/archlang-3d/glb` | Node and browsers (0.9.0 and later) | `writeGlb` (the GLB's bytes) and its node names |
93
112
  | `@chanmeng666/archlang-3d/node` | Node | `makeNodeWorld`, `replayHtml`, `renderReplay`, `writeGlb`, the checks |
94
113
 
95
114
  ## Licence
@@ -8,7 +8,7 @@ The packages below are the package's runtime dependencies, transitively, each so
8
8
  @gltf-transform/core 4.5.1 — MIT
9
9
  https://github.com/donmccurdy/glTF-Transform
10
10
 
11
- LICENSE.md is MIT (Don McCurdy). Original TypeScript; it wraps or ports no other project. One dependency, property-graph (same author).
11
+ LICENSE.md is MIT (Don McCurdy). Original TypeScript; its published dist/index.js bundles parts of gl-matrix 3.4.4 (vec3, mat4; MIT, read 2026-11-17 from the gl-matrix 3.4.4 tarball: Copyright (c) 2015-2025, Brandon Jones, Colin MacKenzie IV, under the same MIT permission notice as below), which this package inlines into dist/ with the library (tsup.config.ts). One dependency, property-graph (same author).
12
12
 
13
13
  The MIT License (MIT)
14
14
 
package/dist/browser.d.ts CHANGED
@@ -1,6 +1,7 @@
1
- import { P as PresetName, V as Vec3 } from './camera-BAsRq_eC.js';
2
- import { R as ReplayPayload, S as StripItem } from './payload-DwiB2P7x.js';
3
- export { P as PREVIEW_ABOUT_URL, a as PREVIEW_LABEL, b as PREVIEW_LEAD, c as PREVIEW_LIMITS, d as ReplayFacts, e as ReplayNode, f as ReplayOptions, n as noticeLevelLabel, r as replayPayload, s as stripAt, v as viewBoxOf } from './payload-DwiB2P7x.js';
1
+ import { P as PresetName, V as Vec3 } from './camera-BqK_JhhV.js';
2
+ import { d as ReplayPayload, S as StripItem } from './payload-CKSLN1CG.js';
3
+ export { P as PREVIEW_ABOUT_URL, e as PREVIEW_LABEL, f as PREVIEW_LEAD, g as PREVIEW_LIMITS, c as ReplayFacts, h as ReplayNode, i as ReplayOptions, n as noticeLevelLabel, r as replayPayload, s as stripAt, v as viewBoxOf } from './payload-CKSLN1CG.js';
4
+ import './types-BQ7xE4YH.js';
4
5
  import '@chanmeng666/archlang';
5
6
 
6
7
  interface ReplayHandle {
package/dist/browser.js CHANGED
@@ -4,7 +4,8 @@ import {
4
4
  faceParts,
5
5
  joinedGroups,
6
6
  wallOutline
7
- } from "./chunk-JQTG6BDR.js";
7
+ } from "./chunk-PKFGND2A.js";
8
+ import "./chunk-ISFIFLC7.js";
8
9
  import {
9
10
  PRESET_LABELS,
10
11
  PREVIEW_ABOUT_URL,
@@ -17,35 +18,37 @@ import {
17
18
  replayPayload,
18
19
  viewBoxOf,
19
20
  viewToolbar
20
- } from "./chunk-VMVKI2WQ.js";
21
+ } from "./chunk-6EAHOIL6.js";
21
22
  import {
22
- CONTACT_SHADOW,
23
23
  ELEVATION_RANGE,
24
24
  END_AZIMUTH,
25
25
  END_FOV,
26
- GROUND_PLANE,
27
- KIND_PALETTE,
28
- PALETTE,
29
26
  START_FOV,
30
- WALL_CAP_SRGB,
31
27
  boxOfNodes,
32
28
  cameraPosition,
33
29
  cameraStops,
34
30
  distanceLimits,
35
31
  drawingFrame,
36
- finishColour,
37
32
  frameCamera,
38
33
  pivotAbove,
39
34
  presetCamera,
40
35
  settledLift,
41
- siteColour,
42
- slotColour,
43
36
  stateAt,
44
37
  stopCount,
45
38
  stripAt,
46
39
  takenLens,
47
40
  targetBounds
48
- } from "./chunk-LNIVDMPG.js";
41
+ } from "./chunk-EL4456GB.js";
42
+ import {
43
+ CONTACT_SHADOW,
44
+ GROUND_PLANE,
45
+ KIND_PALETTE,
46
+ PALETTE,
47
+ WALL_CAP_SRGB,
48
+ finishColour,
49
+ siteColour,
50
+ slotColour
51
+ } from "./chunk-ONUOWO37.js";
49
52
 
50
53
  // src/replay/mount.ts
51
54
  import {
@@ -1,4 +1,4 @@
1
- import { a3 as ReplayEvent, a4 as ReplayState } from './payload-DwiB2P7x.js';
1
+ import { R as ReplayEvent, a as ReplayState } from './payload-CKSLN1CG.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
@@ -1,27 +1,19 @@
1
1
  import {
2
- ARCHLANG_3D_VERSION,
3
2
  validateScene3D
4
- } from "./chunk-33J3YGNF.js";
3
+ } from "./chunk-E65Z5S4K.js";
5
4
  import {
6
5
  PREVIEW_LABEL,
7
6
  PREVIEW_LIMITS,
8
7
  VIEW_CONTROLS_LABEL,
9
8
  noticeLevelLabel,
10
9
  replayPayload
11
- } from "./chunk-VMVKI2WQ.js";
10
+ } from "./chunk-6EAHOIL6.js";
12
11
  import {
13
- FENCE_PALETTE,
14
- FINISH_PALETTE,
15
- FLOOR_FINISHES,
16
- GROUND_ROUGHNESS,
17
- GROUND_SPLITS,
18
- GROUND_TINT,
19
- KIND_PALETTE,
20
- PALETTE,
21
- keyFrames,
22
- linearRgb,
23
- slotGroups
24
- } from "./chunk-LNIVDMPG.js";
12
+ keyFrames
13
+ } from "./chunk-EL4456GB.js";
14
+ import {
15
+ readGlbNodes
16
+ } from "./chunk-7FYCBISZ.js";
25
17
 
26
18
  // src/world.ts
27
19
  import { readFileSync, realpathSync, statSync } from "node:fs";
@@ -235,16 +227,23 @@ function withSupersample(html, k = 1) {
235
227
  const json = JSON.stringify({ ...p, supersample: k }).replace(/</g, "\\u003c");
236
228
  return html.slice(0, at + PAYLOAD_OPEN.length) + json + html.slice(end);
237
229
  }
230
+ function removeScratch(dir) {
231
+ try {
232
+ rmSync(dir, { recursive: true, force: true, maxRetries: 5, retryDelay: 100 });
233
+ } catch {
234
+ }
235
+ }
238
236
  async function renderReplay(o) {
239
237
  const fps = o.fps ?? 30;
240
238
  const seconds = o.seconds ?? 15;
241
239
  const frames = Math.round(fps * seconds);
242
240
  const dir = mkdtempSync(join2(tmpdir(), "archlang3d-replay-"));
243
- const file = join2(dir, "replay.html");
244
- writeFileSync(file, seekOnly(withSupersample(o.html, o.supersample)));
245
- const { chromium } = await import("playwright-core");
246
- const browser = await chromium.launch({ args: SWIFTSHADER_ARGS });
241
+ let browser;
247
242
  try {
243
+ const file = join2(dir, "replay.html");
244
+ writeFileSync(file, seekOnly(withSupersample(o.html, o.supersample)));
245
+ const { chromium } = await import("playwright-core");
246
+ browser = await chromium.launch({ args: SWIFTSHADER_ARGS });
248
247
  const page = await browser.newPage({
249
248
  viewport: { width: o.width + 40, height: o.height + 120 },
250
249
  deviceScaleFactor: 1
@@ -352,129 +351,12 @@ async function renderReplay(o) {
352
351
  browser: browser.version()
353
352
  };
354
353
  } finally {
355
- await browser.close();
356
- rmSync(dir, { recursive: true, force: true });
357
- }
358
- }
359
-
360
- // src/glb/write.ts
361
- import { Document, Logger, WebIO } from "@gltf-transform/core";
362
- var GLB_GENERATOR = `archlang-3d ${ARCHLANG_3D_VERSION}`;
363
- function bodyMaterialName(n) {
364
- if (n.kind === "floor") return `floor:${FLOOR_FINISHES.find((f) => f === n.extras.finish) ?? "neutral"}`;
365
- if (n.kind === "wall" && n.part === "demolish") return "wall:demolish";
366
- if (n.kind === "window" && n.part && `window:${n.part}` in KIND_PALETTE) return `window:${n.part}`;
367
- if ((n.kind === "opening" || n.kind === "stair") && n.part && `${n.kind}:${n.part}` in KIND_PALETTE)
368
- return `${n.kind}:${n.part}`;
369
- if (n.kind === "outdoor") return `outdoor:${String(n.extras.surface)}`;
370
- if (n.kind === "fence") return `fence:${String(n.extras.style)}`;
371
- return n.kind;
372
- }
373
- function bodyMaterial(name, n) {
374
- if (n.kind === "outdoor" || n.kind === "fence") {
375
- const own = n.kind === "fence" ? FENCE_PALETTE[String(n.extras.style)] : GROUND_SPLITS[String(n.extras.surface)];
376
- const tint = GROUND_TINT[String(n.extras.surface)] ?? "paving";
377
- const roughness = own?.roughness ?? (n.kind === "fence" ? FENCE_PALETTE.picket.roughness : GROUND_ROUGHNESS[tint]);
378
- const srgb = typeof n.extras.colour === "string" ? n.extras.colour : KIND_PALETTE.furniture.srgb;
379
- return { srgb, alpha: 1, metallic: 0, roughness };
380
- }
381
- if (name.startsWith("floor:")) return FINISH_PALETTE[name.slice("floor:".length)];
382
- return KIND_PALETTE[name] ?? KIND_PALETTE.furniture;
383
- }
384
- var glbNodeName = (n) => n.key.slice(n.key.indexOf("/") + 1);
385
- var levelNodeName = (level) => `level:L${level}`;
386
- function nodeExtras(n) {
387
- const own = Object.keys(n.extras).sort().map((k) => [k, n.extras[k]]);
388
- return {
389
- key: n.key,
390
- kind: n.kind,
391
- id: n.id,
392
- ...n.part ? { part: n.part } : {},
393
- level: n.level,
394
- stage: n.stage,
395
- order: n.order,
396
- ...n.hidden ? { hidden: true } : {},
397
- ...Object.fromEntries(own)
398
- };
399
- }
400
- async function writeGlb(mesh, opts = {}) {
401
- const doc = new Document();
402
- doc.setLogger(new Logger(Logger.Verbosity.SILENT));
403
- doc.getRoot().getAsset().generator = opts.generator ?? GLB_GENERATOR;
404
- const buffer = doc.createBuffer();
405
- const scene = doc.createScene(mesh.name);
406
- doc.getRoot().setDefaultScene(scene);
407
- const materials = /* @__PURE__ */ new Map();
408
- const material = (n) => {
409
- const key = bodyMaterialName(n);
410
- let m = materials.get(key);
411
- if (!m) {
412
- const p = bodyMaterial(key, n);
413
- m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
414
- if (p.alpha < 1) m.setAlphaMode("BLEND");
415
- materials.set(key, m);
416
- }
417
- return m;
418
- };
419
- const slotMaterial = (slot) => {
420
- const key = `fixture:${slot}`;
421
- let m = materials.get(key);
422
- if (!m) {
423
- const p = PALETTE[slot];
424
- m = doc.createMaterial(key).setBaseColorFactor([...linearRgb(p.srgb), p.alpha]).setMetallicFactor(p.metallic).setRoughnessFactor(p.roughness);
425
- if (p.alpha < 1) m.setAlphaMode("BLEND");
426
- materials.set(key, m);
427
- }
428
- return m;
429
- };
430
- const levels = /* @__PURE__ */ new Map();
431
- for (const n of mesh.nodes) {
432
- let group = levels.get(n.level);
433
- if (!group) {
434
- group = doc.createNode(levelNodeName(n.level)).setExtras({ archlang: { kind: "level", level: n.level } });
435
- scene.addChild(group);
436
- levels.set(n.level, group);
437
- }
438
- const name = glbNodeName(n);
439
- const gmesh = doc.createMesh(name);
440
- for (const g of slotGroups(n.shells)) {
441
- const positions = [];
442
- const indices = [];
443
- for (const s of g.shells) {
444
- const base = positions.length / 3;
445
- for (const v of s.positions) positions.push(v / 1e6);
446
- for (const i of s.indices) indices.push(base + i);
447
- }
448
- const count = positions.length / 3;
449
- const pos = doc.createAccessor().setType("VEC3").setArray(new Float32Array(positions)).setBuffer(buffer);
450
- const idx = doc.createAccessor().setType("SCALAR").setArray(count > 65535 ? new Uint32Array(indices) : new Uint16Array(indices)).setBuffer(buffer);
451
- const mat = g.slot === "body" ? material(n) : slotMaterial(g.slot);
452
- gmesh.addPrimitive(doc.createPrimitive().setAttribute("POSITION", pos).setIndices(idx).setMaterial(mat));
453
- }
454
- const node = doc.createNode(name).setMesh(gmesh).setExtras({ archlang: nodeExtras(n) });
455
- group.addChild(node);
456
- }
457
- return new WebIO().writeBinary(doc);
458
- }
459
- async function readGlbNodes(glb) {
460
- const doc = await new WebIO().readBinary(glb);
461
- const levels = [];
462
- const nodes = [];
463
- const walk = (parent, prefix) => {
464
- for (const c of parent.listChildren()) {
465
- const extras = c.getExtras().archlang ?? {};
466
- nodes.push({ key: `${prefix}${c.getName()}`, name: c.getName(), extras });
467
- walk(c, prefix);
468
- }
469
- };
470
- for (const scene of doc.getRoot().listScenes()) {
471
- for (const group of scene.listChildren()) {
472
- const lv = group.getName();
473
- levels.push(lv);
474
- walk(group, lv.startsWith("level:") ? `${lv.slice("level:".length)}/` : "");
354
+ try {
355
+ await browser?.close();
356
+ } finally {
357
+ removeScratch(dir);
475
358
  }
476
359
  }
477
- return { levels, nodes };
478
360
  }
479
361
 
480
362
  // src/check/verify.ts
@@ -609,13 +491,6 @@ export {
609
491
  replayHtml,
610
492
  SWIFTSHADER_ARGS,
611
493
  renderReplay,
612
- GLB_GENERATOR,
613
- bodyMaterialName,
614
- glbNodeName,
615
- levelNodeName,
616
- nodeExtras,
617
- writeGlb,
618
- readGlbNodes,
619
494
  openEdges,
620
495
  signedVolume,
621
496
  checkScene,
@@ -1,13 +1,15 @@
1
1
  import {
2
- CONTACT_SHADOW,
3
- FLOOR_FINISHES,
4
- contactBandMm,
5
2
  endElevation,
6
3
  explodeLifts,
7
- slotGroups,
8
4
  storeysOf,
9
5
  timeline
10
- } from "./chunk-LNIVDMPG.js";
6
+ } from "./chunk-EL4456GB.js";
7
+ import {
8
+ CONTACT_SHADOW,
9
+ FLOOR_FINISHES,
10
+ contactBandMm,
11
+ slotGroups
12
+ } from "./chunk-ONUOWO37.js";
11
13
 
12
14
  // src/replay/view-dom.ts
13
15
  var PRESET_LABELS = [