@geometra/renderer-three 0.2.0 → 1.3.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.
Files changed (39) hide show
  1. package/dist/host-css-coerce.d.ts +39 -0
  2. package/dist/host-css-coerce.d.ts.map +1 -0
  3. package/dist/host-css-coerce.js +69 -0
  4. package/dist/host-css-coerce.js.map +1 -0
  5. package/dist/host-layout-plain.d.ts +164 -0
  6. package/dist/host-layout-plain.d.ts.map +1 -0
  7. package/dist/host-layout-plain.js +255 -0
  8. package/dist/host-layout-plain.js.map +1 -0
  9. package/dist/index.d.ts +42 -5
  10. package/dist/index.d.ts.map +1 -1
  11. package/dist/index.js +41 -5
  12. package/dist/index.js.map +1 -1
  13. package/dist/layout-sync.d.ts +51 -0
  14. package/dist/layout-sync.d.ts.map +1 -0
  15. package/dist/layout-sync.js +59 -0
  16. package/dist/layout-sync.js.map +1 -0
  17. package/dist/scene3d-manager.d.ts +29 -0
  18. package/dist/scene3d-manager.d.ts.map +1 -0
  19. package/dist/scene3d-manager.js +339 -0
  20. package/dist/scene3d-manager.js.map +1 -0
  21. package/dist/split-host.d.ts +48 -9
  22. package/dist/split-host.d.ts.map +1 -1
  23. package/dist/split-host.js +74 -39
  24. package/dist/split-host.js.map +1 -1
  25. package/dist/stacked-host.d.ts +64 -14
  26. package/dist/stacked-host.d.ts.map +1 -1
  27. package/dist/stacked-host.js +77 -41
  28. package/dist/stacked-host.js.map +1 -1
  29. package/dist/three-scene-basics.d.ts +313 -2
  30. package/dist/three-scene-basics.d.ts.map +1 -1
  31. package/dist/three-scene-basics.js +418 -1
  32. package/dist/three-scene-basics.js.map +1 -1
  33. package/dist/utils.d.ts +156 -0
  34. package/dist/utils.d.ts.map +1 -1
  35. package/dist/utils.js +207 -6
  36. package/dist/utils.js.map +1 -1
  37. package/package.json +15 -18
  38. package/LICENSE +0 -21
  39. package/README.md +0 -111
@@ -1,24 +1,49 @@
1
1
  import * as THREE from 'three';
2
2
  import { type BrowserCanvasClientHandle, type BrowserCanvasClientOptions } from '@geometra/renderer-canvas';
3
3
  import { type GeometraThreeSceneBasicsOptions } from './three-scene-basics.js';
4
- export interface ThreeGeometraSplitHostOptions extends Omit<BrowserCanvasClientOptions, 'canvas'>, GeometraThreeSceneBasicsOptions {
4
+ /**
5
+ * Every {@link createBrowserCanvasClient} option except `canvas`, which split/stacked hosts create
6
+ * internally. Includes `url`, `binaryFraming`, optional explicit `window` for tests/iframes, and
7
+ * the rest of {@link BrowserCanvasClientOptions}.
8
+ */
9
+ export type GeometraHostBrowserCanvasClientOptions = Omit<BrowserCanvasClientOptions, 'canvas'>;
10
+ /**
11
+ * Default Geometra column width for {@link createThreeGeometraSplitHost}; same value as the
12
+ * `geometraWidth` option fallback and README.
13
+ */
14
+ export declare const GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS: {
15
+ readonly geometraWidth: 420;
16
+ };
17
+ export interface ThreeGeometraSplitHostOptions extends GeometraHostBrowserCanvasClientOptions, GeometraThreeSceneBasicsOptions {
5
18
  /** Host element; a flex row is appended as a child (existing children are left untouched). */
6
19
  container: HTMLElement;
7
- /** Geometra column width in CSS pixels. Default: 420. */
20
+ /**
21
+ * Geometra column width in CSS pixels. Default: 420 ({@link GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS}).
22
+ * Non-finite or negative values fall back to the default so layout does not emit invalid `px` styles.
23
+ */
8
24
  geometraWidth?: number;
9
25
  /** When true, Geometra panel is on the left. Default: false (Three.js left, Geometra right). */
10
26
  geometraOnLeft?: boolean;
27
+ /**
28
+ * Upper bound for `window.devicePixelRatio` when sizing the WebGL drawing buffer (e.g. `2` on retina
29
+ * to cut memory and fragment cost). When omitted, the full device pixel ratio is used.
30
+ */
31
+ maxDevicePixelRatio?: number;
11
32
  /**
12
33
  * Called once after scene, camera, and renderer are created.
13
34
  * Add meshes, lights, controls, etc. Call `ctx.destroy()` to tear down immediately; the render loop
14
- * will not start if the host is already destroyed.
35
+ * will not start if the host is already destroyed. If this callback throws, the host is fully torn
36
+ * down and the error is rethrown.
15
37
  */
16
38
  onThreeReady?: (ctx: ThreeRuntimeContext) => void;
17
39
  /**
18
40
  * Called every frame before `renderer.render`.
19
- * Use for animations; return nothing.
41
+ * Use for animations. Return **`false`** to skip `render` for this frame only (same idea as
42
+ * {@link tickGeometraThreeWebGLWithSceneBasicsFrame}). If you call {@link ThreeRuntimeContext.destroy} here,
43
+ * teardown runs and this frame’s `render` is skipped (avoids rendering after WebGL dispose).
44
+ * If this callback throws, the host is fully torn down and the error is rethrown (same as {@link onThreeReady}).
20
45
  */
21
- onThreeFrame?: (ctx: ThreeFrameContext) => void;
46
+ onThreeFrame?: (ctx: ThreeFrameContext) => void | false;
22
47
  }
23
48
  export interface ThreeRuntimeContext {
24
49
  renderer: THREE.WebGLRenderer;
@@ -44,7 +69,12 @@ export interface ThreeGeometraSplitHostHandle {
44
69
  camera: THREE.PerspectiveCamera;
45
70
  clock: THREE.Clock;
46
71
  geometra: BrowserCanvasClientHandle;
47
- /** Stops the render loop, disconnects observers, disposes WebGL, and tears down the Geometra client. */
72
+ /**
73
+ * Stops the render loop, tears down WebGL via {@link disposeGeometraThreeWebGLWithSceneBasics} (clock stop +
74
+ * the same renderer registration headless {@link renderGeometraThreeWebGLWithSceneBasicsFrame} /
75
+ * {@link tickGeometraThreeWebGLWithSceneBasicsFrame} use to skip draws after dispose), disconnects observers,
76
+ * and tears down the Geometra client.
77
+ */
48
78
  destroy(): void;
49
79
  }
50
80
  /**
@@ -52,11 +82,20 @@ export interface ThreeGeometraSplitHostHandle {
52
82
  *
53
83
  * This is the recommended **hybrid** layout: 3D stays in Three; chrome and data panes stay in Geometra’s protocol.
54
84
  * Geometra’s client still uses `resizeTarget: window` by default; when only the Geometra column changes size,
55
- * a `ResizeObserver` dispatches a synthetic `resize` on `window` so layout width/height track the panel
56
- * (coalesced to at most once per animation frame when both panes notify in the same frame).
85
+ * a `ResizeObserver` schedules a synthetic `resize` on `window` so layout width/height track the panel.
86
+ * The host `root` and both flex panes are observed (same idea as {@link createThreeGeometraStackedHost} observing
87
+ * its `root`) so container-driven root box changes still coalesce into the same rAF pass even if a panel callback
88
+ * ordering quirk would otherwise miss a tick.
89
+ * Panel-driven updates coalesce to at most **one** animation frame per burst: a single `requestAnimationFrame`
90
+ * pass runs the Three.js buffer resize and (when needed) that synthetic `resize`, so both flex panes firing
91
+ * in the same frame do not call `renderer.setSize` twice.
92
+ *
93
+ * Real `window` `resize` events schedule the same coalesced Three.js pass **without** an extra synthetic
94
+ * `resize`, so the thin client is not double-notified when the browser already fired `resize`.
57
95
  *
58
96
  * The Three.js pane listens to `window` `resize` as well so `devicePixelRatio` updates (zoom / display changes)
59
- * refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone.
97
+ * refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone. Optional
98
+ * {@link ThreeGeometraSplitHostOptions.maxDevicePixelRatio} caps the ratio used for the WebGL buffer.
60
99
  *
61
100
  * Pass through {@link BrowserCanvasClientOptions} from `@geometra/renderer-canvas` / `@geometra/client`
62
101
  * (for example `binaryFraming`, `onError`, `onFrameMetrics`, `onData` for JSON side-channels on the same
@@ -1 +1 @@
1
- {"version":3,"file":"split-host.d.ts","sourceRoot":"","sources":["../src/split-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAChC,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAkC,KAAK,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AAG9G,MAAM,WAAW,6BACf,SAAQ,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,EAChD,+BAA+B;IACjC,8FAA8F;IAC9F,SAAS,EAAE,WAAW,CAAA;IACtB,yDAAyD;IACzD,aAAa,CAAC,EAAE,MAAM,CAAA;IACtB,gGAAgG;IAChG,cAAc,CAAC,EAAE,OAAO,C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A;IAC7B,WAAW,EAAE,iBAAiB,CAAA;IAC9B,cAAc,EAAE,iBAAiB,CAAA;IACjC,QAAQ,EAAE,KAAK,CAAC,aAAa,CAAA;IAC7B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,MAAM,EAAE,KAAK,CAAC,iBAAiB,CAAA;IAC/B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,QAAQ,EAAE,yBAAyB,CAAA;IACnC;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAA;CAChB;AAgBD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,4BAA4B,CAC1C,OAAO,EAAE,6BAA6B,GACrC,4BAA4B,CA0L9B"}
@@ -1,7 +1,15 @@
1
- import * as THREE from 'three';
2
1
  import { createBrowserCanvasClient, } from '@geometra/renderer-canvas';
3
- import { createGeometraThreeSceneBasics } from './three-scene-basics.js';
4
- import { resizeGeometraThreePerspectiveView } from './utils.js';
2
+ import { GEOMETRA_THREE_HOST_SCENE_DEFAULTS, createGeometraThreeWebGLWithSceneBasics, disposeGeometraThreeWebGLWithSceneBasics, } from './three-scene-basics.js';
3
+ import { createGeometraHostLayoutSyncRaf } from './layout-sync.js';
4
+ import { coerceHostNonNegativeCssPx } from './host-css-coerce.js';
5
+ import { resizeGeometraThreePerspectiveView, resolveHostDevicePixelRatio } from './utils.js';
6
+ /**
7
+ * Default Geometra column width for {@link createThreeGeometraSplitHost}; same value as the
8
+ * `geometraWidth` option fallback and README.
9
+ */
10
+ export const GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS = {
11
+ geometraWidth: 420,
12
+ };
5
13
  function panelStyle(el, flex) {
6
14
  el.style.flex = flex;
7
15
  el.style.minWidth = '0';
@@ -19,18 +27,28 @@ function fullSizeCanvas(canvas) {
19
27
  *
20
28
  * This is the recommended **hybrid** layout: 3D stays in Three; chrome and data panes stay in Geometra’s protocol.
21
29
  * Geometra’s client still uses `resizeTarget: window` by default; when only the Geometra column changes size,
22
- * a `ResizeObserver` dispatches a synthetic `resize` on `window` so layout width/height track the panel
23
- * (coalesced to at most once per animation frame when both panes notify in the same frame).
30
+ * a `ResizeObserver` schedules a synthetic `resize` on `window` so layout width/height track the panel.
31
+ * The host `root` and both flex panes are observed (same idea as {@link createThreeGeometraStackedHost} observing
32
+ * its `root`) so container-driven root box changes still coalesce into the same rAF pass even if a panel callback
33
+ * ordering quirk would otherwise miss a tick.
34
+ * Panel-driven updates coalesce to at most **one** animation frame per burst: a single `requestAnimationFrame`
35
+ * pass runs the Three.js buffer resize and (when needed) that synthetic `resize`, so both flex panes firing
36
+ * in the same frame do not call `renderer.setSize` twice.
37
+ *
38
+ * Real `window` `resize` events schedule the same coalesced Three.js pass **without** an extra synthetic
39
+ * `resize`, so the thin client is not double-notified when the browser already fired `resize`.
24
40
  *
25
41
  * The Three.js pane listens to `window` `resize` as well so `devicePixelRatio` updates (zoom / display changes)
26
- * refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone.
42
+ * refresh the WebGL drawing buffer without relying on panel `ResizeObserver` alone. Optional
43
+ * {@link ThreeGeometraSplitHostOptions.maxDevicePixelRatio} caps the ratio used for the WebGL buffer.
27
44
  *
28
45
  * Pass through {@link BrowserCanvasClientOptions} from `@geometra/renderer-canvas` / `@geometra/client`
29
46
  * (for example `binaryFraming`, `onError`, `onFrameMetrics`, `onData` for JSON side-channels on the same
30
47
  * socket as layout; channel names are defined by your app and the Geometra server).
31
48
  */
32
49
  export function createThreeGeometraSplitHost(options) {
33
- const { container, geometraWidth = 420, geometraOnLeft = false, threeBackground = 0x000000, cameraFov = 50, cameraNear = 0.1, cameraFar = 2000, cameraPosition = [0, 0, 5], onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
50
+ const { container, geometraWidth: geometraWidthOpt = GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS.geometraWidth, geometraOnLeft = false, maxDevicePixelRatio, threeBackground = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.threeBackground, cameraFov = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFov, cameraNear = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraNear, cameraFar = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFar, cameraPosition = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraPosition, onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
51
+ const geometraWidth = coerceHostNonNegativeCssPx(geometraWidthOpt, GEOMETRA_SPLIT_HOST_LAYOUT_DEFAULTS.geometraWidth);
34
52
  const doc = container.ownerDocument;
35
53
  const win = providedWindow ?? doc.defaultView;
36
54
  if (!win) {
@@ -62,12 +80,7 @@ export function createThreeGeometraSplitHost(options) {
62
80
  const geometraCanvas = doc.createElement('canvas');
63
81
  fullSizeCanvas(geometraCanvas);
64
82
  geometraPanel.appendChild(geometraCanvas);
65
- const glRenderer = new THREE.WebGLRenderer({
66
- canvas: threeCanvas,
67
- antialias: true,
68
- alpha: false,
69
- });
70
- const { scene, camera, clock } = createGeometraThreeSceneBasics({
83
+ const { renderer: glRenderer, scene, camera, clock } = createGeometraThreeWebGLWithSceneBasics(threeCanvas, {
71
84
  threeBackground,
72
85
  cameraFov,
73
86
  cameraNear,
@@ -75,35 +88,44 @@ export function createThreeGeometraSplitHost(options) {
75
88
  cameraPosition,
76
89
  });
77
90
  const resizeThree = () => {
78
- resizeGeometraThreePerspectiveView(glRenderer, camera, threePanel.clientWidth, threePanel.clientHeight, win.devicePixelRatio || 1);
91
+ resizeGeometraThreePerspectiveView(glRenderer, camera, threePanel.clientWidth, threePanel.clientHeight, resolveHostDevicePixelRatio(win.devicePixelRatio || 1, maxDevicePixelRatio));
79
92
  };
93
+ let destroyed = false;
94
+ const layoutSync = createGeometraHostLayoutSyncRaf(win, {
95
+ isDestroyed: () => destroyed,
96
+ syncLayout: resizeThree,
97
+ dispatchGeometraResize: () => {
98
+ win.dispatchEvent(new Event('resize'));
99
+ },
100
+ });
80
101
  const onWindowResize = () => {
81
- resizeThree();
102
+ layoutSync.schedule(false);
82
103
  };
83
104
  win.addEventListener('resize', onWindowResize, { passive: true });
84
105
  resizeThree();
85
- const geometraHandle = createBrowserCanvasClient({
86
- ...browserOptions,
87
- canvas: geometraCanvas,
88
- window: win,
89
- });
90
- let geometraResizeRafId;
91
- const triggerGeometraResize = () => {
92
- if (geometraResizeRafId !== undefined)
93
- return;
94
- geometraResizeRafId = win.requestAnimationFrame(() => {
95
- geometraResizeRafId = undefined;
96
- win.dispatchEvent(new Event('resize'));
97
- });
98
- };
106
+ const geometraHandle = (() => {
107
+ try {
108
+ return createBrowserCanvasClient({
109
+ ...browserOptions,
110
+ canvas: geometraCanvas,
111
+ window: win,
112
+ });
113
+ }
114
+ catch (err) {
115
+ layoutSync.cancel();
116
+ win.removeEventListener('resize', onWindowResize);
117
+ disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
118
+ root.remove();
119
+ throw err;
120
+ }
121
+ })();
99
122
  const roContainer = new ResizeObserver(() => {
100
- resizeThree();
101
- triggerGeometraResize();
123
+ layoutSync.schedule(true);
102
124
  });
125
+ roContainer.observe(root);
103
126
  roContainer.observe(threePanel);
104
127
  roContainer.observe(geometraPanel);
105
128
  let rafId;
106
- let destroyed = false;
107
129
  const destroy = () => {
108
130
  if (destroyed)
109
131
  return;
@@ -112,14 +134,11 @@ export function createThreeGeometraSplitHost(options) {
112
134
  win.cancelAnimationFrame(rafId);
113
135
  rafId = undefined;
114
136
  }
115
- if (geometraResizeRafId !== undefined) {
116
- win.cancelAnimationFrame(geometraResizeRafId);
117
- geometraResizeRafId = undefined;
118
- }
137
+ layoutSync.cancel();
119
138
  win.removeEventListener('resize', onWindowResize);
120
139
  roContainer.disconnect();
121
140
  geometraHandle.destroy();
122
- glRenderer.dispose();
141
+ disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
123
142
  root.remove();
124
143
  };
125
144
  const ctxBase = {
@@ -129,14 +148,30 @@ export function createThreeGeometraSplitHost(options) {
129
148
  threeCanvas,
130
149
  destroy,
131
150
  };
132
- onThreeReady?.(ctxBase);
151
+ try {
152
+ onThreeReady?.(ctxBase);
153
+ }
154
+ catch (err) {
155
+ destroy();
156
+ throw err;
157
+ }
133
158
  const loop = () => {
134
159
  if (destroyed)
135
160
  return;
136
161
  rafId = win.requestAnimationFrame(loop);
137
162
  const delta = clock.getDelta();
138
163
  const elapsed = clock.elapsedTime;
139
- onThreeFrame?.({ ...ctxBase, clock, delta, elapsed });
164
+ try {
165
+ if (onThreeFrame?.({ ...ctxBase, clock, delta, elapsed }) === false) {
166
+ return;
167
+ }
168
+ }
169
+ catch (err) {
170
+ destroy();
171
+ throw err;
172
+ }
173
+ if (destroyed)
174
+ return;
140
175
  glRenderer.render(scene, camera);
141
176
  };
142
177
  if (!destroyed) {
@@ -1 +1 @@
1
- {"version":3,"file":"split-host.js","sourceRoot":"","sources":["../src/split-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EACL,yBAAyB,GAG1B,MAAM,2BAA2B,CAAA;AAClC,OAAO,EAAE,8BAA8B,EAAwC,MAAM,yBAAyB,CAAA;AAC9G,OAAO,EAAE,kCAAkC,EAAE,MAAM,YAAY,CAAA;AAsD/D,SAAS,UAAU,CAAC,EAAe,EAAE,IAAY;IAC/C,EAAE,CAAC,KAAK,CAAC,IAAI,GAAG,IAAI,CAAA;IACpB,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,GAAG,CAAA;IACvB,EAAE,CAAC,KAAK,CAAC,SAAS,GAAG,GAAG,CAAA;IACxB,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,UAAU,CAAA;IAC9B,EAAE,CAAC,KAAK,CAAC,QAAQ,GAAG,QAAQ,CAAA;AAC9B,CAAC;AAED,SAAS,cAAc,CAAC,MAAyB;IAC/C,MAAM,CAAC,KAAK,CAAC,OAAO,GAAG,OAAO,CAAA;IAC9B,M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AAC,qBAAqB,CAAC,IAAI,CAAC,CAAA;IACzC,CAAC;IAED,OAAO;QACL,IAAI;QACJ,UAAU;QACV,aAAa;QACb,WAAW;QACX,cAAc;QACd,QAAQ,EAAE,UAAU;QACpB,KAAK;QACL,MAAM;QACN,KAAK;QACL,QAAQ,EAAE,cAAc;QACxB,OAAO;KACR,CAAA;AACH,CAAC"}
@@ -1,34 +1,74 @@
1
1
  import * as THREE from 'three';
2
- import { type BrowserCanvasClientHandle, type BrowserCanvasClientOptions } from '@geometra/renderer-canvas';
3
- import type { ThreeFrameContext, ThreeRuntimeContext } from './split-host.js';
2
+ import { type BrowserCanvasClientHandle } from '@geometra/renderer-canvas';
3
+ import type { GeometraHostBrowserCanvasClientOptions, ThreeFrameContext, ThreeRuntimeContext } from './split-host.js';
4
4
  import { type GeometraThreeSceneBasicsOptions } from './three-scene-basics.js';
5
- /** Corner anchor for the Geometra HUD overlay (CSS `position: absolute` on the host). */
6
- export type GeometraHudPlacement = 'bottom-right' | 'bottom-left' | 'top-right' | 'top-left';
7
- export interface ThreeGeometraStackedHostOptions extends Omit<BrowserCanvasClientOptions, 'canvas'>, GeometraThreeSceneBasicsOptions {
5
+ import { type GeometraHudPlacement } from './host-css-coerce.js';
6
+ export type { GeometraHudPlacement } from './host-css-coerce.js';
7
+ /**
8
+ * Default HUD width, height, corner, and margin for {@link createThreeGeometraStackedHost}; same as
9
+ * those option fallbacks and README.
10
+ */
11
+ export declare const GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS: {
12
+ readonly geometraHudWidth: 420;
13
+ readonly geometraHudHeight: 320;
14
+ readonly geometraHudPlacement: "bottom-right";
15
+ readonly geometraHudMargin: 12;
16
+ };
17
+ export interface ThreeGeometraStackedHostOptions extends GeometraHostBrowserCanvasClientOptions, GeometraThreeSceneBasicsOptions {
8
18
  /** Host element; a full-size stacking context is appended (existing children are left untouched). */
9
19
  container: HTMLElement;
10
- /** HUD width in CSS pixels. Default: 420. */
20
+ /**
21
+ * HUD width in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth}.
22
+ * Non-finite or negative values fall back to the default so layout does not emit invalid `px` styles.
23
+ */
11
24
  geometraHudWidth?: number;
12
- /** HUD height in CSS pixels. Default: 320. */
25
+ /**
26
+ * HUD height in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight}.
27
+ * Non-finite or negative values fall back to the default.
28
+ */
13
29
  geometraHudHeight?: number;
14
- /** HUD corner. Default: `bottom-right`. */
30
+ /**
31
+ * HUD corner. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement}.
32
+ * Runtime strings (e.g. from JSON or agents) are normalized with {@link coerceGeometraHudPlacement}
33
+ * (trim + case-insensitive match for the four literals; anything else uses the default).
34
+ */
15
35
  geometraHudPlacement?: GeometraHudPlacement;
16
- /** Inset from the chosen corner in CSS pixels. Default: 12. */
36
+ /**
37
+ * Inset from the chosen corner in CSS pixels. Default: {@link GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin}.
38
+ * Non-finite or negative values fall back to the default.
39
+ */
17
40
  geometraHudMargin?: number;
18
41
  /**
19
42
  * CSS `pointer-events` on the HUD wrapper (e.g. `'none'` so input falls through to the WebGL canvas).
20
- * Default: `'auto'`.
43
+ * Default: `'auto'`. Blank or whitespace-only strings fall back to the default; use
44
+ * {@link coerceGeometraHudPointerEvents} in custom layouts for the same rules.
21
45
  */
22
46
  geometraHudPointerEvents?: string;
47
+ /**
48
+ * CSS `z-index` on the HUD wrapper when you stack other siblings in {@link ThreeGeometraStackedHostOptions.container}
49
+ * or need a fixed order above the WebGL layer (Three canvas uses `0`). Default: `1`.
50
+ * Non-finite numbers and blank/whitespace-only strings fall back to the default so the HUD keeps a predictable stack order.
51
+ */
52
+ geometraHudZIndex?: string | number;
53
+ /**
54
+ * Upper bound for `window.devicePixelRatio` when sizing the WebGL drawing buffer (e.g. `2` on retina
55
+ * to cut memory and fragment cost). When omitted, the full device pixel ratio is used.
56
+ */
57
+ maxDevicePixelRatio?: number;
23
58
  /**
24
59
  * Called once after scene, camera, and renderer are created.
25
60
  * Call `ctx.destroy()` to tear down immediately; the render loop will not start if the host is already destroyed.
61
+ * If this callback throws, the host is fully torn down and the error is rethrown.
26
62
  */
27
63
  onThreeReady?: (ctx: ThreeRuntimeContext) => void;
28
64
  /**
29
65
  * Called every frame before `renderer.render`.
66
+ * Return **`false`** to skip `render` for this frame only (same idea as
67
+ * {@link tickGeometraThreeWebGLWithSceneBasicsFrame}). If you call {@link ThreeRuntimeContext.destroy} here,
68
+ * teardown runs and this frame’s `render` is skipped.
69
+ * If this callback throws, the host is fully torn down and the error is rethrown (same as {@link onThreeReady}).
30
70
  */
31
- onThreeFrame?: (ctx: ThreeFrameContext) => void;
71
+ onThreeFrame?: (ctx: ThreeFrameContext) => void | false;
32
72
  }
33
73
  export interface ThreeGeometraStackedHostHandle {
34
74
  root: HTMLDivElement;
@@ -41,19 +81,29 @@ export interface ThreeGeometraStackedHostHandle {
41
81
  camera: THREE.PerspectiveCamera;
42
82
  clock: THREE.Clock;
43
83
  geometra: BrowserCanvasClientHandle;
84
+ /**
85
+ * Stops the render loop, tears down WebGL via {@link disposeGeometraThreeWebGLWithSceneBasics} (clock stop +
86
+ * the same renderer registration headless {@link renderGeometraThreeWebGLWithSceneBasicsFrame} /
87
+ * {@link tickGeometraThreeWebGLWithSceneBasicsFrame} use to skip draws after dispose), disconnects observers,
88
+ * and tears down the Geometra client.
89
+ */
44
90
  destroy(): void;
45
91
  }
46
92
  /**
47
93
  * Stacked host: full-viewport Three.js `WebGLRenderer` with a positioned Geometra canvas **HUD** on top.
48
94
  *
49
95
  * Pointer routing follows normal hit-testing: events hit the Geometra canvas where it overlaps the WebGL layer
50
- * (`z-index` above the Three canvas); elsewhere, the Three canvas receives input. Override with
51
- * {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD).
96
+ * (HUD `z-index` above the Three canvas, which uses `0`); elsewhere, the Three canvas receives input. Override with
97
+ * {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD) or
98
+ * {@link ThreeGeometraStackedHostOptions.geometraHudZIndex} when you add other positioned siblings.
52
99
  *
53
100
  * Geometra’s client still uses `resizeTarget: window` by default; when only the HUD box changes size,
54
101
  * a coalesced synthetic `resize` is dispatched on `window` (same pattern as {@link createThreeGeometraSplitHost}).
102
+ * `ResizeObserver` callbacks and real `window` `resize` share one rAF-coalesced Three.js buffer pass; the
103
+ * synthetic `resize` is emitted only from observer-driven layout changes, not from real window resizes.
55
104
  * The Three.js layer listens to `window` `resize` for `devicePixelRatio` changes and uses the host `root` size
56
- * for the drawing buffer.
105
+ * for the drawing buffer. Optional {@link ThreeGeometraStackedHostOptions.maxDevicePixelRatio} caps the ratio
106
+ * used for the WebGL buffer.
57
107
  */
58
108
  export declare function createThreeGeometraStackedHost(options: ThreeGeometraStackedHostOptions): ThreeGeometraStackedHostHandle;
59
109
  //# sourceMappingURL=stacked-host.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"stacked-host.d.ts","sourceRoot":"","sources":["../src/stacked-host.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAC9B,OAAO,EAEL,KAAK,yBAAyB,EAC9B,KAAK,0BAA0B,EAChC,MAAM,2BAA2B,CAAA;AAClC,OAAO,KAAK,EAAE,iBAAiB,EAAE,mBAAmB,EAAE,MAAM,iBAAiB,CAAA;AAC7E,OAAO,EAAkC,KAAK,+BAA+B,EAAE,MAAM,yBAAyB,CAAA;AAG9G,yFAAyF;AACzF,MAAM,MAAM,oBAAoB,GAAG,cAAc,GAAG,aAAa,GAAG,WAAW,GAAG,UAAU,CAAA;AAE5F,MAAM,WAAW,+BACf,SAAQ,IAAI,CAAC,0BAA0B,EAAE,QAAQ,CAAC,EAChD,+BAA+B;IACj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A;IAC/B,KAAK,EAAE,KAAK,CAAC,KAAK,CAAA;IAClB,QAAQ,EAAE,yBAAyB,CAAA;IACnC;;;;;OAKG;IACH,OAAO,IAAI,IAAI,CAAA;CAChB;AAsCD;;;;;;;;;;;;;;;GAeG;AACH,wBAAgB,8BAA8B,CAC5C,OAAO,EAAE,+BAA+B,GACvC,8BAA8B,CAkNhC"}
@@ -1,7 +1,18 @@
1
- import * as THREE from 'three';
2
1
  import { createBrowserCanvasClient, } from '@geometra/renderer-canvas';
3
- import { createGeometraThreeSceneBasics } from './three-scene-basics.js';
4
- import { resizeGeometraThreePerspectiveView } from './utils.js';
2
+ import { GEOMETRA_THREE_HOST_SCENE_DEFAULTS, createGeometraThreeWebGLWithSceneBasics, disposeGeometraThreeWebGLWithSceneBasics, } from './three-scene-basics.js';
3
+ import { createGeometraHostLayoutSyncRaf } from './layout-sync.js';
4
+ import { coerceGeometraHudPlacement, coerceGeometraHudPointerEvents, coerceHostNonNegativeCssPx, coerceHostStackingZIndexCss, } from './host-css-coerce.js';
5
+ import { resizeGeometraThreePerspectiveView, resolveHostDevicePixelRatio } from './utils.js';
6
+ /**
7
+ * Default HUD width, height, corner, and margin for {@link createThreeGeometraStackedHost}; same as
8
+ * those option fallbacks and README.
9
+ */
10
+ export const GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS = {
11
+ geometraHudWidth: 420,
12
+ geometraHudHeight: 320,
13
+ geometraHudPlacement: 'bottom-right',
14
+ geometraHudMargin: 12,
15
+ };
5
16
  function fullSizeCanvas(canvas) {
6
17
  canvas.style.display = 'block';
7
18
  canvas.style.width = '100%';
@@ -36,16 +47,25 @@ function applyHudPlacement(wrap, placement, marginPx) {
36
47
  * Stacked host: full-viewport Three.js `WebGLRenderer` with a positioned Geometra canvas **HUD** on top.
37
48
  *
38
49
  * Pointer routing follows normal hit-testing: events hit the Geometra canvas where it overlaps the WebGL layer
39
- * (`z-index` above the Three canvas); elsewhere, the Three canvas receives input. Override with
40
- * {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD).
50
+ * (HUD `z-index` above the Three canvas, which uses `0`); elsewhere, the Three canvas receives input. Override with
51
+ * {@link ThreeGeometraStackedHostOptions.geometraHudPointerEvents} (e.g. `'none'` for a click-through HUD) or
52
+ * {@link ThreeGeometraStackedHostOptions.geometraHudZIndex} when you add other positioned siblings.
41
53
  *
42
54
  * Geometra’s client still uses `resizeTarget: window` by default; when only the HUD box changes size,
43
55
  * a coalesced synthetic `resize` is dispatched on `window` (same pattern as {@link createThreeGeometraSplitHost}).
56
+ * `ResizeObserver` callbacks and real `window` `resize` share one rAF-coalesced Three.js buffer pass; the
57
+ * synthetic `resize` is emitted only from observer-driven layout changes, not from real window resizes.
44
58
  * The Three.js layer listens to `window` `resize` for `devicePixelRatio` changes and uses the host `root` size
45
- * for the drawing buffer.
59
+ * for the drawing buffer. Optional {@link ThreeGeometraStackedHostOptions.maxDevicePixelRatio} caps the ratio
60
+ * used for the WebGL buffer.
46
61
  */
47
62
  export function createThreeGeometraStackedHost(options) {
48
- const { container, geometraHudWidth = 420, geometraHudHeight = 320, geometraHudPlacement = 'bottom-right', geometraHudMargin = 12, geometraHudPointerEvents = 'auto', threeBackground = 0x000000, cameraFov = 50, cameraNear = 0.1, cameraFar = 2000, cameraPosition = [0, 0, 5], onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
63
+ const { container, geometraHudWidth: geometraHudWidthOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth, geometraHudHeight: geometraHudHeightOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight, geometraHudPlacement: geometraHudPlacementOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement, geometraHudMargin: geometraHudMarginOpt = GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin, geometraHudPointerEvents: geometraHudPointerEventsOpt = 'auto', geometraHudZIndex = 1, maxDevicePixelRatio, threeBackground = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.threeBackground, cameraFov = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFov, cameraNear = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraNear, cameraFar = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraFar, cameraPosition = GEOMETRA_THREE_HOST_SCENE_DEFAULTS.cameraPosition, onThreeReady, onThreeFrame, window: providedWindow, ...browserOptions } = options;
64
+ const geometraHudWidth = coerceHostNonNegativeCssPx(geometraHudWidthOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudWidth);
65
+ const geometraHudHeight = coerceHostNonNegativeCssPx(geometraHudHeightOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudHeight);
66
+ const geometraHudMargin = coerceHostNonNegativeCssPx(geometraHudMarginOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudMargin);
67
+ const geometraHudPlacement = coerceGeometraHudPlacement(geometraHudPlacementOpt, GEOMETRA_STACKED_HOST_LAYOUT_DEFAULTS.geometraHudPlacement);
68
+ const geometraHudPointerEvents = coerceGeometraHudPointerEvents(geometraHudPointerEventsOpt, 'auto');
49
69
  const doc = container.ownerDocument;
50
70
  const win = providedWindow ?? doc.defaultView;
51
71
  if (!win) {
@@ -70,7 +90,7 @@ export function createThreeGeometraStackedHost(options) {
70
90
  root.appendChild(threeCanvas);
71
91
  const geometraHud = doc.createElement('div');
72
92
  geometraHud.style.position = 'absolute';
73
- geometraHud.style.zIndex = '1';
93
+ geometraHud.style.zIndex = coerceHostStackingZIndexCss(geometraHudZIndex, 1);
74
94
  geometraHud.style.width = `${geometraHudWidth}px`;
75
95
  geometraHud.style.height = `${geometraHudHeight}px`;
76
96
  geometraHud.style.minWidth = '0';
@@ -82,12 +102,7 @@ export function createThreeGeometraStackedHost(options) {
82
102
  const geometraCanvas = doc.createElement('canvas');
83
103
  fullSizeCanvas(geometraCanvas);
84
104
  geometraHud.appendChild(geometraCanvas);
85
- const glRenderer = new THREE.WebGLRenderer({
86
- canvas: threeCanvas,
87
- antialias: true,
88
- alpha: false,
89
- });
90
- const { scene, camera, clock } = createGeometraThreeSceneBasics({
105
+ const { renderer: glRenderer, scene, camera, clock } = createGeometraThreeWebGLWithSceneBasics(threeCanvas, {
91
106
  threeBackground,
92
107
  cameraFov,
93
108
  cameraNear,
@@ -95,38 +110,46 @@ export function createThreeGeometraStackedHost(options) {
95
110
  cameraPosition,
96
111
  });
97
112
  const resizeThree = () => {
98
- resizeGeometraThreePerspectiveView(glRenderer, camera, root.clientWidth, root.clientHeight, win.devicePixelRatio || 1);
113
+ resizeGeometraThreePerspectiveView(glRenderer, camera, root.clientWidth, root.clientHeight, resolveHostDevicePixelRatio(win.devicePixelRatio || 1, maxDevicePixelRatio));
99
114
  };
115
+ let destroyed = false;
116
+ const layoutSync = createGeometraHostLayoutSyncRaf(win, {
117
+ isDestroyed: () => destroyed,
118
+ syncLayout: resizeThree,
119
+ dispatchGeometraResize: () => {
120
+ win.dispatchEvent(new Event('resize'));
121
+ },
122
+ });
100
123
  const onWindowResize = () => {
101
- resizeThree();
124
+ layoutSync.schedule(false);
102
125
  };
103
126
  win.addEventListener('resize', onWindowResize, { passive: true });
104
127
  resizeThree();
105
- const geometraHandle = createBrowserCanvasClient({
106
- ...browserOptions,
107
- canvas: geometraCanvas,
108
- window: win,
109
- });
110
- let geometraResizeRafId;
111
- const triggerGeometraResize = () => {
112
- if (geometraResizeRafId !== undefined)
113
- return;
114
- geometraResizeRafId = win.requestAnimationFrame(() => {
115
- geometraResizeRafId = undefined;
116
- win.dispatchEvent(new Event('resize'));
117
- });
118
- };
128
+ const geometraHandle = (() => {
129
+ try {
130
+ return createBrowserCanvasClient({
131
+ ...browserOptions,
132
+ canvas: geometraCanvas,
133
+ window: win,
134
+ });
135
+ }
136
+ catch (err) {
137
+ layoutSync.cancel();
138
+ win.removeEventListener('resize', onWindowResize);
139
+ disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
140
+ root.remove();
141
+ throw err;
142
+ }
143
+ })();
119
144
  const roRoot = new ResizeObserver(() => {
120
- resizeThree();
121
- triggerGeometraResize();
145
+ layoutSync.schedule(true);
122
146
  });
123
147
  roRoot.observe(root);
124
148
  const roHud = new ResizeObserver(() => {
125
- triggerGeometraResize();
149
+ layoutSync.schedule(true);
126
150
  });
127
151
  roHud.observe(geometraHud);
128
152
  let rafId;
129
- let destroyed = false;
130
153
  const destroy = () => {
131
154
  if (destroyed)
132
155
  return;
@@ -135,15 +158,12 @@ export function createThreeGeometraStackedHost(options) {
135
158
  win.cancelAnimationFrame(rafId);
136
159
  rafId = undefined;
137
160
  }
138
- if (geometraResizeRafId !== undefined) {
139
- win.cancelAnimationFrame(geometraResizeRafId);
140
- geometraResizeRafId = undefined;
141
- }
161
+ layoutSync.cancel();
142
162
  win.removeEventListener('resize', onWindowResize);
143
163
  roRoot.disconnect();
144
164
  roHud.disconnect();
145
165
  geometraHandle.destroy();
146
- glRenderer.dispose();
166
+ disposeGeometraThreeWebGLWithSceneBasics({ renderer: glRenderer, clock });
147
167
  root.remove();
148
168
  };
149
169
  const ctxBase = {
@@ -153,14 +173,30 @@ export function createThreeGeometraStackedHost(options) {
153
173
  threeCanvas,
154
174
  destroy,
155
175
  };
156
- onThreeReady?.(ctxBase);
176
+ try {
177
+ onThreeReady?.(ctxBase);
178
+ }
179
+ catch (err) {
180
+ destroy();
181
+ throw err;
182
+ }
157
183
  const loop = () => {
158
184
  if (destroyed)
159
185
  return;
160
186
  rafId = win.requestAnimationFrame(loop);
161
187
  const delta = clock.getDelta();
162
188
  const elapsed = clock.elapsedTime;
163
- onThreeFrame?.({ ...ctxBase, clock, delta, elapsed });
189
+ try {
190
+ if (onThreeFrame?.({ ...ctxBase, clock, delta, elapsed }) === false) {
191
+ return;
192
+ }
193
+ }
194
+ catch (err) {
195
+ destroy();
196
+ throw err;
197
+ }
198
+ if (destroyed)
199
+ return;
164
200
  glRenderer.render(scene, camera);
165
201
  };
166
202
  if (!destroyed) {