@n-uf/motion 26.12.3 → 26.12.4
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/CHANGELOG.md +12 -0
- package/dist/{chunk-F5FNGVQT.js → chunk-XKCRMQZQ.js} +140 -121
- package/dist/chunk-XKCRMQZQ.js.map +1 -0
- package/dist/drag.d.ts +10 -2
- package/dist/drag.js +1 -1
- package/dist/index.js +1 -1
- package/package.json +1 -1
- package/dist/chunk-F5FNGVQT.js.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ within the month), the same scheme as `@n-uf/hypr-tiling`.
|
|
|
5
5
|
|
|
6
6
|
Unreleased entries live in `changes/` until a release joins them.
|
|
7
7
|
|
|
8
|
+
## 26.12.4
|
|
9
|
+
|
|
10
|
+
- **Fixed (behavior):** `createLandingModel(...).release` and `createDragIntent(...).release`: a release point that
|
|
11
|
+
differs from the last `update`'s, taken as one more sample, now counts none of the time no frame drew when it comes
|
|
12
|
+
the hand's rest gap or more after the last `update` (`min(40, gates.pause)` ms for the landing model, 40 ms for the
|
|
13
|
+
drag intent). The landing model reads that sample's step as unknown and adds nothing to a slide with it; the drag
|
|
14
|
+
intent stamps it at the last `update`'s time and keeps the speed that update read. Before, a release 1 to 3 px from the last frame's point after a rest no
|
|
15
|
+
frame drew docked in a lane no frame had shown entered (the landing model's crawl step), or armed a spring-loaded
|
|
16
|
+
target on the release's own clock (the drag intent), while a release at the very point went home. A slow page now
|
|
17
|
+
docks late, never falsely. Under the gap a release sample is read as before. See
|
|
18
|
+
docs/decisions/0020-a-rest-no-frame-drew-counts-for-nothing.md.
|
|
19
|
+
|
|
8
20
|
## 26.12.3
|
|
9
21
|
|
|
10
22
|
No changes in `@n-uf/motion`. Released in step with `@n-uf/placement` and `@n-uf/docking`, which share the version.
|
|
@@ -5,6 +5,120 @@ import {
|
|
|
5
5
|
sampleOrder
|
|
6
6
|
} from "./chunk-TJC6AXFM.js";
|
|
7
7
|
|
|
8
|
+
// src/drag/hand-speed.ts
|
|
9
|
+
var HAND_SLOW_STEP = 3;
|
|
10
|
+
var HAND_SPEED = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, still: 20, carry: 0.5, fill: 2.5, accelerating: 1.5, gathering: 1.25 };
|
|
11
|
+
var FILL_MAX = 32;
|
|
12
|
+
function createHandSpeed(options = {}) {
|
|
13
|
+
const o = { ...HAND_SPEED, ...options };
|
|
14
|
+
let samples = [];
|
|
15
|
+
let newest = Infinity;
|
|
16
|
+
let step = Infinity;
|
|
17
|
+
let long = null;
|
|
18
|
+
let longs = [];
|
|
19
|
+
let heldTo = null;
|
|
20
|
+
let behind = null;
|
|
21
|
+
const dist = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
22
|
+
const path = () => {
|
|
23
|
+
let sum = 0;
|
|
24
|
+
for (let i = 1; i < samples.length; i++) sum += dist(samples[i - 1].p, samples[i].p);
|
|
25
|
+
return sum;
|
|
26
|
+
};
|
|
27
|
+
const sofar = () => {
|
|
28
|
+
if (long !== null) return long;
|
|
29
|
+
const first = samples[0];
|
|
30
|
+
const lastT = samples[samples.length - 1].t;
|
|
31
|
+
return samples.length > 1 && lastT > first.t ? path() / (lastT - first.t) : null;
|
|
32
|
+
};
|
|
33
|
+
const add = (p, t) => {
|
|
34
|
+
const last = samples[samples.length - 1];
|
|
35
|
+
if (!last) newest = step = Infinity;
|
|
36
|
+
else {
|
|
37
|
+
const d = dist(last.p, p);
|
|
38
|
+
newest = step = d / (t - last.t);
|
|
39
|
+
}
|
|
40
|
+
samples.push({ p, t });
|
|
41
|
+
while (samples.length > o.steps + 1 && t - samples[1].t >= o.span) samples.shift();
|
|
42
|
+
const first = samples[0];
|
|
43
|
+
if (samples.length > o.steps && t - first.t >= o.span) {
|
|
44
|
+
long = path() / (t - first.t);
|
|
45
|
+
longs.push({ t, v: long });
|
|
46
|
+
while (longs.length > 1 && t - longs[1].t >= o.span / 2) longs.shift();
|
|
47
|
+
} else long = null;
|
|
48
|
+
};
|
|
49
|
+
return {
|
|
50
|
+
push(p, t) {
|
|
51
|
+
const last = samples[samples.length - 1];
|
|
52
|
+
const seenStill = !!last && heldTo !== null && heldTo - last.t >= o.still;
|
|
53
|
+
if (!last) {
|
|
54
|
+
heldTo = behind = null;
|
|
55
|
+
add(p, t);
|
|
56
|
+
return;
|
|
57
|
+
}
|
|
58
|
+
const dt = t - last.t;
|
|
59
|
+
if (sampleOrder(last.t, t) !== "next") {
|
|
60
|
+
if (dt > -Math.max(o.gap, SAME_SAMPLE)) return;
|
|
61
|
+
if (behind === null || t < behind) behind = t;
|
|
62
|
+
if (t - behind < Math.max(o.still, SAME_SAMPLE)) return;
|
|
63
|
+
heldTo = behind = null;
|
|
64
|
+
samples = [{ p, t }];
|
|
65
|
+
newest = step = Infinity;
|
|
66
|
+
long = null;
|
|
67
|
+
longs = [];
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
heldTo = behind = null;
|
|
71
|
+
const d = dist(last.p, p);
|
|
72
|
+
const across = d <= o.slowStep ? d / dt : Infinity;
|
|
73
|
+
if (dt >= o.gap) {
|
|
74
|
+
const v = sofar();
|
|
75
|
+
if (seenStill || v === null || d / dt < v * o.carry) {
|
|
76
|
+
samples = [{ p, t }];
|
|
77
|
+
newest = step = across;
|
|
78
|
+
long = null;
|
|
79
|
+
longs = [];
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
let frame = 1;
|
|
84
|
+
for (let i = 1; i < samples.length; i++) frame = Math.max(frame, samples[i].t - samples[i - 1].t);
|
|
85
|
+
if (!seenStill && samples.length > 1 && (dt >= o.gap || dt >= o.fill * frame)) {
|
|
86
|
+
const n = Math.floor(dt / frame);
|
|
87
|
+
for (let i = Math.max(1, n - FILL_MAX); i < n; i++) add({ x: last.p.x + (p.x - last.p.x) * i / n, y: last.p.y + (p.y - last.p.y) * i / n }, last.t + dt * i / n);
|
|
88
|
+
}
|
|
89
|
+
add(p, t);
|
|
90
|
+
if (dt >= o.gap) step = across;
|
|
91
|
+
},
|
|
92
|
+
hold(t) {
|
|
93
|
+
const last = samples[samples.length - 1];
|
|
94
|
+
if (last && t > last.t) {
|
|
95
|
+
heldTo = t;
|
|
96
|
+
behind = null;
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
reset() {
|
|
100
|
+
samples = [];
|
|
101
|
+
newest = step = Infinity;
|
|
102
|
+
long = null;
|
|
103
|
+
longs = [];
|
|
104
|
+
heldTo = behind = null;
|
|
105
|
+
},
|
|
106
|
+
get step() {
|
|
107
|
+
return step;
|
|
108
|
+
},
|
|
109
|
+
get long() {
|
|
110
|
+
return long;
|
|
111
|
+
},
|
|
112
|
+
get speed() {
|
|
113
|
+
return long === null ? newest : Math.max(newest, long);
|
|
114
|
+
},
|
|
115
|
+
get steady() {
|
|
116
|
+
const then = longs[0];
|
|
117
|
+
return long !== null && newest <= long * o.accelerating && !!then && longs[longs.length - 1].t - then.t >= o.span / 2 && long <= then.v * o.gathering;
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
|
|
8
122
|
// src/drag/intent.ts
|
|
9
123
|
var DRAG_DEFAULTS = {
|
|
10
124
|
lift: 5,
|
|
@@ -83,6 +197,8 @@ function createDragIntent(options) {
|
|
|
83
197
|
let restart = false;
|
|
84
198
|
let bounds = options.bounds ? { ...options.bounds } : void 0;
|
|
85
199
|
let lastPoint = null;
|
|
200
|
+
let lastT = 0;
|
|
201
|
+
let unseen = false;
|
|
86
202
|
const clampInto = (p) => bounds ? { x: Math.min(Math.max(p.x, bounds.x), bounds.x + bounds.width), y: Math.min(Math.max(p.y, bounds.y), bounds.y + bounds.height) } : p;
|
|
87
203
|
let armedId = null;
|
|
88
204
|
let armingId = null;
|
|
@@ -143,10 +259,11 @@ function createDragIntent(options) {
|
|
|
143
259
|
const p = clampInto(point);
|
|
144
260
|
lastPoint = p;
|
|
145
261
|
const t = time;
|
|
262
|
+
lastT = t;
|
|
146
263
|
samples.push({ x: p.x, y: p.y, t });
|
|
147
264
|
while (samples.length > 2 && t - samples[0].t > tuning.speedWindow) samples.shift();
|
|
148
265
|
const a = samples[0];
|
|
149
|
-
speed = speed * 0.5 + Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t) * 0.5;
|
|
266
|
+
if (!unseen) speed = speed * 0.5 + Math.hypot(p.x - a.x, p.y - a.y) / Math.max(1, t - a.t) * 0.5;
|
|
150
267
|
if (!anchor || Math.hypot(p.x - anchor.x, p.y - anchor.y) > tuning.still) {
|
|
151
268
|
anchor = { x: p.x, y: p.y };
|
|
152
269
|
stillSince = t;
|
|
@@ -250,7 +367,14 @@ function createDragIntent(options) {
|
|
|
250
367
|
update,
|
|
251
368
|
release(point, time, given, keys) {
|
|
252
369
|
const p = clampInto(point);
|
|
253
|
-
if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y)
|
|
370
|
+
if (!lastPoint || lastPoint.x !== p.x || lastPoint.y !== p.y) {
|
|
371
|
+
unseen = !!lastPoint && time - lastT >= HAND_SPEED.gap;
|
|
372
|
+
try {
|
|
373
|
+
update(p, unseen ? lastT : time, given, keys);
|
|
374
|
+
} finally {
|
|
375
|
+
unseen = false;
|
|
376
|
+
}
|
|
377
|
+
}
|
|
254
378
|
return landAt(p, given, keys);
|
|
255
379
|
},
|
|
256
380
|
setBounds(next) {
|
|
@@ -275,120 +399,6 @@ function createDragIntent(options) {
|
|
|
275
399
|
};
|
|
276
400
|
}
|
|
277
401
|
|
|
278
|
-
// src/drag/hand-speed.ts
|
|
279
|
-
var HAND_SLOW_STEP = 3;
|
|
280
|
-
var HAND_SPEED = { span: 48, steps: 5, gap: 40, slowStep: HAND_SLOW_STEP, still: 20, carry: 0.5, fill: 2.5, accelerating: 1.5, gathering: 1.25 };
|
|
281
|
-
var FILL_MAX = 32;
|
|
282
|
-
function createHandSpeed(options = {}) {
|
|
283
|
-
const o = { ...HAND_SPEED, ...options };
|
|
284
|
-
let samples = [];
|
|
285
|
-
let newest = Infinity;
|
|
286
|
-
let step = Infinity;
|
|
287
|
-
let long = null;
|
|
288
|
-
let longs = [];
|
|
289
|
-
let heldTo = null;
|
|
290
|
-
let behind = null;
|
|
291
|
-
const dist = (a, b) => Math.hypot(b.x - a.x, b.y - a.y);
|
|
292
|
-
const path = () => {
|
|
293
|
-
let sum = 0;
|
|
294
|
-
for (let i = 1; i < samples.length; i++) sum += dist(samples[i - 1].p, samples[i].p);
|
|
295
|
-
return sum;
|
|
296
|
-
};
|
|
297
|
-
const sofar = () => {
|
|
298
|
-
if (long !== null) return long;
|
|
299
|
-
const first = samples[0];
|
|
300
|
-
const lastT = samples[samples.length - 1].t;
|
|
301
|
-
return samples.length > 1 && lastT > first.t ? path() / (lastT - first.t) : null;
|
|
302
|
-
};
|
|
303
|
-
const add = (p, t) => {
|
|
304
|
-
const last = samples[samples.length - 1];
|
|
305
|
-
if (!last) newest = step = Infinity;
|
|
306
|
-
else {
|
|
307
|
-
const d = dist(last.p, p);
|
|
308
|
-
newest = step = d / (t - last.t);
|
|
309
|
-
}
|
|
310
|
-
samples.push({ p, t });
|
|
311
|
-
while (samples.length > o.steps + 1 && t - samples[1].t >= o.span) samples.shift();
|
|
312
|
-
const first = samples[0];
|
|
313
|
-
if (samples.length > o.steps && t - first.t >= o.span) {
|
|
314
|
-
long = path() / (t - first.t);
|
|
315
|
-
longs.push({ t, v: long });
|
|
316
|
-
while (longs.length > 1 && t - longs[1].t >= o.span / 2) longs.shift();
|
|
317
|
-
} else long = null;
|
|
318
|
-
};
|
|
319
|
-
return {
|
|
320
|
-
push(p, t) {
|
|
321
|
-
const last = samples[samples.length - 1];
|
|
322
|
-
const seenStill = !!last && heldTo !== null && heldTo - last.t >= o.still;
|
|
323
|
-
if (!last) {
|
|
324
|
-
heldTo = behind = null;
|
|
325
|
-
add(p, t);
|
|
326
|
-
return;
|
|
327
|
-
}
|
|
328
|
-
const dt = t - last.t;
|
|
329
|
-
if (sampleOrder(last.t, t) !== "next") {
|
|
330
|
-
if (dt > -Math.max(o.gap, SAME_SAMPLE)) return;
|
|
331
|
-
if (behind === null || t < behind) behind = t;
|
|
332
|
-
if (t - behind < Math.max(o.still, SAME_SAMPLE)) return;
|
|
333
|
-
heldTo = behind = null;
|
|
334
|
-
samples = [{ p, t }];
|
|
335
|
-
newest = step = Infinity;
|
|
336
|
-
long = null;
|
|
337
|
-
longs = [];
|
|
338
|
-
return;
|
|
339
|
-
}
|
|
340
|
-
heldTo = behind = null;
|
|
341
|
-
const d = dist(last.p, p);
|
|
342
|
-
const across = d <= o.slowStep ? d / dt : Infinity;
|
|
343
|
-
if (dt >= o.gap) {
|
|
344
|
-
const v = sofar();
|
|
345
|
-
if (seenStill || v === null || d / dt < v * o.carry) {
|
|
346
|
-
samples = [{ p, t }];
|
|
347
|
-
newest = step = across;
|
|
348
|
-
long = null;
|
|
349
|
-
longs = [];
|
|
350
|
-
return;
|
|
351
|
-
}
|
|
352
|
-
}
|
|
353
|
-
let frame = 1;
|
|
354
|
-
for (let i = 1; i < samples.length; i++) frame = Math.max(frame, samples[i].t - samples[i - 1].t);
|
|
355
|
-
if (!seenStill && samples.length > 1 && (dt >= o.gap || dt >= o.fill * frame)) {
|
|
356
|
-
const n = Math.floor(dt / frame);
|
|
357
|
-
for (let i = Math.max(1, n - FILL_MAX); i < n; i++) add({ x: last.p.x + (p.x - last.p.x) * i / n, y: last.p.y + (p.y - last.p.y) * i / n }, last.t + dt * i / n);
|
|
358
|
-
}
|
|
359
|
-
add(p, t);
|
|
360
|
-
if (dt >= o.gap) step = across;
|
|
361
|
-
},
|
|
362
|
-
hold(t) {
|
|
363
|
-
const last = samples[samples.length - 1];
|
|
364
|
-
if (last && t > last.t) {
|
|
365
|
-
heldTo = t;
|
|
366
|
-
behind = null;
|
|
367
|
-
}
|
|
368
|
-
},
|
|
369
|
-
reset() {
|
|
370
|
-
samples = [];
|
|
371
|
-
newest = step = Infinity;
|
|
372
|
-
long = null;
|
|
373
|
-
longs = [];
|
|
374
|
-
heldTo = behind = null;
|
|
375
|
-
},
|
|
376
|
-
get step() {
|
|
377
|
-
return step;
|
|
378
|
-
},
|
|
379
|
-
get long() {
|
|
380
|
-
return long;
|
|
381
|
-
},
|
|
382
|
-
get speed() {
|
|
383
|
-
return long === null ? newest : Math.max(newest, long);
|
|
384
|
-
},
|
|
385
|
-
get steady() {
|
|
386
|
-
const then = longs[0];
|
|
387
|
-
return long !== null && newest <= long * o.accelerating && !!then && longs[longs.length - 1].t - then.t >= o.span / 2 && long <= then.v * o.gathering;
|
|
388
|
-
}
|
|
389
|
-
};
|
|
390
|
-
}
|
|
391
|
-
|
|
392
402
|
// src/drag/preview.ts
|
|
393
403
|
var DRAG_PREVIEW_DEFAULT = { mode: "glide" };
|
|
394
404
|
var PLACE_GUIDES_DEFAULT = { outline: "off", placeholder: "near", glide: "off", snap: "near" };
|
|
@@ -484,7 +494,9 @@ function createLandingModel(options) {
|
|
|
484
494
|
let flung = false;
|
|
485
495
|
let slowFrom = null;
|
|
486
496
|
let lastStep = 0;
|
|
487
|
-
const
|
|
497
|
+
const handGap = Math.min(HAND_SPEED.gap, gates.pause);
|
|
498
|
+
const hand = createHandSpeed({ gap: handGap, still: Math.min(HAND_SPEED.still, gates.rest) });
|
|
499
|
+
let unseen = false;
|
|
488
500
|
let lastKeys;
|
|
489
501
|
const pathIn = /* @__PURE__ */ new Map();
|
|
490
502
|
const slide = /* @__PURE__ */ new Map();
|
|
@@ -594,7 +606,7 @@ function createLandingModel(options) {
|
|
|
594
606
|
const before = moved.t;
|
|
595
607
|
moved = { raw, t };
|
|
596
608
|
hand.push(raw, t);
|
|
597
|
-
step = hand.step;
|
|
609
|
+
step = unseen ? Infinity : hand.step;
|
|
598
610
|
lastStep = step;
|
|
599
611
|
const sp = hand.speed;
|
|
600
612
|
if (Number.isFinite(sp) && sp > gates.slideSpeed) {
|
|
@@ -634,7 +646,7 @@ function createLandingModel(options) {
|
|
|
634
646
|
const inL = strictlyIn(l.rect, p);
|
|
635
647
|
pathIn.set(l.id, inL ? (pathIn.get(l.id) ?? 0) + (slow ? go : 0) : 0);
|
|
636
648
|
const s = slide.get(l.id);
|
|
637
|
-
const counts = hand.steady && hand.speed <= gates.slideSpeed;
|
|
649
|
+
const counts = !unseen && hand.steady && hand.speed <= gates.slideSpeed;
|
|
638
650
|
const u = !was && inL && from && fromRaw ? entryOf(l.rect, from, p) : 0;
|
|
639
651
|
const by = was ? { along: go, across: over } : u > 0 && from && fromRaw ? { along: Math.abs(alongOf(l, p) - alongOf(l, lerp(from, p, u))), across: Math.abs(acrossOf(l, raw) - acrossOf(l, lerp(fromRaw, raw, u))) } : { along: 0, across: 0 };
|
|
640
652
|
slide.set(l.id, !inL ? { along: 0, across: 0 } : counts ? { along: (s?.along ?? 0) + by.along, across: (s?.across ?? 0) + by.across } : s ?? { along: 0, across: 0 });
|
|
@@ -733,7 +745,14 @@ function createLandingModel(options) {
|
|
|
733
745
|
return {
|
|
734
746
|
update,
|
|
735
747
|
release(point, time, keys) {
|
|
736
|
-
if (!last || last.raw.x !== point.x || last.raw.y !== point.y)
|
|
748
|
+
if (!last || last.raw.x !== point.x || last.raw.y !== point.y) {
|
|
749
|
+
unseen = !!last && time - last.t >= handGap;
|
|
750
|
+
try {
|
|
751
|
+
update(point, time, keys ?? lastKeys);
|
|
752
|
+
} finally {
|
|
753
|
+
unseen = false;
|
|
754
|
+
}
|
|
755
|
+
}
|
|
737
756
|
const s = frame.held;
|
|
738
757
|
if (s?.kind === "spot" && frame.region === "lane") {
|
|
739
758
|
const ownSpot = !!options.home && options.home.spot === s.spot && options.home.lane === s.lane;
|
|
@@ -978,4 +997,4 @@ export {
|
|
|
978
997
|
MIN_BOX_LENGTH,
|
|
979
998
|
guideRects
|
|
980
999
|
};
|
|
981
|
-
//# sourceMappingURL=chunk-
|
|
1000
|
+
//# sourceMappingURL=chunk-XKCRMQZQ.js.map
|