@tileflow/svelte 0.1.0-alpha.19 → 0.1.0-alpha.20
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/GENERATED_OUTPUT_LICENSE.md +21 -0
- package/LICENSE +201 -0
- package/NOTICE +9 -0
- package/README.md +151 -6
- package/TRADEMARKS.md +10 -0
- package/package.json +15 -9
- package/src/TileflowMap.svelte +1062 -122
- package/src/index.d.ts +91 -20
- package/src/maplibre.js +18 -0
- package/src/style-source.d.ts +17 -0
- package/src/style-source.js +35 -0
- package/src/TileflowMap.svelte.d.ts +0 -8
package/src/index.d.ts
CHANGED
|
@@ -1,43 +1,114 @@
|
|
|
1
1
|
import type {Map as MapLibreMap, MapOptions as MapLibreMapOptions} from 'maplibre-gl';
|
|
2
|
-
import type {SvelteComponentTyped} from 'svelte';
|
|
2
|
+
import type {Snippet, SvelteComponentTyped} from 'svelte';
|
|
3
|
+
import type {TileflowThemeTransition} from '@tileflow/core/browser';
|
|
3
4
|
import type {
|
|
4
|
-
MapLibreStyle,
|
|
5
5
|
TileflowAnalytics,
|
|
6
|
-
TileflowConfig,
|
|
7
6
|
TileflowMapMarker,
|
|
8
|
-
|
|
9
|
-
|
|
7
|
+
TileflowRuntimeSource,
|
|
8
|
+
TileflowThemeSelection,
|
|
9
|
+
} from '@tileflow/core/runtime';
|
|
10
|
+
import type {
|
|
11
|
+
TileflowAnnotation,
|
|
12
|
+
TileflowAnnotationViewContext,
|
|
13
|
+
TileflowInteractionBinding,
|
|
14
|
+
TileflowInteractionDiagnostic,
|
|
15
|
+
TileflowInteractionEvent,
|
|
16
|
+
TileflowInteractionState,
|
|
17
|
+
TileflowInteractionViewContext,
|
|
18
|
+
} from '@tileflow/interactions';
|
|
10
19
|
|
|
11
20
|
export type TileflowMapMode = 'interactive' | 'image';
|
|
12
21
|
export type TileflowMapOptions = Omit<MapLibreMapOptions, 'container' | 'style'>;
|
|
22
|
+
export type TileflowMapSource = TileflowRuntimeSource;
|
|
23
|
+
|
|
24
|
+
export type TileflowMapMarkerSnippet<TAnnotation extends TileflowAnnotation = TileflowAnnotation> =
|
|
25
|
+
Snippet<[context: TileflowAnnotationViewContext<TAnnotation>]>;
|
|
26
|
+
|
|
27
|
+
export type TileflowMapAnnotationSnippet<
|
|
28
|
+
TAnnotation extends TileflowAnnotation = TileflowAnnotation,
|
|
29
|
+
> = TileflowMapMarkerSnippet<TAnnotation>;
|
|
13
30
|
|
|
14
|
-
export type
|
|
31
|
+
export type TileflowMapInteractionSnippet<
|
|
32
|
+
TAnnotation extends TileflowAnnotation = TileflowAnnotation,
|
|
33
|
+
> = Snippet<[context: TileflowInteractionViewContext<TAnnotation>]>;
|
|
34
|
+
|
|
35
|
+
type TileflowMapBaseProps = {
|
|
15
36
|
alt?: string;
|
|
16
37
|
analytics?: TileflowAnalytics;
|
|
17
38
|
center?: [number, number];
|
|
18
39
|
captureId?: string;
|
|
19
40
|
className?: string;
|
|
20
|
-
config?: TileflowConfig;
|
|
21
41
|
height?: number | string;
|
|
22
42
|
imageLoading?: HTMLImageElement['loading'];
|
|
23
43
|
imageUrl?: string;
|
|
24
44
|
interactive?: boolean;
|
|
25
|
-
manifestUrl?: string;
|
|
26
|
-
map?: string;
|
|
27
45
|
mapOptions?: TileflowMapOptions;
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
mode?: TileflowMapMode;
|
|
31
|
-
preferLocalDev?: boolean;
|
|
32
|
-
styleBaseUrl?: string;
|
|
33
|
-
styleUrl?: string;
|
|
34
|
-
themes?: TileflowProjectThemes;
|
|
46
|
+
onThemeChange?: (transition: TileflowThemeTransition) => void;
|
|
47
|
+
theme?: TileflowThemeSelection;
|
|
35
48
|
zoom?: number;
|
|
36
49
|
};
|
|
37
50
|
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
51
|
+
export type TileflowMapAnnotationProps<
|
|
52
|
+
TAnnotation extends TileflowAnnotation = TileflowAnnotation,
|
|
53
|
+
> =
|
|
54
|
+
| {
|
|
55
|
+
annotations?: readonly TAnnotation[];
|
|
56
|
+
markers?: never;
|
|
57
|
+
}
|
|
58
|
+
| {
|
|
59
|
+
annotations?: never;
|
|
60
|
+
markers?: readonly TileflowMapMarker[];
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
export type TileflowMapInteractionStateProps =
|
|
64
|
+
| {
|
|
65
|
+
defaultInteractionState?: TileflowInteractionState;
|
|
66
|
+
interactionState?: never;
|
|
67
|
+
}
|
|
68
|
+
| {
|
|
69
|
+
defaultInteractionState?: never;
|
|
70
|
+
interactionState?: TileflowInteractionState;
|
|
71
|
+
};
|
|
72
|
+
|
|
73
|
+
type TileflowMapStyleSourceProps = {
|
|
74
|
+
source: TileflowRuntimeSource;
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
type TileflowMapInteractiveProps<TAnnotation extends TileflowAnnotation> =
|
|
78
|
+
TileflowMapAnnotationProps<TAnnotation> &
|
|
79
|
+
TileflowMapInteractionStateProps & {
|
|
80
|
+
interactions?: readonly TileflowInteractionBinding[];
|
|
81
|
+
marker?: TileflowMapMarkerSnippet<TAnnotation>;
|
|
82
|
+
mode?: 'interactive';
|
|
83
|
+
onInteractionDiagnostic?: (diagnostic: TileflowInteractionDiagnostic) => void;
|
|
84
|
+
onInteractionEvent?: (event: TileflowInteractionEvent<TAnnotation>) => void;
|
|
85
|
+
onInteractionStateChange?: (state: TileflowInteractionState) => void;
|
|
86
|
+
popup?: TileflowMapInteractionSnippet<TAnnotation>;
|
|
87
|
+
tooltip?: TileflowMapInteractionSnippet<TAnnotation>;
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
type TileflowMapImageProps = {
|
|
91
|
+
annotations?: never;
|
|
92
|
+
defaultInteractionState?: never;
|
|
93
|
+
interactions?: never;
|
|
94
|
+
interactionState?: never;
|
|
95
|
+
marker?: never;
|
|
96
|
+
markers?: never;
|
|
97
|
+
mode: 'image';
|
|
98
|
+
onInteractionDiagnostic?: never;
|
|
99
|
+
onInteractionEvent?: never;
|
|
100
|
+
onInteractionStateChange?: never;
|
|
101
|
+
popup?: never;
|
|
102
|
+
tooltip?: never;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
export type TileflowMapProps<TAnnotation extends TileflowAnnotation = TileflowAnnotation> =
|
|
106
|
+
TileflowMapBaseProps &
|
|
107
|
+
TileflowMapStyleSourceProps &
|
|
108
|
+
(TileflowMapInteractiveProps<TAnnotation> | TileflowMapImageProps);
|
|
109
|
+
|
|
110
|
+
export default class TileflowMap<
|
|
111
|
+
TAnnotation extends TileflowAnnotation = TileflowAnnotation,
|
|
112
|
+
> extends SvelteComponentTyped<TileflowMapProps<TAnnotation>, {load: CustomEvent<MapLibreMap>}> {}
|
|
42
113
|
|
|
43
114
|
export {TileflowMap};
|
package/src/maplibre.js
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/** @typedef {typeof import('maplibre-gl')} TileflowMapLibre */
|
|
2
|
+
|
|
3
|
+
/** @type {Promise<TileflowMapLibre> | undefined} */
|
|
4
|
+
let mapLibrePromise;
|
|
5
|
+
|
|
6
|
+
/** Load the interactive renderer only after a browser map requests it. */
|
|
7
|
+
export function loadTileflowMapLibre() {
|
|
8
|
+
mapLibrePromise ??= import('maplibre-gl').then(resolveMapLibreModule).catch((error) => {
|
|
9
|
+
mapLibrePromise = undefined;
|
|
10
|
+
throw error;
|
|
11
|
+
});
|
|
12
|
+
return mapLibrePromise;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** @param {TileflowMapLibre} module */
|
|
16
|
+
function resolveMapLibreModule(module) {
|
|
17
|
+
return /** @type {TileflowMapLibre & {default?: TileflowMapLibre}} */ (module).default ?? module;
|
|
18
|
+
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type TileflowMapStyleInput = {
|
|
2
|
+
source?: unknown;
|
|
3
|
+
theme?: unknown;
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
type TileflowMapStyleInputValidation =
|
|
7
|
+
| {ok: true}
|
|
8
|
+
| {
|
|
9
|
+
error: string;
|
|
10
|
+
ok: false;
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
export declare function validateTileflowMapStyleInputs(
|
|
14
|
+
input: TileflowMapStyleInput,
|
|
15
|
+
): TileflowMapStyleInputValidation;
|
|
16
|
+
|
|
17
|
+
export declare function assertTileflowMapStyleInputs(input: TileflowMapStyleInput): void;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import {
|
|
2
|
+
validateTileflowRuntimeSource,
|
|
3
|
+
validateTileflowThemeSelection,
|
|
4
|
+
} from '@tileflow/core/runtime';
|
|
5
|
+
|
|
6
|
+
/** @typedef {{source?: unknown, theme?: unknown}} TileflowMapStyleInput */
|
|
7
|
+
/** @typedef {{ok: true} | {error: string; ok: false}} TileflowMapStyleInputValidation */
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* @param {TileflowMapStyleInput} input
|
|
11
|
+
* @returns {TileflowMapStyleInputValidation}
|
|
12
|
+
*/
|
|
13
|
+
export function validateTileflowMapStyleInputs(input) {
|
|
14
|
+
const sourceValidation = validateTileflowRuntimeSource(input.source);
|
|
15
|
+
if (!sourceValidation.ok) return sourceValidation;
|
|
16
|
+
if (input.theme !== undefined && !validateTileflowThemeSelection(input.theme)) {
|
|
17
|
+
return {error: 'theme must be a concrete portable theme name or "system"', ok: false};
|
|
18
|
+
}
|
|
19
|
+
if (
|
|
20
|
+
input.theme !== undefined &&
|
|
21
|
+
/** @type {{kind?: unknown}} */ (input.source).kind !== 'tileflow'
|
|
22
|
+
) {
|
|
23
|
+
return {error: 'theme is only valid with a tileflow source', ok: false};
|
|
24
|
+
}
|
|
25
|
+
return {ok: true};
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @param {TileflowMapStyleInput} input */
|
|
29
|
+
export function assertTileflowMapStyleInputs(input) {
|
|
30
|
+
const validation = validateTileflowMapStyleInputs(input);
|
|
31
|
+
|
|
32
|
+
if (!validation.ok) {
|
|
33
|
+
throw new TypeError(`Invalid TileflowMap source: ${validation.error}`);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import type {Map as MapLibreMap} from 'maplibre-gl';
|
|
2
|
-
import type {SvelteComponentTyped} from 'svelte';
|
|
3
|
-
import type {TileflowMapProps} from './index';
|
|
4
|
-
|
|
5
|
-
export default class TileflowMap extends SvelteComponentTyped<
|
|
6
|
-
TileflowMapProps,
|
|
7
|
-
{load: CustomEvent<MapLibreMap>}
|
|
8
|
-
> {}
|