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,711 @@
1
+ import { __publicField } from './chunk-V6TY7KAL.js';
2
+
3
+ // src/polyfills/blob-url.ts
4
+ var encoderTable = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
5
+ function bytesToBase64(bytes) {
6
+ var _a, _b, _c;
7
+ let out = "";
8
+ for (let i = 0; i < bytes.length; i += 3) {
9
+ const a = (_a = bytes[i]) != null ? _a : 0;
10
+ const b = (_b = bytes[i + 1]) != null ? _b : 0;
11
+ const c = (_c = bytes[i + 2]) != null ? _c : 0;
12
+ const n = a << 16 | b << 8 | c;
13
+ out += encoderTable.charAt(n >> 18 & 63) + encoderTable.charAt(n >> 12 & 63);
14
+ out += i + 1 < bytes.length ? encoderTable.charAt(n >> 6 & 63) : "=";
15
+ out += i + 2 < bytes.length ? encoderTable.charAt(n & 63) : "=";
16
+ }
17
+ return out;
18
+ }
19
+ function base64ToBytes(input) {
20
+ var _a, _b, _c, _d;
21
+ const clean = input.replace(/[\s=]/g, "");
22
+ const out = new Uint8Array(Math.floor(clean.length * 3 / 4));
23
+ let p = 0;
24
+ for (let i = 0; i < clean.length; i += 4) {
25
+ const a = encoderTable.indexOf((_a = clean[i]) != null ? _a : "");
26
+ const b = encoderTable.indexOf((_b = clean[i + 1]) != null ? _b : "");
27
+ const c = encoderTable.indexOf((_c = clean[i + 2]) != null ? _c : "");
28
+ const d = encoderTable.indexOf((_d = clean[i + 3]) != null ? _d : "");
29
+ const n = (a < 0 ? 0 : a) << 18 | (b < 0 ? 0 : b) << 12 | (c < 0 ? 0 : c) << 6 | (d < 0 ? 0 : d);
30
+ if (p < out.length) out[p++] = n >> 16 & 255;
31
+ if (p < out.length) out[p++] = n >> 8 & 255;
32
+ if (p < out.length) out[p++] = n & 255;
33
+ }
34
+ return out.subarray(0, p);
35
+ }
36
+ function partToBytes(part) {
37
+ if (typeof part === "string") {
38
+ const bytes = [];
39
+ for (let i = 0; i < part.length; i++) {
40
+ let cp = part.charCodeAt(i);
41
+ if (cp >= 55296 && cp <= 56319 && i + 1 < part.length) {
42
+ const low = part.charCodeAt(i + 1);
43
+ if (low >= 56320 && low <= 57343) {
44
+ cp = 65536 + (cp - 55296 << 10) + (low - 56320);
45
+ i++;
46
+ }
47
+ }
48
+ if (cp < 128) bytes.push(cp);
49
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
50
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
51
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
52
+ }
53
+ return new Uint8Array(bytes);
54
+ }
55
+ if (part instanceof MiniBlob) return part.bytes();
56
+ if (part instanceof ArrayBuffer) return new Uint8Array(part);
57
+ return new Uint8Array(part.buffer, part.byteOffset, part.byteLength);
58
+ }
59
+ var MiniBlob = class _MiniBlob {
60
+ constructor(parts = [], options = {}) {
61
+ __publicField(this, "type");
62
+ __publicField(this, "size");
63
+ __publicField(this, "parts");
64
+ var _a;
65
+ this.parts = parts;
66
+ this.type = (_a = options.type) != null ? _a : "";
67
+ this.size = parts.reduce((sum, part) => sum + partToBytes(part).byteLength, 0);
68
+ }
69
+ bytes() {
70
+ const chunks = this.parts.map(partToBytes);
71
+ const out = new Uint8Array(this.size);
72
+ let offset = 0;
73
+ for (const chunk of chunks) {
74
+ out.set(chunk, offset);
75
+ offset += chunk.byteLength;
76
+ }
77
+ return out;
78
+ }
79
+ arrayBuffer() {
80
+ const bytes = this.bytes();
81
+ return Promise.resolve(bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength));
82
+ }
83
+ text() {
84
+ return Promise.resolve(new TextDecoderLike().decode(this.bytes()));
85
+ }
86
+ slice(start = 0, end = this.size, contentType = "") {
87
+ return new _MiniBlob([this.bytes().slice(start, end)], { type: contentType });
88
+ }
89
+ dataURL() {
90
+ return `data:${this.type || "application/octet-stream"};base64,${bytesToBase64(this.bytes())}`;
91
+ }
92
+ };
93
+ var TextDecoderLike = class {
94
+ decode(input) {
95
+ var _a, _b, _c, _d, _e, _f, _g;
96
+ let out = "";
97
+ for (let i = 0; i < input.length; i++) {
98
+ const a = (_a = input[i]) != null ? _a : 0;
99
+ if (a < 128) out += String.fromCharCode(a);
100
+ else if (a < 224) out += String.fromCharCode((a & 31) << 6 | ((_b = input[++i]) != null ? _b : 0) & 63);
101
+ else if (a < 240) {
102
+ const b = (_c = input[++i]) != null ? _c : 0;
103
+ const c = (_d = input[++i]) != null ? _d : 0;
104
+ out += String.fromCharCode((a & 15) << 12 | (b & 63) << 6 | c & 63);
105
+ } else {
106
+ const b = (_e = input[++i]) != null ? _e : 0;
107
+ const c = (_f = input[++i]) != null ? _f : 0;
108
+ const d = (_g = input[++i]) != null ? _g : 0;
109
+ const cp = (a & 7) << 18 | (b & 63) << 12 | (c & 63) << 6 | d & 63;
110
+ const v = cp - 65536;
111
+ out += String.fromCharCode(55296 + (v >> 10), 56320 + (v & 1023));
112
+ }
113
+ }
114
+ return out;
115
+ }
116
+ };
117
+ var objectUrlSeed = 0;
118
+ var objectUrls = /* @__PURE__ */ new Map();
119
+ var OBJECT_URL_PREFIX = "mini-three-blob:";
120
+ var MiniURLSearchParams = class {
121
+ constructor(init = "") {
122
+ __publicField(this, "map", /* @__PURE__ */ new Map());
123
+ const q = init.startsWith("?") ? init.slice(1) : init;
124
+ if (!q) return;
125
+ for (const pair of q.split("&")) {
126
+ const [k, v = ""] = pair.split("=");
127
+ if (k) this.map.set(decodeURIComponent(k), decodeURIComponent(v));
128
+ }
129
+ }
130
+ get(name) {
131
+ return this.map.has(name) ? this.map.get(name) : null;
132
+ }
133
+ set(name, value) {
134
+ this.map.set(name, value);
135
+ }
136
+ toString() {
137
+ const parts = [];
138
+ for (const [k, v] of this.map) parts.push(`${encodeURIComponent(k)}=${encodeURIComponent(v)}`);
139
+ return parts.join("&");
140
+ }
141
+ };
142
+ var MiniURL = class {
143
+ constructor(url, base) {
144
+ __publicField(this, "href");
145
+ __publicField(this, "protocol");
146
+ __publicField(this, "host");
147
+ __publicField(this, "hostname");
148
+ __publicField(this, "port");
149
+ __publicField(this, "pathname");
150
+ __publicField(this, "search");
151
+ __publicField(this, "hash");
152
+ __publicField(this, "origin");
153
+ __publicField(this, "searchParams");
154
+ var _a, _b, _c, _d, _e, _f;
155
+ const resolved = resolveUrl(url, base);
156
+ const m = /^([a-z][a-z\d+.-]*:)\/\/([^/?#]*)([^?#]*)(\?[^#]*)?(#.*)?$/i.exec(resolved);
157
+ if (m) {
158
+ this.protocol = (_a = m[1]) != null ? _a : "";
159
+ this.host = (_b = m[2]) != null ? _b : "";
160
+ this.pathname = m[3] || "/";
161
+ this.search = (_c = m[4]) != null ? _c : "";
162
+ this.hash = (_d = m[5]) != null ? _d : "";
163
+ const hp = /^([^:]*)(?::(\d+))?$/.exec(this.host);
164
+ this.hostname = (_e = hp == null ? void 0 : hp[1]) != null ? _e : this.host;
165
+ this.port = (_f = hp == null ? void 0 : hp[2]) != null ? _f : "";
166
+ this.origin = `${this.protocol}//${this.host}`;
167
+ } else {
168
+ this.protocol = "";
169
+ this.host = "";
170
+ this.hostname = "";
171
+ this.port = "";
172
+ this.pathname = resolved;
173
+ this.search = "";
174
+ this.hash = "";
175
+ this.origin = "null";
176
+ }
177
+ this.href = `${this.origin === "null" ? "" : this.origin}${this.pathname}${this.search}${this.hash}`;
178
+ this.searchParams = new MiniURLSearchParams(this.search);
179
+ }
180
+ toString() {
181
+ return this.href;
182
+ }
183
+ static createObjectURL(blob) {
184
+ const mini = blob instanceof MiniBlob ? blob : new MiniBlob([], { type: blob.type });
185
+ const id = `${OBJECT_URL_PREFIX}${Date.now().toString(36)}-${(objectUrlSeed++).toString(36)}`;
186
+ objectUrls.set(id, mini);
187
+ return id;
188
+ }
189
+ static revokeObjectURL(url) {
190
+ objectUrls.delete(url);
191
+ }
192
+ /** Resolve a `mini-three-blob:` URL back to its data URI. */
193
+ static resolveObjectURL(url) {
194
+ const blob = objectUrls.get(url);
195
+ return blob ? blob.dataURL() : null;
196
+ }
197
+ static clearObjectURLs() {
198
+ objectUrls.clear();
199
+ }
200
+ };
201
+ function resolveUrl(url, base) {
202
+ var _a;
203
+ const baseHref = typeof base === "string" ? base : base == null ? void 0 : base.href;
204
+ if (/^[a-z][a-z\d+.-]*:/i.test(url) || url.startsWith("//")) {
205
+ return url.startsWith("//") && baseHref ? `${new MiniURL(baseHref).protocol}${url}` : url;
206
+ }
207
+ if (!baseHref) return url;
208
+ const b = new MiniURL(baseHref);
209
+ if (url.startsWith("/")) return `${b.origin}${url}`;
210
+ const dir = b.pathname.slice(0, b.pathname.lastIndexOf("/") + 1);
211
+ const combined = `${b.origin}${dir}${url}`;
212
+ const m = /^([a-z][a-z\d+.-]*:\/\/[^/]+)(\/.*)$/i.exec(combined);
213
+ if (!m) return combined;
214
+ const segments = [];
215
+ for (const seg of ((_a = m[2]) != null ? _a : "").split("/")) {
216
+ if (seg === "." || seg === "") continue;
217
+ if (seg === "..") segments.pop();
218
+ else segments.push(seg);
219
+ }
220
+ return `${m[1]}/${segments.join("/")}`;
221
+ }
222
+
223
+ // src/polyfills/event.ts
224
+ var MiniEvent = class {
225
+ constructor(type, init = {}) {
226
+ __publicField(this, "type");
227
+ __publicField(this, "bubbles");
228
+ __publicField(this, "cancelable");
229
+ __publicField(this, "composed");
230
+ __publicField(this, "timeStamp");
231
+ __publicField(this, "isTrusted", false);
232
+ __publicField(this, "defaultPrevented", false);
233
+ __publicField(this, "cancelBubble", false);
234
+ __publicField(this, "target", null);
235
+ __publicField(this, "currentTarget", null);
236
+ __publicField(this, "eventPhase", 0);
237
+ __publicField(this, "immediateStopped", false);
238
+ var _a, _b, _c;
239
+ this.type = type;
240
+ this.bubbles = (_a = init.bubbles) != null ? _a : false;
241
+ this.cancelable = (_b = init.cancelable) != null ? _b : false;
242
+ this.composed = (_c = init.composed) != null ? _c : false;
243
+ this.timeStamp = Date.now();
244
+ }
245
+ preventDefault() {
246
+ if (this.cancelable) this.defaultPrevented = true;
247
+ }
248
+ stopPropagation() {
249
+ this.cancelBubble = true;
250
+ }
251
+ stopImmediatePropagation() {
252
+ this.cancelBubble = true;
253
+ this.immediateStopped = true;
254
+ }
255
+ get _immediateStopped() {
256
+ return this.immediateStopped;
257
+ }
258
+ composedPath() {
259
+ return this.target == null ? [] : [this.target];
260
+ }
261
+ };
262
+ var MiniCustomEvent = class extends MiniEvent {
263
+ constructor(type, init = {}) {
264
+ super(type, init);
265
+ __publicField(this, "detail");
266
+ this.detail = init.detail;
267
+ }
268
+ };
269
+ var MiniPointerEvent = class extends MiniEvent {
270
+ constructor(type, init = {}) {
271
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r;
272
+ super(type, init);
273
+ __publicField(this, "pointerId");
274
+ __publicField(this, "pointerType");
275
+ __publicField(this, "isPrimary");
276
+ __publicField(this, "clientX");
277
+ __publicField(this, "clientY");
278
+ __publicField(this, "pageX");
279
+ __publicField(this, "pageY");
280
+ __publicField(this, "offsetX");
281
+ __publicField(this, "offsetY");
282
+ __publicField(this, "button");
283
+ __publicField(this, "buttons");
284
+ __publicField(this, "ctrlKey");
285
+ __publicField(this, "shiftKey");
286
+ __publicField(this, "altKey");
287
+ __publicField(this, "metaKey");
288
+ __publicField(this, "width");
289
+ __publicField(this, "height");
290
+ __publicField(this, "pressure");
291
+ this.pointerId = (_a = init.pointerId) != null ? _a : 1;
292
+ this.pointerType = (_b = init.pointerType) != null ? _b : "touch";
293
+ this.isPrimary = (_c = init.isPrimary) != null ? _c : true;
294
+ this.clientX = (_d = init.clientX) != null ? _d : 0;
295
+ this.clientY = (_e = init.clientY) != null ? _e : 0;
296
+ this.pageX = (_f = init.pageX) != null ? _f : this.clientX;
297
+ this.pageY = (_g = init.pageY) != null ? _g : this.clientY;
298
+ this.offsetX = (_h = init.offsetX) != null ? _h : this.clientX;
299
+ this.offsetY = (_i = init.offsetY) != null ? _i : this.clientY;
300
+ this.button = (_j = init.button) != null ? _j : 0;
301
+ this.buttons = (_k = init.buttons) != null ? _k : 0;
302
+ this.ctrlKey = (_l = init.ctrlKey) != null ? _l : false;
303
+ this.shiftKey = (_m = init.shiftKey) != null ? _m : false;
304
+ this.altKey = (_n = init.altKey) != null ? _n : false;
305
+ this.metaKey = (_o = init.metaKey) != null ? _o : false;
306
+ this.width = (_p = init.width) != null ? _p : 1;
307
+ this.height = (_q = init.height) != null ? _q : 1;
308
+ this.pressure = (_r = init.pressure) != null ? _r : 0.5;
309
+ }
310
+ };
311
+ var MiniMouseEvent = class extends MiniPointerEvent {
312
+ constructor(type, init = {}) {
313
+ super(type, { pointerType: "mouse", ...init });
314
+ }
315
+ };
316
+ var MiniMessageEvent = class extends MiniEvent {
317
+ constructor(type, init = {}) {
318
+ super(type, init);
319
+ __publicField(this, "data");
320
+ __publicField(this, "origin", "");
321
+ __publicField(this, "lastEventId", "");
322
+ this.data = init.data;
323
+ }
324
+ };
325
+ var MiniProgressEvent = class extends MiniEvent {
326
+ constructor(type, init = {}) {
327
+ var _a, _b, _c;
328
+ super(type, init);
329
+ __publicField(this, "lengthComputable");
330
+ __publicField(this, "loaded");
331
+ __publicField(this, "total");
332
+ this.lengthComputable = (_a = init.lengthComputable) != null ? _a : false;
333
+ this.loaded = (_b = init.loaded) != null ? _b : 0;
334
+ this.total = (_c = init.total) != null ? _c : 0;
335
+ }
336
+ };
337
+ var MiniDOMException = class extends Error {
338
+ constructor(message = "", name = "Error") {
339
+ super(message);
340
+ __publicField(this, "name");
341
+ this.name = name;
342
+ }
343
+ };
344
+ var MiniEventTarget = class {
345
+ constructor() {
346
+ __publicField(this, "listeners", /* @__PURE__ */ new Map());
347
+ }
348
+ addEventListener(type, listener, options) {
349
+ if (!listener) return;
350
+ let set = this.listeners.get(type);
351
+ if (!set) {
352
+ set = /* @__PURE__ */ new Set();
353
+ this.listeners.set(type, set);
354
+ }
355
+ const once = typeof options === "object" && options !== null ? Boolean(options.once) : false;
356
+ set.add({ listener, once });
357
+ }
358
+ removeEventListener(type, listener, _options) {
359
+ if (!listener) return;
360
+ const set = this.listeners.get(type);
361
+ if (!set) return;
362
+ for (const record of set) {
363
+ if (record.listener === listener) set.delete(record);
364
+ }
365
+ if (set.size === 0) this.listeners.delete(type);
366
+ }
367
+ dispatchEvent(event) {
368
+ const ev = event;
369
+ if (!ev || typeof ev.type !== "string") return true;
370
+ if (ev.target == null) ev.target = this;
371
+ ev.currentTarget = this;
372
+ const set = this.listeners.get(ev.type);
373
+ if (set) {
374
+ for (const record of Array.from(set)) {
375
+ if (record.once) set.delete(record);
376
+ if (typeof record.listener === "function") record.listener.call(this, ev);
377
+ else record.listener.handleEvent(ev);
378
+ if (ev instanceof MiniEvent && ev._immediateStopped) break;
379
+ }
380
+ if (set.size === 0) this.listeners.delete(ev.type);
381
+ }
382
+ const inline = this["on" + ev.type];
383
+ if (typeof inline === "function") inline.call(this, ev);
384
+ ev.currentTarget = null;
385
+ return !ev.defaultPrevented;
386
+ }
387
+ /** Remove every listener. Called by `Runtime.dispose()`. */
388
+ clearEventListeners() {
389
+ this.listeners.clear();
390
+ }
391
+ };
392
+ function patchEventTarget(target) {
393
+ const own = new MiniEventTarget();
394
+ const methods = ["addEventListener", "removeEventListener", "dispatchEvent", "clearEventListeners"];
395
+ for (const key of methods) {
396
+ const fn = own[key];
397
+ Object.defineProperty(target, key, {
398
+ value: typeof fn === "function" ? fn.bind(own) : fn,
399
+ writable: true,
400
+ configurable: true,
401
+ enumerable: false
402
+ });
403
+ }
404
+ return target;
405
+ }
406
+
407
+ // src/polyfills/text-encoding.ts
408
+ function atob(data) {
409
+ var _a;
410
+ const bytes = base64ToBytes(String(data));
411
+ let out = "";
412
+ for (let i = 0; i < bytes.length; i++) out += String.fromCharCode((_a = bytes[i]) != null ? _a : 0);
413
+ return out;
414
+ }
415
+ function btoa(data) {
416
+ const bytes = new Uint8Array(data.length);
417
+ for (let i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i) & 255;
418
+ return bytesToBase64(bytes);
419
+ }
420
+ var MiniTextEncoder = class {
421
+ constructor() {
422
+ __publicField(this, "encoding", "utf-8");
423
+ }
424
+ encode(input = "") {
425
+ const bytes = [];
426
+ for (let i = 0; i < input.length; i++) {
427
+ let cp = input.charCodeAt(i);
428
+ if (cp >= 55296 && cp <= 56319 && i + 1 < input.length) {
429
+ const low = input.charCodeAt(i + 1);
430
+ if (low >= 56320 && low <= 57343) {
431
+ cp = 65536 + (cp - 55296 << 10) + (low - 56320);
432
+ i++;
433
+ }
434
+ }
435
+ if (cp < 128) bytes.push(cp);
436
+ else if (cp < 2048) bytes.push(192 | cp >> 6, 128 | cp & 63);
437
+ else if (cp < 65536) bytes.push(224 | cp >> 12, 128 | cp >> 6 & 63, 128 | cp & 63);
438
+ else bytes.push(240 | cp >> 18, 128 | cp >> 12 & 63, 128 | cp >> 6 & 63, 128 | cp & 63);
439
+ }
440
+ return new Uint8Array(bytes);
441
+ }
442
+ encodeInto(source, destination) {
443
+ const bytes = this.encode(source);
444
+ const n = Math.min(bytes.length, destination.length);
445
+ destination.set(bytes.subarray(0, n));
446
+ return { read: n === bytes.length ? source.length : source.length, written: n };
447
+ }
448
+ };
449
+ var MiniTextDecoder = class {
450
+ constructor(label = "utf-8", options = {}) {
451
+ __publicField(this, "encoding");
452
+ __publicField(this, "fatal");
453
+ __publicField(this, "ignoreBOM");
454
+ var _a, _b;
455
+ this.encoding = (label || "utf-8").toLowerCase();
456
+ this.fatal = (_a = options.fatal) != null ? _a : false;
457
+ this.ignoreBOM = (_b = options.ignoreBOM) != null ? _b : false;
458
+ }
459
+ decode(input, _options = {}) {
460
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
461
+ let bytes;
462
+ if (!input) bytes = new Uint8Array(0);
463
+ else if (input instanceof ArrayBuffer) bytes = new Uint8Array(input);
464
+ else bytes = new Uint8Array(input.buffer, input.byteOffset, input.byteLength);
465
+ if (this.encoding === "ascii" || this.encoding === "latin1" || this.encoding === "iso-8859-1") {
466
+ let out2 = "";
467
+ for (let i = 0; i < bytes.length; i++) out2 += String.fromCharCode((_a = bytes[i]) != null ? _a : 0);
468
+ return out2;
469
+ }
470
+ if (this.encoding === "utf-16le" || this.encoding === "utf-16") {
471
+ let out2 = "";
472
+ for (let i = 0; i + 1 < bytes.length; i += 2) out2 += String.fromCharCode(((_b = bytes[i]) != null ? _b : 0) | ((_c = bytes[i + 1]) != null ? _c : 0) << 8);
473
+ return out2;
474
+ }
475
+ let start = 0;
476
+ if (!this.ignoreBOM && bytes.length >= 3 && bytes[0] === 239 && bytes[1] === 187 && bytes[2] === 191) start = 3;
477
+ let out = "";
478
+ for (let i = start; i < bytes.length; i++) {
479
+ const a = (_d = bytes[i]) != null ? _d : 0;
480
+ if (a < 128) out += String.fromCharCode(a);
481
+ else if (a < 224) out += String.fromCharCode((a & 31) << 6 | ((_e = bytes[++i]) != null ? _e : 0) & 63);
482
+ else if (a < 240) {
483
+ const b = (_f = bytes[++i]) != null ? _f : 0;
484
+ const c = (_g = bytes[++i]) != null ? _g : 0;
485
+ out += String.fromCharCode((a & 15) << 12 | (b & 63) << 6 | c & 63);
486
+ } else {
487
+ const b = (_h = bytes[++i]) != null ? _h : 0;
488
+ const c = (_i = bytes[++i]) != null ? _i : 0;
489
+ const d = (_j = bytes[++i]) != null ? _j : 0;
490
+ const cp = (a & 7) << 18 | (b & 63) << 12 | (c & 63) << 6 | d & 63;
491
+ const v = cp - 65536;
492
+ out += String.fromCharCode(55296 + (v >> 10), 56320 + (v & 1023));
493
+ }
494
+ }
495
+ return out;
496
+ }
497
+ };
498
+
499
+ // src/polyfills/network.ts
500
+ function createHeaders(init) {
501
+ const map = /* @__PURE__ */ new Map();
502
+ for (const [k, v] of Object.entries(init != null ? init : {})) map.set(k.toLowerCase(), v);
503
+ return {
504
+ get: (name) => {
505
+ var _a;
506
+ return (_a = map.get(name.toLowerCase())) != null ? _a : null;
507
+ },
508
+ has: (name) => map.has(name.toLowerCase()),
509
+ forEach: (cb) => map.forEach((value, key) => cb(value, key)),
510
+ [Symbol.iterator]: () => map.entries()
511
+ };
512
+ }
513
+ function toArrayBuffer(data) {
514
+ if (data instanceof ArrayBuffer) return data;
515
+ if (ArrayBuffer.isView(data)) {
516
+ const view = data;
517
+ return view.buffer.slice(view.byteOffset, view.byteOffset + view.byteLength);
518
+ }
519
+ if (typeof data === "string") {
520
+ const bytes = new Uint8Array(data.length);
521
+ for (let i = 0; i < data.length; i++) bytes[i] = data.charCodeAt(i) & 255;
522
+ return bytes.buffer;
523
+ }
524
+ const encoded = new MiniTextEncoder().encode(JSON.stringify(data));
525
+ return encoded.buffer.slice(encoded.byteOffset, encoded.byteOffset + encoded.byteLength);
526
+ }
527
+ function makeResponse(url, result) {
528
+ const buffer = toArrayBuffer(result.data);
529
+ let used = false;
530
+ const status = result.statusCode;
531
+ const build = () => ({
532
+ ok: status >= 200 && status < 300,
533
+ status,
534
+ statusText: "",
535
+ url,
536
+ headers: createHeaders(result.header),
537
+ get bodyUsed() {
538
+ return used;
539
+ },
540
+ async arrayBuffer() {
541
+ used = true;
542
+ return buffer.slice(0);
543
+ },
544
+ async text() {
545
+ used = true;
546
+ return new MiniTextDecoder().decode(buffer);
547
+ },
548
+ async json() {
549
+ used = true;
550
+ return JSON.parse(new MiniTextDecoder().decode(buffer));
551
+ },
552
+ async blob() {
553
+ var _a;
554
+ used = true;
555
+ return new MiniBlob([new Uint8Array(buffer)], {
556
+ type: (_a = createHeaders(result.header).get("content-type")) != null ? _a : ""
557
+ });
558
+ },
559
+ clone: () => build()
560
+ });
561
+ return build();
562
+ }
563
+ function createFetch(wx) {
564
+ if (typeof wx.request !== "function") {
565
+ const native = globalThis.fetch;
566
+ if (typeof native === "function") return (input, init) => native(input, init);
567
+ return async () => {
568
+ throw new Error("[mini-three-adapter] no wx.request and no native fetch available");
569
+ };
570
+ }
571
+ return (input, init = {}) => new Promise((resolve, reject) => {
572
+ var _a, _b, _c;
573
+ const task = (_b = wx.request) == null ? void 0 : _b.call(wx, {
574
+ url: input,
575
+ method: (_a = init.method) != null ? _a : "GET",
576
+ header: init.headers,
577
+ data: init.body,
578
+ responseType: "arraybuffer",
579
+ success: (result) => resolve(makeResponse(input, result)),
580
+ fail: (error) => {
581
+ var _a2;
582
+ return reject(new Error((_a2 = error.errMsg) != null ? _a2 : `wx.request failed: ${input}`));
583
+ }
584
+ });
585
+ if ((_c = init.signal) == null ? void 0 : _c.addEventListener) {
586
+ init.signal.addEventListener("abort", () => {
587
+ var _a2;
588
+ return (_a2 = task == null ? void 0 : task.abort) == null ? void 0 : _a2.call(task);
589
+ });
590
+ }
591
+ });
592
+ }
593
+ var MiniAbortSignal = class extends MiniEventTarget {
594
+ constructor() {
595
+ super(...arguments);
596
+ __publicField(this, "aborted", false);
597
+ __publicField(this, "reason");
598
+ }
599
+ throwIfAborted() {
600
+ var _a;
601
+ if (this.aborted) throw (_a = this.reason) != null ? _a : new Error("Aborted");
602
+ }
603
+ };
604
+ var MiniAbortController = class {
605
+ constructor() {
606
+ __publicField(this, "signal", new MiniAbortSignal());
607
+ }
608
+ abort(reason) {
609
+ if (this.signal.aborted) return;
610
+ this.signal.aborted = true;
611
+ this.signal.reason = reason != null ? reason : new Error("Aborted");
612
+ this.signal.dispatchEvent({ type: "abort", target: this.signal });
613
+ }
614
+ };
615
+ var MiniXMLHttpRequest = class extends MiniEventTarget {
616
+ constructor(wx) {
617
+ super();
618
+ __publicField(this, "wx", wx);
619
+ __publicField(this, "readyState", 0);
620
+ __publicField(this, "status", 0);
621
+ __publicField(this, "statusText", "");
622
+ __publicField(this, "response", null);
623
+ __publicField(this, "responseText", "");
624
+ __publicField(this, "responseType", "");
625
+ __publicField(this, "responseURL", "");
626
+ __publicField(this, "timeout", 0);
627
+ __publicField(this, "withCredentials", false);
628
+ __publicField(this, "onreadystatechange", null);
629
+ __publicField(this, "onload", null);
630
+ __publicField(this, "onerror", null);
631
+ __publicField(this, "onprogress", null);
632
+ __publicField(this, "onabort", null);
633
+ __publicField(this, "method", "GET");
634
+ __publicField(this, "url", "");
635
+ __publicField(this, "headers", {});
636
+ __publicField(this, "body");
637
+ }
638
+ open(method, url) {
639
+ this.method = method;
640
+ this.url = url;
641
+ this.responseURL = url;
642
+ this.readyState = 1;
643
+ }
644
+ setRequestHeader(name, value) {
645
+ this.headers[name] = value;
646
+ }
647
+ getAllResponseHeaders() {
648
+ return "";
649
+ }
650
+ send(body) {
651
+ this.body = body;
652
+ if (typeof this.wx.request !== "function") {
653
+ this.fail(new Error("wx.request unavailable"));
654
+ return;
655
+ }
656
+ this.wx.request({
657
+ url: this.url,
658
+ method: this.method,
659
+ header: this.headers,
660
+ data: this.body,
661
+ responseType: this.responseType === "arraybuffer" ? "arraybuffer" : "text",
662
+ success: (result) => {
663
+ var _a, _b;
664
+ this.status = result.statusCode;
665
+ const buffer = toArrayBuffer(result.data);
666
+ this.response = this.responseType === "arraybuffer" ? buffer : new MiniTextDecoder().decode(buffer);
667
+ this.responseText = typeof this.response === "string" ? this.response : "";
668
+ this.readyState = 4;
669
+ (_a = this.onreadystatechange) == null ? void 0 : _a.call(this, { type: "readystatechange" });
670
+ this.dispatchEvent(new MiniProgressEvent("progress", { loaded: buffer.byteLength, total: buffer.byteLength, lengthComputable: true }));
671
+ (_b = this.onload) == null ? void 0 : _b.call(this, { type: "load" });
672
+ this.dispatchEvent({ type: "load", target: this });
673
+ this.dispatchEvent({ type: "loadend", target: this });
674
+ },
675
+ fail: (error) => {
676
+ var _a;
677
+ return this.fail(new Error((_a = error.errMsg) != null ? _a : "wx.request failed"));
678
+ }
679
+ });
680
+ }
681
+ abort() {
682
+ var _a;
683
+ this.readyState = 4;
684
+ (_a = this.onabort) == null ? void 0 : _a.call(this, { type: "abort" });
685
+ this.dispatchEvent({ type: "abort", target: this });
686
+ }
687
+ fail(error) {
688
+ var _a;
689
+ this.status = 0;
690
+ this.readyState = 4;
691
+ (_a = this.onerror) == null ? void 0 : _a.call(this, error);
692
+ this.dispatchEvent({ type: "error", target: this });
693
+ this.dispatchEvent({ type: "loadend", target: this });
694
+ }
695
+ };
696
+ __publicField(MiniXMLHttpRequest, "UNSENT", 0);
697
+ __publicField(MiniXMLHttpRequest, "OPENED", 1);
698
+ __publicField(MiniXMLHttpRequest, "HEADERS_RECEIVED", 2);
699
+ __publicField(MiniXMLHttpRequest, "LOADING", 3);
700
+ __publicField(MiniXMLHttpRequest, "DONE", 4);
701
+ function createXMLHttpRequestFactory(wx) {
702
+ return class extends MiniXMLHttpRequest {
703
+ constructor() {
704
+ super(wx);
705
+ }
706
+ };
707
+ }
708
+
709
+ 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 };
710
+ //# sourceMappingURL=chunk-4UEBRAK6.js.map
711
+ //# sourceMappingURL=chunk-4UEBRAK6.js.map