mini-three-adapter 0.0.0-stage → 0.1.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/AGENTS.md +85 -0
- package/LICENSE +21 -0
- package/README.md +158 -2
- package/dist/build/rollup.d.ts +8 -0
- package/dist/build/rollup.js +393 -0
- package/dist/build/rollup.js.map +1 -0
- package/dist/build/vite.d.ts +15 -0
- package/dist/build/vite.js +395 -0
- package/dist/build/vite.js.map +1 -0
- package/dist/chunk-34RWHAW4.js +128 -0
- package/dist/chunk-34RWHAW4.js.map +1 -0
- package/dist/chunk-3UGQWFH3.js +1246 -0
- package/dist/chunk-3UGQWFH3.js.map +1 -0
- package/dist/chunk-4UEBRAK6.js +711 -0
- package/dist/chunk-4UEBRAK6.js.map +1 -0
- package/dist/chunk-LB3WL24R.js +91 -0
- package/dist/chunk-LB3WL24R.js.map +1 -0
- package/dist/chunk-MTBMOFAL.js +132 -0
- package/dist/chunk-MTBMOFAL.js.map +1 -0
- package/dist/chunk-QYQQ5J6E.js +3 -0
- package/dist/chunk-QYQQ5J6E.js.map +1 -0
- package/dist/chunk-V6TY7KAL.js +7 -0
- package/dist/chunk-V6TY7KAL.js.map +1 -0
- package/dist/chunk-WLRQDTSZ.js +145 -0
- package/dist/chunk-WLRQDTSZ.js.map +1 -0
- package/dist/chunk-Z7AMDRN3.js +66 -0
- package/dist/chunk-Z7AMDRN3.js.map +1 -0
- package/dist/core/index.d.ts +101 -0
- package/dist/core/index.js +7 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +11 -0
- package/dist/index.js.map +1 -0
- package/dist/platforms/browser.d.ts +23 -0
- package/dist/platforms/browser.js +7 -0
- package/dist/platforms/browser.js.map +1 -0
- package/dist/platforms/wechat-game.d.ts +31 -0
- package/dist/platforms/wechat-game.js +8 -0
- package/dist/platforms/wechat-game.js.map +1 -0
- package/dist/platforms/wechat-miniprogram.d.ts +26 -0
- package/dist/platforms/wechat-miniprogram.js +8 -0
- package/dist/platforms/wechat-miniprogram.js.map +1 -0
- package/dist/plugin-core-BuqW9C-L.d.ts +127 -0
- package/dist/polyfills/index.d.ts +291 -0
- package/dist/polyfills/index.js +4 -0
- package/dist/polyfills/index.js.map +1 -0
- package/dist/runtime-7uUOoFhC.d.ts +263 -0
- package/dist/scope.d.ts +146 -0
- package/dist/scope.js +4 -0
- package/dist/scope.js.map +1 -0
- package/dist/types-BzK0LQMa.d.ts +153 -0
- package/dist/wx-types-NMNyrsWO.d.ts +150 -0
- package/docs/01-design-principles.md +105 -0
- package/docs/02-architecture.md +126 -0
- package/docs/03-module-map.md +99 -0
- package/docs/04-api-reference.md +291 -0
- package/docs/05-build-plugin.md +146 -0
- package/docs/06-platform-notes.md +108 -0
- package/docs/07-integration-guide.md +211 -0
- package/docs/08-extension-guide.md +101 -0
- package/docs/09-testing-and-release.md +206 -0
- package/docs/10-ai-playbook.md +140 -0
- package/docs/11-compat-matrix.md +94 -0
- package/docs/README.md +41 -0
- package/docs/adr/0001-scoped-globals.md +41 -0
- package/docs/adr/0002-unified-runtime-lifecycle.md +40 -0
- package/docs/adr/0003-ast-rewrite.md +51 -0
- package/docs/adr/0004-in-place-patching.md +42 -0
- package/docs/adr/0005-webgl2-only.md +44 -0
- package/docs/adr/0006-zero-three-dependency.md +43 -0
- package/docs/adr/README.md +28 -0
- package/llms.txt +65 -0
- package/package.json +117 -4
|
@@ -0,0 +1,1246 @@
|
|
|
1
|
+
import { createScope, setActiveScope, hasActiveScope, getActiveScope, installGlobals } from './chunk-34RWHAW4.js';
|
|
2
|
+
import { patchEventTarget, MiniEventTarget, MiniMouseEvent, MiniPointerEvent, atob, btoa, MiniEvent, MiniCustomEvent, MiniMessageEvent, MiniProgressEvent, MiniDOMException, MiniBlob, MiniURL, MiniTextDecoder, MiniTextEncoder, MiniAbortController, MiniAbortSignal, createFetch, createXMLHttpRequestFactory } from './chunk-4UEBRAK6.js';
|
|
3
|
+
import { __publicField } from './chunk-V6TY7KAL.js';
|
|
4
|
+
|
|
5
|
+
// src/core/diagnostics.ts
|
|
6
|
+
var LEVEL_ORDER = { silent: 0, error: 1, warn: 2, info: 3, debug: 4 };
|
|
7
|
+
var defaultReporter = (level, message, payload) => {
|
|
8
|
+
const fn = level === "error" ? console.error : level === "warn" ? console.warn : console.log;
|
|
9
|
+
const prefix = `[mini-three] ${level.toUpperCase()} ${message}`;
|
|
10
|
+
if (payload === void 0) fn(prefix);
|
|
11
|
+
else fn(prefix, payload);
|
|
12
|
+
};
|
|
13
|
+
function createDiagnostics(level = "warn", reporter = defaultReporter) {
|
|
14
|
+
const seen = /* @__PURE__ */ new Set();
|
|
15
|
+
const emit = (l, message, payload) => {
|
|
16
|
+
if (LEVEL_ORDER[level] >= LEVEL_ORDER[l]) reporter(l, message, payload);
|
|
17
|
+
};
|
|
18
|
+
return {
|
|
19
|
+
level,
|
|
20
|
+
error: (m, p) => emit("error", m, p),
|
|
21
|
+
warn: (m, p) => emit("warn", m, p),
|
|
22
|
+
info: (m, p) => emit("info", m, p),
|
|
23
|
+
debug: (m, p) => emit("debug", m, p),
|
|
24
|
+
warnOnce: (key, m, p) => {
|
|
25
|
+
if (seen.has(key)) return;
|
|
26
|
+
seen.add(key);
|
|
27
|
+
emit("warn", m, p);
|
|
28
|
+
},
|
|
29
|
+
capabilityReport: (caps) => capabilityReport(caps)
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
function capabilityReport(caps) {
|
|
33
|
+
const lines = [
|
|
34
|
+
"mini-three-adapter capability report",
|
|
35
|
+
` platform : ${caps.platform}`,
|
|
36
|
+
` baseLibraryVersion : ${caps.baseLibraryVersion || "unknown"}`,
|
|
37
|
+
` WebGL2 / WebGL1 : ${caps.webgl2} / ${caps.webgl1}`,
|
|
38
|
+
` offscreenCanvas : ${caps.offscreenCanvas}`,
|
|
39
|
+
` worker / wasm : ${caps.worker} / ${caps.wasm} (brotli: ${caps.brotliWasm})`,
|
|
40
|
+
` nativeImage : ${caps.nativeImage}`,
|
|
41
|
+
` triggerGC : ${caps.triggerGC}`,
|
|
42
|
+
` getWindowInfo : ${caps.getWindowInfo} (resize events: ${caps.windowResizeEvent})`
|
|
43
|
+
];
|
|
44
|
+
if (!caps.webgl2) {
|
|
45
|
+
lines.push(" !! WebGL2 unavailable: three.js >= r163 requires WebGL2.");
|
|
46
|
+
}
|
|
47
|
+
return lines.join("\n");
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
// src/core/element.ts
|
|
51
|
+
var registries = /* @__PURE__ */ new WeakMap();
|
|
52
|
+
function createMockClass(name) {
|
|
53
|
+
const instances = /* @__PURE__ */ new WeakSet();
|
|
54
|
+
const Ctor = function() {
|
|
55
|
+
throw new TypeError(`[mini-three-adapter] ${name} is an interface shim, use the platform factory instead`);
|
|
56
|
+
};
|
|
57
|
+
Object.defineProperty(Ctor, "name", { value: name });
|
|
58
|
+
Object.defineProperty(Ctor, Symbol.hasInstance, {
|
|
59
|
+
value: (instance) => (typeof instance === "object" || typeof instance === "function") && instance !== null && instances.has(instance)
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(Ctor, "__instances", { value: instances });
|
|
62
|
+
registries.set(Ctor, instances);
|
|
63
|
+
return Ctor;
|
|
64
|
+
}
|
|
65
|
+
function markAs(ctor, instance) {
|
|
66
|
+
ctor.__instances.add(instance);
|
|
67
|
+
}
|
|
68
|
+
function isMarked(ctor, instance) {
|
|
69
|
+
return (typeof instance === "object" || typeof instance === "function") && instance !== null && ctor.__instances.has(instance);
|
|
70
|
+
}
|
|
71
|
+
var HTMLCanvasElementShim = createMockClass("HTMLCanvasElement");
|
|
72
|
+
var HTMLImageElementShim = createMockClass("HTMLImageElement");
|
|
73
|
+
var HTMLElementShim = createMockClass("HTMLElement");
|
|
74
|
+
var OffscreenCanvasShim = createMockClass("OffscreenCanvas");
|
|
75
|
+
var ImageDataShim = createMockClass("ImageData");
|
|
76
|
+
var WebGLRenderingContextShim = createMockClass("WebGLRenderingContext");
|
|
77
|
+
var WebGL2RenderingContextShim = createMockClass("WebGL2RenderingContext");
|
|
78
|
+
var DOMRectShim = createMockClass("DOMRect");
|
|
79
|
+
function define(target, key, descriptor) {
|
|
80
|
+
Object.defineProperty(target, key, {
|
|
81
|
+
enumerable: false,
|
|
82
|
+
configurable: true,
|
|
83
|
+
...descriptor
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function patchElement(instance, options) {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
if (!instance || typeof instance !== "object" && typeof instance !== "function") {
|
|
89
|
+
throw new TypeError("[mini-three-adapter] patchElement expects an object");
|
|
90
|
+
}
|
|
91
|
+
let rect = { ...options.rect };
|
|
92
|
+
const style = {};
|
|
93
|
+
define(style, "width", { get: () => `${rect.width}px`, set: (v) => {
|
|
94
|
+
const n = Number.parseFloat(String(v));
|
|
95
|
+
if (!Number.isNaN(n) && String(v).endsWith("px")) rect = { ...rect, width: n };
|
|
96
|
+
} });
|
|
97
|
+
define(style, "height", { get: () => `${rect.height}px`, set: (v) => {
|
|
98
|
+
const n = Number.parseFloat(String(v));
|
|
99
|
+
if (!Number.isNaN(n) && String(v).endsWith("px")) rect = { ...rect, height: n };
|
|
100
|
+
} });
|
|
101
|
+
let display = "block";
|
|
102
|
+
define(style, "display", { get: () => display, set: (v) => {
|
|
103
|
+
display = String(v);
|
|
104
|
+
} });
|
|
105
|
+
style.cursor = "default";
|
|
106
|
+
style.touchAction = "none";
|
|
107
|
+
define(instance, "style", { value: style, writable: true });
|
|
108
|
+
define(instance, "clientTop", { get: () => 0 });
|
|
109
|
+
define(instance, "clientLeft", { get: () => 0 });
|
|
110
|
+
define(instance, "clientWidth", { get: () => rect.width });
|
|
111
|
+
define(instance, "clientHeight", { get: () => rect.height });
|
|
112
|
+
define(instance, "offsetTop", { get: () => rect.top });
|
|
113
|
+
define(instance, "offsetLeft", { get: () => rect.left });
|
|
114
|
+
define(instance, "offsetWidth", { get: () => rect.width });
|
|
115
|
+
define(instance, "offsetHeight", { get: () => rect.height });
|
|
116
|
+
define(instance, "getBoundingClientRect", { value: () => ({ ...rect }), writable: true });
|
|
117
|
+
define(instance, "setAttribute", { value: (name, value) => {
|
|
118
|
+
var _a2;
|
|
119
|
+
(_a2 = options.onSetAttribute) == null ? void 0 : _a2.call(options, name, value, instance);
|
|
120
|
+
}, writable: true });
|
|
121
|
+
define(instance, "removeAttribute", { value: () => void 0, writable: true });
|
|
122
|
+
define(instance, "ownerDocument", { value: (_a = options.document) != null ? _a : null, writable: true });
|
|
123
|
+
define(instance, "getRootNode", { value: () => {
|
|
124
|
+
var _a2;
|
|
125
|
+
return (_a2 = options.document) != null ? _a2 : instance;
|
|
126
|
+
}, writable: true });
|
|
127
|
+
define(instance, "setPointerCapture", { value: () => void 0, writable: true });
|
|
128
|
+
define(instance, "releasePointerCapture", { value: () => void 0, writable: true });
|
|
129
|
+
define(instance, "hasPointerCapture", { value: () => false, writable: true });
|
|
130
|
+
define(instance, "requestPointerLock", { value: () => void 0, writable: true });
|
|
131
|
+
define(instance, "exitPointerLock", { value: () => void 0, writable: true });
|
|
132
|
+
define(instance, "focus", { value: () => void 0, writable: true });
|
|
133
|
+
define(instance, "blur", { value: () => void 0, writable: true });
|
|
134
|
+
define(instance, "scrollTop", { get: () => 0, set: () => void 0 });
|
|
135
|
+
define(instance, "scrollLeft", { get: () => 0, set: () => void 0 });
|
|
136
|
+
patchEventTarget(instance);
|
|
137
|
+
if (options.extra) {
|
|
138
|
+
for (const [key, descriptor] of Object.entries(options.extra)) {
|
|
139
|
+
define(instance, key, descriptor);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
for (const ctor of (_b = options.instanceOf) != null ? _b : []) {
|
|
143
|
+
ctor.__instances.add(instance);
|
|
144
|
+
}
|
|
145
|
+
return {
|
|
146
|
+
element: instance,
|
|
147
|
+
updateRect(next) {
|
|
148
|
+
rect = { ...next };
|
|
149
|
+
},
|
|
150
|
+
disposers: []
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
function normalizeRect(partial = {}) {
|
|
154
|
+
var _a, _b, _c, _d, _e, _f;
|
|
155
|
+
const width = (_a = partial.width) != null ? _a : 0;
|
|
156
|
+
const height = (_b = partial.height) != null ? _b : 0;
|
|
157
|
+
const left = (_c = partial.left) != null ? _c : 0;
|
|
158
|
+
const top = (_d = partial.top) != null ? _d : 0;
|
|
159
|
+
return {
|
|
160
|
+
width,
|
|
161
|
+
height,
|
|
162
|
+
left,
|
|
163
|
+
top,
|
|
164
|
+
right: (_e = partial.right) != null ? _e : left + width,
|
|
165
|
+
bottom: (_f = partial.bottom) != null ? _f : top + height
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// src/core/canvas.ts
|
|
170
|
+
function findOriginalGetContext(raw) {
|
|
171
|
+
var _a, _b;
|
|
172
|
+
let node = raw;
|
|
173
|
+
while (node) {
|
|
174
|
+
const descriptor = Object.getOwnPropertyDescriptor(node, "getContext");
|
|
175
|
+
if (descriptor) {
|
|
176
|
+
const fn = (_b = descriptor.value) != null ? _b : (_a = descriptor.get) == null ? void 0 : _a.call(raw);
|
|
177
|
+
if (typeof fn === "function") return fn.bind(raw);
|
|
178
|
+
}
|
|
179
|
+
node = Object.getPrototypeOf(node);
|
|
180
|
+
}
|
|
181
|
+
return () => null;
|
|
182
|
+
}
|
|
183
|
+
function normalizeContext(ctx, raw, type, normalizeWebGL) {
|
|
184
|
+
if (!ctx || typeof ctx !== "object" && typeof ctx !== "function") return ctx;
|
|
185
|
+
const target = ctx;
|
|
186
|
+
if (type === "webgl2") WebGL2RenderingContextShim.__instances.add(target);
|
|
187
|
+
else if (type === "webgl") WebGLRenderingContextShim.__instances.add(target);
|
|
188
|
+
try {
|
|
189
|
+
Object.defineProperty(target, "canvas", { value: raw, configurable: true, writable: true });
|
|
190
|
+
} catch {
|
|
191
|
+
}
|
|
192
|
+
if (normalizeWebGL && (type === "webgl" || type === "webgl2")) {
|
|
193
|
+
const original = target.getExtension;
|
|
194
|
+
if (typeof original === "function") {
|
|
195
|
+
Object.defineProperty(target, "getExtension", {
|
|
196
|
+
value: function(name) {
|
|
197
|
+
const result = original.call(this, name);
|
|
198
|
+
if (typeof result === "number" || typeof result === "boolean") return result ? {} : null;
|
|
199
|
+
return result != null ? result : null;
|
|
200
|
+
},
|
|
201
|
+
configurable: true,
|
|
202
|
+
writable: true
|
|
203
|
+
});
|
|
204
|
+
}
|
|
205
|
+
if (typeof target.drawingBufferWidth !== "number") {
|
|
206
|
+
Object.defineProperty(target, "drawingBufferWidth", { get: () => raw.width, configurable: true });
|
|
207
|
+
}
|
|
208
|
+
if (typeof target.drawingBufferHeight !== "number") {
|
|
209
|
+
Object.defineProperty(target, "drawingBufferHeight", { get: () => raw.height, configurable: true });
|
|
210
|
+
}
|
|
211
|
+
}
|
|
212
|
+
return ctx;
|
|
213
|
+
}
|
|
214
|
+
function patchCanvas(raw, options = {}) {
|
|
215
|
+
var _a;
|
|
216
|
+
const originalGetContext = findOriginalGetContext(raw);
|
|
217
|
+
const contexts = /* @__PURE__ */ new Map();
|
|
218
|
+
const diagnostics = options.diagnostics;
|
|
219
|
+
const cache = (_a = options.cacheContexts) != null ? _a : true;
|
|
220
|
+
const getContext = (type, attrs) => {
|
|
221
|
+
var _a2;
|
|
222
|
+
const requested = type === "experimental-webgl" ? "webgl" : type;
|
|
223
|
+
if (cache && contexts.has(requested)) return contexts.get(requested);
|
|
224
|
+
let ctx;
|
|
225
|
+
try {
|
|
226
|
+
ctx = originalGetContext(requested, attrs);
|
|
227
|
+
} catch (error) {
|
|
228
|
+
diagnostics == null ? void 0 : diagnostics.error(`canvas.getContext("${requested}") threw`, error);
|
|
229
|
+
return null;
|
|
230
|
+
}
|
|
231
|
+
if (!ctx) {
|
|
232
|
+
diagnostics == null ? void 0 : diagnostics.warnOnce(
|
|
233
|
+
`ctx-${String(requested)}`,
|
|
234
|
+
`canvas.getContext("${String(requested)}") returned ${String(ctx)}. three.js >= r163 requires WebGL2; check game.json / device support.`
|
|
235
|
+
);
|
|
236
|
+
return ctx;
|
|
237
|
+
}
|
|
238
|
+
ctx = normalizeContext(ctx, raw, requested, (_a2 = options.normalizeWebGL) != null ? _a2 : false);
|
|
239
|
+
if (cache) contexts.set(requested, ctx);
|
|
240
|
+
return ctx;
|
|
241
|
+
};
|
|
242
|
+
const toDataURL = (type, quality) => {
|
|
243
|
+
if (typeof raw.toDataURL === "function") return raw.toDataURL(type, quality);
|
|
244
|
+
return "data:,";
|
|
245
|
+
};
|
|
246
|
+
const patched = patchElement(raw, {
|
|
247
|
+
rect: normalizeRect(options.rect),
|
|
248
|
+
document: options.document,
|
|
249
|
+
instanceOf: [HTMLCanvasElementShim, HTMLElementShim],
|
|
250
|
+
extra: {
|
|
251
|
+
getContext: { value: getContext, writable: true },
|
|
252
|
+
toDataURL: { value: toDataURL, writable: true },
|
|
253
|
+
// three.js reads `canvas.nodeType` / `canvas.tagName` in a few addons.
|
|
254
|
+
nodeType: { value: 1 },
|
|
255
|
+
tagName: { value: "CANVAS" },
|
|
256
|
+
nodeName: { value: "CANVAS" }
|
|
257
|
+
}
|
|
258
|
+
});
|
|
259
|
+
return {
|
|
260
|
+
...patched,
|
|
261
|
+
canvas: raw,
|
|
262
|
+
contexts
|
|
263
|
+
};
|
|
264
|
+
}
|
|
265
|
+
function createOffscreenCanvas(wx, width = 1, height = 1, options = {}) {
|
|
266
|
+
var _a;
|
|
267
|
+
if (typeof wx.createOffscreenCanvas !== "function") {
|
|
268
|
+
throw new Error("[mini-three-adapter] wx.createOffscreenCanvas is unavailable on this base library");
|
|
269
|
+
}
|
|
270
|
+
const raw = wx.createOffscreenCanvas({
|
|
271
|
+
width,
|
|
272
|
+
height,
|
|
273
|
+
type: (_a = options.type) != null ? _a : "2d"
|
|
274
|
+
});
|
|
275
|
+
raw.width = width;
|
|
276
|
+
raw.height = height;
|
|
277
|
+
const patched = patchCanvas(raw, {
|
|
278
|
+
...options,
|
|
279
|
+
rect: { width, height, left: 0, top: 0, right: width, bottom: height }
|
|
280
|
+
});
|
|
281
|
+
OffscreenCanvasShim.__instances.add(raw);
|
|
282
|
+
return patched.canvas;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
// src/core/dom.ts
|
|
286
|
+
var ShimDOMRect = class _ShimDOMRect {
|
|
287
|
+
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
288
|
+
__publicField(this, "x");
|
|
289
|
+
__publicField(this, "y");
|
|
290
|
+
__publicField(this, "width");
|
|
291
|
+
__publicField(this, "height");
|
|
292
|
+
this.x = x;
|
|
293
|
+
this.y = y;
|
|
294
|
+
this.width = width;
|
|
295
|
+
this.height = height;
|
|
296
|
+
DOMRectShim.__instances.add(this);
|
|
297
|
+
}
|
|
298
|
+
get top() {
|
|
299
|
+
return this.y;
|
|
300
|
+
}
|
|
301
|
+
get left() {
|
|
302
|
+
return this.x;
|
|
303
|
+
}
|
|
304
|
+
get right() {
|
|
305
|
+
return this.x + this.width;
|
|
306
|
+
}
|
|
307
|
+
get bottom() {
|
|
308
|
+
return this.y + this.height;
|
|
309
|
+
}
|
|
310
|
+
toJSON() {
|
|
311
|
+
return { x: this.x, y: this.y, width: this.width, height: this.height, top: this.top, left: this.left, right: this.right, bottom: this.bottom };
|
|
312
|
+
}
|
|
313
|
+
static fromRect(other) {
|
|
314
|
+
var _a, _b, _c, _d;
|
|
315
|
+
return new _ShimDOMRect((_a = other == null ? void 0 : other.left) != null ? _a : 0, (_b = other == null ? void 0 : other.top) != null ? _b : 0, (_c = other == null ? void 0 : other.width) != null ? _c : 0, (_d = other == null ? void 0 : other.height) != null ? _d : 0);
|
|
316
|
+
}
|
|
317
|
+
};
|
|
318
|
+
function createBody(document) {
|
|
319
|
+
const body = {};
|
|
320
|
+
patchElement(body, {
|
|
321
|
+
rect: { width: 0, height: 0, left: 0, top: 0, right: 0, bottom: 0 },
|
|
322
|
+
document,
|
|
323
|
+
instanceOf: [HTMLElementShim],
|
|
324
|
+
extra: {
|
|
325
|
+
tagName: { value: "BODY" },
|
|
326
|
+
appendChild: { value: (child) => child, writable: true },
|
|
327
|
+
removeChild: { value: (child) => child, writable: true },
|
|
328
|
+
insertBefore: { value: (child) => child, writable: true },
|
|
329
|
+
contains: { value: () => false, writable: true }
|
|
330
|
+
}
|
|
331
|
+
});
|
|
332
|
+
return body;
|
|
333
|
+
}
|
|
334
|
+
function createDocument(options) {
|
|
335
|
+
const { binding, diagnostics, defaultContextType } = options;
|
|
336
|
+
const document = new MiniEventTarget();
|
|
337
|
+
const body = createBody(document);
|
|
338
|
+
document.body = body;
|
|
339
|
+
document.documentElement = body;
|
|
340
|
+
document.defaultView = null;
|
|
341
|
+
const createCanvas = (width, height, type = defaultContextType) => {
|
|
342
|
+
const raw = binding.createOffscreenCanvas(width , height , type);
|
|
343
|
+
const patched = patchCanvas(raw, {
|
|
344
|
+
rect: { width: raw.width, height: raw.height, left: 0, top: 0, right: raw.width, bottom: raw.height },
|
|
345
|
+
document,
|
|
346
|
+
diagnostics,
|
|
347
|
+
normalizeWebGL: true
|
|
348
|
+
});
|
|
349
|
+
OffscreenCanvasShim.__instances.add(raw);
|
|
350
|
+
return patched.canvas;
|
|
351
|
+
};
|
|
352
|
+
const createElement = (tagName) => {
|
|
353
|
+
const tag = String(tagName).toLowerCase();
|
|
354
|
+
if (tag === "canvas") {
|
|
355
|
+
try {
|
|
356
|
+
return createCanvas(1, 1, "webgl2");
|
|
357
|
+
} catch (error) {
|
|
358
|
+
diagnostics.warn('createElement("canvas"): webgl2 offscreen canvas failed, falling back to 2d', error);
|
|
359
|
+
return createCanvas(1, 1, "2d");
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
if (tag === "img" || tag === "image") return binding.imageFactory.createImage();
|
|
363
|
+
if (tag === "div" || tag === "span" || tag === "a") {
|
|
364
|
+
const el2 = {};
|
|
365
|
+
patchElement(el2, {
|
|
366
|
+
rect: { width: 0, height: 0, left: 0, top: 0, right: 0, bottom: 0 },
|
|
367
|
+
document,
|
|
368
|
+
instanceOf: [HTMLElementShim]
|
|
369
|
+
});
|
|
370
|
+
return el2;
|
|
371
|
+
}
|
|
372
|
+
diagnostics.warnOnce(`createElement-${tag}`, `document.createElement("${tag}") is not emulated; returning a generic element`);
|
|
373
|
+
const el = {};
|
|
374
|
+
patchElement(el, {
|
|
375
|
+
rect: { width: 0, height: 0, left: 0, top: 0, right: 0, bottom: 0 },
|
|
376
|
+
document
|
|
377
|
+
});
|
|
378
|
+
return el;
|
|
379
|
+
};
|
|
380
|
+
Object.defineProperties(document, {
|
|
381
|
+
createElement: { value: createElement, writable: true, configurable: true },
|
|
382
|
+
createElementNS: {
|
|
383
|
+
value: (_ns, tagName) => createElement(tagName),
|
|
384
|
+
writable: true,
|
|
385
|
+
configurable: true
|
|
386
|
+
},
|
|
387
|
+
createTextNode: { value: (text) => ({ textContent: text }), configurable: true },
|
|
388
|
+
getElementById: { value: () => null, configurable: true },
|
|
389
|
+
querySelector: { value: () => null, configurable: true },
|
|
390
|
+
querySelectorAll: { value: () => [], configurable: true },
|
|
391
|
+
hidden: { value: false, writable: true, configurable: true },
|
|
392
|
+
visibilityState: { value: "visible", writable: true, configurable: true },
|
|
393
|
+
readyState: { value: "complete", writable: true, configurable: true },
|
|
394
|
+
nodeType: { value: 9, writable: true, configurable: true }
|
|
395
|
+
});
|
|
396
|
+
options.documentRef.current = document;
|
|
397
|
+
return document;
|
|
398
|
+
}
|
|
399
|
+
function createScreen(width, height) {
|
|
400
|
+
const screen = {
|
|
401
|
+
width,
|
|
402
|
+
height,
|
|
403
|
+
availWidth: width,
|
|
404
|
+
availHeight: height,
|
|
405
|
+
colorDepth: 24,
|
|
406
|
+
pixelDepth: 24,
|
|
407
|
+
orientation: { type: "portrait-primary", angle: 0 }
|
|
408
|
+
};
|
|
409
|
+
patchEventTarget(screen);
|
|
410
|
+
return screen;
|
|
411
|
+
}
|
|
412
|
+
function createOffscreenCanvasCtor(binding) {
|
|
413
|
+
const Ctor = function(width = 1, height = 1) {
|
|
414
|
+
const raw = binding.createOffscreenCanvas(width, height, "2d");
|
|
415
|
+
const patched = patchCanvas(raw, {
|
|
416
|
+
rect: { width, height, left: 0, top: 0, right: width, bottom: height },
|
|
417
|
+
normalizeWebGL: true
|
|
418
|
+
});
|
|
419
|
+
OffscreenCanvasShim.__instances.add(raw);
|
|
420
|
+
return patched.canvas;
|
|
421
|
+
};
|
|
422
|
+
Object.defineProperty(Ctor, "name", { value: "OffscreenCanvas" });
|
|
423
|
+
Object.defineProperty(Ctor, Symbol.hasInstance, {
|
|
424
|
+
value: (instance) => OffscreenCanvasShim.__instances.has(instance)
|
|
425
|
+
});
|
|
426
|
+
return Ctor;
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/core/frames.ts
|
|
430
|
+
function createFrameScheduler(request, cancel, options = {}) {
|
|
431
|
+
var _a, _b;
|
|
432
|
+
const now = (_a = options.now) != null ? _a : (() => Date.now());
|
|
433
|
+
let fpsCap = (_b = options.fpsCap) != null ? _b : 0;
|
|
434
|
+
let measuredFps = 0;
|
|
435
|
+
let disposed = false;
|
|
436
|
+
const active = /* @__PURE__ */ new Set();
|
|
437
|
+
const state = {
|
|
438
|
+
get fps() {
|
|
439
|
+
return measuredFps;
|
|
440
|
+
},
|
|
441
|
+
request(callback) {
|
|
442
|
+
if (disposed) return -1;
|
|
443
|
+
const id = request((time) => {
|
|
444
|
+
active.delete(id);
|
|
445
|
+
if (!disposed) callback(time);
|
|
446
|
+
});
|
|
447
|
+
active.add(id);
|
|
448
|
+
return id;
|
|
449
|
+
},
|
|
450
|
+
cancel(id) {
|
|
451
|
+
if (active.delete(id)) cancel(id);
|
|
452
|
+
},
|
|
453
|
+
loop(callback) {
|
|
454
|
+
let last = 0;
|
|
455
|
+
let lastAccepted = 0;
|
|
456
|
+
let handle = -1;
|
|
457
|
+
let running = true;
|
|
458
|
+
const minDelta = () => fpsCap > 0 ? 1e3 / fpsCap : 0;
|
|
459
|
+
const tick = (time) => {
|
|
460
|
+
var _a2;
|
|
461
|
+
if (!running || disposed) return;
|
|
462
|
+
handle = state.request(tick);
|
|
463
|
+
const t = typeof time === "number" && Number.isFinite(time) ? time : now();
|
|
464
|
+
const delta = last === 0 ? 16.67 : t - last;
|
|
465
|
+
if (t - lastAccepted < minDelta()) return;
|
|
466
|
+
lastAccepted = t;
|
|
467
|
+
last = t;
|
|
468
|
+
measuredFps = delta > 0 ? measuredFps * 0.9 + 1e3 / delta * 0.1 : measuredFps;
|
|
469
|
+
const started = now();
|
|
470
|
+
callback(delta, t);
|
|
471
|
+
const duration = now() - started;
|
|
472
|
+
if (options.slowFrameThreshold && duration > options.slowFrameThreshold) {
|
|
473
|
+
(_a2 = options.onSlowFrame) == null ? void 0 : _a2.call(options, duration);
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
handle = state.request(tick);
|
|
477
|
+
return {
|
|
478
|
+
cancel: () => {
|
|
479
|
+
running = false;
|
|
480
|
+
state.cancel(handle);
|
|
481
|
+
}
|
|
482
|
+
};
|
|
483
|
+
},
|
|
484
|
+
setFpsCap(fps) {
|
|
485
|
+
fpsCap = Math.max(0, Number.isFinite(fps) ? fps : 0);
|
|
486
|
+
},
|
|
487
|
+
dispose() {
|
|
488
|
+
disposed = true;
|
|
489
|
+
for (const id of active) cancel(id);
|
|
490
|
+
active.clear();
|
|
491
|
+
}
|
|
492
|
+
};
|
|
493
|
+
return state;
|
|
494
|
+
}
|
|
495
|
+
|
|
496
|
+
// src/core/pointer.ts
|
|
497
|
+
var TYPE_MAP = {
|
|
498
|
+
touchstart: "pointerdown",
|
|
499
|
+
touchmove: "pointermove",
|
|
500
|
+
touchend: "pointerup",
|
|
501
|
+
touchcancel: "pointercancel"
|
|
502
|
+
};
|
|
503
|
+
var MOUSE_TYPE_MAP = {
|
|
504
|
+
pointerdown: "mousedown",
|
|
505
|
+
pointermove: "mousemove",
|
|
506
|
+
pointerup: "mouseup",
|
|
507
|
+
pointercancel: "mouseup"
|
|
508
|
+
};
|
|
509
|
+
function toArrayLike(value) {
|
|
510
|
+
if (!value) return [];
|
|
511
|
+
return Array.prototype.slice.call(value);
|
|
512
|
+
}
|
|
513
|
+
var PointerBridge = class {
|
|
514
|
+
constructor(options) {
|
|
515
|
+
__publicField(this, "options", options);
|
|
516
|
+
__publicField(this, "pointers", /* @__PURE__ */ new Map());
|
|
517
|
+
__publicField(this, "captured", /* @__PURE__ */ new Map());
|
|
518
|
+
__publicField(this, "rect", normalizeRect({ width: 1, height: 1 }));
|
|
519
|
+
__publicField(this, "rectReady", false);
|
|
520
|
+
__publicField(this, "fallbackId", 61440);
|
|
521
|
+
__publicField(this, "lastTapAt", 0);
|
|
522
|
+
__publicField(this, "disposed", false);
|
|
523
|
+
this.refreshRect();
|
|
524
|
+
}
|
|
525
|
+
get activePointerCount() {
|
|
526
|
+
return this.pointers.size;
|
|
527
|
+
}
|
|
528
|
+
getRect() {
|
|
529
|
+
return { ...this.rect };
|
|
530
|
+
}
|
|
531
|
+
setRect(rect) {
|
|
532
|
+
this.rect = normalizeRect(rect);
|
|
533
|
+
this.rectReady = true;
|
|
534
|
+
}
|
|
535
|
+
/** Re-read the bounding rect. Async rects update the cache when resolved. */
|
|
536
|
+
refreshRect() {
|
|
537
|
+
var _a;
|
|
538
|
+
try {
|
|
539
|
+
const result = this.options.getRect();
|
|
540
|
+
if (result && typeof result.then === "function") {
|
|
541
|
+
result.then((r) => this.setRect(r)).catch((error) => {
|
|
542
|
+
var _a2;
|
|
543
|
+
return (_a2 = this.options.diagnostics) == null ? void 0 : _a2.warn("pointer rect refresh failed", error);
|
|
544
|
+
});
|
|
545
|
+
} else {
|
|
546
|
+
this.setRect(result);
|
|
547
|
+
}
|
|
548
|
+
} catch (error) {
|
|
549
|
+
(_a = this.options.diagnostics) == null ? void 0 : _a.warn("pointer rect read failed", error);
|
|
550
|
+
}
|
|
551
|
+
}
|
|
552
|
+
setPointerCapture(pointerId, target) {
|
|
553
|
+
this.captured.set(pointerId, target);
|
|
554
|
+
}
|
|
555
|
+
releasePointerCapture(pointerId) {
|
|
556
|
+
this.captured.delete(pointerId);
|
|
557
|
+
}
|
|
558
|
+
/** Accept any WeChat touch-like event and dispatch normalized pointer events. */
|
|
559
|
+
dispatch(event, overrides = {}) {
|
|
560
|
+
var _a, _b, _c, _d, _e, _f;
|
|
561
|
+
if (this.disposed) return;
|
|
562
|
+
if (overrides.computeRect) this.refreshRect();
|
|
563
|
+
if (!this.rectReady) {
|
|
564
|
+
(_a = this.options.diagnostics) == null ? void 0 : _a.warnOnce(
|
|
565
|
+
"pointer-rect-not-ready",
|
|
566
|
+
"Pointer event dropped: canvas rect is not available yet. Call await runtime.resize() first."
|
|
567
|
+
);
|
|
568
|
+
return;
|
|
569
|
+
}
|
|
570
|
+
const type = String((_b = event.type) != null ? _b : "").toLowerCase();
|
|
571
|
+
const touches = (_c = toArrayLike(event.changedTouches)) != null ? _c : [];
|
|
572
|
+
toArrayLike(event.touches);
|
|
573
|
+
const points = touches.length > 0 ? touches : this.synthesizePoint(event, type);
|
|
574
|
+
if (type === "touchstart" || type === "pointerdown") {
|
|
575
|
+
for (const point of points) this.track(point, event, touches.length === 0);
|
|
576
|
+
}
|
|
577
|
+
const pointerType = (_d = TYPE_MAP[type]) != null ? _d : type === "tap" ? "pointerup" : "";
|
|
578
|
+
if (!pointerType) {
|
|
579
|
+
(_e = this.options.diagnostics) == null ? void 0 : _e.debug(`ignoring unknown touch event type: ${type}`);
|
|
580
|
+
return;
|
|
581
|
+
}
|
|
582
|
+
for (const point of points) {
|
|
583
|
+
const id = this.identifierOf(point, type);
|
|
584
|
+
const coords = this.toCoords(point, event);
|
|
585
|
+
const primary = this.pointers.size <= 1 || id === this.pointers.keys().next().value;
|
|
586
|
+
const buttons = pointerType === "pointerup" || pointerType === "pointercancel" ? 0 : 1;
|
|
587
|
+
const init = {
|
|
588
|
+
pointerId: id,
|
|
589
|
+
pointerType: "touch",
|
|
590
|
+
isPrimary: primary,
|
|
591
|
+
clientX: coords.x,
|
|
592
|
+
clientY: coords.y,
|
|
593
|
+
pageX: coords.x,
|
|
594
|
+
pageY: coords.y,
|
|
595
|
+
offsetX: coords.offsetX,
|
|
596
|
+
offsetY: coords.offsetY,
|
|
597
|
+
button: pointerType === "pointerdown" ? 0 : -1,
|
|
598
|
+
buttons,
|
|
599
|
+
bubbles: true,
|
|
600
|
+
cancelable: true
|
|
601
|
+
};
|
|
602
|
+
if (pointerType === "pointerdown") {
|
|
603
|
+
this.emit("pointerover", id, init);
|
|
604
|
+
this.emit("pointerenter", id, init);
|
|
605
|
+
}
|
|
606
|
+
this.emit(pointerType, id, init);
|
|
607
|
+
if (this.options.emitMouseEvents !== false) {
|
|
608
|
+
const mouseType = (_f = MOUSE_TYPE_MAP[pointerType]) != null ? _f : "mouseup";
|
|
609
|
+
const mouse = new MiniMouseEvent(mouseType, {
|
|
610
|
+
...init,
|
|
611
|
+
button: pointerType === "pointerdown" ? 0 : 0,
|
|
612
|
+
buttons,
|
|
613
|
+
pointerType: "mouse"
|
|
614
|
+
});
|
|
615
|
+
this.fanout(mouse, id, overrides.propagate);
|
|
616
|
+
}
|
|
617
|
+
if (pointerType === "pointerup" || pointerType === "pointercancel") {
|
|
618
|
+
this.emit("pointerout", id, { ...init, buttons: 0 });
|
|
619
|
+
this.emit("pointerleave", id, { ...init, buttons: 0 });
|
|
620
|
+
this.pointers.delete(id);
|
|
621
|
+
this.captured.delete(id);
|
|
622
|
+
}
|
|
623
|
+
}
|
|
624
|
+
if (type === "tap" || type === "touchend" && Date.now() - this.lastTapAt < 350) {
|
|
625
|
+
if (type === "tap") this.lastTapAt = Date.now();
|
|
626
|
+
const point = points[0];
|
|
627
|
+
if (point) {
|
|
628
|
+
const coords = this.toCoords(point, event);
|
|
629
|
+
this.fanout(new MiniMouseEvent("click", {
|
|
630
|
+
pointerId: 1,
|
|
631
|
+
clientX: coords.x,
|
|
632
|
+
clientY: coords.y,
|
|
633
|
+
offsetX: coords.offsetX,
|
|
634
|
+
offsetY: coords.offsetY,
|
|
635
|
+
button: 0,
|
|
636
|
+
buttons: 0
|
|
637
|
+
}), 1, overrides.propagate);
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
}
|
|
641
|
+
/** Convenience for mouse events coming from WeChat devtools / PC. */
|
|
642
|
+
dispatchMouse(event) {
|
|
643
|
+
var _a, _b, _c, _d, _e, _f;
|
|
644
|
+
const rect = this.rect;
|
|
645
|
+
const x = (_b = (_a = event.clientX) != null ? _a : event.x) != null ? _b : 0;
|
|
646
|
+
const y = (_d = (_c = event.clientY) != null ? _c : event.y) != null ? _d : 0;
|
|
647
|
+
const type = event.type.startsWith("mouse") ? event.type : `mouse${event.type}`;
|
|
648
|
+
const mouse = new MiniMouseEvent(type, {
|
|
649
|
+
pointerId: 1,
|
|
650
|
+
clientX: x,
|
|
651
|
+
clientY: y,
|
|
652
|
+
offsetX: x - rect.left,
|
|
653
|
+
offsetY: y - rect.top,
|
|
654
|
+
button: (_e = event.button) != null ? _e : 0,
|
|
655
|
+
buttons: type === "mouseup" ? 0 : 1,
|
|
656
|
+
pointerType: "mouse"
|
|
657
|
+
});
|
|
658
|
+
mouse.wheelDelta = (_f = event.deltaY) != null ? _f : 0;
|
|
659
|
+
this.fanout(mouse, 1);
|
|
660
|
+
}
|
|
661
|
+
dispose() {
|
|
662
|
+
this.disposed = true;
|
|
663
|
+
this.pointers.clear();
|
|
664
|
+
this.captured.clear();
|
|
665
|
+
}
|
|
666
|
+
track(point, event, synthetic) {
|
|
667
|
+
var _a;
|
|
668
|
+
const id = this.identifierOf(point, (_a = event.type) != null ? _a : "touchstart");
|
|
669
|
+
const coords = this.toCoords(point, event);
|
|
670
|
+
this.pointers.set(id, { x: coords.offsetX, y: coords.offsetY });
|
|
671
|
+
if (synthetic) this.fallbackId++;
|
|
672
|
+
}
|
|
673
|
+
identifierOf(point, type) {
|
|
674
|
+
var _a;
|
|
675
|
+
if (typeof point.identifier === "number") return point.identifier;
|
|
676
|
+
if (this.pointers.size === 1) return this.pointers.keys().next().value;
|
|
677
|
+
if (type === "touchend" || type === "touchcancel" || type === "tap") {
|
|
678
|
+
return (_a = this.pointers.keys().next().value) != null ? _a : this.fallbackId;
|
|
679
|
+
}
|
|
680
|
+
return this.fallbackId++;
|
|
681
|
+
}
|
|
682
|
+
synthesizePoint(event, type) {
|
|
683
|
+
var _a, _b;
|
|
684
|
+
const detail = event.detail;
|
|
685
|
+
if (detail && typeof detail.x === "number") {
|
|
686
|
+
return [{ clientX: detail.x, clientY: (_a = detail.y) != null ? _a : 0, identifier: (_b = this.pointers.keys().next().value) != null ? _b : 1 }];
|
|
687
|
+
}
|
|
688
|
+
if (type === "tap" || type === "touchend") {
|
|
689
|
+
const last = this.pointers.entries().next().value;
|
|
690
|
+
if (last) return [{ clientX: last[1].x + this.rect.left, clientY: last[1].y + this.rect.top, identifier: last[0] }];
|
|
691
|
+
}
|
|
692
|
+
return [];
|
|
693
|
+
}
|
|
694
|
+
toCoords(point, _event) {
|
|
695
|
+
var _a, _b, _c, _d, _e, _f;
|
|
696
|
+
const x = (_c = (_b = (_a = point.clientX) != null ? _a : point.pageX) != null ? _b : point.x) != null ? _c : 0;
|
|
697
|
+
const y = (_f = (_e = (_d = point.clientY) != null ? _d : point.pageY) != null ? _e : point.y) != null ? _f : 0;
|
|
698
|
+
return { x, y, offsetX: x - this.rect.left, offsetY: y - this.rect.top };
|
|
699
|
+
}
|
|
700
|
+
emit(type, pointerId, init = {}) {
|
|
701
|
+
const ev = new MiniPointerEvent(type, { ...init, pointerId });
|
|
702
|
+
ev.target = this.options.targets.element;
|
|
703
|
+
this.fanout(ev, pointerId);
|
|
704
|
+
}
|
|
705
|
+
fanout(event, pointerId, propagateOverride) {
|
|
706
|
+
var _a;
|
|
707
|
+
const propagate = (_a = propagateOverride != null ? propagateOverride : this.options.propagate) != null ? _a : true;
|
|
708
|
+
const captured = this.captured.get(pointerId);
|
|
709
|
+
const targets = captured ? [captured] : [this.options.targets.element, this.options.targets.document, this.options.targets.window];
|
|
710
|
+
for (const target of targets) {
|
|
711
|
+
if (!target) continue;
|
|
712
|
+
if (!propagate && target !== this.options.targets.element && target !== captured) continue;
|
|
713
|
+
event.currentTarget = target;
|
|
714
|
+
target.dispatchEvent(event);
|
|
715
|
+
if (event.cancelBubble) break;
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
|
|
720
|
+
// src/core/window-info.ts
|
|
721
|
+
function readWindowInfo(wx, pixelRatioCap = 2) {
|
|
722
|
+
const raw = wx.getWindowInfo ? wx.getWindowInfo() : wx.getSystemInfoSync ? wx.getSystemInfoSync() : { windowWidth: 0, windowHeight: 0, pixelRatio: 1 };
|
|
723
|
+
const width = raw.windowWidth || raw.screenWidth || 0;
|
|
724
|
+
const height = raw.windowHeight || raw.screenHeight || 0;
|
|
725
|
+
const rawPixelRatio = raw.pixelRatio || 1;
|
|
726
|
+
const safeArea = raw.safeArea ? {
|
|
727
|
+
top: raw.safeArea.top,
|
|
728
|
+
left: raw.safeArea.left,
|
|
729
|
+
width: raw.safeArea.width,
|
|
730
|
+
height: raw.safeArea.height,
|
|
731
|
+
right: raw.safeArea.right,
|
|
732
|
+
bottom: raw.safeArea.bottom
|
|
733
|
+
} : void 0;
|
|
734
|
+
return {
|
|
735
|
+
width,
|
|
736
|
+
height,
|
|
737
|
+
pixelRatio: Math.min(rawPixelRatio, pixelRatioCap > 0 ? pixelRatioCap : rawPixelRatio),
|
|
738
|
+
rawPixelRatio,
|
|
739
|
+
...safeArea ? { safeArea } : {}
|
|
740
|
+
};
|
|
741
|
+
}
|
|
742
|
+
function createWindowInfoStore(wx, options = {}) {
|
|
743
|
+
var _a, _b, _c;
|
|
744
|
+
let cap = (_a = options.pixelRatioCap) != null ? _a : 2;
|
|
745
|
+
let current = readWindowInfo(wx, cap);
|
|
746
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
747
|
+
let disposed = false;
|
|
748
|
+
const publish = (next) => {
|
|
749
|
+
const changed = next.width !== current.width || next.height !== current.height || next.pixelRatio !== current.pixelRatio;
|
|
750
|
+
current = next;
|
|
751
|
+
if (changed) for (const listener of Array.from(listeners)) listener(current);
|
|
752
|
+
};
|
|
753
|
+
const refresh = () => {
|
|
754
|
+
const next = readWindowInfo(wx, cap);
|
|
755
|
+
const changed = next.width !== current.width || next.height !== current.height || next.pixelRatio !== current.pixelRatio;
|
|
756
|
+
publish(next);
|
|
757
|
+
return changed;
|
|
758
|
+
};
|
|
759
|
+
const resizeListener = () => {
|
|
760
|
+
refresh();
|
|
761
|
+
};
|
|
762
|
+
const canWatch = typeof wx.onWindowResize === "function";
|
|
763
|
+
if (canWatch) (_b = wx.onWindowResize) == null ? void 0 : _b.call(wx, resizeListener);
|
|
764
|
+
else (_c = options.diagnostics) == null ? void 0 : _c.warnOnce(
|
|
765
|
+
"no-window-resize",
|
|
766
|
+
"wx.onWindowResize unavailable; call runtime.resize() manually after orientation changes."
|
|
767
|
+
);
|
|
768
|
+
return {
|
|
769
|
+
get info() {
|
|
770
|
+
return current;
|
|
771
|
+
},
|
|
772
|
+
refresh,
|
|
773
|
+
onChange(listener) {
|
|
774
|
+
listeners.add(listener);
|
|
775
|
+
return () => listeners.delete(listener);
|
|
776
|
+
},
|
|
777
|
+
setPixelRatioCap(value) {
|
|
778
|
+
cap = value;
|
|
779
|
+
refresh();
|
|
780
|
+
},
|
|
781
|
+
dispose() {
|
|
782
|
+
var _a2;
|
|
783
|
+
if (disposed) return;
|
|
784
|
+
disposed = true;
|
|
785
|
+
if (canWatch) (_a2 = wx.offWindowResize) == null ? void 0 : _a2.call(wx, resizeListener);
|
|
786
|
+
listeners.clear();
|
|
787
|
+
}
|
|
788
|
+
};
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
// src/core/runtime.ts
|
|
792
|
+
function hostWxStub() {
|
|
793
|
+
const host = globalThis;
|
|
794
|
+
return {
|
|
795
|
+
getWindowInfo: () => {
|
|
796
|
+
var _a, _b, _c;
|
|
797
|
+
return {
|
|
798
|
+
windowWidth: (_a = host.innerWidth) != null ? _a : 1,
|
|
799
|
+
windowHeight: (_b = host.innerHeight) != null ? _b : 1,
|
|
800
|
+
pixelRatio: (_c = host.devicePixelRatio) != null ? _c : 1
|
|
801
|
+
};
|
|
802
|
+
}
|
|
803
|
+
};
|
|
804
|
+
}
|
|
805
|
+
var NoopResizeObserver = class {
|
|
806
|
+
observe() {
|
|
807
|
+
}
|
|
808
|
+
unobserve() {
|
|
809
|
+
}
|
|
810
|
+
disconnect() {
|
|
811
|
+
}
|
|
812
|
+
};
|
|
813
|
+
async function createRuntime(platform, options = {}) {
|
|
814
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
815
|
+
const binding = typeof platform === "function" ? await platform() : platform;
|
|
816
|
+
const wx = (_a = binding.wx) != null ? _a : hostWxStub();
|
|
817
|
+
const diagnostics = createDiagnostics((_b = options.logLevel) != null ? _b : "warn", options.reporter);
|
|
818
|
+
const initialRect = await binding.getCanvasRect();
|
|
819
|
+
const documentRef = { current: null };
|
|
820
|
+
const document = createDocument({
|
|
821
|
+
binding,
|
|
822
|
+
diagnostics,
|
|
823
|
+
defaultContextType: (_c = options.defaultContextType) != null ? _c : "webgl2",
|
|
824
|
+
documentRef
|
|
825
|
+
});
|
|
826
|
+
const patched = patchCanvas(binding.rawCanvas, {
|
|
827
|
+
rect: initialRect,
|
|
828
|
+
document,
|
|
829
|
+
diagnostics,
|
|
830
|
+
cacheContexts: (_d = options.cacheContexts) != null ? _d : true,
|
|
831
|
+
normalizeWebGL: (_e = options.normalizeWebGL) != null ? _e : true
|
|
832
|
+
});
|
|
833
|
+
const canvas = patched.canvas;
|
|
834
|
+
const windowInfo = createWindowInfoStore(wx, {
|
|
835
|
+
pixelRatioCap: (_f = options.pixelRatioCap) != null ? _f : 2,
|
|
836
|
+
diagnostics
|
|
837
|
+
});
|
|
838
|
+
const screen = createScreen(windowInfo.info.width, windowInfo.info.height);
|
|
839
|
+
const scope = createScope();
|
|
840
|
+
patchEventTarget(scope);
|
|
841
|
+
document.defaultView = scope;
|
|
842
|
+
scope.document = document;
|
|
843
|
+
scope.screen = screen;
|
|
844
|
+
scope.navigator = {
|
|
845
|
+
userAgent: `Mozilla/5.0 (WeChat MiniGame) mini-three-adapter/${binding.capabilities.platform}`,
|
|
846
|
+
platform: binding.capabilities.platform,
|
|
847
|
+
hardwareConcurrency: 4
|
|
848
|
+
};
|
|
849
|
+
Object.defineProperties(scope, {
|
|
850
|
+
innerWidth: { get: () => windowInfo.info.width, enumerable: true, configurable: true },
|
|
851
|
+
innerHeight: { get: () => windowInfo.info.height, enumerable: true, configurable: true },
|
|
852
|
+
outerWidth: { get: () => windowInfo.info.width, enumerable: true, configurable: true },
|
|
853
|
+
outerHeight: { get: () => windowInfo.info.height, enumerable: true, configurable: true },
|
|
854
|
+
devicePixelRatio: { get: () => windowInfo.info.pixelRatio, enumerable: true, configurable: true },
|
|
855
|
+
pageXOffset: { get: () => 0, enumerable: true, configurable: true },
|
|
856
|
+
pageYOffset: { get: () => 0, enumerable: true, configurable: true }
|
|
857
|
+
});
|
|
858
|
+
const frames = createFrameScheduler(
|
|
859
|
+
(cb) => binding.requestAnimationFrame(cb),
|
|
860
|
+
(id) => binding.cancelAnimationFrame(id),
|
|
861
|
+
{
|
|
862
|
+
now: () => binding.now(),
|
|
863
|
+
...options.fpsCap ? { fpsCap: options.fpsCap } : {},
|
|
864
|
+
...options.slowFrameThreshold ? { slowFrameThreshold: options.slowFrameThreshold } : {},
|
|
865
|
+
onSlowFrame: (ms) => diagnostics.warnOnce("slow-frame", `Slow frame: ${ms.toFixed(1)}ms`)
|
|
866
|
+
}
|
|
867
|
+
);
|
|
868
|
+
scope.performance = { now: () => binding.now() };
|
|
869
|
+
scope.requestAnimationFrame = (cb) => frames.request(cb);
|
|
870
|
+
scope.cancelAnimationFrame = (id) => frames.cancel(id);
|
|
871
|
+
scope.getComputedStyle = (element) => {
|
|
872
|
+
const style = element == null ? void 0 : element.style;
|
|
873
|
+
return style != null ? style : { width: "0px", height: "0px", display: "block" };
|
|
874
|
+
};
|
|
875
|
+
scope.matchMedia = (query) => ({
|
|
876
|
+
matches: false,
|
|
877
|
+
media: query,
|
|
878
|
+
addListener: () => void 0,
|
|
879
|
+
removeListener: () => void 0
|
|
880
|
+
});
|
|
881
|
+
scope.atob = atob;
|
|
882
|
+
scope.btoa = btoa;
|
|
883
|
+
scope.Event = MiniEvent;
|
|
884
|
+
scope.EventTarget = MiniEventTarget;
|
|
885
|
+
scope.CustomEvent = MiniCustomEvent;
|
|
886
|
+
scope.PointerEvent = MiniPointerEvent;
|
|
887
|
+
scope.MouseEvent = MiniMouseEvent;
|
|
888
|
+
scope.TouchEvent = MiniEvent;
|
|
889
|
+
scope.MessageEvent = MiniMessageEvent;
|
|
890
|
+
scope.ProgressEvent = MiniProgressEvent;
|
|
891
|
+
scope.KeyboardEvent = MiniEvent;
|
|
892
|
+
scope.DOMException = MiniDOMException;
|
|
893
|
+
scope.HTMLElement = HTMLElementShim;
|
|
894
|
+
scope.HTMLCanvasElement = HTMLCanvasElementShim;
|
|
895
|
+
scope.HTMLImageElement = HTMLImageElementShim;
|
|
896
|
+
scope.HTMLVideoElement = void 0;
|
|
897
|
+
scope.OffscreenCanvas = createOffscreenCanvasCtor(binding);
|
|
898
|
+
scope.Image = binding.imageFactory.Image;
|
|
899
|
+
scope.ImageData = binding.imageFactory.ImageData;
|
|
900
|
+
scope.DOMRect = ShimDOMRect;
|
|
901
|
+
scope.WebGLRenderingContext = WebGLRenderingContextShim;
|
|
902
|
+
scope.WebGL2RenderingContext = WebGL2RenderingContextShim;
|
|
903
|
+
scope.AudioContext = typeof wx.createWebAudioContext === "function" ? wx.createWebAudioContext : void 0;
|
|
904
|
+
scope.Blob = MiniBlob;
|
|
905
|
+
scope.URL = MiniURL;
|
|
906
|
+
scope.FileReader = void 0;
|
|
907
|
+
scope.TextDecoder = MiniTextDecoder;
|
|
908
|
+
scope.TextEncoder = MiniTextEncoder;
|
|
909
|
+
scope.AbortController = MiniAbortController;
|
|
910
|
+
scope.AbortSignal = MiniAbortSignal;
|
|
911
|
+
scope.fetch = createFetch(wx);
|
|
912
|
+
scope.XMLHttpRequest = createXMLHttpRequestFactory(wx);
|
|
913
|
+
scope.WebSocket = void 0;
|
|
914
|
+
scope.createImageBitmap = void 0;
|
|
915
|
+
scope.ResizeObserver = NoopResizeObserver;
|
|
916
|
+
const host = globalThis;
|
|
917
|
+
scope.Worker = (_g = host.Worker) != null ? _g : void 0;
|
|
918
|
+
scope.WebAssembly = (_i = (_h = host.WebAssembly) != null ? _h : host.WXWebAssembly) != null ? _i : void 0;
|
|
919
|
+
const bridge = new PointerBridge({
|
|
920
|
+
getRect: () => canvas.getBoundingClientRect(),
|
|
921
|
+
targets: { element: canvas, document, window: scope },
|
|
922
|
+
propagate: (_j = options.propagatePointerEvents) != null ? _j : true,
|
|
923
|
+
emitMouseEvents: (_k = options.emitMouseEvents) != null ? _k : true,
|
|
924
|
+
diagnostics
|
|
925
|
+
});
|
|
926
|
+
Object.defineProperties(canvas, {
|
|
927
|
+
setPointerCapture: { value: (id) => bridge.setPointerCapture(id, canvas), configurable: true },
|
|
928
|
+
releasePointerCapture: { value: (id) => bridge.releasePointerCapture(id), configurable: true },
|
|
929
|
+
hasPointerCapture: { value: (id) => bridge.activePointerCount > 0 && id >= 0, configurable: true }
|
|
930
|
+
});
|
|
931
|
+
const emitter = /* @__PURE__ */ new Map();
|
|
932
|
+
const emit = (name, ...args) => {
|
|
933
|
+
const set = emitter.get(name);
|
|
934
|
+
if (!set) return;
|
|
935
|
+
for (const listener of Array.from(set)) listener(...args);
|
|
936
|
+
};
|
|
937
|
+
const on = (name, listener) => {
|
|
938
|
+
let set = emitter.get(name);
|
|
939
|
+
if (!set) {
|
|
940
|
+
set = /* @__PURE__ */ new Set();
|
|
941
|
+
emitter.set(name, set);
|
|
942
|
+
}
|
|
943
|
+
set.add(listener);
|
|
944
|
+
return () => set == null ? void 0 : set.delete(listener);
|
|
945
|
+
};
|
|
946
|
+
const disposers = [];
|
|
947
|
+
let disposed = false;
|
|
948
|
+
disposers.push(windowInfo.onChange((info) => {
|
|
949
|
+
screen.width = info.width;
|
|
950
|
+
screen.height = info.height;
|
|
951
|
+
screen.availWidth = info.width;
|
|
952
|
+
screen.availHeight = info.height;
|
|
953
|
+
emit("resize", info);
|
|
954
|
+
}));
|
|
955
|
+
disposers.push(binding.watchTouch((event) => {
|
|
956
|
+
bridge.dispatch(event);
|
|
957
|
+
}));
|
|
958
|
+
disposers.push(binding.watchVisibility((visible) => {
|
|
959
|
+
emit("visibilitychange", visible);
|
|
960
|
+
document.visibilityState = visible ? "visible" : "hidden";
|
|
961
|
+
}));
|
|
962
|
+
canvas.addEventListener("webglcontextlost", (event) => {
|
|
963
|
+
var _a2;
|
|
964
|
+
(_a2 = event == null ? void 0 : event.preventDefault) == null ? void 0 : _a2.call(event);
|
|
965
|
+
emit("contextlost");
|
|
966
|
+
});
|
|
967
|
+
const restoreScope = setActiveScope(scope);
|
|
968
|
+
disposers.push(restoreScope);
|
|
969
|
+
const runtime = {
|
|
970
|
+
canvas,
|
|
971
|
+
scope,
|
|
972
|
+
document,
|
|
973
|
+
capabilities: binding.capabilities,
|
|
974
|
+
diagnostics,
|
|
975
|
+
frames,
|
|
976
|
+
bridge,
|
|
977
|
+
get windowInfo() {
|
|
978
|
+
return windowInfo.info;
|
|
979
|
+
},
|
|
980
|
+
rendererHints: {
|
|
981
|
+
canvas,
|
|
982
|
+
antialias: false,
|
|
983
|
+
alpha: false,
|
|
984
|
+
powerPreference: "high-performance",
|
|
985
|
+
preserveDrawingBuffer: false,
|
|
986
|
+
outputColorSpace: "srgb"
|
|
987
|
+
},
|
|
988
|
+
get disposed() {
|
|
989
|
+
return disposed;
|
|
990
|
+
},
|
|
991
|
+
handleTouch(event, opts) {
|
|
992
|
+
bridge.dispatch(event, opts);
|
|
993
|
+
},
|
|
994
|
+
async resize() {
|
|
995
|
+
await resize();
|
|
996
|
+
},
|
|
997
|
+
installGlobals(opts) {
|
|
998
|
+
const undo = installGlobals(scope, opts);
|
|
999
|
+
disposers.push(undo);
|
|
1000
|
+
return undo;
|
|
1001
|
+
},
|
|
1002
|
+
createCanvas(width = 1, height = 1, type = "2d") {
|
|
1003
|
+
const raw = binding.createOffscreenCanvas(width, height, type);
|
|
1004
|
+
const p = patchCanvas(raw, {
|
|
1005
|
+
rect: { width, height, left: 0, top: 0, right: width, bottom: height },
|
|
1006
|
+
document,
|
|
1007
|
+
diagnostics
|
|
1008
|
+
});
|
|
1009
|
+
return p.canvas;
|
|
1010
|
+
},
|
|
1011
|
+
on,
|
|
1012
|
+
report: () => capabilityReport(binding.capabilities),
|
|
1013
|
+
dispose() {
|
|
1014
|
+
var _a2;
|
|
1015
|
+
if (disposed) return;
|
|
1016
|
+
disposed = true;
|
|
1017
|
+
emit("dispose");
|
|
1018
|
+
for (const undo of disposers.splice(0).reverse()) {
|
|
1019
|
+
try {
|
|
1020
|
+
undo();
|
|
1021
|
+
} catch (error) {
|
|
1022
|
+
diagnostics.warn("disposer threw", error);
|
|
1023
|
+
}
|
|
1024
|
+
}
|
|
1025
|
+
bridge.dispose();
|
|
1026
|
+
frames.dispose();
|
|
1027
|
+
windowInfo.dispose();
|
|
1028
|
+
binding.dispose();
|
|
1029
|
+
MiniURL.clearObjectURLs();
|
|
1030
|
+
const clearable = canvas;
|
|
1031
|
+
(_a2 = clearable.clearEventListeners) == null ? void 0 : _a2.call(clearable);
|
|
1032
|
+
emitter.clear();
|
|
1033
|
+
}
|
|
1034
|
+
};
|
|
1035
|
+
async function resize() {
|
|
1036
|
+
const next = await binding.getCanvasRect();
|
|
1037
|
+
patched.updateRect(next);
|
|
1038
|
+
bridge.setRect(next);
|
|
1039
|
+
windowInfo.refresh();
|
|
1040
|
+
diagnostics.debug("runtime resized", next);
|
|
1041
|
+
}
|
|
1042
|
+
if (options.installGlobals) runtime.installGlobals({ skipExisting: true });
|
|
1043
|
+
if (!binding.capabilities.webgl2) {
|
|
1044
|
+
diagnostics.warn("WebGL2 was not detected.\n" + capabilityReport(binding.capabilities));
|
|
1045
|
+
}
|
|
1046
|
+
diagnostics.info("runtime ready", { platform: binding.capabilities.platform, rect: initialRect });
|
|
1047
|
+
return runtime;
|
|
1048
|
+
}
|
|
1049
|
+
function currentScope() {
|
|
1050
|
+
return hasActiveScope() ? getActiveScope() : null;
|
|
1051
|
+
}
|
|
1052
|
+
|
|
1053
|
+
// src/core/capabilities.ts
|
|
1054
|
+
function safe(fn, fallback = false) {
|
|
1055
|
+
try {
|
|
1056
|
+
return fn();
|
|
1057
|
+
} catch {
|
|
1058
|
+
return fallback;
|
|
1059
|
+
}
|
|
1060
|
+
}
|
|
1061
|
+
function readBaseLibraryVersion(wx) {
|
|
1062
|
+
var _a;
|
|
1063
|
+
const direct = wx.SDKVersion;
|
|
1064
|
+
if (typeof direct === "string") return direct;
|
|
1065
|
+
const info = safe(() => {
|
|
1066
|
+
var _a2;
|
|
1067
|
+
return (_a2 = wx.getSystemInfoSync) == null ? void 0 : _a2.call(wx);
|
|
1068
|
+
});
|
|
1069
|
+
return (_a = info == null ? void 0 : info.SDKVersion) != null ? _a : "";
|
|
1070
|
+
}
|
|
1071
|
+
function detectCapabilities(wx, platform, options = {}) {
|
|
1072
|
+
const version = readBaseLibraryVersion(wx);
|
|
1073
|
+
const has = (key) => typeof wx[key] === "function";
|
|
1074
|
+
const webgl2 = options.probeContext ? Boolean(safe(() => {
|
|
1075
|
+
var _a;
|
|
1076
|
+
return (_a = options.probeContext) == null ? void 0 : _a.call(options, "webgl2");
|
|
1077
|
+
}, false)) : versionAtLeast(version, "2.20.0");
|
|
1078
|
+
const webgl1 = options.probeContext ? Boolean(safe(() => {
|
|
1079
|
+
var _a;
|
|
1080
|
+
return (_a = options.probeContext) == null ? void 0 : _a.call(options, "webgl");
|
|
1081
|
+
}, true)) : true;
|
|
1082
|
+
const caps = {
|
|
1083
|
+
platform,
|
|
1084
|
+
webgl2,
|
|
1085
|
+
webgl1,
|
|
1086
|
+
offscreenCanvas: has("createOffscreenCanvas"),
|
|
1087
|
+
worker: has("createWorker"),
|
|
1088
|
+
wasm: typeof globalThis.WXWebAssembly === "object" || typeof globalThis.WebAssembly === "object",
|
|
1089
|
+
brotliWasm: versionAtLeast(version, "2.14.0"),
|
|
1090
|
+
nativeImage: has("createImage") || has("createOffscreenCanvas"),
|
|
1091
|
+
triggerGC: has("triggerGC"),
|
|
1092
|
+
getWindowInfo: has("getWindowInfo"),
|
|
1093
|
+
windowResizeEvent: has("onWindowResize") && has("offWindowResize"),
|
|
1094
|
+
baseLibraryVersion: version
|
|
1095
|
+
};
|
|
1096
|
+
return { ...caps, ...options.overrides };
|
|
1097
|
+
}
|
|
1098
|
+
function versionAtLeast(actual, required) {
|
|
1099
|
+
var _a, _b;
|
|
1100
|
+
if (!actual) return true;
|
|
1101
|
+
const a = actual.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
1102
|
+
const b = required.split(".").map((n) => Number.parseInt(n, 10) || 0);
|
|
1103
|
+
for (let i = 0; i < Math.max(a.length, b.length); i++) {
|
|
1104
|
+
const x = (_a = a[i]) != null ? _a : 0;
|
|
1105
|
+
const y = (_b = b[i]) != null ? _b : 0;
|
|
1106
|
+
if (x > y) return true;
|
|
1107
|
+
if (x < y) return false;
|
|
1108
|
+
}
|
|
1109
|
+
return true;
|
|
1110
|
+
}
|
|
1111
|
+
|
|
1112
|
+
// src/core/image.ts
|
|
1113
|
+
var ShimImageData = class {
|
|
1114
|
+
constructor(widthOrData, heightOrWidth, height) {
|
|
1115
|
+
__publicField(this, "width");
|
|
1116
|
+
__publicField(this, "height");
|
|
1117
|
+
__publicField(this, "data");
|
|
1118
|
+
__publicField(this, "colorSpace", "srgb");
|
|
1119
|
+
if (typeof widthOrData === "number") {
|
|
1120
|
+
this.width = widthOrData;
|
|
1121
|
+
this.height = heightOrWidth != null ? heightOrWidth : widthOrData;
|
|
1122
|
+
this.data = new Uint8ClampedArray(this.width * this.height * 4);
|
|
1123
|
+
} else {
|
|
1124
|
+
this.data = widthOrData;
|
|
1125
|
+
this.width = heightOrWidth != null ? heightOrWidth : 0;
|
|
1126
|
+
this.height = height != null ? height : this.width ? this.data.length / (this.width * 4) : 0;
|
|
1127
|
+
}
|
|
1128
|
+
ImageDataShim.__instances.add(this);
|
|
1129
|
+
}
|
|
1130
|
+
};
|
|
1131
|
+
function findDescriptor(target, key) {
|
|
1132
|
+
let node = target;
|
|
1133
|
+
while (node) {
|
|
1134
|
+
const d = Object.getOwnPropertyDescriptor(node, key);
|
|
1135
|
+
if (d) return d;
|
|
1136
|
+
node = Object.getPrototypeOf(node);
|
|
1137
|
+
}
|
|
1138
|
+
return void 0;
|
|
1139
|
+
}
|
|
1140
|
+
function resolveSrc(src) {
|
|
1141
|
+
if (typeof src !== "string") return src;
|
|
1142
|
+
const resolved = MiniURL.resolveObjectURL(src);
|
|
1143
|
+
return resolved != null ? resolved : src;
|
|
1144
|
+
}
|
|
1145
|
+
function createImageFactory(wx, diagnostics) {
|
|
1146
|
+
const createRaw = () => {
|
|
1147
|
+
if (typeof wx.createImage === "function") return wx.createImage();
|
|
1148
|
+
if (typeof wx.createOffscreenCanvas === "function") {
|
|
1149
|
+
const off = wx.createOffscreenCanvas({ width: 1, height: 1, type: "2d" });
|
|
1150
|
+
if (typeof off.createImage === "function") return off.createImage();
|
|
1151
|
+
}
|
|
1152
|
+
throw new Error(
|
|
1153
|
+
"[mini-three-adapter] Neither wx.createImage nor OffscreenCanvas.createImage is available. Upgrade the WeChat base library or inject an `imageFactory` in options."
|
|
1154
|
+
);
|
|
1155
|
+
};
|
|
1156
|
+
const make = (width, height) => {
|
|
1157
|
+
const raw = createRaw();
|
|
1158
|
+
if (width != null) raw.width = width;
|
|
1159
|
+
if (height != null) raw.height = height;
|
|
1160
|
+
HTMLImageElementShim.__instances.add(raw);
|
|
1161
|
+
HTMLElementShim.__instances.add(raw);
|
|
1162
|
+
patchElement(raw, {
|
|
1163
|
+
rect: { width: raw.width || 0, height: raw.height || 0, left: 0, top: 0, right: raw.width || 0, bottom: raw.height || 0 },
|
|
1164
|
+
extra: {
|
|
1165
|
+
tagName: { value: "IMG" },
|
|
1166
|
+
nodeName: { value: "IMG" },
|
|
1167
|
+
nodeType: { value: 1 }
|
|
1168
|
+
}
|
|
1169
|
+
});
|
|
1170
|
+
const srcDescriptor = findDescriptor(raw, "src");
|
|
1171
|
+
let currentSrc = "";
|
|
1172
|
+
Object.defineProperty(raw, "src", {
|
|
1173
|
+
configurable: true,
|
|
1174
|
+
enumerable: true,
|
|
1175
|
+
get: () => (srcDescriptor == null ? void 0 : srcDescriptor.get) ? srcDescriptor.get.call(raw) : currentSrc,
|
|
1176
|
+
set: (value) => {
|
|
1177
|
+
const next = resolveSrc(String(value));
|
|
1178
|
+
currentSrc = next;
|
|
1179
|
+
if (srcDescriptor == null ? void 0 : srcDescriptor.set) srcDescriptor.set.call(raw, next);
|
|
1180
|
+
else if (!srcDescriptor) {
|
|
1181
|
+
diagnostics == null ? void 0 : diagnostics.warnOnce("image-no-src-setter", "wx image has no src setter; loading may not trigger");
|
|
1182
|
+
}
|
|
1183
|
+
}
|
|
1184
|
+
});
|
|
1185
|
+
const dispatch = (event) => {
|
|
1186
|
+
raw.dispatchEvent(event);
|
|
1187
|
+
};
|
|
1188
|
+
for (const [prop, eventName] of [["onload", "load"], ["onerror", "error"]]) {
|
|
1189
|
+
let handler;
|
|
1190
|
+
Object.defineProperty(raw, prop, {
|
|
1191
|
+
configurable: true,
|
|
1192
|
+
enumerable: true,
|
|
1193
|
+
get: () => handler,
|
|
1194
|
+
set: (next) => {
|
|
1195
|
+
handler = (e) => {
|
|
1196
|
+
dispatch(new MiniEvent(eventName));
|
|
1197
|
+
next == null ? void 0 : next(e);
|
|
1198
|
+
};
|
|
1199
|
+
}
|
|
1200
|
+
});
|
|
1201
|
+
}
|
|
1202
|
+
Object.defineProperty(raw, "crossOrigin", { value: "", writable: true, configurable: true });
|
|
1203
|
+
Object.defineProperty(raw, "decode", {
|
|
1204
|
+
value: () => new Promise((resolve, reject) => {
|
|
1205
|
+
if (raw.complete) return resolve();
|
|
1206
|
+
const previousLoad = raw.onload;
|
|
1207
|
+
const previousError = raw.onerror;
|
|
1208
|
+
raw.onload = () => {
|
|
1209
|
+
previousLoad == null ? void 0 : previousLoad();
|
|
1210
|
+
resolve();
|
|
1211
|
+
};
|
|
1212
|
+
raw.onerror = (e) => {
|
|
1213
|
+
previousError == null ? void 0 : previousError(e);
|
|
1214
|
+
reject(e);
|
|
1215
|
+
};
|
|
1216
|
+
}),
|
|
1217
|
+
configurable: true
|
|
1218
|
+
});
|
|
1219
|
+
return raw;
|
|
1220
|
+
};
|
|
1221
|
+
const ImageCtor = function(width, height) {
|
|
1222
|
+
return make(width, height);
|
|
1223
|
+
};
|
|
1224
|
+
Object.defineProperty(ImageCtor, "name", { value: "Image" });
|
|
1225
|
+
return {
|
|
1226
|
+
Image: ImageCtor,
|
|
1227
|
+
HTMLImageElement: HTMLImageElementShim,
|
|
1228
|
+
ImageData: ShimImageData,
|
|
1229
|
+
createImage: () => make(),
|
|
1230
|
+
createImageData: (width, height) => {
|
|
1231
|
+
var _a;
|
|
1232
|
+
const native = (_a = wx.createImageData) == null ? void 0 : _a.call(wx, width, height);
|
|
1233
|
+
if (native) {
|
|
1234
|
+
const obj = native;
|
|
1235
|
+
ImageDataShim.__instances.add(obj);
|
|
1236
|
+
return obj;
|
|
1237
|
+
}
|
|
1238
|
+
return new ShimImageData(width, height);
|
|
1239
|
+
},
|
|
1240
|
+
createImageBitmap: void 0
|
|
1241
|
+
};
|
|
1242
|
+
}
|
|
1243
|
+
|
|
1244
|
+
export { DOMRectShim, HTMLCanvasElementShim, HTMLElementShim, HTMLImageElementShim, ImageDataShim, OffscreenCanvasShim, PointerBridge, ShimDOMRect, ShimImageData, WebGL2RenderingContextShim, WebGLRenderingContextShim, capabilityReport, createDiagnostics, createDocument, createFrameScheduler, createImageFactory, createMockClass, createOffscreenCanvas, createRuntime, createScreen, createWindowInfoStore, currentScope, detectCapabilities, isMarked, markAs, normalizeRect, patchCanvas, patchElement, readWindowInfo, versionAtLeast };
|
|
1245
|
+
//# sourceMappingURL=chunk-3UGQWFH3.js.map
|
|
1246
|
+
//# sourceMappingURL=chunk-3UGQWFH3.js.map
|