mini-three-adapter 0.1.5 → 0.1.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/AGENTS.md +1 -1
- package/README.md +1 -1
- package/dist/build/rollup.d.ts +2 -2
- package/dist/build/rollup.js.map +1 -1
- package/dist/build/vite.d.ts +2 -2
- package/dist/build/vite.js.map +1 -1
- package/dist/{chunk-F7CSLEUI.js → chunk-7XOHQFZ6.js} +43 -4
- package/dist/chunk-7XOHQFZ6.js.map +1 -0
- package/dist/{chunk-LE4FRYNG.js → chunk-DDCQIBWW.js} +4 -4
- package/dist/{chunk-LE4FRYNG.js.map → chunk-DDCQIBWW.js.map} +1 -1
- package/dist/{chunk-ZB3AYNOS.js → chunk-FQ2GOIOE.js} +4 -4
- package/dist/{chunk-ZB3AYNOS.js.map → chunk-FQ2GOIOE.js.map} +1 -1
- package/dist/{chunk-VA7SZFLN.js → chunk-HKT54DDM.js} +3 -3
- package/dist/{chunk-VA7SZFLN.js.map → chunk-HKT54DDM.js.map} +1 -1
- package/dist/{chunk-LCJNTN6F.js → chunk-U3P3XHA3.js} +8 -5
- package/dist/chunk-U3P3XHA3.js.map +1 -0
- package/dist/{chunk-ZFJLEEF4.js → chunk-V64V4HIZ.js} +111 -58
- package/dist/chunk-V64V4HIZ.js.map +1 -0
- package/dist/core/index.d.ts +9 -3
- package/dist/core/index.js +2 -2
- package/dist/index.d.ts +2 -2
- 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/{plugin-core-BuqW9C-L.d.ts → plugin-core-CBOr1cyv.d.ts} +15 -4
- package/dist/polyfills/index.d.ts +1 -1
- package/dist/polyfills/index.js +1 -1
- package/dist/{runtime-BrHExTjl.d.ts → runtime-C8_xIlDM.d.ts} +29 -1
- package/dist/scope.d.ts +1 -1
- package/dist/{types-X_5SJh4y.d.ts → types-DOoJ7noL.d.ts} +13 -1
- package/docs/03-module-map.md +7 -7
- package/docs/04-api-reference.md +12 -6
- package/docs/06-platform-notes.md +15 -1
- package/docs/07-integration-guide.md +2 -1
- package/docs/09-testing-and-release.md +5 -3
- package/docs/11-compat-matrix.md +3 -3
- package/docs/adr/0010-native-event-target-boundary.md +82 -0
- package/docs/adr/README.md +1 -0
- package/package.json +3 -2
- package/dist/chunk-F7CSLEUI.js.map +0 -1
- package/dist/chunk-LCJNTN6F.js.map +0 -1
- package/dist/chunk-ZFJLEEF4.js.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { createScope, setActiveScope, getEarlyScopeReads, clearEarlyScopeReads, hasActiveScope, getActiveScope, installGlobals } from './chunk-35XVAVDB.js';
|
|
2
|
-
import { patchEventTarget, MiniEventTarget,
|
|
2
|
+
import { patchEventTarget, MiniEventTarget, MiniPointerEvent, MiniMouseEvent, atob, btoa, MiniEvent, MiniCustomEvent, MiniMessageEvent, MiniProgressEvent, MiniDOMException, MiniBlob, MiniURL, MiniTextDecoder, MiniTextEncoder, MiniAbortController, MiniAbortSignal, createFetch, createXMLHttpRequestFactory } from './chunk-U3P3XHA3.js';
|
|
3
3
|
import { __publicField } from './chunk-V6TY7KAL.js';
|
|
4
4
|
|
|
5
5
|
// src/core/diagnostics.ts
|
|
@@ -96,6 +96,7 @@ function patchElement(instance, options) {
|
|
|
96
96
|
throw new TypeError("[mini-three-adapter] patchElement expects an object");
|
|
97
97
|
}
|
|
98
98
|
let rect = { ...options.rect };
|
|
99
|
+
const native = options.nativeEventTarget === true;
|
|
99
100
|
const style = {};
|
|
100
101
|
define(style, "width", { get: () => `${rect.width}px`, set: (v) => {
|
|
101
102
|
const n = Number.parseFloat(String(v));
|
|
@@ -111,36 +112,40 @@ function patchElement(instance, options) {
|
|
|
111
112
|
} });
|
|
112
113
|
style.cursor = "default";
|
|
113
114
|
style.touchAction = "none";
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
115
|
+
const defineMember = (key, descriptor) => {
|
|
116
|
+
if (native && key in instance) return;
|
|
117
|
+
define(instance, key, descriptor);
|
|
118
|
+
};
|
|
119
|
+
defineMember("style", { value: style, writable: true });
|
|
120
|
+
defineMember("clientTop", { get: () => 0 });
|
|
121
|
+
defineMember("clientLeft", { get: () => 0 });
|
|
122
|
+
defineMember("clientWidth", { get: () => rect.width });
|
|
123
|
+
defineMember("clientHeight", { get: () => rect.height });
|
|
124
|
+
defineMember("offsetTop", { get: () => rect.top });
|
|
125
|
+
defineMember("offsetLeft", { get: () => rect.left });
|
|
126
|
+
defineMember("offsetWidth", { get: () => rect.width });
|
|
127
|
+
defineMember("offsetHeight", { get: () => rect.height });
|
|
128
|
+
defineMember("getBoundingClientRect", { value: () => ({ ...rect }), writable: true });
|
|
129
|
+
defineMember("setAttribute", { value: (name, value) => {
|
|
125
130
|
var _a2;
|
|
126
131
|
(_a2 = options.onSetAttribute) == null ? void 0 : _a2.call(options, name, value, instance);
|
|
127
132
|
}, writable: true });
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
133
|
+
defineMember("removeAttribute", { value: () => void 0, writable: true });
|
|
134
|
+
defineMember("ownerDocument", { value: (_a = options.document) != null ? _a : null, writable: true });
|
|
135
|
+
defineMember("getRootNode", { value: () => {
|
|
131
136
|
var _a2;
|
|
132
137
|
return (_a2 = options.document) != null ? _a2 : instance;
|
|
133
138
|
}, writable: true });
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
patchEventTarget(instance);
|
|
139
|
+
defineMember("setPointerCapture", { value: () => void 0, writable: true });
|
|
140
|
+
defineMember("releasePointerCapture", { value: () => void 0, writable: true });
|
|
141
|
+
defineMember("hasPointerCapture", { value: () => false, writable: true });
|
|
142
|
+
defineMember("requestPointerLock", { value: () => void 0, writable: true });
|
|
143
|
+
defineMember("exitPointerLock", { value: () => void 0, writable: true });
|
|
144
|
+
defineMember("focus", { value: () => void 0, writable: true });
|
|
145
|
+
defineMember("blur", { value: () => void 0, writable: true });
|
|
146
|
+
defineMember("scrollTop", { get: () => 0, set: () => void 0 });
|
|
147
|
+
defineMember("scrollLeft", { get: () => 0, set: () => void 0 });
|
|
148
|
+
if (!native) patchEventTarget(instance);
|
|
144
149
|
if (options.extra) {
|
|
145
150
|
for (const [key, descriptor] of Object.entries(options.extra)) {
|
|
146
151
|
define(instance, key, descriptor);
|
|
@@ -250,18 +255,27 @@ function patchCanvas(raw, options = {}) {
|
|
|
250
255
|
if (typeof raw.toDataURL === "function") return raw.toDataURL(type, quality);
|
|
251
256
|
return "data:,";
|
|
252
257
|
};
|
|
258
|
+
const native = options.nativeEventTarget === true;
|
|
259
|
+
const extra = {
|
|
260
|
+
// Context caching and WebGL normalisation stay ours even on a real canvas:
|
|
261
|
+
// the native getContext is re-read through findOriginalGetContext, so
|
|
262
|
+
// identity and behaviour are unchanged for the host.
|
|
263
|
+
getContext: { value: getContext, writable: true }
|
|
264
|
+
};
|
|
265
|
+
if (!native) {
|
|
266
|
+
extra.toDataURL = { value: toDataURL, writable: true };
|
|
267
|
+
extra.nodeType = { value: 1 };
|
|
268
|
+
extra.tagName = { value: "CANVAS" };
|
|
269
|
+
extra.nodeName = { value: "CANVAS" };
|
|
270
|
+
} else if (typeof raw.toDataURL !== "function") {
|
|
271
|
+
extra.toDataURL = { value: toDataURL, writable: true };
|
|
272
|
+
}
|
|
253
273
|
const patched = patchElement(raw, {
|
|
254
274
|
rect: normalizeRect(options.rect),
|
|
255
275
|
document: options.document,
|
|
256
276
|
instanceOf: [HTMLCanvasElementShim, HTMLElementShim],
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
toDataURL: { value: toDataURL, writable: true },
|
|
260
|
-
// three.js reads `canvas.nodeType` / `canvas.tagName` in a few addons.
|
|
261
|
-
nodeType: { value: 1 },
|
|
262
|
-
tagName: { value: "CANVAS" },
|
|
263
|
-
nodeName: { value: "CANVAS" }
|
|
264
|
-
}
|
|
277
|
+
nativeEventTarget: native,
|
|
278
|
+
extra
|
|
265
279
|
});
|
|
266
280
|
return {
|
|
267
281
|
...patched,
|
|
@@ -351,7 +365,8 @@ function createDocument(options) {
|
|
|
351
365
|
rect: { width: raw.width, height: raw.height, left: 0, top: 0, right: raw.width, bottom: raw.height },
|
|
352
366
|
document,
|
|
353
367
|
diagnostics,
|
|
354
|
-
normalizeWebGL: true
|
|
368
|
+
normalizeWebGL: true,
|
|
369
|
+
nativeEventTarget: binding.nativeEventTarget === true
|
|
355
370
|
});
|
|
356
371
|
OffscreenCanvasShim.__instances.add(raw);
|
|
357
372
|
return patched.canvas;
|
|
@@ -421,7 +436,8 @@ function createOffscreenCanvasCtor(binding) {
|
|
|
421
436
|
const raw = binding.createOffscreenCanvas(width, height, "2d");
|
|
422
437
|
const patched = patchCanvas(raw, {
|
|
423
438
|
rect: { width, height, left: 0, top: 0, right: width, bottom: height },
|
|
424
|
-
normalizeWebGL: true
|
|
439
|
+
normalizeWebGL: true,
|
|
440
|
+
nativeEventTarget: binding.nativeEventTarget === true
|
|
425
441
|
});
|
|
426
442
|
OffscreenCanvasShim.__instances.add(raw);
|
|
427
443
|
return patched.canvas;
|
|
@@ -517,6 +533,16 @@ function toArrayLike(value) {
|
|
|
517
533
|
if (!value) return [];
|
|
518
534
|
return Array.prototype.slice.call(value);
|
|
519
535
|
}
|
|
536
|
+
function normalizeMouseType(raw) {
|
|
537
|
+
if (raw === "wheel") return "wheel";
|
|
538
|
+
return raw.startsWith("mouse") ? raw : `mouse${raw}`;
|
|
539
|
+
}
|
|
540
|
+
function writeExtra(target, key, value) {
|
|
541
|
+
try {
|
|
542
|
+
target[key] = value;
|
|
543
|
+
} catch {
|
|
544
|
+
}
|
|
545
|
+
}
|
|
520
546
|
var PointerBridge = class {
|
|
521
547
|
constructor(options) {
|
|
522
548
|
__publicField(this, "options", options);
|
|
@@ -613,7 +639,7 @@ var PointerBridge = class {
|
|
|
613
639
|
this.emit(pointerType, id, init);
|
|
614
640
|
if (this.options.emitMouseEvents !== false) {
|
|
615
641
|
const mouseType = (_f = MOUSE_TYPE_MAP[pointerType]) != null ? _f : "mouseup";
|
|
616
|
-
const mouse =
|
|
642
|
+
const mouse = this.makeMouse(mouseType, {
|
|
617
643
|
...init,
|
|
618
644
|
button: pointerType === "pointerdown" ? 0 : 0,
|
|
619
645
|
buttons,
|
|
@@ -633,7 +659,7 @@ var PointerBridge = class {
|
|
|
633
659
|
const point = points[0];
|
|
634
660
|
if (point) {
|
|
635
661
|
const coords = this.toCoords(point, event);
|
|
636
|
-
this.fanout(
|
|
662
|
+
this.fanout(this.makeMouse("click", {
|
|
637
663
|
pointerId: 1,
|
|
638
664
|
clientX: coords.x,
|
|
639
665
|
clientY: coords.y,
|
|
@@ -647,12 +673,12 @@ var PointerBridge = class {
|
|
|
647
673
|
}
|
|
648
674
|
/** Convenience for mouse events coming from WeChat devtools / PC. */
|
|
649
675
|
dispatchMouse(event) {
|
|
650
|
-
var _a, _b, _c, _d, _e, _f;
|
|
676
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
651
677
|
const rect = this.rect;
|
|
652
678
|
const x = (_b = (_a = event.clientX) != null ? _a : event.x) != null ? _b : 0;
|
|
653
679
|
const y = (_d = (_c = event.clientY) != null ? _c : event.y) != null ? _d : 0;
|
|
654
|
-
const type = event.type
|
|
655
|
-
const mouse =
|
|
680
|
+
const type = normalizeMouseType(event.type);
|
|
681
|
+
const mouse = this.makeMouse(type, {
|
|
656
682
|
pointerId: 1,
|
|
657
683
|
clientX: x,
|
|
658
684
|
clientY: y,
|
|
@@ -660,9 +686,13 @@ var PointerBridge = class {
|
|
|
660
686
|
offsetY: y - rect.top,
|
|
661
687
|
button: (_e = event.button) != null ? _e : 0,
|
|
662
688
|
buttons: type === "mouseup" ? 0 : 1,
|
|
663
|
-
pointerType: "mouse"
|
|
689
|
+
pointerType: "mouse",
|
|
690
|
+
...type === "wheel" ? { deltaY: (_f = event.deltaY) != null ? _f : 0, deltaMode: (_g = event.deltaMode) != null ? _g : 0 } : {}
|
|
664
691
|
});
|
|
665
|
-
|
|
692
|
+
if (type === "wheel") {
|
|
693
|
+
writeExtra(mouse, "deltaY", (_h = event.deltaY) != null ? _h : 0);
|
|
694
|
+
writeExtra(mouse, "wheelDelta", (_i = event.deltaY) != null ? _i : 0);
|
|
695
|
+
}
|
|
666
696
|
this.fanout(mouse, 1);
|
|
667
697
|
}
|
|
668
698
|
dispose() {
|
|
@@ -705,19 +735,30 @@ var PointerBridge = class {
|
|
|
705
735
|
return { x, y, offsetX: x - this.rect.left, offsetY: y - this.rect.top };
|
|
706
736
|
}
|
|
707
737
|
emit(type, pointerId, init = {}) {
|
|
708
|
-
|
|
738
|
+
this.fanout(this.makePointer(type, { ...init, pointerId }), pointerId);
|
|
739
|
+
}
|
|
740
|
+
makePointer(type, init) {
|
|
741
|
+
if (this.options.createEvent) return this.options.createEvent(type, init);
|
|
742
|
+
const ev = new MiniPointerEvent(type, init);
|
|
709
743
|
ev.target = this.options.targets.element;
|
|
710
|
-
|
|
744
|
+
return ev;
|
|
745
|
+
}
|
|
746
|
+
makeMouse(type, init) {
|
|
747
|
+
if (this.options.createEvent) return this.options.createEvent(type, init);
|
|
748
|
+
const ev = new MiniMouseEvent(type, init);
|
|
749
|
+
ev.target = this.options.targets.element;
|
|
750
|
+
return ev;
|
|
711
751
|
}
|
|
712
752
|
fanout(event, pointerId, propagateOverride) {
|
|
713
753
|
var _a;
|
|
754
|
+
const native = this.options.nativeEventTarget === true;
|
|
714
755
|
const propagate = (_a = propagateOverride != null ? propagateOverride : this.options.propagate) != null ? _a : true;
|
|
715
756
|
const captured = this.captured.get(pointerId);
|
|
716
|
-
const targets = captured ? [captured] : [this.options.targets.element, this.options.targets.document, this.options.targets.window];
|
|
757
|
+
const targets = captured ? [captured] : native ? [this.options.targets.element] : [this.options.targets.element, this.options.targets.document, this.options.targets.window];
|
|
717
758
|
for (const target of targets) {
|
|
718
759
|
if (!target) continue;
|
|
719
760
|
if (!propagate && target !== this.options.targets.element && target !== captured) continue;
|
|
720
|
-
event.currentTarget = target;
|
|
761
|
+
if (!native) event.currentTarget = target;
|
|
721
762
|
target.dispatchEvent(event);
|
|
722
763
|
if (event.cancelBubble) break;
|
|
723
764
|
}
|
|
@@ -830,12 +871,14 @@ async function createRuntime(platform, options = {}) {
|
|
|
830
871
|
defaultContextType: (_c = options.defaultContextType) != null ? _c : "webgl2",
|
|
831
872
|
documentRef
|
|
832
873
|
});
|
|
874
|
+
const nativeEvents = binding.nativeEventTarget === true;
|
|
833
875
|
const patched = patchCanvas(binding.rawCanvas, {
|
|
834
876
|
rect: initialRect,
|
|
835
877
|
document,
|
|
836
878
|
diagnostics,
|
|
837
879
|
cacheContexts: (_d = options.cacheContexts) != null ? _d : true,
|
|
838
|
-
normalizeWebGL: (_e = options.normalizeWebGL) != null ? _e : true
|
|
880
|
+
normalizeWebGL: (_e = options.normalizeWebGL) != null ? _e : true,
|
|
881
|
+
nativeEventTarget: nativeEvents
|
|
839
882
|
});
|
|
840
883
|
const canvas = patched.canvas;
|
|
841
884
|
const windowInfo = createWindowInfoStore(wx, {
|
|
@@ -923,18 +966,23 @@ async function createRuntime(platform, options = {}) {
|
|
|
923
966
|
const host = globalThis;
|
|
924
967
|
scope.Worker = (_g = host.Worker) != null ? _g : void 0;
|
|
925
968
|
scope.WebAssembly = (_i = (_h = host.WebAssembly) != null ? _h : host.WXWebAssembly) != null ? _i : void 0;
|
|
969
|
+
const createEvent = nativeEvents && typeof binding.createEvent === "function" ? binding.createEvent.bind(binding) : void 0;
|
|
926
970
|
const bridge = new PointerBridge({
|
|
927
971
|
getRect: () => canvas.getBoundingClientRect(),
|
|
928
972
|
targets: { element: canvas, document, window: scope },
|
|
929
973
|
propagate: (_j = options.propagatePointerEvents) != null ? _j : true,
|
|
930
974
|
emitMouseEvents: (_k = options.emitMouseEvents) != null ? _k : true,
|
|
975
|
+
nativeEventTarget: nativeEvents,
|
|
976
|
+
...createEvent ? { createEvent } : {},
|
|
931
977
|
diagnostics
|
|
932
978
|
});
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
979
|
+
if (!nativeEvents) {
|
|
980
|
+
Object.defineProperties(canvas, {
|
|
981
|
+
setPointerCapture: { value: (id) => bridge.setPointerCapture(id, canvas), configurable: true },
|
|
982
|
+
releasePointerCapture: { value: (id) => bridge.releasePointerCapture(id), configurable: true },
|
|
983
|
+
hasPointerCapture: { value: (id) => bridge.activePointerCount > 0 && id >= 0, configurable: true }
|
|
984
|
+
});
|
|
985
|
+
}
|
|
938
986
|
const emitter = /* @__PURE__ */ new Map();
|
|
939
987
|
const emit = (name, ...args) => {
|
|
940
988
|
const set = emitter.get(name);
|
|
@@ -1019,7 +1067,8 @@ async function createRuntime(platform, options = {}) {
|
|
|
1019
1067
|
const p = patchCanvas(raw, {
|
|
1020
1068
|
rect: { width, height, left: 0, top: 0, right: width, bottom: height },
|
|
1021
1069
|
document,
|
|
1022
|
-
diagnostics
|
|
1070
|
+
diagnostics,
|
|
1071
|
+
nativeEventTarget: nativeEvents
|
|
1023
1072
|
});
|
|
1024
1073
|
return p.canvas;
|
|
1025
1074
|
},
|
|
@@ -1367,15 +1416,20 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1367
1416
|
if (watchdogId !== void 0) return;
|
|
1368
1417
|
watchdogId = setTimeout(() => {
|
|
1369
1418
|
watchdogId = void 0;
|
|
1419
|
+
if (hostComplete()) {
|
|
1420
|
+
finish("load", { type: "load", reason: "watchdog-complete" });
|
|
1421
|
+
return;
|
|
1422
|
+
}
|
|
1370
1423
|
forwardError({ type: "error", reason: "image-events-timeout", path: eventPath });
|
|
1371
1424
|
}, EVENT_WATCHDOG_MS);
|
|
1372
1425
|
};
|
|
1373
1426
|
const startFallback = (src) => {
|
|
1374
|
-
if (
|
|
1427
|
+
if (settled || failed || !src) return;
|
|
1428
|
+
armWatchdog();
|
|
1429
|
+
if (eventPath || fallbackStarted) return;
|
|
1375
1430
|
fallbackStarted = true;
|
|
1376
1431
|
if (getImageInfo) {
|
|
1377
1432
|
eventPath = "getImageInfo";
|
|
1378
|
-
armWatchdog();
|
|
1379
1433
|
try {
|
|
1380
1434
|
getImageInfo({
|
|
1381
1435
|
src,
|
|
@@ -1407,7 +1461,6 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1407
1461
|
return;
|
|
1408
1462
|
}
|
|
1409
1463
|
eventPath = "watchdog";
|
|
1410
|
-
armWatchdog();
|
|
1411
1464
|
};
|
|
1412
1465
|
onSrcChange = startFallback;
|
|
1413
1466
|
Object.defineProperty(raw, "crossOrigin", { value: "", writable: true, configurable: true });
|
|
@@ -1445,5 +1498,5 @@ function createImageFactory(wx, diagnostics) {
|
|
|
1445
1498
|
}
|
|
1446
1499
|
|
|
1447
1500
|
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 };
|
|
1448
|
-
//# sourceMappingURL=chunk-
|
|
1449
|
-
//# sourceMappingURL=chunk-
|
|
1501
|
+
//# sourceMappingURL=chunk-V64V4HIZ.js.map
|
|
1502
|
+
//# sourceMappingURL=chunk-V64V4HIZ.js.map
|