@marianmeres/stuic 3.30.0 → 3.31.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.
@@ -1,7 +1,7 @@
1
1
  <script lang="ts" module>
2
2
  import type { ItemCollection as ItemCollectionBase } from "@marianmeres/item-collection";
3
- import type { HTMLAttributes } from "svelte/elements";
4
3
  import type { Snippet } from "svelte";
4
+ import type { HTMLAttributes } from "svelte/elements";
5
5
 
6
6
  export interface BookPageArea {
7
7
  id: string | number;
@@ -196,37 +196,14 @@
196
196
  height: targetHeight,
197
197
  };
198
198
  }
199
-
200
- /** Resolve a possibly relative URL against an optional base URL. */
201
- export function resolveUrl(url: string, baseUrl?: string): string {
202
- if (!baseUrl || !url) return url;
203
- try {
204
- return new URL(url, baseUrl).href;
205
- } catch {
206
- return url;
207
- }
208
- }
209
-
210
- /** Resolve all URLs inside a srcset string against an optional base URL. */
211
- export function resolveSrcset(srcset: string, baseUrl?: string): string {
212
- if (!baseUrl || !srcset) return srcset;
213
- return srcset
214
- .split(",")
215
- .map((entry) => {
216
- const parts = entry.trim().split(/\s+/);
217
- if (parts.length === 0) return entry;
218
- parts[0] = resolveUrl(parts[0], baseUrl);
219
- return parts.join(" ");
220
- })
221
- .join(", ");
222
- }
223
199
  </script>
224
200
 
225
201
  <script lang="ts">
202
+ import { createClog } from "@marianmeres/clog";
226
203
  import { ItemCollection } from "@marianmeres/item-collection";
227
- import { twMerge } from "../../utils/tw-merge.js";
228
204
  import { preloadImgs, type PreloadImgOptions } from "../../utils/preload-img.js";
229
- import { createClog } from "@marianmeres/clog";
205
+ import { resolveSrcset, resolveUrl } from "../../utils/resolve-url.js";
206
+ import { twMerge } from "../../utils/tw-merge.js";
230
207
 
231
208
  const clog = createClog("Book", { color: "auto" });
232
209
 
@@ -347,7 +324,8 @@
347
324
  if (page)
348
325
  toPreload.push({
349
326
  src: resolveUrl(page.src, page.baseUrl || baseUrl),
350
- srcset: resolveSrcset(page.srcset ?? "", page.baseUrl || baseUrl) || undefined,
327
+ srcset:
328
+ resolveSrcset(page.srcset ?? "", page.baseUrl || baseUrl) || undefined,
351
329
  sizes: page.sizes,
352
330
  });
353
331
  }
@@ -811,12 +789,24 @@
811
789
  </div>
812
790
  {:else}
813
791
  <img
814
- src={resolveUrl(sheet.frontPage.src, sheet.frontPage.baseUrl || baseUrl)}
815
- srcset={resolveSrcset(sheet.frontPage.srcset ?? "", sheet.frontPage.baseUrl || baseUrl) || undefined}
792
+ src={resolveUrl(
793
+ sheet.frontPage.src,
794
+ sheet.frontPage.baseUrl || baseUrl
795
+ )}
796
+ srcset={resolveSrcset(
797
+ sheet.frontPage.srcset ?? "",
798
+ sheet.frontPage.baseUrl || baseUrl
799
+ ) || undefined}
816
800
  sizes={sheet.frontPage.sizes}
817
801
  alt={sheet.frontPage.title ?? ""}
818
802
  draggable="false"
819
- onerror={() => handleImgError(resolveUrl(sheet.frontPage!.src, sheet.frontPage!.baseUrl || baseUrl))}
803
+ onerror={() =>
804
+ handleImgError(
805
+ resolveUrl(
806
+ sheet.frontPage!.src,
807
+ sheet.frontPage!.baseUrl || baseUrl
808
+ )
809
+ )}
820
810
  />
821
811
  {/if}
822
812
  {#if onAreaClick && Math.abs(sheet.id - activeSpread) <= 1 && sheet.frontPage.areas?.length && sheet.frontPage.width && sheet.frontPage.height}
@@ -827,7 +817,7 @@
827
817
  >
828
818
  <!-- svelte-ignore a11y_click_events_have_key_events -->
829
819
  <!-- svelte-ignore a11y_no_static_element_interactions -->
830
- {#each sheet.frontPage.areas as area (area.id)}
820
+ {#each sheet.frontPage.areas as area, i (`${area.id}-${i}`)}
831
821
  <rect
832
822
  x={area.x}
833
823
  y={area.y}
@@ -884,12 +874,24 @@
884
874
  </div>
885
875
  {:else}
886
876
  <img
887
- src={resolveUrl(sheet.backPage.src, sheet.backPage.baseUrl || baseUrl)}
888
- srcset={resolveSrcset(sheet.backPage.srcset ?? "", sheet.backPage.baseUrl || baseUrl) || undefined}
877
+ src={resolveUrl(
878
+ sheet.backPage.src,
879
+ sheet.backPage.baseUrl || baseUrl
880
+ )}
881
+ srcset={resolveSrcset(
882
+ sheet.backPage.srcset ?? "",
883
+ sheet.backPage.baseUrl || baseUrl
884
+ ) || undefined}
889
885
  sizes={sheet.backPage.sizes}
890
886
  alt={sheet.backPage.title ?? ""}
891
887
  draggable="false"
892
- onerror={() => handleImgError(resolveUrl(sheet.backPage!.src, sheet.backPage!.baseUrl || baseUrl))}
888
+ onerror={() =>
889
+ handleImgError(
890
+ resolveUrl(
891
+ sheet.backPage!.src,
892
+ sheet.backPage!.baseUrl || baseUrl
893
+ )
894
+ )}
893
895
  />
894
896
  {/if}
895
897
  {#if onAreaClick && Math.abs(sheet.id - activeSpread) <= 1 && sheet.backPage.areas?.length && sheet.backPage.width && sheet.backPage.height}
@@ -900,7 +902,7 @@
900
902
  >
901
903
  <!-- svelte-ignore a11y_click_events_have_key_events -->
902
904
  <!-- svelte-ignore a11y_no_static_element_interactions -->
903
- {#each sheet.backPage.areas as area (area.id)}
905
+ {#each sheet.backPage.areas as area, i (`${area.id}-${i}`)}
904
906
  <rect
905
907
  x={area.x}
906
908
  y={area.y}
@@ -1,6 +1,6 @@
1
1
  import type { ItemCollection as ItemCollectionBase } from "@marianmeres/item-collection";
2
- import type { HTMLAttributes } from "svelte/elements";
3
2
  import type { Snippet } from "svelte";
3
+ import type { HTMLAttributes } from "svelte/elements";
4
4
  export interface BookPageArea {
5
5
  id: string | number;
6
6
  /** X position in natural image pixels */
@@ -124,10 +124,6 @@ export declare function computeBookPageSize(pages: BookPage[], targetHeight?: nu
124
124
  width: number;
125
125
  height: number;
126
126
  };
127
- /** Resolve a possibly relative URL against an optional base URL. */
128
- export declare function resolveUrl(url: string, baseUrl?: string): string;
129
- /** Resolve all URLs inside a srcset string against an optional base URL. */
130
- export declare function resolveSrcset(srcset: string, baseUrl?: string): string;
131
127
  declare const Book: import("svelte").Component<Props, {
132
128
  zoomIn: () => void;
133
129
  zoomOut: () => void;
@@ -29,6 +29,7 @@ export * from "./prefers-reduced-motion.svelte.js";
29
29
  export * from "./preload-img.js";
30
30
  export * from "./qsa.js";
31
31
  export * from "./replace-map.js";
32
+ export * from "./resolve-url.js";
32
33
  export * from "./seconds.js";
33
34
  export * from "./sleep.js";
34
35
  export * from "./storage-abstraction.js";
@@ -29,6 +29,7 @@ export * from "./prefers-reduced-motion.svelte.js";
29
29
  export * from "./preload-img.js";
30
30
  export * from "./qsa.js";
31
31
  export * from "./replace-map.js";
32
+ export * from "./resolve-url.js";
32
33
  export * from "./seconds.js";
33
34
  export * from "./sleep.js";
34
35
  export * from "./storage-abstraction.js";
@@ -0,0 +1,4 @@
1
+ /** Resolve a possibly relative URL against an optional base URL. */
2
+ export declare function resolveUrl(url: string, baseUrl?: string): string;
3
+ /** Resolve all URLs inside a srcset string against an optional base URL. */
4
+ export declare function resolveSrcset(srcset: string, baseUrl?: string): string;
@@ -0,0 +1,26 @@
1
+ /** Resolve a possibly relative URL against an optional base URL. */
2
+ export function resolveUrl(url, baseUrl) {
3
+ if (!baseUrl || !url)
4
+ return url;
5
+ try {
6
+ return new URL(url, baseUrl).href;
7
+ }
8
+ catch {
9
+ return url;
10
+ }
11
+ }
12
+ /** Resolve all URLs inside a srcset string against an optional base URL. */
13
+ export function resolveSrcset(srcset, baseUrl) {
14
+ if (!baseUrl || !srcset)
15
+ return srcset;
16
+ return srcset
17
+ .split(",")
18
+ .map((entry) => {
19
+ const parts = entry.trim().split(/\s+/);
20
+ if (parts.length === 0)
21
+ return entry;
22
+ parts[0] = resolveUrl(parts[0], baseUrl);
23
+ return parts.join(" ");
24
+ })
25
+ .join(", ");
26
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.30.0",
3
+ "version": "3.31.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",