glasslikeui 1.9.0 → 1.10.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 (128) hide show
  1. package/README.md +892 -24
  2. package/dist/actions/adaptiveTone.d.ts +50 -0
  3. package/dist/actions/adaptiveTone.js +569 -0
  4. package/dist/actions/alertLogic.d.ts +67 -0
  5. package/dist/actions/alertLogic.js +123 -0
  6. package/dist/actions/anchorPlacement.d.ts +92 -0
  7. package/dist/actions/anchorPlacement.js +137 -0
  8. package/dist/actions/dragSnap.d.ts +1 -1
  9. package/dist/actions/dragSnapMath.d.ts +70 -0
  10. package/dist/actions/dragSnapMath.js +115 -0
  11. package/dist/actions/glassToneLogic.d.ts +182 -0
  12. package/dist/actions/glassToneLogic.js +513 -0
  13. package/dist/actions/heightTransition.d.ts +32 -0
  14. package/dist/actions/heightTransition.js +64 -0
  15. package/dist/actions/index.d.ts +1 -0
  16. package/dist/actions/index.js +1 -0
  17. package/dist/actions/inertSiblings.js +20 -4
  18. package/dist/actions/menuLogic.d.ts +40 -0
  19. package/dist/actions/menuLogic.js +68 -0
  20. package/dist/actions/modalDialog.d.ts +19 -0
  21. package/dist/actions/modalDialog.js +48 -0
  22. package/dist/actions/popoverLogic.d.ts +25 -0
  23. package/dist/actions/popoverLogic.js +48 -0
  24. package/dist/actions/rovingIndex.d.ts +30 -0
  25. package/dist/actions/rovingIndex.js +49 -0
  26. package/dist/actions/scrollRunTracker.d.ts +36 -0
  27. package/dist/actions/scrollRunTracker.js +77 -0
  28. package/dist/actions/scrollUnder.d.ts +21 -0
  29. package/dist/actions/scrollUnder.js +29 -0
  30. package/dist/actions/segmentedLogic.d.ts +38 -0
  31. package/dist/actions/segmentedLogic.js +59 -0
  32. package/dist/actions/sheetLogic.d.ts +43 -0
  33. package/dist/actions/sheetLogic.js +71 -0
  34. package/dist/actions/sliderLogic.d.ts +29 -0
  35. package/dist/actions/sliderLogic.js +53 -0
  36. package/dist/actions/swipeActions.d.ts +46 -2
  37. package/dist/actions/swipeActions.js +267 -46
  38. package/dist/actions/tabBarMinimize.d.ts +31 -0
  39. package/dist/actions/tabBarMinimize.js +38 -0
  40. package/dist/actions/tabViewLogic.d.ts +47 -0
  41. package/dist/actions/tabViewLogic.js +71 -0
  42. package/dist/actions/toggleKnobLogic.d.ts +57 -0
  43. package/dist/actions/toggleKnobLogic.js +66 -0
  44. package/dist/actions/toolbarFocus.d.ts +44 -0
  45. package/dist/actions/toolbarFocus.js +228 -0
  46. package/dist/actions/topLayer.d.ts +12 -0
  47. package/dist/actions/topLayer.js +18 -0
  48. package/dist/components/dialog/ActionSheet.svelte +457 -0
  49. package/dist/components/dialog/ActionSheet.svelte.d.ts +25 -0
  50. package/dist/components/dialog/Alert.svelte +337 -0
  51. package/dist/components/dialog/Alert.svelte.d.ts +28 -0
  52. package/dist/components/dialog/index.d.ts +6 -0
  53. package/dist/components/dialog/index.js +6 -0
  54. package/dist/components/glass/Glass.svelte +49 -17
  55. package/dist/components/glass/Glass.svelte.d.ts +8 -0
  56. package/dist/components/glass/GlassSection.svelte +9 -1
  57. package/dist/components/glass/LensFilters.svelte +4 -2
  58. package/dist/components/glass/Popover.svelte +379 -0
  59. package/dist/components/glass/Popover.svelte.d.ts +30 -0
  60. package/dist/components/glass/Sheet.svelte +470 -103
  61. package/dist/components/glass/Sheet.svelte.d.ts +55 -7
  62. package/dist/components/glass/index.d.ts +3 -0
  63. package/dist/components/glass/index.js +1 -0
  64. package/dist/components/index.d.ts +2 -0
  65. package/dist/components/index.js +4 -0
  66. package/dist/components/interactive/Badge.svelte +97 -6
  67. package/dist/components/interactive/Badge.svelte.d.ts +13 -2
  68. package/dist/components/interactive/Button.svelte +162 -20
  69. package/dist/components/interactive/Button.svelte.d.ts +14 -1
  70. package/dist/components/interactive/IconButton.svelte +214 -4
  71. package/dist/components/interactive/IconButton.svelte.d.ts +2 -1
  72. package/dist/components/interactive/ProgressView.svelte +306 -0
  73. package/dist/components/interactive/ProgressView.svelte.d.ts +25 -0
  74. package/dist/components/interactive/Segment.d.ts +14 -0
  75. package/dist/components/interactive/Segment.js +1 -0
  76. package/dist/components/interactive/SegmentedControl.svelte +399 -0
  77. package/dist/components/interactive/SegmentedControl.svelte.d.ts +17 -0
  78. package/dist/components/interactive/Slider.svelte +299 -0
  79. package/dist/components/interactive/Slider.svelte.d.ts +23 -0
  80. package/dist/components/interactive/TabView.svelte +573 -41
  81. package/dist/components/interactive/TabView.svelte.d.ts +25 -0
  82. package/dist/components/interactive/Toggle.svelte +287 -16
  83. package/dist/components/interactive/Toggle.svelte.d.ts +12 -0
  84. package/dist/components/interactive/index.d.ts +4 -0
  85. package/dist/components/interactive/index.js +3 -0
  86. package/dist/components/list/List.svelte +41 -17
  87. package/dist/components/list/List.svelte.d.ts +1 -0
  88. package/dist/components/list/ListRow.svelte +208 -47
  89. package/dist/components/list/ListRow.svelte.d.ts +16 -1
  90. package/dist/components/menu/Menu.svelte +51 -27
  91. package/dist/components/menu/Menu.svelte.d.ts +5 -0
  92. package/dist/components/menu/MenuItem.svelte +82 -25
  93. package/dist/components/menu/MenuItem.svelte.d.ts +8 -0
  94. package/dist/components/menu/MenuSection.svelte +95 -0
  95. package/dist/components/menu/MenuSection.svelte.d.ts +18 -0
  96. package/dist/components/menu/MenuSubmenu.svelte +196 -0
  97. package/dist/components/menu/MenuSubmenu.svelte.d.ts +11 -0
  98. package/dist/components/menu/index.d.ts +4 -1
  99. package/dist/components/menu/index.js +3 -1
  100. package/dist/components/navigation/NavigationBar.svelte +97 -15
  101. package/dist/components/navigation/NavigationBar.svelte.d.ts +6 -0
  102. package/dist/components/toolbar/Toolbar.svelte +43 -0
  103. package/dist/components/toolbar/Toolbar.svelte.d.ts +13 -0
  104. package/dist/components/toolbar/ToolbarItemGroup.svelte +45 -0
  105. package/dist/components/toolbar/ToolbarItemGroup.svelte.d.ts +14 -0
  106. package/dist/components/toolbar/ToolbarSpacer.svelte +36 -0
  107. package/dist/components/toolbar/ToolbarSpacer.svelte.d.ts +12 -0
  108. package/dist/components/toolbar/index.d.ts +7 -0
  109. package/dist/components/toolbar/index.js +7 -0
  110. package/dist/components/typography/Text.svelte +9 -1
  111. package/dist/constants/alertAction.d.ts +19 -0
  112. package/dist/constants/alertAction.js +1 -0
  113. package/dist/constants/badge.d.ts +32 -0
  114. package/dist/constants/badge.js +47 -0
  115. package/dist/constants/buttons.d.ts +45 -0
  116. package/dist/constants/buttons.js +52 -0
  117. package/dist/constants/colors.d.ts +9 -4
  118. package/dist/constants/colors.js +9 -4
  119. package/dist/constants/index.d.ts +3 -0
  120. package/dist/constants/index.js +3 -0
  121. package/dist/constants/progress.d.ts +56 -0
  122. package/dist/constants/progress.js +75 -0
  123. package/dist/constants/variants.d.ts +6 -2
  124. package/dist/constants/variants.js +2 -2
  125. package/dist/styles/glasslikeui.css +135 -1
  126. package/dist/styles/lens.css +21 -19
  127. package/dist/styles/squircle.css +17 -7
  128. package/package.json +1 -1
@@ -1,16 +1,38 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
- import { onMount } from 'svelte';
3
+ import { flushSync, onMount, untrack } from 'svelte';
4
4
  import { Glass } from '../glass';
5
5
  import { HStack } from '../layout';
6
6
  import { fitFocusRing } from '../../actions/focusRingFit';
7
+ import {
8
+ collapsedTabId,
9
+ needsTabDock,
10
+ rovingTabIndex,
11
+ tabGroups,
12
+ tabKeyTarget
13
+ } from '../../actions/tabViewLogic';
14
+ import { type TabBarMinimizeBehavior } from '../../actions/tabBarMinimize';
15
+ import { ScrollRunTracker, isIgnoredScrollSource } from '../../actions/scrollRunTracker';
16
+ import { badgeDisplay, badgeSpokenText, type BadgeValue } from '../../constants/badge';
17
+ import { getIconPath } from '../../icons';
18
+ import { captureHeights, playHeightTransition } from '../../actions/heightTransition';
19
+ import { prefersReducedMotion } from '../../actions/reducedMotion';
7
20
 
8
21
  interface Tab {
9
22
  id: string;
10
23
  label: string;
11
24
  icon?: Snippet;
25
+ /** A badge on the tab: a count, a short text, or `true` for a dot. Below 1, empty or false shows none. */
26
+ badge?: BadgeValue;
27
+ /** The words read for the badge, such as "3 unread". Defaults to the badge text, or "New" for a dot. */
28
+ badgeLabel?: string;
29
+ /** `'search'` sets the tab apart at the trailing end of the bar, in its own circle. */
30
+ role?: 'search';
12
31
  }
13
32
 
33
+ /** Where the bottom accessory sits: above the bar, or inline with a minimised bar. */
34
+ type AccessoryPlacement = 'expanded' | 'inline';
35
+
14
36
  interface Props {
15
37
  tabs: Tab[];
16
38
  activeTab?: string;
@@ -18,6 +40,19 @@
18
40
  position?: 'top' | 'bottom';
19
41
  inline?: boolean;
20
42
  onchange?: (id: string) => void;
43
+ /** Accessible name for the tab list, read before the tabs. */
44
+ label?: string;
45
+ /**
46
+ * Content in its own glass capsule above the bar, such as a now playing
47
+ * control. It moves inline between the collapsed tab and the search tab
48
+ * when the bar minimises, and gets the placement to adapt its layout.
49
+ */
50
+ bottomAccessory?: Snippet<[{ placement: AccessoryPlacement }]>;
51
+ /**
52
+ * When the bar minimises to the selected tab as the page or the tab
53
+ * content scrolls. Defaults to `'never'`.
54
+ */
55
+ minimizeBehavior?: TabBarMinimizeBehavior;
21
56
  class?: string;
22
57
  }
23
58
 
@@ -28,24 +63,141 @@
28
63
  position = 'bottom',
29
64
  inline = false,
30
65
  onchange,
66
+ label,
67
+ bottomAccessory,
68
+ minimizeBehavior = 'never',
31
69
  class: className = ''
32
70
  }: Props = $props();
33
71
 
72
+ const uid = $props.id();
73
+ const panelId = `${uid}-panel`;
74
+ const tabId = (id: string) => `${uid}-tab-${id}`;
75
+ const tabLabelId = (id: string) => `${uid}-tab-${id}-label`;
76
+
77
+ const groups = $derived(tabGroups(tabs));
78
+ // Search tabs come last in the keyboard order, as they sit last on screen.
79
+ const ordered = $derived([...groups.main, ...groups.search]);
80
+ const dock = $derived(
81
+ needsTabDock(groups.search.length > 0, bottomAccessory !== undefined, minimizeBehavior !== 'never')
82
+ );
83
+
84
+ // The one tab in the Tab order: the selected one, else the first.
85
+ const focusIndex = $derived(rovingTabIndex(ordered.map((t) => t.id), activeTab));
86
+
87
+ let minimized = $state(false);
88
+ const collapsedId = $derived(collapsedTabId(groups.main.map((t) => t.id), activeTab));
89
+
34
90
  function selectTab(tabId: string) {
35
91
  activeTab = tabId;
36
92
  onchange?.(tabId);
37
93
  }
38
94
 
95
+ function handleTabClick(id: string) {
96
+ // Tapping the collapsed tab of a minimised bar expands it, as on iOS.
97
+ expand();
98
+ selectTab(id);
99
+ }
100
+
101
+ /** Arrow keys, Home and End move focus along the tabs and select as they go. */
102
+ function handleKeydown(event: KeyboardEvent) {
103
+ const current = ordered.findIndex((t) => buttonEls[t.id] === event.target);
104
+ if (current < 0) return;
105
+ const rtl = getComputedStyle(event.currentTarget as Element).direction === 'rtl';
106
+ const next = tabKeyTarget(event.key, current, ordered.length, rtl);
107
+ if (next === null) return;
108
+ event.preventDefault();
109
+ const tab = ordered[next];
110
+ if (!tab) return;
111
+ // A minimised bar hides the other tabs. Expand it first and apply the
112
+ // change now, so the tab is shown before it takes focus.
113
+ if (minimized) {
114
+ expand();
115
+ flushSync();
116
+ }
117
+ buttonEls[tab.id]?.focus();
118
+ if (tab.id !== activeTab) selectTab(tab.id);
119
+ }
120
+
121
+ // Scroll runs per source (the page, the tab content or any other scroll
122
+ // container), so one source's position is never measured against another's.
123
+ const runs = new ScrollRunTracker();
124
+
125
+ /**
126
+ * The scroll position of a scroll event's target. An element reports its
127
+ * own. Anything else is the page (the window or the document), which is
128
+ * tracked as the window.
129
+ */
130
+ function scrollTopOf(target: EventTarget | null): { source: EventTarget; y: number } | null {
131
+ if (target instanceof Element) {
132
+ return isIgnoredScrollSource(target) ? null : { source: target, y: target.scrollTop };
133
+ }
134
+ return { source: window, y: window.scrollY };
135
+ }
136
+
137
+ function trackScroll(source: EventTarget, y: number) {
138
+ minimized = runs.step(minimizeBehavior, minimized, source, y);
139
+ }
140
+
141
+ /** Expands a minimised bar; the next scroll has to run the whole threshold again to minimise it. */
142
+ function expand() {
143
+ if (!minimized) return;
144
+ minimized = false;
145
+ runs.restart();
146
+ }
147
+
148
+ let contentEl = $state<HTMLDivElement | undefined>();
149
+
150
+ $effect(() => {
151
+ if (minimizeBehavior === 'never') {
152
+ minimized = false;
153
+ return;
154
+ }
155
+ if (typeof window === 'undefined') return;
156
+ const content = contentEl;
157
+ runs.clear();
158
+ runs.start(window, window.scrollY);
159
+ if (content) runs.start(content, content.scrollTop);
160
+ // Scroll events do not bubble, but they do pass the window in the capture
161
+ // phase, so one listener hears the page, the tab content and any scroll
162
+ // container the app uses. A container first seen mid scroll starts its
163
+ // run where that event finds it. Text areas and anything in a dialog or
164
+ // popover over the page are ignored (see isIgnoredScrollSource).
165
+ const onScroll = (event: Event) => {
166
+ const at = scrollTopOf(event.target);
167
+ if (at) trackScroll(at.source, at.y);
168
+ };
169
+ window.addEventListener('scroll', onScroll, { capture: true, passive: true });
170
+ return () => window.removeEventListener('scroll', onScroll, { capture: true });
171
+ });
172
+
39
173
  let wrapperEl = $state<HTMLDivElement | undefined>();
40
174
  let buttonEls: Record<string, HTMLButtonElement | undefined> = $state({});
41
175
  let indicatorLeft = $state(0);
42
176
  let indicatorWidth = $state(0);
43
177
  let indicatorReady = $state(false);
178
+ // The widths of the collapsed tab and the search circle, which set the
179
+ // inline accessory's margins on a minimised bar.
180
+ let leadEl = $state<HTMLDivElement | undefined>();
181
+ let trailEl = $state<HTMLDivElement | undefined>();
182
+ let leadWidth = $state(0);
183
+ let trailWidth = $state(0);
184
+ // The height of the single fixed capsule, so the content can end clear of
185
+ // it. The dock and an inline bar pad nothing.
186
+ let barHeight = $state(0);
187
+
188
+ /** The single fixed capsule, or null for the dock and an inline bar. */
189
+ function fixedBar(): HTMLElement | null {
190
+ return dock || inline ? null : (wrapperEl?.closest<HTMLElement>('.tab-bar-container') ?? null);
191
+ }
44
192
 
45
193
  function measure() {
194
+ leadWidth = leadEl?.offsetWidth ?? 0;
195
+ trailWidth = trailEl?.offsetWidth ?? 0;
196
+ barHeight = fixedBar()?.offsetHeight ?? 0;
46
197
  const wrapper = wrapperEl;
47
198
  const btn = buttonEls[activeTab];
48
- if (!wrapper || !btn) {
199
+ // A selected search tab sits in its own circle: the pill stays hidden.
200
+ if (!wrapper || !btn || !wrapper.contains(btn)) {
49
201
  indicatorReady = false;
50
202
  return;
51
203
  }
@@ -55,66 +207,227 @@
55
207
  }
56
208
 
57
209
  $effect(() => {
58
- // Re-measure whenever the active tab changes; RAF lets the DOM settle first.
210
+ // Re-measure whenever the active tab changes or the bar minimises; RAF
211
+ // lets the DOM settle first.
59
212
  void activeTab;
213
+ void minimized;
60
214
  if (typeof requestAnimationFrame === 'undefined') return;
61
215
  const id = requestAnimationFrame(measure);
62
216
  return () => cancelAnimationFrame(id);
63
217
  });
64
218
 
219
+ // A minimised bar drops the label row, so the tabs that stay shown get
220
+ // shorter (and taller again on expanding). The height is read before the
221
+ // change and played to the new one with the minimise transition.
222
+ let heightsBefore = new Map<HTMLElement, number>();
223
+
224
+ $effect.pre(() => {
225
+ void minimized;
226
+ untrack(() => {
227
+ heightsBefore = captureHeights(
228
+ Object.values(buttonEls).filter((el): el is HTMLButtonElement => el !== undefined)
229
+ );
230
+ });
231
+ });
232
+
233
+ $effect(() => {
234
+ void minimized;
235
+ untrack(() => playHeightTransition(heightsBefore, prefersReducedMotion()));
236
+ });
237
+
65
238
  onMount(() => {
66
239
  measure();
67
240
  if (typeof ResizeObserver === 'undefined' || !wrapperEl) return;
68
241
  const ro = new ResizeObserver(() => measure());
69
242
  ro.observe(wrapperEl);
243
+ // The bar itself too, border box included: page CSS that pads or
244
+ // borders it changes its height without resizing the wrapper.
245
+ const bar = fixedBar();
246
+ if (bar) ro.observe(bar, { box: 'border-box' });
247
+ if (leadEl) ro.observe(leadEl);
248
+ if (trailEl) ro.observe(trailEl);
70
249
  return () => ro.disconnect();
71
250
  });
72
251
  </script>
73
252
 
253
+ {#snippet tabButton(tab: Tab, i: number)}
254
+ {@const badge = badgeDisplay(tab.badge)}
255
+ {@const search = tab.role === 'search'}
256
+ <button
257
+ type="button"
258
+ class="tab-item"
259
+ class:active={activeTab === tab.id}
260
+ class:search
261
+ class:collapsed-away={minimized && !search && tab.id !== collapsedId}
262
+ id={tabId(tab.id)}
263
+ role="tab"
264
+ aria-selected={activeTab === tab.id}
265
+ aria-controls={children ? panelId : undefined}
266
+ tabindex={i === focusIndex ? 0 : -1}
267
+ onclick={() => handleTabClick(tab.id)}
268
+ bind:this={buttonEls[tab.id]}
269
+ {@attach fitFocusRing}
270
+ >
271
+ {#if tab.icon}
272
+ <span class="tab-icon">{@render tab.icon()}</span>
273
+ {:else if search}
274
+ <span class="tab-icon">
275
+ <svg
276
+ xmlns="http://www.w3.org/2000/svg"
277
+ width="1em"
278
+ height="1em"
279
+ viewBox="0 0 24 24"
280
+ fill="none"
281
+ stroke="currentColor"
282
+ stroke-width="2.25"
283
+ stroke-linecap="round"
284
+ stroke-linejoin="round"
285
+ aria-hidden="true"
286
+ focusable="false"
287
+ >
288
+ {@html getIconPath('magnifyingglass')}
289
+ </svg>
290
+ </span>
291
+ {/if}
292
+ <span class="tab-label" id={tabLabelId(tab.id)}>{tab.label}</span>
293
+ {#if badge.kind !== 'hidden'}
294
+ <span
295
+ class="tab-badge"
296
+ class:dot={badge.kind === 'dot'}
297
+ data-badge-form={badge.kind === 'dot' ? 'dot' : 'count'}
298
+ aria-hidden="true">{badge.kind === 'text' ? badge.text : ''}</span
299
+ >
300
+ <span class="tab-sr">, {badgeSpokenText(badge, tab.badgeLabel)}</span>
301
+ {/if}
302
+ </button>
303
+ {/snippet}
304
+
305
+ {#snippet mainBar(isTablist: boolean)}
306
+ <!-- The indicator is aria-hidden and the stack a plain div, so the tabs are
307
+ the list's only accessible children. The list itself takes no focus:
308
+ the roving tabindex puts one tab in the Tab order instead. -->
309
+ <!-- svelte-ignore a11y_interactive_supports_focus -->
310
+ <div
311
+ class="tab-bar-wrapper"
312
+ bind:this={wrapperEl}
313
+ role={isTablist ? 'tablist' : undefined}
314
+ aria-label={isTablist ? label : undefined}
315
+ aria-orientation={isTablist ? 'horizontal' : undefined}
316
+ onkeydown={isTablist ? handleKeydown : undefined}
317
+ >
318
+ <span
319
+ class="tab-indicator"
320
+ class:ready={indicatorReady}
321
+ style="transform: translateX({indicatorLeft}px); width: {indicatorWidth}px;"
322
+ aria-hidden="true"
323
+ ></span>
324
+ <HStack spacing="xs" justify="center" class="tab-bar">
325
+ {#each groups.main as tab, i (tab.id)}
326
+ {@render tabButton(tab, i)}
327
+ {/each}
328
+ </HStack>
329
+ </div>
330
+ {/snippet}
331
+
74
332
  <div
75
333
  class="tab-view {className}"
76
334
  class:position-bottom={position === 'bottom' && !inline}
335
+ class:position-top={position === 'top' && !inline}
336
+ class:fixed-bar={!dock && !inline}
77
337
  class:inline
338
+ style:--_tab-bar-height={barHeight ? `${barHeight}px` : undefined}
339
+ data-minimized={minimizeBehavior === 'never' ? undefined : String(minimized)}
78
340
  >
79
341
  {#if children}
80
- <div class="tab-content">
342
+ <div
343
+ class="tab-content"
344
+ id={panelId}
345
+ role="tabpanel"
346
+ aria-labelledby={tabs.some((t) => t.id === activeTab) ? tabLabelId(activeTab) : undefined}
347
+ tabindex="0"
348
+ bind:this={contentEl}
349
+ >
81
350
  {@render children(activeTab)}
82
351
  </div>
83
352
  {/if}
84
353
 
85
- <Glass
86
- variant="regular"
87
- intensity="prominent"
88
- cornerRadius="full"
89
- padding="xs"
90
- class={inline ? 'tab-bar-container-inline' : 'tab-bar-container'}
91
- >
92
- <div class="tab-bar-wrapper" bind:this={wrapperEl}>
93
- <span
94
- class="tab-indicator"
95
- class:ready={indicatorReady}
96
- style="transform: translateX({indicatorLeft}px); width: {indicatorWidth}px;"
97
- aria-hidden="true"
98
- ></span>
99
- <HStack spacing="xs" justify="center" class="tab-bar">
100
- {#each tabs as tab (tab.id)}
101
- <button
102
- type="button"
103
- class="tab-item"
104
- class:active={activeTab === tab.id}
105
- onclick={() => selectTab(tab.id)}
106
- bind:this={buttonEls[tab.id]}
107
- {@attach fitFocusRing}
108
- >
109
- {#if tab.icon}
110
- <span class="tab-icon">{@render tab.icon()}</span>
111
- {/if}
112
- <span class="tab-label">{tab.label}</span>
113
- </button>
114
- {/each}
115
- </HStack>
354
+ {#if !dock}
355
+ <Glass
356
+ variant="regular"
357
+ intensity="prominent"
358
+ cornerRadius="full"
359
+ padding="xs"
360
+ class={inline ? 'tab-bar-container-inline' : 'tab-bar-container'}
361
+ >
362
+ {@render mainBar(true)}
363
+ </Glass>
364
+ {:else}
365
+ <div
366
+ class="tab-dock"
367
+ class:dock-inline={inline}
368
+ class:minimized
369
+ class:has-search={groups.search.length > 0}
370
+ style:--tab-dock-lead="{leadWidth}px"
371
+ style:--tab-dock-trail="{trailWidth}px"
372
+ >
373
+ {#if bottomAccessory}
374
+ <Glass
375
+ variant="regular"
376
+ intensity="prominent"
377
+ cornerRadius="full"
378
+ padding="xs"
379
+ class="tab-accessory"
380
+ >
381
+ <div class="tab-accessory-content">
382
+ {@render bottomAccessory({ placement: minimized ? 'inline' : 'expanded' })}
383
+ </div>
384
+ </Glass>
385
+ {/if}
386
+ <!-- One tab list holds both glass groups, so the arrow keys and the
387
+ roving tabindex run across the search tab too. Focus anywhere in it
388
+ expands a minimised bar, so every tab is reachable. -->
389
+ <!-- svelte-ignore a11y_interactive_supports_focus -->
390
+ <div
391
+ class="tab-dock-row"
392
+ role="tablist"
393
+ aria-label={label}
394
+ aria-orientation="horizontal"
395
+ onkeydown={handleKeydown}
396
+ onfocusin={expand}
397
+ >
398
+ {#if groups.main.length > 0}
399
+ <div class="tab-dock-main" bind:this={leadEl}>
400
+ <Glass
401
+ variant="regular"
402
+ intensity="prominent"
403
+ cornerRadius="full"
404
+ padding="xs"
405
+ class={inline ? 'tab-bar-container-inline tab-bar-docked' : 'tab-bar-container tab-bar-docked'}
406
+ >
407
+ {@render mainBar(false)}
408
+ </Glass>
409
+ </div>
410
+ {/if}
411
+ {#if groups.search.length > 0}
412
+ <div class="tab-dock-search" bind:this={trailEl}>
413
+ <Glass
414
+ variant="regular"
415
+ intensity="prominent"
416
+ cornerRadius="full"
417
+ padding="xs"
418
+ class="tab-search-container"
419
+ >
420
+ <div class="tab-search-group">
421
+ {#each groups.search as tab, j (tab.id)}
422
+ {@render tabButton(tab, groups.main.length + j)}
423
+ {/each}
424
+ </div>
425
+ </Glass>
426
+ </div>
427
+ {/if}
428
+ </div>
116
429
  </div>
117
- </Glass>
430
+ {/if}
118
431
  </div>
119
432
 
120
433
  <style>
@@ -135,12 +448,29 @@
135
448
 
136
449
  :global(.tab-bar-container) {
137
450
  position: fixed;
138
- bottom: var(--spacing-md);
451
+ bottom: calc(var(--spacing-md) + env(safe-area-inset-bottom, 0px));
139
452
  left: 50%;
140
453
  transform: translateX(-50%);
141
454
  z-index: 50;
142
455
  }
143
456
 
457
+ .tab-view.position-top > :global(.tab-bar-container) {
458
+ top: calc(var(--spacing-md) + env(safe-area-inset-top, 0px));
459
+ bottom: auto;
460
+ }
461
+
462
+ /* The fixed bar floats over the page, so the content ends clear of it and
463
+ its last line can scroll into view. Until the bar is measured (before
464
+ hydration, or with no script) the fallback is the default bar's height,
465
+ an icon over a label. */
466
+ .tab-view.fixed-bar.position-bottom > .tab-content {
467
+ padding-bottom: calc(var(--_tab-bar-height, 4.8125rem) + var(--spacing-md) + env(safe-area-inset-bottom, 0px));
468
+ }
469
+
470
+ .tab-view.fixed-bar.position-top > .tab-content {
471
+ padding-top: calc(var(--_tab-bar-height, 4.8125rem) + var(--spacing-md) + env(safe-area-inset-top, 0px));
472
+ }
473
+
144
474
  :global(.tab-bar-container-inline) {
145
475
  display: block;
146
476
  }
@@ -168,7 +498,8 @@
168
498
  left: 0;
169
499
  width: 0;
170
500
  border-radius: var(--glass-radius-full);
171
- background: var(--glass-active-bg);
501
+ /* On a toned bar with no accent left, a pill that leans away from the label (see adaptiveTone). */
502
+ background: var(--glass-tone-active-bg, var(--glass-active-bg));
172
503
  pointer-events: none;
173
504
  opacity: 0;
174
505
  z-index: 0;
@@ -188,12 +519,17 @@
188
519
  display: flex;
189
520
  flex-direction: column;
190
521
  align-items: center;
522
+ /* Centred: a tab whose label is hidden (a search tab, or any tab of a
523
+ minimised bar) keeps its icon in the middle when it is taller than
524
+ its content, as while its height animates. */
525
+ justify-content: center;
191
526
  gap: 4px;
192
527
  padding: 10px 20px;
193
528
  background: transparent;
194
529
  border: none;
195
530
  border-radius: var(--glass-radius-full);
196
- color: var(--color-text-secondary);
531
+ /* The bar's adaptive tone (see adaptiveTone), or the theme colour. */
532
+ color: var(--glass-fg-secondary, var(--color-text-secondary));
197
533
  font-size: 0.75rem;
198
534
  font-weight: 500;
199
535
  cursor: pointer;
@@ -221,12 +557,25 @@
221
557
  outline-offset: calc(-2 * var(--glass-focus-ring-width, 2px));
222
558
  }
223
559
 
560
+ /* The panel's focus ring, for the panel's own Tab stop. Drawn inside its
561
+ edge: the panel scrolls, and an outline outside it would be clipped by
562
+ the page around it. The same two tones as the shared ring, the halo inside
563
+ the outline. :where keeps it at zero specificity, so a page's own focus
564
+ rules win. */
565
+ :where(.tab-content:focus-visible) {
566
+ outline: var(--glass-focus-ring-width, 2px) solid var(--glass-focus-ring-color, var(--glass-focus-ring-color-default, #9ecbff));
567
+ outline-offset: calc(-1 * var(--glass-focus-ring-width, 2px));
568
+ box-shadow: inset 0 0 0 calc(2 * var(--glass-focus-ring-width, 2px)) var(--glass-focus-ring-halo-color, var(--glass-focus-ring-halo-color-default, #000000));
569
+ }
570
+
224
571
  .tab-item:not(.active):hover {
225
- color: var(--color-text);
572
+ color: var(--glass-fg, var(--color-text));
226
573
  }
227
574
 
575
+ /* On a toned bar, the accent that still holds 4.5:1 over the backdrop
576
+ (see adaptiveTone). */
228
577
  .tab-item.active {
229
- color: var(--_accent-text);
578
+ color: var(--glass-fg-accent, var(--_accent-text));
230
579
  }
231
580
 
232
581
  .tab-icon,
@@ -254,4 +603,187 @@
254
603
  .tab-label {
255
604
  white-space: nowrap;
256
605
  }
606
+ /* The dock: the layout for a search tab, a bottom accessory or a bar that
607
+ minimises. Without any of them the single capsule above is used, so the
608
+ default bar looks exactly as before. */
609
+ .tab-dock {
610
+ position: fixed;
611
+ bottom: var(--spacing-md);
612
+ left: 50%;
613
+ transform: translateX(-50%);
614
+ z-index: 50;
615
+ display: grid;
616
+ gap: var(--spacing-xs, 8px);
617
+ width: max-content;
618
+ max-width: calc(100vw - 2 * var(--spacing-md, 16px));
619
+ }
620
+
621
+ .tab-dock.dock-inline {
622
+ position: static;
623
+ transform: none;
624
+ }
625
+
626
+ .tab-dock-row {
627
+ display: flex;
628
+ align-items: stretch;
629
+ gap: var(--spacing-xs, 8px);
630
+ }
631
+
632
+ .tab-dock-main,
633
+ .tab-dock-search {
634
+ display: flex;
635
+ min-width: 0;
636
+ }
637
+
638
+ /* Inside the dock the capsule flows in the row; the dock itself is placed. */
639
+ .tab-dock-row :global(.tab-bar-docked) {
640
+ position: relative;
641
+ left: auto;
642
+ bottom: auto;
643
+ transform: none;
644
+ display: block;
645
+ }
646
+
647
+ .tab-search-group {
648
+ display: flex;
649
+ align-items: stretch;
650
+ height: 100%;
651
+ }
652
+
653
+ .tab-accessory-content {
654
+ display: flex;
655
+ align-items: center;
656
+ box-sizing: border-box;
657
+ /* Fills the capsule, so the content stays centred when the capsule is
658
+ stretched to the height of a minimised bar. */
659
+ height: 100%;
660
+ min-height: 2.75rem;
661
+ padding: 0 var(--spacing-sm, 12px);
662
+ }
663
+
664
+ /* Minimised: the accessory moves inline, between the collapsed tab and the
665
+ search tab. Both share one grid cell and the row lets clicks through its
666
+ gap, so the accessory is laid out without leaving the tab list. */
667
+ .tab-dock.minimized {
668
+ grid-template-areas: 'dock';
669
+ }
670
+
671
+ .tab-dock.minimized > :global(*) {
672
+ grid-area: dock;
673
+ }
674
+
675
+ .tab-dock.minimized .tab-dock-row {
676
+ justify-content: space-between;
677
+ pointer-events: none;
678
+ }
679
+
680
+ .tab-dock.minimized .tab-dock-row > * {
681
+ pointer-events: auto;
682
+ }
683
+
684
+ .tab-dock.minimized :global(.tab-accessory) {
685
+ margin-inline-start: calc(var(--tab-dock-lead) + var(--spacing-xs, 8px));
686
+ }
687
+
688
+ .tab-dock.minimized.has-search :global(.tab-accessory) {
689
+ margin-inline-end: calc(var(--tab-dock-trail) + var(--spacing-xs, 8px));
690
+ }
691
+
692
+ /* Hidden from sight only, not with display: none, so the arrow keys can
693
+ still focus it (which expands the bar) and its name stays in the
694
+ accessibility tree. */
695
+ .tab-item.collapsed-away {
696
+ position: absolute;
697
+ width: 1px;
698
+ height: 1px;
699
+ margin: -1px;
700
+ padding: 0;
701
+ overflow: hidden;
702
+ clip-path: inset(50%);
703
+ white-space: nowrap;
704
+ opacity: 0;
705
+ }
706
+
707
+ /* A minimised bar and a search tab show the icon alone. The label is
708
+ hidden from sight and out of the layout, so the bar shrinks to the
709
+ icons, and it stays in the accessible name. */
710
+ .tab-dock.minimized .tab-item:has(.tab-icon) .tab-label,
711
+ .tab-item.search .tab-label {
712
+ position: absolute;
713
+ width: 1px;
714
+ height: 1px;
715
+ margin: -1px;
716
+ padding: 0;
717
+ overflow: hidden;
718
+ clip-path: inset(50%);
719
+ white-space: nowrap;
720
+ opacity: 0;
721
+ }
722
+
723
+ .tab-dock.minimized .tab-item:has(.tab-icon),
724
+ .tab-item.search {
725
+ padding-inline: 16px;
726
+ }
727
+
728
+ /* Compact: with no label row a tab is its icon and 12px above and below,
729
+ 44px tall, the same as the inline accessory. */
730
+ .tab-dock.minimized .tab-item:has(.tab-icon),
731
+ .tab-dock.minimized .tab-item.search {
732
+ padding-block: 12px;
733
+ }
734
+
735
+ .tab-item.search.active {
736
+ background: var(--glass-tone-active-bg, var(--glass-active-bg));
737
+ }
738
+
739
+ /* The tab badge: the notification red of iOS, white text at 4.7:1 on the
740
+ default danger colour, over the top trailing corner of the icon. */
741
+ .tab-badge {
742
+ position: absolute;
743
+ top: 4px;
744
+ inset-inline-start: calc(50% + 4px);
745
+ box-sizing: border-box;
746
+ min-width: 18px;
747
+ height: 18px;
748
+ padding: 0 5px;
749
+ display: inline-flex;
750
+ align-items: center;
751
+ justify-content: center;
752
+ border-radius: var(--glass-radius-full);
753
+ background: var(--glass-badge-notification-bg, var(--color-danger));
754
+ color: var(--glass-badge-notification-text, #ffffff);
755
+ font-size: 0.6875rem;
756
+ font-weight: 600;
757
+ line-height: 1;
758
+ font-variant-numeric: tabular-nums;
759
+ pointer-events: none;
760
+ }
761
+
762
+ .tab-badge.dot {
763
+ min-width: 10px;
764
+ width: 10px;
765
+ height: 10px;
766
+ padding: 0;
767
+ top: 8px;
768
+ }
769
+
770
+ .tab-sr {
771
+ position: absolute;
772
+ width: 1px;
773
+ height: 1px;
774
+ margin: -1px;
775
+ padding: 0;
776
+ overflow: hidden;
777
+ clip: rect(0 0 0 0);
778
+ clip-path: inset(50%);
779
+ white-space: nowrap;
780
+ border: 0;
781
+ }
782
+
783
+ .tab-label {
784
+ transition:
785
+ transform var(--transition-spring),
786
+ opacity var(--transition-fast),
787
+ max-width var(--transition-spring);
788
+ }
257
789
  </style>