@studiometa/ui-motion 0.0.1 → 1.11.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.
package/dist/Motion.js ADDED
@@ -0,0 +1,402 @@
1
+ import { getMotion, resolveMotion } from "./dependencies.js";
2
+ import { Base } from "@studiometa/js-toolkit/Base";
3
+ //#region src/Motion.ts
4
+ /**
5
+ * Motion class.
6
+ *
7
+ * Animate the component's root element declaratively with the
8
+ * [Motion](https://motion.dev) library. The `initial` styles are applied on
9
+ * mount, then the `animate` keyframes play when playback on mount is enabled
10
+ * with `data-option-autoplay`.
11
+ *
12
+ * The component holds a single current animation. `play()` and `reverse()`
13
+ * always drive the animation declared by the options — recreating it when an
14
+ * imperative {@link Motion.animate} call superseded it — while the other
15
+ * playback methods (`pause`, `seek`, `stop`, ...) act on whichever animation
16
+ * is current. An `Action` can control it from any interaction:
17
+ * `data-on:click="Motion->target.play()"`.
18
+ *
19
+ * Events bubble, so an ancestor `Action` can catch and route them; use the
20
+ * `.stop` event modifier to contain them in nested setups.
21
+ *
22
+ * @link https://ui.studiometa.dev/reference/items/Motion/
23
+ */
24
+ var Motion = class extends Base {
25
+ /**
26
+ * Config.
27
+ */
28
+ static config = {
29
+ name: "Motion",
30
+ emits: [
31
+ "motion-play",
32
+ "motion-pause",
33
+ "motion-complete",
34
+ "motion-cancel",
35
+ "motion-stop"
36
+ ],
37
+ options: {
38
+ initial: Object,
39
+ animate: Object,
40
+ transition: Object,
41
+ autoplay: Boolean,
42
+ at: String,
43
+ hover: Object,
44
+ press: Object,
45
+ inView: Object,
46
+ inViewMargin: String,
47
+ inViewAmount: String,
48
+ once: Boolean
49
+ }
50
+ };
51
+ /**
52
+ * The current animation playback controls, or `null` when idle.
53
+ * @private
54
+ */
55
+ __controls = null;
56
+ /**
57
+ * Monotonic token invalidating stale completion watchers whenever the
58
+ * current playback changes (new play, stop, cancel, destroy).
59
+ * @private
60
+ */
61
+ __completionToken = 0;
62
+ /**
63
+ * The stop function of each gesture binding, released on destroy.
64
+ * @private
65
+ */
66
+ __gestureStops = [];
67
+ /**
68
+ * The base value of every property a gesture animated, captured the first
69
+ * time a gesture touched it — the values a gesture returns to when it ends.
70
+ * @private
71
+ */
72
+ __baseValues = {};
73
+ /**
74
+ * Whether the current animation was built from the `animate` and
75
+ * `transition` options, as opposed to an imperative `animate()` call.
76
+ * @private
77
+ */
78
+ __fromOptions = false;
79
+ /**
80
+ * The current animation playback controls, exposed for advanced use from
81
+ * `Action` effects (e.g. `Motion->target.controls.speed = 2`).
82
+ */
83
+ get controls() {
84
+ return this.__controls;
85
+ }
86
+ /**
87
+ * The current playback time in seconds.
88
+ */
89
+ get time() {
90
+ return this.__controls?.time ?? 0;
91
+ }
92
+ /**
93
+ * The current animation duration in seconds.
94
+ */
95
+ get duration() {
96
+ return this.__controls?.duration ?? 0;
97
+ }
98
+ /**
99
+ * The current playback progress, from 0 to 1.
100
+ */
101
+ get progress() {
102
+ const duration = this.duration;
103
+ return duration > 0 ? this.time / duration : 0;
104
+ }
105
+ /**
106
+ * Apply the `initial` styles, play the `animate` keyframes when `autoplay`
107
+ * is enabled, then bind the gesture options.
108
+ */
109
+ async mounted() {
110
+ const { initial, autoplay } = this.$options;
111
+ const motion = await resolveMotion();
112
+ if (!this.$isMounted) return;
113
+ if (Object.keys(initial).length > 0) motion.animate(this.$el, initial, { duration: 0 });
114
+ if (autoplay && this.__hasDeclaredAnimation) this.play();
115
+ this.__bindGestures(motion);
116
+ }
117
+ /**
118
+ * Whether the options declare an animation to play — the gate for
119
+ * `autoplay`. Subclasses building their animation from another source
120
+ * (e.g. `MotionSequence` from its children) override this.
121
+ * @protected
122
+ */
123
+ get __hasDeclaredAnimation() {
124
+ return Object.keys(this.$options.animate).length > 0;
125
+ }
126
+ /**
127
+ * Stop the current animation and release the gesture bindings on destroy,
128
+ * keeping the styles the animation reached.
129
+ */
130
+ destroyed() {
131
+ this.__completionToken += 1;
132
+ this.__controls?.stop();
133
+ this.__controls = null;
134
+ for (const stop of this.__gestureStops) stop();
135
+ this.__gestureStops = [];
136
+ }
137
+ /**
138
+ * Play the animation declared by the `animate` and `transition` options
139
+ * forward, creating it on first play — or recreating it when an imperative
140
+ * `animate()` call superseded it. Restarts a finished animation. The
141
+ * returned promise resolves when the animation settles.
142
+ */
143
+ async play() {
144
+ await resolveMotion();
145
+ let controls = this.__controls;
146
+ if (!controls || !this.__fromOptions) {
147
+ controls?.stop();
148
+ controls = this.__createControls();
149
+ }
150
+ controls.speed = Math.abs(controls.speed || 1);
151
+ controls.play();
152
+ this.__dispatch("motion-play");
153
+ return this.__watchCompletion(controls);
154
+ }
155
+ /**
156
+ * Play the animation declared by the options backward. When nothing has
157
+ * played yet — or when an imperative `animate()` call superseded the
158
+ * declared animation — it is created at its end so it plays back to its
159
+ * starting styles. The returned promise resolves when the animation settles.
160
+ */
161
+ async reverse() {
162
+ await resolveMotion();
163
+ let controls = this.__controls;
164
+ if (!controls || !this.__fromOptions) {
165
+ controls?.stop();
166
+ controls = this.__createControls();
167
+ controls.time = controls.duration;
168
+ }
169
+ controls.speed = -Math.abs(controls.speed || 1);
170
+ controls.play();
171
+ this.__dispatch("motion-play");
172
+ return this.__watchCompletion(controls);
173
+ }
174
+ /**
175
+ * Pause the current animation in place.
176
+ */
177
+ pause() {
178
+ if (!this.__controls) return;
179
+ this.__controls.pause();
180
+ this.__dispatch("motion-pause");
181
+ }
182
+ /**
183
+ * Animate to the given keyframes, replacing the current animation. The
184
+ * options are merged over the `transition` option. The returned promise
185
+ * resolves when the animation settles.
186
+ */
187
+ async animate(keyframes, options) {
188
+ const motion = await resolveMotion();
189
+ this.__completionToken += 1;
190
+ this.__controls?.stop();
191
+ const controls = motion.animate(this.$el, keyframes, {
192
+ ...this.$options.transition,
193
+ ...options
194
+ });
195
+ this.__controls = controls;
196
+ this.__fromOptions = false;
197
+ this.__dispatch("motion-play");
198
+ return this.__watchCompletion(controls);
199
+ }
200
+ /**
201
+ * Seek the current animation to the given progress (0 to 1), creating it
202
+ * paused when nothing has played yet.
203
+ */
204
+ async seek(progress) {
205
+ await resolveMotion();
206
+ let controls = this.__controls;
207
+ if (!controls) {
208
+ controls = this.__createControls();
209
+ controls.pause();
210
+ }
211
+ controls.time = Math.min(Math.max(progress, 0), 1) * controls.duration;
212
+ }
213
+ /**
214
+ * Stop the current animation, committing the styles it reached. The next
215
+ * `play()` creates a fresh animation.
216
+ */
217
+ stop() {
218
+ if (!this.__controls) return;
219
+ this.__completionToken += 1;
220
+ this.__controls.stop();
221
+ this.__controls = null;
222
+ this.__dispatch("motion-stop");
223
+ }
224
+ /**
225
+ * Cancel the current animation, reverting the element to its pre-animation
226
+ * styles. The next `play()` creates a fresh animation.
227
+ */
228
+ cancel() {
229
+ if (!this.__controls) return;
230
+ this.__completionToken += 1;
231
+ this.__controls.cancel();
232
+ this.__controls = null;
233
+ this.__dispatch("motion-cancel");
234
+ }
235
+ /**
236
+ * Jump the current animation to its end state.
237
+ */
238
+ complete() {
239
+ this.__controls?.complete();
240
+ }
241
+ /**
242
+ * Bind the `hover`, `press` and `inView` gesture options with Motion's own
243
+ * gesture functions (touch-filtered, keyboard-accessible press, real
244
+ * IntersectionObserver). Nothing binds when an option is empty, so idle
245
+ * elements pay nothing. Gesture animations are transient: they never become
246
+ * the current animation and emit no lifecycle events.
247
+ * @private
248
+ */
249
+ __bindGestures(motion) {
250
+ const { hover, press, inView, inViewMargin, inViewAmount, once } = this.$options;
251
+ if (Object.keys(hover).length > 0) if (motion.hover) this.__gestureStops.push(motion.hover(this.$el, () => {
252
+ this.__startGesture(hover);
253
+ return () => this.__revertGesture(hover);
254
+ }));
255
+ else this.__warnMissingGesture("hover");
256
+ if (Object.keys(press).length > 0) if (motion.press) this.__gestureStops.push(motion.press(this.$el, () => {
257
+ this.__startGesture(press);
258
+ return () => this.__revertGesture(press);
259
+ }));
260
+ else this.__warnMissingGesture("press");
261
+ if (Object.keys(inView).length > 0) if (motion.inView) {
262
+ const options = {};
263
+ if (inViewMargin) options.margin = inViewMargin;
264
+ if (inViewAmount) {
265
+ const numeric = Number(inViewAmount);
266
+ options.amount = Number.isNaN(numeric) ? inViewAmount : numeric;
267
+ }
268
+ this.__gestureStops.push(motion.inView(this.$el, () => {
269
+ this.__startGesture(inView);
270
+ if (once) return;
271
+ return () => this.__revertGesture(inView);
272
+ }, options));
273
+ } else this.__warnMissingGesture("inView");
274
+ }
275
+ /**
276
+ * Animate to a gesture state, alongside — not replacing — the current
277
+ * animation, capturing the base value of every property it touches first.
278
+ * @private
279
+ */
280
+ __startGesture(keyframes) {
281
+ this.__captureBaseValues(keyframes);
282
+ return getMotion().animate(this.$el, keyframes, this.$options.transition);
283
+ }
284
+ /**
285
+ * Capture the element's current value for every property a gesture is about
286
+ * to animate, once per property and never refreshed afterwards.
287
+ *
288
+ * The read mirrors Motion's own `VisualElement.readValueFromInstance()`: the
289
+ * parsed transform matrix for a transform property, the computed style
290
+ * otherwise — both through Motion's own readers, so the values come back in
291
+ * the shape its animations expect. Motion React hydrates the same snapshot
292
+ * (its `baseTarget`) the first time it reads a value and keeps it, which is
293
+ * what makes a return immune to a second gesture starting while the previous
294
+ * one is still returning.
295
+ *
296
+ * A property the readers cannot resolve is left out, so nothing is invented:
297
+ * the return animation simply does not touch it.
298
+ * @private
299
+ */
300
+ __captureBaseValues(keyframes) {
301
+ const { transformProps, readTransformValue, getComputedStyle } = getMotion();
302
+ for (const property of Object.keys(keyframes)) {
303
+ if (property in this.__baseValues) continue;
304
+ if (readTransformValue && transformProps?.has(property)) {
305
+ this.__baseValues[property] = readTransformValue(this.$el, property);
306
+ continue;
307
+ }
308
+ const computed = getComputedStyle?.(this.$el, property);
309
+ if (typeof computed === "string" && computed !== "") {
310
+ const numeric = Number(computed);
311
+ this.__baseValues[property] = Number.isNaN(numeric) ? computed : numeric;
312
+ }
313
+ }
314
+ }
315
+ /**
316
+ * Return the element to its base values when a gesture ends, animating
317
+ * forward with the `transition` option — the gesture animation is never
318
+ * rewound.
319
+ *
320
+ * This is what Motion React does: ending a gesture deactivates its variant
321
+ * (`node.animationState.setActive("whileHover", false)`), which recomputes
322
+ * the target of every property the variant owned and animates to it. Playing
323
+ * the gesture animation backward instead would run its easing or spring
324
+ * curve in reverse — a different feel — and could never reach a base value
325
+ * the element did not hold when the gesture started.
326
+ * @private
327
+ */
328
+ __revertGesture(keyframes) {
329
+ const base = {};
330
+ for (const property of Object.keys(keyframes)) if (property in this.__baseValues) base[property] = this.__baseValues[property];
331
+ if (Object.keys(base).length === 0) return;
332
+ getMotion().animate(this.$el, base, this.$options.transition);
333
+ }
334
+ /**
335
+ * Warn about a gesture option the resolved motion module cannot honor.
336
+ * @private
337
+ */
338
+ __warnMissingGesture(name) {
339
+ this.$warn(`The resolved motion module has no \`${name}()\` (e.g. \`motion/mini\`). Provide the full \`motion\` entry to use the \`${name}\` option.`);
340
+ }
341
+ /**
342
+ * Create the animation from the `animate` and `transition` options and make
343
+ * it the current one. Subclasses override this to build the current
344
+ * animation from another source.
345
+ * @protected
346
+ */
347
+ __createControls() {
348
+ const { transition } = this.$options;
349
+ const controls = getMotion().animate(this.$el, this.keyframes, transition);
350
+ this.__controls = controls;
351
+ this.__fromOptions = true;
352
+ return controls;
353
+ }
354
+ /**
355
+ * The keyframes of the declared animation, with the `initial` styles folded
356
+ * in as the starting point of every property they both describe.
357
+ *
358
+ * Motion reads a lone target value as "from wherever the element is now", so
359
+ * a settled animation would have nothing left to move on the next `play()`.
360
+ * Pairing each such value with its `initial` counterpart pins the start, and
361
+ * the animation replays identically for as long as the options stand. A
362
+ * property already written as a `[from, to]` array is left untouched, and so
363
+ * is one the `initial` styles say nothing about — there, animating from the
364
+ * current state is the point.
365
+ */
366
+ get keyframes() {
367
+ const { initial, animate } = this.$options;
368
+ const keyframes = { ...animate };
369
+ for (const [property, to] of Object.entries(keyframes)) if (!Array.isArray(to) && property in initial) keyframes[property] = [initial[property], to];
370
+ return keyframes;
371
+ }
372
+ /**
373
+ * Emit `motion-complete` when the given animation finishes, unless another
374
+ * playback superseded it in the meantime. The returned promise resolves when
375
+ * the animation settles and never rejects, so playback methods can safely
376
+ * hand it to callers that do not catch.
377
+ * @private
378
+ */
379
+ __watchCompletion(controls) {
380
+ const token = ++this.__completionToken;
381
+ return new Promise((resolve) => {
382
+ controls.then(() => {
383
+ if (token === this.__completionToken && this.__controls === controls) this.__dispatch("motion-complete");
384
+ resolve();
385
+ }, resolve);
386
+ });
387
+ }
388
+ /**
389
+ * Dispatch a bubbling event so an ancestor `Action` can catch and route it.
390
+ * @private
391
+ */
392
+ __dispatch(name, ...detail) {
393
+ this.$emit(new CustomEvent(name, {
394
+ detail,
395
+ bubbles: true
396
+ }));
397
+ }
398
+ };
399
+ //#endregion
400
+ export { Motion, Motion as default };
401
+
402
+ //# sourceMappingURL=Motion.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"Motion.js","names":[],"sources":["../src/Motion.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type {\n AnimationOptions,\n AnimationPlaybackControlsWithThen,\n DOMKeyframesDefinition,\n} from 'motion';\nimport { getMotion, resolveMotion } from './dependencies.js';\nimport type { MotionModule } from './dependencies.js';\n\nexport interface MotionProps extends BaseProps {\n $options: {\n initial: DOMKeyframesDefinition;\n animate: DOMKeyframesDefinition;\n transition: AnimationOptions;\n autoplay: boolean;\n at: string;\n hover: DOMKeyframesDefinition;\n press: DOMKeyframesDefinition;\n inView: DOMKeyframesDefinition;\n inViewMargin: string;\n inViewAmount: string;\n once: boolean;\n };\n}\n\n/**\n * Motion class.\n *\n * Animate the component's root element declaratively with the\n * [Motion](https://motion.dev) library. The `initial` styles are applied on\n * mount, then the `animate` keyframes play when playback on mount is enabled\n * with `data-option-autoplay`.\n *\n * The component holds a single current animation. `play()` and `reverse()`\n * always drive the animation declared by the options — recreating it when an\n * imperative {@link Motion.animate} call superseded it — while the other\n * playback methods (`pause`, `seek`, `stop`, ...) act on whichever animation\n * is current. An `Action` can control it from any interaction:\n * `data-on:click=\"Motion->target.play()\"`.\n *\n * Events bubble, so an ancestor `Action` can catch and route them; use the\n * `.stop` event modifier to contain them in nested setups.\n *\n * @link https://ui.studiometa.dev/reference/items/Motion/\n */\nexport class Motion<T extends BaseProps = BaseProps> extends Base<MotionProps & T> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'Motion',\n emits: ['motion-play', 'motion-pause', 'motion-complete', 'motion-cancel', 'motion-stop'],\n options: {\n initial: Object,\n animate: Object,\n transition: Object,\n autoplay: Boolean,\n at: String,\n hover: Object,\n press: Object,\n inView: Object,\n inViewMargin: String,\n inViewAmount: String,\n once: Boolean,\n },\n };\n\n /**\n * The current animation playback controls, or `null` when idle.\n * @private\n */\n __controls: AnimationPlaybackControlsWithThen | null = null;\n\n /**\n * Monotonic token invalidating stale completion watchers whenever the\n * current playback changes (new play, stop, cancel, destroy).\n * @private\n */\n __completionToken = 0;\n\n /**\n * The stop function of each gesture binding, released on destroy.\n * @private\n */\n __gestureStops: VoidFunction[] = [];\n\n /**\n * The base value of every property a gesture animated, captured the first\n * time a gesture touched it — the values a gesture returns to when it ends.\n * @private\n */\n __baseValues: Record<string, string | number> = {};\n\n /**\n * Whether the current animation was built from the `animate` and\n * `transition` options, as opposed to an imperative `animate()` call.\n * @private\n */\n __fromOptions = false;\n\n /**\n * The current animation playback controls, exposed for advanced use from\n * `Action` effects (e.g. `Motion->target.controls.speed = 2`).\n */\n get controls(): AnimationPlaybackControlsWithThen | null {\n return this.__controls;\n }\n\n /**\n * The current playback time in seconds.\n */\n get time(): number {\n return this.__controls?.time ?? 0;\n }\n\n /**\n * The current animation duration in seconds.\n */\n get duration(): number {\n return this.__controls?.duration ?? 0;\n }\n\n /**\n * The current playback progress, from 0 to 1.\n */\n get progress(): number {\n const duration = this.duration;\n return duration > 0 ? this.time / duration : 0;\n }\n\n /**\n * Apply the `initial` styles, play the `animate` keyframes when `autoplay`\n * is enabled, then bind the gesture options.\n */\n async mounted() {\n const { initial, autoplay } = this.$options;\n const motion = await resolveMotion();\n\n if (!this.$isMounted) {\n return;\n }\n\n if (Object.keys(initial).length > 0) {\n motion.animate(this.$el, initial, { duration: 0 });\n }\n\n if (autoplay && this.__hasDeclaredAnimation) {\n this.play();\n }\n\n this.__bindGestures(motion);\n }\n\n /**\n * Whether the options declare an animation to play — the gate for\n * `autoplay`. Subclasses building their animation from another source\n * (e.g. `MotionSequence` from its children) override this.\n * @protected\n */\n get __hasDeclaredAnimation(): boolean {\n return Object.keys(this.$options.animate).length > 0;\n }\n\n /**\n * Stop the current animation and release the gesture bindings on destroy,\n * keeping the styles the animation reached.\n */\n destroyed() {\n this.__completionToken += 1;\n this.__controls?.stop();\n this.__controls = null;\n\n for (const stop of this.__gestureStops) {\n stop();\n }\n this.__gestureStops = [];\n }\n\n /**\n * Play the animation declared by the `animate` and `transition` options\n * forward, creating it on first play — or recreating it when an imperative\n * `animate()` call superseded it. Restarts a finished animation. The\n * returned promise resolves when the animation settles.\n */\n async play(): Promise<void> {\n await resolveMotion();\n let controls = this.__controls;\n\n if (!controls || !this.__fromOptions) {\n controls?.stop();\n controls = this.__createControls();\n }\n\n controls.speed = Math.abs(controls.speed || 1);\n controls.play();\n this.__dispatch('motion-play');\n return this.__watchCompletion(controls);\n }\n\n /**\n * Play the animation declared by the options backward. When nothing has\n * played yet — or when an imperative `animate()` call superseded the\n * declared animation — it is created at its end so it plays back to its\n * starting styles. The returned promise resolves when the animation settles.\n */\n async reverse(): Promise<void> {\n await resolveMotion();\n let controls = this.__controls;\n\n if (!controls || !this.__fromOptions) {\n controls?.stop();\n controls = this.__createControls();\n controls.time = controls.duration;\n }\n\n controls.speed = -Math.abs(controls.speed || 1);\n controls.play();\n this.__dispatch('motion-play');\n return this.__watchCompletion(controls);\n }\n\n /**\n * Pause the current animation in place.\n */\n pause() {\n if (!this.__controls) {\n return;\n }\n\n this.__controls.pause();\n this.__dispatch('motion-pause');\n }\n\n /**\n * Animate to the given keyframes, replacing the current animation. The\n * options are merged over the `transition` option. The returned promise\n * resolves when the animation settles.\n */\n async animate(keyframes: DOMKeyframesDefinition, options?: AnimationOptions): Promise<void> {\n const motion = await resolveMotion();\n this.__completionToken += 1;\n this.__controls?.stop();\n const controls = motion.animate(this.$el, keyframes, {\n ...this.$options.transition,\n ...options,\n });\n this.__controls = controls;\n this.__fromOptions = false;\n this.__dispatch('motion-play');\n return this.__watchCompletion(controls);\n }\n\n /**\n * Seek the current animation to the given progress (0 to 1), creating it\n * paused when nothing has played yet.\n */\n async seek(progress: number) {\n await resolveMotion();\n let controls = this.__controls;\n\n if (!controls) {\n controls = this.__createControls();\n controls.pause();\n }\n\n controls.time = Math.min(Math.max(progress, 0), 1) * controls.duration;\n }\n\n /**\n * Stop the current animation, committing the styles it reached. The next\n * `play()` creates a fresh animation.\n */\n stop() {\n if (!this.__controls) {\n return;\n }\n\n this.__completionToken += 1;\n this.__controls.stop();\n this.__controls = null;\n this.__dispatch('motion-stop');\n }\n\n /**\n * Cancel the current animation, reverting the element to its pre-animation\n * styles. The next `play()` creates a fresh animation.\n */\n cancel() {\n if (!this.__controls) {\n return;\n }\n\n this.__completionToken += 1;\n this.__controls.cancel();\n this.__controls = null;\n this.__dispatch('motion-cancel');\n }\n\n /**\n * Jump the current animation to its end state.\n */\n complete() {\n this.__controls?.complete();\n }\n\n /**\n * Bind the `hover`, `press` and `inView` gesture options with Motion's own\n * gesture functions (touch-filtered, keyboard-accessible press, real\n * IntersectionObserver). Nothing binds when an option is empty, so idle\n * elements pay nothing. Gesture animations are transient: they never become\n * the current animation and emit no lifecycle events.\n * @private\n */\n __bindGestures(motion: MotionModule) {\n const { hover, press, inView, inViewMargin, inViewAmount, once } = this.$options;\n\n if (Object.keys(hover).length > 0) {\n if (motion.hover) {\n this.__gestureStops.push(\n motion.hover(this.$el, () => {\n this.__startGesture(hover);\n return () => this.__revertGesture(hover);\n }),\n );\n } else {\n this.__warnMissingGesture('hover');\n }\n }\n\n if (Object.keys(press).length > 0) {\n if (motion.press) {\n this.__gestureStops.push(\n motion.press(this.$el, () => {\n this.__startGesture(press);\n return () => this.__revertGesture(press);\n }),\n );\n } else {\n this.__warnMissingGesture('press');\n }\n }\n\n if (Object.keys(inView).length > 0) {\n if (motion.inView) {\n const options: { margin?: string; amount?: 'some' | 'all' | number } = {};\n if (inViewMargin) {\n options.margin = inViewMargin;\n }\n if (inViewAmount) {\n const numeric = Number(inViewAmount);\n options.amount = Number.isNaN(numeric) ? (inViewAmount as 'some' | 'all') : numeric;\n }\n this.__gestureStops.push(\n motion.inView(\n this.$el,\n () => {\n this.__startGesture(inView);\n // With no leave handler returned, `inView()` fires once and the\n // reached styles persist.\n if (once) {\n return undefined;\n }\n return () => this.__revertGesture(inView);\n },\n options as Parameters<NonNullable<MotionModule['inView']>>[2],\n ),\n );\n } else {\n this.__warnMissingGesture('inView');\n }\n }\n }\n\n /**\n * Animate to a gesture state, alongside — not replacing — the current\n * animation, capturing the base value of every property it touches first.\n * @private\n */\n __startGesture(keyframes: DOMKeyframesDefinition): AnimationPlaybackControlsWithThen {\n this.__captureBaseValues(keyframes);\n return getMotion().animate(this.$el, keyframes, this.$options.transition);\n }\n\n /**\n * Capture the element's current value for every property a gesture is about\n * to animate, once per property and never refreshed afterwards.\n *\n * The read mirrors Motion's own `VisualElement.readValueFromInstance()`: the\n * parsed transform matrix for a transform property, the computed style\n * otherwise — both through Motion's own readers, so the values come back in\n * the shape its animations expect. Motion React hydrates the same snapshot\n * (its `baseTarget`) the first time it reads a value and keeps it, which is\n * what makes a return immune to a second gesture starting while the previous\n * one is still returning.\n *\n * A property the readers cannot resolve is left out, so nothing is invented:\n * the return animation simply does not touch it.\n * @private\n */\n __captureBaseValues(keyframes: DOMKeyframesDefinition) {\n const { transformProps, readTransformValue, getComputedStyle } = getMotion();\n\n for (const property of Object.keys(keyframes)) {\n if (property in this.__baseValues) {\n continue;\n }\n\n if (readTransformValue && transformProps?.has(property)) {\n this.__baseValues[property] = readTransformValue(this.$el, property);\n continue;\n }\n\n const computed = getComputedStyle?.(this.$el, property);\n\n if (typeof computed === 'string' && computed !== '') {\n const numeric = Number(computed);\n this.__baseValues[property] = Number.isNaN(numeric) ? computed : numeric;\n }\n }\n }\n\n /**\n * Return the element to its base values when a gesture ends, animating\n * forward with the `transition` option — the gesture animation is never\n * rewound.\n *\n * This is what Motion React does: ending a gesture deactivates its variant\n * (`node.animationState.setActive(\"whileHover\", false)`), which recomputes\n * the target of every property the variant owned and animates to it. Playing\n * the gesture animation backward instead would run its easing or spring\n * curve in reverse — a different feel — and could never reach a base value\n * the element did not hold when the gesture started.\n * @private\n */\n __revertGesture(keyframes: DOMKeyframesDefinition) {\n const base: Record<string, string | number> = {};\n\n for (const property of Object.keys(keyframes)) {\n if (property in this.__baseValues) {\n base[property] = this.__baseValues[property];\n }\n }\n\n if (Object.keys(base).length === 0) {\n return;\n }\n\n getMotion().animate(this.$el, base as DOMKeyframesDefinition, this.$options.transition);\n }\n\n /**\n * Warn about a gesture option the resolved motion module cannot honor.\n * @private\n */\n __warnMissingGesture(name: string) {\n this.$warn(\n `The resolved motion module has no \\`${name}()\\` (e.g. \\`motion/mini\\`). Provide the full \\`motion\\` entry to use the \\`${name}\\` option.`,\n );\n }\n\n /**\n * Create the animation from the `animate` and `transition` options and make\n * it the current one. Subclasses override this to build the current\n * animation from another source.\n * @protected\n */\n __createControls(): AnimationPlaybackControlsWithThen {\n const { transition } = this.$options;\n const controls = getMotion().animate(this.$el, this.keyframes, transition);\n this.__controls = controls;\n this.__fromOptions = true;\n return controls;\n }\n\n /**\n * The keyframes of the declared animation, with the `initial` styles folded\n * in as the starting point of every property they both describe.\n *\n * Motion reads a lone target value as \"from wherever the element is now\", so\n * a settled animation would have nothing left to move on the next `play()`.\n * Pairing each such value with its `initial` counterpart pins the start, and\n * the animation replays identically for as long as the options stand. A\n * property already written as a `[from, to]` array is left untouched, and so\n * is one the `initial` styles say nothing about — there, animating from the\n * current state is the point.\n */\n get keyframes(): DOMKeyframesDefinition {\n const { initial, animate } = this.$options;\n const keyframes: Record<string, unknown> = { ...animate };\n\n for (const [property, to] of Object.entries(keyframes)) {\n if (!Array.isArray(to) && property in initial) {\n keyframes[property] = [initial[property], to];\n }\n }\n\n return keyframes as DOMKeyframesDefinition;\n }\n\n /**\n * Emit `motion-complete` when the given animation finishes, unless another\n * playback superseded it in the meantime. The returned promise resolves when\n * the animation settles and never rejects, so playback methods can safely\n * hand it to callers that do not catch.\n * @private\n */\n __watchCompletion(controls: AnimationPlaybackControlsWithThen): Promise<void> {\n const token = ++this.__completionToken;\n return new Promise((resolve) => {\n controls.then(() => {\n if (token === this.__completionToken && this.__controls === controls) {\n this.__dispatch('motion-complete');\n }\n resolve();\n }, resolve);\n });\n }\n\n /**\n * Dispatch a bubbling event so an ancestor `Action` can catch and route it.\n * @private\n */\n __dispatch(name: string, ...detail: unknown[]) {\n this.$emit(new CustomEvent(name, { detail, bubbles: true }));\n }\n}\n\nexport default Motion;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AA8CA,IAAa,SAAb,cAA6D,KAAsB;;;;CAIjF,OAAO,SAAqB;EAC1B,MAAM;EACN,OAAO;GAAC;GAAe;GAAgB;GAAmB;GAAiB;GAAc;EACzF,SAAS;GACP,SAAS;GACT,SAAS;GACT,YAAY;GACZ,UAAU;GACV,IAAI;GACJ,OAAO;GACP,OAAO;GACP,QAAQ;GACR,cAAc;GACd,cAAc;GACd,MAAM;GACP;EACF;;;;;CAMD,aAAuD;;;;;;CAOvD,oBAAoB;;;;;CAMpB,iBAAiC,EAAE;;;;;;CAOnC,eAAgD,EAAE;;;;;;CAOlD,gBAAgB;;;;;CAMhB,IAAI,WAAqD;AACvD,SAAO,KAAK;;;;;CAMd,IAAI,OAAe;AACjB,SAAO,KAAK,YAAY,QAAQ;;;;;CAMlC,IAAI,WAAmB;AACrB,SAAO,KAAK,YAAY,YAAY;;;;;CAMtC,IAAI,WAAmB;EACr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M,YAAY,OAAO,KAAK,UAAU,CAC3C,KAAI,YAAY,KAAK,aACnB,MAAK,YAAY,KAAK,aAAa;AAIvC,MAAI,OAAO,KAAK,KAAK,CAAC,WAAW,EAC/B;AAGF,aAAW,CAAC,QAAQ,KAAK,KAAK,MAAgC,KAAK,SAAS,WAAW;;;;;;CAOzF,qBAAqB,MAAc;AACjC,OAAK,MACH,uCAAuC,KAAK,8EAA8E,KAAK,YAChI;;;;;;;;CASH,mBAAsD;EACpD,MAAM,EAAE,eAAe,KAAK;EAC5B,MAAM,WAAW,WAAW,CAAC,QAAQ,KAAK,KAAK,KAAK,WAAW,WAAW;AAC1E,OAAK,aAAa;AAClB,OAAK,gBAAgB;AACrB,SAAO;;;;;;;;;;;;;;CAeT,IAAI,YAAoC;EACtC,MAAM,EAAE,SAAS,YAAY,KAAK;EAClC,MAAM,YAAqC,EAAE,GAAG,SAAS;AAEzD,OAAK,MAAM,CAAC,UAAU,OAAO,OAAO,QAAQ,UAAU,CACpD,KAAI,CAAC,MAAM,QAAQ,GAAG,IAAI,YAAY,QACpC,WAAU,YAAY,CAAC,QAAQ,WAAW,GAAG;AAIjD,SAAO;;;;;;;;;CAUT,kBAAkB,UAA4D;EAC5E,MAAM,QAAQ,EAAE,KAAK;AACrB,SAAO,IAAI,SAAS,YAAY;AAC9B,YAAS,WAAW;AAClB,QAAI,UAAU,KAAK,qBAAqB,KAAK,eAAe,SAC1D,MAAK,WAAW,kBAAkB;AAEpC,aAAS;MACR,QAAQ;IACX;;;;;;CAOJ,WAAW,MAAc,GAAG,QAAmB;AAC7C,OAAK,MAAM,IAAI,YAAY,MAAM;GAAE;GAAQ,SAAS;GAAM,CAAC,CAAC"}
@@ -0,0 +1,69 @@
1
+ import { Motion } from "./Motion.js";
2
+ import { Base } from "@studiometa/js-toolkit/Base";
3
+ import { BaseConfig, BaseProps } from "@studiometa/js-toolkit";
4
+ import { scroll } from "motion";
5
+
6
+ //#region src/MotionScrollTimeline.d.ts
7
+ interface MotionScrollTimelineProps extends BaseProps {
8
+ $children: {
9
+ Motion: Motion[];
10
+ };
11
+ $options: {
12
+ offset: string[];
13
+ axis: 'x' | 'y';
14
+ trackContentSize: boolean;
15
+ };
16
+ }
17
+ /**
18
+ * MotionScrollTimeline class.
19
+ *
20
+ * The scroll driver for a group of animations: this element's traversal of the
21
+ * viewport defines the timeline, and every `Motion` child it contains is bound
22
+ * to that progress with Motion's `scroll()` — hardware-accelerated where the
23
+ * browser supports `ScrollTimeline`. The children declare their keyframes as
24
+ * usual and keep their whole playback surface; the timeline takes over their
25
+ * playback on mount — leave their `autoplay` off (its default) so nothing
26
+ * plays before the link lands.
27
+ *
28
+ * `scroll()` is not part of `motion/mini`: when the injected module lacks it,
29
+ * the timeline warns and leaves its children untouched.
30
+ *
31
+ * @example
32
+ * ```html
33
+ * <section data-component="MotionScrollTimeline" class="h-[300vh]">
34
+ * <div data-component="Motion" data-option-animate='{ "opacity": [0, 1, 0] }'>
35
+ * Content
36
+ * </div>
37
+ * </section>
38
+ * ```
39
+ *
40
+ * @link https://ui.studiometa.dev/reference/items/MotionScrollTimeline/
41
+ */
42
+ declare class MotionScrollTimeline<T extends BaseProps = BaseProps> extends Base<MotionScrollTimelineProps & T> {
43
+ /**
44
+ * Config.
45
+ */
46
+ static config: BaseConfig;
47
+ /**
48
+ * The stop function of each `scroll()` link, released on destroy.
49
+ * @private
50
+ */
51
+ __stops: VoidFunction[];
52
+ /**
53
+ * Bind every `Motion` child to this element's scroll progress.
54
+ */
55
+ mounted(): Promise<void>;
56
+ /**
57
+ * Release every scroll link on destroy.
58
+ */
59
+ destroyed(): void;
60
+ /**
61
+ * Bind one child's declared animation to the timeline: `seek(0)` builds it
62
+ * paused when nothing has played yet, then `scroll()` takes over its
63
+ * playback.
64
+ * @private
65
+ */
66
+ __link(scrollFn: typeof scroll, child: Motion): Promise<void>;
67
+ }
68
+ //#endregion
69
+ export { MotionScrollTimeline, MotionScrollTimeline as default, MotionScrollTimelineProps };
@@ -0,0 +1,96 @@
1
+ import { resolveMotion } from "./dependencies.js";
2
+ import { Motion } from "./Motion.js";
3
+ import { Base } from "@studiometa/js-toolkit/Base";
4
+ //#region src/MotionScrollTimeline.ts
5
+ /**
6
+ * MotionScrollTimeline class.
7
+ *
8
+ * The scroll driver for a group of animations: this element's traversal of the
9
+ * viewport defines the timeline, and every `Motion` child it contains is bound
10
+ * to that progress with Motion's `scroll()` — hardware-accelerated where the
11
+ * browser supports `ScrollTimeline`. The children declare their keyframes as
12
+ * usual and keep their whole playback surface; the timeline takes over their
13
+ * playback on mount — leave their `autoplay` off (its default) so nothing
14
+ * plays before the link lands.
15
+ *
16
+ * `scroll()` is not part of `motion/mini`: when the injected module lacks it,
17
+ * the timeline warns and leaves its children untouched.
18
+ *
19
+ * @example
20
+ * ```html
21
+ * <section data-component="MotionScrollTimeline" class="h-[300vh]">
22
+ * <div data-component="Motion" data-option-animate='{ "opacity": [0, 1, 0] }'>
23
+ * Content
24
+ * </div>
25
+ * </section>
26
+ * ```
27
+ *
28
+ * @link https://ui.studiometa.dev/reference/items/MotionScrollTimeline/
29
+ */
30
+ var MotionScrollTimeline = class extends Base {
31
+ /**
32
+ * Config.
33
+ */
34
+ static config = {
35
+ name: "MotionScrollTimeline",
36
+ components: { Motion },
37
+ options: {
38
+ offset: {
39
+ type: Array,
40
+ default: () => ["start end", "end start"]
41
+ },
42
+ axis: {
43
+ type: String,
44
+ default: "y"
45
+ },
46
+ trackContentSize: Boolean
47
+ }
48
+ };
49
+ /**
50
+ * The stop function of each `scroll()` link, released on destroy.
51
+ * @private
52
+ */
53
+ __stops = [];
54
+ /**
55
+ * Bind every `Motion` child to this element's scroll progress.
56
+ */
57
+ async mounted() {
58
+ const motion = await resolveMotion();
59
+ if (!this.$isMounted) return;
60
+ if (!motion.scroll) {
61
+ this.$warn("The resolved motion module has no `scroll()` (e.g. `motion/mini`). Provide the full `motion` entry to use MotionScrollTimeline.");
62
+ return;
63
+ }
64
+ for (const child of this.$children.Motion) this.__link(motion.scroll, child);
65
+ }
66
+ /**
67
+ * Release every scroll link on destroy.
68
+ */
69
+ destroyed() {
70
+ for (const stop of this.__stops) stop();
71
+ this.__stops = [];
72
+ }
73
+ /**
74
+ * Bind one child's declared animation to the timeline: `seek(0)` builds it
75
+ * paused when nothing has played yet, then `scroll()` takes over its
76
+ * playback.
77
+ * @private
78
+ */
79
+ async __link(scrollFn, child) {
80
+ await child.seek(0);
81
+ const { controls } = child;
82
+ if (!controls) return;
83
+ const { offset, axis, trackContentSize } = this.$options;
84
+ const options = {
85
+ target: this.$el,
86
+ axis
87
+ };
88
+ if (offset.length > 0) options.offset = offset;
89
+ if (trackContentSize) options.trackContentSize = true;
90
+ this.__stops.push(scrollFn(controls, options));
91
+ }
92
+ };
93
+ //#endregion
94
+ export { MotionScrollTimeline, MotionScrollTimeline as default };
95
+
96
+ //# sourceMappingURL=MotionScrollTimeline.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"MotionScrollTimeline.js","names":[],"sources":["../src/MotionScrollTimeline.ts"],"sourcesContent":["import { Base } from '@studiometa/js-toolkit/Base';\nimport type { BaseProps, BaseConfig } from '@studiometa/js-toolkit';\nimport type { scroll } from 'motion';\nimport { Motion } from './Motion.js';\nimport { resolveMotion } from './dependencies.js';\n\n/**\n * The options `scroll()` accepts, widened with `trackContentSize`.\n *\n * `scroll()` forwards every option it does not read itself to `scrollInfo()`,\n * which declares `trackContentSize` on its own `ScrollInfoOptions` — Motion's\n * public `ScrollOptions` interface simply omits it.\n */\ntype ScrollOptions = NonNullable<Parameters<typeof scroll>[1]> & {\n trackContentSize?: boolean;\n};\n\nexport interface MotionScrollTimelineProps extends BaseProps {\n $children: {\n Motion: Motion[];\n };\n $options: {\n offset: string[];\n axis: 'x' | 'y';\n trackContentSize: boolean;\n };\n}\n\n/**\n * MotionScrollTimeline class.\n *\n * The scroll driver for a group of animations: this element's traversal of the\n * viewport defines the timeline, and every `Motion` child it contains is bound\n * to that progress with Motion's `scroll()` — hardware-accelerated where the\n * browser supports `ScrollTimeline`. The children declare their keyframes as\n * usual and keep their whole playback surface; the timeline takes over their\n * playback on mount — leave their `autoplay` off (its default) so nothing\n * plays before the link lands.\n *\n * `scroll()` is not part of `motion/mini`: when the injected module lacks it,\n * the timeline warns and leaves its children untouched.\n *\n * @example\n * ```html\n * <section data-component=\"MotionScrollTimeline\" class=\"h-[300vh]\">\n * <div data-component=\"Motion\" data-option-animate='{ \"opacity\": [0, 1, 0] }'>\n * Content\n * </div>\n * </section>\n * ```\n *\n * @link https://ui.studiometa.dev/reference/items/MotionScrollTimeline/\n */\nexport class MotionScrollTimeline<T extends BaseProps = BaseProps> extends Base<\n MotionScrollTimelineProps & T\n> {\n /**\n * Config.\n */\n static config: BaseConfig = {\n name: 'MotionScrollTimeline',\n components: { Motion },\n options: {\n offset: { type: Array, default: () => ['start end', 'end start'] },\n axis: { type: String, default: 'y' },\n trackContentSize: Boolean,\n },\n };\n\n /**\n * The stop function of each `scroll()` link, released on destroy.\n * @private\n */\n __stops: VoidFunction[] = [];\n\n /**\n * Bind every `Motion` child to this element's scroll progress.\n */\n async mounted() {\n const motion = await resolveMotion();\n\n if (!this.$isMounted) {\n return;\n }\n\n if (!motion.scroll) {\n this.$warn(\n 'The resolved motion module has no `scroll()` (e.g. `motion/mini`). Provide the full `motion` entry to use MotionScrollTimeline.',\n );\n return;\n }\n\n for (const child of this.$children.Motion) {\n this.__link(motion.scroll, child);\n }\n }\n\n /**\n * Release every scroll link on destroy.\n */\n destroyed() {\n for (const stop of this.__stops) {\n stop();\n }\n this.__stops = [];\n }\n\n /**\n * Bind one child's declared animation to the timeline: `seek(0)` builds it\n * paused when nothing has played yet, then `scroll()` takes over its\n * playback.\n * @private\n */\n async __link(scrollFn: typeof scroll, child: Motion) {\n await child.seek(0);\n const { controls } = child;\n\n if (!controls) {\n return;\n }\n\n const { offset, axis, trackContentSize } = this.$options;\n const options: ScrollOptions = { target: this.$el, axis };\n if (offset.length > 0) {\n options.offset = offset as ScrollOptions['offset'];\n }\n if (trackContentSize) {\n options.trackContentSize = true;\n }\n this.__stops.push(scrollFn(controls, options));\n }\n}\n\nexport default MotionScrollTimeline;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAqDA,IAAa,uBAAb,cAA2E,KAEzE;;;;CAIA,OAAO,SAAqB;EAC1B,MAAM;EACN,YAAY,EAAE,QAAQ;EACtB,SAAS;GACP,QAAQ;IAAE,MAAM;IAAO,eAAe,CAAC,aAAa,YAAY;IAAE;GAClE,MAAM;IAAE,MAAM;IAAQ,SAAS;IAAK;GACpC,kBAAkB;GACnB;EACF;;;;;CAMD,UAA0B,EAAE;;;;CAK5B,MAAM,UAAU;EACd,MAAM,SAAS,MAAM,eAAe;AAEpC,MAAI,CAAC,KAAK,WACR;AAGF,MAAI,CAAC,OAAO,QAAQ;AAClB,QAAK,MACH,kIACD;AACD;;AAGF,OAAK,MAAM,SAAS,KAAK,UAAU,OACjC,MAAK,OAAO,OAAO,QAAQ,MAAM;;;;;CAOrC,YAAY;AACV,OAAK,MAAM,QAAQ,KAAK,QACtB,OAAM;AAER,OAAK,UAAU,EAAE;;;;;;;;CASnB,MAAM,OAAO,UAAyB,OAAe;AACnD,QAAM,MAAM,KAAK,EAAE;EACnB,MAAM,EAAE,aAAa;AAErB,MAAI,CAAC,SACH;EAGF,MAAM,EAAE,QAAQ,MAAM,qBAAqB,KAAK;EAChD,MAAM,UAAyB;GAAE,QAAQ,KAAK;GAAK;GAAM;AACzD,MAAI,OAAO,SAAS,EAClB,SAAQ,SAAS;AAEnB,MAAI,iBACF,SAAQ,mBAAmB;AAE7B,OAAK,QAAQ,KAAK,SAAS,UAAU,QAAQ,CAAC"}