@vielzeug/necromancer 2.1.0 → 3.0.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/README.md +9 -41
- package/dist/_elements.cjs.map +1 -1
- package/dist/_elements.d.ts +1 -1
- package/dist/_elements.d.ts.map +1 -1
- package/dist/_elements.js.map +1 -1
- package/dist/_handle.cjs +1 -1
- package/dist/_handle.cjs.map +1 -1
- package/dist/_handle.d.ts.map +1 -1
- package/dist/_handle.js +1 -1
- package/dist/_handle.js.map +1 -1
- package/dist/_motion.cjs +1 -1
- package/dist/_motion.cjs.map +1 -1
- package/dist/_motion.d.ts.map +1 -1
- package/dist/_motion.js +8 -15
- package/dist/_motion.js.map +1 -1
- package/dist/animate-each.cjs +1 -1
- package/dist/animate-each.cjs.map +1 -1
- package/dist/animate-each.d.ts +1 -1
- package/dist/animate-each.d.ts.map +1 -1
- package/dist/animate-each.js +3 -1
- package/dist/animate-each.js.map +1 -1
- package/dist/animate.cjs +1 -1
- package/dist/animate.cjs.map +1 -1
- package/dist/animate.d.ts.map +1 -1
- package/dist/animate.js +9 -11
- package/dist/animate.js.map +1 -1
- package/dist/layout.cjs.map +1 -1
- package/dist/layout.d.ts +1 -1
- package/dist/layout.d.ts.map +1 -1
- package/dist/layout.js.map +1 -1
- package/dist/necromancer.cjs +1 -1
- package/dist/necromancer.cjs.map +1 -1
- package/dist/necromancer.iife.js +1 -1
- package/dist/necromancer.iife.js.map +1 -1
- package/dist/necromancer.js +1 -1
- package/dist/necromancer.js.map +1 -1
- package/dist/testing/index.d.ts +7 -7
- package/dist/testing/index.d.ts.map +1 -1
- package/dist/testing.cjs +1 -1
- package/dist/testing.cjs.map +1 -1
- package/dist/testing.js +9 -6
- package/dist/testing.js.map +1 -1
- package/dist/types.d.ts +11 -16
- package/dist/types.d.ts.map +1 -1
- package/package.json +9 -8
- package/dist/_active.cjs +0 -2
- package/dist/_active.cjs.map +0 -1
- package/dist/_active.d.ts +0 -6
- package/dist/_active.d.ts.map +0 -1
- package/dist/_active.js +0 -15
- package/dist/_active.js.map +0 -1
package/README.md
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
1
|
# @vielzeug/necromancer
|
|
2
2
|
|
|
3
|
-
Lifecycle-owned
|
|
4
|
-
|
|
5
|
-
## Overview
|
|
6
|
-
|
|
7
|
-
`@vielzeug/necromancer` owns native animations so UI lifecycles can cancel them predictably. It animates one element, coordinates staggered groups, and applies additive FLIP layout transitions.
|
|
8
|
-
|
|
9
|
-
- `animate()` defaults to `180ms` and returns a lifecycle owner with direct access to its native `Animation`.
|
|
10
|
-
- `animateEach()` animates unique elements with optional staggered delays.
|
|
11
|
-
- `captureLayout()` returns a one-shot, additive FLIP transition covering both position and size.
|
|
3
|
+
> Lifecycle-owned Web Animations API primitives with native access, per-handle groups, and additive FLIP
|
|
12
4
|
|
|
13
5
|
## Installation
|
|
14
6
|
|
|
15
7
|
```sh
|
|
16
8
|
pnpm add @vielzeug/necromancer
|
|
9
|
+
npm install @vielzeug/necromancer
|
|
10
|
+
yarn add @vielzeug/necromancer
|
|
17
11
|
```
|
|
18
12
|
|
|
19
|
-
##
|
|
20
|
-
|
|
21
|
-
Create the element after mount, use the native animation when playback control is needed, and dispose its owner with the UI that created it.
|
|
13
|
+
## Quick Start
|
|
22
14
|
|
|
23
15
|
```ts
|
|
24
16
|
import { animate } from '@vielzeug/necromancer';
|
|
@@ -38,38 +30,14 @@ await handle.result;
|
|
|
38
30
|
handle.dispose();
|
|
39
31
|
```
|
|
40
32
|
|
|
41
|
-
## API Summary
|
|
42
|
-
|
|
43
|
-
| Export | Purpose |
|
|
44
|
-
| --- | --- |
|
|
45
|
-
| `animate()` | Animate one element and return an `AnimationHandle`. |
|
|
46
|
-
| `animateEach()` | Animate unique elements in iteration order and return an `AnimationGroup`. |
|
|
47
|
-
| `captureLayout()` | Capture element positions and sizes and return a one-shot layout transition, including keyed replacement nodes. |
|
|
48
|
-
| `NecromancerError` | Base class for Necromancer-originated errors. |
|
|
49
|
-
|
|
50
|
-
`AnimateOptions` accepts native `KeyframeAnimationOptions`, `interrupt`, `motion`, and `signal`. `duration` defaults to `180` milliseconds; use `interrupt: 'cancel'` to replace active Necromancer-owned animations on one element. `animateEach()` and layout transitions also accept `stagger`. Pass `captureLayout()` a `getKey` function and its transition the committed `elements` to animate framework-rendered replacement nodes from their captured positions.
|
|
51
|
-
|
|
52
|
-
## Testing
|
|
53
|
-
|
|
54
|
-
`@vielzeug/necromancer/testing` provides `installFakeAnimations()`, `FakeAnimation`, and `createRect()` for testing code that calls Necromancer without a browser's `Element.animate()`. See the [Usage Guide](https://vielzeug.dev/necromancer/usage#testing).
|
|
55
|
-
|
|
56
|
-
## Environment
|
|
57
|
-
|
|
58
|
-
Necromancer is for browser execution and requires the Web Animations API when an animation starts. Its root module is safe to import during SSR; call its functions only from a client mount lifecycle where DOM elements exist.
|
|
59
|
-
|
|
60
|
-
`motion` defaults to `'system'`, which follows `prefers-reduced-motion`. When motion is reduced, Necromancer preserves the supplied keyframes but normalizes their timing to an instant transition and resolves with `{ status: 'reduced' }`. Set it to `'full'` to animate regardless of that preference or `'reduced'` to always remove movement.
|
|
61
|
-
|
|
62
|
-
## Peers and Dependencies
|
|
63
|
-
|
|
64
|
-
Necromancer has no runtime or peer dependencies. It uses browser-provided `Element.animate()`, `AbortSignal`, and `Symbol.dispose`.
|
|
65
|
-
|
|
66
|
-
## Scope
|
|
67
|
-
|
|
68
|
-
Necromancer owns explicit Web Animations API keyframes. It does not inject or observe CSS animations, watch DOM mutations, generate springs, interpolate SVG geometry, or provide a JavaScript tween fallback.
|
|
69
|
-
|
|
70
33
|
## Documentation
|
|
71
34
|
|
|
72
35
|
- [Overview](https://vielzeug.dev/necromancer/)
|
|
73
36
|
- [Usage Guide](https://vielzeug.dev/necromancer/usage)
|
|
74
37
|
- [API Reference](https://vielzeug.dev/necromancer/api)
|
|
75
38
|
- [Examples](https://vielzeug.dev/necromancer/examples)
|
|
39
|
+
- [Migration Guide](https://vielzeug.dev/necromancer/migration)
|
|
40
|
+
|
|
41
|
+
## License
|
|
42
|
+
|
|
43
|
+
MIT © [Helmuth Saatkamp](https://github.com/helmuthdu) — part of the [Vielzeug](https://github.com/helmuthdu/vielzeug) monorepo.
|
package/dist/_elements.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_elements.cjs","names":[],"sources":["../src/_elements.ts"],"sourcesContent":["/** Deduplicates elements while preserving first-seen order. Shared by `animateEach()` and `captureLayout()`. */\nexport function uniqueElements(elements: Iterable<
|
|
1
|
+
{"version":3,"file":"_elements.cjs","names":[],"sources":["../src/_elements.ts"],"sourcesContent":["/** Deduplicates elements while preserving first-seen order. Shared by `animateEach()` and `captureLayout()`. */\nexport function uniqueElements<ElementType extends Element>(elements: Iterable<ElementType>): ElementType[] {\n return [...new Set(elements)];\n}\n"],"mappings":"AACA,SAAgB,EAA4C,EAAgD,CAC1G,MAAO,CAAC,GAAG,IAAI,IAAI,CAAQ,CAAC,CAC9B"}
|
package/dist/_elements.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/** Deduplicates elements while preserving first-seen order. Shared by `animateEach()` and `captureLayout()`. */
|
|
2
|
-
export declare function uniqueElements(elements: Iterable<
|
|
2
|
+
export declare function uniqueElements<ElementType extends Element>(elements: Iterable<ElementType>): ElementType[];
|
|
3
3
|
//# sourceMappingURL=_elements.d.ts.map
|
package/dist/_elements.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_elements.d.ts","sourceRoot":"","sources":["../src/_elements.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,wBAAgB,cAAc,CAAC,QAAQ,EAAE,QAAQ,CAAC,
|
|
1
|
+
{"version":3,"file":"_elements.d.ts","sourceRoot":"","sources":["../src/_elements.ts"],"names":[],"mappings":"AAAA,gHAAgH;AAChH,wBAAgB,cAAc,CAAC,WAAW,SAAS,OAAO,EAAE,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,GAAG,WAAW,EAAE,CAE1G"}
|
package/dist/_elements.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_elements.js","names":[],"sources":["../src/_elements.ts"],"sourcesContent":["/** Deduplicates elements while preserving first-seen order. Shared by `animateEach()` and `captureLayout()`. */\nexport function uniqueElements(elements: Iterable<
|
|
1
|
+
{"version":3,"file":"_elements.js","names":[],"sources":["../src/_elements.ts"],"sourcesContent":["/** Deduplicates elements while preserving first-seen order. Shared by `animateEach()` and `captureLayout()`. */\nexport function uniqueElements<ElementType extends Element>(elements: Iterable<ElementType>): ElementType[] {\n return [...new Set(elements)];\n}\n"],"mappings":";AACA,SAAgB,EAA4C,GAAgD;CAC1G,OAAO,CAAC,GAAG,IAAI,IAAI,CAAQ,CAAC;AAC9B"}
|
package/dist/_handle.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
function e(e,t){let n=()=>t(e.reason);return e.addEventListener(`abort`,n,{once:!0}),()=>e.removeEventListener(`abort`,n)}function t(e,t,n){return e.finished.then(()=>(t(),{status:n?`reduced`:`finished`}),e=>(t(),{reason:e,status:`cancelled`}))}function n(n,r,i=!1){let a=!1,o,s=!1,c,l=t(n,()=>{c?.(),c=void 0},i).then(e=>a&&s&&e.status===`cancelled`?{reason:o,status:`cancelled`}:e),u=e=>{a||(a=!0,o=e,s=e!==void 0,c?.(),c=void 0,n.cancel())};return r&&(c=e(r,u)),{animation:n,dispose:u,get disposed(){return a},result:l,[Symbol.dispose](){this.dispose()}}}function r(t,n){let r=!1,i,a=Promise.all(t.map(e=>e.result)).then(e=>(i?.(),i=void 0,e)),o=e=>{if(!r){r=!0,i?.(),i=void 0;for(let n of t)n.dispose(e)}};return n&&(i=e(n,o)),{dispose:o,get disposed(){return r},handles:t,results:a,[Symbol.dispose](){this.dispose()}}}exports.createAnimationGroup=r,exports.createAnimationHandle=n;
|
|
1
|
+
function e(e,t){let n=()=>t(e.reason);return e.addEventListener(`abort`,n,{once:!0}),e.aborted?(e.removeEventListener(`abort`,n),t(e.reason),()=>void 0):()=>e.removeEventListener(`abort`,n)}function t(e,t,n){return e.finished.then(()=>(t(),{status:n?`reduced`:`finished`}),e=>(t(),{reason:e,status:`cancelled`}))}function n(n,r,i=!1){let a=!1,o,s=!1,c,l=t(n,()=>{c?.(),c=void 0},i).then(e=>a&&s&&e.status===`cancelled`?{reason:o,status:`cancelled`}:e),u=e=>{a||(a=!0,o=e,s=e!==void 0,c?.(),c=void 0,n.cancel())};return r&&(c=e(r,u)),{animation:n,dispose:u,get disposed(){return a},result:l,[Symbol.dispose](){this.dispose()}}}function r(t,n){let r=!1,i,a=Promise.all(t.map(e=>e.result)).then(e=>(i?.(),i=void 0,e)),o=e=>{if(!r){r=!0,i?.(),i=void 0;for(let n of t)n.dispose(e)}};return n&&(i=e(n,o)),{dispose:o,get disposed(){return r},handles:t,results:a,[Symbol.dispose](){this.dispose()}}}exports.createAnimationGroup=r,exports.createAnimationHandle=n;
|
|
2
2
|
//# sourceMappingURL=_handle.cjs.map
|
package/dist/_handle.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_handle.cjs","names":[],"sources":["../src/_handle.ts"],"sourcesContent":["import type { AnimationGroup, AnimationHandle, AnimationResult } from './types';\n\n/**\n * Attaches an abort listener to a signal and returns a function that removes it.\n * When the signal aborts, calls the dispose function with the signal's reason.\n */\nfunction attachAbortSignalListener(signal: AbortSignal, dispose: (reason?: unknown) => void): () => void {\n const abort = () => dispose(signal.reason);\n\n signal.addEventListener('abort', abort, { once: true });\n\n return () => signal.removeEventListener('abort', abort);\n}\n\nfunction createResultPromise(animation: Animation, onSettled: () => void, reduced: boolean): Promise<AnimationResult> {\n return animation.finished.then(\n () => {\n onSettled();\n\n return { status: reduced ? 'reduced' : 'finished' };\n },\n (reason: unknown) => {\n onSettled();\n\n return { reason, status: 'cancelled' };\n },\n );\n}\n\n/** Wraps a native Animation with Necromancer's lifecycle contract. */\nexport function createAnimationHandle(animation: Animation, signal?: AbortSignal, reduced = false): AnimationHandle {\n let disposed = false;\n let disposeReason: unknown;\n let hasDisposeReason = false;\n let removeAbortListener: (() => void) | undefined;\n\n const result: Promise<AnimationResult> = createResultPromise(\n animation,\n () => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n },\n reduced,\n ).then((outcome): AnimationResult => {\n if (disposed && hasDisposeReason && outcome.status === 'cancelled') {\n return { reason: disposeReason, status: 'cancelled' };\n }\n\n return outcome;\n });\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n disposeReason = reason;\n hasDisposeReason = reason !== undefined;\n removeAbortListener?.();\n removeAbortListener = undefined;\n animation.cancel();\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n animation,\n dispose,\n get disposed() {\n return disposed;\n },\n result,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n\n/** Combines child animation handles under one disposal owner. */\nexport function createAnimationGroup(handles: readonly AnimationHandle[], signal?: AbortSignal): AnimationGroup {\n let disposed = false;\n let removeAbortListener: (() => void) | undefined;\n\n const results: Promise<readonly AnimationResult[]> = Promise.all(handles.map((handle) => handle.result)).then(\n (childResults): readonly AnimationResult[] => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n\n return childResults;\n },\n );\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n removeAbortListener?.();\n removeAbortListener = undefined;\n for (const handle of handles) handle.dispose(reason);\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n dispose,\n get disposed() {\n return disposed;\n },\n handles,\n results,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n"],"mappings":"AAMA,SAAS,EAA0B,EAAqB,EAAiD,CACvG,IAAM,MAAc,EAAQ,EAAO,MAAM,
|
|
1
|
+
{"version":3,"file":"_handle.cjs","names":[],"sources":["../src/_handle.ts"],"sourcesContent":["import type { AnimationGroup, AnimationHandle, AnimationResult } from './types';\n\n/**\n * Attaches an abort listener to a signal and returns a function that removes it.\n * When the signal aborts, calls the dispose function with the signal's reason.\n */\nfunction attachAbortSignalListener(signal: AbortSignal, dispose: (reason?: unknown) => void): () => void {\n const abort = () => dispose(signal.reason);\n\n signal.addEventListener('abort', abort, { once: true });\n\n if (signal.aborted) {\n signal.removeEventListener('abort', abort);\n dispose(signal.reason);\n return () => undefined;\n }\n\n return () => signal.removeEventListener('abort', abort);\n}\n\nfunction createResultPromise(animation: Animation, onSettled: () => void, reduced: boolean): Promise<AnimationResult> {\n return animation.finished.then(\n () => {\n onSettled();\n\n return { status: reduced ? 'reduced' : 'finished' };\n },\n (reason: unknown) => {\n onSettled();\n\n return { reason, status: 'cancelled' };\n },\n );\n}\n\n/** Wraps a native Animation with Necromancer's lifecycle contract. */\nexport function createAnimationHandle(animation: Animation, signal?: AbortSignal, reduced = false): AnimationHandle {\n let disposed = false;\n let disposeReason: unknown;\n let hasDisposeReason = false;\n let removeAbortListener: (() => void) | undefined;\n\n const result: Promise<AnimationResult> = createResultPromise(\n animation,\n () => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n },\n reduced,\n ).then((outcome): AnimationResult => {\n if (disposed && hasDisposeReason && outcome.status === 'cancelled') {\n return { reason: disposeReason, status: 'cancelled' };\n }\n\n return outcome;\n });\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n disposeReason = reason;\n hasDisposeReason = reason !== undefined;\n removeAbortListener?.();\n removeAbortListener = undefined;\n animation.cancel();\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n animation,\n dispose,\n get disposed() {\n return disposed;\n },\n result,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n\n/** Combines child animation handles under one disposal owner. */\nexport function createAnimationGroup(handles: readonly AnimationHandle[], signal?: AbortSignal): AnimationGroup {\n let disposed = false;\n let removeAbortListener: (() => void) | undefined;\n\n const results: Promise<readonly AnimationResult[]> = Promise.all(handles.map((handle) => handle.result)).then(\n (childResults): readonly AnimationResult[] => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n\n return childResults;\n },\n );\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n removeAbortListener?.();\n removeAbortListener = undefined;\n for (const handle of handles) handle.dispose(reason);\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n dispose,\n get disposed() {\n return disposed;\n },\n handles,\n results,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n"],"mappings":"AAMA,SAAS,EAA0B,EAAqB,EAAiD,CACvG,IAAM,MAAc,EAAQ,EAAO,MAAM,EAUzC,OARA,EAAO,iBAAiB,QAAS,EAAO,CAAE,KAAM,EAAK,CAAC,EAElD,EAAO,SACT,EAAO,oBAAoB,QAAS,CAAK,EACzC,EAAQ,EAAO,MAAM,MACR,IAAA,QAGF,EAAO,oBAAoB,QAAS,CAAK,CACxD,CAEA,SAAS,EAAoB,EAAsB,EAAuB,EAA4C,CACpH,OAAO,EAAU,SAAS,UAEtB,EAAU,EAEH,CAAE,OAAQ,EAAU,UAAY,UAAW,GAEnD,IACC,EAAU,EAEH,CAAE,SAAQ,OAAQ,WAAY,EAEzC,CACF,CAGA,SAAgB,EAAsB,EAAsB,EAAsB,EAAU,GAAwB,CAClH,IAAI,EAAW,GACX,EACA,EAAmB,GACnB,EAEE,EAAmC,EACvC,MACM,CACJ,IAAsB,EACtB,EAAsB,IAAA,EACxB,EACA,CACF,CAAC,CAAC,KAAM,GACF,GAAY,GAAoB,EAAQ,SAAW,YAC9C,CAAE,OAAQ,EAAe,OAAQ,WAAY,EAG/C,CACR,EAEK,EAAW,GAA2B,CACtC,IAEJ,EAAW,GACX,EAAgB,EAChB,EAAmB,IAAW,IAAA,GAC9B,IAAsB,EACtB,EAAsB,IAAA,GACtB,EAAU,OAAO,EACnB,EAMA,OAJI,IACF,EAAsB,EAA0B,EAAQ,CAAO,GAG1D,CACL,YACA,UACA,IAAI,UAAW,CACb,OAAO,CACT,EACA,SACA,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,CACF,CACF,CAGA,SAAgB,EAAqB,EAAqC,EAAsC,CAC9G,IAAI,EAAW,GACX,EAEE,EAA+C,QAAQ,IAAI,EAAQ,IAAK,GAAW,EAAO,MAAM,CAAC,CAAC,CAAC,KACtG,IACC,IAAsB,EACtB,EAAsB,IAAA,GAEf,EAEX,EAEM,EAAW,GAA2B,CACtC,MAIJ,CAFA,EAAW,GACX,IAAsB,EACtB,EAAsB,IAAA,GACtB,IAAK,IAAM,KAAU,EAAS,EAAO,QAAQ,CAAM,CAD7B,CAExB,EAMA,OAJI,IACF,EAAsB,EAA0B,EAAQ,CAAO,GAG1D,CACL,UACA,IAAI,UAAW,CACb,OAAO,CACT,EACA,UACA,UACA,CAAC,OAAO,UAAW,CACjB,KAAK,QAAQ,CACf,CACF,CACF"}
|
package/dist/_handle.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_handle.d.ts","sourceRoot":"","sources":["../src/_handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"_handle.d.ts","sourceRoot":"","sources":["../src/_handle.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAmB,MAAM,SAAS,CAAC;AAmChF,sEAAsE;AACtE,wBAAgB,qBAAqB,CAAC,SAAS,EAAE,SAAS,EAAE,MAAM,CAAC,EAAE,WAAW,EAAE,OAAO,UAAQ,GAAG,eAAe,CA+ClH;AAED,iEAAiE;AACjE,wBAAgB,oBAAoB,CAAC,OAAO,EAAE,SAAS,eAAe,EAAE,EAAE,MAAM,CAAC,EAAE,WAAW,GAAG,cAAc,CAqC9G"}
|
package/dist/_handle.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//#region src/_handle.ts
|
|
2
2
|
function e(e, t) {
|
|
3
3
|
let n = () => t(e.reason);
|
|
4
|
-
return e.addEventListener("abort", n, { once: !0 }), () => e.removeEventListener("abort", n);
|
|
4
|
+
return e.addEventListener("abort", n, { once: !0 }), e.aborted ? (e.removeEventListener("abort", n), t(e.reason), () => void 0) : () => e.removeEventListener("abort", n);
|
|
5
5
|
}
|
|
6
6
|
function t(e, t, n) {
|
|
7
7
|
return e.finished.then(() => (t(), { status: n ? "reduced" : "finished" }), (e) => (t(), {
|
package/dist/_handle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_handle.js","names":[],"sources":["../src/_handle.ts"],"sourcesContent":["import type { AnimationGroup, AnimationHandle, AnimationResult } from './types';\n\n/**\n * Attaches an abort listener to a signal and returns a function that removes it.\n * When the signal aborts, calls the dispose function with the signal's reason.\n */\nfunction attachAbortSignalListener(signal: AbortSignal, dispose: (reason?: unknown) => void): () => void {\n const abort = () => dispose(signal.reason);\n\n signal.addEventListener('abort', abort, { once: true });\n\n return () => signal.removeEventListener('abort', abort);\n}\n\nfunction createResultPromise(animation: Animation, onSettled: () => void, reduced: boolean): Promise<AnimationResult> {\n return animation.finished.then(\n () => {\n onSettled();\n\n return { status: reduced ? 'reduced' : 'finished' };\n },\n (reason: unknown) => {\n onSettled();\n\n return { reason, status: 'cancelled' };\n },\n );\n}\n\n/** Wraps a native Animation with Necromancer's lifecycle contract. */\nexport function createAnimationHandle(animation: Animation, signal?: AbortSignal, reduced = false): AnimationHandle {\n let disposed = false;\n let disposeReason: unknown;\n let hasDisposeReason = false;\n let removeAbortListener: (() => void) | undefined;\n\n const result: Promise<AnimationResult> = createResultPromise(\n animation,\n () => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n },\n reduced,\n ).then((outcome): AnimationResult => {\n if (disposed && hasDisposeReason && outcome.status === 'cancelled') {\n return { reason: disposeReason, status: 'cancelled' };\n }\n\n return outcome;\n });\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n disposeReason = reason;\n hasDisposeReason = reason !== undefined;\n removeAbortListener?.();\n removeAbortListener = undefined;\n animation.cancel();\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n animation,\n dispose,\n get disposed() {\n return disposed;\n },\n result,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n\n/** Combines child animation handles under one disposal owner. */\nexport function createAnimationGroup(handles: readonly AnimationHandle[], signal?: AbortSignal): AnimationGroup {\n let disposed = false;\n let removeAbortListener: (() => void) | undefined;\n\n const results: Promise<readonly AnimationResult[]> = Promise.all(handles.map((handle) => handle.result)).then(\n (childResults): readonly AnimationResult[] => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n\n return childResults;\n },\n );\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n removeAbortListener?.();\n removeAbortListener = undefined;\n for (const handle of handles) handle.dispose(reason);\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n dispose,\n get disposed() {\n return disposed;\n },\n handles,\n results,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n"],"mappings":";AAMA,SAAS,EAA0B,GAAqB,GAAiD;CACvG,IAAM,UAAc,EAAQ,EAAO,MAAM;
|
|
1
|
+
{"version":3,"file":"_handle.js","names":[],"sources":["../src/_handle.ts"],"sourcesContent":["import type { AnimationGroup, AnimationHandle, AnimationResult } from './types';\n\n/**\n * Attaches an abort listener to a signal and returns a function that removes it.\n * When the signal aborts, calls the dispose function with the signal's reason.\n */\nfunction attachAbortSignalListener(signal: AbortSignal, dispose: (reason?: unknown) => void): () => void {\n const abort = () => dispose(signal.reason);\n\n signal.addEventListener('abort', abort, { once: true });\n\n if (signal.aborted) {\n signal.removeEventListener('abort', abort);\n dispose(signal.reason);\n return () => undefined;\n }\n\n return () => signal.removeEventListener('abort', abort);\n}\n\nfunction createResultPromise(animation: Animation, onSettled: () => void, reduced: boolean): Promise<AnimationResult> {\n return animation.finished.then(\n () => {\n onSettled();\n\n return { status: reduced ? 'reduced' : 'finished' };\n },\n (reason: unknown) => {\n onSettled();\n\n return { reason, status: 'cancelled' };\n },\n );\n}\n\n/** Wraps a native Animation with Necromancer's lifecycle contract. */\nexport function createAnimationHandle(animation: Animation, signal?: AbortSignal, reduced = false): AnimationHandle {\n let disposed = false;\n let disposeReason: unknown;\n let hasDisposeReason = false;\n let removeAbortListener: (() => void) | undefined;\n\n const result: Promise<AnimationResult> = createResultPromise(\n animation,\n () => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n },\n reduced,\n ).then((outcome): AnimationResult => {\n if (disposed && hasDisposeReason && outcome.status === 'cancelled') {\n return { reason: disposeReason, status: 'cancelled' };\n }\n\n return outcome;\n });\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n disposeReason = reason;\n hasDisposeReason = reason !== undefined;\n removeAbortListener?.();\n removeAbortListener = undefined;\n animation.cancel();\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n animation,\n dispose,\n get disposed() {\n return disposed;\n },\n result,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n\n/** Combines child animation handles under one disposal owner. */\nexport function createAnimationGroup(handles: readonly AnimationHandle[], signal?: AbortSignal): AnimationGroup {\n let disposed = false;\n let removeAbortListener: (() => void) | undefined;\n\n const results: Promise<readonly AnimationResult[]> = Promise.all(handles.map((handle) => handle.result)).then(\n (childResults): readonly AnimationResult[] => {\n removeAbortListener?.();\n removeAbortListener = undefined;\n\n return childResults;\n },\n );\n\n const dispose = (reason?: unknown): void => {\n if (disposed) return;\n\n disposed = true;\n removeAbortListener?.();\n removeAbortListener = undefined;\n for (const handle of handles) handle.dispose(reason);\n };\n\n if (signal) {\n removeAbortListener = attachAbortSignalListener(signal, dispose);\n }\n\n return {\n dispose,\n get disposed() {\n return disposed;\n },\n handles,\n results,\n [Symbol.dispose]() {\n this.dispose();\n },\n };\n}\n"],"mappings":";AAMA,SAAS,EAA0B,GAAqB,GAAiD;CACvG,IAAM,UAAc,EAAQ,EAAO,MAAM;CAUzC,OARA,EAAO,iBAAiB,SAAS,GAAO,EAAE,MAAM,GAAK,CAAC,GAElD,EAAO,WACT,EAAO,oBAAoB,SAAS,CAAK,GACzC,EAAQ,EAAO,MAAM,SACR,KAAA,WAGF,EAAO,oBAAoB,SAAS,CAAK;AACxD;AAEA,SAAS,EAAoB,GAAsB,GAAuB,GAA4C;CACpH,OAAO,EAAU,SAAS,YAEtB,EAAU,GAEH,EAAE,QAAQ,IAAU,YAAY,WAAW,KAEnD,OACC,EAAU,GAEH;EAAE;EAAQ,QAAQ;CAAY,EAEzC;AACF;AAGA,SAAgB,EAAsB,GAAsB,GAAsB,IAAU,IAAwB;CAClH,IAAI,IAAW,IACX,GACA,IAAmB,IACnB,GAEE,IAAmC,EACvC,SACM;EAEJ,AADA,IAAsB,GACtB,IAAsB,KAAA;CACxB,GACA,CACF,CAAC,CAAC,MAAM,MACF,KAAY,KAAoB,EAAQ,WAAW,cAC9C;EAAE,QAAQ;EAAe,QAAQ;CAAY,IAG/C,CACR,GAEK,KAAW,MAA2B;EACtC,MAEJ,IAAW,IACX,IAAgB,GAChB,IAAmB,MAAW,KAAA,GAC9B,IAAsB,GACtB,IAAsB,KAAA,GACtB,EAAU,OAAO;CACnB;CAMA,OAJI,MACF,IAAsB,EAA0B,GAAQ,CAAO,IAG1D;EACL;EACA;EACA,IAAI,WAAW;GACb,OAAO;EACT;EACA;EACA,CAAC,OAAO,WAAW;GACjB,KAAK,QAAQ;EACf;CACF;AACF;AAGA,SAAgB,EAAqB,GAAqC,GAAsC;CAC9G,IAAI,IAAW,IACX,GAEE,IAA+C,QAAQ,IAAI,EAAQ,KAAK,MAAW,EAAO,MAAM,CAAC,CAAC,CAAC,MACtG,OACC,IAAsB,GACtB,IAAsB,KAAA,GAEf,EAEX,GAEM,KAAW,MAA2B;EACtC,QAIJ;GAFA,IAAW,IACX,IAAsB,GACtB,IAAsB,KAAA;GACtB,KAAK,IAAM,KAAU,GAAS,EAAO,QAAQ,CAAM;EAD7B;CAExB;CAMA,OAJI,MACF,IAAsB,EAA0B,GAAQ,CAAO,IAG1D;EACL;EACA,IAAI,WAAW;GACb,OAAO;EACT;EACA;EACA;EACA,CAAC,OAAO,WAAW;GACjB,KAAK,QAAQ;EACf;CACF;AACF"}
|
package/dist/_motion.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./errors.cjs");
|
|
1
|
+
const e=require("./errors.cjs");function t(e){return e===`full`?!1:e===`reduced`||typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function n(e={},t=!1){let{motion:n,signal:r,...i}=e;return t?{...i,delay:0,duration:0,endDelay:0,iterations:1}:i}function r(t,n){if(n===0)return t;let r=t.delay??0;if(typeof r!=`number`)throw new e.NecromancerConfigError(`A non-zero stagger requires a numeric delay; received ${typeof r}.`);return{...t,delay:r+n}}exports.resolveAnimationOptions=n,exports.shouldReduceMotion=t,exports.withStaggeredDelay=r;
|
|
2
2
|
//# sourceMappingURL=_motion.cjs.map
|
package/dist/_motion.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_motion.cjs","names":[],"sources":["../src/_motion.ts"],"sourcesContent":["import { NecromancerConfigError } from './errors';\nimport type { AnimateOptions, MotionMode } from './types';\n\
|
|
1
|
+
{"version":3,"file":"_motion.cjs","names":[],"sources":["../src/_motion.ts"],"sourcesContent":["import { NecromancerConfigError } from './errors';\nimport type { AnimateOptions, MotionMode } from './types';\n\n/** Reports whether the requested motion preference reduces visible movement. */\nexport function shouldReduceMotion(mode: MotionMode): boolean {\n if (mode === 'full') return false;\n\n if (mode === 'reduced') return true;\n\n return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n/** Converts ownership options to native timing, collapsing reduced motion to an instant transition. */\nexport function resolveAnimationOptions(options: AnimateOptions = {}, reduced = false): KeyframeAnimationOptions {\n const { motion: _motion, signal: _signal, ...nativeOptions } = options;\n\n return reduced ? { ...nativeOptions, delay: 0, duration: 0, endDelay: 0, iterations: 1 } : nativeOptions;\n}\n\n/** Adds an element's stagger offset without changing native nonnumeric delays when no offset is needed. */\nexport function withStaggeredDelay(options: AnimateOptions, offset: number): AnimateOptions {\n if (offset === 0) return options;\n\n const delay = options.delay ?? 0;\n\n if (typeof delay !== 'number') {\n throw new NecromancerConfigError(`A non-zero stagger requires a numeric delay; received ${typeof delay}.`);\n }\n\n return { ...options, delay: delay + offset };\n}\n"],"mappings":"gCAIA,SAAgB,EAAmB,EAA2B,CAK5D,OAJI,IAAS,OAAe,GAExB,IAAS,WAEN,OAAO,YAAe,YAAc,WAAW,kCAAkC,CAAC,CAAC,OAC5F,CAGA,SAAgB,EAAwB,EAA0B,CAAC,EAAG,EAAU,GAAiC,CAC/G,GAAM,CAAE,OAAQ,EAAS,OAAQ,EAAS,GAAG,GAAkB,EAE/D,OAAO,EAAU,CAAE,GAAG,EAAe,MAAO,EAAG,SAAU,EAAG,SAAU,EAAG,WAAY,CAAE,EAAI,CAC7F,CAGA,SAAgB,EAAmB,EAAyB,EAAgC,CAC1F,GAAI,IAAW,EAAG,OAAO,EAEzB,IAAM,EAAQ,EAAQ,OAAS,EAE/B,GAAI,OAAO,GAAU,SACnB,MAAM,IAAI,EAAA,uBAAuB,yDAAyD,OAAO,EAAM,EAAE,EAG3G,MAAO,CAAE,GAAG,EAAS,MAAO,EAAQ,CAAO,CAC7C"}
|
package/dist/_motion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_motion.d.ts","sourceRoot":"","sources":["../src/_motion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"_motion.d.ts","sourceRoot":"","sources":["../src/_motion.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,cAAc,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAE1D,gFAAgF;AAChF,wBAAgB,kBAAkB,CAAC,IAAI,EAAE,UAAU,GAAG,OAAO,CAM5D;AAED,uGAAuG;AACvG,wBAAgB,uBAAuB,CAAC,OAAO,GAAE,cAAmB,EAAE,OAAO,UAAQ,GAAG,wBAAwB,CAI/G;AAED,2GAA2G;AAC3G,wBAAgB,kBAAkB,CAAC,OAAO,EAAE,cAAc,EAAE,MAAM,EAAE,MAAM,GAAG,cAAc,CAU1F"}
|
package/dist/_motion.js
CHANGED
|
@@ -1,26 +1,19 @@
|
|
|
1
1
|
import { NecromancerConfigError as e } from "./errors.js";
|
|
2
2
|
//#region src/_motion.ts
|
|
3
|
-
|
|
4
|
-
function n(e) {
|
|
3
|
+
function t(e) {
|
|
5
4
|
return e === "full" ? !1 : e === "reduced" || typeof matchMedia == "function" && matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
6
5
|
}
|
|
7
|
-
function
|
|
8
|
-
let {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
} : {
|
|
12
|
-
...s,
|
|
13
|
-
duration: r
|
|
14
|
-
};
|
|
15
|
-
return n ? {
|
|
16
|
-
...c,
|
|
6
|
+
function n(e = {}, t = !1) {
|
|
7
|
+
let { motion: n, signal: r, ...i } = e;
|
|
8
|
+
return t ? {
|
|
9
|
+
...i,
|
|
17
10
|
delay: 0,
|
|
18
11
|
duration: 0,
|
|
19
12
|
endDelay: 0,
|
|
20
13
|
iterations: 1
|
|
21
|
-
} :
|
|
14
|
+
} : i;
|
|
22
15
|
}
|
|
23
|
-
function
|
|
16
|
+
function r(t, n) {
|
|
24
17
|
if (n === 0) return t;
|
|
25
18
|
let r = t.delay ?? 0;
|
|
26
19
|
if (typeof r != "number") throw new e(`A non-zero stagger requires a numeric delay; received ${typeof r}.`);
|
|
@@ -30,6 +23,6 @@ function i(t, n) {
|
|
|
30
23
|
};
|
|
31
24
|
}
|
|
32
25
|
//#endregion
|
|
33
|
-
export {
|
|
26
|
+
export { n as resolveAnimationOptions, t as shouldReduceMotion, r as withStaggeredDelay };
|
|
34
27
|
|
|
35
28
|
//# sourceMappingURL=_motion.js.map
|
package/dist/_motion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"_motion.js","names":[],"sources":["../src/_motion.ts"],"sourcesContent":["import { NecromancerConfigError } from './errors';\nimport type { AnimateOptions, MotionMode } from './types';\n\
|
|
1
|
+
{"version":3,"file":"_motion.js","names":[],"sources":["../src/_motion.ts"],"sourcesContent":["import { NecromancerConfigError } from './errors';\nimport type { AnimateOptions, MotionMode } from './types';\n\n/** Reports whether the requested motion preference reduces visible movement. */\nexport function shouldReduceMotion(mode: MotionMode): boolean {\n if (mode === 'full') return false;\n\n if (mode === 'reduced') return true;\n\n return typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;\n}\n\n/** Converts ownership options to native timing, collapsing reduced motion to an instant transition. */\nexport function resolveAnimationOptions(options: AnimateOptions = {}, reduced = false): KeyframeAnimationOptions {\n const { motion: _motion, signal: _signal, ...nativeOptions } = options;\n\n return reduced ? { ...nativeOptions, delay: 0, duration: 0, endDelay: 0, iterations: 1 } : nativeOptions;\n}\n\n/** Adds an element's stagger offset without changing native nonnumeric delays when no offset is needed. */\nexport function withStaggeredDelay(options: AnimateOptions, offset: number): AnimateOptions {\n if (offset === 0) return options;\n\n const delay = options.delay ?? 0;\n\n if (typeof delay !== 'number') {\n throw new NecromancerConfigError(`A non-zero stagger requires a numeric delay; received ${typeof delay}.`);\n }\n\n return { ...options, delay: delay + offset };\n}\n"],"mappings":";;AAIA,SAAgB,EAAmB,GAA2B;CAK5D,OAJI,MAAS,SAAe,KAExB,MAAS,aAEN,OAAO,cAAe,cAAc,WAAW,kCAAkC,CAAC,CAAC;AAC5F;AAGA,SAAgB,EAAwB,IAA0B,CAAC,GAAG,IAAU,IAAiC;CAC/G,IAAM,EAAE,QAAQ,GAAS,QAAQ,GAAS,GAAG,MAAkB;CAE/D,OAAO,IAAU;EAAE,GAAG;EAAe,OAAO;EAAG,UAAU;EAAG,UAAU;EAAG,YAAY;CAAE,IAAI;AAC7F;AAGA,SAAgB,EAAmB,GAAyB,GAAgC;CAC1F,IAAI,MAAW,GAAG,OAAO;CAEzB,IAAM,IAAQ,EAAQ,SAAS;CAE/B,IAAI,OAAO,KAAU,UACnB,MAAM,IAAI,EAAuB,yDAAyD,OAAO,EAAM,EAAE;CAG3G,OAAO;EAAE,GAAG;EAAS,OAAO,IAAQ;CAAO;AAC7C"}
|
package/dist/animate-each.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./_handle.cjs"),t=require("./errors.cjs"),n=require("./_motion.cjs"),r=require("./animate.cjs"),i=require("./_elements.cjs");function a(e){if(!Number.isFinite(e)||e<0)throw new t.NecromancerConfigError(`stagger must be a finite, non-negative number.`)}function o(t,o,s={}){let{signal:c,stagger:l=0,...u}=s;if(a(l),c?.aborted)throw c.reason;let d=i.uniqueElements(t),f=d.map((e,t)=>typeof o==`function`?o(e,t,d.length):o)
|
|
1
|
+
const e=require("./_handle.cjs"),t=require("./errors.cjs"),n=require("./_motion.cjs"),r=require("./animate.cjs"),i=require("./_elements.cjs");function a(e){if(!Number.isFinite(e)||e<0)throw new t.NecromancerConfigError(`stagger must be a finite, non-negative number.`)}function o(t,o,s={}){let{signal:c,stagger:l=0,...u}=s;if(a(l),c?.aborted)throw c.reason;let d=i.uniqueElements(t),f=d.map((e,t)=>typeof o==`function`?o(e,t,d.length):o);if(c?.aborted)throw c.reason;let p=[];try{for(let[e,t]of d.entries()){let i=f[e];p.push(r.animate(t,i,n.withStaggeredDelay(u,e*l)))}}catch(e){for(let t of p)t.dispose(e);throw e}return e.createAnimationGroup(p,c)}exports.animateEach=o;
|
|
2
2
|
//# sourceMappingURL=animate-each.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate-each.cjs","names":[],"sources":["../src/animate-each.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { createAnimationGroup } from './_handle';\nimport { withStaggeredDelay } from './_motion';\nimport { animate } from './animate';\nimport { NecromancerConfigError } from './errors';\nimport type { AnimateEachOptions, AnimationGroup, AnimationHandle, KeyframeFactory, Keyframes } from './types';\n\nfunction validateStagger(stagger: number): void {\n if (!Number.isFinite(stagger) || stagger < 0) {\n throw new NecromancerConfigError('stagger must be a finite, non-negative number.');\n }\n}\n\n/**\n * Starts lifecycle-owned animations for unique elements in iteration order.\n *\n * Each subsequent element starts after `stagger` milliseconds. A keyframe factory\n * receives the stable unique-element index and total before any animation starts.\n */\nexport function animateEach(\n elements: Iterable<
|
|
1
|
+
{"version":3,"file":"animate-each.cjs","names":[],"sources":["../src/animate-each.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { createAnimationGroup } from './_handle';\nimport { withStaggeredDelay } from './_motion';\nimport { animate } from './animate';\nimport { NecromancerConfigError } from './errors';\nimport type { AnimateEachOptions, AnimationGroup, AnimationHandle, KeyframeFactory, Keyframes } from './types';\n\nfunction validateStagger(stagger: number): void {\n if (!Number.isFinite(stagger) || stagger < 0) {\n throw new NecromancerConfigError('stagger must be a finite, non-negative number.');\n }\n}\n\n/**\n * Starts lifecycle-owned animations for unique elements in iteration order.\n *\n * Each subsequent element starts after `stagger` milliseconds. A keyframe factory\n * receives the stable unique-element index and total before any animation starts.\n */\nexport function animateEach<ElementType extends Element>(\n elements: Iterable<ElementType>,\n keyframes: Keyframes | KeyframeFactory<ElementType>,\n options: AnimateEachOptions = {},\n): AnimationGroup {\n const { signal, stagger = 0, ...animationOptions } = options;\n\n validateStagger(stagger);\n\n if (signal?.aborted) throw signal.reason;\n\n const unique = uniqueElements(elements);\n const frames = unique.map((element, index) =>\n typeof keyframes === 'function' ? keyframes(element, index, unique.length) : keyframes,\n );\n\n if (signal?.aborted) throw signal.reason;\n\n const handles: AnimationHandle[] = [];\n\n try {\n for (const [index, element] of unique.entries()) {\n // `frames` was built above from `unique`, one entry per element, so this index is always in range.\n const currentFrames = frames[index]!;\n\n handles.push(animate(element, currentFrames, withStaggeredDelay(animationOptions, index * stagger)));\n }\n } catch (error) {\n for (const handle of handles) handle.dispose(error);\n\n throw error;\n }\n\n return createAnimationGroup(handles, signal);\n}\n"],"mappings":"8IAOA,SAAS,EAAgB,EAAuB,CAC9C,GAAI,CAAC,OAAO,SAAS,CAAO,GAAK,EAAU,EACzC,MAAM,IAAI,EAAA,uBAAuB,gDAAgD,CAErF,CAQA,SAAgB,EACd,EACA,EACA,EAA8B,CAAC,EACf,CAChB,GAAM,CAAE,SAAQ,UAAU,EAAG,GAAG,GAAqB,EAIrD,GAFA,EAAgB,CAAO,EAEnB,GAAQ,QAAS,MAAM,EAAO,OAElC,IAAM,EAAS,EAAA,eAAe,CAAQ,EAChC,EAAS,EAAO,KAAK,EAAS,IAClC,OAAO,GAAc,WAAa,EAAU,EAAS,EAAO,EAAO,MAAM,EAAI,CAC/E,EAEA,GAAI,GAAQ,QAAS,MAAM,EAAO,OAElC,IAAM,EAA6B,CAAC,EAEpC,GAAI,CACF,IAAK,GAAM,CAAC,EAAO,KAAY,EAAO,QAAQ,EAAG,CAE/C,IAAM,EAAgB,EAAO,GAE7B,EAAQ,KAAK,EAAA,QAAQ,EAAS,EAAe,EAAA,mBAAmB,EAAkB,EAAQ,CAAO,CAAC,CAAC,CACrG,CACF,OAAS,EAAO,CACd,IAAK,IAAM,KAAU,EAAS,EAAO,QAAQ,CAAK,EAElD,MAAM,CACR,CAEA,OAAO,EAAA,qBAAqB,EAAS,CAAM,CAC7C"}
|
package/dist/animate-each.d.ts
CHANGED
|
@@ -5,5 +5,5 @@ import type { AnimateEachOptions, AnimationGroup, KeyframeFactory, Keyframes } f
|
|
|
5
5
|
* Each subsequent element starts after `stagger` milliseconds. A keyframe factory
|
|
6
6
|
* receives the stable unique-element index and total before any animation starts.
|
|
7
7
|
*/
|
|
8
|
-
export declare function animateEach(elements: Iterable<
|
|
8
|
+
export declare function animateEach<ElementType extends Element>(elements: Iterable<ElementType>, keyframes: Keyframes | KeyframeFactory<ElementType>, options?: AnimateEachOptions): AnimationGroup;
|
|
9
9
|
//# sourceMappingURL=animate-each.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate-each.d.ts","sourceRoot":"","sources":["../src/animate-each.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAmB,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAQ/G;;;;;GAKG;AACH,wBAAgB,WAAW,
|
|
1
|
+
{"version":3,"file":"animate-each.d.ts","sourceRoot":"","sources":["../src/animate-each.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,kBAAkB,EAAE,cAAc,EAAmB,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAQ/G;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,WAAW,SAAS,OAAO,EACrD,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC/B,SAAS,EAAE,SAAS,GAAG,eAAe,CAAC,WAAW,CAAC,EACnD,OAAO,GAAE,kBAAuB,GAC/B,cAAc,CA8BhB"}
|
package/dist/animate-each.js
CHANGED
|
@@ -10,7 +10,9 @@ function a(e) {
|
|
|
10
10
|
function o(t, o, s = {}) {
|
|
11
11
|
let { signal: c, stagger: l = 0, ...u } = s;
|
|
12
12
|
if (a(l), c?.aborted) throw c.reason;
|
|
13
|
-
let d = i(t), f = d.map((e, t) => typeof o == "function" ? o(e, t, d.length) : o)
|
|
13
|
+
let d = i(t), f = d.map((e, t) => typeof o == "function" ? o(e, t, d.length) : o);
|
|
14
|
+
if (c?.aborted) throw c.reason;
|
|
15
|
+
let p = [];
|
|
14
16
|
try {
|
|
15
17
|
for (let [e, t] of d.entries()) {
|
|
16
18
|
let i = f[e];
|
package/dist/animate-each.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate-each.js","names":[],"sources":["../src/animate-each.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { createAnimationGroup } from './_handle';\nimport { withStaggeredDelay } from './_motion';\nimport { animate } from './animate';\nimport { NecromancerConfigError } from './errors';\nimport type { AnimateEachOptions, AnimationGroup, AnimationHandle, KeyframeFactory, Keyframes } from './types';\n\nfunction validateStagger(stagger: number): void {\n if (!Number.isFinite(stagger) || stagger < 0) {\n throw new NecromancerConfigError('stagger must be a finite, non-negative number.');\n }\n}\n\n/**\n * Starts lifecycle-owned animations for unique elements in iteration order.\n *\n * Each subsequent element starts after `stagger` milliseconds. A keyframe factory\n * receives the stable unique-element index and total before any animation starts.\n */\nexport function animateEach(\n elements: Iterable<
|
|
1
|
+
{"version":3,"file":"animate-each.js","names":[],"sources":["../src/animate-each.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { createAnimationGroup } from './_handle';\nimport { withStaggeredDelay } from './_motion';\nimport { animate } from './animate';\nimport { NecromancerConfigError } from './errors';\nimport type { AnimateEachOptions, AnimationGroup, AnimationHandle, KeyframeFactory, Keyframes } from './types';\n\nfunction validateStagger(stagger: number): void {\n if (!Number.isFinite(stagger) || stagger < 0) {\n throw new NecromancerConfigError('stagger must be a finite, non-negative number.');\n }\n}\n\n/**\n * Starts lifecycle-owned animations for unique elements in iteration order.\n *\n * Each subsequent element starts after `stagger` milliseconds. A keyframe factory\n * receives the stable unique-element index and total before any animation starts.\n */\nexport function animateEach<ElementType extends Element>(\n elements: Iterable<ElementType>,\n keyframes: Keyframes | KeyframeFactory<ElementType>,\n options: AnimateEachOptions = {},\n): AnimationGroup {\n const { signal, stagger = 0, ...animationOptions } = options;\n\n validateStagger(stagger);\n\n if (signal?.aborted) throw signal.reason;\n\n const unique = uniqueElements(elements);\n const frames = unique.map((element, index) =>\n typeof keyframes === 'function' ? keyframes(element, index, unique.length) : keyframes,\n );\n\n if (signal?.aborted) throw signal.reason;\n\n const handles: AnimationHandle[] = [];\n\n try {\n for (const [index, element] of unique.entries()) {\n // `frames` was built above from `unique`, one entry per element, so this index is always in range.\n const currentFrames = frames[index]!;\n\n handles.push(animate(element, currentFrames, withStaggeredDelay(animationOptions, index * stagger)));\n }\n } catch (error) {\n for (const handle of handles) handle.dispose(error);\n\n throw error;\n }\n\n return createAnimationGroup(handles, signal);\n}\n"],"mappings":";;;;;;AAOA,SAAS,EAAgB,GAAuB;CAC9C,IAAI,CAAC,OAAO,SAAS,CAAO,KAAK,IAAU,GACzC,MAAM,IAAI,EAAuB,gDAAgD;AAErF;AAQA,SAAgB,EACd,GACA,GACA,IAA8B,CAAC,GACf;CAChB,IAAM,EAAE,WAAQ,aAAU,GAAG,GAAG,MAAqB;CAIrD,IAFA,EAAgB,CAAO,GAEnB,GAAQ,SAAS,MAAM,EAAO;CAElC,IAAM,IAAS,EAAe,CAAQ,GAChC,IAAS,EAAO,KAAK,GAAS,MAClC,OAAO,KAAc,aAAa,EAAU,GAAS,GAAO,EAAO,MAAM,IAAI,CAC/E;CAEA,IAAI,GAAQ,SAAS,MAAM,EAAO;CAElC,IAAM,IAA6B,CAAC;CAEpC,IAAI;EACF,KAAK,IAAM,CAAC,GAAO,MAAY,EAAO,QAAQ,GAAG;GAE/C,IAAM,IAAgB,EAAO;GAE7B,EAAQ,KAAK,EAAQ,GAAS,GAAe,EAAmB,GAAkB,IAAQ,CAAO,CAAC,CAAC;EACrG;CACF,SAAS,GAAO;EACd,KAAK,IAAM,KAAU,GAAS,EAAO,QAAQ,CAAK;EAElD,MAAM;CACR;CAEA,OAAO,EAAqB,GAAS,CAAM;AAC7C"}
|
package/dist/animate.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e=require("./
|
|
1
|
+
const e=require("./_handle.cjs"),t=require("./errors.cjs"),n=require("./_motion.cjs");function r(r,i,a={}){if(a.signal?.aborted)throw a.signal.reason;if(typeof r.animate!=`function`)throw new t.NecromancerUnsupportedError(`The Web Animations API is not available in this environment.`);let o=n.shouldReduceMotion(a.motion??`system`),s=r.animate(i,n.resolveAnimationOptions(a,o));return e.createAnimationHandle(s,a.signal,o)}exports.animate=r;
|
|
2
2
|
//# sourceMappingURL=animate.cjs.map
|
package/dist/animate.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate.cjs","names":[],"sources":["../src/animate.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"animate.cjs","names":[],"sources":["../src/animate.ts"],"sourcesContent":["import { createAnimationHandle } from './_handle';\nimport { resolveAnimationOptions, shouldReduceMotion } from './_motion';\nimport { NecromancerUnsupportedError } from './errors';\nimport type { AnimateOptions, AnimationHandle, Keyframes } from './types';\n\n/**\n * Starts a lifecycle-owned native Web Animation for one element.\n *\n * The returned handle cancels its native animation when disposed. By default, the\n * operating system's reduced-motion preference suppresses movement.\n */\nexport function animate(element: Element, keyframes: Keyframes, options: AnimateOptions = {}): AnimationHandle {\n if (options.signal?.aborted) throw options.signal.reason;\n\n if (typeof element.animate !== 'function') {\n throw new NecromancerUnsupportedError('The Web Animations API is not available in this environment.');\n }\n\n const reduced = shouldReduceMotion(options.motion ?? 'system');\n const nativeAnimation = element.animate(\n keyframes as Keyframe[] | PropertyIndexedKeyframes,\n resolveAnimationOptions(options, reduced),\n );\n return createAnimationHandle(nativeAnimation, options.signal, reduced);\n}\n"],"mappings":"sFAWA,SAAgB,EAAQ,EAAkB,EAAsB,EAA0B,CAAC,EAAoB,CAC7G,GAAI,EAAQ,QAAQ,QAAS,MAAM,EAAQ,OAAO,OAElD,GAAI,OAAO,EAAQ,SAAY,WAC7B,MAAM,IAAI,EAAA,4BAA4B,8DAA8D,EAGtG,IAAM,EAAU,EAAA,mBAAmB,EAAQ,QAAU,QAAQ,EACvD,EAAkB,EAAQ,QAC9B,EACA,EAAA,wBAAwB,EAAS,CAAO,CAC1C,EACA,OAAO,EAAA,sBAAsB,EAAiB,EAAQ,OAAQ,CAAO,CACvE"}
|
package/dist/animate.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate.d.ts","sourceRoot":"","sources":["../src/animate.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"animate.d.ts","sourceRoot":"","sources":["../src/animate.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,cAAc,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,SAAS,CAAC;AAE1E;;;;;GAKG;AACH,wBAAgB,OAAO,CAAC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,SAAS,EAAE,OAAO,GAAE,cAAmB,GAAG,eAAe,CAa7G"}
|
package/dist/animate.js
CHANGED
|
@@ -1,16 +1,14 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import { resolveAnimationOptions as i, shouldReduceMotion as a } from "./_motion.js";
|
|
1
|
+
import { createAnimationHandle as e } from "./_handle.js";
|
|
2
|
+
import { NecromancerUnsupportedError as t } from "./errors.js";
|
|
3
|
+
import { resolveAnimationOptions as n, shouldReduceMotion as r } from "./_motion.js";
|
|
5
4
|
//#region src/animate.ts
|
|
6
|
-
function
|
|
7
|
-
if (
|
|
8
|
-
if (typeof
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
return t(o, d), d;
|
|
5
|
+
function i(i, a, o = {}) {
|
|
6
|
+
if (o.signal?.aborted) throw o.signal.reason;
|
|
7
|
+
if (typeof i.animate != "function") throw new t("The Web Animations API is not available in this environment.");
|
|
8
|
+
let s = r(o.motion ?? "system"), c = i.animate(a, n(o, s));
|
|
9
|
+
return e(c, o.signal, s);
|
|
12
10
|
}
|
|
13
11
|
//#endregion
|
|
14
|
-
export {
|
|
12
|
+
export { i as animate };
|
|
15
13
|
|
|
16
14
|
//# sourceMappingURL=animate.js.map
|
package/dist/animate.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"animate.js","names":[],"sources":["../src/animate.ts"],"sourcesContent":["import {
|
|
1
|
+
{"version":3,"file":"animate.js","names":[],"sources":["../src/animate.ts"],"sourcesContent":["import { createAnimationHandle } from './_handle';\nimport { resolveAnimationOptions, shouldReduceMotion } from './_motion';\nimport { NecromancerUnsupportedError } from './errors';\nimport type { AnimateOptions, AnimationHandle, Keyframes } from './types';\n\n/**\n * Starts a lifecycle-owned native Web Animation for one element.\n *\n * The returned handle cancels its native animation when disposed. By default, the\n * operating system's reduced-motion preference suppresses movement.\n */\nexport function animate(element: Element, keyframes: Keyframes, options: AnimateOptions = {}): AnimationHandle {\n if (options.signal?.aborted) throw options.signal.reason;\n\n if (typeof element.animate !== 'function') {\n throw new NecromancerUnsupportedError('The Web Animations API is not available in this environment.');\n }\n\n const reduced = shouldReduceMotion(options.motion ?? 'system');\n const nativeAnimation = element.animate(\n keyframes as Keyframe[] | PropertyIndexedKeyframes,\n resolveAnimationOptions(options, reduced),\n );\n return createAnimationHandle(nativeAnimation, options.signal, reduced);\n}\n"],"mappings":";;;;AAWA,SAAgB,EAAQ,GAAkB,GAAsB,IAA0B,CAAC,GAAoB;CAC7G,IAAI,EAAQ,QAAQ,SAAS,MAAM,EAAQ,OAAO;CAElD,IAAI,OAAO,EAAQ,WAAY,YAC7B,MAAM,IAAI,EAA4B,8DAA8D;CAGtG,IAAM,IAAU,EAAmB,EAAQ,UAAU,QAAQ,GACvD,IAAkB,EAAQ,QAC9B,GACA,EAAwB,GAAS,CAAO,CAC1C;CACA,OAAO,EAAsB,GAAiB,EAAQ,QAAQ,CAAO;AACvE"}
|
package/dist/layout.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.cjs","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { animateEach } from './animate-each';\nimport { NecromancerConfigError } from './errors';\nimport type { LayoutAnimationOptions, LayoutCaptureOptions, LayoutTransition } from './types';\n\ntype LayoutRect = Readonly<Pick<DOMRectReadOnly, 'height' | 'width' | 'x' | 'y'>>;\ntype LayoutEntry = Readonly<{ element:
|
|
1
|
+
{"version":3,"file":"layout.cjs","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { animateEach } from './animate-each';\nimport { NecromancerConfigError } from './errors';\nimport type { LayoutAnimationOptions, LayoutCaptureOptions, LayoutTransition } from './types';\n\ntype LayoutRect = Readonly<Pick<DOMRectReadOnly, 'height' | 'width' | 'x' | 'y'>>;\ntype LayoutEntry<ElementType extends Element> = Readonly<{ element: ElementType; rect: LayoutRect }>;\ntype LayoutChange<ElementType extends Element> = Readonly<{\n element: ElementType;\n scaleX: number;\n scaleY: number;\n x: number;\n y: number;\n}>;\n\n// Rounds before templating into a keyframe string purely for DevTools readability — a `getBoundingClientRect()`\n// subtraction routinely produces values like `12.340000000000002`, which is noise once rendered as CSS.\n// Pixels only need whole-number precision; scale factors (close to 1) need finer precision to stay visually exact.\nfunction round(value: number, precision: number): number {\n const factor = 10 ** precision;\n\n return Math.round(value * factor) / factor;\n}\n\n// `getBoundingClientRect()`'s width/height is the rotated, axis-aligned bounding box — using it\n// for size would distort the scale ratio under any rotation. `offsetWidth`/`offsetHeight` report\n// the box's own untransformed layout size instead. Elements without an offset box (e.g. SVG)\n// fall back to the bounding rect, accepting that same distortion as the only option available.\nfunction measureSize(element: Element): Readonly<{ height: number; width: number }> {\n if ('offsetWidth' in element && 'offsetHeight' in element) {\n return { height: (element as HTMLElement).offsetHeight, width: (element as HTMLElement).offsetWidth };\n }\n\n const rect = element.getBoundingClientRect();\n\n return { height: rect.height, width: rect.width };\n}\n\nfunction measureLayout(element: Element): LayoutRect {\n const rect = element.getBoundingClientRect();\n const size = measureSize(element);\n\n return { height: size.height, width: size.width, x: rect.x, y: rect.y };\n}\n\n// `next` is 0 exactly when the element has collapsed (e.g. `display: none` mid-transition);\n// there's no meaningful ratio to compute then, so treat it as unscaled rather than producing Infinity/NaN.\nfunction computeScale(captured: number, next: number): number {\n return next === 0 ? 1 : captured / next;\n}\n\nfunction readKey<ElementType extends Element>(\n element: ElementType,\n getKey: (element: ElementType) => string,\n phase: string,\n): string {\n const key = getKey(element);\n\n if (typeof key !== 'string' || key.length === 0) {\n throw new NecromancerConfigError(`getKey must return a non-empty string for every ${phase} element.`);\n }\n\n return key;\n}\n\nfunction createKeyMap<ElementType extends Element>(\n entries: readonly LayoutEntry<ElementType>[],\n getKey: (element: ElementType) => string,\n phase: string,\n) {\n const keys = new Map<string, LayoutEntry<ElementType>>();\n\n for (const entry of entries) {\n const key = readKey(entry.element, getKey, phase);\n\n if (keys.has(key)) {\n throw new NecromancerConfigError(`getKey returned duplicate keys for the ${phase} elements.`);\n }\n\n keys.set(key, entry);\n }\n\n return keys;\n}\n\nfunction changedElement<ElementType extends Element>(\n element: ElementType,\n rect: LayoutRect,\n): LayoutChange<ElementType> | undefined {\n if (!element.isConnected) return undefined;\n\n const next = measureLayout(element);\n const x = rect.x - next.x;\n const y = rect.y - next.y;\n const scaleX = computeScale(rect.width, next.width);\n const scaleY = computeScale(rect.height, next.height);\n\n return x === 0 && y === 0 && scaleX === 1 && scaleY === 1 ? undefined : { element, scaleX, scaleY, x, y };\n}\n\nfunction matchByIdentity<ElementType extends Element>(\n entries: readonly LayoutEntry<ElementType>[],\n elements: readonly ElementType[],\n): LayoutChange<ElementType>[] {\n const captured = new Map(entries.map((entry) => [entry.element, entry]));\n\n return elements.flatMap((element) => {\n const entry = captured.get(element);\n\n return entry\n ? [changedElement(element, entry.rect)].filter((change): change is LayoutChange<ElementType> => Boolean(change))\n : [];\n });\n}\n\nfunction matchByKey<ElementType extends Element>(\n captured: ReadonlyMap<string, LayoutEntry<ElementType>>,\n elements: readonly ElementType[],\n getKey: (element: ElementType) => string,\n): LayoutChange<ElementType>[] {\n const committed = new Set<string>();\n\n return elements.flatMap((element) => {\n const key = readKey(element, getKey, 'committed');\n const entry = captured.get(key);\n\n if (committed.has(key)) {\n throw new NecromancerConfigError('getKey returned duplicate keys for the committed elements.');\n }\n\n committed.add(key);\n\n return entry\n ? [changedElement(element, entry.rect)].filter((change): change is LayoutChange<ElementType> => Boolean(change))\n : [];\n });\n}\n\n/**\n * Captures the current position and size of unique elements for a later FLIP animation.\n *\n * Each element's `x`/`y` position and `width`/`height` are captured. Rotation and other\n * transforms are not captured or compensated. Capture before mutating the DOM, then call\n * the returned transition's `animate()` method after the browser has applied the resulting\n * layout — position changes animate via translate, and size changes via scale, both\n * additively composed on top of any authored transform.\n */\nexport function captureLayout<ElementType extends Element>(\n elements: Iterable<ElementType>,\n options: LayoutCaptureOptions<ElementType> = {},\n): LayoutTransition<ElementType> {\n const entries: LayoutEntry<ElementType>[] = uniqueElements(elements).map((element) => ({\n element,\n rect: measureLayout(element),\n }));\n const getKey = options.getKey;\n const captured = getKey ? createKeyMap(entries, getKey, 'captured') : undefined;\n\n let consumed = false;\n\n return {\n animate(options: LayoutAnimationOptions<ElementType> = {}) {\n if (consumed) throw new NecromancerConfigError('This layout transition has already been animated.');\n\n const { elements: committedElements, ...animationOptions } = options;\n const elements = uniqueElements(committedElements ?? entries.map(({ element }) => element));\n const changed = getKey && captured ? matchByKey(captured, elements, getKey) : matchByIdentity(entries, elements);\n\n consumed = true;\n\n return animateEach(\n changed.map(({ element }) => element),\n (_, index) => {\n // `changed` was mapped directly into the elements array above, so this index is always in range.\n const change = changed[index]!;\n const translate = `${round(change.x, 2)}px ${round(change.y, 2)}px`;\n const scale = `${round(change.scaleX, 4)} ${round(change.scaleY, 4)}`;\n\n return [\n { composite: 'add', scale, translate },\n { composite: 'add', scale: '1 1', translate: '0px 0px' },\n ];\n },\n animationOptions,\n );\n },\n };\n}\n"],"mappings":"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"}
|
package/dist/layout.d.ts
CHANGED
|
@@ -8,5 +8,5 @@ import type { LayoutCaptureOptions, LayoutTransition } from './types';
|
|
|
8
8
|
* layout — position changes animate via translate, and size changes via scale, both
|
|
9
9
|
* additively composed on top of any authored transform.
|
|
10
10
|
*/
|
|
11
|
-
export declare function captureLayout(elements: Iterable<
|
|
11
|
+
export declare function captureLayout<ElementType extends Element>(elements: Iterable<ElementType>, options?: LayoutCaptureOptions<ElementType>): LayoutTransition<ElementType>;
|
|
12
12
|
//# sourceMappingURL=layout.d.ts.map
|
package/dist/layout.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA0B,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"layout.d.ts","sourceRoot":"","sources":["../src/layout.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAA0B,oBAAoB,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAuI9F;;;;;;;;GAQG;AACH,wBAAgB,aAAa,CAAC,WAAW,SAAS,OAAO,EACvD,QAAQ,EAAE,QAAQ,CAAC,WAAW,CAAC,EAC/B,OAAO,GAAE,oBAAoB,CAAC,WAAW,CAAM,GAC9C,gBAAgB,CAAC,WAAW,CAAC,CAqC/B"}
|
package/dist/layout.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { animateEach } from './animate-each';\nimport { NecromancerConfigError } from './errors';\nimport type { LayoutAnimationOptions, LayoutCaptureOptions, LayoutTransition } from './types';\n\ntype LayoutRect = Readonly<Pick<DOMRectReadOnly, 'height' | 'width' | 'x' | 'y'>>;\ntype LayoutEntry = Readonly<{ element:
|
|
1
|
+
{"version":3,"file":"layout.js","names":[],"sources":["../src/layout.ts"],"sourcesContent":["import { uniqueElements } from './_elements';\nimport { animateEach } from './animate-each';\nimport { NecromancerConfigError } from './errors';\nimport type { LayoutAnimationOptions, LayoutCaptureOptions, LayoutTransition } from './types';\n\ntype LayoutRect = Readonly<Pick<DOMRectReadOnly, 'height' | 'width' | 'x' | 'y'>>;\ntype LayoutEntry<ElementType extends Element> = Readonly<{ element: ElementType; rect: LayoutRect }>;\ntype LayoutChange<ElementType extends Element> = Readonly<{\n element: ElementType;\n scaleX: number;\n scaleY: number;\n x: number;\n y: number;\n}>;\n\n// Rounds before templating into a keyframe string purely for DevTools readability — a `getBoundingClientRect()`\n// subtraction routinely produces values like `12.340000000000002`, which is noise once rendered as CSS.\n// Pixels only need whole-number precision; scale factors (close to 1) need finer precision to stay visually exact.\nfunction round(value: number, precision: number): number {\n const factor = 10 ** precision;\n\n return Math.round(value * factor) / factor;\n}\n\n// `getBoundingClientRect()`'s width/height is the rotated, axis-aligned bounding box — using it\n// for size would distort the scale ratio under any rotation. `offsetWidth`/`offsetHeight` report\n// the box's own untransformed layout size instead. Elements without an offset box (e.g. SVG)\n// fall back to the bounding rect, accepting that same distortion as the only option available.\nfunction measureSize(element: Element): Readonly<{ height: number; width: number }> {\n if ('offsetWidth' in element && 'offsetHeight' in element) {\n return { height: (element as HTMLElement).offsetHeight, width: (element as HTMLElement).offsetWidth };\n }\n\n const rect = element.getBoundingClientRect();\n\n return { height: rect.height, width: rect.width };\n}\n\nfunction measureLayout(element: Element): LayoutRect {\n const rect = element.getBoundingClientRect();\n const size = measureSize(element);\n\n return { height: size.height, width: size.width, x: rect.x, y: rect.y };\n}\n\n// `next` is 0 exactly when the element has collapsed (e.g. `display: none` mid-transition);\n// there's no meaningful ratio to compute then, so treat it as unscaled rather than producing Infinity/NaN.\nfunction computeScale(captured: number, next: number): number {\n return next === 0 ? 1 : captured / next;\n}\n\nfunction readKey<ElementType extends Element>(\n element: ElementType,\n getKey: (element: ElementType) => string,\n phase: string,\n): string {\n const key = getKey(element);\n\n if (typeof key !== 'string' || key.length === 0) {\n throw new NecromancerConfigError(`getKey must return a non-empty string for every ${phase} element.`);\n }\n\n return key;\n}\n\nfunction createKeyMap<ElementType extends Element>(\n entries: readonly LayoutEntry<ElementType>[],\n getKey: (element: ElementType) => string,\n phase: string,\n) {\n const keys = new Map<string, LayoutEntry<ElementType>>();\n\n for (const entry of entries) {\n const key = readKey(entry.element, getKey, phase);\n\n if (keys.has(key)) {\n throw new NecromancerConfigError(`getKey returned duplicate keys for the ${phase} elements.`);\n }\n\n keys.set(key, entry);\n }\n\n return keys;\n}\n\nfunction changedElement<ElementType extends Element>(\n element: ElementType,\n rect: LayoutRect,\n): LayoutChange<ElementType> | undefined {\n if (!element.isConnected) return undefined;\n\n const next = measureLayout(element);\n const x = rect.x - next.x;\n const y = rect.y - next.y;\n const scaleX = computeScale(rect.width, next.width);\n const scaleY = computeScale(rect.height, next.height);\n\n return x === 0 && y === 0 && scaleX === 1 && scaleY === 1 ? undefined : { element, scaleX, scaleY, x, y };\n}\n\nfunction matchByIdentity<ElementType extends Element>(\n entries: readonly LayoutEntry<ElementType>[],\n elements: readonly ElementType[],\n): LayoutChange<ElementType>[] {\n const captured = new Map(entries.map((entry) => [entry.element, entry]));\n\n return elements.flatMap((element) => {\n const entry = captured.get(element);\n\n return entry\n ? [changedElement(element, entry.rect)].filter((change): change is LayoutChange<ElementType> => Boolean(change))\n : [];\n });\n}\n\nfunction matchByKey<ElementType extends Element>(\n captured: ReadonlyMap<string, LayoutEntry<ElementType>>,\n elements: readonly ElementType[],\n getKey: (element: ElementType) => string,\n): LayoutChange<ElementType>[] {\n const committed = new Set<string>();\n\n return elements.flatMap((element) => {\n const key = readKey(element, getKey, 'committed');\n const entry = captured.get(key);\n\n if (committed.has(key)) {\n throw new NecromancerConfigError('getKey returned duplicate keys for the committed elements.');\n }\n\n committed.add(key);\n\n return entry\n ? [changedElement(element, entry.rect)].filter((change): change is LayoutChange<ElementType> => Boolean(change))\n : [];\n });\n}\n\n/**\n * Captures the current position and size of unique elements for a later FLIP animation.\n *\n * Each element's `x`/`y` position and `width`/`height` are captured. Rotation and other\n * transforms are not captured or compensated. Capture before mutating the DOM, then call\n * the returned transition's `animate()` method after the browser has applied the resulting\n * layout — position changes animate via translate, and size changes via scale, both\n * additively composed on top of any authored transform.\n */\nexport function captureLayout<ElementType extends Element>(\n elements: Iterable<ElementType>,\n options: LayoutCaptureOptions<ElementType> = {},\n): LayoutTransition<ElementType> {\n const entries: LayoutEntry<ElementType>[] = uniqueElements(elements).map((element) => ({\n element,\n rect: measureLayout(element),\n }));\n const getKey = options.getKey;\n const captured = getKey ? createKeyMap(entries, getKey, 'captured') : undefined;\n\n let consumed = false;\n\n return {\n animate(options: LayoutAnimationOptions<ElementType> = {}) {\n if (consumed) throw new NecromancerConfigError('This layout transition has already been animated.');\n\n const { elements: committedElements, ...animationOptions } = options;\n const elements = uniqueElements(committedElements ?? entries.map(({ element }) => element));\n const changed = getKey && captured ? matchByKey(captured, elements, getKey) : matchByIdentity(entries, elements);\n\n consumed = true;\n\n return animateEach(\n changed.map(({ element }) => element),\n (_, index) => {\n // `changed` was mapped directly into the elements array above, so this index is always in range.\n const change = changed[index]!;\n const translate = `${round(change.x, 2)}px ${round(change.y, 2)}px`;\n const scale = `${round(change.scaleX, 4)} ${round(change.scaleY, 4)}`;\n\n return [\n { composite: 'add', scale, translate },\n { composite: 'add', scale: '1 1', translate: '0px 0px' },\n ];\n },\n animationOptions,\n );\n },\n };\n}\n"],"mappings":"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"}
|
package/dist/necromancer.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});function e(e,t){let n=()=>t(e.reason);return e.addEventListener(`abort`,n,{once:!0}),e.aborted?(e.removeEventListener(`abort`,n),t(e.reason),()=>void 0):()=>e.removeEventListener(`abort`,n)}function t(e,t,n){return e.finished.then(()=>(t(),{status:n?`reduced`:`finished`}),e=>(t(),{reason:e,status:`cancelled`}))}function n(n,r,i=!1){let a=!1,o,s=!1,c,l=t(n,()=>{c?.(),c=void 0},i).then(e=>a&&s&&e.status===`cancelled`?{reason:o,status:`cancelled`}:e),u=e=>{a||(a=!0,o=e,s=e!==void 0,c?.(),c=void 0,n.cancel())};return r&&(c=e(r,u)),{animation:n,dispose:u,get disposed(){return a},result:l,[Symbol.dispose](){this.dispose()}}}function r(t,n){let r=!1,i,a=Promise.all(t.map(e=>e.result)).then(e=>(i?.(),i=void 0,e)),o=e=>{if(!r){r=!0,i?.(),i=void 0;for(let n of t)n.dispose(e)}};return n&&(i=e(n,o)),{dispose:o,get disposed(){return r},handles:t,results:a,[Symbol.dispose](){this.dispose()}}}var i=class extends Error{constructor(e,t){super(e,t),this.name=new.target.name,Object.setPrototypeOf(this,new.target.prototype)}},a=class extends i{},o=class extends i{};function s(e){return e===`full`?!1:e===`reduced`||typeof matchMedia==`function`&&matchMedia(`(prefers-reduced-motion: reduce)`).matches}function c(e={},t=!1){let{motion:n,signal:r,...i}=e;return t?{...i,delay:0,duration:0,endDelay:0,iterations:1}:i}function l(e,t){if(t===0)return e;let n=e.delay??0;if(typeof n!=`number`)throw new a(`A non-zero stagger requires a numeric delay; received ${typeof n}.`);return{...e,delay:n+t}}function u(e,t,r={}){if(r.signal?.aborted)throw r.signal.reason;if(typeof e.animate!=`function`)throw new o(`The Web Animations API is not available in this environment.`);let i=s(r.motion??`system`);return n(e.animate(t,c(r,i)),r.signal,i)}function d(e){return[...new Set(e)]}function f(e){if(!Number.isFinite(e)||e<0)throw new a(`stagger must be a finite, non-negative number.`)}function p(e,t,n={}){let{signal:i,stagger:a=0,...o}=n;if(f(a),i?.aborted)throw i.reason;let s=d(e),c=s.map((e,n)=>typeof t==`function`?t(e,n,s.length):t);if(i?.aborted)throw i.reason;let p=[];try{for(let[e,t]of s.entries()){let n=c[e];p.push(u(t,n,l(o,e*a)))}}catch(e){for(let t of p)t.dispose(e);throw e}return r(p,i)}function m(e,t){let n=10**t;return Math.round(e*n)/n}function h(e){if(`offsetWidth`in e&&`offsetHeight`in e)return{height:e.offsetHeight,width:e.offsetWidth};let t=e.getBoundingClientRect();return{height:t.height,width:t.width}}function g(e){let t=e.getBoundingClientRect(),n=h(e);return{height:n.height,width:n.width,x:t.x,y:t.y}}function _(e,t){return t===0?1:e/t}function v(e,t,n){let r=t(e);if(typeof r!=`string`||r.length===0)throw new a(`getKey must return a non-empty string for every ${n} element.`);return r}function y(e,t,n){let r=new Map;for(let i of e){let e=v(i.element,t,n);if(r.has(e))throw new a(`getKey returned duplicate keys for the ${n} elements.`);r.set(e,i)}return r}function b(e,t){if(!e.isConnected)return;let n=g(e),r=t.x-n.x,i=t.y-n.y,a=_(t.width,n.width),o=_(t.height,n.height);return r===0&&i===0&&a===1&&o===1?void 0:{element:e,scaleX:a,scaleY:o,x:r,y:i}}function x(e,t){let n=new Map(e.map(e=>[e.element,e]));return t.flatMap(e=>{let t=n.get(e);return t?[b(e,t.rect)].filter(e=>!!e):[]})}function S(e,t,n){let r=new Set;return t.flatMap(t=>{let i=v(t,n,`committed`),o=e.get(i);if(r.has(i))throw new a(`getKey returned duplicate keys for the committed elements.`);return r.add(i),o?[b(t,o.rect)].filter(e=>!!e):[]})}function C(e,t={}){let n=d(e).map(e=>({element:e,rect:g(e)})),r=t.getKey,i=r?y(n,r,`captured`):void 0,o=!1;return{animate(e={}){if(o)throw new a(`This layout transition has already been animated.`);let{elements:t,...s}=e,c=d(t??n.map(({element:e})=>e)),l=r&&i?S(i,c,r):x(n,c);return o=!0,p(l.map(({element:e})=>e),(e,t)=>{let n=l[t],r=`${m(n.x,2)}px ${m(n.y,2)}px`;return[{composite:`add`,scale:`${m(n.scaleX,4)} ${m(n.scaleY,4)}`,translate:r},{composite:`add`,scale:`1 1`,translate:`0px 0px`}]},s)}}}exports.NecromancerConfigError=a,exports.NecromancerError=i,exports.NecromancerUnsupportedError=o,exports.animate=u,exports.animateEach=p,exports.captureLayout=C;
|
|
2
2
|
//# sourceMappingURL=necromancer.cjs.map
|