@spatial-elements/sveltekit 0.1.0-beta.1
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.
- package/LICENSE +373 -0
- package/README.md +17 -0
- package/dist/catalog/ScrollNavigationBridge.svelte +394 -0
- package/dist/catalog/ScrollNavigationBridge.svelte.d.ts +13 -0
- package/dist/catalog/catalogEndpointAction.d.ts +6 -0
- package/dist/catalog/catalogEndpointAction.js +18 -0
- package/dist/catalog/catalogNavigation.d.ts +7 -0
- package/dist/catalog/catalogNavigation.js +19 -0
- package/dist/catalog/catalogTransition.css +59 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +6 -0
- package/dist/spatial-element/BrandStageShell.svelte +106 -0
- package/dist/spatial-element/BrandStageShell.svelte.d.ts +12 -0
- package/dist/spatial-element/CarouselSection.svelte +350 -0
- package/dist/spatial-element/CarouselSection.svelte.d.ts +15 -0
- package/dist/spatial-element/CarouselSpatialElement.svelte +388 -0
- package/dist/spatial-element/CarouselSpatialElement.svelte.d.ts +17 -0
- package/dist/spatial-element/ContentPage.svelte +68 -0
- package/dist/spatial-element/ContentPage.svelte.d.ts +9 -0
- package/dist/spatial-element/ListSection.svelte +30 -0
- package/dist/spatial-element/ListSection.svelte.d.ts +8 -0
- package/dist/spatial-element/Section.svelte +191 -0
- package/dist/spatial-element/Section.svelte.d.ts +14 -0
- package/dist/spatial-element/SpatialElementBreadcrumbs.svelte +69 -0
- package/dist/spatial-element/SpatialElementBreadcrumbs.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialElementCard.svelte +256 -0
- package/dist/spatial-element/SpatialElementCard.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementMediaRail.svelte +144 -0
- package/dist/spatial-element/SpatialElementMediaRail.svelte.d.ts +7 -0
- package/dist/spatial-element/SpatialElementPage.svelte +249 -0
- package/dist/spatial-element/SpatialElementPage.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementStickyHeader.svelte +351 -0
- package/dist/spatial-element/SpatialElementStickyHeader.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementSummaryPanel.svelte +423 -0
- package/dist/spatial-element/SpatialElementSummaryPanel.svelte.d.ts +7 -0
- package/dist/spatial-element/SpatialElementTabList.svelte +266 -0
- package/dist/spatial-element/SpatialElementTabList.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementTabs.svelte +123 -0
- package/dist/spatial-element/SpatialElementTabs.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialListPage.svelte +23 -0
- package/dist/spatial-element/SpatialListPage.svelte.d.ts +11 -0
- package/dist/spatial-element/brandContext.d.ts +5 -0
- package/dist/spatial-element/brandContext.js +14 -0
- package/dist/spatial-element/index.d.ts +11 -0
- package/dist/spatial-element/index.js +8 -0
- package/dist/stage/Panel.svelte +355 -0
- package/dist/stage/Panel.svelte.d.ts +24 -0
- package/dist/stage/Stage.svelte +747 -0
- package/dist/stage/Stage.svelte.d.ts +22 -0
- package/dist/stage/StageViewport.svelte +73 -0
- package/dist/stage/StageViewport.svelte.d.ts +13 -0
- package/package.json +55 -0
|
@@ -0,0 +1,394 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { readCatalogViewContext } from '@spatial-elements/core/catalog/catalogViewLink';
|
|
3
|
+
import {
|
|
4
|
+
afterNavigate,
|
|
5
|
+
beforeNavigate,
|
|
6
|
+
disableScrollHandling,
|
|
7
|
+
onNavigate,
|
|
8
|
+
pushState,
|
|
9
|
+
replaceState
|
|
10
|
+
} from '$app/navigation';
|
|
11
|
+
import { navigating, page } from '$app/state';
|
|
12
|
+
import type { OnNavigate } from '@sveltejs/kit';
|
|
13
|
+
import { getContext, onDestroy, tick } from 'svelte';
|
|
14
|
+
import { CATALOG_ENDPOINTS, type CatalogEndpointRegistry } from '@spatial-elements/core/catalog/CatalogEndpointRegistry';
|
|
15
|
+
import {
|
|
16
|
+
CATALOG_SECTIONS,
|
|
17
|
+
type CatalogSections,
|
|
18
|
+
type CatalogSectionSnapshot
|
|
19
|
+
} from '@spatial-elements/core/catalog/CatalogSections';
|
|
20
|
+
import type {
|
|
21
|
+
ScrollRestoreTarget,
|
|
22
|
+
VirtualScrollController
|
|
23
|
+
} from '@spatial-elements/core/stage/VirtualScrollController';
|
|
24
|
+
import { subscribeStageScrollFrame, syncStageScrollToNative } from '@spatial-elements/core/stage/scrollFrame';
|
|
25
|
+
import { resolveCatalogIntent } from '@spatial-elements/core/catalog/catalogRecipes';
|
|
26
|
+
|
|
27
|
+
interface EntryState {
|
|
28
|
+
id: string;
|
|
29
|
+
focus?: string;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
interface Props {
|
|
33
|
+
controller?: VirtualScrollController;
|
|
34
|
+
onCapture?: (navigation: OnNavigate) => void | Promise<void>;
|
|
35
|
+
onInterrupt?: () => void;
|
|
36
|
+
onSupersede?: (destination: URL) => void;
|
|
37
|
+
onRestored?: (navigation: OnNavigate) => void | Promise<void>;
|
|
38
|
+
handlesNavigation?: (navigation: OnNavigate) => boolean;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
let { controller, onCapture, onInterrupt, onSupersede, onRestored, handlesNavigation }: Props =
|
|
42
|
+
$props();
|
|
43
|
+
const endpoints = getContext<CatalogEndpointRegistry | undefined>(CATALOG_ENDPOINTS);
|
|
44
|
+
const sections = getContext<CatalogSections | undefined>(CATALOG_SECTIONS);
|
|
45
|
+
const disconnectSections = sections?.connect({
|
|
46
|
+
read: () => (page.state as { catalogSections?: CatalogSectionSnapshot }).catalogSections,
|
|
47
|
+
write: (snapshot: CatalogSectionSnapshot) => {
|
|
48
|
+
// Selection modifies only the current Kit entry; URL, scroll and unrelated state survive.
|
|
49
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
|
50
|
+
replaceState(window.location.href, { ...page.state, catalogSections: snapshot });
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
onDestroy(() => disconnectSections?.());
|
|
54
|
+
const PREPARATION_LIMIT_MS = 500;
|
|
55
|
+
let generation = 0;
|
|
56
|
+
let pendingNavigation = false;
|
|
57
|
+
let focusRevision = 0;
|
|
58
|
+
// This imperative history cache must not subscribe effects to per-frame position writes.
|
|
59
|
+
// eslint-disable-next-line svelte/prefer-svelte-reactivity
|
|
60
|
+
const entryPositions = new Map<string, { x: number; y: number }>();
|
|
61
|
+
let active:
|
|
62
|
+
| {
|
|
63
|
+
controller: VirtualScrollController;
|
|
64
|
+
token: object;
|
|
65
|
+
complete?: Promise<void>;
|
|
66
|
+
releasePreparation?: () => void;
|
|
67
|
+
}
|
|
68
|
+
| undefined;
|
|
69
|
+
let initial = $state<{ target: ScrollRestoreTarget; url: string }>();
|
|
70
|
+
|
|
71
|
+
function entryState(): EntryState | undefined {
|
|
72
|
+
return (page.state as { catalogScroll?: EntryState }).catalogScroll;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
function newEntry(): EntryState {
|
|
76
|
+
return { id: crypto.randomUUID() };
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
function ensureEntry() {
|
|
80
|
+
// An empty relative URL drops the current fragment when resolved by Kit.
|
|
81
|
+
// Preserve the browser's full URL while adding metadata to this history entry.
|
|
82
|
+
if (!entryState()) {
|
|
83
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
|
84
|
+
replaceState(window.location.href, { ...page.state, catalogScroll: newEntry() });
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
function rememberPosition() {
|
|
89
|
+
const id = entryState()?.id;
|
|
90
|
+
if (!id || !controller?.active) return;
|
|
91
|
+
entryPositions.set(id, controller.readPositions().native);
|
|
92
|
+
if (entryPositions.size > 100) entryPositions.delete(entryPositions.keys().next().value!);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
function stopActive(destination?: URL) {
|
|
96
|
+
generation += 1;
|
|
97
|
+
if (active) {
|
|
98
|
+
active.controller.endNavigation(active.token);
|
|
99
|
+
active.releasePreparation?.();
|
|
100
|
+
}
|
|
101
|
+
active = undefined;
|
|
102
|
+
pendingNavigation = false;
|
|
103
|
+
if (destination && onSupersede) {
|
|
104
|
+
try {
|
|
105
|
+
onSupersede(destination);
|
|
106
|
+
} catch {
|
|
107
|
+
interruptVisuals();
|
|
108
|
+
}
|
|
109
|
+
} else interruptVisuals();
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function interruptVisuals() {
|
|
113
|
+
try {
|
|
114
|
+
onInterrupt?.();
|
|
115
|
+
} catch {
|
|
116
|
+
// Visual cleanup must not prevent ordinary navigation.
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function focusDestination(navigation: OnNavigate) {
|
|
121
|
+
const visible = (element?: HTMLElement | null) => {
|
|
122
|
+
if (!element || element.closest('[inert], [aria-hidden="true"]')) return false;
|
|
123
|
+
const rect = element.getBoundingClientRect();
|
|
124
|
+
const style = getComputedStyle(element);
|
|
125
|
+
return (
|
|
126
|
+
rect.width > 0 &&
|
|
127
|
+
rect.height > 0 &&
|
|
128
|
+
rect.bottom > 0 &&
|
|
129
|
+
rect.top < innerHeight &&
|
|
130
|
+
style.visibility !== 'hidden'
|
|
131
|
+
);
|
|
132
|
+
};
|
|
133
|
+
const intent =
|
|
134
|
+
navigation.from && navigation.to
|
|
135
|
+
? resolveCatalogIntent(navigation.from.url, navigation.to.url, navigation.type)
|
|
136
|
+
: undefined;
|
|
137
|
+
const card =
|
|
138
|
+
intent?.direction === 'detail-to-list'
|
|
139
|
+
? endpoints?.resolve({
|
|
140
|
+
...intent.identity,
|
|
141
|
+
slot: endpoints.getContentSlot(intent.identity) ?? 'catalog.card',
|
|
142
|
+
role: 'container'
|
|
143
|
+
})
|
|
144
|
+
: undefined;
|
|
145
|
+
const key = navigation.type === 'popstate' ? entryState()?.focus : undefined;
|
|
146
|
+
const focused = key
|
|
147
|
+
? (document.querySelector<HTMLElement>(`[data-catalog-focus-key="${CSS.escape(key)}"]`) ??
|
|
148
|
+
document.getElementById(key))
|
|
149
|
+
: undefined;
|
|
150
|
+
const heading = Array.from(document.querySelectorAll<HTMLElement>('h1')).find(
|
|
151
|
+
(element) => !element.closest('[inert], [aria-hidden="true"]')
|
|
152
|
+
);
|
|
153
|
+
let section: HTMLElement | null = null;
|
|
154
|
+
if (navigation.type !== 'popstate' && navigation.to?.url.hash) {
|
|
155
|
+
try {
|
|
156
|
+
section = document.getElementById(decodeURIComponent(navigation.to.url.hash.slice(1)));
|
|
157
|
+
} catch {
|
|
158
|
+
/* Malformed fragments use the normal heading fallback. */
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
const target =
|
|
162
|
+
focused ??
|
|
163
|
+
(navigation.type !== 'popstate' && visible(card) ? card : undefined) ??
|
|
164
|
+
(visible(section)
|
|
165
|
+
? (section?.querySelector<HTMLElement>('h1, h2, h3') ?? section)
|
|
166
|
+
: undefined) ??
|
|
167
|
+
heading ??
|
|
168
|
+
document.querySelector<HTMLElement>('main');
|
|
169
|
+
if (!target) return;
|
|
170
|
+
const originalTabIndex = target.getAttribute('tabindex');
|
|
171
|
+
const restoreTabIndex = () => target.removeAttribute('tabindex');
|
|
172
|
+
if (originalTabIndex === null) {
|
|
173
|
+
target.setAttribute('tabindex', '-1');
|
|
174
|
+
// Removing tabindex while focused makes Chrome move focus back to body.
|
|
175
|
+
target.addEventListener('blur', restoreTabIndex, { once: true });
|
|
176
|
+
}
|
|
177
|
+
// Restoring focus is not a fresh request to speculate on the spatialElement just left.
|
|
178
|
+
target.setAttribute('data-catalog-restoring-focus', '');
|
|
179
|
+
try {
|
|
180
|
+
target.focus({ preventScroll: true });
|
|
181
|
+
} finally {
|
|
182
|
+
target.removeAttribute('data-catalog-restoring-focus');
|
|
183
|
+
}
|
|
184
|
+
if (originalTabIndex === null && document.activeElement !== target) {
|
|
185
|
+
target.removeEventListener('blur', restoreTabIndex);
|
|
186
|
+
restoreTabIndex();
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
beforeNavigate((navigation) => {
|
|
191
|
+
if (!pendingNavigation) rememberPosition();
|
|
192
|
+
stopActive(navigation.to?.url);
|
|
193
|
+
pendingNavigation = true;
|
|
194
|
+
const epoch = generation;
|
|
195
|
+
void navigation.complete
|
|
196
|
+
.catch(() => {})
|
|
197
|
+
.finally(() => {
|
|
198
|
+
if (epoch === generation && !active) {
|
|
199
|
+
pendingNavigation = false;
|
|
200
|
+
interruptVisuals();
|
|
201
|
+
}
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
onDestroy(() => stopActive());
|
|
205
|
+
|
|
206
|
+
$effect(() => {
|
|
207
|
+
const complete = navigating.complete;
|
|
208
|
+
// Kit skips beforeNavigate while another navigation is already in progress.
|
|
209
|
+
// The public completion identity still changes when that operation is superseded.
|
|
210
|
+
if (!complete || !active?.complete || complete === active.complete) return;
|
|
211
|
+
stopActive(navigating.to?.url);
|
|
212
|
+
pendingNavigation = true;
|
|
213
|
+
const epoch = generation;
|
|
214
|
+
void complete
|
|
215
|
+
.catch(() => {})
|
|
216
|
+
.finally(() => {
|
|
217
|
+
if (epoch === generation && !active) pendingNavigation = false;
|
|
218
|
+
});
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
onNavigate(async (navigation) => {
|
|
222
|
+
const destination = navigation.to;
|
|
223
|
+
if (!destination) return;
|
|
224
|
+
const owner = controller;
|
|
225
|
+
const handled = handlesNavigation
|
|
226
|
+
? handlesNavigation(navigation)
|
|
227
|
+
: navigation.from?.url.pathname.split('/')[1] === destination.url.pathname.split('/')[1];
|
|
228
|
+
if (!owner?.active || !handled) return;
|
|
229
|
+
const viewContext =
|
|
230
|
+
navigation.type === 'popstate' ? {} : readCatalogViewContext(destination.url);
|
|
231
|
+
const target: ScrollRestoreTarget =
|
|
232
|
+
navigation.type === 'popstate' && destination.scroll
|
|
233
|
+
? { ...destination.scroll }
|
|
234
|
+
: { hash: destination.url.hash };
|
|
235
|
+
const token = {};
|
|
236
|
+
const epoch = ++generation;
|
|
237
|
+
owner.beginNavigation(token);
|
|
238
|
+
let releasePreparation!: () => void;
|
|
239
|
+
const interrupted = new Promise<boolean>((resolve) => {
|
|
240
|
+
releasePreparation = () => resolve(false);
|
|
241
|
+
});
|
|
242
|
+
active = { controller: owner, token, complete: navigation.complete, releasePreparation };
|
|
243
|
+
let preparationTimer: ReturnType<typeof setTimeout> | undefined;
|
|
244
|
+
try {
|
|
245
|
+
const preparation = onCapture?.(navigation);
|
|
246
|
+
if (preparation) {
|
|
247
|
+
const prepared = await Promise.race([
|
|
248
|
+
Promise.resolve(preparation).then(() => true),
|
|
249
|
+
interrupted,
|
|
250
|
+
new Promise<boolean>((resolve) => {
|
|
251
|
+
preparationTimer = setTimeout(() => resolve(false), PREPARATION_LIMIT_MS);
|
|
252
|
+
})
|
|
253
|
+
]);
|
|
254
|
+
if (!prepared) {
|
|
255
|
+
if (epoch !== generation) return;
|
|
256
|
+
interruptVisuals();
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
} catch {
|
|
260
|
+
if (epoch !== generation) return;
|
|
261
|
+
interruptVisuals();
|
|
262
|
+
} finally {
|
|
263
|
+
if (preparationTimer !== undefined) clearTimeout(preparationTimer);
|
|
264
|
+
if (active?.token === token) active.releasePreparation = undefined;
|
|
265
|
+
}
|
|
266
|
+
if (epoch !== generation || !owner.active) return;
|
|
267
|
+
// The finite preparation above holds the outgoing DOM. A visual failure still
|
|
268
|
+
// restores the committed page; a superseded preparation never suppresses its successor.
|
|
269
|
+
disableScrollHandling();
|
|
270
|
+
|
|
271
|
+
// Do not return this promise: SvelteKit must commit before it can complete.
|
|
272
|
+
void navigation.complete
|
|
273
|
+
.then(async () => {
|
|
274
|
+
await tick();
|
|
275
|
+
// Kit queues fragment focus/history work after committing the page. Its
|
|
276
|
+
// scroll correction must finish before our sole destination restoration.
|
|
277
|
+
// A microtask/tick alone runs before that queued task (Kit 2.69.2).
|
|
278
|
+
if (destination.url.hash) await new Promise<void>((resolve) => setTimeout(resolve, 0));
|
|
279
|
+
if (epoch !== generation || !owner.active) return;
|
|
280
|
+
sections?.restore();
|
|
281
|
+
let requestedSection = viewContext.targetSection;
|
|
282
|
+
if (destination.url.hash) {
|
|
283
|
+
try {
|
|
284
|
+
requestedSection = decodeURIComponent(destination.url.hash.slice(1));
|
|
285
|
+
} catch {
|
|
286
|
+
requestedSection = undefined;
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
if (navigation.type !== 'popstate' && requestedSection && viewContext.spatialElementId)
|
|
290
|
+
sections?.selectForView(requestedSection, viewContext.spatialElementId);
|
|
291
|
+
await tick();
|
|
292
|
+
if (epoch !== generation || !owner.active) return;
|
|
293
|
+
owner.measureExtentNow();
|
|
294
|
+
// An interrupted popstate may corrupt Kit's intermediate scroll snapshot.
|
|
295
|
+
// Our bounded cache belongs to public page.state entry IDs, never URLs.
|
|
296
|
+
const saved =
|
|
297
|
+
navigation.type === 'popstate' ? entryPositions.get(entryState()?.id ?? '') : undefined;
|
|
298
|
+
const restored = owner.restoreTarget(saved ?? target, token);
|
|
299
|
+
if (!restored) syncStageScrollToNative();
|
|
300
|
+
ensureEntry();
|
|
301
|
+
const revision = focusRevision;
|
|
302
|
+
endpoints?.restoreFocus(entryState()?.focus);
|
|
303
|
+
const origin = sections?.getOrigin();
|
|
304
|
+
endpoints?.restoreOrigin(origin);
|
|
305
|
+
await onRestored?.(navigation);
|
|
306
|
+
if (restored && epoch === generation && owner.active && revision === focusRevision) {
|
|
307
|
+
focusDestination(navigation);
|
|
308
|
+
}
|
|
309
|
+
})
|
|
310
|
+
.catch(() => {
|
|
311
|
+
// Canceled navigations have no destination to restore.
|
|
312
|
+
})
|
|
313
|
+
.finally(() => {
|
|
314
|
+
owner.endNavigation(token);
|
|
315
|
+
if (active?.token === token) active = undefined;
|
|
316
|
+
if (epoch === generation) {
|
|
317
|
+
pendingNavigation = false;
|
|
318
|
+
rememberPosition();
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
});
|
|
322
|
+
|
|
323
|
+
afterNavigate((navigation) => {
|
|
324
|
+
if (navigation.type !== 'enter' || !navigation.to) return;
|
|
325
|
+
const entry = performance.getEntriesByType('navigation')[0] as
|
|
326
|
+
PerformanceNavigationTiming | undefined;
|
|
327
|
+
const restoreHistory = entry?.type === 'reload' || entry?.type === 'back_forward';
|
|
328
|
+
initial = {
|
|
329
|
+
target:
|
|
330
|
+
restoreHistory && navigation.to.scroll
|
|
331
|
+
? { ...navigation.to.scroll }
|
|
332
|
+
: { hash: navigation.to.url.hash },
|
|
333
|
+
url: navigation.to.url.href
|
|
334
|
+
};
|
|
335
|
+
});
|
|
336
|
+
|
|
337
|
+
$effect(() => {
|
|
338
|
+
const owner = controller;
|
|
339
|
+
if (!owner?.active) return;
|
|
340
|
+
const previousWriter = owner.writeHash;
|
|
341
|
+
owner.writeHash = (url, replace) => {
|
|
342
|
+
// The controller supplies the absolute current URL with only its fragment changed.
|
|
343
|
+
// It already includes the application base path; route resolution would apply it again.
|
|
344
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
|
345
|
+
if (replace) replaceState(url, { ...page.state, catalogScroll: entryState() ?? newEntry() });
|
|
346
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
|
347
|
+
else pushState(url, { ...page.state, catalogScroll: newEntry() });
|
|
348
|
+
};
|
|
349
|
+
const saveFocus = (event: FocusEvent) => {
|
|
350
|
+
focusRevision += 1;
|
|
351
|
+
if (active || pendingNavigation || !(event.target instanceof HTMLElement)) return;
|
|
352
|
+
const focus = event.target.dataset.catalogFocusKey || event.target.id;
|
|
353
|
+
if (!focus) return;
|
|
354
|
+
// Preserve the current fragment and already resolved application base path.
|
|
355
|
+
// eslint-disable-next-line svelte/no-navigation-without-resolve
|
|
356
|
+
replaceState(window.location.href, {
|
|
357
|
+
...page.state,
|
|
358
|
+
catalogScroll: { ...(entryState() ?? newEntry()), focus }
|
|
359
|
+
});
|
|
360
|
+
};
|
|
361
|
+
const stopFrames = subscribeStageScrollFrame(() => {
|
|
362
|
+
if (!active && !pendingNavigation) rememberPosition();
|
|
363
|
+
});
|
|
364
|
+
document.addEventListener('focusin', saveFocus);
|
|
365
|
+
return () => {
|
|
366
|
+
stopFrames();
|
|
367
|
+
owner.writeHash = previousWriter;
|
|
368
|
+
document.removeEventListener('focusin', saveFocus);
|
|
369
|
+
};
|
|
370
|
+
});
|
|
371
|
+
|
|
372
|
+
$effect(() => {
|
|
373
|
+
const owner = controller;
|
|
374
|
+
const start = initial;
|
|
375
|
+
if (!owner?.active || !start) return;
|
|
376
|
+
initial = undefined;
|
|
377
|
+
const token = {};
|
|
378
|
+
const epoch = generation;
|
|
379
|
+
owner.beginNavigation(token);
|
|
380
|
+
active = { controller: owner, token };
|
|
381
|
+
void tick()
|
|
382
|
+
.then(() => {
|
|
383
|
+
if (epoch !== generation || !owner.active || location.href !== start.url) return;
|
|
384
|
+
owner.measureExtentNow();
|
|
385
|
+
owner.restoreTarget(start.target, token);
|
|
386
|
+
ensureEntry();
|
|
387
|
+
})
|
|
388
|
+
.finally(() => {
|
|
389
|
+
owner.endNavigation(token);
|
|
390
|
+
if (active?.token === token) active = undefined;
|
|
391
|
+
if (epoch === generation) rememberPosition();
|
|
392
|
+
});
|
|
393
|
+
});
|
|
394
|
+
</script>
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { OnNavigate } from '@sveltejs/kit';
|
|
2
|
+
import type { VirtualScrollController } from '@spatial-elements/core/stage/VirtualScrollController';
|
|
3
|
+
interface Props {
|
|
4
|
+
controller?: VirtualScrollController;
|
|
5
|
+
onCapture?: (navigation: OnNavigate) => void | Promise<void>;
|
|
6
|
+
onInterrupt?: () => void;
|
|
7
|
+
onSupersede?: (destination: URL) => void;
|
|
8
|
+
onRestored?: (navigation: OnNavigate) => void | Promise<void>;
|
|
9
|
+
handlesNavigation?: (navigation: OnNavigate) => boolean;
|
|
10
|
+
}
|
|
11
|
+
declare const ScrollNavigationBridge: import("svelte").Component<Props, {}, "">;
|
|
12
|
+
type ScrollNavigationBridge = ReturnType<typeof ScrollNavigationBridge>;
|
|
13
|
+
export default ScrollNavigationBridge;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { type CatalogEndpointAddress } from '@spatial-elements/core/catalog/CatalogEndpointRegistry';
|
|
2
|
+
/** Create during component initialization; registration follows the actual element lifecycle. */
|
|
3
|
+
export declare function createCatalogEndpointAction(): (element: HTMLElement, address?: CatalogEndpointAddress) => {
|
|
4
|
+
update(next?: CatalogEndpointAddress): void;
|
|
5
|
+
destroy(): void;
|
|
6
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
import { CATALOG_ENDPOINTS } from '@spatial-elements/core/catalog/CatalogEndpointRegistry';
|
|
3
|
+
/** Create during component initialization; registration follows the actual element lifecycle. */
|
|
4
|
+
export function createCatalogEndpointAction() {
|
|
5
|
+
const registry = getContext(CATALOG_ENDPOINTS);
|
|
6
|
+
return (element, address) => {
|
|
7
|
+
let release = address && registry?.register(address, element);
|
|
8
|
+
return {
|
|
9
|
+
update(next) {
|
|
10
|
+
release?.();
|
|
11
|
+
release = next && registry?.register(next, element);
|
|
12
|
+
},
|
|
13
|
+
destroy() {
|
|
14
|
+
release?.();
|
|
15
|
+
}
|
|
16
|
+
};
|
|
17
|
+
};
|
|
18
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SpatialListItem } from '@spatial-elements/core/spatial-element/types';
|
|
2
|
+
/** Kit integration boundary: authoring components use ordinary hrefs and element metadata. */
|
|
3
|
+
export declare function useCatalogNavigation(): {
|
|
4
|
+
href: (value: string) => string;
|
|
5
|
+
pending: () => URL | undefined;
|
|
6
|
+
prepare(spatialElement: SpatialListItem): void;
|
|
7
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { getContext } from 'svelte';
|
|
2
|
+
import { resolve } from '$app/paths';
|
|
3
|
+
import { navigating } from '$app/state';
|
|
4
|
+
import { preloadData } from '$app/navigation';
|
|
5
|
+
import { STAGE_CONTEXT_KEY } from '@spatial-elements/core/stage/panelContext';
|
|
6
|
+
/** Kit integration boundary: authoring components use ordinary hrefs and element metadata. */
|
|
7
|
+
export function useCatalogNavigation() {
|
|
8
|
+
const stage = getContext(STAGE_CONTEXT_KEY);
|
|
9
|
+
const href = (value) => resolve(...[value]);
|
|
10
|
+
return {
|
|
11
|
+
href,
|
|
12
|
+
pending: () => navigating.to?.url,
|
|
13
|
+
prepare(spatialElement) {
|
|
14
|
+
void preloadData(href(spatialElement.href)).catch(() => { });
|
|
15
|
+
if (spatialElement.stage)
|
|
16
|
+
stage?.prefetchSpatialElement?.(spatialElement.stage);
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
/* Loaded by the persistent stage before any destination page can mount. */
|
|
2
|
+
.stage [data-catalog-transition-group='enter'] {
|
|
3
|
+
--stage-transition-opacity: var(--catalog-enter-opacity, 1);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
.stage [data-catalog-transition-group='shared'] {
|
|
7
|
+
--stage-transition-opacity: var(--catalog-shared-opacity, 1);
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
.stage [data-catalog-transition-dom='enter'] {
|
|
11
|
+
--catalog-content-opacity: var(--catalog-enter-opacity, 1);
|
|
12
|
+
opacity: var(--catalog-content-opacity);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
.stage [data-catalog-transition-dom='exit'] {
|
|
16
|
+
--catalog-content-opacity: var(--catalog-exit-opacity, 1);
|
|
17
|
+
opacity: var(--catalog-content-opacity);
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/* On return, list content is the destination. Source copies own their independent exit opacity. */
|
|
21
|
+
.stage[data-catalog-direction='return'] [data-catalog-list] [data-catalog-transition-dom='exit'] {
|
|
22
|
+
--catalog-content-opacity: var(--catalog-enter-opacity, 0);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
.stage[data-catalog-direction='return'][data-catalog-enter-hidden] [data-catalog-list] {
|
|
26
|
+
visibility: hidden;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
.stage:is([data-catalog-recipe='dock-to-list'], [data-catalog-recipe='dock-to-carousel'])
|
|
30
|
+
[data-catalog-shell] {
|
|
31
|
+
opacity: var(--catalog-enter-opacity, 0);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/* The moving shared-surface actor owns the incoming dock background until handoff. */
|
|
35
|
+
.stage:is(
|
|
36
|
+
[data-catalog-recipe='list-to-dock'],
|
|
37
|
+
[data-catalog-recipe='carousel-to-dock']
|
|
38
|
+
)[data-catalog-transition]
|
|
39
|
+
[data-spatial-element-sticky-header]::before {
|
|
40
|
+
opacity: 0 !important;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.stage[data-catalog-transition] [data-catalog-transition-dom][data-stage-dom-content] {
|
|
44
|
+
opacity: calc(var(--stage-dom-opacity, 1) * var(--catalog-content-opacity, 1));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/* Gate the initial paint before panel registration and renderer binding. */
|
|
48
|
+
.stage[data-catalog-enter-hidden] [data-catalog-transition-dom='enter'],
|
|
49
|
+
.stage[data-catalog-enter-hidden] [data-catalog-transition-group='enter'],
|
|
50
|
+
.stage[data-catalog-shared-hidden] [data-catalog-transition-group='shared'] {
|
|
51
|
+
visibility: hidden !important;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
.stage[data-catalog-transition] [data-catalog-transition-dom],
|
|
55
|
+
.stage[data-catalog-transition] [data-catalog-transition-dom] *,
|
|
56
|
+
.stage[data-catalog-transition] [data-catalog-transition-group],
|
|
57
|
+
.stage[data-catalog-transition] [data-catalog-transition-group] * {
|
|
58
|
+
pointer-events: none !important;
|
|
59
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './spatial-element/index.js';
|
|
2
|
+
export { default as Panel } from './stage/Panel.svelte';
|
|
3
|
+
export { default as Stage } from './stage/Stage.svelte';
|
|
4
|
+
export { default as StageViewport } from './stage/StageViewport.svelte';
|
|
5
|
+
export { catalogViewLink } from '@spatial-elements/core';
|
|
6
|
+
export { default as ScrollNavigationBridge } from './catalog/ScrollNavigationBridge.svelte';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
export * from './spatial-element/index.js';
|
|
2
|
+
export { default as Panel } from './stage/Panel.svelte';
|
|
3
|
+
export { default as Stage } from './stage/Stage.svelte';
|
|
4
|
+
export { default as StageViewport } from './stage/StageViewport.svelte';
|
|
5
|
+
export { catalogViewLink } from '@spatial-elements/core';
|
|
6
|
+
export { default as ScrollNavigationBridge } from './catalog/ScrollNavigationBridge.svelte';
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import type { Snippet } from 'svelte';
|
|
3
|
+
import Stage from '../stage/Stage.svelte';
|
|
4
|
+
import type { CatalogPage } from '@spatial-elements/core/catalog/catalogPage';
|
|
5
|
+
import { getCssPanelBoxShadow, resolvePanelShadowStrength } from '@spatial-elements/core/stage/panelShadow';
|
|
6
|
+
import { provideSpatialTheme } from './brandContext.js';
|
|
7
|
+
import type { SpatialTheme, SpatialStageConfig } from '@spatial-elements/core/spatial-element/types';
|
|
8
|
+
|
|
9
|
+
interface Props {
|
|
10
|
+
theme: SpatialTheme;
|
|
11
|
+
stage: SpatialStageConfig;
|
|
12
|
+
catalog?: CatalogPage;
|
|
13
|
+
children?: Snippet;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
let { theme, stage, catalog, children }: Props = $props();
|
|
17
|
+
|
|
18
|
+
provideSpatialTheme(() => theme);
|
|
19
|
+
|
|
20
|
+
const brandStyle = $derived(
|
|
21
|
+
[
|
|
22
|
+
`--spatial-element-background: ${theme.background}`,
|
|
23
|
+
`--spatial-element-ink: ${theme.colors.ink}`,
|
|
24
|
+
`--spatial-element-body: ${theme.colors.body}`,
|
|
25
|
+
`--spatial-element-accent: ${theme.colors.accent}`,
|
|
26
|
+
`--spatial-element-on-accent: ${theme.colors.onAccent}`,
|
|
27
|
+
`--spatial-element-section-tint: ${theme.sectionTheme.tint}`,
|
|
28
|
+
`--spatial-element-section-tint-opacity: ${toPercentage(theme.sectionTheme.tintOpacity)}`,
|
|
29
|
+
`--spatial-element-section-backdrop-blur: ${Math.max(theme.sectionTheme.backdropBlur, 0)}px`,
|
|
30
|
+
`--spatial-element-tab-background: ${theme.colors.tabBackground}`,
|
|
31
|
+
`--spatial-element-panel-radius: ${theme.panelShape.radius}px`,
|
|
32
|
+
`--spatial-element-docked-panel-tint-rgb: ${getDockedPanelTintRgb(theme.dockedPanelTheme.tint)}`,
|
|
33
|
+
`--spatial-element-docked-panel-tint-opacity: ${clamp(theme.dockedPanelTheme.tintOpacity, 0, 1)}`,
|
|
34
|
+
`--spatial-element-docked-panel-shadow-intensity: ${clamp(theme.dockedPanelTheme.shadowIntensity, 0, 1)}`,
|
|
35
|
+
`--spatial-element-docked-panel-shadow-strength: ${resolvePanelShadowStrength(theme.dockedPanelTheme.shadowIntensity)}`,
|
|
36
|
+
`--spatial-element-docked-panel-box-shadow: ${getCssPanelBoxShadow(theme.dockedPanelTheme.shadowIntensity)}`,
|
|
37
|
+
`--spatial-element-docked-panel-backdrop-blur: ${Math.min(
|
|
38
|
+
Math.max(theme.dockedPanelTheme.backdropBlur, 0),
|
|
39
|
+
100
|
|
40
|
+
)}px`
|
|
41
|
+
].join('; ')
|
|
42
|
+
);
|
|
43
|
+
|
|
44
|
+
function toPercentage(value: number) {
|
|
45
|
+
return `${clamp(value, 0, 1) * 100}%`;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
function getDockedPanelTintRgb(tint: SpatialTheme['dockedPanelTheme']['tint']) {
|
|
49
|
+
const value = tint;
|
|
50
|
+
|
|
51
|
+
if (typeof value === 'number') {
|
|
52
|
+
return hexToRgb(value.toString(16).padStart(6, '0'));
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (typeof value === 'string') {
|
|
56
|
+
const hex = value.trim().replace(/^#/, '');
|
|
57
|
+
if (/^[0-9a-f]{3}$/i.test(hex)) {
|
|
58
|
+
return hexToRgb(hex.replace(/(.)/g, '$1$1'));
|
|
59
|
+
}
|
|
60
|
+
if (/^[0-9a-f]{6}$/i.test(hex)) {
|
|
61
|
+
return hexToRgb(hex);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return '255 255 255';
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function hexToRgb(hex: string) {
|
|
69
|
+
const value = Number.parseInt(hex, 16);
|
|
70
|
+
return `${(value >> 16) & 255} ${(value >> 8) & 255} ${value & 255}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function clamp(value: number, min: number, max: number) {
|
|
74
|
+
return Math.min(Math.max(value, min), max);
|
|
75
|
+
}
|
|
76
|
+
</script>
|
|
77
|
+
|
|
78
|
+
<div class="brand-stage-shell" style={brandStyle}>
|
|
79
|
+
<Stage
|
|
80
|
+
{catalog}
|
|
81
|
+
background={stage.background}
|
|
82
|
+
pageBackground={theme.background}
|
|
83
|
+
hdr={stage.hdr}
|
|
84
|
+
glb={stage.glb}
|
|
85
|
+
lodPair={stage.lodPair}
|
|
86
|
+
model={stage.model}
|
|
87
|
+
camera={stage.camera}
|
|
88
|
+
interactionTheme={theme.interactionTheme}
|
|
89
|
+
ariaLabel={`${theme.name} spatialElement stage`}
|
|
90
|
+
>
|
|
91
|
+
{@render children?.()}
|
|
92
|
+
</Stage>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<style>
|
|
96
|
+
.brand-stage-shell {
|
|
97
|
+
background: var(--spatial-element-background);
|
|
98
|
+
--spatial-element-content-inline-inset: 192px;
|
|
99
|
+
--spatial-element-shell-inline-inset: 192px;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
:global(.stage) {
|
|
103
|
+
color: var(--spatial-element-ink);
|
|
104
|
+
font-family: Inter, ui-sans-serif, system-ui, sans-serif;
|
|
105
|
+
}
|
|
106
|
+
</style>
|
|
@@ -0,0 +1,12 @@
|
|
|
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';
|
|
4
|
+
interface Props {
|
|
5
|
+
theme: SpatialTheme;
|
|
6
|
+
stage: SpatialStageConfig;
|
|
7
|
+
catalog?: CatalogPage;
|
|
8
|
+
children?: Snippet;
|
|
9
|
+
}
|
|
10
|
+
declare const BrandStageShell: import("svelte").Component<Props, {}, "">;
|
|
11
|
+
type BrandStageShell = ReturnType<typeof BrandStageShell>;
|
|
12
|
+
export default BrandStageShell;
|