@noxlovette/material 0.9.2 → 0.9.3

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.
@@ -15,7 +15,7 @@ Source: [m3.material.io → Transitions → Applying transitions](https://m3.mat
15
15
 
16
16
  | Quality | M3 rule | What it means here |
17
17
  | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
18
- | **Follows accessibility settings** | With reduced motion on, use subtle fades instead of intense slides or scales, and turn off decorative effects such as parallax and shape morphing. | This is not implemented yet (see [Reduced motion](#reduced-motion)). Don't add new parallax or morph effects that you couldn't easily switch off. |
18
+ | **Follows accessibility settings** | With reduced motion on, use subtle fades instead of intense slides or scales, and turn off decorative effects such as parallax and shape morphing. | The OS preference switches the transition primitives and CSS spatial tokens automatically (see [Reduced motion](#reduced-motion)). |
19
19
  | **Consistent** | Use the same transition type for the same kind of change everywhere, so the app feels like one cohesive family. | Always use one primitive for one relationship. Every hierarchy step uses `sharedAxis` on the same axis, and every navbar/rail destination uses `fadeThrough`. Never mix patterns for the same kind of navigation. |
20
20
  | **Stable layouts** | Use skeleton loaders so the layout holds still during a transition. Content shouldn't pop in or move around. | Reserve the loaded content's footprint with `{@attach skeleton}` placeholders, then reveal the content with `presence(…, enterExit.fade)`. The content shouldn't be conditionally inserted in a way that shifts its siblings. |
21
21
  | **No jarring jump cuts** | By default, avoid instant screen swaps because they disorient users. A jump cut is fine only when pure efficiency matters most, such as opening a menu in a productivity app. | Surfaces and navigation always animate, which is why the ownership table below is mandatory. A jump cut has to be an explicit, documented choice, never the result of leaving the animation out. |
@@ -196,10 +196,10 @@ MDC's own durations/easings (`short1`…`extraLong4` × `emphasized`/`standard`)
196
196
 
197
197
  ## Reduced motion
198
198
 
199
- Not implemented yet — tracked in https://github.com/noxlovette/material/issues/24. `Layer.svelte`'s ripple is the only thing that currently checks `prefers-reduced-motion`.
199
+ The OS `prefers-reduced-motion: reduce` setting governs both the Motion primitives and the CSS tokens. Call sites use the same API regardless of the setting. See [Applying transitions](https://m3.material.io/styles/motion/transitions/applying-transitions) for the M3 rationale.
200
200
 
201
- Target behavior, per [Applying transitions](https://m3.material.io/styles/motion/transitions/applying-transitions). When `prefers-reduced-motion: reduce` is set:
202
-
203
- - **Swap movement for subtle fades rather than removing the transition** (a jump cut would break the "no jarring jump cuts" rule). `enterExit.scale`/`dialog`/`slideUp`/`sideSheet`/`bottomSheet` fall back to `enterExit.fade`. `sharedAxis`, `lateral` and `fadeThrough` fall back to an opacity-only fade with no translate or scale, their region's box swapping instantly; `containerTransform` crossfades its two states in place without growing (`animation/reducedMotion.ts`).
204
- - **Disable decorative effects**: shape morphing (button `--btn-shape` morphs; `morphShape`/`shapeMorph` already swap instantly), parallax, the ripple (already done).
205
- - Keep effects-spring color/opacity feedback (state layers, hover/press color), since that motion carries meaning and isn't intense.
201
+ - `presence` keeps a short opacity fade for every `enterExit` preset, including sheets. Scale and translation stay at their settled values. `sharedAxis`, `lateral` and `fadeThrough` use an opacity-only fade; the region's box swaps immediately. `containerTransform` fades its snapshots without growing the group.
202
+ - `motion.css` makes the three spatial duration tokens `0ms` and maps their timing functions to non-overshooting effects curves. Color, opacity and state-layer transitions retain their effects springs.
203
+ - The `skeleton` attachment shows a static placeholder. It stops or resumes the pulse if the OS preference changes while mounted.
204
+ - Shape morphs in the shape library swap instantly, and ripples and decorative rotation stop. Button corner and button-group pressed feedback remain animated with a critically damped spring, so they do not overshoot.
205
+ - Storybook's **Motion/Transition patterns** page uses these same primitives, so it shows the reduced variants when the OS preference is on.
@@ -183,7 +183,8 @@
183
183
  skeleton: {
184
184
  id: 'skeleton',
185
185
  title: 'Skeleton loaders',
186
- summary: 'A placeholder pulses until real content fades in.',
186
+ summary:
187
+ 'A placeholder pulses until real content fades in; it stays still with reduced motion.',
187
188
  anchor: 'skeleton-loaders',
188
189
  run: runSkeleton
189
190
  }
@@ -76,11 +76,12 @@ export const containerTransform = (update, { from, to, spring = springTokens.spa
76
76
  root.style.setProperty(SHADOW, shadowOf(target) ?? fromShadow ?? 'none');
77
77
  };
78
78
  // The class lets motion.css keep both snapshots at their width, clipped by the container.
79
- const builder = animateView(updateAndFill, springTransition(spring))
79
+ const reduced = prefersReducedMotion();
80
+ const builder = animateView(updateAndFill, springTransition(reduced ? springTokens.effects : spring))
80
81
  .add(from, to)
81
82
  .class('md-container-transform');
82
83
  // Reduced motion: the container doesn't grow; its two states just crossfade in place.
83
- if (prefersReducedMotion())
84
+ if (reduced)
84
85
  builder.layout({ duration: 0 });
85
86
  return builder
86
87
  .old({ opacity: [1, 0] }, springTransition(springTokens.effects))
@@ -1,5 +1,7 @@
1
1
  import { animate } from 'motion';
2
2
  import { untrack } from 'svelte';
3
+ import { enterExit } from './enterExit.js';
4
+ import { prefersReducedMotion } from './reducedMotion.js';
3
5
  const fromTo = (from, to) => Object.fromEntries(Object.entries(to).map(([key, value]) => [key, [from[key], value]]));
4
6
  /**
5
7
  * Enter/exit attachment driven by Motion's `animate()`. Plays `transition.enter` from `hidden` to
@@ -33,7 +35,16 @@ export const presence = (isOpen, transition, onExitComplete) => (node) => {
33
35
  $effect(() => {
34
36
  const open = isOpen();
35
37
  untrack(() => {
36
- const { hidden, shown, exited = hidden, enter, exit } = transition;
38
+ // Reduced motion keeps the mount/unmount cue, but never animates the preset's
39
+ // scale or translation (including the sheet presets that normally have no fade).
40
+ const active = prefersReducedMotion() ? enterExit.fade : transition;
41
+ const { hidden, shown, exited = hidden, enter, exit } = active;
42
+ if (active !== transition) {
43
+ const shownTransform = transition.shown.transform;
44
+ const settled = Array.isArray(shownTransform) ? shownTransform.at(-1) : shownTransform;
45
+ if (typeof settled === 'string')
46
+ node.style.transform = settled;
47
+ }
37
48
  clearTimeout(settleTimer);
38
49
  if (open) {
39
50
  controls = animate(node, started ? shown : fromTo(hidden, shown), enter);
@@ -61,13 +61,15 @@ const fadeInPlace = (update, target, spring, incoming) => {
61
61
  outgoing.transform = Array(2).fill(`translate(${dx}px, ${dy}px)`);
62
62
  };
63
63
  const builder = view(run, target, spring);
64
+ // The whole-page group also has a layout animation when no target was supplied.
65
+ builder.layout({ duration: 0 });
64
66
  if (target)
65
- builder.layout({ duration: 0 }).crop(false);
67
+ builder.crop(false);
66
68
  return builder.old(outgoing, fadeOut).new(...incoming);
67
69
  };
68
70
  /* Reduced motion: every navigation pattern becomes this fade, with no movement or scale. M3
69
71
  swaps movement for a subtle fade rather than cutting. */
70
- const reducedFade = (update, target, spring) => fadeInPlace(update, target, spring, [{ opacity: [0, 1] }, fadeInAfterOut]);
72
+ const reducedFade = (update, target) => fadeInPlace(update, target, springTokens.effects, [{ opacity: [0, 1] }, fadeInAfterOut]);
71
73
  /**
72
74
  * M3 forward and backward (shared axis): outgoing and incoming content travel together along one
73
75
  * axis while fading through each other.
@@ -85,7 +87,7 @@ const reducedFade = (update, target, spring) => fadeInPlace(update, target, spri
85
87
  */
86
88
  export const sharedAxis = (update, { target, axis = 'x', direction = 'forward', spring = springTokens.spatial } = {}) => {
87
89
  if (prefersReducedMotion())
88
- return reducedFade(update, target, spring);
90
+ return reducedFade(update, target);
89
91
  const forward = direction === 'forward';
90
92
  const [outgoing, incoming] = axis === 'z'
91
93
  ? [`scale(${forward ? 1.1 : 0.8})`, `scale(${forward ? 0.8 : 1.1})`]
@@ -116,7 +118,7 @@ export const sharedAxis = (update, { target, axis = 'x', direction = 'forward',
116
118
  */
117
119
  export const lateral = (update, { target, axis = 'x', direction = 'forward', spring = springTokens.spatial } = {}) => {
118
120
  if (prefersReducedMotion())
119
- return reducedFade(update, target, spring);
121
+ return reducedFade(update, target);
120
122
  const sign = direction === 'forward' ? 1 : -1;
121
123
  const move = axis === 'y' ? 'translateY' : 'translateX';
122
124
  const builder = view(update, target, spring)
@@ -144,7 +146,7 @@ export const lateral = (update, { target, axis = 'x', direction = 'forward', spr
144
146
  */
145
147
  export const fadeThrough = (update, { target, spring = springTokens.spatial } = {}) => {
146
148
  if (prefersReducedMotion())
147
- return reducedFade(update, target, spring);
149
+ return reducedFade(update, target);
148
150
  return fadeInPlace(update, target, spring, [
149
151
  { opacity: [0, 1], transform: ['scale(0.92)', 'scale(1)'] },
150
152
  { opacity: fadeInAfterOut }
@@ -1,7 +1,8 @@
1
1
  import type { Attachment } from 'svelte/attachments';
2
2
  /**
3
- * M3 skeleton loader: a placeholder pulses until real content replaces it. Swap the placeholder
4
- * for the content with `presence(…, enterExit.fade)` so the reveal is a fade, not a cut.
3
+ * M3 skeleton loader: a placeholder pulses until real content replaces it, and stays static under
4
+ * reduced motion. Swap the placeholder for the content with `presence(…, enterExit.fade)` so the
5
+ * reveal is a fade, not a cut.
5
6
  * https://m3.material.io/styles/motion/transitions/transition-patterns#skeleton-loaders
6
7
  *
7
8
  * M3 "stable layouts" (https://m3.material.io/styles/motion/transitions/applying-transitions): the placeholder takes the loaded
@@ -1,11 +1,13 @@
1
1
  import { animate } from 'motion';
2
+ import { prefersReducedMotion } from './reducedMotion.js';
2
3
  import { springTokens, springTransition } from './spring.js';
3
4
  /* Hold at each end of the pulse — a critically damped spring alone settles in ~370ms, which reads
4
5
  as flicker. Not an M3 value: tune by eye. */
5
6
  const PULSE_HOLD_S = 0.5;
6
7
  /**
7
- * M3 skeleton loader: a placeholder pulses until real content replaces it. Swap the placeholder
8
- * for the content with `presence(…, enterExit.fade)` so the reveal is a fade, not a cut.
8
+ * M3 skeleton loader: a placeholder pulses until real content replaces it, and stays static under
9
+ * reduced motion. Swap the placeholder for the content with `presence(…, enterExit.fade)` so the
10
+ * reveal is a fade, not a cut.
9
11
  * https://m3.material.io/styles/motion/transitions/transition-patterns#skeleton-loaders
10
12
  *
11
13
  * M3 "stable layouts" (https://m3.material.io/styles/motion/transitions/applying-transitions): the placeholder takes the loaded
@@ -18,11 +20,27 @@ const PULSE_HOLD_S = 0.5;
18
20
  * ```
19
21
  */
20
22
  export const skeleton = (node) => {
21
- const controls = animate(node, { opacity: [1, 0.4] }, {
22
- ...springTransition(springTokens.slowEffects),
23
- repeat: Infinity,
24
- repeatType: 'reverse',
25
- repeatDelay: PULSE_HOLD_S
26
- });
27
- return () => controls.stop();
23
+ const media = typeof matchMedia === 'function' ? matchMedia('(prefers-reduced-motion: reduce)') : null;
24
+ const initialOpacity = node.style.opacity;
25
+ let controls;
26
+ const sync = () => {
27
+ controls?.stop();
28
+ controls = undefined;
29
+ node.style.opacity = initialOpacity;
30
+ if (prefersReducedMotion())
31
+ return;
32
+ controls = animate(node, { opacity: [1, 0.4] }, {
33
+ ...springTransition(springTokens.slowEffects),
34
+ repeat: Infinity,
35
+ repeatType: 'reverse',
36
+ repeatDelay: PULSE_HOLD_S
37
+ });
38
+ };
39
+ sync();
40
+ media?.addEventListener('change', sync);
41
+ return () => {
42
+ media?.removeEventListener('change', sync);
43
+ controls?.stop();
44
+ node.style.opacity = initialOpacity;
45
+ };
28
46
  };
@@ -29,6 +29,7 @@ For a set of related options where one or more is selected, use `ConnectedButton
29
29
 
30
30
  const GROW = 0.15;
31
31
  const spring = springTransition(springTokens.fastSpatial);
32
+ const reducedSpring = springTransition(springTokens.fastEffects);
32
33
  const reducedMotion = () =>
33
34
  typeof matchMedia === 'function' && matchMedia('(prefers-reduced-motion: reduce)').matches;
34
35
 
@@ -57,7 +58,7 @@ For a set of related options where one or more is selected, use `ConnectedButton
57
58
  };
58
59
 
59
60
  const start = (el: HTMLElement) => {
60
- if (orientation !== 'horizontal' || press || reducedMotion()) return;
61
+ if (orientation !== 'horizontal' || press) return;
61
62
  const width = widthOf(el);
62
63
  const neighbours = [el.previousElementSibling, el.nextElementSibling].filter(isEnabled);
63
64
  const share = (width * GROW) / Math.max(neighbours.length, 1);
@@ -70,7 +71,8 @@ For a set of related options where one or more is selected, use `ConnectedButton
70
71
  })
71
72
  ]
72
73
  };
73
- for (const { el: item, to } of press.items) animate(item, { width: `${to}px` }, spring);
74
+ for (const { el: item, to } of press.items)
75
+ animate(item, { width: `${to}px` }, reducedMotion() ? reducedSpring : spring);
74
76
  };
75
77
 
76
78
  const end = () => {
@@ -78,7 +80,7 @@ For a set of related options where one or more is selected, use `ConnectedButton
78
80
  const { items } = press;
79
81
  press = null;
80
82
  for (const { el, width } of items) {
81
- animate(el, { width: `${width}px` }, spring).then(() => {
83
+ animate(el, { width: `${width}px` }, reducedMotion() ? reducedSpring : spring).then(() => {
82
84
  // Hand the width back to the layout, unless a new press picked this button up.
83
85
  if (press?.items.some((i) => i.el === el)) return;
84
86
  el.style.width = '';
@@ -25,6 +25,7 @@ const isDisabled = (el) => el.matches(':disabled, [aria-disabled="true"], [data-
25
25
  export function shapeMorph(el, corners) {
26
26
  const reduced = matchMedia('(prefers-reduced-motion: reduce)');
27
27
  const spring = springTransition(springTokens.fastSpatial);
28
+ const reducedSpring = springTransition(springTokens.fastEffects);
28
29
  const state = { pressed: false, hovered: false, focusVisible: false };
29
30
  const resolve = () => {
30
31
  const style = getComputedStyle(el);
@@ -43,10 +44,7 @@ export function shapeMorph(el, corners) {
43
44
  return;
44
45
  targets[i] = to;
45
46
  controls[i]?.stop();
46
- if (reduced.matches)
47
- values[i].jump(to);
48
- else
49
- controls[i] = animate(values[i], to, spring);
47
+ controls[i] = animate(values[i], to, reduced.matches ? reducedSpring : spring);
50
48
  });
51
49
  };
52
50
  const set = (key, on) => {
@@ -81,6 +79,15 @@ export function shapeMorph(el, corners) {
81
79
  attributes: true,
82
80
  attributeFilter: ['class', 'data-state', 'aria-pressed', 'aria-expanded']
83
81
  });
82
+ const onReducedChange = () => {
83
+ if (!reduced.matches)
84
+ return;
85
+ controls.forEach((control, i) => {
86
+ control?.stop();
87
+ values[i].jump(targets[i]);
88
+ });
89
+ };
90
+ reduced.addEventListener?.('change', onReducedChange);
84
91
  el.addEventListener('pointerdown', onPointerDown);
85
92
  el.addEventListener('pointerenter', onEnter);
86
93
  el.addEventListener('pointerleave', onLeave);
@@ -92,6 +99,7 @@ export function shapeMorph(el, corners) {
92
99
  window.addEventListener('pointercancel', release);
93
100
  return () => {
94
101
  observer.disconnect();
102
+ reduced.removeEventListener?.('change', onReducedChange);
95
103
  controls.forEach((c) => c?.stop());
96
104
  unsubscribe.forEach((u) => u());
97
105
  el.removeEventListener('pointerdown', onPointerDown);
@@ -284,6 +284,23 @@
284
284
  /* @generated:springs:end */
285
285
  }
286
286
 
287
+ /* Spatial CSS transitions settle immediately under the OS motion preference. Effects tokens
288
+ remain available for short opacity and color fades. Keep this outside the generated block. */
289
+ @media (prefers-reduced-motion: reduce) {
290
+ :root {
291
+ --md-sys-motion-duration-fast-spatial: 0ms;
292
+ --md-sys-motion-duration-spatial: 0ms;
293
+ --md-sys-motion-duration-slow-spatial: 0ms;
294
+ --md-sys-motion-timing-function-fast-spatial: var(
295
+ --md-sys-motion-timing-function-fast-effects-spring
296
+ );
297
+ --md-sys-motion-timing-function-spatial: var(--md-sys-motion-timing-function-effects-spring);
298
+ --md-sys-motion-timing-function-slow-spatial: var(
299
+ --md-sys-motion-timing-function-slow-effects-spring
300
+ );
301
+ }
302
+ }
303
+
287
304
  /*
288
305
  One utility per Expressive spring, setting duration + timing function together. Pair with a
289
306
  Tailwind transition-property utility: `transition-colors md-sys-motion-fast-effects`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@noxlovette/material",
3
- "version": "0.9.2",
3
+ "version": "0.9.3",
4
4
  "type": "module",
5
5
  "description": "A Material Design 3 component library for Svelte, built on Bits UI.",
6
6
  "keywords": [