lido-player 0.0.2-beta-22-dev → 0.0.2-beta-23-dev

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 (30) hide show
  1. package/dist/cjs/{decode-Cr5DANqc.js → decode-BDs2S8om.js} +1 -1
  2. package/dist/cjs/{index-0BvcfeCt.js → index-D5olYRJo.js} +130 -21
  3. package/dist/cjs/index.cjs.js +1 -1
  4. package/dist/cjs/lido-avatar_22.cjs.entry.js +38 -18
  5. package/dist/collection/components/flashCard/lido-flash-card.js +30 -3
  6. package/dist/collection/components/trace/lido-trace.js +6 -13
  7. package/dist/collection/stories/Templates/balancing/balancing.stories.js +2 -2
  8. package/dist/collection/utils/utilsHandlers/dragDropHandler.js +129 -20
  9. package/dist/components/index.js +1 -1
  10. package/dist/components/lido-flash-card.js +1 -1
  11. package/dist/components/lido-home.js +1 -1
  12. package/dist/components/lido-root.js +1 -1
  13. package/dist/components/lido-trace.js +1 -1
  14. package/dist/components/p-D0cGjo5e.js +1 -0
  15. package/dist/components/{p-CkxAm8rY.js → p-Ds-d6wd0.js} +2 -2
  16. package/dist/components/p-Lg85waqZ.js +1 -0
  17. package/dist/esm/{decode-DkSXjv7K.js → decode-CAwfe7ub.js} +1 -1
  18. package/dist/esm/{index-D9-TTsdZ.js → index-bo7729YG.js} +130 -21
  19. package/dist/esm/index.js +1 -1
  20. package/dist/esm/lido-avatar_22.entry.js +38 -18
  21. package/dist/lido-player/index.esm.js +1 -1
  22. package/dist/lido-player/lido-player.esm.js +1 -1
  23. package/dist/lido-player/{p-35fa0b8b.entry.js → p-461a3d23.entry.js} +2 -2
  24. package/dist/lido-player/{p-Dc8j8Hxw.js → p-D4kAEWCU.js} +1 -1
  25. package/dist/lido-player/p-VRJMO_sg.js +1 -0
  26. package/dist/types/components/flashCard/lido-flash-card.d.ts +4 -0
  27. package/package.json +1 -1
  28. package/dist/components/p-BUfCIPRa.js +0 -1
  29. package/dist/components/p-u3czV7QM.js +0 -1
  30. package/dist/lido-player/p-D2iINRNN.js +0 -1
@@ -62,6 +62,19 @@ export function enableDraggingWithScaling(element) {
62
62
  let clone = null;
63
63
  let duplicateElement = null;
64
64
  let mutationFlag = false;
65
+ let pendingMoveFrame = null;
66
+ let latestClientX = 0;
67
+ let latestClientY = 0;
68
+ let hasPendingMove = false;
69
+ let touchTransformUpdated = false;
70
+ let touchDragScale = 1;
71
+ let touchDragScaleY = 1;
72
+ let touchOffsetX = 0;
73
+ let touchOffsetY = 0;
74
+ let touchStartElementLeft = 0;
75
+ let touchStartElementTop = 0;
76
+ let touchStartRect = null;
77
+ let isTouchDragging = false;
65
78
  // Fetch the container element
66
79
  const container = document.getElementById(LidoContainer);
67
80
  if (!container) {
@@ -74,6 +87,33 @@ export function enableDraggingWithScaling(element) {
74
87
  let verticalDistance;
75
88
  let horizontalDistance;
76
89
  let dragingElementTransform;
90
+ const getContainerScale = () => {
91
+ const transform = window.getComputedStyle(container).transform;
92
+ const matrix3dMatch = transform.match(/matrix3d\(([^)]+)\)/);
93
+ const matrixMatch = transform.match(/matrix\(([^)]+)\)/);
94
+ if (matrix3dMatch) {
95
+ const values = matrix3dMatch[1].split(',').map(value => parseFloat(value.trim()));
96
+ return {
97
+ scaleX: Math.sqrt(values[0] ** 2 + values[1] ** 2) || 1,
98
+ scaleY: Math.sqrt(values[4] ** 2 + values[5] ** 2) || 1,
99
+ };
100
+ }
101
+ if (matrixMatch) {
102
+ const values = matrixMatch[1].split(',').map(value => parseFloat(value.trim()));
103
+ return {
104
+ scaleX: Math.sqrt(values[0] ** 2 + values[1] ** 2) || 1,
105
+ scaleY: Math.sqrt(values[2] ** 2 + values[3] ** 2) || 1,
106
+ };
107
+ }
108
+ return { scaleX: 1, scaleY: 1 };
109
+ };
110
+ const updateTouchDragScale = () => {
111
+ if (isTouchDragging) {
112
+ const { scaleX, scaleY } = getContainerScale();
113
+ touchDragScale = scaleX;
114
+ touchDragScaleY = scaleY;
115
+ }
116
+ };
77
117
  const onStart = (event) => {
78
118
  var _a, _b;
79
119
  if (container && container.getAttribute("game-completed") === "true")
@@ -90,17 +130,29 @@ export function enableDraggingWithScaling(element) {
90
130
  if (event instanceof MouseEvent) {
91
131
  startX = event.clientX;
92
132
  startY = event.clientY;
133
+ touchStartRect = null;
93
134
  }
94
135
  else {
95
136
  startX = event.touches[0].clientX;
96
137
  startY = event.touches[0].clientY;
138
+ isTouchDragging = true;
139
+ touchStartRect = element.getBoundingClientRect();
140
+ touchOffsetX = startX - touchStartRect.left;
141
+ touchOffsetY = startY - touchStartRect.top;
142
+ touchStartElementLeft = touchStartRect.left;
143
+ touchStartElementTop = touchStartRect.top;
144
+ const { scaleX, scaleY } = getContainerScale();
145
+ touchDragScale = scaleX;
146
+ touchDragScaleY = scaleY;
147
+ element.style.willChange = 'transform';
148
+ window.addEventListener('resize', updateTouchDragScale);
97
149
  }
98
150
  // Apply dragging styles to the element
99
151
  element.style.opacity = '1';
100
152
  element.style.cursor = 'grabbing';
101
153
  if (((_a = element.getAttribute('dropAttr')) === null || _a === void 0 ? void 0 : _a.toLowerCase()) === DropMode.Diagonal) {
102
154
  const computedStyle = window.getComputedStyle(element);
103
- const rect = element.getBoundingClientRect();
155
+ const rect = touchStartRect || element.getBoundingClientRect();
104
156
  if (!clone) {
105
157
  clone = element.cloneNode(true);
106
158
  clone.style.left = `${rect.left}px`;
@@ -119,7 +171,7 @@ export function enableDraggingWithScaling(element) {
119
171
  const imgElement = element.querySelector('img');
120
172
  const src = imgElement === null || imgElement === void 0 ? void 0 : imgElement.getAttribute('src');
121
173
  const computedStyle = window.getComputedStyle(element);
122
- const rect = element.getBoundingClientRect();
174
+ const rect = touchStartRect || element.getBoundingClientRect();
123
175
  if (!duplicateElement) {
124
176
  duplicateElement = element.cloneNode(false);
125
177
  duplicateElement.setAttribute('src', src);
@@ -196,31 +248,31 @@ export function enableDraggingWithScaling(element) {
196
248
  target.style.opacity = value;
197
249
  }
198
250
  };
199
- const onMove = (event) => {
200
- if (!isDragging)
251
+ const processMove = () => {
252
+ pendingMoveFrame = null;
253
+ if (!isDragging || !hasPendingMove)
201
254
  return;
255
+ hasPendingMove = false;
256
+ const deferTouchDropValidation = touchTransformUpdated;
202
257
  if (isDraggingDisabled) {
203
258
  isDragging = false;
259
+ touchTransformUpdated = false;
204
260
  return;
205
261
  }
206
- isClicked = false;
207
262
  element.style.transition = 'none';
208
- const containerScale = calculateScale();
209
- let dx = 0;
210
- let dy = 0;
211
- if (event instanceof MouseEvent) {
212
- dx = (event.clientX - startX) / containerScale;
213
- dy = (event.clientY - startY) / containerScale;
263
+ if (!touchTransformUpdated) {
264
+ const containerScale = calculateScale();
265
+ const dx = (latestClientX - startX) / containerScale;
266
+ const dy = (latestClientY - startY) / containerScale;
267
+ // Calculate the new position considering scaling
268
+ const newLeft = initialX + dx;
269
+ const newTop = initialY + dy;
270
+ // Apply transform with translation without boundaries
271
+ element.style.transform = `translate(${newLeft}px, ${newTop}px)`;
214
272
  }
215
- else {
216
- dx = (event.touches[0].clientX - startX) / containerScale;
217
- dy = (event.touches[0].clientY - startY) / containerScale;
218
- }
219
- // Calculate the new position considering scaling
220
- const newLeft = initialX + dx;
221
- const newTop = initialY + dy;
222
- // Apply transform with translation without boundaries
223
- element.style.transform = `translate(${newLeft}px, ${newTop}px)`;
273
+ touchTransformUpdated = false;
274
+ if (deferTouchDropValidation)
275
+ return;
224
276
  // Check for overlaps and highlight only the most overlapping element
225
277
  let mostOverlappedElement = findMostoverlappedElement(element, 'drop');
226
278
  const allElements = document.querySelectorAll("[type='drop']");
@@ -259,6 +311,44 @@ export function enableDraggingWithScaling(element) {
259
311
  }
260
312
  }
261
313
  };
314
+ const onMove = (event) => {
315
+ if (!isDragging)
316
+ return;
317
+ if (isDraggingDisabled) {
318
+ isDragging = false;
319
+ return;
320
+ }
321
+ if (event instanceof MouseEvent) {
322
+ touchTransformUpdated = false;
323
+ latestClientX = event.clientX;
324
+ latestClientY = event.clientY;
325
+ }
326
+ else {
327
+ const touch = event.touches[0];
328
+ if (!touch)
329
+ return;
330
+ latestClientX = touch.clientX;
331
+ latestClientY = touch.clientY;
332
+ }
333
+ if (!(event instanceof MouseEvent)) {
334
+ element.style.transition = 'none';
335
+ const desiredLeft = latestClientX - touchOffsetX;
336
+ const desiredTop = latestClientY - touchOffsetY;
337
+ const dx = (desiredLeft - touchStartElementLeft) / touchDragScale;
338
+ const dy = (desiredTop - touchStartElementTop) / touchDragScaleY;
339
+ const newLeft = initialX + dx;
340
+ const newTop = initialY + dy;
341
+ element.style.transform = `translate3d(${newLeft}px, ${newTop}px, 0)`;
342
+ touchTransformUpdated = true;
343
+ }
344
+ isClicked = false;
345
+ if (event instanceof MouseEvent) {
346
+ hasPendingMove = true;
347
+ if (pendingMoveFrame === null) {
348
+ pendingMoveFrame = requestAnimationFrame(processMove);
349
+ }
350
+ }
351
+ };
262
352
  let lastOverlappedElement = null;
263
353
  const removeDocumentDragListeners = () => {
264
354
  document.removeEventListener('mousemove', onMove);
@@ -266,9 +356,19 @@ export function enableDraggingWithScaling(element) {
266
356
  document.removeEventListener('touchmove', onMove);
267
357
  document.removeEventListener('touchend', onEnd);
268
358
  };
359
+ const flushPendingMove = () => {
360
+ if (pendingMoveFrame === null)
361
+ return;
362
+ cancelAnimationFrame(pendingMoveFrame);
363
+ processMove();
364
+ };
269
365
  const onEnd = (endEv) => {
270
366
  var _a, _b, _c;
367
+ flushPendingMove();
271
368
  isDragging = false;
369
+ isTouchDragging = false;
370
+ element.style.willChange = '';
371
+ window.removeEventListener('resize', updateTouchDragScale);
272
372
  removeDocumentDragListeners();
273
373
  if (isClicked) {
274
374
  if (clone) {
@@ -374,6 +474,15 @@ export function enableDraggingWithScaling(element) {
374
474
  };
375
475
  const cleanup = () => {
376
476
  isDragging = false;
477
+ isTouchDragging = false;
478
+ element.style.willChange = '';
479
+ window.removeEventListener('resize', updateTouchDragScale);
480
+ if (pendingMoveFrame !== null) {
481
+ cancelAnimationFrame(pendingMoveFrame);
482
+ pendingMoveFrame = null;
483
+ }
484
+ hasPendingMove = false;
485
+ touchTransformUpdated = false;
377
486
  observer.disconnect();
378
487
  removeDocumentDragListeners();
379
488
  element.removeEventListener('mousedown', onStart);