@humanspeak/svelte-motion 0.2.1 → 0.3.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -11,6 +11,7 @@ export { useMotionTemplate } from './utils/motionTemplate';
11
11
  export { useMotionValue } from './utils/motionValue';
12
12
  export type { MotionValue } from './utils/motionValue';
13
13
  export { useMotionValueEvent } from './utils/motionValueEvent';
14
+ export { useReducedMotion } from './utils/reducedMotion';
14
15
  export { useScroll } from './utils/scroll';
15
16
  export { useSpring } from './utils/spring';
16
17
  export { useVelocity } from './utils/velocity';
package/dist/index.js CHANGED
@@ -12,6 +12,7 @@ export { createDragControls } from './utils/dragControls';
12
12
  export { useMotionTemplate } from './utils/motionTemplate';
13
13
  export { useMotionValue } from './utils/motionValue';
14
14
  export { useMotionValueEvent } from './utils/motionValueEvent';
15
+ export { useReducedMotion } from './utils/reducedMotion';
15
16
  export { useScroll } from './utils/scroll';
16
17
  export { useSpring } from './utils/spring';
17
18
  export { useVelocity } from './utils/velocity';
@@ -0,0 +1,20 @@
1
+ import { type Readable } from 'svelte/store';
2
+ /**
3
+ * Returns a readable store that reflects the user's `prefers-reduced-motion` setting.
4
+ *
5
+ * Defaults to `false` in SSR or when `matchMedia` is unavailable/throws.
6
+ *
7
+ * @returns {Readable<boolean>} `true` when the user prefers reduced motion.
8
+ * @see https://motion.dev/docs/react-reduced-motion
9
+ *
10
+ * @example
11
+ * ```svelte
12
+ * <script>
13
+ * import { useReducedMotion } from '@humanspeak/svelte-motion'
14
+ * const reduced = useReducedMotion()
15
+ * </script>
16
+ *
17
+ * <div style:transform={$reduced ? 'none' : 'rotate(45deg)'}>...</div>
18
+ * ```
19
+ */
20
+ export declare const useReducedMotion: () => Readable<boolean>;
@@ -0,0 +1,42 @@
1
+ import { readable } from 'svelte/store';
2
+ const REDUCED_MOTION_QUERY = '(prefers-reduced-motion: reduce)';
3
+ const SSR_FALLBACK = readable(false, () => { });
4
+ /**
5
+ * Returns a readable store that reflects the user's `prefers-reduced-motion` setting.
6
+ *
7
+ * Defaults to `false` in SSR or when `matchMedia` is unavailable/throws.
8
+ *
9
+ * @returns {Readable<boolean>} `true` when the user prefers reduced motion.
10
+ * @see https://motion.dev/docs/react-reduced-motion
11
+ *
12
+ * @example
13
+ * ```svelte
14
+ * <script>
15
+ * import { useReducedMotion } from '@humanspeak/svelte-motion'
16
+ * const reduced = useReducedMotion()
17
+ * </script>
18
+ *
19
+ * <div style:transform={$reduced ? 'none' : 'rotate(45deg)'}>...</div>
20
+ * ```
21
+ */
22
+ export const useReducedMotion = () => {
23
+ if (typeof window === 'undefined' || typeof window.matchMedia !== 'function') {
24
+ return SSR_FALLBACK;
25
+ }
26
+ let media;
27
+ try {
28
+ media = window.matchMedia(REDUCED_MOTION_QUERY);
29
+ }
30
+ catch {
31
+ return SSR_FALLBACK;
32
+ }
33
+ return readable(media.matches, (set) => {
34
+ const handler = (event) => set(event.matches);
35
+ if (typeof media.addEventListener === 'function') {
36
+ media.addEventListener('change', handler);
37
+ return () => media.removeEventListener('change', handler);
38
+ }
39
+ media.addListener(handler);
40
+ return () => media.removeListener(handler);
41
+ });
42
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@humanspeak/svelte-motion",
3
- "version": "0.2.1",
3
+ "version": "0.3.0",
4
4
  "description": "A Framer Motion-compatible animation library for Svelte 5 that provides smooth, hardware-accelerated animations. Features include spring physics, custom easing, and fluid transitions. Built on top of the motion library, it offers a simple API for creating complex animations with minimal code. Perfect for interactive UIs, micro-interactions, and engaging user experiences.",
5
5
  "keywords": [
6
6
  "svelte",