@cellarnode/ui 0.7.5 → 0.7.7

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.
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * Web Worker polyfill for three-globe compatibility.
3
3
  *
4
- * three-globe accesses `window.THREE` at module evaluation time and
5
- * `window.innerWidth`/`window.innerHeight`. Web Workers have no `window`
6
- * global, so this must be imported BEFORE any three.js-related modules.
4
+ * Problem: three-globe accesses `window.THREE`, `window.requestAnimationFrame`,
5
+ * `window.innerWidth`, etc. Workers don't have `window`.
7
6
  *
8
- * @react-three/offscreen applies its own shims, but only inside the
9
- * `render()` function body — too late for module-level code.
7
+ * Complication: @react-three/offscreen's `render()` later overwrites
8
+ * `self.window = {}`, blowing away any simple `window = globalThis` polyfill.
9
+ *
10
+ * Solution: use a property trap on globalThis so that any assignment to `window`
11
+ * automatically gets our worker API shims merged in.
10
12
  *
11
13
  * Usage in consumer worker files:
12
14
  * ```ts
@@ -17,4 +19,24 @@
17
19
  * ```
18
20
  */
19
21
  declare const g: any;
22
+ declare const noop: () => void;
23
+ declare const mockElement: () => {
24
+ style: {};
25
+ setAttribute: () => void;
26
+ getAttribute: () => null;
27
+ removeAttribute: () => void;
28
+ appendChild: () => void;
29
+ removeChild: () => void;
30
+ addEventListener: () => void;
31
+ removeEventListener: () => void;
32
+ classList: {
33
+ add: () => void;
34
+ remove: () => void;
35
+ toggle: () => void;
36
+ contains: () => boolean;
37
+ };
38
+ };
39
+ declare const workerShims: Record<string, any>;
40
+ declare function applyShims(target: any): any;
41
+ declare let _windowRef: any;
20
42
  //# sourceMappingURL=worker-polyfill.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-polyfill.d.ts","sourceRoot":"","sources":["../../src/globe/worker-polyfill.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;GAiBG;AACH,QAAA,MAAM,CAAC,EAAiB,GAAG,CAAC"}
1
+ {"version":3,"file":"worker-polyfill.d.ts","sourceRoot":"","sources":["../../src/globe/worker-polyfill.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;;;;;GAmBG;AACH,QAAA,MAAM,CAAC,EAAiB,GAAG,CAAC;AAC5B,QAAA,MAAM,IAAI,YAAW,CAAC;AAItB,QAAA,MAAM,WAAW;;;;;;;;;;;;;;;CAUf,CAAC;AAIH,QAAA,MAAM,WAAW,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CA6BpC,CAAC;AAIF,iBAAS,UAAU,CAAC,MAAM,EAAE,GAAG,OAO9B;AASD,QAAA,IAAI,UAAU,EAAE,GAAO,CAAC"}
@@ -3,12 +3,14 @@
3
3
  /**
4
4
  * Web Worker polyfill for three-globe compatibility.
5
5
  *
6
- * three-globe accesses `window.THREE` at module evaluation time and
7
- * `window.innerWidth`/`window.innerHeight`. Web Workers have no `window`
8
- * global, so this must be imported BEFORE any three.js-related modules.
6
+ * Problem: three-globe accesses `window.THREE`, `window.requestAnimationFrame`,
7
+ * `window.innerWidth`, etc. Workers don't have `window`.
9
8
  *
10
- * @react-three/offscreen applies its own shims, but only inside the
11
- * `render()` function body — too late for module-level code.
9
+ * Complication: @react-three/offscreen's `render()` later overwrites
10
+ * `self.window = {}`, blowing away any simple `window = globalThis` polyfill.
11
+ *
12
+ * Solution: use a property trap on globalThis so that any assignment to `window`
13
+ * automatically gets our worker API shims merged in.
12
14
  *
13
15
  * Usage in consumer worker files:
14
16
  * ```ts
@@ -19,23 +21,31 @@
19
21
  * ```
20
22
  */
21
23
  const g = globalThis;
22
- if (typeof g.window === "undefined") {
23
- g.window = g;
24
- }
25
- if (typeof g.document === "undefined") {
26
- const noop = () => { };
27
- const mockElement = () => ({
28
- style: {},
29
- setAttribute: noop,
30
- getAttribute: () => null,
31
- removeAttribute: noop,
32
- appendChild: noop,
33
- removeChild: noop,
34
- addEventListener: noop,
35
- removeEventListener: noop,
36
- classList: { add: noop, remove: noop, toggle: noop, contains: () => false },
37
- });
38
- g.document = {
24
+ const noop = () => { };
25
+ // ── Mock DOM element ─────────────────────────────────────────────────────────
26
+ const mockElement = () => ({
27
+ style: {},
28
+ setAttribute: noop,
29
+ getAttribute: () => null,
30
+ removeAttribute: noop,
31
+ appendChild: noop,
32
+ removeChild: noop,
33
+ addEventListener: noop,
34
+ removeEventListener: noop,
35
+ classList: { add: noop, remove: noop, toggle: noop, contains: () => false },
36
+ });
37
+ // ── Shims that must survive @react-three/offscreen overwriting self.window ───
38
+ const workerShims = {
39
+ // three-globe animation loop
40
+ requestAnimationFrame: g.requestAnimationFrame?.bind(g) ??
41
+ ((cb) => setTimeout(cb, 16)),
42
+ cancelAnimationFrame: g.cancelAnimationFrame?.bind(g) ??
43
+ ((id) => clearTimeout(id)),
44
+ // three-globe default renderer size
45
+ innerWidth: g.innerWidth ?? 1024,
46
+ innerHeight: g.innerHeight ?? 768,
47
+ // document shim for react-dom + three-globe
48
+ document: {
39
49
  createElement: mockElement,
40
50
  createElementNS: mockElement,
41
51
  createTextNode: () => ({ textContent: "" }),
@@ -47,15 +57,38 @@ if (typeof g.document === "undefined") {
47
57
  addEventListener: noop,
48
58
  removeEventListener: noop,
49
59
  documentElement: { style: {} },
50
- };
60
+ },
61
+ HTMLCanvasElement: g.OffscreenCanvas ?? class {
62
+ },
63
+ };
64
+ // ── Install shims on an object (only fills missing keys) ─────────────────────
65
+ function applyShims(target) {
66
+ for (const [key, value] of Object.entries(workerShims)) {
67
+ if (target[key] === undefined || target[key] === null) {
68
+ target[key] = value;
69
+ }
70
+ }
71
+ return target;
51
72
  }
52
- if (typeof g.HTMLCanvasElement === "undefined") {
53
- g.HTMLCanvasElement = g.OffscreenCanvas ?? class {
54
- };
73
+ // ── Trap `window` assignment ─────────────────────────────────────────────────
74
+ // 1. Set `window = globalThis` initially (with shims)
75
+ // 2. When @react-three/offscreen does `self.window = {}`, the setter fires
76
+ // and patches the new object with our shims before anyone reads from it.
77
+ applyShims(g); // ensure globalThis has the shims
78
+ let _windowRef = g;
79
+ Object.defineProperty(g, "window", {
80
+ get: () => _windowRef,
81
+ set: (v) => {
82
+ if (v && typeof v === "object") {
83
+ applyShims(v);
84
+ }
85
+ _windowRef = v;
86
+ },
87
+ configurable: true,
88
+ enumerable: true,
89
+ });
90
+ // Also ensure `document` is on globalThis directly (some code reads `document` not `window.document`)
91
+ if (typeof g.document === "undefined") {
92
+ g.document = workerShims.document;
55
93
  }
56
- // three-globe reads window.innerWidth / window.innerHeight for default renderer size
57
- if (typeof g.innerWidth === "undefined")
58
- g.innerWidth = 1024;
59
- if (typeof g.innerHeight === "undefined")
60
- g.innerHeight = 768;
61
94
  //# sourceMappingURL=worker-polyfill.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"worker-polyfill.js","sourceRoot":"","sources":["../../src/globe/worker-polyfill.ts"],"names":[],"mappings":";AAAA,uDAAuD;AACvD;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM,CAAC,GAAG,UAAiB,CAAC;AAE5B,IAAI,OAAO,CAAC,CAAC,MAAM,KAAK,WAAW,EAAE,CAAC;IACpC,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC;AACf,CAAC;AAED,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;IACtC,MAAM,IAAI,GAAG,GAAG,EAAE,GAAE,CAAC,CAAC;IACtB,MAAM,WAAW,GAAG,GAAG,EAAE,CAAC,CAAC;QACzB,KAAK,EAAE,EAAE;QACT,YAAY,EAAE,IAAI;QAClB,YAAY,EAAE,GAAG,EAAE,CAAC,IAAI;QACxB,eAAe,EAAE,IAAI;QACrB,WAAW,EAAE,IAAI;QACjB,WAAW,EAAE,IAAI;QACjB,gBAAgB,EAAE,IAAI;QACtB,mBAAmB,EAAE,IAAI;QACzB,SAAS,EAAE,EAAE,GAAG,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,EAAE,CAAC,KAAK,EAAE;KAC5E,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AI;KAAQ;CACjD,CAAC;AAEF,gFAAgF;AAEhF,SAAS,UAAU,CAAC,MAAW;IAC7B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,CAAC;QACvD,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,SAAS,IAAI,MAAM,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC;YACtD,MAAM,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;QACtB,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,gFAAgF;AAChF,sDAAsD;AACtD,2EAA2E;AAC3E,4EAA4E;AAE5E,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC,kCAAkC;AAEjD,IAAI,UAAU,GAAQ,CAAC,CAAC;AAExB,MAAM,CAAC,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE;IACjC,GAAG,EAAE,GAAG,EAAE,CAAC,UAAU;IACrB,GAAG,EAAE,CAAC,CAAM,EAAE,EAAE;QACd,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,EAAE,CAAC;YAC/B,UAAU,CAAC,CAAC,CAAC,CAAC;QAChB,CAAC;QACD,UAAU,GAAG,CAAC,CAAC;IACjB,CAAC;IACD,YAAY,EAAE,IAAI;IAClB,UAAU,EAAE,IAAI;CACjB,CAAC,CAAC;AAEH,sGAAsG;AACtG,IAAI,OAAO,CAAC,CAAC,QAAQ,KAAK,WAAW,EAAE,CAAC;IACtC,CAAC,CAAC,QAAQ,GAAG,WAAW,CAAC,QAAQ,CAAC;AACpC,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cellarnode/ui",
3
- "version": "0.7.5",
3
+ "version": "0.7.7",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "description": "Shared UI components, theme tokens, and chat/offer primitives for CellarNode dashboards.",