mini-three-adapter 0.1.3 → 0.1.5
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 -85
- package/README.md +159 -159
- package/dist/build/rollup.js.map +1 -1
- package/dist/build/vite.js.map +1 -1
- package/dist/{chunk-34RWHAW4.js → chunk-35XVAVDB.js} +23 -5
- package/dist/chunk-35XVAVDB.js.map +1 -0
- package/dist/{chunk-52IMRKOX.js → chunk-F7CSLEUI.js} +3 -3
- package/dist/{chunk-52IMRKOX.js.map → chunk-F7CSLEUI.js.map} +1 -1
- package/dist/{chunk-WZ2HKYC5.js → chunk-LE4FRYNG.js} +4 -4
- package/dist/{chunk-WZ2HKYC5.js.map → chunk-LE4FRYNG.js.map} +1 -1
- package/dist/{chunk-OL7NVZZJ.js → chunk-VA7SZFLN.js} +21 -12
- package/dist/chunk-VA7SZFLN.js.map +1 -0
- package/dist/{chunk-3QUEDYTT.js → chunk-ZB3AYNOS.js} +19 -11
- package/dist/chunk-ZB3AYNOS.js.map +1 -0
- package/dist/{chunk-J7VBWZRR.js → chunk-ZFJLEEF4.js} +188 -45
- package/dist/chunk-ZFJLEEF4.js.map +1 -0
- package/dist/core/index.d.ts +3 -3
- package/dist/core/index.js +2 -2
- package/dist/index.d.ts +3 -3
- package/dist/index.js +6 -6
- package/dist/platforms/browser.d.ts +2 -2
- package/dist/platforms/browser.js +3 -3
- package/dist/platforms/wechat-game.d.ts +2 -2
- package/dist/platforms/wechat-game.js +4 -4
- package/dist/platforms/wechat-miniprogram.d.ts +2 -2
- package/dist/platforms/wechat-miniprogram.js +4 -4
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/{runtime-DnEkKZjo.d.ts → runtime-BrHExTjl.d.ts} +1 -1
- package/dist/scope.d.ts +8 -1
- package/dist/scope.js +1 -1
- package/dist/{wx-types-NMNyrsWO.d.ts → wx-types-BZTQ2jWG.d.ts} +17 -0
- package/docs/02-architecture.md +4 -4
- package/docs/03-module-map.md +99 -99
- package/docs/04-api-reference.md +304 -294
- package/docs/05-build-plugin.md +4 -2
- package/docs/06-platform-notes.md +44 -6
- package/docs/07-integration-guide.md +2 -2
- package/docs/09-testing-and-release.md +210 -209
- package/docs/10-ai-playbook.md +2 -1
- package/docs/11-compat-matrix.md +100 -96
- package/docs/adr/0007-capability-probe-fallback.md +8 -4
- package/docs/adr/0008-probe-fallback-boundary.md +56 -0
- package/docs/adr/0009-placeholder-scope-environment-globals.md +69 -0
- package/docs/adr/README.md +3 -1
- package/llms.txt +5 -2
- package/package.json +1 -1
- package/dist/chunk-34RWHAW4.js.map +0 -1
- package/dist/chunk-3QUEDYTT.js.map +0 -1
- package/dist/chunk-J7VBWZRR.js.map +0 -1
- package/dist/chunk-OL7NVZZJ.js.map +0 -1
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createImageFactory } from './chunk-
|
|
1
|
+
import { createImageFactory } from './chunk-ZFJLEEF4.js';
|
|
2
2
|
|
|
3
3
|
// src/platforms/wechat-common.ts
|
|
4
4
|
function createWechatImageFactory(wx, diagnostics) {
|
|
@@ -53,6 +53,12 @@ function watchWxVisibility(wx, handler) {
|
|
|
53
53
|
(_b2 = wx.offHide) == null ? void 0 : _b2.call(wx, onHide);
|
|
54
54
|
};
|
|
55
55
|
}
|
|
56
|
+
function isReserved(raw, reserved) {
|
|
57
|
+
for (const candidate of reserved) {
|
|
58
|
+
if (candidate != null && candidate === raw) return true;
|
|
59
|
+
}
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
56
62
|
function probeRawContext(raw, type) {
|
|
57
63
|
var _a, _b;
|
|
58
64
|
const ctx = raw.getContext(type);
|
|
@@ -62,6 +68,7 @@ function probeRawContext(raw, type) {
|
|
|
62
68
|
return true;
|
|
63
69
|
}
|
|
64
70
|
function probeContext(wx, type, options = {}) {
|
|
71
|
+
var _a;
|
|
65
72
|
let offscreen;
|
|
66
73
|
if (typeof wx.createOffscreenCanvas === "function") {
|
|
67
74
|
try {
|
|
@@ -71,16 +78,18 @@ function probeContext(wx, type, options = {}) {
|
|
|
71
78
|
}
|
|
72
79
|
}
|
|
73
80
|
if (offscreen === true) return true;
|
|
74
|
-
if (options.allowCanvasFallback
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
if (!options.allowCanvasFallback) return offscreen;
|
|
82
|
+
if (typeof wx.createOffscreenCanvas !== "function") {
|
|
83
|
+
return void 0;
|
|
84
|
+
}
|
|
85
|
+
if (typeof wx.createCanvas !== "function") return void 0;
|
|
86
|
+
try {
|
|
87
|
+
const raw = wx.createCanvas();
|
|
88
|
+
if (isReserved(raw, (_a = options.reservedCanvases) != null ? _a : [])) return void 0;
|
|
89
|
+
return probeRawContext(raw, type);
|
|
90
|
+
} catch {
|
|
91
|
+
return void 0;
|
|
82
92
|
}
|
|
83
|
-
return offscreen;
|
|
84
93
|
}
|
|
85
94
|
function createOffscreenCanvasRaw(wx, width, height, type, diagnostics) {
|
|
86
95
|
if (typeof wx.createOffscreenCanvas === "function") {
|
|
@@ -143,5 +152,5 @@ function resolveWx(injected) {
|
|
|
143
152
|
}
|
|
144
153
|
|
|
145
154
|
export { createNow, createOffscreenCanvasRaw, createRafPair, createWechatImageFactory, probeContext, rectFromSelectorResult, rectFromWindowInfo, resolveWx, watchWxTouch, watchWxVisibility };
|
|
146
|
-
//# sourceMappingURL=chunk-
|
|
147
|
-
//# sourceMappingURL=chunk-
|
|
155
|
+
//# sourceMappingURL=chunk-VA7SZFLN.js.map
|
|
156
|
+
//# sourceMappingURL=chunk-VA7SZFLN.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platforms/wechat-common.ts","../src/platforms/wx-types.ts"],"names":["_a","_b","raw"],"mappings":";;;AAMO,SAAS,wBAAA,CAAyB,IAAY,WAAA,EAAyC;AAC5F,EAAA,OAAO,kBAAA,CAAmB,IAAI,WA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A,IAC9B,MAAA,EAAA,CAAQ,EAAA,GAAA,MAAA,CAAO,MAAA,KAAP,IAAA,GAAA,EAAA,GAAiB,GAAA,GAAM;AAAA,GACjC;AACF;;;ACvDO,SAAS,UAAU,QAAA,EAA2B;AACnD,EAAA,IAAI,UAAU,OAAO,QAAA;AACrB,EAAA,MAAM,IAAA,GAAO,UAAA;AACb,EAAA,MAAM,KAAK,IAAA,CAAK,EAAA;AAChB,EAAA,IAAI,CAAC,EAAA,EAAI;AACP,IAAA,MAAM,IAAI,KAAA;AAAA,MACR;AAAA,KACF;AAAA,EACF;AACA,EAAA,OAAO,EAAA;AACT","file":"chunk-VA7SZFLN.js","sourcesContent":["/** Shared WeChat plumbing used by both mini game and mini program bindings. */\nimport type { ContextType, Disposer, Rect, TouchLikeEvent } from '../types';\nimport type { WxCanvas, WxLike, WxTouchEvent } from './wx-types';\nimport { createImageFactory, type ImageFactory } from '../core/image';\nimport type { Diagnostics } from '../core/diagnostics';\n\nexport function createWechatImageFactory(wx: WxLike, diagnostics?: Diagnostics): ImageFactory {\n return createImageFactory(wx, diagnostics);\n}\n\n/** rAF comes from the global in mini games, from the canvas node in mini programs. */\nexport function createRafPair(\n wx: WxLike,\n canvas?: WxCanvas,\n): { request(cb: (time: number) => void): number; cancel(id: number): void } {\n const host = globalThis as unknown as {\n requestAnimationFrame?: (cb: (time: number) => void) => number;\n cancelAnimationFrame?: (id: number) => void;\n };\n const canvasRaf = canvas?.requestAnimationFrame?.bind(canvas);\n const canvasCaf = canvas?.cancelAnimationFrame?.bind(canvas);\n const request = canvasRaf ?? host.requestAnimationFrame?.bind(host) ??\n ((cb: (time: number) => void) => setTimeout(() => cb(Date.now()), 16) as unknown as number);\n const cancel = canvasCaf ?? host.cancelAnimationFrame?.bind(host) ??\n ((id: number) => clearTimeout(id as unknown as ReturnType<typeof setTimeout>));\n void wx;\n return { request, cancel };\n}\n\nexport function createNow(wx: WxLike): () => number {\n const perf = wx.getPerformance?.();\n if (perf && typeof perf.now === 'function') return () => perf.now();\n const host = globalThis as unknown as { performance?: { now(): number } };\n const hostPerf = host.performance;\n if (hostPerf && typeof hostPerf.now === 'function') return () => hostPerf.now();\n const start = Date.now();\n return () => Date.now() - start;\n}\n\n/** Subscribe to mini game touch events. Mini programs use WXML bindings instead. */\nexport function watchWxTouch(wx: WxLike, handler: (event: TouchLikeEvent) => void): Disposer {\n const methods = ['onTouchStart', 'onTouchMove', 'onTouchEnd', 'onTouchCancel'] as const;\n const offs = ['offTouchStart', 'offTouchMove', 'offTouchEnd', 'offTouchCancel'] as const;\n const attached: Array<[string, (event: WxTouchEvent) => void]> = [];\n methods.forEach((name, index) => {\n const attach = wx[name];\n if (typeof attach !== 'function') return;\n const listener = (event: WxTouchEvent): void => handler(event as TouchLikeEvent);\n attach.call(wx, listener);\n attached.push([offs[index] as string, listener]);\n });\n return () => {\n for (const [off, listener] of attached) {\n const fn = (wx as Record<string, unknown>)[off];\n if (typeof fn === 'function') (fn as (l: unknown) => void).call(wx, listener);\n }\n };\n}\n\nexport function watchWxVisibility(wx: WxLike, handler: (visible: boolean) => void): Disposer {\n const onShow = (): void => handler(true);\n const onHide = (): void => handler(false);\n wx.onShow?.(onShow);\n wx.onHide?.(onHide);\n return () => {\n wx.offShow?.(onShow);\n wx.offHide?.(onHide);\n };\n}\n\nexport interface ProbeContextOptions {\n /**\n * Allow falling back to a second `wx.createCanvas()` when the offscreen probe\n * answers \"no\". Only callers that already resolved the on-screen canvas may\n * opt in, and only when `createOffscreenCanvas` exists at all (see ADR-0007\n * and ADR-0008).\n */\n allowCanvasFallback?: boolean;\n /**\n * Every object that could be the on-screen canvas on this device: the canvas\n * in use, the one the host seeded through `GameGlobal.screencanvas`, and\n * `globalThis.canvas` (weapp-adapter style).\n *\n * WeChat returns the *on-screen* canvas from the first `createCanvas()` call.\n * A host that seeded the canvas never consumes that first call, so the\n * fallback below can receive the screen canvas back — or a *different*\n * pre-seeded canvas when the host also passed `canvas` explicitly. Probing\n * any of them creates a context and then destroys it with\n * `WEBGL_lose_context`: a black screen with no error. Identity is the only\n * reliable judgement, so the whole candidate set is passed in.\n */\n reservedCanvases?: readonly (WxCanvas | null | undefined)[];\n}\n\n/** Identity check against every known on-screen canvas candidate. */\nfunction isReserved(raw: WxCanvas, reserved: readonly (WxCanvas | null | undefined)[]): boolean {\n for (const candidate of reserved) {\n if (candidate != null && candidate === raw) return true;\n }\n return false;\n}\n\n/** Try one canvas; returns `false` when the context is simply unavailable. */\nfunction probeRawContext(raw: WxCanvas, type: ContextType): boolean {\n const ctx = raw.getContext(type);\n if (!ctx) return false;\n // Release GPU resources as soon as possible on constrained devices.\n const lose = (ctx as { getExtension?: (name: string) => { loseContext?: () => void } | null }).getExtension;\n lose?.call(ctx, 'WEBGL_lose_context')?.loseContext?.();\n return true;\n}\n\n/**\n * WebGL2 / WebGL1 capability probe.\n *\n * The offscreen canvas is preferred because it has no side effects on the\n * on-screen canvas. But offscreen support is NOT the same capability as\n * on-screen support: a base library can render WebGL2 on the screen canvas while\n * `createOffscreenCanvas` is missing or cannot create a WebGL2 context. So when\n * the offscreen answer is negative and the caller allows it, we ask the real\n * canvas type as well.\n *\n * Returns `undefined` when the host cannot answer — callers must treat that as\n * \"unknown\", never as \"unsupported\".\n */\nexport function probeContext(\n wx: WxLike,\n type: ContextType,\n options: ProbeContextOptions = {},\n): boolean | undefined {\n let offscreen: boolean | undefined;\n if (typeof wx.createOffscreenCanvas === 'function') {\n try {\n offscreen = probeRawContext(wx.createOffscreenCanvas({ width: 1, height: 1, type }), type);\n } catch {\n // Some base libraries expose the API but throw for webgl2; keep probing.\n offscreen = undefined;\n }\n }\n if (offscreen === true) return true;\n if (!options.allowCanvasFallback) return offscreen;\n if (typeof wx.createOffscreenCanvas !== 'function') {\n // No offscreen API at all: nothing tells us whether the first\n // `createCanvas()` was already consumed, so the fallback turns into a coin\n // flip whose losing side is a destroyed screen context. Report \"unknown\"\n // and let the caller infer from the base library version instead.\n return undefined;\n }\n if (typeof wx.createCanvas !== 'function') return undefined;\n try {\n const raw = wx.createCanvas();\n // Identity check, not a heuristic: the screen canvas must never be probed,\n // because probing creates a context and then loses it.\n if (isReserved(raw, options.reservedCanvases ?? [])) return undefined;\n return probeRawContext(raw, type);\n } catch {\n return undefined;\n }\n}\n\nexport function createOffscreenCanvasRaw(\n wx: WxLike,\n width: number,\n height: number,\n type: ContextType,\n diagnostics?: Diagnostics,\n): WxCanvas {\n if (typeof wx.createOffscreenCanvas === 'function') {\n try {\n const raw = wx.createOffscreenCanvas({ width, height, type });\n raw.width = width;\n raw.height = height;\n return raw;\n } catch (error) {\n diagnostics?.warn(`createOffscreenCanvas(${type}) failed, falling back to 2d`, error);\n }\n }\n // Last resort for old base libraries: createCanvas() after the first call is\n // guaranteed to be off-screen, but it still counts against the canvas budget.\n if (typeof wx.createCanvas !== 'function') {\n throw new Error('[mini-three-adapter] no canvas creation API available');\n }\n const raw = wx.createCanvas();\n raw.width = width;\n raw.height = height;\n return raw;\n}\n\nexport function rectFromWindowInfo(wx: WxLike): Rect {\n const info = wx.getWindowInfo?.() ?? wx.getSystemInfoSync?.() ??\n { windowWidth: 0, windowHeight: 0, pixelRatio: 1 };\n return {\n left: 0,\n top: 0,\n width: info.windowWidth,\n height: info.windowHeight,\n right: info.windowWidth,\n bottom: info.windowHeight,\n };\n}\n\nexport function rectFromSelectorResult(result: {\n width?: number; height?: number; top?: number; left?: number; right?: number; bottom?: number;\n}): Rect {\n const width = result.width ?? 0;\n const height = result.height ?? 0;\n const left = result.left ?? 0;\n const top = result.top ?? 0;\n return {\n width, height, left, top,\n right: result.right ?? left + width,\n bottom: result.bottom ?? top + height,\n };\n}\n","/**\n * Hand-written, minimal structural types for the WeChat runtime.\n *\n * Why not `minigame-api-typings`? Because consuming the official typings forces\n * a global `wx` declaration onto every consumer (including browser builds and\n * Node tests) and couples us to a specific version. Structural interfaces let\n * the adapter work with a real `wx`, a mock in tests, or a future platform.\n */\n\nexport interface WxCanvas {\n width: number;\n height: number;\n getContext(type: string, attributes?: Record<string, unknown>): unknown;\n toDataURL?(type?: string, quality?: number): string;\n createImage?(): WxImage;\n requestAnimationFrame?(callback: (time: number) => void): number;\n cancelAnimationFrame?(id: number): void;\n [key: string]: unknown;\n}\n\nexport interface WxImage {\n width: number;\n height: number;\n src: string;\n onload?: ((event?: unknown) => void) | null;\n onerror?: ((error?: unknown) => void) | null;\n complete?: boolean;\n [key: string]: unknown;\n}\n\nexport interface WxImageInfo {\n width: number;\n height: number;\n path?: string;\n type?: string;\n orientation?: string;\n}\n\nexport interface WxGetImageInfoOptions {\n src: string;\n success?: (info: WxImageInfo) => void;\n fail?: (error: { errMsg?: string; [key: string]: unknown }) => void;\n}\n\nexport interface WxRect {\n top: number;\n left: number;\n width: number;\n height: number;\n right: number;\n bottom: number;\n}\n\nexport interface WxWindowInfo {\n windowWidth: number;\n windowHeight: number;\n pixelRatio: number;\n screenWidth?: number;\n screenHeight?: number;\n safeArea?: WxRect;\n}\n\nexport interface WxTouchPoint {\n identifier?: number;\n clientX?: number;\n clientY?: number;\n pageX?: number;\n pageY?: number;\n x?: number;\n y?: number;\n force?: number;\n}\n\nexport interface WxTouchEvent {\n type: string;\n touches?: ArrayLike<WxTouchPoint>;\n changedTouches?: ArrayLike<WxTouchPoint>;\n timeStamp?: number;\n}\n\nexport interface WxRequestResult {\n statusCode: number;\n data: string | ArrayBuffer | Record<string, unknown>;\n header?: Record<string, string>;\n errMsg?: string;\n}\n\nexport interface WxRequestOptions {\n url: string;\n method?: string;\n data?: unknown;\n header?: Record<string, string>;\n responseType?: 'text' | 'arraybuffer';\n timeout?: number;\n success?: (result: WxRequestResult) => void;\n fail?: (error: { errMsg?: string; [key: string]: unknown }) => void;\n}\n\nexport interface WxSelectorQueryResult {\n node?: WxCanvas;\n width?: number;\n height?: number;\n top?: number;\n left?: number;\n right?: number;\n bottom?: number;\n}\n\nexport interface WxSelectorQuery {\n select(selector: string): WxSelectorQuery;\n fields(fields: Record<string, boolean>): WxSelectorQuery;\n exec(callback: (results: (WxSelectorQueryResult | null)[]) => void): void;\n}\n\n/** The subset of `wx` the adapter touches. All members are optional so the\n * same interface can describe a mini game, a mini program or a test mock. */\nexport interface WxLike {\n createCanvas?(): WxCanvas;\n createOffscreenCanvas?(options?: {\n width?: number;\n height?: number;\n type?: '2d' | 'webgl' | 'webgl2';\n }): WxCanvas;\n createImage?(): WxImage;\n createImageData?(width: number, height: number): unknown;\n /** Metadata-only decode: proves an asset is readable without loading it. */\n getImageInfo?(options: WxGetImageInfoOptions): void;\n getWindowInfo?(): WxWindowInfo;\n getSystemInfoSync?(): WxWindowInfo;\n onWindowResize?(listener: (res: { windowWidth: number; windowHeight: number }) => void): void;\n offWindowResize?(listener: (res: { windowWidth: number; windowHeight: number }) => void): void;\n\n onTouchStart?(listener: (event: WxTouchEvent) => void): void;\n onTouchMove?(listener: (event: WxTouchEvent) => void): void;\n onTouchEnd?(listener: (event: WxTouchEvent) => void): void;\n onTouchCancel?(listener: (event: WxTouchEvent) => void): void;\n offTouchStart?(listener: (event: WxTouchEvent) => void): void;\n offTouchMove?(listener: (event: WxTouchEvent) => void): void;\n offTouchEnd?(listener: (event: WxTouchEvent) => void): void;\n offTouchCancel?(listener: (event: WxTouchEvent) => void): void;\n\n onShow?(listener: () => void): void;\n onHide?(listener: () => void): void;\n offShow?(listener: () => void): void;\n offHide?(listener: () => void): void;\n\n request?(options: WxRequestOptions): { abort?(): void };\n createSelectorQuery?(): WxSelectorQuery;\n getPerformance?(): { now(): number };\n setPreferredFramesPerSecond?(fps: number): void;\n triggerGC?(): void;\n createWorker?(path: string, options?: unknown): unknown;\n env?: { USER_DATA_PATH?: string; [key: string]: unknown };\n getSystemInfo?(options: { success?: (info: WxWindowInfo & { SDKVersion?: string }) => void }): void;\n [key: string]: unknown;\n}\n\n/** Resolve `wx` from an explicit injection or from the host global. */\nexport function resolveWx(injected?: WxLike): WxLike {\n if (injected) return injected;\n const host = globalThis as unknown as Record<string, unknown>;\n const wx = host.wx as WxLike | undefined;\n if (!wx) {\n throw new Error(\n '[mini-three-adapter] `wx` is not available. Pass `{ wx }` in options when running outside WeChat (e.g. in Node tests).',\n );\n }\n return wx;\n}\n"]}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { resolveWx, probeContext, createWechatImageFactory, createRafPair, createNow, watchWxVisibility, watchWxTouch, createOffscreenCanvasRaw, rectFromWindowInfo } from './chunk-
|
|
2
|
-
import { createDiagnostics, detectCapabilities, createRuntime } from './chunk-
|
|
1
|
+
import { resolveWx, probeContext, createWechatImageFactory, createRafPair, createNow, watchWxVisibility, watchWxTouch, createOffscreenCanvasRaw, rectFromWindowInfo } from './chunk-VA7SZFLN.js';
|
|
2
|
+
import { createDiagnostics, detectCapabilities, createRuntime } from './chunk-ZFJLEEF4.js';
|
|
3
3
|
|
|
4
4
|
// src/platforms/wechat-game.ts
|
|
5
5
|
var cachedScreenCanvas = null;
|
|
@@ -23,21 +23,29 @@ function getScreenCanvas(wx, supplied) {
|
|
|
23
23
|
function resetScreenCanvasCache() {
|
|
24
24
|
cachedScreenCanvas = null;
|
|
25
25
|
}
|
|
26
|
+
function screenCanvasCandidates(supplied) {
|
|
27
|
+
const host = globalThis;
|
|
28
|
+
const gameGlobal = host.GameGlobal;
|
|
29
|
+
const sources = [supplied, cachedScreenCanvas, gameGlobal == null ? void 0 : gameGlobal.screencanvas, host.canvas];
|
|
30
|
+
const candidates = [];
|
|
31
|
+
for (const source of sources) {
|
|
32
|
+
if (!source) continue;
|
|
33
|
+
const canvas = source;
|
|
34
|
+
if (typeof canvas.getContext !== "function") continue;
|
|
35
|
+
if (!candidates.includes(canvas)) candidates.push(canvas);
|
|
36
|
+
}
|
|
37
|
+
return candidates;
|
|
38
|
+
}
|
|
26
39
|
function createWeChatGameBinding(options = {}) {
|
|
27
40
|
var _a;
|
|
28
41
|
const wx = resolveWx(options.wx);
|
|
29
42
|
const diagnostics = (_a = options.diagnostics) != null ? _a : createDiagnostics("warn");
|
|
30
43
|
const rawCanvas = getScreenCanvas(wx, options.canvas);
|
|
44
|
+
const reservedCanvases = screenCanvasCandidates(rawCanvas);
|
|
31
45
|
const capabilities = detectCapabilities(wx, "wechat-game", {
|
|
32
46
|
overrides: options.capabilities,
|
|
33
47
|
diagnostics,
|
|
34
|
-
|
|
35
|
-
// createCanvas() is guaranteed to be off-screen and safe to probe — except
|
|
36
|
-
// when the host seeded `GameGlobal.screencanvas`: then the first call was
|
|
37
|
-
// never consumed and can still hand the screen canvas back. Passing it in
|
|
38
|
-
// lets `probeContext` refuse that object by identity instead of creating
|
|
39
|
-
// and immediately losing its context.
|
|
40
|
-
probeContext: (type) => probeContext(wx, type, { allowCanvasFallback: true, screenCanvas: rawCanvas })
|
|
48
|
+
probeContext: (type) => probeContext(wx, type, { allowCanvasFallback: true, reservedCanvases })
|
|
41
49
|
});
|
|
42
50
|
const imageFactory = createWechatImageFactory(wx, diagnostics);
|
|
43
51
|
const raf = createRafPair(wx, rawCanvas);
|
|
@@ -69,5 +77,5 @@ function createWeChatGameRuntime(options = {}) {
|
|
|
69
77
|
}
|
|
70
78
|
|
|
71
79
|
export { createWeChatGameBinding, createWeChatGameRuntime, getScreenCanvas, resetScreenCanvasCache };
|
|
72
|
-
//# sourceMappingURL=chunk-
|
|
73
|
-
//# sourceMappingURL=chunk-
|
|
80
|
+
//# sourceMappingURL=chunk-ZB3AYNOS.js.map
|
|
81
|
+
//# sourceMappingURL=chunk-ZB3AYNOS.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/platforms/wechat-game.ts"],"names":[],"mappings":";;;;AAiCA,IAAI,kBAAA,GAAsC,IAAA;AAGnC,SAAS,eAAA,CAAgB,IAAY,QAAA,EAA+B;AApC3E,EAAA,IAAA,EAAA;AAqCE,EAAA,IAAI,UAAU,OAAO,QAAA;AACrB,EAAA,IAAI,oBAAoB,OAAO,kBAAA;AAC/B,EAAA,MAAM,IAAA,GAAO,UAAA;AACb,EAAA,MAAM,aAAa,IA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A,EAAM,WAAW,CAAA;AAAA,IAC/D,UAAA,EAAY,CAAC,OAAA,KAAuD,YAAA,CAAa,IAAI,OAAO,CAAA;AAAA,IAC5F,eAAA,EAAiB,CAAC,OAAA,KAAY,iBAAA,CAAkB,IAAI,OAAO,CAAA;AAAA,IAC3D,uBAAuB,GAAA,CAAI,OAAA;AAAA,IAC3B,sBAAsB,GAAA,CAAI,MAAA;AAAA,IAC1B,GAAA;AAAA,IACA,SAAS,MAAM;AAEb,MAAA,WAAA,CAAY,MAAM,8BAA8B,CAAA;AAAA,IAClD;AAAA,GACF;AACF;AAKO,SAAS,uBAAA,CACd,OAAA,GAAoC,EAAC,EACV;AAC3B,EAAA,OAAO,aAAA,CAAc,MAAM,uBAAA,CAAwB,OAAO,GAAG,OAAO,CAAA;AACtE","file":"chunk-ZB3AYNOS.js","sourcesContent":["/** WeChat Mini Game (小游戏) platform binding. */\nimport type { Capabilities, ContextType, Disposer, Rect, TouchLikeEvent } from '../types';\nimport type { PlatformBinding } from '../core/platform';\nimport { createRuntime, type MiniThreeRuntime, type RuntimeOptions } from '../core/runtime';\nimport { detectCapabilities } from '../core/capabilities';\nimport { createDiagnostics, type Diagnostics } from '../core/diagnostics';\nimport {\n createNow,\n createOffscreenCanvasRaw,\n createRafPair,\n createWechatImageFactory,\n probeContext,\n rectFromWindowInfo,\n watchWxTouch,\n watchWxVisibility,\n} from './wechat-common';\nimport { resolveWx, type WxCanvas, type WxLike } from './wx-types';\n\nexport interface WeChatGameOptions {\n /** Inject a `wx` mock (tests / non-WeChat hosts). */\n wx?: WxLike;\n /**\n * Reuse an existing on-screen canvas. If omitted, the adapter checks\n * `GameGlobal.screencanvas`, `globalThis.canvas` (weapp-adapter) and finally\n * calls `wx.createCanvas()` exactly once.\n */\n canvas?: WxCanvas;\n capabilities?: Partial<Capabilities>;\n diagnostics?: Diagnostics;\n /** Call wx.setPreferredFramesPerSecond(fps) when supported. */\n preferredFps?: number;\n}\n\nlet cachedScreenCanvas: WxCanvas | null = null;\n\n/** Resolve (and memoize) the single on-screen canvas. */\nexport function getScreenCanvas(wx: WxLike, supplied?: WxCanvas): WxCanvas {\n if (supplied) return supplied;\n if (cachedScreenCanvas) return cachedScreenCanvas;\n const host = globalThis as unknown as Record<string, unknown>;\n const gameGlobal = host.GameGlobal as Record<string, unknown> | undefined;\n const existing = (gameGlobal?.screencanvas ?? host.canvas) as WxCanvas | undefined;\n if (existing && typeof existing.getContext === 'function') {\n cachedScreenCanvas = existing;\n return existing;\n }\n if (typeof wx.createCanvas !== 'function') {\n throw new Error('[mini-three-adapter] wx.createCanvas is missing: this is not a WeChat Mini Game runtime');\n }\n cachedScreenCanvas = wx.createCanvas();\n return cachedScreenCanvas;\n}\n\n/** Only for tests: forget the memoized screen canvas. */\nexport function resetScreenCanvasCache(): void {\n cachedScreenCanvas = null;\n}\n\n/**\n * Every object that may be the on-screen canvas on this device.\n *\n * It is NOT enough to compare against the canvas in use: a host that seeds\n * `GameGlobal.screencanvas` and *also* passes `canvas` explicitly makes the\n * `supplied` path skip the memo, so the seeded canvas stays unknown to the\n * probe — and that is exactly the object `createCanvas()` hands back. Collect\n * all four sources so the identity guard cannot be fooled by the entry point\n * (ADR-0008).\n */\nfunction screenCanvasCandidates(supplied?: WxCanvas): WxCanvas[] {\n const host = globalThis as unknown as Record<string, unknown>;\n const gameGlobal = host.GameGlobal as Record<string, unknown> | undefined;\n const sources: unknown[] = [supplied, cachedScreenCanvas, gameGlobal?.screencanvas, host.canvas];\n const candidates: WxCanvas[] = [];\n for (const source of sources) {\n if (!source) continue;\n const canvas = source as WxCanvas;\n if (typeof canvas.getContext !== 'function') continue;\n if (!candidates.includes(canvas)) candidates.push(canvas);\n }\n return candidates;\n}\n\nexport function createWeChatGameBinding(options: WeChatGameOptions = {}): PlatformBinding {\n const wx = resolveWx(options.wx);\n const diagnostics = options.diagnostics ?? createDiagnostics('warn');\n const rawCanvas = getScreenCanvas(wx, options.canvas);\n // The on-screen canvas is already resolved above, so a second createCanvas()\n // is *usually* off-screen. The exception is a host that seeded the canvas:\n // then the first call was never consumed and can still hand the screen canvas\n // back. Passing every candidate lets `probeContext` refuse those objects by\n // identity instead of creating and immediately losing their context.\n const reservedCanvases = screenCanvasCandidates(rawCanvas);\n const capabilities = detectCapabilities(wx, 'wechat-game', {\n overrides: options.capabilities,\n diagnostics,\n probeContext: (type) =>\n probeContext(wx, type, { allowCanvasFallback: true, reservedCanvases }),\n });\n const imageFactory = createWechatImageFactory(wx, diagnostics);\n const raf = createRafPair(wx, rawCanvas);\n const now = createNow(wx);\n\n if (options.preferredFps && typeof wx.setPreferredFramesPerSecond === 'function') {\n wx.setPreferredFramesPerSecond(options.preferredFps);\n }\n\n const getCanvasRect = (): Rect => rectFromWindowInfo(wx);\n\n return {\n kind: 'wechat-game',\n wx,\n rawCanvas,\n capabilities,\n imageFactory,\n getCanvasRect,\n createOffscreenCanvas: (width: number, height: number, type: ContextType) =>\n createOffscreenCanvasRaw(wx, width, height, type, diagnostics),\n watchTouch: (handler: (event: TouchLikeEvent) => void): Disposer => watchWxTouch(wx, handler),\n watchVisibility: (handler) => watchWxVisibility(wx, handler),\n requestAnimationFrame: raf.request,\n cancelAnimationFrame: raf.cancel,\n now,\n dispose: () => {\n // The on-screen canvas belongs to the game; never destroy it here.\n diagnostics.debug('wechat-game binding disposed');\n },\n };\n}\n\nexport type WeChatGameRuntimeOptions = WeChatGameOptions & RuntimeOptions;\n\n/** One-line bootstrap for mini games. */\nexport function createWeChatGameRuntime(\n options: WeChatGameRuntimeOptions = {},\n): Promise<MiniThreeRuntime> {\n return createRuntime(() => createWeChatGameBinding(options), options);\n}\n"]}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createScope, setActiveScope, hasActiveScope, getActiveScope, installGlobals } from './chunk-
|
|
1
|
+
import { createScope, setActiveScope, getEarlyScopeReads, clearEarlyScopeReads, hasActiveScope, getActiveScope, installGlobals } from './chunk-35XVAVDB.js';
|
|
2
2
|
import { patchEventTarget, MiniEventTarget, MiniMouseEvent, MiniPointerEvent, atob, btoa, MiniEvent, MiniCustomEvent, MiniMessageEvent, MiniProgressEvent, MiniDOMException, MiniBlob, MiniURL, MiniTextDecoder, MiniTextEncoder, MiniAbortController, MiniAbortSignal, createFetch, createXMLHttpRequestFactory } from './chunk-LCJNTN6F.js';
|
|
3
3
|
import { __publicField } from './chunk-V6TY7KAL.js';
|
|
4
4
|
|
|
@@ -973,6 +973,14 @@ async function createRuntime(platform, options = {}) {
|
|
|
973
973
|
});
|
|
974
974
|
const restoreScope = setActiveScope(scope);
|
|
975
975
|
disposers.push(restoreScope);
|
|
976
|
+
const earlyReads = getEarlyScopeReads();
|
|
977
|
+
if (earlyReads.length > 0) {
|
|
978
|
+
clearEarlyScopeReads();
|
|
979
|
+
diagnostics.warnOnce(
|
|
980
|
+
"early-scope-read",
|
|
981
|
+
`Scoped globals were read before this runtime existed: ${earlyReads.join(", ")}. Those reads returned undefined, so feature detection saw a non-browser host. Await createXxxRuntime() before importing three.js (dynamic import), or call installGlobals() first.`
|
|
982
|
+
);
|
|
983
|
+
}
|
|
976
984
|
const runtime = {
|
|
977
985
|
canvas,
|
|
978
986
|
scope,
|
|
@@ -1162,6 +1170,33 @@ function resolveSrc(src) {
|
|
|
1162
1170
|
const resolved = MiniURL.resolveObjectURL(src);
|
|
1163
1171
|
return resolved != null ? resolved : src;
|
|
1164
1172
|
}
|
|
1173
|
+
function callable(target, key) {
|
|
1174
|
+
let value;
|
|
1175
|
+
try {
|
|
1176
|
+
value = target[key];
|
|
1177
|
+
} catch {
|
|
1178
|
+
return void 0;
|
|
1179
|
+
}
|
|
1180
|
+
if (typeof value !== "function") return void 0;
|
|
1181
|
+
try {
|
|
1182
|
+
return value.bind(target);
|
|
1183
|
+
} catch {
|
|
1184
|
+
return void 0;
|
|
1185
|
+
}
|
|
1186
|
+
}
|
|
1187
|
+
function ownPropertyNames(target) {
|
|
1188
|
+
try {
|
|
1189
|
+
return Object.getOwnPropertyNames(target).slice(0, 16);
|
|
1190
|
+
} catch {
|
|
1191
|
+
return [];
|
|
1192
|
+
}
|
|
1193
|
+
}
|
|
1194
|
+
function describeSlot(descriptor) {
|
|
1195
|
+
if (!descriptor) return "missing";
|
|
1196
|
+
if (typeof descriptor.set === "function") return "accessor";
|
|
1197
|
+
return descriptor.writable ? "data" : "data-readonly";
|
|
1198
|
+
}
|
|
1199
|
+
var EVENT_WATCHDOG_MS = 2e3;
|
|
1165
1200
|
function createImageFactory(wx, diagnostics) {
|
|
1166
1201
|
const createRaw = () => {
|
|
1167
1202
|
if (typeof wx.createImage === "function") return wx.createImage();
|
|
@@ -1179,6 +1214,16 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1179
1214
|
if (height != null) raw.height = height;
|
|
1180
1215
|
const nativeLoad = findDescriptor(raw, "onload");
|
|
1181
1216
|
const nativeError = findDescriptor(raw, "onerror");
|
|
1217
|
+
const nativeComplete = findDescriptor(raw, "complete");
|
|
1218
|
+
const nativeAdd = callable(raw, "addEventListener");
|
|
1219
|
+
const hostShape = {
|
|
1220
|
+
onload: describeSlot(nativeLoad),
|
|
1221
|
+
onerror: describeSlot(nativeError),
|
|
1222
|
+
addEventListener: nativeAdd ? "native" : "missing",
|
|
1223
|
+
complete: nativeComplete ? "native" : "missing",
|
|
1224
|
+
getImageInfo: typeof wx.getImageInfo === "function" ? "available" : "missing",
|
|
1225
|
+
ownNames: ownPropertyNames(raw)
|
|
1226
|
+
};
|
|
1182
1227
|
HTMLImageElementShim.__instances.add(raw);
|
|
1183
1228
|
HTMLElementShim.__instances.add(raw);
|
|
1184
1229
|
patchElement(raw, {
|
|
@@ -1191,52 +1236,99 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1191
1236
|
});
|
|
1192
1237
|
const srcDescriptor = findDescriptor(raw, "src");
|
|
1193
1238
|
let currentSrc = "";
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1239
|
+
let onSrcChange;
|
|
1240
|
+
const writeNativeSrc = (next) => {
|
|
1241
|
+
if (srcDescriptor == null ? void 0 : srcDescriptor.set) {
|
|
1242
|
+
srcDescriptor.set.call(raw, next);
|
|
1243
|
+
return;
|
|
1244
|
+
}
|
|
1245
|
+
if (srcDescriptor && srcDescriptor.writable === true) {
|
|
1246
|
+
try {
|
|
1247
|
+
Object.defineProperty(raw, "src", srcDescriptor);
|
|
1248
|
+
raw.src = next;
|
|
1249
|
+
} finally {
|
|
1250
|
+
installSrcAccessor();
|
|
1204
1251
|
}
|
|
1252
|
+
return;
|
|
1205
1253
|
}
|
|
1206
|
-
|
|
1254
|
+
diagnostics == null ? void 0 : diagnostics.warnOnce(
|
|
1255
|
+
"image-no-src-setter",
|
|
1256
|
+
"wx image exposes no writable src; the host will never start loading and textures will fail",
|
|
1257
|
+
{ src: next }
|
|
1258
|
+
);
|
|
1259
|
+
};
|
|
1260
|
+
const installSrcAccessor = () => {
|
|
1261
|
+
try {
|
|
1262
|
+
Object.defineProperty(raw, "src", {
|
|
1263
|
+
configurable: true,
|
|
1264
|
+
enumerable: true,
|
|
1265
|
+
get: () => (srcDescriptor == null ? void 0 : srcDescriptor.get) ? srcDescriptor.get.call(raw) : currentSrc,
|
|
1266
|
+
set: (value) => {
|
|
1267
|
+
const next = resolveSrc(String(value));
|
|
1268
|
+
currentSrc = next;
|
|
1269
|
+
writeNativeSrc(next);
|
|
1270
|
+
onSrcChange == null ? void 0 : onSrcChange(next);
|
|
1271
|
+
}
|
|
1272
|
+
});
|
|
1273
|
+
} catch {
|
|
1274
|
+
}
|
|
1275
|
+
};
|
|
1276
|
+
installSrcAccessor();
|
|
1207
1277
|
const handlers = {
|
|
1208
1278
|
load: void 0,
|
|
1209
1279
|
error: void 0
|
|
1210
1280
|
};
|
|
1211
1281
|
let settled = false;
|
|
1282
|
+
let failed = false;
|
|
1283
|
+
let terminalDetail;
|
|
1284
|
+
const decodeWaiters = [];
|
|
1285
|
+
let watchdogId;
|
|
1212
1286
|
const dispatch = (event) => {
|
|
1213
1287
|
raw.dispatchEvent(event);
|
|
1214
1288
|
};
|
|
1215
|
-
const
|
|
1289
|
+
const finish = (eventName, detail) => {
|
|
1290
|
+
if (settled || failed) return;
|
|
1291
|
+
terminalDetail = detail;
|
|
1216
1292
|
if (eventName === "load") settled = true;
|
|
1217
|
-
|
|
1293
|
+
else failed = true;
|
|
1294
|
+
if (watchdogId !== void 0) {
|
|
1295
|
+
clearTimeout(watchdogId);
|
|
1296
|
+
watchdogId = void 0;
|
|
1297
|
+
}
|
|
1298
|
+
for (const waiter of decodeWaiters.splice(0)) {
|
|
1299
|
+
if (eventName === "load") waiter.resolve();
|
|
1300
|
+
else waiter.reject(detail);
|
|
1301
|
+
}
|
|
1302
|
+
dispatch(new MiniCustomEvent(eventName, { detail }));
|
|
1303
|
+
};
|
|
1304
|
+
const forwardLoad = (nativeEvent) => {
|
|
1305
|
+
finish("load", nativeEvent);
|
|
1306
|
+
};
|
|
1307
|
+
const forwardError = (nativeEvent) => {
|
|
1308
|
+
finish("error", nativeEvent);
|
|
1218
1309
|
};
|
|
1219
|
-
|
|
1220
|
-
|
|
1310
|
+
let eventPath;
|
|
1311
|
+
if (nativeAdd) {
|
|
1221
1312
|
try {
|
|
1222
|
-
|
|
1223
|
-
|
|
1224
|
-
|
|
1225
|
-
}
|
|
1226
|
-
if (native && native.writable) {
|
|
1227
|
-
Object.defineProperty(raw, `on${eventName}`, { ...native, value: forward });
|
|
1228
|
-
return true;
|
|
1229
|
-
}
|
|
1313
|
+
nativeAdd("load", forwardLoad);
|
|
1314
|
+
nativeAdd("error", forwardError);
|
|
1315
|
+
eventPath = "addEventListener";
|
|
1230
1316
|
} catch {
|
|
1231
1317
|
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1318
|
+
}
|
|
1319
|
+
if (!eventPath) {
|
|
1320
|
+
try {
|
|
1321
|
+
raw.onload = forwardLoad;
|
|
1322
|
+
raw.onerror = forwardError;
|
|
1323
|
+
if (typeof raw.onload === "function") eventPath = "onload";
|
|
1324
|
+
} catch {
|
|
1325
|
+
}
|
|
1326
|
+
}
|
|
1327
|
+
if (!eventPath) {
|
|
1237
1328
|
diagnostics == null ? void 0 : diagnostics.warnOnce(
|
|
1238
1329
|
"image-native-events",
|
|
1239
|
-
|
|
1330
|
+
"image exposes neither onload/onerror slots nor a native addEventListener; load/error will come from a fallback (wx.getImageInfo or a watchdog)",
|
|
1331
|
+
hostShape
|
|
1240
1332
|
);
|
|
1241
1333
|
}
|
|
1242
1334
|
for (const eventName of ["load", "error"]) {
|
|
@@ -1252,27 +1344,78 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1252
1344
|
} catch {
|
|
1253
1345
|
}
|
|
1254
1346
|
}
|
|
1255
|
-
|
|
1347
|
+
const hostComplete = () => {
|
|
1348
|
+
if (!nativeComplete) return false;
|
|
1349
|
+
try {
|
|
1350
|
+
if (typeof nativeComplete.get === "function") return Boolean(nativeComplete.get.call(raw));
|
|
1351
|
+
return Boolean(nativeComplete.value);
|
|
1352
|
+
} catch {
|
|
1353
|
+
return false;
|
|
1354
|
+
}
|
|
1355
|
+
};
|
|
1356
|
+
try {
|
|
1256
1357
|
Object.defineProperty(raw, "complete", {
|
|
1257
1358
|
configurable: true,
|
|
1258
1359
|
enumerable: true,
|
|
1259
|
-
get: () => settled
|
|
1360
|
+
get: () => settled || failed || hostComplete()
|
|
1260
1361
|
});
|
|
1362
|
+
} catch {
|
|
1261
1363
|
}
|
|
1364
|
+
const getImageInfo = typeof wx.getImageInfo === "function" ? wx.getImageInfo.bind(wx) : void 0;
|
|
1365
|
+
let fallbackStarted = false;
|
|
1366
|
+
const armWatchdog = () => {
|
|
1367
|
+
if (watchdogId !== void 0) return;
|
|
1368
|
+
watchdogId = setTimeout(() => {
|
|
1369
|
+
watchdogId = void 0;
|
|
1370
|
+
forwardError({ type: "error", reason: "image-events-timeout", path: eventPath });
|
|
1371
|
+
}, EVENT_WATCHDOG_MS);
|
|
1372
|
+
};
|
|
1373
|
+
const startFallback = (src) => {
|
|
1374
|
+
if (eventPath || fallbackStarted || settled || failed || !src) return;
|
|
1375
|
+
fallbackStarted = true;
|
|
1376
|
+
if (getImageInfo) {
|
|
1377
|
+
eventPath = "getImageInfo";
|
|
1378
|
+
armWatchdog();
|
|
1379
|
+
try {
|
|
1380
|
+
getImageInfo({
|
|
1381
|
+
src,
|
|
1382
|
+
success: (info) => {
|
|
1383
|
+
diagnostics == null ? void 0 : diagnostics.warnOnce(
|
|
1384
|
+
"image-events-unavailable",
|
|
1385
|
+
`image "${src}" is reachable (${info.width}x${info.height}) but this host delivers no image events; the texture is reported as failed instead of uploading an empty image`,
|
|
1386
|
+
hostShape
|
|
1387
|
+
);
|
|
1388
|
+
forwardError({
|
|
1389
|
+
type: "error",
|
|
1390
|
+
reason: "image-events-unavailable",
|
|
1391
|
+
width: info.width,
|
|
1392
|
+
height: info.height
|
|
1393
|
+
});
|
|
1394
|
+
},
|
|
1395
|
+
fail: (error) => {
|
|
1396
|
+
diagnostics == null ? void 0 : diagnostics.warnOnce(
|
|
1397
|
+
"image-getImageInfo-failed",
|
|
1398
|
+
`wx.getImageInfo could not read "${src}"; check the path, the format (WebP is not decodable on every device) and whether the file is inside the package`,
|
|
1399
|
+
{ errMsg: error == null ? void 0 : error.errMsg, host: hostShape }
|
|
1400
|
+
);
|
|
1401
|
+
forwardError({ type: "error", reason: "getImageInfo-failed", error });
|
|
1402
|
+
}
|
|
1403
|
+
});
|
|
1404
|
+
} catch (error) {
|
|
1405
|
+
forwardError({ type: "error", reason: "getImageInfo-threw", error });
|
|
1406
|
+
}
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
eventPath = "watchdog";
|
|
1410
|
+
armWatchdog();
|
|
1411
|
+
};
|
|
1412
|
+
onSrcChange = startFallback;
|
|
1262
1413
|
Object.defineProperty(raw, "crossOrigin", { value: "", writable: true, configurable: true });
|
|
1263
1414
|
Object.defineProperty(raw, "decode", {
|
|
1264
1415
|
value: () => new Promise((resolve, reject) => {
|
|
1265
|
-
if (
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
handlers.load = (e) => {
|
|
1269
|
-
previousLoad == null ? void 0 : previousLoad(e);
|
|
1270
|
-
resolve();
|
|
1271
|
-
};
|
|
1272
|
-
handlers.error = (e) => {
|
|
1273
|
-
previousError == null ? void 0 : previousError(e);
|
|
1274
|
-
reject(e);
|
|
1275
|
-
};
|
|
1416
|
+
if (failed) return reject(terminalDetail);
|
|
1417
|
+
if (settled || hostComplete()) return resolve();
|
|
1418
|
+
decodeWaiters.push({ resolve, reject });
|
|
1276
1419
|
}),
|
|
1277
1420
|
configurable: true
|
|
1278
1421
|
});
|
|
@@ -1302,5 +1445,5 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1302
1445
|
}
|
|
1303
1446
|
|
|
1304
1447
|
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 };
|
|
1305
|
-
//# sourceMappingURL=chunk-
|
|
1306
|
-
//# sourceMappingURL=chunk-
|
|
1448
|
+
//# sourceMappingURL=chunk-ZFJLEEF4.js.map
|
|
1449
|
+
//# sourceMappingURL=chunk-ZFJLEEF4.js.map
|