glasslikeui 1.7.0 → 1.8.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 CHANGED
@@ -181,6 +181,10 @@ close button (`aria-label="Close"`) at the trailing side. The sheet is a modal
181
181
  the sheet. Anything shorter snaps back. Set `interactiveDismissDisabled`
182
182
  to turn this off, mirroring SwiftUI. The close button, Escape and the
183
183
  backdrop still close the sheet.
184
+ - The sheet is a viewport tall and slides down to its detent. The content area
185
+ ends at the bottom of the screen at every detent, so the end of long content
186
+ can be scrolled into view. It resizes when a drag snaps. Remove any
187
+ `margin-bottom` you added to `.sheet-content` to work around this.
184
188
  - Every close path (button, Escape, backdrop, drag, or the parent setting
185
189
  `isOpen` to `false`) slides the sheet down and fades the backdrop before
186
190
  it unmounts. `isOpen` turns false and `onClose` fires when the close
@@ -280,13 +284,112 @@ restored exactly when it closes. Ancestors are never made inert, and anything
280
284
  you had already made inert stays inert. Tab and Shift+Tab wrap inside the
281
285
  sheet, and focus returns to the element that opened it.
282
286
 
283
- Under reduced transparency, `Sheet` turns its blur off, including the backdrop
284
- blur (`--glass-backdrop-blur`), and its background becomes near opaque
285
- (`--glass-sheet-bg` at 0.98 alpha in both themes). `Menu` goes opaque with it.
287
+ Under reduced transparency (the media query, or
288
+ `data-reduced-transparency="true"` on `:root` or on any element around the
289
+ parts, in both themes):
290
+
291
+ - `Glass`, and everything built on it, loses its blur, lens filter and blended
292
+ highlight. `--glass-opacity` becomes 1, so the default background is solid
293
+ `--glass-surface-color`, and a `tint` is painted over a solid base of that
294
+ colour. A background of your own that works normally works here too, and so
295
+ does your own `--glass-surface-bg`: both are left as you set them, see-through
296
+ ones included, so keep them opaque enough for their text.
297
+ - To recolour surfaces, set `--glass-surface-color` on `:root`. To recolour one
298
+ surface, set `--glass-surface-bg` or `tint` on it. `--glass-surface-color` set
299
+ on a single surface does not change its default background, with or without
300
+ reduced transparency, because `--glass-surface-bg` is resolved on `:root`.
301
+ - Glass `Button`s lose their blur and get a solid fill. `glassProminent`
302
+ becomes solid accent with its `--color-on-accent` label.
303
+ - `Sheet` turns its blur off, including the backdrop blur
304
+ (`--glass-backdrop-blur`), and its background becomes near opaque
305
+ (`--glass-sheet-bg` at 0.98 alpha). `Menu` goes opaque with it.
306
+ - `NavigationBar` becomes near opaque too (`--glass-nav-bg` at 0.98 alpha).
307
+
308
+ The empty `::before` layer is removed from `Glass` and glass `Button`s, so a
309
+ `::before` rule of your own for the fill cannot cover the solid one, and
310
+ contrast checkers can read the background. A tinted `Glass` keeps the layer to
311
+ paint its tint, so a checker may report its text as incomplete.
312
+
313
+ On an element inside the page, the attribute also makes `--glass-surface-bg`
314
+ solid `--glass-surface-color` there, in place of a value you set on `:root`, and
315
+ the light theme is still read from `:root`. To switch the preference for the
316
+ whole page, put the attribute on `:root`.
317
+
318
+ With the media query, the library's values (`--glass-opacity`, the blurs,
319
+ `--glass-sheet-bg` and `--glass-nav-bg`) are declared on `:root:root`, so your
320
+ plain `:root` values for them do not keep sheets and bars see-through before any
321
+ script has run. A selector of the same weight loaded later, such as
322
+ `:root[data-theme='dark']`, or a heavier one, still wins, so give such rules
323
+ solid values under the media query. To use your own solid colours there,
324
+ outrank the library:
325
+
326
+ ```css
327
+ @media (prefers-reduced-transparency: reduce) {
328
+ :root:root:root {
329
+ --glass-sheet-bg: #101820;
330
+ --glass-nav-bg: #101820;
331
+ }
332
+ }
333
+ ```
334
+
335
+ No `!important` is needed. `Glass` still sets `--glass-blur` and the other
336
+ effect values inline; the rules replace the properties that read them. Asking
337
+ for more contrast at the same time leaves surfaces solid.
338
+
339
+ Under reduced motion, `withGlassTransition` runs the update with no view
340
+ transition and returns `{ supported: false }`, and `GlassMorph` elements do not
341
+ animate even in a view transition you start yourself.
342
+
343
+ A `Button` with `href` and `disabled` renders a link with no `href`, marked
344
+ `aria-disabled="true"`. It cannot be focused or followed and does not call
345
+ `onclick`.
346
+
347
+ ### Focus ring
348
+
349
+ The library's buttons, links, rows, tabs, menu items and switch draw one shared
350
+ ring for keyboard users. Restyle the rings with these tokens, set on `:root` or
351
+ on any ancestor:
352
+
353
+ | Token | Default |
354
+ | ------------------------------- | ------------------------------------ |
355
+ | `--glass-focus-ring-color` | `#9ecbff` dark, `#00408a` light |
356
+ | `--glass-focus-ring-halo-color` | `#000000` dark, `#ffffff` light |
357
+ | `--glass-focus-ring-width` | `2px` |
358
+ | `--glass-focus-ring-offset` | `2px` |
359
+
360
+ The ring has two tones, because no single colour holds 3:1 against every
361
+ backdrop: the outline, and a halo that fills the gap inside it (inside the
362
+ outline on `ListRow` and `MenuItem`). With the defaults, one tone or the other
363
+ holds 3:1 against any backdrop. If you change either colour, keep the two at
364
+ least 9:1 apart, or set the halo to `transparent` and check the single ring
365
+ against your backgrounds. The four tokens are unset by default (the per theme
366
+ colours live in the `-default` tokens), so a value you set wins in both themes.
367
+ The halo is a `box-shadow`. On `Button` it has to outrank the variant shadows, so
368
+ a `box-shadow` of yours needs more than two classes to replace it there. `ListRow` and `MenuItem` sit in clipping containers, so their ring
369
+ is always drawn inside, offset by minus the width. The colour, width and style
370
+ rules have zero specificity, so any focus rule of your own beats them. The
371
+ inward offsets are the exception, so that an ordinary
372
+ `:focus-visible { outline-offset: 2px }` of yours cannot push a ring out where
373
+ it is cut off. Their selectors weigh two classes on `ListRow` and `MenuItem`,
374
+ three on a part marked `data-focus-ring="inset"` and four on a `Toggle` track
375
+ marked that way. To change one on purpose, use a heavier selector.
376
+
377
+ A container that clips can also cut off the ring of a part flush against its
378
+ edge: a full width `Button` in `<Glass padding="none">`, in a `ScrollView` or at
379
+ the top of `Sheet` content. When `Button`, `IconButton`, a `TabView` item,
380
+ `NavigationLink`, the `Menu` trigger or `Toggle` takes focus with no room for
381
+ its ring, it sets `data-focus-ring="inset"` and draws the ring inside, in its
382
+ label colour unless `--glass-focus-ring-color` is set. A colour you set should
383
+ then stand out on the part's own fill as well as on the page. This is measured
384
+ when the part takes focus.
286
385
 
287
386
  The `Sheet` close button focus ring is two tones, so it holds 3:1 on both the
288
- dark and the light sheet. Override `--sheet-focus-ring-inner` (the ring against
289
- the button) and `--sheet-focus-ring-outer` (the outline) to rebrand it.
387
+ dark and the light sheet. It follows the shared width and offset, and
388
+ `--glass-focus-ring-color`, when set on any ancestor, replaces its outer tone.
389
+ Without that, `--sheet-focus-ring-outer` colours the outline, and
390
+ `--sheet-focus-ring-inner` the ring against the button. To give this button its
391
+ own colour while a shared one is set, set `--glass-focus-ring-color` on
392
+ `.sheet-close-btn`.
290
393
 
291
394
  ## Theming
292
395
 
@@ -306,6 +409,134 @@ Override any token via your own stylesheet, e.g.:
306
409
  }
307
410
  ```
308
411
 
412
+ ### Component tokens
413
+
414
+ These are unset by default, so you can set them on `:root` or on any ancestor.
415
+
416
+ | Token | Used by | Default |
417
+ | ------------------------- | ------------------------------------------------- | --------------------- |
418
+ | `--glass-track-checked` | The checked `Toggle` track. | `--color-accent` |
419
+ | `--color-on-accent` | Labels on accent fills: filled `Button`, filled `IconButton` and `glassProminent`. | `white` |
420
+ | `--color-on-danger` | The `destructive` `Button` label. | `white` |
421
+ | `--glass-sheet-max-width` | `Sheet` width cap on viewports from 769px. | `900px` |
422
+ | `--glass-button-fill` | The resting fill of the plain `glass` `Button`. You own its contrast. | see below |
423
+ | `--glass-button-fill-hover` | Its hover fill. | `--glass-button-fill`, else the library hover fill |
424
+ | `--glass-button-fill-active` | Its pressed fill. | `--glass-button-fill`, else the library pressed fill |
425
+
426
+ ```css
427
+ .my-sheet {
428
+ --glass-sheet-max-width: 1100px;
429
+ }
430
+ ```
431
+
432
+ If you change `--color-accent` or `--color-danger` to a light colour, set the
433
+ matching label token and check for 4.5:1.
434
+
435
+ `glassProminent` fills with `--color-accent`, shaded toward black and slightly
436
+ see-through (84% opaque, a little darker on hover and again when pressed), with
437
+ a `--color-on-accent` label. With the default colours the label holds at least
438
+ 4.5:1 over any backdrop. Your own pair needs more room than on a solid fill:
439
+ the shade darkens the accent and the backdrop shows through, so check it over
440
+ both black and white.
441
+
442
+ The plain `glass` `Button` is see-through, and its default label holds 4.5:1
443
+ (WCAG 2.2 AA) at rest, on hover and when pressed, over any backdrop, in both
444
+ themes: smoked glass under a light label in the dark theme, and white glass,
445
+ 55% opaque or more, under a dark label in the light one. This takes your
446
+ `--color-text` to be light in the dark theme (about `#f5f5f7`) and dark in the
447
+ light theme (about `#1d1d1f`); the library does not set it. The button's edge
448
+ can be faint against a backdrop of a similar grey.
449
+
450
+ Change the fill with `--glass-button-fill` and, if you want hover and press
451
+ feedback with it, the `-hover` and `-active` tokens. A fill of your own owns its
452
+ contrast: check the label against it over your lightest and darkest backdrops.
453
+ Reduced transparency ignores all three. Use them instead of styling the
454
+ button's `::before`.
455
+
456
+ ### Text and fill colours (WCAG 2.2 AA)
457
+
458
+ With the default colours, the labels of these hold 4.5:1 (WCAG 2.2 AA 1.4.3) at
459
+ rest, on hover and when pressed, measured from painted pixels in Chromium and
460
+ WebKit.
461
+
462
+ Solid fills, over any backdrop: `filled` `Button` and `IconButton` (4.70 rest,
463
+ 5.38 hover and press at the lowest), `destructive` `Button` (4.72, 5.43, 6.11),
464
+ `glassProminent` and the plain `glass` `Button` (see above).
465
+
466
+ See-through variants, over the surfaces of their theme: `outlined`, `plain` and
467
+ `tinted` `Button`s, accent `Badge`, the active `TabView` item, `Text` with
468
+ `color="accent"` or `"danger"`, and a destructive `MenuItem`. The lowest measured
469
+ over the dark theme's black, `rgb(28, 28, 30)`, `rgb(53, 53, 55)` and
470
+ `rgb(64, 64, 66)`, and the light theme's white, `rgb(242, 242, 247)` and
471
+ `rgb(224, 224, 224)`, is 4.87:1. They do not hold over every backdrop, and no
472
+ colour can: text that contrasts with both black and white fails against a grey
473
+ or saturated colour in between. Over white in the dark theme, black in the light
474
+ theme or a saturated colour they measure from 1.0 to 1.3:1. Use `filled`,
475
+ `glassProminent` or `glass` over busy backdrops.
476
+
477
+ Text in the accent or danger colour is the colour mixed toward white in the dark
478
+ theme and toward black in the light one, worked out from `--color-accent` or
479
+ `--color-danger` where the part is, so it follows a wrapper's own colour with
480
+ nothing to mark:
481
+
482
+ | Token | Default |
483
+ | ------------------------------------ | ---------------------------------------- |
484
+ | `--color-accent-text` | the accent, 33% (dark) or 72% (light) toward white or black |
485
+ | `--color-accent-text-hover` | the same at 26% (dark) or 62% (light) |
486
+ | `--color-danger-text` | the danger colour, 30% (dark) or 78% (light) |
487
+
488
+ They are unset by default. The strengths and direction are
489
+ `--glass-accent-text-strength`, `--glass-accent-text-strength-hover`,
490
+ `--glass-danger-text-strength` and `--glass-text-toward`. If you set an accent
491
+ that suits the other theme, such as a pale accent in the light theme, set
492
+ `--color-accent-text` yourself.
493
+
494
+ **What an override owns.** The numbers above are for the library's default
495
+ colours. A `--color-accent`, `--color-danger`, `--color-on-accent`,
496
+ `--color-on-danger`, `--color-accent-text`, `--color-danger-text` or glass fill
497
+ token of your own makes its contrast yours to check. Your values on `:root` for
498
+ `--color-accent-hover`, `--color-danger-hover` and the other shades still apply.
499
+ `--color-accent-hover` and `--color-danger-hover` default to the colour mixed 92%
500
+ with black, because a white label on a lighter shade falls below 4.5:1. The
501
+ default `--color-danger` is `#d23c3c`, the lightest red a white label holds 4.5:1
502
+ on.
503
+
504
+ The active `NavigationLink` has an accent fill of its own and a `--color-on-accent`
505
+ label, like a filled `Button`, so it holds over any page or bar: 4.70 at rest,
506
+ 5.38 on hover and 6.10 when pressed, in both themes and in the reduced-transparency
507
+ and increased-contrast modes. It was white with no fill, 1.00:1 on a light page.
508
+
509
+ Not met: `SymbolImage` icons in the accent colour are non-text and need 3:1: the default blue is 2.2:1
510
+ on `rgb(64, 64, 66)`.
511
+
512
+ ### A wrapper with its own accent
513
+
514
+ `--color-accent-hover`, `-active`, `-10`, `-15`, `-25`, `-50` and
515
+ `--color-danger-hover` and `-active` are worked out on `:root`, where you can
516
+ still override them. Text in the accent or danger colour is worked out in the
517
+ part itself, so a wrapper's colour reaches it without a mark. A wrapper that sets `--color-accent` or `--color-danger`
518
+ inline works them out again from its own colour. A wrapper that sets either
519
+ from a stylesheet cannot be detected, so mark it:
520
+
521
+ ```svelte
522
+ <div class="my-theme glass-accent-scope">...</div>
523
+ ```
524
+
525
+ ```css
526
+ .my-theme {
527
+ --color-accent: #dcdff0;
528
+ --color-on-accent: #0f1014;
529
+ }
530
+ ```
531
+
532
+ Without the mark, the fills for hover and press of a filled or destructive
533
+ button keep the root's colour: with a pale accent and a dark label they measure
534
+ 3.1 to 3.6:1, against 5.2 and above with the mark or an inline colour. Inside
535
+ such a scope the shades follow the wrapper, in place of overrides on
536
+ `:root`. A shade you set on the wrapper itself wins. Without the mark, hover,
537
+ press and wash colours keep the root's colour, which can put your label below
538
+ 4.5:1. `glassProminent` follows the wrapper without a mark.
539
+
309
540
  ## Browser support
310
541
 
311
542
  | Browser | Support |
@@ -137,11 +137,12 @@ export function computeVelocity(samples) {
137
137
  }
138
138
  export function findScrollableAncestor(el, stopAt) {
139
139
  for (var node = el; node && node !== stopAt; node = node.parentElement) {
140
- if (node instanceof HTMLElement) {
140
+ // Overflow first: reading the computed style costs far more, and most
141
+ // elements have nothing to scroll.
142
+ if (node instanceof HTMLElement && node.scrollHeight > node.clientHeight) {
141
143
  var overflowY = getComputedStyle(node).overflowY;
142
- if ((overflowY === 'auto' || overflowY === 'scroll') && node.scrollHeight > node.clientHeight) {
144
+ if (overflowY === 'auto' || overflowY === 'scroll')
143
145
  return node;
144
- }
145
146
  }
146
147
  }
147
148
  return null;
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Moves a keyboard focus ring inside its part when a container would cut it
3
+ * off, such as a flush full width button in a surface with no padding. CSS
4
+ * cannot ask whether an outline is clipped, so it is measured when the part
5
+ * takes focus, and again on a key press while it is unmarked, which can bring
6
+ * the ring out after a click. A clipped part is marked
7
+ * `data-focus-ring="inset"`. Internal.
8
+ */
9
+ /** The four edges of a box, in viewport pixels. */
10
+ export interface Edges {
11
+ top: number;
12
+ right: number;
13
+ bottom: number;
14
+ left: number;
15
+ }
16
+ /** Whether a ring reaching `reach` px outside `box` is cut by any of the clipping boxes. */
17
+ export declare function isRingClipped(box: Edges, clips: readonly Edges[], reach: number): boolean;
18
+ /**
19
+ * Watches `node` for focus and marks the element that draws its ring, which is
20
+ * `node` itself unless `ringOf` names another. Returns a cleanup function.
21
+ */
22
+ export declare function fitFocusRing(node: HTMLElement, ringOf?: (node: HTMLElement) => Element | null): () => void;
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Moves a keyboard focus ring inside its part when a container would cut it
3
+ * off, such as a flush full width button in a surface with no padding. CSS
4
+ * cannot ask whether an outline is clipped, so it is measured when the part
5
+ * takes focus, and again on a key press while it is unmarked, which can bring
6
+ * the ring out after a click. A clipped part is marked
7
+ * `data-focus-ring="inset"`. Internal.
8
+ */
9
+ var ATTRIBUTE = 'data-focus-ring';
10
+ /** Layout rounding that does not show as a clipped ring, in px. */
11
+ var SLACK = 0.5;
12
+ /** Whether a ring reaching `reach` px outside `box` is cut by any of the clipping boxes. */
13
+ export function isRingClipped(box, clips, reach) {
14
+ var needed = reach - SLACK;
15
+ return clips.some(function (clip) {
16
+ return box.top - clip.top < needed ||
17
+ clip.right - box.right < needed ||
18
+ box.bottom - clip.bottom > -needed ||
19
+ box.left - clip.left < needed;
20
+ });
21
+ }
22
+ /**
23
+ * The inner boxes of the ancestors of `element` that clip what sticks out. An
24
+ * axis that does not clip is left unbounded. The page itself is left out.
25
+ */
26
+ function clippingBoxes(element) {
27
+ var boxes = [];
28
+ var body = element.ownerDocument.body;
29
+ // A fixed box slips past the overflow of its ancestors, up to one that holds it.
30
+ var fixed = getComputedStyle(element).position === 'fixed';
31
+ for (var node = element.parentElement; node && node !== body; node = node.parentElement) {
32
+ var style = getComputedStyle(node);
33
+ if (fixed && !holdsFixed(style))
34
+ continue;
35
+ fixed = style.position === 'fixed';
36
+ // An element with no box of its own, such as an inline one, clips nothing.
37
+ if (node.clientWidth === 0 && node.clientHeight === 0)
38
+ continue;
39
+ var across = clips(style.overflowX);
40
+ var down = clips(style.overflowY);
41
+ var rect = node.getBoundingClientRect();
42
+ var left = rect.left + node.clientLeft;
43
+ var top = rect.top + node.clientTop;
44
+ boxes.push({
45
+ top: down ? top : -Infinity,
46
+ right: across ? left + node.clientWidth : Infinity,
47
+ bottom: down ? top + node.clientHeight : Infinity,
48
+ left: across ? left : -Infinity
49
+ });
50
+ }
51
+ return boxes;
52
+ }
53
+ /** Whether an element with this style is the containing block of fixed descendants. */
54
+ function holdsFixed(style) {
55
+ return ([style.transform, style.perspective, style.filter, style.backdropFilter].some(function (value) { return !!value && value !== 'none'; }) ||
56
+ /paint|layout|strict|content/.test(style.contain) ||
57
+ /transform|perspective|filter/.test(style.willChange));
58
+ }
59
+ function clips(overflow) {
60
+ return !!overflow && overflow !== 'visible';
61
+ }
62
+ /** How far the outline drawn on `element` sticks out of it, in px; 0 or less if it does not. */
63
+ function ringReach(element) {
64
+ var style = getComputedStyle(element);
65
+ if (style.outlineStyle === 'none')
66
+ return 0;
67
+ return parseFloat(style.outlineWidth) + parseFloat(style.outlineOffset);
68
+ }
69
+ /**
70
+ * Watches `node` for focus and marks the element that draws its ring, which is
71
+ * `node` itself unless `ringOf` names another. Returns a cleanup function.
72
+ */
73
+ export function fitFocusRing(node, ringOf) {
74
+ if (ringOf === void 0) { ringOf = function (self) { return self; }; }
75
+ var frame;
76
+ function measure() {
77
+ var ring = ringOf(node);
78
+ if (!ring)
79
+ return;
80
+ var reach = ringReach(ring);
81
+ if (reach > 0 && isRingClipped(ring.getBoundingClientRect(), clippingBoxes(ring), reach)) {
82
+ ring.setAttribute(ATTRIBUTE, 'inset');
83
+ }
84
+ }
85
+ function reset() {
86
+ var _a;
87
+ if (frame !== undefined)
88
+ cancelAnimationFrame(frame);
89
+ frame = undefined;
90
+ (_a = ringOf(node)) === null || _a === void 0 ? void 0 : _a.removeAttribute(ATTRIBUTE);
91
+ }
92
+ function schedule() {
93
+ reset();
94
+ // A frame later, once the browser has scrolled the part into view.
95
+ if (typeof requestAnimationFrame === 'function')
96
+ frame = requestAnimationFrame(measure);
97
+ else
98
+ measure();
99
+ }
100
+ // :focus-visible can start matching on a key press, with no new focus event.
101
+ function onKeyDown() {
102
+ var _a;
103
+ if (!((_a = ringOf(node)) === null || _a === void 0 ? void 0 : _a.hasAttribute(ATTRIBUTE)))
104
+ schedule();
105
+ }
106
+ node.addEventListener('focus', schedule);
107
+ node.addEventListener('keydown', onKeyDown);
108
+ node.addEventListener('blur', reset);
109
+ return function () {
110
+ reset();
111
+ node.removeEventListener('focus', schedule);
112
+ node.removeEventListener('keydown', onKeyDown);
113
+ node.removeEventListener('blur', reset);
114
+ };
115
+ }
@@ -20,6 +20,13 @@ export var FOCUSABLE_SELECTOR = [
20
20
  ].join(',');
21
21
  /** True when the element can take focus by Tab: not disabled, hidden or inert, and not tabindex -1. */
22
22
  export function isTabbable(element) {
23
+ return tabbableWith(element, new Map());
24
+ }
25
+ /**
26
+ * isTabbable, remembering in `hidden` whether each node is `display: none`, so
27
+ * that elements checked together read each shared ancestor's style only once.
28
+ */
29
+ function tabbableWith(element, hidden) {
23
30
  if (element.tabIndex < 0 || element.matches(':disabled, input[type="hidden"]'))
24
31
  return false;
25
32
  if (element.closest('[inert], [hidden]'))
@@ -30,18 +37,30 @@ export function isTabbable(element) {
30
37
  if (view.getComputedStyle(element).visibility === 'hidden')
31
38
  return false;
32
39
  for (var node = element; node; node = node.parentElement) {
33
- if (view.getComputedStyle(node).display === 'none')
40
+ var none = hidden.get(node);
41
+ if (none === undefined) {
42
+ none = view.getComputedStyle(node).display === 'none';
43
+ hidden.set(node, none);
44
+ }
45
+ if (none)
34
46
  return false;
35
47
  }
36
48
  return true;
37
49
  }
50
+ function tabbableAmong(elements) {
51
+ var hidden = new Map();
52
+ return elements.filter(function (element) { return tabbableWith(element, hidden); });
53
+ }
38
54
  /**
39
55
  * Where Tab should send focus, or `null` to let the browser move it as usual.
40
56
  * Wraps from the last tabbable element to the first (and back for Shift+Tab),
41
57
  * and pulls focus in when it is on the container itself or outside the list.
42
58
  */
43
59
  export function nextFocusTarget(focusables, active, direction) {
44
- var tabbable = focusables.filter(isTabbable);
60
+ return edgeTarget(tabbableAmong(focusables), active, direction);
61
+ }
62
+ /** nextFocusTarget over elements already known to be tabbable. */
63
+ function edgeTarget(tabbable, active, direction) {
45
64
  var first = tabbable[0];
46
65
  var last = tabbable[tabbable.length - 1];
47
66
  if (!first || !last)
@@ -70,12 +89,13 @@ export function trapTab(event, container) {
70
89
  return;
71
90
  var focusables = Array.from(container.querySelectorAll(FOCUSABLE_SELECTOR));
72
91
  var direction = event.shiftKey ? 'backward' : 'forward';
73
- if (!focusables.some(isTabbable)) {
92
+ var tabbable = tabbableAmong(focusables);
93
+ if (tabbable.length === 0) {
74
94
  event.preventDefault();
75
95
  container.focus({ preventScroll: true });
76
96
  return;
77
97
  }
78
- var target = nextFocusTarget(focusables, container.ownerDocument.activeElement, direction);
98
+ var target = edgeTarget(tabbable, container.ownerDocument.activeElement, direction);
79
99
  if (!target)
80
100
  return;
81
101
  event.preventDefault();
@@ -6,7 +6,8 @@
6
6
  * `view-transition-name` animate between their old and new positions.
7
7
  *
8
8
  * Falls through to invoking the callback directly when the API is
9
- * unavailable (SSR, older browsers, or Firefox behind a flag).
9
+ * unavailable (SSR, older browsers, or Firefox behind a flag), and under
10
+ * reduced motion.
10
11
  */
11
12
  type ViewTransitionLike = {
12
13
  finished: Promise<void>;
@@ -6,8 +6,10 @@
6
6
  * `view-transition-name` animate between their old and new positions.
7
7
  *
8
8
  * Falls through to invoking the callback directly when the API is
9
- * unavailable (SSR, older browsers, or Firefox behind a flag).
9
+ * unavailable (SSR, older browsers, or Firefox behind a flag), and under
10
+ * reduced motion.
10
11
  */
12
+ import { prefersReducedMotion } from './reducedMotion';
11
13
  export function withGlassTransition(callback) {
12
14
  if (typeof document === 'undefined') {
13
15
  var result = callback();
@@ -17,7 +19,7 @@ export function withGlassTransition(callback) {
17
19
  return { supported: false };
18
20
  }
19
21
  var doc = document;
20
- if (typeof doc.startViewTransition !== 'function') {
22
+ if (typeof doc.startViewTransition !== 'function' || prefersReducedMotion()) {
21
23
  var result = callback();
22
24
  if (result instanceof Promise) {
23
25
  return result.then(function () { return ({ supported: false }); });
@@ -53,6 +53,10 @@
53
53
  const cfg = $derived(INTENSITY_CONFIG[intensity] ?? INTENSITY_CONFIG[DEFAULT_INTENSITY]);
54
54
  const vcfg = $derived(VARIANT_CONFIG[variant] ?? VARIANT_CONFIG[DEFAULT_VARIANT]);
55
55
  const shapeStyle = $derived(glassShapeStyle(shape, cornerRadius));
56
+ // Marks a surface that shows the tint, not a background of the page's own.
57
+ const hasTint = $derived(
58
+ !!tint && !/(^|;)\s*background(-color|-image)?\s*:/i.test(customStyle)
59
+ );
56
60
  </script>
57
61
 
58
62
  {#if motion}
@@ -60,6 +64,7 @@
60
64
  class="glass-surface {variant} {className}"
61
65
  data-glass-shape={shape}
62
66
  class:has-lensing={cfg.displacementScale > 0}
67
+ class:has-tint={hasTint}
63
68
  class:has-shadow={shadow}
64
69
  class:is-interactive={interactive}
65
70
  {@attach fromAction(deviceMotion, () => ({}))}
@@ -84,6 +89,7 @@
84
89
  class="glass-surface {variant} {className}"
85
90
  data-glass-shape={shape}
86
91
  class:has-lensing={cfg.displacementScale > 0}
92
+ class:has-tint={hasTint}
87
93
  class:has-shadow={shadow}
88
94
  class:is-interactive={interactive}
89
95
  style="
@@ -219,4 +225,54 @@
219
225
  .glass-surface.is-interactive:active {
220
226
  transform: scale(calc(1 - 0.005 * var(--glass-motion-enabled)));
221
227
  }
228
+
229
+ /* Reduced transparency: no blur, no lens and no blended highlight. Glass writes
230
+ its effect values inline, where no token can reach them, so the properties
231
+ that read them are replaced. The tokens make the background solid, and the
232
+ empty ::before layer goes, so contrast checkers can read it.
233
+ A tint is see-through, so a tinted surface paints it over an opaque base;
234
+ otherwise the background is left alone, so one of the page's own still wins.
235
+ :where keeps each rule as specific as the one it replaces. */
236
+ @media (prefers-reduced-transparency: reduce) {
237
+ .glass-surface:where(:not(.has-tint))::before {
238
+ content: none;
239
+ }
240
+ .glass-surface::before {
241
+ backdrop-filter: none;
242
+ -webkit-backdrop-filter: none;
243
+ }
244
+ .glass-surface.has-lensing::before {
245
+ filter: none;
246
+ }
247
+ .glass-surface::after {
248
+ background: none;
249
+ mix-blend-mode: normal;
250
+ }
251
+ .glass-surface:where(.has-tint) {
252
+ background: rgb(var(--glass-surface-color, 28, 28, 30));
253
+ }
254
+ .glass-surface:where(.has-tint)::before {
255
+ background: var(--glass-surface-bg);
256
+ }
257
+ }
258
+ :global(:where([data-reduced-transparency='true'])) .glass-surface:where(:not(.has-tint))::before {
259
+ content: none;
260
+ }
261
+ :global(:where([data-reduced-transparency='true'])) .glass-surface::before {
262
+ backdrop-filter: none;
263
+ -webkit-backdrop-filter: none;
264
+ }
265
+ :global(:where([data-reduced-transparency='true'])) .glass-surface.has-lensing::before {
266
+ filter: none;
267
+ }
268
+ :global(:where([data-reduced-transparency='true'])) .glass-surface::after {
269
+ background: none;
270
+ mix-blend-mode: normal;
271
+ }
272
+ :global(:where([data-reduced-transparency='true'])) .glass-surface:where(.has-tint) {
273
+ background: rgb(var(--glass-surface-color, 28, 28, 30));
274
+ }
275
+ :global(:where([data-reduced-transparency='true'])) .glass-surface:where(.has-tint)::before {
276
+ background: var(--glass-surface-bg);
277
+ }
222
278
  </style>
@@ -35,8 +35,29 @@
35
35
  /* View Transitions needs a rendered box, so no display: contents here.
36
36
  Keep this wrapper transparent to layout by inheriting flow. */
37
37
  display: inline;
38
+ view-transition-class: glass-morph;
38
39
  }
39
40
  .glass-morph:where(div, section) {
40
41
  display: block;
41
42
  }
43
+
44
+ /* Under reduced motion a morph jumps to its new place, including in a view
45
+ transition the page starts itself. The old snapshot is hidden so it cannot
46
+ show over the new one while the rest of the page cross fades. */
47
+ @media (prefers-reduced-motion: reduce) {
48
+ :global(::view-transition-group(*.glass-morph)),
49
+ :global(::view-transition-new(*.glass-morph)) {
50
+ animation: none;
51
+ }
52
+ :global(::view-transition-old(*.glass-morph)) {
53
+ display: none;
54
+ }
55
+ }
56
+ :global(:root[data-reduced-motion='true']::view-transition-group(*.glass-morph)),
57
+ :global(:root[data-reduced-motion='true']::view-transition-new(*.glass-morph)) {
58
+ animation: none;
59
+ }
60
+ :global(:root[data-reduced-motion='true']::view-transition-old(*.glass-morph)) {
61
+ display: none;
62
+ }
42
63
  </style>