resuxjs 0.2.34 → 0.2.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/dist/cli.js +22 -3
- package/dist/cli.js.map +1 -1
- package/dist/deploy/index.js +1 -34
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/vercel.js +6 -8
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/runtime/index.js +337 -82
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -1
package/dist/runtime/index.js
CHANGED
|
@@ -533,15 +533,22 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
533
533
|
const trimmedProvider = providerName.trim().toLowerCase();
|
|
534
534
|
const baseURL = providerBaseURL?.trim()
|
|
535
535
|
|| (trimmedProvider === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
536
|
+
const normalizedFormat = normalizeImageOutputFormat(typeof modifiers.format === "string" ? modifiers.format : undefined);
|
|
536
537
|
if (baseURL.includes("{src}")) {
|
|
537
538
|
return injectImageTemplateSource(baseURL, src, modifiers);
|
|
538
539
|
}
|
|
540
|
+
const sourceDescriptor = trimmedProvider === "vercel"
|
|
541
|
+
? { publicSource: src }
|
|
542
|
+
: rewriteImageSourceForDisplayFormat(src, normalizedFormat);
|
|
539
543
|
const query = new URLSearchParams();
|
|
540
544
|
if (trimmedProvider === "vercel") {
|
|
541
545
|
query.set("url", src);
|
|
542
546
|
}
|
|
543
547
|
else {
|
|
544
|
-
query.set("src",
|
|
548
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
549
|
+
if (sourceDescriptor.originalSource) {
|
|
550
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
551
|
+
}
|
|
545
552
|
}
|
|
546
553
|
const width = Number(modifiers.width);
|
|
547
554
|
const height = Number(modifiers.height);
|
|
@@ -558,7 +565,10 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
558
565
|
if (typeof modifiers.fit === "string" && modifiers.fit.length > 0) {
|
|
559
566
|
query.set("fit", modifiers.fit);
|
|
560
567
|
}
|
|
561
|
-
if (
|
|
568
|
+
if (normalizedFormat) {
|
|
569
|
+
query.set("f", normalizedFormat);
|
|
570
|
+
}
|
|
571
|
+
else if (typeof modifiers.format === "string" && modifiers.format.length > 0) {
|
|
562
572
|
query.set("f", modifiers.format);
|
|
563
573
|
}
|
|
564
574
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
@@ -585,6 +595,58 @@ function injectImageTemplateSource(template, src, modifiers) {
|
|
|
585
595
|
}
|
|
586
596
|
return resolved;
|
|
587
597
|
}
|
|
598
|
+
function normalizeImageOutputFormat(value) {
|
|
599
|
+
if (typeof value !== "string") {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
const normalized = value.trim().toLowerCase();
|
|
603
|
+
if (!normalized) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
607
|
+
}
|
|
608
|
+
function rewriteImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
609
|
+
if (!normalizedFormat) {
|
|
610
|
+
return { publicSource: src };
|
|
611
|
+
}
|
|
612
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
613
|
+
return { publicSource: src };
|
|
614
|
+
}
|
|
615
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
616
|
+
try {
|
|
617
|
+
const sourceUrl = new URL(src);
|
|
618
|
+
const rewrittenPathname = rewriteImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
619
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
620
|
+
return { publicSource: src };
|
|
621
|
+
}
|
|
622
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
623
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
return { publicSource: src };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
630
|
+
const rewrittenPath = rewriteImagePathExtension(pathPart, normalizedFormat);
|
|
631
|
+
if (rewrittenPath === pathPart) {
|
|
632
|
+
return { publicSource: src };
|
|
633
|
+
}
|
|
634
|
+
return { publicSource: `${rewrittenPath}${suffix}`, originalSource: src };
|
|
635
|
+
}
|
|
636
|
+
function rewriteImagePathExtension(pathname, extension) {
|
|
637
|
+
if (!pathname) {
|
|
638
|
+
return pathname;
|
|
639
|
+
}
|
|
640
|
+
const normalizedExtension = extension.startsWith(".")
|
|
641
|
+
? extension.slice(1)
|
|
642
|
+
: extension;
|
|
643
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
644
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
645
|
+
if (lastDot > lastSlash) {
|
|
646
|
+
return `${pathname.slice(0, lastDot + 1)}${normalizedExtension}`;
|
|
647
|
+
}
|
|
648
|
+
return `${pathname}.${normalizedExtension}`;
|
|
649
|
+
}
|
|
588
650
|
function runtimeOrigin(runtimeConfig) {
|
|
589
651
|
const publicConfig = runtimeConfig.public ?? {};
|
|
590
652
|
for (const key of ["appOrigin", "appURL", "siteURL", "origin"]) {
|
|
@@ -834,6 +896,7 @@ const resuxImageReservedProps = new Set([
|
|
|
834
896
|
"fetchpriority",
|
|
835
897
|
"fetchPriority",
|
|
836
898
|
]);
|
|
899
|
+
const resuxLazyPlaceholderSrc = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
837
900
|
function renderResuxImg(node, context, locals) {
|
|
838
901
|
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
839
902
|
if (!input.src) {
|
|
@@ -850,7 +913,7 @@ function renderResuxImg(node, context, locals) {
|
|
|
850
913
|
modifiers: input.modifiers,
|
|
851
914
|
});
|
|
852
915
|
const srcset = buildResuxImageSrcset(builder, input);
|
|
853
|
-
registerResuxImagePreload(context, src, srcset, input
|
|
916
|
+
registerResuxImagePreload(context, src, srcset, input, input.preload);
|
|
854
917
|
return renderResuxImgTag(input, src, srcset, context.styleScopeId);
|
|
855
918
|
}
|
|
856
919
|
function renderResuxPicture(node, context, locals) {
|
|
@@ -871,7 +934,7 @@ function renderResuxPicture(node, context, locals) {
|
|
|
871
934
|
...input,
|
|
872
935
|
format: undefined,
|
|
873
936
|
});
|
|
874
|
-
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input
|
|
937
|
+
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input, input.preload);
|
|
875
938
|
const manualChildren = renderTemplateNodes(node.children, context, locals);
|
|
876
939
|
const generatedSources = input.formats
|
|
877
940
|
.map((format) => {
|
|
@@ -892,12 +955,18 @@ function renderResuxPicture(node, context, locals) {
|
|
|
892
955
|
if (!resolvedSrcset) {
|
|
893
956
|
return "";
|
|
894
957
|
}
|
|
895
|
-
const sourceAttrs = [
|
|
896
|
-
|
|
897
|
-
`srcset="${escapeAttribute(resolvedSrcset)}"
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
958
|
+
const sourceAttrs = [`type="${escapeAttribute(resuxImageMimeType(format))}"`];
|
|
959
|
+
if (input.deferLazy) {
|
|
960
|
+
sourceAttrs.push(`data-rx-lazy-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
961
|
+
if (input.sizes) {
|
|
962
|
+
sourceAttrs.push(`data-rx-lazy-sizes="${escapeAttribute(input.sizes)}"`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
sourceAttrs.push(`srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
967
|
+
if (input.sizes) {
|
|
968
|
+
sourceAttrs.push(`sizes="${escapeAttribute(input.sizes)}"`);
|
|
969
|
+
}
|
|
901
970
|
}
|
|
902
971
|
return `<source ${sourceAttrs.join(" ")}>`;
|
|
903
972
|
})
|
|
@@ -923,8 +992,13 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
923
992
|
const height = readNumberProp(props.height);
|
|
924
993
|
const priority = readBooleanProp(props.priority, false);
|
|
925
994
|
const preload = readBooleanProp(props.preload, priority);
|
|
926
|
-
const
|
|
927
|
-
const
|
|
995
|
+
const explicitLoading = readStringProp(props.loading);
|
|
996
|
+
const explicitLazy = props.lazy === undefined
|
|
997
|
+
? undefined
|
|
998
|
+
: readBooleanProp(props.lazy, true);
|
|
999
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
1000
|
+
const loading = explicitLoading ?? (lazy ? "lazy" : "eager");
|
|
1001
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
928
1002
|
const decoding = readStringProp(props.decoding) ?? "async";
|
|
929
1003
|
const fetchPriority = readStringProp(props.fetchpriority ?? props.fetchPriority)
|
|
930
1004
|
?? (priority ? "high" : undefined);
|
|
@@ -952,6 +1026,7 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
952
1026
|
format: explicitFormats.length ? undefined : explicitFormat ?? runtimeImageConfig.format,
|
|
953
1027
|
formats: explicitFormats,
|
|
954
1028
|
preload,
|
|
1029
|
+
deferLazy,
|
|
955
1030
|
modifiers,
|
|
956
1031
|
attrs: passthrough,
|
|
957
1032
|
};
|
|
@@ -1018,7 +1093,7 @@ function buildResuxImageSrcset(builder, input) {
|
|
|
1018
1093
|
})
|
|
1019
1094
|
.join(", ");
|
|
1020
1095
|
}
|
|
1021
|
-
function registerResuxImagePreload(context, href, srcset,
|
|
1096
|
+
function registerResuxImagePreload(context, href, srcset, input, enabled) {
|
|
1022
1097
|
if (!enabled || !href || !context.addHeadEntry) {
|
|
1023
1098
|
return;
|
|
1024
1099
|
}
|
|
@@ -1026,28 +1101,37 @@ function registerResuxImagePreload(context, href, srcset, sizes, enabled) {
|
|
|
1026
1101
|
rel: "preload",
|
|
1027
1102
|
as: "image",
|
|
1028
1103
|
href,
|
|
1104
|
+
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1029
1105
|
};
|
|
1030
1106
|
if (srcset) {
|
|
1031
1107
|
link.imagesrcset = srcset;
|
|
1032
1108
|
}
|
|
1033
|
-
if (sizes) {
|
|
1034
|
-
link.imagesizes = sizes;
|
|
1109
|
+
if (input.sizes) {
|
|
1110
|
+
link.imagesizes = input.sizes;
|
|
1111
|
+
}
|
|
1112
|
+
if (input.format && input.formats.length === 0) {
|
|
1113
|
+
link.type = resuxImageMimeType(input.format);
|
|
1035
1114
|
}
|
|
1036
1115
|
context.addHeadEntry({ link: [link] });
|
|
1037
1116
|
}
|
|
1038
1117
|
function renderResuxImgTag(input, src, srcset, styleScopeId) {
|
|
1039
1118
|
const attrs = [];
|
|
1119
|
+
const isDeferredLazy = input.deferLazy && input.loading.toLowerCase() === "lazy";
|
|
1040
1120
|
const mergedAttrs = {
|
|
1041
1121
|
...input.attrs,
|
|
1042
|
-
src,
|
|
1122
|
+
src: isDeferredLazy ? resuxLazyPlaceholderSrc : src,
|
|
1043
1123
|
alt: input.alt,
|
|
1044
1124
|
loading: input.loading,
|
|
1045
1125
|
decoding: input.decoding,
|
|
1126
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
1127
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src } : {}),
|
|
1128
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset } : {}),
|
|
1129
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
1046
1130
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1047
1131
|
...(input.width ? { width: String(input.width) } : {}),
|
|
1048
1132
|
...(input.height ? { height: String(input.height) } : {}),
|
|
1049
|
-
...(srcset ? { srcset } : {}),
|
|
1050
|
-
...(input.sizes ? { sizes: input.sizes } : {}),
|
|
1133
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
1134
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {}),
|
|
1051
1135
|
};
|
|
1052
1136
|
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
1053
1137
|
if (value === undefined || value === null) {
|
|
@@ -1679,9 +1763,11 @@ let routeTransitionProgressTimer = 0;
|
|
|
1679
1763
|
let routeTransitionStartedAt = 0;
|
|
1680
1764
|
let routeTransitionVisible = false;
|
|
1681
1765
|
let routeTransitionIndicator = null;
|
|
1766
|
+
let lazyImageObserver = null;
|
|
1682
1767
|
const clientPluginIds = new Set();
|
|
1683
1768
|
const clientMiddlewareById = new Map();
|
|
1684
1769
|
const clientProvides = globalThis.__RESUX_PROVIDES__ ||= {};
|
|
1770
|
+
const RESUX_LAZY_PLACEHOLDER_SRC = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
1685
1771
|
|
|
1686
1772
|
const __rxFlags = {
|
|
1687
1773
|
isReactive: "__v_isReactive",
|
|
@@ -2205,50 +2291,55 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2205
2291
|
const providerName = String(options.provider || imageConfig.provider || "resux").trim().toLowerCase();
|
|
2206
2292
|
const providerConfig = imageConfig.providers[providerName] || {};
|
|
2207
2293
|
const baseURL = providerConfig.baseURL || (providerName === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
2208
|
-
const
|
|
2294
|
+
const modifiers = {
|
|
2295
|
+
...(providerConfig.modifiers || {}),
|
|
2296
|
+
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
2297
|
+
...(typeof imageConfig.format === "string" ? { format: imageConfig.format } : {}),
|
|
2298
|
+
...(options.modifiers || {}),
|
|
2299
|
+
...(Number.isFinite(options.width) ? { width: Math.round(options.width) } : {}),
|
|
2300
|
+
...(Number.isFinite(options.height) ? { height: Math.round(options.height) } : {}),
|
|
2301
|
+
...(Number.isFinite(options.quality) ? { quality: Math.round(options.quality) } : {}),
|
|
2302
|
+
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2303
|
+
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2304
|
+
};
|
|
2305
|
+
const normalizedFormat = normalizeClientImageOutputFormat(
|
|
2306
|
+
typeof modifiers.format === "string" ? modifiers.format : undefined
|
|
2307
|
+
);
|
|
2209
2308
|
|
|
2210
2309
|
if (baseURL.includes("{src}")) {
|
|
2211
2310
|
let resolved = baseURL.replaceAll("{src}", encodeURIComponent(normalizedSrc));
|
|
2212
|
-
const
|
|
2213
|
-
...(providerConfig.modifiers || {}),
|
|
2214
|
-
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
2215
|
-
...(typeof imageConfig.format === "string" ? { format: imageConfig.format } : {}),
|
|
2216
|
-
...(options.modifiers || {}),
|
|
2217
|
-
...(Number.isFinite(options.width) ? { width: Math.round(options.width) } : {}),
|
|
2218
|
-
...(Number.isFinite(options.height) ? { height: Math.round(options.height) } : {}),
|
|
2219
|
-
...(Number.isFinite(options.quality) ? { quality: Math.round(options.quality) } : {}),
|
|
2220
|
-
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2221
|
-
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2222
|
-
};
|
|
2223
|
-
for (const [key, value] of Object.entries(templateModifiers)) {
|
|
2311
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
2224
2312
|
resolved = resolved.replaceAll("{" + key + "}", encodeURIComponent(String(value)));
|
|
2225
2313
|
}
|
|
2226
2314
|
return resolved;
|
|
2227
2315
|
}
|
|
2228
2316
|
|
|
2317
|
+
const query = new URLSearchParams();
|
|
2318
|
+
const sourceDescriptor = providerName === "vercel"
|
|
2319
|
+
? { publicSource: normalizedSrc }
|
|
2320
|
+
: rewriteClientImageSourceForDisplayFormat(normalizedSrc, normalizedFormat);
|
|
2321
|
+
|
|
2229
2322
|
if (providerName === "vercel") {
|
|
2230
2323
|
query.set("url", normalizedSrc);
|
|
2231
2324
|
} else {
|
|
2232
|
-
query.set("src",
|
|
2325
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
2326
|
+
if (sourceDescriptor.originalSource) {
|
|
2327
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
2328
|
+
}
|
|
2233
2329
|
}
|
|
2234
2330
|
|
|
2235
|
-
const
|
|
2236
|
-
|
|
2237
|
-
|
|
2238
|
-
|
|
2239
|
-
|
|
2240
|
-
|
|
2241
|
-
...(Number.isFinite(options.height) ? { height: Math.round(options.height) } : {}),
|
|
2242
|
-
...(Number.isFinite(options.quality) ? { quality: Math.round(options.quality) } : {}),
|
|
2243
|
-
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2244
|
-
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2245
|
-
};
|
|
2246
|
-
|
|
2247
|
-
if (Number.isFinite(modifiers.width) && modifiers.width > 0) query.set("w", String(modifiers.width));
|
|
2248
|
-
if (Number.isFinite(modifiers.height) && modifiers.height > 0) query.set("h", String(modifiers.height));
|
|
2249
|
-
if (Number.isFinite(modifiers.quality) && modifiers.quality > 0) query.set("q", String(modifiers.quality));
|
|
2331
|
+
const width = Number(modifiers.width);
|
|
2332
|
+
const height = Number(modifiers.height);
|
|
2333
|
+
const quality = Number(modifiers.quality);
|
|
2334
|
+
if (Number.isFinite(width) && width > 0) query.set("w", String(Math.round(width)));
|
|
2335
|
+
if (Number.isFinite(height) && height > 0) query.set("h", String(Math.round(height)));
|
|
2336
|
+
if (Number.isFinite(quality) && quality > 0) query.set("q", String(Math.round(quality)));
|
|
2250
2337
|
if (typeof modifiers.fit === "string" && modifiers.fit) query.set("fit", modifiers.fit);
|
|
2251
|
-
if (
|
|
2338
|
+
if (normalizedFormat) {
|
|
2339
|
+
query.set("f", normalizedFormat);
|
|
2340
|
+
} else if (typeof modifiers.format === "string" && modifiers.format) {
|
|
2341
|
+
query.set("f", modifiers.format);
|
|
2342
|
+
}
|
|
2252
2343
|
|
|
2253
2344
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
2254
2345
|
if (["width", "height", "quality", "fit", "format"].includes(key)) continue;
|
|
@@ -2261,6 +2352,64 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2261
2352
|
};
|
|
2262
2353
|
}
|
|
2263
2354
|
|
|
2355
|
+
function normalizeClientImageOutputFormat(value) {
|
|
2356
|
+
if (typeof value !== "string") {
|
|
2357
|
+
return undefined;
|
|
2358
|
+
}
|
|
2359
|
+
const normalized = value.trim().toLowerCase();
|
|
2360
|
+
if (!normalized) {
|
|
2361
|
+
return undefined;
|
|
2362
|
+
}
|
|
2363
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
function rewriteClientImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
2367
|
+
if (!normalizedFormat) {
|
|
2368
|
+
return { publicSource: src };
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
2372
|
+
return { publicSource: src };
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
2376
|
+
try {
|
|
2377
|
+
const sourceUrl = new URL(src);
|
|
2378
|
+
const rewrittenPathname = rewriteClientImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
2379
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
2380
|
+
return { publicSource: src };
|
|
2381
|
+
}
|
|
2382
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
2383
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
2384
|
+
} catch {
|
|
2385
|
+
return { publicSource: src };
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
2390
|
+
const rewrittenPath = rewriteClientImagePathExtension(pathPart, normalizedFormat);
|
|
2391
|
+
if (rewrittenPath === pathPart) {
|
|
2392
|
+
return { publicSource: src };
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
return { publicSource: rewrittenPath + suffix, originalSource: src };
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
function rewriteClientImagePathExtension(pathname, extension) {
|
|
2399
|
+
if (!pathname) {
|
|
2400
|
+
return pathname;
|
|
2401
|
+
}
|
|
2402
|
+
const normalizedExtension = extension.startsWith(".")
|
|
2403
|
+
? extension.slice(1)
|
|
2404
|
+
: extension;
|
|
2405
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
2406
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
2407
|
+
if (lastDot > lastSlash) {
|
|
2408
|
+
return pathname.slice(0, lastDot + 1) + normalizedExtension;
|
|
2409
|
+
}
|
|
2410
|
+
return pathname + "." + normalizedExtension;
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2264
2413
|
function normalizeClientImageSource(src, route) {
|
|
2265
2414
|
const value = String(src || "").trim();
|
|
2266
2415
|
if (!value) return "";
|
|
@@ -2592,8 +2741,90 @@ async function initializeClientRuntime() {
|
|
|
2592
2741
|
}
|
|
2593
2742
|
void resumePendingAsyncData();
|
|
2594
2743
|
void mountVueIslands();
|
|
2744
|
+
activateDeferredLazyImages();
|
|
2595
2745
|
}
|
|
2596
|
-
|
|
2746
|
+
|
|
2747
|
+
function activateDeferredLazyImages(root = document) {
|
|
2748
|
+
const images = root.querySelectorAll ? root.querySelectorAll("img[data-rx-lazy-image='true']") : [];
|
|
2749
|
+
if (!images.length) {
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
const observer = getLazyImageObserver();
|
|
2754
|
+
for (const image of images) {
|
|
2755
|
+
if (image.getAttribute("data-rx-lazy-ready") === "true") {
|
|
2756
|
+
continue;
|
|
2757
|
+
}
|
|
2758
|
+
if (!observer) {
|
|
2759
|
+
revealDeferredLazyImage(image);
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
observer.observe(image);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
function getLazyImageObserver() {
|
|
2767
|
+
if (lazyImageObserver) {
|
|
2768
|
+
return lazyImageObserver;
|
|
2769
|
+
}
|
|
2770
|
+
if (typeof IntersectionObserver !== "function") {
|
|
2771
|
+
return null;
|
|
2772
|
+
}
|
|
2773
|
+
lazyImageObserver = new IntersectionObserver((entries) => {
|
|
2774
|
+
for (const entry of entries) {
|
|
2775
|
+
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
2776
|
+
continue;
|
|
2777
|
+
}
|
|
2778
|
+
const target = entry.target;
|
|
2779
|
+
lazyImageObserver?.unobserve(target);
|
|
2780
|
+
revealDeferredLazyImage(target);
|
|
2781
|
+
}
|
|
2782
|
+
}, { rootMargin: "320px 0px" });
|
|
2783
|
+
return lazyImageObserver;
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
function revealDeferredLazyImage(image) {
|
|
2787
|
+
if (!image || image.getAttribute("data-rx-lazy-ready") === "true") {
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
const picture = image.closest ? image.closest("picture") : null;
|
|
2792
|
+
if (picture && picture.querySelectorAll) {
|
|
2793
|
+
picture.querySelectorAll("source[data-rx-lazy-srcset]").forEach((source) => {
|
|
2794
|
+
const nextSrcset = source.getAttribute("data-rx-lazy-srcset");
|
|
2795
|
+
if (nextSrcset) {
|
|
2796
|
+
source.setAttribute("srcset", nextSrcset);
|
|
2797
|
+
}
|
|
2798
|
+
source.removeAttribute("data-rx-lazy-srcset");
|
|
2799
|
+
const nextSizes = source.getAttribute("data-rx-lazy-sizes");
|
|
2800
|
+
if (nextSizes) {
|
|
2801
|
+
source.setAttribute("sizes", nextSizes);
|
|
2802
|
+
}
|
|
2803
|
+
source.removeAttribute("data-rx-lazy-sizes");
|
|
2804
|
+
});
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
const srcset = image.getAttribute("data-rx-lazy-srcset");
|
|
2808
|
+
if (srcset) {
|
|
2809
|
+
image.setAttribute("srcset", srcset);
|
|
2810
|
+
}
|
|
2811
|
+
image.removeAttribute("data-rx-lazy-srcset");
|
|
2812
|
+
const sizes = image.getAttribute("data-rx-lazy-sizes");
|
|
2813
|
+
if (sizes) {
|
|
2814
|
+
image.setAttribute("sizes", sizes);
|
|
2815
|
+
}
|
|
2816
|
+
image.removeAttribute("data-rx-lazy-sizes");
|
|
2817
|
+
|
|
2818
|
+
const src = image.getAttribute("data-rx-lazy-src");
|
|
2819
|
+
if (src) {
|
|
2820
|
+
image.setAttribute("src", src);
|
|
2821
|
+
} else if (image.getAttribute("src") === RESUX_LAZY_PLACEHOLDER_SRC) {
|
|
2822
|
+
image.removeAttribute("src");
|
|
2823
|
+
}
|
|
2824
|
+
image.removeAttribute("data-rx-lazy-src");
|
|
2825
|
+
image.setAttribute("data-rx-lazy-ready", "true");
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2597
2828
|
function createAsyncDataResource(value, pending = false, error = null) {
|
|
2598
2829
|
const data = ref(value);
|
|
2599
2830
|
let completion = Promise.resolve();
|
|
@@ -3006,6 +3237,7 @@ async function navigateTo(target, options = {}) {
|
|
|
3006
3237
|
clearScopeCacheExcept(preserved.scopeIds);
|
|
3007
3238
|
void resumePendingAsyncData();
|
|
3008
3239
|
void mountVueIslands(preserved.root);
|
|
3240
|
+
activateDeferredLazyImages(preserved.root);
|
|
3009
3241
|
|
|
3010
3242
|
if (nextUrl.hash) {
|
|
3011
3243
|
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
@@ -3683,12 +3915,17 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3683
3915
|
if (!resolvedSrcset) {
|
|
3684
3916
|
return "";
|
|
3685
3917
|
}
|
|
3686
|
-
const sourceAttrs = [
|
|
3687
|
-
|
|
3688
|
-
'srcset="' + escapeAttribute(resolvedSrcset) + '"'
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3918
|
+
const sourceAttrs = ['type="' + escapeAttribute(clientImageMimeType(format)) + '"'];
|
|
3919
|
+
if (input.deferLazy) {
|
|
3920
|
+
sourceAttrs.push('data-rx-lazy-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3921
|
+
if (input.sizes) {
|
|
3922
|
+
sourceAttrs.push('data-rx-lazy-sizes="' + escapeAttribute(input.sizes) + '"');
|
|
3923
|
+
}
|
|
3924
|
+
} else {
|
|
3925
|
+
sourceAttrs.push('srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3926
|
+
if (input.sizes) {
|
|
3927
|
+
sourceAttrs.push('sizes="' + escapeAttribute(input.sizes) + '"');
|
|
3928
|
+
}
|
|
3692
3929
|
}
|
|
3693
3930
|
return "<source " + sourceAttrs.join(" ") + ">";
|
|
3694
3931
|
})
|
|
@@ -3718,7 +3955,13 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3718
3955
|
);
|
|
3719
3956
|
const priority = readClientBooleanProp(props.priority, false);
|
|
3720
3957
|
const preload = readClientBooleanProp(props.preload, priority);
|
|
3721
|
-
const
|
|
3958
|
+
const explicitLoading = readClientStringProp(props.loading);
|
|
3959
|
+
const explicitLazy = props.lazy === undefined
|
|
3960
|
+
? undefined
|
|
3961
|
+
: readClientBooleanProp(props.lazy, true);
|
|
3962
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
3963
|
+
const loading = explicitLoading || (lazy ? "lazy" : "eager");
|
|
3964
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
3722
3965
|
const quality = readClientNumberProp(props.quality) || imageConfig.quality;
|
|
3723
3966
|
const densities = parseClientImageNumberList(props.densities)
|
|
3724
3967
|
|| imageConfig.densities
|
|
@@ -3731,7 +3974,7 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3731
3974
|
sizes: readClientStringProp(props.sizes),
|
|
3732
3975
|
widths: parseClientImageNumberList(props.widths) || [],
|
|
3733
3976
|
densities,
|
|
3734
|
-
loading
|
|
3977
|
+
loading,
|
|
3735
3978
|
decoding: readClientStringProp(props.decoding) || "async",
|
|
3736
3979
|
fetchPriority: readClientStringProp(props.fetchpriority || props.fetchPriority) || (priority ? "high" : undefined),
|
|
3737
3980
|
provider: readClientStringProp(props.provider),
|
|
@@ -3741,7 +3984,8 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3741
3984
|
formats: explicitFormats,
|
|
3742
3985
|
modifiers: normalizeClientImageModifiers(props.modifiers),
|
|
3743
3986
|
attrs: collectClientImageAttrs(props),
|
|
3744
|
-
preload
|
|
3987
|
+
preload,
|
|
3988
|
+
deferLazy
|
|
3745
3989
|
};
|
|
3746
3990
|
}
|
|
3747
3991
|
|
|
@@ -3827,17 +4071,22 @@ function buildClientImageSrcset(builder, input) {
|
|
|
3827
4071
|
|
|
3828
4072
|
function renderClientResuxImgTag(input, src, srcset, styleScopeId) {
|
|
3829
4073
|
const attrs = [];
|
|
4074
|
+
const isDeferredLazy = input.deferLazy && String(input.loading || "").toLowerCase() === "lazy";
|
|
3830
4075
|
const mergedAttrs = {
|
|
3831
4076
|
...input.attrs,
|
|
3832
|
-
src,
|
|
4077
|
+
src: isDeferredLazy ? RESUX_LAZY_PLACEHOLDER_SRC : src,
|
|
3833
4078
|
alt: input.alt,
|
|
3834
4079
|
loading: input.loading,
|
|
3835
4080
|
decoding: input.decoding,
|
|
4081
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
4082
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src } : {}),
|
|
4083
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset } : {}),
|
|
4084
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
3836
4085
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
3837
4086
|
...(input.width ? { width: String(input.width) } : {}),
|
|
3838
4087
|
...(input.height ? { height: String(input.height) } : {}),
|
|
3839
|
-
...(srcset ? { srcset } : {}),
|
|
3840
|
-
...(input.sizes ? { sizes: input.sizes } : {})
|
|
4088
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
4089
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {})
|
|
3841
4090
|
};
|
|
3842
4091
|
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
3843
4092
|
if (value === undefined || value === null) {
|
|
@@ -3945,12 +4194,13 @@ function nativeAttributeName(node, name) {
|
|
|
3945
4194
|
return node.tag === "ResuxLink" && name === "to" ? "href" : name;
|
|
3946
4195
|
}
|
|
3947
4196
|
|
|
3948
|
-
function applyPatches(scopeId, patches) {
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
4197
|
+
function applyPatches(scopeId, patches) {
|
|
4198
|
+
let needsLazyImageActivation = false;
|
|
4199
|
+
for (const patch of patches) {
|
|
4200
|
+
if (patch.type === "text") {
|
|
4201
|
+
document.querySelectorAll('[data-rx-text="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4202
|
+
element.textContent = patch.value;
|
|
4203
|
+
});
|
|
3954
4204
|
continue;
|
|
3955
4205
|
}
|
|
3956
4206
|
if (patch.type === "attr") {
|
|
@@ -3972,21 +4222,26 @@ function applyPatches(scopeId, patches) {
|
|
|
3972
4222
|
});
|
|
3973
4223
|
continue;
|
|
3974
4224
|
}
|
|
3975
|
-
if (patch.type === "html") {
|
|
3976
|
-
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
3977
|
-
unmountVueIslands(element);
|
|
3978
|
-
element.innerHTML = patch.value;
|
|
3979
|
-
void mountVueIslands(element);
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
element
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
}
|
|
4225
|
+
if (patch.type === "html") {
|
|
4226
|
+
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4227
|
+
unmountVueIslands(element);
|
|
4228
|
+
element.innerHTML = patch.value;
|
|
4229
|
+
void mountVueIslands(element);
|
|
4230
|
+
needsLazyImageActivation = true;
|
|
4231
|
+
});
|
|
4232
|
+
continue;
|
|
4233
|
+
}
|
|
4234
|
+
document.querySelectorAll('[data-rx-block="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4235
|
+
unmountVueIslands(element);
|
|
4236
|
+
element.innerHTML = patch.value;
|
|
4237
|
+
void mountVueIslands(element);
|
|
4238
|
+
needsLazyImageActivation = true;
|
|
4239
|
+
});
|
|
4240
|
+
}
|
|
4241
|
+
if (needsLazyImageActivation) {
|
|
4242
|
+
activateDeferredLazyImages();
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
3990
4245
|
|
|
3991
4246
|
function evaluateExpression(expression, scope, locals) {
|
|
3992
4247
|
return Function("scope", "locals", "with (scope) { with (locals) { return (" + expression + "); } }")(scope, locals);
|