resuxjs 0.2.35 → 0.2.36
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 +574 -17
- package/dist/cli.js.map +1 -1
- package/dist/deploy/vercel.js +99 -0
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/runtime/index.d.ts +9 -2
- package/dist/runtime/index.js +2243 -146
- package/dist/runtime/index.js.map +1 -1
- package/package.json +1 -1
- package/templates/default/public/resux-placeholder.svg +27 -0
package/dist/runtime/index.js
CHANGED
|
@@ -236,7 +236,7 @@ class ResuxRenderer {
|
|
|
236
236
|
components: this.components,
|
|
237
237
|
layouts: {},
|
|
238
238
|
pageMeta: definition.meta ?? {},
|
|
239
|
-
addHeadEntry: (entry) => this.headEntries
|
|
239
|
+
addHeadEntry: (entry) => insertHeadEntryWithPriority(this.headEntries, entry),
|
|
240
240
|
renderPage,
|
|
241
241
|
renderSlot
|
|
242
242
|
});
|
|
@@ -428,6 +428,8 @@ function createResuxImageBuilder(route, runtimeConfig, client) {
|
|
|
428
428
|
const imageConfig = resolveRuntimeImageConfig(runtimeConfig);
|
|
429
429
|
const providerName = (options.provider ?? imageConfig.provider ?? "resux").trim();
|
|
430
430
|
const providerConfig = resolveImageProviderConfig(providerName, imageConfig);
|
|
431
|
+
const cache = normalizeImageCacheValue(options.cache)
|
|
432
|
+
?? normalizeImageCacheValue(imageConfig.cache);
|
|
431
433
|
const modifiers = normalizeImageModifiers({
|
|
432
434
|
...(providerConfig.modifiers ?? {}),
|
|
433
435
|
...(typeof imageConfig.quality === "number" ? { quality: imageConfig.quality } : {}),
|
|
@@ -439,7 +441,7 @@ function createResuxImageBuilder(route, runtimeConfig, client) {
|
|
|
439
441
|
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
440
442
|
...(typeof options.format === "string" ? { format: options.format } : {}),
|
|
441
443
|
});
|
|
442
|
-
return buildResuxImageURL(providerName, providerConfig.baseURL, normalizedSrc, modifiers, client);
|
|
444
|
+
return buildResuxImageURL(providerName, providerConfig.baseURL, normalizedSrc, modifiers, client, cache);
|
|
443
445
|
};
|
|
444
446
|
}
|
|
445
447
|
function normalizeImageSource(src, route) {
|
|
@@ -475,12 +477,54 @@ function resolveRuntimeImageConfig(runtimeConfig) {
|
|
|
475
477
|
const densities = resolveImageDensities(input.densities);
|
|
476
478
|
return {
|
|
477
479
|
provider: typeof input.provider === "string" ? input.provider : undefined,
|
|
478
|
-
quality: typeof input.quality === "number" ? input.quality : undefined,
|
|
480
|
+
quality: typeof input.quality === "number" ? normalizeImageQualityValue(input.quality) : undefined,
|
|
479
481
|
format: typeof input.format === "string" ? input.format : undefined,
|
|
482
|
+
cache: normalizeImageCacheValue(input.cache),
|
|
480
483
|
...(densities.length ? { densities } : {}),
|
|
481
484
|
...(Object.keys(providers).length ? { providers } : {}),
|
|
482
485
|
};
|
|
483
486
|
}
|
|
487
|
+
function normalizeImageQualityValue(value, fallback = 86) {
|
|
488
|
+
const parsed = typeof value === "number" ? value : Number(value);
|
|
489
|
+
if (!Number.isFinite(parsed)) {
|
|
490
|
+
return fallback;
|
|
491
|
+
}
|
|
492
|
+
return Math.min(100, Math.max(1, Math.round(parsed)));
|
|
493
|
+
}
|
|
494
|
+
function normalizeImageCacheValue(value) {
|
|
495
|
+
if (value === undefined || value === null || value === false) {
|
|
496
|
+
return undefined;
|
|
497
|
+
}
|
|
498
|
+
if (value === true) {
|
|
499
|
+
return "1d";
|
|
500
|
+
}
|
|
501
|
+
if (typeof value === "number") {
|
|
502
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
503
|
+
return undefined;
|
|
504
|
+
}
|
|
505
|
+
return String(Math.round(value));
|
|
506
|
+
}
|
|
507
|
+
if (typeof value === "string") {
|
|
508
|
+
const normalized = value.trim().toLowerCase();
|
|
509
|
+
if (!normalized || normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
510
|
+
return "1d";
|
|
511
|
+
}
|
|
512
|
+
if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
|
|
513
|
+
return undefined;
|
|
514
|
+
}
|
|
515
|
+
return normalized;
|
|
516
|
+
}
|
|
517
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
518
|
+
const record = value;
|
|
519
|
+
for (const key of ["maxAge", "expiresIn", "ttl"]) {
|
|
520
|
+
const normalized = normalizeImageCacheValue(record[key]);
|
|
521
|
+
if (normalized) {
|
|
522
|
+
return normalized;
|
|
523
|
+
}
|
|
524
|
+
}
|
|
525
|
+
}
|
|
526
|
+
return undefined;
|
|
527
|
+
}
|
|
484
528
|
function resolveImageProviders(value) {
|
|
485
529
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
486
530
|
return {};
|
|
@@ -515,7 +559,16 @@ function resolveImageProviderConfig(providerName, imageConfig) {
|
|
|
515
559
|
function normalizeImageModifiers(modifiers) {
|
|
516
560
|
const normalized = {};
|
|
517
561
|
for (const [key, value] of Object.entries(modifiers ?? {})) {
|
|
518
|
-
if (value ===
|
|
562
|
+
if (value === false) {
|
|
563
|
+
if (key === "format" || key === "quality") {
|
|
564
|
+
normalized[key] = false;
|
|
565
|
+
}
|
|
566
|
+
continue;
|
|
567
|
+
}
|
|
568
|
+
if (value === undefined || value === null) {
|
|
569
|
+
continue;
|
|
570
|
+
}
|
|
571
|
+
if (key === "cache") {
|
|
519
572
|
continue;
|
|
520
573
|
}
|
|
521
574
|
if (key === "width" || key === "height" || key === "quality") {
|
|
@@ -529,7 +582,7 @@ function normalizeImageModifiers(modifiers) {
|
|
|
529
582
|
}
|
|
530
583
|
return normalized;
|
|
531
584
|
}
|
|
532
|
-
function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, client) {
|
|
585
|
+
function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, client, cacheOption) {
|
|
533
586
|
const trimmedProvider = providerName.trim().toLowerCase();
|
|
534
587
|
const baseURL = providerBaseURL?.trim()
|
|
535
588
|
|| (trimmedProvider === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
@@ -540,6 +593,7 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
540
593
|
const sourceDescriptor = trimmedProvider === "vercel"
|
|
541
594
|
? { publicSource: src }
|
|
542
595
|
: rewriteImageSourceForDisplayFormat(src, normalizedFormat);
|
|
596
|
+
const useGeneratedCache = trimmedProvider === "resux" && typeof cacheOption === "string" && cacheOption.length > 0;
|
|
543
597
|
const query = new URLSearchParams();
|
|
544
598
|
if (trimmedProvider === "vercel") {
|
|
545
599
|
query.set("url", src);
|
|
@@ -577,6 +631,12 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
577
631
|
}
|
|
578
632
|
query.set(key, String(value));
|
|
579
633
|
}
|
|
634
|
+
if (useGeneratedCache) {
|
|
635
|
+
query.set("cache", cacheOption);
|
|
636
|
+
const generatedPath = createGeneratedImageRoutePath(sourceDescriptor.publicSource, sourceDescriptor.originalSource, normalizedFormat, modifiers);
|
|
637
|
+
const queryString = query.toString();
|
|
638
|
+
return queryString.length > 0 ? `${generatedPath}?${queryString}` : generatedPath;
|
|
639
|
+
}
|
|
580
640
|
const separator = baseURL.includes("?") ? "&" : "?";
|
|
581
641
|
const queryString = query.toString();
|
|
582
642
|
if (!queryString) {
|
|
@@ -588,6 +648,85 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
588
648
|
}
|
|
589
649
|
return resolved;
|
|
590
650
|
}
|
|
651
|
+
function createGeneratedImageRoutePath(source, originalSource, normalizedFormat, modifiers) {
|
|
652
|
+
const extension = normalizedFormat
|
|
653
|
+
?? inferImageExtensionFromSource(source)
|
|
654
|
+
?? inferImageExtensionFromSource(originalSource)
|
|
655
|
+
?? "bin";
|
|
656
|
+
const signature = createImageTransformSignature(source, originalSource, normalizedFormat, modifiers);
|
|
657
|
+
const digest = hashImageSignature(signature);
|
|
658
|
+
return `/_resux/generated/images/${digest}.${extension}`;
|
|
659
|
+
}
|
|
660
|
+
function createImageTransformSignature(source, originalSource, normalizedFormat, modifiers) {
|
|
661
|
+
const entries = [`src=${source}`];
|
|
662
|
+
if (originalSource) {
|
|
663
|
+
entries.push(`original=${originalSource}`);
|
|
664
|
+
}
|
|
665
|
+
const width = Number(modifiers.width);
|
|
666
|
+
if (Number.isFinite(width) && width > 0) {
|
|
667
|
+
entries.push(`w=${Math.round(width)}`);
|
|
668
|
+
}
|
|
669
|
+
const height = Number(modifiers.height);
|
|
670
|
+
if (Number.isFinite(height) && height > 0) {
|
|
671
|
+
entries.push(`h=${Math.round(height)}`);
|
|
672
|
+
}
|
|
673
|
+
if (typeof modifiers.fit === "string" && modifiers.fit.length > 0) {
|
|
674
|
+
entries.push(`fit=${modifiers.fit}`);
|
|
675
|
+
}
|
|
676
|
+
if (normalizedFormat) {
|
|
677
|
+
entries.push(`f=${normalizedFormat}`);
|
|
678
|
+
}
|
|
679
|
+
const quality = Number(modifiers.quality);
|
|
680
|
+
if (Number.isFinite(quality) && quality > 0) {
|
|
681
|
+
entries.push(`q=${Math.round(quality)}`);
|
|
682
|
+
}
|
|
683
|
+
const extraKeys = Object.keys(modifiers)
|
|
684
|
+
.filter((key) => !["width", "height", "quality", "fit", "format", "cache"].includes(key))
|
|
685
|
+
.sort();
|
|
686
|
+
for (const key of extraKeys) {
|
|
687
|
+
const value = modifiers[key];
|
|
688
|
+
if (value === undefined || value === null || value === false) {
|
|
689
|
+
continue;
|
|
690
|
+
}
|
|
691
|
+
entries.push(`${key}=${String(value)}`);
|
|
692
|
+
}
|
|
693
|
+
return entries.join("&");
|
|
694
|
+
}
|
|
695
|
+
function hashImageSignature(value) {
|
|
696
|
+
let hash = 2166136261;
|
|
697
|
+
for (let index = 0; index < value.length; index++) {
|
|
698
|
+
hash ^= value.charCodeAt(index);
|
|
699
|
+
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
700
|
+
}
|
|
701
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
702
|
+
}
|
|
703
|
+
function inferImageExtensionFromSource(value) {
|
|
704
|
+
if (!value) {
|
|
705
|
+
return undefined;
|
|
706
|
+
}
|
|
707
|
+
const trimmed = value.trim();
|
|
708
|
+
if (!trimmed) {
|
|
709
|
+
return undefined;
|
|
710
|
+
}
|
|
711
|
+
if (trimmed.startsWith("data:")) {
|
|
712
|
+
const mimeMatch = /^data:image\/([a-zA-Z0-9.+-]+);/i.exec(trimmed);
|
|
713
|
+
if (!mimeMatch) {
|
|
714
|
+
return undefined;
|
|
715
|
+
}
|
|
716
|
+
const normalized = mimeMatch[1].toLowerCase();
|
|
717
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
718
|
+
}
|
|
719
|
+
const withoutQuery = trimmed.split(/[?#]/)[0];
|
|
720
|
+
const dotIndex = withoutQuery.lastIndexOf(".");
|
|
721
|
+
if (dotIndex < 0) {
|
|
722
|
+
return undefined;
|
|
723
|
+
}
|
|
724
|
+
const extension = withoutQuery.slice(dotIndex + 1).toLowerCase();
|
|
725
|
+
if (!extension) {
|
|
726
|
+
return undefined;
|
|
727
|
+
}
|
|
728
|
+
return extension === "jpg" ? "jpeg" : extension;
|
|
729
|
+
}
|
|
591
730
|
function injectImageTemplateSource(template, src, modifiers) {
|
|
592
731
|
let resolved = template.replaceAll("{src}", encodeURIComponent(src));
|
|
593
732
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
@@ -716,6 +855,9 @@ function renderElement(node, context, locals) {
|
|
|
716
855
|
if (node.tag === "ResuxPicture") {
|
|
717
856
|
return renderResuxPicture(node, context, locals);
|
|
718
857
|
}
|
|
858
|
+
if (node.tag === "ResuxVideo") {
|
|
859
|
+
return renderResuxVideo(node, context, locals);
|
|
860
|
+
}
|
|
719
861
|
if (node.tag === "ResuxLoadingIndicator") {
|
|
720
862
|
return renderResuxLoadingIndicatorSync(node, context, locals, renderTemplateNodes(node.children, context, locals));
|
|
721
863
|
}
|
|
@@ -825,6 +967,9 @@ async function renderElementAsync(node, context, renderComponent, locals) {
|
|
|
825
967
|
if (node.tag === "ResuxPicture") {
|
|
826
968
|
return renderResuxPicture(node, context, locals);
|
|
827
969
|
}
|
|
970
|
+
if (node.tag === "ResuxVideo") {
|
|
971
|
+
return renderResuxVideo(node, context, locals);
|
|
972
|
+
}
|
|
828
973
|
if (node.tag === "ResuxLoadingIndicator") {
|
|
829
974
|
return renderResuxLoadingIndicatorAsync(node, context, locals, renderTemplateNodesAsync(node.children, context, renderComponent, locals));
|
|
830
975
|
}
|
|
@@ -878,6 +1023,7 @@ const resuxImageReservedProps = new Set([
|
|
|
878
1023
|
"src",
|
|
879
1024
|
"alt",
|
|
880
1025
|
"provider",
|
|
1026
|
+
"cache",
|
|
881
1027
|
"modifiers",
|
|
882
1028
|
"quality",
|
|
883
1029
|
"fit",
|
|
@@ -895,8 +1041,18 @@ const resuxImageReservedProps = new Set([
|
|
|
895
1041
|
"decoding",
|
|
896
1042
|
"fetchpriority",
|
|
897
1043
|
"fetchPriority",
|
|
1044
|
+
"placeholder",
|
|
1045
|
+
"placeholderClass",
|
|
1046
|
+
"placeholderStyle",
|
|
1047
|
+
"fallback",
|
|
1048
|
+
"fallbackSrc",
|
|
1049
|
+
"sources",
|
|
1050
|
+
"rootMargin",
|
|
1051
|
+
"threshold",
|
|
898
1052
|
]);
|
|
899
1053
|
const resuxLazyPlaceholderSrc = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
1054
|
+
const resuxDefaultPlaceholderSrc = "/__resux/resux-placeholder.svg";
|
|
1055
|
+
const resuxResponsiveViewportWidths = [320, 640, 768, 1024, 1280, 1536, 1920, 2560];
|
|
900
1056
|
function renderResuxImg(node, context, locals) {
|
|
901
1057
|
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
902
1058
|
if (!input.src) {
|
|
@@ -905,6 +1061,7 @@ function renderResuxImg(node, context, locals) {
|
|
|
905
1061
|
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
906
1062
|
const src = builder(input.src, {
|
|
907
1063
|
provider: input.provider,
|
|
1064
|
+
cache: input.cache,
|
|
908
1065
|
width: input.width,
|
|
909
1066
|
height: input.height,
|
|
910
1067
|
quality: input.quality,
|
|
@@ -916,14 +1073,169 @@ function renderResuxImg(node, context, locals) {
|
|
|
916
1073
|
registerResuxImagePreload(context, src, srcset, input, input.preload);
|
|
917
1074
|
return renderResuxImgTag(input, src, srcset, context.styleScopeId);
|
|
918
1075
|
}
|
|
1076
|
+
function renderResuxVideo(node, context, locals) {
|
|
1077
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
1078
|
+
const explicitLoading = readStringProp(props.loading);
|
|
1079
|
+
const explicitLazy = props.lazy === undefined
|
|
1080
|
+
? undefined
|
|
1081
|
+
: readBooleanProp(props.lazy, true);
|
|
1082
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : false);
|
|
1083
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true || lazy;
|
|
1084
|
+
const src = readStringProp(props.src);
|
|
1085
|
+
const poster = readStringProp(props.poster);
|
|
1086
|
+
const fallbackPoster = readStringProp(props.fallbackPoster);
|
|
1087
|
+
const width = readNumberProp(props.width);
|
|
1088
|
+
const height = readNumberProp(props.height);
|
|
1089
|
+
const placeholderSrc = resolveMediaPlaceholderSource(props.placeholder);
|
|
1090
|
+
const preload = readStringProp(props.preload) ?? "metadata";
|
|
1091
|
+
const ariaLabel = readStringProp(props.ariaLabel ?? props["aria-label"]);
|
|
1092
|
+
const rootMargin = readStringProp(props.rootMargin) ?? "320px 0px";
|
|
1093
|
+
const thresholdRaw = Number(props.threshold);
|
|
1094
|
+
const threshold = Number.isFinite(thresholdRaw)
|
|
1095
|
+
? Math.min(1, Math.max(0, thresholdRaw))
|
|
1096
|
+
: 0;
|
|
1097
|
+
const forceAutoplay = readBooleanProp(props.forceAutoplay, false);
|
|
1098
|
+
const autoplay = readBooleanProp(props.autoplay, false);
|
|
1099
|
+
const resolvedSources = resolveVideoSources(props.sources);
|
|
1100
|
+
const hasSourceChildren = resolvedSources.length > 0;
|
|
1101
|
+
const styleParts = [];
|
|
1102
|
+
if (typeof props.style === "string" && props.style.trim().length > 0) {
|
|
1103
|
+
styleParts.push(props.style.trim().replace(/;+\s*$/, ""));
|
|
1104
|
+
}
|
|
1105
|
+
const aspectRatio = props.aspectRatio;
|
|
1106
|
+
if (aspectRatio !== undefined && aspectRatio !== null && aspectRatio !== false) {
|
|
1107
|
+
const aspectValue = String(aspectRatio).trim();
|
|
1108
|
+
if (aspectValue.length > 0) {
|
|
1109
|
+
styleParts.push(`aspect-ratio: ${aspectValue}`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
const ratioStyle = resolveAspectRatioStyle(width, height, props.style);
|
|
1114
|
+
if (ratioStyle) {
|
|
1115
|
+
styleParts.push(ratioStyle);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
styleParts.push("display: block");
|
|
1119
|
+
styleParts.push("width: 100%");
|
|
1120
|
+
styleParts.push("max-width: 100%");
|
|
1121
|
+
if (!styleParts.some((entry) => /(^|;)\s*height\s*:/.test(entry))) {
|
|
1122
|
+
styleParts.push("height: auto");
|
|
1123
|
+
}
|
|
1124
|
+
const attrs = [];
|
|
1125
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
1126
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
if (name === "aspectRatio"
|
|
1130
|
+
|| name === "style"
|
|
1131
|
+
|| name === "lazy"
|
|
1132
|
+
|| name === "loading"
|
|
1133
|
+
|| name === "placeholder"
|
|
1134
|
+
|| name === "fallbackPoster"
|
|
1135
|
+
|| name === "rootMargin"
|
|
1136
|
+
|| name === "threshold"
|
|
1137
|
+
|| name === "sources"
|
|
1138
|
+
|| name === "forceAutoplay"
|
|
1139
|
+
|| name === "ariaLabel"
|
|
1140
|
+
|| name === "autoplay"
|
|
1141
|
+
|| name === "src"
|
|
1142
|
+
|| name === "poster"
|
|
1143
|
+
|| name === "preload"
|
|
1144
|
+
|| name === "fallbackText") {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const attrName = name === "className"
|
|
1148
|
+
? "class"
|
|
1149
|
+
: name === "playsInline"
|
|
1150
|
+
? "playsinline"
|
|
1151
|
+
: name === "crossOrigin"
|
|
1152
|
+
? "crossorigin"
|
|
1153
|
+
: name === "referrerPolicy"
|
|
1154
|
+
? "referrerpolicy"
|
|
1155
|
+
: name;
|
|
1156
|
+
attrs.push(`${attrName}="${escapeAttribute(stringifyAttributeValue(attrName, rawValue))}"`);
|
|
1157
|
+
}
|
|
1158
|
+
if (!hasSourceChildren && !deferLazy && src) {
|
|
1159
|
+
attrs.push(`src="${escapeAttribute(src)}"`);
|
|
1160
|
+
}
|
|
1161
|
+
attrs.push('data-resux-media="video"');
|
|
1162
|
+
if (deferLazy && src) {
|
|
1163
|
+
attrs.push(`data-rx-lazy-src="${escapeAttribute(src)}"`);
|
|
1164
|
+
attrs.push(`data-src="${escapeAttribute(src)}"`);
|
|
1165
|
+
}
|
|
1166
|
+
if (deferLazy) {
|
|
1167
|
+
attrs.push('data-rx-lazy-video="true"');
|
|
1168
|
+
attrs.push('data-resux-lazy="true"');
|
|
1169
|
+
attrs.push(`data-rx-lazy-root-margin="${escapeAttribute(rootMargin)}"`);
|
|
1170
|
+
attrs.push(`data-rx-lazy-threshold="${escapeAttribute(String(threshold))}"`);
|
|
1171
|
+
attrs.push(`data-rx-lazy-preload="${escapeAttribute(preload)}"`);
|
|
1172
|
+
attrs.push('preload="none"');
|
|
1173
|
+
}
|
|
1174
|
+
else if (preload) {
|
|
1175
|
+
attrs.push(`preload="${escapeAttribute(preload)}"`);
|
|
1176
|
+
}
|
|
1177
|
+
if (poster) {
|
|
1178
|
+
attrs.push(`data-rx-poster="${escapeAttribute(poster)}"`);
|
|
1179
|
+
}
|
|
1180
|
+
if (fallbackPoster) {
|
|
1181
|
+
attrs.push(`data-rx-fallback-poster="${escapeAttribute(fallbackPoster)}"`);
|
|
1182
|
+
}
|
|
1183
|
+
if (placeholderSrc) {
|
|
1184
|
+
attrs.push(`data-rx-placeholder-src="${escapeAttribute(placeholderSrc)}"`);
|
|
1185
|
+
attrs.push(`data-placeholder="${escapeAttribute(placeholderSrc)}"`);
|
|
1186
|
+
attrs.push('data-rx-placeholder-active="true"');
|
|
1187
|
+
attrs.push('data-resux-placeholder-active="true"');
|
|
1188
|
+
}
|
|
1189
|
+
const initialPoster = placeholderSrc ?? poster;
|
|
1190
|
+
if (initialPoster) {
|
|
1191
|
+
attrs.push(`poster="${escapeAttribute(initialPoster)}"`);
|
|
1192
|
+
}
|
|
1193
|
+
if (autoplay) {
|
|
1194
|
+
attrs.push('autoplay="autoplay"');
|
|
1195
|
+
attrs.push('data-rx-autoplay-requested="true"');
|
|
1196
|
+
if (!forceAutoplay) {
|
|
1197
|
+
attrs.push('data-rx-respect-reduced-motion="true"');
|
|
1198
|
+
}
|
|
1199
|
+
else {
|
|
1200
|
+
attrs.push('data-rx-force-autoplay="true"');
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (ariaLabel) {
|
|
1204
|
+
attrs.push(`aria-label="${escapeAttribute(ariaLabel)}"`);
|
|
1205
|
+
}
|
|
1206
|
+
if (styleParts.length > 0) {
|
|
1207
|
+
attrs.push(`style="${escapeAttribute(styleParts.join("; "))}"`);
|
|
1208
|
+
}
|
|
1209
|
+
appendStyleScopeAttribute(attrs, context.styleScopeId);
|
|
1210
|
+
const attrText = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
1211
|
+
const sourceTags = hasSourceChildren
|
|
1212
|
+
? resolvedSources
|
|
1213
|
+
.map((source) => {
|
|
1214
|
+
const sourceAttrs = deferLazy
|
|
1215
|
+
? [`data-rx-lazy-src="${escapeAttribute(source.src)}"`, `data-src="${escapeAttribute(source.src)}"`]
|
|
1216
|
+
: [`src="${escapeAttribute(source.src)}"`];
|
|
1217
|
+
if (source.type) {
|
|
1218
|
+
sourceAttrs.push(`type="${escapeAttribute(source.type)}"`);
|
|
1219
|
+
}
|
|
1220
|
+
return `<source ${sourceAttrs.join(" ")}>`;
|
|
1221
|
+
})
|
|
1222
|
+
.join("")
|
|
1223
|
+
: "";
|
|
1224
|
+
const children = renderTemplateNodes(node.children, context, locals);
|
|
1225
|
+
const fallbackText = escapeHtml(readStringProp(props.fallbackText) ?? "Your browser does not support the video tag.");
|
|
1226
|
+
return `<video${attrText}>${sourceTags}${children}${fallbackText}</video>`;
|
|
1227
|
+
}
|
|
919
1228
|
function renderResuxPicture(node, context, locals) {
|
|
920
1229
|
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
921
1230
|
if (!input.src) {
|
|
922
1231
|
return "";
|
|
923
1232
|
}
|
|
1233
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
924
1234
|
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
925
|
-
const
|
|
1235
|
+
const fallbackSource = input.fallbackSrc ?? input.src;
|
|
1236
|
+
const fallbackSrc = builder(fallbackSource, {
|
|
926
1237
|
provider: input.provider,
|
|
1238
|
+
cache: input.cache,
|
|
927
1239
|
width: input.width,
|
|
928
1240
|
height: input.height,
|
|
929
1241
|
quality: input.quality,
|
|
@@ -932,40 +1244,82 @@ function renderResuxPicture(node, context, locals) {
|
|
|
932
1244
|
});
|
|
933
1245
|
const fallbackSrcset = buildResuxImageSrcset(builder, {
|
|
934
1246
|
...input,
|
|
1247
|
+
src: fallbackSource,
|
|
935
1248
|
format: undefined,
|
|
936
1249
|
});
|
|
937
1250
|
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input, input.preload);
|
|
938
1251
|
const manualChildren = renderTemplateNodes(node.children, context, locals);
|
|
939
|
-
const
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
1252
|
+
const explicitSources = resolvePictureSourceInputs(props.sources, input);
|
|
1253
|
+
const sourceInputs = explicitSources.length
|
|
1254
|
+
? explicitSources
|
|
1255
|
+
: input.formats.map((format) => ({
|
|
1256
|
+
src: input.src,
|
|
1257
|
+
widths: input.widths,
|
|
1258
|
+
width: input.width,
|
|
1259
|
+
height: input.height,
|
|
1260
|
+
quality: input.quality,
|
|
943
1261
|
format,
|
|
1262
|
+
fit: input.fit,
|
|
1263
|
+
sizes: input.sizes,
|
|
1264
|
+
modifiers: input.modifiers,
|
|
1265
|
+
type: resuxImageMimeType(format),
|
|
1266
|
+
}));
|
|
1267
|
+
const generatedSources = sourceInputs
|
|
1268
|
+
.map((sourceInput) => {
|
|
1269
|
+
const sourceRenderInput = {
|
|
1270
|
+
...input,
|
|
1271
|
+
src: sourceInput.src,
|
|
1272
|
+
width: sourceInput.width,
|
|
1273
|
+
height: sourceInput.height,
|
|
1274
|
+
widths: sourceInput.widths,
|
|
1275
|
+
sizes: sourceInput.sizes,
|
|
1276
|
+
quality: sourceInput.quality,
|
|
1277
|
+
format: sourceInput.format,
|
|
1278
|
+
fit: sourceInput.fit,
|
|
1279
|
+
modifiers: sourceInput.modifiers,
|
|
1280
|
+
placeholderSrc: undefined,
|
|
1281
|
+
placeholderClass: undefined,
|
|
1282
|
+
placeholderStyle: undefined,
|
|
1283
|
+
fallbackSrc: undefined,
|
|
1284
|
+
attrs: {},
|
|
1285
|
+
preload: false,
|
|
1286
|
+
deferLazy: input.deferLazy,
|
|
1287
|
+
};
|
|
1288
|
+
const sourceSrcset = sourceInput.srcset || buildResuxImageSrcset(builder, sourceRenderInput);
|
|
1289
|
+
const sourceUrl = builder(sourceInput.src, {
|
|
1290
|
+
provider: input.provider,
|
|
1291
|
+
cache: input.cache,
|
|
1292
|
+
width: sourceInput.width,
|
|
1293
|
+
height: sourceInput.height,
|
|
1294
|
+
quality: sourceInput.quality,
|
|
1295
|
+
fit: sourceInput.fit,
|
|
1296
|
+
format: sourceInput.format,
|
|
1297
|
+
modifiers: sourceInput.modifiers,
|
|
944
1298
|
});
|
|
945
|
-
const resolvedSrcset = sourceSrcset
|
|
946
|
-
|| builder(input.src, {
|
|
947
|
-
provider: input.provider,
|
|
948
|
-
width: input.width,
|
|
949
|
-
height: input.height,
|
|
950
|
-
quality: input.quality,
|
|
951
|
-
fit: input.fit,
|
|
952
|
-
format,
|
|
953
|
-
modifiers: input.modifiers,
|
|
954
|
-
});
|
|
1299
|
+
const resolvedSrcset = sourceSrcset || sourceUrl;
|
|
955
1300
|
if (!resolvedSrcset) {
|
|
956
1301
|
return "";
|
|
957
1302
|
}
|
|
958
|
-
const sourceAttrs = [
|
|
1303
|
+
const sourceAttrs = [];
|
|
1304
|
+
const sourceType = sourceInput.type
|
|
1305
|
+
|| (sourceInput.format ? resuxImageMimeType(sourceInput.format) : inferImageMimeTypeFromSource(sourceInput.src));
|
|
1306
|
+
if (sourceType) {
|
|
1307
|
+
sourceAttrs.push(`type="${escapeAttribute(sourceType)}"`);
|
|
1308
|
+
}
|
|
1309
|
+
if (sourceInput.media) {
|
|
1310
|
+
sourceAttrs.push(`media="${escapeAttribute(sourceInput.media)}"`);
|
|
1311
|
+
}
|
|
959
1312
|
if (input.deferLazy) {
|
|
960
1313
|
sourceAttrs.push(`data-rx-lazy-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
961
|
-
|
|
962
|
-
|
|
1314
|
+
sourceAttrs.push(`data-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
1315
|
+
if (sourceInput.sizes) {
|
|
1316
|
+
sourceAttrs.push(`data-rx-lazy-sizes="${escapeAttribute(sourceInput.sizes)}"`);
|
|
963
1317
|
}
|
|
964
1318
|
}
|
|
965
1319
|
else {
|
|
966
1320
|
sourceAttrs.push(`srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
967
|
-
if (
|
|
968
|
-
sourceAttrs.push(`sizes="${escapeAttribute(
|
|
1321
|
+
if (sourceInput.sizes) {
|
|
1322
|
+
sourceAttrs.push(`sizes="${escapeAttribute(sourceInput.sizes)}"`);
|
|
969
1323
|
}
|
|
970
1324
|
}
|
|
971
1325
|
return `<source ${sourceAttrs.join(" ")}>`;
|
|
@@ -973,7 +1327,7 @@ function renderResuxPicture(node, context, locals) {
|
|
|
973
1327
|
.filter(Boolean)
|
|
974
1328
|
.join("");
|
|
975
1329
|
const img = renderResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
976
|
-
const attrs = [];
|
|
1330
|
+
const attrs = ['data-resux-media="picture"'];
|
|
977
1331
|
appendStyleScopeAttribute(attrs, context.styleScopeId);
|
|
978
1332
|
const attrText = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
979
1333
|
return `<picture${attrText}>${manualChildren}${generatedSources}${img}</picture>`;
|
|
@@ -981,12 +1335,23 @@ function renderResuxPicture(node, context, locals) {
|
|
|
981
1335
|
function resolveResuxImageRenderInput(node, context, locals) {
|
|
982
1336
|
const props = collectComponentProps(node, context.scope, locals);
|
|
983
1337
|
const runtimeImageConfig = resolveRuntimeImageConfig(context.runtimeConfig);
|
|
984
|
-
const
|
|
1338
|
+
const baseModifiers = resolveResuxImageModifierProps(props.modifiers);
|
|
985
1339
|
const explicitFormat = readStringProp(props.format);
|
|
986
1340
|
const explicitFormats = parseImageFormats(props.formats
|
|
987
1341
|
?? (explicitFormat?.includes(",") ? explicitFormat : undefined));
|
|
1342
|
+
const hasExplicitQuality = Object.prototype.hasOwnProperty.call(props, "quality");
|
|
1343
|
+
const hasExplicitFormat = Object.prototype.hasOwnProperty.call(props, "format");
|
|
1344
|
+
const explicitQuality = readNumberProp(props.quality);
|
|
1345
|
+
const modifiers = normalizeImageModifiers({
|
|
1346
|
+
...baseModifiers,
|
|
1347
|
+
...(hasExplicitFormat && !explicitFormat ? { format: false } : {}),
|
|
1348
|
+
...(hasExplicitQuality && !explicitQuality ? { quality: false } : {}),
|
|
1349
|
+
});
|
|
988
1350
|
const provider = readStringProp(props.provider);
|
|
989
|
-
const quality =
|
|
1351
|
+
const quality = hasExplicitQuality
|
|
1352
|
+
? explicitQuality
|
|
1353
|
+
: (explicitQuality ?? runtimeImageConfig.quality);
|
|
1354
|
+
const cache = normalizeImageCacheValue(props.cache ?? runtimeImageConfig.cache);
|
|
990
1355
|
const fit = readStringProp(props.fit);
|
|
991
1356
|
const width = readNumberProp(props.width);
|
|
992
1357
|
const height = readNumberProp(props.height);
|
|
@@ -999,6 +1364,11 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
999
1364
|
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
1000
1365
|
const loading = explicitLoading ?? (lazy ? "lazy" : "eager");
|
|
1001
1366
|
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
1367
|
+
const lazyRootMargin = readStringProp(props.rootMargin) ?? "0px 0px";
|
|
1368
|
+
const lazyThresholdRaw = Number(props.threshold);
|
|
1369
|
+
const lazyThreshold = Number.isFinite(lazyThresholdRaw)
|
|
1370
|
+
? Math.min(1, Math.max(0, lazyThresholdRaw))
|
|
1371
|
+
: 0;
|
|
1002
1372
|
const decoding = readStringProp(props.decoding) ?? "async";
|
|
1003
1373
|
const fetchPriority = readStringProp(props.fetchpriority ?? props.fetchPriority)
|
|
1004
1374
|
?? (priority ? "high" : undefined);
|
|
@@ -1007,8 +1377,12 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
1007
1377
|
|| [1, 2];
|
|
1008
1378
|
const widths = parseImageNumberList(props.widths) ?? [];
|
|
1009
1379
|
const passthrough = collectResuxImagePassthroughAttributes(props);
|
|
1010
|
-
const src = readStringProp(props.src)
|
|
1380
|
+
const src = readStringProp(props.src)
|
|
1381
|
+
?? readStringProp(props.fallbackSrc ?? props.fallback)
|
|
1382
|
+
?? "";
|
|
1011
1383
|
const alt = readStringProp(props.alt) ?? "";
|
|
1384
|
+
const placeholderSrc = resolveMediaPlaceholderSource(props.placeholder);
|
|
1385
|
+
const fallbackSrc = readStringProp(props.fallbackSrc ?? props.fallback);
|
|
1012
1386
|
return {
|
|
1013
1387
|
src,
|
|
1014
1388
|
alt,
|
|
@@ -1021,12 +1395,21 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
1021
1395
|
decoding,
|
|
1022
1396
|
fetchPriority,
|
|
1023
1397
|
provider,
|
|
1398
|
+
cache,
|
|
1024
1399
|
quality,
|
|
1025
1400
|
fit,
|
|
1026
|
-
format: explicitFormats.length
|
|
1401
|
+
format: explicitFormats.length
|
|
1402
|
+
? undefined
|
|
1403
|
+
: (hasExplicitFormat ? explicitFormat : (explicitFormat ?? runtimeImageConfig.format)),
|
|
1027
1404
|
formats: explicitFormats,
|
|
1028
1405
|
preload,
|
|
1029
1406
|
deferLazy,
|
|
1407
|
+
lazyRootMargin,
|
|
1408
|
+
lazyThreshold,
|
|
1409
|
+
placeholderSrc,
|
|
1410
|
+
placeholderClass: readStringProp(props.placeholderClass),
|
|
1411
|
+
placeholderStyle: readStringProp(props.placeholderStyle),
|
|
1412
|
+
fallbackSrc,
|
|
1030
1413
|
modifiers,
|
|
1031
1414
|
attrs: passthrough,
|
|
1032
1415
|
};
|
|
@@ -1058,15 +1441,14 @@ function resolveResuxImageModifierProps(value) {
|
|
|
1058
1441
|
return normalizeImageModifiers(value);
|
|
1059
1442
|
}
|
|
1060
1443
|
function buildResuxImageSrcset(builder, input) {
|
|
1061
|
-
const widthCandidates = input
|
|
1062
|
-
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
1063
|
-
: [];
|
|
1444
|
+
const widthCandidates = resolveResuxImageWidthCandidates(input);
|
|
1064
1445
|
if (widthCandidates.length) {
|
|
1065
1446
|
return widthCandidates
|
|
1066
1447
|
.map((width) => `${builder(input.src, {
|
|
1067
1448
|
provider: input.provider,
|
|
1449
|
+
cache: input.cache,
|
|
1068
1450
|
width,
|
|
1069
|
-
height: input
|
|
1451
|
+
height: resolveResuxImageCandidateHeight(input, width),
|
|
1070
1452
|
quality: input.quality,
|
|
1071
1453
|
fit: input.fit,
|
|
1072
1454
|
format: input.format,
|
|
@@ -1083,6 +1465,7 @@ function buildResuxImageSrcset(builder, input) {
|
|
|
1083
1465
|
const width = Math.max(1, Math.round(input.width * density));
|
|
1084
1466
|
return `${builder(input.src, {
|
|
1085
1467
|
provider: input.provider,
|
|
1468
|
+
cache: input.cache,
|
|
1086
1469
|
width,
|
|
1087
1470
|
height: input.height ? Math.max(1, Math.round(input.height * density)) : undefined,
|
|
1088
1471
|
quality: input.quality,
|
|
@@ -1093,6 +1476,83 @@ function buildResuxImageSrcset(builder, input) {
|
|
|
1093
1476
|
})
|
|
1094
1477
|
.join(", ");
|
|
1095
1478
|
}
|
|
1479
|
+
function resolveResuxImageWidthCandidates(input) {
|
|
1480
|
+
const explicitWidths = input.widths.length
|
|
1481
|
+
? normalizeResuxImageWidthCandidates(input.widths, input.width)
|
|
1482
|
+
: [];
|
|
1483
|
+
if (explicitWidths.length) {
|
|
1484
|
+
return explicitWidths;
|
|
1485
|
+
}
|
|
1486
|
+
if (!input.sizes) {
|
|
1487
|
+
return [];
|
|
1488
|
+
}
|
|
1489
|
+
return resolveResuxImageWidthsFromSizes(input.sizes, input.densities, input.width);
|
|
1490
|
+
}
|
|
1491
|
+
function resolveResuxImageWidthsFromSizes(sizes, densities, maxWidth) {
|
|
1492
|
+
const descriptors = sizes
|
|
1493
|
+
.split(",")
|
|
1494
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
1495
|
+
.filter(Boolean);
|
|
1496
|
+
const baseWidths = [];
|
|
1497
|
+
for (const descriptor of descriptors) {
|
|
1498
|
+
const match = [...descriptor.matchAll(/([0-9]*\.?[0-9]+)\s*(px|vw)\b/g)].pop();
|
|
1499
|
+
if (!match) {
|
|
1500
|
+
continue;
|
|
1501
|
+
}
|
|
1502
|
+
const value = Number(match[1]);
|
|
1503
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
1504
|
+
continue;
|
|
1505
|
+
}
|
|
1506
|
+
if (match[2] === "px") {
|
|
1507
|
+
baseWidths.push(Math.round(value));
|
|
1508
|
+
continue;
|
|
1509
|
+
}
|
|
1510
|
+
for (const viewportWidth of resuxResponsiveViewportWidths) {
|
|
1511
|
+
baseWidths.push(Math.round((viewportWidth * value) / 100));
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
const safeDensities = densities.length
|
|
1515
|
+
? [...new Set(densities)]
|
|
1516
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
1517
|
+
.sort((left, right) => left - right)
|
|
1518
|
+
: [1];
|
|
1519
|
+
const expandedWidths = baseWidths.flatMap((width) => safeDensities.map((density) => Math.round(width * density)));
|
|
1520
|
+
if (!expandedWidths.length && Number.isFinite(maxWidth) && maxWidth > 0) {
|
|
1521
|
+
return [Math.max(1, Math.round(maxWidth))];
|
|
1522
|
+
}
|
|
1523
|
+
return normalizeResuxImageWidthCandidates(expandedWidths, maxWidth);
|
|
1524
|
+
}
|
|
1525
|
+
function normalizeResuxImageWidthCandidates(candidates, maxWidth) {
|
|
1526
|
+
const resolvedMaxWidth = Number.isFinite(maxWidth) && maxWidth > 0
|
|
1527
|
+
? Math.round(maxWidth)
|
|
1528
|
+
: Number.POSITIVE_INFINITY;
|
|
1529
|
+
const normalized = [...new Set(candidates
|
|
1530
|
+
.map((entry) => Number(entry))
|
|
1531
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
1532
|
+
.map((entry) => Math.min(8192, Math.max(1, Math.round(entry)), resolvedMaxWidth)))]
|
|
1533
|
+
.sort((left, right) => left - right);
|
|
1534
|
+
const compacted = [];
|
|
1535
|
+
for (const width of normalized) {
|
|
1536
|
+
const previous = compacted[compacted.length - 1];
|
|
1537
|
+
const shouldKeep = previous === undefined
|
|
1538
|
+
|| width - previous >= 24
|
|
1539
|
+
|| (Number.isFinite(resolvedMaxWidth) && width === resolvedMaxWidth);
|
|
1540
|
+
if (shouldKeep) {
|
|
1541
|
+
compacted.push(width);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return compacted;
|
|
1545
|
+
}
|
|
1546
|
+
function resolveResuxImageCandidateHeight(input, width) {
|
|
1547
|
+
if (!input.height) {
|
|
1548
|
+
return undefined;
|
|
1549
|
+
}
|
|
1550
|
+
if (!input.width) {
|
|
1551
|
+
return input.height;
|
|
1552
|
+
}
|
|
1553
|
+
const scaledHeight = Math.round((input.height / input.width) * width);
|
|
1554
|
+
return Math.max(1, scaledHeight);
|
|
1555
|
+
}
|
|
1096
1556
|
function registerResuxImagePreload(context, href, srcset, input, enabled) {
|
|
1097
1557
|
if (!enabled || !href || !context.addHeadEntry) {
|
|
1098
1558
|
return;
|
|
@@ -1117,16 +1577,39 @@ function registerResuxImagePreload(context, href, srcset, input, enabled) {
|
|
|
1117
1577
|
function renderResuxImgTag(input, src, srcset, styleScopeId) {
|
|
1118
1578
|
const attrs = [];
|
|
1119
1579
|
const isDeferredLazy = input.deferLazy && input.loading.toLowerCase() === "lazy";
|
|
1580
|
+
const placeholderSrc = input.placeholderSrc;
|
|
1581
|
+
const placeholderClass = input.placeholderClass;
|
|
1582
|
+
const placeholderStyle = input.placeholderStyle;
|
|
1583
|
+
const aspectRatioStyle = resolveAspectRatioStyle(input.width, input.height, input.attrs.style, placeholderStyle);
|
|
1584
|
+
const placeholderBackground = placeholderSrc
|
|
1585
|
+
? `background-image: url('${placeholderSrc}'); background-size: cover; background-position: center; background-repeat: no-repeat`
|
|
1586
|
+
: undefined;
|
|
1587
|
+
const mergedClass = mergeClassNames(input.attrs.class, placeholderClass);
|
|
1588
|
+
const mergedStyle = mergeInlineStyles(input.attrs.style, aspectRatioStyle, !isDeferredLazy ? placeholderBackground : undefined, placeholderStyle);
|
|
1589
|
+
const initialSrc = isDeferredLazy
|
|
1590
|
+
? (placeholderSrc ?? resuxLazyPlaceholderSrc)
|
|
1591
|
+
: src;
|
|
1120
1592
|
const mergedAttrs = {
|
|
1121
1593
|
...input.attrs,
|
|
1122
|
-
|
|
1594
|
+
...(mergedClass ? { class: mergedClass } : {}),
|
|
1595
|
+
...(mergedStyle ? { style: mergedStyle } : {}),
|
|
1596
|
+
src: initialSrc,
|
|
1123
1597
|
alt: input.alt,
|
|
1124
1598
|
loading: input.loading,
|
|
1125
1599
|
decoding: input.decoding,
|
|
1600
|
+
"data-resux-media": "img",
|
|
1126
1601
|
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
1127
|
-
...(isDeferredLazy ? { "data-
|
|
1128
|
-
...(isDeferredLazy
|
|
1602
|
+
...(isDeferredLazy ? { "data-resux-lazy": "true" } : {}),
|
|
1603
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src, "data-src": src } : {}),
|
|
1604
|
+
...(isDeferredLazy ? { "data-rx-lazy-root-margin": input.lazyRootMargin } : {}),
|
|
1605
|
+
...(isDeferredLazy ? { "data-rx-lazy-threshold": String(input.lazyThreshold) } : {}),
|
|
1606
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset, "data-srcset": srcset } : {}),
|
|
1129
1607
|
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
1608
|
+
...(placeholderSrc ? { "data-rx-placeholder-src": placeholderSrc, "data-placeholder": placeholderSrc } : {}),
|
|
1609
|
+
...(placeholderClass ? { "data-rx-placeholder-class": placeholderClass } : {}),
|
|
1610
|
+
...(placeholderStyle ? { "data-rx-placeholder-style": placeholderStyle } : {}),
|
|
1611
|
+
...(placeholderSrc ? { "data-rx-placeholder-active": "true", "data-resux-placeholder-active": "true" } : {}),
|
|
1612
|
+
...(input.fallbackSrc ? { "data-rx-fallback-src": input.fallbackSrc } : {}),
|
|
1130
1613
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1131
1614
|
...(input.width ? { width: String(input.width) } : {}),
|
|
1132
1615
|
...(input.height ? { height: String(input.height) } : {}),
|
|
@@ -1199,6 +1682,9 @@ function readBooleanProp(value, fallback) {
|
|
|
1199
1682
|
}
|
|
1200
1683
|
if (typeof value === "string") {
|
|
1201
1684
|
const normalized = value.trim().toLowerCase();
|
|
1685
|
+
if (normalized === "") {
|
|
1686
|
+
return true;
|
|
1687
|
+
}
|
|
1202
1688
|
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
1203
1689
|
return true;
|
|
1204
1690
|
}
|
|
@@ -1208,6 +1694,161 @@ function readBooleanProp(value, fallback) {
|
|
|
1208
1694
|
}
|
|
1209
1695
|
return fallback;
|
|
1210
1696
|
}
|
|
1697
|
+
function resolveMediaPlaceholderSource(value) {
|
|
1698
|
+
if (value === undefined || value === null || value === false) {
|
|
1699
|
+
return undefined;
|
|
1700
|
+
}
|
|
1701
|
+
if (value === true) {
|
|
1702
|
+
return resuxDefaultPlaceholderSrc;
|
|
1703
|
+
}
|
|
1704
|
+
if (typeof value !== "string") {
|
|
1705
|
+
return undefined;
|
|
1706
|
+
}
|
|
1707
|
+
const trimmed = value.trim();
|
|
1708
|
+
if (!trimmed) {
|
|
1709
|
+
return undefined;
|
|
1710
|
+
}
|
|
1711
|
+
const normalized = trimmed.toLowerCase();
|
|
1712
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
1713
|
+
return resuxDefaultPlaceholderSrc;
|
|
1714
|
+
}
|
|
1715
|
+
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
|
1716
|
+
return undefined;
|
|
1717
|
+
}
|
|
1718
|
+
if (looksLikeMediaSource(trimmed)) {
|
|
1719
|
+
return trimmed;
|
|
1720
|
+
}
|
|
1721
|
+
return createTextPlaceholderDataUri(trimmed);
|
|
1722
|
+
}
|
|
1723
|
+
function looksLikeMediaSource(value) {
|
|
1724
|
+
return (value.startsWith("/")
|
|
1725
|
+
|| value.startsWith("./")
|
|
1726
|
+
|| value.startsWith("../")
|
|
1727
|
+
|| value.startsWith("http://")
|
|
1728
|
+
|| value.startsWith("https://")
|
|
1729
|
+
|| value.startsWith("data:image/")
|
|
1730
|
+
|| value.startsWith("blob:"));
|
|
1731
|
+
}
|
|
1732
|
+
function createTextPlaceholderDataUri(value) {
|
|
1733
|
+
const safeLabel = escapeSvgText(value);
|
|
1734
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360" role="img" aria-label="${safeLabel}">`
|
|
1735
|
+
+ `<rect width="640" height="360" fill="#0f172a"/>`
|
|
1736
|
+
+ `<rect x="24" y="24" width="592" height="312" rx="20" fill="#111827" stroke="#334155" stroke-width="2"/>`
|
|
1737
|
+
+ `<text x="320" y="192" fill="#cbd5e1" font-size="30" text-anchor="middle" font-family="Segoe UI, Arial, sans-serif">${safeLabel}</text>`
|
|
1738
|
+
+ `</svg>`;
|
|
1739
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
1740
|
+
}
|
|
1741
|
+
function escapeSvgText(value) {
|
|
1742
|
+
return value
|
|
1743
|
+
.replace(/&/g, "&")
|
|
1744
|
+
.replace(/</g, "<")
|
|
1745
|
+
.replace(/>/g, ">")
|
|
1746
|
+
.replace(/"/g, """)
|
|
1747
|
+
.replace(/'/g, "'");
|
|
1748
|
+
}
|
|
1749
|
+
function mergeClassNames(...values) {
|
|
1750
|
+
const tokens = values
|
|
1751
|
+
.flatMap((value) => String(value ?? "").split(/\s+/))
|
|
1752
|
+
.map((token) => token.trim())
|
|
1753
|
+
.filter(Boolean);
|
|
1754
|
+
return tokens.length ? [...new Set(tokens)].join(" ") : undefined;
|
|
1755
|
+
}
|
|
1756
|
+
function mergeInlineStyles(...values) {
|
|
1757
|
+
const parts = values
|
|
1758
|
+
.flatMap((value) => String(value ?? "").split(";"))
|
|
1759
|
+
.map((entry) => entry.trim())
|
|
1760
|
+
.filter(Boolean);
|
|
1761
|
+
return parts.length ? parts.join("; ") : undefined;
|
|
1762
|
+
}
|
|
1763
|
+
function hasInlineStyleProperty(styleValue, propertyName) {
|
|
1764
|
+
if (typeof styleValue !== "string") {
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
const normalized = propertyName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1768
|
+
const pattern = new RegExp(`(^|;)\\s*${normalized}\\s*:`, "i");
|
|
1769
|
+
return pattern.test(styleValue);
|
|
1770
|
+
}
|
|
1771
|
+
function resolveAspectRatioStyle(width, height, ...styleValues) {
|
|
1772
|
+
if (!width || !height) {
|
|
1773
|
+
return undefined;
|
|
1774
|
+
}
|
|
1775
|
+
if (styleValues.some((entry) => hasInlineStyleProperty(entry, "aspect-ratio"))) {
|
|
1776
|
+
return undefined;
|
|
1777
|
+
}
|
|
1778
|
+
return `aspect-ratio: ${width} / ${height}`;
|
|
1779
|
+
}
|
|
1780
|
+
function resolvePictureSourceInputs(value, fallbackInput) {
|
|
1781
|
+
if (!Array.isArray(value)) {
|
|
1782
|
+
return [];
|
|
1783
|
+
}
|
|
1784
|
+
const resolved = [];
|
|
1785
|
+
for (const entry of value) {
|
|
1786
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
const record = entry;
|
|
1790
|
+
const src = readStringProp(record.src) ?? fallbackInput.src;
|
|
1791
|
+
if (!src) {
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
const hasQuality = Object.prototype.hasOwnProperty.call(record, "quality");
|
|
1795
|
+
const hasFormat = Object.prototype.hasOwnProperty.call(record, "format");
|
|
1796
|
+
const explicitFormat = readStringProp(record.format);
|
|
1797
|
+
const sourceWidths = parseImageNumberList(record.widths) ?? fallbackInput.widths;
|
|
1798
|
+
const baseModifiers = resolveResuxImageModifierProps(record.modifiers);
|
|
1799
|
+
const modifiers = normalizeImageModifiers({
|
|
1800
|
+
...fallbackInput.modifiers,
|
|
1801
|
+
...baseModifiers,
|
|
1802
|
+
...(hasFormat && !explicitFormat ? { format: false } : {}),
|
|
1803
|
+
...(hasQuality && !readNumberProp(record.quality) ? { quality: false } : {}),
|
|
1804
|
+
...(readStringProp(record.fit) ? { fit: readStringProp(record.fit) } : {}),
|
|
1805
|
+
...(readNumberProp(record.width) ? { width: readNumberProp(record.width) } : {}),
|
|
1806
|
+
...(readNumberProp(record.height) ? { height: readNumberProp(record.height) } : {}),
|
|
1807
|
+
...(readNumberProp(record.quality) ? { quality: readNumberProp(record.quality) } : {}),
|
|
1808
|
+
...(explicitFormat ? { format: explicitFormat } : {}),
|
|
1809
|
+
});
|
|
1810
|
+
resolved.push({
|
|
1811
|
+
src,
|
|
1812
|
+
srcset: readStringProp(record.srcset),
|
|
1813
|
+
type: readStringProp(record.type),
|
|
1814
|
+
media: readStringProp(record.media),
|
|
1815
|
+
sizes: readStringProp(record.sizes) ?? fallbackInput.sizes,
|
|
1816
|
+
width: readNumberProp(record.width) ?? fallbackInput.width,
|
|
1817
|
+
height: readNumberProp(record.height) ?? fallbackInput.height,
|
|
1818
|
+
widths: sourceWidths,
|
|
1819
|
+
quality: hasQuality
|
|
1820
|
+
? readNumberProp(record.quality)
|
|
1821
|
+
: fallbackInput.quality,
|
|
1822
|
+
format: hasFormat
|
|
1823
|
+
? explicitFormat
|
|
1824
|
+
: fallbackInput.format,
|
|
1825
|
+
fit: readStringProp(record.fit) ?? fallbackInput.fit,
|
|
1826
|
+
modifiers,
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
return resolved;
|
|
1830
|
+
}
|
|
1831
|
+
function resolveVideoSources(value) {
|
|
1832
|
+
if (!Array.isArray(value)) {
|
|
1833
|
+
return [];
|
|
1834
|
+
}
|
|
1835
|
+
const sources = [];
|
|
1836
|
+
for (const entry of value) {
|
|
1837
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
const record = entry;
|
|
1841
|
+
const src = readStringProp(record.src);
|
|
1842
|
+
if (!src) {
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
sources.push({
|
|
1846
|
+
src,
|
|
1847
|
+
type: readStringProp(record.type),
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
return sources;
|
|
1851
|
+
}
|
|
1211
1852
|
function resuxImageMimeType(format) {
|
|
1212
1853
|
const normalized = format.toLowerCase();
|
|
1213
1854
|
if (normalized === "jpg") {
|
|
@@ -1215,6 +1856,21 @@ function resuxImageMimeType(format) {
|
|
|
1215
1856
|
}
|
|
1216
1857
|
return normalized.startsWith("image/") ? normalized : `image/${normalized}`;
|
|
1217
1858
|
}
|
|
1859
|
+
function inferImageMimeTypeFromSource(src) {
|
|
1860
|
+
const clean = src.split(/[?#]/)[0]?.toLowerCase();
|
|
1861
|
+
if (!clean) {
|
|
1862
|
+
return undefined;
|
|
1863
|
+
}
|
|
1864
|
+
const dotIndex = clean.lastIndexOf(".");
|
|
1865
|
+
if (dotIndex < 0) {
|
|
1866
|
+
return undefined;
|
|
1867
|
+
}
|
|
1868
|
+
const extension = clean.slice(dotIndex + 1);
|
|
1869
|
+
if (!extension) {
|
|
1870
|
+
return undefined;
|
|
1871
|
+
}
|
|
1872
|
+
return resuxImageMimeType(extension);
|
|
1873
|
+
}
|
|
1218
1874
|
function renderVueIsland(node, context, locals) {
|
|
1219
1875
|
const name = resolveVueIslandName(node, context, locals);
|
|
1220
1876
|
const props = resolveVueIslandProps(node, context, locals);
|
|
@@ -1370,7 +2026,7 @@ export class AsyncResuxRenderer {
|
|
|
1370
2026
|
components: this.components,
|
|
1371
2027
|
layouts: this.layouts,
|
|
1372
2028
|
pageMeta: this.pageMeta,
|
|
1373
|
-
addHeadEntry: (entry) => this.headEntries
|
|
2029
|
+
addHeadEntry: (entry) => insertHeadEntryWithPriority(this.headEntries, entry),
|
|
1374
2030
|
renderPage,
|
|
1375
2031
|
renderSlot,
|
|
1376
2032
|
renderLayout: (name, slot) => this.renderLayout(name, slot)
|
|
@@ -1598,15 +2254,22 @@ function mergeHead(entries) {
|
|
|
1598
2254
|
merged.style.push(...entry.style);
|
|
1599
2255
|
}
|
|
1600
2256
|
}
|
|
2257
|
+
merged.link = sortHeadLinksForPriority(merged.link ?? []);
|
|
1601
2258
|
return merged;
|
|
1602
2259
|
}
|
|
1603
2260
|
function renderHead(head) {
|
|
1604
2261
|
const tags = [];
|
|
1605
2262
|
tags.push(`<title>${escapeHtml(head.title ?? "Resux App")}</title>`);
|
|
2263
|
+
const links = sortHeadLinksForPriority(head.link ?? []);
|
|
2264
|
+
const highPriorityImagePreloads = links.filter((link) => isPriorityImagePreloadLink(link));
|
|
2265
|
+
const remainingLinks = links.filter((link) => !isPriorityImagePreloadLink(link));
|
|
2266
|
+
for (const link of highPriorityImagePreloads) {
|
|
2267
|
+
tags.push(`<link data-rx-head="true" ${renderAttributes(link)}>`);
|
|
2268
|
+
}
|
|
1606
2269
|
for (const meta of head.meta ?? []) {
|
|
1607
2270
|
tags.push(`<meta data-rx-head="true" ${renderAttributes(meta)}>`);
|
|
1608
2271
|
}
|
|
1609
|
-
for (const link of
|
|
2272
|
+
for (const link of remainingLinks) {
|
|
1610
2273
|
tags.push(`<link data-rx-head="true" ${renderAttributes(link)}>`);
|
|
1611
2274
|
}
|
|
1612
2275
|
for (const style of head.style ?? []) {
|
|
@@ -1614,6 +2277,49 @@ function renderHead(head) {
|
|
|
1614
2277
|
}
|
|
1615
2278
|
return tags.join("");
|
|
1616
2279
|
}
|
|
2280
|
+
function sortHeadLinksForPriority(links) {
|
|
2281
|
+
return links
|
|
2282
|
+
.map((link, index) => ({
|
|
2283
|
+
link,
|
|
2284
|
+
index,
|
|
2285
|
+
priority: isPriorityImagePreloadLink(link)
|
|
2286
|
+
? 0
|
|
2287
|
+
: normalizeHeadLinkRel(link) === "preload"
|
|
2288
|
+
? 1
|
|
2289
|
+
: 2,
|
|
2290
|
+
}))
|
|
2291
|
+
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
2292
|
+
.map((entry) => entry.link);
|
|
2293
|
+
}
|
|
2294
|
+
function normalizeHeadLinkRel(link) {
|
|
2295
|
+
return String(link.rel ?? "").trim().toLowerCase();
|
|
2296
|
+
}
|
|
2297
|
+
function isPriorityImagePreloadLink(link) {
|
|
2298
|
+
if (normalizeHeadLinkRel(link) !== "preload") {
|
|
2299
|
+
return false;
|
|
2300
|
+
}
|
|
2301
|
+
return String(link.as ?? "").trim().toLowerCase() === "image";
|
|
2302
|
+
}
|
|
2303
|
+
function isPriorityImagePreloadEntry(entry) {
|
|
2304
|
+
return (!entry.title
|
|
2305
|
+
&& !entry.meta
|
|
2306
|
+
&& !entry.style
|
|
2307
|
+
&& Array.isArray(entry.link)
|
|
2308
|
+
&& entry.link.length > 0
|
|
2309
|
+
&& entry.link.every((link) => isPriorityImagePreloadLink(link)));
|
|
2310
|
+
}
|
|
2311
|
+
function insertHeadEntryWithPriority(entries, entry) {
|
|
2312
|
+
if (!isPriorityImagePreloadEntry(entry)) {
|
|
2313
|
+
entries.push(entry);
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
const insertionIndex = entries.findIndex((candidate) => !isPriorityImagePreloadEntry(candidate));
|
|
2317
|
+
if (insertionIndex === -1) {
|
|
2318
|
+
entries.push(entry);
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2321
|
+
entries.splice(insertionIndex, 0, entry);
|
|
2322
|
+
}
|
|
1617
2323
|
function escapeStyleContent(css) {
|
|
1618
2324
|
return css.replace(/<\/style/gi, "<\\/style");
|
|
1619
2325
|
}
|
|
@@ -1706,7 +2412,7 @@ function collectPatches(nodes, scope, scopeId, locals, patches, styleScopeId) {
|
|
|
1706
2412
|
value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals))
|
|
1707
2413
|
});
|
|
1708
2414
|
}
|
|
1709
|
-
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
2415
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture" && node.tag !== "ResuxVideo") {
|
|
1710
2416
|
for (const attr of node.attrs) {
|
|
1711
2417
|
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
1712
2418
|
patches.push({
|
|
@@ -1763,11 +2469,18 @@ let routeTransitionProgressTimer = 0;
|
|
|
1763
2469
|
let routeTransitionStartedAt = 0;
|
|
1764
2470
|
let routeTransitionVisible = false;
|
|
1765
2471
|
let routeTransitionIndicator = null;
|
|
1766
|
-
|
|
2472
|
+
const lazyImageObservers = new Map();
|
|
2473
|
+
const lazyVideoObservers = new Map();
|
|
1767
2474
|
const clientPluginIds = new Set();
|
|
1768
2475
|
const clientMiddlewareById = new Map();
|
|
1769
2476
|
const clientProvides = globalThis.__RESUX_PROVIDES__ ||= {};
|
|
1770
2477
|
const RESUX_LAZY_PLACEHOLDER_SRC = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
2478
|
+
const RESUX_DEFAULT_PLACEHOLDER_SRC = "/__resux/resux-placeholder.svg";
|
|
2479
|
+
const observedLazyImages = new Set();
|
|
2480
|
+
const observedLazyVideos = new Set();
|
|
2481
|
+
const lazyImageObserverByElement = new WeakMap();
|
|
2482
|
+
const lazyVideoObserverByElement = new WeakMap();
|
|
2483
|
+
const failedMediaSources = new Set();
|
|
1771
2484
|
|
|
1772
2485
|
const __rxFlags = {
|
|
1773
2486
|
isReactive: "__v_isReactive",
|
|
@@ -2291,6 +3004,7 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2291
3004
|
const providerName = String(options.provider || imageConfig.provider || "resux").trim().toLowerCase();
|
|
2292
3005
|
const providerConfig = imageConfig.providers[providerName] || {};
|
|
2293
3006
|
const baseURL = providerConfig.baseURL || (providerName === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
3007
|
+
const cacheOption = normalizeClientImageCacheValue(options.cache ?? imageConfig.cache);
|
|
2294
3008
|
const modifiers = {
|
|
2295
3009
|
...(providerConfig.modifiers || {}),
|
|
2296
3010
|
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
@@ -2318,6 +3032,7 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2318
3032
|
const sourceDescriptor = providerName === "vercel"
|
|
2319
3033
|
? { publicSource: normalizedSrc }
|
|
2320
3034
|
: rewriteClientImageSourceForDisplayFormat(normalizedSrc, normalizedFormat);
|
|
3035
|
+
const useGeneratedCache = providerName === "resux" && typeof cacheOption === "string" && cacheOption.length > 0;
|
|
2321
3036
|
|
|
2322
3037
|
if (providerName === "vercel") {
|
|
2323
3038
|
query.set("url", normalizedSrc);
|
|
@@ -2347,46 +3062,182 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2347
3062
|
query.set(key, String(value));
|
|
2348
3063
|
}
|
|
2349
3064
|
|
|
3065
|
+
if (useGeneratedCache) {
|
|
3066
|
+
query.set("cache", cacheOption);
|
|
3067
|
+
const generatedPath = createClientGeneratedImageRoutePath(
|
|
3068
|
+
sourceDescriptor.publicSource,
|
|
3069
|
+
sourceDescriptor.originalSource,
|
|
3070
|
+
normalizedFormat,
|
|
3071
|
+
modifiers,
|
|
3072
|
+
);
|
|
3073
|
+
const queryString = query.toString();
|
|
3074
|
+
return queryString ? generatedPath + "?" + queryString : generatedPath;
|
|
3075
|
+
}
|
|
3076
|
+
|
|
2350
3077
|
const separator = baseURL.includes("?") ? "&" : "?";
|
|
2351
3078
|
return query.toString() ? baseURL + separator + query.toString() : baseURL;
|
|
2352
3079
|
};
|
|
2353
3080
|
}
|
|
2354
3081
|
|
|
2355
|
-
function
|
|
2356
|
-
if (
|
|
3082
|
+
function normalizeClientImageCacheValue(value) {
|
|
3083
|
+
if (value === undefined || value === null || value === false) {
|
|
2357
3084
|
return undefined;
|
|
2358
3085
|
}
|
|
2359
|
-
|
|
2360
|
-
|
|
2361
|
-
return undefined;
|
|
3086
|
+
if (value === true) {
|
|
3087
|
+
return "1d";
|
|
2362
3088
|
}
|
|
2363
|
-
|
|
3089
|
+
if (typeof value === "number") {
|
|
3090
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3091
|
+
return undefined;
|
|
3092
|
+
}
|
|
3093
|
+
return String(Math.round(value));
|
|
3094
|
+
}
|
|
3095
|
+
if (typeof value === "string") {
|
|
3096
|
+
const normalized = value.trim().toLowerCase();
|
|
3097
|
+
if (!normalized || normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
3098
|
+
return "1d";
|
|
3099
|
+
}
|
|
3100
|
+
if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
|
|
3101
|
+
return undefined;
|
|
3102
|
+
}
|
|
3103
|
+
return normalized;
|
|
3104
|
+
}
|
|
3105
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
3106
|
+
for (const key of ["maxAge", "expiresIn", "ttl"]) {
|
|
3107
|
+
const normalized = normalizeClientImageCacheValue(value[key]);
|
|
3108
|
+
if (normalized) {
|
|
3109
|
+
return normalized;
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
return undefined;
|
|
2364
3114
|
}
|
|
2365
3115
|
|
|
2366
|
-
function
|
|
2367
|
-
|
|
2368
|
-
|
|
3116
|
+
function createClientGeneratedImageRoutePath(source, originalSource, normalizedFormat, modifiers) {
|
|
3117
|
+
const extension =
|
|
3118
|
+
normalizedFormat
|
|
3119
|
+
|| inferClientImageExtensionFromSource(source)
|
|
3120
|
+
|| inferClientImageExtensionFromSource(originalSource)
|
|
3121
|
+
|| "bin";
|
|
3122
|
+
const signature = createClientImageTransformSignature(source, originalSource, normalizedFormat, modifiers);
|
|
3123
|
+
const digest = hashClientImageSignature(signature);
|
|
3124
|
+
return "/_resux/generated/images/" + digest + "." + extension;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
function createClientImageTransformSignature(source, originalSource, normalizedFormat, modifiers) {
|
|
3128
|
+
const entries = ["src=" + source];
|
|
3129
|
+
if (originalSource) {
|
|
3130
|
+
entries.push("original=" + originalSource);
|
|
2369
3131
|
}
|
|
2370
3132
|
|
|
2371
|
-
|
|
2372
|
-
|
|
3133
|
+
const width = Number(modifiers.width);
|
|
3134
|
+
if (Number.isFinite(width) && width > 0) {
|
|
3135
|
+
entries.push("w=" + Math.round(width));
|
|
3136
|
+
}
|
|
3137
|
+
const height = Number(modifiers.height);
|
|
3138
|
+
if (Number.isFinite(height) && height > 0) {
|
|
3139
|
+
entries.push("h=" + Math.round(height));
|
|
3140
|
+
}
|
|
3141
|
+
if (typeof modifiers.fit === "string" && modifiers.fit) {
|
|
3142
|
+
entries.push("fit=" + modifiers.fit);
|
|
3143
|
+
}
|
|
3144
|
+
if (normalizedFormat) {
|
|
3145
|
+
entries.push("f=" + normalizedFormat);
|
|
3146
|
+
}
|
|
3147
|
+
const quality = Number(modifiers.quality);
|
|
3148
|
+
if (Number.isFinite(quality) && quality > 0) {
|
|
3149
|
+
entries.push("q=" + Math.round(quality));
|
|
2373
3150
|
}
|
|
2374
3151
|
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
|
|
2378
|
-
|
|
2379
|
-
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
sourceUrl.pathname = rewrittenPathname;
|
|
2383
|
-
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
2384
|
-
} catch {
|
|
2385
|
-
return { publicSource: src };
|
|
3152
|
+
const extraKeys = Object.keys(modifiers)
|
|
3153
|
+
.filter((key) => !["width", "height", "quality", "fit", "format", "cache"].includes(key))
|
|
3154
|
+
.sort();
|
|
3155
|
+
for (const key of extraKeys) {
|
|
3156
|
+
const value = modifiers[key];
|
|
3157
|
+
if (value === undefined || value === null || value === false) {
|
|
3158
|
+
continue;
|
|
2386
3159
|
}
|
|
3160
|
+
entries.push(key + "=" + String(value));
|
|
2387
3161
|
}
|
|
2388
3162
|
|
|
2389
|
-
|
|
3163
|
+
return entries.join("&");
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
function hashClientImageSignature(value) {
|
|
3167
|
+
let hash = 2166136261;
|
|
3168
|
+
for (let index = 0; index < value.length; index++) {
|
|
3169
|
+
hash ^= value.charCodeAt(index);
|
|
3170
|
+
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
3171
|
+
}
|
|
3172
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
function inferClientImageExtensionFromSource(value) {
|
|
3176
|
+
if (!value) {
|
|
3177
|
+
return undefined;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
const trimmed = String(value).trim();
|
|
3181
|
+
if (!trimmed) {
|
|
3182
|
+
return undefined;
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
if (trimmed.startsWith("data:")) {
|
|
3186
|
+
const mimeMatch = /^data:image\/([a-zA-Z0-9.+-]+);/i.exec(trimmed);
|
|
3187
|
+
if (!mimeMatch) {
|
|
3188
|
+
return undefined;
|
|
3189
|
+
}
|
|
3190
|
+
const normalized = mimeMatch[1].toLowerCase();
|
|
3191
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
const withoutQuery = trimmed.split(/[?#]/)[0];
|
|
3195
|
+
const dotIndex = withoutQuery.lastIndexOf(".");
|
|
3196
|
+
if (dotIndex < 0) {
|
|
3197
|
+
return undefined;
|
|
3198
|
+
}
|
|
3199
|
+
const extension = withoutQuery.slice(dotIndex + 1).toLowerCase();
|
|
3200
|
+
if (!extension) {
|
|
3201
|
+
return undefined;
|
|
3202
|
+
}
|
|
3203
|
+
return extension === "jpg" ? "jpeg" : extension;
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
function normalizeClientImageOutputFormat(value) {
|
|
3207
|
+
if (typeof value !== "string") {
|
|
3208
|
+
return undefined;
|
|
3209
|
+
}
|
|
3210
|
+
const normalized = value.trim().toLowerCase();
|
|
3211
|
+
if (!normalized) {
|
|
3212
|
+
return undefined;
|
|
3213
|
+
}
|
|
3214
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
function rewriteClientImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
3218
|
+
if (!normalizedFormat) {
|
|
3219
|
+
return { publicSource: src };
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
3223
|
+
return { publicSource: src };
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
3227
|
+
try {
|
|
3228
|
+
const sourceUrl = new URL(src);
|
|
3229
|
+
const rewrittenPathname = rewriteClientImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
3230
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
3231
|
+
return { publicSource: src };
|
|
3232
|
+
}
|
|
3233
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
3234
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
3235
|
+
} catch {
|
|
3236
|
+
return { publicSource: src };
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
2390
3241
|
const rewrittenPath = rewriteClientImagePathExtension(pathPart, normalizedFormat);
|
|
2391
3242
|
if (rewrittenPath === pathPart) {
|
|
2392
3243
|
return { publicSource: src };
|
|
@@ -2437,8 +3288,11 @@ function readClientImageConfig(runtimeConfig) {
|
|
|
2437
3288
|
: undefined;
|
|
2438
3289
|
return {
|
|
2439
3290
|
provider: typeof image.provider === "string" ? image.provider : undefined,
|
|
2440
|
-
quality: Number.isFinite(image.quality)
|
|
3291
|
+
quality: Number.isFinite(image.quality)
|
|
3292
|
+
? Math.min(100, Math.max(1, Math.round(Number(image.quality) || 1)))
|
|
3293
|
+
: undefined,
|
|
2441
3294
|
format: typeof image.format === "string" ? image.format : undefined,
|
|
3295
|
+
cache: normalizeClientImageCacheValue(image.cache),
|
|
2442
3296
|
densities: densities && densities.length ? densities : undefined,
|
|
2443
3297
|
providers
|
|
2444
3298
|
};
|
|
@@ -2703,20 +3557,34 @@ function installResux() {
|
|
|
2703
3557
|
document.addEventListener("pointerover", (event) => {
|
|
2704
3558
|
void prefetchNavigationTarget(event);
|
|
2705
3559
|
});
|
|
2706
|
-
document.addEventListener("focusin", (event) => {
|
|
2707
|
-
void prefetchNavigationTarget(event);
|
|
2708
|
-
});
|
|
2709
|
-
|
|
2710
|
-
|
|
2711
|
-
|
|
2712
|
-
|
|
2713
|
-
|
|
2714
|
-
|
|
2715
|
-
|
|
2716
|
-
void
|
|
2717
|
-
});
|
|
2718
|
-
|
|
2719
|
-
|
|
3560
|
+
document.addEventListener("focusin", (event) => {
|
|
3561
|
+
void prefetchNavigationTarget(event);
|
|
3562
|
+
});
|
|
3563
|
+
document.addEventListener("load", handleManagedMediaLoad, true);
|
|
3564
|
+
document.addEventListener("error", handleManagedMediaError, true);
|
|
3565
|
+
document.addEventListener("loadedmetadata", handleManagedVideoReady, true);
|
|
3566
|
+
document.addEventListener("loadeddata", handleManagedVideoReady, true);
|
|
3567
|
+
document.addEventListener("canplay", handleManagedVideoReady, true);
|
|
3568
|
+
for (const eventName of ["input", "change", "submit", "keydown", "keyup", "keypress", "mousedown", "mouseup", "blur", "focusout"]) {
|
|
3569
|
+
document.addEventListener(eventName, (event) => {
|
|
3570
|
+
void handleDelegatedEvent(eventName, event);
|
|
3571
|
+
});
|
|
3572
|
+
}
|
|
3573
|
+
for (const eventName of ["load", "error", "loadstart", "loadedmetadata", "loadeddata", "canplay", "lazy-load-start", "lazy-load-complete"]) {
|
|
3574
|
+
document.addEventListener(eventName, (event) => {
|
|
3575
|
+
void handleDelegatedEvent(eventName, event);
|
|
3576
|
+
}, true);
|
|
3577
|
+
}
|
|
3578
|
+
if (typeof window !== "undefined" && typeof history !== "undefined" && typeof location !== "undefined") {
|
|
3579
|
+
window.addEventListener("popstate", () => {
|
|
3580
|
+
void navigateTo(location.pathname + location.search + location.hash, {
|
|
3581
|
+
replace: true,
|
|
3582
|
+
force: true,
|
|
3583
|
+
preserveScroll: true,
|
|
3584
|
+
});
|
|
3585
|
+
});
|
|
3586
|
+
if (!history.state || !history.state.__resux) {
|
|
3587
|
+
history.replaceState({ __resux: true, path: location.pathname + location.search }, "", location.href);
|
|
2720
3588
|
}
|
|
2721
3589
|
}
|
|
2722
3590
|
if (typeof window !== "undefined") {
|
|
@@ -2741,7 +3609,15 @@ async function initializeClientRuntime() {
|
|
|
2741
3609
|
}
|
|
2742
3610
|
void resumePendingAsyncData();
|
|
2743
3611
|
void mountVueIslands();
|
|
2744
|
-
|
|
3612
|
+
activateDeferredLazyMedia();
|
|
3613
|
+
applyReducedMotionVideoPreference();
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
function activateDeferredLazyMedia(root = document) {
|
|
3617
|
+
cleanupDetachedLazyMedia();
|
|
3618
|
+
activateDeferredLazyImages(root);
|
|
3619
|
+
activateDeferredLazyVideos(root);
|
|
3620
|
+
dispatchPageReadyEvent(root);
|
|
2745
3621
|
}
|
|
2746
3622
|
|
|
2747
3623
|
function activateDeferredLazyImages(root = document) {
|
|
@@ -2749,53 +3625,100 @@ function activateDeferredLazyImages(root = document) {
|
|
|
2749
3625
|
if (!images.length) {
|
|
2750
3626
|
return;
|
|
2751
3627
|
}
|
|
2752
|
-
|
|
2753
|
-
const observer = getLazyImageObserver();
|
|
2754
3628
|
for (const image of images) {
|
|
2755
|
-
if (image
|
|
3629
|
+
if (!isManagedMediaConnected(image)) {
|
|
2756
3630
|
continue;
|
|
2757
3631
|
}
|
|
3632
|
+
if (
|
|
3633
|
+
image.getAttribute("data-rx-lazy-ready") === "true"
|
|
3634
|
+
|| image.getAttribute("data-resux-loaded") === "true"
|
|
3635
|
+
|| image.getAttribute("data-resux-error-handled") === "true"
|
|
3636
|
+
|| observedLazyImages.has(image)
|
|
3637
|
+
) {
|
|
3638
|
+
continue;
|
|
3639
|
+
}
|
|
3640
|
+
const observer = getLazyImageObserver(image);
|
|
2758
3641
|
if (!observer) {
|
|
2759
3642
|
revealDeferredLazyImage(image);
|
|
2760
3643
|
continue;
|
|
2761
3644
|
}
|
|
3645
|
+
observedLazyImages.add(image);
|
|
3646
|
+
lazyImageObserverByElement.set(image, observer);
|
|
3647
|
+
image.setAttribute("data-rx-lazy-observed", "true");
|
|
3648
|
+
image.setAttribute("data-resux-observed", "true");
|
|
2762
3649
|
observer.observe(image);
|
|
2763
3650
|
}
|
|
2764
3651
|
}
|
|
2765
3652
|
|
|
2766
|
-
function getLazyImageObserver() {
|
|
2767
|
-
if (lazyImageObserver) {
|
|
2768
|
-
return lazyImageObserver;
|
|
2769
|
-
}
|
|
3653
|
+
function getLazyImageObserver(image) {
|
|
2770
3654
|
if (typeof IntersectionObserver !== "function") {
|
|
2771
3655
|
return null;
|
|
2772
3656
|
}
|
|
2773
|
-
|
|
3657
|
+
const rootMargin = image.getAttribute("data-rx-lazy-root-margin") || "0px 0px";
|
|
3658
|
+
const thresholdRaw = Number(image.getAttribute("data-rx-lazy-threshold"));
|
|
3659
|
+
const threshold = Number.isFinite(thresholdRaw) ? Math.min(1, Math.max(0, thresholdRaw)) : 0;
|
|
3660
|
+
const key = rootMargin + "|" + String(threshold);
|
|
3661
|
+
if (lazyImageObservers.has(key)) {
|
|
3662
|
+
return lazyImageObservers.get(key);
|
|
3663
|
+
}
|
|
3664
|
+
const observer = new IntersectionObserver((entries) => {
|
|
2774
3665
|
for (const entry of entries) {
|
|
2775
3666
|
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
2776
3667
|
continue;
|
|
2777
3668
|
}
|
|
2778
3669
|
const target = entry.target;
|
|
2779
|
-
|
|
3670
|
+
observer.unobserve(target);
|
|
2780
3671
|
revealDeferredLazyImage(target);
|
|
2781
3672
|
}
|
|
2782
|
-
}, { rootMargin
|
|
2783
|
-
|
|
3673
|
+
}, { rootMargin, threshold });
|
|
3674
|
+
lazyImageObservers.set(key, observer);
|
|
3675
|
+
return observer;
|
|
2784
3676
|
}
|
|
2785
3677
|
|
|
2786
3678
|
function revealDeferredLazyImage(image) {
|
|
2787
|
-
if (!image || image
|
|
3679
|
+
if (!image || !isManagedMediaConnected(image)) {
|
|
3680
|
+
return;
|
|
3681
|
+
}
|
|
3682
|
+
unobserveLazyImage(image);
|
|
3683
|
+
|
|
3684
|
+
if (
|
|
3685
|
+
image.getAttribute("data-rx-lazy-ready") === "true"
|
|
3686
|
+
|| image.getAttribute("data-resux-loaded") === "true"
|
|
3687
|
+
|| image.getAttribute("data-resux-error-handled") === "true"
|
|
3688
|
+
) {
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
const targetSrc = image.getAttribute("data-rx-lazy-src") || image.getAttribute("data-src") || "";
|
|
3693
|
+
if (targetSrc && mediaSourceWasFailed(image, targetSrc)) {
|
|
3694
|
+
applyKnownImageFailure(image, targetSrc);
|
|
3695
|
+
return;
|
|
3696
|
+
}
|
|
3697
|
+
if (
|
|
3698
|
+
targetSrc
|
|
3699
|
+
&& image.getAttribute("data-resux-loading") === "true"
|
|
3700
|
+
&& mediaUrlsEqual(getCurrentMediaUrl(image), targetSrc, image)
|
|
3701
|
+
) {
|
|
2788
3702
|
return;
|
|
2789
3703
|
}
|
|
2790
3704
|
|
|
3705
|
+
dispatchManagedEvent(image, "lazy-load-start");
|
|
3706
|
+
image.setAttribute("data-rx-lazy-pending", "true");
|
|
3707
|
+
image.setAttribute("data-rx-lazy-ready", "true");
|
|
3708
|
+
image.setAttribute("data-resux-loading", "true");
|
|
3709
|
+
|
|
2791
3710
|
const picture = image.closest ? image.closest("picture") : null;
|
|
2792
3711
|
if (picture && picture.querySelectorAll) {
|
|
3712
|
+
picture.setAttribute("data-resux-loading", "true");
|
|
2793
3713
|
picture.querySelectorAll("source[data-rx-lazy-srcset]").forEach((source) => {
|
|
2794
3714
|
const nextSrcset = source.getAttribute("data-rx-lazy-srcset");
|
|
2795
|
-
if (nextSrcset) {
|
|
3715
|
+
if (nextSrcset && !mediaSourceWasFailed(image, nextSrcset)) {
|
|
2796
3716
|
source.setAttribute("srcset", nextSrcset);
|
|
3717
|
+
} else if (nextSrcset) {
|
|
3718
|
+
source.setAttribute("data-rx-failed-srcset", nextSrcset);
|
|
2797
3719
|
}
|
|
2798
3720
|
source.removeAttribute("data-rx-lazy-srcset");
|
|
3721
|
+
source.removeAttribute("data-srcset");
|
|
2799
3722
|
const nextSizes = source.getAttribute("data-rx-lazy-sizes");
|
|
2800
3723
|
if (nextSizes) {
|
|
2801
3724
|
source.setAttribute("sizes", nextSizes);
|
|
@@ -2805,24 +3728,633 @@ function revealDeferredLazyImage(image) {
|
|
|
2805
3728
|
}
|
|
2806
3729
|
|
|
2807
3730
|
const srcset = image.getAttribute("data-rx-lazy-srcset");
|
|
2808
|
-
if (srcset) {
|
|
3731
|
+
if (srcset && !mediaSourceWasFailed(image, srcset)) {
|
|
2809
3732
|
image.setAttribute("srcset", srcset);
|
|
2810
3733
|
}
|
|
2811
3734
|
image.removeAttribute("data-rx-lazy-srcset");
|
|
3735
|
+
image.removeAttribute("data-srcset");
|
|
2812
3736
|
const sizes = image.getAttribute("data-rx-lazy-sizes");
|
|
2813
3737
|
if (sizes) {
|
|
2814
3738
|
image.setAttribute("sizes", sizes);
|
|
2815
3739
|
}
|
|
2816
3740
|
image.removeAttribute("data-rx-lazy-sizes");
|
|
2817
3741
|
|
|
2818
|
-
|
|
2819
|
-
|
|
2820
|
-
image.setAttribute("src", src);
|
|
3742
|
+
if (targetSrc && shouldAssignMediaSource(image, targetSrc)) {
|
|
3743
|
+
image.setAttribute("src", targetSrc);
|
|
2821
3744
|
} else if (image.getAttribute("src") === RESUX_LAZY_PLACEHOLDER_SRC) {
|
|
2822
3745
|
image.removeAttribute("src");
|
|
2823
3746
|
}
|
|
2824
3747
|
image.removeAttribute("data-rx-lazy-src");
|
|
2825
|
-
image.
|
|
3748
|
+
image.removeAttribute("data-src");
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
function activateDeferredLazyVideos(root = document) {
|
|
3752
|
+
const videos = root.querySelectorAll ? root.querySelectorAll("video[data-rx-lazy-video='true']") : [];
|
|
3753
|
+
if (!videos.length) {
|
|
3754
|
+
return;
|
|
3755
|
+
}
|
|
3756
|
+
for (const video of videos) {
|
|
3757
|
+
if (!isManagedMediaConnected(video)) {
|
|
3758
|
+
continue;
|
|
3759
|
+
}
|
|
3760
|
+
if (
|
|
3761
|
+
video.getAttribute("data-rx-lazy-ready") === "true"
|
|
3762
|
+
|| video.getAttribute("data-resux-loaded") === "true"
|
|
3763
|
+
|| video.getAttribute("data-resux-error-handled") === "true"
|
|
3764
|
+
|| observedLazyVideos.has(video)
|
|
3765
|
+
) {
|
|
3766
|
+
continue;
|
|
3767
|
+
}
|
|
3768
|
+
const observer = getLazyVideoObserver(video);
|
|
3769
|
+
if (!observer) {
|
|
3770
|
+
revealDeferredLazyVideo(video);
|
|
3771
|
+
continue;
|
|
3772
|
+
}
|
|
3773
|
+
observedLazyVideos.add(video);
|
|
3774
|
+
lazyVideoObserverByElement.set(video, observer);
|
|
3775
|
+
video.setAttribute("data-rx-lazy-observed", "true");
|
|
3776
|
+
video.setAttribute("data-resux-observed", "true");
|
|
3777
|
+
observer.observe(video);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
function getLazyVideoObserver(video) {
|
|
3782
|
+
if (typeof IntersectionObserver !== "function") {
|
|
3783
|
+
return null;
|
|
3784
|
+
}
|
|
3785
|
+
const rootMargin = video.getAttribute("data-rx-lazy-root-margin") || "320px 0px";
|
|
3786
|
+
const thresholdRaw = Number(video.getAttribute("data-rx-lazy-threshold"));
|
|
3787
|
+
const threshold = Number.isFinite(thresholdRaw) ? Math.min(1, Math.max(0, thresholdRaw)) : 0;
|
|
3788
|
+
const key = rootMargin + "|" + String(threshold);
|
|
3789
|
+
if (lazyVideoObservers.has(key)) {
|
|
3790
|
+
return lazyVideoObservers.get(key);
|
|
3791
|
+
}
|
|
3792
|
+
const observer = new IntersectionObserver((entries) => {
|
|
3793
|
+
for (const entry of entries) {
|
|
3794
|
+
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
3795
|
+
continue;
|
|
3796
|
+
}
|
|
3797
|
+
const target = entry.target;
|
|
3798
|
+
observer.unobserve(target);
|
|
3799
|
+
revealDeferredLazyVideo(target);
|
|
3800
|
+
}
|
|
3801
|
+
}, { rootMargin, threshold });
|
|
3802
|
+
lazyVideoObservers.set(key, observer);
|
|
3803
|
+
return observer;
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
function revealDeferredLazyVideo(video) {
|
|
3807
|
+
if (!video || !isManagedMediaConnected(video)) {
|
|
3808
|
+
return;
|
|
3809
|
+
}
|
|
3810
|
+
unobserveLazyVideo(video);
|
|
3811
|
+
|
|
3812
|
+
if (
|
|
3813
|
+
video.getAttribute("data-rx-lazy-ready") === "true"
|
|
3814
|
+
|| video.getAttribute("data-resux-loaded") === "true"
|
|
3815
|
+
|| video.getAttribute("data-resux-error-handled") === "true"
|
|
3816
|
+
) {
|
|
3817
|
+
return;
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
const targetSrc = video.getAttribute("data-rx-lazy-src") || video.getAttribute("data-src") || "";
|
|
3821
|
+
if (targetSrc && mediaSourceWasFailed(video, targetSrc)) {
|
|
3822
|
+
applyKnownVideoFailure(video, targetSrc);
|
|
3823
|
+
return;
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
dispatchManagedEvent(video, "lazy-load-start");
|
|
3827
|
+
|
|
3828
|
+
const preload = video.getAttribute("data-rx-lazy-preload") || "metadata";
|
|
3829
|
+
video.setAttribute("preload", preload);
|
|
3830
|
+
const sourceNodes = video.querySelectorAll
|
|
3831
|
+
? video.querySelectorAll("source[data-rx-lazy-src]")
|
|
3832
|
+
: [];
|
|
3833
|
+
sourceNodes.forEach((source) => {
|
|
3834
|
+
const nextSrc = source.getAttribute("data-rx-lazy-src");
|
|
3835
|
+
if (nextSrc && !mediaSourceWasFailed(video, nextSrc)) {
|
|
3836
|
+
source.setAttribute("src", nextSrc);
|
|
3837
|
+
}
|
|
3838
|
+
source.removeAttribute("data-rx-lazy-src");
|
|
3839
|
+
source.removeAttribute("data-src");
|
|
3840
|
+
});
|
|
3841
|
+
if (targetSrc && sourceNodes.length === 0 && shouldAssignMediaSource(video, targetSrc)) {
|
|
3842
|
+
video.setAttribute("src", targetSrc);
|
|
3843
|
+
}
|
|
3844
|
+
video.removeAttribute("data-rx-lazy-src");
|
|
3845
|
+
video.removeAttribute("data-src");
|
|
3846
|
+
video.removeAttribute("data-rx-lazy-video");
|
|
3847
|
+
video.setAttribute("data-rx-lazy-pending", "true");
|
|
3848
|
+
video.setAttribute("data-rx-lazy-ready", "true");
|
|
3849
|
+
video.setAttribute("data-resux-loading", "true");
|
|
3850
|
+
video.setAttribute("data-resux-video-loading", "true");
|
|
3851
|
+
|
|
3852
|
+
if (typeof video.load === "function" && video.getAttribute("data-rx-load-called") !== "true") {
|
|
3853
|
+
video.setAttribute("data-rx-load-called", "true");
|
|
3854
|
+
try {
|
|
3855
|
+
video.load();
|
|
3856
|
+
} catch {
|
|
3857
|
+
// Ignore load() runtime failures from older browsers.
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
if (shouldAutoplayManagedVideo(video)) {
|
|
3861
|
+
attemptManagedVideoPlay(video);
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
function applyReducedMotionVideoPreference(root = document) {
|
|
3866
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
3867
|
+
return;
|
|
3868
|
+
}
|
|
3869
|
+
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
3870
|
+
return;
|
|
3871
|
+
}
|
|
3872
|
+
const videos = root.querySelectorAll ? root.querySelectorAll("video[data-rx-respect-reduced-motion='true']") : [];
|
|
3873
|
+
videos.forEach((video) => {
|
|
3874
|
+
if (video.getAttribute("data-rx-force-autoplay") === "true") {
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
video.removeAttribute("autoplay");
|
|
3878
|
+
if (typeof video.pause === "function") {
|
|
3879
|
+
video.pause();
|
|
3880
|
+
}
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
function shouldAutoplayManagedVideo(video) {
|
|
3885
|
+
if (video.getAttribute("data-rx-autoplay-requested") !== "true") {
|
|
3886
|
+
return false;
|
|
3887
|
+
}
|
|
3888
|
+
if (video.getAttribute("data-rx-force-autoplay") === "true") {
|
|
3889
|
+
return true;
|
|
3890
|
+
}
|
|
3891
|
+
if (video.getAttribute("data-rx-respect-reduced-motion") !== "true") {
|
|
3892
|
+
return true;
|
|
3893
|
+
}
|
|
3894
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
3895
|
+
return true;
|
|
3896
|
+
}
|
|
3897
|
+
return !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
function attemptManagedVideoPlay(video) {
|
|
3901
|
+
if (!video || video.getAttribute("data-rx-play-attempted") === "true") {
|
|
3902
|
+
return;
|
|
3903
|
+
}
|
|
3904
|
+
video.setAttribute("data-rx-play-attempted", "true");
|
|
3905
|
+
if (typeof video.play !== "function") {
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3908
|
+
const playResult = video.play();
|
|
3909
|
+
if (playResult && typeof playResult.catch === "function") {
|
|
3910
|
+
playResult.catch(() => {});
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
function dispatchManagedEvent(target, name, detail = {}) {
|
|
3915
|
+
if (!target || typeof target.dispatchEvent !== "function") {
|
|
3916
|
+
return;
|
|
3917
|
+
}
|
|
3918
|
+
const view = target.ownerDocument?.defaultView ?? (typeof window !== "undefined" ? window : undefined);
|
|
3919
|
+
const CustomEventCtor = view && typeof view.CustomEvent === "function"
|
|
3920
|
+
? view.CustomEvent
|
|
3921
|
+
: null;
|
|
3922
|
+
if (!CustomEventCtor) {
|
|
3923
|
+
return;
|
|
3924
|
+
}
|
|
3925
|
+
target.dispatchEvent(new CustomEventCtor(name, { bubbles: true, detail }));
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
function handleManagedMediaLoad(event) {
|
|
3929
|
+
const target = event && event.target;
|
|
3930
|
+
if (!target || !target.tagName) {
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
const tag = String(target.tagName).toLowerCase();
|
|
3934
|
+
if (tag !== "img") {
|
|
3935
|
+
return;
|
|
3936
|
+
}
|
|
3937
|
+
if (target.getAttribute("data-rx-lazy-image") === "true" && target.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
3938
|
+
return;
|
|
3939
|
+
}
|
|
3940
|
+
if (target.getAttribute("data-rx-lazy-pending") === "true") {
|
|
3941
|
+
target.removeAttribute("data-rx-lazy-pending");
|
|
3942
|
+
dispatchManagedEvent(target, "lazy-load-complete");
|
|
3943
|
+
}
|
|
3944
|
+
target.setAttribute("data-resux-loaded", "true");
|
|
3945
|
+
target.removeAttribute("data-resux-loading");
|
|
3946
|
+
clearManagedPlaceholderState(target);
|
|
3947
|
+
}
|
|
3948
|
+
|
|
3949
|
+
function handleManagedVideoReady(event) {
|
|
3950
|
+
const target = event && event.target;
|
|
3951
|
+
if (!target || !target.tagName || String(target.tagName).toLowerCase() !== "video") {
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
if ((event.type === "loadedmetadata" || event.type === "canplay") && shouldAutoplayManagedVideo(target)) {
|
|
3956
|
+
attemptManagedVideoPlay(target);
|
|
3957
|
+
}
|
|
3958
|
+
if (event.type !== "loadedmetadata" && event.type !== "loadeddata" && event.type !== "canplay") {
|
|
3959
|
+
return;
|
|
3960
|
+
}
|
|
3961
|
+
if (target.getAttribute("data-rx-lazy-pending") === "true") {
|
|
3962
|
+
target.removeAttribute("data-rx-lazy-pending");
|
|
3963
|
+
dispatchManagedEvent(target, "lazy-load-complete");
|
|
3964
|
+
}
|
|
3965
|
+
target.setAttribute("data-resux-loaded", "true");
|
|
3966
|
+
target.removeAttribute("data-resux-loading");
|
|
3967
|
+
target.removeAttribute("data-resux-video-loading");
|
|
3968
|
+
clearManagedPlaceholderState(target);
|
|
3969
|
+
if (target.getAttribute("data-rx-placeholder-src")) {
|
|
3970
|
+
const realPoster = target.getAttribute("data-rx-poster");
|
|
3971
|
+
if (realPoster) {
|
|
3972
|
+
target.setAttribute("poster", realPoster);
|
|
3973
|
+
} else {
|
|
3974
|
+
target.removeAttribute("poster");
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
function handleManagedMediaError(event) {
|
|
3980
|
+
const target = event && event.target;
|
|
3981
|
+
if (!target || !target.tagName) {
|
|
3982
|
+
return;
|
|
3983
|
+
}
|
|
3984
|
+
const tag = String(target.tagName).toLowerCase();
|
|
3985
|
+
if (tag === "img") {
|
|
3986
|
+
handleManagedImageError(target);
|
|
3987
|
+
return;
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
if (tag === "source") {
|
|
3991
|
+
const parentVideo = target.parentElement && String(target.parentElement.tagName || "").toLowerCase() === "video"
|
|
3992
|
+
? target.parentElement
|
|
3993
|
+
: null;
|
|
3994
|
+
if (parentVideo) {
|
|
3995
|
+
markFailedMediaSource(parentVideo, target.getAttribute("src") || target.getAttribute("data-rx-lazy-src") || "");
|
|
3996
|
+
}
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
if (tag === "video") {
|
|
4001
|
+
handleManagedVideoError(target);
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
function handleManagedImageError(target) {
|
|
4006
|
+
if (!isManagedMediaConnected(target)) {
|
|
4007
|
+
return;
|
|
4008
|
+
}
|
|
4009
|
+
if (target.getAttribute("data-rx-lazy-image") === "true" && target.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
4010
|
+
return;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
unobserveLazyImage(target);
|
|
4014
|
+
const failedSrc = getCurrentMediaUrl(target) || target.getAttribute("data-rx-lazy-src") || "";
|
|
4015
|
+
markFailedMediaSource(target, failedSrc);
|
|
4016
|
+
target.setAttribute("data-resux-error", "true");
|
|
4017
|
+
target.setAttribute("data-rx-error", "true");
|
|
4018
|
+
target.removeAttribute("data-resux-loading");
|
|
4019
|
+
disablePictureSources(target);
|
|
4020
|
+
|
|
4021
|
+
const fallbackSrc = target.getAttribute("data-rx-fallback-src");
|
|
4022
|
+
if (target.getAttribute("data-resux-error-handled") === "true") {
|
|
4023
|
+
if (
|
|
4024
|
+
target.getAttribute("data-rx-fallback-active") === "true"
|
|
4025
|
+
&& fallbackSrc
|
|
4026
|
+
&& mediaUrlsEqual(failedSrc, fallbackSrc, target)
|
|
4027
|
+
) {
|
|
4028
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4029
|
+
}
|
|
4030
|
+
return;
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
if (fallbackSrc && shouldAssignMediaSource(target, fallbackSrc)) {
|
|
4034
|
+
markMediaErrorHandled(target);
|
|
4035
|
+
target.setAttribute("data-rx-fallback-used", "true");
|
|
4036
|
+
target.setAttribute("data-rx-fallback-active", "true");
|
|
4037
|
+
target.setAttribute("data-resux-fallback-active", "true");
|
|
4038
|
+
target.removeAttribute("srcset");
|
|
4039
|
+
target.removeAttribute("sizes");
|
|
4040
|
+
target.removeAttribute("data-rx-lazy-srcset");
|
|
4041
|
+
target.removeAttribute("data-rx-lazy-sizes");
|
|
4042
|
+
target.setAttribute("src", fallbackSrc);
|
|
4043
|
+
return;
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
markMediaErrorHandled(target);
|
|
4047
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
function applyKnownImageFailure(target, failedSrc) {
|
|
4051
|
+
markFailedMediaSource(target, failedSrc);
|
|
4052
|
+
target.setAttribute("data-resux-error", "true");
|
|
4053
|
+
target.setAttribute("data-rx-error", "true");
|
|
4054
|
+
target.removeAttribute("data-resux-loading");
|
|
4055
|
+
disablePictureSources(target);
|
|
4056
|
+
const fallbackSrc = target.getAttribute("data-rx-fallback-src");
|
|
4057
|
+
markMediaErrorHandled(target);
|
|
4058
|
+
if (fallbackSrc && shouldAssignMediaSource(target, fallbackSrc)) {
|
|
4059
|
+
target.setAttribute("data-rx-fallback-used", "true");
|
|
4060
|
+
target.setAttribute("data-rx-fallback-active", "true");
|
|
4061
|
+
target.setAttribute("data-resux-fallback-active", "true");
|
|
4062
|
+
target.removeAttribute("srcset");
|
|
4063
|
+
target.removeAttribute("sizes");
|
|
4064
|
+
target.setAttribute("src", fallbackSrc);
|
|
4065
|
+
return;
|
|
4066
|
+
}
|
|
4067
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
function handleManagedVideoError(video) {
|
|
4071
|
+
if (!isManagedMediaConnected(video)) {
|
|
4072
|
+
return;
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
const failedSrc = getCurrentVideoUrl(video);
|
|
4076
|
+
markFailedMediaSource(video, failedSrc);
|
|
4077
|
+
video.setAttribute("data-resux-error", "true");
|
|
4078
|
+
video.setAttribute("data-rx-error", "true");
|
|
4079
|
+
video.removeAttribute("data-resux-loading");
|
|
4080
|
+
video.removeAttribute("data-resux-video-loading");
|
|
4081
|
+
|
|
4082
|
+
if (video.getAttribute("data-rx-lazy-video") === "true" && video.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
4083
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
|
|
4087
|
+
unobserveLazyVideo(video);
|
|
4088
|
+
if (video.getAttribute("data-resux-error-handled") === "true") {
|
|
4089
|
+
return;
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
markMediaErrorHandled(video);
|
|
4093
|
+
clearManagedVideoSources(video);
|
|
4094
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
function applyKnownVideoFailure(video, failedSrc) {
|
|
4098
|
+
markFailedMediaSource(video, failedSrc);
|
|
4099
|
+
video.setAttribute("data-resux-error", "true");
|
|
4100
|
+
video.setAttribute("data-rx-error", "true");
|
|
4101
|
+
video.removeAttribute("data-resux-loading");
|
|
4102
|
+
video.removeAttribute("data-resux-video-loading");
|
|
4103
|
+
markMediaErrorHandled(video);
|
|
4104
|
+
clearManagedVideoSources(video);
|
|
4105
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4106
|
+
}
|
|
4107
|
+
|
|
4108
|
+
function applyVideoPosterFallback(video, failedSrc) {
|
|
4109
|
+
const fallbackPoster = video.getAttribute("data-rx-fallback-poster");
|
|
4110
|
+
if (fallbackPoster && !mediaUrlsEqual(video.getAttribute("poster") || "", fallbackPoster, video)) {
|
|
4111
|
+
video.setAttribute("poster", fallbackPoster);
|
|
4112
|
+
video.setAttribute("data-rx-fallback-active", "true");
|
|
4113
|
+
video.setAttribute("data-resux-fallback-active", "true");
|
|
4114
|
+
return;
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
const placeholder = video.getAttribute("data-rx-placeholder-src");
|
|
4118
|
+
if (placeholder && !mediaUrlsEqual(placeholder, failedSrc, video)) {
|
|
4119
|
+
video.setAttribute("poster", placeholder);
|
|
4120
|
+
video.setAttribute("data-rx-placeholder-active", "true");
|
|
4121
|
+
video.setAttribute("data-resux-placeholder-active", "true");
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
function showManagedImagePlaceholder(target, failedSrc) {
|
|
4126
|
+
const placeholder = target.getAttribute("data-rx-placeholder-src");
|
|
4127
|
+
if (placeholder && shouldAssignMediaSource(target, placeholder) && !mediaUrlsEqual(placeholder, failedSrc, target)) {
|
|
4128
|
+
target.removeAttribute("srcset");
|
|
4129
|
+
target.removeAttribute("sizes");
|
|
4130
|
+
target.setAttribute("src", placeholder);
|
|
4131
|
+
target.setAttribute("data-rx-placeholder-active", "true");
|
|
4132
|
+
target.setAttribute("data-resux-placeholder-active", "true");
|
|
4133
|
+
return;
|
|
4134
|
+
}
|
|
4135
|
+
target.setAttribute("data-rx-placeholder-active", "true");
|
|
4136
|
+
target.setAttribute("data-resux-placeholder-active", "true");
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
function disablePictureSources(image) {
|
|
4140
|
+
const picture = image.closest ? image.closest("picture") : null;
|
|
4141
|
+
if (!picture || !picture.querySelectorAll) {
|
|
4142
|
+
return;
|
|
4143
|
+
}
|
|
4144
|
+
picture.setAttribute("data-resux-error", "true");
|
|
4145
|
+
picture.querySelectorAll("source").forEach((source) => {
|
|
4146
|
+
const srcset = source.getAttribute("srcset") || source.getAttribute("data-rx-lazy-srcset");
|
|
4147
|
+
if (srcset) {
|
|
4148
|
+
source.setAttribute("data-rx-failed-srcset", srcset);
|
|
4149
|
+
}
|
|
4150
|
+
source.removeAttribute("srcset");
|
|
4151
|
+
source.removeAttribute("sizes");
|
|
4152
|
+
source.removeAttribute("data-rx-lazy-srcset");
|
|
4153
|
+
source.removeAttribute("data-rx-lazy-sizes");
|
|
4154
|
+
source.removeAttribute("data-srcset");
|
|
4155
|
+
});
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
function clearManagedVideoSources(video) {
|
|
4159
|
+
if (typeof video.pause === "function") {
|
|
4160
|
+
try {
|
|
4161
|
+
video.pause();
|
|
4162
|
+
} catch {}
|
|
4163
|
+
}
|
|
4164
|
+
video.removeAttribute("src");
|
|
4165
|
+
video.removeAttribute("data-rx-lazy-src");
|
|
4166
|
+
video.removeAttribute("data-src");
|
|
4167
|
+
if (video.querySelectorAll) {
|
|
4168
|
+
video.querySelectorAll("source").forEach((source) => {
|
|
4169
|
+
const src = source.getAttribute("src") || source.getAttribute("data-rx-lazy-src");
|
|
4170
|
+
if (src) {
|
|
4171
|
+
source.setAttribute("data-rx-failed-src", src);
|
|
4172
|
+
}
|
|
4173
|
+
source.removeAttribute("src");
|
|
4174
|
+
source.removeAttribute("data-rx-lazy-src");
|
|
4175
|
+
source.removeAttribute("data-src");
|
|
4176
|
+
});
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
function clearManagedPlaceholderState(target) {
|
|
4181
|
+
clearManagedPlaceholderStyle(target);
|
|
4182
|
+
const placeholderClass = target.getAttribute("data-rx-placeholder-class");
|
|
4183
|
+
if (placeholderClass && target.classList) {
|
|
4184
|
+
for (const token of placeholderClass.split(/\s+/).filter(Boolean)) {
|
|
4185
|
+
target.classList.remove(token);
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
target.removeAttribute("data-rx-placeholder-active");
|
|
4189
|
+
target.removeAttribute("data-resux-placeholder-active");
|
|
4190
|
+
}
|
|
4191
|
+
|
|
4192
|
+
function clearManagedPlaceholderStyle(target) {
|
|
4193
|
+
const style = target && target.getAttribute ? target.getAttribute("style") : "";
|
|
4194
|
+
if (!style) {
|
|
4195
|
+
return;
|
|
4196
|
+
}
|
|
4197
|
+
const placeholderStyle = target.getAttribute("data-rx-placeholder-style") || "";
|
|
4198
|
+
const nextStyle = style
|
|
4199
|
+
.replace(/background-image\s*:[^;]+;?/gi, "")
|
|
4200
|
+
.replace(/background-size\s*:[^;]+;?/gi, "")
|
|
4201
|
+
.replace(/background-position\s*:[^;]+;?/gi, "")
|
|
4202
|
+
.replace(/background-repeat\s*:[^;]+;?/gi, "")
|
|
4203
|
+
.split(";")
|
|
4204
|
+
.map((entry) => entry.trim())
|
|
4205
|
+
.filter((entry) => entry && !placeholderStyle.split(";").map((item) => item.trim()).filter(Boolean).includes(entry))
|
|
4206
|
+
.join("; ")
|
|
4207
|
+
.replace(/\s{2,}/g, " ")
|
|
4208
|
+
.trim()
|
|
4209
|
+
.replace(/;+$/g, "");
|
|
4210
|
+
if (!nextStyle) {
|
|
4211
|
+
target.removeAttribute("style");
|
|
4212
|
+
return;
|
|
4213
|
+
}
|
|
4214
|
+
target.setAttribute("style", nextStyle);
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
function shouldAssignMediaSource(target, nextSrc) {
|
|
4218
|
+
if (!nextSrc || mediaSourceWasFailed(target, nextSrc)) {
|
|
4219
|
+
return false;
|
|
4220
|
+
}
|
|
4221
|
+
const current = getCurrentMediaUrl(target);
|
|
4222
|
+
if (current && mediaUrlsEqual(current, nextSrc, target)) {
|
|
4223
|
+
return false;
|
|
4224
|
+
}
|
|
4225
|
+
const attrSrc = target.getAttribute ? target.getAttribute("src") : "";
|
|
4226
|
+
if (attrSrc && mediaUrlsEqual(attrSrc, nextSrc, target)) {
|
|
4227
|
+
return false;
|
|
4228
|
+
}
|
|
4229
|
+
return true;
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4232
|
+
function getCurrentMediaUrl(target) {
|
|
4233
|
+
return String(target?.currentSrc || target?.getAttribute?.("src") || "");
|
|
4234
|
+
}
|
|
4235
|
+
|
|
4236
|
+
function getCurrentVideoUrl(video) {
|
|
4237
|
+
const direct = String(video?.currentSrc || video?.getAttribute?.("src") || "");
|
|
4238
|
+
if (direct) {
|
|
4239
|
+
return direct;
|
|
4240
|
+
}
|
|
4241
|
+
const source = video?.querySelector ? video.querySelector("source[src], source[data-rx-lazy-src]") : null;
|
|
4242
|
+
return String(source?.getAttribute("src") || source?.getAttribute("data-rx-lazy-src") || "");
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
function markFailedMediaSource(target, src) {
|
|
4246
|
+
if (!target || !src) {
|
|
4247
|
+
return;
|
|
4248
|
+
}
|
|
4249
|
+
target.setAttribute("data-rx-failed-src", src);
|
|
4250
|
+
target.setAttribute("data-resux-failed-src", src);
|
|
4251
|
+
for (const candidate of mediaSourceCandidates(src)) {
|
|
4252
|
+
const normalized = normalizeMediaUrl(candidate, target);
|
|
4253
|
+
if (normalized) {
|
|
4254
|
+
failedMediaSources.add(normalized);
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
4257
|
+
}
|
|
4258
|
+
|
|
4259
|
+
function markMediaErrorHandled(target) {
|
|
4260
|
+
target.setAttribute("data-rx-error-handled", "true");
|
|
4261
|
+
target.setAttribute("data-resux-error-handled", "true");
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
function mediaSourceWasFailed(target, src) {
|
|
4265
|
+
const failed = target?.getAttribute?.("data-rx-failed-src") || target?.getAttribute?.("data-resux-failed-src") || "";
|
|
4266
|
+
if (failed && src && mediaUrlsEqual(failed, src, target)) {
|
|
4267
|
+
return true;
|
|
4268
|
+
}
|
|
4269
|
+
return mediaSourceCandidates(src).some((candidate) => {
|
|
4270
|
+
const normalized = normalizeMediaUrl(candidate, target);
|
|
4271
|
+
return Boolean(normalized && failedMediaSources.has(normalized));
|
|
4272
|
+
});
|
|
4273
|
+
}
|
|
4274
|
+
|
|
4275
|
+
function mediaSourceCandidates(value) {
|
|
4276
|
+
const raw = String(value || "").trim();
|
|
4277
|
+
if (!raw) {
|
|
4278
|
+
return [];
|
|
4279
|
+
}
|
|
4280
|
+
if (!raw.includes(",")) {
|
|
4281
|
+
return [raw.split(/\s+/)[0]].filter(Boolean);
|
|
4282
|
+
}
|
|
4283
|
+
return raw
|
|
4284
|
+
.split(",")
|
|
4285
|
+
.map((entry) => entry.trim().split(/\s+/)[0])
|
|
4286
|
+
.filter(Boolean);
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
function mediaUrlsEqual(left, right, target) {
|
|
4290
|
+
const normalizedLeft = normalizeMediaUrl(left, target);
|
|
4291
|
+
const normalizedRight = normalizeMediaUrl(right, target);
|
|
4292
|
+
return Boolean(normalizedLeft && normalizedRight && normalizedLeft === normalizedRight);
|
|
4293
|
+
}
|
|
4294
|
+
|
|
4295
|
+
function normalizeMediaUrl(value, target) {
|
|
4296
|
+
const raw = String(value || "").trim();
|
|
4297
|
+
if (!raw) {
|
|
4298
|
+
return "";
|
|
4299
|
+
}
|
|
4300
|
+
try {
|
|
4301
|
+
const view = target?.ownerDocument?.defaultView || (typeof window !== "undefined" ? window : null);
|
|
4302
|
+
const base = view?.location?.href || (typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
4303
|
+
return new URL(raw, base).href;
|
|
4304
|
+
} catch {
|
|
4305
|
+
return raw;
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
function isManagedMediaConnected(target) {
|
|
4310
|
+
if (!target) {
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
if (target.isConnected === true) {
|
|
4314
|
+
return true;
|
|
4315
|
+
}
|
|
4316
|
+
const root = target.ownerDocument && target.ownerDocument.documentElement;
|
|
4317
|
+
return Boolean(root && root.contains && root.contains(target));
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4320
|
+
function unobserveLazyImage(image) {
|
|
4321
|
+
const observer = lazyImageObserverByElement.get(image);
|
|
4322
|
+
if (observer) {
|
|
4323
|
+
observer.unobserve(image);
|
|
4324
|
+
}
|
|
4325
|
+
observedLazyImages.delete(image);
|
|
4326
|
+
lazyImageObserverByElement.delete(image);
|
|
4327
|
+
image.removeAttribute("data-rx-lazy-observed");
|
|
4328
|
+
image.removeAttribute("data-resux-observed");
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4331
|
+
function unobserveLazyVideo(video) {
|
|
4332
|
+
const observer = lazyVideoObserverByElement.get(video);
|
|
4333
|
+
if (observer) {
|
|
4334
|
+
observer.unobserve(video);
|
|
4335
|
+
}
|
|
4336
|
+
observedLazyVideos.delete(video);
|
|
4337
|
+
lazyVideoObserverByElement.delete(video);
|
|
4338
|
+
video.removeAttribute("data-rx-lazy-observed");
|
|
4339
|
+
video.removeAttribute("data-resux-observed");
|
|
4340
|
+
}
|
|
4341
|
+
|
|
4342
|
+
function cleanupDetachedLazyMedia() {
|
|
4343
|
+
for (const image of Array.from(observedLazyImages)) {
|
|
4344
|
+
if (!isManagedMediaConnected(image)) {
|
|
4345
|
+
unobserveLazyImage(image);
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4348
|
+
for (const video of Array.from(observedLazyVideos)) {
|
|
4349
|
+
if (!isManagedMediaConnected(video)) {
|
|
4350
|
+
unobserveLazyVideo(video);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
function dispatchPageReadyEvent(root) {
|
|
4356
|
+
const target = root && typeof root.dispatchEvent === "function" ? root : document;
|
|
4357
|
+
dispatchManagedEvent(target, "resux:page-ready", { root });
|
|
2826
4358
|
}
|
|
2827
4359
|
|
|
2828
4360
|
function createAsyncDataResource(value, pending = false, error = null) {
|
|
@@ -3171,7 +4703,7 @@ async function navigateTo(target, options = {}) {
|
|
|
3171
4703
|
const routePath = nextUrl.pathname + nextUrl.search;
|
|
3172
4704
|
const currentUrl = new URL(location.href);
|
|
3173
4705
|
const currentRoutePath = currentUrl.pathname + currentUrl.search;
|
|
3174
|
-
if (routePath === currentRoutePath && nextUrl.hash === currentUrl.hash) {
|
|
4706
|
+
if (!options.force && routePath === currentRoutePath && nextUrl.hash === currentUrl.hash) {
|
|
3175
4707
|
return;
|
|
3176
4708
|
}
|
|
3177
4709
|
const transitionToken = ++routeTransitionToken;
|
|
@@ -3215,8 +4747,7 @@ async function navigateTo(target, options = {}) {
|
|
|
3215
4747
|
|
|
3216
4748
|
const root = document.getElementById("__resux");
|
|
3217
4749
|
if (!root) {
|
|
3218
|
-
|
|
3219
|
-
return;
|
|
4750
|
+
throw new Error("Missing Resux root for client navigation.");
|
|
3220
4751
|
}
|
|
3221
4752
|
|
|
3222
4753
|
if (transitionToken !== routeTransitionToken) {
|
|
@@ -3237,21 +4768,25 @@ async function navigateTo(target, options = {}) {
|
|
|
3237
4768
|
clearScopeCacheExcept(preserved.scopeIds);
|
|
3238
4769
|
void resumePendingAsyncData();
|
|
3239
4770
|
void mountVueIslands(preserved.root);
|
|
3240
|
-
|
|
4771
|
+
activateDeferredLazyMedia(preserved.root);
|
|
4772
|
+
applyReducedMotionVideoPreference(preserved.root);
|
|
3241
4773
|
|
|
3242
|
-
if (nextUrl.hash) {
|
|
3243
|
-
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
3244
|
-
} else if (typeof scrollTo === "function") {
|
|
3245
|
-
scrollTo(0, 0);
|
|
3246
|
-
}
|
|
4774
|
+
if (!options.preserveScroll && nextUrl.hash) {
|
|
4775
|
+
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
4776
|
+
} else if (!options.preserveScroll && typeof scrollTo === "function") {
|
|
4777
|
+
scrollTo(0, 0);
|
|
4778
|
+
}
|
|
3247
4779
|
if (transitionToken === routeTransitionToken) {
|
|
3248
4780
|
setRouteTransition("complete", { path: routePath });
|
|
3249
4781
|
completed = true;
|
|
3250
4782
|
}
|
|
3251
|
-
} catch {
|
|
3252
|
-
setRouteTransition("error", { path: routePath });
|
|
3253
|
-
|
|
3254
|
-
|
|
4783
|
+
} catch (error) {
|
|
4784
|
+
setRouteTransition("error", { path: routePath });
|
|
4785
|
+
dispatchManagedEvent(document, "resux:navigation-error", {
|
|
4786
|
+
path: routePath,
|
|
4787
|
+
message: error instanceof Error ? error.message : String(error)
|
|
4788
|
+
});
|
|
4789
|
+
} finally {
|
|
3255
4790
|
if (!completed && transitionToken === routeTransitionToken) {
|
|
3256
4791
|
setRouteTransition("idle", { path: routePath });
|
|
3257
4792
|
}
|
|
@@ -3753,7 +5288,7 @@ function collectPatches(nodes, scope, locals, patches, styleScopeId) {
|
|
|
3753
5288
|
if (node.html) {
|
|
3754
5289
|
patches.push({ type: "html", id: node.html.bindingId, value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals)) });
|
|
3755
5290
|
}
|
|
3756
|
-
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
5291
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture" && node.tag !== "ResuxVideo") {
|
|
3757
5292
|
for (const attr of node.attrs) {
|
|
3758
5293
|
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
3759
5294
|
const attrName = nativeAttributeName(node, attr.name);
|
|
@@ -3799,6 +5334,9 @@ function renderElement(node, scope, locals, styleScopeId) {
|
|
|
3799
5334
|
if (node.tag === "ResuxPicture") {
|
|
3800
5335
|
return renderClientResuxPicture(node, scope, locals, styleScopeId);
|
|
3801
5336
|
}
|
|
5337
|
+
if (node.tag === "ResuxVideo") {
|
|
5338
|
+
return renderClientResuxVideo(node, scope, locals, styleScopeId);
|
|
5339
|
+
}
|
|
3802
5340
|
const tag = nativeElementTag(node);
|
|
3803
5341
|
const attrs = [];
|
|
3804
5342
|
for (const attr of node.attrs) {
|
|
@@ -3836,6 +5374,7 @@ const clientImageReservedProps = new Set([
|
|
|
3836
5374
|
"src",
|
|
3837
5375
|
"alt",
|
|
3838
5376
|
"provider",
|
|
5377
|
+
"cache",
|
|
3839
5378
|
"modifiers",
|
|
3840
5379
|
"quality",
|
|
3841
5380
|
"fit",
|
|
@@ -3852,8 +5391,176 @@ const clientImageReservedProps = new Set([
|
|
|
3852
5391
|
"loading",
|
|
3853
5392
|
"decoding",
|
|
3854
5393
|
"fetchpriority",
|
|
3855
|
-
"fetchPriority"
|
|
5394
|
+
"fetchPriority",
|
|
5395
|
+
"placeholder",
|
|
5396
|
+
"placeholderClass",
|
|
5397
|
+
"placeholderStyle",
|
|
5398
|
+
"fallback",
|
|
5399
|
+
"fallbackSrc",
|
|
5400
|
+
"sources",
|
|
5401
|
+
"rootMargin",
|
|
5402
|
+
"threshold"
|
|
3856
5403
|
]);
|
|
5404
|
+
const RESUX_CLIENT_RESPONSIVE_VIEWPORT_WIDTHS = [320, 640, 768, 1024, 1280, 1536, 1920, 2560];
|
|
5405
|
+
|
|
5406
|
+
function renderClientResuxVideo(node, scope, locals, styleScopeId) {
|
|
5407
|
+
const props = {};
|
|
5408
|
+
for (const attr of node.attrs) {
|
|
5409
|
+
const normalizedName = attr.name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
5410
|
+
props[normalizedName] = attr.kind === "static"
|
|
5411
|
+
? attr.value
|
|
5412
|
+
: evaluateExpression(attr.value, scope, locals);
|
|
5413
|
+
}
|
|
5414
|
+
const explicitLoading = readClientStringProp(props.loading);
|
|
5415
|
+
const explicitLazy = props.lazy === undefined
|
|
5416
|
+
? undefined
|
|
5417
|
+
: readClientBooleanProp(props.lazy, true);
|
|
5418
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : false);
|
|
5419
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true || lazy;
|
|
5420
|
+
const src = readClientStringProp(props.src);
|
|
5421
|
+
const poster = readClientStringProp(props.poster);
|
|
5422
|
+
const fallbackPoster = readClientStringProp(props.fallbackPoster);
|
|
5423
|
+
const width = readClientNumberProp(props.width);
|
|
5424
|
+
const height = readClientNumberProp(props.height);
|
|
5425
|
+
const placeholderSrc = resolveClientPlaceholderSource(props.placeholder);
|
|
5426
|
+
const preload = readClientStringProp(props.preload) || "metadata";
|
|
5427
|
+
const ariaLabel = readClientStringProp(props.ariaLabel || props["aria-label"]);
|
|
5428
|
+
const rootMargin = readClientStringProp(props.rootMargin) || "320px 0px";
|
|
5429
|
+
const thresholdRaw = Number(props.threshold);
|
|
5430
|
+
const threshold = Number.isFinite(thresholdRaw)
|
|
5431
|
+
? Math.min(1, Math.max(0, thresholdRaw))
|
|
5432
|
+
: 0;
|
|
5433
|
+
const forceAutoplay = readClientBooleanProp(props.forceAutoplay, false);
|
|
5434
|
+
const autoplay = readClientBooleanProp(props.autoplay, false);
|
|
5435
|
+
const resolvedSources = resolveClientVideoSources(props.sources);
|
|
5436
|
+
const hasSourceChildren = resolvedSources.length > 0;
|
|
5437
|
+
const styleParts = [];
|
|
5438
|
+
if (typeof props.style === "string" && props.style.trim()) {
|
|
5439
|
+
styleParts.push(props.style.trim().replace(/;+\s*$/, ""));
|
|
5440
|
+
}
|
|
5441
|
+
if (props.aspectRatio !== undefined && props.aspectRatio !== null && props.aspectRatio !== false) {
|
|
5442
|
+
const aspectValue = String(props.aspectRatio).trim();
|
|
5443
|
+
if (aspectValue) {
|
|
5444
|
+
styleParts.push("aspect-ratio: " + aspectValue);
|
|
5445
|
+
}
|
|
5446
|
+
} else {
|
|
5447
|
+
const ratioStyle = resolveClientAspectRatioStyle(width, height, props.style);
|
|
5448
|
+
if (ratioStyle) {
|
|
5449
|
+
styleParts.push(ratioStyle);
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
styleParts.push("display: block");
|
|
5453
|
+
styleParts.push("width: 100%");
|
|
5454
|
+
styleParts.push("max-width: 100%");
|
|
5455
|
+
if (!styleParts.some((entry) => /(^|;)\s*height\s*:/.test(entry))) {
|
|
5456
|
+
styleParts.push("height: auto");
|
|
5457
|
+
}
|
|
5458
|
+
const attrs = [];
|
|
5459
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
5460
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
5461
|
+
continue;
|
|
5462
|
+
}
|
|
5463
|
+
if (
|
|
5464
|
+
name === "aspectRatio"
|
|
5465
|
+
|| name === "style"
|
|
5466
|
+
|| name === "lazy"
|
|
5467
|
+
|| name === "loading"
|
|
5468
|
+
|| name === "placeholder"
|
|
5469
|
+
|| name === "fallbackPoster"
|
|
5470
|
+
|| name === "rootMargin"
|
|
5471
|
+
|| name === "threshold"
|
|
5472
|
+
|| name === "sources"
|
|
5473
|
+
|| name === "forceAutoplay"
|
|
5474
|
+
|| name === "ariaLabel"
|
|
5475
|
+
|| name === "autoplay"
|
|
5476
|
+
|| name === "src"
|
|
5477
|
+
|| name === "poster"
|
|
5478
|
+
|| name === "preload"
|
|
5479
|
+
|| name === "fallbackText"
|
|
5480
|
+
) {
|
|
5481
|
+
continue;
|
|
5482
|
+
}
|
|
5483
|
+
const attrName = name === "className"
|
|
5484
|
+
? "class"
|
|
5485
|
+
: name === "playsInline"
|
|
5486
|
+
? "playsinline"
|
|
5487
|
+
: name === "crossOrigin"
|
|
5488
|
+
? "crossorigin"
|
|
5489
|
+
: name === "referrerPolicy"
|
|
5490
|
+
? "referrerpolicy"
|
|
5491
|
+
: name;
|
|
5492
|
+
attrs.push(attrName + '="' + escapeAttribute(stringifyAttributeValue(attrName, rawValue)) + '"');
|
|
5493
|
+
}
|
|
5494
|
+
if (!hasSourceChildren && !deferLazy && src) {
|
|
5495
|
+
attrs.push('src="' + escapeAttribute(src) + '"');
|
|
5496
|
+
}
|
|
5497
|
+
attrs.push('data-resux-media="video"');
|
|
5498
|
+
if (deferLazy && src) {
|
|
5499
|
+
attrs.push('data-rx-lazy-src="' + escapeAttribute(src) + '"');
|
|
5500
|
+
attrs.push('data-src="' + escapeAttribute(src) + '"');
|
|
5501
|
+
}
|
|
5502
|
+
if (deferLazy) {
|
|
5503
|
+
attrs.push('data-rx-lazy-video="true"');
|
|
5504
|
+
attrs.push('data-resux-lazy="true"');
|
|
5505
|
+
attrs.push('data-rx-lazy-root-margin="' + escapeAttribute(rootMargin) + '"');
|
|
5506
|
+
attrs.push('data-rx-lazy-threshold="' + escapeAttribute(String(threshold)) + '"');
|
|
5507
|
+
attrs.push('data-rx-lazy-preload="' + escapeAttribute(preload) + '"');
|
|
5508
|
+
attrs.push('preload="none"');
|
|
5509
|
+
} else if (preload) {
|
|
5510
|
+
attrs.push('preload="' + escapeAttribute(preload) + '"');
|
|
5511
|
+
}
|
|
5512
|
+
if (poster) {
|
|
5513
|
+
attrs.push('data-rx-poster="' + escapeAttribute(poster) + '"');
|
|
5514
|
+
}
|
|
5515
|
+
if (fallbackPoster) {
|
|
5516
|
+
attrs.push('data-rx-fallback-poster="' + escapeAttribute(fallbackPoster) + '"');
|
|
5517
|
+
}
|
|
5518
|
+
if (placeholderSrc) {
|
|
5519
|
+
attrs.push('data-rx-placeholder-src="' + escapeAttribute(placeholderSrc) + '"');
|
|
5520
|
+
attrs.push('data-placeholder="' + escapeAttribute(placeholderSrc) + '"');
|
|
5521
|
+
attrs.push('data-rx-placeholder-active="true"');
|
|
5522
|
+
attrs.push('data-resux-placeholder-active="true"');
|
|
5523
|
+
}
|
|
5524
|
+
const initialPoster = placeholderSrc || poster;
|
|
5525
|
+
if (initialPoster) {
|
|
5526
|
+
attrs.push('poster="' + escapeAttribute(initialPoster) + '"');
|
|
5527
|
+
}
|
|
5528
|
+
if (autoplay) {
|
|
5529
|
+
attrs.push('autoplay="autoplay"');
|
|
5530
|
+
attrs.push('data-rx-autoplay-requested="true"');
|
|
5531
|
+
if (!forceAutoplay) {
|
|
5532
|
+
attrs.push('data-rx-respect-reduced-motion="true"');
|
|
5533
|
+
} else {
|
|
5534
|
+
attrs.push('data-rx-force-autoplay="true"');
|
|
5535
|
+
}
|
|
5536
|
+
}
|
|
5537
|
+
if (ariaLabel) {
|
|
5538
|
+
attrs.push('aria-label="' + escapeAttribute(ariaLabel) + '"');
|
|
5539
|
+
}
|
|
5540
|
+
if (styleParts.length > 0) {
|
|
5541
|
+
attrs.push('style="' + escapeAttribute(styleParts.join("; ")) + '"');
|
|
5542
|
+
}
|
|
5543
|
+
if (styleScopeId) {
|
|
5544
|
+
attrs.push(styleScopeId + '=""');
|
|
5545
|
+
}
|
|
5546
|
+
const attrText = attrs.length ? " " + attrs.join(" ") : "";
|
|
5547
|
+
const sourceTags = hasSourceChildren
|
|
5548
|
+
? resolvedSources
|
|
5549
|
+
.map((source) => {
|
|
5550
|
+
const sourceAttrs = deferLazy
|
|
5551
|
+
? ['data-rx-lazy-src="' + escapeAttribute(source.src) + '"', 'data-src="' + escapeAttribute(source.src) + '"']
|
|
5552
|
+
: ['src="' + escapeAttribute(source.src) + '"'];
|
|
5553
|
+
if (source.type) {
|
|
5554
|
+
sourceAttrs.push('type="' + escapeAttribute(source.type) + '"');
|
|
5555
|
+
}
|
|
5556
|
+
return "<source " + sourceAttrs.join(" ") + ">";
|
|
5557
|
+
})
|
|
5558
|
+
.join("")
|
|
5559
|
+
: "";
|
|
5560
|
+
const children = node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
5561
|
+
const fallbackText = escapeHtml(readClientStringProp(props.fallbackText) || "Your browser does not support the video tag.");
|
|
5562
|
+
return "<video" + attrText + ">" + sourceTags + children + fallbackText + "</video>";
|
|
5563
|
+
}
|
|
3857
5564
|
|
|
3858
5565
|
function renderClientResuxImg(node, scope, locals, styleScopeId) {
|
|
3859
5566
|
const input = resolveClientImageRenderInput(node, scope, locals);
|
|
@@ -3865,6 +5572,7 @@ function renderClientResuxImg(node, scope, locals, styleScopeId) {
|
|
|
3865
5572
|
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3866
5573
|
const src = builder(input.src, {
|
|
3867
5574
|
provider: input.provider,
|
|
5575
|
+
cache: input.cache,
|
|
3868
5576
|
width: input.width,
|
|
3869
5577
|
height: input.height,
|
|
3870
5578
|
quality: input.quality,
|
|
@@ -3881,11 +5589,20 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3881
5589
|
if (!input.src) {
|
|
3882
5590
|
return "";
|
|
3883
5591
|
}
|
|
5592
|
+
const props = {};
|
|
5593
|
+
for (const attr of node.attrs) {
|
|
5594
|
+
const normalizedName = attr.name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
5595
|
+
props[normalizedName] = attr.kind === "static"
|
|
5596
|
+
? attr.value
|
|
5597
|
+
: evaluateExpression(attr.value, scope, locals);
|
|
5598
|
+
}
|
|
3884
5599
|
|
|
3885
5600
|
const app = getClientResuxApp();
|
|
3886
5601
|
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3887
|
-
const
|
|
5602
|
+
const fallbackSource = input.fallbackSrc || input.src;
|
|
5603
|
+
const fallbackSrc = builder(fallbackSource, {
|
|
3888
5604
|
provider: input.provider,
|
|
5605
|
+
cache: input.cache,
|
|
3889
5606
|
width: input.width,
|
|
3890
5607
|
height: input.height,
|
|
3891
5608
|
quality: input.quality,
|
|
@@ -3894,37 +5611,81 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3894
5611
|
});
|
|
3895
5612
|
const fallbackSrcset = buildClientImageSrcset(builder, {
|
|
3896
5613
|
...input,
|
|
5614
|
+
src: fallbackSource,
|
|
3897
5615
|
format: undefined
|
|
3898
5616
|
});
|
|
3899
5617
|
const manualChildren = node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
3900
|
-
const
|
|
3901
|
-
|
|
3902
|
-
|
|
5618
|
+
const explicitSources = resolveClientPictureSourceInputs(props.sources, input);
|
|
5619
|
+
const sourceInputs = explicitSources.length
|
|
5620
|
+
? explicitSources
|
|
5621
|
+
: input.formats.map((format) => ({
|
|
5622
|
+
src: input.src,
|
|
5623
|
+
widths: input.widths,
|
|
5624
|
+
width: input.width,
|
|
5625
|
+
height: input.height,
|
|
5626
|
+
quality: input.quality,
|
|
5627
|
+
format,
|
|
5628
|
+
fit: input.fit,
|
|
5629
|
+
sizes: input.sizes,
|
|
5630
|
+
modifiers: input.modifiers,
|
|
5631
|
+
type: clientImageMimeType(format)
|
|
5632
|
+
}));
|
|
5633
|
+
const generatedSources = sourceInputs
|
|
5634
|
+
.map((entry) => {
|
|
5635
|
+
const sourceInput = entry;
|
|
5636
|
+
const sourceRenderInput = {
|
|
3903
5637
|
...input,
|
|
3904
|
-
|
|
3905
|
-
|
|
3906
|
-
|
|
5638
|
+
src: sourceInput.src,
|
|
5639
|
+
width: sourceInput.width,
|
|
5640
|
+
height: sourceInput.height,
|
|
5641
|
+
widths: sourceInput.widths,
|
|
5642
|
+
sizes: sourceInput.sizes,
|
|
5643
|
+
quality: sourceInput.quality,
|
|
5644
|
+
format: sourceInput.format,
|
|
5645
|
+
fit: sourceInput.fit,
|
|
5646
|
+
modifiers: sourceInput.modifiers,
|
|
5647
|
+
placeholderSrc: undefined,
|
|
5648
|
+
placeholderClass: undefined,
|
|
5649
|
+
placeholderStyle: undefined,
|
|
5650
|
+
fallbackSrc: undefined,
|
|
5651
|
+
attrs: {},
|
|
5652
|
+
preload: false,
|
|
5653
|
+
deferLazy: input.deferLazy
|
|
5654
|
+
};
|
|
5655
|
+
const sourceSrcset = sourceInput.srcset || buildClientImageSrcset(builder, sourceRenderInput);
|
|
5656
|
+
const sourceUrl = builder(sourceInput.src, {
|
|
3907
5657
|
provider: input.provider,
|
|
3908
|
-
|
|
3909
|
-
|
|
3910
|
-
|
|
3911
|
-
|
|
3912
|
-
|
|
3913
|
-
|
|
5658
|
+
cache: input.cache,
|
|
5659
|
+
width: sourceInput.width,
|
|
5660
|
+
height: sourceInput.height,
|
|
5661
|
+
quality: sourceInput.quality,
|
|
5662
|
+
fit: sourceInput.fit,
|
|
5663
|
+
format: sourceInput.format,
|
|
5664
|
+
modifiers: sourceInput.modifiers
|
|
3914
5665
|
});
|
|
5666
|
+
const resolvedSrcset = sourceSrcset || sourceUrl;
|
|
3915
5667
|
if (!resolvedSrcset) {
|
|
3916
5668
|
return "";
|
|
3917
5669
|
}
|
|
3918
|
-
const sourceAttrs = [
|
|
5670
|
+
const sourceAttrs = [];
|
|
5671
|
+
const sourceType = sourceInput.type
|
|
5672
|
+
|| (sourceInput.format ? clientImageMimeType(sourceInput.format) : inferClientImageMimeTypeFromSource(sourceInput.src));
|
|
5673
|
+
if (sourceType) {
|
|
5674
|
+
sourceAttrs.push('type="' + escapeAttribute(sourceType) + '"');
|
|
5675
|
+
}
|
|
5676
|
+
if (sourceInput.media) {
|
|
5677
|
+
sourceAttrs.push('media="' + escapeAttribute(sourceInput.media) + '"');
|
|
5678
|
+
}
|
|
3919
5679
|
if (input.deferLazy) {
|
|
3920
5680
|
sourceAttrs.push('data-rx-lazy-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3921
|
-
|
|
3922
|
-
|
|
5681
|
+
sourceAttrs.push('data-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
5682
|
+
if (sourceInput.sizes) {
|
|
5683
|
+
sourceAttrs.push('data-rx-lazy-sizes="' + escapeAttribute(sourceInput.sizes) + '"');
|
|
3923
5684
|
}
|
|
3924
5685
|
} else {
|
|
3925
5686
|
sourceAttrs.push('srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3926
|
-
if (
|
|
3927
|
-
sourceAttrs.push('sizes="' + escapeAttribute(
|
|
5687
|
+
if (sourceInput.sizes) {
|
|
5688
|
+
sourceAttrs.push('sizes="' + escapeAttribute(sourceInput.sizes) + '"');
|
|
3928
5689
|
}
|
|
3929
5690
|
}
|
|
3930
5691
|
return "<source " + sourceAttrs.join(" ") + ">";
|
|
@@ -3932,7 +5693,7 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3932
5693
|
.filter(Boolean)
|
|
3933
5694
|
.join("");
|
|
3934
5695
|
const img = renderClientResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
3935
|
-
const attrs = [];
|
|
5696
|
+
const attrs = ['data-resux-media="picture"'];
|
|
3936
5697
|
if (styleScopeId) {
|
|
3937
5698
|
attrs.push(styleScopeId + '=""');
|
|
3938
5699
|
}
|
|
@@ -3953,6 +5714,14 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3953
5714
|
const explicitFormats = parseClientImageFormats(
|
|
3954
5715
|
props.formats || (explicitFormat && explicitFormat.includes(",") ? explicitFormat : undefined)
|
|
3955
5716
|
);
|
|
5717
|
+
const hasExplicitQuality = Object.prototype.hasOwnProperty.call(props, "quality");
|
|
5718
|
+
const hasExplicitFormat = Object.prototype.hasOwnProperty.call(props, "format");
|
|
5719
|
+
const explicitQuality = readClientNumberProp(props.quality);
|
|
5720
|
+
const modifiers = normalizeClientImageModifiers({
|
|
5721
|
+
...normalizeClientImageModifiers(props.modifiers),
|
|
5722
|
+
...(hasExplicitFormat && !explicitFormat ? { format: false } : {}),
|
|
5723
|
+
...(hasExplicitQuality && !explicitQuality ? { quality: false } : {})
|
|
5724
|
+
});
|
|
3956
5725
|
const priority = readClientBooleanProp(props.priority, false);
|
|
3957
5726
|
const preload = readClientBooleanProp(props.preload, priority);
|
|
3958
5727
|
const explicitLoading = readClientStringProp(props.loading);
|
|
@@ -3962,12 +5731,23 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3962
5731
|
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
3963
5732
|
const loading = explicitLoading || (lazy ? "lazy" : "eager");
|
|
3964
5733
|
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
3965
|
-
const
|
|
5734
|
+
const lazyRootMargin = readClientStringProp(props.rootMargin) || "0px 0px";
|
|
5735
|
+
const lazyThresholdRaw = Number(props.threshold);
|
|
5736
|
+
const lazyThreshold = Number.isFinite(lazyThresholdRaw)
|
|
5737
|
+
? Math.min(1, Math.max(0, lazyThresholdRaw))
|
|
5738
|
+
: 0;
|
|
5739
|
+
const quality = hasExplicitQuality
|
|
5740
|
+
? explicitQuality
|
|
5741
|
+
: (explicitQuality ?? imageConfig.quality);
|
|
5742
|
+
const cache = normalizeClientImageCacheValue(props.cache ?? imageConfig.cache);
|
|
3966
5743
|
const densities = parseClientImageNumberList(props.densities)
|
|
3967
5744
|
|| imageConfig.densities
|
|
3968
5745
|
|| [1, 2];
|
|
5746
|
+
const src = readClientStringProp(props.src)
|
|
5747
|
+
|| readClientStringProp(props.fallbackSrc ?? props.fallback)
|
|
5748
|
+
|| "";
|
|
3969
5749
|
return {
|
|
3970
|
-
src
|
|
5750
|
+
src,
|
|
3971
5751
|
alt: readClientStringProp(props.alt) || "",
|
|
3972
5752
|
width: readClientNumberProp(props.width),
|
|
3973
5753
|
height: readClientNumberProp(props.height),
|
|
@@ -3978,14 +5758,23 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3978
5758
|
decoding: readClientStringProp(props.decoding) || "async",
|
|
3979
5759
|
fetchPriority: readClientStringProp(props.fetchpriority || props.fetchPriority) || (priority ? "high" : undefined),
|
|
3980
5760
|
provider: readClientStringProp(props.provider),
|
|
5761
|
+
cache,
|
|
3981
5762
|
quality,
|
|
3982
5763
|
fit: readClientStringProp(props.fit),
|
|
3983
|
-
format: explicitFormats.length
|
|
5764
|
+
format: explicitFormats.length
|
|
5765
|
+
? undefined
|
|
5766
|
+
: (hasExplicitFormat ? explicitFormat : (explicitFormat || imageConfig.format)),
|
|
3984
5767
|
formats: explicitFormats,
|
|
3985
|
-
|
|
5768
|
+
placeholderSrc: resolveClientPlaceholderSource(props.placeholder),
|
|
5769
|
+
placeholderClass: readClientStringProp(props.placeholderClass),
|
|
5770
|
+
placeholderStyle: readClientStringProp(props.placeholderStyle),
|
|
5771
|
+
fallbackSrc: readClientStringProp(props.fallbackSrc ?? props.fallback),
|
|
5772
|
+
modifiers,
|
|
3986
5773
|
attrs: collectClientImageAttrs(props),
|
|
3987
5774
|
preload,
|
|
3988
|
-
deferLazy
|
|
5775
|
+
deferLazy,
|
|
5776
|
+
lazyRootMargin,
|
|
5777
|
+
lazyThreshold
|
|
3989
5778
|
};
|
|
3990
5779
|
}
|
|
3991
5780
|
|
|
@@ -4016,7 +5805,16 @@ function normalizeClientImageModifiers(value) {
|
|
|
4016
5805
|
}
|
|
4017
5806
|
const modifiers = {};
|
|
4018
5807
|
for (const [key, entry] of Object.entries(value)) {
|
|
4019
|
-
if (entry ===
|
|
5808
|
+
if (entry === false) {
|
|
5809
|
+
if (key === "format" || key === "quality") {
|
|
5810
|
+
modifiers[key] = false;
|
|
5811
|
+
}
|
|
5812
|
+
continue;
|
|
5813
|
+
}
|
|
5814
|
+
if (entry === undefined || entry === null) {
|
|
5815
|
+
continue;
|
|
5816
|
+
}
|
|
5817
|
+
if (key === "cache") {
|
|
4020
5818
|
continue;
|
|
4021
5819
|
}
|
|
4022
5820
|
if (key === "width" || key === "height" || key === "quality") {
|
|
@@ -4032,15 +5830,14 @@ function normalizeClientImageModifiers(value) {
|
|
|
4032
5830
|
}
|
|
4033
5831
|
|
|
4034
5832
|
function buildClientImageSrcset(builder, input) {
|
|
4035
|
-
const widthCandidates = input
|
|
4036
|
-
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
4037
|
-
: [];
|
|
5833
|
+
const widthCandidates = resolveClientImageWidthCandidates(input);
|
|
4038
5834
|
if (widthCandidates.length) {
|
|
4039
5835
|
return widthCandidates
|
|
4040
5836
|
.map((width) => builder(input.src, {
|
|
4041
5837
|
provider: input.provider,
|
|
5838
|
+
cache: input.cache,
|
|
4042
5839
|
width,
|
|
4043
|
-
height: input
|
|
5840
|
+
height: resolveClientImageCandidateHeight(input, width),
|
|
4044
5841
|
quality: input.quality,
|
|
4045
5842
|
fit: input.fit,
|
|
4046
5843
|
format: input.format,
|
|
@@ -4058,6 +5855,7 @@ function buildClientImageSrcset(builder, input) {
|
|
|
4058
5855
|
const height = input.height ? Math.max(1, Math.round(input.height * density)) : undefined;
|
|
4059
5856
|
return builder(input.src, {
|
|
4060
5857
|
provider: input.provider,
|
|
5858
|
+
cache: input.cache,
|
|
4061
5859
|
width,
|
|
4062
5860
|
height,
|
|
4063
5861
|
quality: input.quality,
|
|
@@ -4069,19 +5867,133 @@ function buildClientImageSrcset(builder, input) {
|
|
|
4069
5867
|
.join(", ");
|
|
4070
5868
|
}
|
|
4071
5869
|
|
|
5870
|
+
function resolveClientImageWidthCandidates(input) {
|
|
5871
|
+
const explicitWidths = input.widths.length
|
|
5872
|
+
? normalizeClientImageWidthCandidates(input.widths, input.width)
|
|
5873
|
+
: [];
|
|
5874
|
+
if (explicitWidths.length) {
|
|
5875
|
+
return explicitWidths;
|
|
5876
|
+
}
|
|
5877
|
+
if (!input.sizes) {
|
|
5878
|
+
return [];
|
|
5879
|
+
}
|
|
5880
|
+
return resolveClientImageWidthsFromSizes(input.sizes, input.densities, input.width);
|
|
5881
|
+
}
|
|
5882
|
+
|
|
5883
|
+
function resolveClientImageWidthsFromSizes(sizes, densities, maxWidth) {
|
|
5884
|
+
const descriptors = String(sizes)
|
|
5885
|
+
.split(",")
|
|
5886
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
5887
|
+
.filter(Boolean);
|
|
5888
|
+
const baseWidths = [];
|
|
5889
|
+
for (const descriptor of descriptors) {
|
|
5890
|
+
const matches = [...descriptor.matchAll(/([0-9]*\.?[0-9]+)\s*(px|vw)\b/g)];
|
|
5891
|
+
const match = matches[matches.length - 1];
|
|
5892
|
+
if (!match) {
|
|
5893
|
+
continue;
|
|
5894
|
+
}
|
|
5895
|
+
const value = Number(match[1]);
|
|
5896
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
5897
|
+
continue;
|
|
5898
|
+
}
|
|
5899
|
+
if (match[2] === "px") {
|
|
5900
|
+
baseWidths.push(Math.round(value));
|
|
5901
|
+
continue;
|
|
5902
|
+
}
|
|
5903
|
+
for (const viewportWidth of RESUX_CLIENT_RESPONSIVE_VIEWPORT_WIDTHS) {
|
|
5904
|
+
baseWidths.push(Math.round((viewportWidth * value) / 100));
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
const safeDensities = densities.length
|
|
5909
|
+
? [...new Set(densities)]
|
|
5910
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
5911
|
+
.sort((left, right) => left - right)
|
|
5912
|
+
: [1];
|
|
5913
|
+
const expandedWidths = baseWidths.flatMap((width) =>
|
|
5914
|
+
safeDensities.map((density) => Math.round(width * density))
|
|
5915
|
+
);
|
|
5916
|
+
|
|
5917
|
+
if (!expandedWidths.length && Number.isFinite(maxWidth) && maxWidth > 0) {
|
|
5918
|
+
return [Math.max(1, Math.round(maxWidth))];
|
|
5919
|
+
}
|
|
5920
|
+
return normalizeClientImageWidthCandidates(expandedWidths, maxWidth);
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5923
|
+
function normalizeClientImageWidthCandidates(candidates, maxWidth) {
|
|
5924
|
+
const resolvedMaxWidth = Number.isFinite(maxWidth) && maxWidth > 0
|
|
5925
|
+
? Math.round(maxWidth)
|
|
5926
|
+
: Number.POSITIVE_INFINITY;
|
|
5927
|
+
const normalized = [...new Set(candidates
|
|
5928
|
+
.map((entry) => Number(entry))
|
|
5929
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
5930
|
+
.map((entry) => Math.min(8192, Math.max(1, Math.round(entry)), resolvedMaxWidth)))]
|
|
5931
|
+
.sort((left, right) => left - right);
|
|
5932
|
+
const compacted = [];
|
|
5933
|
+
for (const width of normalized) {
|
|
5934
|
+
const previous = compacted[compacted.length - 1];
|
|
5935
|
+
const shouldKeep = previous === undefined
|
|
5936
|
+
|| width - previous >= 24
|
|
5937
|
+
|| (Number.isFinite(resolvedMaxWidth) && width === resolvedMaxWidth);
|
|
5938
|
+
if (shouldKeep) {
|
|
5939
|
+
compacted.push(width);
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
5942
|
+
return compacted;
|
|
5943
|
+
}
|
|
5944
|
+
|
|
5945
|
+
function resolveClientImageCandidateHeight(input, width) {
|
|
5946
|
+
if (!input.height) {
|
|
5947
|
+
return undefined;
|
|
5948
|
+
}
|
|
5949
|
+
if (!input.width) {
|
|
5950
|
+
return input.height;
|
|
5951
|
+
}
|
|
5952
|
+
const scaledHeight = Math.round((input.height / input.width) * width);
|
|
5953
|
+
return Math.max(1, scaledHeight);
|
|
5954
|
+
}
|
|
5955
|
+
|
|
4072
5956
|
function renderClientResuxImgTag(input, src, srcset, styleScopeId) {
|
|
4073
5957
|
const attrs = [];
|
|
4074
5958
|
const isDeferredLazy = input.deferLazy && String(input.loading || "").toLowerCase() === "lazy";
|
|
5959
|
+
const placeholderSrc = input.placeholderSrc;
|
|
5960
|
+
const placeholderClass = input.placeholderClass;
|
|
5961
|
+
const placeholderStyle = input.placeholderStyle;
|
|
5962
|
+
const aspectRatioStyle = resolveClientAspectRatioStyle(input.width, input.height, input.attrs.style, placeholderStyle);
|
|
5963
|
+
const placeholderBackground = placeholderSrc
|
|
5964
|
+
? "background-image: url('" + placeholderSrc + "'); background-size: cover; background-position: center; background-repeat: no-repeat"
|
|
5965
|
+
: undefined;
|
|
5966
|
+
const mergedClass = mergeClientClassNames(input.attrs.class, placeholderClass);
|
|
5967
|
+
const mergedStyle = mergeClientInlineStyles(
|
|
5968
|
+
input.attrs.style,
|
|
5969
|
+
aspectRatioStyle,
|
|
5970
|
+
!isDeferredLazy ? placeholderBackground : undefined,
|
|
5971
|
+
placeholderStyle
|
|
5972
|
+
);
|
|
5973
|
+
const initialSrc = isDeferredLazy
|
|
5974
|
+
? (placeholderSrc || RESUX_LAZY_PLACEHOLDER_SRC)
|
|
5975
|
+
: src;
|
|
4075
5976
|
const mergedAttrs = {
|
|
4076
5977
|
...input.attrs,
|
|
4077
|
-
|
|
5978
|
+
...(mergedClass ? { class: mergedClass } : {}),
|
|
5979
|
+
...(mergedStyle ? { style: mergedStyle } : {}),
|
|
5980
|
+
src: initialSrc,
|
|
4078
5981
|
alt: input.alt,
|
|
4079
5982
|
loading: input.loading,
|
|
4080
5983
|
decoding: input.decoding,
|
|
5984
|
+
"data-resux-media": "img",
|
|
4081
5985
|
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
4082
|
-
...(isDeferredLazy ? { "data-
|
|
4083
|
-
...(isDeferredLazy
|
|
5986
|
+
...(isDeferredLazy ? { "data-resux-lazy": "true" } : {}),
|
|
5987
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src, "data-src": src } : {}),
|
|
5988
|
+
...(isDeferredLazy ? { "data-rx-lazy-root-margin": input.lazyRootMargin } : {}),
|
|
5989
|
+
...(isDeferredLazy ? { "data-rx-lazy-threshold": String(input.lazyThreshold) } : {}),
|
|
5990
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset, "data-srcset": srcset } : {}),
|
|
4084
5991
|
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
5992
|
+
...(placeholderSrc ? { "data-rx-placeholder-src": placeholderSrc, "data-placeholder": placeholderSrc } : {}),
|
|
5993
|
+
...(placeholderClass ? { "data-rx-placeholder-class": placeholderClass } : {}),
|
|
5994
|
+
...(placeholderStyle ? { "data-rx-placeholder-style": placeholderStyle } : {}),
|
|
5995
|
+
...(placeholderSrc ? { "data-rx-placeholder-active": "true", "data-resux-placeholder-active": "true" } : {}),
|
|
5996
|
+
...(input.fallbackSrc ? { "data-rx-fallback-src": input.fallbackSrc } : {}),
|
|
4085
5997
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
4086
5998
|
...(input.width ? { width: String(input.width) } : {}),
|
|
4087
5999
|
...(input.height ? { height: String(input.height) } : {}),
|
|
@@ -4156,6 +6068,9 @@ function readClientBooleanProp(value, fallback) {
|
|
|
4156
6068
|
}
|
|
4157
6069
|
if (typeof value === "string") {
|
|
4158
6070
|
const normalized = value.trim().toLowerCase();
|
|
6071
|
+
if (normalized === "") {
|
|
6072
|
+
return true;
|
|
6073
|
+
}
|
|
4159
6074
|
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
4160
6075
|
return true;
|
|
4161
6076
|
}
|
|
@@ -4166,6 +6081,187 @@ function readClientBooleanProp(value, fallback) {
|
|
|
4166
6081
|
return fallback;
|
|
4167
6082
|
}
|
|
4168
6083
|
|
|
6084
|
+
function resolveClientPlaceholderSource(value) {
|
|
6085
|
+
if (value === undefined || value === null || value === false) {
|
|
6086
|
+
return undefined;
|
|
6087
|
+
}
|
|
6088
|
+
if (value === true) {
|
|
6089
|
+
return RESUX_DEFAULT_PLACEHOLDER_SRC;
|
|
6090
|
+
}
|
|
6091
|
+
if (typeof value !== "string") {
|
|
6092
|
+
return undefined;
|
|
6093
|
+
}
|
|
6094
|
+
const trimmed = value.trim();
|
|
6095
|
+
if (!trimmed) {
|
|
6096
|
+
return undefined;
|
|
6097
|
+
}
|
|
6098
|
+
const normalized = trimmed.toLowerCase();
|
|
6099
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
6100
|
+
return RESUX_DEFAULT_PLACEHOLDER_SRC;
|
|
6101
|
+
}
|
|
6102
|
+
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
|
6103
|
+
return undefined;
|
|
6104
|
+
}
|
|
6105
|
+
if (looksLikeClientMediaSource(trimmed)) {
|
|
6106
|
+
return trimmed;
|
|
6107
|
+
}
|
|
6108
|
+
return createClientTextPlaceholderDataUri(trimmed);
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
function looksLikeClientMediaSource(value) {
|
|
6112
|
+
return value.startsWith("/")
|
|
6113
|
+
|| value.startsWith("./")
|
|
6114
|
+
|| value.startsWith("../")
|
|
6115
|
+
|| value.startsWith("http://")
|
|
6116
|
+
|| value.startsWith("https://")
|
|
6117
|
+
|| value.startsWith("data:image/")
|
|
6118
|
+
|| value.startsWith("blob:");
|
|
6119
|
+
}
|
|
6120
|
+
|
|
6121
|
+
function createClientTextPlaceholderDataUri(value) {
|
|
6122
|
+
const safeLabel = escapeClientSvgText(value);
|
|
6123
|
+
const svg =
|
|
6124
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360" role="img" aria-label="' + safeLabel + '">'
|
|
6125
|
+
+ '<rect width="640" height="360" fill="#0f172a"/>'
|
|
6126
|
+
+ '<rect x="24" y="24" width="592" height="312" rx="20" fill="#111827" stroke="#334155" stroke-width="2"/>'
|
|
6127
|
+
+ '<text x="320" y="192" fill="#cbd5e1" font-size="30" text-anchor="middle" font-family="Segoe UI, Arial, sans-serif">' + safeLabel + '</text>'
|
|
6128
|
+
+ '</svg>';
|
|
6129
|
+
return "data:image/svg+xml," + encodeURIComponent(svg);
|
|
6130
|
+
}
|
|
6131
|
+
|
|
6132
|
+
function escapeClientSvgText(value) {
|
|
6133
|
+
return String(value)
|
|
6134
|
+
.replace(/&/g, "&")
|
|
6135
|
+
.replace(/</g, "<")
|
|
6136
|
+
.replace(/>/g, ">")
|
|
6137
|
+
.replace(/"/g, """)
|
|
6138
|
+
.replace(/'/g, "'");
|
|
6139
|
+
}
|
|
6140
|
+
|
|
6141
|
+
function mergeClientClassNames() {
|
|
6142
|
+
const values = Array.from(arguments);
|
|
6143
|
+
const tokens = values
|
|
6144
|
+
.flatMap((value) => String(value || "").split(/\s+/))
|
|
6145
|
+
.map((token) => token.trim())
|
|
6146
|
+
.filter(Boolean);
|
|
6147
|
+
return tokens.length ? [...new Set(tokens)].join(" ") : undefined;
|
|
6148
|
+
}
|
|
6149
|
+
|
|
6150
|
+
function mergeClientInlineStyles() {
|
|
6151
|
+
const values = Array.from(arguments);
|
|
6152
|
+
const parts = values
|
|
6153
|
+
.flatMap((value) => String(value || "").split(";"))
|
|
6154
|
+
.map((entry) => entry.trim())
|
|
6155
|
+
.filter(Boolean);
|
|
6156
|
+
return parts.length ? parts.join("; ") : undefined;
|
|
6157
|
+
}
|
|
6158
|
+
|
|
6159
|
+
function hasClientInlineStyleProperty(styleValue, propertyName) {
|
|
6160
|
+
if (typeof styleValue !== "string") {
|
|
6161
|
+
return false;
|
|
6162
|
+
}
|
|
6163
|
+
const normalized = String(propertyName).replace(/[.*+?^{}$()|[\]\\]/g, "\\$&");
|
|
6164
|
+
const pattern = new RegExp("(^|;)\\s*" + normalized + "\\s*:", "i");
|
|
6165
|
+
return pattern.test(styleValue);
|
|
6166
|
+
}
|
|
6167
|
+
|
|
6168
|
+
function resolveClientAspectRatioStyle(width, height) {
|
|
6169
|
+
const styleValues = Array.from(arguments).slice(2);
|
|
6170
|
+
if (!width || !height) {
|
|
6171
|
+
return undefined;
|
|
6172
|
+
}
|
|
6173
|
+
if (styleValues.some((entry) => hasClientInlineStyleProperty(entry, "aspect-ratio"))) {
|
|
6174
|
+
return undefined;
|
|
6175
|
+
}
|
|
6176
|
+
return "aspect-ratio: " + width + " / " + height;
|
|
6177
|
+
}
|
|
6178
|
+
|
|
6179
|
+
function inferClientImageMimeTypeFromSource(src) {
|
|
6180
|
+
const clean = String(src || "").split(/[?#]/)[0].toLowerCase();
|
|
6181
|
+
if (!clean) {
|
|
6182
|
+
return undefined;
|
|
6183
|
+
}
|
|
6184
|
+
const dotIndex = clean.lastIndexOf(".");
|
|
6185
|
+
if (dotIndex < 0) {
|
|
6186
|
+
return undefined;
|
|
6187
|
+
}
|
|
6188
|
+
const extension = clean.slice(dotIndex + 1);
|
|
6189
|
+
if (!extension) {
|
|
6190
|
+
return undefined;
|
|
6191
|
+
}
|
|
6192
|
+
return clientImageMimeType(extension);
|
|
6193
|
+
}
|
|
6194
|
+
|
|
6195
|
+
function resolveClientPictureSourceInputs(value, fallbackInput) {
|
|
6196
|
+
if (!Array.isArray(value)) {
|
|
6197
|
+
return [];
|
|
6198
|
+
}
|
|
6199
|
+
const resolved = [];
|
|
6200
|
+
for (const entry of value) {
|
|
6201
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6202
|
+
continue;
|
|
6203
|
+
}
|
|
6204
|
+
const record = entry;
|
|
6205
|
+
const src = readClientStringProp(record.src) || fallbackInput.src;
|
|
6206
|
+
if (!src) {
|
|
6207
|
+
continue;
|
|
6208
|
+
}
|
|
6209
|
+
const hasQuality = Object.prototype.hasOwnProperty.call(record, "quality");
|
|
6210
|
+
const hasFormat = Object.prototype.hasOwnProperty.call(record, "format");
|
|
6211
|
+
const explicitFormat = readClientStringProp(record.format);
|
|
6212
|
+
const explicitQuality = readClientNumberProp(record.quality);
|
|
6213
|
+
const widths = parseClientImageNumberList(record.widths) || fallbackInput.widths;
|
|
6214
|
+
const baseModifiers = normalizeClientImageModifiers(record.modifiers);
|
|
6215
|
+
const modifiers = normalizeClientImageModifiers({
|
|
6216
|
+
...fallbackInput.modifiers,
|
|
6217
|
+
...baseModifiers,
|
|
6218
|
+
...(hasFormat && !explicitFormat ? { format: false } : {}),
|
|
6219
|
+
...(hasQuality && !explicitQuality ? { quality: false } : {}),
|
|
6220
|
+
...(readClientStringProp(record.fit) ? { fit: readClientStringProp(record.fit) } : {}),
|
|
6221
|
+
...(readClientNumberProp(record.width) ? { width: readClientNumberProp(record.width) } : {}),
|
|
6222
|
+
...(readClientNumberProp(record.height) ? { height: readClientNumberProp(record.height) } : {}),
|
|
6223
|
+
...(explicitQuality ? { quality: explicitQuality } : {}),
|
|
6224
|
+
...(explicitFormat ? { format: explicitFormat } : {})
|
|
6225
|
+
});
|
|
6226
|
+
resolved.push({
|
|
6227
|
+
src,
|
|
6228
|
+
srcset: readClientStringProp(record.srcset),
|
|
6229
|
+
type: readClientStringProp(record.type),
|
|
6230
|
+
media: readClientStringProp(record.media),
|
|
6231
|
+
sizes: readClientStringProp(record.sizes) || fallbackInput.sizes,
|
|
6232
|
+
width: readClientNumberProp(record.width) || fallbackInput.width,
|
|
6233
|
+
height: readClientNumberProp(record.height) || fallbackInput.height,
|
|
6234
|
+
widths,
|
|
6235
|
+
quality: hasQuality ? explicitQuality : fallbackInput.quality,
|
|
6236
|
+
format: hasFormat ? explicitFormat : fallbackInput.format,
|
|
6237
|
+
fit: readClientStringProp(record.fit) || fallbackInput.fit,
|
|
6238
|
+
modifiers
|
|
6239
|
+
});
|
|
6240
|
+
}
|
|
6241
|
+
return resolved;
|
|
6242
|
+
}
|
|
6243
|
+
|
|
6244
|
+
function resolveClientVideoSources(value) {
|
|
6245
|
+
if (!Array.isArray(value)) {
|
|
6246
|
+
return [];
|
|
6247
|
+
}
|
|
6248
|
+
const sources = [];
|
|
6249
|
+
for (const entry of value) {
|
|
6250
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6251
|
+
continue;
|
|
6252
|
+
}
|
|
6253
|
+
const src = readClientStringProp(entry.src);
|
|
6254
|
+
if (!src) {
|
|
6255
|
+
continue;
|
|
6256
|
+
}
|
|
6257
|
+
sources.push({
|
|
6258
|
+
src,
|
|
6259
|
+
type: readClientStringProp(entry.type)
|
|
6260
|
+
});
|
|
6261
|
+
}
|
|
6262
|
+
return sources;
|
|
6263
|
+
}
|
|
6264
|
+
|
|
4169
6265
|
function clientImageMimeType(format) {
|
|
4170
6266
|
const normalized = String(format || "").trim().toLowerCase();
|
|
4171
6267
|
if (!normalized) {
|
|
@@ -4239,7 +6335,8 @@ function applyPatches(scopeId, patches) {
|
|
|
4239
6335
|
});
|
|
4240
6336
|
}
|
|
4241
6337
|
if (needsLazyImageActivation) {
|
|
4242
|
-
|
|
6338
|
+
activateDeferredLazyMedia();
|
|
6339
|
+
applyReducedMotionVideoPreference();
|
|
4243
6340
|
}
|
|
4244
6341
|
}
|
|
4245
6342
|
|