@naniteninja/profile-comparison-lib 1.0.15 → 1.0.16
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.
|
@@ -2086,6 +2086,7 @@ class ProfileComparisonLibComponent {
|
|
|
2086
2086
|
let isDragging = false;
|
|
2087
2087
|
let dragStartX = 0;
|
|
2088
2088
|
let activeFrame = null;
|
|
2089
|
+
let edgeDragEmitted = false; // Track whether we have emitted edgeDrag for the current gesture
|
|
2089
2090
|
const initialTranslateXLeft = -24; // starting CSS value percent
|
|
2090
2091
|
const initialTranslateXRight = 24;
|
|
2091
2092
|
const onMouseMove = (e) => {
|
|
@@ -2098,6 +2099,19 @@ class ProfileComparisonLibComponent {
|
|
|
2098
2099
|
if (Math.abs(deltaX) > 5) {
|
|
2099
2100
|
this.wasDragging = true;
|
|
2100
2101
|
}
|
|
2102
|
+
// Check for edge drag swiping (both mouse and touch support!)
|
|
2103
|
+
const leftRect = leftFrame.getBoundingClientRect();
|
|
2104
|
+
const rightRect = rightFrame.getBoundingClientRect();
|
|
2105
|
+
const overlapPx = Math.max(0, leftRect.right - leftRect.left); // Frame width
|
|
2106
|
+
const maxDisplacementPx = overlapPx / 3;
|
|
2107
|
+
if (!edgeDragEmitted && Math.abs(deltaX) > maxDisplacementPx * 1.05) {
|
|
2108
|
+
// Only trigger swipe outward:
|
|
2109
|
+
// Left frame dragged further left (deltaX < 0) or Right frame dragged further right (deltaX > 0)
|
|
2110
|
+
if ((activeFrame === leftFrame && deltaX < 0) || (activeFrame === rightFrame && deltaX > 0)) {
|
|
2111
|
+
edgeDragEmitted = true;
|
|
2112
|
+
this.edgeDrag.emit(deltaX < 0 ? 'left' : 'right');
|
|
2113
|
+
}
|
|
2114
|
+
}
|
|
2101
2115
|
// Clamp delta to the pre-calculated displacement limit
|
|
2102
2116
|
deltaPercent = Math.max(-initialMaxDisplacementPercent, Math.min(initialMaxDisplacementPercent, deltaPercent));
|
|
2103
2117
|
// Calculate actual frame displacement in pixels for text coordination
|
|
@@ -2206,6 +2220,8 @@ class ProfileComparisonLibComponent {
|
|
|
2206
2220
|
};
|
|
2207
2221
|
const resetDrag = () => {
|
|
2208
2222
|
isDragging = false;
|
|
2223
|
+
activeFrame = null;
|
|
2224
|
+
edgeDragEmitted = false; // Reset edge drag flag on release
|
|
2209
2225
|
const leftContent = leftFrame.querySelector('.profile-comparison__content--left');
|
|
2210
2226
|
const rightContent = rightFrame.querySelector('.profile-comparison__content--right');
|
|
2211
2227
|
// Smoother rebound transition
|
|
@@ -2303,6 +2319,7 @@ class ProfileComparisonLibComponent {
|
|
|
2303
2319
|
e.preventDefault();
|
|
2304
2320
|
isDragging = true;
|
|
2305
2321
|
this.wasDragging = false;
|
|
2322
|
+
activeFrame = frame; // Track which frame is active
|
|
2306
2323
|
dragStartX = e.clientX;
|
|
2307
2324
|
// Lighten shadow on grab, then slowly return to normal while holding
|
|
2308
2325
|
const activeGlass = frame === leftFrame ? leftGlass : rightGlass;
|
|
@@ -2337,6 +2354,7 @@ class ProfileComparisonLibComponent {
|
|
|
2337
2354
|
e.stopPropagation();
|
|
2338
2355
|
isDragging = true;
|
|
2339
2356
|
this.wasDragging = false;
|
|
2357
|
+
activeFrame = frame; // Track which frame is active
|
|
2340
2358
|
dragStartX = e.touches[0].clientX;
|
|
2341
2359
|
const activeGlass = frame === leftFrame ? leftGlass : rightGlass;
|
|
2342
2360
|
if (activeGlass) {
|
|
@@ -2349,25 +2367,10 @@ class ProfileComparisonLibComponent {
|
|
|
2349
2367
|
}
|
|
2350
2368
|
});
|
|
2351
2369
|
}
|
|
2352
|
-
// Track whether we have already emitted an edgeDrag for this touch gesture
|
|
2353
|
-
let edgeDragEmitted = false;
|
|
2354
|
-
const containerWidthForEdge = leftFrame.parentElement?.clientWidth || 360;
|
|
2355
|
-
const leftRectEdge = leftFrame.getBoundingClientRect();
|
|
2356
|
-
const rightRectEdge = rightFrame.getBoundingClientRect();
|
|
2357
|
-
const overlapPxEdge = Math.max(0, leftRectEdge.right - rightRectEdge.left);
|
|
2358
|
-
const maxDisplacementPxEdge = overlapPxEdge / 3;
|
|
2359
2370
|
const onTouchMove = (ev) => {
|
|
2360
|
-
const rawDeltaX = ev.touches[0].clientX - dragStartX;
|
|
2361
|
-
// When the user pulls past the edge limit and hasn't yet signalled
|
|
2362
|
-
// the parent, emit once so the parent can slide to next/prev.
|
|
2363
|
-
if (!edgeDragEmitted && Math.abs(rawDeltaX) > maxDisplacementPxEdge * 1.1) {
|
|
2364
|
-
edgeDragEmitted = true;
|
|
2365
|
-
this.edgeDrag.emit(rawDeltaX < 0 ? 'left' : 'right');
|
|
2366
|
-
}
|
|
2367
2371
|
onMouseMove({ clientX: ev.touches[0].clientX });
|
|
2368
2372
|
};
|
|
2369
2373
|
const onTouchEnd = () => {
|
|
2370
|
-
edgeDragEmitted = false; // reset for next gesture
|
|
2371
2374
|
resetDrag();
|
|
2372
2375
|
document.removeEventListener('touchmove', onTouchMove);
|
|
2373
2376
|
document.removeEventListener('touchend', onTouchEnd);
|