@spatial-elements/sveltekit 0.1.0-beta.1 → 1.0.0-beta.10
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/README.md +19 -9
- package/dist/catalog/ScrollNavigationBridge.svelte +172 -47
- package/dist/catalog/ScrollNavigationBridge.svelte.d.ts +9 -2
- package/dist/catalog/catalogNavigation.js +3 -2
- package/dist/catalog/catalogSummaryTransfer.d.ts +16 -0
- package/dist/catalog/catalogSummaryTransfer.js +79 -0
- package/dist/catalog/catalogTransition.css +58 -3
- package/dist/catalog/interruptedPresentation.d.ts +10 -0
- package/dist/catalog/interruptedPresentation.js +29 -0
- package/dist/catalog/presentationCleanup.d.ts +4 -0
- package/dist/catalog/presentationCleanup.js +20 -0
- package/dist/catalog/stagedCatalogNavigation.d.ts +44 -0
- package/dist/catalog/stagedCatalogNavigation.js +403 -0
- package/dist/catalog/stagedDomReveal.d.ts +8 -0
- package/dist/catalog/stagedDomReveal.js +76 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +3 -0
- package/dist/spatial-element/BrandStageShell.svelte +52 -71
- package/dist/spatial-element/BrandStageShell.svelte.d.ts +31 -4
- package/dist/spatial-element/CarouselSpatialElement.svelte +150 -197
- package/dist/spatial-element/CarouselSpatialElement.svelte.d.ts +5 -1
- package/dist/spatial-element/ContentBlock.svelte +7 -0
- package/dist/spatial-element/ContentBlock.svelte.d.ts +9 -0
- package/dist/spatial-element/ContentGrid.svelte +7 -0
- package/dist/spatial-element/ContentGrid.svelte.d.ts +8 -0
- package/dist/spatial-element/ContentPage.svelte +51 -55
- package/dist/spatial-element/ContentPage.svelte.d.ts +14 -3
- package/dist/spatial-element/InteractionGesture.svelte +39 -0
- package/dist/spatial-element/InteractionGesture.svelte.d.ts +7 -0
- package/dist/spatial-element/OverflowControls.svelte +125 -0
- package/dist/spatial-element/OverflowControls.svelte.d.ts +9 -0
- package/dist/spatial-element/PointerHint.svelte +80 -0
- package/dist/spatial-element/PointerHint.svelte.d.ts +3 -0
- package/dist/spatial-element/Section.svelte +25 -106
- package/dist/spatial-element/Section.svelte.d.ts +1 -0
- package/dist/spatial-element/SectionSurfaceGroup.svelte +8 -0
- package/dist/spatial-element/SectionSurfaceGroup.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialCardGridSection.svelte +79 -0
- package/dist/spatial-element/SpatialCardGridSection.svelte.d.ts +11 -0
- package/dist/spatial-element/SpatialCardPresentation.svelte +311 -0
- package/dist/spatial-element/SpatialCardPresentation.svelte.d.ts +19 -0
- package/dist/spatial-element/SpatialCardSlot.svelte +33 -0
- package/dist/spatial-element/SpatialCardSlot.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialCarouselSection.svelte +752 -0
- package/dist/spatial-element/{CarouselSection.svelte.d.ts → SpatialCarouselSection.svelte.d.ts} +5 -5
- package/dist/spatial-element/SpatialElementBreadcrumbs.svelte +12 -65
- package/dist/spatial-element/SpatialElementCard.svelte +54 -238
- package/dist/spatial-element/SpatialElementCard.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementHelp.svelte +292 -0
- package/dist/spatial-element/SpatialElementHelp.svelte.d.ts +6 -0
- package/dist/spatial-element/SpatialElementMediaRail.svelte +321 -52
- package/dist/spatial-element/SpatialElementMediaRail.svelte.d.ts +4 -1
- package/dist/spatial-element/SpatialElementNativeMedia.svelte +101 -0
- package/dist/spatial-element/SpatialElementNativeMedia.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialElementPage.svelte +150 -70
- package/dist/spatial-element/SpatialElementPage.svelte.d.ts +6 -3
- package/dist/spatial-element/SpatialElementStickyHeader.svelte +76 -104
- package/dist/spatial-element/SpatialElementStickyHeader.svelte.d.ts +3 -1
- package/dist/spatial-element/SpatialElementSummaryContent.svelte +185 -0
- package/dist/spatial-element/SpatialElementSummaryContent.svelte.d.ts +18 -0
- package/dist/spatial-element/SpatialElementSummaryPanel.svelte +48 -380
- package/dist/spatial-element/SpatialElementSummaryPanel.svelte.d.ts +2 -1
- package/dist/spatial-element/SpatialElementTabList.svelte +40 -17
- package/dist/spatial-element/SpatialElementTabList.svelte.d.ts +2 -1
- package/dist/spatial-element/SpatialElementTabs.svelte +61 -18
- package/dist/spatial-element/SpatialElementTabs.svelte.d.ts +3 -1
- package/dist/spatial-element/SpatialElementViewToggle.svelte +54 -0
- package/dist/spatial-element/SpatialElementViewToggle.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialIconButton.svelte +59 -0
- package/dist/spatial-element/SpatialIconButton.svelte.d.ts +14 -0
- package/dist/spatial-element/SpatialListPage.svelte +37 -8
- package/dist/spatial-element/SpatialListPage.svelte.d.ts +4 -1
- package/dist/spatial-element/SpatialMediaIndicator.svelte +16 -0
- package/dist/spatial-element/SpatialMediaIndicator.svelte.d.ts +26 -0
- package/dist/spatial-element/SpatialNavigationShell.svelte +136 -0
- package/dist/spatial-element/SpatialNavigationShell.svelte.d.ts +15 -0
- package/dist/spatial-element/SpatialSummaryHost.svelte +19 -0
- package/dist/spatial-element/SpatialSummaryHost.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialSummaryRoot.svelte +78 -0
- package/dist/spatial-element/SpatialSummaryRoot.svelte.d.ts +8 -0
- package/dist/spatial-element/SpatialSummarySlot.svelte +39 -0
- package/dist/spatial-element/SpatialSummarySlot.svelte.d.ts +9 -0
- package/dist/spatial-element/SpatialViewIcon.svelte +29 -0
- package/dist/spatial-element/SpatialViewIcon.svelte.d.ts +6 -0
- package/dist/spatial-element/brandContext.d.ts +1 -1
- package/dist/spatial-element/brandContext.js +1 -1
- package/dist/spatial-element/cardAppearanceFreeze.d.ts +5 -0
- package/dist/spatial-element/cardAppearanceFreeze.js +72 -0
- package/dist/spatial-element/carouselTextHit.d.ts +2 -0
- package/dist/spatial-element/carouselTextHit.js +17 -0
- package/dist/spatial-element/contentSidebars.d.ts +3 -0
- package/dist/spatial-element/contentSidebars.js +56 -0
- package/dist/spatial-element/index.d.ts +18 -3
- package/dist/spatial-element/index.js +11 -2
- package/dist/spatial-element/layout.generated.css +363 -0
- package/dist/spatial-element/messagesContext.d.ts +3 -0
- package/dist/spatial-element/messagesContext.js +10 -0
- package/dist/spatial-element/presentationBoxFreeze.d.ts +8 -0
- package/dist/spatial-element/presentationBoxFreeze.js +35 -0
- package/dist/spatial-element/spatialCardGrid.d.ts +12 -0
- package/dist/spatial-element/spatialCardGrid.js +1 -0
- package/dist/spatial-element/spatialPageContext.d.ts +4 -0
- package/dist/spatial-element/spatialPageContext.js +9 -0
- package/dist/spatial-element/spatialPresentationOwner.d.ts +6 -0
- package/dist/spatial-element/spatialPresentationOwner.js +2 -0
- package/dist/spatial-element/spatialSummary.d.ts +43 -0
- package/dist/spatial-element/spatialSummary.js +1 -0
- package/dist/spatial-element/spatialSummaryHost.svelte.d.ts +60 -0
- package/dist/spatial-element/spatialSummaryHost.svelte.js +233 -0
- package/dist/spatial-element/spatialThemeStyle.d.ts +3 -0
- package/dist/spatial-element/spatialThemeStyle.js +69 -0
- package/dist/spatial-element/truncatedTitle.d.ts +5 -0
- package/dist/spatial-element/truncatedTitle.js +28 -0
- package/dist/stage/ButtonGroup.svelte +151 -0
- package/dist/stage/ButtonGroup.svelte.d.ts +24 -0
- package/dist/stage/Panel.svelte +72 -14
- package/dist/stage/Panel.svelte.d.ts +14 -2
- package/dist/stage/Stage.svelte +405 -48
- package/dist/stage/Stage.svelte.d.ts +8 -1
- package/dist/stage/StageViewport.svelte +15 -2
- package/dist/stage/authoredStyle.d.ts +4 -0
- package/dist/stage/authoredStyle.js +17 -0
- package/dist/stage/buttonGroup.d.ts +9 -0
- package/dist/stage/buttonGroup.js +1 -0
- package/logo.svg +188 -0
- package/package.json +9 -6
- package/dist/spatial-element/CarouselSection.svelte +0 -350
- package/dist/spatial-element/ListSection.svelte +0 -30
- package/dist/spatial-element/ListSection.svelte.d.ts +0 -8
|
@@ -0,0 +1,233 @@
|
|
|
1
|
+
import { hydrate, mount, unmount, untrack } from 'svelte';
|
|
2
|
+
import { PresentationLease } from '@spatial-elements/core/catalog/PresentationLease';
|
|
3
|
+
import SpatialSummaryRoot from './SpatialSummaryRoot.svelte';
|
|
4
|
+
import { freezePresentationBox } from './presentationBoxFreeze.js';
|
|
5
|
+
import { releasePresentationResources } from '../catalog/presentationCleanup.js';
|
|
6
|
+
export const SPATIAL_SUMMARY_HOST = Symbol('spatial-summary-host');
|
|
7
|
+
/** Real Svelte instance ownership is independent of a route's placement node. */
|
|
8
|
+
export class SpatialSummaryHostController {
|
|
9
|
+
content;
|
|
10
|
+
contexts;
|
|
11
|
+
records = new Map();
|
|
12
|
+
roots = new Set();
|
|
13
|
+
placements = new WeakMap();
|
|
14
|
+
pendingModels = new Map();
|
|
15
|
+
disposed = false;
|
|
16
|
+
constructor(content, contexts) {
|
|
17
|
+
this.content = content;
|
|
18
|
+
this.contexts = contexts;
|
|
19
|
+
}
|
|
20
|
+
attach(slot, key, context) {
|
|
21
|
+
return this.attachModel(slot, key, { kind: 'summary', current: context, active: true });
|
|
22
|
+
}
|
|
23
|
+
attachCard(slot, key, context) {
|
|
24
|
+
return this.attachModel(slot, key, { kind: 'card', current: context, active: true });
|
|
25
|
+
}
|
|
26
|
+
attachModel(slot, key, initial) {
|
|
27
|
+
let active = true;
|
|
28
|
+
const placement = {};
|
|
29
|
+
// A slot's reactive context can change before its deferred Svelte root mounts
|
|
30
|
+
// (for example the carousel's SSR width is replaced by the mobile viewport).
|
|
31
|
+
// Keep those updates with the incoming placement, not an older held record.
|
|
32
|
+
const pending = { model: initial };
|
|
33
|
+
this.pendingModels.set(key, pending);
|
|
34
|
+
const forgetPending = () => { if (this.pendingModels.get(key) === pending)
|
|
35
|
+
this.pendingModels.delete(key); };
|
|
36
|
+
this.placements.set(slot, placement);
|
|
37
|
+
queueMicrotask(() => {
|
|
38
|
+
if (!active || this.disposed) {
|
|
39
|
+
forgetPending();
|
|
40
|
+
return;
|
|
41
|
+
}
|
|
42
|
+
try {
|
|
43
|
+
const previous = this.records.get(key);
|
|
44
|
+
if (previous && !previous.held)
|
|
45
|
+
throw new Error(`Duplicate presentation occurrence: ${key}`);
|
|
46
|
+
let root = slot.querySelector('[data-spatial-presentation-root]');
|
|
47
|
+
const serverRoot = Boolean(root);
|
|
48
|
+
if (!root) {
|
|
49
|
+
root = document.createElement('div');
|
|
50
|
+
root.dataset.spatialPresentationRoot = '';
|
|
51
|
+
root.className = initial.kind === 'card' ? 'spatial-card-root' : 'spatial-summary-island';
|
|
52
|
+
slot.append(root);
|
|
53
|
+
}
|
|
54
|
+
root.dataset.spatialPresentationKey = key;
|
|
55
|
+
const model = $state(pending.model);
|
|
56
|
+
pending.model = model;
|
|
57
|
+
if (model.kind === 'summary') {
|
|
58
|
+
root.style.setProperty('--spatial-summary-content-inset', `${model.current.contentInset}px`);
|
|
59
|
+
root.dataset.presentationMode = model.current.mode;
|
|
60
|
+
}
|
|
61
|
+
const options = { target: root, props: { content: this.content(), model }, context: this.contexts };
|
|
62
|
+
const component = serverRoot ? hydrate(SpatialSummaryRoot, { ...options, recover: false }) : mount(SpatialSummaryRoot, options);
|
|
63
|
+
const lease = new PresentationLease(root, () => {
|
|
64
|
+
releasePresentationResources('Unable to unmount spatial presentation', [
|
|
65
|
+
() => unmount(component),
|
|
66
|
+
() => root.remove(),
|
|
67
|
+
() => {
|
|
68
|
+
if (this.records.get(record.key) === record)
|
|
69
|
+
this.records.delete(record.key);
|
|
70
|
+
this.roots.delete(record);
|
|
71
|
+
}
|
|
72
|
+
]);
|
|
73
|
+
});
|
|
74
|
+
const owner = lease.claim();
|
|
75
|
+
const record = { key, kind: model.kind, root, slot, model, component, lease, owner, held: false };
|
|
76
|
+
placement.release = owner.release;
|
|
77
|
+
this.records.set(key, record);
|
|
78
|
+
this.roots.add(record);
|
|
79
|
+
}
|
|
80
|
+
finally {
|
|
81
|
+
forgetPending();
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
return () => { active = false; forgetPending(); placement.release?.(); this.placements.delete(slot); };
|
|
85
|
+
}
|
|
86
|
+
update(key, context) { untrack(() => this.updateModel(key, 'summary', context)); }
|
|
87
|
+
updateCard(key, context) { untrack(() => this.updateModel(key, 'card', context)); }
|
|
88
|
+
updateModel(key, kind, context) {
|
|
89
|
+
const pending = this.pendingModels.get(key);
|
|
90
|
+
if (pending?.model.kind === kind) {
|
|
91
|
+
if (pending.model.kind === 'summary')
|
|
92
|
+
pending.model.current = context;
|
|
93
|
+
else
|
|
94
|
+
pending.model.current = context;
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
97
|
+
const record = this.records.get(key);
|
|
98
|
+
if (!record || record.kind !== kind)
|
|
99
|
+
return;
|
|
100
|
+
if (record.frozen) {
|
|
101
|
+
record.frozen.pending = context;
|
|
102
|
+
return;
|
|
103
|
+
}
|
|
104
|
+
this.applyContext(record, context);
|
|
105
|
+
}
|
|
106
|
+
applyContext(record, context) {
|
|
107
|
+
if (record.model.kind === 'summary') {
|
|
108
|
+
record.model.current = context;
|
|
109
|
+
record.root.dataset.presentationMode = context.mode;
|
|
110
|
+
record.root.style.setProperty('--spatial-summary-content-inset', `${context.contentInset}px`);
|
|
111
|
+
}
|
|
112
|
+
else
|
|
113
|
+
record.model.current = context;
|
|
114
|
+
}
|
|
115
|
+
retainByElement(element) {
|
|
116
|
+
const matches = [...this.roots].filter(entry => entry.root === element || entry.root.contains(element) || element.contains(entry.root));
|
|
117
|
+
const record = matches.length === 1 ? matches[0] : undefined;
|
|
118
|
+
return record && this.retainRecord(record);
|
|
119
|
+
}
|
|
120
|
+
retain(key) {
|
|
121
|
+
const record = this.records.get(key);
|
|
122
|
+
return record && this.retainRecord(record);
|
|
123
|
+
}
|
|
124
|
+
retainRecord(record) {
|
|
125
|
+
if (this.disposed)
|
|
126
|
+
return;
|
|
127
|
+
const owner = record.owner = record.lease.claim();
|
|
128
|
+
const originalSlot = record.slot, originalKey = record.key;
|
|
129
|
+
const unfreeze = () => {
|
|
130
|
+
const frozen = record.frozen;
|
|
131
|
+
if (!frozen)
|
|
132
|
+
return;
|
|
133
|
+
record.root.style.cssText = frozen.css;
|
|
134
|
+
record.root.inert = frozen.inert;
|
|
135
|
+
delete record.root.dataset.spatialPresentationFrozen;
|
|
136
|
+
delete record.root.dataset.spatialPresentationGlass;
|
|
137
|
+
delete record.root.dataset.spatialPresentationModelReady;
|
|
138
|
+
record.frozen = undefined;
|
|
139
|
+
if (frozen.pending)
|
|
140
|
+
this.applyContext(record, frozen.pending);
|
|
141
|
+
if (!record.held)
|
|
142
|
+
record.model.active = true;
|
|
143
|
+
};
|
|
144
|
+
const freeze = () => {
|
|
145
|
+
if (record.frozen)
|
|
146
|
+
return record.frozen.box;
|
|
147
|
+
const root = record.root;
|
|
148
|
+
record.frozen = freezePresentationBox(root);
|
|
149
|
+
root.dataset.spatialPresentationFrozen = '';
|
|
150
|
+
if (root.closest('[data-carousel-glass-ready]'))
|
|
151
|
+
root.dataset.spatialPresentationGlass = '';
|
|
152
|
+
// Catalog disposal clears the original card's ready marker. Its captured GPU
|
|
153
|
+
// geometry still owns the image while this complete source island is held.
|
|
154
|
+
if (root.querySelector('[data-catalog-card][data-catalog-model-ready]'))
|
|
155
|
+
root.dataset.spatialPresentationModelReady = '';
|
|
156
|
+
return record.frozen.box;
|
|
157
|
+
};
|
|
158
|
+
return {
|
|
159
|
+
record, freeze,
|
|
160
|
+
hold: targetHost => {
|
|
161
|
+
const box = freeze();
|
|
162
|
+
record.held = true;
|
|
163
|
+
record.model.active = false;
|
|
164
|
+
record.root.inert = true;
|
|
165
|
+
Object.assign(record.root.style, { position: 'absolute', left: '0px', top: '0px', margin: '0px', pointerEvents: 'none' });
|
|
166
|
+
targetHost.append(record.root);
|
|
167
|
+
return box;
|
|
168
|
+
},
|
|
169
|
+
adopt: (slot, key, context) => {
|
|
170
|
+
if (this.disposed || !owner.isCurrent() || record.kind !== 'summary')
|
|
171
|
+
return false;
|
|
172
|
+
const destination = [...this.roots].find(entry => entry.slot === slot && entry !== record);
|
|
173
|
+
const placement = this.placements.get(slot);
|
|
174
|
+
if (!destination || destination.kind !== 'summary' || !placement)
|
|
175
|
+
return false;
|
|
176
|
+
const nextContext = context ?? destination.model.current;
|
|
177
|
+
const nextKey = key ?? destination.key;
|
|
178
|
+
destination.owner.release();
|
|
179
|
+
if (this.records.get(record.key) === record)
|
|
180
|
+
this.records.delete(record.key);
|
|
181
|
+
record.key = nextKey;
|
|
182
|
+
record.slot = slot;
|
|
183
|
+
record.root.dataset.spatialPresentationKey = nextKey;
|
|
184
|
+
record.owner = record.lease.claim();
|
|
185
|
+
placement.release = record.owner.release;
|
|
186
|
+
this.records.set(nextKey, record);
|
|
187
|
+
slot.append(record.root);
|
|
188
|
+
record.held = false;
|
|
189
|
+
// Do not register the outgoing address again between adoption and destination-model commit.
|
|
190
|
+
record.model.active = false;
|
|
191
|
+
if (record.frozen)
|
|
192
|
+
record.frozen.pending = nextContext;
|
|
193
|
+
else {
|
|
194
|
+
this.applyContext(record, nextContext);
|
|
195
|
+
record.model.active = true;
|
|
196
|
+
}
|
|
197
|
+
return true;
|
|
198
|
+
},
|
|
199
|
+
restore: () => {
|
|
200
|
+
const placement = this.placements.get(originalSlot);
|
|
201
|
+
const current = this.records.get(originalKey);
|
|
202
|
+
if (this.disposed || !owner.isCurrent() || !originalSlot.isConnected || !placement || current && current !== record)
|
|
203
|
+
return false;
|
|
204
|
+
if (record.root.parentElement !== originalSlot)
|
|
205
|
+
originalSlot.append(record.root);
|
|
206
|
+
if (this.records.get(record.key) === record)
|
|
207
|
+
this.records.delete(record.key);
|
|
208
|
+
record.key = originalKey;
|
|
209
|
+
record.slot = originalSlot;
|
|
210
|
+
record.root.dataset.spatialPresentationKey = originalKey;
|
|
211
|
+
record.owner = record.lease.claim();
|
|
212
|
+
placement.release = record.owner.release;
|
|
213
|
+
this.records.set(originalKey, record);
|
|
214
|
+
record.held = false;
|
|
215
|
+
unfreeze();
|
|
216
|
+
record.model.active = true;
|
|
217
|
+
return true;
|
|
218
|
+
},
|
|
219
|
+
unfreeze,
|
|
220
|
+
release: owner.release
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
destroy() {
|
|
224
|
+
if (this.disposed)
|
|
225
|
+
return;
|
|
226
|
+
this.disposed = true;
|
|
227
|
+
for (const record of this.roots)
|
|
228
|
+
record.owner.release();
|
|
229
|
+
this.records.clear();
|
|
230
|
+
this.pendingModels.clear();
|
|
231
|
+
this.roots.clear();
|
|
232
|
+
}
|
|
233
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { resolveSpatialSectionBackgrounds, resolveSpatialThemeRadii } from '@spatial-elements/core/spatial-element/spatialTheme';
|
|
2
|
+
import { getCssPanelBoxShadow, resolvePanelShadowStrength } from '@spatial-elements/core/stage/panelShadow';
|
|
3
|
+
/** CSS declarations shared by the shell and optional server-rendered theme previews. */
|
|
4
|
+
export function getSpatialThemeStyle(theme) {
|
|
5
|
+
const radii = resolveSpatialThemeRadii(theme);
|
|
6
|
+
const sectionBackgrounds = resolveSpatialSectionBackgrounds(theme);
|
|
7
|
+
return [
|
|
8
|
+
`--ps-background: transparent`,
|
|
9
|
+
`--ps-ink: ${theme.colors.ink}`,
|
|
10
|
+
`--ps-body: ${theme.colors.body}`,
|
|
11
|
+
`--ps-accent: ${theme.colors.accent}`,
|
|
12
|
+
`--ps-on-accent: ${theme.colors.onAccent}`,
|
|
13
|
+
`--ps-section-standard: ${sectionBackgrounds.standard}`,
|
|
14
|
+
`--ps-section-muted: ${sectionBackgrounds.muted}`,
|
|
15
|
+
`--ps-radius: ${radii.panel}px`,
|
|
16
|
+
`--ps-font-family: Inter, ui-sans-serif, system-ui, sans-serif`,
|
|
17
|
+
`--ps-border: color-mix(in srgb, ${theme.colors.ink} 18%, transparent)`,
|
|
18
|
+
`--ps-scroll-offset: var(--spatial-element-section-scroll-offset, 150px)`,
|
|
19
|
+
`--spatial-element-background: ${theme.background}`,
|
|
20
|
+
`--spatial-element-ink: ${theme.colors.ink}`,
|
|
21
|
+
`--spatial-element-body: ${theme.colors.body}`,
|
|
22
|
+
`--spatial-element-accent: ${theme.colors.accent}`,
|
|
23
|
+
`--spatial-element-on-accent: ${theme.colors.onAccent}`,
|
|
24
|
+
`--spatial-element-section-tint: ${theme.sectionTheme.tint}`,
|
|
25
|
+
`--spatial-element-section-standard: ${sectionBackgrounds.standard}`,
|
|
26
|
+
`--spatial-element-section-muted: ${sectionBackgrounds.muted}`,
|
|
27
|
+
`--spatial-element-section-tint-opacity: ${toPercentage(theme.sectionTheme.tintOpacity)}`,
|
|
28
|
+
`--spatial-element-section-backdrop-blur: ${clamp(theme.sectionTheme.backdropBlur, 0, 100)}px`,
|
|
29
|
+
`--spatial-element-tab-background: ${theme.colors.tabBackground}`,
|
|
30
|
+
`--spatial-element-control-radius: ${radii.control}px`,
|
|
31
|
+
`--spatial-element-panel-radius: ${radii.panel}px`,
|
|
32
|
+
`--spatial-element-panel-tint-rgb: ${getDockedPanelTintRgb(theme.panelTheme.tint ?? '#ffffff')}`,
|
|
33
|
+
`--spatial-element-panel-tint-opacity: ${clamp(theme.panelTheme.tintOpacity ?? 0.65, 0, 1)}`,
|
|
34
|
+
`--spatial-element-panel-backdrop-blur: ${clamp(theme.panelTheme.backdropBlur ?? 8, 0, 100)}px`,
|
|
35
|
+
`--spatial-element-panel-box-shadow: ${getCssPanelBoxShadow(theme.panelTheme.shadowIntensity ?? 0.2)}`,
|
|
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: ${clamp(theme.dockedPanelTheme.backdropBlur, 0, 100)}px`
|
|
42
|
+
].join('; ');
|
|
43
|
+
}
|
|
44
|
+
function toPercentage(value) {
|
|
45
|
+
return `${clamp(value, 0, 1) * 100}%`;
|
|
46
|
+
}
|
|
47
|
+
function getDockedPanelTintRgb(tint) {
|
|
48
|
+
const value = tint;
|
|
49
|
+
if (typeof value === 'number') {
|
|
50
|
+
return hexToRgb(value.toString(16).padStart(6, '0'));
|
|
51
|
+
}
|
|
52
|
+
if (typeof value === 'string') {
|
|
53
|
+
const hex = value.trim().replace(/^#/, '');
|
|
54
|
+
if (/^[0-9a-f]{3}$/i.test(hex)) {
|
|
55
|
+
return hexToRgb(hex.replace(/(.)/g, '$1$1'));
|
|
56
|
+
}
|
|
57
|
+
if (/^[0-9a-f]{6}$/i.test(hex)) {
|
|
58
|
+
return hexToRgb(hex);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return '255 255 255';
|
|
62
|
+
}
|
|
63
|
+
function hexToRgb(hex) {
|
|
64
|
+
const value = Number.parseInt(hex, 16);
|
|
65
|
+
return `${(value >> 16) & 255} ${(value >> 8) & 255} ${value & 255}`;
|
|
66
|
+
}
|
|
67
|
+
function clamp(value, min, max) {
|
|
68
|
+
return Number.isFinite(value) ? Math.min(Math.max(value, min), max) : min;
|
|
69
|
+
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
/** Native tooltips only for clipped text; measurements never run on pointer movement. */
|
|
2
|
+
export function truncatedTitle(node, text) {
|
|
3
|
+
const target = node.closest('[data-catalog-card]') ?? node;
|
|
4
|
+
let frame = 0;
|
|
5
|
+
const measure = () => {
|
|
6
|
+
frame = 0;
|
|
7
|
+
if (node.scrollHeight > node.clientHeight + 1 || node.scrollWidth > node.clientWidth + 1)
|
|
8
|
+
target.title = node.textContent?.trim() || text;
|
|
9
|
+
else
|
|
10
|
+
target.removeAttribute('title');
|
|
11
|
+
};
|
|
12
|
+
const schedule = () => {
|
|
13
|
+
if (!frame)
|
|
14
|
+
frame = requestAnimationFrame(measure);
|
|
15
|
+
};
|
|
16
|
+
const observer = new ResizeObserver(schedule);
|
|
17
|
+
observer.observe(node);
|
|
18
|
+
document.fonts?.addEventListener('loadingdone', schedule);
|
|
19
|
+
schedule();
|
|
20
|
+
return {
|
|
21
|
+
update(value) { text = value; schedule(); },
|
|
22
|
+
destroy() {
|
|
23
|
+
cancelAnimationFrame(frame);
|
|
24
|
+
observer.disconnect();
|
|
25
|
+
document.fonts?.removeEventListener('loadingdone', schedule);
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
<script lang="ts">
|
|
2
|
+
import { onMount, type Snippet } from 'svelte';
|
|
3
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
4
|
+
import type { StagePanelShape, StagePanelTheme } from '@spatial-elements/core/stage/panelContext';
|
|
5
|
+
import type { CatalogTransitionGroup } from '@spatial-elements/core/catalog/catalogPresentation';
|
|
6
|
+
import { mouseHover } from '@spatial-elements/core/stage/mouseHover';
|
|
7
|
+
import Panel from './Panel.svelte';
|
|
8
|
+
import type { ButtonGroupItem } from './buttonGroup.js';
|
|
9
|
+
type Props = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> & {
|
|
10
|
+
items: readonly ButtonGroupItem[];
|
|
11
|
+
/** Controlled selection. Omit when no button is selected. */
|
|
12
|
+
value?: string;
|
|
13
|
+
onchange?: (value: string) => void;
|
|
14
|
+
label: string;
|
|
15
|
+
content?: Snippet<[ButtonGroupItem]>;
|
|
16
|
+
iconOnly?: boolean;
|
|
17
|
+
disabled?: boolean;
|
|
18
|
+
visible?: boolean;
|
|
19
|
+
shape: StagePanelShape;
|
|
20
|
+
theme?: StagePanelTheme;
|
|
21
|
+
focusReactive?: boolean | 'top-right';
|
|
22
|
+
focusAnchor?: HTMLElement;
|
|
23
|
+
transitionGroup?: CatalogTransitionGroup;
|
|
24
|
+
};
|
|
25
|
+
let {
|
|
26
|
+
items,
|
|
27
|
+
value,
|
|
28
|
+
onchange,
|
|
29
|
+
label,
|
|
30
|
+
content,
|
|
31
|
+
iconOnly = false,
|
|
32
|
+
disabled = false,
|
|
33
|
+
visible = true,
|
|
34
|
+
shape,
|
|
35
|
+
theme,
|
|
36
|
+
focusReactive = false,
|
|
37
|
+
focusAnchor,
|
|
38
|
+
transitionGroup,
|
|
39
|
+
class: className = '',
|
|
40
|
+
...rest
|
|
41
|
+
}: Props = $props();
|
|
42
|
+
let group: HTMLDivElement;
|
|
43
|
+
let measuredWidth = $state<number>();
|
|
44
|
+
const radius = $derived(Number.isFinite(shape.radius) ? Math.max(0, shape.radius) : 12);
|
|
45
|
+
const width = $derived(
|
|
46
|
+
iconOnly ? `${items.length * 40}px` : measuredWidth ? `${measuredWidth}px` : 'max-content'
|
|
47
|
+
);
|
|
48
|
+
onMount(() => {
|
|
49
|
+
const observer = new ResizeObserver(() => {
|
|
50
|
+
measuredWidth = group.offsetWidth;
|
|
51
|
+
});
|
|
52
|
+
observer.observe(group);
|
|
53
|
+
return () => observer.disconnect();
|
|
54
|
+
});
|
|
55
|
+
</script>
|
|
56
|
+
|
|
57
|
+
<div class="button-group-frame" style:width>
|
|
58
|
+
<Panel
|
|
59
|
+
class="button-group-panel"
|
|
60
|
+
shape={{ ...shape, radius, contentInset: 0 }}
|
|
61
|
+
{theme}
|
|
62
|
+
pointerReactive={false}
|
|
63
|
+
{focusReactive}
|
|
64
|
+
{focusAnchor}
|
|
65
|
+
{transitionGroup}
|
|
66
|
+
>
|
|
67
|
+
<div
|
|
68
|
+
{...rest}
|
|
69
|
+
bind:this={group}
|
|
70
|
+
role="group"
|
|
71
|
+
aria-label={label}
|
|
72
|
+
class={['button-group', className]}
|
|
73
|
+
use:mouseHover
|
|
74
|
+
style:--control-radius={`${radius}px`}
|
|
75
|
+
style:visibility={visible ? 'visible' : 'hidden'}
|
|
76
|
+
>
|
|
77
|
+
{#each items as item (item.value)}
|
|
78
|
+
<button
|
|
79
|
+
type="button"
|
|
80
|
+
class:icon-only={iconOnly}
|
|
81
|
+
disabled={disabled || item.disabled}
|
|
82
|
+
aria-label={item.label}
|
|
83
|
+
title={item.tooltip ?? item.label}
|
|
84
|
+
aria-pressed={item.value === value}
|
|
85
|
+
style:--selection={`${Math.min(1, Math.max(0, item.selection ?? (item.value === value ? 1 : 0))) * 100}%`}
|
|
86
|
+
onclick={() => onchange?.(item.value)}
|
|
87
|
+
>
|
|
88
|
+
{#if content}{@render content(item)}{:else}{item.label}{/if}
|
|
89
|
+
</button>
|
|
90
|
+
{/each}
|
|
91
|
+
</div>
|
|
92
|
+
</Panel>
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<style>
|
|
96
|
+
.button-group-frame {
|
|
97
|
+
height: 40px;
|
|
98
|
+
flex: none;
|
|
99
|
+
}
|
|
100
|
+
.button-group-frame :global(.button-group-panel) {
|
|
101
|
+
width: 100%;
|
|
102
|
+
height: 40px;
|
|
103
|
+
}
|
|
104
|
+
.button-group {
|
|
105
|
+
display: flex;
|
|
106
|
+
width: max-content;
|
|
107
|
+
height: 40px;
|
|
108
|
+
border-radius: var(--control-radius);
|
|
109
|
+
}
|
|
110
|
+
button {
|
|
111
|
+
box-sizing: border-box;
|
|
112
|
+
display: grid;
|
|
113
|
+
place-items: center;
|
|
114
|
+
min-width: 40px;
|
|
115
|
+
height: 40px;
|
|
116
|
+
padding: 0 12px;
|
|
117
|
+
border: 0;
|
|
118
|
+
font: inherit;
|
|
119
|
+
white-space: nowrap;
|
|
120
|
+
background: color-mix(
|
|
121
|
+
in srgb,
|
|
122
|
+
var(--ps-selection, var(--ps-section-muted, #eeeeee)) var(--selection),
|
|
123
|
+
transparent
|
|
124
|
+
);
|
|
125
|
+
color: color-mix(in srgb, var(--spatial-element-accent) var(--selection), var(--spatial-element-ink));
|
|
126
|
+
cursor: pointer;
|
|
127
|
+
touch-action: manipulation;
|
|
128
|
+
transition: background-color 180ms ease;
|
|
129
|
+
}
|
|
130
|
+
button.icon-only {
|
|
131
|
+
width: 40px;
|
|
132
|
+
padding: 0;
|
|
133
|
+
}
|
|
134
|
+
button { border-radius: max(0px, calc(var(--control-radius) - 2px)); }
|
|
135
|
+
.button-group:global([data-mouse-hover]) button:enabled:hover {
|
|
136
|
+
background: color-mix(in srgb, var(--spatial-element-body, currentColor) 8%, transparent);
|
|
137
|
+
}
|
|
138
|
+
button:focus-visible {
|
|
139
|
+
outline: 2px solid var(--spatial-element-accent, currentColor);
|
|
140
|
+
outline-offset: -2px;
|
|
141
|
+
}
|
|
142
|
+
button:disabled {
|
|
143
|
+
cursor: default;
|
|
144
|
+
opacity: 0.45;
|
|
145
|
+
}
|
|
146
|
+
@media (prefers-reduced-motion: reduce) {
|
|
147
|
+
button {
|
|
148
|
+
transition: none;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
</style>
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { type Snippet } from 'svelte';
|
|
2
|
+
import type { HTMLAttributes } from 'svelte/elements';
|
|
3
|
+
import type { StagePanelShape, StagePanelTheme } from '@spatial-elements/core/stage/panelContext';
|
|
4
|
+
import type { CatalogTransitionGroup } from '@spatial-elements/core/catalog/catalogPresentation';
|
|
5
|
+
import type { ButtonGroupItem } from './buttonGroup.js';
|
|
6
|
+
type Props = Omit<HTMLAttributes<HTMLDivElement>, 'children' | 'onchange'> & {
|
|
7
|
+
items: readonly ButtonGroupItem[];
|
|
8
|
+
/** Controlled selection. Omit when no button is selected. */
|
|
9
|
+
value?: string;
|
|
10
|
+
onchange?: (value: string) => void;
|
|
11
|
+
label: string;
|
|
12
|
+
content?: Snippet<[ButtonGroupItem]>;
|
|
13
|
+
iconOnly?: boolean;
|
|
14
|
+
disabled?: boolean;
|
|
15
|
+
visible?: boolean;
|
|
16
|
+
shape: StagePanelShape;
|
|
17
|
+
theme?: StagePanelTheme;
|
|
18
|
+
focusReactive?: boolean | 'top-right';
|
|
19
|
+
focusAnchor?: HTMLElement;
|
|
20
|
+
transitionGroup?: CatalogTransitionGroup;
|
|
21
|
+
};
|
|
22
|
+
declare const ButtonGroup: import("svelte").Component<Props, {}, "">;
|
|
23
|
+
type ButtonGroup = ReturnType<typeof ButtonGroup>;
|
|
24
|
+
export default ButtonGroup;
|