hiraki 0.0.5 → 0.0.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/dist/index.cjs +48 -13
- package/dist/index.js +48 -13
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -301,22 +301,49 @@ function createGestureEngine(options) {
|
|
|
301
301
|
return false;
|
|
302
302
|
}
|
|
303
303
|
isDragging = false;
|
|
304
|
-
const
|
|
305
|
-
const
|
|
304
|
+
const smoothedVelocityPxMs = getVelocity();
|
|
305
|
+
const trackerState = tracker.getState();
|
|
306
|
+
const totalDelta = isHorizontal(opts.direction) ? Math.abs(trackerState.deltaX) : Math.abs(trackerState.deltaY);
|
|
307
|
+
const totalTime = trackerState.timestamp - trackerState.startTimestamp;
|
|
308
|
+
const avgVelocityPxMs = totalTime > 0 ? totalDelta / totalTime : 0;
|
|
309
|
+
const velocityPxMs = Math.abs(smoothedVelocityPxMs) > avgVelocityPxMs ? smoothedVelocityPxMs : avgVelocityPxMs * (smoothedVelocityPxMs >= 0 ? 1 : -1);
|
|
310
|
+
const velocityPxSec = velocityPxMs * 1e3;
|
|
311
|
+
const dragDelta = translateValue - dragStartTranslate;
|
|
312
|
+
const isDraggingTowardClose = dragDelta > 0;
|
|
306
313
|
const closeThresholdPx = opts.closeThreshold * opts.maxTranslate;
|
|
307
|
-
const
|
|
314
|
+
const snapPoints = opts.snapPoints;
|
|
315
|
+
let shouldClose = false;
|
|
308
316
|
let targetSnapIndex;
|
|
309
|
-
if (
|
|
317
|
+
if (velocityPxMs > 2 && isDraggingTowardClose) {
|
|
318
|
+
shouldClose = true;
|
|
310
319
|
targetSnapIndex = -1;
|
|
320
|
+
} else if (velocityPxMs < -2) {
|
|
321
|
+
shouldClose = false;
|
|
322
|
+
targetSnapIndex = snapPoints[snapPoints.length - 1]?.index ?? 0;
|
|
323
|
+
} else if (Math.abs(velocityPxMs) > 0.4 && Math.abs(dragDelta) < opts.maxTranslate * 0.4) {
|
|
324
|
+
const stepDir = isDraggingTowardClose ? -1 : 1;
|
|
325
|
+
const nextIndex = opts.activeSnapIndex + stepDir;
|
|
326
|
+
if (nextIndex < 0) {
|
|
327
|
+
shouldClose = true;
|
|
328
|
+
targetSnapIndex = -1;
|
|
329
|
+
} else {
|
|
330
|
+
shouldClose = false;
|
|
331
|
+
targetSnapIndex = Math.min(nextIndex, snapPoints.length - 1);
|
|
332
|
+
}
|
|
311
333
|
} else {
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
334
|
+
shouldClose = translateValue > closeThresholdPx;
|
|
335
|
+
if (shouldClose) {
|
|
336
|
+
targetSnapIndex = -1;
|
|
337
|
+
} else {
|
|
338
|
+
targetSnapIndex = findNearestSnapPoint(
|
|
339
|
+
opts.maxTranslate - translateValue,
|
|
340
|
+
-velocityPxMs,
|
|
341
|
+
snapPoints,
|
|
342
|
+
opts.inertia
|
|
343
|
+
);
|
|
344
|
+
}
|
|
318
345
|
}
|
|
319
|
-
opts.onDragEnd?.({ translateValue, velocityPxMs, targetSnapIndex, shouldClose });
|
|
346
|
+
opts.onDragEnd?.({ translateValue, velocityPxMs: velocityPxSec, targetSnapIndex, shouldClose });
|
|
320
347
|
return true;
|
|
321
348
|
}
|
|
322
349
|
function setTranslate(value) {
|
|
@@ -328,7 +355,15 @@ function createGestureEngine(options) {
|
|
|
328
355
|
function getTranslate() {
|
|
329
356
|
return translateValue;
|
|
330
357
|
}
|
|
331
|
-
return {
|
|
358
|
+
return {
|
|
359
|
+
update,
|
|
360
|
+
onPointerDown,
|
|
361
|
+
onPointerMove,
|
|
362
|
+
onPointerUp,
|
|
363
|
+
setTranslate,
|
|
364
|
+
getIsDragging,
|
|
365
|
+
getTranslate
|
|
366
|
+
};
|
|
332
367
|
}
|
|
333
368
|
|
|
334
369
|
// src/utils/focus-trap.ts
|
|
@@ -647,7 +682,7 @@ function Root({
|
|
|
647
682
|
snapPoints: snapPointsProp = [],
|
|
648
683
|
activeSnapPoint: controlledSnap,
|
|
649
684
|
onSnapPointChange,
|
|
650
|
-
closeThreshold = 0.
|
|
685
|
+
closeThreshold = 0.25,
|
|
651
686
|
rubberBand: rubberBand2 = true,
|
|
652
687
|
inertia = true,
|
|
653
688
|
shouldScaleBackground = false,
|
package/dist/index.js
CHANGED
|
@@ -299,22 +299,49 @@ function createGestureEngine(options) {
|
|
|
299
299
|
return false;
|
|
300
300
|
}
|
|
301
301
|
isDragging = false;
|
|
302
|
-
const
|
|
303
|
-
const
|
|
302
|
+
const smoothedVelocityPxMs = getVelocity();
|
|
303
|
+
const trackerState = tracker.getState();
|
|
304
|
+
const totalDelta = isHorizontal(opts.direction) ? Math.abs(trackerState.deltaX) : Math.abs(trackerState.deltaY);
|
|
305
|
+
const totalTime = trackerState.timestamp - trackerState.startTimestamp;
|
|
306
|
+
const avgVelocityPxMs = totalTime > 0 ? totalDelta / totalTime : 0;
|
|
307
|
+
const velocityPxMs = Math.abs(smoothedVelocityPxMs) > avgVelocityPxMs ? smoothedVelocityPxMs : avgVelocityPxMs * (smoothedVelocityPxMs >= 0 ? 1 : -1);
|
|
308
|
+
const velocityPxSec = velocityPxMs * 1e3;
|
|
309
|
+
const dragDelta = translateValue - dragStartTranslate;
|
|
310
|
+
const isDraggingTowardClose = dragDelta > 0;
|
|
304
311
|
const closeThresholdPx = opts.closeThreshold * opts.maxTranslate;
|
|
305
|
-
const
|
|
312
|
+
const snapPoints = opts.snapPoints;
|
|
313
|
+
let shouldClose = false;
|
|
306
314
|
let targetSnapIndex;
|
|
307
|
-
if (
|
|
315
|
+
if (velocityPxMs > 2 && isDraggingTowardClose) {
|
|
316
|
+
shouldClose = true;
|
|
308
317
|
targetSnapIndex = -1;
|
|
318
|
+
} else if (velocityPxMs < -2) {
|
|
319
|
+
shouldClose = false;
|
|
320
|
+
targetSnapIndex = snapPoints[snapPoints.length - 1]?.index ?? 0;
|
|
321
|
+
} else if (Math.abs(velocityPxMs) > 0.4 && Math.abs(dragDelta) < opts.maxTranslate * 0.4) {
|
|
322
|
+
const stepDir = isDraggingTowardClose ? -1 : 1;
|
|
323
|
+
const nextIndex = opts.activeSnapIndex + stepDir;
|
|
324
|
+
if (nextIndex < 0) {
|
|
325
|
+
shouldClose = true;
|
|
326
|
+
targetSnapIndex = -1;
|
|
327
|
+
} else {
|
|
328
|
+
shouldClose = false;
|
|
329
|
+
targetSnapIndex = Math.min(nextIndex, snapPoints.length - 1);
|
|
330
|
+
}
|
|
309
331
|
} else {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
332
|
+
shouldClose = translateValue > closeThresholdPx;
|
|
333
|
+
if (shouldClose) {
|
|
334
|
+
targetSnapIndex = -1;
|
|
335
|
+
} else {
|
|
336
|
+
targetSnapIndex = findNearestSnapPoint(
|
|
337
|
+
opts.maxTranslate - translateValue,
|
|
338
|
+
-velocityPxMs,
|
|
339
|
+
snapPoints,
|
|
340
|
+
opts.inertia
|
|
341
|
+
);
|
|
342
|
+
}
|
|
316
343
|
}
|
|
317
|
-
opts.onDragEnd?.({ translateValue, velocityPxMs, targetSnapIndex, shouldClose });
|
|
344
|
+
opts.onDragEnd?.({ translateValue, velocityPxMs: velocityPxSec, targetSnapIndex, shouldClose });
|
|
318
345
|
return true;
|
|
319
346
|
}
|
|
320
347
|
function setTranslate(value) {
|
|
@@ -326,7 +353,15 @@ function createGestureEngine(options) {
|
|
|
326
353
|
function getTranslate() {
|
|
327
354
|
return translateValue;
|
|
328
355
|
}
|
|
329
|
-
return {
|
|
356
|
+
return {
|
|
357
|
+
update,
|
|
358
|
+
onPointerDown,
|
|
359
|
+
onPointerMove,
|
|
360
|
+
onPointerUp,
|
|
361
|
+
setTranslate,
|
|
362
|
+
getIsDragging,
|
|
363
|
+
getTranslate
|
|
364
|
+
};
|
|
330
365
|
}
|
|
331
366
|
|
|
332
367
|
// src/utils/focus-trap.ts
|
|
@@ -645,7 +680,7 @@ function Root({
|
|
|
645
680
|
snapPoints: snapPointsProp = [],
|
|
646
681
|
activeSnapPoint: controlledSnap,
|
|
647
682
|
onSnapPointChange,
|
|
648
|
-
closeThreshold = 0.
|
|
683
|
+
closeThreshold = 0.25,
|
|
649
684
|
rubberBand: rubberBand2 = true,
|
|
650
685
|
inertia = true,
|
|
651
686
|
shouldScaleBackground = false,
|