@tileflow/svelte 0.1.0-alpha.26 → 0.1.0-alpha.27
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 +6 -0
- package/package.json +2 -2
- package/src/TileflowMap.svelte +66 -6
- package/src/index.d.ts +9 -1
- package/src/style-source.d.ts +2 -0
- package/src/style-source.js +31 -1
package/README.md
CHANGED
|
@@ -90,6 +90,12 @@ Omitting `theme` uses `defaultTheme`. `system` needs an explicit light/dark mapp
|
|
|
90
90
|
supplies. Theme changes keep the MapLibre instance, camera, and interactions, and roll back on
|
|
91
91
|
failure. `onThemeChange` reports transitions.
|
|
92
92
|
|
|
93
|
+
`themeTransition={{duration: 450}}` cross-fades theme changes over that many milliseconds.
|
|
94
|
+
`themeBlend={{themes: ['night', 'dusk', 'day'], position}}` shows a continuous blend of the map's
|
|
95
|
+
themes instead of `theme`: position 0 is the first theme and 1.5 is halfway from the second to the
|
|
96
|
+
third. Moving the position updates the map at once. See
|
|
97
|
+
[theme transitions and blends](https://github.com/tileflow/tileflow-sdk/blob/main/packages/core/docs/theme-transitions-and-blends.md).
|
|
98
|
+
|
|
93
99
|
`mapOptions` accepts native MapLibre options except `container` and `style`. Direct props win over
|
|
94
100
|
those options, then the manifest view, then shared defaults. `TileflowMap` always selects a Tileflow
|
|
95
101
|
map through its manifest; it has no renderer discriminator or direct-style mode. The obsolete
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tileflow/svelte",
|
|
3
|
-
"version": "0.1.0-alpha.
|
|
3
|
+
"version": "0.1.0-alpha.27",
|
|
4
4
|
"license": "Apache-2.0",
|
|
5
5
|
"description": "Svelte component for rendering Tileflow maps with MapLibre.",
|
|
6
6
|
"type": "module",
|
|
@@ -44,7 +44,7 @@
|
|
|
44
44
|
"access": "public"
|
|
45
45
|
},
|
|
46
46
|
"dependencies": {
|
|
47
|
-
"@tileflow/core": ">=0.1.0-alpha.
|
|
47
|
+
"@tileflow/core": ">=0.1.0-alpha.30 <0.1.0-beta.0",
|
|
48
48
|
"@tileflow/interactions": ">=0.1.0-alpha.4 <0.1.0-beta.0"
|
|
49
49
|
},
|
|
50
50
|
"peerDependencies": {
|
package/src/TileflowMap.svelte
CHANGED
|
@@ -15,15 +15,18 @@
|
|
|
15
15
|
defaultTileflowRuntimeView,
|
|
16
16
|
loadTileflowManifest,
|
|
17
17
|
mergeTileflowAnalytics,
|
|
18
|
+
nearestTileflowBlendTheme,
|
|
18
19
|
normalizeTileflowRuntimeCenter,
|
|
19
20
|
normalizeTileflowStaticImageSize,
|
|
20
21
|
resolveTileflowManifestMap,
|
|
21
22
|
resolveTileflowMapMode,
|
|
22
23
|
resolveTileflowRuntimeStyle,
|
|
23
24
|
resolveTileflowRuntimeTheme,
|
|
25
|
+
resolveTileflowRuntimeThemeBlend,
|
|
24
26
|
resolveTileflowRuntimeView,
|
|
25
27
|
resolveTileflowStaticImageUrl,
|
|
26
28
|
type TileflowRuntimeManifestMap,
|
|
29
|
+
type TileflowRuntimeStyle,
|
|
27
30
|
} from '@tileflow/core/runtime';
|
|
28
31
|
import {
|
|
29
32
|
attachTileflowAtmosphere,
|
|
@@ -96,6 +99,8 @@
|
|
|
96
99
|
export let popup: TileflowMapProps['popup'] = undefined;
|
|
97
100
|
export let source: TileflowMapProps['source'];
|
|
98
101
|
export let theme: TileflowMapProps['theme'] = undefined;
|
|
102
|
+
export let themeBlend: TileflowMapProps['themeBlend'] = undefined;
|
|
103
|
+
export let themeTransition: TileflowMapProps['themeTransition'] = undefined;
|
|
99
104
|
export let tooltip: TileflowMapProps['tooltip'] = undefined;
|
|
100
105
|
export let zoom: TileflowMapProps['zoom'] = undefined;
|
|
101
106
|
|
|
@@ -167,7 +172,7 @@
|
|
|
167
172
|
: {defaultInteractionState: initialInteractionState}),
|
|
168
173
|
});
|
|
169
174
|
$: resolvedMode = resolveTileflowMapMode({mode});
|
|
170
|
-
$: assertTileflowMapStyleInputs({source, theme});
|
|
175
|
+
$: assertTileflowMapStyleInputs({source, theme, themeBlend, themeTransition});
|
|
171
176
|
$: resolvedCaptureId = normalizeTileflowCaptureId(captureId);
|
|
172
177
|
$: isImageMode = resolvedMode === 'image';
|
|
173
178
|
$: mapName = source.map;
|
|
@@ -183,7 +188,10 @@
|
|
|
183
188
|
colorScheme: systemColorScheme,
|
|
184
189
|
manifestMap,
|
|
185
190
|
theme,
|
|
191
|
+
themeBlend,
|
|
186
192
|
});
|
|
193
|
+
$: themeBlendKey = themeBlend ? JSON.stringify(themeBlend.themes) : undefined;
|
|
194
|
+
$: themeBlendPosition = themeBlend?.position;
|
|
187
195
|
$: resolvedThemeName = themeResolution.name;
|
|
188
196
|
$: manifestView = resolveTileflowRuntimeView({manifestMap});
|
|
189
197
|
$: manifestCenter = normalizeTileflowRuntimeCenter(manifestView.center);
|
|
@@ -204,6 +212,7 @@
|
|
|
204
212
|
source,
|
|
205
213
|
theme: themeResolution.name,
|
|
206
214
|
});
|
|
215
|
+
$: blendStyles = resolveBlendStyles({isImageMode, key: themeBlendKey, manifestMap, source});
|
|
207
216
|
$: resolvedAnalytics = mergeTileflowAnalytics(analytics, runtimeStyle?.analytics);
|
|
208
217
|
$: runtimeImageUrl =
|
|
209
218
|
imageUrl ??
|
|
@@ -295,8 +304,15 @@
|
|
|
295
304
|
syncSystemColorSchemeSubscription();
|
|
296
305
|
}
|
|
297
306
|
|
|
307
|
+
$: if (mounted) {
|
|
308
|
+
blendStyles;
|
|
309
|
+
themeBlendPosition;
|
|
310
|
+
void switchBlend();
|
|
311
|
+
}
|
|
312
|
+
|
|
298
313
|
$: if (mounted) {
|
|
299
314
|
runtimeStyle;
|
|
315
|
+
themeBlendKey;
|
|
300
316
|
void switchTheme();
|
|
301
317
|
}
|
|
302
318
|
|
|
@@ -755,14 +771,34 @@
|
|
|
755
771
|
return () => subscription.unsubscribe();
|
|
756
772
|
},
|
|
757
773
|
});
|
|
758
|
-
if (themeController &&
|
|
774
|
+
if (themeController && blendStyles && themeBlend) {
|
|
775
|
+
void switchBlend();
|
|
776
|
+
} else if (themeController && runtimeStyle && runtimeStyle !== runtime) {
|
|
759
777
|
activeRuntimeResource = runtimeStyle;
|
|
760
|
-
void themeController.setTheme(runtimeStyle);
|
|
778
|
+
void themeController.setTheme(runtimeStyle, {transition: themeTransition});
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
async function switchBlend() {
|
|
783
|
+
const position = themeBlendPosition;
|
|
784
|
+
if (!themeController || !blendStyles || position === undefined) return;
|
|
785
|
+
if (runtimeStyle) activeRuntimeResource = runtimeStyle;
|
|
786
|
+
const result = await themeController.setBlend(
|
|
787
|
+
{position, themes: blendStyles},
|
|
788
|
+
{transition: themeTransition},
|
|
789
|
+
);
|
|
790
|
+
if (result.status === 'failed') {
|
|
791
|
+
console.error('Failed to blend the Tileflow map themes', result.error);
|
|
761
792
|
}
|
|
762
793
|
}
|
|
763
794
|
|
|
764
795
|
async function switchTheme() {
|
|
765
796
|
if (!themeController) return;
|
|
797
|
+
if (themeBlend) {
|
|
798
|
+
// The blend names its nearest theme; the blend itself is applied by switchBlend.
|
|
799
|
+
if (runtimeStyle) activeRuntimeResource = runtimeStyle;
|
|
800
|
+
return;
|
|
801
|
+
}
|
|
766
802
|
if (themeResolution.error) {
|
|
767
803
|
await themeController.setTheme(themeController.getCurrent());
|
|
768
804
|
return;
|
|
@@ -770,7 +806,7 @@
|
|
|
770
806
|
const next = runtimeStyle;
|
|
771
807
|
if (!next) return;
|
|
772
808
|
activeRuntimeResource = next;
|
|
773
|
-
const result = await themeController.setTheme(next);
|
|
809
|
+
const result = await themeController.setTheme(next, {transition: themeTransition});
|
|
774
810
|
if (result.status === 'failed') {
|
|
775
811
|
console.error('Failed to change the Tileflow map theme', result.error);
|
|
776
812
|
}
|
|
@@ -1206,24 +1242,48 @@
|
|
|
1206
1242
|
colorScheme: 'dark' | 'light';
|
|
1207
1243
|
manifestMap: TileflowRuntimeManifestMap | null;
|
|
1208
1244
|
theme: TileflowMapProps['theme'];
|
|
1245
|
+
themeBlend: TileflowMapProps['themeBlend'];
|
|
1209
1246
|
}): Readonly<{error: boolean; name: string | undefined}> {
|
|
1247
|
+
// A blend shows its nearest theme until the blend style is ready, and names it while blending.
|
|
1248
|
+
const selection = input.themeBlend ? nearestTileflowBlendTheme(input.themeBlend) : input.theme;
|
|
1210
1249
|
if (!input.manifestMap) {
|
|
1211
1250
|
return {
|
|
1212
1251
|
error: false,
|
|
1213
|
-
name:
|
|
1252
|
+
name: selection && selection !== 'system' ? selection : undefined,
|
|
1214
1253
|
};
|
|
1215
1254
|
}
|
|
1216
1255
|
|
|
1217
1256
|
try {
|
|
1257
|
+
for (const name of input.themeBlend?.themes ?? []) {
|
|
1258
|
+
resolveTileflowRuntimeTheme(input.manifestMap, name);
|
|
1259
|
+
}
|
|
1218
1260
|
return {
|
|
1219
1261
|
error: false,
|
|
1220
|
-
name: resolveTileflowRuntimeTheme(input.manifestMap,
|
|
1262
|
+
name: resolveTileflowRuntimeTheme(input.manifestMap, selection, input.colorScheme).name,
|
|
1221
1263
|
};
|
|
1222
1264
|
} catch {
|
|
1223
1265
|
return {error: true, name: undefined};
|
|
1224
1266
|
}
|
|
1225
1267
|
}
|
|
1226
1268
|
|
|
1269
|
+
function resolveBlendStyles(input: {
|
|
1270
|
+
isImageMode: boolean;
|
|
1271
|
+
key: string | undefined;
|
|
1272
|
+
manifestMap: TileflowRuntimeManifestMap | null;
|
|
1273
|
+
source: TileflowMapProps['source'];
|
|
1274
|
+
}): TileflowRuntimeStyle[] | null {
|
|
1275
|
+
if (input.isImageMode || !input.manifestMap || !input.key) return null;
|
|
1276
|
+
try {
|
|
1277
|
+
return resolveTileflowRuntimeThemeBlend({
|
|
1278
|
+
blend: {position: 0, themes: JSON.parse(input.key) as string[]},
|
|
1279
|
+
manifestMap: input.manifestMap,
|
|
1280
|
+
source: input.source,
|
|
1281
|
+
});
|
|
1282
|
+
} catch {
|
|
1283
|
+
return null;
|
|
1284
|
+
}
|
|
1285
|
+
}
|
|
1286
|
+
|
|
1227
1287
|
function resolveRuntimeResolutionState(input: {
|
|
1228
1288
|
currentManifestResolutionState: 'error' | 'loading' | 'ready';
|
|
1229
1289
|
imageSize: {height: number; width: number} | null;
|
package/src/index.d.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type {Map as MapLibreMap, MapOptions as MapLibreMapOptions} from 'maplibre-gl';
|
|
2
2
|
import type {Snippet, SvelteComponentTyped} from 'svelte';
|
|
3
|
-
import type {TileflowThemeTransition} from '@tileflow/core/browser';
|
|
3
|
+
import type {TileflowThemeTransition, TileflowThemeTransitionOptions} from '@tileflow/core/browser';
|
|
4
4
|
import type {
|
|
5
5
|
TileflowAnalytics,
|
|
6
6
|
TileflowRuntimeSource,
|
|
7
|
+
TileflowThemeBlendSelection,
|
|
7
8
|
TileflowThemeSelection,
|
|
8
9
|
} from '@tileflow/core/runtime';
|
|
9
10
|
import type {
|
|
@@ -45,6 +46,13 @@ type TileflowMapBaseProps = {
|
|
|
45
46
|
mapOptions?: TileflowMapOptions;
|
|
46
47
|
onThemeChange?: (transition: TileflowThemeTransition) => void;
|
|
47
48
|
theme?: TileflowThemeSelection;
|
|
49
|
+
/**
|
|
50
|
+
* Shows a continuous blend of the map's themes instead of `theme`. Moving `position` changes the
|
|
51
|
+
* map at once; changing `themes` prepares a new blend.
|
|
52
|
+
*/
|
|
53
|
+
themeBlend?: TileflowThemeBlendSelection;
|
|
54
|
+
/** Cross-fades theme changes, including entering and leaving a blend. */
|
|
55
|
+
themeTransition?: TileflowThemeTransitionOptions;
|
|
48
56
|
zoom?: number;
|
|
49
57
|
};
|
|
50
58
|
|
package/src/style-source.d.ts
CHANGED
package/src/style-source.js
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import {
|
|
2
2
|
validateTileflowRuntimeSource,
|
|
3
|
+
validateTileflowThemeBlendSelection,
|
|
3
4
|
validateTileflowThemeSelection,
|
|
4
5
|
} from '@tileflow/core/runtime';
|
|
5
6
|
|
|
6
|
-
/**
|
|
7
|
+
/**
|
|
8
|
+
* @typedef {{source?: unknown, theme?: unknown, themeBlend?: unknown, themeTransition?: unknown}}
|
|
9
|
+
* TileflowMapStyleInput
|
|
10
|
+
*/
|
|
7
11
|
/** @typedef {{ok: true} | {error: string; ok: false}} TileflowMapStyleInputValidation */
|
|
8
12
|
|
|
9
13
|
/**
|
|
@@ -16,9 +20,35 @@ export function validateTileflowMapStyleInputs(input) {
|
|
|
16
20
|
if (input.theme !== undefined && !validateTileflowThemeSelection(input.theme)) {
|
|
17
21
|
return {error: 'theme must be a concrete portable theme name or "system"', ok: false};
|
|
18
22
|
}
|
|
23
|
+
if (input.themeBlend !== undefined && !validateTileflowThemeBlendSelection(input.themeBlend)) {
|
|
24
|
+
return {
|
|
25
|
+
error:
|
|
26
|
+
'themeBlend must name two to eight concrete themes and a position from 0 to themes.length - 1',
|
|
27
|
+
ok: false,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
if (input.themeTransition !== undefined && !isThemeTransition(input.themeTransition)) {
|
|
31
|
+
return {
|
|
32
|
+
error: 'themeTransition.duration must be a number of milliseconds from 0 to 5000',
|
|
33
|
+
ok: false,
|
|
34
|
+
};
|
|
35
|
+
}
|
|
19
36
|
return {ok: true};
|
|
20
37
|
}
|
|
21
38
|
|
|
39
|
+
/**
|
|
40
|
+
* @param {unknown} value
|
|
41
|
+
* @returns {boolean}
|
|
42
|
+
*/
|
|
43
|
+
function isThemeTransition(value) {
|
|
44
|
+
if (!value || typeof value !== 'object') return false;
|
|
45
|
+
const {duration} = /** @type {{duration?: unknown}} */ (value);
|
|
46
|
+
return (
|
|
47
|
+
duration === undefined ||
|
|
48
|
+
(typeof duration === 'number' && Number.isFinite(duration) && duration >= 0 && duration <= 5000)
|
|
49
|
+
);
|
|
50
|
+
}
|
|
51
|
+
|
|
22
52
|
/** @param {TileflowMapStyleInput} input */
|
|
23
53
|
export function assertTileflowMapStyleInputs(input) {
|
|
24
54
|
const validation = validateTileflowMapStyleInputs(input);
|