@spatial-elements/sveltekit 1.0.0-beta.3 → 1.0.0-beta.5

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 (42) hide show
  1. package/README.md +7 -1
  2. package/dist/index.d.ts +3 -0
  3. package/dist/index.js +2 -0
  4. package/dist/spatial-element/BrandStageShell.svelte +12 -59
  5. package/dist/spatial-element/BrandStageShell.svelte.d.ts +5 -0
  6. package/dist/spatial-element/CarouselSection.svelte +191 -48
  7. package/dist/spatial-element/CarouselSpatialElement.svelte +7 -2
  8. package/dist/spatial-element/ContentPage.svelte +2 -1
  9. package/dist/spatial-element/InteractionGesture.svelte +39 -0
  10. package/dist/spatial-element/InteractionGesture.svelte.d.ts +7 -0
  11. package/dist/spatial-element/SpatialElementBreadcrumbs.svelte +3 -1
  12. package/dist/spatial-element/SpatialElementCard.svelte +2 -1
  13. package/dist/spatial-element/SpatialElementHelp.svelte +286 -0
  14. package/dist/spatial-element/SpatialElementHelp.svelte.d.ts +3 -0
  15. package/dist/spatial-element/SpatialElementMediaRail.svelte +2 -1
  16. package/dist/spatial-element/SpatialElementPage.svelte +11 -2
  17. package/dist/spatial-element/SpatialElementSummaryPanel.svelte +34 -12
  18. package/dist/spatial-element/SpatialElementTabList.svelte +3 -1
  19. package/dist/spatial-element/SpatialElementTabs.svelte +2 -1
  20. package/dist/spatial-element/SpatialElementViewToggle.svelte +53 -0
  21. package/dist/spatial-element/SpatialElementViewToggle.svelte.d.ts +8 -0
  22. package/dist/spatial-element/SpatialIconButton.svelte +57 -0
  23. package/dist/spatial-element/SpatialIconButton.svelte.d.ts +14 -0
  24. package/dist/spatial-element/brandContext.d.ts +1 -1
  25. package/dist/spatial-element/brandContext.js +1 -1
  26. package/dist/spatial-element/index.d.ts +1 -0
  27. package/dist/spatial-element/index.js +1 -0
  28. package/dist/spatial-element/messagesContext.d.ts +3 -0
  29. package/dist/spatial-element/messagesContext.js +10 -0
  30. package/dist/spatial-element/spatialThemeStyle.d.ts +3 -0
  31. package/dist/spatial-element/spatialThemeStyle.js +48 -0
  32. package/dist/stage/ButtonGroup.svelte +163 -0
  33. package/dist/stage/ButtonGroup.svelte.d.ts +24 -0
  34. package/dist/stage/Panel.svelte +54 -11
  35. package/dist/stage/Panel.svelte.d.ts +12 -2
  36. package/dist/stage/Stage.svelte +67 -7
  37. package/dist/stage/Stage.svelte.d.ts +2 -0
  38. package/dist/stage/authoredStyle.d.ts +4 -0
  39. package/dist/stage/authoredStyle.js +17 -0
  40. package/dist/stage/buttonGroup.d.ts +9 -0
  41. package/dist/stage/buttonGroup.js +1 -0
  42. package/package.json +2 -2
package/README.md CHANGED
@@ -2,13 +2,19 @@
2
2
 
3
3
  SvelteKit components and navigation for Spatial Elements.
4
4
 
5
+ Pass a reactive `theme` and optional resolved `colorScheme` (`light` or `dark`) to `BrandStageShell` for live appearance changes. The host owns system preference and persistence. The public `ButtonGroup` component can implement a theme switch, language selector or other choices. See [runtime themes and ButtonGroup](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/theming.md).
6
+
7
+ Detail pages include 3D help and a detail/fullscreen view switch, with a viewport fallback when native fullscreen is unavailable. Pass optional `messages` to `BrandStageShell` to translate labels, tooltips and instructions, including `controls.detailView` and `controls.fullscreen`; missing strings use English defaults. See [interface texts and help](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/interface-texts.md) for the complete typed dictionary and examples.
8
+
9
+ The detail button always restores the fitted camera view, including when already on the detail page. Its selected background fades with camera zoom; the fullscreen button remains selected throughout fullscreen navigation.
10
+
5
11
  See the [authoring guide](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/authoring.md) and [development guide](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/development.md).
6
12
 
7
13
  Beta API; MPL-2.0; see LICENSE.
8
14
 
9
15
  Read the [getting-started tutorial](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/getting-started.md), [API reference](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/api.md) and [configuration migration](https://github.com/LauridBergjohann/spatial-elements/blob/main/docs/configuration-migration.md).
10
16
 
11
- Element content and required `geometry: { low, high }` belong in `SpatialElementData`; shared appearance belongs in `SpatialTheme`. Use `createSpatialTheme({ id, name })` for defaults. The SvelteKit shell needs only the theme; pages register their own data. These docs target version `1.0.0-beta.3` and newer.
17
+ Element content and required `geometry: { low, high }` belong in `SpatialElementData`; shared appearance belongs in `SpatialTheme`. Use `createSpatialTheme({ id, name })` for defaults. The SvelteKit shell needs only the theme; pages register their own data. These docs target version `1.0.0-beta.5` and newer.
12
18
 
13
19
  Installation:
14
20
 
package/dist/index.d.ts CHANGED
@@ -4,3 +4,6 @@ export { default as Stage } from './stage/Stage.svelte';
4
4
  export { default as StageViewport } from './stage/StageViewport.svelte';
5
5
  export { catalogViewLink } from '@spatial-elements/core';
6
6
  export { default as ScrollNavigationBridge } from './catalog/ScrollNavigationBridge.svelte';
7
+ export { default as ButtonGroup } from './stage/ButtonGroup.svelte';
8
+ export type { ButtonGroupItem } from './stage/buttonGroup.js';
9
+ export { getSpatialThemeStyle } from './spatial-element/spatialThemeStyle.js';
package/dist/index.js CHANGED
@@ -4,3 +4,5 @@ export { default as Stage } from './stage/Stage.svelte';
4
4
  export { default as StageViewport } from './stage/StageViewport.svelte';
5
5
  export { catalogViewLink } from '@spatial-elements/core';
6
6
  export { default as ScrollNavigationBridge } from './catalog/ScrollNavigationBridge.svelte';
7
+ export { default as ButtonGroup } from './stage/ButtonGroup.svelte';
8
+ export { getSpatialThemeStyle } from './spatial-element/spatialThemeStyle.js';
@@ -2,13 +2,19 @@
2
2
  import type { Snippet } from 'svelte';
3
3
  import Stage from '../stage/Stage.svelte';
4
4
  import type { StageRenderSettings } from '@spatial-elements/core';
5
- import { getCssPanelBoxShadow, resolvePanelShadowStrength } from '@spatial-elements/core/stage/panelShadow';
5
+ import { getSpatialThemeStyle } from './spatialThemeStyle.js';
6
6
  import { provideSpatialTheme } from './brandContext.js';
7
+ import { provideSpatialMessages } from './messagesContext.js';
8
+ import type { SpatialMessagesInput } from '@spatial-elements/core/spatial-element/messages';
7
9
  import type { SpatialTheme } from '@spatial-elements/core/spatial-element/types';
8
10
 
9
11
  interface Props {
10
12
  /** Shared appearance and namespace. Use createSpatialTheme for defaults. */
11
13
  theme: SpatialTheme;
14
+ /** Resolved by the host. System preference and persistence belong to the shell. */
15
+ colorScheme?: 'light' | 'dark';
16
+ /** Localized interface copy. Missing groups/strings fall back to English; updates are reactive. */
17
+ messages?: SpatialMessagesInput;
12
18
  /** Optional GPU resolution budget; defaults to DPR 1 and 2,073,600 pixels. */
13
19
  renderSettings?: StageRenderSettings;
14
20
  /** Draco decoder directory, including trailing slash. Default: /assets/draco/gltf/; the host must serve the files. */
@@ -17,74 +23,21 @@
17
23
  children?: Snippet;
18
24
  }
19
25
 
20
- let { theme, renderSettings, dracoDecoderPath, children }: Props = $props();
26
+ let { theme, colorScheme, messages, renderSettings, dracoDecoderPath, children }: Props = $props();
21
27
 
22
28
  provideSpatialTheme(() => theme);
29
+ provideSpatialMessages(() => messages);
23
30
 
24
- const brandStyle = $derived(
25
- [
26
- `--spatial-element-background: ${theme.background}`,
27
- `--spatial-element-ink: ${theme.colors.ink}`,
28
- `--spatial-element-body: ${theme.colors.body}`,
29
- `--spatial-element-accent: ${theme.colors.accent}`,
30
- `--spatial-element-on-accent: ${theme.colors.onAccent}`,
31
- `--spatial-element-section-tint: ${theme.sectionTheme.tint}`,
32
- `--spatial-element-section-tint-opacity: ${toPercentage(theme.sectionTheme.tintOpacity)}`,
33
- `--spatial-element-section-backdrop-blur: ${Math.max(theme.sectionTheme.backdropBlur, 0)}px`,
34
- `--spatial-element-tab-background: ${theme.colors.tabBackground}`,
35
- `--spatial-element-panel-radius: ${theme.panelShape.radius}px`,
36
- `--spatial-element-docked-panel-tint-rgb: ${getDockedPanelTintRgb(theme.dockedPanelTheme.tint)}`,
37
- `--spatial-element-docked-panel-tint-opacity: ${clamp(theme.dockedPanelTheme.tintOpacity, 0, 1)}`,
38
- `--spatial-element-docked-panel-shadow-intensity: ${clamp(theme.dockedPanelTheme.shadowIntensity, 0, 1)}`,
39
- `--spatial-element-docked-panel-shadow-strength: ${resolvePanelShadowStrength(theme.dockedPanelTheme.shadowIntensity)}`,
40
- `--spatial-element-docked-panel-box-shadow: ${getCssPanelBoxShadow(theme.dockedPanelTheme.shadowIntensity)}`,
41
- `--spatial-element-docked-panel-backdrop-blur: ${Math.min(
42
- Math.max(theme.dockedPanelTheme.backdropBlur, 0),
43
- 100
44
- )}px`
45
- ].join('; ')
46
- );
47
-
48
- function toPercentage(value: number) {
49
- return `${clamp(value, 0, 1) * 100}%`;
50
- }
51
-
52
- function getDockedPanelTintRgb(tint: SpatialTheme['dockedPanelTheme']['tint']) {
53
- const value = tint;
54
-
55
- if (typeof value === 'number') {
56
- return hexToRgb(value.toString(16).padStart(6, '0'));
57
- }
58
-
59
- if (typeof value === 'string') {
60
- const hex = value.trim().replace(/^#/, '');
61
- if (/^[0-9a-f]{3}$/i.test(hex)) {
62
- return hexToRgb(hex.replace(/(.)/g, '$1$1'));
63
- }
64
- if (/^[0-9a-f]{6}$/i.test(hex)) {
65
- return hexToRgb(hex);
66
- }
67
- }
68
-
69
- return '255 255 255';
70
- }
71
-
72
- function hexToRgb(hex: string) {
73
- const value = Number.parseInt(hex, 16);
74
- return `${(value >> 16) & 255} ${(value >> 8) & 255} ${value & 255}`;
75
- }
76
-
77
- function clamp(value: number, min: number, max: number) {
78
- return Math.min(Math.max(value, min), max);
79
- }
31
+ const brandStyle = $derived(getSpatialThemeStyle(theme));
80
32
  </script>
81
33
 
82
- <div class="brand-stage-shell" style={brandStyle}>
34
+ <div class="brand-stage-shell" style={brandStyle} style:color-scheme={colorScheme} data-color-scheme={colorScheme}>
83
35
  <Stage
84
36
  brandId={theme.id}
85
37
  {renderSettings}
86
38
  {dracoDecoderPath}
87
39
  pageBackground={theme.background}
40
+ sceneBackground={theme.sceneBackground}
88
41
  interactionTheme={theme.interactionTheme}
89
42
  ariaLabel={`${theme.name} spatialElement stage`}
90
43
  >
@@ -1,9 +1,14 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { StageRenderSettings } from '@spatial-elements/core';
3
+ import type { SpatialMessagesInput } from '@spatial-elements/core/spatial-element/messages';
3
4
  import type { SpatialTheme } from '@spatial-elements/core/spatial-element/types';
4
5
  interface Props {
5
6
  /** Shared appearance and namespace. Use createSpatialTheme for defaults. */
6
7
  theme: SpatialTheme;
8
+ /** Resolved by the host. System preference and persistence belong to the shell. */
9
+ colorScheme?: 'light' | 'dark';
10
+ /** Localized interface copy. Missing groups/strings fall back to English; updates are reactive. */
11
+ messages?: SpatialMessagesInput;
7
12
  /** Optional GPU resolution budget; defaults to DPR 1 and 2,073,600 pixels. */
8
13
  renderSettings?: StageRenderSettings;
9
14
  /** Draco decoder directory, including trailing slash. Default: /assets/draco/gltf/; the host must serve the files. */
@@ -11,6 +11,14 @@
11
11
  resolveCarouselSelection,
12
12
  stepCarouselSelection
13
13
  } from '@spatial-elements/core/catalog/carouselSelection';
14
+ import {
15
+ CarouselDrag,
16
+ CarouselScrollDrag,
17
+ clampCarouselPhase,
18
+ sampleCarouselSpring,
19
+ sampleCarouselScrollMomentum
20
+ } from '@spatial-elements/core/catalog/carouselMotion';
21
+ import { markStageScrollInput } from '@spatial-elements/core/stage/scrollFrame';
14
22
 
15
23
  let {
16
24
  section,
@@ -41,6 +49,7 @@
41
49
  });
42
50
  let ring: HTMLDivElement;
43
51
  let frame = 0;
52
+ let scrollFrame = 0;
44
53
  let visible = true;
45
54
  let suppressClick = false;
46
55
  let clickTimer: ReturnType<typeof setTimeout>;
@@ -52,14 +61,53 @@
52
61
  selectionDirty = false;
53
62
  sections?.remember();
54
63
  }
55
- let drag: { id: number; x: number; y: number; phase: number; active: boolean } | undefined;
64
+ let drag: { id: number; kind: 'pointer' | 'touch'; motion: CarouselDrag; scroll?: CarouselScrollDrag } | undefined;
65
+ function writeScroll(position: number) {
66
+ markStageScrollInput('touch');
67
+ window.scrollTo({ top: position, behavior: 'instant' });
68
+ }
69
+ function stopScrollMomentum() {
70
+ cancelAnimationFrame(scrollFrame);
71
+ scrollFrame = 0;
72
+ window.removeEventListener('touchstart', stopScrollMomentum, true);
73
+ window.removeEventListener('pointerdown', stopScrollMomentum, true);
74
+ window.removeEventListener('wheel', stopScrollMomentum, true);
75
+ window.removeEventListener('keydown', stopScrollMomentum, true);
76
+ window.removeEventListener('popstate', stopScrollMomentum);
77
+ }
78
+ function scrollMomentum(scroll: CarouselScrollDrag, velocity: number) {
79
+ stopScrollMomentum();
80
+ if (Math.abs(velocity) < 0.02 || matchMedia('(prefers-reduced-motion: reduce)').matches) return;
81
+ const start = scroll.position;
82
+ const started = performance.now();
83
+ for (const name of ['touchstart', 'pointerdown', 'wheel', 'keydown'])
84
+ window.addEventListener(name, stopScrollMomentum, { capture: true, passive: true });
85
+ window.addEventListener('popstate', stopScrollMomentum);
86
+ const advance = (now: number) => {
87
+ if (ring?.closest('[data-catalog-transition]')) {
88
+ stopScrollMomentum();
89
+ return;
90
+ }
91
+ const sample = sampleCarouselScrollMomentum(start, velocity, now - started, scroll.maximum);
92
+ writeScroll(sample.position);
93
+ if (sample.finished) stopScrollMomentum();
94
+ else scrollFrame = requestAnimationFrame(advance);
95
+ };
96
+ scrollFrame = requestAnimationFrame(advance);
97
+ }
56
98
  function invalidate() {
57
99
  window.dispatchEvent(new Event(CATALOG_POSE_CHANGED));
58
100
  }
59
101
  function releaseDrag() {
60
102
  const current = drag;
61
103
  drag = undefined;
62
- if (current && ring?.hasPointerCapture(current.id)) ring.releasePointerCapture(current.id);
104
+ window.removeEventListener('pointerup', pointerup);
105
+ window.removeEventListener('touchstart', multitouch);
106
+ window.removeEventListener('touchmove', touchmove);
107
+ window.removeEventListener('touchend', touchend);
108
+ window.removeEventListener('touchcancel', touchcancel);
109
+ if (current?.kind === 'pointer' && ring?.hasPointerCapture(current.id))
110
+ ring.releasePointerCapture(current.id);
63
111
  }
64
112
  function settle() {
65
113
  cancelAnimationFrame(frame);
@@ -70,12 +118,13 @@
70
118
  void tick().then(invalidate);
71
119
  rememberSelection();
72
120
  }
73
- function animate(target: number) {
121
+ function animate(target: number, velocity?: number) {
74
122
  cancelAnimationFrame(frame);
123
+ frame = 0;
75
124
  const start = phase;
76
125
  const started = performance.now();
77
126
  if (
78
- Math.abs(target - start) > 1.5 ||
127
+ (velocity === undefined && Math.abs(target - start) > 1.5) ||
79
128
  !visible ||
80
129
  document.hidden ||
81
130
  matchMedia('(prefers-reduced-motion: reduce)').matches
@@ -91,10 +140,17 @@
91
140
  frame = 0;
92
141
  return;
93
142
  }
94
- const t = Math.min(1, (now - started) / 320);
95
- phase = start + (target - start) * (1 - (1 - t) ** 2);
143
+ const elapsed = now - started;
144
+ const spring = velocity === undefined ? undefined : sampleCarouselSpring(start, velocity, target, elapsed);
145
+ const t = Math.min(1, elapsed / 320);
146
+ const finished = spring
147
+ ? (Math.abs(spring.phase - target) < 0.001 && Math.abs(spring.velocity) < 0.00005) || elapsed >= 1000
148
+ : t >= 1;
149
+ phase = finished ? target : spring
150
+ ? clampCarouselPhase(spring.phase, keys.length)
151
+ : start + (target - start) * (1 - (1 - t) ** 2);
96
152
  void tick().then(invalidate);
97
- if (t < 1) frame = requestAnimationFrame(advance);
153
+ if (!finished) frame = requestAnimationFrame(advance);
98
154
  else {
99
155
  frame = 0;
100
156
  announced = selected;
@@ -105,44 +161,110 @@
105
161
  }
106
162
  function pointerdown(event: PointerEvent) {
107
163
  if (
164
+ event.pointerType === 'touch' ||
165
+ drag ||
108
166
  list.length < 2 ||
109
167
  event.button !== 0 ||
110
168
  !(event.target as Element).closest('.spatial-element-visual')
111
169
  )
112
170
  return;
113
- drag = { id: event.pointerId, x: event.clientX, y: event.clientY, phase, active: false };
171
+ beginDrag(event.pointerId, 'pointer', event.clientX);
172
+ window.addEventListener('pointerup', pointerup);
114
173
  }
115
174
  function pointermove(event: PointerEvent) {
116
- if (!drag || drag.id !== event.pointerId) return;
117
- const x = event.clientX - drag.x,
118
- y = event.clientY - drag.y;
119
- if (!drag.active) {
120
- if (Math.abs(y) > 10 && Math.abs(y) > Math.abs(x)) {
121
- drag = undefined;
122
- return;
123
- }
124
- if (Math.abs(x) < 10 || Math.abs(x) < Math.abs(y) * 1.2) return;
125
- drag.active = true;
126
- suppressClick = true;
127
- cancelAnimationFrame(frame);
128
- ring.setPointerCapture(event.pointerId);
129
- }
130
- phase = Math.max(0, Math.min(keys.length - 1, drag.phase - x / 220));
131
- invalidate();
175
+ if (drag?.kind !== 'pointer' || drag.id !== event.pointerId) return;
176
+ moveDrag(event.clientX);
177
+ if (drag.motion.active && !ring.hasPointerCapture(event.pointerId)) ring.setPointerCapture(event.pointerId);
132
178
  }
133
179
  function pointerup(event: PointerEvent) {
134
- if (!drag || drag.id !== event.pointerId) return;
135
- const active = drag.active;
180
+ if (drag?.kind !== 'pointer' || drag.id !== event.pointerId) return;
181
+ endDrag(false, event.clientX);
182
+ }
183
+ function beginDrag(id: number, kind: 'pointer' | 'touch', x: number, y?: number) {
184
+ cancelAnimationFrame(frame);
185
+ stopScrollMomentum();
186
+ frame = 0;
187
+ clearTimeout(clickTimer);
188
+ suppressClick = false;
189
+ const now = performance.now();
190
+ drag = {
191
+ id, kind, motion: new CarouselDrag(x, phase, now),
192
+ scroll: y === undefined ? undefined : new CarouselScrollDrag(y, window.scrollY,
193
+ Math.max(0, document.documentElement.scrollHeight - window.innerHeight), now)
194
+ };
195
+ }
196
+ function moveDrag(x: number, y?: number) {
197
+ if (!drag) return;
198
+ const now = performance.now();
199
+ drag.motion.move(x, now, keys.length);
200
+ if (y !== undefined) drag.scroll?.move(y, now);
201
+ if (!drag.motion.active && !drag.scroll?.active) return;
202
+ suppressClick = true;
203
+ // Touch input can arrive faster than rendering. Commit only once per animation frame.
204
+ if (!frame) frame = requestAnimationFrame(() => {
205
+ frame = 0;
206
+ if (!drag) return;
207
+ phase = drag.motion.phase;
208
+ if (drag.scroll?.active) writeScroll(drag.scroll.position);
209
+ void tick().then(invalidate);
210
+ });
211
+ }
212
+ function endDrag(cancelled = false, x?: number, y?: number) {
213
+ if (!drag) return;
214
+ const { motion, kind, scroll } = drag;
215
+ const now = performance.now();
216
+ const release = motion.release(now, keys.length, x);
217
+ const scrollVelocity = scroll?.release(now, y) ?? 0;
218
+ if (motion.active || scroll?.active) suppressClick = true;
219
+ cancelAnimationFrame(frame);
220
+ frame = 0;
221
+ phase = motion.phase;
222
+ if (scroll?.active) writeScroll(scroll.position);
136
223
  releaseDrag();
137
- if (active) select(keys[Math.round(phase)]);
224
+ const momentum = !cancelled && !matchMedia('(prefers-reduced-motion: reduce)').matches;
225
+ if (motion.active) select(keys[momentum ? release.target : Math.round(phase)], momentum ? release.velocity : 0);
226
+ else animate(Math.max(0, keys.indexOf(selected ?? '')));
227
+ if (!cancelled && scroll?.active) scrollMomentum(scroll, scrollVelocity);
138
228
  clearTimeout(clickTimer);
139
- clickTimer = setTimeout(() => (suppressClick = false), 0);
229
+ // Cover compatibility clicks after touch release; a new gesture always clears this.
230
+ clickTimer = setTimeout(() => (suppressClick = false), kind === 'touch' ? 400 : 0);
140
231
  }
141
- function pointercancel() {
232
+ function pointercancel(event?: PointerEvent) {
233
+ // Native pinch zoom may cancel PointerEvents; TouchEvents own gesture cleanup.
234
+ if (event?.pointerType === 'touch') return;
235
+ stopScrollMomentum();
142
236
  releaseDrag();
143
- suppressClick = false;
237
+ clearTimeout(clickTimer);
238
+ clickTimer = setTimeout(() => (suppressClick = false), 400);
144
239
  animate(Math.max(0, keys.indexOf(selected ?? '')));
145
240
  }
241
+ function touchstart(event: TouchEvent) {
242
+ if (drag || event.touches.length !== 1 ||
243
+ !(event.target as Element).closest('.spatial-element-visual')) return;
244
+ const touch = event.touches[0];
245
+ beginDrag(touch.identifier, 'touch', touch.clientX, touch.clientY);
246
+ window.addEventListener('touchstart', multitouch, { passive: true });
247
+ window.addEventListener('touchmove', touchmove, { passive: true });
248
+ window.addEventListener('touchend', touchend, { passive: true });
249
+ window.addEventListener('touchcancel', touchcancel, { passive: true });
250
+ }
251
+ function multitouch(event: TouchEvent) {
252
+ if (drag?.kind === 'touch' && event.touches.length > 1) endDrag(true);
253
+ }
254
+ function touchmove(event: TouchEvent) {
255
+ if (drag?.kind !== 'touch') return;
256
+ if (event.touches.length !== 1) return endDrag(true);
257
+ const touch = event.touches[0];
258
+ if (touch.identifier === drag.id) moveDrag(touch.clientX, touch.clientY);
259
+ }
260
+ function touchend(event: TouchEvent) {
261
+ if (drag?.kind !== 'touch') return;
262
+ const touch = Array.from(event.changedTouches).find((touch) => touch.identifier === drag?.id);
263
+ if (touch) endDrag(false, touch.clientX, touch.clientY);
264
+ }
265
+ function touchcancel() {
266
+ if (drag?.kind === 'touch') endDrag(true);
267
+ }
146
268
  const keys = $derived(list.map(carouselKey));
147
269
  const selected = $derived(resolveCarouselSelection(keys, requested ?? initialItemKey));
148
270
  $effect(() => {
@@ -155,13 +277,13 @@
155
277
  settle();
156
278
  });
157
279
  });
158
- function select(key: string | undefined) {
280
+ function select(key: string | undefined, velocity?: number) {
159
281
  selectionDirty = true;
160
282
  requested = key;
161
283
  // Persist in the current entry before a possible popstate changes the history index.
162
284
  rememberSelection();
163
285
  const target = Math.max(0, keys.indexOf(key ?? ''));
164
- animate(target);
286
+ animate(target, velocity);
165
287
  const spatialElement = list.find((item) => carouselKey(item) === selected);
166
288
  if (spatialElement && selected) onselectionchange?.({ itemKey: selected, spatialElementId: spatialElement.id });
167
289
  }
@@ -174,36 +296,44 @@
174
296
  event.preventDefault();
175
297
  }
176
298
  onMount(() => {
299
+ // Section's child snippet can clear bind:this before this mount cleanup runs.
300
+ const carouselRing = ring;
177
301
  interactive = true;
302
+ // The model owns both single-finger axes; passive events still allow native pinch zoom.
303
+ carouselRing.addEventListener('touchstart', touchstart, { passive: true });
178
304
  const release = sections?.register(section.id, {
179
305
  read: () => selected,
180
306
  restore: (key) => {
307
+ stopScrollMomentum();
181
308
  selectionDirty = false;
182
309
  requested = resolveCarouselSelection(keys, key ?? initialItemKey);
183
310
  cancelAnimationFrame(frame);
311
+ frame = 0;
312
+ releaseDrag();
184
313
  phase = Math.max(0, keys.indexOf(requested ?? ''));
185
314
  announced = requested;
186
315
  }
187
316
  });
188
317
  const observer = new IntersectionObserver(([entry]) => {
189
318
  visible = entry.isIntersecting;
190
- if (!visible) {
319
+ // The same touch must keep scrolling after carrying the carousel out of view.
320
+ if (!visible && drag?.kind !== 'touch') {
191
321
  settle();
192
322
  }
193
323
  });
194
- observer.observe(ring);
324
+ observer.observe(carouselRing);
195
325
  let sizingFrame = 0;
196
326
  const measure = () => {
197
327
  sizingFrame = 0;
198
- const heights = [...ring.querySelectorAll<HTMLElement>('.summary')].map(
328
+ const heights = [...carouselRing.querySelectorAll<HTMLElement>('.summary')].map(
199
329
  (panel) => panel.offsetHeight
200
330
  );
201
331
  const contentHeight = Math.max(0, ...heights);
202
332
  const height =
203
- ring.clientWidth < 700 ? 408 + contentHeight : Math.max(560, contentHeight + 64);
333
+ carouselRing.clientWidth < 700 ? 408 + contentHeight : Math.max(560, contentHeight + 64);
204
334
  const value = height + 'px';
205
- if (ring.style.getPropertyValue('--carousel-height') !== value)
206
- ring.style.setProperty('--carousel-height', value);
335
+ if (carouselRing.style.getPropertyValue('--carousel-height') !== value)
336
+ carouselRing.style.setProperty('--carousel-height', value);
207
337
  };
208
338
  const scheduleSize = () => {
209
339
  if (!sizingFrame) sizingFrame = requestAnimationFrame(measure);
@@ -211,17 +341,27 @@
211
341
  const sizing = new ResizeObserver(scheduleSize);
212
342
  const contentChanges = new MutationObserver(() => {
213
343
  sizing.disconnect();
214
- sizing.observe(ring);
215
- for (const panel of ring.querySelectorAll('.summary')) sizing.observe(panel);
344
+ sizing.observe(carouselRing);
345
+ for (const panel of carouselRing.querySelectorAll('.summary')) sizing.observe(panel);
216
346
  scheduleSize();
217
347
  });
218
- contentChanges.observe(ring, { childList: true, subtree: true });
219
- sizing.observe(ring);
220
- for (const panel of ring.querySelectorAll('.summary')) sizing.observe(panel);
348
+ contentChanges.observe(carouselRing, { childList: true, subtree: true });
349
+ sizing.observe(carouselRing);
350
+ for (const panel of carouselRing.querySelectorAll('.summary')) sizing.observe(panel);
221
351
  const stop = () => pointercancel();
222
- window.addEventListener('resize', stop);
352
+ let viewportWidth = window.innerWidth;
353
+ const resize = () => {
354
+ // Mobile browser chrome resizes the height during scrolling; keep that gesture alive.
355
+ if (window.innerWidth !== viewportWidth) stop();
356
+ viewportWidth = window.innerWidth;
357
+ };
358
+ window.addEventListener('resize', resize);
359
+ window.addEventListener('blur', stop);
223
360
  const hidden = () => {
224
- if (document.hidden) settle();
361
+ if (document.hidden) {
362
+ stopScrollMomentum();
363
+ settle();
364
+ }
225
365
  };
226
366
  document.addEventListener('visibilitychange', hidden);
227
367
  const escape = (event: KeyboardEvent) => {
@@ -230,14 +370,17 @@
230
370
  window.addEventListener('keydown', escape);
231
371
  return () => {
232
372
  cancelAnimationFrame(frame);
373
+ stopScrollMomentum();
233
374
  clearTimeout(clickTimer);
234
375
  releaseDrag();
376
+ carouselRing.removeEventListener('touchstart', touchstart);
235
377
  observer.disconnect();
236
378
  sizing.disconnect();
237
379
  contentChanges.disconnect();
238
380
  cancelAnimationFrame(sizingFrame);
239
381
  release?.();
240
- window.removeEventListener('resize', stop);
382
+ window.removeEventListener('resize', resize);
383
+ window.removeEventListener('blur', stop);
241
384
  window.removeEventListener('keydown', escape);
242
385
  document.removeEventListener('visibilitychange', hidden);
243
386
  };
@@ -259,7 +402,7 @@
259
402
  onpointerup={pointerup}
260
403
  onpointercancel={pointercancel}
261
404
  onlostpointercapture={() => {
262
- if (drag) pointercancel();
405
+ if (drag?.kind === 'pointer') pointercancel();
263
406
  }}
264
407
  role="group"
265
408
  aria-label={section.title}
@@ -307,7 +450,7 @@
307
450
  .ring {
308
451
  container-type: inline-size;
309
452
  position: relative;
310
- touch-action: pan-y;
453
+ touch-action: manipulation;
311
454
  }
312
455
  .interactive.populated .ring {
313
456
  min-height: var(--carousel-height, 560px);
@@ -42,7 +42,8 @@
42
42
  const items = getContext<CatalogItems | undefined>(CATALOG_ITEMS);
43
43
  const endpoints = getContext<CatalogEndpointRegistry | undefined>(CATALOG_ENDPOINTS);
44
44
  const sections = getContext<CatalogSections | undefined>(CATALOG_SECTIONS);
45
- const brand = useSpatialTheme();
45
+ const readTheme = useSpatialTheme();
46
+ const brand = $derived(readTheme());
46
47
  const catalogEndpoint = createCatalogEndpointAction();
47
48
  function address(role: CatalogEndpointRole) {
48
49
  return interactive &&
@@ -239,12 +240,16 @@
239
240
  position: relative;
240
241
  display: grid;
241
242
  place-items: center;
242
- touch-action: pan-y;
243
+ touch-action: manipulation;
243
244
  }
244
245
  .interactive {
245
246
  display: block;
246
247
  margin: 0;
247
248
  }
249
+ .interactive .spatial-element-visual {
250
+ /* One owner for diagonal single-finger motion; two-finger page zoom stays native. */
251
+ touch-action: pinch-zoom;
252
+ }
248
253
  .interactive[hidden] {
249
254
  /* Keep known summary dimensions measurable without painting or registering GPU actors. */
250
255
  display: block;
@@ -19,7 +19,8 @@
19
19
  children?: Snippet;
20
20
  }
21
21
  let { page, hdr, children }: Props = $props();
22
- const brand = useSpatialTheme();
22
+ const readTheme = useSpatialTheme();
23
+ const brand = $derived(readTheme());
23
24
  registerSpatialPage(() => ({ kind: 'content', hdr }));
24
25
  setContext(SPATIAL_ELEMENT_SECTION_REGISTRY_KEY, new SpatialElementSectionRegistry());
25
26
  setContext(SECTION_PAGE_KIND, 'content');
@@ -0,0 +1,39 @@
1
+ <script lang="ts">
2
+ let { action, touch = false }: { action: 'rotate' | 'zoom' | 'pan'; touch?: boolean } = $props();
3
+ </script>
4
+
5
+ <!-- Decorative diagrams; the adjacent definition list supplies localized instructions. -->
6
+ <svg width="48" height="44" viewBox="0 0 48 44" fill="none" stroke="currentColor" stroke-width="1.6"
7
+ stroke-linecap="round" stroke-linejoin="round" aria-hidden="true" data-gesture={action} data-input={touch ? 'touch' : 'mouse'}>
8
+ {#if !touch}
9
+ {#if action === 'rotate'}
10
+ <path class="input-highlight" d="M24 5 C17.4 5 13 9.8 13 16 V19 H24 Z" />
11
+ {:else if action === 'pan'}
12
+ <path class="input-highlight" d="M24 5 C30.6 5 35 9.8 35 16 V19 H24 Z" />
13
+ {/if}
14
+ <rect x="13" y="5" width="22" height="34" rx="11" />
15
+ <path d="M13 19 H35 M24 5 V10 M24 16 V19" />
16
+ <rect x="22" y="10" width="4" height="7" rx="2" class:input-highlight={action === 'zoom'} />
17
+ {#if action === 'zoom'}
18
+ <path class="motion" d="M41 10 V32 M38 13 L41 10 L44 13 M38 29 L41 32 L44 29" />
19
+ {/if}
20
+ {:else if action === 'zoom'}
21
+ <!-- Two fingertips moving apart/together. -->
22
+ <path d="M6 34 L14 26 Q17 23 20 26 Q23 29 20 32 L13 39 M28 13 L35 6 Q38 3 41 6 Q44 9 41 12 L33 20" />
23
+ <path class="motion" d="M17 22 L7 22 L7 12 M7 22 L17 12 M28 24 L39 24 L39 35 M39 24 L29 34" />
24
+ {:else}
25
+ <!-- A raised index finger, or two raised fingers for panning. -->
26
+ {#if action === 'pan'}
27
+ <path d="M13 28 V15 A3 3 0 0 1 19 15 V24 V12 A3 3 0 0 1 25 12 V24 L28 22 Q30 21 32 23 L36 27 V32 Q36 36 32 40 H19 L10 30 Q8 27 10 25 Q12 23 15 26 L19 30" />
28
+ {:else}
29
+ <path d="M19 30 V14 A3 3 0 0 1 25 14 V24 L28 22 Q30 21 32 23 L36 27 V32 Q36 36 32 40 H19 L10 30 Q8 27 10 25 Q12 23 15 26 Z" />
30
+ {/if}
31
+ <path class="motion" d="M10 6 H35 M14 2 L10 6 L14 10 M31 2 L35 6 L31 10" />
32
+ {/if}
33
+ </svg>
34
+
35
+ <style>
36
+ svg { display: block; flex: none; }
37
+ .input-highlight { fill: var(--spatial-element-accent); stroke: var(--spatial-element-accent); }
38
+ .motion { stroke: var(--spatial-element-accent); }
39
+ </style>
@@ -0,0 +1,7 @@
1
+ type $$ComponentProps = {
2
+ action: 'rotate' | 'zoom' | 'pan';
3
+ touch?: boolean;
4
+ };
5
+ declare const InteractionGesture: import("svelte").Component<$$ComponentProps, {}, "">;
6
+ type InteractionGesture = ReturnType<typeof InteractionGesture>;
7
+ export default InteractionGesture;
@@ -1,5 +1,6 @@
1
1
  <script lang="ts">
2
2
  import { resolve } from '$app/paths';
3
+ import { mouseHover } from '@spatial-elements/core/stage/mouseHover';
3
4
  import type { SpatialElementBreadcrumb } from '@spatial-elements/core/spatial-element/types';
4
5
 
5
6
  let {
@@ -9,6 +10,7 @@
9
10
  </script>
10
11
 
11
12
  <nav
13
+ use:mouseHover
12
14
  class="breadcrumbs"
13
15
  data-stage-dom-content
14
16
  aria-label="Breadcrumb"
@@ -56,7 +58,7 @@
56
58
  pointer-events: auto;
57
59
  }
58
60
 
59
- a:hover {
61
+ .breadcrumbs:global([data-mouse-hover]) a:hover {
60
62
  text-decoration: underline;
61
63
  }
62
64
 
@@ -15,7 +15,8 @@
15
15
  occurrence,
16
16
  order = 0
17
17
  }: { spatialElement: SpatialListItem; occurrence: string; order?: number } = $props();
18
- const brand = useSpatialTheme();
18
+ const readTheme = useSpatialTheme();
19
+ const brand = $derived(readTheme());
19
20
  const catalogEndpoint = createCatalogEndpointAction();
20
21
  const endpoints = getContext<CatalogEndpointRegistry | undefined>(CATALOG_ENDPOINTS);
21
22
  const items = getContext<CatalogItems | undefined>(CATALOG_ITEMS);