motionary 10.7.0 → 10.8.0

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 (129) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/README.md +42 -3
  3. package/dist/chunks/{anim-image-CFGpUX7t.cjs → anim-image-BzTQa2k3.cjs} +2 -2
  4. package/dist/chunks/{anim-image-CFGpUX7t.cjs.map → anim-image-BzTQa2k3.cjs.map} +1 -1
  5. package/dist/chunks/{anim-image-CXDD19FH.js → anim-image-iD646Q7i.js} +2 -2
  6. package/dist/chunks/{anim-image-CXDD19FH.js.map → anim-image-iD646Q7i.js.map} +1 -1
  7. package/dist/chunks/{keyframes-DwR6GPej.js → keyframes-B4zefz0k.js} +2 -2
  8. package/dist/chunks/{keyframes-DwR6GPej.js.map → keyframes-B4zefz0k.js.map} +1 -1
  9. package/dist/chunks/{keyframes-DdwGY1gr.cjs → keyframes-BlOyB1PP.cjs} +2 -2
  10. package/dist/chunks/{keyframes-DdwGY1gr.cjs.map → keyframes-BlOyB1PP.cjs.map} +1 -1
  11. package/dist/chunks/{registry-DhKZCitb.cjs → registry-BZxDVL3h.cjs} +2 -2
  12. package/dist/chunks/{registry-DhKZCitb.cjs.map → registry-BZxDVL3h.cjs.map} +1 -1
  13. package/dist/chunks/{registry-D87dP_aR.js → registry-Bkt3-3ET.js} +3 -3
  14. package/dist/chunks/{registry-D87dP_aR.js.map → registry-Bkt3-3ET.js.map} +1 -1
  15. package/dist/chunks/runtime-link-CUiZ8lbE.cjs +38 -0
  16. package/dist/chunks/runtime-link-CUiZ8lbE.cjs.map +1 -0
  17. package/dist/chunks/runtime-link-c13gskBZ.js +36 -0
  18. package/dist/chunks/runtime-link-c13gskBZ.js.map +1 -0
  19. package/dist/chunks/{ticker-jD9_A9Rh.cjs → ticker-BfxAECfO.cjs} +2 -2
  20. package/dist/chunks/{ticker-jD9_A9Rh.cjs.map → ticker-BfxAECfO.cjs.map} +1 -1
  21. package/dist/chunks/{ticker-CJYI5Pxc.js → ticker-ZtweD3U4.js} +2 -2
  22. package/dist/chunks/{ticker-CJYI5Pxc.js.map → ticker-ZtweD3U4.js.map} +1 -1
  23. package/dist/chunks/{tween-Dk0QmNe9.cjs → tween--MD-39y0.cjs} +2 -2
  24. package/dist/chunks/{tween-Dk0QmNe9.cjs.map → tween--MD-39y0.cjs.map} +1 -1
  25. package/dist/chunks/{tween-_Lld1MsF.js → tween-DACdkLyO.js} +2 -2
  26. package/dist/chunks/{tween-_Lld1MsF.js.map → tween-DACdkLyO.js.map} +1 -1
  27. package/dist/components/snap-carousel.cjs +216 -0
  28. package/dist/components/snap-carousel.cjs.map +1 -0
  29. package/dist/components/snap-carousel.d.cts +80 -0
  30. package/dist/components/snap-carousel.d.ts +80 -0
  31. package/dist/components/snap-carousel.js +214 -0
  32. package/dist/components/snap-carousel.js.map +1 -0
  33. package/dist/components/widgets.cjs +32 -46
  34. package/dist/components/widgets.cjs.map +1 -1
  35. package/dist/components/widgets.d.cts +77 -4
  36. package/dist/components/widgets.d.ts +77 -4
  37. package/dist/components/widgets.js +22 -36
  38. package/dist/components/widgets.js.map +1 -1
  39. package/dist/llms-full.txt +94 -6
  40. package/dist/llms.txt +6 -3
  41. package/dist/manifest.json +260 -19
  42. package/dist/runtime/drag-snap.cjs +269 -0
  43. package/dist/runtime/drag-snap.cjs.map +1 -0
  44. package/dist/runtime/drag-snap.d.cts +109 -0
  45. package/dist/runtime/drag-snap.d.ts +109 -0
  46. package/dist/runtime/drag-snap.iife.js +2 -0
  47. package/dist/runtime/drag-snap.iife.js.map +1 -0
  48. package/dist/runtime/drag-snap.js +261 -0
  49. package/dist/runtime/drag-snap.js.map +1 -0
  50. package/dist/runtime/format-apng.cjs +4 -4
  51. package/dist/runtime/format-apng.js +4 -4
  52. package/dist/runtime/format-css.cjs +4 -4
  53. package/dist/runtime/format-css.js +4 -4
  54. package/dist/runtime/format-gif.cjs +4 -4
  55. package/dist/runtime/format-gif.js +4 -4
  56. package/dist/runtime/format-gltf.cjs +37 -18
  57. package/dist/runtime/format-gltf.cjs.map +1 -1
  58. package/dist/runtime/format-gltf.d.cts +18 -2
  59. package/dist/runtime/format-gltf.d.ts +18 -2
  60. package/dist/runtime/format-gltf.iife.js +1 -1
  61. package/dist/runtime/format-gltf.iife.js.map +1 -1
  62. package/dist/runtime/format-gltf.js +37 -18
  63. package/dist/runtime/format-gltf.js.map +1 -1
  64. package/dist/runtime/format-motion.cjs +4 -4
  65. package/dist/runtime/format-motion.js +4 -4
  66. package/dist/runtime/format-obj.cjs +1 -1
  67. package/dist/runtime/format-obj.d.cts +2 -0
  68. package/dist/runtime/format-obj.d.ts +2 -0
  69. package/dist/runtime/format-obj.iife.js.map +1 -1
  70. package/dist/runtime/format-obj.js +1 -1
  71. package/dist/runtime/format-scene.cjs +1 -1
  72. package/dist/runtime/format-scene.js +1 -1
  73. package/dist/runtime/format-sprite.cjs +3 -3
  74. package/dist/runtime/format-sprite.js +3 -3
  75. package/dist/runtime/format-svg.cjs +3 -3
  76. package/dist/runtime/format-svg.js +3 -3
  77. package/dist/runtime/format-webp.cjs +4 -4
  78. package/dist/runtime/format-webp.js +4 -4
  79. package/dist/runtime/gl.cjs +17 -4
  80. package/dist/runtime/gl.cjs.map +1 -1
  81. package/dist/runtime/gl.d.cts +2 -0
  82. package/dist/runtime/gl.d.ts +2 -0
  83. package/dist/runtime/gl.iife.js +1 -1
  84. package/dist/runtime/gl.iife.js.map +1 -1
  85. package/dist/runtime/gl.js +17 -4
  86. package/dist/runtime/gl.js.map +1 -1
  87. package/dist/runtime/gltf-anim.cjs +251 -0
  88. package/dist/runtime/gltf-anim.cjs.map +1 -0
  89. package/dist/runtime/gltf-anim.d.cts +216 -0
  90. package/dist/runtime/gltf-anim.d.ts +216 -0
  91. package/dist/runtime/gltf-anim.iife.js +2 -0
  92. package/dist/runtime/gltf-anim.iife.js.map +1 -0
  93. package/dist/runtime/gltf-anim.js +243 -0
  94. package/dist/runtime/gltf-anim.js.map +1 -0
  95. package/dist/runtime/physics.cjs +1 -1
  96. package/dist/runtime/physics.js +1 -1
  97. package/dist/runtime/scroll.cjs +2 -2
  98. package/dist/runtime/scroll.js +2 -2
  99. package/dist/runtime/smooth.cjs +1 -1
  100. package/dist/runtime/smooth.js +1 -1
  101. package/dist/runtime/text.cjs +1 -1
  102. package/dist/runtime/text.js +1 -1
  103. package/dist/runtime/vector.cjs +421 -11
  104. package/dist/runtime/vector.cjs.map +1 -1
  105. package/dist/runtime/vector.d.cts +20 -4
  106. package/dist/runtime/vector.d.ts +20 -4
  107. package/dist/runtime/vector.iife.js +1 -1
  108. package/dist/runtime/vector.iife.js.map +1 -1
  109. package/dist/runtime/vector.js +421 -12
  110. package/dist/runtime/vector.js.map +1 -1
  111. package/dist/runtime.cjs +3 -3
  112. package/dist/runtime.d.cts +1 -1
  113. package/dist/runtime.d.ts +1 -1
  114. package/dist/runtime.iife.js +1 -1
  115. package/dist/runtime.iife.js.map +1 -1
  116. package/dist/runtime.js +5 -5
  117. package/dist/widgets.umd.js +1 -1
  118. package/dist/widgets.umd.js.map +1 -1
  119. package/docs/ROADMAP.md +1 -1
  120. package/docs/components/README.md +3 -2
  121. package/docs/components/usa-gl-scene.md +27 -6
  122. package/docs/components/usa-lottie-player.md +18 -0
  123. package/docs/components/usa-snap-carousel.md +68 -0
  124. package/docs/components.md +51 -3
  125. package/docs/runtime/drag-snap.md +60 -0
  126. package/docs/runtime/format-gltf.md +3 -2
  127. package/docs/runtime/gltf-anim.md +62 -0
  128. package/docs/runtime/vector.md +3 -2
  129. package/package.json +31 -1
@@ -0,0 +1,269 @@
1
+ 'use strict';
2
+
3
+ var registry = require('../chunks/registry-BZxDVL3h.cjs');
4
+
5
+ /**
6
+ * `motionary/runtime/drag-snap` (10.8) — pointer drag with inertia and snap
7
+ * points, for carousels, sheets, sliders and pickers (own implementation).
8
+ *
9
+ * - one axis (`x` / `y`) per controller; pointer, touch and pen through
10
+ * Pointer Events, a movement threshold before a drag starts (so clicks
11
+ * inside still work), `touch-action` set for the other axis;
12
+ * - velocity from the last 100 ms of samples; release projects the throw
13
+ * with constant deceleration and snaps to the nearest point (or to the
14
+ * next / previous point for a fast flick, `flick`), with a critically
15
+ * damped spring on the shared ticker;
16
+ * - bounds with rubber-band resistance past the ends;
17
+ * - `createDragSnap(el, options)`; `snapTo(index)`, `setPosition(px)`, `setSnapPoints([...])`; reduced
18
+ * motion: no inertia, snaps without the spring.
19
+ *
20
+ * The maths (`projectThrow`, `nearestSnap`, `rubberband`, `springStep`,
21
+ * `velocityTracker`) is pure and exported for tests / workers.
22
+ */
23
+ /** Where a throw at `velocity` (px/s) ends with constant `deceleration` (px/s²). */
24
+ function projectThrow(position, velocity, deceleration = 3000) {
25
+ return position + (velocity * Math.abs(velocity)) / (2 * Math.max(1, deceleration));
26
+ }
27
+ /** Index of the snap point nearest to `p` (points in any order). */
28
+ function nearestSnap(points, p) {
29
+ let best = 0, d = Infinity;
30
+ points.forEach((x, i) => {
31
+ const e = Math.abs(x - p);
32
+ if (e < d)
33
+ (d = e), (best = i);
34
+ });
35
+ return best;
36
+ }
37
+ /** Rubber-band: how far content moves when dragged `over` px past an edge of a `size` px viewport. */
38
+ function rubberband(over, size, c = 0.55) {
39
+ const s = Math.sign(over), x = Math.abs(over);
40
+ return s * (1 - 1 / ((x * c) / Math.max(1, size) + 1)) * size;
41
+ }
42
+ /** One semi-implicit Euler step of a damped spring towards `target`. Returns [position, velocity]. */
43
+ function springStep(x, v, target, dt, stiffness = 260, damping = 2 * Math.sqrt(260)) {
44
+ const a = -stiffness * (x - target) - damping * v;
45
+ const nv = v + a * dt;
46
+ return [x + nv * dt, nv];
47
+ }
48
+ /** Velocity estimate (units/s) from the samples of the last `window` ms. */
49
+ function velocityTracker(window = 100) {
50
+ let s = [];
51
+ return {
52
+ add(t, p) {
53
+ s.push([t, p]);
54
+ while (s.length > 2 && t - s[0][0] > window)
55
+ s.shift();
56
+ },
57
+ velocity(now) {
58
+ if (s.length < 2)
59
+ return 0;
60
+ const [t1, p1] = s[s.length - 1];
61
+ if (now !== undefined && now - t1 > 60)
62
+ return 0; // finger stopped before release
63
+ const [t0, p0] = s[0];
64
+ return t1 > t0 ? ((p1 - p0) / (t1 - t0)) * 1000 : 0;
65
+ },
66
+ reset() {
67
+ s = [];
68
+ },
69
+ };
70
+ }
71
+ /** Make `el` draggable along one axis; `onUpdate(px)` applies the position (e.g. a transform). */
72
+ function createDragSnap(el, o = {}) {
73
+ const core = registry.requireModule('core', 'motionary/runtime/drag-snap');
74
+ const X = (o.axis || 'x') === 'x';
75
+ let points = (o.snap || []).slice();
76
+ let lo = 0, hi = 0;
77
+ const setBounds = (b) => {
78
+ if (b)
79
+ [lo, hi] = [Math.min(b[0], b[1]), Math.max(b[0], b[1])];
80
+ else if (points.length)
81
+ [lo, hi] = [Math.min(...points), Math.max(...points)];
82
+ else
83
+ [lo, hi] = [-Infinity, Infinity];
84
+ };
85
+ setBounds(o.bounds);
86
+ let pos = o.position ?? (points.length ? points[0] : 0), vel = 0, target = null, idx = points.length ? nearestSnap(points, pos) : 0;
87
+ let drag = false, down = false, startP = 0, startPos = 0, pid = -1, off = null;
88
+ const vt = velocityTracker();
89
+ const reduced = () => !!o.reducedMotion;
90
+ const clampB = (p) => Math.min(hi, Math.max(lo, p));
91
+ const emit = () => o.onUpdate?.(pos);
92
+ const stop = () => {
93
+ off?.();
94
+ off = null;
95
+ };
96
+ const settle = (t, animate = true) => {
97
+ target = t;
98
+ if (!animate || reduced()) {
99
+ pos = t;
100
+ vel = 0;
101
+ target = null;
102
+ stop();
103
+ emit();
104
+ if (points.length)
105
+ o.onSnap?.(idx, pos);
106
+ return;
107
+ }
108
+ if (!off)
109
+ off = core.getTicker().add((_, ms) => {
110
+ if (target === null)
111
+ return stop();
112
+ let left = Math.min(ms, 64) / 1000;
113
+ while (left > 0) {
114
+ const dt = Math.min(left, 1 / 120);
115
+ [pos, vel] = springStep(pos, vel, target, dt, o.stiffness, o.damping);
116
+ left -= dt;
117
+ }
118
+ if (Math.abs(pos - target) < 0.3 && Math.abs(vel) < 8) {
119
+ pos = target;
120
+ vel = 0;
121
+ target = null;
122
+ stop();
123
+ emit();
124
+ if (points.length)
125
+ o.onSnap?.(idx, pos);
126
+ return;
127
+ }
128
+ emit();
129
+ });
130
+ };
131
+ const targetFor = (p, v) => {
132
+ if (!points.length)
133
+ return -1;
134
+ const thrown = o.inertia === false || reduced() ? p : projectThrow(p, v, o.deceleration);
135
+ let i = nearestSnap(points, thrown);
136
+ const from = nearestSnap(points, startPos);
137
+ if (i === from && Math.abs(v) > (o.flick ?? 400)) {
138
+ // a short fast flick still moves one point in the throw direction
139
+ const sorted = points.map((x, k) => [x, k]).sort((a, b) => a[0] - b[0]);
140
+ const at = sorted.findIndex((s) => s[1] === from);
141
+ const n = sorted[at + (v > 0 ? 1 : -1)];
142
+ if (n)
143
+ i = n[1];
144
+ }
145
+ return i;
146
+ };
147
+ const coord = (e) => (X ? e.clientX : e.clientY);
148
+ const onDown = (e) => {
149
+ if (e.button > 0 || down)
150
+ return;
151
+ down = true;
152
+ drag = false;
153
+ pid = e.pointerId;
154
+ startP = coord(e);
155
+ startPos = pos;
156
+ vt.reset();
157
+ vt.add(e.timeStamp ?? performance.now(), pos);
158
+ };
159
+ const onMove = (e) => {
160
+ if (!down || e.pointerId !== pid)
161
+ return;
162
+ const d = coord(e) - startP;
163
+ if (!drag) {
164
+ if (Math.abs(d) < (o.threshold ?? 4))
165
+ return;
166
+ drag = true;
167
+ target = null;
168
+ stop();
169
+ try {
170
+ el.setPointerCapture?.(pid);
171
+ }
172
+ catch {
173
+ /* synthetic events */
174
+ }
175
+ o.onDragStart?.();
176
+ }
177
+ const raw = startPos + d;
178
+ const r = o.resistance ?? 0.55;
179
+ const size = (X ? el.parentElement?.clientWidth : el.parentElement?.clientHeight) || 300;
180
+ pos = raw < lo ? (r ? lo + rubberband(raw - lo, size, r) : lo) : raw > hi ? (r ? hi + rubberband(raw - hi, size, r) : hi) : raw;
181
+ vt.add(e.timeStamp ?? performance.now(), pos);
182
+ emit();
183
+ e.preventDefault?.();
184
+ };
185
+ const onUp = (e) => {
186
+ if (!down || e.pointerId !== pid)
187
+ return;
188
+ down = false;
189
+ if (!drag)
190
+ return;
191
+ drag = false;
192
+ const v = vt.velocity(e.timeStamp ?? performance.now());
193
+ o.onDragEnd?.(v);
194
+ // a click right after a drag must not activate links / buttons inside
195
+ const eat = (c) => (c.stopPropagation(), c.preventDefault());
196
+ el.addEventListener('click', eat, { capture: true, once: true });
197
+ setTimeout(() => el.removeEventListener('click', eat, { capture: true }), 0);
198
+ vel = reduced() ? 0 : v;
199
+ if (points.length) {
200
+ idx = targetFor(pos, v);
201
+ settle(points[idx]);
202
+ }
203
+ else
204
+ settle(clampB(o.inertia === false || reduced() ? pos : projectThrow(pos, v, o.deceleration)));
205
+ };
206
+ el.style.touchAction = X ? 'pan-y' : 'pan-x';
207
+ el.addEventListener('pointerdown', onDown);
208
+ el.addEventListener('pointermove', onMove);
209
+ el.addEventListener('pointerup', onUp);
210
+ el.addEventListener('pointercancel', onUp);
211
+ emit();
212
+ return {
213
+ get position() {
214
+ return pos;
215
+ },
216
+ get index() {
217
+ return idx;
218
+ },
219
+ get dragging() {
220
+ return drag;
221
+ },
222
+ get moving() {
223
+ return target !== null || drag;
224
+ },
225
+ snapTo(i, animate = true) {
226
+ if (!points.length)
227
+ return;
228
+ idx = Math.max(0, Math.min(points.length - 1, Math.round(i)));
229
+ vel = 0;
230
+ settle(points[idx], animate);
231
+ },
232
+ setPosition(px, animate = false) {
233
+ vel = 0;
234
+ if (points.length)
235
+ idx = nearestSnap(points, px);
236
+ settle(clampB(px), animate);
237
+ },
238
+ setSnapPoints(p, b) {
239
+ points = p.slice();
240
+ setBounds(b);
241
+ if (points.length) {
242
+ idx = Math.min(idx, points.length - 1);
243
+ pos = points[idx];
244
+ target = null;
245
+ stop();
246
+ emit();
247
+ }
248
+ },
249
+ targetFor,
250
+ dispose() {
251
+ stop();
252
+ el.removeEventListener('pointerdown', onDown);
253
+ el.removeEventListener('pointermove', onMove);
254
+ el.removeEventListener('pointerup', onUp);
255
+ el.removeEventListener('pointercancel', onUp);
256
+ },
257
+ };
258
+ }
259
+ /** The module object: `use(dragSnap)`. */
260
+ const dragSnap = { id: 'drag-snap', version: registry.RUNTIME_VERSION, requires: ['core'], api: { createDragSnap, projectThrow, nearestSnap, rubberband, springStep, velocityTracker } };
261
+
262
+ exports.createDragSnap = createDragSnap;
263
+ exports.dragSnap = dragSnap;
264
+ exports.nearestSnap = nearestSnap;
265
+ exports.projectThrow = projectThrow;
266
+ exports.rubberband = rubberband;
267
+ exports.springStep = springStep;
268
+ exports.velocityTracker = velocityTracker;
269
+ //# sourceMappingURL=drag-snap.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-snap.cjs","sources":["../../src/runtime/drag-snap.ts"],"sourcesContent":["/**\n * `motionary/runtime/drag-snap` (10.8) — pointer drag with inertia and snap\n * points, for carousels, sheets, sliders and pickers (own implementation).\n *\n * - one axis (`x` / `y`) per controller; pointer, touch and pen through\n * Pointer Events, a movement threshold before a drag starts (so clicks\n * inside still work), `touch-action` set for the other axis;\n * - velocity from the last 100 ms of samples; release projects the throw\n * with constant deceleration and snaps to the nearest point (or to the\n * next / previous point for a fast flick, `flick`), with a critically\n * damped spring on the shared ticker;\n * - bounds with rubber-band resistance past the ends;\n * - `createDragSnap(el, options)`; `snapTo(index)`, `setPosition(px)`, `setSnapPoints([...])`; reduced\n * motion: no inertia, snaps without the spring.\n *\n * The maths (`projectThrow`, `nearestSnap`, `rubberband`, `springStep`,\n * `velocityTracker`) is pure and exported for tests / workers.\n */\nimport { RUNTIME_VERSION, requireModule, type RuntimeModule } from './registry';\nimport type { CoreApi } from './index';\n\ntype Num = number;\n\n/** Where a throw at `velocity` (px/s) ends with constant `deceleration` (px/s²). */\nexport function projectThrow(position: Num, velocity: Num, deceleration = 3000): Num {\n return position + (velocity * Math.abs(velocity)) / (2 * Math.max(1, deceleration));\n}\n\n/** Index of the snap point nearest to `p` (points in any order). */\nexport function nearestSnap(points: Num[], p: Num): Num {\n let best = 0, d = Infinity;\n points.forEach((x, i) => {\n const e = Math.abs(x - p);\n if (e < d) (d = e), (best = i);\n });\n return best;\n}\n\n/** Rubber-band: how far content moves when dragged `over` px past an edge of a `size` px viewport. */\nexport function rubberband(over: Num, size: Num, c = 0.55): Num {\n const s = Math.sign(over), x = Math.abs(over);\n return s * (1 - 1 / ((x * c) / Math.max(1, size) + 1)) * size;\n}\n\n/** One semi-implicit Euler step of a damped spring towards `target`. Returns [position, velocity]. */\nexport function springStep(x: Num, v: Num, target: Num, dt: Num, stiffness = 260, damping = 2 * Math.sqrt(260)): [Num, Num] {\n const a = -stiffness * (x - target) - damping * v;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\n/** Velocity estimate (units/s) from the samples of the last `window` ms. */\nexport function velocityTracker(window = 100): { add(t: Num, p: Num): void; velocity(now?: Num): Num; reset(): void } {\n let s: [Num, Num][] = [];\n return {\n add(t, p) {\n s.push([t, p]);\n while (s.length > 2 && t - s[0][0] > window) s.shift();\n },\n velocity(now) {\n if (s.length < 2) return 0;\n const [t1, p1] = s[s.length - 1];\n if (now !== undefined && now - t1 > 60) return 0; // finger stopped before release\n const [t0, p0] = s[0];\n return t1 > t0 ? ((p1 - p0) / (t1 - t0)) * 1000 : 0;\n },\n reset() {\n s = [];\n },\n };\n}\n\nexport interface DragSnapOptions {\n /** 'x' (default) or 'y'. */\n axis?: 'x' | 'y';\n /** Snap points in px (content offsets, usually ≤ 0 for a track moved left). Empty = free drag. */\n snap?: Num[];\n /** [min, max] position; defaults to the snap point range. */\n bounds?: [Num, Num];\n /** Throw with inertia on release (default true; off under reduced motion). */\n inertia?: boolean;\n /** Deceleration of a throw in px/s² (default 3000). */\n deceleration?: Num;\n /** A release faster than this (px/s) moves at least one snap point (default 400). */\n flick?: Num;\n /** Spring stiffness (default 260) and damping (default critical). */\n stiffness?: Num;\n damping?: Num;\n /** px before a press becomes a drag (default 4). */\n threshold?: Num;\n /** Rubber-band strength past the bounds (0 = hard stop, default 0.55). */\n resistance?: Num;\n /** Start position (px). */\n position?: Num;\n /** Skip the spring / inertia (reduced motion). */\n reducedMotion?: boolean;\n onUpdate?(position: Num): void;\n onSnap?(index: Num, position: Num): void;\n onDragStart?(): void;\n onDragEnd?(velocity: Num): void;\n}\n\nexport interface DragSnap {\n readonly position: Num;\n readonly index: Num;\n readonly dragging: boolean;\n readonly moving: boolean;\n snapTo(index: Num, animate?: boolean): void;\n setPosition(px: Num, animate?: boolean): void;\n setSnapPoints(points: Num[], bounds?: [Num, Num]): void;\n /** Where a release at `velocity` would come to rest (index). */\n targetFor(position: Num, velocity: Num): Num;\n dispose(): void;\n}\n\n/** Make `el` draggable along one axis; `onUpdate(px)` applies the position (e.g. a transform). */\nexport function createDragSnap(el: HTMLElement, o: DragSnapOptions = {}): DragSnap {\n const core = requireModule<CoreApi>('core', 'motionary/runtime/drag-snap');\n const X = (o.axis || 'x') === 'x';\n let points = (o.snap || []).slice();\n let lo = 0, hi = 0;\n const setBounds = (b?: [Num, Num]) => {\n if (b) [lo, hi] = [Math.min(b[0], b[1]), Math.max(b[0], b[1])];\n else if (points.length) [lo, hi] = [Math.min(...points), Math.max(...points)];\n else [lo, hi] = [-Infinity, Infinity];\n };\n setBounds(o.bounds);\n let pos = o.position ?? (points.length ? points[0] : 0), vel = 0, target: Num | null = null, idx = points.length ? nearestSnap(points, pos) : 0;\n let drag = false, down = false, startP = 0, startPos = 0, pid = -1, off: (() => void) | null = null;\n const vt = velocityTracker();\n const reduced = () => !!o.reducedMotion;\n const clampB = (p: Num) => Math.min(hi, Math.max(lo, p));\n const emit = () => o.onUpdate?.(pos);\n const stop = () => {\n off?.();\n off = null;\n };\n const settle = (t: Num, animate = true) => {\n target = t;\n if (!animate || reduced()) {\n pos = t;\n vel = 0;\n target = null;\n stop();\n emit();\n if (points.length) o.onSnap?.(idx, pos);\n return;\n }\n if (!off)\n off = core.getTicker().add((_, ms) => {\n if (target === null) return stop();\n let left = Math.min(ms, 64) / 1000;\n while (left > 0) {\n const dt = Math.min(left, 1 / 120);\n [pos, vel] = springStep(pos, vel, target, dt, o.stiffness, o.damping);\n left -= dt;\n }\n if (Math.abs(pos - target) < 0.3 && Math.abs(vel) < 8) {\n pos = target;\n vel = 0;\n target = null;\n stop();\n emit();\n if (points.length) o.onSnap?.(idx, pos);\n return;\n }\n emit();\n });\n };\n const targetFor = (p: Num, v: Num): Num => {\n if (!points.length) return -1;\n const thrown = o.inertia === false || reduced() ? p : projectThrow(p, v, o.deceleration);\n let i = nearestSnap(points, thrown);\n const from = nearestSnap(points, startPos);\n if (i === from && Math.abs(v) > (o.flick ?? 400)) {\n // a short fast flick still moves one point in the throw direction\n const sorted = points.map((x, k) => [x, k]).sort((a, b) => a[0] - b[0]);\n const at = sorted.findIndex((s) => s[1] === from);\n const n = sorted[at + (v > 0 ? 1 : -1)];\n if (n) i = n[1];\n }\n return i;\n };\n const coord = (e: PointerEvent) => (X ? e.clientX : e.clientY);\n const onDown = (e: PointerEvent) => {\n if (e.button > 0 || down) return;\n down = true;\n drag = false;\n pid = e.pointerId;\n startP = coord(e);\n startPos = pos;\n vt.reset();\n vt.add(e.timeStamp ?? performance.now(), pos);\n };\n const onMove = (e: PointerEvent) => {\n if (!down || e.pointerId !== pid) return;\n const d = coord(e) - startP;\n if (!drag) {\n if (Math.abs(d) < (o.threshold ?? 4)) return;\n drag = true;\n target = null;\n stop();\n try {\n el.setPointerCapture?.(pid);\n } catch {\n /* synthetic events */\n }\n o.onDragStart?.();\n }\n const raw = startPos + d;\n const r = o.resistance ?? 0.55;\n const size = (X ? el.parentElement?.clientWidth : el.parentElement?.clientHeight) || 300;\n pos = raw < lo ? (r ? lo + rubberband(raw - lo, size, r) : lo) : raw > hi ? (r ? hi + rubberband(raw - hi, size, r) : hi) : raw;\n vt.add(e.timeStamp ?? performance.now(), pos);\n emit();\n e.preventDefault?.();\n };\n const onUp = (e: PointerEvent) => {\n if (!down || e.pointerId !== pid) return;\n down = false;\n if (!drag) return;\n drag = false;\n const v = vt.velocity(e.timeStamp ?? performance.now());\n o.onDragEnd?.(v);\n // a click right after a drag must not activate links / buttons inside\n const eat = (c: Event) => (c.stopPropagation(), c.preventDefault());\n el.addEventListener('click', eat, { capture: true, once: true });\n setTimeout(() => el.removeEventListener('click', eat, { capture: true }), 0);\n vel = reduced() ? 0 : v;\n if (points.length) {\n idx = targetFor(pos, v);\n settle(points[idx]);\n } else settle(clampB(o.inertia === false || reduced() ? pos : projectThrow(pos, v, o.deceleration)));\n };\n el.style.touchAction = X ? 'pan-y' : 'pan-x';\n el.addEventListener('pointerdown', onDown);\n el.addEventListener('pointermove', onMove);\n el.addEventListener('pointerup', onUp);\n el.addEventListener('pointercancel', onUp);\n emit();\n return {\n get position() {\n return pos;\n },\n get index() {\n return idx;\n },\n get dragging() {\n return drag;\n },\n get moving() {\n return target !== null || drag;\n },\n snapTo(i, animate = true) {\n if (!points.length) return;\n idx = Math.max(0, Math.min(points.length - 1, Math.round(i)));\n vel = 0;\n settle(points[idx], animate);\n },\n setPosition(px, animate = false) {\n vel = 0;\n if (points.length) idx = nearestSnap(points, px);\n settle(clampB(px), animate);\n },\n setSnapPoints(p, b) {\n points = p.slice();\n setBounds(b);\n if (points.length) {\n idx = Math.min(idx, points.length - 1);\n pos = points[idx];\n target = null;\n stop();\n emit();\n }\n },\n targetFor,\n dispose() {\n stop();\n el.removeEventListener('pointerdown', onDown);\n el.removeEventListener('pointermove', onMove);\n el.removeEventListener('pointerup', onUp);\n el.removeEventListener('pointercancel', onUp);\n },\n };\n}\n\nexport interface DragSnapApi {\n createDragSnap: typeof createDragSnap;\n projectThrow: typeof projectThrow;\n nearestSnap: typeof nearestSnap;\n rubberband: typeof rubberband;\n springStep: typeof springStep;\n velocityTracker: typeof velocityTracker;\n}\n\n/** The module object: `use(dragSnap)`. */\nexport const dragSnap: RuntimeModule<DragSnapApi> = { id: 'drag-snap', version: RUNTIME_VERSION, requires: ['core'], api: { createDragSnap, projectThrow, nearestSnap, rubberband, springStep, velocityTracker } };\n"],"names":["requireModule","RUNTIME_VERSION"],"mappings":";;;;AAAA;;;;;;;;;;;;;;;;;AAiBG;AAMH;AACM,SAAU,YAAY,CAAC,QAAa,EAAE,QAAa,EAAE,YAAY,GAAG,IAAI,EAAA;IAC5E,OAAO,QAAQ,GAAG,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,YAAY,CAAC,CAAC;AACrF;AAEA;AACM,SAAU,WAAW,CAAC,MAAa,EAAE,CAAM,EAAA;AAC/C,IAAA,IAAI,IAAI,GAAG,CAAC,EAAE,CAAC,GAAG,QAAQ;IAC1B,MAAM,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,CAAC,KAAI;QACtB,MAAM,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,CAAC;QACzB,IAAI,CAAC,GAAG,CAAC;YAAE,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,GAAG,CAAC,CAAC;AAChC,IAAA,CAAC,CAAC;AACF,IAAA,OAAO,IAAI;AACb;AAEA;AACM,SAAU,UAAU,CAAC,IAAS,EAAE,IAAS,EAAE,CAAC,GAAG,IAAI,EAAA;AACvD,IAAA,MAAM,CAAC,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC;AAC7C,IAAA,OAAO,CAAC,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC,GAAG,CAAC,IAAI,IAAI,CAAC,GAAG,CAAC,CAAC,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI;AAC/D;AAEA;AACM,SAAU,UAAU,CAAC,CAAM,EAAE,CAAM,EAAE,MA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,CAAC,MAAM,GAAG,CAAC,CAAC;AACtC,gBAAA,GAAG,GAAG,MAAM,CAAC,GAAG,CAAC;gBACjB,MAAM,GAAG,IAAI;AACb,gBAAA,IAAI,EAAE;AACN,gBAAA,IAAI,EAAE;YACR;QACF,CAAC;QACD,SAAS;QACT,OAAO,GAAA;AACL,YAAA,IAAI,EAAE;AACN,YAAA,EAAE,CAAC,mBAAmB,CAAC,aAAa,EAAE,MAAM,CAAC;AAC7C,YAAA,EAAE,CAAC,mBAAmB,CAAC,aAAa,EAAE,MAAM,CAAC;AAC7C,YAAA,EAAE,CAAC,mBAAmB,CAAC,WAAW,EAAE,IAAI,CAAC;AACzC,YAAA,EAAE,CAAC,mBAAmB,CAAC,eAAe,EAAE,IAAI,CAAC;QAC/C,CAAC;KACF;AACH;AAWA;AACO,MAAM,QAAQ,GAA+B,EAAE,EAAE,EAAE,WAAW,EAAE,OAAO,EAAEC,wBAAe,EAAE,QAAQ,EAAE,CAAC,MAAM,CAAC,EAAE,GAAG,EAAE,EAAE,cAAc,EAAE,YAAY,EAAE,WAAW,EAAE,UAAU,EAAE,UAAU,EAAE,eAAe,EAAE;;;;;;;;"}
@@ -0,0 +1,109 @@
1
+ /** A runtime module: `{ id, version, api }`, registered with `use()`. */
2
+ interface RuntimeModule<A = unknown> {
3
+ /** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
4
+ id: string;
5
+ version: string;
6
+ /** Other modules this one needs (registered first by `use()` callers). */
7
+ requires?: string[];
8
+ /** The module's public API (what `requireModule(id)` returns). */
9
+ api: A;
10
+ /** Optional one-time setup, called on first registration. */
11
+ setup?(registry: RuntimeRegistry): void;
12
+ }
13
+ interface RuntimeRegistry {
14
+ version: string;
15
+ modules: Map<string, RuntimeModule>;
16
+ /** Shared per-page state slots (the ticker lives here). */
17
+ slots: Record<string, unknown>;
18
+ }
19
+
20
+ /**
21
+ * `motionary/runtime/drag-snap` (10.8) — pointer drag with inertia and snap
22
+ * points, for carousels, sheets, sliders and pickers (own implementation).
23
+ *
24
+ * - one axis (`x` / `y`) per controller; pointer, touch and pen through
25
+ * Pointer Events, a movement threshold before a drag starts (so clicks
26
+ * inside still work), `touch-action` set for the other axis;
27
+ * - velocity from the last 100 ms of samples; release projects the throw
28
+ * with constant deceleration and snaps to the nearest point (or to the
29
+ * next / previous point for a fast flick, `flick`), with a critically
30
+ * damped spring on the shared ticker;
31
+ * - bounds with rubber-band resistance past the ends;
32
+ * - `createDragSnap(el, options)`; `snapTo(index)`, `setPosition(px)`, `setSnapPoints([...])`; reduced
33
+ * motion: no inertia, snaps without the spring.
34
+ *
35
+ * The maths (`projectThrow`, `nearestSnap`, `rubberband`, `springStep`,
36
+ * `velocityTracker`) is pure and exported for tests / workers.
37
+ */
38
+
39
+ type Num = number;
40
+ /** Where a throw at `velocity` (px/s) ends with constant `deceleration` (px/s²). */
41
+ declare function projectThrow(position: Num, velocity: Num, deceleration?: number): Num;
42
+ /** Index of the snap point nearest to `p` (points in any order). */
43
+ declare function nearestSnap(points: Num[], p: Num): Num;
44
+ /** Rubber-band: how far content moves when dragged `over` px past an edge of a `size` px viewport. */
45
+ declare function rubberband(over: Num, size: Num, c?: number): Num;
46
+ /** One semi-implicit Euler step of a damped spring towards `target`. Returns [position, velocity]. */
47
+ declare function springStep(x: Num, v: Num, target: Num, dt: Num, stiffness?: number, damping?: number): [Num, Num];
48
+ /** Velocity estimate (units/s) from the samples of the last `window` ms. */
49
+ declare function velocityTracker(window?: number): {
50
+ add(t: Num, p: Num): void;
51
+ velocity(now?: Num): Num;
52
+ reset(): void;
53
+ };
54
+ interface DragSnapOptions {
55
+ /** 'x' (default) or 'y'. */
56
+ axis?: 'x' | 'y';
57
+ /** Snap points in px (content offsets, usually ≤ 0 for a track moved left). Empty = free drag. */
58
+ snap?: Num[];
59
+ /** [min, max] position; defaults to the snap point range. */
60
+ bounds?: [Num, Num];
61
+ /** Throw with inertia on release (default true; off under reduced motion). */
62
+ inertia?: boolean;
63
+ /** Deceleration of a throw in px/s² (default 3000). */
64
+ deceleration?: Num;
65
+ /** A release faster than this (px/s) moves at least one snap point (default 400). */
66
+ flick?: Num;
67
+ /** Spring stiffness (default 260) and damping (default critical). */
68
+ stiffness?: Num;
69
+ damping?: Num;
70
+ /** px before a press becomes a drag (default 4). */
71
+ threshold?: Num;
72
+ /** Rubber-band strength past the bounds (0 = hard stop, default 0.55). */
73
+ resistance?: Num;
74
+ /** Start position (px). */
75
+ position?: Num;
76
+ /** Skip the spring / inertia (reduced motion). */
77
+ reducedMotion?: boolean;
78
+ onUpdate?(position: Num): void;
79
+ onSnap?(index: Num, position: Num): void;
80
+ onDragStart?(): void;
81
+ onDragEnd?(velocity: Num): void;
82
+ }
83
+ interface DragSnap {
84
+ readonly position: Num;
85
+ readonly index: Num;
86
+ readonly dragging: boolean;
87
+ readonly moving: boolean;
88
+ snapTo(index: Num, animate?: boolean): void;
89
+ setPosition(px: Num, animate?: boolean): void;
90
+ setSnapPoints(points: Num[], bounds?: [Num, Num]): void;
91
+ /** Where a release at `velocity` would come to rest (index). */
92
+ targetFor(position: Num, velocity: Num): Num;
93
+ dispose(): void;
94
+ }
95
+ /** Make `el` draggable along one axis; `onUpdate(px)` applies the position (e.g. a transform). */
96
+ declare function createDragSnap(el: HTMLElement, o?: DragSnapOptions): DragSnap;
97
+ interface DragSnapApi {
98
+ createDragSnap: typeof createDragSnap;
99
+ projectThrow: typeof projectThrow;
100
+ nearestSnap: typeof nearestSnap;
101
+ rubberband: typeof rubberband;
102
+ springStep: typeof springStep;
103
+ velocityTracker: typeof velocityTracker;
104
+ }
105
+ /** The module object: `use(dragSnap)`. */
106
+ declare const dragSnap: RuntimeModule<DragSnapApi>;
107
+
108
+ export { createDragSnap, dragSnap, nearestSnap, projectThrow, rubberband, springStep, velocityTracker };
109
+ export type { DragSnap, DragSnapApi, DragSnapOptions };
@@ -0,0 +1,109 @@
1
+ /** A runtime module: `{ id, version, api }`, registered with `use()`. */
2
+ interface RuntimeModule<A = unknown> {
3
+ /** Module id: 'core', 'format-css', 'scroll', … (import path `motionary/runtime/<id>`). */
4
+ id: string;
5
+ version: string;
6
+ /** Other modules this one needs (registered first by `use()` callers). */
7
+ requires?: string[];
8
+ /** The module's public API (what `requireModule(id)` returns). */
9
+ api: A;
10
+ /** Optional one-time setup, called on first registration. */
11
+ setup?(registry: RuntimeRegistry): void;
12
+ }
13
+ interface RuntimeRegistry {
14
+ version: string;
15
+ modules: Map<string, RuntimeModule>;
16
+ /** Shared per-page state slots (the ticker lives here). */
17
+ slots: Record<string, unknown>;
18
+ }
19
+
20
+ /**
21
+ * `motionary/runtime/drag-snap` (10.8) — pointer drag with inertia and snap
22
+ * points, for carousels, sheets, sliders and pickers (own implementation).
23
+ *
24
+ * - one axis (`x` / `y`) per controller; pointer, touch and pen through
25
+ * Pointer Events, a movement threshold before a drag starts (so clicks
26
+ * inside still work), `touch-action` set for the other axis;
27
+ * - velocity from the last 100 ms of samples; release projects the throw
28
+ * with constant deceleration and snaps to the nearest point (or to the
29
+ * next / previous point for a fast flick, `flick`), with a critically
30
+ * damped spring on the shared ticker;
31
+ * - bounds with rubber-band resistance past the ends;
32
+ * - `createDragSnap(el, options)`; `snapTo(index)`, `setPosition(px)`, `setSnapPoints([...])`; reduced
33
+ * motion: no inertia, snaps without the spring.
34
+ *
35
+ * The maths (`projectThrow`, `nearestSnap`, `rubberband`, `springStep`,
36
+ * `velocityTracker`) is pure and exported for tests / workers.
37
+ */
38
+
39
+ type Num = number;
40
+ /** Where a throw at `velocity` (px/s) ends with constant `deceleration` (px/s²). */
41
+ declare function projectThrow(position: Num, velocity: Num, deceleration?: number): Num;
42
+ /** Index of the snap point nearest to `p` (points in any order). */
43
+ declare function nearestSnap(points: Num[], p: Num): Num;
44
+ /** Rubber-band: how far content moves when dragged `over` px past an edge of a `size` px viewport. */
45
+ declare function rubberband(over: Num, size: Num, c?: number): Num;
46
+ /** One semi-implicit Euler step of a damped spring towards `target`. Returns [position, velocity]. */
47
+ declare function springStep(x: Num, v: Num, target: Num, dt: Num, stiffness?: number, damping?: number): [Num, Num];
48
+ /** Velocity estimate (units/s) from the samples of the last `window` ms. */
49
+ declare function velocityTracker(window?: number): {
50
+ add(t: Num, p: Num): void;
51
+ velocity(now?: Num): Num;
52
+ reset(): void;
53
+ };
54
+ interface DragSnapOptions {
55
+ /** 'x' (default) or 'y'. */
56
+ axis?: 'x' | 'y';
57
+ /** Snap points in px (content offsets, usually ≤ 0 for a track moved left). Empty = free drag. */
58
+ snap?: Num[];
59
+ /** [min, max] position; defaults to the snap point range. */
60
+ bounds?: [Num, Num];
61
+ /** Throw with inertia on release (default true; off under reduced motion). */
62
+ inertia?: boolean;
63
+ /** Deceleration of a throw in px/s² (default 3000). */
64
+ deceleration?: Num;
65
+ /** A release faster than this (px/s) moves at least one snap point (default 400). */
66
+ flick?: Num;
67
+ /** Spring stiffness (default 260) and damping (default critical). */
68
+ stiffness?: Num;
69
+ damping?: Num;
70
+ /** px before a press becomes a drag (default 4). */
71
+ threshold?: Num;
72
+ /** Rubber-band strength past the bounds (0 = hard stop, default 0.55). */
73
+ resistance?: Num;
74
+ /** Start position (px). */
75
+ position?: Num;
76
+ /** Skip the spring / inertia (reduced motion). */
77
+ reducedMotion?: boolean;
78
+ onUpdate?(position: Num): void;
79
+ onSnap?(index: Num, position: Num): void;
80
+ onDragStart?(): void;
81
+ onDragEnd?(velocity: Num): void;
82
+ }
83
+ interface DragSnap {
84
+ readonly position: Num;
85
+ readonly index: Num;
86
+ readonly dragging: boolean;
87
+ readonly moving: boolean;
88
+ snapTo(index: Num, animate?: boolean): void;
89
+ setPosition(px: Num, animate?: boolean): void;
90
+ setSnapPoints(points: Num[], bounds?: [Num, Num]): void;
91
+ /** Where a release at `velocity` would come to rest (index). */
92
+ targetFor(position: Num, velocity: Num): Num;
93
+ dispose(): void;
94
+ }
95
+ /** Make `el` draggable along one axis; `onUpdate(px)` applies the position (e.g. a transform). */
96
+ declare function createDragSnap(el: HTMLElement, o?: DragSnapOptions): DragSnap;
97
+ interface DragSnapApi {
98
+ createDragSnap: typeof createDragSnap;
99
+ projectThrow: typeof projectThrow;
100
+ nearestSnap: typeof nearestSnap;
101
+ rubberband: typeof rubberband;
102
+ springStep: typeof springStep;
103
+ velocityTracker: typeof velocityTracker;
104
+ }
105
+ /** The module object: `use(dragSnap)`. */
106
+ declare const dragSnap: RuntimeModule<DragSnapApi>;
107
+
108
+ export { createDragSnap, dragSnap, nearestSnap, projectThrow, rubberband, springStep, velocityTracker };
109
+ export type { DragSnap, DragSnapApi, DragSnapOptions };
@@ -0,0 +1,2 @@
1
+ !function(t,e){"use strict";function n(t,e,n=3e3){return t+e*Math.abs(e)/(2*Math.max(1,n))}function r(t,e){let n=0,r=1/0;return t.forEach((t,i)=>{const a=Math.abs(t-e);a<r&&(r=a,n=i)}),n}function i(t,e,n=.55){return Math.sign(t)*(1-1/(Math.abs(t)*n/Math.max(1,e)+1))*e}function a(t,e,n,r,i=260,a=2*Math.sqrt(260)){const o=e+(-i*(t-n)-a*e)*r;return[t+o*r,o]}function o(t=100){let e=[];return{add(n,r){for(e.push([n,r]);e.length>2&&n-e[0][0]>t;)e.shift()},velocity(t){if(e.length<2)return 0;const[n,r]=e[e.length-1];if(void 0!==t&&t-n>60)return 0;const[i,a]=e[0];return n>i?(r-a)/(n-i)*1e3:0},reset(){e=[]}}}function s(t,s={}){const c=e.requireModule("core","motionary/runtime/drag-snap"),l="x"===(s.axis||"x");let u=(s.snap||[]).slice(),p=0,h=0;const d=t=>{t?[p,h]=[Math.min(t[0],t[1]),Math.max(t[0],t[1])]:u.length?[p,h]=[Math.min(...u),Math.max(...u)]:[p,h]=[-1/0,1/0]};d(s.bounds);let m=s.position??(u.length?u[0]:0),g=0,f=null,M=u.length?r(u,m):0,v=!1,E=!1,b=0,S=0,x=-1,y=null;const L=o(),T=()=>!!s.reducedMotion,w=t=>Math.min(h,Math.max(p,t)),k=()=>s.onUpdate?.(m),D=()=>{y?.(),y=null},I=(t,e=!0)=>{if(f=t,!e||T())return m=t,g=0,f=null,D(),k(),void(u.length&&s.onSnap?.(M,m));y||(y=c.getTicker().add((t,e)=>{if(null===f)return D();let n=Math.min(e,64)/1e3;for(;n>0;){const t=Math.min(n,1/120);[m,g]=a(m,g,f,t,s.stiffness,s.damping),n-=t}if(Math.abs(m-f)<.3&&Math.abs(g)<8)return m=f,g=0,f=null,D(),k(),void(u.length&&s.onSnap?.(M,m));k()}))},R=(t,e)=>{if(!u.length)return-1;const i=!1===s.inertia||T()?t:n(t,e,s.deceleration);let a=r(u,i);const o=r(u,S);if(a===o&&Math.abs(e)>(s.flick??400)){const t=u.map((t,e)=>[t,e]).sort((t,e)=>t[0]-e[0]),n=t.findIndex(t=>t[1]===o),r=t[n+(e>0?1:-1)];r&&(a=r[1])}return a},P=t=>l?t.clientX:t.clientY,q=t=>{t.button>0||E||(E=!0,v=!1,x=t.pointerId,b=P(t),S=m,L.reset(),L.add(t.timeStamp??performance.now(),m))},j=e=>{if(!E||e.pointerId!==x)return;const n=P(e)-b;if(!v){if(Math.abs(n)<(s.threshold??4))return;v=!0,f=null,D();try{t.setPointerCapture?.(x)}catch{}s.onDragStart?.()}const r=S+n,a=s.resistance??.55,o=(l?t.parentElement?.clientWidth:t.parentElement?.clientHeight)||300;m=r<p?a?p+i(r-p,o,a):p:r>h?a?h+i(r-h,o,a):h:r,L.add(e.timeStamp??performance.now(),m),k(),e.preventDefault?.()},N=e=>{if(!E||e.pointerId!==x)return;if(E=!1,!v)return;v=!1;const r=L.velocity(e.timeStamp??performance.now());s.onDragEnd?.(r);const i=t=>(t.stopPropagation(),t.preventDefault());t.addEventListener("click",i,{capture:!0,once:!0}),setTimeout(()=>t.removeEventListener("click",i,{capture:!0}),0),g=T()?0:r,u.length?(M=R(m,r),I(u[M])):I(w(!1===s.inertia||T()?m:n(m,r,s.deceleration)))};return t.style.touchAction=l?"pan-y":"pan-x",t.addEventListener("pointerdown",q),t.addEventListener("pointermove",j),t.addEventListener("pointerup",N),t.addEventListener("pointercancel",N),k(),{get position(){return m},get index(){return M},get dragging(){return v},get moving(){return null!==f||v},snapTo(t,e=!0){u.length&&(M=Math.max(0,Math.min(u.length-1,Math.round(t))),g=0,I(u[M],e))},setPosition(t,e=!1){g=0,u.length&&(M=r(u,t)),I(w(t),e)},setSnapPoints(t,e){u=t.slice(),d(e),u.length&&(M=Math.min(M,u.length-1),m=u[M],f=null,D(),k())},targetFor:R,dispose(){D(),t.removeEventListener("pointerdown",q),t.removeEventListener("pointermove",j),t.removeEventListener("pointerup",N),t.removeEventListener("pointercancel",N)}}}const c={id:"drag-snap",version:e.RUNTIME_VERSION,requires:["core"],api:{createDragSnap:s,projectThrow:n,nearestSnap:r,rubberband:i,springStep:a,velocityTracker:o}};e.register(c),t.createDragSnap=s,t.dragSnap=c,t.nearestSnap=r,t.projectThrow=n,t.rubberband=i,t.springStep=a,t.velocityTracker=o}(this.MotionaryRuntime=this.MotionaryRuntime||{},MotionaryRuntime);
2
+ //# sourceMappingURL=drag-snap.iife.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag-snap.iife.js","sources":["../../src/runtime/drag-snap.ts","../../src/runtime/iife/drag-snap.ts"],"sourcesContent":["/**\n * `motionary/runtime/drag-snap` (10.8) — pointer drag with inertia and snap\n * points, for carousels, sheets, sliders and pickers (own implementation).\n *\n * - one axis (`x` / `y`) per controller; pointer, touch and pen through\n * Pointer Events, a movement threshold before a drag starts (so clicks\n * inside still work), `touch-action` set for the other axis;\n * - velocity from the last 100 ms of samples; release projects the throw\n * with constant deceleration and snaps to the nearest point (or to the\n * next / previous point for a fast flick, `flick`), with a critically\n * damped spring on the shared ticker;\n * - bounds with rubber-band resistance past the ends;\n * - `createDragSnap(el, options)`; `snapTo(index)`, `setPosition(px)`, `setSnapPoints([...])`; reduced\n * motion: no inertia, snaps without the spring.\n *\n * The maths (`projectThrow`, `nearestSnap`, `rubberband`, `springStep`,\n * `velocityTracker`) is pure and exported for tests / workers.\n */\nimport { RUNTIME_VERSION, requireModule, type RuntimeModule } from './registry';\nimport type { CoreApi } from './index';\n\ntype Num = number;\n\n/** Where a throw at `velocity` (px/s) ends with constant `deceleration` (px/s²). */\nexport function projectThrow(position: Num, velocity: Num, deceleration = 3000): Num {\n return position + (velocity * Math.abs(velocity)) / (2 * Math.max(1, deceleration));\n}\n\n/** Index of the snap point nearest to `p` (points in any order). */\nexport function nearestSnap(points: Num[], p: Num): Num {\n let best = 0, d = Infinity;\n points.forEach((x, i) => {\n const e = Math.abs(x - p);\n if (e < d) (d = e), (best = i);\n });\n return best;\n}\n\n/** Rubber-band: how far content moves when dragged `over` px past an edge of a `size` px viewport. */\nexport function rubberband(over: Num, size: Num, c = 0.55): Num {\n const s = Math.sign(over), x = Math.abs(over);\n return s * (1 - 1 / ((x * c) / Math.max(1, size) + 1)) * size;\n}\n\n/** One semi-implicit Euler step of a damped spring towards `target`. Returns [position, velocity]. */\nexport function springStep(x: Num, v: Num, target: Num, dt: Num, stiffness = 260, damping = 2 * Math.sqrt(260)): [Num, Num] {\n const a = -stiffness * (x - target) - damping * v;\n const nv = v + a * dt;\n return [x + nv * dt, nv];\n}\n\n/** Velocity estimate (units/s) from the samples of the last `window` ms. */\nexport function velocityTracker(window = 100): { add(t: Num, p: Num): void; velocity(now?: Num): Num; reset(): void } {\n let s: [Num, Num][] = [];\n return {\n add(t, p) {\n s.push([t, p]);\n while (s.length > 2 && t - s[0][0] > window) s.shift();\n },\n velocity(now) {\n if (s.length < 2) return 0;\n const [t1, p1] = s[s.length - 1];\n if (now !== undefined && now - t1 > 60) return 0; // finger stopped before release\n const [t0, p0] = s[0];\n return t1 > t0 ? ((p1 - p0) / (t1 - t0)) * 1000 : 0;\n },\n reset() {\n s = [];\n },\n };\n}\n\nexport interface DragSnapOptions {\n /** 'x' (default) or 'y'. */\n axis?: 'x' | 'y';\n /** Snap points in px (content offsets, usually ≤ 0 for a track moved left). Empty = free drag. */\n snap?: Num[];\n /** [min, max] position; defaults to the snap point range. */\n bounds?: [Num, Num];\n /** Throw with inertia on release (default true; off under reduced motion). */\n inertia?: boolean;\n /** Deceleration of a throw in px/s² (default 3000). */\n deceleration?: Num;\n /** A release faster than this (px/s) moves at least one snap point (default 400). */\n flick?: Num;\n /** Spring stiffness (default 260) and damping (default critical). */\n stiffness?: Num;\n damping?: Num;\n /** px before a press becomes a drag (default 4). */\n threshold?: Num;\n /** Rubber-band strength past the bounds (0 = hard stop, default 0.55). */\n resistance?: Num;\n /** Start position (px). */\n position?: Num;\n /** Skip the spring / inertia (reduced motion). */\n reducedMotion?: boolean;\n onUpdate?(position: Num): void;\n onSnap?(index: Num, position: Num): void;\n onDragStart?(): void;\n onDragEnd?(velocity: Num): void;\n}\n\nexport interface DragSnap {\n readonly position: Num;\n readonly index: Num;\n readonly dragging: boolean;\n readonly moving: boolean;\n snapTo(index: Num, animate?: boolean): void;\n setPosition(px: Num, animate?: boolean): void;\n setSnapPoints(points: Num[], bounds?: [Num, Num]): void;\n /** Where a release at `velocity` would come to rest (index). */\n targetFor(position: Num, velocity: Num): Num;\n dispose(): void;\n}\n\n/** Make `el` draggable along one axis; `onUpdate(px)` applies the position (e.g. a transform). */\nexport function createDragSnap(el: HTMLElement, o: DragSnapOptions = {}): DragSnap {\n const core = requireModule<CoreApi>('core', 'motionary/runtime/drag-snap');\n const X = (o.axis || 'x') === 'x';\n let points = (o.snap || []).slice();\n let lo = 0, hi = 0;\n const setBounds = (b?: [Num, Num]) => {\n if (b) [lo, hi] = [Math.min(b[0], b[1]), Math.max(b[0], b[1])];\n else if (points.length) [lo, hi] = [Math.min(...points), Math.max(...points)];\n else [lo, hi] = [-Infinity, Infinity];\n };\n setBounds(o.bounds);\n let pos = o.position ?? (points.length ? points[0] : 0), vel = 0, target: Num | null = null, idx = points.length ? nearestSnap(points, pos) : 0;\n let drag = false, down = false, startP = 0, startPos = 0, pid = -1, off: (() => void) | null = null;\n const vt = velocityTracker();\n const reduced = () => !!o.reducedMotion;\n const clampB = (p: Num) => Math.min(hi, Math.max(lo, p));\n const emit = () => o.onUpdate?.(pos);\n const stop = () => {\n off?.();\n off = null;\n };\n const settle = (t: Num, animate = true) => {\n target = t;\n if (!animate || reduced()) {\n pos = t;\n vel = 0;\n target = null;\n stop();\n emit();\n if (points.length) o.onSnap?.(idx, pos);\n return;\n }\n if (!off)\n off = core.getTicker().add((_, ms) => {\n if (target === null) return stop();\n let left = Math.min(ms, 64) / 1000;\n while (left > 0) {\n const dt = Math.min(left, 1 / 120);\n [pos, vel] = springStep(pos, vel, target, dt, o.stiffness, o.damping);\n left -= dt;\n }\n if (Math.abs(pos - target) < 0.3 && Math.abs(vel) < 8) {\n pos = target;\n vel = 0;\n target = null;\n stop();\n emit();\n if (points.length) o.onSnap?.(idx, pos);\n return;\n }\n emit();\n });\n };\n const targetFor = (p: Num, v: Num): Num => {\n if (!points.length) return -1;\n const thrown = o.inertia === false || reduced() ? p : projectThrow(p, v, o.deceleration);\n let i = nearestSnap(points, thrown);\n const from = nearestSnap(points, startPos);\n if (i === from && Math.abs(v) > (o.flick ?? 400)) {\n // a short fast flick still moves one point in the throw direction\n const sorted = points.map((x, k) => [x, k]).sort((a, b) => a[0] - b[0]);\n const at = sorted.findIndex((s) => s[1] === from);\n const n = sorted[at + (v > 0 ? 1 : -1)];\n if (n) i = n[1];\n }\n return i;\n };\n const coord = (e: PointerEvent) => (X ? e.clientX : e.clientY);\n const onDown = (e: PointerEvent) => {\n if (e.button > 0 || down) return;\n down = true;\n drag = false;\n pid = e.pointerId;\n startP = coord(e);\n startPos = pos;\n vt.reset();\n vt.add(e.timeStamp ?? performance.now(), pos);\n };\n const onMove = (e: PointerEvent) => {\n if (!down || e.pointerId !== pid) return;\n const d = coord(e) - startP;\n if (!drag) {\n if (Math.abs(d) < (o.threshold ?? 4)) return;\n drag = true;\n target = null;\n stop();\n try {\n el.setPointerCapture?.(pid);\n } catch {\n /* synthetic events */\n }\n o.onDragStart?.();\n }\n const raw = startPos + d;\n const r = o.resistance ?? 0.55;\n const size = (X ? el.parentElement?.clientWidth : el.parentElement?.clientHeight) || 300;\n pos = raw < lo ? (r ? lo + rubberband(raw - lo, size, r) : lo) : raw > hi ? (r ? hi + rubberband(raw - hi, size, r) : hi) : raw;\n vt.add(e.timeStamp ?? performance.now(), pos);\n emit();\n e.preventDefault?.();\n };\n const onUp = (e: PointerEvent) => {\n if (!down || e.pointerId !== pid) return;\n down = false;\n if (!drag) return;\n drag = false;\n const v = vt.velocity(e.timeStamp ?? performance.now());\n o.onDragEnd?.(v);\n // a click right after a drag must not activate links / buttons inside\n const eat = (c: Event) => (c.stopPropagation(), c.preventDefault());\n el.addEventListener('click', eat, { capture: true, once: true });\n setTimeout(() => el.removeEventListener('click', eat, { capture: true }), 0);\n vel = reduced() ? 0 : v;\n if (points.length) {\n idx = targetFor(pos, v);\n settle(points[idx]);\n } else settle(clampB(o.inertia === false || reduced() ? pos : projectThrow(pos, v, o.deceleration)));\n };\n el.style.touchAction = X ? 'pan-y' : 'pan-x';\n el.addEventListener('pointerdown', onDown);\n el.addEventListener('pointermove', onMove);\n el.addEventListener('pointerup', onUp);\n el.addEventListener('pointercancel', onUp);\n emit();\n return {\n get position() {\n return pos;\n },\n get index() {\n return idx;\n },\n get dragging() {\n return drag;\n },\n get moving() {\n return target !== null || drag;\n },\n snapTo(i, animate = true) {\n if (!points.length) return;\n idx = Math.max(0, Math.min(points.length - 1, Math.round(i)));\n vel = 0;\n settle(points[idx], animate);\n },\n setPosition(px, animate = false) {\n vel = 0;\n if (points.length) idx = nearestSnap(points, px);\n settle(clampB(px), animate);\n },\n setSnapPoints(p, b) {\n points = p.slice();\n setBounds(b);\n if (points.length) {\n idx = Math.min(idx, points.length - 1);\n pos = points[idx];\n target = null;\n stop();\n emit();\n }\n },\n targetFor,\n dispose() {\n stop();\n el.removeEventListener('pointerdown', onDown);\n el.removeEventListener('pointermove', onMove);\n el.removeEventListener('pointerup', onUp);\n el.removeEventListener('pointercancel', onUp);\n },\n };\n}\n\nexport interface DragSnapApi {\n createDragSnap: typeof createDragSnap;\n projectThrow: typeof projectThrow;\n nearestSnap: typeof nearestSnap;\n rubberband: typeof rubberband;\n springStep: typeof springStep;\n velocityTracker: typeof velocityTracker;\n}\n\n/** The module object: `use(dragSnap)`. */\nexport const dragSnap: RuntimeModule<DragSnapApi> = { id: 'drag-snap', version: RUNTIME_VERSION, requires: ['core'], api: { createDragSnap, projectThrow, nearestSnap, rubberband, springStep, velocityTracker } };\n","// CDN build: load runtime.iife.js first, then this file → registers motionary/runtime/drag-snap and adds its API to window.MotionaryRuntime.\nimport { register } from '../registry';\nimport { dragSnap } from '../drag-snap';\nexport * from '../drag-snap';\nregister(dragSnap);\n"],"names":["projectThrow","position","velocity","deceleration","Math","abs","max","nearestSnap","points","p","best","d","Infinity","forEach","x","i","e","rubberband","over","size","c","sign","springStep","v","target","dt","stiffness","damping","sqrt","nv","velocityTracker","window","s","add","t","push","length","shift","now","t1","p1","undefined","t0","p0","reset","createDragSnap","el","o","core","requireModule","X","axis","snap","slice","lo","hi","setBounds","b","min","bounds","pos","vel","idx","drag","down","startP","startPos","pid","off","vt","reduced","reducedMotion","clampB","emit","onUpdate","stop","settle","animate","onSnap","getTicker","_","ms","left","targetFor","thrown","inertia","from","flick","sorted","map","k","sort","a","at","findIndex","n","coord","clientX","clientY","onDown","button","pointerId","timeStamp","performance","onMove","threshold","setPointerCapture","onDragStart","raw","r","resistance","parentElement","clientWidth","clientHeight","preventDefault","onUp","onDragEnd","eat","stopPropagation","addEventListener","capture","once","setTimeout","removeEventListener","style","touchAction","index","dragging","moving","snapTo","round","setPosition","px","setSnapPoints","dispose","dragSnap","id","version","RUNTIME_VERSION","requires","api","register"],"mappings":"4BAwBM,SAAUA,EAAaC,EAAeC,EAAeC,EAAe,KACxE,OAAOF,EAAYC,EAAWE,KAAKC,IAAIH,IAAc,EAAIE,KAAKE,IAAI,EAAGH,GACvE,CAGM,SAAUI,EAAYC,EAAeC,GACzC,IAAIC,EAAO,EAAGC,EAAI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