@versatiles/svelte 0.0.4 → 0.1.0

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 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,12 +1,14 @@
1
1
  <!-- AutoComplete.svelte -->
2
- <script generics="T">import { createEventDispatcher } from "svelte";
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
8
  export let initialText = "";
8
9
  export let items;
9
- let input;
10
+ let inputElement;
11
+ let autocompleteElement;
10
12
  let isOpen = false;
11
13
  let results = [];
12
14
  let inputText = initialText;
@@ -32,7 +34,7 @@ function onChange() {
32
34
  }
33
35
  }
34
36
  function onFocus() {
35
- input.setSelectionRange(0, 1e3);
37
+ inputElement.setSelectionRange(0, 1e3);
36
38
  }
37
39
  function filterResults() {
38
40
  const searchText = inputText.trim();
@@ -69,11 +71,16 @@ function close(index = -1) {
69
71
  dispatch("change", JSON.parse(JSON.stringify(value)));
70
72
  }
71
73
  }
74
+ onMount(() => {
75
+ const darkMode = isDarkMode(autocompleteElement);
76
+ autocompleteElement.style.setProperty("--bg-color", darkMode ? "#000" : "#fff");
77
+ autocompleteElement.style.setProperty("--fg-color", darkMode ? "#fff" : "#000");
78
+ });
72
79
  </script>
73
80
 
74
81
  <svelte:window on:click={() => close()} />
75
82
 
76
- <div class="autocomplete">
83
+ <div class="autocomplete" bind:this={autocompleteElement}>
77
84
  <input
78
85
  type="text"
79
86
  bind:value={inputText}
@@ -83,7 +90,7 @@ function close(index = -1) {
83
90
  on:keydown={onKeyDown}
84
91
  on:focusin={onFocus}
85
92
  on:click={(e) => e.stopPropagation()}
86
- bind:this={input}
93
+ bind:this={inputElement}
87
94
  aria-activedescendant={isOpen ? `result-${selectedIndex}` : undefined}
88
95
  aria-autocomplete="list"
89
96
  aria-controls="autocomplete-results"
@@ -104,8 +111,6 @@ function close(index = -1) {
104
111
 
105
112
  <style>
106
113
  .autocomplete {
107
- --bg-color: var(--autocomplete-bg-color, light-dark(white, black));
108
- --fg-color: var(--autocomplete-text-color, light-dark(black, white));
109
114
  position: relative;
110
115
  border-radius: 0.5em;
111
116
  background: color-mix(in srgb, var(--bg-color) 80%, transparent);
@@ -3,37 +3,24 @@
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 container;
10
+ let mapContainer;
10
11
  const worldBBox = [-180, -85, 180, 85];
11
12
  const startTime = Date.now();
12
13
  export let selectedBBox = worldBBox;
13
14
  let map;
14
15
  let initialCountry = getCountry();
15
- onMount(() => init());
16
- async function init() {
17
- let MaplibreMap = void 0;
18
- await Promise.all([
19
- (async () => bboxes = await loadBBoxes())(),
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
+ });
19
+ function handleMapReady(event) {
20
+ map = event.detail.map;
35
21
  map.setPadding({ top: 31 + 5, right: 5, bottom: 5, left: 5 });
36
22
  const canvas = map.getCanvasContainer();
23
+ const bboxColor = isDarkMode(mapContainer) ? "#FFFFFF" : "#000000";
37
24
  map.on("load", () => {
38
25
  map.addSource("bbox", { type: "geojson", data: getBBoxGeometry(selectedBBox) });
39
26
  map.addLayer({
@@ -42,14 +29,14 @@ function initMap(MaplibreMap) {
42
29
  source: "bbox",
43
30
  filter: ["==", "$type", "LineString"],
44
31
  layout: { "line-cap": "round", "line-join": "round" },
45
- paint: { "line-color": darkMode ? "#FFFFFF" : "#000000", "line-width": 0.5 }
32
+ paint: { "line-color": bboxColor, "line-width": 0.5 }
46
33
  });
47
34
  map.addLayer({
48
35
  id: "bbox-fill",
49
36
  type: "fill",
50
37
  source: "bbox",
51
38
  filter: ["==", "$type", "Polygon"],
52
- paint: { "fill-color": darkMode ? "#FFFFFF" : "#000000", "fill-opacity": 0.2 }
39
+ paint: { "fill-color": bboxColor, "fill-opacity": 0.2 }
53
40
  });
54
41
  });
55
42
  function getDrag(point) {
@@ -89,7 +76,6 @@ function initMap(MaplibreMap) {
89
76
  }
90
77
  });
91
78
  map.on("mouseup", () => dragging = false);
92
- return () => map.remove();
93
79
  }
94
80
  function redrawBBox() {
95
81
  const bboxSource = map.getSource("bbox");
@@ -124,36 +110,16 @@ function flyTo(bbox) {
124
110
  />
125
111
  </div>
126
112
  {/if}
127
- <div class="map" bind:this={container}></div>
113
+ <BasicMap {map} bind:container={mapContainer} on:mapReady={handleMapReady}></BasicMap>
128
114
  </div>
129
115
 
130
116
  <style>
131
117
  .container {
132
- --bg-color: var(--bboxmap-bg-color, light-dark(white, black));
133
- --fg-color: var(--bboxmap-text-color, light-dark(black, white));
134
118
  width: 100%;
135
119
  height: 100%;
136
120
  position: relative;
137
121
  min-height: 6em;
138
122
  }
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
123
  .input {
158
124
  position: absolute;
159
125
  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
@@ -1,2 +1,3 @@
1
+ import BasicMap from './components/BasicMap/BasicMap.svelte';
1
2
  import BBoxMap from './components/BBoxMap/BBoxMap.svelte';
2
- export { BBoxMap };
3
+ export { BasicMap, BBoxMap };
package/dist/index.js CHANGED
@@ -1,2 +1,3 @@
1
+ import BasicMap from './components/BasicMap/BasicMap.svelte';
1
2
  import BBoxMap from './components/BBoxMap/BBoxMap.svelte';
2
- export { BBoxMap };
3
+ export { BasicMap, BBoxMap };
@@ -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;
@@ -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.0.4",
3
+ "version": "0.1.0",
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.46.1",
40
- "@sveltejs/adapter-auto": "^3.2.4",
41
- "@sveltejs/kit": "^2.5.22",
42
- "@sveltejs/package": "^2.3.4",
43
- "@sveltejs/vite-plugin-svelte": "^3.1.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.0",
46
- "@types/node": "^22.4.0",
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.5",
49
- "eslint": "^9.9.0",
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.43.0",
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.10",
56
+ "publint": "^0.2.11",
57
57
  "split2": "^4.2.0",
58
- "svelte": "^4.2.18",
59
- "svelte-check": "^3.8.5",
60
- "tsx": "^4.17.0",
61
- "typescript": "^5.5.4",
62
- "typescript-eslint": "^8.1.0",
63
- "vite": "^5.4.1",
64
- "vitest": "^2.0.5"
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.5.2"
71
+ "maplibre-gl": "^4.7.1"
72
72
  }
73
73
  }