mini-three-adapter 0.1.6 → 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.
Files changed (45) hide show
  1. package/AGENTS.md +1 -1
  2. package/dist/build/rollup.d.ts +2 -2
  3. package/dist/build/rollup.js.map +1 -1
  4. package/dist/build/vite.d.ts +2 -2
  5. package/dist/build/vite.js.map +1 -1
  6. package/dist/{chunk-WYUHMKUM.js → chunk-7XOHQFZ6.js} +43 -4
  7. package/dist/chunk-7XOHQFZ6.js.map +1 -0
  8. package/dist/{chunk-6Y4MKIJL.js → chunk-DDCQIBWW.js} +4 -4
  9. package/dist/{chunk-6Y4MKIJL.js.map → chunk-DDCQIBWW.js.map} +1 -1
  10. package/dist/{chunk-L4QZ5SP6.js → chunk-FQ2GOIOE.js} +4 -4
  11. package/dist/{chunk-L4QZ5SP6.js.map → chunk-FQ2GOIOE.js.map} +1 -1
  12. package/dist/{chunk-MSP7V7KM.js → chunk-HKT54DDM.js} +3 -3
  13. package/dist/{chunk-MSP7V7KM.js.map → chunk-HKT54DDM.js.map} +1 -1
  14. package/dist/{chunk-LCJNTN6F.js → chunk-U3P3XHA3.js} +8 -5
  15. package/dist/chunk-U3P3XHA3.js.map +1 -0
  16. package/dist/{chunk-TDVL2OAV.js → chunk-V64V4HIZ.js} +104 -55
  17. package/dist/chunk-V64V4HIZ.js.map +1 -0
  18. package/dist/core/index.d.ts +9 -3
  19. package/dist/core/index.js +2 -2
  20. package/dist/index.d.ts +2 -2
  21. package/dist/index.js +6 -6
  22. package/dist/platforms/browser.d.ts +2 -2
  23. package/dist/platforms/browser.js +3 -3
  24. package/dist/platforms/wechat-game.d.ts +2 -2
  25. package/dist/platforms/wechat-game.js +4 -4
  26. package/dist/platforms/wechat-miniprogram.d.ts +2 -2
  27. package/dist/platforms/wechat-miniprogram.js +4 -4
  28. package/dist/{plugin-core-BuqW9C-L.d.ts → plugin-core-CBOr1cyv.d.ts} +15 -4
  29. package/dist/polyfills/index.d.ts +1 -1
  30. package/dist/polyfills/index.js +1 -1
  31. package/dist/{runtime-BrHExTjl.d.ts → runtime-C8_xIlDM.d.ts} +29 -1
  32. package/dist/scope.d.ts +1 -1
  33. package/dist/{types-X_5SJh4y.d.ts → types-DOoJ7noL.d.ts} +13 -1
  34. package/docs/03-module-map.md +7 -7
  35. package/docs/04-api-reference.md +10 -4
  36. package/docs/06-platform-notes.md +2 -1
  37. package/docs/07-integration-guide.md +2 -1
  38. package/docs/09-testing-and-release.md +3 -2
  39. package/docs/11-compat-matrix.md +2 -2
  40. package/docs/adr/0010-native-event-target-boundary.md +82 -0
  41. package/docs/adr/README.md +1 -0
  42. package/package.json +2 -1
  43. package/dist/chunk-LCJNTN6F.js.map +0 -1
  44. package/dist/chunk-TDVL2OAV.js.map +0 -1
  45. package/dist/chunk-WYUHMKUM.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, MiniMouseEvent, MiniPointerEvent, atob, btoa, MiniEvent, MiniCustomEvent, MiniMessageEvent, MiniProgressEvent, MiniDOMException, MiniBlob, MiniURL, MiniTextDecoder, MiniTextEncoder, MiniAbortController, MiniAbortSignal, createFetch, createXMLHttpRequestFactory } from './chunk-LCJNTN6F.js';
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
- define(instance, "style", { value: style, writable: true });
115
- define(instance, "clientTop", { get: () => 0 });
116
- define(instance, "clientLeft", { get: () => 0 });
117
- define(instance, "clientWidth", { get: () => rect.width });
118
- define(instance, "clientHeight", { get: () => rect.height });
119
- define(instance, "offsetTop", { get: () => rect.top });
120
- define(instance, "offsetLeft", { get: () => rect.left });
121
- define(instance, "offsetWidth", { get: () => rect.width });
122
- define(instance, "offsetHeight", { get: () => rect.height });
123
- define(instance, "getBoundingClientRect", { value: () => ({ ...rect }), writable: true });
124
- define(instance, "setAttribute", { value: (name, value) => {
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
- define(instance, "removeAttribute", { value: () => void 0, writable: true });
129
- define(instance, "ownerDocument", { value: (_a = options.document) != null ? _a : null, writable: true });
130
- define(instance, "getRootNode", { value: () => {
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
- define(instance, "setPointerCapture", { value: () => void 0, writable: true });
135
- define(instance, "releasePointerCapture", { value: () => void 0, writable: true });
136
- define(instance, "hasPointerCapture", { value: () => false, writable: true });
137
- define(instance, "requestPointerLock", { value: () => void 0, writable: true });
138
- define(instance, "exitPointerLock", { value: () => void 0, writable: true });
139
- define(instance, "focus", { value: () => void 0, writable: true });
140
- define(instance, "blur", { value: () => void 0, writable: true });
141
- define(instance, "scrollTop", { get: () => 0, set: () => void 0 });
142
- define(instance, "scrollLeft", { get: () => 0, set: () => void 0 });
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
- extra: {
258
- getContext: { value: getContext, writable: true },
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 = new MiniMouseEvent(mouseType, {
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(new MiniMouseEvent("click", {
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.startsWith("mouse") ? event.type : `mouse${event.type}`;
655
- const mouse = new MiniMouseEvent(type, {
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
- mouse.wheelDelta = (_f = event.deltaY) != null ? _f : 0;
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
- const ev = new MiniPointerEvent(type, { ...init, pointerId });
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
- this.fanout(ev, pointerId);
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
- Object.defineProperties(canvas, {
934
- setPointerCapture: { value: (id) => bridge.setPointerCapture(id, canvas), configurable: true },
935
- releasePointerCapture: { value: (id) => bridge.releasePointerCapture(id), configurable: true },
936
- hasPointerCapture: { value: (id) => bridge.activePointerCount > 0 && id >= 0, configurable: true }
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
  },
@@ -1449,5 +1498,5 @@ function createImageFactory(wx, diagnostics) {
1449
1498
  }
1450
1499
 
1451
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 };
1452
- //# sourceMappingURL=chunk-TDVL2OAV.js.map
1453
- //# sourceMappingURL=chunk-TDVL2OAV.js.map
1501
+ //# sourceMappingURL=chunk-V64V4HIZ.js.map
1502
+ //# sourceMappingURL=chunk-V64V4HIZ.js.map