@motion.page/sdk 1.2.0 → 1.2.1
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/README.md +49 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -19,6 +19,7 @@ A high-performance animation SDK with a declarative API. Scroll-triggered animat
|
|
|
19
19
|
- [Motion()](#motion-function)
|
|
20
20
|
- [Motion Static Methods](#motion-static-methods)
|
|
21
21
|
- [Motion.context](#motioncontext--dynamic-content--spa)
|
|
22
|
+
- [Motion.responsive](#motionresponsive--responsive-breakpoint-variants)
|
|
22
23
|
- [Motion.utils](#motionutils)
|
|
23
24
|
- [Timeline](#timeline)
|
|
24
25
|
- [Triggers](#triggers)
|
|
@@ -284,6 +285,7 @@ Calling `Motion()` with the same name on an already-existing timeline returns it
|
|
|
284
285
|
| `Motion.refreshScrollTriggers` | `(): void` | Recalculate all scroll trigger start/end positions (call after layout changes). |
|
|
285
286
|
| `Motion.cleanup` | `(): void` | Remove ScrollTrigger spacer and marker DOM nodes from the document. |
|
|
286
287
|
| `Motion.context` | `(fn: () => void): MotionContext` | Create a scoped context that tracks all timelines created during `fn()`. Returns a `MotionContext` with `revert()`, `refresh()`, and `add(fn)` methods. Essential for dynamic content (AJAX filters, SPA navigation, infinite scroll). |
|
|
288
|
+
| `Motion.responsive` | `(name, variants, breakpoints): ResponsiveManager` | Register a reactive timeline whose per-breakpoint variant is live-swapped as the viewport crosses a breakpoint — no page reload. `variants` is a sparse map of `desktop` / `laptop` / `tablet` / `phone` factories; `breakpoints` is `{ laptops, tablets, phones }` in px. Returns a manager with `getActiveTier()` and `destroy()`. |
|
|
287
289
|
|
|
288
290
|
#### Examples
|
|
289
291
|
|
|
@@ -344,6 +346,53 @@ ctx.add(() => {
|
|
|
344
346
|
});
|
|
345
347
|
```
|
|
346
348
|
|
|
349
|
+
#### Motion.responsive — Responsive Breakpoint Variants
|
|
350
|
+
|
|
351
|
+
Use `Motion.responsive()` to give one timeline a different animation per viewport tier. Instead of compiling a separate block per breakpoint, you register a **sparse map of variant factories** and the SDK live-swaps the active variant as the viewport crosses a breakpoint — it kills the previous tier's timeline and builds the new one, with **no page reload**.
|
|
352
|
+
|
|
353
|
+
```ts
|
|
354
|
+
Motion.responsive(
|
|
355
|
+
'hero',
|
|
356
|
+
{
|
|
357
|
+
// Each tier is a factory that builds AND registers its timeline.
|
|
358
|
+
desktop: () =>
|
|
359
|
+
Motion('hero', '.title', {
|
|
360
|
+
from: { opacity: 0, x: -120 },
|
|
361
|
+
duration: 1,
|
|
362
|
+
}).onPageLoad(),
|
|
363
|
+
|
|
364
|
+
phone: () =>
|
|
365
|
+
Motion('hero', '.title', {
|
|
366
|
+
from: { opacity: 0, y: 40 },
|
|
367
|
+
duration: 0.6,
|
|
368
|
+
}).onPageLoad(),
|
|
369
|
+
},
|
|
370
|
+
{ laptops: 992, tablets: 768, phones: 576 } // breakpoint boundaries in px
|
|
371
|
+
);
|
|
372
|
+
```
|
|
373
|
+
|
|
374
|
+
**Tiers & ranges.** There are four tiers — `desktop`, `laptop`, `tablet`, `phone`. The `breakpoints` object sets the boundaries, and each tier owns a width range (with the values above):
|
|
375
|
+
|
|
376
|
+
| Tier | Active range |
|
|
377
|
+
|------|--------------|
|
|
378
|
+
| `desktop` | `≥ 993px` (above `laptops`) |
|
|
379
|
+
| `laptop` | `769px – 992px` |
|
|
380
|
+
| `tablet` | `577px – 768px` |
|
|
381
|
+
| `phone` | `≤ 576px` (at or below `phones`) |
|
|
382
|
+
|
|
383
|
+
**Sparse maps cascade up.** You only define the tiers you care about. A tier with no variant falls back to the nearest **wider** tier that does. In the example above, `laptop` and `tablet` widths both use the `desktop` variant; only `phone` width switches to the phone variant.
|
|
384
|
+
|
|
385
|
+
**Return value — the manager.** `Motion.responsive()` returns a `ResponsiveManager`:
|
|
386
|
+
|
|
387
|
+
```ts
|
|
388
|
+
const hero = Motion.responsive('hero', { /* variants */ }, { laptops: 992, tablets: 768, phones: 576 });
|
|
389
|
+
|
|
390
|
+
hero.getActiveTier(); // 'desktop' | 'laptop' | 'tablet' | 'phone' | null — the tier currently driving the page
|
|
391
|
+
hero.destroy(); // remove the breakpoint listeners and kill the active variant
|
|
392
|
+
```
|
|
393
|
+
|
|
394
|
+
> In SSR or environments without `matchMedia`, the `desktop` variant is built once with no live swapping. If the responsive runtime is tree-shaken out of a custom bundle that has no responsive timelines, the call best-effort builds the `desktop` variant and returns `undefined`.
|
|
395
|
+
|
|
347
396
|
---
|
|
348
397
|
|
|
349
398
|
### Motion.utils
|