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.
Files changed (73) hide show
  1. package/AGENTS.md +85 -0
  2. package/LICENSE +21 -0
  3. package/README.md +158 -2
  4. package/dist/build/rollup.d.ts +8 -0
  5. package/dist/build/rollup.js +393 -0
  6. package/dist/build/rollup.js.map +1 -0
  7. package/dist/build/vite.d.ts +15 -0
  8. package/dist/build/vite.js +395 -0
  9. package/dist/build/vite.js.map +1 -0
  10. package/dist/chunk-34RWHAW4.js +128 -0
  11. package/dist/chunk-34RWHAW4.js.map +1 -0
  12. package/dist/chunk-3UGQWFH3.js +1246 -0
  13. package/dist/chunk-3UGQWFH3.js.map +1 -0
  14. package/dist/chunk-4UEBRAK6.js +711 -0
  15. package/dist/chunk-4UEBRAK6.js.map +1 -0
  16. package/dist/chunk-LB3WL24R.js +91 -0
  17. package/dist/chunk-LB3WL24R.js.map +1 -0
  18. package/dist/chunk-MTBMOFAL.js +132 -0
  19. package/dist/chunk-MTBMOFAL.js.map +1 -0
  20. package/dist/chunk-QYQQ5J6E.js +3 -0
  21. package/dist/chunk-QYQQ5J6E.js.map +1 -0
  22. package/dist/chunk-V6TY7KAL.js +7 -0
  23. package/dist/chunk-V6TY7KAL.js.map +1 -0
  24. package/dist/chunk-WLRQDTSZ.js +145 -0
  25. package/dist/chunk-WLRQDTSZ.js.map +1 -0
  26. package/dist/chunk-Z7AMDRN3.js +66 -0
  27. package/dist/chunk-Z7AMDRN3.js.map +1 -0
  28. package/dist/core/index.d.ts +101 -0
  29. package/dist/core/index.js +7 -0
  30. package/dist/core/index.js.map +1 -0
  31. package/dist/index.d.ts +8 -0
  32. package/dist/index.js +11 -0
  33. package/dist/index.js.map +1 -0
  34. package/dist/platforms/browser.d.ts +23 -0
  35. package/dist/platforms/browser.js +7 -0
  36. package/dist/platforms/browser.js.map +1 -0
  37. package/dist/platforms/wechat-game.d.ts +31 -0
  38. package/dist/platforms/wechat-game.js +8 -0
  39. package/dist/platforms/wechat-game.js.map +1 -0
  40. package/dist/platforms/wechat-miniprogram.d.ts +26 -0
  41. package/dist/platforms/wechat-miniprogram.js +8 -0
  42. package/dist/platforms/wechat-miniprogram.js.map +1 -0
  43. package/dist/plugin-core-BuqW9C-L.d.ts +127 -0
  44. package/dist/polyfills/index.d.ts +291 -0
  45. package/dist/polyfills/index.js +4 -0
  46. package/dist/polyfills/index.js.map +1 -0
  47. package/dist/runtime-7uUOoFhC.d.ts +263 -0
  48. package/dist/scope.d.ts +146 -0
  49. package/dist/scope.js +4 -0
  50. package/dist/scope.js.map +1 -0
  51. package/dist/types-BzK0LQMa.d.ts +153 -0
  52. package/dist/wx-types-NMNyrsWO.d.ts +150 -0
  53. package/docs/01-design-principles.md +105 -0
  54. package/docs/02-architecture.md +126 -0
  55. package/docs/03-module-map.md +99 -0
  56. package/docs/04-api-reference.md +291 -0
  57. package/docs/05-build-plugin.md +146 -0
  58. package/docs/06-platform-notes.md +108 -0
  59. package/docs/07-integration-guide.md +211 -0
  60. package/docs/08-extension-guide.md +101 -0
  61. package/docs/09-testing-and-release.md +206 -0
  62. package/docs/10-ai-playbook.md +140 -0
  63. package/docs/11-compat-matrix.md +94 -0
  64. package/docs/README.md +41 -0
  65. package/docs/adr/0001-scoped-globals.md +41 -0
  66. package/docs/adr/0002-unified-runtime-lifecycle.md +40 -0
  67. package/docs/adr/0003-ast-rewrite.md +51 -0
  68. package/docs/adr/0004-in-place-patching.md +42 -0
  69. package/docs/adr/0005-webgl2-only.md +44 -0
  70. package/docs/adr/0006-zero-three-dependency.md +43 -0
  71. package/docs/adr/README.md +28 -0
  72. package/llms.txt +65 -0
  73. package/package.json +117 -4
@@ -0,0 +1,291 @@
1
+ import { c as EventTargetLike, E as EventListenerLike } from '../types-BzK0LQMa.js';
2
+ import { b as WxLike } from '../wx-types-NMNyrsWO.js';
3
+
4
+ /**
5
+ * Blob + URL shims. WeChat mini games have neither. GLTFLoader, KTX2Loader,
6
+ * EXRLoader and several addons call `URL.createObjectURL(new Blob([...]))`.
7
+ *
8
+ * Object URLs are resolved to `data:` URIs instead of `blob:` URIs. The WeChat
9
+ * image loader understands `data:` directly, so no interception of `Image.src`
10
+ * is needed and there is no global URL scheme registry to leak.
11
+ */
12
+ type BlobPart = string | ArrayBuffer | ArrayBufferView | MiniBlob;
13
+ declare function bytesToBase64(bytes: Uint8Array): string;
14
+ declare function base64ToBytes(input: string): Uint8Array;
15
+ declare class MiniBlob {
16
+ readonly type: string;
17
+ readonly size: number;
18
+ private readonly parts;
19
+ constructor(parts?: BlobPart[], options?: {
20
+ type?: string;
21
+ });
22
+ bytes(): Uint8Array;
23
+ arrayBuffer(): Promise<ArrayBuffer>;
24
+ text(): Promise<string>;
25
+ slice(start?: number, end?: number, contentType?: string): MiniBlob;
26
+ dataURL(): string;
27
+ }
28
+ declare const OBJECT_URL_PREFIX = "mini-three-blob:";
29
+ interface URLSearchParamsLike {
30
+ get(name: string): string | null;
31
+ set(name: string, value: string): void;
32
+ toString(): string;
33
+ }
34
+ declare class MiniURLSearchParams implements URLSearchParamsLike {
35
+ private readonly map;
36
+ constructor(init?: string);
37
+ get(name: string): string | null;
38
+ set(name: string, value: string): void;
39
+ toString(): string;
40
+ }
41
+ /** Lightweight URL implementation: enough for three.js loaders and addons. */
42
+ declare class MiniURL {
43
+ href: string;
44
+ protocol: string;
45
+ host: string;
46
+ hostname: string;
47
+ port: string;
48
+ pathname: string;
49
+ search: string;
50
+ hash: string;
51
+ origin: string;
52
+ searchParams: MiniURLSearchParams;
53
+ constructor(url: string, base?: string | MiniURL);
54
+ toString(): string;
55
+ static createObjectURL(blob: MiniBlob | Blob): string;
56
+ static revokeObjectURL(url: string): void;
57
+ /** Resolve a `mini-three-blob:` URL back to its data URI. */
58
+ static resolveObjectURL(url: string): string | null;
59
+ static clearObjectURLs(): void;
60
+ }
61
+ /** Resolve `url` against `base` without relying on a browser URL implementation. */
62
+ declare function resolveUrl(url: string, base?: string | MiniURL): string;
63
+
64
+ /** Minimal W3C-compatible event system, independent of any browser global. */
65
+
66
+ interface MiniEventInit {
67
+ bubbles?: boolean;
68
+ cancelable?: boolean;
69
+ composed?: boolean;
70
+ }
71
+ declare class MiniEvent {
72
+ readonly type: string;
73
+ readonly bubbles: boolean;
74
+ readonly cancelable: boolean;
75
+ readonly composed: boolean;
76
+ readonly timeStamp: number;
77
+ readonly isTrusted = false;
78
+ defaultPrevented: boolean;
79
+ cancelBubble: boolean;
80
+ target: unknown;
81
+ currentTarget: unknown;
82
+ eventPhase: number;
83
+ private immediateStopped;
84
+ constructor(type: string, init?: MiniEventInit);
85
+ preventDefault(): void;
86
+ stopPropagation(): void;
87
+ stopImmediatePropagation(): void;
88
+ get _immediateStopped(): boolean;
89
+ composedPath(): unknown[];
90
+ }
91
+ declare class MiniCustomEvent<T = unknown> extends MiniEvent {
92
+ readonly detail: T;
93
+ constructor(type: string, init?: MiniEventInit & {
94
+ detail?: T;
95
+ });
96
+ }
97
+ interface MiniPointerEventInit extends MiniEventInit {
98
+ pointerId?: number;
99
+ pointerType?: 'touch' | 'mouse' | 'pen';
100
+ isPrimary?: boolean;
101
+ clientX?: number;
102
+ clientY?: number;
103
+ pageX?: number;
104
+ pageY?: number;
105
+ offsetX?: number;
106
+ offsetY?: number;
107
+ button?: number;
108
+ buttons?: number;
109
+ ctrlKey?: boolean;
110
+ shiftKey?: boolean;
111
+ altKey?: boolean;
112
+ metaKey?: boolean;
113
+ width?: number;
114
+ height?: number;
115
+ pressure?: number;
116
+ }
117
+ declare class MiniPointerEvent extends MiniEvent {
118
+ readonly pointerId: number;
119
+ readonly pointerType: 'touch' | 'mouse' | 'pen';
120
+ readonly isPrimary: boolean;
121
+ readonly clientX: number;
122
+ readonly clientY: number;
123
+ readonly pageX: number;
124
+ readonly pageY: number;
125
+ readonly offsetX: number;
126
+ readonly offsetY: number;
127
+ readonly button: number;
128
+ readonly buttons: number;
129
+ readonly ctrlKey: boolean;
130
+ readonly shiftKey: boolean;
131
+ readonly altKey: boolean;
132
+ readonly metaKey: boolean;
133
+ readonly width: number;
134
+ readonly height: number;
135
+ readonly pressure: number;
136
+ constructor(type: string, init?: MiniPointerEventInit);
137
+ }
138
+ declare class MiniMouseEvent extends MiniPointerEvent {
139
+ constructor(type: string, init?: MiniPointerEventInit);
140
+ }
141
+ declare class MiniMessageEvent<T = unknown> extends MiniEvent {
142
+ readonly data: T;
143
+ readonly origin = "";
144
+ readonly lastEventId = "";
145
+ constructor(type: string, init?: MiniEventInit & {
146
+ data?: T;
147
+ });
148
+ }
149
+ declare class MiniProgressEvent extends MiniEvent {
150
+ readonly lengthComputable: boolean;
151
+ readonly loaded: number;
152
+ readonly total: number;
153
+ constructor(type: string, init?: MiniEventInit & {
154
+ lengthComputable?: boolean;
155
+ loaded?: number;
156
+ total?: number;
157
+ });
158
+ }
159
+ declare class MiniDOMException extends Error {
160
+ readonly name: string;
161
+ constructor(message?: string, name?: string);
162
+ }
163
+ /**
164
+ * A small but correct EventTarget. three.js controls only rely on
165
+ * add/remove/dispatch, but we also support `onxxx` inline handlers and `once`,
166
+ * because several addons (and r3f/tresjs) use them.
167
+ */
168
+ declare class MiniEventTarget implements EventTargetLike {
169
+ private readonly listeners;
170
+ addEventListener(type: string, listener: EventListenerLike | {
171
+ handleEvent(event: unknown): void;
172
+ } | null, options?: boolean | {
173
+ once?: boolean;
174
+ capture?: boolean;
175
+ } | unknown): void;
176
+ removeEventListener(type: string, listener: EventListenerLike | {
177
+ handleEvent(event: unknown): void;
178
+ } | null, _options?: unknown): void;
179
+ dispatchEvent(event: unknown): boolean;
180
+ /** Remove every listener. Called by `Runtime.dispose()`. */
181
+ clearEventListeners(): void;
182
+ }
183
+ /** Patch EventTarget behaviour onto an existing object without changing identity. */
184
+ declare function patchEventTarget<T extends object>(target: T): T & MiniEventTarget;
185
+
186
+ /** fetch / XMLHttpRequest backed by `wx.request`. three.js FileLoader uses fetch. */
187
+
188
+ interface MiniHeaders {
189
+ get(name: string): string | null;
190
+ has(name: string): boolean;
191
+ forEach(callback: (value: string, key: string) => void): void;
192
+ [Symbol.iterator](): IterableIterator<[string, string]>;
193
+ }
194
+ interface MiniResponse {
195
+ readonly ok: boolean;
196
+ readonly status: number;
197
+ readonly statusText: string;
198
+ readonly url: string;
199
+ readonly headers: MiniHeaders;
200
+ readonly bodyUsed: boolean;
201
+ arrayBuffer(): Promise<ArrayBuffer>;
202
+ text(): Promise<string>;
203
+ json<T = unknown>(): Promise<T>;
204
+ blob(): Promise<MiniBlob>;
205
+ clone(): MiniResponse;
206
+ }
207
+ type MiniFetch = (input: string, init?: {
208
+ method?: string;
209
+ headers?: Record<string, string>;
210
+ body?: unknown;
211
+ signal?: {
212
+ aborted: boolean;
213
+ addEventListener?(type: string, listener: () => void): void;
214
+ };
215
+ }) => Promise<MiniResponse>;
216
+ declare function createFetch(wx: WxLike): MiniFetch;
217
+ /** Minimal AbortController, used by three's FileLoader abort support. */
218
+ declare class MiniAbortSignal extends MiniEventTarget {
219
+ aborted: boolean;
220
+ reason: unknown;
221
+ throwIfAborted(): void;
222
+ }
223
+ declare class MiniAbortController {
224
+ readonly signal: MiniAbortSignal;
225
+ abort(reason?: unknown): void;
226
+ }
227
+ /**
228
+ * Small XMLHttpRequest-compatible class. Modern three.js uses fetch, but many
229
+ * addons (and older three versions) still instantiate XMLHttpRequest directly.
230
+ */
231
+ declare class MiniXMLHttpRequest extends MiniEventTarget {
232
+ private readonly wx;
233
+ static readonly UNSENT = 0;
234
+ static readonly OPENED = 1;
235
+ static readonly HEADERS_RECEIVED = 2;
236
+ static readonly LOADING = 3;
237
+ static readonly DONE = 4;
238
+ readyState: number;
239
+ status: number;
240
+ statusText: string;
241
+ response: unknown;
242
+ responseText: string;
243
+ responseType: string;
244
+ responseURL: string;
245
+ timeout: number;
246
+ withCredentials: boolean;
247
+ onreadystatechange: ((event: unknown) => void) | null;
248
+ onload: ((event: unknown) => void) | null;
249
+ onerror: ((event: unknown) => void) | null;
250
+ onprogress: ((event: unknown) => void) | null;
251
+ onabort: ((event: unknown) => void) | null;
252
+ private method;
253
+ private url;
254
+ private headers;
255
+ private body;
256
+ constructor(wx: WxLike);
257
+ open(method: string, url: string): void;
258
+ setRequestHeader(name: string, value: string): void;
259
+ getAllResponseHeaders(): string;
260
+ send(body?: unknown): void;
261
+ abort(): void;
262
+ private fail;
263
+ }
264
+ declare function createXMLHttpRequestFactory(wx: WxLike): typeof MiniXMLHttpRequest;
265
+
266
+ declare function atob(data: string): string;
267
+ declare function btoa(data: string): string;
268
+ declare class MiniTextEncoder {
269
+ readonly encoding = "utf-8";
270
+ encode(input?: string): Uint8Array;
271
+ encodeInto(source: string, destination: Uint8Array): {
272
+ read: number;
273
+ written: number;
274
+ };
275
+ }
276
+ interface TextDecoderOptions {
277
+ fatal?: boolean;
278
+ ignoreBOM?: boolean;
279
+ }
280
+ interface TextDecodeOptions {
281
+ stream?: boolean;
282
+ }
283
+ declare class MiniTextDecoder {
284
+ readonly encoding: string;
285
+ readonly fatal: boolean;
286
+ readonly ignoreBOM: boolean;
287
+ constructor(label?: string, options?: TextDecoderOptions);
288
+ decode(input?: ArrayBufferView | ArrayBuffer, _options?: TextDecodeOptions): string;
289
+ }
290
+
291
+ export { type BlobPart, MiniAbortController, MiniAbortSignal, MiniBlob, MiniCustomEvent, MiniDOMException, MiniEvent, type MiniEventInit, MiniEventTarget, type MiniFetch, type MiniHeaders, MiniMessageEvent, MiniMouseEvent, MiniPointerEvent, type MiniPointerEventInit, MiniProgressEvent, type MiniResponse, MiniTextDecoder, MiniTextEncoder, MiniURL, MiniURLSearchParams, MiniXMLHttpRequest, OBJECT_URL_PREFIX, type TextDecodeOptions, type TextDecoderOptions, type URLSearchParamsLike, atob, base64ToBytes, btoa, bytesToBase64, createFetch, createXMLHttpRequestFactory, patchEventTarget, resolveUrl };
@@ -0,0 +1,4 @@
1
+ export { MiniAbortController, MiniAbortSignal, MiniBlob, MiniCustomEvent, MiniDOMException, MiniEvent, MiniEventTarget, MiniMessageEvent, MiniMouseEvent, MiniPointerEvent, MiniProgressEvent, MiniTextDecoder, MiniTextEncoder, MiniURL, MiniURLSearchParams, MiniXMLHttpRequest, OBJECT_URL_PREFIX, atob, base64ToBytes, btoa, bytesToBase64, createFetch, createXMLHttpRequestFactory, patchEventTarget, resolveUrl } from '../chunk-4UEBRAK6.js';
2
+ import '../chunk-V6TY7KAL.js';
3
+ //# sourceMappingURL=index.js.map
4
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":[],"names":[],"mappings":"","file":"index.js"}
@@ -0,0 +1,263 @@
1
+ import { a as Capabilities, R as Rect, D as Disposer, b as ContextType, f as TouchLikeEvent, d as FrameScheduler, W as WindowInfo, e as RuntimeEvents } from './types-BzK0LQMa.js';
2
+ import { MiniThreeScope, DocumentLike } from './scope.js';
3
+ import { b as WxLike, W as WxCanvas } from './wx-types-NMNyrsWO.js';
4
+
5
+ /** Structured, level-filtered diagnostics. No console spam in production. */
6
+
7
+ type LogLevel = 'silent' | 'error' | 'warn' | 'info' | 'debug';
8
+ type Reporter = (level: Exclude<LogLevel, 'silent'>, message: string, payload?: unknown) => void;
9
+ interface Diagnostics {
10
+ readonly level: LogLevel;
11
+ error(message: string, payload?: unknown): void;
12
+ warn(message: string, payload?: unknown): void;
13
+ info(message: string, payload?: unknown): void;
14
+ debug(message: string, payload?: unknown): void;
15
+ /** Warn once per unique key (avoids per-frame warnings). */
16
+ warnOnce(key: string, message: string, payload?: unknown): void;
17
+ capabilityReport(caps: Capabilities): string;
18
+ }
19
+ declare function createDiagnostics(level?: LogLevel, reporter?: Reporter): Diagnostics;
20
+ /** Human-readable, copy-pasteable report for bug reports and AI debugging. */
21
+ declare function capabilityReport(caps: Capabilities): string;
22
+
23
+ /**
24
+ * In-place DOM-ish patching.
25
+ *
26
+ * WeChat stores canvas/image validation metadata in an internal WeakMap keyed by
27
+ * object identity. Wrapping in a `new`-ed class or a `Proxy` breaks those checks.
28
+ * So we **define properties on the original object** and use
29
+ * `Symbol.hasInstance` + a registry to make `instanceof HTMLCanvasElement` pass.
30
+ *
31
+ * Improvement over the reference adapter: we do NOT mutate the object's
32
+ * prototype (`Object.setPrototypeOf`), which is a de-optimisation in JSC/V8 and
33
+ * can break other libraries that also patch prototypes.
34
+ */
35
+
36
+ interface MockClass<T extends object = object> {
37
+ new (...args: never[]): T;
38
+ readonly __instances: WeakSet<object>;
39
+ }
40
+ /**
41
+ * Create a constructor whose `instanceof` checks consult a registry. The
42
+ * constructor itself throws (it must never be used to create real objects).
43
+ */
44
+ declare function createMockClass<T extends object = object>(name: string): MockClass<T>;
45
+ declare function markAs<T extends object>(ctor: MockClass<T>, instance: object): void;
46
+ declare function isMarked<T extends object>(ctor: MockClass<T>, instance: unknown): boolean;
47
+ /** Shared mock constructors. Registered globally so all platforms agree. */
48
+ declare const HTMLCanvasElementShim: MockClass<HTMLCanvasElement>;
49
+ declare const HTMLImageElementShim: MockClass<HTMLImageElement>;
50
+ declare const HTMLElementShim: MockClass<HTMLElement>;
51
+ declare const OffscreenCanvasShim: MockClass<OffscreenCanvas>;
52
+ declare const ImageDataShim: MockClass<ImageData>;
53
+ declare const WebGLRenderingContextShim: MockClass<WebGLRenderingContext>;
54
+ declare const WebGL2RenderingContextShim: MockClass<WebGL2RenderingContext>;
55
+ declare const DOMRectShim: MockClass<DOMRect>;
56
+ interface PatchedElement<T extends object> {
57
+ element: T;
58
+ updateRect(rect: Rect): void;
59
+ disposers: Disposer[];
60
+ }
61
+ interface PatchElementOptions<T extends object> {
62
+ rect: Rect;
63
+ document?: unknown;
64
+ /** Extra property descriptors merged onto the object. */
65
+ extra?: PropertyDescriptorMap;
66
+ /** Mark the object as an instance of these shims. */
67
+ instanceOf?: Array<{
68
+ __instances: WeakSet<object>;
69
+ }>;
70
+ /** Called on `setAttribute(name, value)`. */
71
+ onSetAttribute?: (name: string, value: unknown, element: T) => void;
72
+ }
73
+ /** Patch DOM-ish properties onto an existing object while keeping identity. */
74
+ declare function patchElement<T extends object>(instance: T, options: PatchElementOptions<T>): PatchedElement<T>;
75
+ declare function normalizeRect(partial?: Partial<Rect>): Rect;
76
+
77
+ /** Image / ImageData / HTMLImageElement shims built on wx.createImage. */
78
+
79
+ interface MiniImageData {
80
+ width: number;
81
+ height: number;
82
+ data: Uint8ClampedArray;
83
+ colorSpace: string;
84
+ }
85
+ declare class ShimImageData implements MiniImageData {
86
+ readonly width: number;
87
+ readonly height: number;
88
+ readonly data: Uint8ClampedArray;
89
+ colorSpace: string;
90
+ constructor(widthOrData: number | Uint8ClampedArray, heightOrWidth?: number, height?: number);
91
+ }
92
+ interface ImageFactory {
93
+ /** `new Image()` returns a wx image object patched with DOM-ish behaviour. */
94
+ Image: new (width?: number, height?: number) => HTMLImageElement;
95
+ HTMLImageElement: MockClass<HTMLImageElement>;
96
+ ImageData: new (dataOrWidth: number | Uint8ClampedArray, widthOrHeight?: number, height?: number) => MiniImageData;
97
+ createImage(): HTMLImageElement;
98
+ createImageData(width: number, height: number): MiniImageData;
99
+ /** Always undefined on WeChat: Blob is unavailable, so three.js must take its
100
+ * non-createImageBitmap branch. The build plugin can force this to `void 0`. */
101
+ createImageBitmap: undefined;
102
+ }
103
+ declare function createImageFactory(wx: WxLike, diagnostics?: Diagnostics): ImageFactory;
104
+
105
+ /** Platform binding contract: everything the runtime needs from a host. */
106
+
107
+ interface PlatformBinding {
108
+ readonly kind: Capabilities['platform'];
109
+ /** Undefined on the browser platform. */
110
+ readonly wx?: WxLike;
111
+ /** The raw platform canvas. The runtime patches it in place. */
112
+ readonly rawCanvas: WxCanvas;
113
+ readonly capabilities: Capabilities;
114
+ readonly imageFactory: ImageFactory;
115
+ /** Current bounding rect of `rawCanvas`; may be async on mini programs. */
116
+ getCanvasRect(): Rect | Promise<Rect>;
117
+ /** Create a secondary canvas without disturbing the on-screen one. */
118
+ createOffscreenCanvas(width: number, height: number, type: ContextType): WxCanvas;
119
+ /** Subscribe to platform touch events (no-op on mini programs). */
120
+ watchTouch(handler: (event: TouchLikeEvent) => void): Disposer;
121
+ watchVisibility(handler: (visible: boolean) => void): Disposer;
122
+ requestAnimationFrame(callback: (time: number) => void): number;
123
+ cancelAnimationFrame(id: number): void;
124
+ now(): number;
125
+ /** Platform-specific teardown (detach listeners, release the canvas...). */
126
+ dispose(): void;
127
+ }
128
+ type PlatformFactory = () => PlatformBinding | Promise<PlatformBinding>;
129
+
130
+ interface PointerTargets {
131
+ element: {
132
+ dispatchEvent(event: unknown): boolean;
133
+ };
134
+ document?: {
135
+ dispatchEvent(event: unknown): boolean;
136
+ };
137
+ window?: {
138
+ dispatchEvent(event: unknown): boolean;
139
+ };
140
+ }
141
+ interface PointerBridgeOptions {
142
+ getRect: () => Rect | Promise<Rect>;
143
+ targets: PointerTargets;
144
+ /** Dispatch to document/window in addition to the canvas. Default true. */
145
+ propagate?: boolean;
146
+ /** Also emit legacy mouse* / click events. Default true. */
147
+ emitMouseEvents?: boolean;
148
+ diagnostics?: Diagnostics;
149
+ }
150
+ declare class PointerBridge {
151
+ private readonly options;
152
+ private readonly pointers;
153
+ private readonly captured;
154
+ private rect;
155
+ private rectReady;
156
+ private fallbackId;
157
+ private lastTapAt;
158
+ private disposed;
159
+ constructor(options: PointerBridgeOptions);
160
+ get activePointerCount(): number;
161
+ getRect(): Rect;
162
+ setRect(rect: Rect): void;
163
+ /** Re-read the bounding rect. Async rects update the cache when resolved. */
164
+ refreshRect(): void;
165
+ setPointerCapture(pointerId: number, target: {
166
+ dispatchEvent(event: unknown): boolean;
167
+ }): void;
168
+ releasePointerCapture(pointerId: number): void;
169
+ /** Accept any WeChat touch-like event and dispatch normalized pointer events. */
170
+ dispatch(event: TouchLikeEvent, overrides?: {
171
+ propagate?: boolean;
172
+ computeRect?: boolean;
173
+ }): void;
174
+ /** Convenience for mouse events coming from WeChat devtools / PC. */
175
+ dispatchMouse(event: {
176
+ type: string;
177
+ x?: number;
178
+ y?: number;
179
+ clientX?: number;
180
+ clientY?: number;
181
+ button?: number;
182
+ deltaY?: number;
183
+ }): void;
184
+ dispose(): void;
185
+ private track;
186
+ private identifierOf;
187
+ private synthesizePoint;
188
+ private toCoords;
189
+ private emit;
190
+ private fanout;
191
+ }
192
+
193
+ interface RuntimeOptions {
194
+ /** Clamp devicePixelRatio (WeChat devices can report 3~4). Default 2. */
195
+ pixelRatioCap?: number;
196
+ /** Also replay pointer events on document / window. Default true. */
197
+ propagatePointerEvents?: boolean;
198
+ /** Emit legacy mouse* / click events. Default true. */
199
+ emitMouseEvents?: boolean;
200
+ /** Context type used by `document.createElement('canvas')`. Default 'webgl2'. */
201
+ defaultContextType?: ContextType;
202
+ /** Cache getContext() results so context identity is stable. Default true. */
203
+ cacheContexts?: boolean;
204
+ /** Fix known WeChat WebGL quirks (getExtension, drawingBuffer size). Default true. */
205
+ normalizeWebGL?: boolean;
206
+ /** Cap logical frames per second. 0 = uncapped. Default 0. */
207
+ fpsCap?: number;
208
+ logLevel?: LogLevel;
209
+ reporter?: Reporter;
210
+ /** Override detected capabilities (device tiers / tests). */
211
+ capabilities?: Partial<Capabilities>;
212
+ /** Immediately install scoped globals onto globalThis. Default false. */
213
+ installGlobals?: boolean;
214
+ /** Warn when a frame callback exceeds this many ms. 0 disables. Default 0. */
215
+ slowFrameThreshold?: number;
216
+ }
217
+ interface RendererHints {
218
+ canvas: HTMLCanvasElement;
219
+ antialias: boolean;
220
+ alpha: boolean;
221
+ powerPreference: 'high-performance';
222
+ preserveDrawingBuffer: boolean;
223
+ /** Recommended value; three.js r15x+ uses outputColorSpace, not outputEncoding. */
224
+ outputColorSpace: 'srgb';
225
+ }
226
+ interface MiniThreeRuntime {
227
+ /** A wx canvas patched to behave as HTMLCanvasElement. */
228
+ readonly canvas: HTMLCanvasElement;
229
+ /** The scoped "window" object consumed by rewritten third-party modules. */
230
+ readonly scope: MiniThreeScope;
231
+ readonly document: DocumentLike;
232
+ readonly capabilities: Capabilities;
233
+ readonly diagnostics: Diagnostics;
234
+ readonly frames: FrameScheduler;
235
+ readonly bridge: PointerBridge;
236
+ readonly windowInfo: WindowInfo;
237
+ readonly rendererHints: RendererHints;
238
+ readonly disposed: boolean;
239
+ /** Feed a WeChat touch event. Mini games bind this automatically. */
240
+ handleTouch(event: TouchLikeEvent, options?: {
241
+ propagate?: boolean;
242
+ computeRect?: boolean;
243
+ }): void;
244
+ /** Re-measure the canvas and window, then emit `resize`. */
245
+ resize(): Promise<void>;
246
+ /** Opt-in global pollution for untransformed libraries; returns a disposer. */
247
+ installGlobals(options?: {
248
+ skipExisting?: boolean;
249
+ extraKeys?: string[];
250
+ }): Disposer;
251
+ /** Create an additional patched canvas (e.g. for render targets / text). */
252
+ createCanvas(width?: number, height?: number, type?: ContextType): HTMLCanvasElement;
253
+ on<K extends keyof RuntimeEvents>(event: K, listener: RuntimeEvents[K]): Disposer;
254
+ /** Dump a copy-pasteable capability report. */
255
+ report(): string;
256
+ dispose(): void;
257
+ }
258
+ /** Create a runtime from a binding or an (async) platform factory. */
259
+ declare function createRuntime(platform: PlatformBinding | PlatformFactory, options?: RuntimeOptions): Promise<MiniThreeRuntime>;
260
+ /** The active scoped global, if a runtime has been created. */
261
+ declare function currentScope(): MiniThreeScope | null;
262
+
263
+ export { DOMRectShim as D, HTMLCanvasElementShim as H, ImageDataShim as I, type LogLevel as L, type MiniImageData as M, OffscreenCanvasShim as O, type PatchElementOptions as P, type RendererHints as R, ShimImageData as S, WebGL2RenderingContextShim as W, type Diagnostics as a, HTMLElementShim as b, HTMLImageElementShim as c, type ImageFactory as d, type MiniThreeRuntime as e, type MockClass as f, type PatchedElement as g, type PlatformBinding as h, type PlatformFactory as i, PointerBridge as j, type PointerBridgeOptions as k, type PointerTargets as l, type Reporter as m, type RuntimeOptions as n, WebGLRenderingContextShim as o, capabilityReport as p, createDiagnostics as q, createImageFactory as r, createMockClass as s, createRuntime as t, currentScope as u, isMarked as v, markAs as w, normalizeRect as x, patchElement as y };