@spatial-elements/sveltekit 0.1.0-beta.2 → 1.0.0-beta.11

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 (133) hide show
  1. package/README.md +18 -13
  2. package/dist/catalog/ScrollNavigationBridge.svelte +172 -47
  3. package/dist/catalog/ScrollNavigationBridge.svelte.d.ts +9 -2
  4. package/dist/catalog/catalogNavigation.js +3 -2
  5. package/dist/catalog/catalogSummaryTransfer.d.ts +16 -0
  6. package/dist/catalog/catalogSummaryTransfer.js +79 -0
  7. package/dist/catalog/catalogTransition.css +58 -3
  8. package/dist/catalog/interruptedPresentation.d.ts +10 -0
  9. package/dist/catalog/interruptedPresentation.js +29 -0
  10. package/dist/catalog/presentationCleanup.d.ts +4 -0
  11. package/dist/catalog/presentationCleanup.js +20 -0
  12. package/dist/catalog/stagedCatalogNavigation.d.ts +44 -0
  13. package/dist/catalog/stagedCatalogNavigation.js +403 -0
  14. package/dist/catalog/stagedDomReveal.d.ts +8 -0
  15. package/dist/catalog/stagedDomReveal.js +76 -0
  16. package/dist/index.d.ts +4 -0
  17. package/dist/index.js +3 -0
  18. package/dist/spatial-element/BrandStageShell.svelte +52 -71
  19. package/dist/spatial-element/BrandStageShell.svelte.d.ts +31 -4
  20. package/dist/spatial-element/CarouselSpatialElement.svelte +152 -200
  21. package/dist/spatial-element/CarouselSpatialElement.svelte.d.ts +5 -1
  22. package/dist/spatial-element/ContentBlock.svelte +7 -0
  23. package/dist/spatial-element/ContentBlock.svelte.d.ts +9 -0
  24. package/dist/spatial-element/ContentGrid.svelte +7 -0
  25. package/dist/spatial-element/ContentGrid.svelte.d.ts +8 -0
  26. package/dist/spatial-element/ContentPage.svelte +51 -55
  27. package/dist/spatial-element/ContentPage.svelte.d.ts +14 -3
  28. package/dist/spatial-element/InteractionGesture.svelte +39 -0
  29. package/dist/spatial-element/InteractionGesture.svelte.d.ts +7 -0
  30. package/dist/spatial-element/OverflowControls.svelte +129 -0
  31. package/dist/spatial-element/OverflowControls.svelte.d.ts +9 -0
  32. package/dist/spatial-element/PointerHint.svelte +80 -0
  33. package/dist/spatial-element/PointerHint.svelte.d.ts +3 -0
  34. package/dist/spatial-element/Section.svelte +25 -106
  35. package/dist/spatial-element/Section.svelte.d.ts +1 -0
  36. package/dist/spatial-element/SectionSurfaceGroup.svelte +8 -0
  37. package/dist/spatial-element/SectionSurfaceGroup.svelte.d.ts +8 -0
  38. package/dist/spatial-element/SpaceMouseControl.svelte +159 -0
  39. package/dist/spatial-element/SpaceMouseControl.svelte.d.ts +7 -0
  40. package/dist/spatial-element/SpaceMouseIcon.svelte +12 -0
  41. package/dist/spatial-element/SpaceMouseIcon.svelte.d.ts +26 -0
  42. package/dist/spatial-element/SpatialCardGridSection.svelte +79 -0
  43. package/dist/spatial-element/SpatialCardGridSection.svelte.d.ts +11 -0
  44. package/dist/spatial-element/SpatialCardPresentation.svelte +311 -0
  45. package/dist/spatial-element/SpatialCardPresentation.svelte.d.ts +19 -0
  46. package/dist/spatial-element/SpatialCardSlot.svelte +33 -0
  47. package/dist/spatial-element/SpatialCardSlot.svelte.d.ts +8 -0
  48. package/dist/spatial-element/SpatialCarouselSection.svelte +754 -0
  49. package/dist/spatial-element/{CarouselSection.svelte.d.ts → SpatialCarouselSection.svelte.d.ts} +5 -5
  50. package/dist/spatial-element/SpatialElementBreadcrumbs.svelte +12 -65
  51. package/dist/spatial-element/SpatialElementCard.svelte +54 -238
  52. package/dist/spatial-element/SpatialElementCard.svelte.d.ts +9 -0
  53. package/dist/spatial-element/SpatialElementHelp.svelte +300 -0
  54. package/dist/spatial-element/SpatialElementHelp.svelte.d.ts +6 -0
  55. package/dist/spatial-element/SpatialElementMediaRail.svelte +322 -52
  56. package/dist/spatial-element/SpatialElementMediaRail.svelte.d.ts +4 -1
  57. package/dist/spatial-element/SpatialElementNativeMedia.svelte +101 -0
  58. package/dist/spatial-element/SpatialElementNativeMedia.svelte.d.ts +9 -0
  59. package/dist/spatial-element/SpatialElementPage.svelte +156 -71
  60. package/dist/spatial-element/SpatialElementPage.svelte.d.ts +10 -3
  61. package/dist/spatial-element/SpatialElementStickyHeader.svelte +89 -105
  62. package/dist/spatial-element/SpatialElementStickyHeader.svelte.d.ts +6 -1
  63. package/dist/spatial-element/SpatialElementSummaryContent.svelte +198 -0
  64. package/dist/spatial-element/SpatialElementSummaryContent.svelte.d.ts +23 -0
  65. package/dist/spatial-element/SpatialElementSummaryPanel.svelte +48 -380
  66. package/dist/spatial-element/SpatialElementSummaryPanel.svelte.d.ts +2 -1
  67. package/dist/spatial-element/SpatialElementTabList.svelte +40 -17
  68. package/dist/spatial-element/SpatialElementTabList.svelte.d.ts +2 -1
  69. package/dist/spatial-element/SpatialElementTabs.svelte +61 -18
  70. package/dist/spatial-element/SpatialElementTabs.svelte.d.ts +3 -1
  71. package/dist/spatial-element/SpatialElementViewToggle.svelte +54 -0
  72. package/dist/spatial-element/SpatialElementViewToggle.svelte.d.ts +8 -0
  73. package/dist/spatial-element/SpatialIconButton.svelte +66 -0
  74. package/dist/spatial-element/SpatialIconButton.svelte.d.ts +17 -0
  75. package/dist/spatial-element/SpatialListPage.svelte +37 -8
  76. package/dist/spatial-element/SpatialListPage.svelte.d.ts +4 -1
  77. package/dist/spatial-element/SpatialMediaIndicator.svelte +16 -0
  78. package/dist/spatial-element/SpatialMediaIndicator.svelte.d.ts +26 -0
  79. package/dist/spatial-element/SpatialNavigationShell.svelte +138 -0
  80. package/dist/spatial-element/SpatialNavigationShell.svelte.d.ts +15 -0
  81. package/dist/spatial-element/SpatialSummaryHost.svelte +19 -0
  82. package/dist/spatial-element/SpatialSummaryHost.svelte.d.ts +9 -0
  83. package/dist/spatial-element/SpatialSummaryRoot.svelte +80 -0
  84. package/dist/spatial-element/SpatialSummaryRoot.svelte.d.ts +8 -0
  85. package/dist/spatial-element/SpatialSummarySlot.svelte +39 -0
  86. package/dist/spatial-element/SpatialSummarySlot.svelte.d.ts +9 -0
  87. package/dist/spatial-element/SpatialViewIcon.svelte +29 -0
  88. package/dist/spatial-element/SpatialViewIcon.svelte.d.ts +6 -0
  89. package/dist/spatial-element/brandContext.d.ts +1 -1
  90. package/dist/spatial-element/brandContext.js +1 -1
  91. package/dist/spatial-element/cardAppearanceFreeze.d.ts +5 -0
  92. package/dist/spatial-element/cardAppearanceFreeze.js +72 -0
  93. package/dist/spatial-element/carouselTextHit.d.ts +2 -0
  94. package/dist/spatial-element/carouselTextHit.js +17 -0
  95. package/dist/spatial-element/contentSidebars.d.ts +3 -0
  96. package/dist/spatial-element/contentSidebars.js +56 -0
  97. package/dist/spatial-element/index.d.ts +19 -3
  98. package/dist/spatial-element/index.js +12 -2
  99. package/dist/spatial-element/layout.generated.css +363 -0
  100. package/dist/spatial-element/messagesContext.d.ts +3 -0
  101. package/dist/spatial-element/messagesContext.js +10 -0
  102. package/dist/spatial-element/presentationBoxFreeze.d.ts +8 -0
  103. package/dist/spatial-element/presentationBoxFreeze.js +35 -0
  104. package/dist/spatial-element/spatialCardGrid.d.ts +12 -0
  105. package/dist/spatial-element/spatialCardGrid.js +1 -0
  106. package/dist/spatial-element/spatialPageContext.d.ts +4 -0
  107. package/dist/spatial-element/spatialPageContext.js +9 -0
  108. package/dist/spatial-element/spatialPresentationOwner.d.ts +6 -0
  109. package/dist/spatial-element/spatialPresentationOwner.js +2 -0
  110. package/dist/spatial-element/spatialSummary.d.ts +43 -0
  111. package/dist/spatial-element/spatialSummary.js +1 -0
  112. package/dist/spatial-element/spatialSummaryHost.svelte.d.ts +60 -0
  113. package/dist/spatial-element/spatialSummaryHost.svelte.js +233 -0
  114. package/dist/spatial-element/spatialThemeStyle.d.ts +3 -0
  115. package/dist/spatial-element/spatialThemeStyle.js +69 -0
  116. package/dist/spatial-element/truncatedTitle.d.ts +5 -0
  117. package/dist/spatial-element/truncatedTitle.js +28 -0
  118. package/dist/stage/ButtonGroup.svelte +152 -0
  119. package/dist/stage/ButtonGroup.svelte.d.ts +24 -0
  120. package/dist/stage/Panel.svelte +72 -14
  121. package/dist/stage/Panel.svelte.d.ts +14 -2
  122. package/dist/stage/Stage.svelte +471 -51
  123. package/dist/stage/Stage.svelte.d.ts +8 -1
  124. package/dist/stage/StageViewport.svelte +15 -2
  125. package/dist/stage/authoredStyle.d.ts +4 -0
  126. package/dist/stage/authoredStyle.js +17 -0
  127. package/dist/stage/buttonGroup.d.ts +9 -0
  128. package/dist/stage/buttonGroup.js +1 -0
  129. package/logo.svg +225 -0
  130. package/package.json +9 -6
  131. package/dist/spatial-element/CarouselSection.svelte +0 -350
  132. package/dist/spatial-element/ListSection.svelte +0 -30
  133. package/dist/spatial-element/ListSection.svelte.d.ts +0 -8
@@ -0,0 +1,754 @@
1
+ <script lang="ts">
2
+ import { getContext, onMount, tick, untrack } from 'svelte';
3
+ import Section from './Section.svelte';
4
+ import { retainListDeviceOrientation } from '@spatial-elements/core/catalog/listDeviceOrientation';
5
+ import { carouselTextHit } from './carouselTextHit.js';
6
+ import CarouselSpatialElement from './CarouselSpatialElement.svelte';
7
+ import {
8
+ CATALOG_POSE_CHANGED,
9
+ carouselEmphasis,
10
+ CarouselDragEmphasis,
11
+ resolveCarouselPoseLayout,
12
+ type CarouselEmphasis,
13
+ type CarouselLayout,
14
+ type CarouselPresentation
15
+ } from '@spatial-elements/core/catalog/catalogPose';
16
+ import type {
17
+ SpatialListItem,
18
+ SpatialElementSectionDefinition
19
+ } from '@spatial-elements/core/spatial-element/types';
20
+ import {
21
+ CATALOG_SECTIONS,
22
+ type CatalogSections
23
+ } from '@spatial-elements/core/catalog/CatalogSections';
24
+ import {
25
+ carouselKey,
26
+ resolveCarouselSelection,
27
+ stepCarouselSelection
28
+ } from '@spatial-elements/core/catalog/carouselSelection';
29
+ import {
30
+ CarouselDrag,
31
+ CarouselWheelInput,
32
+ clampCarouselPhase,
33
+ sampleCarouselInertia
34
+ } from '@spatial-elements/core/catalog/carouselMotion';
35
+ import {
36
+ STAGE_CONTEXT_KEY,
37
+ STAGE_PANEL_LAYOUT_EVENT,
38
+ type StageContext
39
+ } from '@spatial-elements/core/stage/panelContext';
40
+
41
+ let {
42
+ section,
43
+ presentation,
44
+ list,
45
+ initialItemKey,
46
+ onselectionchange
47
+ }: {
48
+ section: SpatialElementSectionDefinition;
49
+ presentation?: CarouselPresentation;
50
+ list: SpatialListItem[];
51
+ initialItemKey?: string;
52
+ onselectionchange?: (selection: { itemKey: string; spatialElementId: string }) => void;
53
+ } = $props();
54
+ const sections = getContext<CatalogSections | undefined>(CATALOG_SECTIONS);
55
+ const stage = getContext<StageContext | undefined>(STAGE_CONTEXT_KEY);
56
+ const interactive = $derived(stage?.isEnhanced?.() ?? false);
57
+ const keys = $derived(list.map(carouselKey));
58
+ let requested = $state<string>();
59
+ const selected = $derived(resolveCarouselSelection(keys, requested ?? initialItemKey));
60
+ const initialIndex = $derived(
61
+ Math.max(0, keys.indexOf(resolveCarouselSelection(keys, initialItemKey) ?? ''))
62
+ );
63
+ const orderedItems = $derived(
64
+ interactive
65
+ ? [...list.entries()]
66
+ : [...list.entries()].slice(initialIndex).concat([...list.entries()].slice(0, initialIndex))
67
+ );
68
+ let phase = $state(0);
69
+ let windowPhase = $state(0);
70
+ let emphasis = $state<CarouselEmphasis[] | undefined>();
71
+ const focus = $derived(emphasis ? Math.max(0, ...emphasis.map((value) => value.advance)) : 1);
72
+ const arrowOpacity = $derived(
73
+ Math.max(0, ...list.map((_, i) => emphasis?.[i]?.panel ?? carouselEmphasis(i - phase).panel))
74
+ );
75
+ const indicated = $derived(keys[Math.round(clampCarouselPhase(phase, keys.length))]);
76
+ let announced = $state<string>();
77
+ let ring: HTMLDivElement;
78
+ $effect(() => {
79
+ if (interactive && ring) return retainListDeviceOrientation(ring, () => {});
80
+ });
81
+ let layout = $state<CarouselLayout>({ width: 1320, height: 600, left: 60, viewportWidth: 1440 });
82
+ let frame = 0;
83
+ let nativeFrame = 0;
84
+ let mounted = false;
85
+ let generation = 0;
86
+ let suppressClick = false;
87
+ let clickTimer: ReturnType<typeof setTimeout>;
88
+ let wheelTimer: ReturnType<typeof setTimeout>;
89
+ let drag:
90
+ | {
91
+ id: number;
92
+ kind: 'pointer' | 'wheel';
93
+ motion: CarouselDrag;
94
+ emphasis: CarouselDragEmphasis;
95
+ x: number;
96
+ y: number;
97
+ time: number;
98
+ touch: boolean;
99
+ }
100
+ | undefined;
101
+ let wheelInput: CarouselWheelInput | undefined;
102
+ const currentEmphasis = () => keys.map((_, i) => emphasis?.[i] ?? carouselEmphasis(i - phase));
103
+ const blocked = () => !!ring?.closest('[data-catalog-transition]');
104
+ function invalidate() {
105
+ if (Math.abs(phase - windowPhase) > 0.75) windowPhase = Math.round(phase);
106
+ void tick().then(() => {
107
+ if (mounted) window.dispatchEvent(new Event(CATALOG_POSE_CHANGED));
108
+ });
109
+ }
110
+ function measureLayout() {
111
+ if (!ring) return;
112
+ const { width, left } = ring.getBoundingClientRect();
113
+ const metrics = stage?.getLayoutMetrics?.('stable') ?? {
114
+ width: innerWidth,
115
+ height: innerHeight,
116
+ scrollbarWidth: innerWidth - document.documentElement.clientWidth
117
+ };
118
+ layout = resolveCarouselPoseLayout(
119
+ { ...metrics, hasHeadline: Boolean(section.headline), hasEyebrow: true },
120
+ { width, left }
121
+ );
122
+ invalidate();
123
+ }
124
+ function commit(key: string | undefined) {
125
+ const changed = key !== selected;
126
+ requested = key;
127
+ if (changed) {
128
+ sections?.remember();
129
+ const item = list.find((item) => carouselKey(item) === key);
130
+ if (item && key) onselectionchange?.({ itemKey: key, spatialElementId: item.id });
131
+ }
132
+ }
133
+ function releaseDrag() {
134
+ ring?.closest('section')?.removeAttribute('data-carousel-dragging');
135
+ clearTimeout(wheelTimer);
136
+ const current = drag;
137
+ drag = undefined;
138
+ wheelInput = undefined;
139
+ window.removeEventListener('pointermove', pointermove);
140
+ window.removeEventListener('pointerup', pointerup);
141
+ window.removeEventListener('pointercancel', pointercancel);
142
+ if (current?.kind === 'pointer' && ring?.hasPointerCapture(current.id))
143
+ ring.releasePointerCapture(current.id);
144
+ }
145
+ // One clock drives the turntable and foreground reveal. No scrollLeft writes,
146
+ // snap handoff or velocity overshoot can move the destination sideways first.
147
+ function animate(target: number, reveal = false, velocity = 0) {
148
+ cancelAnimationFrame(frame);
149
+ const start = phase,
150
+ initial = reveal ? currentEmphasis() : undefined;
151
+ if (!reveal) emphasis = undefined;
152
+ const started = performance.now();
153
+ const duration = reveal ? 240 : Math.min(600, 280 + Math.abs(target - start) * 40);
154
+ const reduced = document.hidden || matchMedia('(prefers-reduced-motion: reduce)').matches;
155
+ const advance = (now: number) => {
156
+ frame = 0;
157
+ if (blocked()) return;
158
+ // A queued frame timestamp can precede the release event within that frame.
159
+ const t = reduced ? 1 : Math.max(0, Math.min(1, (now - started) / duration));
160
+ const inertia =
161
+ !reduced && velocity * (target - start) > 0
162
+ ? sampleCarouselInertia(start, velocity, target, now - started)
163
+ : undefined;
164
+ const amount = inertia?.progress ?? 1 - (1 - t) ** 2;
165
+ // A nearby endpoint can absorb the horizontal speed in one frame. Keep
166
+ // foreground travel continuous, starting now, even in that limiting case.
167
+ const revealAmount = inertia ? Math.min(amount, 1 - (1 - t) ** 2) : amount;
168
+ const finished = inertia ? inertia.finished && t === 1 : t === 1;
169
+ phase = inertia?.phase ?? start + (target - start) * amount;
170
+ if (initial)
171
+ emphasis = initial.map((value, i) => ({
172
+ advance: value.advance * (1 - revealAmount) + (i === target ? revealAmount : 0),
173
+ panel: value.panel * (1 - revealAmount) + (i === target ? revealAmount : 0)
174
+ }));
175
+ if (finished) {
176
+ emphasis = undefined;
177
+ announced = selected;
178
+ }
179
+ invalidate();
180
+ if (!finished) frame = requestAnimationFrame(advance);
181
+ };
182
+ if (reduced) advance(started);
183
+ else frame = requestAnimationFrame(advance);
184
+ }
185
+ function beginDrag(id: number, kind: 'pointer' | 'wheel', x: number, y = 0, touch = false) {
186
+ // A tap or zero wheel sample must not interrupt a running selection.
187
+ const time = performance.now();
188
+ drag = {
189
+ id,
190
+ kind,
191
+ x,
192
+ y,
193
+ touch,
194
+ time,
195
+ motion: new CarouselDrag(x, phase, time),
196
+ emphasis: new CarouselDragEmphasis(phase, currentEmphasis())
197
+ };
198
+ clearTimeout(clickTimer);
199
+ suppressClick = false;
200
+ }
201
+ function moveDrag(x: number) {
202
+ if (!drag) return;
203
+ if (!drag.motion.active) {
204
+ drag.motion = new CarouselDrag(drag.x, phase, drag.time);
205
+ drag.emphasis = new CarouselDragEmphasis(phase, currentEmphasis());
206
+ }
207
+ drag.motion.move(x, performance.now(), keys.length);
208
+ if (!drag.motion.active) return;
209
+ if (drag.kind === 'pointer' && !drag.touch)
210
+ ring.closest('section')?.setAttribute('data-carousel-dragging', '');
211
+ cancelAnimationFrame(frame);
212
+ suppressClick = true;
213
+ phase = drag.motion.phase;
214
+ emphasis = drag.emphasis.move(phase);
215
+ invalidate();
216
+ }
217
+ function endDrag(x?: number, inertia = false) {
218
+ if (!drag) return;
219
+ const { motion, touch, kind } = drag;
220
+ // An idle timeout detects wheel release after the fact; use the final
221
+ // sample's time so this bookkeeping delay does not discard its velocity.
222
+ const wheelRelease = kind === 'wheel' && inertia && (wheelInput?.samples ?? 0) > 1;
223
+ const release = motion.release(
224
+ wheelRelease ? wheelInput!.lastTime! : performance.now(),
225
+ keys.length,
226
+ x
227
+ );
228
+ const active = motion.active;
229
+ if (active) {
230
+ phase = motion.phase;
231
+ emphasis = drag.emphasis.move(phase);
232
+ }
233
+ const velocity =
234
+ inertia &&
235
+ (kind === 'pointer' || wheelRelease) &&
236
+ Math.abs(release.velocity) >= 0.0005 &&
237
+ !matchMedia('(prefers-reduced-motion: reduce)').matches
238
+ ? release.velocity
239
+ : 0;
240
+ releaseDrag();
241
+ if (active) {
242
+ const target = velocity ? release.target : Math.round(clampCarouselPhase(phase, keys.length));
243
+ commit(keys[target]);
244
+ animate(target, true, velocity);
245
+ }
246
+ clearTimeout(clickTimer);
247
+ clickTimer = setTimeout(
248
+ () => {
249
+ suppressClick = false;
250
+ },
251
+ touch ? 400 : 0
252
+ );
253
+ }
254
+ function canStartDrag(target: EventTarget | null, touch = false) {
255
+ if (
256
+ !(target instanceof Element) ||
257
+ target.closest('.controls, .carousel-arrows, input, textarea, select, [contenteditable]')
258
+ )
259
+ return false;
260
+ return touch || !target.closest('a, button') || !!target.closest('.spatial-element-target');
261
+ }
262
+ function pointerdown(event: PointerEvent) {
263
+ if (!interactive || blocked() || list.length < 2) return;
264
+ if (!event.isPrimary) {
265
+ if (drag?.kind === 'pointer') endDrag();
266
+ return;
267
+ }
268
+ if (drag?.kind === 'wheel') endDrag();
269
+ const touch = event.pointerType !== 'mouse';
270
+ if (!touch && carouselTextHit(event.target, event.clientX, event.clientY)) return;
271
+ if (drag || event.button !== 0 || !canStartDrag(event.target, touch)) return;
272
+ if (!touch) event.preventDefault();
273
+ beginDrag(event.pointerId, 'pointer', event.clientX, event.clientY, touch);
274
+ window.addEventListener('pointermove', pointermove);
275
+ window.addEventListener('pointerup', pointerup);
276
+ window.addEventListener('pointercancel', pointercancel);
277
+ }
278
+ function pointermove(event: PointerEvent) {
279
+ if (drag?.kind !== 'pointer' || drag.id !== event.pointerId || blocked()) return;
280
+ if (
281
+ drag.touch &&
282
+ !drag.motion.active &&
283
+ Math.abs(event.clientX - drag.x) <= Math.abs(event.clientY - drag.y) * 1.2
284
+ )
285
+ return;
286
+ moveDrag(event.clientX);
287
+ if (drag?.motion.active && !ring.hasPointerCapture(event.pointerId))
288
+ ring.setPointerCapture(event.pointerId);
289
+ }
290
+ function pointerup(event: PointerEvent) {
291
+ if (drag?.kind !== 'pointer' || drag.id !== event.pointerId) return;
292
+ // Do not turn a native vertical gesture or a tap into a horizontal release.
293
+ endDrag(drag.motion.active ? event.clientX : undefined, true);
294
+ }
295
+ function pointercancel(event: PointerEvent) {
296
+ if (drag?.kind === 'pointer' && drag.id === event.pointerId) endDrag();
297
+ }
298
+ function wheel(event: WheelEvent) {
299
+ if (
300
+ !interactive ||
301
+ blocked() ||
302
+ list.length < 2 ||
303
+ event.ctrlKey ||
304
+ (drag && drag.kind !== 'wheel')
305
+ )
306
+ return;
307
+ const scale = event.deltaMode === 1 ? 16 : event.deltaMode === 2 ? ring.clientWidth : 1;
308
+ const dx = (event.shiftKey && !event.deltaX ? event.deltaY : event.deltaX) * scale;
309
+ const dy = event.shiftKey && !event.deltaX ? 0 : event.deltaY * scale;
310
+ if (!drag && (!dx || Math.abs(dx) <= Math.abs(dy) * 1.2)) return;
311
+ if (event.cancelable) event.preventDefault();
312
+ // Newer browsers identify the platform's inertial tail. Finish once and
313
+ // ignore that tail; never add a second fling or reopen the withdrawn panel.
314
+ if ((event as WheelEvent & { momentum?: boolean }).momentum === true) {
315
+ if (drag?.kind === 'wheel') endDrag(undefined, true);
316
+ return;
317
+ }
318
+ if (!dx && !drag) return;
319
+ if (!drag) {
320
+ beginDrag(0, 'wheel', 0);
321
+ wheelInput = new CarouselWheelInput();
322
+ }
323
+ if (!wheelInput) return;
324
+ wheelInput.move(dx, performance.now());
325
+ moveDrag(wheelInput.x);
326
+ clearTimeout(wheelTimer);
327
+ wheelTimer = setTimeout(() => {
328
+ if (drag?.kind === 'wheel') endDrag(undefined, true);
329
+ }, wheelInput.idleMs);
330
+ }
331
+ function select(key: string | undefined) {
332
+ releaseDrag();
333
+ commit(key);
334
+ if (interactive) animate(Math.max(0, keys.indexOf(key ?? '')));
335
+ else scrollNative(key, true);
336
+ }
337
+ function scrollNative(key: string | undefined, smooth = false) {
338
+ if (!ring || !keys.length || interactive) return;
339
+ const index = Math.max(0, keys.indexOf(key ?? ''));
340
+ const seat = (index - initialIndex + keys.length) % keys.length;
341
+ ring.scrollTo({
342
+ left: seat * ring.clientWidth,
343
+ behavior:
344
+ smooth && !matchMedia('(prefers-reduced-motion: reduce)').matches ? 'smooth' : 'instant'
345
+ });
346
+ }
347
+ function nativeScroll() {
348
+ if (interactive || nativeFrame || !keys.length) return;
349
+ nativeFrame = requestAnimationFrame(() => {
350
+ nativeFrame = 0;
351
+ if (interactive) return;
352
+ const seat = Math.round(ring.scrollLeft / Math.max(1, ring.clientWidth));
353
+ const index = (seat + initialIndex) % keys.length;
354
+ phase = windowPhase = index;
355
+ announced = keys[index];
356
+ commit(keys[index]);
357
+ });
358
+ }
359
+ function keydown(event: KeyboardEvent) {
360
+ const step = event.key === 'ArrowRight' ? 1 : event.key === 'ArrowLeft' ? -1 : 0;
361
+ if (step) select(stepCarouselSelection(keys, selected, step));
362
+ else if (event.key === 'Home') select(keys[0]);
363
+ else if (event.key === 'End') select(keys.at(-1));
364
+ else return;
365
+ event.preventDefault();
366
+ }
367
+ function resetMotion() {
368
+ cancelAnimationFrame(frame);
369
+ cancelAnimationFrame(nativeFrame);
370
+ frame = nativeFrame = 0;
371
+ releaseDrag();
372
+ phase = windowPhase = Math.max(0, keys.indexOf(selected ?? ''));
373
+ emphasis = undefined;
374
+ announced = selected;
375
+ invalidate();
376
+ }
377
+ $effect(() => {
378
+ const enhanced = interactive,
379
+ signature = JSON.stringify(keys);
380
+ untrack(() => {
381
+ if (!mounted) return;
382
+ const token = ++generation;
383
+ resetMotion();
384
+ void tick().then(() => {
385
+ if (!mounted || token !== generation) return;
386
+ if (enhanced) ring.scrollLeft = 0;
387
+ else {
388
+ for (const panel of ring.querySelectorAll<HTMLElement>('.summary'))
389
+ panel.style.removeProperty('transform');
390
+ for (const target of ring.querySelectorAll<HTMLElement>('.spatial-element-target'))
391
+ for (const property of ['left', 'top', 'width', 'height', 'max-width'])
392
+ target.style.removeProperty(property);
393
+ scrollNative(selected);
394
+ }
395
+ measureLayout();
396
+ });
397
+ });
398
+ });
399
+ onMount(() => {
400
+ mounted = true;
401
+ const carouselRing = ring;
402
+ const nativeSeat = Math.round(ring.scrollLeft / Math.max(1, ring.clientWidth));
403
+ const nativeInitialKey = keys[(nativeSeat + initialIndex) % Math.max(1, keys.length)];
404
+ let restored = false;
405
+ const release = sections?.register(section.id, {
406
+ read: () => selected,
407
+ restore: (key) => {
408
+ requested = resolveCarouselSelection(
409
+ keys,
410
+ key ?? (!restored && !interactive ? nativeInitialKey : initialItemKey)
411
+ );
412
+ restored = true;
413
+ resetMotion();
414
+ void tick().then(() => {
415
+ if (mounted) scrollNative(requested);
416
+ });
417
+ }
418
+ });
419
+ measureLayout();
420
+ const observer = new ResizeObserver(measureLayout);
421
+ observer.observe(carouselRing);
422
+ const dragSection = ring.closest('section')!;
423
+ dragSection.addEventListener('wheel', wheel, { passive: false });
424
+ const stop = () => {
425
+ if (drag) endDrag();
426
+ };
427
+ const hidden = () => {
428
+ if (document.hidden) resetMotion();
429
+ };
430
+ const escape = (event: KeyboardEvent) => {
431
+ if (event.key === 'Escape') stop();
432
+ };
433
+ window.addEventListener('blur', stop);
434
+ window.addEventListener('keydown', escape);
435
+ window.addEventListener('resize', measureLayout);
436
+ window.addEventListener(STAGE_PANEL_LAYOUT_EVENT, measureLayout);
437
+ document.addEventListener('visibilitychange', hidden);
438
+ return () => {
439
+ mounted = false;
440
+ generation++;
441
+ cancelAnimationFrame(frame);
442
+ cancelAnimationFrame(nativeFrame);
443
+ clearTimeout(clickTimer);
444
+ releaseDrag();
445
+ observer.disconnect();
446
+ release?.();
447
+ dragSection.removeEventListener('wheel', wheel);
448
+ window.removeEventListener('blur', stop);
449
+ window.removeEventListener('keydown', escape);
450
+ window.removeEventListener('resize', measureLayout);
451
+ window.removeEventListener(STAGE_PANEL_LAYOUT_EVENT, measureLayout);
452
+ document.removeEventListener('visibilitychange', hidden);
453
+ };
454
+ });
455
+ </script>
456
+
457
+ <Section
458
+ {section}
459
+ presentation="list"
460
+ class="carousel-drag-section"
461
+ ondragstart={(event) => {
462
+ if (interactive && canStartDrag(event.target)) event.preventDefault();
463
+ }}
464
+ onpointerdown={pointerdown}
465
+ onclickcapture={(event) => {
466
+ if (suppressClick) {
467
+ event.preventDefault();
468
+ event.stopPropagation();
469
+ }
470
+ }}
471
+ onlostpointercapture={(event) => {
472
+ // Touch starts with implicit capture on its hit target. Moving capture to
473
+ // the ring must not be mistaken for the end of that same gesture.
474
+ if (event.target === ring && drag?.kind === 'pointer' && drag.id === event.pointerId) endDrag();
475
+ }}
476
+ >
477
+ {#if interactive}
478
+ <div
479
+ class="drag-surface"
480
+ aria-hidden="true"
481
+ style:left={section.background?.size === 'full' ? `${-layout.left}px` : '0'}
482
+ style:width={section.background?.size === 'full' ? `${layout.viewportWidth}px` : '100%'}
483
+ ></div>
484
+ {/if}
485
+ <div
486
+ class="carousel"
487
+ class:interactive
488
+ class:populated={list.length > 0}
489
+ data-carousel-section={section.id}
490
+ data-device-orientation=""
491
+ >
492
+ <!-- svelte-ignore a11y_no_noninteractive_tabindex (The native scroll rail must be keyboard-scrollable without JavaScript.) -->
493
+ <div
494
+ class="ring"
495
+ id={`carousel-ring-${section.id}`}
496
+ tabindex={interactive ? undefined : 0}
497
+ bind:this={ring}
498
+ onscroll={nativeScroll}
499
+ role="group"
500
+ aria-label={section.title}
501
+ >
502
+ {#each orderedItems as [index, spatialElement] (carouselKey(spatialElement))}
503
+ <CarouselSpatialElement
504
+ {spatialElement}
505
+ sectionId={section.id}
506
+ {presentation}
507
+ {layout}
508
+ {index}
509
+ count={list.length}
510
+ {phase}
511
+ emphasis={emphasis?.[index]}
512
+ {focus}
513
+ {windowPhase}
514
+ selected={selected === carouselKey(spatialElement)}
515
+ {interactive}
516
+ onselect={() => {
517
+ if (!suppressClick) select(carouselKey(spatialElement));
518
+ }}
519
+ canActivate={() => !suppressClick}
520
+ />
521
+ {/each}
522
+ {#if interactive && list.length > 1}
523
+ <div
524
+ class="carousel-arrows"
525
+ role="group"
526
+ aria-label="Carousel navigation"
527
+ style:opacity={arrowOpacity}
528
+ inert={arrowOpacity < 0.05}
529
+ >
530
+ <button
531
+ type="button"
532
+ class="previous"
533
+ hidden={selected === keys[0]}
534
+ aria-label="Previous product"
535
+ aria-controls={`carousel-ring-${section.id}`}
536
+ onclick={() => select(stepCarouselSelection(keys, selected, -1))}
537
+ >
538
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m14 6-6 6 6 6" /></svg>
539
+ </button>
540
+ <button
541
+ type="button"
542
+ class="next"
543
+ hidden={selected === keys.at(-1)}
544
+ aria-label="Next product"
545
+ aria-controls={`carousel-ring-${section.id}`}
546
+ onclick={() => select(stepCarouselSelection(keys, selected, 1))}
547
+ >
548
+ <svg viewBox="0 0 24 24" aria-hidden="true"><path d="m10 6 6 6-6 6" /></svg>
549
+ </button>
550
+ </div>
551
+ {/if}
552
+ </div>
553
+ {#if list.length > 0}
554
+ <div class="controls" role="group" aria-label={`${section.title}: element selection`}>
555
+ {#if list.length > 1}
556
+ {#each list as spatialElement (carouselKey(spatialElement))}
557
+ {#if interactive}
558
+ <button
559
+ onkeydown={keydown}
560
+ aria-label={spatialElement.eyebrow || spatialElement.title}
561
+ aria-pressed={indicated === carouselKey(spatialElement)}
562
+ onclick={() => select(carouselKey(spatialElement))}
563
+ ><span aria-hidden="true"></span></button
564
+ >
565
+ {:else}
566
+ <a
567
+ href={`#carousel-${section.id}-${list.indexOf(spatialElement)}`}
568
+ aria-label={spatialElement.eyebrow || spatialElement.title}
569
+ aria-current={selected === carouselKey(spatialElement) ? 'true' : undefined}
570
+ onclick={(event) => {
571
+ event.preventDefault();
572
+ select(carouselKey(spatialElement));
573
+ }}><span aria-hidden="true"></span></a
574
+ >
575
+ {/if}
576
+ {/each}
577
+ {/if}
578
+ </div>
579
+ {/if}
580
+ {#if interactive}<p class="sr-only" role="status">
581
+ {list.find((item) => carouselKey(item) === announced)?.title ?? ''}
582
+ </p>{/if}
583
+ </div>
584
+ </Section>
585
+
586
+ <style>
587
+ /* Clip projected DOM hit regions to the same surface as the GPU models. */
588
+ :global(.carousel-drag-section) {
589
+ position: relative;
590
+ /* clip-path creates a Backdrop Root and prevents frosted panels from
591
+ sampling the stage canvas. Overflow clipping preserves that backdrop. */
592
+ overflow: clip;
593
+ }
594
+ :global(.carousel-drag-section[data-section-background-size='full']) {
595
+ overflow-x: visible;
596
+ }
597
+ :global(.carousel-drag-section:has(.interactive)) {
598
+ touch-action: pan-y pinch-zoom;
599
+ }
600
+ :global(.carousel-drag-section > .ps-section-content > .section-heading .headline) {
601
+ /* Match the carousel resolver's measured heading budget. */
602
+ font-size: var(--spatial-grid-headline-size);
603
+ line-height: var(--spatial-grid-headline-line-height);
604
+ pointer-events: none;
605
+ }
606
+ .drag-surface {
607
+ position: absolute;
608
+ top: 0;
609
+ bottom: 0;
610
+ pointer-events: auto;
611
+ touch-action: pan-y pinch-zoom;
612
+ cursor: grab;
613
+ }
614
+ :global(.carousel.interactive .summary) {
615
+ cursor: grab;
616
+ }
617
+ :global(.carousel.interactive .summary a),
618
+ :global(.carousel.interactive .summary button) {
619
+ cursor: pointer;
620
+ }
621
+ :global(.carousel.interactive [data-carousel-text-hit]) {
622
+ cursor: text;
623
+ }
624
+ :global(.carousel-drag-section[data-carousel-dragging]),
625
+ :global(.carousel-drag-section[data-carousel-dragging] *) {
626
+ cursor: grabbing !important;
627
+ user-select: none;
628
+ }
629
+ .carousel.interactive {
630
+ pointer-events: none;
631
+ }
632
+ .carousel {
633
+ pointer-events: auto;
634
+ margin-top: 0;
635
+ }
636
+ .ring {
637
+ container-type: inline-size;
638
+ display: grid;
639
+ grid-auto-flow: column;
640
+ grid-auto-columns: 100%;
641
+ position: relative;
642
+ height: calc(var(--spatial-carousel-title-reserve) + var(--spatial-carousel-fit-height));
643
+ overflow-x: auto;
644
+ overflow-y: hidden;
645
+ scroll-snap-type: x mandatory;
646
+ overscroll-behavior-x: contain;
647
+ scrollbar-width: none;
648
+ scrollbar-color: var(--spatial-element-accent) transparent;
649
+ touch-action: manipulation;
650
+ }
651
+ .ring:focus-visible {
652
+ outline: 2px solid var(--spatial-element-accent);
653
+ outline-offset: 4px;
654
+ }
655
+ .interactive .ring {
656
+ scrollbar-width: none;
657
+ grid-auto-flow: row;
658
+ grid-template-columns: 100%;
659
+ overflow: visible;
660
+ scroll-snap-type: none;
661
+ }
662
+ .carousel-arrows {
663
+ position: absolute;
664
+ left: var(--spatial-carousel-fit-left);
665
+ width: var(--spatial-carousel-fit-width);
666
+ top: calc(var(--spatial-carousel-title-reserve) + var(--spatial-carousel-fit-height) / 2);
667
+ transform: translateY(-50%);
668
+ z-index: 1500;
669
+ display: flex;
670
+ justify-content: space-between;
671
+ pointer-events: none;
672
+ }
673
+ .carousel-arrows button {
674
+ pointer-events: auto;
675
+ width: 44px;
676
+ height: 44px;
677
+ display: grid;
678
+ place-items: center;
679
+ padding: 8px;
680
+ border: 0;
681
+ border-radius: 50%;
682
+ color: var(--spatial-element-accent);
683
+ background: transparent;
684
+ cursor: pointer;
685
+ }
686
+ .carousel-arrows button[hidden] {
687
+ visibility: hidden;
688
+ pointer-events: none;
689
+ }
690
+ .carousel-arrows button:hover {
691
+ background: color-mix(in srgb, var(--spatial-element-accent) 12%, transparent);
692
+ }
693
+ .carousel-arrows button:focus-visible {
694
+ outline: 2px solid var(--spatial-element-accent);
695
+ }
696
+ .carousel-arrows svg {
697
+ width: 24px;
698
+ height: 24px;
699
+ fill: none;
700
+ stroke: currentColor;
701
+ stroke-width: 2;
702
+ stroke-linecap: round;
703
+ stroke-linejoin: round;
704
+ }
705
+ .controls {
706
+ position: relative;
707
+ display: flex;
708
+ justify-content: center;
709
+ flex-wrap: nowrap;
710
+ height: var(--spatial-carousel-dots-height);
711
+ margin-top: var(--spatial-carousel-dots-gap);
712
+ overflow-x: auto;
713
+ scrollbar-width: none;
714
+ }
715
+ .controls button,
716
+ .controls a {
717
+ pointer-events: auto;
718
+ display: grid;
719
+ place-items: center;
720
+ flex: 0 0 var(--spatial-carousel-dots-height);
721
+ width: var(--spatial-carousel-dots-height);
722
+ height: var(--spatial-carousel-dots-height);
723
+ padding: 0;
724
+ border: 0;
725
+ background: transparent;
726
+ border-radius: 50%;
727
+ cursor: pointer;
728
+ }
729
+ .controls span {
730
+ width: 10px;
731
+ height: 10px;
732
+ border: 1px solid var(--spatial-element-accent);
733
+ border-radius: 50%;
734
+ }
735
+ .controls button[aria-pressed='true'] span,
736
+ .controls a[aria-current='true'] span {
737
+ background: var(--spatial-element-accent);
738
+ }
739
+ .controls button:focus-visible,
740
+ .controls a:focus-visible {
741
+ outline: 2px solid var(--spatial-element-accent);
742
+ outline-offset: -4px;
743
+ }
744
+ .sr-only {
745
+ position: absolute;
746
+ width: 1px;
747
+ height: 1px;
748
+ padding: 0;
749
+ margin: -1px;
750
+ overflow: hidden;
751
+ clip-path: inset(50%);
752
+ white-space: nowrap;
753
+ }
754
+ </style>