@versatiles/svelte 0.0.4 → 0.1.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/README.md +5 -0
- package/dist/components/AutoComplete.svelte +19 -9
- package/dist/components/AutoComplete.svelte.d.ts +2 -1
- package/dist/components/BBoxMap/BBoxMap.svelte +22 -48
- package/dist/components/BasicMap/BasicMap.svelte +42 -0
- package/dist/components/BasicMap/BasicMap.svelte.d.ts +27 -0
- package/dist/index.d.ts +2 -1
- package/dist/index.js +2 -1
- package/dist/utils/style.d.ts +2 -2
- package/dist/utils/style.js +3 -2
- package/package.json +21 -21
package/README.md
CHANGED
@@ -14,6 +14,11 @@ npm i @versatiles/svelte
|
|
14
14
|
<th>Light Mode</th>
|
15
15
|
<th>Dark Mode</th>
|
16
16
|
</tr>
|
17
|
+
<tr>
|
18
|
+
<th>BasicMap</th>
|
19
|
+
<td><img src="https://github.com/versatiles-org/node-versatiles-svelte/releases/latest/download/basic-map-light.png"></td>
|
20
|
+
<td><img src="https://github.com/versatiles-org/node-versatiles-svelte/releases/latest/download/basic-map-dark.png"></td>
|
21
|
+
</tr>
|
17
22
|
<tr>
|
18
23
|
<th>BBoxMap</th>
|
19
24
|
<td><img src="https://github.com/versatiles-org/node-versatiles-svelte/releases/latest/download/bbox-map-light.png"></td>
|
@@ -1,16 +1,17 @@
|
|
1
1
|
<!-- AutoComplete.svelte -->
|
2
|
-
<script generics="T">import {
|
2
|
+
<script generics="T">import { isDarkMode } from "../utils/style.js";
|
3
|
+
import { createEventDispatcher, onMount } from "svelte";
|
3
4
|
const dispatch = createEventDispatcher();
|
4
5
|
export let placeholder = "";
|
5
6
|
export let minChar = 0;
|
6
7
|
export let maxItems = 10;
|
7
|
-
export let initialText = "";
|
8
8
|
export let items;
|
9
|
-
let
|
9
|
+
let inputElement;
|
10
|
+
let autocompleteElement;
|
10
11
|
let isOpen = false;
|
11
12
|
let results = [];
|
12
|
-
let inputText = initialText;
|
13
13
|
let selectedIndex = 0;
|
14
|
+
let inputText = "";
|
14
15
|
const regExpEscape = (s) => s.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&");
|
15
16
|
if (inputText.length >= minChar) {
|
16
17
|
const r = filterResults();
|
@@ -22,6 +23,12 @@ if (inputText.length >= minChar) {
|
|
22
23
|
inputText = "";
|
23
24
|
}
|
24
25
|
}
|
26
|
+
export function setInputText(text) {
|
27
|
+
console.log(text);
|
28
|
+
inputText = text;
|
29
|
+
results = filterResults();
|
30
|
+
close(0);
|
31
|
+
}
|
25
32
|
function onChange() {
|
26
33
|
if (inputText.length >= minChar) {
|
27
34
|
results = filterResults();
|
@@ -32,7 +39,7 @@ function onChange() {
|
|
32
39
|
}
|
33
40
|
}
|
34
41
|
function onFocus() {
|
35
|
-
|
42
|
+
inputElement.setSelectionRange(0, 1e3);
|
36
43
|
}
|
37
44
|
function filterResults() {
|
38
45
|
const searchText = inputText.trim();
|
@@ -69,11 +76,16 @@ function close(index = -1) {
|
|
69
76
|
dispatch("change", JSON.parse(JSON.stringify(value)));
|
70
77
|
}
|
71
78
|
}
|
79
|
+
onMount(() => {
|
80
|
+
const darkMode = isDarkMode(autocompleteElement);
|
81
|
+
autocompleteElement.style.setProperty("--bg-color", darkMode ? "#000" : "#fff");
|
82
|
+
autocompleteElement.style.setProperty("--fg-color", darkMode ? "#fff" : "#000");
|
83
|
+
});
|
72
84
|
</script>
|
73
85
|
|
74
86
|
<svelte:window on:click={() => close()} />
|
75
87
|
|
76
|
-
<div class="autocomplete">
|
88
|
+
<div class="autocomplete" bind:this={autocompleteElement}>
|
77
89
|
<input
|
78
90
|
type="text"
|
79
91
|
bind:value={inputText}
|
@@ -83,7 +95,7 @@ function close(index = -1) {
|
|
83
95
|
on:keydown={onKeyDown}
|
84
96
|
on:focusin={onFocus}
|
85
97
|
on:click={(e) => e.stopPropagation()}
|
86
|
-
bind:this={
|
98
|
+
bind:this={inputElement}
|
87
99
|
aria-activedescendant={isOpen ? `result-${selectedIndex}` : undefined}
|
88
100
|
aria-autocomplete="list"
|
89
101
|
aria-controls="autocomplete-results"
|
@@ -104,8 +116,6 @@ function close(index = -1) {
|
|
104
116
|
|
105
117
|
<style>
|
106
118
|
.autocomplete {
|
107
|
-
--bg-color: var(--autocomplete-bg-color, light-dark(white, black));
|
108
|
-
--fg-color: var(--autocomplete-text-color, light-dark(black, white));
|
109
119
|
position: relative;
|
110
120
|
border-radius: 0.5em;
|
111
121
|
background: color-mix(in srgb, var(--bg-color) 80%, transparent);
|
@@ -4,11 +4,11 @@ declare class __sveltets_Render<T> {
|
|
4
4
|
placeholder?: string;
|
5
5
|
minChar?: number;
|
6
6
|
maxItems?: number;
|
7
|
-
initialText?: string;
|
8
7
|
items: {
|
9
8
|
key: string;
|
10
9
|
value: T;
|
11
10
|
}[];
|
11
|
+
setInputText?: ((text: string) => void) | undefined;
|
12
12
|
};
|
13
13
|
events(): {
|
14
14
|
change: CustomEvent<any>;
|
@@ -21,5 +21,6 @@ export type AutoCompleteProps<T> = ReturnType<__sveltets_Render<T>['props']>;
|
|
21
21
|
export type AutoCompleteEvents<T> = ReturnType<__sveltets_Render<T>['events']>;
|
22
22
|
export type AutoCompleteSlots<T> = ReturnType<__sveltets_Render<T>['slots']>;
|
23
23
|
export default class AutoComplete<T> extends SvelteComponent<AutoCompleteProps<T>, AutoCompleteEvents<T>, AutoCompleteSlots<T>> {
|
24
|
+
get setInputText(): (text: string) => void;
|
24
25
|
}
|
25
26
|
export {};
|
@@ -3,37 +3,25 @@
|
|
3
3
|
import "maplibre-gl/dist/maplibre-gl.css";
|
4
4
|
import { dragBBox, getBBoxDrag, loadBBoxes, getBBoxGeometry, getCursor } from "./BBoxMap.js";
|
5
5
|
import AutoComplete from "../AutoComplete.svelte";
|
6
|
-
import { getMapStyle, isDarkMode } from "../../utils/style.js";
|
7
6
|
import { getCountry } from "../../utils/location.js";
|
7
|
+
import BasicMap from "../BasicMap/BasicMap.svelte";
|
8
|
+
import { isDarkMode } from "../../utils/style.js";
|
8
9
|
let bboxes = void 0;
|
9
|
-
let
|
10
|
+
let mapContainer;
|
11
|
+
let autoComplete = void 0;
|
10
12
|
const worldBBox = [-180, -85, 180, 85];
|
11
13
|
const startTime = Date.now();
|
12
14
|
export let selectedBBox = worldBBox;
|
13
15
|
let map;
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
(async () => MaplibreMap = (await import("maplibre-gl")).Map)()
|
21
|
-
]);
|
22
|
-
if (MaplibreMap == null) throw Error();
|
23
|
-
initMap(MaplibreMap);
|
24
|
-
}
|
25
|
-
function initMap(MaplibreMap) {
|
26
|
-
const darkMode = isDarkMode(container);
|
27
|
-
map = new MaplibreMap({
|
28
|
-
container,
|
29
|
-
style: getMapStyle(darkMode),
|
30
|
-
bounds: selectedBBox,
|
31
|
-
renderWorldCopies: false,
|
32
|
-
dragRotate: false,
|
33
|
-
attributionControl: { compact: false }
|
34
|
-
});
|
16
|
+
onMount(async () => {
|
17
|
+
bboxes = await loadBBoxes();
|
18
|
+
start();
|
19
|
+
});
|
20
|
+
function handleMapReady(event) {
|
21
|
+
map = event.detail.map;
|
35
22
|
map.setPadding({ top: 31 + 5, right: 5, bottom: 5, left: 5 });
|
36
23
|
const canvas = map.getCanvasContainer();
|
24
|
+
const bboxColor = isDarkMode(mapContainer) ? "#FFFFFF" : "#000000";
|
37
25
|
map.on("load", () => {
|
38
26
|
map.addSource("bbox", { type: "geojson", data: getBBoxGeometry(selectedBBox) });
|
39
27
|
map.addLayer({
|
@@ -42,14 +30,14 @@ function initMap(MaplibreMap) {
|
|
42
30
|
source: "bbox",
|
43
31
|
filter: ["==", "$type", "LineString"],
|
44
32
|
layout: { "line-cap": "round", "line-join": "round" },
|
45
|
-
paint: { "line-color":
|
33
|
+
paint: { "line-color": bboxColor, "line-width": 0.5 }
|
46
34
|
});
|
47
35
|
map.addLayer({
|
48
36
|
id: "bbox-fill",
|
49
37
|
type: "fill",
|
50
38
|
source: "bbox",
|
51
39
|
filter: ["==", "$type", "Polygon"],
|
52
|
-
paint: { "fill-color":
|
40
|
+
paint: { "fill-color": bboxColor, "fill-opacity": 0.2 }
|
53
41
|
});
|
54
42
|
});
|
55
43
|
function getDrag(point) {
|
@@ -89,7 +77,13 @@ function initMap(MaplibreMap) {
|
|
89
77
|
}
|
90
78
|
});
|
91
79
|
map.on("mouseup", () => dragging = false);
|
92
|
-
|
80
|
+
start();
|
81
|
+
}
|
82
|
+
function start() {
|
83
|
+
if (!bboxes) return;
|
84
|
+
if (!map) return;
|
85
|
+
if (!autoComplete) return;
|
86
|
+
autoComplete.setInputText(getCountry());
|
93
87
|
}
|
94
88
|
function redrawBBox() {
|
95
89
|
const bboxSource = map.getSource("bbox");
|
@@ -119,41 +113,21 @@ function flyTo(bbox) {
|
|
119
113
|
<AutoComplete
|
120
114
|
items={bboxes}
|
121
115
|
placeholder="Find country, region or city …"
|
122
|
-
initialText={initialCountry}
|
123
116
|
on:change={(e) => flyTo(e.detail)}
|
117
|
+
bind:this={autoComplete}
|
124
118
|
/>
|
125
119
|
</div>
|
126
120
|
{/if}
|
127
|
-
<
|
121
|
+
<BasicMap {map} bind:container={mapContainer} on:mapReady={handleMapReady}></BasicMap>
|
128
122
|
</div>
|
129
123
|
|
130
124
|
<style>
|
131
125
|
.container {
|
132
|
-
--bg-color: var(--bboxmap-bg-color, light-dark(white, black));
|
133
|
-
--fg-color: var(--bboxmap-text-color, light-dark(black, white));
|
134
126
|
width: 100%;
|
135
127
|
height: 100%;
|
136
128
|
position: relative;
|
137
129
|
min-height: 6em;
|
138
130
|
}
|
139
|
-
.map {
|
140
|
-
position: absolute;
|
141
|
-
top: 0px;
|
142
|
-
left: 0px;
|
143
|
-
bottom: 0px;
|
144
|
-
right: 0px;
|
145
|
-
}
|
146
|
-
:global(.maplibregl-ctrl-attrib) {
|
147
|
-
background-color: color-mix(in srgb, var(--bg-color) 50%, transparent) !important;
|
148
|
-
color: var(--fg-color) !important;
|
149
|
-
opacity: 0.5;
|
150
|
-
font-size: 0.85em;
|
151
|
-
padding: 0.1em !important;
|
152
|
-
line-height: normal !important;
|
153
|
-
}
|
154
|
-
:global(.maplibregl-ctrl-attrib a) {
|
155
|
-
color: var(--fg-color) !important;
|
156
|
-
}
|
157
131
|
.input {
|
158
132
|
position: absolute;
|
159
133
|
top: 0.5em;
|
@@ -0,0 +1,42 @@
|
|
1
|
+
<!-- BasicMap.svelte -->
|
2
|
+
<script>import { onMount, createEventDispatcher } from "svelte";
|
3
|
+
import "maplibre-gl/dist/maplibre-gl.css";
|
4
|
+
import { getMapStyle, isDarkMode } from "../../utils/style.js";
|
5
|
+
export let style = "position:absolute; left:0px; top:0px; width:100%; height:100%;";
|
6
|
+
export let container = void 0;
|
7
|
+
export let map = void 0;
|
8
|
+
export let styleOptions = {};
|
9
|
+
export let mapOptions = {};
|
10
|
+
const dispatch = createEventDispatcher();
|
11
|
+
onMount(async () => {
|
12
|
+
let MaplibreMap = (await import("maplibre-gl")).Map;
|
13
|
+
if (!container) throw Error();
|
14
|
+
const darkMode = isDarkMode(container);
|
15
|
+
container.style.setProperty("--bg-color", darkMode ? "#000" : "#fff");
|
16
|
+
container.style.setProperty("--fg-color", darkMode ? "#fff" : "#000");
|
17
|
+
map = new MaplibreMap({
|
18
|
+
container,
|
19
|
+
style: getMapStyle(darkMode, styleOptions),
|
20
|
+
renderWorldCopies: false,
|
21
|
+
dragRotate: false,
|
22
|
+
attributionControl: { compact: false },
|
23
|
+
...mapOptions
|
24
|
+
});
|
25
|
+
dispatch("mapReady", { map });
|
26
|
+
});
|
27
|
+
</script>
|
28
|
+
|
29
|
+
<div class="map" {style} bind:this={container}></div>
|
30
|
+
|
31
|
+
<style>
|
32
|
+
.map :global(.maplibregl-ctrl-attrib) {
|
33
|
+
background-color: color-mix(in srgb, var(--bg-color) 50%, transparent) !important;
|
34
|
+
color: var(--fg-color) !important;
|
35
|
+
opacity: 0.5;
|
36
|
+
font-size: 0.85em;
|
37
|
+
line-height: normal !important;
|
38
|
+
}
|
39
|
+
.map :global(.maplibregl-ctrl-attrib a) {
|
40
|
+
color: var(--fg-color) !important;
|
41
|
+
}
|
42
|
+
</style>
|
@@ -0,0 +1,27 @@
|
|
1
|
+
import { SvelteComponent } from "svelte";
|
2
|
+
import type { Map as MaplibreMapType, MapOptions } from 'maplibre-gl';
|
3
|
+
import 'maplibre-gl/dist/maplibre-gl.css';
|
4
|
+
import type { ColorfulOptions } from '@versatiles/style';
|
5
|
+
declare const __propDef: {
|
6
|
+
props: {
|
7
|
+
style?: string;
|
8
|
+
container?: HTMLDivElement | undefined;
|
9
|
+
map?: MaplibreMapType | undefined;
|
10
|
+
styleOptions?: ColorfulOptions;
|
11
|
+
mapOptions?: Partial<MapOptions>;
|
12
|
+
};
|
13
|
+
events: {
|
14
|
+
mapReady: CustomEvent<any>;
|
15
|
+
} & {
|
16
|
+
[evt: string]: CustomEvent<any>;
|
17
|
+
};
|
18
|
+
slots: {};
|
19
|
+
exports?: {} | undefined;
|
20
|
+
bindings?: string | undefined;
|
21
|
+
};
|
22
|
+
export type BasicMapProps = typeof __propDef.props;
|
23
|
+
export type BasicMapEvents = typeof __propDef.events;
|
24
|
+
export type BasicMapSlots = typeof __propDef.slots;
|
25
|
+
export default class BasicMap extends SvelteComponent<BasicMapProps, BasicMapEvents, BasicMapSlots> {
|
26
|
+
}
|
27
|
+
export {};
|
package/dist/index.d.ts
CHANGED
package/dist/index.js
CHANGED
package/dist/utils/style.d.ts
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
import { styles } from '@versatiles/style';
|
2
|
-
export declare function getMapStyle(darkMode: boolean): styles.MaplibreStyle;
|
1
|
+
import { styles, type ColorfulOptions } from '@versatiles/style';
|
2
|
+
export declare function getMapStyle(darkMode: boolean, styleOptions?: ColorfulOptions): styles.MaplibreStyle;
|
3
3
|
export declare function isDarkMode(element: HTMLElement): boolean;
|
package/dist/utils/style.js
CHANGED
@@ -1,13 +1,14 @@
|
|
1
1
|
import { styles } from '@versatiles/style';
|
2
2
|
import { getLanguage } from './location.js';
|
3
|
-
export function getMapStyle(darkMode) {
|
3
|
+
export function getMapStyle(darkMode, styleOptions = {}) {
|
4
4
|
return styles.colorful({
|
5
5
|
baseUrl: 'https://tiles.versatiles.org',
|
6
6
|
languageSuffix: getLanguage(),
|
7
7
|
recolor: {
|
8
8
|
invertBrightness: darkMode,
|
9
9
|
gamma: darkMode ? 0.5 : 1
|
10
|
-
}
|
10
|
+
},
|
11
|
+
...styleOptions
|
11
12
|
});
|
12
13
|
}
|
13
14
|
export function isDarkMode(element) {
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@versatiles/svelte",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.1.1",
|
4
4
|
"scripts": {
|
5
5
|
"build": "vite build && npm run package",
|
6
6
|
"check:watch": "svelte-kit sync && svelte-check --tsconfig ./tsconfig.json --watch",
|
@@ -15,7 +15,7 @@
|
|
15
15
|
"screenshots": "npm run build && npx tsx ./scripts/screenshots.ts",
|
16
16
|
"release": "npm run build && npx vrt release-npm",
|
17
17
|
"test:integration": "playwright test",
|
18
|
-
"test:unit": "vitest",
|
18
|
+
"test:unit": "vitest run",
|
19
19
|
"test": "npm run test:integration && npm run test:unit",
|
20
20
|
"upgrade": "npm-check-updates -u && rm -f package-lock.json; rm -rf node_modules; npm i && npm update"
|
21
21
|
},
|
@@ -36,38 +36,38 @@
|
|
36
36
|
"svelte": "^4.0.0"
|
37
37
|
},
|
38
38
|
"devDependencies": {
|
39
|
-
"@playwright/test": "^1.
|
40
|
-
"@sveltejs/adapter-auto": "^3.2.
|
41
|
-
"@sveltejs/kit": "^2.5.
|
42
|
-
"@sveltejs/package": "^2.3.
|
43
|
-
"@sveltejs/vite-plugin-svelte": "^3.1.
|
39
|
+
"@playwright/test": "^1.47.2",
|
40
|
+
"@sveltejs/adapter-auto": "^3.2.5",
|
41
|
+
"@sveltejs/kit": "^2.5.28",
|
42
|
+
"@sveltejs/package": "^2.3.5",
|
43
|
+
"@sveltejs/vite-plugin-svelte": "^3.1.2",
|
44
44
|
"@turf/turf": "^7.1.0",
|
45
|
-
"@types/eslint": "^9.6.
|
46
|
-
"@types/node": "^22.
|
45
|
+
"@types/eslint": "^9.6.1",
|
46
|
+
"@types/node": "^22.5.5",
|
47
47
|
"@types/split2": "^4.2.3",
|
48
|
-
"@versatiles/release-tool": "^1.2.
|
49
|
-
"eslint": "^9.
|
48
|
+
"@versatiles/release-tool": "^1.2.6",
|
49
|
+
"eslint": "^9.11.0",
|
50
50
|
"eslint-config-prettier": "^9.1.0",
|
51
|
-
"eslint-plugin-svelte": "^2.
|
51
|
+
"eslint-plugin-svelte": "^2.44.0",
|
52
52
|
"geojson": "^0.5.0",
|
53
53
|
"globals": "^15.9.0",
|
54
54
|
"prettier": "^3.3.3",
|
55
55
|
"prettier-plugin-svelte": "^3.2.6",
|
56
|
-
"publint": "^0.2.
|
56
|
+
"publint": "^0.2.11",
|
57
57
|
"split2": "^4.2.0",
|
58
|
-
"svelte": "^4.2.
|
59
|
-
"svelte-check": "^
|
60
|
-
"tsx": "^4.
|
61
|
-
"typescript": "^5.
|
62
|
-
"typescript-eslint": "^8.
|
63
|
-
"vite": "^5.4.
|
64
|
-
"vitest": "^2.
|
58
|
+
"svelte": "^4.2.19",
|
59
|
+
"svelte-check": "^4.0.2",
|
60
|
+
"tsx": "^4.19.1",
|
61
|
+
"typescript": "^5.6.2",
|
62
|
+
"typescript-eslint": "^8.6.0",
|
63
|
+
"vite": "^5.4.7",
|
64
|
+
"vitest": "^2.1.1"
|
65
65
|
},
|
66
66
|
"svelte": "./dist/index.js",
|
67
67
|
"types": "./dist/index.d.ts",
|
68
68
|
"type": "module",
|
69
69
|
"dependencies": {
|
70
70
|
"@versatiles/style": "^4.4.1",
|
71
|
-
"maplibre-gl": "^4.
|
71
|
+
"maplibre-gl": "^4.7.1"
|
72
72
|
}
|
73
73
|
}
|