poe-svelte-ui-lib 1.7.7 → 1.7.9

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.
@@ -1,5 +1,4 @@
1
- <!-- $lib/ElementsUI/Map.svelte
2
- <script lang="ts">
1
+ <!-- <script lang="ts">
3
2
  import { t } from "../locales/i18n"
4
3
  import type { IDeviceGNSS, IMapProps } from "../types"
5
4
  import { onDestroy, onMount } from "svelte"
@@ -96,6 +95,7 @@
96
95
  }
97
96
  </script>
98
97
 
98
+ $lib/ElementsUI/Map.svelte
99
99
  <div id={`${id}-${crypto.randomUUID().slice(0, 6)}`} class="h-full min-h-50">
100
100
  {#if label.name}
101
101
  <h5 class={twMerge(` w-full px-4 text-center`, label.class)}>{label.name}</h5>
@@ -218,17 +218,101 @@
218
218
  </div> -->
219
219
 
220
220
  <script lang="ts">
221
- import { Map, TileLayer, Marker, Popup } from "sveaflet"
221
+ import { onMount } from "svelte"
222
+
223
+ let mapContainer: HTMLElement | null = null
224
+ let isLoading = $state(false)
225
+ let hasConnection = $state(true)
226
+
227
+ const CDN_URL = "https://cdn.jsdelivr.net/npm/maplibre-gl@5.17.0/dist/maplibre-gl.min.js"
228
+ const CSS_URL = "https://cdn.jsdelivr.net/npm/maplibre-gl@5.17.0/dist/maplibre-gl.min.css"
229
+
230
+ async function loadMapLibre() {
231
+ if (typeof window === "undefined") return
232
+
233
+ // Проверяем наличие интернета
234
+ if (!navigator.onLine) {
235
+ hasConnection = false
236
+ return
237
+ }
238
+
239
+ isLoading = true
240
+
241
+ try {
242
+ // Проверяем, не загружена ли уже библиотека
243
+ if (!window.maplibregl) {
244
+ await loadScript(CDN_URL)
245
+ await loadCSS(CSS_URL)
246
+
247
+ // После загрузки скрипта проверим, что window.maplibregl существует
248
+ if (!window.maplibregl) {
249
+ throw new Error("MapLibre GL не был загружен корректно.")
250
+ }
251
+ }
252
+
253
+ initMap()
254
+ } catch (err) {
255
+ console.error("Ошибка загрузки MapLibre GL:", err)
256
+ hasConnection = false
257
+ } finally {
258
+ isLoading = false
259
+ }
260
+ }
261
+
262
+ function loadScript(src: string): Promise<void> {
263
+ return new Promise((resolve, reject) => {
264
+ if (document.querySelector(`script[src="${src}"]`)) {
265
+ resolve()
266
+ return
267
+ }
268
+ const script = document.createElement("script")
269
+ script.src = src
270
+ script.async = true
271
+ script.onload = () => resolve() // Обернули resolve в стрелочную функцию
272
+ script.onerror = () => reject(new Error(`Не удалось загрузить скрипт ${src}`))
273
+ document.head.appendChild(script)
274
+ })
275
+ }
276
+
277
+ function loadCSS(href: string): Promise<void> {
278
+ return new Promise((resolve, reject) => {
279
+ if (document.querySelector(`link[href="${href}"]`)) {
280
+ resolve()
281
+ return
282
+ }
283
+ const link = document.createElement("link")
284
+ link.rel = "stylesheet"
285
+ link.href = href
286
+ link.onload = () => resolve() // Обернули resolve в стрелочную функцию
287
+ link.onerror = () => reject(new Error(`Не удалось загрузить стиль ${href}`))
288
+ document.head.appendChild(link)
289
+ })
290
+ }
291
+
292
+ function initMap() {
293
+ if (!mapContainer || !window.maplibregl) return
294
+
295
+ const map = new window.maplibregl.Map({
296
+ container: mapContainer,
297
+ style: "https://demotiles.maplibre.org/style.json",
298
+ center: [0, 0],
299
+ zoom: 1,
300
+ })
301
+
302
+ new window.maplibregl.Marker().setLngLat([0, 0]).addTo(map)
303
+ }
304
+
305
+ onMount(() => {
306
+ loadMapLibre()
307
+ })
222
308
  </script>
223
309
 
224
- <div style="width:100%;height:500px;">
225
- <Map
226
- options={{
227
- center: [51.505, -0.09],
228
- zoom: 13,
229
- }}
230
- >
231
- <TileLayer url={"https://tile.openstreetmap.org/{z}/{x}/{y}.png"} />
232
- <Marker latLng={[51.505, -0.09]} />
233
- </Map>
234
- </div>
310
+ <div class="map-container h-150 w-full" bind:this={mapContainer}></div>
311
+
312
+ {#if isLoading}
313
+ <p>Загрузка карты...</p>
314
+ {/if}
315
+
316
+ {#if !hasConnection}
317
+ <p>Нет подключения к интернету.</p>
318
+ {/if}
@@ -1,19 +1,3 @@
1
- import { Map } from "sveaflet";
2
- interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
3
- new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
4
- $$bindings?: Bindings;
5
- } & Exports;
6
- (internal: unknown, props: {
7
- $$events?: Events;
8
- $$slots?: Slots;
9
- }): Exports & {
10
- $set?: any;
11
- $on?: any;
12
- };
13
- z_$$bindings?: Bindings;
14
- }
15
- declare const Map: $$__sveltets_2_IsomorphicComponent<Record<string, never>, {
16
- [evt: string]: CustomEvent<any>;
17
- }, {}, {}, string>;
18
- type Map = InstanceType<typeof Map>;
1
+ declare const Map: import("svelte").Component<Record<string, never>, {}, "">;
2
+ type Map = ReturnType<typeof Map>;
19
3
  export default Map;
@@ -1,6 +1,5 @@
1
1
  <script lang="ts">
2
- import { onDestroy, type Snippet } from "svelte"
3
- import maplibregl from "maplibre-gl"
2
+ import { onDestroy, onMount, type Snippet } from "svelte"
4
3
  import { prepareMapContext } from "./contexts.svelte.js"
5
4
 
6
5
  interface Props {
@@ -1,5 +1,4 @@
1
1
  import { type Snippet } from "svelte";
2
- import maplibregl from "maplibre-gl";
3
2
  interface Props {
4
3
  class?: string;
5
4
  style?: maplibregl.StyleSpecification | string;
@@ -1,8 +1,7 @@
1
1
  <script lang="ts">
2
2
  // https://maplibre.org/maplibre-gl-js/docs/API/classes/Marker/
3
3
 
4
- import { onDestroy, type Snippet } from "svelte"
5
- import maplibregl from "maplibre-gl"
4
+ import { onDestroy, onMount, type Snippet } from "svelte"
6
5
  import { getMapContext, prepareMarkerContext } from "./contexts.svelte.js"
7
6
  import { formatLngLat, resetEventListener } from "./utils.js"
8
7
 
@@ -1,5 +1,4 @@
1
1
  import { type Snippet } from "svelte";
2
- import maplibregl from "maplibre-gl";
3
2
  interface Props extends Omit<maplibregl.MarkerOptions, "className"> {
4
3
  lnglat: maplibregl.LngLatLike;
5
4
  class?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "poe-svelte-ui-lib",
3
- "version": "1.7.7",
3
+ "version": "1.7.9",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "scripts": {
@@ -33,7 +33,7 @@
33
33
  "svelte": "^5.0.0"
34
34
  },
35
35
  "dependencies": {
36
- "sveaflet": "^0.1.4",
36
+ "@types/maplibre-gl": "^1.13.2",
37
37
  "tailwind-merge": "^3.4.0"
38
38
  },
39
39
  "devDependencies": {