glasslikeui 1.7.0 → 1.9.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
@@ -164,8 +164,21 @@ to mirror all of these onto an ancestor that your strip can read.
164
164
  ```
165
165
 
166
166
  A sheet with a `title` shows a header with the title centred and an icon-only
167
- close button (`aria-label="Close"`) at the trailing side. The sheet is a modal
168
- `dialog`, labelled by its title (or by an `aria-label` when there is none).
167
+ close button (`aria-label="Close"`) at the leading side, as on iOS 26 sheets.
168
+ The sheet is a modal `dialog`, labelled by its title (or by an `aria-label`
169
+ when there is none).
170
+
171
+ - `closePlacement` picks the side of the close button: `'leading'` (the
172
+ default) or `'trailing'`, the placement before 1.9. The sides are logical:
173
+ under `dir="rtl"` leading is the right. The button moves in the DOM as well,
174
+ so Tab reaches it first in the header when it leads. The title stays centred
175
+ either way. The header carries `data-close-placement` with the value in use.
176
+
177
+ ```svelte
178
+ <Sheet bind:isOpen title="Options" closePlacement="trailing">
179
+ {#snippet children()}...{/snippet}
180
+ </Sheet>
181
+ ```
169
182
 
170
183
  - Dragging the handle or the header moves the sheet between its detents.
171
184
  Presses on the close button or on interactive content never start a drag.
@@ -181,6 +194,10 @@ close button (`aria-label="Close"`) at the trailing side. The sheet is a modal
181
194
  the sheet. Anything shorter snaps back. Set `interactiveDismissDisabled`
182
195
  to turn this off, mirroring SwiftUI. The close button, Escape and the
183
196
  backdrop still close the sheet.
197
+ - The sheet is a viewport tall and slides down to its detent. The content area
198
+ ends at the bottom of the screen at every detent, so the end of long content
199
+ can be scrolled into view. It resizes when a drag snaps. Remove any
200
+ `margin-bottom` you added to `.sheet-content` to work around this.
184
201
  - Every close path (button, Escape, backdrop, drag, or the parent setting
185
202
  `isOpen` to `false`) slides the sheet down and fades the backdrop before
186
203
  it unmounts. `isOpen` turns false and `onClose` fires when the close
@@ -280,13 +297,112 @@ restored exactly when it closes. Ancestors are never made inert, and anything
280
297
  you had already made inert stays inert. Tab and Shift+Tab wrap inside the
281
298
  sheet, and focus returns to the element that opened it.
282
299
 
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.
300
+ Under reduced transparency (the media query, or
301
+ `data-reduced-transparency="true"` on `:root` or on any element around the
302
+ parts, in both themes):
303
+
304
+ - `Glass`, and everything built on it, loses its blur, lens filter and blended
305
+ highlight. `--glass-opacity` becomes 1, so the default background is solid
306
+ `--glass-surface-color`, and a `tint` is painted over a solid base of that
307
+ colour. A background of your own that works normally works here too, and so
308
+ does your own `--glass-surface-bg`: both are left as you set them, see-through
309
+ ones included, so keep them opaque enough for their text.
310
+ - To recolour surfaces, set `--glass-surface-color` on `:root`. To recolour one
311
+ surface, set `--glass-surface-bg` or `tint` on it. `--glass-surface-color` set
312
+ on a single surface does not change its default background, with or without
313
+ reduced transparency, because `--glass-surface-bg` is resolved on `:root`.
314
+ - Glass `Button`s lose their blur and get a solid fill. `glassProminent`
315
+ becomes solid accent with its `--color-on-accent` label.
316
+ - `Sheet` turns its blur off, including the backdrop blur
317
+ (`--glass-backdrop-blur`), and its background becomes near opaque
318
+ (`--glass-sheet-bg` at 0.98 alpha). `Menu` goes opaque with it.
319
+ - `NavigationBar` becomes near opaque too (`--glass-nav-bg` at 0.98 alpha).
320
+
321
+ The empty `::before` layer is removed from `Glass` and glass `Button`s, so a
322
+ `::before` rule of your own for the fill cannot cover the solid one, and
323
+ contrast checkers can read the background. A tinted `Glass` keeps the layer to
324
+ paint its tint, so a checker may report its text as incomplete.
325
+
326
+ On an element inside the page, the attribute also makes `--glass-surface-bg`
327
+ solid `--glass-surface-color` there, in place of a value you set on `:root`, and
328
+ the light theme is still read from `:root`. To switch the preference for the
329
+ whole page, put the attribute on `:root`.
330
+
331
+ With the media query, the library's values (`--glass-opacity`, the blurs,
332
+ `--glass-sheet-bg` and `--glass-nav-bg`) are declared on `:root:root`, so your
333
+ plain `:root` values for them do not keep sheets and bars see-through before any
334
+ script has run. A selector of the same weight loaded later, such as
335
+ `:root[data-theme='dark']`, or a heavier one, still wins, so give such rules
336
+ solid values under the media query. To use your own solid colours there,
337
+ outrank the library:
338
+
339
+ ```css
340
+ @media (prefers-reduced-transparency: reduce) {
341
+ :root:root:root {
342
+ --glass-sheet-bg: #101820;
343
+ --glass-nav-bg: #101820;
344
+ }
345
+ }
346
+ ```
347
+
348
+ No `!important` is needed. `Glass` still sets `--glass-blur` and the other
349
+ effect values inline; the rules replace the properties that read them. Asking
350
+ for more contrast at the same time leaves surfaces solid.
351
+
352
+ Under reduced motion, `withGlassTransition` runs the update with no view
353
+ transition and returns `{ supported: false }`, and `GlassMorph` elements do not
354
+ animate even in a view transition you start yourself.
355
+
356
+ A `Button` with `href` and `disabled` renders a link with no `href`, marked
357
+ `aria-disabled="true"`. It cannot be focused or followed and does not call
358
+ `onclick`.
359
+
360
+ ### Focus ring
361
+
362
+ The library's buttons, links, rows, tabs, menu items and switch draw one shared
363
+ ring for keyboard users. Restyle the rings with these tokens, set on `:root` or
364
+ on any ancestor:
365
+
366
+ | Token | Default |
367
+ | ------------------------------- | ------------------------------------ |
368
+ | `--glass-focus-ring-color` | `#9ecbff` dark, `#00408a` light |
369
+ | `--glass-focus-ring-halo-color` | `#000000` dark, `#ffffff` light |
370
+ | `--glass-focus-ring-width` | `2px` |
371
+ | `--glass-focus-ring-offset` | `2px` |
372
+
373
+ The ring has two tones, because no single colour holds 3:1 against every
374
+ backdrop: the outline, and a halo that fills the gap inside it (inside the
375
+ outline on `ListRow` and `MenuItem`). With the defaults, one tone or the other
376
+ holds 3:1 against any backdrop. If you change either colour, keep the two at
377
+ least 9:1 apart, or set the halo to `transparent` and check the single ring
378
+ against your backgrounds. The four tokens are unset by default (the per theme
379
+ colours live in the `-default` tokens), so a value you set wins in both themes.
380
+ The halo is a `box-shadow`. On `Button` it has to outrank the variant shadows, so
381
+ a `box-shadow` of yours needs more than two classes to replace it there. `ListRow` and `MenuItem` sit in clipping containers, so their ring
382
+ is always drawn inside, offset by minus the width. The colour, width and style
383
+ rules have zero specificity, so any focus rule of your own beats them. The
384
+ inward offsets are the exception, so that an ordinary
385
+ `:focus-visible { outline-offset: 2px }` of yours cannot push a ring out where
386
+ it is cut off. Their selectors weigh two classes on `ListRow` and `MenuItem`,
387
+ three on a part marked `data-focus-ring="inset"` and four on a `Toggle` track
388
+ marked that way. To change one on purpose, use a heavier selector.
389
+
390
+ A container that clips can also cut off the ring of a part flush against its
391
+ edge: a full width `Button` in `<Glass padding="none">`, in a `ScrollView` or at
392
+ the top of `Sheet` content. When `Button`, `IconButton`, a `TabView` item,
393
+ `NavigationLink`, the `Menu` trigger or `Toggle` takes focus with no room for
394
+ its ring, it sets `data-focus-ring="inset"` and draws the ring inside, in its
395
+ label colour unless `--glass-focus-ring-color` is set. A colour you set should
396
+ then stand out on the part's own fill as well as on the page. This is measured
397
+ when the part takes focus.
286
398
 
287
399
  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.
400
+ dark and the light sheet. It follows the shared width and offset, and
401
+ `--glass-focus-ring-color`, when set on any ancestor, replaces its outer tone.
402
+ Without that, `--sheet-focus-ring-outer` colours the outline, and
403
+ `--sheet-focus-ring-inner` the ring against the button. To give this button its
404
+ own colour while a shared one is set, set `--glass-focus-ring-color` on
405
+ `.sheet-close-btn`.
290
406
 
291
407
  ## Theming
292
408
 
@@ -306,6 +422,134 @@ Override any token via your own stylesheet, e.g.:
306
422
  }
307
423
  ```
308
424
 
425
+ ### Component tokens
426
+
427
+ These are unset by default, so you can set them on `:root` or on any ancestor.
428
+
429
+ | Token | Used by | Default |
430
+ | ------------------------- | ------------------------------------------------- | --------------------- |
431
+ | `--glass-track-checked` | The checked `Toggle` track. | `--color-accent` |
432
+ | `--color-on-accent` | Labels on accent fills: filled `Button`, filled `IconButton` and `glassProminent`. | `white` |
433
+ | `--color-on-danger` | The `destructive` `Button` label. | `white` |
434
+ | `--glass-sheet-max-width` | `Sheet` width cap on viewports from 769px. | `900px` |
435
+ | `--glass-button-fill` | The resting fill of the plain `glass` `Button`. You own its contrast. | see below |
436
+ | `--glass-button-fill-hover` | Its hover fill. | `--glass-button-fill`, else the library hover fill |
437
+ | `--glass-button-fill-active` | Its pressed fill. | `--glass-button-fill`, else the library pressed fill |
438
+
439
+ ```css
440
+ .my-sheet {
441
+ --glass-sheet-max-width: 1100px;
442
+ }
443
+ ```
444
+
445
+ If you change `--color-accent` or `--color-danger` to a light colour, set the
446
+ matching label token and check for 4.5:1.
447
+
448
+ `glassProminent` fills with `--color-accent`, shaded toward black and slightly
449
+ see-through (84% opaque, a little darker on hover and again when pressed), with
450
+ a `--color-on-accent` label. With the default colours the label holds at least
451
+ 4.5:1 over any backdrop. Your own pair needs more room than on a solid fill:
452
+ the shade darkens the accent and the backdrop shows through, so check it over
453
+ both black and white.
454
+
455
+ The plain `glass` `Button` is see-through, and its default label holds 4.5:1
456
+ (WCAG 2.2 AA) at rest, on hover and when pressed, over any backdrop, in both
457
+ themes: smoked glass under a light label in the dark theme, and white glass,
458
+ 55% opaque or more, under a dark label in the light one. This takes your
459
+ `--color-text` to be light in the dark theme (about `#f5f5f7`) and dark in the
460
+ light theme (about `#1d1d1f`); the library does not set it. The button's edge
461
+ can be faint against a backdrop of a similar grey.
462
+
463
+ Change the fill with `--glass-button-fill` and, if you want hover and press
464
+ feedback with it, the `-hover` and `-active` tokens. A fill of your own owns its
465
+ contrast: check the label against it over your lightest and darkest backdrops.
466
+ Reduced transparency ignores all three. Use them instead of styling the
467
+ button's `::before`.
468
+
469
+ ### Text and fill colours (WCAG 2.2 AA)
470
+
471
+ With the default colours, the labels of these hold 4.5:1 (WCAG 2.2 AA 1.4.3) at
472
+ rest, on hover and when pressed, measured from painted pixels in Chromium and
473
+ WebKit.
474
+
475
+ Solid fills, over any backdrop: `filled` `Button` and `IconButton` (4.70 rest,
476
+ 5.38 hover and press at the lowest), `destructive` `Button` (4.72, 5.43, 6.11),
477
+ `glassProminent` and the plain `glass` `Button` (see above).
478
+
479
+ See-through variants, over the surfaces of their theme: `outlined`, `plain` and
480
+ `tinted` `Button`s, accent `Badge`, the active `TabView` item, `Text` with
481
+ `color="accent"` or `"danger"`, and a destructive `MenuItem`. The lowest measured
482
+ over the dark theme's black, `rgb(28, 28, 30)`, `rgb(53, 53, 55)` and
483
+ `rgb(64, 64, 66)`, and the light theme's white, `rgb(242, 242, 247)` and
484
+ `rgb(224, 224, 224)`, is 4.87:1. They do not hold over every backdrop, and no
485
+ colour can: text that contrasts with both black and white fails against a grey
486
+ or saturated colour in between. Over white in the dark theme, black in the light
487
+ theme or a saturated colour they measure from 1.0 to 1.3:1. Use `filled`,
488
+ `glassProminent` or `glass` over busy backdrops.
489
+
490
+ Text in the accent or danger colour is the colour mixed toward white in the dark
491
+ theme and toward black in the light one, worked out from `--color-accent` or
492
+ `--color-danger` where the part is, so it follows a wrapper's own colour with
493
+ nothing to mark:
494
+
495
+ | Token | Default |
496
+ | ------------------------------------ | ---------------------------------------- |
497
+ | `--color-accent-text` | the accent, 33% (dark) or 72% (light) toward white or black |
498
+ | `--color-accent-text-hover` | the same at 26% (dark) or 62% (light) |
499
+ | `--color-danger-text` | the danger colour, 30% (dark) or 78% (light) |
500
+
501
+ They are unset by default. The strengths and direction are
502
+ `--glass-accent-text-strength`, `--glass-accent-text-strength-hover`,
503
+ `--glass-danger-text-strength` and `--glass-text-toward`. If you set an accent
504
+ that suits the other theme, such as a pale accent in the light theme, set
505
+ `--color-accent-text` yourself.
506
+
507
+ **What an override owns.** The numbers above are for the library's default
508
+ colours. A `--color-accent`, `--color-danger`, `--color-on-accent`,
509
+ `--color-on-danger`, `--color-accent-text`, `--color-danger-text` or glass fill
510
+ token of your own makes its contrast yours to check. Your values on `:root` for
511
+ `--color-accent-hover`, `--color-danger-hover` and the other shades still apply.
512
+ `--color-accent-hover` and `--color-danger-hover` default to the colour mixed 92%
513
+ with black, because a white label on a lighter shade falls below 4.5:1. The
514
+ default `--color-danger` is `#d23c3c`, the lightest red a white label holds 4.5:1
515
+ on.
516
+
517
+ The active `NavigationLink` has an accent fill of its own and a `--color-on-accent`
518
+ label, like a filled `Button`, so it holds over any page or bar: 4.70 at rest,
519
+ 5.38 on hover and 6.10 when pressed, in both themes and in the reduced-transparency
520
+ and increased-contrast modes. It was white with no fill, 1.00:1 on a light page.
521
+
522
+ Not met: `SymbolImage` icons in the accent colour are non-text and need 3:1: the default blue is 2.2:1
523
+ on `rgb(64, 64, 66)`.
524
+
525
+ ### A wrapper with its own accent
526
+
527
+ `--color-accent-hover`, `-active`, `-10`, `-15`, `-25`, `-50` and
528
+ `--color-danger-hover` and `-active` are worked out on `:root`, where you can
529
+ still override them. Text in the accent or danger colour is worked out in the
530
+ part itself, so a wrapper's colour reaches it without a mark. A wrapper that sets `--color-accent` or `--color-danger`
531
+ inline works them out again from its own colour. A wrapper that sets either
532
+ from a stylesheet cannot be detected, so mark it:
533
+
534
+ ```svelte
535
+ <div class="my-theme glass-accent-scope">...</div>
536
+ ```
537
+
538
+ ```css
539
+ .my-theme {
540
+ --color-accent: #dcdff0;
541
+ --color-on-accent: #0f1014;
542
+ }
543
+ ```
544
+
545
+ Without the mark, the fills for hover and press of a filled or destructive
546
+ button keep the root's colour: with a pale accent and a dark label they measure
547
+ 3.1 to 3.6:1, against 5.2 and above with the mark or an inline colour. Inside
548
+ such a scope the shades follow the wrapper, in place of overrides on
549
+ `:root`. A shade you set on the wrapper itself wins. Without the mark, hover,
550
+ press and wash colours keep the root's colour, which can put your label below
551
+ 4.5:1. `glassProminent` follows the wrapper without a mark.
552
+
309
553
  ## Browser support
310
554
 
311
555
  | 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>