@marianmeres/stuic 3.47.3 → 3.47.4

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.
@@ -46,6 +46,8 @@
46
46
  initialIndex?: number;
47
47
  /** Current asset index (bindable). Defaults to initialIndex. */
48
48
  currentIndex?: number;
49
+ /** Force preloading of all assets on mount, regardless of count (default: false) */
50
+ preloadAll?: boolean;
49
51
  }
50
52
  </script>
51
53
 
@@ -75,6 +77,7 @@
75
77
  prevNextBottom = false,
76
78
  initialIndex = 0,
77
79
  currentIndex = $bindable(initialIndex),
80
+ preloadAll = false,
78
81
  }: Props = $props();
79
82
 
80
83
  let assets: AssetPreviewNormalized[] = $derived(
@@ -83,18 +86,28 @@
83
86
 
84
87
  let content: AssetsPreviewContent | undefined = $state();
85
88
 
86
- // Preload images when assets change
89
+ // On-mount preload: all assets for small galleries or when forced;
90
+ // a window around the initial index for large collections.
87
91
  $effect(() => {
88
- const toPreload: PreloadImgOptions[] = (assets ?? [])
89
- .filter((asset) => asset.isImage)
90
- .map((asset) => ({
91
- src: resolveUrl(String(asset.url.full), baseUrl),
92
- srcset: resolveSrcset(asset.srcset ?? "", baseUrl) || undefined,
93
- sizes: asset.sizes,
94
- }));
95
- if (toPreload.length) {
96
- preloadImgs(toPreload);
97
- }
92
+ const SMALL_THRESHOLD = 20;
93
+ const WINDOW = 5;
94
+
95
+ const all = (assets ?? []).filter((a) => a.isImage);
96
+ const subset =
97
+ preloadAll || all.length <= SMALL_THRESHOLD
98
+ ? all
99
+ : all.slice(
100
+ Math.max(0, currentIndex - WINDOW),
101
+ Math.min(all.length, currentIndex + WINDOW + 1)
102
+ );
103
+
104
+ const toPreload: PreloadImgOptions[] = subset.map((asset) => ({
105
+ src: resolveUrl(String(asset.url.full), baseUrl),
106
+ srcset: resolveSrcset(asset.srcset ?? "", baseUrl) || undefined,
107
+ sizes: asset.sizes,
108
+ }));
109
+
110
+ if (toPreload.length) preloadImgs(toPreload);
98
111
  });
99
112
 
100
113
  export function goTo(index: number) {
@@ -39,6 +39,8 @@ export interface Props {
39
39
  initialIndex?: number;
40
40
  /** Current asset index (bindable). Defaults to initialIndex. */
41
41
  currentIndex?: number;
42
+ /** Force preloading of all assets on mount, regardless of count (default: false) */
43
+ preloadAll?: boolean;
42
44
  }
43
45
  declare const AssetsPreviewInline: import("svelte").Component<Props, {
44
46
  goTo: (index: number) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.47.3",
3
+ "version": "3.47.4",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",