@cognitap/radiant 0.0.5 → 0.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. package/CHANGELOG.md +17 -0
  2. package/README.md +8 -0
  3. package/dist/library/Button.d.ts +3 -1
  4. package/dist/library/Button.d.ts.map +1 -1
  5. package/dist/library/Button.js +43 -2
  6. package/dist/library/Button.js.map +1 -1
  7. package/dist/library/Collapsible.d.ts +2 -1
  8. package/dist/library/Collapsible.d.ts.map +1 -1
  9. package/dist/library/Collapsible.js +5 -2
  10. package/dist/library/Collapsible.js.map +1 -1
  11. package/dist/library/Dialog.d.ts +2 -1
  12. package/dist/library/Dialog.d.ts.map +1 -1
  13. package/dist/library/Dialog.js +5 -2
  14. package/dist/library/Dialog.js.map +1 -1
  15. package/dist/library/ThemeScope.d.ts.map +1 -1
  16. package/dist/library/ThemeScope.js +10 -9
  17. package/dist/library/ThemeScope.js.map +1 -1
  18. package/dist/library/index.d.ts +3 -1
  19. package/dist/library/index.d.ts.map +1 -1
  20. package/dist/library/index.js +1 -0
  21. package/dist/library/index.js.map +1 -1
  22. package/dist/library/motion/MotionLink.d.ts +7 -0
  23. package/dist/library/motion/MotionLink.d.ts.map +1 -0
  24. package/dist/library/motion/MotionLink.js +45 -0
  25. package/dist/library/motion/MotionLink.js.map +1 -0
  26. package/dist/library/motion/browser.d.ts +5 -0
  27. package/dist/library/motion/browser.d.ts.map +1 -0
  28. package/dist/library/motion/browser.js +35 -0
  29. package/dist/library/motion/browser.js.map +1 -0
  30. package/dist/library/motion/config.d.ts +26 -0
  31. package/dist/library/motion/config.d.ts.map +1 -0
  32. package/dist/library/motion/config.js +58 -0
  33. package/dist/library/motion/config.js.map +1 -0
  34. package/dist/library/motion/context.d.ts +2 -0
  35. package/dist/library/motion/context.d.ts.map +1 -0
  36. package/dist/library/motion/context.js +5 -0
  37. package/dist/library/motion/context.js.map +1 -0
  38. package/dist/library/motion/drag.d.ts +20 -0
  39. package/dist/library/motion/drag.d.ts.map +1 -0
  40. package/dist/library/motion/drag.js +138 -0
  41. package/dist/library/motion/drag.js.map +1 -0
  42. package/dist/library/motion/dragBrowser.d.ts +4 -0
  43. package/dist/library/motion/dragBrowser.d.ts.map +1 -0
  44. package/dist/library/motion/dragBrowser.js +156 -0
  45. package/dist/library/motion/dragBrowser.js.map +1 -0
  46. package/dist/library/motion/follow.d.ts +9 -0
  47. package/dist/library/motion/follow.d.ts.map +1 -0
  48. package/dist/library/motion/follow.js +26 -0
  49. package/dist/library/motion/follow.js.map +1 -0
  50. package/dist/library/motion/host.d.ts +27 -0
  51. package/dist/library/motion/host.d.ts.map +1 -0
  52. package/dist/library/motion/host.js +62 -0
  53. package/dist/library/motion/host.js.map +1 -0
  54. package/dist/library/motion/index.d.ts +16 -0
  55. package/dist/library/motion/index.d.ts.map +1 -0
  56. package/dist/library/motion/index.js +9 -0
  57. package/dist/library/motion/index.js.map +1 -0
  58. package/dist/library/motion/layout.d.ts +20 -0
  59. package/dist/library/motion/layout.d.ts.map +1 -0
  60. package/dist/library/motion/layout.js +67 -0
  61. package/dist/library/motion/layout.js.map +1 -0
  62. package/dist/library/motion/layoutDom.d.ts +17 -0
  63. package/dist/library/motion/layoutDom.d.ts.map +1 -0
  64. package/dist/library/motion/layoutDom.js +272 -0
  65. package/dist/library/motion/layoutDom.js.map +1 -0
  66. package/dist/library/motion/press.d.ts +5 -0
  67. package/dist/library/motion/press.d.ts.map +1 -0
  68. package/dist/library/motion/press.js +72 -0
  69. package/dist/library/motion/press.js.map +1 -0
  70. package/dist/library/motion/pressPolicy.d.ts +5 -0
  71. package/dist/library/motion/pressPolicy.d.ts.map +1 -0
  72. package/dist/library/motion/pressPolicy.js +8 -0
  73. package/dist/library/motion/pressPolicy.js.map +1 -0
  74. package/dist/library/motion/react.d.ts +35 -0
  75. package/dist/library/motion/react.d.ts.map +1 -0
  76. package/dist/library/motion/react.js +224 -0
  77. package/dist/library/motion/react.js.map +1 -0
  78. package/dist/library/motion/runtime.d.ts +22 -0
  79. package/dist/library/motion/runtime.d.ts.map +1 -0
  80. package/dist/library/motion/runtime.js +117 -0
  81. package/dist/library/motion/runtime.js.map +1 -0
  82. package/dist/library/motion/transitions.d.ts +5 -0
  83. package/dist/library/motion/transitions.d.ts.map +1 -0
  84. package/dist/library/motion/transitions.js +211 -0
  85. package/dist/library/motion/transitions.js.map +1 -0
  86. package/dist/library/styles.css +1 -1
  87. package/dist/library/themes/defineTheme.d.ts +3 -0
  88. package/dist/library/themes/defineTheme.d.ts.map +1 -1
  89. package/dist/library/themes/defineTheme.js +4 -2
  90. package/dist/library/themes/defineTheme.js.map +1 -1
  91. package/dist/library/themes/index.d.ts +1 -1
  92. package/dist/library/themes/index.d.ts.map +1 -1
  93. package/dist/library/themes/index.js.map +1 -1
  94. package/dist/library/themes/themeDocument.d.ts.map +1 -1
  95. package/dist/library/themes/themeDocument.js +11 -5
  96. package/dist/library/themes/themeDocument.js.map +1 -1
  97. package/dist/library/themes/themeDocumentTypes.d.ts +5 -1
  98. package/dist/library/themes/themeDocumentTypes.d.ts.map +1 -1
  99. package/dist/library/themes/themeDocumentTypes.js.map +1 -1
  100. package/docs/motion.md +434 -0
  101. package/docs/system.md +26 -0
  102. package/package.json +14 -3
  103. package/src/Button.tsx +49 -1
  104. package/src/Collapsible.tsx +13 -1
  105. package/src/Dialog.tsx +10 -1
  106. package/src/ThemeScope.tsx +21 -17
  107. package/src/index.ts +9 -0
  108. package/src/motion/MotionLink.tsx +64 -0
  109. package/src/motion/browser.ts +45 -0
  110. package/src/motion/config.ts +79 -0
  111. package/src/motion/context.ts +4 -0
  112. package/src/motion/drag.ts +151 -0
  113. package/src/motion/dragBrowser.ts +159 -0
  114. package/src/motion/follow.ts +28 -0
  115. package/src/motion/host.ts +88 -0
  116. package/src/motion/index.ts +28 -0
  117. package/src/motion/layout.ts +78 -0
  118. package/src/motion/layoutDom.ts +293 -0
  119. package/src/motion/press.ts +77 -0
  120. package/src/motion/pressPolicy.ts +12 -0
  121. package/src/motion/react.ts +272 -0
  122. package/src/motion/runtime.ts +122 -0
  123. package/src/motion/transitions.ts +206 -0
  124. package/src/themes/defineTheme.ts +10 -2
  125. package/src/themes/index.ts +1 -0
  126. package/src/themes/themeDocument.ts +14 -6
  127. package/src/themes/themeDocumentTypes.ts +12 -5
@@ -0,0 +1,45 @@
1
+ 'use client';
2
+ import { jsx as _jsx } from "react/jsx-runtime";
3
+ import { useContext } from 'react';
4
+ import { Link } from '../Link.js';
5
+ import { cn } from '../cn.js';
6
+ import { MotionHostContext } from './host.js';
7
+ import { usePressHost } from './host.js';
8
+ import { callerOwnsPress, springPressClass, offPressClass } from './pressPolicy.js';
9
+ /** Optional client adapter for action-shaped Link; ordinary Link stays server-renderable. */
10
+ export function MotionLink({ ref, motion = 'inherit', className, ...props }) {
11
+ const owns = callerOwnsPress(props.style, className);
12
+ const disabled = owns ||
13
+ motion === 'off' ||
14
+ props.variant === undefined ||
15
+ props.variant === 'inline' ||
16
+ props.variant === 'subtle';
17
+ const runtime = useContext(MotionHostContext);
18
+ const active = runtime !== null && !disabled;
19
+ const { ref: motionRef, press: startPress, release } = usePressHost(ref, disabled);
20
+ return (_jsx(Link, { ...props, ref: active ? motionRef : ref, className: cn(active && springPressClass, motion === 'off' && !owns && offPressClass, className), onPointerDown: event => {
21
+ props.onPointerDown?.(event);
22
+ if (!event.defaultPrevented)
23
+ startPress(event.nativeEvent);
24
+ }, onPointerUp: event => {
25
+ props.onPointerUp?.(event);
26
+ release();
27
+ }, onPointerCancel: event => {
28
+ props.onPointerCancel?.(event);
29
+ release();
30
+ }, onPointerLeave: event => {
31
+ props.onPointerLeave?.(event);
32
+ release();
33
+ }, onBlur: event => {
34
+ props.onBlur?.(event);
35
+ release();
36
+ }, onKeyDown: event => {
37
+ props.onKeyDown?.(event);
38
+ if (!event.defaultPrevented)
39
+ startPress(event.nativeEvent);
40
+ }, onKeyUp: event => {
41
+ props.onKeyUp?.(event);
42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AC7B,SAAS,EAAE,EAAE,CACX,MAAM,IAAI,gBAAgB,EAC1B,MAAM,KAAK,KAAK,IAAI,CAAC,IAAI,IAAI,aAAa,EAC1C,SAAS,CACV,EACD,aAAa,EAAE,KAAK,CAAC,EAAE;YACrB,KAAK,CAAC,aAAa,EAAE,CAAC,KAAK,CAAC,CAAA;YAC5B,IAAI,CAAC,KAAK,CAAC,gBAAgB;gBAAE,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAC5D,CAAC,EACD,WAAW,EAAE,KAAK,CAAC,EAAE;YACnB,KAAK,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAA;YAC1B,OAAO,EAAE,CAAA;QACX,CAAC,EACD,eAAe,EAAE,KAAK,CAAC,EAAE;YACvB,KAAK,CAAC,eAAe,EAAE,CAAC,KAAK,CAAC,CAAA;YAC9B,OAAO,EAAE,CAAA;QACX,CAAC,EACD,cAAc,EAAE,KAAK,CAAC,EAAE;YACtB,KAAK,CAAC,cAAc,EAAE,CAAC,KAAK,CAAC,CAAA;YAC7B,OAAO,EAAE,CAAA;QACX,CAAC,EACD,MAAM,EAAE,KAAK,CAAC,EAAE;YACd,KAAK,CAAC,MAAM,EAAE,CAAC,KAAK,CAAC,CAAA;YACrB,OAAO,EAAE,CAAA;QACX,CAAC,EACD,SAAS,EAAE,KAAK,CAAC,EAAE;YACjB,KAAK,CAAC,SAAS,EAAE,CAAC,KAAK,CAAC,CAAA;YACxB,IAAI,CAAC,KAAK,CAAC,gBAAgB;gBAAE,UAAU,CAAC,KAAK,CAAC,WAAW,CAAC,CAAA;QAC5D,CAAC,EACD,OAAO,EAAE,KAAK,CAAC,EAAE;YACf,KAAK,CAAC,OAAO,EAAE,CAAC,KAAK,CAAC,CAAA;YACtB,OAAO,EAAE,CAAA;QACX,CAAC,GACD,CACH,CAAA;AACH,CAAC","sourcesContent":["'use client'\nimport { useContext } from 'react'\nimport { Link, type LinkProps } from '../Link.js'\nimport { cn } from '../cn.js'\nimport { MotionHostContext } from './host.js'\nimport { usePressHost } from './host.js'\nimport { callerOwnsPress, springPressClass, offPressClass } from './pressPolicy.js'\nexport type MotionLinkProps = LinkProps & { motion?: 'inherit' | 'off' }\n/** Optional client adapter for action-shaped Link; ordinary Link stays server-renderable. */\nexport function MotionLink({ ref, motion = 'inherit', className, ...props }: MotionLinkProps) {\n const owns = callerOwnsPress(props.style, className)\n const disabled =\n owns ||\n motion === 'off' ||\n props.variant === undefined ||\n props.variant === 'inline' ||\n props.variant === 'subtle'\n const runtime = useContext(MotionHostContext)\n const active = runtime !== null && !disabled\n const {\n ref: motionRef,\n press: startPress,\n release\n } = usePressHost<HTMLAnchorElement>(ref, disabled)\n return (\n <Link\n {...props}\n ref={active ? motionRef : ref}\n className={cn(\n active && springPressClass,\n motion === 'off' && !owns && offPressClass,\n className\n )}\n onPointerDown={event => {\n props.onPointerDown?.(event)\n if (!event.defaultPrevented) startPress(event.nativeEvent)\n }}\n onPointerUp={event => {\n props.onPointerUp?.(event)\n release()\n }}\n onPointerCancel={event => {\n props.onPointerCancel?.(event)\n release()\n }}\n onPointerLeave={event => {\n props.onPointerLeave?.(event)\n release()\n }}\n onBlur={event => {\n props.onBlur?.(event)\n release()\n }}\n onKeyDown={event => {\n props.onKeyDown?.(event)\n if (!event.defaultPrevented) startPress(event.nativeEvent)\n }}\n onKeyUp={event => {\n props.onKeyUp?.(event)\n release()\n }}\n />\n )\n}\n"]}
@@ -0,0 +1,5 @@
1
+ import type { SpringController } from './runtime.js';
2
+ export type SpringStyleProperty = 'scale' | 'opacity' | 'width' | 'height' | 'translateX' | 'translateY';
3
+ /** Bind one explicitly reserved individual property; never overwrite transform or events. */
4
+ export declare function bindSpringStyle(node: HTMLElement, spring: SpringController, property: SpringStyleProperty): () => void;
5
+ //# sourceMappingURL=browser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.d.ts","sourceRoot":"","sources":["../../../src/motion/browser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,MAAM,MAAM,mBAAmB,GAC3B,OAAO,GACP,SAAS,GACT,OAAO,GACP,QAAQ,GACR,YAAY,GACZ,YAAY,CAAA;AAChB,6FAA6F;AAC7F,wBAAgB,eAAe,CAC7B,IAAI,EAAE,WAAW,EACjB,MAAM,EAAE,gBAAgB,EACxB,QAAQ,EAAE,mBAAmB,GAC5B,MAAM,IAAI,CA8BZ"}
@@ -0,0 +1,35 @@
1
+ /** Bind one explicitly reserved individual property; never overwrite transform or events. */
2
+ export function bindSpringStyle(node, spring, property) {
3
+ if (!['scale', 'opacity', 'width', 'height', 'translateX', 'translateY'].includes(property))
4
+ throw new TypeError('Unsupported spring style property.');
5
+ const key = property === 'translateX' || property === 'translateY' ? 'translate' : property;
6
+ const previous = node.style.getPropertyValue(key);
7
+ const priority = node.style.getPropertyPriority(key);
8
+ let owned = previous;
9
+ const apply = (next) => {
10
+ const formatted = property === 'width' || property === 'height'
11
+ ? `${Math.max(0, next)}px`
12
+ : property === 'translateX'
13
+ ? `${next}px 0px`
14
+ : property === 'translateY'
15
+ ? `0px ${next}px`
16
+ : property === 'opacity'
17
+ ? String(Math.max(0, Math.min(1, next)))
18
+ : String(Math.max(0, next));
19
+ node.style.setProperty(key, formatted);
20
+ owned = node.style.getPropertyValue(key);
21
+ };
22
+ apply(spring.get());
23
+ const off = spring.subscribe(apply);
24
+ return () => {
25
+ off();
26
+ // A caller may have reclaimed the property since the last spring frame.
27
+ if (node.style.getPropertyValue(key) !== owned)
28
+ return;
29
+ if (previous)
30
+ node.style.setProperty(key, previous, priority);
31
+ else
32
+ node.style.removeProperty(key);
33
+ };
34
+ }
35
+ //# sourceMappingURL=browser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"browser.js","sourceRoot":"","sources":["../../../src/motion/browser.ts"],"names":[],"mappings":"AASA,6FAA6F;AAC7F,MAAM,UAAU,eAAe,CAC7B,IAAiB,EACjB,MAAwB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,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAA;IAC1C,CAAC,CAAA;IACD,KAAK,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC,CAAA;IACnB,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,KAAK,CAAC,CAAA;IACnC,OAAO,GAAG,EAAE;QACV,GAAG,EAAE,CAAA;QACL,wEAAwE;QACxE,IAAI,IAAI,CAAC,KAAK,CAAC,gBAAgB,CAAC,GAAG,CAAC,KAAK,KAAK;YAAE,OAAM;QACtD,IAAI,QAAQ;YAAE,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,EAAE,QAAQ,EAAE,QAAQ,CAAC,CAAA;;YACxD,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAA;IACrC,CAAC,CAAA;AACH,CAAC","sourcesContent":["import type { SpringController } from './runtime.js'\n\nexport type SpringStyleProperty =\n | 'scale'\n | 'opacity'\n | 'width'\n | 'height'\n | 'translateX'\n | 'translateY'\n/** Bind one explicitly reserved individual property; never overwrite transform or events. */\nexport function bindSpringStyle(\n node: HTMLElement,\n spring: SpringController,\n property: SpringStyleProperty\n): () => void {\n if (!['scale', 'opacity', 'width', 'height', 'translateX', 'translateY'].includes(property))\n throw new TypeError('Unsupported spring style property.')\n const key = property === 'translateX' || property === 'translateY' ? 'translate' : property\n const previous = node.style.getPropertyValue(key)\n const priority = node.style.getPropertyPriority(key)\n let owned = previous\n const apply = (next: number) => {\n const formatted =\n property === 'width' || property === 'height'\n ? `${Math.max(0, next)}px`\n : property === 'translateX'\n ? `${next}px 0px`\n : property === 'translateY'\n ? `0px ${next}px`\n : property === 'opacity'\n ? String(Math.max(0, Math.min(1, next)))\n : String(Math.max(0, next))\n node.style.setProperty(key, formatted)\n owned = node.style.getPropertyValue(key)\n }\n apply(spring.get())\n const off = spring.subscribe(apply)\n return () => {\n off()\n // A caller may have reclaimed the property since the last spring frame.\n if (node.style.getPropertyValue(key) !== owned) return\n if (previous) node.style.setProperty(key, previous, priority)\n else node.style.removeProperty(key)\n }\n}\n"]}
@@ -0,0 +1,26 @@
1
+ export interface SpringParameters {
2
+ readonly stiffness: number;
3
+ readonly damping: number;
4
+ readonly mass: number;
5
+ }
6
+ export declare const motionInteractions: readonly ["press", "disclosure", "dialog", "follow", "drag", "layout"];
7
+ export type MotionInteraction = (typeof motionInteractions)[number];
8
+ export interface MotionProfileInput {
9
+ readonly mode?: 'system' | 'off';
10
+ readonly spring?: Partial<SpringParameters>;
11
+ readonly interactions?: Partial<Record<MotionInteraction, Partial<SpringParameters>>>;
12
+ }
13
+ export interface MotionProfile {
14
+ readonly mode: 'system' | 'off';
15
+ readonly spring: SpringParameters;
16
+ readonly interactions: Readonly<Record<MotionInteraction, SpringParameters>>;
17
+ }
18
+ export declare function resolveSpringParameters(input?: Partial<SpringParameters>, base?: SpringParameters): SpringParameters;
19
+ /** Plain immutable theme data; importing configuration never loads an animation engine. */
20
+ export declare function defineMotionProfile(input?: MotionProfileInput): MotionProfile;
21
+ export declare const defaultMotionProfile: MotionProfile;
22
+ export declare function resolveMotion(profile: MotionProfile, interaction: MotionInteraction, reducedMotion: boolean): {
23
+ enabled: boolean;
24
+ parameters: SpringParameters;
25
+ };
26
+ //# sourceMappingURL=config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.d.ts","sourceRoot":"","sources":["../../../src/motion/config.ts"],"names":[],"mappings":"AAAA,MAAM,WAAW,gBAAgB;IAC/B,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAA;CACtB;AACD,eAAO,MAAM,kBAAkB,wEAOrB,CAAA;AACV,MAAM,MAAM,iBAAiB,GAAG,CAAC,OAAO,kBAAkB,CAAC,CAAC,MAAM,CAAC,CAAA;AACnE,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,IAAI,CAAC,EAAE,QAAQ,GAAG,KAAK,CAAA;IAChC,QAAQ,CAAC,MAAM,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;IAC3C,QAAQ,CAAC,YAAY,CAAC,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAC,CAAC,CAAA;CACtF;AACD,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,QAAQ,GAAG,KAAK,CAAA;IAC/B,QAAQ,CAAC,MAAM,EAAE,gBAAgB,CAAA;IACjC,QAAQ,CAAC,YAAY,EAAE,QAAQ,CAAC,MAAM,CAAC,iBAAiB,EAAE,gBAAgB,CAAC,CAAC,CAAA;CAC7E;AAQD,wBAAgB,uBAAuB,CACrC,KAAK,GAAE,OAAO,CAAC,gBAAgB,CAAM,EACrC,IAAI,GAAE,gBAA2B,GAChC,gBAAgB,CAYlB;AACD,2FAA2F;AAC3F,wBAAgB,mBAAmB,CAAC,KAAK,GAAE,kBAAuB,GAAG,aAAa,CAkBjF;AACD,eAAO,MAAM,oBAAoB,eAAwB,CAAA;AACzD,wBAAgB,aAAa,CAC3B,OAAO,EAAE,aAAa,EACtB,WAAW,EAAE,iBAAiB,EAC9B,aAAa,EAAE,OAAO;;;EAOvB"}
@@ -0,0 +1,58 @@
1
+ export const motionInteractions = [
2
+ 'press',
3
+ 'disclosure',
4
+ 'dialog',
5
+ 'follow',
6
+ 'drag',
7
+ 'layout'
8
+ ];
9
+ const baseline = Object.freeze({ stiffness: 320, damping: 30, mass: 1 });
10
+ function record(value, allowed, path) {
11
+ if (!value || typeof value !== 'object' || Array.isArray(value))
12
+ throw new TypeError(`${path} must be an object.`);
13
+ for (const key of Object.keys(value))
14
+ if (!allowed.includes(key))
15
+ throw new TypeError(`Unknown key: ${path}.${key}.`);
16
+ }
17
+ export function resolveSpringParameters(input = {}, base = baseline) {
18
+ record(input, ['stiffness', 'damping', 'mass'], 'spring');
19
+ const result = { ...base };
20
+ for (const key of ['stiffness', 'damping', 'mass']) {
21
+ const value = input[key];
22
+ if (value === undefined)
23
+ continue;
24
+ const max = key === 'mass' ? 100 : 10000;
25
+ if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > max)
26
+ throw new TypeError(`spring.${key} must be greater than zero and at most ${max}.`);
27
+ result[key] = value;
28
+ }
29
+ return Object.freeze(result);
30
+ }
31
+ /** Plain immutable theme data; importing configuration never loads an animation engine. */
32
+ export function defineMotionProfile(input = {}) {
33
+ record(input, ['mode', 'spring', 'interactions'], 'motion');
34
+ if (input.mode !== undefined && input.mode !== 'system' && input.mode !== 'off')
35
+ throw new TypeError('motion.mode must be system or off.');
36
+ const spring = resolveSpringParameters(input.spring);
37
+ if (input.interactions !== undefined)
38
+ record(input.interactions, motionInteractions, 'motion.interactions');
39
+ const interactions = Object.fromEntries(motionInteractions.map(name => [
40
+ name,
41
+ resolveSpringParameters(input.interactions?.[name], spring)
42
+ ]));
43
+ return Object.freeze({
44
+ mode: input.mode ?? 'system',
45
+ spring,
46
+ interactions: Object.freeze(interactions)
47
+ });
48
+ }
49
+ export const defaultMotionProfile = defineMotionProfile();
50
+ export function resolveMotion(profile, interaction, reducedMotion) {
51
+ if (!motionInteractions.includes(interaction))
52
+ throw new TypeError('Unknown motion interaction.');
53
+ return {
54
+ enabled: profile.mode !== 'off' && !reducedMotion,
55
+ parameters: profile.interactions[interaction]
56
+ };
57
+ }
58
+ //# sourceMappingURL=config.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"config.js","sourceRoot":"","sources":["../../../src/motion/config.ts"],"names":[],"mappings":"AAKA,MAAM,CAAC,MAAM,kBAAkB,GAAG;IAChC,OAAO;IACP,YAAY;IACZ,QAAQ;IACR,QAAQ;IACR,MAAM;IACN,QAAQ;CACA,CAAA;AAYV,MAAM,QAAQ,GAAqB,MAAM,CAAC,MAAM,CAAC,EAAE,SAAS,EAAE,GAAG,EAAE,OAAO,EAAE,EAAE,EAAE,I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AAO,EAAE,OAAO,CAAC,IAAI,KAAK,KAAK,IAAI,CAAC,aAAa;QACjD,UAAU,EAAE,OAAO,CAAC,YAAY,CAAC,WAAW,CAAC;KAC9C,CAAA;AACH,CAAC","sourcesContent":["export interface SpringParameters {\n readonly stiffness: number\n readonly damping: number\n readonly mass: number\n}\nexport const motionInteractions = [\n 'press',\n 'disclosure',\n 'dialog',\n 'follow',\n 'drag',\n 'layout'\n] as const\nexport type MotionInteraction = (typeof motionInteractions)[number]\nexport interface MotionProfileInput {\n readonly mode?: 'system' | 'off'\n readonly spring?: Partial<SpringParameters>\n readonly interactions?: Partial<Record<MotionInteraction, Partial<SpringParameters>>>\n}\nexport interface MotionProfile {\n readonly mode: 'system' | 'off'\n readonly spring: SpringParameters\n readonly interactions: Readonly<Record<MotionInteraction, SpringParameters>>\n}\nconst baseline: SpringParameters = Object.freeze({ stiffness: 320, damping: 30, mass: 1 })\nfunction record(value: unknown, allowed: readonly string[], path: string): void {\n if (!value || typeof value !== 'object' || Array.isArray(value))\n throw new TypeError(`${path} must be an object.`)\n for (const key of Object.keys(value))\n if (!allowed.includes(key)) throw new TypeError(`Unknown key: ${path}.${key}.`)\n}\nexport function resolveSpringParameters(\n input: Partial<SpringParameters> = {},\n base: SpringParameters = baseline\n): SpringParameters {\n record(input, ['stiffness', 'damping', 'mass'], 'spring')\n const result = { ...base }\n for (const key of ['stiffness', 'damping', 'mass'] as const) {\n const value = input[key]\n if (value === undefined) continue\n const max = key === 'mass' ? 100 : 10000\n if (typeof value !== 'number' || !Number.isFinite(value) || value <= 0 || value > max)\n throw new TypeError(`spring.${key} must be greater than zero and at most ${max}.`)\n result[key] = value\n }\n return Object.freeze(result)\n}\n/** Plain immutable theme data; importing configuration never loads an animation engine. */\nexport function defineMotionProfile(input: MotionProfileInput = {}): MotionProfile {\n record(input, ['mode', 'spring', 'interactions'], 'motion')\n if (input.mode !== undefined && input.mode !== 'system' && input.mode !== 'off')\n throw new TypeError('motion.mode must be system or off.')\n const spring = resolveSpringParameters(input.spring)\n if (input.interactions !== undefined)\n record(input.interactions, motionInteractions, 'motion.interactions')\n const interactions = Object.fromEntries(\n motionInteractions.map(name => [\n name,\n resolveSpringParameters(input.interactions?.[name], spring)\n ])\n ) as Record<MotionInteraction, SpringParameters>\n return Object.freeze({\n mode: input.mode ?? 'system',\n spring,\n interactions: Object.freeze(interactions)\n })\n}\nexport const defaultMotionProfile = defineMotionProfile()\nexport function resolveMotion(\n profile: MotionProfile,\n interaction: MotionInteraction,\n reducedMotion: boolean\n) {\n if (!motionInteractions.includes(interaction)) throw new TypeError('Unknown motion interaction.')\n return {\n enabled: profile.mode !== 'off' && !reducedMotion,\n parameters: profile.interactions[interaction]\n }\n}\n"]}
@@ -0,0 +1,2 @@
1
+ export declare const MotionProfileContext: import("react").Context<import("./config.js").MotionProfile>;
2
+ //# sourceMappingURL=context.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.d.ts","sourceRoot":"","sources":["../../../src/motion/context.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,oBAAoB,8DAAsC,CAAA"}
@@ -0,0 +1,5 @@
1
+ 'use client';
2
+ import { createContext } from 'react';
3
+ import { defaultMotionProfile } from './config.js';
4
+ export const MotionProfileContext = createContext(defaultMotionProfile);
5
+ //# sourceMappingURL=context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"context.js","sourceRoot":"","sources":["../../../src/motion/context.ts"],"names":[],"mappings":"AAAA,YAAY,CAAA;AACZ,OAAO,EAAE,aAAa,EAAE,MAAM,OAAO,CAAA;AACrC,OAAO,EAAE,oBAAoB,EAAE,MAAM,aAAa,CAAA;AAClD,MAAM,CAAC,MAAM,oBAAoB,GAAG,aAAa,CAAC,oBAAoB,CAAC,CAAA","sourcesContent":["'use client'\nimport { createContext } from 'react'\nimport { defaultMotionProfile } from './config.js'\nexport const MotionProfileContext = createContext(defaultMotionProfile)\n"]}
@@ -0,0 +1,20 @@
1
+ import { type SpringController, type SpringOptions } from './runtime.js';
2
+ export interface SpringDragOptions extends SpringOptions {
3
+ readonly min: number;
4
+ readonly max: number;
5
+ readonly snapPoints?: readonly number[];
6
+ }
7
+ export interface SpringDragController extends SpringController {
8
+ begin(): void;
9
+ move(position: number, time: number): void;
10
+ release(time: number): {
11
+ target: number;
12
+ velocity: number;
13
+ };
14
+ cancel(): void;
15
+ step(direction: -1 | 1 | 'first' | 'last'): void;
16
+ configure(options: Partial<SpringDragOptions>): void;
17
+ }
18
+ /** One axis, local pixels; Motion supplies all spring physics. */
19
+ export declare function createSpringDrag(initial: number, input: SpringDragOptions): SpringDragController;
20
+ //# sourceMappingURL=drag.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag.d.ts","sourceRoot":"","sources":["../../../src/motion/drag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAgB,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,MAAM,cAAc,CAAA;AACtF,MAAM,WAAW,iBAAkB,SAAQ,aAAa;IACtD,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAA;IACpB,QAAQ,CAAC,UAAU,CAAC,EAAE,SAAS,MAAM,EAAE,CAAA;CACxC;AACD,MAAM,WAAW,oBAAqB,SAAQ,gBAAgB;IAC5D,KAAK,IAAI,IAAI,CAAA;IACb,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI,CAAA;IAC1C,OAAO,CAAC,IAAI,EAAE,MAAM,GAAG;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;IAC3D,MAAM,IAAI,IAAI,CAAA;IACd,IAAI,CAAC,SAAS,EAAE,CAAC,CAAC,GAAG,CAAC,GAAG,OAAO,GAAG,MAAM,GAAG,IAAI,CAAA;IAChD,SAAS,CAAC,OAAO,EAAE,OAAO,CAAC,iBAAiB,CAAC,GAAG,IAAI,CAAA;CACrD;AAeD,kEAAkE;AAClE,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,EAAE,iBAAiB,GAAG,oBAAoB,CAyHhG"}
@@ -0,0 +1,138 @@
1
+ import { createSpring } from './runtime.js';
2
+ function validated(input) {
3
+ if (!Number.isFinite(input.min) || !Number.isFinite(input.max) || input.min >= input.max)
4
+ throw new TypeError('Drag bounds must be finite and min < max.');
5
+ if (input.reducedValue !== undefined)
6
+ throw new TypeError('Drag off snaps to its functional goal, not a decorative reducedValue.');
7
+ const points = input.snapPoints ?? [input.min, input.max];
8
+ if (!Array.isArray(points) ||
9
+ !points.length ||
10
+ points.some(value => !Number.isFinite(value) || value < input.min || value > input.max))
11
+ throw new TypeError('Snap points must be a nonempty array within bounds.');
12
+ return { ...input, snapPoints: [...new Set(points)].sort((a, b) => a - b) };
13
+ }
14
+ /** One axis, local pixels; Motion supplies all spring physics. */
15
+ export function createSpringDrag(initial, input) {
16
+ let options = validated(input);
17
+ const clamp = (value) => Math.max(options.min, Math.min(options.max, value));
18
+ if (!Number.isFinite(initial) || initial < options.min || initial > options.max)
19
+ throw new TypeError('Initial drag position must be within bounds.');
20
+ const spring = createSpring(initial, options);
21
+ let goal = initial, cancelGoal = initial, dragging = false, velocity = 0, lastTime, lastPosition = initial, destroyed = false;
22
+ const choose = (position) => options.snapPoints.reduce((best, point) => (Math.abs(point - position) < Math.abs(best - position) ? point : best), options.snapPoints[0]);
23
+ const to = (target, speed) => {
24
+ if (!Number.isFinite(target))
25
+ throw new TypeError('Drag target must be finite.');
26
+ if (destroyed)
27
+ return;
28
+ goal = clamp(target);
29
+ spring.to(goal, speed);
30
+ };
31
+ const controller = {
32
+ get: () => clamp(spring.get()),
33
+ getVelocity: () => spring.get() < options.min || spring.get() > options.max ? 0 : spring.getVelocity(),
34
+ isAnimating: () => spring.isAnimating(),
35
+ to,
36
+ jump(target) {
37
+ if (!Number.isFinite(target))
38
+ throw new TypeError('Drag target must be finite.');
39
+ if (destroyed)
40
+ return;
41
+ goal = clamp(target);
42
+ spring.jump(goal);
43
+ },
44
+ stop() {
45
+ if (destroyed)
46
+ return;
47
+ spring.stop();
48
+ goal = controller.get();
49
+ },
50
+ subscribe(listener) {
51
+ return spring.subscribe(() => listener(controller.get()));
52
+ },
53
+ configure(next) {
54
+ if (destroyed)
55
+ return;
56
+ const resolved = validated({ ...options, ...next });
57
+ spring.configure(resolved);
58
+ options = resolved;
59
+ goal = clamp(goal);
60
+ cancelGoal = clamp(cancelGoal);
61
+ if (dragging)
62
+ spring.jump(controller.get());
63
+ else
64
+ spring.to(goal);
65
+ },
66
+ begin() {
67
+ if (destroyed)
68
+ return;
69
+ cancelGoal = goal;
70
+ dragging = true;
71
+ lastTime = undefined;
72
+ velocity = 0;
73
+ lastPosition = controller.get();
74
+ spring.jump(lastPosition);
75
+ },
76
+ move(position, time) {
77
+ if (!Number.isFinite(position) || !Number.isFinite(time))
78
+ throw new TypeError('Drag samples need finite pixel positions and millisecond times.');
79
+ if (!dragging || destroyed)
80
+ return;
81
+ const current = clamp(position);
82
+ if (lastTime !== undefined) {
83
+ const dt = time - lastTime;
84
+ velocity =
85
+ dt > 0 && dt <= 80
86
+ ? Math.max(-3000, Math.min(3000, ((current - lastPosition) * 1000) / dt))
87
+ : 0;
88
+ }
89
+ lastTime = time;
90
+ lastPosition = current;
91
+ spring.jump(current);
92
+ },
93
+ release(time) {
94
+ if (!Number.isFinite(time))
95
+ throw new TypeError('Release time must be finite.');
96
+ if (!dragging || destroyed)
97
+ return { target: goal, velocity: 0 };
98
+ dragging = false;
99
+ const speed = options.enabled === false ||
100
+ lastTime === undefined ||
101
+ time - lastTime > 80 ||
102
+ time < lastTime
103
+ ? 0
104
+ : velocity;
105
+ const target = choose(clamp(controller.get() + speed * 0.18));
106
+ to(target, speed);
107
+ return { target, velocity: speed };
108
+ },
109
+ cancel() {
110
+ if (!dragging || destroyed)
111
+ return;
112
+ dragging = false;
113
+ to(cancelGoal, 0);
114
+ },
115
+ step(direction) {
116
+ if (destroyed)
117
+ return;
118
+ dragging = false;
119
+ const current = goal;
120
+ const points = options.snapPoints;
121
+ const target = direction === 'first'
122
+ ? points[0]
123
+ : direction === 'last'
124
+ ? points.at(-1)
125
+ : direction === 1
126
+ ? (points.find(point => point > current + 0.01) ?? points.at(-1))
127
+ : ([...points].reverse().find(point => point < current - 0.01) ?? points[0]);
128
+ to(target);
129
+ },
130
+ destroy() {
131
+ destroyed = true;
132
+ dragging = false;
133
+ spring.destroy();
134
+ }
135
+ };
136
+ return controller;
137
+ }
138
+ //# sourceMappingURL=drag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"drag.js","sourceRoot":"","sources":["../../../src/motion/drag.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAA6C,MAAM,cAAc,CAAA;AActF,SAAS,SAAS,CAAC,KAAwB;IACzC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,KAAK,CAAC,GAAG,IAAI,KAAK,CAAC,GAAG;QACtF,MAAM,IAAI,SAAS,CAAC,2CAA2C,CAAC,CAAA;IAClE,IAAI,KAAK,CAAC,YAAY,KAAK,SAAS;QAClC,MAAM,IAAI,SAAS,CAAC,uEAAuE,CAAC,CAAA;IAC9F,MAAM,MAAM,GAAG,KAAK,CAAC,UAAU,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,KAAK,CAAC,GAAG,CAAC,CAAA;IACzD,IACE,CAAC,KAAK,CAAC,OAAO,CAAC,MAAM,CAAC;QACtB,CAAC,MAAM,CAAC,MAAM;QACd,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC,MAAM,CAAC,QAAQ,CAAC,KAAK,CAAC,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,IAAI,KAAK,GAAG,KAAK,CAAC,GAAG,CAAC;Q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B,EAAE,CAAC,UAAU,EAAE,CAAC,CAAC,CAAA;QACnB,CAAC;QACD,IAAI,CAAC,SAAS;YACZ,IAAI,SAAS;gBAAE,OAAM;YACrB,QAAQ,GAAG,KAAK,CAAA;YAChB,MAAM,OAAO,GAAG,IAAI,CAAA;YACpB,MAAM,MAAM,GAAG,OAAO,CAAC,UAAU,CAAA;YACjC,MAAM,MAAM,GACV,SAAS,KAAK,OAAO;gBACnB,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC;gBACX,CAAC,CAAC,SAAS,KAAK,MAAM;oBACpB,CAAC,CAAC,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE;oBAChB,CAAC,CAAC,SAAS,KAAK,CAAC;wBACf,CAAC,CAAC,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC,IAAI,MAAM,CAAC,EAAE,CAAC,CAAC,CAAC,CAAE,CAAC;wBAClE,CAAC,CAAC,CAAC,CAAC,GAAG,MAAM,CAAC,CAAC,OAAO,EAAE,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,GAAG,OAAO,GAAG,IAAI,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC,CAAA;YACpF,EAAE,CAAC,MAAM,CAAC,CAAA;QACZ,CAAC;QACD,OAAO;YACL,SAAS,GAAG,IAAI,CAAA;YAChB,QAAQ,GAAG,KAAK,CAAA;YAChB,MAAM,CAAC,OAAO,EAAE,CAAA;QAClB,CAAC;KACF,CAAA;IACD,OAAO,UAAU,CAAA;AACnB,CAAC","sourcesContent":["import { createSpring, type SpringController, type SpringOptions } from './runtime.js'\nexport interface SpringDragOptions extends SpringOptions {\n readonly min: number\n readonly max: number\n readonly snapPoints?: readonly number[]\n}\nexport interface SpringDragController extends SpringController {\n begin(): void\n move(position: number, time: number): void\n release(time: number): { target: number; velocity: number }\n cancel(): void\n step(direction: -1 | 1 | 'first' | 'last'): void\n configure(options: Partial<SpringDragOptions>): void\n}\nfunction validated(input: SpringDragOptions) {\n if (!Number.isFinite(input.min) || !Number.isFinite(input.max) || input.min >= input.max)\n throw new TypeError('Drag bounds must be finite and min < max.')\n if (input.reducedValue !== undefined)\n throw new TypeError('Drag off snaps to its functional goal, not a decorative reducedValue.')\n const points = input.snapPoints ?? [input.min, input.max]\n if (\n !Array.isArray(points) ||\n !points.length ||\n points.some(value => !Number.isFinite(value) || value < input.min || value > input.max)\n )\n throw new TypeError('Snap points must be a nonempty array within bounds.')\n return { ...input, snapPoints: [...new Set(points)].sort((a, b) => a - b) }\n}\n/** One axis, local pixels; Motion supplies all spring physics. */\nexport function createSpringDrag(initial: number, input: SpringDragOptions): SpringDragController {\n let options = validated(input)\n const clamp = (value: number) => Math.max(options.min, Math.min(options.max, value))\n if (!Number.isFinite(initial) || initial < options.min || initial > options.max)\n throw new TypeError('Initial drag position must be within bounds.')\n const spring = createSpring(initial, options)\n let goal = initial,\n cancelGoal = initial,\n dragging = false,\n velocity = 0,\n lastTime: number | undefined,\n lastPosition = initial,\n destroyed = false\n const choose = (position: number) =>\n options.snapPoints.reduce(\n (best, point) => (Math.abs(point - position) < Math.abs(best - position) ? point : best),\n options.snapPoints[0]\n )\n const to = (target: number, speed?: number) => {\n if (!Number.isFinite(target)) throw new TypeError('Drag target must be finite.')\n if (destroyed) return\n goal = clamp(target)\n spring.to(goal, speed)\n }\n const controller: SpringDragController = {\n get: () => clamp(spring.get()),\n getVelocity: () =>\n spring.get() < options.min || spring.get() > options.max ? 0 : spring.getVelocity(),\n isAnimating: () => spring.isAnimating(),\n to,\n jump(target) {\n if (!Number.isFinite(target)) throw new TypeError('Drag target must be finite.')\n if (destroyed) return\n goal = clamp(target)\n spring.jump(goal)\n },\n stop() {\n if (destroyed) return\n spring.stop()\n goal = controller.get()\n },\n subscribe(listener) {\n return spring.subscribe(() => listener(controller.get()))\n },\n configure(next) {\n if (destroyed) return\n const resolved = validated({ ...options, ...next })\n spring.configure(resolved)\n options = resolved\n goal = clamp(goal)\n cancelGoal = clamp(cancelGoal)\n if (dragging) spring.jump(controller.get())\n else spring.to(goal)\n },\n begin() {\n if (destroyed) return\n cancelGoal = goal\n dragging = true\n lastTime = undefined\n velocity = 0\n lastPosition = controller.get()\n spring.jump(lastPosition)\n },\n move(position, time) {\n if (!Number.isFinite(position) || !Number.isFinite(time))\n throw new TypeError('Drag samples need finite pixel positions and millisecond times.')\n if (!dragging || destroyed) return\n const current = clamp(position)\n if (lastTime !== undefined) {\n const dt = time - lastTime\n velocity =\n dt > 0 && dt <= 80\n ? Math.max(-3000, Math.min(3000, ((current - lastPosition) * 1000) / dt))\n : 0\n }\n lastTime = time\n lastPosition = current\n spring.jump(current)\n },\n release(time) {\n if (!Number.isFinite(time)) throw new TypeError('Release time must be finite.')\n if (!dragging || destroyed) return { target: goal, velocity: 0 }\n dragging = false\n const speed =\n options.enabled === false ||\n lastTime === undefined ||\n time - lastTime > 80 ||\n time < lastTime\n ? 0\n : velocity\n const target = choose(clamp(controller.get() + speed * 0.18))\n to(target, speed)\n return { target, velocity: speed }\n },\n cancel() {\n if (!dragging || destroyed) return\n dragging = false\n to(cancelGoal, 0)\n },\n step(direction) {\n if (destroyed) return\n dragging = false\n const current = goal\n const points = options.snapPoints\n const target =\n direction === 'first'\n ? points[0]\n : direction === 'last'\n ? points.at(-1)!\n : direction === 1\n ? (points.find(point => point > current + 0.01) ?? points.at(-1)!)\n : ([...points].reverse().find(point => point < current - 0.01) ?? points[0])\n to(target)\n },\n destroy() {\n destroyed = true\n dragging = false\n spring.destroy()\n }\n }\n return controller\n}\n"]}
@@ -0,0 +1,4 @@
1
+ import type { SpringDragController } from './drag.js';
2
+ /** Bind one dedicated handle. Document bubble handlers let React/native consumers cancel first. */
3
+ export declare function bindSpringDrag(node: HTMLElement, controller: SpringDragController, axis?: 'x' | 'y'): () => void;
4
+ //# sourceMappingURL=dragBrowser.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dragBrowser.d.ts","sourceRoot":"","sources":["../../../src/motion/dragBrowser.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,MAAM,WAAW,CAAA;AAErD,mGAAmG;AACnG,wBAAgB,cAAc,CAC5B,IAAI,EAAE,WAAW,EACjB,UAAU,EAAE,oBAAoB,EAChC,IAAI,GAAE,GAAG,GAAG,GAAS,cAwJtB"}
@@ -0,0 +1,156 @@
1
+ import { bindSpringStyle } from './browser.js';
2
+ /** Bind one dedicated handle. Document bubble handlers let React/native consumers cancel first. */
3
+ export function bindSpringDrag(node, controller, axis = 'x') {
4
+ const document = node.ownerDocument;
5
+ const unbind = bindSpringStyle(node, controller, axis === 'x' ? 'translateX' : 'translateY');
6
+ const previousTouch = node.style.touchAction;
7
+ const ownsTouch = !previousTouch;
8
+ if (ownsTouch)
9
+ node.style.touchAction = axis === 'x' ? 'pan-y' : 'pan-x';
10
+ const ownedTouch = node.style.touchAction;
11
+ let active, start = 0, origin = 0, cross = 0, moved = false, suppress = false;
12
+ const coordinate = (event) => (axis === 'x' ? event.clientX : event.clientY);
13
+ const other = (event) => (axis === 'x' ? event.clientY : event.clientX);
14
+ const blocked = () => node.matches(':disabled') ||
15
+ node.getAttribute('aria-busy') === 'true' ||
16
+ node.getAttribute('aria-disabled') === 'true';
17
+ const target = (event) => event.target instanceof Node && node.contains(event.target);
18
+ function free() {
19
+ if (active !== undefined && node.hasPointerCapture(active))
20
+ node.releasePointerCapture(active);
21
+ active = undefined;
22
+ }
23
+ function down(event) {
24
+ if (event.defaultPrevented ||
25
+ !target(event) ||
26
+ event.button !== 0 ||
27
+ event.isPrimary === false ||
28
+ active !== undefined ||
29
+ blocked())
30
+ return;
31
+ suppress = false;
32
+ active = event.pointerId;
33
+ start = coordinate(event);
34
+ cross = other(event);
35
+ origin = controller.get();
36
+ moved = false;
37
+ controller.begin();
38
+ controller.move(origin, event.timeStamp);
39
+ }
40
+ function move(event) {
41
+ if (active !== event.pointerId)
42
+ return;
43
+ if (event.defaultPrevented || blocked()) {
44
+ cancel();
45
+ return;
46
+ }
47
+ const delta = coordinate(event) - start;
48
+ if (!moved && Math.abs(other(event) - cross) > Math.max(4, Math.abs(delta))) {
49
+ cancel();
50
+ return;
51
+ }
52
+ if (!moved && Math.abs(delta) < 3)
53
+ return;
54
+ if (!moved) {
55
+ moved = true;
56
+ try {
57
+ node.setPointerCapture(event.pointerId);
58
+ }
59
+ catch {
60
+ /* Document events still provide outside release for synthetic input. */
61
+ }
62
+ }
63
+ controller.move(origin + delta, event.timeStamp);
64
+ }
65
+ function up(event) {
66
+ if (active !== event.pointerId)
67
+ return;
68
+ if (event.defaultPrevented || blocked()) {
69
+ cancel();
70
+ return;
71
+ }
72
+ suppress = moved;
73
+ controller.release(event.timeStamp);
74
+ free();
75
+ moved = false;
76
+ }
77
+ function cancel() {
78
+ if (active === undefined)
79
+ return;
80
+ controller.cancel();
81
+ free();
82
+ suppress = moved;
83
+ }
84
+ function cancelled(event) {
85
+ if (active === event.pointerId)
86
+ cancel();
87
+ }
88
+ function key(event) {
89
+ if (!target(event) || event.defaultPrevented || blocked())
90
+ return;
91
+ const backward = axis === 'x' ? 'ArrowLeft' : 'ArrowUp', forward = axis === 'x' ? 'ArrowRight' : 'ArrowDown';
92
+ if (event.key === 'Escape') {
93
+ if (active !== undefined) {
94
+ event.preventDefault();
95
+ cancel();
96
+ }
97
+ return;
98
+ }
99
+ if ([backward, forward, 'Home', 'End'].includes(event.key)) {
100
+ event.preventDefault();
101
+ if (active !== undefined)
102
+ cancel();
103
+ controller.step(event.key === 'Home'
104
+ ? 'first'
105
+ : event.key === 'End'
106
+ ? 'last'
107
+ : event.key === forward
108
+ ? 1
109
+ : -1);
110
+ }
111
+ }
112
+ function click(event) {
113
+ if (suppress) {
114
+ suppress = false;
115
+ event.preventDefault();
116
+ event.stopPropagation();
117
+ }
118
+ }
119
+ document.addEventListener('pointerdown', down);
120
+ document.addEventListener('pointermove', move);
121
+ document.addEventListener('pointerup', up);
122
+ document.addEventListener('pointercancel', cancelled);
123
+ document.addEventListener('keydown', key);
124
+ node.addEventListener('lostpointercapture', cancelled);
125
+ node.addEventListener('click', click, true);
126
+ document.defaultView.addEventListener('blur', cancel);
127
+ node.addEventListener('blur', cancel);
128
+ const observer = new MutationObserver(() => {
129
+ if (blocked())
130
+ cancel();
131
+ });
132
+ observer.observe(node, {
133
+ attributes: true,
134
+ attributeFilter: ['disabled', 'aria-busy', 'aria-disabled']
135
+ });
136
+ for (let parent = node.parentElement; parent; parent = parent.parentElement)
137
+ if (parent.tagName === 'FIELDSET')
138
+ observer.observe(parent, { attributes: true, attributeFilter: ['disabled'] });
139
+ return () => {
140
+ cancel();
141
+ unbind();
142
+ if (ownsTouch && node.style.touchAction === ownedTouch)
143
+ node.style.touchAction = previousTouch;
144
+ document.removeEventListener('pointerdown', down);
145
+ document.removeEventListener('pointermove', move);
146
+ document.removeEventListener('pointerup', up);
147
+ document.removeEventListener('pointercancel', cancelled);
148
+ document.removeEventListener('keydown', key);
149
+ node.removeEventListener('lostpointercapture', cancelled);
150
+ node.removeEventListener('click', click, true);
151
+ document.defaultView.removeEventListener('blur', cancel);
152
+ node.removeEventListener('blur', cancel);
153
+ observer.disconnect();
154
+ };
155
+ }
156
+ //# sourceMappingURL=dragBrowser.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dragBrowser.js","sourceRoot":"","sources":["../../../src/motion/dragBrowser.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,eAAe,EAAE,MAAM,cAAc,CAAA;AAC9C,mGAAmG;AACnG,MAAM,UAAU,cAAc,CAC5B,IAAiB,EACjB,UAAgC,EAChC,OAAkB,GAAG;IAErB,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAA;IACnC,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,EAAE,UAAU,EAAE,IAAI,KAAK,GAAG,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,YAAY,CAAC,CAA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AAE,SAAS,CAAC,CAAA;QACxD,QAAQ,CAAC,mBAAmB,CAAC,SAAS,EAAE,GAAG,CAAC,CAAA;QAC5C,IAAI,CAAC,mBAAmB,CAAC,oBAAoB,EAAE,SAAS,CAAC,CAAA;QACzD,IAAI,CAAC,mBAAmB,CAAC,OAAO,EAAE,KAAK,EAAE,IAAI,CAAC,CAAA;QAC9C,QAAQ,CAAC,WAAY,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACzD,IAAI,CAAC,mBAAmB,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;QACxC,QAAQ,CAAC,UAAU,EAAE,CAAA;IACvB,CAAC,CAAA;AACH,CAAC","sourcesContent":["import type { SpringDragController } from './drag.js'\nimport { bindSpringStyle } from './browser.js'\n/** Bind one dedicated handle. Document bubble handlers let React/native consumers cancel first. */\nexport function bindSpringDrag(\n node: HTMLElement,\n controller: SpringDragController,\n axis: 'x' | 'y' = 'x'\n) {\n const document = node.ownerDocument\n const unbind = bindSpringStyle(node, controller, axis === 'x' ? 'translateX' : 'translateY')\n const previousTouch = node.style.touchAction\n const ownsTouch = !previousTouch\n if (ownsTouch) node.style.touchAction = axis === 'x' ? 'pan-y' : 'pan-x'\n const ownedTouch = node.style.touchAction\n let active: number | undefined,\n start = 0,\n origin = 0,\n cross = 0,\n moved = false,\n suppress = false\n const coordinate = (event: PointerEvent) => (axis === 'x' ? event.clientX : event.clientY)\n const other = (event: PointerEvent) => (axis === 'x' ? event.clientY : event.clientX)\n const blocked = () =>\n node.matches(':disabled') ||\n node.getAttribute('aria-busy') === 'true' ||\n node.getAttribute('aria-disabled') === 'true'\n const target = (event: Event) => event.target instanceof Node && node.contains(event.target)\n function free() {\n if (active !== undefined && node.hasPointerCapture(active)) node.releasePointerCapture(active)\n active = undefined\n }\n function down(event: PointerEvent) {\n if (\n event.defaultPrevented ||\n !target(event) ||\n event.button !== 0 ||\n event.isPrimary === false ||\n active !== undefined ||\n blocked()\n )\n return\n suppress = false\n active = event.pointerId\n start = coordinate(event)\n cross = other(event)\n origin = controller.get()\n moved = false\n controller.begin()\n controller.move(origin, event.timeStamp)\n }\n function move(event: PointerEvent) {\n if (active !== event.pointerId) return\n if (event.defaultPrevented || blocked()) {\n cancel()\n return\n }\n const delta = coordinate(event) - start\n if (!moved && Math.abs(other(event) - cross) > Math.max(4, Math.abs(delta))) {\n cancel()\n return\n }\n if (!moved && Math.abs(delta) < 3) return\n if (!moved) {\n moved = true\n try {\n node.setPointerCapture(event.pointerId)\n } catch {\n /* Document events still provide outside release for synthetic input. */\n }\n }\n controller.move(origin + delta, event.timeStamp)\n }\n function up(event: PointerEvent) {\n if (active !== event.pointerId) return\n if (event.defaultPrevented || blocked()) {\n cancel()\n return\n }\n suppress = moved\n controller.release(event.timeStamp)\n free()\n moved = false\n }\n function cancel() {\n if (active === undefined) return\n controller.cancel()\n free()\n suppress = moved\n }\n function cancelled(event: PointerEvent) {\n if (active === event.pointerId) cancel()\n }\n function key(event: KeyboardEvent) {\n if (!target(event) || event.defaultPrevented || blocked()) return\n const backward = axis === 'x' ? 'ArrowLeft' : 'ArrowUp',\n forward = axis === 'x' ? 'ArrowRight' : 'ArrowDown'\n if (event.key === 'Escape') {\n if (active !== undefined) {\n event.preventDefault()\n cancel()\n }\n return\n }\n if ([backward, forward, 'Home', 'End'].includes(event.key)) {\n event.preventDefault()\n if (active !== undefined) cancel()\n controller.step(\n event.key === 'Home'\n ? 'first'\n : event.key === 'End'\n ? 'last'\n : event.key === forward\n ? 1\n : -1\n )\n }\n }\n function click(event: MouseEvent) {\n if (suppress) {\n suppress = false\n event.preventDefault()\n event.stopPropagation()\n }\n }\n document.addEventListener('pointerdown', down)\n document.addEventListener('pointermove', move)\n document.addEventListener('pointerup', up)\n document.addEventListener('pointercancel', cancelled)\n document.addEventListener('keydown', key)\n node.addEventListener('lostpointercapture', cancelled)\n node.addEventListener('click', click, true)\n document.defaultView!.addEventListener('blur', cancel)\n node.addEventListener('blur', cancel)\n const observer = new MutationObserver(() => {\n if (blocked()) cancel()\n })\n observer.observe(node, {\n attributes: true,\n attributeFilter: ['disabled', 'aria-busy', 'aria-disabled']\n })\n for (let parent = node.parentElement; parent; parent = parent.parentElement)\n if (parent.tagName === 'FIELDSET')\n observer.observe(parent, { attributes: true, attributeFilter: ['disabled'] })\n return () => {\n cancel()\n unbind()\n if (ownsTouch && node.style.touchAction === ownedTouch) node.style.touchAction = previousTouch\n document.removeEventListener('pointerdown', down)\n document.removeEventListener('pointermove', move)\n document.removeEventListener('pointerup', up)\n document.removeEventListener('pointercancel', cancelled)\n document.removeEventListener('keydown', key)\n node.removeEventListener('lostpointercapture', cancelled)\n node.removeEventListener('click', click, true)\n document.defaultView!.removeEventListener('blur', cancel)\n node.removeEventListener('blur', cancel)\n observer.disconnect()\n }\n}\n"]}
@@ -0,0 +1,9 @@
1
+ import type { SpringController } from './runtime.js';
2
+ /** Synchronous numeric snapshot with notifications in the same units as the follower. */
3
+ export interface SpringSource {
4
+ get(): number;
5
+ subscribe(listener: (value: number) => void): () => void;
6
+ }
7
+ /** The source owns destinations; the existing spring owns position, momentum and physics. */
8
+ export declare function bindSpringSource(spring: SpringController, source: SpringSource): () => void;
9
+ //# sourceMappingURL=follow.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"follow.d.ts","sourceRoot":"","sources":["../../../src/motion/follow.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,cAAc,CAAA;AAEpD,yFAAyF;AACzF,MAAM,WAAW,YAAY;IAC3B,GAAG,IAAI,MAAM,CAAA;IACb,SAAS,CAAC,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI,CAAA;CACzD;AACD,6FAA6F;AAC7F,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,gBAAgB,EAAE,MAAM,EAAE,YAAY,GAAG,MAAM,IAAI,CAmB3F"}