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

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 (41) hide show
  1. package/README.md +11 -3
  2. package/dist/catalog/catalogNavigation.js +3 -2
  3. package/dist/spatial-element/BrandStageShell.svelte +17 -12
  4. package/dist/spatial-element/BrandStageShell.svelte.d.ts +11 -4
  5. package/dist/spatial-element/CarouselSection.svelte +184 -38
  6. package/dist/spatial-element/CarouselSection.svelte.d.ts +5 -0
  7. package/dist/spatial-element/CarouselSpatialElement.svelte +7 -3
  8. package/dist/spatial-element/ContentPage.svelte +11 -1
  9. package/dist/spatial-element/ContentPage.svelte.d.ts +7 -3
  10. package/dist/spatial-element/InteractionGesture.svelte +39 -0
  11. package/dist/spatial-element/InteractionGesture.svelte.d.ts +7 -0
  12. package/dist/spatial-element/ListSection.svelte +11 -3
  13. package/dist/spatial-element/ListSection.svelte.d.ts +5 -3
  14. package/dist/spatial-element/SpatialElementBreadcrumbs.svelte +3 -1
  15. package/dist/spatial-element/SpatialElementCard.svelte +2 -2
  16. package/dist/spatial-element/SpatialElementHelp.svelte +277 -0
  17. package/dist/spatial-element/SpatialElementHelp.svelte.d.ts +3 -0
  18. package/dist/spatial-element/SpatialElementMediaRail.svelte +1 -1
  19. package/dist/spatial-element/SpatialElementMediaRail.svelte.d.ts +1 -1
  20. package/dist/spatial-element/SpatialElementPage.svelte +25 -8
  21. package/dist/spatial-element/SpatialElementPage.svelte.d.ts +5 -3
  22. package/dist/spatial-element/SpatialElementStickyHeader.svelte +42 -37
  23. package/dist/spatial-element/SpatialElementStickyHeader.svelte.d.ts +2 -1
  24. package/dist/spatial-element/SpatialElementSummaryPanel.svelte +60 -55
  25. package/dist/spatial-element/SpatialElementSummaryPanel.svelte.d.ts +1 -1
  26. package/dist/spatial-element/SpatialElementTabList.svelte +3 -1
  27. package/dist/spatial-element/SpatialIconButton.svelte +56 -0
  28. package/dist/spatial-element/SpatialIconButton.svelte.d.ts +14 -0
  29. package/dist/spatial-element/SpatialListPage.svelte +4 -1
  30. package/dist/spatial-element/SpatialListPage.svelte.d.ts +2 -0
  31. package/dist/spatial-element/index.d.ts +5 -1
  32. package/dist/spatial-element/index.js +3 -0
  33. package/dist/spatial-element/messagesContext.d.ts +3 -0
  34. package/dist/spatial-element/messagesContext.js +10 -0
  35. package/dist/spatial-element/spatialPageContext.d.ts +4 -0
  36. package/dist/spatial-element/spatialPageContext.js +9 -0
  37. package/dist/stage/Panel.svelte +30 -2
  38. package/dist/stage/Panel.svelte.d.ts +12 -2
  39. package/dist/stage/Stage.svelte +97 -17
  40. package/dist/stage/Stage.svelte.d.ts +5 -1
  41. package/package.json +4 -4
package/README.md CHANGED
@@ -2,21 +2,29 @@
2
2
 
3
3
  SvelteKit components and navigation for Spatial Elements.
4
4
 
5
+ Detail pages include a compact 3D help button. Pass optional `messages` to `BrandStageShell` to translate its labels, tooltips and instructions; 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.
6
+
5
7
  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
8
 
7
9
  Beta API; MPL-2.0; see LICENSE.
8
10
 
11
+ 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).
12
+
13
+ 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.
14
+
9
15
  Installation:
10
16
 
11
17
  ~~~sh
12
- npm install @spatial-elements/sveltekit@beta
18
+ npm install @spatial-elements/sveltekit@latest
13
19
  ~~~
14
20
 
15
21
  Requires Node.js 22.12+ tooling. Use in an existing Svelte 5 / SvelteKit 2 application.
16
22
 
17
23
  A visible “Built with Spatial Elements” link is appreciated, but not required. This does not replace your obligations under the MPL-2.0 license.
18
24
 
19
- Three.js is a required peer dependency (^0.185.1), shared with the application and other adapters.
25
+ Three.js is a required peer dependency (^0.186.1), shared with the application and other adapters.
20
26
  Modern npm installs it automatically. If the application imports Three.js directly, declare it
21
- explicitly with `npm install three@^0.185.1`. Do not bypass incompatible peer ranges with
27
+ explicitly with `npm install three@^0.186.1`. Do not bypass incompatible peer ranges with
22
28
  `--legacy-peer-deps`. Other package managers may require explicit peer installation.
29
+
30
+ Category lighting is explicit: pass `hdr="/assets/category.hdr"` to `ContentPage` (also `SpatialListPage`). It is never inferred from an element. Identical geometry URLs share one cached fetch/decode.
@@ -1,3 +1,4 @@
1
+ import { getSpatialElementScene, hasSpatialElementScene } from '@spatial-elements/core/spatial-element/spatialElementScene';
1
2
  import { getContext } from 'svelte';
2
3
  import { resolve } from '$app/paths';
3
4
  import { navigating } from '$app/state';
@@ -12,8 +13,8 @@ export function useCatalogNavigation() {
12
13
  pending: () => navigating.to?.url,
13
14
  prepare(spatialElement) {
14
15
  void preloadData(href(spatialElement.href)).catch(() => { });
15
- if (spatialElement.stage)
16
- stage?.prefetchSpatialElement?.(spatialElement.stage);
16
+ if (hasSpatialElementScene(spatialElement))
17
+ stage?.prefetchSpatialElement?.(getSpatialElementScene(spatialElement));
17
18
  }
18
19
  };
19
20
  }
@@ -1,21 +1,30 @@
1
1
  <script lang="ts">
2
2
  import type { Snippet } from 'svelte';
3
3
  import Stage from '../stage/Stage.svelte';
4
- import type { CatalogPage } from '@spatial-elements/core/catalog/catalogPage';
4
+ import type { StageRenderSettings } from '@spatial-elements/core';
5
5
  import { getCssPanelBoxShadow, resolvePanelShadowStrength } from '@spatial-elements/core/stage/panelShadow';
6
6
  import { provideSpatialTheme } from './brandContext.js';
7
- import type { SpatialTheme, SpatialStageConfig } from '@spatial-elements/core/spatial-element/types';
7
+ import { provideSpatialMessages } from './messagesContext.js';
8
+ import type { SpatialMessagesInput } from '@spatial-elements/core/spatial-element/messages';
9
+ import type { SpatialTheme } from '@spatial-elements/core/spatial-element/types';
8
10
 
9
11
  interface Props {
12
+ /** Shared appearance and namespace. Use createSpatialTheme for defaults. */
10
13
  theme: SpatialTheme;
11
- stage: SpatialStageConfig;
12
- catalog?: CatalogPage;
14
+ /** Localized interface copy. Missing groups/strings fall back to English; updates are reactive. */
15
+ messages?: SpatialMessagesInput;
16
+ /** Optional GPU resolution budget; defaults to DPR 1 and 2,073,600 pixels. */
17
+ renderSettings?: StageRenderSettings;
18
+ /** Draco decoder directory, including trailing slash. Default: /assets/draco/gltf/; the host must serve the files. */
19
+ dracoDecoderPath?: string;
20
+ /** Layout contents. ContentPage and SpatialElementPage register their own data. */
13
21
  children?: Snippet;
14
22
  }
15
23
 
16
- let { theme, stage, catalog, children }: Props = $props();
24
+ let { theme, messages, renderSettings, dracoDecoderPath, children }: Props = $props();
17
25
 
18
26
  provideSpatialTheme(() => theme);
27
+ provideSpatialMessages(() => messages);
19
28
 
20
29
  const brandStyle = $derived(
21
30
  [
@@ -77,14 +86,10 @@
77
86
 
78
87
  <div class="brand-stage-shell" style={brandStyle}>
79
88
  <Stage
80
- {catalog}
81
- background={stage.background}
89
+ brandId={theme.id}
90
+ {renderSettings}
91
+ {dracoDecoderPath}
82
92
  pageBackground={theme.background}
83
- hdr={stage.hdr}
84
- glb={stage.glb}
85
- lodPair={stage.lodPair}
86
- model={stage.model}
87
- camera={stage.camera}
88
93
  interactionTheme={theme.interactionTheme}
89
94
  ariaLabel={`${theme.name} spatialElement stage`}
90
95
  >
@@ -1,10 +1,17 @@
1
1
  import type { Snippet } from 'svelte';
2
- import type { CatalogPage } from '@spatial-elements/core/catalog/catalogPage';
3
- import type { SpatialTheme, SpatialStageConfig } from '@spatial-elements/core/spatial-element/types';
2
+ import type { StageRenderSettings } from '@spatial-elements/core';
3
+ import type { SpatialMessagesInput } from '@spatial-elements/core/spatial-element/messages';
4
+ import type { SpatialTheme } from '@spatial-elements/core/spatial-element/types';
4
5
  interface Props {
6
+ /** Shared appearance and namespace. Use createSpatialTheme for defaults. */
5
7
  theme: SpatialTheme;
6
- stage: SpatialStageConfig;
7
- catalog?: CatalogPage;
8
+ /** Localized interface copy. Missing groups/strings fall back to English; updates are reactive. */
9
+ messages?: SpatialMessagesInput;
10
+ /** Optional GPU resolution budget; defaults to DPR 1 and 2,073,600 pixels. */
11
+ renderSettings?: StageRenderSettings;
12
+ /** Draco decoder directory, including trailing slash. Default: /assets/draco/gltf/; the host must serve the files. */
13
+ dracoDecoderPath?: string;
14
+ /** Layout contents. ContentPage and SpatialElementPage register their own data. */
8
15
  children?: Snippet;
9
16
  }
10
17
  declare const BrandStageShell: import("svelte").Component<Props, {}, "">;
@@ -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,
@@ -19,10 +27,15 @@
19
27
  initialItemKey,
20
28
  onselectionchange
21
29
  }: {
30
+ /** Unique page-local anchor, heading and optional CSS appearance overrides. */
22
31
  section: SpatialElementSectionDefinition;
32
+ /** Project element documents with getSpatialListItems; assets register automatically. */
23
33
  list: SpatialListItem[];
34
+ /** Arc radius (default 0.48 of width) and depth (default 700 CSS-world pixels). */
24
35
  presentation?: CarouselPresentation;
36
+ /** Initially selected itemKey (or element ID); defaults to the first item. */
25
37
  initialItemKey?: string;
38
+ /** Reports selection changes; URL and application state remain host-owned. */
26
39
  onselectionchange?: (selection: { itemKey: string; spatialElementId: string }) => void;
27
40
  } = $props();
28
41
  const sections = getContext<CatalogSections | undefined>(CATALOG_SECTIONS);
@@ -36,6 +49,7 @@
36
49
  });
37
50
  let ring: HTMLDivElement;
38
51
  let frame = 0;
52
+ let scrollFrame = 0;
39
53
  let visible = true;
40
54
  let suppressClick = false;
41
55
  let clickTimer: ReturnType<typeof setTimeout>;
@@ -47,14 +61,53 @@
47
61
  selectionDirty = false;
48
62
  sections?.remember();
49
63
  }
50
- 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
+ }
51
98
  function invalidate() {
52
99
  window.dispatchEvent(new Event(CATALOG_POSE_CHANGED));
53
100
  }
54
101
  function releaseDrag() {
55
102
  const current = drag;
56
103
  drag = undefined;
57
- 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);
58
111
  }
59
112
  function settle() {
60
113
  cancelAnimationFrame(frame);
@@ -65,12 +118,13 @@
65
118
  void tick().then(invalidate);
66
119
  rememberSelection();
67
120
  }
68
- function animate(target: number) {
121
+ function animate(target: number, velocity?: number) {
69
122
  cancelAnimationFrame(frame);
123
+ frame = 0;
70
124
  const start = phase;
71
125
  const started = performance.now();
72
126
  if (
73
- Math.abs(target - start) > 1.5 ||
127
+ (velocity === undefined && Math.abs(target - start) > 1.5) ||
74
128
  !visible ||
75
129
  document.hidden ||
76
130
  matchMedia('(prefers-reduced-motion: reduce)').matches
@@ -86,10 +140,17 @@
86
140
  frame = 0;
87
141
  return;
88
142
  }
89
- const t = Math.min(1, (now - started) / 320);
90
- 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);
91
152
  void tick().then(invalidate);
92
- if (t < 1) frame = requestAnimationFrame(advance);
153
+ if (!finished) frame = requestAnimationFrame(advance);
93
154
  else {
94
155
  frame = 0;
95
156
  announced = selected;
@@ -100,44 +161,110 @@
100
161
  }
101
162
  function pointerdown(event: PointerEvent) {
102
163
  if (
164
+ event.pointerType === 'touch' ||
165
+ drag ||
103
166
  list.length < 2 ||
104
167
  event.button !== 0 ||
105
168
  !(event.target as Element).closest('.spatial-element-visual')
106
169
  )
107
170
  return;
108
- 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);
109
173
  }
110
174
  function pointermove(event: PointerEvent) {
111
- if (!drag || drag.id !== event.pointerId) return;
112
- const x = event.clientX - drag.x,
113
- y = event.clientY - drag.y;
114
- if (!drag.active) {
115
- if (Math.abs(y) > 10 && Math.abs(y) > Math.abs(x)) {
116
- drag = undefined;
117
- return;
118
- }
119
- if (Math.abs(x) < 10 || Math.abs(x) < Math.abs(y) * 1.2) return;
120
- drag.active = true;
121
- suppressClick = true;
122
- cancelAnimationFrame(frame);
123
- ring.setPointerCapture(event.pointerId);
124
- }
125
- phase = Math.max(0, Math.min(keys.length - 1, drag.phase - x / 220));
126
- 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);
127
178
  }
128
179
  function pointerup(event: PointerEvent) {
129
- if (!drag || drag.id !== event.pointerId) return;
130
- 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);
131
223
  releaseDrag();
132
- 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);
133
228
  clearTimeout(clickTimer);
134
- 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);
135
231
  }
136
- 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();
137
236
  releaseDrag();
138
- suppressClick = false;
237
+ clearTimeout(clickTimer);
238
+ clickTimer = setTimeout(() => (suppressClick = false), 400);
139
239
  animate(Math.max(0, keys.indexOf(selected ?? '')));
140
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
+ }
141
268
  const keys = $derived(list.map(carouselKey));
142
269
  const selected = $derived(resolveCarouselSelection(keys, requested ?? initialItemKey));
143
270
  $effect(() => {
@@ -150,13 +277,13 @@
150
277
  settle();
151
278
  });
152
279
  });
153
- function select(key: string | undefined) {
280
+ function select(key: string | undefined, velocity?: number) {
154
281
  selectionDirty = true;
155
282
  requested = key;
156
283
  // Persist in the current entry before a possible popstate changes the history index.
157
284
  rememberSelection();
158
285
  const target = Math.max(0, keys.indexOf(key ?? ''));
159
- animate(target);
286
+ animate(target, velocity);
160
287
  const spatialElement = list.find((item) => carouselKey(item) === selected);
161
288
  if (spatialElement && selected) onselectionchange?.({ itemKey: selected, spatialElementId: spatialElement.id });
162
289
  }
@@ -170,19 +297,25 @@
170
297
  }
171
298
  onMount(() => {
172
299
  interactive = true;
300
+ // The model owns both single-finger axes; passive events still allow native pinch zoom.
301
+ ring.addEventListener('touchstart', touchstart, { passive: true });
173
302
  const release = sections?.register(section.id, {
174
303
  read: () => selected,
175
304
  restore: (key) => {
305
+ stopScrollMomentum();
176
306
  selectionDirty = false;
177
307
  requested = resolveCarouselSelection(keys, key ?? initialItemKey);
178
308
  cancelAnimationFrame(frame);
309
+ frame = 0;
310
+ releaseDrag();
179
311
  phase = Math.max(0, keys.indexOf(requested ?? ''));
180
312
  announced = requested;
181
313
  }
182
314
  });
183
315
  const observer = new IntersectionObserver(([entry]) => {
184
316
  visible = entry.isIntersecting;
185
- if (!visible) {
317
+ // The same touch must keep scrolling after carrying the carousel out of view.
318
+ if (!visible && drag?.kind !== 'touch') {
186
319
  settle();
187
320
  }
188
321
  });
@@ -214,9 +347,19 @@
214
347
  sizing.observe(ring);
215
348
  for (const panel of ring.querySelectorAll('.summary')) sizing.observe(panel);
216
349
  const stop = () => pointercancel();
217
- window.addEventListener('resize', stop);
350
+ let viewportWidth = window.innerWidth;
351
+ const resize = () => {
352
+ // Mobile browser chrome resizes the height during scrolling; keep that gesture alive.
353
+ if (window.innerWidth !== viewportWidth) stop();
354
+ viewportWidth = window.innerWidth;
355
+ };
356
+ window.addEventListener('resize', resize);
357
+ window.addEventListener('blur', stop);
218
358
  const hidden = () => {
219
- if (document.hidden) settle();
359
+ if (document.hidden) {
360
+ stopScrollMomentum();
361
+ settle();
362
+ }
220
363
  };
221
364
  document.addEventListener('visibilitychange', hidden);
222
365
  const escape = (event: KeyboardEvent) => {
@@ -225,14 +368,17 @@
225
368
  window.addEventListener('keydown', escape);
226
369
  return () => {
227
370
  cancelAnimationFrame(frame);
371
+ stopScrollMomentum();
228
372
  clearTimeout(clickTimer);
229
373
  releaseDrag();
374
+ ring.removeEventListener('touchstart', touchstart);
230
375
  observer.disconnect();
231
376
  sizing.disconnect();
232
377
  contentChanges.disconnect();
233
378
  cancelAnimationFrame(sizingFrame);
234
379
  release?.();
235
- window.removeEventListener('resize', stop);
380
+ window.removeEventListener('resize', resize);
381
+ window.removeEventListener('blur', stop);
236
382
  window.removeEventListener('keydown', escape);
237
383
  document.removeEventListener('visibilitychange', hidden);
238
384
  };
@@ -254,7 +400,7 @@
254
400
  onpointerup={pointerup}
255
401
  onpointercancel={pointercancel}
256
402
  onlostpointercapture={() => {
257
- if (drag) pointercancel();
403
+ if (drag?.kind === 'pointer') pointercancel();
258
404
  }}
259
405
  role="group"
260
406
  aria-label={section.title}
@@ -302,7 +448,7 @@
302
448
  .ring {
303
449
  container-type: inline-size;
304
450
  position: relative;
305
- touch-action: pan-y;
451
+ touch-action: manipulation;
306
452
  }
307
453
  .interactive.populated .ring {
308
454
  min-height: var(--carousel-height, 560px);
@@ -1,10 +1,15 @@
1
1
  import type { CarouselPresentation } from '@spatial-elements/core/catalog/catalogPose';
2
2
  import type { SpatialListItem, SpatialElementSectionDefinition } from '@spatial-elements/core/spatial-element/types';
3
3
  type $$ComponentProps = {
4
+ /** Unique page-local anchor, heading and optional CSS appearance overrides. */
4
5
  section: SpatialElementSectionDefinition;
6
+ /** Project element documents with getSpatialListItems; assets register automatically. */
5
7
  list: SpatialListItem[];
8
+ /** Arc radius (default 0.48 of width) and depth (default 700 CSS-world pixels). */
6
9
  presentation?: CarouselPresentation;
10
+ /** Initially selected itemKey (or element ID); defaults to the first item. */
7
11
  initialItemKey?: string;
12
+ /** Reports selection changes; URL and application state remain host-owned. */
8
13
  onselectionchange?: (selection: {
9
14
  itemKey: string;
10
15
  spatialElementId: string;
@@ -127,9 +127,9 @@
127
127
  ? `left:${(pose.x - 0.19 * Math.cos(pose.yaw)) * 100}%;top:${pose.y * 100}%;width:${pose.size * 100}%;max-width:${pose.size * 480}px;z-index:${Math.round(1300 + pose.depth)}`
128
128
  : undefined}
129
129
  >
130
- {#if spatialElement.stage?.fallbackImage}<img
130
+ {#if spatialElement.fallbackImage}<img
131
131
  draggable="false"
132
- src={spatialElement.stage.fallbackImage}
132
+ src={spatialElement.fallbackImage}
133
133
  alt={`${brand.name} ${spatialElement.title}`}
134
134
  width="320"
135
135
  height="320"
@@ -239,12 +239,16 @@
239
239
  position: relative;
240
240
  display: grid;
241
241
  place-items: center;
242
- touch-action: pan-y;
242
+ touch-action: manipulation;
243
243
  }
244
244
  .interactive {
245
245
  display: block;
246
246
  margin: 0;
247
247
  }
248
+ .interactive .spatial-element-visual {
249
+ /* One owner for diagonal single-finger motion; two-finger page zoom stays native. */
250
+ touch-action: pinch-zoom;
251
+ }
248
252
  .interactive[hidden] {
249
253
  /* Keep known summary dimensions measurable without painting or registering GPU actors. */
250
254
  display: block;
@@ -4,13 +4,23 @@
4
4
  import type { ContentPageData } from '@spatial-elements/core/spatial-element/types';
5
5
  import { useSpatialTheme } from './brandContext.js';
6
6
  import SpatialElementBreadcrumbs from './SpatialElementBreadcrumbs.svelte';
7
+ import { registerSpatialPage } from './spatialPageContext.js';
7
8
  import {
8
9
  SPATIAL_ELEMENT_SECTION_REGISTRY_KEY,
9
10
  SpatialElementSectionRegistry,
10
11
  SECTION_PAGE_KIND
11
12
  } from '@spatial-elements/core/spatial-element/spatialElementSectionRegistry';
12
- let { page, children }: { page: ContentPageData; children?: Snippet } = $props();
13
+ interface Props {
14
+ /** Explicit HDR used to light this page's shared 3D scene; never inferred from an element. */
15
+ hdr: string;
16
+ /** Category metadata. Only title is required; pageTitle defaults to title. */
17
+ page: ContentPageData;
18
+ /** ListSection, CarouselSection and ordinary Section children. */
19
+ children?: Snippet;
20
+ }
21
+ let { page, hdr, children }: Props = $props();
13
22
  const brand = useSpatialTheme();
23
+ registerSpatialPage(() => ({ kind: 'content', hdr }));
14
24
  setContext(SPATIAL_ELEMENT_SECTION_REGISTRY_KEY, new SpatialElementSectionRegistry());
15
25
  setContext(SECTION_PAGE_KIND, 'content');
16
26
  </script>
@@ -1,9 +1,13 @@
1
1
  import type { Snippet } from 'svelte';
2
2
  import type { ContentPageData } from '@spatial-elements/core/spatial-element/types';
3
- type $$ComponentProps = {
3
+ interface Props {
4
+ /** Explicit HDR used to light this page's shared 3D scene; never inferred from an element. */
5
+ hdr: string;
6
+ /** Category metadata. Only title is required; pageTitle defaults to title. */
4
7
  page: ContentPageData;
8
+ /** ListSection, CarouselSection and ordinary Section children. */
5
9
  children?: Snippet;
6
- };
7
- declare const ContentPage: import("svelte").Component<$$ComponentProps, {}, "">;
10
+ }
11
+ declare const ContentPage: import("svelte").Component<Props, {}, "">;
8
12
  type ContentPage = ReturnType<typeof ContentPage>;
9
13
  export default ContentPage;
@@ -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,9 +1,17 @@
1
1
  <script lang="ts">
2
2
  import Section from './Section.svelte';
3
3
  import SpatialElementCard from './SpatialElementCard.svelte';
4
- import type { SpatialListItem, SpatialElementSectionDefinition } from '@spatial-elements/core/spatial-element/types';
5
- let { section, list }: { section: SpatialElementSectionDefinition; list: SpatialListItem[] } =
6
- $props();
4
+ import type {
5
+ SpatialListItem,
6
+ SpatialElementSectionDefinition
7
+ } from '@spatial-elements/core/spatial-element/types';
8
+ interface Props {
9
+ /** Unique page-local anchor, heading and optional CSS appearance overrides. */
10
+ section: SpatialElementSectionDefinition;
11
+ /** Project element documents with getSpatialListItems; assets register automatically. */
12
+ list: SpatialListItem[];
13
+ }
14
+ let { section, list }: Props = $props();
7
15
  </script>
8
16
 
9
17
  <Section {section} presentation="list">