glasslikeui 1.6.1 → 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.
Files changed (46) hide show
  1. package/LICENSE +373 -674
  2. package/README.md +299 -4
  3. package/dist/actions/dragSnap.d.ts +16 -39
  4. package/dist/actions/dragSnap.js +6 -224
  5. package/dist/actions/dragSnapMath.d.ts +68 -0
  6. package/dist/actions/dragSnapMath.js +166 -0
  7. package/dist/actions/dragSurface.d.ts +26 -0
  8. package/dist/actions/dragSurface.js +187 -0
  9. package/dist/actions/focusRingFit.d.ts +22 -0
  10. package/dist/actions/focusRingFit.js +115 -0
  11. package/dist/actions/focusTrap.d.ts +22 -0
  12. package/dist/actions/focusTrap.js +103 -0
  13. package/dist/actions/index.d.ts +3 -0
  14. package/dist/actions/index.js +3 -0
  15. package/dist/actions/inertSiblings.d.ts +10 -0
  16. package/dist/actions/inertSiblings.js +35 -0
  17. package/dist/actions/reducedMotion.d.ts +25 -0
  18. package/dist/actions/reducedMotion.js +26 -0
  19. package/dist/actions/sheetBodyDrag.d.ts +14 -0
  20. package/dist/actions/sheetBodyDrag.js +26 -0
  21. package/dist/actions/sheetExit.d.ts +36 -0
  22. package/dist/actions/sheetExit.js +65 -0
  23. package/dist/actions/swipeActions.d.ts +14 -5
  24. package/dist/actions/swipeActions.js +89 -16
  25. package/dist/actions/viewTransition.d.ts +2 -1
  26. package/dist/actions/viewTransition.js +4 -2
  27. package/dist/components/glass/Glass.svelte +97 -6
  28. package/dist/components/glass/GlassMorph.svelte +21 -0
  29. package/dist/components/glass/Sheet.svelte +243 -61
  30. package/dist/components/glass/Sheet.svelte.d.ts +7 -1
  31. package/dist/components/interactive/Badge.svelte +2 -1
  32. package/dist/components/interactive/Button.svelte +164 -18
  33. package/dist/components/interactive/IconButton.svelte +23 -1
  34. package/dist/components/interactive/TabView.svelte +24 -1
  35. package/dist/components/interactive/Toggle.svelte +22 -4
  36. package/dist/components/layout/ScrollView.svelte +6 -0
  37. package/dist/components/list/ListRow.svelte +43 -9
  38. package/dist/components/menu/Menu.svelte +23 -0
  39. package/dist/components/menu/MenuItem.svelte +15 -2
  40. package/dist/components/navigation/NavigationLink.svelte +38 -2
  41. package/dist/components/typography/Text.svelte +2 -2
  42. package/dist/constants/shapes.d.ts +7 -0
  43. package/dist/constants/shapes.js +16 -0
  44. package/dist/styles/glasslikeui.css +143 -15
  45. package/dist/styles/lens.css +77 -0
  46. package/package.json +2 -2
@@ -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="
@@ -151,17 +157,52 @@
151
157
  mix-blend-mode: overlay;
152
158
  }
153
159
 
154
- /* A circular surface centres its content; a square box would not. */
155
- .glass-surface[data-glass-shape='circle'] .glass-content {
160
+ .glass-content {
161
+ position: relative;
162
+ z-index: 2;
163
+ height: 100%;
164
+ }
165
+
166
+ /* Control shapes centre their content on both axes. The surface does the
167
+ centring rather than a percentage height on .glass-content: WebKit
168
+ resolves that percentage against the aspect-ratio box without removing
169
+ the padding, so the content overflowed and a circle label sat one
170
+ padding-width below centre. :where keeps callers able to override. */
171
+ :where(.glass-surface[data-glass-shape='capsule']),
172
+ :where(.glass-surface[data-glass-shape='circle']) {
156
173
  display: flex;
157
174
  align-items: center;
158
175
  justify-content: center;
159
176
  }
160
177
 
161
- .glass-content {
162
- position: relative;
163
- z-index: 2;
164
- height: 100%;
178
+ :where(.glass-surface[data-glass-shape='capsule']) > .glass-content,
179
+ :where(.glass-surface[data-glass-shape='circle']) > .glass-content {
180
+ height: auto;
181
+ min-width: 0;
182
+ max-width: 100%;
183
+ text-align: center;
184
+ }
185
+
186
+ :where(.glass-surface[data-glass-shape='circle']) > .glass-content {
187
+ display: flex;
188
+ align-items: center;
189
+ justify-content: center;
190
+ }
191
+
192
+ /* A rect surface holding one text-level child (see GLASS_LONE_LABEL_ELEMENTS)
193
+ centres it the same way. The :has() guard keeps panels, cards and stacks,
194
+ whose child is a div or several children, laid out exactly as before. */
195
+ :where(.glass-surface:has(> .glass-content > :global(:where(span, label, strong, b, em, small, svg, img):only-child))) {
196
+ display: flex;
197
+ align-items: center;
198
+ justify-content: center;
199
+ }
200
+
201
+ :where(.glass-surface:has(> .glass-content > :global(:where(span, label, strong, b, em, small, svg, img):only-child))) > .glass-content {
202
+ height: auto;
203
+ min-width: 0;
204
+ max-width: 100%;
205
+ text-align: center;
165
206
  }
166
207
 
167
208
  .glass-surface.has-shadow {
@@ -184,4 +225,54 @@
184
225
  .glass-surface.is-interactive:active {
185
226
  transform: scale(calc(1 - 0.005 * var(--glass-motion-enabled)));
186
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
+ }
187
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>
@@ -1,14 +1,27 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
3
  import { fromAction } from 'svelte/attachments';
4
- import { HStack, Spacer } from '../layout';
4
+ import { getIconPath } from '../../icons';
5
+ import { dragSurface } from '../../actions/dragSurface';
5
6
  import {
6
- dragSnap,
7
7
  detentFractions,
8
+ isDragStartAllowed,
9
+ sheetYForFraction,
10
+ detentAt,
8
11
  type SheetDetentName
9
- } from '../../actions/dragSnap';
12
+ } from '../../actions/dragSnapMath';
13
+ import { startSheetExit, type SheetExit } from '../../actions/sheetExit';
14
+ import { inertSiblings } from '../../actions/inertSiblings';
15
+ import { trapTab } from '../../actions/focusTrap';
10
16
 
11
- const isBrowser = typeof window !== 'undefined';
17
+ /** The parts of the sheet a drag starts from on the press: the handle and the header. */
18
+ const DRAG_REGIONS = '.sheet-handle-container, .sheet-header';
19
+
20
+ /**
21
+ * The body, where a press only arms a drag that starts once it pulls down
22
+ * with the content at the top, so taps and scrolling there keep working.
23
+ */
24
+ const BODY_DRAG_REGION = '.sheet-content';
12
25
 
13
26
  interface Props {
14
27
  isOpen?: boolean;
@@ -20,6 +33,12 @@
20
33
  initialDetent?: SheetDetentName;
21
34
  showHandle?: boolean;
22
35
  draggable?: boolean;
36
+ /**
37
+ * Turns off drag to dismiss, mirroring SwiftUI's interactiveDismissDisabled.
38
+ * Dragging below the smallest detent then rubber-bands and snaps back. The
39
+ * close button, Escape and the backdrop still close the sheet.
40
+ */
41
+ interactiveDismissDisabled?: boolean;
23
42
  class?: string;
24
43
  }
25
44
 
@@ -33,29 +52,77 @@
33
52
  initialDetent = 'medium',
34
53
  showHandle = true,
35
54
  draggable = true,
55
+ interactiveDismissDisabled = false,
36
56
  class: className = ''
37
57
  }: Props = $props();
38
58
 
59
+ const uid = $props.id();
60
+ const titleId = `${uid}-title`;
61
+
39
62
  const fractions = $derived(detentFractions(detents));
40
63
  const initialIndex = $derived(Math.max(0, detents.indexOf(initialDetent)));
41
64
 
42
65
  let currentIndex = $derived(initialIndex);
43
66
  let sheetEl = $state<HTMLElement | undefined>();
44
67
 
68
+ // The sheet stays in the DOM after isOpen turns false, for as long as its exit
69
+ // animation runs. `mounted` is set once it has been shown and cleared when the
70
+ // exit completes.
71
+ let mounted = $state(false);
72
+ let exit: SheetExit | null = null;
73
+ let opener: Element | null = null;
74
+ let releaseInert: (() => void) | null = null;
75
+
76
+ const present = $derived(isOpen || mounted);
77
+ const sheetState = $derived(isOpen ? 'open' : 'closing');
78
+
79
+ /** Slide the sheet away, then unmount. Safe to call more than once. */
80
+ function beginExit() {
81
+ if (exit) return;
82
+ if (!sheetEl) {
83
+ finishExit();
84
+ return;
85
+ }
86
+ let done = false;
87
+ const handle = startSheetExit({
88
+ element: sheetEl,
89
+ restoreY: sheetYForFraction(detentAt(fractions, currentIndex)),
90
+ onDone: () => {
91
+ done = true;
92
+ finishExit();
93
+ }
94
+ });
95
+ // Under reduced motion onDone has already run, so there is nothing to track.
96
+ if (!done) exit = handle;
97
+ }
98
+
99
+ function finishExit() {
100
+ exit = null;
101
+ mounted = false;
102
+ // The opener sits behind the sheet, so it cannot take focus until the page
103
+ // is no longer inert.
104
+ releaseInert?.();
105
+ if (opener instanceof HTMLElement && opener.isConnected) opener.focus({ preventScroll: true });
106
+ opener = null;
107
+ }
108
+
45
109
  function close() {
110
+ // A closed or already closing sheet ignores repeat requests, so onClose
111
+ // fires exactly once per close.
112
+ if (!isOpen || exit) return;
113
+ beginExit();
46
114
  isOpen = false;
47
115
  onClose?.();
48
- if (isBrowser) {
49
- document.body.style.overflow = '';
50
- }
51
116
  }
52
117
 
53
118
  function handleKeydown(e: KeyboardEvent) {
54
119
  // The window listener is always attached, so a closed sheet would
55
- // otherwise fire onClose - and clear body overflow - on every Escape.
120
+ // otherwise fire onClose on every Escape.
56
121
  if (!isOpen) return;
57
122
  if (e.key === 'Escape') {
58
123
  close();
124
+ } else if (e.key === 'Tab' && sheetEl) {
125
+ trapTab(e, sheetEl);
59
126
  }
60
127
  }
61
128
 
@@ -71,22 +138,84 @@
71
138
  if (name) onDetentChange?.(name);
72
139
  }
73
140
 
141
+ function canStartDrag(event: PointerEvent): boolean {
142
+ if (exit || !sheetEl) return false;
143
+ return isDragStartAllowed(event.target as Element | null, sheetEl, DRAG_REGIONS);
144
+ }
145
+
146
+ function canStartBodyDrag(event: PointerEvent): boolean {
147
+ if (exit || !sheetEl) return false;
148
+ return isDragStartAllowed(event.target as Element | null, sheetEl, BODY_DRAG_REGION);
149
+ }
150
+
151
+ /**
152
+ * Whether the content is scrolled to the top, mirrored to data-scroll-at-top.
153
+ * The browser reads touch-action when a touch begins, so this has to be right
154
+ * before the next pointerdown, not worked out during it.
155
+ */
156
+ let contentAtTop = $state(true);
157
+
158
+ function trackScrollTop(node: HTMLElement) {
159
+ // Content is mounted afresh on every open, so start from its real offset.
160
+ const sync = () => (contentAtTop = node.scrollTop <= 0);
161
+ sync();
162
+ node.addEventListener('scroll', sync, { passive: true });
163
+ return () => node.removeEventListener('scroll', sync);
164
+ }
165
+
166
+ // Follows isOpen: shows the sheet, cancels a pending exit when it is reopened
167
+ // mid-animation, and starts the exit when the parent clears isOpen itself.
74
168
  $effect(() => {
75
169
  if (isOpen) {
170
+ if (exit) {
171
+ exit.cancel();
172
+ exit = null;
173
+ }
174
+ mounted = true;
175
+ } else if (sheetEl && mounted) {
176
+ beginExit();
177
+ }
178
+ });
179
+
180
+ // Move focus into the dialog when it appears and give it back on close.
181
+ $effect(() => {
182
+ if (!sheetEl) return;
183
+ opener = document.activeElement;
184
+ // Leave focus alone if something inside (an autofocus field) already has it.
185
+ if (!sheetEl.contains(opener)) sheetEl.focus({ preventScroll: true });
186
+ });
187
+
188
+ // The page behind a modal dialog is inert for as long as the sheet is on screen.
189
+ // Declared after the focus effect so the opener is recorded before it goes inert.
190
+ $effect(() => {
191
+ if (!sheetEl) return;
192
+ const release = inertSiblings(sheetEl);
193
+ releaseInert = release;
194
+ return () => {
195
+ release();
196
+ if (releaseInert === release) releaseInert = null;
197
+ };
198
+ });
199
+
200
+ $effect(() => {
201
+ if (present) {
76
202
  document.body.style.overflow = 'hidden';
77
203
  }
78
204
  return () => {
79
205
  document.body.style.overflow = '';
80
206
  };
81
207
  });
208
+
209
+ $effect(() => () => exit?.cancel());
82
210
  </script>
83
211
 
84
212
  <svelte:window onkeydown={handleKeydown} />
85
213
 
86
- {#if isOpen}
214
+ {#if present}
87
215
  <div
88
216
  class="sheet-backdrop"
89
217
  class:open={isOpen}
218
+ data-sheet-state={sheetState}
90
219
  onclick={handleBackdropClick}
91
220
  onkeydown={(e) => e.key === 'Escape' && close()}
92
221
  role="presentation"
@@ -94,51 +223,55 @@
94
223
  <div
95
224
  bind:this={sheetEl}
96
225
  class="sheet-container {className}"
226
+ style:--sheet-hidden-height={sheetYForFraction(detentAt(fractions, currentIndex))}
97
227
  class:open={isOpen}
228
+ data-sheet-state={sheetState}
229
+ role="dialog"
230
+ aria-modal="true"
231
+ aria-labelledby={title ? titleId : undefined}
232
+ aria-label={title ? undefined : 'Sheet'}
233
+ tabindex="-1"
234
+ {@attach fromAction(dragSurface, () => ({
235
+ detents: fractions,
236
+ initial: currentIndex,
237
+ disabled: !draggable || (fractions.length < 2 && interactiveDismissDisabled),
238
+ canStart: canStartDrag,
239
+ canStartAfterSlop: canStartBodyDrag,
240
+ onSnap: handleSnap,
241
+ ...(interactiveDismissDisabled ? {} : { onDismiss: close })
242
+ }))}
98
243
  >
99
244
  {#if showHandle}
100
- <div
101
- class="sheet-handle-container"
102
- {@attach fromAction(dragSnap, () => ({
103
- target: sheetEl,
104
- detents: fractions,
105
- initial: currentIndex,
106
- disabled: !draggable || fractions.length < 2,
107
- onSnap: handleSnap
108
- }))}
109
- >
245
+ <div class="sheet-handle-container">
110
246
  <div class="sheet-handle"></div>
111
247
  </div>
112
248
  {/if}
113
249
 
114
250
  {#if title}
115
251
  <header class="sheet-header">
116
- <HStack alignment="center">
117
- <button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
118
- <svg
119
- xmlns="http://www.w3.org/2000/svg"
120
- width="20"
121
- height="20"
122
- viewBox="0 0 24 24"
123
- fill="none"
124
- stroke="currentColor"
125
- stroke-width="2"
126
- stroke-linecap="round"
127
- stroke-linejoin="round"
128
- >
129
- <polyline points="15 18 9 12 15 6"></polyline>
130
- </svg>
131
- <span>Back</span>
132
- </button>
133
- <Spacer />
134
- <h2 class="sheet-title">{title}</h2>
135
- <Spacer />
136
- <div class="sheet-spacer"></div>
137
- </HStack>
252
+ <div class="sheet-spacer"></div>
253
+ <h2 class="sheet-title" id={titleId}>{title}</h2>
254
+ <button type="button" class="sheet-close-btn" onclick={close} aria-label="Close">
255
+ <svg
256
+ xmlns="http://www.w3.org/2000/svg"
257
+ width="16"
258
+ height="16"
259
+ viewBox="0 0 24 24"
260
+ fill="none"
261
+ stroke="currentColor"
262
+ stroke-width="2.5"
263
+ stroke-linecap="round"
264
+ stroke-linejoin="round"
265
+ aria-hidden="true"
266
+ focusable="false"
267
+ >
268
+ {@html getIconPath('xmark')}
269
+ </svg>
270
+ </button>
138
271
  </header>
139
272
  {/if}
140
273
 
141
- <div class="sheet-content">
274
+ <div class="sheet-content" data-scroll-at-top={contentAtTop} {@attach trackScrollTop}>
142
275
  {@render children()}
143
276
  </div>
144
277
  </div>
@@ -150,12 +283,16 @@
150
283
  position: fixed;
151
284
  inset: 0;
152
285
  background: rgba(0, 0, 0, 0.4);
153
- backdrop-filter: blur(4px);
154
- -webkit-backdrop-filter: blur(4px);
286
+ backdrop-filter: blur(var(--glass-backdrop-blur, 4px));
287
+ -webkit-backdrop-filter: blur(var(--glass-backdrop-blur, 4px));
155
288
  z-index: 1000;
156
289
  opacity: 0;
157
290
  visibility: hidden;
158
- transition: all 0.3s ease;
291
+ /* The fade runs in step with the sheet's slide, and stops with it under
292
+ reduced motion. */
293
+ transition:
294
+ opacity var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1)),
295
+ visibility var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1));
159
296
  }
160
297
 
161
298
  .sheet-backdrop.open {
@@ -163,6 +300,12 @@
163
300
  visibility: visible;
164
301
  }
165
302
 
303
+ /* An exiting sheet ignores the pointer: no second close, no new drag. */
304
+ .sheet-backdrop[data-sheet-state='closing'],
305
+ .sheet-container[data-sheet-state='closing'] {
306
+ pointer-events: none;
307
+ }
308
+
166
309
  .sheet-container {
167
310
  --sheet-y: 100vh;
168
311
  position: fixed;
@@ -170,6 +313,7 @@
170
313
  right: 0;
171
314
  top: 0;
172
315
  height: 100vh;
316
+ box-sizing: border-box;
173
317
  margin: 0 auto;
174
318
  background: var(--glass-sheet-bg);
175
319
  backdrop-filter: blur(var(--glass-blur-nav)) saturate(var(--glass-saturation));
@@ -179,13 +323,14 @@
179
323
  display: flex;
180
324
  flex-direction: column;
181
325
  transform: translateY(var(--sheet-y));
182
- transition: transform 0.4s cubic-bezier(0.32, 0.72, 0, 1);
326
+ transition: transform var(--transition-spring, 0.4s cubic-bezier(0.32, 0.72, 0, 1));
183
327
  z-index: 1001;
184
328
  border-top: 1px solid var(--glass-border);
185
329
  box-shadow:
186
330
  0 -8px 32px -8px var(--glass-shadow),
187
331
  inset 0 1px 0 0 var(--glass-highlight);
188
332
  touch-action: none;
333
+ outline: none;
189
334
  }
190
335
 
191
336
  .sheet-handle-container {
@@ -205,35 +350,45 @@
205
350
  border-radius: 3px;
206
351
  }
207
352
 
353
+ /* Title centred between an empty cell and the trailing close button, so the
354
+ title stays centred whatever its length. The header is also a drag region. */
208
355
  .sheet-header {
209
356
  padding: 0 var(--spacing-md);
210
357
  height: 56px;
211
358
  border-bottom: 1px solid var(--glass-divider);
212
- display: flex;
359
+ display: grid;
360
+ grid-template-columns: 36px minmax(0, 1fr) 36px;
213
361
  align-items: center;
362
+ gap: var(--spacing-sm);
214
363
  }
215
364
 
216
365
  .sheet-close-btn {
217
- display: flex;
366
+ display: inline-flex;
218
367
  align-items: center;
219
- gap: 4px;
220
- background: none;
368
+ justify-content: center;
369
+ width: 32px;
370
+ height: 32px;
371
+ padding: 0;
221
372
  border: none;
222
- color: var(--color-accent);
223
- font-size: 17px;
224
- font-weight: 400;
373
+ border-radius: 50%;
374
+ /* currentColor, so the glyph and its tint follow the text colour even when
375
+ the page defines no --color-text token. */
376
+ background: color-mix(in srgb, currentColor 10%, transparent);
377
+ color: var(--color-text-secondary, currentColor);
225
378
  cursor: pointer;
226
- padding: 8px 0;
227
- transition: opacity var(--transition-fast);
228
- font-family: var(--font-system);
379
+ transition: background var(--transition-fast), opacity var(--transition-fast);
229
380
  }
230
381
 
231
382
  .sheet-close-btn:hover {
232
- opacity: 0.7;
383
+ background: color-mix(in srgb, currentColor 16%, transparent);
233
384
  }
234
385
 
235
- .sheet-close-btn svg {
236
- margin-left: -6px;
386
+ .sheet-close-btn:focus-visible {
387
+ /* Two tones, so the ring holds 3:1 on a dark or a light sheet. The inner
388
+ ring is the shadow hugging the button, the outer one the outline. */
389
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--sheet-focus-ring-outer, #3b8eea));
390
+ outline-offset: var(--glass-focus-ring-offset, 2px);
391
+ box-shadow: 0 0 0 var(--glass-focus-ring-offset, 2px) var(--sheet-focus-ring-inner, #ffffff);
237
392
  }
238
393
 
239
394
  .sheet-title {
@@ -242,23 +397,50 @@
242
397
  color: var(--color-text);
243
398
  text-align: center;
244
399
  font-family: var(--font-system);
400
+ margin: 0;
245
401
  }
246
402
 
247
403
  .sheet-spacer {
248
- width: 80px;
404
+ width: 36px;
249
405
  }
250
406
 
407
+ /* The sheet is a viewport tall and pushed down to its detent, so that much of
408
+ it is below the screen. The content gives it up, or its end could never be
409
+ scrolled into view. It follows the settled detent, not the finger, so a drag
410
+ does not lay the content out again on every move. */
251
411
  .sheet-content {
252
412
  flex: 1;
413
+ margin-bottom: var(--sheet-hidden-height, 0px);
253
414
  overflow-y: auto;
254
415
  overflow-x: hidden;
255
416
  -webkit-overflow-scrolling: touch;
256
417
  font-family: var(--font-system);
418
+ /* Scrolled down, the content keeps every native pan; a pull down scrolls it
419
+ back up. */
420
+ touch-action: pan-x pan-y;
421
+ }
422
+
423
+ /* On a phone 100vh can reach behind the browser bars, which hides that much
424
+ more of the sheet. */
425
+ @supports (height: 100dvh) {
426
+ .sheet-content {
427
+ margin-bottom: calc(var(--sheet-hidden-height, 0px) + 100vh - 100dvh);
428
+ }
429
+ }
430
+
431
+ /* At the top, the browser keeps only the pan that scrolls the content down
432
+ (a finger moving up), so a finger moving down reaches the drag handlers
433
+ instead of becoming a pan and a pointercancel. Engines without directional
434
+ pans keep pan-x pan-y: the body scrolls, and touch drags use the handle. */
435
+ @supports (touch-action: pan-down) {
436
+ .sheet-content[data-scroll-at-top='true'] {
437
+ touch-action: pan-x pan-down;
438
+ }
257
439
  }
258
440
 
259
441
  @media (min-width: 769px) {
260
442
  .sheet-container {
261
- max-width: 900px;
443
+ max-width: var(--glass-sheet-max-width, 900px);
262
444
  }
263
445
  }
264
446
  </style>
@@ -1,5 +1,5 @@
1
1
  import type { Snippet } from 'svelte';
2
- import { type SheetDetentName } from '../../actions/dragSnap';
2
+ import { type SheetDetentName } from '../../actions/dragSnapMath';
3
3
  interface Props {
4
4
  isOpen?: boolean;
5
5
  title?: string;
@@ -10,6 +10,12 @@ interface Props {
10
10
  initialDetent?: SheetDetentName;
11
11
  showHandle?: boolean;
12
12
  draggable?: boolean;
13
+ /**
14
+ * Turns off drag to dismiss, mirroring SwiftUI's interactiveDismissDisabled.
15
+ * Dragging below the smallest detent then rubber-bands and snaps back. The
16
+ * close button, Escape and the backdrop still close the sheet.
17
+ */
18
+ interactiveDismissDisabled?: boolean;
13
19
  class?: string;
14
20
  }
15
21
  declare const Sheet: import("svelte").Component<Props, {}, string>;
@@ -26,6 +26,7 @@
26
26
  border-radius: var(--glass-radius-full);
27
27
  font-weight: 500;
28
28
  white-space: nowrap;
29
+ --_accent-text: var(--color-accent-text, color-mix(in srgb, var(--color-accent) var(--glass-accent-text-strength, 33%), var(--glass-text-toward, white)));
29
30
  }
30
31
 
31
32
  .badge.size-sm {
@@ -46,7 +47,7 @@
46
47
 
47
48
  .badge.variant-accent {
48
49
  background: var(--color-accent-15);
49
- color: var(--color-accent);
50
+ color: var(--_accent-text);
50
51
  border: 1px solid var(--color-accent-25);
51
52
  }
52
53
  </style>