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