@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`
|
|
5
|
-
* `window.innerWidth
|
|
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
|
|
9
|
-
* `
|
|
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
|
|
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`
|
|
7
|
-
* `window.innerWidth
|
|
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
|
|
11
|
-
* `
|
|
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
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
g.
|
|
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
|
-
|
|
53
|
-
|
|
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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