resuxjs 0.2.34 → 0.2.36
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +595 -19
- package/dist/cli.js.map +1 -1
- package/dist/deploy/index.js +1 -34
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/vercel.js +105 -8
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/runtime/index.d.ts +9 -2
- package/dist/runtime/index.js +2531 -179
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -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,19 +582,27 @@ 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");
|
|
589
|
+
const normalizedFormat = normalizeImageOutputFormat(typeof modifiers.format === "string" ? modifiers.format : undefined);
|
|
536
590
|
if (baseURL.includes("{src}")) {
|
|
537
591
|
return injectImageTemplateSource(baseURL, src, modifiers);
|
|
538
592
|
}
|
|
593
|
+
const sourceDescriptor = trimmedProvider === "vercel"
|
|
594
|
+
? { publicSource: src }
|
|
595
|
+
: rewriteImageSourceForDisplayFormat(src, normalizedFormat);
|
|
596
|
+
const useGeneratedCache = trimmedProvider === "resux" && typeof cacheOption === "string" && cacheOption.length > 0;
|
|
539
597
|
const query = new URLSearchParams();
|
|
540
598
|
if (trimmedProvider === "vercel") {
|
|
541
599
|
query.set("url", src);
|
|
542
600
|
}
|
|
543
601
|
else {
|
|
544
|
-
query.set("src",
|
|
602
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
603
|
+
if (sourceDescriptor.originalSource) {
|
|
604
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
605
|
+
}
|
|
545
606
|
}
|
|
546
607
|
const width = Number(modifiers.width);
|
|
547
608
|
const height = Number(modifiers.height);
|
|
@@ -558,7 +619,10 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
558
619
|
if (typeof modifiers.fit === "string" && modifiers.fit.length > 0) {
|
|
559
620
|
query.set("fit", modifiers.fit);
|
|
560
621
|
}
|
|
561
|
-
if (
|
|
622
|
+
if (normalizedFormat) {
|
|
623
|
+
query.set("f", normalizedFormat);
|
|
624
|
+
}
|
|
625
|
+
else if (typeof modifiers.format === "string" && modifiers.format.length > 0) {
|
|
562
626
|
query.set("f", modifiers.format);
|
|
563
627
|
}
|
|
564
628
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
@@ -567,6 +631,12 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
567
631
|
}
|
|
568
632
|
query.set(key, String(value));
|
|
569
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
|
+
}
|
|
570
640
|
const separator = baseURL.includes("?") ? "&" : "?";
|
|
571
641
|
const queryString = query.toString();
|
|
572
642
|
if (!queryString) {
|
|
@@ -578,6 +648,85 @@ function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, clien
|
|
|
578
648
|
}
|
|
579
649
|
return resolved;
|
|
580
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
|
+
}
|
|
581
730
|
function injectImageTemplateSource(template, src, modifiers) {
|
|
582
731
|
let resolved = template.replaceAll("{src}", encodeURIComponent(src));
|
|
583
732
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
@@ -585,6 +734,58 @@ function injectImageTemplateSource(template, src, modifiers) {
|
|
|
585
734
|
}
|
|
586
735
|
return resolved;
|
|
587
736
|
}
|
|
737
|
+
function normalizeImageOutputFormat(value) {
|
|
738
|
+
if (typeof value !== "string") {
|
|
739
|
+
return undefined;
|
|
740
|
+
}
|
|
741
|
+
const normalized = value.trim().toLowerCase();
|
|
742
|
+
if (!normalized) {
|
|
743
|
+
return undefined;
|
|
744
|
+
}
|
|
745
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
746
|
+
}
|
|
747
|
+
function rewriteImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
748
|
+
if (!normalizedFormat) {
|
|
749
|
+
return { publicSource: src };
|
|
750
|
+
}
|
|
751
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
752
|
+
return { publicSource: src };
|
|
753
|
+
}
|
|
754
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
755
|
+
try {
|
|
756
|
+
const sourceUrl = new URL(src);
|
|
757
|
+
const rewrittenPathname = rewriteImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
758
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
759
|
+
return { publicSource: src };
|
|
760
|
+
}
|
|
761
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
762
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
763
|
+
}
|
|
764
|
+
catch {
|
|
765
|
+
return { publicSource: src };
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
769
|
+
const rewrittenPath = rewriteImagePathExtension(pathPart, normalizedFormat);
|
|
770
|
+
if (rewrittenPath === pathPart) {
|
|
771
|
+
return { publicSource: src };
|
|
772
|
+
}
|
|
773
|
+
return { publicSource: `${rewrittenPath}${suffix}`, originalSource: src };
|
|
774
|
+
}
|
|
775
|
+
function rewriteImagePathExtension(pathname, extension) {
|
|
776
|
+
if (!pathname) {
|
|
777
|
+
return pathname;
|
|
778
|
+
}
|
|
779
|
+
const normalizedExtension = extension.startsWith(".")
|
|
780
|
+
? extension.slice(1)
|
|
781
|
+
: extension;
|
|
782
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
783
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
784
|
+
if (lastDot > lastSlash) {
|
|
785
|
+
return `${pathname.slice(0, lastDot + 1)}${normalizedExtension}`;
|
|
786
|
+
}
|
|
787
|
+
return `${pathname}.${normalizedExtension}`;
|
|
788
|
+
}
|
|
588
789
|
function runtimeOrigin(runtimeConfig) {
|
|
589
790
|
const publicConfig = runtimeConfig.public ?? {};
|
|
590
791
|
for (const key of ["appOrigin", "appURL", "siteURL", "origin"]) {
|
|
@@ -654,6 +855,9 @@ function renderElement(node, context, locals) {
|
|
|
654
855
|
if (node.tag === "ResuxPicture") {
|
|
655
856
|
return renderResuxPicture(node, context, locals);
|
|
656
857
|
}
|
|
858
|
+
if (node.tag === "ResuxVideo") {
|
|
859
|
+
return renderResuxVideo(node, context, locals);
|
|
860
|
+
}
|
|
657
861
|
if (node.tag === "ResuxLoadingIndicator") {
|
|
658
862
|
return renderResuxLoadingIndicatorSync(node, context, locals, renderTemplateNodes(node.children, context, locals));
|
|
659
863
|
}
|
|
@@ -763,6 +967,9 @@ async function renderElementAsync(node, context, renderComponent, locals) {
|
|
|
763
967
|
if (node.tag === "ResuxPicture") {
|
|
764
968
|
return renderResuxPicture(node, context, locals);
|
|
765
969
|
}
|
|
970
|
+
if (node.tag === "ResuxVideo") {
|
|
971
|
+
return renderResuxVideo(node, context, locals);
|
|
972
|
+
}
|
|
766
973
|
if (node.tag === "ResuxLoadingIndicator") {
|
|
767
974
|
return renderResuxLoadingIndicatorAsync(node, context, locals, renderTemplateNodesAsync(node.children, context, renderComponent, locals));
|
|
768
975
|
}
|
|
@@ -816,6 +1023,7 @@ const resuxImageReservedProps = new Set([
|
|
|
816
1023
|
"src",
|
|
817
1024
|
"alt",
|
|
818
1025
|
"provider",
|
|
1026
|
+
"cache",
|
|
819
1027
|
"modifiers",
|
|
820
1028
|
"quality",
|
|
821
1029
|
"fit",
|
|
@@ -833,7 +1041,18 @@ const resuxImageReservedProps = new Set([
|
|
|
833
1041
|
"decoding",
|
|
834
1042
|
"fetchpriority",
|
|
835
1043
|
"fetchPriority",
|
|
1044
|
+
"placeholder",
|
|
1045
|
+
"placeholderClass",
|
|
1046
|
+
"placeholderStyle",
|
|
1047
|
+
"fallback",
|
|
1048
|
+
"fallbackSrc",
|
|
1049
|
+
"sources",
|
|
1050
|
+
"rootMargin",
|
|
1051
|
+
"threshold",
|
|
836
1052
|
]);
|
|
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];
|
|
837
1056
|
function renderResuxImg(node, context, locals) {
|
|
838
1057
|
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
839
1058
|
if (!input.src) {
|
|
@@ -842,6 +1061,7 @@ function renderResuxImg(node, context, locals) {
|
|
|
842
1061
|
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
843
1062
|
const src = builder(input.src, {
|
|
844
1063
|
provider: input.provider,
|
|
1064
|
+
cache: input.cache,
|
|
845
1065
|
width: input.width,
|
|
846
1066
|
height: input.height,
|
|
847
1067
|
quality: input.quality,
|
|
@@ -850,17 +1070,172 @@ function renderResuxImg(node, context, locals) {
|
|
|
850
1070
|
modifiers: input.modifiers,
|
|
851
1071
|
});
|
|
852
1072
|
const srcset = buildResuxImageSrcset(builder, input);
|
|
853
|
-
registerResuxImagePreload(context, src, srcset, input
|
|
1073
|
+
registerResuxImagePreload(context, src, srcset, input, input.preload);
|
|
854
1074
|
return renderResuxImgTag(input, src, srcset, context.styleScopeId);
|
|
855
1075
|
}
|
|
1076
|
+
function renderResuxVideo(node, context, locals) {
|
|
1077
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
1078
|
+
const explicitLoading = readStringProp(props.loading);
|
|
1079
|
+
const explicitLazy = props.lazy === undefined
|
|
1080
|
+
? undefined
|
|
1081
|
+
: readBooleanProp(props.lazy, true);
|
|
1082
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : false);
|
|
1083
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true || lazy;
|
|
1084
|
+
const src = readStringProp(props.src);
|
|
1085
|
+
const poster = readStringProp(props.poster);
|
|
1086
|
+
const fallbackPoster = readStringProp(props.fallbackPoster);
|
|
1087
|
+
const width = readNumberProp(props.width);
|
|
1088
|
+
const height = readNumberProp(props.height);
|
|
1089
|
+
const placeholderSrc = resolveMediaPlaceholderSource(props.placeholder);
|
|
1090
|
+
const preload = readStringProp(props.preload) ?? "metadata";
|
|
1091
|
+
const ariaLabel = readStringProp(props.ariaLabel ?? props["aria-label"]);
|
|
1092
|
+
const rootMargin = readStringProp(props.rootMargin) ?? "320px 0px";
|
|
1093
|
+
const thresholdRaw = Number(props.threshold);
|
|
1094
|
+
const threshold = Number.isFinite(thresholdRaw)
|
|
1095
|
+
? Math.min(1, Math.max(0, thresholdRaw))
|
|
1096
|
+
: 0;
|
|
1097
|
+
const forceAutoplay = readBooleanProp(props.forceAutoplay, false);
|
|
1098
|
+
const autoplay = readBooleanProp(props.autoplay, false);
|
|
1099
|
+
const resolvedSources = resolveVideoSources(props.sources);
|
|
1100
|
+
const hasSourceChildren = resolvedSources.length > 0;
|
|
1101
|
+
const styleParts = [];
|
|
1102
|
+
if (typeof props.style === "string" && props.style.trim().length > 0) {
|
|
1103
|
+
styleParts.push(props.style.trim().replace(/;+\s*$/, ""));
|
|
1104
|
+
}
|
|
1105
|
+
const aspectRatio = props.aspectRatio;
|
|
1106
|
+
if (aspectRatio !== undefined && aspectRatio !== null && aspectRatio !== false) {
|
|
1107
|
+
const aspectValue = String(aspectRatio).trim();
|
|
1108
|
+
if (aspectValue.length > 0) {
|
|
1109
|
+
styleParts.push(`aspect-ratio: ${aspectValue}`);
|
|
1110
|
+
}
|
|
1111
|
+
}
|
|
1112
|
+
else {
|
|
1113
|
+
const ratioStyle = resolveAspectRatioStyle(width, height, props.style);
|
|
1114
|
+
if (ratioStyle) {
|
|
1115
|
+
styleParts.push(ratioStyle);
|
|
1116
|
+
}
|
|
1117
|
+
}
|
|
1118
|
+
styleParts.push("display: block");
|
|
1119
|
+
styleParts.push("width: 100%");
|
|
1120
|
+
styleParts.push("max-width: 100%");
|
|
1121
|
+
if (!styleParts.some((entry) => /(^|;)\s*height\s*:/.test(entry))) {
|
|
1122
|
+
styleParts.push("height: auto");
|
|
1123
|
+
}
|
|
1124
|
+
const attrs = [];
|
|
1125
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
1126
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
1127
|
+
continue;
|
|
1128
|
+
}
|
|
1129
|
+
if (name === "aspectRatio"
|
|
1130
|
+
|| name === "style"
|
|
1131
|
+
|| name === "lazy"
|
|
1132
|
+
|| name === "loading"
|
|
1133
|
+
|| name === "placeholder"
|
|
1134
|
+
|| name === "fallbackPoster"
|
|
1135
|
+
|| name === "rootMargin"
|
|
1136
|
+
|| name === "threshold"
|
|
1137
|
+
|| name === "sources"
|
|
1138
|
+
|| name === "forceAutoplay"
|
|
1139
|
+
|| name === "ariaLabel"
|
|
1140
|
+
|| name === "autoplay"
|
|
1141
|
+
|| name === "src"
|
|
1142
|
+
|| name === "poster"
|
|
1143
|
+
|| name === "preload"
|
|
1144
|
+
|| name === "fallbackText") {
|
|
1145
|
+
continue;
|
|
1146
|
+
}
|
|
1147
|
+
const attrName = name === "className"
|
|
1148
|
+
? "class"
|
|
1149
|
+
: name === "playsInline"
|
|
1150
|
+
? "playsinline"
|
|
1151
|
+
: name === "crossOrigin"
|
|
1152
|
+
? "crossorigin"
|
|
1153
|
+
: name === "referrerPolicy"
|
|
1154
|
+
? "referrerpolicy"
|
|
1155
|
+
: name;
|
|
1156
|
+
attrs.push(`${attrName}="${escapeAttribute(stringifyAttributeValue(attrName, rawValue))}"`);
|
|
1157
|
+
}
|
|
1158
|
+
if (!hasSourceChildren && !deferLazy && src) {
|
|
1159
|
+
attrs.push(`src="${escapeAttribute(src)}"`);
|
|
1160
|
+
}
|
|
1161
|
+
attrs.push('data-resux-media="video"');
|
|
1162
|
+
if (deferLazy && src) {
|
|
1163
|
+
attrs.push(`data-rx-lazy-src="${escapeAttribute(src)}"`);
|
|
1164
|
+
attrs.push(`data-src="${escapeAttribute(src)}"`);
|
|
1165
|
+
}
|
|
1166
|
+
if (deferLazy) {
|
|
1167
|
+
attrs.push('data-rx-lazy-video="true"');
|
|
1168
|
+
attrs.push('data-resux-lazy="true"');
|
|
1169
|
+
attrs.push(`data-rx-lazy-root-margin="${escapeAttribute(rootMargin)}"`);
|
|
1170
|
+
attrs.push(`data-rx-lazy-threshold="${escapeAttribute(String(threshold))}"`);
|
|
1171
|
+
attrs.push(`data-rx-lazy-preload="${escapeAttribute(preload)}"`);
|
|
1172
|
+
attrs.push('preload="none"');
|
|
1173
|
+
}
|
|
1174
|
+
else if (preload) {
|
|
1175
|
+
attrs.push(`preload="${escapeAttribute(preload)}"`);
|
|
1176
|
+
}
|
|
1177
|
+
if (poster) {
|
|
1178
|
+
attrs.push(`data-rx-poster="${escapeAttribute(poster)}"`);
|
|
1179
|
+
}
|
|
1180
|
+
if (fallbackPoster) {
|
|
1181
|
+
attrs.push(`data-rx-fallback-poster="${escapeAttribute(fallbackPoster)}"`);
|
|
1182
|
+
}
|
|
1183
|
+
if (placeholderSrc) {
|
|
1184
|
+
attrs.push(`data-rx-placeholder-src="${escapeAttribute(placeholderSrc)}"`);
|
|
1185
|
+
attrs.push(`data-placeholder="${escapeAttribute(placeholderSrc)}"`);
|
|
1186
|
+
attrs.push('data-rx-placeholder-active="true"');
|
|
1187
|
+
attrs.push('data-resux-placeholder-active="true"');
|
|
1188
|
+
}
|
|
1189
|
+
const initialPoster = placeholderSrc ?? poster;
|
|
1190
|
+
if (initialPoster) {
|
|
1191
|
+
attrs.push(`poster="${escapeAttribute(initialPoster)}"`);
|
|
1192
|
+
}
|
|
1193
|
+
if (autoplay) {
|
|
1194
|
+
attrs.push('autoplay="autoplay"');
|
|
1195
|
+
attrs.push('data-rx-autoplay-requested="true"');
|
|
1196
|
+
if (!forceAutoplay) {
|
|
1197
|
+
attrs.push('data-rx-respect-reduced-motion="true"');
|
|
1198
|
+
}
|
|
1199
|
+
else {
|
|
1200
|
+
attrs.push('data-rx-force-autoplay="true"');
|
|
1201
|
+
}
|
|
1202
|
+
}
|
|
1203
|
+
if (ariaLabel) {
|
|
1204
|
+
attrs.push(`aria-label="${escapeAttribute(ariaLabel)}"`);
|
|
1205
|
+
}
|
|
1206
|
+
if (styleParts.length > 0) {
|
|
1207
|
+
attrs.push(`style="${escapeAttribute(styleParts.join("; "))}"`);
|
|
1208
|
+
}
|
|
1209
|
+
appendStyleScopeAttribute(attrs, context.styleScopeId);
|
|
1210
|
+
const attrText = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
1211
|
+
const sourceTags = hasSourceChildren
|
|
1212
|
+
? resolvedSources
|
|
1213
|
+
.map((source) => {
|
|
1214
|
+
const sourceAttrs = deferLazy
|
|
1215
|
+
? [`data-rx-lazy-src="${escapeAttribute(source.src)}"`, `data-src="${escapeAttribute(source.src)}"`]
|
|
1216
|
+
: [`src="${escapeAttribute(source.src)}"`];
|
|
1217
|
+
if (source.type) {
|
|
1218
|
+
sourceAttrs.push(`type="${escapeAttribute(source.type)}"`);
|
|
1219
|
+
}
|
|
1220
|
+
return `<source ${sourceAttrs.join(" ")}>`;
|
|
1221
|
+
})
|
|
1222
|
+
.join("")
|
|
1223
|
+
: "";
|
|
1224
|
+
const children = renderTemplateNodes(node.children, context, locals);
|
|
1225
|
+
const fallbackText = escapeHtml(readStringProp(props.fallbackText) ?? "Your browser does not support the video tag.");
|
|
1226
|
+
return `<video${attrText}>${sourceTags}${children}${fallbackText}</video>`;
|
|
1227
|
+
}
|
|
856
1228
|
function renderResuxPicture(node, context, locals) {
|
|
857
1229
|
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
858
1230
|
if (!input.src) {
|
|
859
1231
|
return "";
|
|
860
1232
|
}
|
|
1233
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
861
1234
|
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
862
|
-
const
|
|
1235
|
+
const fallbackSource = input.fallbackSrc ?? input.src;
|
|
1236
|
+
const fallbackSrc = builder(fallbackSource, {
|
|
863
1237
|
provider: input.provider,
|
|
1238
|
+
cache: input.cache,
|
|
864
1239
|
width: input.width,
|
|
865
1240
|
height: input.height,
|
|
866
1241
|
quality: input.quality,
|
|
@@ -869,42 +1244,90 @@ function renderResuxPicture(node, context, locals) {
|
|
|
869
1244
|
});
|
|
870
1245
|
const fallbackSrcset = buildResuxImageSrcset(builder, {
|
|
871
1246
|
...input,
|
|
1247
|
+
src: fallbackSource,
|
|
872
1248
|
format: undefined,
|
|
873
1249
|
});
|
|
874
|
-
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input
|
|
1250
|
+
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input, input.preload);
|
|
875
1251
|
const manualChildren = renderTemplateNodes(node.children, context, locals);
|
|
876
|
-
const
|
|
877
|
-
|
|
878
|
-
|
|
879
|
-
|
|
1252
|
+
const explicitSources = resolvePictureSourceInputs(props.sources, input);
|
|
1253
|
+
const sourceInputs = explicitSources.length
|
|
1254
|
+
? explicitSources
|
|
1255
|
+
: input.formats.map((format) => ({
|
|
1256
|
+
src: input.src,
|
|
1257
|
+
widths: input.widths,
|
|
1258
|
+
width: input.width,
|
|
1259
|
+
height: input.height,
|
|
1260
|
+
quality: input.quality,
|
|
880
1261
|
format,
|
|
1262
|
+
fit: input.fit,
|
|
1263
|
+
sizes: input.sizes,
|
|
1264
|
+
modifiers: input.modifiers,
|
|
1265
|
+
type: resuxImageMimeType(format),
|
|
1266
|
+
}));
|
|
1267
|
+
const generatedSources = sourceInputs
|
|
1268
|
+
.map((sourceInput) => {
|
|
1269
|
+
const sourceRenderInput = {
|
|
1270
|
+
...input,
|
|
1271
|
+
src: sourceInput.src,
|
|
1272
|
+
width: sourceInput.width,
|
|
1273
|
+
height: sourceInput.height,
|
|
1274
|
+
widths: sourceInput.widths,
|
|
1275
|
+
sizes: sourceInput.sizes,
|
|
1276
|
+
quality: sourceInput.quality,
|
|
1277
|
+
format: sourceInput.format,
|
|
1278
|
+
fit: sourceInput.fit,
|
|
1279
|
+
modifiers: sourceInput.modifiers,
|
|
1280
|
+
placeholderSrc: undefined,
|
|
1281
|
+
placeholderClass: undefined,
|
|
1282
|
+
placeholderStyle: undefined,
|
|
1283
|
+
fallbackSrc: undefined,
|
|
1284
|
+
attrs: {},
|
|
1285
|
+
preload: false,
|
|
1286
|
+
deferLazy: input.deferLazy,
|
|
1287
|
+
};
|
|
1288
|
+
const sourceSrcset = sourceInput.srcset || buildResuxImageSrcset(builder, sourceRenderInput);
|
|
1289
|
+
const sourceUrl = builder(sourceInput.src, {
|
|
1290
|
+
provider: input.provider,
|
|
1291
|
+
cache: input.cache,
|
|
1292
|
+
width: sourceInput.width,
|
|
1293
|
+
height: sourceInput.height,
|
|
1294
|
+
quality: sourceInput.quality,
|
|
1295
|
+
fit: sourceInput.fit,
|
|
1296
|
+
format: sourceInput.format,
|
|
1297
|
+
modifiers: sourceInput.modifiers,
|
|
881
1298
|
});
|
|
882
|
-
const resolvedSrcset = sourceSrcset
|
|
883
|
-
|| builder(input.src, {
|
|
884
|
-
provider: input.provider,
|
|
885
|
-
width: input.width,
|
|
886
|
-
height: input.height,
|
|
887
|
-
quality: input.quality,
|
|
888
|
-
fit: input.fit,
|
|
889
|
-
format,
|
|
890
|
-
modifiers: input.modifiers,
|
|
891
|
-
});
|
|
1299
|
+
const resolvedSrcset = sourceSrcset || sourceUrl;
|
|
892
1300
|
if (!resolvedSrcset) {
|
|
893
1301
|
return "";
|
|
894
1302
|
}
|
|
895
|
-
const sourceAttrs = [
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
1303
|
+
const sourceAttrs = [];
|
|
1304
|
+
const sourceType = sourceInput.type
|
|
1305
|
+
|| (sourceInput.format ? resuxImageMimeType(sourceInput.format) : inferImageMimeTypeFromSource(sourceInput.src));
|
|
1306
|
+
if (sourceType) {
|
|
1307
|
+
sourceAttrs.push(`type="${escapeAttribute(sourceType)}"`);
|
|
1308
|
+
}
|
|
1309
|
+
if (sourceInput.media) {
|
|
1310
|
+
sourceAttrs.push(`media="${escapeAttribute(sourceInput.media)}"`);
|
|
1311
|
+
}
|
|
1312
|
+
if (input.deferLazy) {
|
|
1313
|
+
sourceAttrs.push(`data-rx-lazy-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
1314
|
+
sourceAttrs.push(`data-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
1315
|
+
if (sourceInput.sizes) {
|
|
1316
|
+
sourceAttrs.push(`data-rx-lazy-sizes="${escapeAttribute(sourceInput.sizes)}"`);
|
|
1317
|
+
}
|
|
1318
|
+
}
|
|
1319
|
+
else {
|
|
1320
|
+
sourceAttrs.push(`srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
1321
|
+
if (sourceInput.sizes) {
|
|
1322
|
+
sourceAttrs.push(`sizes="${escapeAttribute(sourceInput.sizes)}"`);
|
|
1323
|
+
}
|
|
901
1324
|
}
|
|
902
1325
|
return `<source ${sourceAttrs.join(" ")}>`;
|
|
903
1326
|
})
|
|
904
1327
|
.filter(Boolean)
|
|
905
1328
|
.join("");
|
|
906
1329
|
const img = renderResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
907
|
-
const attrs = [];
|
|
1330
|
+
const attrs = ['data-resux-media="picture"'];
|
|
908
1331
|
appendStyleScopeAttribute(attrs, context.styleScopeId);
|
|
909
1332
|
const attrText = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
910
1333
|
return `<picture${attrText}>${manualChildren}${generatedSources}${img}</picture>`;
|
|
@@ -912,19 +1335,40 @@ function renderResuxPicture(node, context, locals) {
|
|
|
912
1335
|
function resolveResuxImageRenderInput(node, context, locals) {
|
|
913
1336
|
const props = collectComponentProps(node, context.scope, locals);
|
|
914
1337
|
const runtimeImageConfig = resolveRuntimeImageConfig(context.runtimeConfig);
|
|
915
|
-
const
|
|
1338
|
+
const baseModifiers = resolveResuxImageModifierProps(props.modifiers);
|
|
916
1339
|
const explicitFormat = readStringProp(props.format);
|
|
917
1340
|
const explicitFormats = parseImageFormats(props.formats
|
|
918
1341
|
?? (explicitFormat?.includes(",") ? explicitFormat : undefined));
|
|
1342
|
+
const hasExplicitQuality = Object.prototype.hasOwnProperty.call(props, "quality");
|
|
1343
|
+
const hasExplicitFormat = Object.prototype.hasOwnProperty.call(props, "format");
|
|
1344
|
+
const explicitQuality = readNumberProp(props.quality);
|
|
1345
|
+
const modifiers = normalizeImageModifiers({
|
|
1346
|
+
...baseModifiers,
|
|
1347
|
+
...(hasExplicitFormat && !explicitFormat ? { format: false } : {}),
|
|
1348
|
+
...(hasExplicitQuality && !explicitQuality ? { quality: false } : {}),
|
|
1349
|
+
});
|
|
919
1350
|
const provider = readStringProp(props.provider);
|
|
920
|
-
const quality =
|
|
1351
|
+
const quality = hasExplicitQuality
|
|
1352
|
+
? explicitQuality
|
|
1353
|
+
: (explicitQuality ?? runtimeImageConfig.quality);
|
|
1354
|
+
const cache = normalizeImageCacheValue(props.cache ?? runtimeImageConfig.cache);
|
|
921
1355
|
const fit = readStringProp(props.fit);
|
|
922
1356
|
const width = readNumberProp(props.width);
|
|
923
1357
|
const height = readNumberProp(props.height);
|
|
924
1358
|
const priority = readBooleanProp(props.priority, false);
|
|
925
1359
|
const preload = readBooleanProp(props.preload, priority);
|
|
926
|
-
const
|
|
927
|
-
const
|
|
1360
|
+
const explicitLoading = readStringProp(props.loading);
|
|
1361
|
+
const explicitLazy = props.lazy === undefined
|
|
1362
|
+
? undefined
|
|
1363
|
+
: readBooleanProp(props.lazy, true);
|
|
1364
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
1365
|
+
const loading = explicitLoading ?? (lazy ? "lazy" : "eager");
|
|
1366
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
1367
|
+
const lazyRootMargin = readStringProp(props.rootMargin) ?? "0px 0px";
|
|
1368
|
+
const lazyThresholdRaw = Number(props.threshold);
|
|
1369
|
+
const lazyThreshold = Number.isFinite(lazyThresholdRaw)
|
|
1370
|
+
? Math.min(1, Math.max(0, lazyThresholdRaw))
|
|
1371
|
+
: 0;
|
|
928
1372
|
const decoding = readStringProp(props.decoding) ?? "async";
|
|
929
1373
|
const fetchPriority = readStringProp(props.fetchpriority ?? props.fetchPriority)
|
|
930
1374
|
?? (priority ? "high" : undefined);
|
|
@@ -933,8 +1377,12 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
933
1377
|
|| [1, 2];
|
|
934
1378
|
const widths = parseImageNumberList(props.widths) ?? [];
|
|
935
1379
|
const passthrough = collectResuxImagePassthroughAttributes(props);
|
|
936
|
-
const src = readStringProp(props.src)
|
|
1380
|
+
const src = readStringProp(props.src)
|
|
1381
|
+
?? readStringProp(props.fallbackSrc ?? props.fallback)
|
|
1382
|
+
?? "";
|
|
937
1383
|
const alt = readStringProp(props.alt) ?? "";
|
|
1384
|
+
const placeholderSrc = resolveMediaPlaceholderSource(props.placeholder);
|
|
1385
|
+
const fallbackSrc = readStringProp(props.fallbackSrc ?? props.fallback);
|
|
938
1386
|
return {
|
|
939
1387
|
src,
|
|
940
1388
|
alt,
|
|
@@ -947,11 +1395,21 @@ function resolveResuxImageRenderInput(node, context, locals) {
|
|
|
947
1395
|
decoding,
|
|
948
1396
|
fetchPriority,
|
|
949
1397
|
provider,
|
|
1398
|
+
cache,
|
|
950
1399
|
quality,
|
|
951
1400
|
fit,
|
|
952
|
-
format: explicitFormats.length
|
|
1401
|
+
format: explicitFormats.length
|
|
1402
|
+
? undefined
|
|
1403
|
+
: (hasExplicitFormat ? explicitFormat : (explicitFormat ?? runtimeImageConfig.format)),
|
|
953
1404
|
formats: explicitFormats,
|
|
954
1405
|
preload,
|
|
1406
|
+
deferLazy,
|
|
1407
|
+
lazyRootMargin,
|
|
1408
|
+
lazyThreshold,
|
|
1409
|
+
placeholderSrc,
|
|
1410
|
+
placeholderClass: readStringProp(props.placeholderClass),
|
|
1411
|
+
placeholderStyle: readStringProp(props.placeholderStyle),
|
|
1412
|
+
fallbackSrc,
|
|
955
1413
|
modifiers,
|
|
956
1414
|
attrs: passthrough,
|
|
957
1415
|
};
|
|
@@ -983,15 +1441,14 @@ function resolveResuxImageModifierProps(value) {
|
|
|
983
1441
|
return normalizeImageModifiers(value);
|
|
984
1442
|
}
|
|
985
1443
|
function buildResuxImageSrcset(builder, input) {
|
|
986
|
-
const widthCandidates = input
|
|
987
|
-
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
988
|
-
: [];
|
|
1444
|
+
const widthCandidates = resolveResuxImageWidthCandidates(input);
|
|
989
1445
|
if (widthCandidates.length) {
|
|
990
1446
|
return widthCandidates
|
|
991
1447
|
.map((width) => `${builder(input.src, {
|
|
992
1448
|
provider: input.provider,
|
|
1449
|
+
cache: input.cache,
|
|
993
1450
|
width,
|
|
994
|
-
height: input
|
|
1451
|
+
height: resolveResuxImageCandidateHeight(input, width),
|
|
995
1452
|
quality: input.quality,
|
|
996
1453
|
fit: input.fit,
|
|
997
1454
|
format: input.format,
|
|
@@ -1008,6 +1465,7 @@ function buildResuxImageSrcset(builder, input) {
|
|
|
1008
1465
|
const width = Math.max(1, Math.round(input.width * density));
|
|
1009
1466
|
return `${builder(input.src, {
|
|
1010
1467
|
provider: input.provider,
|
|
1468
|
+
cache: input.cache,
|
|
1011
1469
|
width,
|
|
1012
1470
|
height: input.height ? Math.max(1, Math.round(input.height * density)) : undefined,
|
|
1013
1471
|
quality: input.quality,
|
|
@@ -1018,7 +1476,84 @@ function buildResuxImageSrcset(builder, input) {
|
|
|
1018
1476
|
})
|
|
1019
1477
|
.join(", ");
|
|
1020
1478
|
}
|
|
1021
|
-
function
|
|
1479
|
+
function resolveResuxImageWidthCandidates(input) {
|
|
1480
|
+
const explicitWidths = input.widths.length
|
|
1481
|
+
? normalizeResuxImageWidthCandidates(input.widths, input.width)
|
|
1482
|
+
: [];
|
|
1483
|
+
if (explicitWidths.length) {
|
|
1484
|
+
return explicitWidths;
|
|
1485
|
+
}
|
|
1486
|
+
if (!input.sizes) {
|
|
1487
|
+
return [];
|
|
1488
|
+
}
|
|
1489
|
+
return resolveResuxImageWidthsFromSizes(input.sizes, input.densities, input.width);
|
|
1490
|
+
}
|
|
1491
|
+
function resolveResuxImageWidthsFromSizes(sizes, densities, maxWidth) {
|
|
1492
|
+
const descriptors = sizes
|
|
1493
|
+
.split(",")
|
|
1494
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
1495
|
+
.filter(Boolean);
|
|
1496
|
+
const baseWidths = [];
|
|
1497
|
+
for (const descriptor of descriptors) {
|
|
1498
|
+
const match = [...descriptor.matchAll(/([0-9]*\.?[0-9]+)\s*(px|vw)\b/g)].pop();
|
|
1499
|
+
if (!match) {
|
|
1500
|
+
continue;
|
|
1501
|
+
}
|
|
1502
|
+
const value = Number(match[1]);
|
|
1503
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
1504
|
+
continue;
|
|
1505
|
+
}
|
|
1506
|
+
if (match[2] === "px") {
|
|
1507
|
+
baseWidths.push(Math.round(value));
|
|
1508
|
+
continue;
|
|
1509
|
+
}
|
|
1510
|
+
for (const viewportWidth of resuxResponsiveViewportWidths) {
|
|
1511
|
+
baseWidths.push(Math.round((viewportWidth * value) / 100));
|
|
1512
|
+
}
|
|
1513
|
+
}
|
|
1514
|
+
const safeDensities = densities.length
|
|
1515
|
+
? [...new Set(densities)]
|
|
1516
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
1517
|
+
.sort((left, right) => left - right)
|
|
1518
|
+
: [1];
|
|
1519
|
+
const expandedWidths = baseWidths.flatMap((width) => safeDensities.map((density) => Math.round(width * density)));
|
|
1520
|
+
if (!expandedWidths.length && Number.isFinite(maxWidth) && maxWidth > 0) {
|
|
1521
|
+
return [Math.max(1, Math.round(maxWidth))];
|
|
1522
|
+
}
|
|
1523
|
+
return normalizeResuxImageWidthCandidates(expandedWidths, maxWidth);
|
|
1524
|
+
}
|
|
1525
|
+
function normalizeResuxImageWidthCandidates(candidates, maxWidth) {
|
|
1526
|
+
const resolvedMaxWidth = Number.isFinite(maxWidth) && maxWidth > 0
|
|
1527
|
+
? Math.round(maxWidth)
|
|
1528
|
+
: Number.POSITIVE_INFINITY;
|
|
1529
|
+
const normalized = [...new Set(candidates
|
|
1530
|
+
.map((entry) => Number(entry))
|
|
1531
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
1532
|
+
.map((entry) => Math.min(8192, Math.max(1, Math.round(entry)), resolvedMaxWidth)))]
|
|
1533
|
+
.sort((left, right) => left - right);
|
|
1534
|
+
const compacted = [];
|
|
1535
|
+
for (const width of normalized) {
|
|
1536
|
+
const previous = compacted[compacted.length - 1];
|
|
1537
|
+
const shouldKeep = previous === undefined
|
|
1538
|
+
|| width - previous >= 24
|
|
1539
|
+
|| (Number.isFinite(resolvedMaxWidth) && width === resolvedMaxWidth);
|
|
1540
|
+
if (shouldKeep) {
|
|
1541
|
+
compacted.push(width);
|
|
1542
|
+
}
|
|
1543
|
+
}
|
|
1544
|
+
return compacted;
|
|
1545
|
+
}
|
|
1546
|
+
function resolveResuxImageCandidateHeight(input, width) {
|
|
1547
|
+
if (!input.height) {
|
|
1548
|
+
return undefined;
|
|
1549
|
+
}
|
|
1550
|
+
if (!input.width) {
|
|
1551
|
+
return input.height;
|
|
1552
|
+
}
|
|
1553
|
+
const scaledHeight = Math.round((input.height / input.width) * width);
|
|
1554
|
+
return Math.max(1, scaledHeight);
|
|
1555
|
+
}
|
|
1556
|
+
function registerResuxImagePreload(context, href, srcset, input, enabled) {
|
|
1022
1557
|
if (!enabled || !href || !context.addHeadEntry) {
|
|
1023
1558
|
return;
|
|
1024
1559
|
}
|
|
@@ -1026,28 +1561,60 @@ function registerResuxImagePreload(context, href, srcset, sizes, enabled) {
|
|
|
1026
1561
|
rel: "preload",
|
|
1027
1562
|
as: "image",
|
|
1028
1563
|
href,
|
|
1564
|
+
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1029
1565
|
};
|
|
1030
1566
|
if (srcset) {
|
|
1031
1567
|
link.imagesrcset = srcset;
|
|
1032
1568
|
}
|
|
1033
|
-
if (sizes) {
|
|
1034
|
-
link.imagesizes = sizes;
|
|
1569
|
+
if (input.sizes) {
|
|
1570
|
+
link.imagesizes = input.sizes;
|
|
1571
|
+
}
|
|
1572
|
+
if (input.format && input.formats.length === 0) {
|
|
1573
|
+
link.type = resuxImageMimeType(input.format);
|
|
1035
1574
|
}
|
|
1036
1575
|
context.addHeadEntry({ link: [link] });
|
|
1037
1576
|
}
|
|
1038
1577
|
function renderResuxImgTag(input, src, srcset, styleScopeId) {
|
|
1039
1578
|
const attrs = [];
|
|
1579
|
+
const isDeferredLazy = input.deferLazy && input.loading.toLowerCase() === "lazy";
|
|
1580
|
+
const placeholderSrc = input.placeholderSrc;
|
|
1581
|
+
const placeholderClass = input.placeholderClass;
|
|
1582
|
+
const placeholderStyle = input.placeholderStyle;
|
|
1583
|
+
const aspectRatioStyle = resolveAspectRatioStyle(input.width, input.height, input.attrs.style, placeholderStyle);
|
|
1584
|
+
const placeholderBackground = placeholderSrc
|
|
1585
|
+
? `background-image: url('${placeholderSrc}'); background-size: cover; background-position: center; background-repeat: no-repeat`
|
|
1586
|
+
: undefined;
|
|
1587
|
+
const mergedClass = mergeClassNames(input.attrs.class, placeholderClass);
|
|
1588
|
+
const mergedStyle = mergeInlineStyles(input.attrs.style, aspectRatioStyle, !isDeferredLazy ? placeholderBackground : undefined, placeholderStyle);
|
|
1589
|
+
const initialSrc = isDeferredLazy
|
|
1590
|
+
? (placeholderSrc ?? resuxLazyPlaceholderSrc)
|
|
1591
|
+
: src;
|
|
1040
1592
|
const mergedAttrs = {
|
|
1041
1593
|
...input.attrs,
|
|
1042
|
-
|
|
1594
|
+
...(mergedClass ? { class: mergedClass } : {}),
|
|
1595
|
+
...(mergedStyle ? { style: mergedStyle } : {}),
|
|
1596
|
+
src: initialSrc,
|
|
1043
1597
|
alt: input.alt,
|
|
1044
1598
|
loading: input.loading,
|
|
1045
1599
|
decoding: input.decoding,
|
|
1600
|
+
"data-resux-media": "img",
|
|
1601
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
1602
|
+
...(isDeferredLazy ? { "data-resux-lazy": "true" } : {}),
|
|
1603
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src, "data-src": src } : {}),
|
|
1604
|
+
...(isDeferredLazy ? { "data-rx-lazy-root-margin": input.lazyRootMargin } : {}),
|
|
1605
|
+
...(isDeferredLazy ? { "data-rx-lazy-threshold": String(input.lazyThreshold) } : {}),
|
|
1606
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset, "data-srcset": srcset } : {}),
|
|
1607
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
1608
|
+
...(placeholderSrc ? { "data-rx-placeholder-src": placeholderSrc, "data-placeholder": placeholderSrc } : {}),
|
|
1609
|
+
...(placeholderClass ? { "data-rx-placeholder-class": placeholderClass } : {}),
|
|
1610
|
+
...(placeholderStyle ? { "data-rx-placeholder-style": placeholderStyle } : {}),
|
|
1611
|
+
...(placeholderSrc ? { "data-rx-placeholder-active": "true", "data-resux-placeholder-active": "true" } : {}),
|
|
1612
|
+
...(input.fallbackSrc ? { "data-rx-fallback-src": input.fallbackSrc } : {}),
|
|
1046
1613
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1047
1614
|
...(input.width ? { width: String(input.width) } : {}),
|
|
1048
1615
|
...(input.height ? { height: String(input.height) } : {}),
|
|
1049
|
-
...(srcset ? { srcset } : {}),
|
|
1050
|
-
...(input.sizes ? { sizes: input.sizes } : {}),
|
|
1616
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
1617
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {}),
|
|
1051
1618
|
};
|
|
1052
1619
|
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
1053
1620
|
if (value === undefined || value === null) {
|
|
@@ -1115,6 +1682,9 @@ function readBooleanProp(value, fallback) {
|
|
|
1115
1682
|
}
|
|
1116
1683
|
if (typeof value === "string") {
|
|
1117
1684
|
const normalized = value.trim().toLowerCase();
|
|
1685
|
+
if (normalized === "") {
|
|
1686
|
+
return true;
|
|
1687
|
+
}
|
|
1118
1688
|
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
1119
1689
|
return true;
|
|
1120
1690
|
}
|
|
@@ -1124,6 +1694,161 @@ function readBooleanProp(value, fallback) {
|
|
|
1124
1694
|
}
|
|
1125
1695
|
return fallback;
|
|
1126
1696
|
}
|
|
1697
|
+
function resolveMediaPlaceholderSource(value) {
|
|
1698
|
+
if (value === undefined || value === null || value === false) {
|
|
1699
|
+
return undefined;
|
|
1700
|
+
}
|
|
1701
|
+
if (value === true) {
|
|
1702
|
+
return resuxDefaultPlaceholderSrc;
|
|
1703
|
+
}
|
|
1704
|
+
if (typeof value !== "string") {
|
|
1705
|
+
return undefined;
|
|
1706
|
+
}
|
|
1707
|
+
const trimmed = value.trim();
|
|
1708
|
+
if (!trimmed) {
|
|
1709
|
+
return undefined;
|
|
1710
|
+
}
|
|
1711
|
+
const normalized = trimmed.toLowerCase();
|
|
1712
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
1713
|
+
return resuxDefaultPlaceholderSrc;
|
|
1714
|
+
}
|
|
1715
|
+
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
|
1716
|
+
return undefined;
|
|
1717
|
+
}
|
|
1718
|
+
if (looksLikeMediaSource(trimmed)) {
|
|
1719
|
+
return trimmed;
|
|
1720
|
+
}
|
|
1721
|
+
return createTextPlaceholderDataUri(trimmed);
|
|
1722
|
+
}
|
|
1723
|
+
function looksLikeMediaSource(value) {
|
|
1724
|
+
return (value.startsWith("/")
|
|
1725
|
+
|| value.startsWith("./")
|
|
1726
|
+
|| value.startsWith("../")
|
|
1727
|
+
|| value.startsWith("http://")
|
|
1728
|
+
|| value.startsWith("https://")
|
|
1729
|
+
|| value.startsWith("data:image/")
|
|
1730
|
+
|| value.startsWith("blob:"));
|
|
1731
|
+
}
|
|
1732
|
+
function createTextPlaceholderDataUri(value) {
|
|
1733
|
+
const safeLabel = escapeSvgText(value);
|
|
1734
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360" role="img" aria-label="${safeLabel}">`
|
|
1735
|
+
+ `<rect width="640" height="360" fill="#0f172a"/>`
|
|
1736
|
+
+ `<rect x="24" y="24" width="592" height="312" rx="20" fill="#111827" stroke="#334155" stroke-width="2"/>`
|
|
1737
|
+
+ `<text x="320" y="192" fill="#cbd5e1" font-size="30" text-anchor="middle" font-family="Segoe UI, Arial, sans-serif">${safeLabel}</text>`
|
|
1738
|
+
+ `</svg>`;
|
|
1739
|
+
return `data:image/svg+xml,${encodeURIComponent(svg)}`;
|
|
1740
|
+
}
|
|
1741
|
+
function escapeSvgText(value) {
|
|
1742
|
+
return value
|
|
1743
|
+
.replace(/&/g, "&")
|
|
1744
|
+
.replace(/</g, "<")
|
|
1745
|
+
.replace(/>/g, ">")
|
|
1746
|
+
.replace(/"/g, """)
|
|
1747
|
+
.replace(/'/g, "'");
|
|
1748
|
+
}
|
|
1749
|
+
function mergeClassNames(...values) {
|
|
1750
|
+
const tokens = values
|
|
1751
|
+
.flatMap((value) => String(value ?? "").split(/\s+/))
|
|
1752
|
+
.map((token) => token.trim())
|
|
1753
|
+
.filter(Boolean);
|
|
1754
|
+
return tokens.length ? [...new Set(tokens)].join(" ") : undefined;
|
|
1755
|
+
}
|
|
1756
|
+
function mergeInlineStyles(...values) {
|
|
1757
|
+
const parts = values
|
|
1758
|
+
.flatMap((value) => String(value ?? "").split(";"))
|
|
1759
|
+
.map((entry) => entry.trim())
|
|
1760
|
+
.filter(Boolean);
|
|
1761
|
+
return parts.length ? parts.join("; ") : undefined;
|
|
1762
|
+
}
|
|
1763
|
+
function hasInlineStyleProperty(styleValue, propertyName) {
|
|
1764
|
+
if (typeof styleValue !== "string") {
|
|
1765
|
+
return false;
|
|
1766
|
+
}
|
|
1767
|
+
const normalized = propertyName.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
1768
|
+
const pattern = new RegExp(`(^|;)\\s*${normalized}\\s*:`, "i");
|
|
1769
|
+
return pattern.test(styleValue);
|
|
1770
|
+
}
|
|
1771
|
+
function resolveAspectRatioStyle(width, height, ...styleValues) {
|
|
1772
|
+
if (!width || !height) {
|
|
1773
|
+
return undefined;
|
|
1774
|
+
}
|
|
1775
|
+
if (styleValues.some((entry) => hasInlineStyleProperty(entry, "aspect-ratio"))) {
|
|
1776
|
+
return undefined;
|
|
1777
|
+
}
|
|
1778
|
+
return `aspect-ratio: ${width} / ${height}`;
|
|
1779
|
+
}
|
|
1780
|
+
function resolvePictureSourceInputs(value, fallbackInput) {
|
|
1781
|
+
if (!Array.isArray(value)) {
|
|
1782
|
+
return [];
|
|
1783
|
+
}
|
|
1784
|
+
const resolved = [];
|
|
1785
|
+
for (const entry of value) {
|
|
1786
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
1787
|
+
continue;
|
|
1788
|
+
}
|
|
1789
|
+
const record = entry;
|
|
1790
|
+
const src = readStringProp(record.src) ?? fallbackInput.src;
|
|
1791
|
+
if (!src) {
|
|
1792
|
+
continue;
|
|
1793
|
+
}
|
|
1794
|
+
const hasQuality = Object.prototype.hasOwnProperty.call(record, "quality");
|
|
1795
|
+
const hasFormat = Object.prototype.hasOwnProperty.call(record, "format");
|
|
1796
|
+
const explicitFormat = readStringProp(record.format);
|
|
1797
|
+
const sourceWidths = parseImageNumberList(record.widths) ?? fallbackInput.widths;
|
|
1798
|
+
const baseModifiers = resolveResuxImageModifierProps(record.modifiers);
|
|
1799
|
+
const modifiers = normalizeImageModifiers({
|
|
1800
|
+
...fallbackInput.modifiers,
|
|
1801
|
+
...baseModifiers,
|
|
1802
|
+
...(hasFormat && !explicitFormat ? { format: false } : {}),
|
|
1803
|
+
...(hasQuality && !readNumberProp(record.quality) ? { quality: false } : {}),
|
|
1804
|
+
...(readStringProp(record.fit) ? { fit: readStringProp(record.fit) } : {}),
|
|
1805
|
+
...(readNumberProp(record.width) ? { width: readNumberProp(record.width) } : {}),
|
|
1806
|
+
...(readNumberProp(record.height) ? { height: readNumberProp(record.height) } : {}),
|
|
1807
|
+
...(readNumberProp(record.quality) ? { quality: readNumberProp(record.quality) } : {}),
|
|
1808
|
+
...(explicitFormat ? { format: explicitFormat } : {}),
|
|
1809
|
+
});
|
|
1810
|
+
resolved.push({
|
|
1811
|
+
src,
|
|
1812
|
+
srcset: readStringProp(record.srcset),
|
|
1813
|
+
type: readStringProp(record.type),
|
|
1814
|
+
media: readStringProp(record.media),
|
|
1815
|
+
sizes: readStringProp(record.sizes) ?? fallbackInput.sizes,
|
|
1816
|
+
width: readNumberProp(record.width) ?? fallbackInput.width,
|
|
1817
|
+
height: readNumberProp(record.height) ?? fallbackInput.height,
|
|
1818
|
+
widths: sourceWidths,
|
|
1819
|
+
quality: hasQuality
|
|
1820
|
+
? readNumberProp(record.quality)
|
|
1821
|
+
: fallbackInput.quality,
|
|
1822
|
+
format: hasFormat
|
|
1823
|
+
? explicitFormat
|
|
1824
|
+
: fallbackInput.format,
|
|
1825
|
+
fit: readStringProp(record.fit) ?? fallbackInput.fit,
|
|
1826
|
+
modifiers,
|
|
1827
|
+
});
|
|
1828
|
+
}
|
|
1829
|
+
return resolved;
|
|
1830
|
+
}
|
|
1831
|
+
function resolveVideoSources(value) {
|
|
1832
|
+
if (!Array.isArray(value)) {
|
|
1833
|
+
return [];
|
|
1834
|
+
}
|
|
1835
|
+
const sources = [];
|
|
1836
|
+
for (const entry of value) {
|
|
1837
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
1838
|
+
continue;
|
|
1839
|
+
}
|
|
1840
|
+
const record = entry;
|
|
1841
|
+
const src = readStringProp(record.src);
|
|
1842
|
+
if (!src) {
|
|
1843
|
+
continue;
|
|
1844
|
+
}
|
|
1845
|
+
sources.push({
|
|
1846
|
+
src,
|
|
1847
|
+
type: readStringProp(record.type),
|
|
1848
|
+
});
|
|
1849
|
+
}
|
|
1850
|
+
return sources;
|
|
1851
|
+
}
|
|
1127
1852
|
function resuxImageMimeType(format) {
|
|
1128
1853
|
const normalized = format.toLowerCase();
|
|
1129
1854
|
if (normalized === "jpg") {
|
|
@@ -1131,6 +1856,21 @@ function resuxImageMimeType(format) {
|
|
|
1131
1856
|
}
|
|
1132
1857
|
return normalized.startsWith("image/") ? normalized : `image/${normalized}`;
|
|
1133
1858
|
}
|
|
1859
|
+
function inferImageMimeTypeFromSource(src) {
|
|
1860
|
+
const clean = src.split(/[?#]/)[0]?.toLowerCase();
|
|
1861
|
+
if (!clean) {
|
|
1862
|
+
return undefined;
|
|
1863
|
+
}
|
|
1864
|
+
const dotIndex = clean.lastIndexOf(".");
|
|
1865
|
+
if (dotIndex < 0) {
|
|
1866
|
+
return undefined;
|
|
1867
|
+
}
|
|
1868
|
+
const extension = clean.slice(dotIndex + 1);
|
|
1869
|
+
if (!extension) {
|
|
1870
|
+
return undefined;
|
|
1871
|
+
}
|
|
1872
|
+
return resuxImageMimeType(extension);
|
|
1873
|
+
}
|
|
1134
1874
|
function renderVueIsland(node, context, locals) {
|
|
1135
1875
|
const name = resolveVueIslandName(node, context, locals);
|
|
1136
1876
|
const props = resolveVueIslandProps(node, context, locals);
|
|
@@ -1286,7 +2026,7 @@ export class AsyncResuxRenderer {
|
|
|
1286
2026
|
components: this.components,
|
|
1287
2027
|
layouts: this.layouts,
|
|
1288
2028
|
pageMeta: this.pageMeta,
|
|
1289
|
-
addHeadEntry: (entry) => this.headEntries
|
|
2029
|
+
addHeadEntry: (entry) => insertHeadEntryWithPriority(this.headEntries, entry),
|
|
1290
2030
|
renderPage,
|
|
1291
2031
|
renderSlot,
|
|
1292
2032
|
renderLayout: (name, slot) => this.renderLayout(name, slot)
|
|
@@ -1514,15 +2254,22 @@ function mergeHead(entries) {
|
|
|
1514
2254
|
merged.style.push(...entry.style);
|
|
1515
2255
|
}
|
|
1516
2256
|
}
|
|
2257
|
+
merged.link = sortHeadLinksForPriority(merged.link ?? []);
|
|
1517
2258
|
return merged;
|
|
1518
2259
|
}
|
|
1519
2260
|
function renderHead(head) {
|
|
1520
2261
|
const tags = [];
|
|
1521
2262
|
tags.push(`<title>${escapeHtml(head.title ?? "Resux App")}</title>`);
|
|
2263
|
+
const links = sortHeadLinksForPriority(head.link ?? []);
|
|
2264
|
+
const highPriorityImagePreloads = links.filter((link) => isPriorityImagePreloadLink(link));
|
|
2265
|
+
const remainingLinks = links.filter((link) => !isPriorityImagePreloadLink(link));
|
|
2266
|
+
for (const link of highPriorityImagePreloads) {
|
|
2267
|
+
tags.push(`<link data-rx-head="true" ${renderAttributes(link)}>`);
|
|
2268
|
+
}
|
|
1522
2269
|
for (const meta of head.meta ?? []) {
|
|
1523
2270
|
tags.push(`<meta data-rx-head="true" ${renderAttributes(meta)}>`);
|
|
1524
2271
|
}
|
|
1525
|
-
for (const link of
|
|
2272
|
+
for (const link of remainingLinks) {
|
|
1526
2273
|
tags.push(`<link data-rx-head="true" ${renderAttributes(link)}>`);
|
|
1527
2274
|
}
|
|
1528
2275
|
for (const style of head.style ?? []) {
|
|
@@ -1530,6 +2277,49 @@ function renderHead(head) {
|
|
|
1530
2277
|
}
|
|
1531
2278
|
return tags.join("");
|
|
1532
2279
|
}
|
|
2280
|
+
function sortHeadLinksForPriority(links) {
|
|
2281
|
+
return links
|
|
2282
|
+
.map((link, index) => ({
|
|
2283
|
+
link,
|
|
2284
|
+
index,
|
|
2285
|
+
priority: isPriorityImagePreloadLink(link)
|
|
2286
|
+
? 0
|
|
2287
|
+
: normalizeHeadLinkRel(link) === "preload"
|
|
2288
|
+
? 1
|
|
2289
|
+
: 2,
|
|
2290
|
+
}))
|
|
2291
|
+
.sort((left, right) => left.priority - right.priority || left.index - right.index)
|
|
2292
|
+
.map((entry) => entry.link);
|
|
2293
|
+
}
|
|
2294
|
+
function normalizeHeadLinkRel(link) {
|
|
2295
|
+
return String(link.rel ?? "").trim().toLowerCase();
|
|
2296
|
+
}
|
|
2297
|
+
function isPriorityImagePreloadLink(link) {
|
|
2298
|
+
if (normalizeHeadLinkRel(link) !== "preload") {
|
|
2299
|
+
return false;
|
|
2300
|
+
}
|
|
2301
|
+
return String(link.as ?? "").trim().toLowerCase() === "image";
|
|
2302
|
+
}
|
|
2303
|
+
function isPriorityImagePreloadEntry(entry) {
|
|
2304
|
+
return (!entry.title
|
|
2305
|
+
&& !entry.meta
|
|
2306
|
+
&& !entry.style
|
|
2307
|
+
&& Array.isArray(entry.link)
|
|
2308
|
+
&& entry.link.length > 0
|
|
2309
|
+
&& entry.link.every((link) => isPriorityImagePreloadLink(link)));
|
|
2310
|
+
}
|
|
2311
|
+
function insertHeadEntryWithPriority(entries, entry) {
|
|
2312
|
+
if (!isPriorityImagePreloadEntry(entry)) {
|
|
2313
|
+
entries.push(entry);
|
|
2314
|
+
return;
|
|
2315
|
+
}
|
|
2316
|
+
const insertionIndex = entries.findIndex((candidate) => !isPriorityImagePreloadEntry(candidate));
|
|
2317
|
+
if (insertionIndex === -1) {
|
|
2318
|
+
entries.push(entry);
|
|
2319
|
+
return;
|
|
2320
|
+
}
|
|
2321
|
+
entries.splice(insertionIndex, 0, entry);
|
|
2322
|
+
}
|
|
1533
2323
|
function escapeStyleContent(css) {
|
|
1534
2324
|
return css.replace(/<\/style/gi, "<\\/style");
|
|
1535
2325
|
}
|
|
@@ -1622,7 +2412,7 @@ function collectPatches(nodes, scope, scopeId, locals, patches, styleScopeId) {
|
|
|
1622
2412
|
value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals))
|
|
1623
2413
|
});
|
|
1624
2414
|
}
|
|
1625
|
-
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
2415
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture" && node.tag !== "ResuxVideo") {
|
|
1626
2416
|
for (const attr of node.attrs) {
|
|
1627
2417
|
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
1628
2418
|
patches.push({
|
|
@@ -1679,9 +2469,18 @@ let routeTransitionProgressTimer = 0;
|
|
|
1679
2469
|
let routeTransitionStartedAt = 0;
|
|
1680
2470
|
let routeTransitionVisible = false;
|
|
1681
2471
|
let routeTransitionIndicator = null;
|
|
2472
|
+
const lazyImageObservers = new Map();
|
|
2473
|
+
const lazyVideoObservers = new Map();
|
|
1682
2474
|
const clientPluginIds = new Set();
|
|
1683
2475
|
const clientMiddlewareById = new Map();
|
|
1684
2476
|
const clientProvides = globalThis.__RESUX_PROVIDES__ ||= {};
|
|
2477
|
+
const RESUX_LAZY_PLACEHOLDER_SRC = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
2478
|
+
const RESUX_DEFAULT_PLACEHOLDER_SRC = "/__resux/resux-placeholder.svg";
|
|
2479
|
+
const observedLazyImages = new Set();
|
|
2480
|
+
const observedLazyVideos = new Set();
|
|
2481
|
+
const lazyImageObserverByElement = new WeakMap();
|
|
2482
|
+
const lazyVideoObserverByElement = new WeakMap();
|
|
2483
|
+
const failedMediaSources = new Set();
|
|
1685
2484
|
|
|
1686
2485
|
const __rxFlags = {
|
|
1687
2486
|
isReactive: "__v_isReactive",
|
|
@@ -2205,33 +3004,7 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2205
3004
|
const providerName = String(options.provider || imageConfig.provider || "resux").trim().toLowerCase();
|
|
2206
3005
|
const providerConfig = imageConfig.providers[providerName] || {};
|
|
2207
3006
|
const baseURL = providerConfig.baseURL || (providerName === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
2208
|
-
const
|
|
2209
|
-
|
|
2210
|
-
if (baseURL.includes("{src}")) {
|
|
2211
|
-
let resolved = baseURL.replaceAll("{src}", encodeURIComponent(normalizedSrc));
|
|
2212
|
-
const templateModifiers = {
|
|
2213
|
-
...(providerConfig.modifiers || {}),
|
|
2214
|
-
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
2215
|
-
...(typeof imageConfig.format === "string" ? { format: imageConfig.format } : {}),
|
|
2216
|
-
...(options.modifiers || {}),
|
|
2217
|
-
...(Number.isFinite(options.width) ? { width: Math.round(options.width) } : {}),
|
|
2218
|
-
...(Number.isFinite(options.height) ? { height: Math.round(options.height) } : {}),
|
|
2219
|
-
...(Number.isFinite(options.quality) ? { quality: Math.round(options.quality) } : {}),
|
|
2220
|
-
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2221
|
-
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2222
|
-
};
|
|
2223
|
-
for (const [key, value] of Object.entries(templateModifiers)) {
|
|
2224
|
-
resolved = resolved.replaceAll("{" + key + "}", encodeURIComponent(String(value)));
|
|
2225
|
-
}
|
|
2226
|
-
return resolved;
|
|
2227
|
-
}
|
|
2228
|
-
|
|
2229
|
-
if (providerName === "vercel") {
|
|
2230
|
-
query.set("url", normalizedSrc);
|
|
2231
|
-
} else {
|
|
2232
|
-
query.set("src", normalizedSrc);
|
|
2233
|
-
}
|
|
2234
|
-
|
|
3007
|
+
const cacheOption = normalizeClientImageCacheValue(options.cache ?? imageConfig.cache);
|
|
2235
3008
|
const modifiers = {
|
|
2236
3009
|
...(providerConfig.modifiers || {}),
|
|
2237
3010
|
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
@@ -2243,12 +3016,45 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2243
3016
|
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2244
3017
|
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2245
3018
|
};
|
|
3019
|
+
const normalizedFormat = normalizeClientImageOutputFormat(
|
|
3020
|
+
typeof modifiers.format === "string" ? modifiers.format : undefined
|
|
3021
|
+
);
|
|
2246
3022
|
|
|
2247
|
-
if (
|
|
2248
|
-
|
|
2249
|
-
|
|
2250
|
-
|
|
2251
|
-
|
|
3023
|
+
if (baseURL.includes("{src}")) {
|
|
3024
|
+
let resolved = baseURL.replaceAll("{src}", encodeURIComponent(normalizedSrc));
|
|
3025
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
3026
|
+
resolved = resolved.replaceAll("{" + key + "}", encodeURIComponent(String(value)));
|
|
3027
|
+
}
|
|
3028
|
+
return resolved;
|
|
3029
|
+
}
|
|
3030
|
+
|
|
3031
|
+
const query = new URLSearchParams();
|
|
3032
|
+
const sourceDescriptor = providerName === "vercel"
|
|
3033
|
+
? { publicSource: normalizedSrc }
|
|
3034
|
+
: rewriteClientImageSourceForDisplayFormat(normalizedSrc, normalizedFormat);
|
|
3035
|
+
const useGeneratedCache = providerName === "resux" && typeof cacheOption === "string" && cacheOption.length > 0;
|
|
3036
|
+
|
|
3037
|
+
if (providerName === "vercel") {
|
|
3038
|
+
query.set("url", normalizedSrc);
|
|
3039
|
+
} else {
|
|
3040
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
3041
|
+
if (sourceDescriptor.originalSource) {
|
|
3042
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
3043
|
+
}
|
|
3044
|
+
}
|
|
3045
|
+
|
|
3046
|
+
const width = Number(modifiers.width);
|
|
3047
|
+
const height = Number(modifiers.height);
|
|
3048
|
+
const quality = Number(modifiers.quality);
|
|
3049
|
+
if (Number.isFinite(width) && width > 0) query.set("w", String(Math.round(width)));
|
|
3050
|
+
if (Number.isFinite(height) && height > 0) query.set("h", String(Math.round(height)));
|
|
3051
|
+
if (Number.isFinite(quality) && quality > 0) query.set("q", String(Math.round(quality)));
|
|
3052
|
+
if (typeof modifiers.fit === "string" && modifiers.fit) query.set("fit", modifiers.fit);
|
|
3053
|
+
if (normalizedFormat) {
|
|
3054
|
+
query.set("f", normalizedFormat);
|
|
3055
|
+
} else if (typeof modifiers.format === "string" && modifiers.format) {
|
|
3056
|
+
query.set("f", modifiers.format);
|
|
3057
|
+
}
|
|
2252
3058
|
|
|
2253
3059
|
for (const [key, value] of Object.entries(modifiers)) {
|
|
2254
3060
|
if (["width", "height", "quality", "fit", "format"].includes(key)) continue;
|
|
@@ -2256,11 +3062,205 @@ function createClientImageBuilder(route, runtimeConfig) {
|
|
|
2256
3062
|
query.set(key, String(value));
|
|
2257
3063
|
}
|
|
2258
3064
|
|
|
3065
|
+
if (useGeneratedCache) {
|
|
3066
|
+
query.set("cache", cacheOption);
|
|
3067
|
+
const generatedPath = createClientGeneratedImageRoutePath(
|
|
3068
|
+
sourceDescriptor.publicSource,
|
|
3069
|
+
sourceDescriptor.originalSource,
|
|
3070
|
+
normalizedFormat,
|
|
3071
|
+
modifiers,
|
|
3072
|
+
);
|
|
3073
|
+
const queryString = query.toString();
|
|
3074
|
+
return queryString ? generatedPath + "?" + queryString : generatedPath;
|
|
3075
|
+
}
|
|
3076
|
+
|
|
2259
3077
|
const separator = baseURL.includes("?") ? "&" : "?";
|
|
2260
3078
|
return query.toString() ? baseURL + separator + query.toString() : baseURL;
|
|
2261
3079
|
};
|
|
2262
3080
|
}
|
|
2263
3081
|
|
|
3082
|
+
function normalizeClientImageCacheValue(value) {
|
|
3083
|
+
if (value === undefined || value === null || value === false) {
|
|
3084
|
+
return undefined;
|
|
3085
|
+
}
|
|
3086
|
+
if (value === true) {
|
|
3087
|
+
return "1d";
|
|
3088
|
+
}
|
|
3089
|
+
if (typeof value === "number") {
|
|
3090
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
3091
|
+
return undefined;
|
|
3092
|
+
}
|
|
3093
|
+
return String(Math.round(value));
|
|
3094
|
+
}
|
|
3095
|
+
if (typeof value === "string") {
|
|
3096
|
+
const normalized = value.trim().toLowerCase();
|
|
3097
|
+
if (!normalized || normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
3098
|
+
return "1d";
|
|
3099
|
+
}
|
|
3100
|
+
if (normalized === "false" || normalized === "0" || normalized === "off" || normalized === "no") {
|
|
3101
|
+
return undefined;
|
|
3102
|
+
}
|
|
3103
|
+
return normalized;
|
|
3104
|
+
}
|
|
3105
|
+
if (typeof value === "object" && !Array.isArray(value)) {
|
|
3106
|
+
for (const key of ["maxAge", "expiresIn", "ttl"]) {
|
|
3107
|
+
const normalized = normalizeClientImageCacheValue(value[key]);
|
|
3108
|
+
if (normalized) {
|
|
3109
|
+
return normalized;
|
|
3110
|
+
}
|
|
3111
|
+
}
|
|
3112
|
+
}
|
|
3113
|
+
return undefined;
|
|
3114
|
+
}
|
|
3115
|
+
|
|
3116
|
+
function createClientGeneratedImageRoutePath(source, originalSource, normalizedFormat, modifiers) {
|
|
3117
|
+
const extension =
|
|
3118
|
+
normalizedFormat
|
|
3119
|
+
|| inferClientImageExtensionFromSource(source)
|
|
3120
|
+
|| inferClientImageExtensionFromSource(originalSource)
|
|
3121
|
+
|| "bin";
|
|
3122
|
+
const signature = createClientImageTransformSignature(source, originalSource, normalizedFormat, modifiers);
|
|
3123
|
+
const digest = hashClientImageSignature(signature);
|
|
3124
|
+
return "/_resux/generated/images/" + digest + "." + extension;
|
|
3125
|
+
}
|
|
3126
|
+
|
|
3127
|
+
function createClientImageTransformSignature(source, originalSource, normalizedFormat, modifiers) {
|
|
3128
|
+
const entries = ["src=" + source];
|
|
3129
|
+
if (originalSource) {
|
|
3130
|
+
entries.push("original=" + originalSource);
|
|
3131
|
+
}
|
|
3132
|
+
|
|
3133
|
+
const width = Number(modifiers.width);
|
|
3134
|
+
if (Number.isFinite(width) && width > 0) {
|
|
3135
|
+
entries.push("w=" + Math.round(width));
|
|
3136
|
+
}
|
|
3137
|
+
const height = Number(modifiers.height);
|
|
3138
|
+
if (Number.isFinite(height) && height > 0) {
|
|
3139
|
+
entries.push("h=" + Math.round(height));
|
|
3140
|
+
}
|
|
3141
|
+
if (typeof modifiers.fit === "string" && modifiers.fit) {
|
|
3142
|
+
entries.push("fit=" + modifiers.fit);
|
|
3143
|
+
}
|
|
3144
|
+
if (normalizedFormat) {
|
|
3145
|
+
entries.push("f=" + normalizedFormat);
|
|
3146
|
+
}
|
|
3147
|
+
const quality = Number(modifiers.quality);
|
|
3148
|
+
if (Number.isFinite(quality) && quality > 0) {
|
|
3149
|
+
entries.push("q=" + Math.round(quality));
|
|
3150
|
+
}
|
|
3151
|
+
|
|
3152
|
+
const extraKeys = Object.keys(modifiers)
|
|
3153
|
+
.filter((key) => !["width", "height", "quality", "fit", "format", "cache"].includes(key))
|
|
3154
|
+
.sort();
|
|
3155
|
+
for (const key of extraKeys) {
|
|
3156
|
+
const value = modifiers[key];
|
|
3157
|
+
if (value === undefined || value === null || value === false) {
|
|
3158
|
+
continue;
|
|
3159
|
+
}
|
|
3160
|
+
entries.push(key + "=" + String(value));
|
|
3161
|
+
}
|
|
3162
|
+
|
|
3163
|
+
return entries.join("&");
|
|
3164
|
+
}
|
|
3165
|
+
|
|
3166
|
+
function hashClientImageSignature(value) {
|
|
3167
|
+
let hash = 2166136261;
|
|
3168
|
+
for (let index = 0; index < value.length; index++) {
|
|
3169
|
+
hash ^= value.charCodeAt(index);
|
|
3170
|
+
hash += (hash << 1) + (hash << 4) + (hash << 7) + (hash << 8) + (hash << 24);
|
|
3171
|
+
}
|
|
3172
|
+
return (hash >>> 0).toString(16).padStart(8, "0");
|
|
3173
|
+
}
|
|
3174
|
+
|
|
3175
|
+
function inferClientImageExtensionFromSource(value) {
|
|
3176
|
+
if (!value) {
|
|
3177
|
+
return undefined;
|
|
3178
|
+
}
|
|
3179
|
+
|
|
3180
|
+
const trimmed = String(value).trim();
|
|
3181
|
+
if (!trimmed) {
|
|
3182
|
+
return undefined;
|
|
3183
|
+
}
|
|
3184
|
+
|
|
3185
|
+
if (trimmed.startsWith("data:")) {
|
|
3186
|
+
const mimeMatch = /^data:image\/([a-zA-Z0-9.+-]+);/i.exec(trimmed);
|
|
3187
|
+
if (!mimeMatch) {
|
|
3188
|
+
return undefined;
|
|
3189
|
+
}
|
|
3190
|
+
const normalized = mimeMatch[1].toLowerCase();
|
|
3191
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
3192
|
+
}
|
|
3193
|
+
|
|
3194
|
+
const withoutQuery = trimmed.split(/[?#]/)[0];
|
|
3195
|
+
const dotIndex = withoutQuery.lastIndexOf(".");
|
|
3196
|
+
if (dotIndex < 0) {
|
|
3197
|
+
return undefined;
|
|
3198
|
+
}
|
|
3199
|
+
const extension = withoutQuery.slice(dotIndex + 1).toLowerCase();
|
|
3200
|
+
if (!extension) {
|
|
3201
|
+
return undefined;
|
|
3202
|
+
}
|
|
3203
|
+
return extension === "jpg" ? "jpeg" : extension;
|
|
3204
|
+
}
|
|
3205
|
+
|
|
3206
|
+
function normalizeClientImageOutputFormat(value) {
|
|
3207
|
+
if (typeof value !== "string") {
|
|
3208
|
+
return undefined;
|
|
3209
|
+
}
|
|
3210
|
+
const normalized = value.trim().toLowerCase();
|
|
3211
|
+
if (!normalized) {
|
|
3212
|
+
return undefined;
|
|
3213
|
+
}
|
|
3214
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
3215
|
+
}
|
|
3216
|
+
|
|
3217
|
+
function rewriteClientImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
3218
|
+
if (!normalizedFormat) {
|
|
3219
|
+
return { publicSource: src };
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
3223
|
+
return { publicSource: src };
|
|
3224
|
+
}
|
|
3225
|
+
|
|
3226
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
3227
|
+
try {
|
|
3228
|
+
const sourceUrl = new URL(src);
|
|
3229
|
+
const rewrittenPathname = rewriteClientImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
3230
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
3231
|
+
return { publicSource: src };
|
|
3232
|
+
}
|
|
3233
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
3234
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
3235
|
+
} catch {
|
|
3236
|
+
return { publicSource: src };
|
|
3237
|
+
}
|
|
3238
|
+
}
|
|
3239
|
+
|
|
3240
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
3241
|
+
const rewrittenPath = rewriteClientImagePathExtension(pathPart, normalizedFormat);
|
|
3242
|
+
if (rewrittenPath === pathPart) {
|
|
3243
|
+
return { publicSource: src };
|
|
3244
|
+
}
|
|
3245
|
+
|
|
3246
|
+
return { publicSource: rewrittenPath + suffix, originalSource: src };
|
|
3247
|
+
}
|
|
3248
|
+
|
|
3249
|
+
function rewriteClientImagePathExtension(pathname, extension) {
|
|
3250
|
+
if (!pathname) {
|
|
3251
|
+
return pathname;
|
|
3252
|
+
}
|
|
3253
|
+
const normalizedExtension = extension.startsWith(".")
|
|
3254
|
+
? extension.slice(1)
|
|
3255
|
+
: extension;
|
|
3256
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
3257
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
3258
|
+
if (lastDot > lastSlash) {
|
|
3259
|
+
return pathname.slice(0, lastDot + 1) + normalizedExtension;
|
|
3260
|
+
}
|
|
3261
|
+
return pathname + "." + normalizedExtension;
|
|
3262
|
+
}
|
|
3263
|
+
|
|
2264
3264
|
function normalizeClientImageSource(src, route) {
|
|
2265
3265
|
const value = String(src || "").trim();
|
|
2266
3266
|
if (!value) return "";
|
|
@@ -2288,8 +3288,11 @@ function readClientImageConfig(runtimeConfig) {
|
|
|
2288
3288
|
: undefined;
|
|
2289
3289
|
return {
|
|
2290
3290
|
provider: typeof image.provider === "string" ? image.provider : undefined,
|
|
2291
|
-
quality: Number.isFinite(image.quality)
|
|
3291
|
+
quality: Number.isFinite(image.quality)
|
|
3292
|
+
? Math.min(100, Math.max(1, Math.round(Number(image.quality) || 1)))
|
|
3293
|
+
: undefined,
|
|
2292
3294
|
format: typeof image.format === "string" ? image.format : undefined,
|
|
3295
|
+
cache: normalizeClientImageCacheValue(image.cache),
|
|
2293
3296
|
densities: densities && densities.length ? densities : undefined,
|
|
2294
3297
|
providers
|
|
2295
3298
|
};
|
|
@@ -2554,46 +3557,806 @@ function installResux() {
|
|
|
2554
3557
|
document.addEventListener("pointerover", (event) => {
|
|
2555
3558
|
void prefetchNavigationTarget(event);
|
|
2556
3559
|
});
|
|
2557
|
-
document.addEventListener("focusin", (event) => {
|
|
2558
|
-
void prefetchNavigationTarget(event);
|
|
2559
|
-
});
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
void
|
|
2568
|
-
});
|
|
2569
|
-
|
|
2570
|
-
|
|
3560
|
+
document.addEventListener("focusin", (event) => {
|
|
3561
|
+
void prefetchNavigationTarget(event);
|
|
3562
|
+
});
|
|
3563
|
+
document.addEventListener("load", handleManagedMediaLoad, true);
|
|
3564
|
+
document.addEventListener("error", handleManagedMediaError, true);
|
|
3565
|
+
document.addEventListener("loadedmetadata", handleManagedVideoReady, true);
|
|
3566
|
+
document.addEventListener("loadeddata", handleManagedVideoReady, true);
|
|
3567
|
+
document.addEventListener("canplay", handleManagedVideoReady, true);
|
|
3568
|
+
for (const eventName of ["input", "change", "submit", "keydown", "keyup", "keypress", "mousedown", "mouseup", "blur", "focusout"]) {
|
|
3569
|
+
document.addEventListener(eventName, (event) => {
|
|
3570
|
+
void handleDelegatedEvent(eventName, event);
|
|
3571
|
+
});
|
|
3572
|
+
}
|
|
3573
|
+
for (const eventName of ["load", "error", "loadstart", "loadedmetadata", "loadeddata", "canplay", "lazy-load-start", "lazy-load-complete"]) {
|
|
3574
|
+
document.addEventListener(eventName, (event) => {
|
|
3575
|
+
void handleDelegatedEvent(eventName, event);
|
|
3576
|
+
}, true);
|
|
3577
|
+
}
|
|
3578
|
+
if (typeof window !== "undefined" && typeof history !== "undefined" && typeof location !== "undefined") {
|
|
3579
|
+
window.addEventListener("popstate", () => {
|
|
3580
|
+
void navigateTo(location.pathname + location.search + location.hash, {
|
|
3581
|
+
replace: true,
|
|
3582
|
+
force: true,
|
|
3583
|
+
preserveScroll: true,
|
|
3584
|
+
});
|
|
3585
|
+
});
|
|
3586
|
+
if (!history.state || !history.state.__resux) {
|
|
3587
|
+
history.replaceState({ __resux: true, path: location.pathname + location.search }, "", location.href);
|
|
2571
3588
|
}
|
|
2572
3589
|
}
|
|
2573
3590
|
if (typeof window !== "undefined") {
|
|
2574
3591
|
window.__RESUX_APPLY_DEV_UPDATE__ = applyDevUpdate;
|
|
2575
3592
|
}
|
|
2576
|
-
void initializeClientRuntime();
|
|
3593
|
+
void initializeClientRuntime();
|
|
3594
|
+
}
|
|
3595
|
+
|
|
3596
|
+
async function initializeClientRuntime() {
|
|
3597
|
+
const payload = globalThis.__RESUX__;
|
|
3598
|
+
if (!payload) {
|
|
3599
|
+
return;
|
|
3600
|
+
}
|
|
3601
|
+
await ensureClientPlugins(payload);
|
|
3602
|
+
const middlewareResult = await runClientRouteMiddleware(payload, { path: "", params: {}, query: {} });
|
|
3603
|
+
if (middlewareResult?.type === "redirect") {
|
|
3604
|
+
await navigateTo(middlewareResult.to, { replace: true });
|
|
3605
|
+
return;
|
|
3606
|
+
}
|
|
3607
|
+
if (middlewareResult?.type === "abort") {
|
|
3608
|
+
return;
|
|
3609
|
+
}
|
|
3610
|
+
void resumePendingAsyncData();
|
|
3611
|
+
void mountVueIslands();
|
|
3612
|
+
activateDeferredLazyMedia();
|
|
3613
|
+
applyReducedMotionVideoPreference();
|
|
3614
|
+
}
|
|
3615
|
+
|
|
3616
|
+
function activateDeferredLazyMedia(root = document) {
|
|
3617
|
+
cleanupDetachedLazyMedia();
|
|
3618
|
+
activateDeferredLazyImages(root);
|
|
3619
|
+
activateDeferredLazyVideos(root);
|
|
3620
|
+
dispatchPageReadyEvent(root);
|
|
3621
|
+
}
|
|
3622
|
+
|
|
3623
|
+
function activateDeferredLazyImages(root = document) {
|
|
3624
|
+
const images = root.querySelectorAll ? root.querySelectorAll("img[data-rx-lazy-image='true']") : [];
|
|
3625
|
+
if (!images.length) {
|
|
3626
|
+
return;
|
|
3627
|
+
}
|
|
3628
|
+
for (const image of images) {
|
|
3629
|
+
if (!isManagedMediaConnected(image)) {
|
|
3630
|
+
continue;
|
|
3631
|
+
}
|
|
3632
|
+
if (
|
|
3633
|
+
image.getAttribute("data-rx-lazy-ready") === "true"
|
|
3634
|
+
|| image.getAttribute("data-resux-loaded") === "true"
|
|
3635
|
+
|| image.getAttribute("data-resux-error-handled") === "true"
|
|
3636
|
+
|| observedLazyImages.has(image)
|
|
3637
|
+
) {
|
|
3638
|
+
continue;
|
|
3639
|
+
}
|
|
3640
|
+
const observer = getLazyImageObserver(image);
|
|
3641
|
+
if (!observer) {
|
|
3642
|
+
revealDeferredLazyImage(image);
|
|
3643
|
+
continue;
|
|
3644
|
+
}
|
|
3645
|
+
observedLazyImages.add(image);
|
|
3646
|
+
lazyImageObserverByElement.set(image, observer);
|
|
3647
|
+
image.setAttribute("data-rx-lazy-observed", "true");
|
|
3648
|
+
image.setAttribute("data-resux-observed", "true");
|
|
3649
|
+
observer.observe(image);
|
|
3650
|
+
}
|
|
3651
|
+
}
|
|
3652
|
+
|
|
3653
|
+
function getLazyImageObserver(image) {
|
|
3654
|
+
if (typeof IntersectionObserver !== "function") {
|
|
3655
|
+
return null;
|
|
3656
|
+
}
|
|
3657
|
+
const rootMargin = image.getAttribute("data-rx-lazy-root-margin") || "0px 0px";
|
|
3658
|
+
const thresholdRaw = Number(image.getAttribute("data-rx-lazy-threshold"));
|
|
3659
|
+
const threshold = Number.isFinite(thresholdRaw) ? Math.min(1, Math.max(0, thresholdRaw)) : 0;
|
|
3660
|
+
const key = rootMargin + "|" + String(threshold);
|
|
3661
|
+
if (lazyImageObservers.has(key)) {
|
|
3662
|
+
return lazyImageObservers.get(key);
|
|
3663
|
+
}
|
|
3664
|
+
const observer = new IntersectionObserver((entries) => {
|
|
3665
|
+
for (const entry of entries) {
|
|
3666
|
+
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
3667
|
+
continue;
|
|
3668
|
+
}
|
|
3669
|
+
const target = entry.target;
|
|
3670
|
+
observer.unobserve(target);
|
|
3671
|
+
revealDeferredLazyImage(target);
|
|
3672
|
+
}
|
|
3673
|
+
}, { rootMargin, threshold });
|
|
3674
|
+
lazyImageObservers.set(key, observer);
|
|
3675
|
+
return observer;
|
|
3676
|
+
}
|
|
3677
|
+
|
|
3678
|
+
function revealDeferredLazyImage(image) {
|
|
3679
|
+
if (!image || !isManagedMediaConnected(image)) {
|
|
3680
|
+
return;
|
|
3681
|
+
}
|
|
3682
|
+
unobserveLazyImage(image);
|
|
3683
|
+
|
|
3684
|
+
if (
|
|
3685
|
+
image.getAttribute("data-rx-lazy-ready") === "true"
|
|
3686
|
+
|| image.getAttribute("data-resux-loaded") === "true"
|
|
3687
|
+
|| image.getAttribute("data-resux-error-handled") === "true"
|
|
3688
|
+
) {
|
|
3689
|
+
return;
|
|
3690
|
+
}
|
|
3691
|
+
|
|
3692
|
+
const targetSrc = image.getAttribute("data-rx-lazy-src") || image.getAttribute("data-src") || "";
|
|
3693
|
+
if (targetSrc && mediaSourceWasFailed(image, targetSrc)) {
|
|
3694
|
+
applyKnownImageFailure(image, targetSrc);
|
|
3695
|
+
return;
|
|
3696
|
+
}
|
|
3697
|
+
if (
|
|
3698
|
+
targetSrc
|
|
3699
|
+
&& image.getAttribute("data-resux-loading") === "true"
|
|
3700
|
+
&& mediaUrlsEqual(getCurrentMediaUrl(image), targetSrc, image)
|
|
3701
|
+
) {
|
|
3702
|
+
return;
|
|
3703
|
+
}
|
|
3704
|
+
|
|
3705
|
+
dispatchManagedEvent(image, "lazy-load-start");
|
|
3706
|
+
image.setAttribute("data-rx-lazy-pending", "true");
|
|
3707
|
+
image.setAttribute("data-rx-lazy-ready", "true");
|
|
3708
|
+
image.setAttribute("data-resux-loading", "true");
|
|
3709
|
+
|
|
3710
|
+
const picture = image.closest ? image.closest("picture") : null;
|
|
3711
|
+
if (picture && picture.querySelectorAll) {
|
|
3712
|
+
picture.setAttribute("data-resux-loading", "true");
|
|
3713
|
+
picture.querySelectorAll("source[data-rx-lazy-srcset]").forEach((source) => {
|
|
3714
|
+
const nextSrcset = source.getAttribute("data-rx-lazy-srcset");
|
|
3715
|
+
if (nextSrcset && !mediaSourceWasFailed(image, nextSrcset)) {
|
|
3716
|
+
source.setAttribute("srcset", nextSrcset);
|
|
3717
|
+
} else if (nextSrcset) {
|
|
3718
|
+
source.setAttribute("data-rx-failed-srcset", nextSrcset);
|
|
3719
|
+
}
|
|
3720
|
+
source.removeAttribute("data-rx-lazy-srcset");
|
|
3721
|
+
source.removeAttribute("data-srcset");
|
|
3722
|
+
const nextSizes = source.getAttribute("data-rx-lazy-sizes");
|
|
3723
|
+
if (nextSizes) {
|
|
3724
|
+
source.setAttribute("sizes", nextSizes);
|
|
3725
|
+
}
|
|
3726
|
+
source.removeAttribute("data-rx-lazy-sizes");
|
|
3727
|
+
});
|
|
3728
|
+
}
|
|
3729
|
+
|
|
3730
|
+
const srcset = image.getAttribute("data-rx-lazy-srcset");
|
|
3731
|
+
if (srcset && !mediaSourceWasFailed(image, srcset)) {
|
|
3732
|
+
image.setAttribute("srcset", srcset);
|
|
3733
|
+
}
|
|
3734
|
+
image.removeAttribute("data-rx-lazy-srcset");
|
|
3735
|
+
image.removeAttribute("data-srcset");
|
|
3736
|
+
const sizes = image.getAttribute("data-rx-lazy-sizes");
|
|
3737
|
+
if (sizes) {
|
|
3738
|
+
image.setAttribute("sizes", sizes);
|
|
3739
|
+
}
|
|
3740
|
+
image.removeAttribute("data-rx-lazy-sizes");
|
|
3741
|
+
|
|
3742
|
+
if (targetSrc && shouldAssignMediaSource(image, targetSrc)) {
|
|
3743
|
+
image.setAttribute("src", targetSrc);
|
|
3744
|
+
} else if (image.getAttribute("src") === RESUX_LAZY_PLACEHOLDER_SRC) {
|
|
3745
|
+
image.removeAttribute("src");
|
|
3746
|
+
}
|
|
3747
|
+
image.removeAttribute("data-rx-lazy-src");
|
|
3748
|
+
image.removeAttribute("data-src");
|
|
3749
|
+
}
|
|
3750
|
+
|
|
3751
|
+
function activateDeferredLazyVideos(root = document) {
|
|
3752
|
+
const videos = root.querySelectorAll ? root.querySelectorAll("video[data-rx-lazy-video='true']") : [];
|
|
3753
|
+
if (!videos.length) {
|
|
3754
|
+
return;
|
|
3755
|
+
}
|
|
3756
|
+
for (const video of videos) {
|
|
3757
|
+
if (!isManagedMediaConnected(video)) {
|
|
3758
|
+
continue;
|
|
3759
|
+
}
|
|
3760
|
+
if (
|
|
3761
|
+
video.getAttribute("data-rx-lazy-ready") === "true"
|
|
3762
|
+
|| video.getAttribute("data-resux-loaded") === "true"
|
|
3763
|
+
|| video.getAttribute("data-resux-error-handled") === "true"
|
|
3764
|
+
|| observedLazyVideos.has(video)
|
|
3765
|
+
) {
|
|
3766
|
+
continue;
|
|
3767
|
+
}
|
|
3768
|
+
const observer = getLazyVideoObserver(video);
|
|
3769
|
+
if (!observer) {
|
|
3770
|
+
revealDeferredLazyVideo(video);
|
|
3771
|
+
continue;
|
|
3772
|
+
}
|
|
3773
|
+
observedLazyVideos.add(video);
|
|
3774
|
+
lazyVideoObserverByElement.set(video, observer);
|
|
3775
|
+
video.setAttribute("data-rx-lazy-observed", "true");
|
|
3776
|
+
video.setAttribute("data-resux-observed", "true");
|
|
3777
|
+
observer.observe(video);
|
|
3778
|
+
}
|
|
3779
|
+
}
|
|
3780
|
+
|
|
3781
|
+
function getLazyVideoObserver(video) {
|
|
3782
|
+
if (typeof IntersectionObserver !== "function") {
|
|
3783
|
+
return null;
|
|
3784
|
+
}
|
|
3785
|
+
const rootMargin = video.getAttribute("data-rx-lazy-root-margin") || "320px 0px";
|
|
3786
|
+
const thresholdRaw = Number(video.getAttribute("data-rx-lazy-threshold"));
|
|
3787
|
+
const threshold = Number.isFinite(thresholdRaw) ? Math.min(1, Math.max(0, thresholdRaw)) : 0;
|
|
3788
|
+
const key = rootMargin + "|" + String(threshold);
|
|
3789
|
+
if (lazyVideoObservers.has(key)) {
|
|
3790
|
+
return lazyVideoObservers.get(key);
|
|
3791
|
+
}
|
|
3792
|
+
const observer = new IntersectionObserver((entries) => {
|
|
3793
|
+
for (const entry of entries) {
|
|
3794
|
+
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
3795
|
+
continue;
|
|
3796
|
+
}
|
|
3797
|
+
const target = entry.target;
|
|
3798
|
+
observer.unobserve(target);
|
|
3799
|
+
revealDeferredLazyVideo(target);
|
|
3800
|
+
}
|
|
3801
|
+
}, { rootMargin, threshold });
|
|
3802
|
+
lazyVideoObservers.set(key, observer);
|
|
3803
|
+
return observer;
|
|
3804
|
+
}
|
|
3805
|
+
|
|
3806
|
+
function revealDeferredLazyVideo(video) {
|
|
3807
|
+
if (!video || !isManagedMediaConnected(video)) {
|
|
3808
|
+
return;
|
|
3809
|
+
}
|
|
3810
|
+
unobserveLazyVideo(video);
|
|
3811
|
+
|
|
3812
|
+
if (
|
|
3813
|
+
video.getAttribute("data-rx-lazy-ready") === "true"
|
|
3814
|
+
|| video.getAttribute("data-resux-loaded") === "true"
|
|
3815
|
+
|| video.getAttribute("data-resux-error-handled") === "true"
|
|
3816
|
+
) {
|
|
3817
|
+
return;
|
|
3818
|
+
}
|
|
3819
|
+
|
|
3820
|
+
const targetSrc = video.getAttribute("data-rx-lazy-src") || video.getAttribute("data-src") || "";
|
|
3821
|
+
if (targetSrc && mediaSourceWasFailed(video, targetSrc)) {
|
|
3822
|
+
applyKnownVideoFailure(video, targetSrc);
|
|
3823
|
+
return;
|
|
3824
|
+
}
|
|
3825
|
+
|
|
3826
|
+
dispatchManagedEvent(video, "lazy-load-start");
|
|
3827
|
+
|
|
3828
|
+
const preload = video.getAttribute("data-rx-lazy-preload") || "metadata";
|
|
3829
|
+
video.setAttribute("preload", preload);
|
|
3830
|
+
const sourceNodes = video.querySelectorAll
|
|
3831
|
+
? video.querySelectorAll("source[data-rx-lazy-src]")
|
|
3832
|
+
: [];
|
|
3833
|
+
sourceNodes.forEach((source) => {
|
|
3834
|
+
const nextSrc = source.getAttribute("data-rx-lazy-src");
|
|
3835
|
+
if (nextSrc && !mediaSourceWasFailed(video, nextSrc)) {
|
|
3836
|
+
source.setAttribute("src", nextSrc);
|
|
3837
|
+
}
|
|
3838
|
+
source.removeAttribute("data-rx-lazy-src");
|
|
3839
|
+
source.removeAttribute("data-src");
|
|
3840
|
+
});
|
|
3841
|
+
if (targetSrc && sourceNodes.length === 0 && shouldAssignMediaSource(video, targetSrc)) {
|
|
3842
|
+
video.setAttribute("src", targetSrc);
|
|
3843
|
+
}
|
|
3844
|
+
video.removeAttribute("data-rx-lazy-src");
|
|
3845
|
+
video.removeAttribute("data-src");
|
|
3846
|
+
video.removeAttribute("data-rx-lazy-video");
|
|
3847
|
+
video.setAttribute("data-rx-lazy-pending", "true");
|
|
3848
|
+
video.setAttribute("data-rx-lazy-ready", "true");
|
|
3849
|
+
video.setAttribute("data-resux-loading", "true");
|
|
3850
|
+
video.setAttribute("data-resux-video-loading", "true");
|
|
3851
|
+
|
|
3852
|
+
if (typeof video.load === "function" && video.getAttribute("data-rx-load-called") !== "true") {
|
|
3853
|
+
video.setAttribute("data-rx-load-called", "true");
|
|
3854
|
+
try {
|
|
3855
|
+
video.load();
|
|
3856
|
+
} catch {
|
|
3857
|
+
// Ignore load() runtime failures from older browsers.
|
|
3858
|
+
}
|
|
3859
|
+
}
|
|
3860
|
+
if (shouldAutoplayManagedVideo(video)) {
|
|
3861
|
+
attemptManagedVideoPlay(video);
|
|
3862
|
+
}
|
|
3863
|
+
}
|
|
3864
|
+
|
|
3865
|
+
function applyReducedMotionVideoPreference(root = document) {
|
|
3866
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
3867
|
+
return;
|
|
3868
|
+
}
|
|
3869
|
+
if (!window.matchMedia("(prefers-reduced-motion: reduce)").matches) {
|
|
3870
|
+
return;
|
|
3871
|
+
}
|
|
3872
|
+
const videos = root.querySelectorAll ? root.querySelectorAll("video[data-rx-respect-reduced-motion='true']") : [];
|
|
3873
|
+
videos.forEach((video) => {
|
|
3874
|
+
if (video.getAttribute("data-rx-force-autoplay") === "true") {
|
|
3875
|
+
return;
|
|
3876
|
+
}
|
|
3877
|
+
video.removeAttribute("autoplay");
|
|
3878
|
+
if (typeof video.pause === "function") {
|
|
3879
|
+
video.pause();
|
|
3880
|
+
}
|
|
3881
|
+
});
|
|
3882
|
+
}
|
|
3883
|
+
|
|
3884
|
+
function shouldAutoplayManagedVideo(video) {
|
|
3885
|
+
if (video.getAttribute("data-rx-autoplay-requested") !== "true") {
|
|
3886
|
+
return false;
|
|
3887
|
+
}
|
|
3888
|
+
if (video.getAttribute("data-rx-force-autoplay") === "true") {
|
|
3889
|
+
return true;
|
|
3890
|
+
}
|
|
3891
|
+
if (video.getAttribute("data-rx-respect-reduced-motion") !== "true") {
|
|
3892
|
+
return true;
|
|
3893
|
+
}
|
|
3894
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") {
|
|
3895
|
+
return true;
|
|
3896
|
+
}
|
|
3897
|
+
return !window.matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
3898
|
+
}
|
|
3899
|
+
|
|
3900
|
+
function attemptManagedVideoPlay(video) {
|
|
3901
|
+
if (!video || video.getAttribute("data-rx-play-attempted") === "true") {
|
|
3902
|
+
return;
|
|
3903
|
+
}
|
|
3904
|
+
video.setAttribute("data-rx-play-attempted", "true");
|
|
3905
|
+
if (typeof video.play !== "function") {
|
|
3906
|
+
return;
|
|
3907
|
+
}
|
|
3908
|
+
const playResult = video.play();
|
|
3909
|
+
if (playResult && typeof playResult.catch === "function") {
|
|
3910
|
+
playResult.catch(() => {});
|
|
3911
|
+
}
|
|
3912
|
+
}
|
|
3913
|
+
|
|
3914
|
+
function dispatchManagedEvent(target, name, detail = {}) {
|
|
3915
|
+
if (!target || typeof target.dispatchEvent !== "function") {
|
|
3916
|
+
return;
|
|
3917
|
+
}
|
|
3918
|
+
const view = target.ownerDocument?.defaultView ?? (typeof window !== "undefined" ? window : undefined);
|
|
3919
|
+
const CustomEventCtor = view && typeof view.CustomEvent === "function"
|
|
3920
|
+
? view.CustomEvent
|
|
3921
|
+
: null;
|
|
3922
|
+
if (!CustomEventCtor) {
|
|
3923
|
+
return;
|
|
3924
|
+
}
|
|
3925
|
+
target.dispatchEvent(new CustomEventCtor(name, { bubbles: true, detail }));
|
|
3926
|
+
}
|
|
3927
|
+
|
|
3928
|
+
function handleManagedMediaLoad(event) {
|
|
3929
|
+
const target = event && event.target;
|
|
3930
|
+
if (!target || !target.tagName) {
|
|
3931
|
+
return;
|
|
3932
|
+
}
|
|
3933
|
+
const tag = String(target.tagName).toLowerCase();
|
|
3934
|
+
if (tag !== "img") {
|
|
3935
|
+
return;
|
|
3936
|
+
}
|
|
3937
|
+
if (target.getAttribute("data-rx-lazy-image") === "true" && target.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
3938
|
+
return;
|
|
3939
|
+
}
|
|
3940
|
+
if (target.getAttribute("data-rx-lazy-pending") === "true") {
|
|
3941
|
+
target.removeAttribute("data-rx-lazy-pending");
|
|
3942
|
+
dispatchManagedEvent(target, "lazy-load-complete");
|
|
3943
|
+
}
|
|
3944
|
+
target.setAttribute("data-resux-loaded", "true");
|
|
3945
|
+
target.removeAttribute("data-resux-loading");
|
|
3946
|
+
clearManagedPlaceholderState(target);
|
|
3947
|
+
}
|
|
3948
|
+
|
|
3949
|
+
function handleManagedVideoReady(event) {
|
|
3950
|
+
const target = event && event.target;
|
|
3951
|
+
if (!target || !target.tagName || String(target.tagName).toLowerCase() !== "video") {
|
|
3952
|
+
return;
|
|
3953
|
+
}
|
|
3954
|
+
|
|
3955
|
+
if ((event.type === "loadedmetadata" || event.type === "canplay") && shouldAutoplayManagedVideo(target)) {
|
|
3956
|
+
attemptManagedVideoPlay(target);
|
|
3957
|
+
}
|
|
3958
|
+
if (event.type !== "loadedmetadata" && event.type !== "loadeddata" && event.type !== "canplay") {
|
|
3959
|
+
return;
|
|
3960
|
+
}
|
|
3961
|
+
if (target.getAttribute("data-rx-lazy-pending") === "true") {
|
|
3962
|
+
target.removeAttribute("data-rx-lazy-pending");
|
|
3963
|
+
dispatchManagedEvent(target, "lazy-load-complete");
|
|
3964
|
+
}
|
|
3965
|
+
target.setAttribute("data-resux-loaded", "true");
|
|
3966
|
+
target.removeAttribute("data-resux-loading");
|
|
3967
|
+
target.removeAttribute("data-resux-video-loading");
|
|
3968
|
+
clearManagedPlaceholderState(target);
|
|
3969
|
+
if (target.getAttribute("data-rx-placeholder-src")) {
|
|
3970
|
+
const realPoster = target.getAttribute("data-rx-poster");
|
|
3971
|
+
if (realPoster) {
|
|
3972
|
+
target.setAttribute("poster", realPoster);
|
|
3973
|
+
} else {
|
|
3974
|
+
target.removeAttribute("poster");
|
|
3975
|
+
}
|
|
3976
|
+
}
|
|
3977
|
+
}
|
|
3978
|
+
|
|
3979
|
+
function handleManagedMediaError(event) {
|
|
3980
|
+
const target = event && event.target;
|
|
3981
|
+
if (!target || !target.tagName) {
|
|
3982
|
+
return;
|
|
3983
|
+
}
|
|
3984
|
+
const tag = String(target.tagName).toLowerCase();
|
|
3985
|
+
if (tag === "img") {
|
|
3986
|
+
handleManagedImageError(target);
|
|
3987
|
+
return;
|
|
3988
|
+
}
|
|
3989
|
+
|
|
3990
|
+
if (tag === "source") {
|
|
3991
|
+
const parentVideo = target.parentElement && String(target.parentElement.tagName || "").toLowerCase() === "video"
|
|
3992
|
+
? target.parentElement
|
|
3993
|
+
: null;
|
|
3994
|
+
if (parentVideo) {
|
|
3995
|
+
markFailedMediaSource(parentVideo, target.getAttribute("src") || target.getAttribute("data-rx-lazy-src") || "");
|
|
3996
|
+
}
|
|
3997
|
+
return;
|
|
3998
|
+
}
|
|
3999
|
+
|
|
4000
|
+
if (tag === "video") {
|
|
4001
|
+
handleManagedVideoError(target);
|
|
4002
|
+
}
|
|
4003
|
+
}
|
|
4004
|
+
|
|
4005
|
+
function handleManagedImageError(target) {
|
|
4006
|
+
if (!isManagedMediaConnected(target)) {
|
|
4007
|
+
return;
|
|
4008
|
+
}
|
|
4009
|
+
if (target.getAttribute("data-rx-lazy-image") === "true" && target.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
4010
|
+
return;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
unobserveLazyImage(target);
|
|
4014
|
+
const failedSrc = getCurrentMediaUrl(target) || target.getAttribute("data-rx-lazy-src") || "";
|
|
4015
|
+
markFailedMediaSource(target, failedSrc);
|
|
4016
|
+
target.setAttribute("data-resux-error", "true");
|
|
4017
|
+
target.setAttribute("data-rx-error", "true");
|
|
4018
|
+
target.removeAttribute("data-resux-loading");
|
|
4019
|
+
disablePictureSources(target);
|
|
4020
|
+
|
|
4021
|
+
const fallbackSrc = target.getAttribute("data-rx-fallback-src");
|
|
4022
|
+
if (target.getAttribute("data-resux-error-handled") === "true") {
|
|
4023
|
+
if (
|
|
4024
|
+
target.getAttribute("data-rx-fallback-active") === "true"
|
|
4025
|
+
&& fallbackSrc
|
|
4026
|
+
&& mediaUrlsEqual(failedSrc, fallbackSrc, target)
|
|
4027
|
+
) {
|
|
4028
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4029
|
+
}
|
|
4030
|
+
return;
|
|
4031
|
+
}
|
|
4032
|
+
|
|
4033
|
+
if (fallbackSrc && shouldAssignMediaSource(target, fallbackSrc)) {
|
|
4034
|
+
markMediaErrorHandled(target);
|
|
4035
|
+
target.setAttribute("data-rx-fallback-used", "true");
|
|
4036
|
+
target.setAttribute("data-rx-fallback-active", "true");
|
|
4037
|
+
target.setAttribute("data-resux-fallback-active", "true");
|
|
4038
|
+
target.removeAttribute("srcset");
|
|
4039
|
+
target.removeAttribute("sizes");
|
|
4040
|
+
target.removeAttribute("data-rx-lazy-srcset");
|
|
4041
|
+
target.removeAttribute("data-rx-lazy-sizes");
|
|
4042
|
+
target.setAttribute("src", fallbackSrc);
|
|
4043
|
+
return;
|
|
4044
|
+
}
|
|
4045
|
+
|
|
4046
|
+
markMediaErrorHandled(target);
|
|
4047
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4048
|
+
}
|
|
4049
|
+
|
|
4050
|
+
function applyKnownImageFailure(target, failedSrc) {
|
|
4051
|
+
markFailedMediaSource(target, failedSrc);
|
|
4052
|
+
target.setAttribute("data-resux-error", "true");
|
|
4053
|
+
target.setAttribute("data-rx-error", "true");
|
|
4054
|
+
target.removeAttribute("data-resux-loading");
|
|
4055
|
+
disablePictureSources(target);
|
|
4056
|
+
const fallbackSrc = target.getAttribute("data-rx-fallback-src");
|
|
4057
|
+
markMediaErrorHandled(target);
|
|
4058
|
+
if (fallbackSrc && shouldAssignMediaSource(target, fallbackSrc)) {
|
|
4059
|
+
target.setAttribute("data-rx-fallback-used", "true");
|
|
4060
|
+
target.setAttribute("data-rx-fallback-active", "true");
|
|
4061
|
+
target.setAttribute("data-resux-fallback-active", "true");
|
|
4062
|
+
target.removeAttribute("srcset");
|
|
4063
|
+
target.removeAttribute("sizes");
|
|
4064
|
+
target.setAttribute("src", fallbackSrc);
|
|
4065
|
+
return;
|
|
4066
|
+
}
|
|
4067
|
+
showManagedImagePlaceholder(target, failedSrc);
|
|
4068
|
+
}
|
|
4069
|
+
|
|
4070
|
+
function handleManagedVideoError(video) {
|
|
4071
|
+
if (!isManagedMediaConnected(video)) {
|
|
4072
|
+
return;
|
|
4073
|
+
}
|
|
4074
|
+
|
|
4075
|
+
const failedSrc = getCurrentVideoUrl(video);
|
|
4076
|
+
markFailedMediaSource(video, failedSrc);
|
|
4077
|
+
video.setAttribute("data-resux-error", "true");
|
|
4078
|
+
video.setAttribute("data-rx-error", "true");
|
|
4079
|
+
video.removeAttribute("data-resux-loading");
|
|
4080
|
+
video.removeAttribute("data-resux-video-loading");
|
|
4081
|
+
|
|
4082
|
+
if (video.getAttribute("data-rx-lazy-video") === "true" && video.getAttribute("data-rx-lazy-ready") !== "true") {
|
|
4083
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4084
|
+
return;
|
|
4085
|
+
}
|
|
4086
|
+
|
|
4087
|
+
unobserveLazyVideo(video);
|
|
4088
|
+
if (video.getAttribute("data-resux-error-handled") === "true") {
|
|
4089
|
+
return;
|
|
4090
|
+
}
|
|
4091
|
+
|
|
4092
|
+
markMediaErrorHandled(video);
|
|
4093
|
+
clearManagedVideoSources(video);
|
|
4094
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4095
|
+
}
|
|
4096
|
+
|
|
4097
|
+
function applyKnownVideoFailure(video, failedSrc) {
|
|
4098
|
+
markFailedMediaSource(video, failedSrc);
|
|
4099
|
+
video.setAttribute("data-resux-error", "true");
|
|
4100
|
+
video.setAttribute("data-rx-error", "true");
|
|
4101
|
+
video.removeAttribute("data-resux-loading");
|
|
4102
|
+
video.removeAttribute("data-resux-video-loading");
|
|
4103
|
+
markMediaErrorHandled(video);
|
|
4104
|
+
clearManagedVideoSources(video);
|
|
4105
|
+
applyVideoPosterFallback(video, failedSrc);
|
|
4106
|
+
}
|
|
4107
|
+
|
|
4108
|
+
function applyVideoPosterFallback(video, failedSrc) {
|
|
4109
|
+
const fallbackPoster = video.getAttribute("data-rx-fallback-poster");
|
|
4110
|
+
if (fallbackPoster && !mediaUrlsEqual(video.getAttribute("poster") || "", fallbackPoster, video)) {
|
|
4111
|
+
video.setAttribute("poster", fallbackPoster);
|
|
4112
|
+
video.setAttribute("data-rx-fallback-active", "true");
|
|
4113
|
+
video.setAttribute("data-resux-fallback-active", "true");
|
|
4114
|
+
return;
|
|
4115
|
+
}
|
|
4116
|
+
|
|
4117
|
+
const placeholder = video.getAttribute("data-rx-placeholder-src");
|
|
4118
|
+
if (placeholder && !mediaUrlsEqual(placeholder, failedSrc, video)) {
|
|
4119
|
+
video.setAttribute("poster", placeholder);
|
|
4120
|
+
video.setAttribute("data-rx-placeholder-active", "true");
|
|
4121
|
+
video.setAttribute("data-resux-placeholder-active", "true");
|
|
4122
|
+
}
|
|
4123
|
+
}
|
|
4124
|
+
|
|
4125
|
+
function showManagedImagePlaceholder(target, failedSrc) {
|
|
4126
|
+
const placeholder = target.getAttribute("data-rx-placeholder-src");
|
|
4127
|
+
if (placeholder && shouldAssignMediaSource(target, placeholder) && !mediaUrlsEqual(placeholder, failedSrc, target)) {
|
|
4128
|
+
target.removeAttribute("srcset");
|
|
4129
|
+
target.removeAttribute("sizes");
|
|
4130
|
+
target.setAttribute("src", placeholder);
|
|
4131
|
+
target.setAttribute("data-rx-placeholder-active", "true");
|
|
4132
|
+
target.setAttribute("data-resux-placeholder-active", "true");
|
|
4133
|
+
return;
|
|
4134
|
+
}
|
|
4135
|
+
target.setAttribute("data-rx-placeholder-active", "true");
|
|
4136
|
+
target.setAttribute("data-resux-placeholder-active", "true");
|
|
4137
|
+
}
|
|
4138
|
+
|
|
4139
|
+
function disablePictureSources(image) {
|
|
4140
|
+
const picture = image.closest ? image.closest("picture") : null;
|
|
4141
|
+
if (!picture || !picture.querySelectorAll) {
|
|
4142
|
+
return;
|
|
4143
|
+
}
|
|
4144
|
+
picture.setAttribute("data-resux-error", "true");
|
|
4145
|
+
picture.querySelectorAll("source").forEach((source) => {
|
|
4146
|
+
const srcset = source.getAttribute("srcset") || source.getAttribute("data-rx-lazy-srcset");
|
|
4147
|
+
if (srcset) {
|
|
4148
|
+
source.setAttribute("data-rx-failed-srcset", srcset);
|
|
4149
|
+
}
|
|
4150
|
+
source.removeAttribute("srcset");
|
|
4151
|
+
source.removeAttribute("sizes");
|
|
4152
|
+
source.removeAttribute("data-rx-lazy-srcset");
|
|
4153
|
+
source.removeAttribute("data-rx-lazy-sizes");
|
|
4154
|
+
source.removeAttribute("data-srcset");
|
|
4155
|
+
});
|
|
4156
|
+
}
|
|
4157
|
+
|
|
4158
|
+
function clearManagedVideoSources(video) {
|
|
4159
|
+
if (typeof video.pause === "function") {
|
|
4160
|
+
try {
|
|
4161
|
+
video.pause();
|
|
4162
|
+
} catch {}
|
|
4163
|
+
}
|
|
4164
|
+
video.removeAttribute("src");
|
|
4165
|
+
video.removeAttribute("data-rx-lazy-src");
|
|
4166
|
+
video.removeAttribute("data-src");
|
|
4167
|
+
if (video.querySelectorAll) {
|
|
4168
|
+
video.querySelectorAll("source").forEach((source) => {
|
|
4169
|
+
const src = source.getAttribute("src") || source.getAttribute("data-rx-lazy-src");
|
|
4170
|
+
if (src) {
|
|
4171
|
+
source.setAttribute("data-rx-failed-src", src);
|
|
4172
|
+
}
|
|
4173
|
+
source.removeAttribute("src");
|
|
4174
|
+
source.removeAttribute("data-rx-lazy-src");
|
|
4175
|
+
source.removeAttribute("data-src");
|
|
4176
|
+
});
|
|
4177
|
+
}
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
function clearManagedPlaceholderState(target) {
|
|
4181
|
+
clearManagedPlaceholderStyle(target);
|
|
4182
|
+
const placeholderClass = target.getAttribute("data-rx-placeholder-class");
|
|
4183
|
+
if (placeholderClass && target.classList) {
|
|
4184
|
+
for (const token of placeholderClass.split(/\s+/).filter(Boolean)) {
|
|
4185
|
+
target.classList.remove(token);
|
|
4186
|
+
}
|
|
4187
|
+
}
|
|
4188
|
+
target.removeAttribute("data-rx-placeholder-active");
|
|
4189
|
+
target.removeAttribute("data-resux-placeholder-active");
|
|
2577
4190
|
}
|
|
2578
4191
|
|
|
2579
|
-
|
|
2580
|
-
const
|
|
2581
|
-
if (!
|
|
4192
|
+
function clearManagedPlaceholderStyle(target) {
|
|
4193
|
+
const style = target && target.getAttribute ? target.getAttribute("style") : "";
|
|
4194
|
+
if (!style) {
|
|
2582
4195
|
return;
|
|
2583
4196
|
}
|
|
2584
|
-
|
|
2585
|
-
const
|
|
2586
|
-
|
|
2587
|
-
|
|
4197
|
+
const placeholderStyle = target.getAttribute("data-rx-placeholder-style") || "";
|
|
4198
|
+
const nextStyle = style
|
|
4199
|
+
.replace(/background-image\s*:[^;]+;?/gi, "")
|
|
4200
|
+
.replace(/background-size\s*:[^;]+;?/gi, "")
|
|
4201
|
+
.replace(/background-position\s*:[^;]+;?/gi, "")
|
|
4202
|
+
.replace(/background-repeat\s*:[^;]+;?/gi, "")
|
|
4203
|
+
.split(";")
|
|
4204
|
+
.map((entry) => entry.trim())
|
|
4205
|
+
.filter((entry) => entry && !placeholderStyle.split(";").map((item) => item.trim()).filter(Boolean).includes(entry))
|
|
4206
|
+
.join("; ")
|
|
4207
|
+
.replace(/\s{2,}/g, " ")
|
|
4208
|
+
.trim()
|
|
4209
|
+
.replace(/;+$/g, "");
|
|
4210
|
+
if (!nextStyle) {
|
|
4211
|
+
target.removeAttribute("style");
|
|
2588
4212
|
return;
|
|
2589
4213
|
}
|
|
2590
|
-
|
|
4214
|
+
target.setAttribute("style", nextStyle);
|
|
4215
|
+
}
|
|
4216
|
+
|
|
4217
|
+
function shouldAssignMediaSource(target, nextSrc) {
|
|
4218
|
+
if (!nextSrc || mediaSourceWasFailed(target, nextSrc)) {
|
|
4219
|
+
return false;
|
|
4220
|
+
}
|
|
4221
|
+
const current = getCurrentMediaUrl(target);
|
|
4222
|
+
if (current && mediaUrlsEqual(current, nextSrc, target)) {
|
|
4223
|
+
return false;
|
|
4224
|
+
}
|
|
4225
|
+
const attrSrc = target.getAttribute ? target.getAttribute("src") : "";
|
|
4226
|
+
if (attrSrc && mediaUrlsEqual(attrSrc, nextSrc, target)) {
|
|
4227
|
+
return false;
|
|
4228
|
+
}
|
|
4229
|
+
return true;
|
|
4230
|
+
}
|
|
4231
|
+
|
|
4232
|
+
function getCurrentMediaUrl(target) {
|
|
4233
|
+
return String(target?.currentSrc || target?.getAttribute?.("src") || "");
|
|
4234
|
+
}
|
|
4235
|
+
|
|
4236
|
+
function getCurrentVideoUrl(video) {
|
|
4237
|
+
const direct = String(video?.currentSrc || video?.getAttribute?.("src") || "");
|
|
4238
|
+
if (direct) {
|
|
4239
|
+
return direct;
|
|
4240
|
+
}
|
|
4241
|
+
const source = video?.querySelector ? video.querySelector("source[src], source[data-rx-lazy-src]") : null;
|
|
4242
|
+
return String(source?.getAttribute("src") || source?.getAttribute("data-rx-lazy-src") || "");
|
|
4243
|
+
}
|
|
4244
|
+
|
|
4245
|
+
function markFailedMediaSource(target, src) {
|
|
4246
|
+
if (!target || !src) {
|
|
2591
4247
|
return;
|
|
2592
4248
|
}
|
|
2593
|
-
|
|
2594
|
-
|
|
4249
|
+
target.setAttribute("data-rx-failed-src", src);
|
|
4250
|
+
target.setAttribute("data-resux-failed-src", src);
|
|
4251
|
+
for (const candidate of mediaSourceCandidates(src)) {
|
|
4252
|
+
const normalized = normalizeMediaUrl(candidate, target);
|
|
4253
|
+
if (normalized) {
|
|
4254
|
+
failedMediaSources.add(normalized);
|
|
4255
|
+
}
|
|
4256
|
+
}
|
|
2595
4257
|
}
|
|
2596
|
-
|
|
4258
|
+
|
|
4259
|
+
function markMediaErrorHandled(target) {
|
|
4260
|
+
target.setAttribute("data-rx-error-handled", "true");
|
|
4261
|
+
target.setAttribute("data-resux-error-handled", "true");
|
|
4262
|
+
}
|
|
4263
|
+
|
|
4264
|
+
function mediaSourceWasFailed(target, src) {
|
|
4265
|
+
const failed = target?.getAttribute?.("data-rx-failed-src") || target?.getAttribute?.("data-resux-failed-src") || "";
|
|
4266
|
+
if (failed && src && mediaUrlsEqual(failed, src, target)) {
|
|
4267
|
+
return true;
|
|
4268
|
+
}
|
|
4269
|
+
return mediaSourceCandidates(src).some((candidate) => {
|
|
4270
|
+
const normalized = normalizeMediaUrl(candidate, target);
|
|
4271
|
+
return Boolean(normalized && failedMediaSources.has(normalized));
|
|
4272
|
+
});
|
|
4273
|
+
}
|
|
4274
|
+
|
|
4275
|
+
function mediaSourceCandidates(value) {
|
|
4276
|
+
const raw = String(value || "").trim();
|
|
4277
|
+
if (!raw) {
|
|
4278
|
+
return [];
|
|
4279
|
+
}
|
|
4280
|
+
if (!raw.includes(",")) {
|
|
4281
|
+
return [raw.split(/\s+/)[0]].filter(Boolean);
|
|
4282
|
+
}
|
|
4283
|
+
return raw
|
|
4284
|
+
.split(",")
|
|
4285
|
+
.map((entry) => entry.trim().split(/\s+/)[0])
|
|
4286
|
+
.filter(Boolean);
|
|
4287
|
+
}
|
|
4288
|
+
|
|
4289
|
+
function mediaUrlsEqual(left, right, target) {
|
|
4290
|
+
const normalizedLeft = normalizeMediaUrl(left, target);
|
|
4291
|
+
const normalizedRight = normalizeMediaUrl(right, target);
|
|
4292
|
+
return Boolean(normalizedLeft && normalizedRight && normalizedLeft === normalizedRight);
|
|
4293
|
+
}
|
|
4294
|
+
|
|
4295
|
+
function normalizeMediaUrl(value, target) {
|
|
4296
|
+
const raw = String(value || "").trim();
|
|
4297
|
+
if (!raw) {
|
|
4298
|
+
return "";
|
|
4299
|
+
}
|
|
4300
|
+
try {
|
|
4301
|
+
const view = target?.ownerDocument?.defaultView || (typeof window !== "undefined" ? window : null);
|
|
4302
|
+
const base = view?.location?.href || (typeof location !== "undefined" ? location.href : "http://localhost/");
|
|
4303
|
+
return new URL(raw, base).href;
|
|
4304
|
+
} catch {
|
|
4305
|
+
return raw;
|
|
4306
|
+
}
|
|
4307
|
+
}
|
|
4308
|
+
|
|
4309
|
+
function isManagedMediaConnected(target) {
|
|
4310
|
+
if (!target) {
|
|
4311
|
+
return false;
|
|
4312
|
+
}
|
|
4313
|
+
if (target.isConnected === true) {
|
|
4314
|
+
return true;
|
|
4315
|
+
}
|
|
4316
|
+
const root = target.ownerDocument && target.ownerDocument.documentElement;
|
|
4317
|
+
return Boolean(root && root.contains && root.contains(target));
|
|
4318
|
+
}
|
|
4319
|
+
|
|
4320
|
+
function unobserveLazyImage(image) {
|
|
4321
|
+
const observer = lazyImageObserverByElement.get(image);
|
|
4322
|
+
if (observer) {
|
|
4323
|
+
observer.unobserve(image);
|
|
4324
|
+
}
|
|
4325
|
+
observedLazyImages.delete(image);
|
|
4326
|
+
lazyImageObserverByElement.delete(image);
|
|
4327
|
+
image.removeAttribute("data-rx-lazy-observed");
|
|
4328
|
+
image.removeAttribute("data-resux-observed");
|
|
4329
|
+
}
|
|
4330
|
+
|
|
4331
|
+
function unobserveLazyVideo(video) {
|
|
4332
|
+
const observer = lazyVideoObserverByElement.get(video);
|
|
4333
|
+
if (observer) {
|
|
4334
|
+
observer.unobserve(video);
|
|
4335
|
+
}
|
|
4336
|
+
observedLazyVideos.delete(video);
|
|
4337
|
+
lazyVideoObserverByElement.delete(video);
|
|
4338
|
+
video.removeAttribute("data-rx-lazy-observed");
|
|
4339
|
+
video.removeAttribute("data-resux-observed");
|
|
4340
|
+
}
|
|
4341
|
+
|
|
4342
|
+
function cleanupDetachedLazyMedia() {
|
|
4343
|
+
for (const image of Array.from(observedLazyImages)) {
|
|
4344
|
+
if (!isManagedMediaConnected(image)) {
|
|
4345
|
+
unobserveLazyImage(image);
|
|
4346
|
+
}
|
|
4347
|
+
}
|
|
4348
|
+
for (const video of Array.from(observedLazyVideos)) {
|
|
4349
|
+
if (!isManagedMediaConnected(video)) {
|
|
4350
|
+
unobserveLazyVideo(video);
|
|
4351
|
+
}
|
|
4352
|
+
}
|
|
4353
|
+
}
|
|
4354
|
+
|
|
4355
|
+
function dispatchPageReadyEvent(root) {
|
|
4356
|
+
const target = root && typeof root.dispatchEvent === "function" ? root : document;
|
|
4357
|
+
dispatchManagedEvent(target, "resux:page-ready", { root });
|
|
4358
|
+
}
|
|
4359
|
+
|
|
2597
4360
|
function createAsyncDataResource(value, pending = false, error = null) {
|
|
2598
4361
|
const data = ref(value);
|
|
2599
4362
|
let completion = Promise.resolve();
|
|
@@ -2940,7 +4703,7 @@ async function navigateTo(target, options = {}) {
|
|
|
2940
4703
|
const routePath = nextUrl.pathname + nextUrl.search;
|
|
2941
4704
|
const currentUrl = new URL(location.href);
|
|
2942
4705
|
const currentRoutePath = currentUrl.pathname + currentUrl.search;
|
|
2943
|
-
if (routePath === currentRoutePath && nextUrl.hash === currentUrl.hash) {
|
|
4706
|
+
if (!options.force && routePath === currentRoutePath && nextUrl.hash === currentUrl.hash) {
|
|
2944
4707
|
return;
|
|
2945
4708
|
}
|
|
2946
4709
|
const transitionToken = ++routeTransitionToken;
|
|
@@ -2984,8 +4747,7 @@ async function navigateTo(target, options = {}) {
|
|
|
2984
4747
|
|
|
2985
4748
|
const root = document.getElementById("__resux");
|
|
2986
4749
|
if (!root) {
|
|
2987
|
-
|
|
2988
|
-
return;
|
|
4750
|
+
throw new Error("Missing Resux root for client navigation.");
|
|
2989
4751
|
}
|
|
2990
4752
|
|
|
2991
4753
|
if (transitionToken !== routeTransitionToken) {
|
|
@@ -3006,20 +4768,25 @@ async function navigateTo(target, options = {}) {
|
|
|
3006
4768
|
clearScopeCacheExcept(preserved.scopeIds);
|
|
3007
4769
|
void resumePendingAsyncData();
|
|
3008
4770
|
void mountVueIslands(preserved.root);
|
|
4771
|
+
activateDeferredLazyMedia(preserved.root);
|
|
4772
|
+
applyReducedMotionVideoPreference(preserved.root);
|
|
3009
4773
|
|
|
3010
|
-
if (nextUrl.hash) {
|
|
3011
|
-
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
3012
|
-
} else if (typeof scrollTo === "function") {
|
|
3013
|
-
scrollTo(0, 0);
|
|
3014
|
-
}
|
|
4774
|
+
if (!options.preserveScroll && nextUrl.hash) {
|
|
4775
|
+
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
4776
|
+
} else if (!options.preserveScroll && typeof scrollTo === "function") {
|
|
4777
|
+
scrollTo(0, 0);
|
|
4778
|
+
}
|
|
3015
4779
|
if (transitionToken === routeTransitionToken) {
|
|
3016
4780
|
setRouteTransition("complete", { path: routePath });
|
|
3017
4781
|
completed = true;
|
|
3018
4782
|
}
|
|
3019
|
-
} catch {
|
|
3020
|
-
setRouteTransition("error", { path: routePath });
|
|
3021
|
-
|
|
3022
|
-
|
|
4783
|
+
} catch (error) {
|
|
4784
|
+
setRouteTransition("error", { path: routePath });
|
|
4785
|
+
dispatchManagedEvent(document, "resux:navigation-error", {
|
|
4786
|
+
path: routePath,
|
|
4787
|
+
message: error instanceof Error ? error.message : String(error)
|
|
4788
|
+
});
|
|
4789
|
+
} finally {
|
|
3023
4790
|
if (!completed && transitionToken === routeTransitionToken) {
|
|
3024
4791
|
setRouteTransition("idle", { path: routePath });
|
|
3025
4792
|
}
|
|
@@ -3521,7 +5288,7 @@ function collectPatches(nodes, scope, locals, patches, styleScopeId) {
|
|
|
3521
5288
|
if (node.html) {
|
|
3522
5289
|
patches.push({ type: "html", id: node.html.bindingId, value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals)) });
|
|
3523
5290
|
}
|
|
3524
|
-
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
5291
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture" && node.tag !== "ResuxVideo") {
|
|
3525
5292
|
for (const attr of node.attrs) {
|
|
3526
5293
|
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
3527
5294
|
const attrName = nativeAttributeName(node, attr.name);
|
|
@@ -3567,6 +5334,9 @@ function renderElement(node, scope, locals, styleScopeId) {
|
|
|
3567
5334
|
if (node.tag === "ResuxPicture") {
|
|
3568
5335
|
return renderClientResuxPicture(node, scope, locals, styleScopeId);
|
|
3569
5336
|
}
|
|
5337
|
+
if (node.tag === "ResuxVideo") {
|
|
5338
|
+
return renderClientResuxVideo(node, scope, locals, styleScopeId);
|
|
5339
|
+
}
|
|
3570
5340
|
const tag = nativeElementTag(node);
|
|
3571
5341
|
const attrs = [];
|
|
3572
5342
|
for (const attr of node.attrs) {
|
|
@@ -3604,6 +5374,7 @@ const clientImageReservedProps = new Set([
|
|
|
3604
5374
|
"src",
|
|
3605
5375
|
"alt",
|
|
3606
5376
|
"provider",
|
|
5377
|
+
"cache",
|
|
3607
5378
|
"modifiers",
|
|
3608
5379
|
"quality",
|
|
3609
5380
|
"fit",
|
|
@@ -3620,8 +5391,176 @@ const clientImageReservedProps = new Set([
|
|
|
3620
5391
|
"loading",
|
|
3621
5392
|
"decoding",
|
|
3622
5393
|
"fetchpriority",
|
|
3623
|
-
"fetchPriority"
|
|
5394
|
+
"fetchPriority",
|
|
5395
|
+
"placeholder",
|
|
5396
|
+
"placeholderClass",
|
|
5397
|
+
"placeholderStyle",
|
|
5398
|
+
"fallback",
|
|
5399
|
+
"fallbackSrc",
|
|
5400
|
+
"sources",
|
|
5401
|
+
"rootMargin",
|
|
5402
|
+
"threshold"
|
|
3624
5403
|
]);
|
|
5404
|
+
const RESUX_CLIENT_RESPONSIVE_VIEWPORT_WIDTHS = [320, 640, 768, 1024, 1280, 1536, 1920, 2560];
|
|
5405
|
+
|
|
5406
|
+
function renderClientResuxVideo(node, scope, locals, styleScopeId) {
|
|
5407
|
+
const props = {};
|
|
5408
|
+
for (const attr of node.attrs) {
|
|
5409
|
+
const normalizedName = attr.name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
5410
|
+
props[normalizedName] = attr.kind === "static"
|
|
5411
|
+
? attr.value
|
|
5412
|
+
: evaluateExpression(attr.value, scope, locals);
|
|
5413
|
+
}
|
|
5414
|
+
const explicitLoading = readClientStringProp(props.loading);
|
|
5415
|
+
const explicitLazy = props.lazy === undefined
|
|
5416
|
+
? undefined
|
|
5417
|
+
: readClientBooleanProp(props.lazy, true);
|
|
5418
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : false);
|
|
5419
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true || lazy;
|
|
5420
|
+
const src = readClientStringProp(props.src);
|
|
5421
|
+
const poster = readClientStringProp(props.poster);
|
|
5422
|
+
const fallbackPoster = readClientStringProp(props.fallbackPoster);
|
|
5423
|
+
const width = readClientNumberProp(props.width);
|
|
5424
|
+
const height = readClientNumberProp(props.height);
|
|
5425
|
+
const placeholderSrc = resolveClientPlaceholderSource(props.placeholder);
|
|
5426
|
+
const preload = readClientStringProp(props.preload) || "metadata";
|
|
5427
|
+
const ariaLabel = readClientStringProp(props.ariaLabel || props["aria-label"]);
|
|
5428
|
+
const rootMargin = readClientStringProp(props.rootMargin) || "320px 0px";
|
|
5429
|
+
const thresholdRaw = Number(props.threshold);
|
|
5430
|
+
const threshold = Number.isFinite(thresholdRaw)
|
|
5431
|
+
? Math.min(1, Math.max(0, thresholdRaw))
|
|
5432
|
+
: 0;
|
|
5433
|
+
const forceAutoplay = readClientBooleanProp(props.forceAutoplay, false);
|
|
5434
|
+
const autoplay = readClientBooleanProp(props.autoplay, false);
|
|
5435
|
+
const resolvedSources = resolveClientVideoSources(props.sources);
|
|
5436
|
+
const hasSourceChildren = resolvedSources.length > 0;
|
|
5437
|
+
const styleParts = [];
|
|
5438
|
+
if (typeof props.style === "string" && props.style.trim()) {
|
|
5439
|
+
styleParts.push(props.style.trim().replace(/;+\s*$/, ""));
|
|
5440
|
+
}
|
|
5441
|
+
if (props.aspectRatio !== undefined && props.aspectRatio !== null && props.aspectRatio !== false) {
|
|
5442
|
+
const aspectValue = String(props.aspectRatio).trim();
|
|
5443
|
+
if (aspectValue) {
|
|
5444
|
+
styleParts.push("aspect-ratio: " + aspectValue);
|
|
5445
|
+
}
|
|
5446
|
+
} else {
|
|
5447
|
+
const ratioStyle = resolveClientAspectRatioStyle(width, height, props.style);
|
|
5448
|
+
if (ratioStyle) {
|
|
5449
|
+
styleParts.push(ratioStyle);
|
|
5450
|
+
}
|
|
5451
|
+
}
|
|
5452
|
+
styleParts.push("display: block");
|
|
5453
|
+
styleParts.push("width: 100%");
|
|
5454
|
+
styleParts.push("max-width: 100%");
|
|
5455
|
+
if (!styleParts.some((entry) => /(^|;)\s*height\s*:/.test(entry))) {
|
|
5456
|
+
styleParts.push("height: auto");
|
|
5457
|
+
}
|
|
5458
|
+
const attrs = [];
|
|
5459
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
5460
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
5461
|
+
continue;
|
|
5462
|
+
}
|
|
5463
|
+
if (
|
|
5464
|
+
name === "aspectRatio"
|
|
5465
|
+
|| name === "style"
|
|
5466
|
+
|| name === "lazy"
|
|
5467
|
+
|| name === "loading"
|
|
5468
|
+
|| name === "placeholder"
|
|
5469
|
+
|| name === "fallbackPoster"
|
|
5470
|
+
|| name === "rootMargin"
|
|
5471
|
+
|| name === "threshold"
|
|
5472
|
+
|| name === "sources"
|
|
5473
|
+
|| name === "forceAutoplay"
|
|
5474
|
+
|| name === "ariaLabel"
|
|
5475
|
+
|| name === "autoplay"
|
|
5476
|
+
|| name === "src"
|
|
5477
|
+
|| name === "poster"
|
|
5478
|
+
|| name === "preload"
|
|
5479
|
+
|| name === "fallbackText"
|
|
5480
|
+
) {
|
|
5481
|
+
continue;
|
|
5482
|
+
}
|
|
5483
|
+
const attrName = name === "className"
|
|
5484
|
+
? "class"
|
|
5485
|
+
: name === "playsInline"
|
|
5486
|
+
? "playsinline"
|
|
5487
|
+
: name === "crossOrigin"
|
|
5488
|
+
? "crossorigin"
|
|
5489
|
+
: name === "referrerPolicy"
|
|
5490
|
+
? "referrerpolicy"
|
|
5491
|
+
: name;
|
|
5492
|
+
attrs.push(attrName + '="' + escapeAttribute(stringifyAttributeValue(attrName, rawValue)) + '"');
|
|
5493
|
+
}
|
|
5494
|
+
if (!hasSourceChildren && !deferLazy && src) {
|
|
5495
|
+
attrs.push('src="' + escapeAttribute(src) + '"');
|
|
5496
|
+
}
|
|
5497
|
+
attrs.push('data-resux-media="video"');
|
|
5498
|
+
if (deferLazy && src) {
|
|
5499
|
+
attrs.push('data-rx-lazy-src="' + escapeAttribute(src) + '"');
|
|
5500
|
+
attrs.push('data-src="' + escapeAttribute(src) + '"');
|
|
5501
|
+
}
|
|
5502
|
+
if (deferLazy) {
|
|
5503
|
+
attrs.push('data-rx-lazy-video="true"');
|
|
5504
|
+
attrs.push('data-resux-lazy="true"');
|
|
5505
|
+
attrs.push('data-rx-lazy-root-margin="' + escapeAttribute(rootMargin) + '"');
|
|
5506
|
+
attrs.push('data-rx-lazy-threshold="' + escapeAttribute(String(threshold)) + '"');
|
|
5507
|
+
attrs.push('data-rx-lazy-preload="' + escapeAttribute(preload) + '"');
|
|
5508
|
+
attrs.push('preload="none"');
|
|
5509
|
+
} else if (preload) {
|
|
5510
|
+
attrs.push('preload="' + escapeAttribute(preload) + '"');
|
|
5511
|
+
}
|
|
5512
|
+
if (poster) {
|
|
5513
|
+
attrs.push('data-rx-poster="' + escapeAttribute(poster) + '"');
|
|
5514
|
+
}
|
|
5515
|
+
if (fallbackPoster) {
|
|
5516
|
+
attrs.push('data-rx-fallback-poster="' + escapeAttribute(fallbackPoster) + '"');
|
|
5517
|
+
}
|
|
5518
|
+
if (placeholderSrc) {
|
|
5519
|
+
attrs.push('data-rx-placeholder-src="' + escapeAttribute(placeholderSrc) + '"');
|
|
5520
|
+
attrs.push('data-placeholder="' + escapeAttribute(placeholderSrc) + '"');
|
|
5521
|
+
attrs.push('data-rx-placeholder-active="true"');
|
|
5522
|
+
attrs.push('data-resux-placeholder-active="true"');
|
|
5523
|
+
}
|
|
5524
|
+
const initialPoster = placeholderSrc || poster;
|
|
5525
|
+
if (initialPoster) {
|
|
5526
|
+
attrs.push('poster="' + escapeAttribute(initialPoster) + '"');
|
|
5527
|
+
}
|
|
5528
|
+
if (autoplay) {
|
|
5529
|
+
attrs.push('autoplay="autoplay"');
|
|
5530
|
+
attrs.push('data-rx-autoplay-requested="true"');
|
|
5531
|
+
if (!forceAutoplay) {
|
|
5532
|
+
attrs.push('data-rx-respect-reduced-motion="true"');
|
|
5533
|
+
} else {
|
|
5534
|
+
attrs.push('data-rx-force-autoplay="true"');
|
|
5535
|
+
}
|
|
5536
|
+
}
|
|
5537
|
+
if (ariaLabel) {
|
|
5538
|
+
attrs.push('aria-label="' + escapeAttribute(ariaLabel) + '"');
|
|
5539
|
+
}
|
|
5540
|
+
if (styleParts.length > 0) {
|
|
5541
|
+
attrs.push('style="' + escapeAttribute(styleParts.join("; ")) + '"');
|
|
5542
|
+
}
|
|
5543
|
+
if (styleScopeId) {
|
|
5544
|
+
attrs.push(styleScopeId + '=""');
|
|
5545
|
+
}
|
|
5546
|
+
const attrText = attrs.length ? " " + attrs.join(" ") : "";
|
|
5547
|
+
const sourceTags = hasSourceChildren
|
|
5548
|
+
? resolvedSources
|
|
5549
|
+
.map((source) => {
|
|
5550
|
+
const sourceAttrs = deferLazy
|
|
5551
|
+
? ['data-rx-lazy-src="' + escapeAttribute(source.src) + '"', 'data-src="' + escapeAttribute(source.src) + '"']
|
|
5552
|
+
: ['src="' + escapeAttribute(source.src) + '"'];
|
|
5553
|
+
if (source.type) {
|
|
5554
|
+
sourceAttrs.push('type="' + escapeAttribute(source.type) + '"');
|
|
5555
|
+
}
|
|
5556
|
+
return "<source " + sourceAttrs.join(" ") + ">";
|
|
5557
|
+
})
|
|
5558
|
+
.join("")
|
|
5559
|
+
: "";
|
|
5560
|
+
const children = node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
5561
|
+
const fallbackText = escapeHtml(readClientStringProp(props.fallbackText) || "Your browser does not support the video tag.");
|
|
5562
|
+
return "<video" + attrText + ">" + sourceTags + children + fallbackText + "</video>";
|
|
5563
|
+
}
|
|
3625
5564
|
|
|
3626
5565
|
function renderClientResuxImg(node, scope, locals, styleScopeId) {
|
|
3627
5566
|
const input = resolveClientImageRenderInput(node, scope, locals);
|
|
@@ -3633,6 +5572,7 @@ function renderClientResuxImg(node, scope, locals, styleScopeId) {
|
|
|
3633
5572
|
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3634
5573
|
const src = builder(input.src, {
|
|
3635
5574
|
provider: input.provider,
|
|
5575
|
+
cache: input.cache,
|
|
3636
5576
|
width: input.width,
|
|
3637
5577
|
height: input.height,
|
|
3638
5578
|
quality: input.quality,
|
|
@@ -3649,11 +5589,20 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3649
5589
|
if (!input.src) {
|
|
3650
5590
|
return "";
|
|
3651
5591
|
}
|
|
5592
|
+
const props = {};
|
|
5593
|
+
for (const attr of node.attrs) {
|
|
5594
|
+
const normalizedName = attr.name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
5595
|
+
props[normalizedName] = attr.kind === "static"
|
|
5596
|
+
? attr.value
|
|
5597
|
+
: evaluateExpression(attr.value, scope, locals);
|
|
5598
|
+
}
|
|
3652
5599
|
|
|
3653
5600
|
const app = getClientResuxApp();
|
|
3654
5601
|
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3655
|
-
const
|
|
5602
|
+
const fallbackSource = input.fallbackSrc || input.src;
|
|
5603
|
+
const fallbackSrc = builder(fallbackSource, {
|
|
3656
5604
|
provider: input.provider,
|
|
5605
|
+
cache: input.cache,
|
|
3657
5606
|
width: input.width,
|
|
3658
5607
|
height: input.height,
|
|
3659
5608
|
quality: input.quality,
|
|
@@ -3662,40 +5611,89 @@ function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
|
3662
5611
|
});
|
|
3663
5612
|
const fallbackSrcset = buildClientImageSrcset(builder, {
|
|
3664
5613
|
...input,
|
|
5614
|
+
src: fallbackSource,
|
|
3665
5615
|
format: undefined
|
|
3666
5616
|
});
|
|
3667
5617
|
const manualChildren = node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
3668
|
-
const
|
|
3669
|
-
|
|
3670
|
-
|
|
5618
|
+
const explicitSources = resolveClientPictureSourceInputs(props.sources, input);
|
|
5619
|
+
const sourceInputs = explicitSources.length
|
|
5620
|
+
? explicitSources
|
|
5621
|
+
: input.formats.map((format) => ({
|
|
5622
|
+
src: input.src,
|
|
5623
|
+
widths: input.widths,
|
|
5624
|
+
width: input.width,
|
|
5625
|
+
height: input.height,
|
|
5626
|
+
quality: input.quality,
|
|
5627
|
+
format,
|
|
5628
|
+
fit: input.fit,
|
|
5629
|
+
sizes: input.sizes,
|
|
5630
|
+
modifiers: input.modifiers,
|
|
5631
|
+
type: clientImageMimeType(format)
|
|
5632
|
+
}));
|
|
5633
|
+
const generatedSources = sourceInputs
|
|
5634
|
+
.map((entry) => {
|
|
5635
|
+
const sourceInput = entry;
|
|
5636
|
+
const sourceRenderInput = {
|
|
3671
5637
|
...input,
|
|
3672
|
-
|
|
3673
|
-
|
|
3674
|
-
|
|
5638
|
+
src: sourceInput.src,
|
|
5639
|
+
width: sourceInput.width,
|
|
5640
|
+
height: sourceInput.height,
|
|
5641
|
+
widths: sourceInput.widths,
|
|
5642
|
+
sizes: sourceInput.sizes,
|
|
5643
|
+
quality: sourceInput.quality,
|
|
5644
|
+
format: sourceInput.format,
|
|
5645
|
+
fit: sourceInput.fit,
|
|
5646
|
+
modifiers: sourceInput.modifiers,
|
|
5647
|
+
placeholderSrc: undefined,
|
|
5648
|
+
placeholderClass: undefined,
|
|
5649
|
+
placeholderStyle: undefined,
|
|
5650
|
+
fallbackSrc: undefined,
|
|
5651
|
+
attrs: {},
|
|
5652
|
+
preload: false,
|
|
5653
|
+
deferLazy: input.deferLazy
|
|
5654
|
+
};
|
|
5655
|
+
const sourceSrcset = sourceInput.srcset || buildClientImageSrcset(builder, sourceRenderInput);
|
|
5656
|
+
const sourceUrl = builder(sourceInput.src, {
|
|
3675
5657
|
provider: input.provider,
|
|
3676
|
-
|
|
3677
|
-
|
|
3678
|
-
|
|
3679
|
-
|
|
3680
|
-
|
|
3681
|
-
|
|
5658
|
+
cache: input.cache,
|
|
5659
|
+
width: sourceInput.width,
|
|
5660
|
+
height: sourceInput.height,
|
|
5661
|
+
quality: sourceInput.quality,
|
|
5662
|
+
fit: sourceInput.fit,
|
|
5663
|
+
format: sourceInput.format,
|
|
5664
|
+
modifiers: sourceInput.modifiers
|
|
3682
5665
|
});
|
|
5666
|
+
const resolvedSrcset = sourceSrcset || sourceUrl;
|
|
3683
5667
|
if (!resolvedSrcset) {
|
|
3684
5668
|
return "";
|
|
3685
5669
|
}
|
|
3686
|
-
const sourceAttrs = [
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
5670
|
+
const sourceAttrs = [];
|
|
5671
|
+
const sourceType = sourceInput.type
|
|
5672
|
+
|| (sourceInput.format ? clientImageMimeType(sourceInput.format) : inferClientImageMimeTypeFromSource(sourceInput.src));
|
|
5673
|
+
if (sourceType) {
|
|
5674
|
+
sourceAttrs.push('type="' + escapeAttribute(sourceType) + '"');
|
|
5675
|
+
}
|
|
5676
|
+
if (sourceInput.media) {
|
|
5677
|
+
sourceAttrs.push('media="' + escapeAttribute(sourceInput.media) + '"');
|
|
5678
|
+
}
|
|
5679
|
+
if (input.deferLazy) {
|
|
5680
|
+
sourceAttrs.push('data-rx-lazy-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
5681
|
+
sourceAttrs.push('data-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
5682
|
+
if (sourceInput.sizes) {
|
|
5683
|
+
sourceAttrs.push('data-rx-lazy-sizes="' + escapeAttribute(sourceInput.sizes) + '"');
|
|
5684
|
+
}
|
|
5685
|
+
} else {
|
|
5686
|
+
sourceAttrs.push('srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
5687
|
+
if (sourceInput.sizes) {
|
|
5688
|
+
sourceAttrs.push('sizes="' + escapeAttribute(sourceInput.sizes) + '"');
|
|
5689
|
+
}
|
|
3692
5690
|
}
|
|
3693
5691
|
return "<source " + sourceAttrs.join(" ") + ">";
|
|
3694
5692
|
})
|
|
3695
5693
|
.filter(Boolean)
|
|
3696
5694
|
.join("");
|
|
3697
5695
|
const img = renderClientResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
3698
|
-
const attrs = [];
|
|
5696
|
+
const attrs = ['data-resux-media="picture"'];
|
|
3699
5697
|
if (styleScopeId) {
|
|
3700
5698
|
attrs.push(styleScopeId + '=""');
|
|
3701
5699
|
}
|
|
@@ -3716,32 +5714,67 @@ function resolveClientImageRenderInput(node, scope, locals) {
|
|
|
3716
5714
|
const explicitFormats = parseClientImageFormats(
|
|
3717
5715
|
props.formats || (explicitFormat && explicitFormat.includes(",") ? explicitFormat : undefined)
|
|
3718
5716
|
);
|
|
5717
|
+
const hasExplicitQuality = Object.prototype.hasOwnProperty.call(props, "quality");
|
|
5718
|
+
const hasExplicitFormat = Object.prototype.hasOwnProperty.call(props, "format");
|
|
5719
|
+
const explicitQuality = readClientNumberProp(props.quality);
|
|
5720
|
+
const modifiers = normalizeClientImageModifiers({
|
|
5721
|
+
...normalizeClientImageModifiers(props.modifiers),
|
|
5722
|
+
...(hasExplicitFormat && !explicitFormat ? { format: false } : {}),
|
|
5723
|
+
...(hasExplicitQuality && !explicitQuality ? { quality: false } : {})
|
|
5724
|
+
});
|
|
3719
5725
|
const priority = readClientBooleanProp(props.priority, false);
|
|
3720
5726
|
const preload = readClientBooleanProp(props.preload, priority);
|
|
3721
|
-
const
|
|
3722
|
-
const
|
|
5727
|
+
const explicitLoading = readClientStringProp(props.loading);
|
|
5728
|
+
const explicitLazy = props.lazy === undefined
|
|
5729
|
+
? undefined
|
|
5730
|
+
: readClientBooleanProp(props.lazy, true);
|
|
5731
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
5732
|
+
const loading = explicitLoading || (lazy ? "lazy" : "eager");
|
|
5733
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
5734
|
+
const lazyRootMargin = readClientStringProp(props.rootMargin) || "0px 0px";
|
|
5735
|
+
const lazyThresholdRaw = Number(props.threshold);
|
|
5736
|
+
const lazyThreshold = Number.isFinite(lazyThresholdRaw)
|
|
5737
|
+
? Math.min(1, Math.max(0, lazyThresholdRaw))
|
|
5738
|
+
: 0;
|
|
5739
|
+
const quality = hasExplicitQuality
|
|
5740
|
+
? explicitQuality
|
|
5741
|
+
: (explicitQuality ?? imageConfig.quality);
|
|
5742
|
+
const cache = normalizeClientImageCacheValue(props.cache ?? imageConfig.cache);
|
|
3723
5743
|
const densities = parseClientImageNumberList(props.densities)
|
|
3724
5744
|
|| imageConfig.densities
|
|
3725
5745
|
|| [1, 2];
|
|
5746
|
+
const src = readClientStringProp(props.src)
|
|
5747
|
+
|| readClientStringProp(props.fallbackSrc ?? props.fallback)
|
|
5748
|
+
|| "";
|
|
3726
5749
|
return {
|
|
3727
|
-
src
|
|
5750
|
+
src,
|
|
3728
5751
|
alt: readClientStringProp(props.alt) || "",
|
|
3729
5752
|
width: readClientNumberProp(props.width),
|
|
3730
5753
|
height: readClientNumberProp(props.height),
|
|
3731
5754
|
sizes: readClientStringProp(props.sizes),
|
|
3732
5755
|
widths: parseClientImageNumberList(props.widths) || [],
|
|
3733
5756
|
densities,
|
|
3734
|
-
loading
|
|
5757
|
+
loading,
|
|
3735
5758
|
decoding: readClientStringProp(props.decoding) || "async",
|
|
3736
5759
|
fetchPriority: readClientStringProp(props.fetchpriority || props.fetchPriority) || (priority ? "high" : undefined),
|
|
3737
5760
|
provider: readClientStringProp(props.provider),
|
|
5761
|
+
cache,
|
|
3738
5762
|
quality,
|
|
3739
5763
|
fit: readClientStringProp(props.fit),
|
|
3740
|
-
format: explicitFormats.length
|
|
5764
|
+
format: explicitFormats.length
|
|
5765
|
+
? undefined
|
|
5766
|
+
: (hasExplicitFormat ? explicitFormat : (explicitFormat || imageConfig.format)),
|
|
3741
5767
|
formats: explicitFormats,
|
|
3742
|
-
|
|
5768
|
+
placeholderSrc: resolveClientPlaceholderSource(props.placeholder),
|
|
5769
|
+
placeholderClass: readClientStringProp(props.placeholderClass),
|
|
5770
|
+
placeholderStyle: readClientStringProp(props.placeholderStyle),
|
|
5771
|
+
fallbackSrc: readClientStringProp(props.fallbackSrc ?? props.fallback),
|
|
5772
|
+
modifiers,
|
|
3743
5773
|
attrs: collectClientImageAttrs(props),
|
|
3744
|
-
preload
|
|
5774
|
+
preload,
|
|
5775
|
+
deferLazy,
|
|
5776
|
+
lazyRootMargin,
|
|
5777
|
+
lazyThreshold
|
|
3745
5778
|
};
|
|
3746
5779
|
}
|
|
3747
5780
|
|
|
@@ -3772,7 +5805,16 @@ function normalizeClientImageModifiers(value) {
|
|
|
3772
5805
|
}
|
|
3773
5806
|
const modifiers = {};
|
|
3774
5807
|
for (const [key, entry] of Object.entries(value)) {
|
|
3775
|
-
if (entry ===
|
|
5808
|
+
if (entry === false) {
|
|
5809
|
+
if (key === "format" || key === "quality") {
|
|
5810
|
+
modifiers[key] = false;
|
|
5811
|
+
}
|
|
5812
|
+
continue;
|
|
5813
|
+
}
|
|
5814
|
+
if (entry === undefined || entry === null) {
|
|
5815
|
+
continue;
|
|
5816
|
+
}
|
|
5817
|
+
if (key === "cache") {
|
|
3776
5818
|
continue;
|
|
3777
5819
|
}
|
|
3778
5820
|
if (key === "width" || key === "height" || key === "quality") {
|
|
@@ -3788,15 +5830,14 @@ function normalizeClientImageModifiers(value) {
|
|
|
3788
5830
|
}
|
|
3789
5831
|
|
|
3790
5832
|
function buildClientImageSrcset(builder, input) {
|
|
3791
|
-
const widthCandidates = input
|
|
3792
|
-
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
3793
|
-
: [];
|
|
5833
|
+
const widthCandidates = resolveClientImageWidthCandidates(input);
|
|
3794
5834
|
if (widthCandidates.length) {
|
|
3795
5835
|
return widthCandidates
|
|
3796
5836
|
.map((width) => builder(input.src, {
|
|
3797
5837
|
provider: input.provider,
|
|
5838
|
+
cache: input.cache,
|
|
3798
5839
|
width,
|
|
3799
|
-
height: input
|
|
5840
|
+
height: resolveClientImageCandidateHeight(input, width),
|
|
3800
5841
|
quality: input.quality,
|
|
3801
5842
|
fit: input.fit,
|
|
3802
5843
|
format: input.format,
|
|
@@ -3814,6 +5855,7 @@ function buildClientImageSrcset(builder, input) {
|
|
|
3814
5855
|
const height = input.height ? Math.max(1, Math.round(input.height * density)) : undefined;
|
|
3815
5856
|
return builder(input.src, {
|
|
3816
5857
|
provider: input.provider,
|
|
5858
|
+
cache: input.cache,
|
|
3817
5859
|
width,
|
|
3818
5860
|
height,
|
|
3819
5861
|
quality: input.quality,
|
|
@@ -3825,19 +5867,138 @@ function buildClientImageSrcset(builder, input) {
|
|
|
3825
5867
|
.join(", ");
|
|
3826
5868
|
}
|
|
3827
5869
|
|
|
5870
|
+
function resolveClientImageWidthCandidates(input) {
|
|
5871
|
+
const explicitWidths = input.widths.length
|
|
5872
|
+
? normalizeClientImageWidthCandidates(input.widths, input.width)
|
|
5873
|
+
: [];
|
|
5874
|
+
if (explicitWidths.length) {
|
|
5875
|
+
return explicitWidths;
|
|
5876
|
+
}
|
|
5877
|
+
if (!input.sizes) {
|
|
5878
|
+
return [];
|
|
5879
|
+
}
|
|
5880
|
+
return resolveClientImageWidthsFromSizes(input.sizes, input.densities, input.width);
|
|
5881
|
+
}
|
|
5882
|
+
|
|
5883
|
+
function resolveClientImageWidthsFromSizes(sizes, densities, maxWidth) {
|
|
5884
|
+
const descriptors = String(sizes)
|
|
5885
|
+
.split(",")
|
|
5886
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
5887
|
+
.filter(Boolean);
|
|
5888
|
+
const baseWidths = [];
|
|
5889
|
+
for (const descriptor of descriptors) {
|
|
5890
|
+
const matches = [...descriptor.matchAll(/([0-9]*\.?[0-9]+)\s*(px|vw)\b/g)];
|
|
5891
|
+
const match = matches[matches.length - 1];
|
|
5892
|
+
if (!match) {
|
|
5893
|
+
continue;
|
|
5894
|
+
}
|
|
5895
|
+
const value = Number(match[1]);
|
|
5896
|
+
if (!Number.isFinite(value) || value <= 0) {
|
|
5897
|
+
continue;
|
|
5898
|
+
}
|
|
5899
|
+
if (match[2] === "px") {
|
|
5900
|
+
baseWidths.push(Math.round(value));
|
|
5901
|
+
continue;
|
|
5902
|
+
}
|
|
5903
|
+
for (const viewportWidth of RESUX_CLIENT_RESPONSIVE_VIEWPORT_WIDTHS) {
|
|
5904
|
+
baseWidths.push(Math.round((viewportWidth * value) / 100));
|
|
5905
|
+
}
|
|
5906
|
+
}
|
|
5907
|
+
|
|
5908
|
+
const safeDensities = densities.length
|
|
5909
|
+
? [...new Set(densities)]
|
|
5910
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
5911
|
+
.sort((left, right) => left - right)
|
|
5912
|
+
: [1];
|
|
5913
|
+
const expandedWidths = baseWidths.flatMap((width) =>
|
|
5914
|
+
safeDensities.map((density) => Math.round(width * density))
|
|
5915
|
+
);
|
|
5916
|
+
|
|
5917
|
+
if (!expandedWidths.length && Number.isFinite(maxWidth) && maxWidth > 0) {
|
|
5918
|
+
return [Math.max(1, Math.round(maxWidth))];
|
|
5919
|
+
}
|
|
5920
|
+
return normalizeClientImageWidthCandidates(expandedWidths, maxWidth);
|
|
5921
|
+
}
|
|
5922
|
+
|
|
5923
|
+
function normalizeClientImageWidthCandidates(candidates, maxWidth) {
|
|
5924
|
+
const resolvedMaxWidth = Number.isFinite(maxWidth) && maxWidth > 0
|
|
5925
|
+
? Math.round(maxWidth)
|
|
5926
|
+
: Number.POSITIVE_INFINITY;
|
|
5927
|
+
const normalized = [...new Set(candidates
|
|
5928
|
+
.map((entry) => Number(entry))
|
|
5929
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
5930
|
+
.map((entry) => Math.min(8192, Math.max(1, Math.round(entry)), resolvedMaxWidth)))]
|
|
5931
|
+
.sort((left, right) => left - right);
|
|
5932
|
+
const compacted = [];
|
|
5933
|
+
for (const width of normalized) {
|
|
5934
|
+
const previous = compacted[compacted.length - 1];
|
|
5935
|
+
const shouldKeep = previous === undefined
|
|
5936
|
+
|| width - previous >= 24
|
|
5937
|
+
|| (Number.isFinite(resolvedMaxWidth) && width === resolvedMaxWidth);
|
|
5938
|
+
if (shouldKeep) {
|
|
5939
|
+
compacted.push(width);
|
|
5940
|
+
}
|
|
5941
|
+
}
|
|
5942
|
+
return compacted;
|
|
5943
|
+
}
|
|
5944
|
+
|
|
5945
|
+
function resolveClientImageCandidateHeight(input, width) {
|
|
5946
|
+
if (!input.height) {
|
|
5947
|
+
return undefined;
|
|
5948
|
+
}
|
|
5949
|
+
if (!input.width) {
|
|
5950
|
+
return input.height;
|
|
5951
|
+
}
|
|
5952
|
+
const scaledHeight = Math.round((input.height / input.width) * width);
|
|
5953
|
+
return Math.max(1, scaledHeight);
|
|
5954
|
+
}
|
|
5955
|
+
|
|
3828
5956
|
function renderClientResuxImgTag(input, src, srcset, styleScopeId) {
|
|
3829
5957
|
const attrs = [];
|
|
5958
|
+
const isDeferredLazy = input.deferLazy && String(input.loading || "").toLowerCase() === "lazy";
|
|
5959
|
+
const placeholderSrc = input.placeholderSrc;
|
|
5960
|
+
const placeholderClass = input.placeholderClass;
|
|
5961
|
+
const placeholderStyle = input.placeholderStyle;
|
|
5962
|
+
const aspectRatioStyle = resolveClientAspectRatioStyle(input.width, input.height, input.attrs.style, placeholderStyle);
|
|
5963
|
+
const placeholderBackground = placeholderSrc
|
|
5964
|
+
? "background-image: url('" + placeholderSrc + "'); background-size: cover; background-position: center; background-repeat: no-repeat"
|
|
5965
|
+
: undefined;
|
|
5966
|
+
const mergedClass = mergeClientClassNames(input.attrs.class, placeholderClass);
|
|
5967
|
+
const mergedStyle = mergeClientInlineStyles(
|
|
5968
|
+
input.attrs.style,
|
|
5969
|
+
aspectRatioStyle,
|
|
5970
|
+
!isDeferredLazy ? placeholderBackground : undefined,
|
|
5971
|
+
placeholderStyle
|
|
5972
|
+
);
|
|
5973
|
+
const initialSrc = isDeferredLazy
|
|
5974
|
+
? (placeholderSrc || RESUX_LAZY_PLACEHOLDER_SRC)
|
|
5975
|
+
: src;
|
|
3830
5976
|
const mergedAttrs = {
|
|
3831
5977
|
...input.attrs,
|
|
3832
|
-
|
|
5978
|
+
...(mergedClass ? { class: mergedClass } : {}),
|
|
5979
|
+
...(mergedStyle ? { style: mergedStyle } : {}),
|
|
5980
|
+
src: initialSrc,
|
|
3833
5981
|
alt: input.alt,
|
|
3834
5982
|
loading: input.loading,
|
|
3835
5983
|
decoding: input.decoding,
|
|
5984
|
+
"data-resux-media": "img",
|
|
5985
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
5986
|
+
...(isDeferredLazy ? { "data-resux-lazy": "true" } : {}),
|
|
5987
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src, "data-src": src } : {}),
|
|
5988
|
+
...(isDeferredLazy ? { "data-rx-lazy-root-margin": input.lazyRootMargin } : {}),
|
|
5989
|
+
...(isDeferredLazy ? { "data-rx-lazy-threshold": String(input.lazyThreshold) } : {}),
|
|
5990
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset, "data-srcset": srcset } : {}),
|
|
5991
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
5992
|
+
...(placeholderSrc ? { "data-rx-placeholder-src": placeholderSrc, "data-placeholder": placeholderSrc } : {}),
|
|
5993
|
+
...(placeholderClass ? { "data-rx-placeholder-class": placeholderClass } : {}),
|
|
5994
|
+
...(placeholderStyle ? { "data-rx-placeholder-style": placeholderStyle } : {}),
|
|
5995
|
+
...(placeholderSrc ? { "data-rx-placeholder-active": "true", "data-resux-placeholder-active": "true" } : {}),
|
|
5996
|
+
...(input.fallbackSrc ? { "data-rx-fallback-src": input.fallbackSrc } : {}),
|
|
3836
5997
|
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
3837
5998
|
...(input.width ? { width: String(input.width) } : {}),
|
|
3838
5999
|
...(input.height ? { height: String(input.height) } : {}),
|
|
3839
|
-
...(srcset ? { srcset } : {}),
|
|
3840
|
-
...(input.sizes ? { sizes: input.sizes } : {})
|
|
6000
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
6001
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {})
|
|
3841
6002
|
};
|
|
3842
6003
|
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
3843
6004
|
if (value === undefined || value === null) {
|
|
@@ -3907,6 +6068,9 @@ function readClientBooleanProp(value, fallback) {
|
|
|
3907
6068
|
}
|
|
3908
6069
|
if (typeof value === "string") {
|
|
3909
6070
|
const normalized = value.trim().toLowerCase();
|
|
6071
|
+
if (normalized === "") {
|
|
6072
|
+
return true;
|
|
6073
|
+
}
|
|
3910
6074
|
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
3911
6075
|
return true;
|
|
3912
6076
|
}
|
|
@@ -3917,6 +6081,187 @@ function readClientBooleanProp(value, fallback) {
|
|
|
3917
6081
|
return fallback;
|
|
3918
6082
|
}
|
|
3919
6083
|
|
|
6084
|
+
function resolveClientPlaceholderSource(value) {
|
|
6085
|
+
if (value === undefined || value === null || value === false) {
|
|
6086
|
+
return undefined;
|
|
6087
|
+
}
|
|
6088
|
+
if (value === true) {
|
|
6089
|
+
return RESUX_DEFAULT_PLACEHOLDER_SRC;
|
|
6090
|
+
}
|
|
6091
|
+
if (typeof value !== "string") {
|
|
6092
|
+
return undefined;
|
|
6093
|
+
}
|
|
6094
|
+
const trimmed = value.trim();
|
|
6095
|
+
if (!trimmed) {
|
|
6096
|
+
return undefined;
|
|
6097
|
+
}
|
|
6098
|
+
const normalized = trimmed.toLowerCase();
|
|
6099
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes" || normalized === "on") {
|
|
6100
|
+
return RESUX_DEFAULT_PLACEHOLDER_SRC;
|
|
6101
|
+
}
|
|
6102
|
+
if (normalized === "false" || normalized === "0" || normalized === "no" || normalized === "off") {
|
|
6103
|
+
return undefined;
|
|
6104
|
+
}
|
|
6105
|
+
if (looksLikeClientMediaSource(trimmed)) {
|
|
6106
|
+
return trimmed;
|
|
6107
|
+
}
|
|
6108
|
+
return createClientTextPlaceholderDataUri(trimmed);
|
|
6109
|
+
}
|
|
6110
|
+
|
|
6111
|
+
function looksLikeClientMediaSource(value) {
|
|
6112
|
+
return value.startsWith("/")
|
|
6113
|
+
|| value.startsWith("./")
|
|
6114
|
+
|| value.startsWith("../")
|
|
6115
|
+
|| value.startsWith("http://")
|
|
6116
|
+
|| value.startsWith("https://")
|
|
6117
|
+
|| value.startsWith("data:image/")
|
|
6118
|
+
|| value.startsWith("blob:");
|
|
6119
|
+
}
|
|
6120
|
+
|
|
6121
|
+
function createClientTextPlaceholderDataUri(value) {
|
|
6122
|
+
const safeLabel = escapeClientSvgText(value);
|
|
6123
|
+
const svg =
|
|
6124
|
+
'<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 640 360" role="img" aria-label="' + safeLabel + '">'
|
|
6125
|
+
+ '<rect width="640" height="360" fill="#0f172a"/>'
|
|
6126
|
+
+ '<rect x="24" y="24" width="592" height="312" rx="20" fill="#111827" stroke="#334155" stroke-width="2"/>'
|
|
6127
|
+
+ '<text x="320" y="192" fill="#cbd5e1" font-size="30" text-anchor="middle" font-family="Segoe UI, Arial, sans-serif">' + safeLabel + '</text>'
|
|
6128
|
+
+ '</svg>';
|
|
6129
|
+
return "data:image/svg+xml," + encodeURIComponent(svg);
|
|
6130
|
+
}
|
|
6131
|
+
|
|
6132
|
+
function escapeClientSvgText(value) {
|
|
6133
|
+
return String(value)
|
|
6134
|
+
.replace(/&/g, "&")
|
|
6135
|
+
.replace(/</g, "<")
|
|
6136
|
+
.replace(/>/g, ">")
|
|
6137
|
+
.replace(/"/g, """)
|
|
6138
|
+
.replace(/'/g, "'");
|
|
6139
|
+
}
|
|
6140
|
+
|
|
6141
|
+
function mergeClientClassNames() {
|
|
6142
|
+
const values = Array.from(arguments);
|
|
6143
|
+
const tokens = values
|
|
6144
|
+
.flatMap((value) => String(value || "").split(/\s+/))
|
|
6145
|
+
.map((token) => token.trim())
|
|
6146
|
+
.filter(Boolean);
|
|
6147
|
+
return tokens.length ? [...new Set(tokens)].join(" ") : undefined;
|
|
6148
|
+
}
|
|
6149
|
+
|
|
6150
|
+
function mergeClientInlineStyles() {
|
|
6151
|
+
const values = Array.from(arguments);
|
|
6152
|
+
const parts = values
|
|
6153
|
+
.flatMap((value) => String(value || "").split(";"))
|
|
6154
|
+
.map((entry) => entry.trim())
|
|
6155
|
+
.filter(Boolean);
|
|
6156
|
+
return parts.length ? parts.join("; ") : undefined;
|
|
6157
|
+
}
|
|
6158
|
+
|
|
6159
|
+
function hasClientInlineStyleProperty(styleValue, propertyName) {
|
|
6160
|
+
if (typeof styleValue !== "string") {
|
|
6161
|
+
return false;
|
|
6162
|
+
}
|
|
6163
|
+
const normalized = String(propertyName).replace(/[.*+?^{}$()|[\]\\]/g, "\\$&");
|
|
6164
|
+
const pattern = new RegExp("(^|;)\\s*" + normalized + "\\s*:", "i");
|
|
6165
|
+
return pattern.test(styleValue);
|
|
6166
|
+
}
|
|
6167
|
+
|
|
6168
|
+
function resolveClientAspectRatioStyle(width, height) {
|
|
6169
|
+
const styleValues = Array.from(arguments).slice(2);
|
|
6170
|
+
if (!width || !height) {
|
|
6171
|
+
return undefined;
|
|
6172
|
+
}
|
|
6173
|
+
if (styleValues.some((entry) => hasClientInlineStyleProperty(entry, "aspect-ratio"))) {
|
|
6174
|
+
return undefined;
|
|
6175
|
+
}
|
|
6176
|
+
return "aspect-ratio: " + width + " / " + height;
|
|
6177
|
+
}
|
|
6178
|
+
|
|
6179
|
+
function inferClientImageMimeTypeFromSource(src) {
|
|
6180
|
+
const clean = String(src || "").split(/[?#]/)[0].toLowerCase();
|
|
6181
|
+
if (!clean) {
|
|
6182
|
+
return undefined;
|
|
6183
|
+
}
|
|
6184
|
+
const dotIndex = clean.lastIndexOf(".");
|
|
6185
|
+
if (dotIndex < 0) {
|
|
6186
|
+
return undefined;
|
|
6187
|
+
}
|
|
6188
|
+
const extension = clean.slice(dotIndex + 1);
|
|
6189
|
+
if (!extension) {
|
|
6190
|
+
return undefined;
|
|
6191
|
+
}
|
|
6192
|
+
return clientImageMimeType(extension);
|
|
6193
|
+
}
|
|
6194
|
+
|
|
6195
|
+
function resolveClientPictureSourceInputs(value, fallbackInput) {
|
|
6196
|
+
if (!Array.isArray(value)) {
|
|
6197
|
+
return [];
|
|
6198
|
+
}
|
|
6199
|
+
const resolved = [];
|
|
6200
|
+
for (const entry of value) {
|
|
6201
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6202
|
+
continue;
|
|
6203
|
+
}
|
|
6204
|
+
const record = entry;
|
|
6205
|
+
const src = readClientStringProp(record.src) || fallbackInput.src;
|
|
6206
|
+
if (!src) {
|
|
6207
|
+
continue;
|
|
6208
|
+
}
|
|
6209
|
+
const hasQuality = Object.prototype.hasOwnProperty.call(record, "quality");
|
|
6210
|
+
const hasFormat = Object.prototype.hasOwnProperty.call(record, "format");
|
|
6211
|
+
const explicitFormat = readClientStringProp(record.format);
|
|
6212
|
+
const explicitQuality = readClientNumberProp(record.quality);
|
|
6213
|
+
const widths = parseClientImageNumberList(record.widths) || fallbackInput.widths;
|
|
6214
|
+
const baseModifiers = normalizeClientImageModifiers(record.modifiers);
|
|
6215
|
+
const modifiers = normalizeClientImageModifiers({
|
|
6216
|
+
...fallbackInput.modifiers,
|
|
6217
|
+
...baseModifiers,
|
|
6218
|
+
...(hasFormat && !explicitFormat ? { format: false } : {}),
|
|
6219
|
+
...(hasQuality && !explicitQuality ? { quality: false } : {}),
|
|
6220
|
+
...(readClientStringProp(record.fit) ? { fit: readClientStringProp(record.fit) } : {}),
|
|
6221
|
+
...(readClientNumberProp(record.width) ? { width: readClientNumberProp(record.width) } : {}),
|
|
6222
|
+
...(readClientNumberProp(record.height) ? { height: readClientNumberProp(record.height) } : {}),
|
|
6223
|
+
...(explicitQuality ? { quality: explicitQuality } : {}),
|
|
6224
|
+
...(explicitFormat ? { format: explicitFormat } : {})
|
|
6225
|
+
});
|
|
6226
|
+
resolved.push({
|
|
6227
|
+
src,
|
|
6228
|
+
srcset: readClientStringProp(record.srcset),
|
|
6229
|
+
type: readClientStringProp(record.type),
|
|
6230
|
+
media: readClientStringProp(record.media),
|
|
6231
|
+
sizes: readClientStringProp(record.sizes) || fallbackInput.sizes,
|
|
6232
|
+
width: readClientNumberProp(record.width) || fallbackInput.width,
|
|
6233
|
+
height: readClientNumberProp(record.height) || fallbackInput.height,
|
|
6234
|
+
widths,
|
|
6235
|
+
quality: hasQuality ? explicitQuality : fallbackInput.quality,
|
|
6236
|
+
format: hasFormat ? explicitFormat : fallbackInput.format,
|
|
6237
|
+
fit: readClientStringProp(record.fit) || fallbackInput.fit,
|
|
6238
|
+
modifiers
|
|
6239
|
+
});
|
|
6240
|
+
}
|
|
6241
|
+
return resolved;
|
|
6242
|
+
}
|
|
6243
|
+
|
|
6244
|
+
function resolveClientVideoSources(value) {
|
|
6245
|
+
if (!Array.isArray(value)) {
|
|
6246
|
+
return [];
|
|
6247
|
+
}
|
|
6248
|
+
const sources = [];
|
|
6249
|
+
for (const entry of value) {
|
|
6250
|
+
if (!entry || typeof entry !== "object" || Array.isArray(entry)) {
|
|
6251
|
+
continue;
|
|
6252
|
+
}
|
|
6253
|
+
const src = readClientStringProp(entry.src);
|
|
6254
|
+
if (!src) {
|
|
6255
|
+
continue;
|
|
6256
|
+
}
|
|
6257
|
+
sources.push({
|
|
6258
|
+
src,
|
|
6259
|
+
type: readClientStringProp(entry.type)
|
|
6260
|
+
});
|
|
6261
|
+
}
|
|
6262
|
+
return sources;
|
|
6263
|
+
}
|
|
6264
|
+
|
|
3920
6265
|
function clientImageMimeType(format) {
|
|
3921
6266
|
const normalized = String(format || "").trim().toLowerCase();
|
|
3922
6267
|
if (!normalized) {
|
|
@@ -3945,12 +6290,13 @@ function nativeAttributeName(node, name) {
|
|
|
3945
6290
|
return node.tag === "ResuxLink" && name === "to" ? "href" : name;
|
|
3946
6291
|
}
|
|
3947
6292
|
|
|
3948
|
-
function applyPatches(scopeId, patches) {
|
|
3949
|
-
|
|
3950
|
-
|
|
3951
|
-
|
|
3952
|
-
|
|
3953
|
-
|
|
6293
|
+
function applyPatches(scopeId, patches) {
|
|
6294
|
+
let needsLazyImageActivation = false;
|
|
6295
|
+
for (const patch of patches) {
|
|
6296
|
+
if (patch.type === "text") {
|
|
6297
|
+
document.querySelectorAll('[data-rx-text="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
6298
|
+
element.textContent = patch.value;
|
|
6299
|
+
});
|
|
3954
6300
|
continue;
|
|
3955
6301
|
}
|
|
3956
6302
|
if (patch.type === "attr") {
|
|
@@ -3972,21 +6318,27 @@ function applyPatches(scopeId, patches) {
|
|
|
3972
6318
|
});
|
|
3973
6319
|
continue;
|
|
3974
6320
|
}
|
|
3975
|
-
if (patch.type === "html") {
|
|
3976
|
-
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
3977
|
-
unmountVueIslands(element);
|
|
3978
|
-
element.innerHTML = patch.value;
|
|
3979
|
-
void mountVueIslands(element);
|
|
3980
|
-
|
|
3981
|
-
|
|
3982
|
-
|
|
3983
|
-
|
|
3984
|
-
|
|
3985
|
-
element
|
|
3986
|
-
|
|
3987
|
-
|
|
3988
|
-
|
|
3989
|
-
}
|
|
6321
|
+
if (patch.type === "html") {
|
|
6322
|
+
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
6323
|
+
unmountVueIslands(element);
|
|
6324
|
+
element.innerHTML = patch.value;
|
|
6325
|
+
void mountVueIslands(element);
|
|
6326
|
+
needsLazyImageActivation = true;
|
|
6327
|
+
});
|
|
6328
|
+
continue;
|
|
6329
|
+
}
|
|
6330
|
+
document.querySelectorAll('[data-rx-block="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
6331
|
+
unmountVueIslands(element);
|
|
6332
|
+
element.innerHTML = patch.value;
|
|
6333
|
+
void mountVueIslands(element);
|
|
6334
|
+
needsLazyImageActivation = true;
|
|
6335
|
+
});
|
|
6336
|
+
}
|
|
6337
|
+
if (needsLazyImageActivation) {
|
|
6338
|
+
activateDeferredLazyMedia();
|
|
6339
|
+
applyReducedMotionVideoPreference();
|
|
6340
|
+
}
|
|
6341
|
+
}
|
|
3990
6342
|
|
|
3991
6343
|
function evaluateExpression(expression, scope, locals) {
|
|
3992
6344
|
return Function("scope", "locals", "with (scope) { with (locals) { return (" + expression + "); } }")(scope, locals);
|