@viji-dev/core 0.3.23 → 0.3.25

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.
@@ -46,8 +46,6 @@ class IFrameManager {
46
46
  isInteractionEnabled = true;
47
47
  // Mouse canvas tracking
48
48
  isMouseInCanvas = false;
49
- // Touch tracking for gesture recognition
50
- activeTouchIds = /* @__PURE__ */ new Set();
51
49
  // Device sensor support
52
50
  deviceSensorCallback = null;
53
51
  initiallyVisible;
@@ -470,6 +468,7 @@ class IFrameManager {
470
468
  type: event.type,
471
469
  key: event.key,
472
470
  code: event.code,
471
+ keyCode: event.keyCode,
473
472
  shiftKey: event.shiftKey,
474
473
  ctrlKey: event.ctrlKey,
475
474
  altKey: event.altKey,
@@ -487,31 +486,43 @@ class IFrameManager {
487
486
  const rect = this.canvas.getBoundingClientRect();
488
487
  const scaleX = this.canvas.width / rect.width;
489
488
  const scaleY = this.canvas.height / rect.height;
490
- const touches = Array.from(event.touches).map((touch) => ({
491
- identifier: touch.identifier,
492
- clientX: (touch.clientX - rect.left) * scaleX,
493
- clientY: (touch.clientY - rect.top) * scaleY,
494
- pressure: touch.pressure || 0,
495
- radiusX: touch.radiusX || 10,
496
- radiusY: touch.radiusY || 10,
497
- rotationAngle: touch.rotationAngle || 0,
498
- force: touch.force || touch.pressure || 0
499
- }));
500
- if (event.type === "touchstart") {
501
- for (const touch of event.changedTouches) {
502
- this.activeTouchIds.add(touch.identifier);
503
- }
504
- } else if (event.type === "touchend" || event.type === "touchcancel") {
505
- for (const touch of event.changedTouches) {
506
- this.activeTouchIds.delete(touch.identifier);
489
+ const canvasW = this.canvas.width;
490
+ const canvasH = this.canvas.height;
491
+ const mapTouch = (touch) => {
492
+ const cx = (touch.clientX - rect.left) * scaleX;
493
+ const cy = (touch.clientY - rect.top) * scaleY;
494
+ return {
495
+ identifier: touch.identifier,
496
+ clientX: cx,
497
+ clientY: cy,
498
+ radiusX: touch.radiusX ?? 0,
499
+ radiusY: touch.radiusY ?? 0,
500
+ rotationAngle: touch.rotationAngle ?? 0,
501
+ force: touch.force ?? 0,
502
+ isInCanvas: cx >= 0 && cx <= canvasW && cy >= 0 && cy <= canvasH
503
+ };
504
+ };
505
+ const changedMap = /* @__PURE__ */ new Map();
506
+ for (let i = 0; i < event.changedTouches.length; i++) {
507
+ const t = event.changedTouches[i];
508
+ changedMap.set(t.identifier, mapTouch(t));
509
+ }
510
+ const touches = Array.from(event.touches).map((touch) => {
511
+ return changedMap.get(touch.identifier) ?? mapTouch(touch);
512
+ });
513
+ if (event.type === "touchend" || event.type === "touchcancel") {
514
+ const activeIds = new Set(touches.map((t) => t.identifier));
515
+ for (const [id, mapped] of changedMap) {
516
+ if (!activeIds.has(id)) {
517
+ touches.push({ ...mapped, ended: true });
518
+ }
507
519
  }
508
520
  }
509
- const data = {
521
+ this.emitInteractionEvent("touch-update", {
510
522
  type: event.type,
511
523
  touches,
512
524
  timestamp: performance.now()
513
- };
514
- this.emitInteractionEvent("touch-update", data);
525
+ });
515
526
  }
516
527
  /**
517
528
  * Emits an interaction event to all registered listeners
@@ -567,7 +578,7 @@ class IFrameManager {
567
578
  }
568
579
  function WorkerWrapper(options) {
569
580
  return new Worker(
570
- "" + new URL("assets/viji.worker-DTQvTudb.js", import.meta.url).href,
581
+ "" + new URL("assets/viji.worker-Zg128woJ.js", import.meta.url).href,
571
582
  {
572
583
  type: "module",
573
584
  name: options?.name
@@ -771,7 +782,6 @@ class InteractionManager {
771
782
  leftButton: false,
772
783
  rightButton: false,
773
784
  middleButton: false,
774
- velocity: { x: 0, y: 0 },
775
785
  deltaX: 0,
776
786
  deltaY: 0,
777
787
  wheelDelta: 0,
@@ -781,8 +791,6 @@ class InteractionManager {
781
791
  wasReleased: false,
782
792
  wasMoved: false
783
793
  };
784
- // Mouse velocity tracking
785
- mouseVelocityHistory = [];
786
794
  // Keyboard state
787
795
  keyboardState = {
788
796
  isPressed: (key) => this.activeKeys.has(key.toLowerCase()),
@@ -796,7 +804,8 @@ class InteractionManager {
796
804
  shift: false,
797
805
  ctrl: false,
798
806
  alt: false,
799
- meta: false
807
+ meta: false,
808
+ textureData: new Uint8Array(256 * 3)
800
809
  };
801
810
  activeKeys = /* @__PURE__ */ new Set();
802
811
  pressedThisFrame = /* @__PURE__ */ new Set();
@@ -808,33 +817,9 @@ class InteractionManager {
808
817
  started: [],
809
818
  moved: [],
810
819
  ended: [],
811
- primary: null,
812
- gestures: {
813
- isPinching: false,
814
- isRotating: false,
815
- isPanning: false,
816
- isTapping: false,
817
- pinchScale: 1,
818
- pinchDelta: 0,
819
- rotationAngle: 0,
820
- rotationDelta: 0,
821
- panDelta: { x: 0, y: 0 },
822
- tapCount: 0,
823
- lastTapTime: 0,
824
- tapPosition: null
825
- }
820
+ primary: null
826
821
  };
827
822
  activeTouches = /* @__PURE__ */ new Map();
828
- gestureState = {
829
- initialDistance: 0,
830
- initialAngle: 0,
831
- lastPinchScale: 1,
832
- lastRotationAngle: 0,
833
- panStartPosition: { x: 0, y: 0 },
834
- tapStartTime: 0,
835
- tapCount: 0,
836
- lastTapTime: 0
837
- };
838
823
  constructor() {
839
824
  }
840
825
  /**
@@ -845,7 +830,6 @@ class InteractionManager {
845
830
  const canvasY = data.y;
846
831
  const deltaX = canvasX - this.mouseState.x;
847
832
  const deltaY = canvasY - this.mouseState.y;
848
- this.updateMouseVelocity(deltaX, deltaY, data.timestamp);
849
833
  const prevPressed = this.mouseState.isPressed;
850
834
  const currentPressed = data.buttons > 0;
851
835
  this.mouseState.wasPressed = !prevPressed && currentPressed;
@@ -864,24 +848,6 @@ class InteractionManager {
864
848
  this.mouseState.wheelX = data.wheelDeltaX;
865
849
  this.mouseState.wheelY = data.wheelDeltaY;
866
850
  }
867
- /**
868
- * Updates mouse velocity with smoothing
869
- */
870
- updateMouseVelocity(deltaX, deltaY, timestamp) {
871
- this.mouseVelocityHistory.push({ x: deltaX, y: deltaY, time: timestamp });
872
- const cutoff = timestamp - 100;
873
- this.mouseVelocityHistory = this.mouseVelocityHistory.filter((sample) => sample.time > cutoff);
874
- if (this.mouseVelocityHistory.length > 1) {
875
- const recent = this.mouseVelocityHistory.slice(-5);
876
- const avgX = recent.reduce((sum, s) => sum + s.x, 0) / recent.length;
877
- const avgY = recent.reduce((sum, s) => sum + s.y, 0) / recent.length;
878
- this.mouseState.velocity.x = avgX;
879
- this.mouseState.velocity.y = avgY;
880
- } else {
881
- this.mouseState.velocity.x = deltaX;
882
- this.mouseState.velocity.y = deltaY;
883
- }
884
- }
885
851
  /**
886
852
  * Processes keyboard update from the host
887
853
  */
@@ -915,12 +881,11 @@ class InteractionManager {
915
881
  } else if (data.type === "touchmove") {
916
882
  this.processTouchMove(data.touches, data.timestamp);
917
883
  } else if (data.type === "touchend" || data.type === "touchcancel") {
918
- this.processTouchEnd(data.touches, data.timestamp);
884
+ this.processTouchEnd(data.touches);
919
885
  }
920
886
  this.touchState.points = Array.from(this.activeTouches.values());
921
887
  this.touchState.count = this.touchState.points.length;
922
888
  this.touchState.primary = this.touchState.points[0] || null;
923
- this.updateGestures();
924
889
  }
925
890
  /**
926
891
  * Processes touch start events
@@ -931,11 +896,6 @@ class InteractionManager {
931
896
  this.activeTouches.set(touch.identifier, touchPoint);
932
897
  this.touchState.started.push(touchPoint);
933
898
  }
934
- if (this.touchState.count === 1) {
935
- this.gestureState.tapStartTime = timestamp;
936
- const touch = this.touchState.points[0];
937
- this.touchState.gestures.tapPosition = { x: touch.x, y: touch.y };
938
- }
939
899
  }
940
900
  /**
941
901
  * Processes touch move events
@@ -953,7 +913,7 @@ class InteractionManager {
953
913
  /**
954
914
  * Processes touch end events
955
915
  */
956
- processTouchEnd(touches, timestamp) {
916
+ processTouchEnd(touches) {
957
917
  for (const touch of touches) {
958
918
  const existing = this.activeTouches.get(touch.identifier);
959
919
  if (existing) {
@@ -962,13 +922,6 @@ class InteractionManager {
962
922
  this.activeTouches.delete(touch.identifier);
963
923
  }
964
924
  }
965
- if (this.touchState.count === 0 && this.gestureState.tapStartTime > 0) {
966
- const tapDuration = timestamp - this.gestureState.tapStartTime;
967
- if (tapDuration < 300) {
968
- this.handleTap(timestamp);
969
- }
970
- this.gestureState.tapStartTime = 0;
971
- }
972
925
  }
973
926
  /**
974
927
  * Creates a touch point from raw touch data
@@ -985,12 +938,13 @@ class InteractionManager {
985
938
  id: touch.identifier,
986
939
  x,
987
940
  y,
988
- pressure: touch.pressure || 0,
989
- radius: Math.max(touch.radiusX || 0, touch.radiusY || 0),
990
- radiusX: touch.radiusX || 0,
991
- radiusY: touch.radiusY || 0,
992
- rotationAngle: touch.rotationAngle || 0,
993
- force: touch.force || touch.pressure || 0,
941
+ pressure: touch.force,
942
+ radius: Math.max(touch.radiusX, touch.radiusY),
943
+ radiusX: touch.radiusX,
944
+ radiusY: touch.radiusY,
945
+ rotationAngle: touch.rotationAngle,
946
+ force: touch.force,
947
+ isInCanvas: touch.isInCanvas ?? true,
994
948
  deltaX,
995
949
  deltaY,
996
950
  velocity: { x: velocityX, y: velocityY },
@@ -999,75 +953,6 @@ class InteractionManager {
999
953
  isEnding: false
1000
954
  };
1001
955
  }
1002
- /**
1003
- * Updates gesture recognition
1004
- */
1005
- updateGestures() {
1006
- const touches = this.touchState.points;
1007
- const gestures = this.touchState.gestures;
1008
- if (touches.length === 2) {
1009
- const touch1 = touches[0];
1010
- const touch2 = touches[1];
1011
- const distance = Math.sqrt(
1012
- Math.pow(touch2.x - touch1.x, 2) + Math.pow(touch2.y - touch1.y, 2)
1013
- );
1014
- const angle = Math.atan2(touch2.y - touch1.y, touch2.x - touch1.x);
1015
- if (this.gestureState.initialDistance === 0) {
1016
- this.gestureState.initialDistance = distance;
1017
- this.gestureState.initialAngle = angle;
1018
- this.gestureState.lastPinchScale = 1;
1019
- this.gestureState.lastRotationAngle = 0;
1020
- }
1021
- const scale = distance / this.gestureState.initialDistance;
1022
- const scaleDelta = scale - this.gestureState.lastPinchScale;
1023
- gestures.isPinching = Math.abs(scaleDelta) > 0.01;
1024
- gestures.pinchScale = scale;
1025
- gestures.pinchDelta = scaleDelta;
1026
- this.gestureState.lastPinchScale = scale;
1027
- const rotationAngle = angle - this.gestureState.initialAngle;
1028
- const rotationDelta = rotationAngle - this.gestureState.lastRotationAngle;
1029
- gestures.isRotating = Math.abs(rotationDelta) > 0.02;
1030
- gestures.rotationAngle = rotationAngle;
1031
- gestures.rotationDelta = rotationDelta;
1032
- this.gestureState.lastRotationAngle = rotationAngle;
1033
- } else {
1034
- this.gestureState.initialDistance = 0;
1035
- gestures.isPinching = false;
1036
- gestures.isRotating = false;
1037
- gestures.pinchDelta = 0;
1038
- gestures.rotationDelta = 0;
1039
- }
1040
- if (touches.length > 0) {
1041
- const primaryTouch = touches[0];
1042
- if (this.gestureState.panStartPosition.x === 0) {
1043
- this.gestureState.panStartPosition = { x: primaryTouch.x, y: primaryTouch.y };
1044
- }
1045
- const panDeltaX = primaryTouch.x - this.gestureState.panStartPosition.x;
1046
- const panDeltaY = primaryTouch.y - this.gestureState.panStartPosition.y;
1047
- const panDistance = Math.sqrt(panDeltaX * panDeltaX + panDeltaY * panDeltaY);
1048
- gestures.isPanning = panDistance > 10;
1049
- gestures.panDelta = { x: panDeltaX, y: panDeltaY };
1050
- } else {
1051
- this.gestureState.panStartPosition = { x: 0, y: 0 };
1052
- gestures.isPanning = false;
1053
- gestures.panDelta = { x: 0, y: 0 };
1054
- }
1055
- }
1056
- /**
1057
- * Handles tap gesture detection
1058
- */
1059
- handleTap(timestamp) {
1060
- const timeSinceLastTap = timestamp - this.gestureState.lastTapTime;
1061
- if (timeSinceLastTap < 300) {
1062
- this.gestureState.tapCount++;
1063
- } else {
1064
- this.gestureState.tapCount = 1;
1065
- }
1066
- this.touchState.gestures.tapCount = this.gestureState.tapCount;
1067
- this.touchState.gestures.lastTapTime = timestamp;
1068
- this.touchState.gestures.isTapping = true;
1069
- this.gestureState.lastTapTime = timestamp;
1070
- }
1071
956
  /**
1072
957
  * Called at the start of each frame to reset frame-based events
1073
958
  */
@@ -1080,9 +965,6 @@ class InteractionManager {
1080
965
  this.mouseState.wheelY = 0;
1081
966
  this.pressedThisFrame.clear();
1082
967
  this.releasedThisFrame.clear();
1083
- this.touchState.gestures.isTapping = false;
1084
- this.touchState.gestures.pinchDelta = 0;
1085
- this.touchState.gestures.rotationDelta = 0;
1086
968
  }
1087
969
  /**
1088
970
  * Get current mouse state (read-only)
@@ -1106,7 +988,6 @@ class InteractionManager {
1106
988
  * Cleanup resources
1107
989
  */
1108
990
  destroy() {
1109
- this.mouseVelocityHistory.length = 0;
1110
991
  this.activeTouches.clear();
1111
992
  this.activeKeys.clear();
1112
993
  this.pressedThisFrame.clear();
@@ -1920,7 +1801,7 @@ class EssentiaOnsetDetection {
1920
1801
  this.initPromise = (async () => {
1921
1802
  try {
1922
1803
  const essentiaModule = await import("./essentia.js-core.es-DnrJE0uR.js");
1923
- const wasmModule = await import("./essentia-wasm.web-0nilrUD3.js").then((n) => n.e);
1804
+ const wasmModule = await import("./essentia-wasm.web-Dq7KVAx1.js").then((n) => n.e);
1924
1805
  const EssentiaClass = essentiaModule.Essentia || essentiaModule.default?.Essentia || essentiaModule.default;
1925
1806
  let WASMModule = wasmModule.default || wasmModule.EssentiaWASM || wasmModule.default?.EssentiaWASM;
1926
1807
  if (!WASMModule) {
@@ -16277,4 +16158,4 @@ export {
16277
16158
  VijiCoreError as b,
16278
16159
  getDefaultExportFromCjs as g
16279
16160
  };
16280
- //# sourceMappingURL=index-Bu1euCdl.js.map
16161
+ //# sourceMappingURL=index-C6fMmKQj.js.map