@tileflow/svelte 0.1.0-alpha.34 → 0.1.0-alpha.35

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
@@ -16,6 +16,12 @@ npm install @tileflow/svelte@alpha @tileflow/core@alpha @tileflow/maps@alpha "ma
16
16
  npm install --save-dev --save-exact tileflow@alpha
17
17
  ```
18
18
 
19
+ Prepared styles may retain relative asset URLs. The component loads them through Core's shared
20
+ resource loader before creating the map and before changing or blending themes. Sprites, fonts,
21
+ data and model resources resolve against their declaring documents. Pending document loads are
22
+ cancelled when the map is replaced or unmounted; `mapOptions.transformRequest` also applies to
23
+ style and HTTP TileJSON requests.
24
+
19
25
  ## Prepare a map
20
26
 
21
27
  Create `tileflow.config.ts` at the application root:
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tileflow/svelte",
3
- "version": "0.1.0-alpha.34",
3
+ "version": "0.1.0-alpha.35",
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.43 <0.1.0-beta.0",
47
+ "@tileflow/core": ">=0.1.0-alpha.45 <0.1.0-beta.0",
48
48
  "@tileflow/interactions": ">=0.1.0-alpha.7 <0.1.0-beta.0"
49
49
  },
50
50
  "peerDependencies": {
@@ -52,7 +52,7 @@
52
52
  "svelte": ">=5 <6"
53
53
  },
54
54
  "devDependencies": {
55
- "maplibre-gl": "6.13.0",
55
+ "maplibre-gl": "6.16.0",
56
56
  "svelte": "^5.57.2",
57
57
  "svelte-check": "^4.7.7"
58
58
  },
@@ -42,6 +42,7 @@
42
42
  type TileflowMap3DAttachment,
43
43
  createTileflowTransformRequest,
44
44
  getTileflowSystemColorScheme,
45
+ loadTileflowRuntimeStyle,
45
46
  loadTileflowStyleFonts,
46
47
  registerTileflowContourProtocol,
47
48
  registerTileflowPathGroundProtocol,
@@ -166,6 +167,7 @@
166
167
  let manifestResolutionKey = '';
167
168
  let manifestResolutionState: 'error' | 'loading' | 'ready' = 'loading';
168
169
  let mapLoadId = 0;
170
+ let resourceLifetime: AbortController | undefined;
169
171
  let mounted = false;
170
172
  let refreshRunId = 0;
171
173
  let readinessRunId = 0;
@@ -451,6 +453,8 @@
451
453
 
452
454
  function destroyMap() {
453
455
  mapLoadId += 1;
456
+ resourceLifetime?.abort();
457
+ resourceLifetime = undefined;
454
458
  readinessRunId += 1;
455
459
  const lifecycleAttachment = mapLifecycleAttachment;
456
460
  const fairUseNotice = mapFairUseNotice;
@@ -552,15 +556,36 @@
552
556
  const loadId = mapLoadId;
553
557
  const targetContainer = container;
554
558
  const runtime = runtimeStyle;
559
+ const session = createTileflowSessionController({source: 'svelte'});
560
+ const lifetime = new AbortController();
561
+ resourceLifetime = lifetime;
562
+ const resourceTransform = createTileflowTransformRequest({
563
+ getAnalytics: () => resolvedAnalytics,
564
+ sessionController: session,
565
+ sessionId: session.sessionId,
566
+ transformRequest: mapOptions?.transformRequest ?? undefined,
567
+ });
568
+ const styleLoadOptions = {
569
+ signal: lifetime.signal,
570
+ transformRequest: (url: string, type: 'Style' | 'Source') =>
571
+ resourceTransform(
572
+ url,
573
+ type as Parameters<NonNullable<TileflowMapOptions['transformRequest']>>[1],
574
+ ),
575
+ };
555
576
  let maplibregl: Awaited<ReturnType<typeof loadTileflowMapLibre>>;
556
-
577
+ let prepared: Awaited<ReturnType<typeof loadTileflowRuntimeStyle>>;
557
578
  try {
558
- [maplibregl] = await Promise.all([
579
+ [maplibregl, prepared] = await Promise.all([
559
580
  loadTileflowMapLibre(),
560
- loadTileflowStyleFonts(runtime.style, {fontFaces: runtime.fontFaces}),
581
+ loadTileflowRuntimeStyle(runtime, styleLoadOptions).then(async (loaded) => {
582
+ await loadTileflowStyleFonts(loaded.style, {fontFaces: loaded.fontFaces});
583
+ return loaded;
584
+ }),
561
585
  ]);
562
586
  } catch (error) {
563
587
  if (mounted && runId === refreshRunId && loadId === mapLoadId) {
588
+ lifetime.abort();
564
589
  console.error('Failed to load the Tileflow map runtime', error);
565
590
  mapCaptureState = 'error';
566
591
  }
@@ -577,7 +602,6 @@
577
602
  return;
578
603
  }
579
604
 
580
- const session = createTileflowSessionController({source: 'svelte'});
581
605
  const sessionStarter = createTileflowSessionStarter({
582
606
  getSessionId: () => session.sessionId,
583
607
  sessionId: session.sessionId,
@@ -603,7 +627,7 @@
603
627
  container: targetContainer,
604
628
  interactive: resolvedInteractive,
605
629
  pitch: resolvedPitch,
606
- style: runtime.style as StyleSpecification | string,
630
+ style: prepared.style as StyleSpecification,
607
631
  transformRequest: createTileflowTransformRequest({
608
632
  getAnalytics: () => resolvedAnalytics,
609
633
  sessionController: session,
@@ -625,7 +649,9 @@
625
649
  runtime.theme === undefined
626
650
  ? null
627
651
  : createTileflowThemeController({
628
- initial: runtime,
652
+ initial: prepared.family ? prepared : runtime,
653
+ initialStyle: prepared.style,
654
+ styleLoadOptions,
629
655
  map: maplibreMap,
630
656
  onTransition(transition) {
631
657
  onThemeChange?.(transition);