resuxjs 0.2.33 → 0.2.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +264 -0
- package/dist/cli.js.map +1 -1
- package/dist/compiler/index.js +5 -2
- package/dist/compiler/index.js.map +1 -1
- package/dist/deploy/cloudflare.js +3 -11
- package/dist/deploy/cloudflare.js.map +1 -1
- package/dist/deploy/common.d.ts +2 -0
- package/dist/deploy/common.js +25 -2
- package/dist/deploy/common.js.map +1 -1
- package/dist/deploy/index.js +1 -34
- package/dist/deploy/index.js.map +1 -1
- package/dist/deploy/netlify.js +5 -1
- package/dist/deploy/netlify.js.map +1 -1
- package/dist/deploy/node.js +7 -1
- package/dist/deploy/node.js.map +1 -1
- package/dist/deploy/static.js +2 -1
- package/dist/deploy/static.js.map +1 -1
- package/dist/deploy/vercel.js +34 -10
- package/dist/deploy/vercel.js.map +1 -1
- package/dist/globals.d.ts +2 -1
- package/dist/runtime/index.d.ts +34 -0
- package/dist/runtime/index.js +1679 -203
- package/dist/runtime/index.js.map +1 -1
- package/package.json +2 -1
package/dist/runtime/index.js
CHANGED
|
@@ -37,6 +37,10 @@ export function useResuxApp() {
|
|
|
37
37
|
}
|
|
38
38
|
throw new Error("useResuxApp() is only available while executing a Resux setup or middleware context.");
|
|
39
39
|
}
|
|
40
|
+
export function useResuxImage() {
|
|
41
|
+
const app = useResuxApp();
|
|
42
|
+
return createResuxImageBuilder(app.route, app.$config, typeof window !== "undefined");
|
|
43
|
+
}
|
|
40
44
|
export function navigateTo(to, options = {}) {
|
|
41
45
|
return {
|
|
42
46
|
type: "redirect",
|
|
@@ -112,64 +116,62 @@ export function renderDocument(result, title = "Resux App", options = {}) {
|
|
|
112
116
|
[data-rx-block] {
|
|
113
117
|
display: contents !important;
|
|
114
118
|
}
|
|
115
|
-
|
|
119
|
+
[data-rx-loading-indicator] {
|
|
116
120
|
position: fixed;
|
|
117
121
|
inset: 0 0 auto;
|
|
118
122
|
z-index: 9999;
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
max-width: min(28rem, calc(100vw - 2rem));
|
|
142
|
-
margin: 0.75rem auto 0;
|
|
123
|
+
pointer-events: none;
|
|
124
|
+
}
|
|
125
|
+
[data-rx-loading-indicator][hidden] {
|
|
126
|
+
display: none;
|
|
127
|
+
}
|
|
128
|
+
[data-rx-loading-indicator] .rx-loading-bar {
|
|
129
|
+
height: var(--resux-loader-height, 3px);
|
|
130
|
+
overflow: hidden;
|
|
131
|
+
background: rgba(24, 24, 27, 0.12);
|
|
132
|
+
}
|
|
133
|
+
[data-rx-loading-indicator] .rx-loading-progress {
|
|
134
|
+
display: block;
|
|
135
|
+
width: var(--resux-progress, 8%);
|
|
136
|
+
height: 100%;
|
|
137
|
+
background: var(--resux-loader-color, #2563eb);
|
|
138
|
+
box-shadow: 0 0 18px rgba(37, 99, 235, 0.45);
|
|
139
|
+
transition: width 160ms ease, background 160ms ease;
|
|
140
|
+
}
|
|
141
|
+
[data-rx-loading-indicator] .rx-loading-slot {
|
|
142
|
+
width: fit-content;
|
|
143
|
+
max-width: min(28rem, calc(100vw - 2rem));
|
|
144
|
+
margin: 0.75rem auto 0;
|
|
143
145
|
padding: 0.55rem 0.8rem;
|
|
144
146
|
border: 1px solid rgba(24, 24, 27, 0.12);
|
|
145
147
|
border-radius: 8px;
|
|
146
148
|
background: rgba(255, 255, 255, 0.92);
|
|
147
|
-
box-shadow: 0 12px 32px rgba(24, 24, 27, 0.12);
|
|
148
|
-
backdrop-filter: blur(12px);
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
}
|
|
149
|
+
box-shadow: 0 12px 32px rgba(24, 24, 27, 0.12);
|
|
150
|
+
backdrop-filter: blur(12px);
|
|
151
|
+
pointer-events: auto;
|
|
152
|
+
}
|
|
153
|
+
[data-rx-loading-indicator][data-state="error"] .rx-loading-progress {
|
|
154
|
+
background: var(--resux-loader-error-color, #dc2626);
|
|
155
|
+
}
|
|
156
|
+
[data-rx-loading-indicator][data-state="complete"] .rx-loading-progress {
|
|
157
|
+
background: #16a34a;
|
|
158
|
+
}
|
|
159
|
+
#__resux[data-route-transition="loading"] {
|
|
160
|
+
opacity: 0.72;
|
|
161
|
+
transition: opacity 120ms ease;
|
|
162
|
+
}
|
|
163
|
+
@media (prefers-reduced-motion: reduce) {
|
|
164
|
+
[data-rx-loading-indicator] .rx-loading-progress,
|
|
165
|
+
#__resux[data-route-transition="loading"] {
|
|
166
|
+
transition: none;
|
|
167
|
+
}
|
|
168
|
+
}
|
|
166
169
|
</style>`,
|
|
167
170
|
"</head>",
|
|
168
171
|
"<body>",
|
|
169
172
|
'<div id="__resux">',
|
|
170
173
|
result.html,
|
|
171
174
|
"</div>",
|
|
172
|
-
'<div id="__resux-loading" hidden data-state="idle" aria-live="polite" aria-busy="false"><div class="bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-valuetext="Idle"><span></span></div><div class="panel" data-rx-transition-message>Ready</div></div>',
|
|
173
175
|
`<script>window.__RESUX__=${payload}</script>`,
|
|
174
176
|
options.devReload ? getDevReloadScript() : "",
|
|
175
177
|
'<script type="module" src="/__resux/runtime-client.mjs"></script>',
|
|
@@ -230,9 +232,11 @@ class ResuxRenderer {
|
|
|
230
232
|
moduleId: definition.id,
|
|
231
233
|
styleScopeId: definition.styleScopeId,
|
|
232
234
|
route: this.route,
|
|
235
|
+
runtimeConfig: this.runtimeConfig,
|
|
233
236
|
components: this.components,
|
|
234
237
|
layouts: {},
|
|
235
238
|
pageMeta: definition.meta ?? {},
|
|
239
|
+
addHeadEntry: (entry) => this.headEntries.push(entry),
|
|
236
240
|
renderPage,
|
|
237
241
|
renderSlot
|
|
238
242
|
});
|
|
@@ -332,6 +336,9 @@ function createServerSetupContext(route, props, stateRefs, asyncDataRefs, headEn
|
|
|
332
336
|
return resuxApp;
|
|
333
337
|
},
|
|
334
338
|
apiURL,
|
|
339
|
+
useResuxImage() {
|
|
340
|
+
return createResuxImageBuilder(route, runtimeConfig, false);
|
|
341
|
+
},
|
|
335
342
|
async useFetch(url, init) {
|
|
336
343
|
return ref(await fetchJson(url, init));
|
|
337
344
|
},
|
|
@@ -415,6 +422,231 @@ function resolveServerApiURL(url, route, runtimeConfig) {
|
|
|
415
422
|
function isInternalApiURL(url) {
|
|
416
423
|
return url === "/api" || url.startsWith("/api/");
|
|
417
424
|
}
|
|
425
|
+
function createResuxImageBuilder(route, runtimeConfig, client) {
|
|
426
|
+
return (src, options = {}) => {
|
|
427
|
+
const normalizedSrc = normalizeImageSource(src, route);
|
|
428
|
+
const imageConfig = resolveRuntimeImageConfig(runtimeConfig);
|
|
429
|
+
const providerName = (options.provider ?? imageConfig.provider ?? "resux").trim();
|
|
430
|
+
const providerConfig = resolveImageProviderConfig(providerName, imageConfig);
|
|
431
|
+
const modifiers = normalizeImageModifiers({
|
|
432
|
+
...(providerConfig.modifiers ?? {}),
|
|
433
|
+
...(typeof imageConfig.quality === "number" ? { quality: imageConfig.quality } : {}),
|
|
434
|
+
...(typeof imageConfig.format === "string" ? { format: imageConfig.format } : {}),
|
|
435
|
+
...(options.modifiers ?? {}),
|
|
436
|
+
...(typeof options.width === "number" ? { width: options.width } : {}),
|
|
437
|
+
...(typeof options.height === "number" ? { height: options.height } : {}),
|
|
438
|
+
...(typeof options.quality === "number" ? { quality: options.quality } : {}),
|
|
439
|
+
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
440
|
+
...(typeof options.format === "string" ? { format: options.format } : {}),
|
|
441
|
+
});
|
|
442
|
+
return buildResuxImageURL(providerName, providerConfig.baseURL, normalizedSrc, modifiers, client);
|
|
443
|
+
};
|
|
444
|
+
}
|
|
445
|
+
function normalizeImageSource(src, route) {
|
|
446
|
+
const value = String(src ?? "").trim();
|
|
447
|
+
if (!value) {
|
|
448
|
+
return "";
|
|
449
|
+
}
|
|
450
|
+
if (value.startsWith("http://")
|
|
451
|
+
|| value.startsWith("https://")
|
|
452
|
+
|| value.startsWith("data:")
|
|
453
|
+
|| value.startsWith("blob:")
|
|
454
|
+
|| value.startsWith("file:")) {
|
|
455
|
+
return value;
|
|
456
|
+
}
|
|
457
|
+
if (value.startsWith("/")) {
|
|
458
|
+
return value;
|
|
459
|
+
}
|
|
460
|
+
const basePath = route.path.startsWith("/") ? route.path : `/${route.path}`;
|
|
461
|
+
const directory = basePath.endsWith("/")
|
|
462
|
+
? basePath
|
|
463
|
+
: `${basePath.slice(0, Math.max(basePath.lastIndexOf("/") + 1, 1))}`;
|
|
464
|
+
const normalized = new URL(value, `https://resux.local${directory}`);
|
|
465
|
+
return `${normalized.pathname}${normalized.search}${normalized.hash}`;
|
|
466
|
+
}
|
|
467
|
+
function resolveRuntimeImageConfig(runtimeConfig) {
|
|
468
|
+
const publicConfig = runtimeConfig.public ?? {};
|
|
469
|
+
const candidate = (publicConfig.image ?? publicConfig.resuxImage);
|
|
470
|
+
if (!candidate || typeof candidate !== "object" || Array.isArray(candidate)) {
|
|
471
|
+
return {};
|
|
472
|
+
}
|
|
473
|
+
const input = candidate;
|
|
474
|
+
const providers = resolveImageProviders(input.providers);
|
|
475
|
+
const densities = resolveImageDensities(input.densities);
|
|
476
|
+
return {
|
|
477
|
+
provider: typeof input.provider === "string" ? input.provider : undefined,
|
|
478
|
+
quality: typeof input.quality === "number" ? input.quality : undefined,
|
|
479
|
+
format: typeof input.format === "string" ? input.format : undefined,
|
|
480
|
+
...(densities.length ? { densities } : {}),
|
|
481
|
+
...(Object.keys(providers).length ? { providers } : {}),
|
|
482
|
+
};
|
|
483
|
+
}
|
|
484
|
+
function resolveImageProviders(value) {
|
|
485
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
486
|
+
return {};
|
|
487
|
+
}
|
|
488
|
+
const providers = {};
|
|
489
|
+
for (const [name, provider] of Object.entries(value)) {
|
|
490
|
+
if (!provider || typeof provider !== "object" || Array.isArray(provider)) {
|
|
491
|
+
continue;
|
|
492
|
+
}
|
|
493
|
+
const record = provider;
|
|
494
|
+
providers[name] = {
|
|
495
|
+
...(typeof record.baseURL === "string" ? { baseURL: record.baseURL } : {}),
|
|
496
|
+
...(record.modifiers && typeof record.modifiers === "object" && !Array.isArray(record.modifiers)
|
|
497
|
+
? { modifiers: normalizeImageModifiers(record.modifiers) }
|
|
498
|
+
: {}),
|
|
499
|
+
};
|
|
500
|
+
}
|
|
501
|
+
return providers;
|
|
502
|
+
}
|
|
503
|
+
function resolveImageDensities(value) {
|
|
504
|
+
if (!Array.isArray(value)) {
|
|
505
|
+
return [];
|
|
506
|
+
}
|
|
507
|
+
return value
|
|
508
|
+
.map((entry) => Number(entry))
|
|
509
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
510
|
+
.map((entry) => Math.round(entry));
|
|
511
|
+
}
|
|
512
|
+
function resolveImageProviderConfig(providerName, imageConfig) {
|
|
513
|
+
return imageConfig.providers?.[providerName] ?? {};
|
|
514
|
+
}
|
|
515
|
+
function normalizeImageModifiers(modifiers) {
|
|
516
|
+
const normalized = {};
|
|
517
|
+
for (const [key, value] of Object.entries(modifiers ?? {})) {
|
|
518
|
+
if (value === undefined || value === null || value === false) {
|
|
519
|
+
continue;
|
|
520
|
+
}
|
|
521
|
+
if (key === "width" || key === "height" || key === "quality") {
|
|
522
|
+
const numeric = Number(value);
|
|
523
|
+
if (Number.isFinite(numeric) && numeric > 0) {
|
|
524
|
+
normalized[key] = Math.round(numeric);
|
|
525
|
+
}
|
|
526
|
+
continue;
|
|
527
|
+
}
|
|
528
|
+
normalized[key] = value;
|
|
529
|
+
}
|
|
530
|
+
return normalized;
|
|
531
|
+
}
|
|
532
|
+
function buildResuxImageURL(providerName, providerBaseURL, src, modifiers, client) {
|
|
533
|
+
const trimmedProvider = providerName.trim().toLowerCase();
|
|
534
|
+
const baseURL = providerBaseURL?.trim()
|
|
535
|
+
|| (trimmedProvider === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
536
|
+
const normalizedFormat = normalizeImageOutputFormat(typeof modifiers.format === "string" ? modifiers.format : undefined);
|
|
537
|
+
if (baseURL.includes("{src}")) {
|
|
538
|
+
return injectImageTemplateSource(baseURL, src, modifiers);
|
|
539
|
+
}
|
|
540
|
+
const sourceDescriptor = trimmedProvider === "vercel"
|
|
541
|
+
? { publicSource: src }
|
|
542
|
+
: rewriteImageSourceForDisplayFormat(src, normalizedFormat);
|
|
543
|
+
const query = new URLSearchParams();
|
|
544
|
+
if (trimmedProvider === "vercel") {
|
|
545
|
+
query.set("url", src);
|
|
546
|
+
}
|
|
547
|
+
else {
|
|
548
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
549
|
+
if (sourceDescriptor.originalSource) {
|
|
550
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
551
|
+
}
|
|
552
|
+
}
|
|
553
|
+
const width = Number(modifiers.width);
|
|
554
|
+
const height = Number(modifiers.height);
|
|
555
|
+
const quality = Number(modifiers.quality);
|
|
556
|
+
if (Number.isFinite(width) && width > 0) {
|
|
557
|
+
query.set("w", String(Math.round(width)));
|
|
558
|
+
}
|
|
559
|
+
if (Number.isFinite(height) && height > 0) {
|
|
560
|
+
query.set("h", String(Math.round(height)));
|
|
561
|
+
}
|
|
562
|
+
if (Number.isFinite(quality) && quality > 0) {
|
|
563
|
+
query.set("q", String(Math.round(quality)));
|
|
564
|
+
}
|
|
565
|
+
if (typeof modifiers.fit === "string" && modifiers.fit.length > 0) {
|
|
566
|
+
query.set("fit", modifiers.fit);
|
|
567
|
+
}
|
|
568
|
+
if (normalizedFormat) {
|
|
569
|
+
query.set("f", normalizedFormat);
|
|
570
|
+
}
|
|
571
|
+
else if (typeof modifiers.format === "string" && modifiers.format.length > 0) {
|
|
572
|
+
query.set("f", modifiers.format);
|
|
573
|
+
}
|
|
574
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
575
|
+
if (["width", "height", "quality", "fit", "format"].includes(key)) {
|
|
576
|
+
continue;
|
|
577
|
+
}
|
|
578
|
+
query.set(key, String(value));
|
|
579
|
+
}
|
|
580
|
+
const separator = baseURL.includes("?") ? "&" : "?";
|
|
581
|
+
const queryString = query.toString();
|
|
582
|
+
if (!queryString) {
|
|
583
|
+
return baseURL;
|
|
584
|
+
}
|
|
585
|
+
const resolved = `${baseURL}${separator}${queryString}`;
|
|
586
|
+
if (client) {
|
|
587
|
+
return resolved;
|
|
588
|
+
}
|
|
589
|
+
return resolved;
|
|
590
|
+
}
|
|
591
|
+
function injectImageTemplateSource(template, src, modifiers) {
|
|
592
|
+
let resolved = template.replaceAll("{src}", encodeURIComponent(src));
|
|
593
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
594
|
+
resolved = resolved.replaceAll(`{${key}}`, encodeURIComponent(String(value)));
|
|
595
|
+
}
|
|
596
|
+
return resolved;
|
|
597
|
+
}
|
|
598
|
+
function normalizeImageOutputFormat(value) {
|
|
599
|
+
if (typeof value !== "string") {
|
|
600
|
+
return undefined;
|
|
601
|
+
}
|
|
602
|
+
const normalized = value.trim().toLowerCase();
|
|
603
|
+
if (!normalized) {
|
|
604
|
+
return undefined;
|
|
605
|
+
}
|
|
606
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
607
|
+
}
|
|
608
|
+
function rewriteImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
609
|
+
if (!normalizedFormat) {
|
|
610
|
+
return { publicSource: src };
|
|
611
|
+
}
|
|
612
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
613
|
+
return { publicSource: src };
|
|
614
|
+
}
|
|
615
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
616
|
+
try {
|
|
617
|
+
const sourceUrl = new URL(src);
|
|
618
|
+
const rewrittenPathname = rewriteImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
619
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
620
|
+
return { publicSource: src };
|
|
621
|
+
}
|
|
622
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
623
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
624
|
+
}
|
|
625
|
+
catch {
|
|
626
|
+
return { publicSource: src };
|
|
627
|
+
}
|
|
628
|
+
}
|
|
629
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
630
|
+
const rewrittenPath = rewriteImagePathExtension(pathPart, normalizedFormat);
|
|
631
|
+
if (rewrittenPath === pathPart) {
|
|
632
|
+
return { publicSource: src };
|
|
633
|
+
}
|
|
634
|
+
return { publicSource: `${rewrittenPath}${suffix}`, originalSource: src };
|
|
635
|
+
}
|
|
636
|
+
function rewriteImagePathExtension(pathname, extension) {
|
|
637
|
+
if (!pathname) {
|
|
638
|
+
return pathname;
|
|
639
|
+
}
|
|
640
|
+
const normalizedExtension = extension.startsWith(".")
|
|
641
|
+
? extension.slice(1)
|
|
642
|
+
: extension;
|
|
643
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
644
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
645
|
+
if (lastDot > lastSlash) {
|
|
646
|
+
return `${pathname.slice(0, lastDot + 1)}${normalizedExtension}`;
|
|
647
|
+
}
|
|
648
|
+
return `${pathname}.${normalizedExtension}`;
|
|
649
|
+
}
|
|
418
650
|
function runtimeOrigin(runtimeConfig) {
|
|
419
651
|
const publicConfig = runtimeConfig.public ?? {};
|
|
420
652
|
for (const key of ["appOrigin", "appURL", "siteURL", "origin"]) {
|
|
@@ -478,6 +710,15 @@ function renderElement(node, context, locals) {
|
|
|
478
710
|
if (node.tag === "ResuxLink") {
|
|
479
711
|
return renderNativeElement(node, context, locals);
|
|
480
712
|
}
|
|
713
|
+
if (node.tag === "ResuxImg") {
|
|
714
|
+
return renderResuxImg(node, context, locals);
|
|
715
|
+
}
|
|
716
|
+
if (node.tag === "ResuxPicture") {
|
|
717
|
+
return renderResuxPicture(node, context, locals);
|
|
718
|
+
}
|
|
719
|
+
if (node.tag === "ResuxLoadingIndicator") {
|
|
720
|
+
return renderResuxLoadingIndicatorSync(node, context, locals, renderTemplateNodes(node.children, context, locals));
|
|
721
|
+
}
|
|
481
722
|
if (node.tag === "VueIsland") {
|
|
482
723
|
return renderVueIsland(node, context, locals);
|
|
483
724
|
}
|
|
@@ -578,6 +819,15 @@ async function renderElementAsync(node, context, renderComponent, locals) {
|
|
|
578
819
|
if (node.tag === "ResuxLink") {
|
|
579
820
|
return renderNativeElementAsync(node, context, renderComponent, locals);
|
|
580
821
|
}
|
|
822
|
+
if (node.tag === "ResuxImg") {
|
|
823
|
+
return renderResuxImg(node, context, locals);
|
|
824
|
+
}
|
|
825
|
+
if (node.tag === "ResuxPicture") {
|
|
826
|
+
return renderResuxPicture(node, context, locals);
|
|
827
|
+
}
|
|
828
|
+
if (node.tag === "ResuxLoadingIndicator") {
|
|
829
|
+
return renderResuxLoadingIndicatorAsync(node, context, locals, renderTemplateNodesAsync(node.children, context, renderComponent, locals));
|
|
830
|
+
}
|
|
581
831
|
if (node.tag === "VueIsland") {
|
|
582
832
|
return renderVueIsland(node, context, locals);
|
|
583
833
|
}
|
|
@@ -624,6 +874,347 @@ async function renderNativeElementAsync(node, context, renderComponent, locals)
|
|
|
624
874
|
: await renderTemplateNodesAsync(node.children, context, renderComponent, locals);
|
|
625
875
|
return `<${tag}${attrText}>${children}</${tag}>`;
|
|
626
876
|
}
|
|
877
|
+
const resuxImageReservedProps = new Set([
|
|
878
|
+
"src",
|
|
879
|
+
"alt",
|
|
880
|
+
"provider",
|
|
881
|
+
"modifiers",
|
|
882
|
+
"quality",
|
|
883
|
+
"fit",
|
|
884
|
+
"format",
|
|
885
|
+
"formats",
|
|
886
|
+
"width",
|
|
887
|
+
"height",
|
|
888
|
+
"widths",
|
|
889
|
+
"sizes",
|
|
890
|
+
"densities",
|
|
891
|
+
"priority",
|
|
892
|
+
"preload",
|
|
893
|
+
"lazy",
|
|
894
|
+
"loading",
|
|
895
|
+
"decoding",
|
|
896
|
+
"fetchpriority",
|
|
897
|
+
"fetchPriority",
|
|
898
|
+
]);
|
|
899
|
+
const resuxLazyPlaceholderSrc = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
900
|
+
function renderResuxImg(node, context, locals) {
|
|
901
|
+
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
902
|
+
if (!input.src) {
|
|
903
|
+
return "";
|
|
904
|
+
}
|
|
905
|
+
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
906
|
+
const src = builder(input.src, {
|
|
907
|
+
provider: input.provider,
|
|
908
|
+
width: input.width,
|
|
909
|
+
height: input.height,
|
|
910
|
+
quality: input.quality,
|
|
911
|
+
fit: input.fit,
|
|
912
|
+
format: input.format,
|
|
913
|
+
modifiers: input.modifiers,
|
|
914
|
+
});
|
|
915
|
+
const srcset = buildResuxImageSrcset(builder, input);
|
|
916
|
+
registerResuxImagePreload(context, src, srcset, input, input.preload);
|
|
917
|
+
return renderResuxImgTag(input, src, srcset, context.styleScopeId);
|
|
918
|
+
}
|
|
919
|
+
function renderResuxPicture(node, context, locals) {
|
|
920
|
+
const input = resolveResuxImageRenderInput(node, context, locals);
|
|
921
|
+
if (!input.src) {
|
|
922
|
+
return "";
|
|
923
|
+
}
|
|
924
|
+
const builder = createResuxImageBuilder(context.route, context.runtimeConfig, false);
|
|
925
|
+
const fallbackSrc = builder(input.src, {
|
|
926
|
+
provider: input.provider,
|
|
927
|
+
width: input.width,
|
|
928
|
+
height: input.height,
|
|
929
|
+
quality: input.quality,
|
|
930
|
+
fit: input.fit,
|
|
931
|
+
modifiers: input.modifiers,
|
|
932
|
+
});
|
|
933
|
+
const fallbackSrcset = buildResuxImageSrcset(builder, {
|
|
934
|
+
...input,
|
|
935
|
+
format: undefined,
|
|
936
|
+
});
|
|
937
|
+
registerResuxImagePreload(context, fallbackSrc, fallbackSrcset, input, input.preload);
|
|
938
|
+
const manualChildren = renderTemplateNodes(node.children, context, locals);
|
|
939
|
+
const generatedSources = input.formats
|
|
940
|
+
.map((format) => {
|
|
941
|
+
const sourceSrcset = buildResuxImageSrcset(builder, {
|
|
942
|
+
...input,
|
|
943
|
+
format,
|
|
944
|
+
});
|
|
945
|
+
const resolvedSrcset = sourceSrcset
|
|
946
|
+
|| builder(input.src, {
|
|
947
|
+
provider: input.provider,
|
|
948
|
+
width: input.width,
|
|
949
|
+
height: input.height,
|
|
950
|
+
quality: input.quality,
|
|
951
|
+
fit: input.fit,
|
|
952
|
+
format,
|
|
953
|
+
modifiers: input.modifiers,
|
|
954
|
+
});
|
|
955
|
+
if (!resolvedSrcset) {
|
|
956
|
+
return "";
|
|
957
|
+
}
|
|
958
|
+
const sourceAttrs = [`type="${escapeAttribute(resuxImageMimeType(format))}"`];
|
|
959
|
+
if (input.deferLazy) {
|
|
960
|
+
sourceAttrs.push(`data-rx-lazy-srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
961
|
+
if (input.sizes) {
|
|
962
|
+
sourceAttrs.push(`data-rx-lazy-sizes="${escapeAttribute(input.sizes)}"`);
|
|
963
|
+
}
|
|
964
|
+
}
|
|
965
|
+
else {
|
|
966
|
+
sourceAttrs.push(`srcset="${escapeAttribute(resolvedSrcset)}"`);
|
|
967
|
+
if (input.sizes) {
|
|
968
|
+
sourceAttrs.push(`sizes="${escapeAttribute(input.sizes)}"`);
|
|
969
|
+
}
|
|
970
|
+
}
|
|
971
|
+
return `<source ${sourceAttrs.join(" ")}>`;
|
|
972
|
+
})
|
|
973
|
+
.filter(Boolean)
|
|
974
|
+
.join("");
|
|
975
|
+
const img = renderResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
976
|
+
const attrs = [];
|
|
977
|
+
appendStyleScopeAttribute(attrs, context.styleScopeId);
|
|
978
|
+
const attrText = attrs.length ? ` ${attrs.join(" ")}` : "";
|
|
979
|
+
return `<picture${attrText}>${manualChildren}${generatedSources}${img}</picture>`;
|
|
980
|
+
}
|
|
981
|
+
function resolveResuxImageRenderInput(node, context, locals) {
|
|
982
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
983
|
+
const runtimeImageConfig = resolveRuntimeImageConfig(context.runtimeConfig);
|
|
984
|
+
const modifiers = resolveResuxImageModifierProps(props.modifiers);
|
|
985
|
+
const explicitFormat = readStringProp(props.format);
|
|
986
|
+
const explicitFormats = parseImageFormats(props.formats
|
|
987
|
+
?? (explicitFormat?.includes(",") ? explicitFormat : undefined));
|
|
988
|
+
const provider = readStringProp(props.provider);
|
|
989
|
+
const quality = readNumberProp(props.quality) ?? runtimeImageConfig.quality;
|
|
990
|
+
const fit = readStringProp(props.fit);
|
|
991
|
+
const width = readNumberProp(props.width);
|
|
992
|
+
const height = readNumberProp(props.height);
|
|
993
|
+
const priority = readBooleanProp(props.priority, false);
|
|
994
|
+
const preload = readBooleanProp(props.preload, priority);
|
|
995
|
+
const explicitLoading = readStringProp(props.loading);
|
|
996
|
+
const explicitLazy = props.lazy === undefined
|
|
997
|
+
? undefined
|
|
998
|
+
: readBooleanProp(props.lazy, true);
|
|
999
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
1000
|
+
const loading = explicitLoading ?? (lazy ? "lazy" : "eager");
|
|
1001
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
1002
|
+
const decoding = readStringProp(props.decoding) ?? "async";
|
|
1003
|
+
const fetchPriority = readStringProp(props.fetchpriority ?? props.fetchPriority)
|
|
1004
|
+
?? (priority ? "high" : undefined);
|
|
1005
|
+
const densities = parseImageNumberList(props.densities)
|
|
1006
|
+
|| runtimeImageConfig.densities
|
|
1007
|
+
|| [1, 2];
|
|
1008
|
+
const widths = parseImageNumberList(props.widths) ?? [];
|
|
1009
|
+
const passthrough = collectResuxImagePassthroughAttributes(props);
|
|
1010
|
+
const src = readStringProp(props.src) ?? "";
|
|
1011
|
+
const alt = readStringProp(props.alt) ?? "";
|
|
1012
|
+
return {
|
|
1013
|
+
src,
|
|
1014
|
+
alt,
|
|
1015
|
+
width,
|
|
1016
|
+
height,
|
|
1017
|
+
sizes: readStringProp(props.sizes),
|
|
1018
|
+
densities,
|
|
1019
|
+
widths,
|
|
1020
|
+
loading,
|
|
1021
|
+
decoding,
|
|
1022
|
+
fetchPriority,
|
|
1023
|
+
provider,
|
|
1024
|
+
quality,
|
|
1025
|
+
fit,
|
|
1026
|
+
format: explicitFormats.length ? undefined : explicitFormat ?? runtimeImageConfig.format,
|
|
1027
|
+
formats: explicitFormats,
|
|
1028
|
+
preload,
|
|
1029
|
+
deferLazy,
|
|
1030
|
+
modifiers,
|
|
1031
|
+
attrs: passthrough,
|
|
1032
|
+
};
|
|
1033
|
+
}
|
|
1034
|
+
function collectResuxImagePassthroughAttributes(props) {
|
|
1035
|
+
const attrs = {};
|
|
1036
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
1037
|
+
if (resuxImageReservedProps.has(name)) {
|
|
1038
|
+
continue;
|
|
1039
|
+
}
|
|
1040
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
1041
|
+
continue;
|
|
1042
|
+
}
|
|
1043
|
+
const attrName = name === "className"
|
|
1044
|
+
? "class"
|
|
1045
|
+
: name === "referrerPolicy"
|
|
1046
|
+
? "referrerpolicy"
|
|
1047
|
+
: name === "crossOrigin"
|
|
1048
|
+
? "crossorigin"
|
|
1049
|
+
: name;
|
|
1050
|
+
attrs[attrName] = stringifyAttributeValue(attrName, rawValue);
|
|
1051
|
+
}
|
|
1052
|
+
return attrs;
|
|
1053
|
+
}
|
|
1054
|
+
function resolveResuxImageModifierProps(value) {
|
|
1055
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
1056
|
+
return {};
|
|
1057
|
+
}
|
|
1058
|
+
return normalizeImageModifiers(value);
|
|
1059
|
+
}
|
|
1060
|
+
function buildResuxImageSrcset(builder, input) {
|
|
1061
|
+
const widthCandidates = input.widths.length
|
|
1062
|
+
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
1063
|
+
: [];
|
|
1064
|
+
if (widthCandidates.length) {
|
|
1065
|
+
return widthCandidates
|
|
1066
|
+
.map((width) => `${builder(input.src, {
|
|
1067
|
+
provider: input.provider,
|
|
1068
|
+
width,
|
|
1069
|
+
height: input.height,
|
|
1070
|
+
quality: input.quality,
|
|
1071
|
+
fit: input.fit,
|
|
1072
|
+
format: input.format,
|
|
1073
|
+
modifiers: input.modifiers,
|
|
1074
|
+
})} ${width}w`)
|
|
1075
|
+
.join(", ");
|
|
1076
|
+
}
|
|
1077
|
+
if (!input.width || !input.densities.length) {
|
|
1078
|
+
return undefined;
|
|
1079
|
+
}
|
|
1080
|
+
return [...new Set(input.densities)]
|
|
1081
|
+
.sort((left, right) => left - right)
|
|
1082
|
+
.map((density) => {
|
|
1083
|
+
const width = Math.max(1, Math.round(input.width * density));
|
|
1084
|
+
return `${builder(input.src, {
|
|
1085
|
+
provider: input.provider,
|
|
1086
|
+
width,
|
|
1087
|
+
height: input.height ? Math.max(1, Math.round(input.height * density)) : undefined,
|
|
1088
|
+
quality: input.quality,
|
|
1089
|
+
fit: input.fit,
|
|
1090
|
+
format: input.format,
|
|
1091
|
+
modifiers: input.modifiers,
|
|
1092
|
+
})} ${density}x`;
|
|
1093
|
+
})
|
|
1094
|
+
.join(", ");
|
|
1095
|
+
}
|
|
1096
|
+
function registerResuxImagePreload(context, href, srcset, input, enabled) {
|
|
1097
|
+
if (!enabled || !href || !context.addHeadEntry) {
|
|
1098
|
+
return;
|
|
1099
|
+
}
|
|
1100
|
+
const link = {
|
|
1101
|
+
rel: "preload",
|
|
1102
|
+
as: "image",
|
|
1103
|
+
href,
|
|
1104
|
+
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1105
|
+
};
|
|
1106
|
+
if (srcset) {
|
|
1107
|
+
link.imagesrcset = srcset;
|
|
1108
|
+
}
|
|
1109
|
+
if (input.sizes) {
|
|
1110
|
+
link.imagesizes = input.sizes;
|
|
1111
|
+
}
|
|
1112
|
+
if (input.format && input.formats.length === 0) {
|
|
1113
|
+
link.type = resuxImageMimeType(input.format);
|
|
1114
|
+
}
|
|
1115
|
+
context.addHeadEntry({ link: [link] });
|
|
1116
|
+
}
|
|
1117
|
+
function renderResuxImgTag(input, src, srcset, styleScopeId) {
|
|
1118
|
+
const attrs = [];
|
|
1119
|
+
const isDeferredLazy = input.deferLazy && input.loading.toLowerCase() === "lazy";
|
|
1120
|
+
const mergedAttrs = {
|
|
1121
|
+
...input.attrs,
|
|
1122
|
+
src: isDeferredLazy ? resuxLazyPlaceholderSrc : src,
|
|
1123
|
+
alt: input.alt,
|
|
1124
|
+
loading: input.loading,
|
|
1125
|
+
decoding: input.decoding,
|
|
1126
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
1127
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src } : {}),
|
|
1128
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset } : {}),
|
|
1129
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
1130
|
+
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
1131
|
+
...(input.width ? { width: String(input.width) } : {}),
|
|
1132
|
+
...(input.height ? { height: String(input.height) } : {}),
|
|
1133
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
1134
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {}),
|
|
1135
|
+
};
|
|
1136
|
+
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
1137
|
+
if (value === undefined || value === null) {
|
|
1138
|
+
continue;
|
|
1139
|
+
}
|
|
1140
|
+
attrs.push(`${name}="${escapeAttribute(String(value))}"`);
|
|
1141
|
+
}
|
|
1142
|
+
appendStyleScopeAttribute(attrs, styleScopeId);
|
|
1143
|
+
const attrText = attrs.length > 0 ? ` ${attrs.join(" ")}` : "";
|
|
1144
|
+
return `<img${attrText}>`;
|
|
1145
|
+
}
|
|
1146
|
+
function parseImageFormats(value) {
|
|
1147
|
+
if (Array.isArray(value)) {
|
|
1148
|
+
return value
|
|
1149
|
+
.map((entry) => String(entry).trim().toLowerCase())
|
|
1150
|
+
.filter(Boolean);
|
|
1151
|
+
}
|
|
1152
|
+
if (typeof value !== "string") {
|
|
1153
|
+
return [];
|
|
1154
|
+
}
|
|
1155
|
+
return value
|
|
1156
|
+
.split(",")
|
|
1157
|
+
.map((entry) => entry.trim().toLowerCase())
|
|
1158
|
+
.filter(Boolean);
|
|
1159
|
+
}
|
|
1160
|
+
function parseImageNumberList(value) {
|
|
1161
|
+
const values = Array.isArray(value)
|
|
1162
|
+
? value
|
|
1163
|
+
: typeof value === "string"
|
|
1164
|
+
? value.split(",")
|
|
1165
|
+
: null;
|
|
1166
|
+
if (!values) {
|
|
1167
|
+
return undefined;
|
|
1168
|
+
}
|
|
1169
|
+
const numbers = values
|
|
1170
|
+
.map((entry) => Number(entry))
|
|
1171
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
1172
|
+
.map((entry) => Math.round(entry));
|
|
1173
|
+
return numbers.length ? numbers : undefined;
|
|
1174
|
+
}
|
|
1175
|
+
function readStringProp(value) {
|
|
1176
|
+
if (typeof value !== "string") {
|
|
1177
|
+
return undefined;
|
|
1178
|
+
}
|
|
1179
|
+
const trimmed = value.trim();
|
|
1180
|
+
return trimmed.length > 0 ? trimmed : undefined;
|
|
1181
|
+
}
|
|
1182
|
+
function readNumberProp(value) {
|
|
1183
|
+
const parsed = typeof value === "number"
|
|
1184
|
+
? value
|
|
1185
|
+
: typeof value === "string"
|
|
1186
|
+
? Number(value)
|
|
1187
|
+
: Number.NaN;
|
|
1188
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
1189
|
+
return undefined;
|
|
1190
|
+
}
|
|
1191
|
+
return Math.round(parsed);
|
|
1192
|
+
}
|
|
1193
|
+
function readBooleanProp(value, fallback) {
|
|
1194
|
+
if (typeof value === "boolean") {
|
|
1195
|
+
return value;
|
|
1196
|
+
}
|
|
1197
|
+
if (typeof value === "number") {
|
|
1198
|
+
return value !== 0;
|
|
1199
|
+
}
|
|
1200
|
+
if (typeof value === "string") {
|
|
1201
|
+
const normalized = value.trim().toLowerCase();
|
|
1202
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
1203
|
+
return true;
|
|
1204
|
+
}
|
|
1205
|
+
if (normalized === "false" || normalized === "0" || normalized === "no") {
|
|
1206
|
+
return false;
|
|
1207
|
+
}
|
|
1208
|
+
}
|
|
1209
|
+
return fallback;
|
|
1210
|
+
}
|
|
1211
|
+
function resuxImageMimeType(format) {
|
|
1212
|
+
const normalized = format.toLowerCase();
|
|
1213
|
+
if (normalized === "jpg") {
|
|
1214
|
+
return "image/jpeg";
|
|
1215
|
+
}
|
|
1216
|
+
return normalized.startsWith("image/") ? normalized : `image/${normalized}`;
|
|
1217
|
+
}
|
|
627
1218
|
function renderVueIsland(node, context, locals) {
|
|
628
1219
|
const name = resolveVueIslandName(node, context, locals);
|
|
629
1220
|
const props = resolveVueIslandProps(node, context, locals);
|
|
@@ -635,6 +1226,78 @@ function appendStyleScopeAttribute(attrs, styleScopeId) {
|
|
|
635
1226
|
attrs.push(`${styleScopeId}=""`);
|
|
636
1227
|
}
|
|
637
1228
|
}
|
|
1229
|
+
const loadingIndicatorDefaults = {
|
|
1230
|
+
color: "#2563eb",
|
|
1231
|
+
errorColor: "#dc2626",
|
|
1232
|
+
height: 3,
|
|
1233
|
+
duration: 2000,
|
|
1234
|
+
throttle: 200,
|
|
1235
|
+
};
|
|
1236
|
+
function renderResuxLoadingIndicatorSync(node, context, locals, slotHtml) {
|
|
1237
|
+
const options = resolveResuxLoadingIndicatorOptions(node, context, locals);
|
|
1238
|
+
return renderResuxLoadingIndicatorMarkup(options, slotHtml);
|
|
1239
|
+
}
|
|
1240
|
+
async function renderResuxLoadingIndicatorAsync(node, context, locals, slotHtml) {
|
|
1241
|
+
const options = resolveResuxLoadingIndicatorOptions(node, context, locals);
|
|
1242
|
+
return renderResuxLoadingIndicatorMarkup(options, await slotHtml);
|
|
1243
|
+
}
|
|
1244
|
+
function resolveResuxLoadingIndicatorOptions(node, context, locals) {
|
|
1245
|
+
const props = collectComponentProps(node, context.scope, locals);
|
|
1246
|
+
const color = normalizeLoadingColor(props.color, loadingIndicatorDefaults.color);
|
|
1247
|
+
const errorColor = normalizeLoadingColor(props.errorColor, loadingIndicatorDefaults.errorColor);
|
|
1248
|
+
return {
|
|
1249
|
+
color,
|
|
1250
|
+
errorColor,
|
|
1251
|
+
height: normalizeLoadingNumber(props.height, loadingIndicatorDefaults.height, 1),
|
|
1252
|
+
duration: normalizeLoadingNumber(props.duration, loadingIndicatorDefaults.duration, 1),
|
|
1253
|
+
throttle: normalizeLoadingNumber(props.throttle, loadingIndicatorDefaults.throttle, 0),
|
|
1254
|
+
estimatedProgress: typeof props.estimatedProgress === "function" ? "custom" : "default",
|
|
1255
|
+
};
|
|
1256
|
+
}
|
|
1257
|
+
function normalizeLoadingColor(value, fallback) {
|
|
1258
|
+
if (value === false) {
|
|
1259
|
+
return false;
|
|
1260
|
+
}
|
|
1261
|
+
if (typeof value === "string" && value.trim().length > 0) {
|
|
1262
|
+
return value.trim();
|
|
1263
|
+
}
|
|
1264
|
+
return fallback;
|
|
1265
|
+
}
|
|
1266
|
+
function normalizeLoadingNumber(value, fallback, min) {
|
|
1267
|
+
const numeric = typeof value === "number"
|
|
1268
|
+
? value
|
|
1269
|
+
: typeof value === "string"
|
|
1270
|
+
? Number(value)
|
|
1271
|
+
: Number.NaN;
|
|
1272
|
+
if (!Number.isFinite(numeric)) {
|
|
1273
|
+
return fallback;
|
|
1274
|
+
}
|
|
1275
|
+
return Math.max(min, Math.round(numeric));
|
|
1276
|
+
}
|
|
1277
|
+
function renderResuxLoadingIndicatorMarkup(options, slotHtml) {
|
|
1278
|
+
const styleParts = [`--resux-loader-height: ${options.height}px`];
|
|
1279
|
+
if (options.color !== false) {
|
|
1280
|
+
styleParts.push(`--resux-loader-color: ${options.color}`);
|
|
1281
|
+
}
|
|
1282
|
+
if (options.errorColor !== false) {
|
|
1283
|
+
styleParts.push(`--resux-loader-error-color: ${options.errorColor}`);
|
|
1284
|
+
}
|
|
1285
|
+
const attrs = [
|
|
1286
|
+
`data-rx-loading-indicator="true"`,
|
|
1287
|
+
"hidden",
|
|
1288
|
+
`data-state="idle"`,
|
|
1289
|
+
`aria-live="polite"`,
|
|
1290
|
+
`aria-busy="false"`,
|
|
1291
|
+
`data-duration="${options.duration}"`,
|
|
1292
|
+
`data-throttle="${options.throttle}"`,
|
|
1293
|
+
`data-estimated-progress="${options.estimatedProgress}"`,
|
|
1294
|
+
`style="${escapeAttribute(styleParts.join("; "))}"`,
|
|
1295
|
+
];
|
|
1296
|
+
const slot = slotHtml.trim().length > 0
|
|
1297
|
+
? `<div class="rx-loading-slot" data-rx-loading-slot>${slotHtml}</div>`
|
|
1298
|
+
: "";
|
|
1299
|
+
return `<div ${attrs.join(" ")}><div class="rx-loading-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-valuetext="Idle"><span class="rx-loading-progress"></span></div>${slot}</div>`;
|
|
1300
|
+
}
|
|
638
1301
|
function resolveVueIslandName(node, context, locals) {
|
|
639
1302
|
const dynamic = node.attrs.find((attr) => attr.kind === "dynamic" && attr.name === "name");
|
|
640
1303
|
if (dynamic) {
|
|
@@ -703,9 +1366,11 @@ export class AsyncResuxRenderer {
|
|
|
703
1366
|
moduleId: definition.id,
|
|
704
1367
|
styleScopeId: definition.styleScopeId,
|
|
705
1368
|
route: this.route,
|
|
1369
|
+
runtimeConfig: this.runtimeConfig,
|
|
706
1370
|
components: this.components,
|
|
707
1371
|
layouts: this.layouts,
|
|
708
1372
|
pageMeta: this.pageMeta,
|
|
1373
|
+
addHeadEntry: (entry) => this.headEntries.push(entry),
|
|
709
1374
|
renderPage,
|
|
710
1375
|
renderSlot,
|
|
711
1376
|
renderLayout: (name, slot) => this.renderLayout(name, slot)
|
|
@@ -1008,6 +1673,7 @@ function collectPatches(nodes, scope, scopeId, locals, patches, styleScopeId) {
|
|
|
1008
1673
|
moduleId: "",
|
|
1009
1674
|
styleScopeId,
|
|
1010
1675
|
route: { path: "", params: {}, query: {} },
|
|
1676
|
+
runtimeConfig: { public: {} },
|
|
1011
1677
|
components: {},
|
|
1012
1678
|
layouts: {},
|
|
1013
1679
|
pageMeta: {}
|
|
@@ -1025,6 +1691,7 @@ function collectPatches(nodes, scope, scopeId, locals, patches, styleScopeId) {
|
|
|
1025
1691
|
moduleId: "",
|
|
1026
1692
|
styleScopeId,
|
|
1027
1693
|
route: { path: "", params: {}, query: {} },
|
|
1694
|
+
runtimeConfig: { public: {} },
|
|
1028
1695
|
components: {},
|
|
1029
1696
|
layouts: {},
|
|
1030
1697
|
pageMeta: {}
|
|
@@ -1039,21 +1706,32 @@ function collectPatches(nodes, scope, scopeId, locals, patches, styleScopeId) {
|
|
|
1039
1706
|
value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals))
|
|
1040
1707
|
});
|
|
1041
1708
|
}
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1709
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
1710
|
+
for (const attr of node.attrs) {
|
|
1711
|
+
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
1712
|
+
patches.push({
|
|
1713
|
+
type: "attr",
|
|
1714
|
+
id: attr.bindingId,
|
|
1715
|
+
attr: nativeAttributeName(node, attr.name),
|
|
1716
|
+
value: stringifyAttributeValue(nativeAttributeName(node, attr.name), evaluateExpression(attr.value, scope, locals))
|
|
1717
|
+
});
|
|
1718
|
+
}
|
|
1050
1719
|
}
|
|
1051
1720
|
}
|
|
1052
1721
|
collectPatches(node.children, scope, scopeId, locals, patches, styleScopeId);
|
|
1053
1722
|
}
|
|
1054
1723
|
}
|
|
1055
1724
|
function nativeElementTag(node) {
|
|
1056
|
-
|
|
1725
|
+
if (node.tag === "ResuxLink") {
|
|
1726
|
+
return "a";
|
|
1727
|
+
}
|
|
1728
|
+
if (node.tag === "ResuxImg") {
|
|
1729
|
+
return "img";
|
|
1730
|
+
}
|
|
1731
|
+
if (node.tag === "ResuxPicture") {
|
|
1732
|
+
return "picture";
|
|
1733
|
+
}
|
|
1734
|
+
return node.tag;
|
|
1057
1735
|
}
|
|
1058
1736
|
function nativeAttributeName(node, name) {
|
|
1059
1737
|
return node.tag === "ResuxLink" && name === "to" ? "href" : name;
|
|
@@ -1080,9 +1758,16 @@ const pendingAsyncDataControllers = globalThis.__RESUX_PENDING_ASYNC_DATA_CONTRO
|
|
|
1080
1758
|
let devImportRevision = 0;
|
|
1081
1759
|
let routeTransitionToken = 0;
|
|
1082
1760
|
let routeTransitionHideTimer = 0;
|
|
1761
|
+
let routeTransitionShowTimer = 0;
|
|
1762
|
+
let routeTransitionProgressTimer = 0;
|
|
1763
|
+
let routeTransitionStartedAt = 0;
|
|
1764
|
+
let routeTransitionVisible = false;
|
|
1765
|
+
let routeTransitionIndicator = null;
|
|
1766
|
+
let lazyImageObserver = null;
|
|
1083
1767
|
const clientPluginIds = new Set();
|
|
1084
1768
|
const clientMiddlewareById = new Map();
|
|
1085
1769
|
const clientProvides = globalThis.__RESUX_PROVIDES__ ||= {};
|
|
1770
|
+
const RESUX_LAZY_PLACEHOLDER_SRC = "data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw==";
|
|
1086
1771
|
|
|
1087
1772
|
const __rxFlags = {
|
|
1088
1773
|
isReactive: "__v_isReactive",
|
|
@@ -1558,6 +2243,11 @@ export function useResuxApp() {
|
|
|
1558
2243
|
return getClientResuxApp();
|
|
1559
2244
|
}
|
|
1560
2245
|
|
|
2246
|
+
export function useResuxImage() {
|
|
2247
|
+
const app = getClientResuxApp();
|
|
2248
|
+
return createClientImageBuilder(app.route, app.$config);
|
|
2249
|
+
}
|
|
2250
|
+
|
|
1561
2251
|
function getClientResuxApp(routeOverride) {
|
|
1562
2252
|
const payload = globalThis.__RESUX__ ?? {
|
|
1563
2253
|
route: routeOverride ?? { path: "/", params: {}, query: {} },
|
|
@@ -1594,6 +2284,166 @@ function getClientResuxApp(routeOverride) {
|
|
|
1594
2284
|
return app;
|
|
1595
2285
|
}
|
|
1596
2286
|
|
|
2287
|
+
function createClientImageBuilder(route, runtimeConfig) {
|
|
2288
|
+
return (src, options = {}) => {
|
|
2289
|
+
const normalizedSrc = normalizeClientImageSource(src, route);
|
|
2290
|
+
const imageConfig = readClientImageConfig(runtimeConfig);
|
|
2291
|
+
const providerName = String(options.provider || imageConfig.provider || "resux").trim().toLowerCase();
|
|
2292
|
+
const providerConfig = imageConfig.providers[providerName] || {};
|
|
2293
|
+
const baseURL = providerConfig.baseURL || (providerName === "vercel" ? "/_vercel/image" : "/__resux/image");
|
|
2294
|
+
const modifiers = {
|
|
2295
|
+
...(providerConfig.modifiers || {}),
|
|
2296
|
+
...(Number.isFinite(imageConfig.quality) ? { quality: Math.round(imageConfig.quality) } : {}),
|
|
2297
|
+
...(typeof imageConfig.format === "string" ? { format: imageConfig.format } : {}),
|
|
2298
|
+
...(options.modifiers || {}),
|
|
2299
|
+
...(Number.isFinite(options.width) ? { width: Math.round(options.width) } : {}),
|
|
2300
|
+
...(Number.isFinite(options.height) ? { height: Math.round(options.height) } : {}),
|
|
2301
|
+
...(Number.isFinite(options.quality) ? { quality: Math.round(options.quality) } : {}),
|
|
2302
|
+
...(typeof options.fit === "string" ? { fit: options.fit } : {}),
|
|
2303
|
+
...(typeof options.format === "string" ? { format: options.format } : {})
|
|
2304
|
+
};
|
|
2305
|
+
const normalizedFormat = normalizeClientImageOutputFormat(
|
|
2306
|
+
typeof modifiers.format === "string" ? modifiers.format : undefined
|
|
2307
|
+
);
|
|
2308
|
+
|
|
2309
|
+
if (baseURL.includes("{src}")) {
|
|
2310
|
+
let resolved = baseURL.replaceAll("{src}", encodeURIComponent(normalizedSrc));
|
|
2311
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
2312
|
+
resolved = resolved.replaceAll("{" + key + "}", encodeURIComponent(String(value)));
|
|
2313
|
+
}
|
|
2314
|
+
return resolved;
|
|
2315
|
+
}
|
|
2316
|
+
|
|
2317
|
+
const query = new URLSearchParams();
|
|
2318
|
+
const sourceDescriptor = providerName === "vercel"
|
|
2319
|
+
? { publicSource: normalizedSrc }
|
|
2320
|
+
: rewriteClientImageSourceForDisplayFormat(normalizedSrc, normalizedFormat);
|
|
2321
|
+
|
|
2322
|
+
if (providerName === "vercel") {
|
|
2323
|
+
query.set("url", normalizedSrc);
|
|
2324
|
+
} else {
|
|
2325
|
+
query.set("src", sourceDescriptor.publicSource);
|
|
2326
|
+
if (sourceDescriptor.originalSource) {
|
|
2327
|
+
query.set("original", sourceDescriptor.originalSource);
|
|
2328
|
+
}
|
|
2329
|
+
}
|
|
2330
|
+
|
|
2331
|
+
const width = Number(modifiers.width);
|
|
2332
|
+
const height = Number(modifiers.height);
|
|
2333
|
+
const quality = Number(modifiers.quality);
|
|
2334
|
+
if (Number.isFinite(width) && width > 0) query.set("w", String(Math.round(width)));
|
|
2335
|
+
if (Number.isFinite(height) && height > 0) query.set("h", String(Math.round(height)));
|
|
2336
|
+
if (Number.isFinite(quality) && quality > 0) query.set("q", String(Math.round(quality)));
|
|
2337
|
+
if (typeof modifiers.fit === "string" && modifiers.fit) query.set("fit", modifiers.fit);
|
|
2338
|
+
if (normalizedFormat) {
|
|
2339
|
+
query.set("f", normalizedFormat);
|
|
2340
|
+
} else if (typeof modifiers.format === "string" && modifiers.format) {
|
|
2341
|
+
query.set("f", modifiers.format);
|
|
2342
|
+
}
|
|
2343
|
+
|
|
2344
|
+
for (const [key, value] of Object.entries(modifiers)) {
|
|
2345
|
+
if (["width", "height", "quality", "fit", "format"].includes(key)) continue;
|
|
2346
|
+
if (value === undefined || value === null || value === false) continue;
|
|
2347
|
+
query.set(key, String(value));
|
|
2348
|
+
}
|
|
2349
|
+
|
|
2350
|
+
const separator = baseURL.includes("?") ? "&" : "?";
|
|
2351
|
+
return query.toString() ? baseURL + separator + query.toString() : baseURL;
|
|
2352
|
+
};
|
|
2353
|
+
}
|
|
2354
|
+
|
|
2355
|
+
function normalizeClientImageOutputFormat(value) {
|
|
2356
|
+
if (typeof value !== "string") {
|
|
2357
|
+
return undefined;
|
|
2358
|
+
}
|
|
2359
|
+
const normalized = value.trim().toLowerCase();
|
|
2360
|
+
if (!normalized) {
|
|
2361
|
+
return undefined;
|
|
2362
|
+
}
|
|
2363
|
+
return normalized === "jpg" ? "jpeg" : normalized;
|
|
2364
|
+
}
|
|
2365
|
+
|
|
2366
|
+
function rewriteClientImageSourceForDisplayFormat(src, normalizedFormat) {
|
|
2367
|
+
if (!normalizedFormat) {
|
|
2368
|
+
return { publicSource: src };
|
|
2369
|
+
}
|
|
2370
|
+
|
|
2371
|
+
if (src.startsWith("data:") || src.startsWith("blob:")) {
|
|
2372
|
+
return { publicSource: src };
|
|
2373
|
+
}
|
|
2374
|
+
|
|
2375
|
+
if (src.startsWith("http://") || src.startsWith("https://")) {
|
|
2376
|
+
try {
|
|
2377
|
+
const sourceUrl = new URL(src);
|
|
2378
|
+
const rewrittenPathname = rewriteClientImagePathExtension(sourceUrl.pathname, normalizedFormat);
|
|
2379
|
+
if (rewrittenPathname === sourceUrl.pathname) {
|
|
2380
|
+
return { publicSource: src };
|
|
2381
|
+
}
|
|
2382
|
+
sourceUrl.pathname = rewrittenPathname;
|
|
2383
|
+
return { publicSource: sourceUrl.toString(), originalSource: src };
|
|
2384
|
+
} catch {
|
|
2385
|
+
return { publicSource: src };
|
|
2386
|
+
}
|
|
2387
|
+
}
|
|
2388
|
+
|
|
2389
|
+
const [pathPart, suffix = ""] = src.split(/(?=[?#])/);
|
|
2390
|
+
const rewrittenPath = rewriteClientImagePathExtension(pathPart, normalizedFormat);
|
|
2391
|
+
if (rewrittenPath === pathPart) {
|
|
2392
|
+
return { publicSource: src };
|
|
2393
|
+
}
|
|
2394
|
+
|
|
2395
|
+
return { publicSource: rewrittenPath + suffix, originalSource: src };
|
|
2396
|
+
}
|
|
2397
|
+
|
|
2398
|
+
function rewriteClientImagePathExtension(pathname, extension) {
|
|
2399
|
+
if (!pathname) {
|
|
2400
|
+
return pathname;
|
|
2401
|
+
}
|
|
2402
|
+
const normalizedExtension = extension.startsWith(".")
|
|
2403
|
+
? extension.slice(1)
|
|
2404
|
+
: extension;
|
|
2405
|
+
const lastSlash = pathname.lastIndexOf("/");
|
|
2406
|
+
const lastDot = pathname.lastIndexOf(".");
|
|
2407
|
+
if (lastDot > lastSlash) {
|
|
2408
|
+
return pathname.slice(0, lastDot + 1) + normalizedExtension;
|
|
2409
|
+
}
|
|
2410
|
+
return pathname + "." + normalizedExtension;
|
|
2411
|
+
}
|
|
2412
|
+
|
|
2413
|
+
function normalizeClientImageSource(src, route) {
|
|
2414
|
+
const value = String(src || "").trim();
|
|
2415
|
+
if (!value) return "";
|
|
2416
|
+
if (value.startsWith("http://") || value.startsWith("https://") || value.startsWith("data:") || value.startsWith("blob:") || value.startsWith("file:")) {
|
|
2417
|
+
return value;
|
|
2418
|
+
}
|
|
2419
|
+
if (value.startsWith("/")) return value;
|
|
2420
|
+
const basePath = route && typeof route.path === "string" && route.path.startsWith("/") ? route.path : "/";
|
|
2421
|
+
const directory = basePath.endsWith("/") ? basePath : basePath.slice(0, Math.max(basePath.lastIndexOf("/") + 1, 1));
|
|
2422
|
+
const resolved = new URL(value, "https://resux.local" + directory);
|
|
2423
|
+
return resolved.pathname + resolved.search + resolved.hash;
|
|
2424
|
+
}
|
|
2425
|
+
|
|
2426
|
+
function readClientImageConfig(runtimeConfig) {
|
|
2427
|
+
const config = runtimeConfig && runtimeConfig.public ? runtimeConfig.public : {};
|
|
2428
|
+
const image = config.image || config.resuxImage || {};
|
|
2429
|
+
if (!image || typeof image !== "object" || Array.isArray(image)) {
|
|
2430
|
+
return { providers: {} };
|
|
2431
|
+
}
|
|
2432
|
+
const providers = image.providers && typeof image.providers === "object" && !Array.isArray(image.providers)
|
|
2433
|
+
? image.providers
|
|
2434
|
+
: {};
|
|
2435
|
+
const densities = Array.isArray(image.densities)
|
|
2436
|
+
? image.densities.map((entry) => Number(entry)).filter((entry) => Number.isFinite(entry) && entry > 0).map((entry) => Math.round(entry))
|
|
2437
|
+
: undefined;
|
|
2438
|
+
return {
|
|
2439
|
+
provider: typeof image.provider === "string" ? image.provider : undefined,
|
|
2440
|
+
quality: Number.isFinite(image.quality) ? Math.round(image.quality) : undefined,
|
|
2441
|
+
format: typeof image.format === "string" ? image.format : undefined,
|
|
2442
|
+
densities: densities && densities.length ? densities : undefined,
|
|
2443
|
+
providers
|
|
2444
|
+
};
|
|
2445
|
+
}
|
|
2446
|
+
|
|
1597
2447
|
async function ensureClientPlugins(payload) {
|
|
1598
2448
|
if (!payload || !Array.isArray(payload.plugins)) {
|
|
1599
2449
|
return;
|
|
@@ -1789,6 +2639,9 @@ export function createClientComponent(definition) {
|
|
|
1789
2639
|
useResuxApp() {
|
|
1790
2640
|
return getClientResuxApp(route);
|
|
1791
2641
|
},
|
|
2642
|
+
useResuxImage() {
|
|
2643
|
+
return createClientImageBuilder(route, getClientResuxApp(route).$config);
|
|
2644
|
+
},
|
|
1792
2645
|
apiURL(url) {
|
|
1793
2646
|
return url;
|
|
1794
2647
|
},
|
|
@@ -1888,38 +2741,120 @@ async function initializeClientRuntime() {
|
|
|
1888
2741
|
}
|
|
1889
2742
|
void resumePendingAsyncData();
|
|
1890
2743
|
void mountVueIslands();
|
|
2744
|
+
activateDeferredLazyImages();
|
|
1891
2745
|
}
|
|
1892
|
-
|
|
1893
|
-
function
|
|
1894
|
-
const
|
|
1895
|
-
|
|
1896
|
-
|
|
1897
|
-
|
|
1898
|
-
|
|
1899
|
-
|
|
1900
|
-
|
|
1901
|
-
|
|
1902
|
-
|
|
1903
|
-
|
|
1904
|
-
|
|
1905
|
-
|
|
1906
|
-
|
|
1907
|
-
|
|
1908
|
-
|
|
1909
|
-
|
|
1910
|
-
|
|
1911
|
-
|
|
1912
|
-
|
|
1913
|
-
|
|
1914
|
-
|
|
1915
|
-
}
|
|
1916
|
-
|
|
1917
|
-
|
|
1918
|
-
}
|
|
1919
|
-
|
|
1920
|
-
|
|
1921
|
-
|
|
1922
|
-
|
|
2746
|
+
|
|
2747
|
+
function activateDeferredLazyImages(root = document) {
|
|
2748
|
+
const images = root.querySelectorAll ? root.querySelectorAll("img[data-rx-lazy-image='true']") : [];
|
|
2749
|
+
if (!images.length) {
|
|
2750
|
+
return;
|
|
2751
|
+
}
|
|
2752
|
+
|
|
2753
|
+
const observer = getLazyImageObserver();
|
|
2754
|
+
for (const image of images) {
|
|
2755
|
+
if (image.getAttribute("data-rx-lazy-ready") === "true") {
|
|
2756
|
+
continue;
|
|
2757
|
+
}
|
|
2758
|
+
if (!observer) {
|
|
2759
|
+
revealDeferredLazyImage(image);
|
|
2760
|
+
continue;
|
|
2761
|
+
}
|
|
2762
|
+
observer.observe(image);
|
|
2763
|
+
}
|
|
2764
|
+
}
|
|
2765
|
+
|
|
2766
|
+
function getLazyImageObserver() {
|
|
2767
|
+
if (lazyImageObserver) {
|
|
2768
|
+
return lazyImageObserver;
|
|
2769
|
+
}
|
|
2770
|
+
if (typeof IntersectionObserver !== "function") {
|
|
2771
|
+
return null;
|
|
2772
|
+
}
|
|
2773
|
+
lazyImageObserver = new IntersectionObserver((entries) => {
|
|
2774
|
+
for (const entry of entries) {
|
|
2775
|
+
if (!entry.isIntersecting && entry.intersectionRatio <= 0) {
|
|
2776
|
+
continue;
|
|
2777
|
+
}
|
|
2778
|
+
const target = entry.target;
|
|
2779
|
+
lazyImageObserver?.unobserve(target);
|
|
2780
|
+
revealDeferredLazyImage(target);
|
|
2781
|
+
}
|
|
2782
|
+
}, { rootMargin: "320px 0px" });
|
|
2783
|
+
return lazyImageObserver;
|
|
2784
|
+
}
|
|
2785
|
+
|
|
2786
|
+
function revealDeferredLazyImage(image) {
|
|
2787
|
+
if (!image || image.getAttribute("data-rx-lazy-ready") === "true") {
|
|
2788
|
+
return;
|
|
2789
|
+
}
|
|
2790
|
+
|
|
2791
|
+
const picture = image.closest ? image.closest("picture") : null;
|
|
2792
|
+
if (picture && picture.querySelectorAll) {
|
|
2793
|
+
picture.querySelectorAll("source[data-rx-lazy-srcset]").forEach((source) => {
|
|
2794
|
+
const nextSrcset = source.getAttribute("data-rx-lazy-srcset");
|
|
2795
|
+
if (nextSrcset) {
|
|
2796
|
+
source.setAttribute("srcset", nextSrcset);
|
|
2797
|
+
}
|
|
2798
|
+
source.removeAttribute("data-rx-lazy-srcset");
|
|
2799
|
+
const nextSizes = source.getAttribute("data-rx-lazy-sizes");
|
|
2800
|
+
if (nextSizes) {
|
|
2801
|
+
source.setAttribute("sizes", nextSizes);
|
|
2802
|
+
}
|
|
2803
|
+
source.removeAttribute("data-rx-lazy-sizes");
|
|
2804
|
+
});
|
|
2805
|
+
}
|
|
2806
|
+
|
|
2807
|
+
const srcset = image.getAttribute("data-rx-lazy-srcset");
|
|
2808
|
+
if (srcset) {
|
|
2809
|
+
image.setAttribute("srcset", srcset);
|
|
2810
|
+
}
|
|
2811
|
+
image.removeAttribute("data-rx-lazy-srcset");
|
|
2812
|
+
const sizes = image.getAttribute("data-rx-lazy-sizes");
|
|
2813
|
+
if (sizes) {
|
|
2814
|
+
image.setAttribute("sizes", sizes);
|
|
2815
|
+
}
|
|
2816
|
+
image.removeAttribute("data-rx-lazy-sizes");
|
|
2817
|
+
|
|
2818
|
+
const src = image.getAttribute("data-rx-lazy-src");
|
|
2819
|
+
if (src) {
|
|
2820
|
+
image.setAttribute("src", src);
|
|
2821
|
+
} else if (image.getAttribute("src") === RESUX_LAZY_PLACEHOLDER_SRC) {
|
|
2822
|
+
image.removeAttribute("src");
|
|
2823
|
+
}
|
|
2824
|
+
image.removeAttribute("data-rx-lazy-src");
|
|
2825
|
+
image.setAttribute("data-rx-lazy-ready", "true");
|
|
2826
|
+
}
|
|
2827
|
+
|
|
2828
|
+
function createAsyncDataResource(value, pending = false, error = null) {
|
|
2829
|
+
const data = ref(value);
|
|
2830
|
+
let completion = Promise.resolve();
|
|
2831
|
+
const resource = {
|
|
2832
|
+
data,
|
|
2833
|
+
value: data,
|
|
2834
|
+
pending: ref(pending),
|
|
2835
|
+
error: ref(error),
|
|
2836
|
+
then(onfulfilled, onrejected) {
|
|
2837
|
+
return completion.then(() => {
|
|
2838
|
+
const resolved = {
|
|
2839
|
+
data: resource.data,
|
|
2840
|
+
value: resource.value,
|
|
2841
|
+
pending: resource.pending,
|
|
2842
|
+
error: resource.error
|
|
2843
|
+
};
|
|
2844
|
+
return onfulfilled ? onfulfilled(resolved) : resolved;
|
|
2845
|
+
}, onrejected);
|
|
2846
|
+
},
|
|
2847
|
+
setCompletion(nextCompletion) {
|
|
2848
|
+
completion = nextCompletion;
|
|
2849
|
+
}
|
|
2850
|
+
};
|
|
2851
|
+
|
|
2852
|
+
return resource;
|
|
2853
|
+
}
|
|
2854
|
+
|
|
2855
|
+
async function settleAsyncDataResource(resource, handler, key, signal) {
|
|
2856
|
+
try {
|
|
2857
|
+
const value = await handler({ signal });
|
|
1923
2858
|
assertJsonSerializable(value, 'useAsyncData("' + key + '")');
|
|
1924
2859
|
resource.data.value = value;
|
|
1925
2860
|
resource.error.value = null;
|
|
@@ -1943,83 +2878,233 @@ function serializeAsyncData(refs) {
|
|
|
1943
2878
|
return output;
|
|
1944
2879
|
}
|
|
1945
2880
|
|
|
1946
|
-
function setRouteLoading(active) {
|
|
1947
|
-
setRouteTransition(active ? "fetching" : "idle");
|
|
1948
|
-
}
|
|
1949
|
-
|
|
1950
|
-
function setRouteTransition(state, options = {}) {
|
|
1951
|
-
const loader =
|
|
1952
|
-
const root = document.getElementById("__resux");
|
|
1953
|
-
if (!loader) {
|
|
1954
|
-
return;
|
|
1955
|
-
}
|
|
1956
|
-
|
|
1957
|
-
if (
|
|
1958
|
-
|
|
1959
|
-
|
|
1960
|
-
|
|
1961
|
-
|
|
1962
|
-
|
|
1963
|
-
|
|
1964
|
-
|
|
1965
|
-
|
|
1966
|
-
|
|
1967
|
-
|
|
1968
|
-
|
|
1969
|
-
|
|
1970
|
-
|
|
1971
|
-
|
|
1972
|
-
|
|
1973
|
-
|
|
1974
|
-
|
|
1975
|
-
|
|
1976
|
-
|
|
1977
|
-
|
|
1978
|
-
|
|
1979
|
-
|
|
1980
|
-
|
|
1981
|
-
|
|
1982
|
-
root.removeAttribute("
|
|
1983
|
-
root.removeAttribute("data-route-transition");
|
|
2881
|
+
function setRouteLoading(active) {
|
|
2882
|
+
setRouteTransition(active ? "fetching" : "idle");
|
|
2883
|
+
}
|
|
2884
|
+
|
|
2885
|
+
function setRouteTransition(state, options = {}) {
|
|
2886
|
+
const loader = getRouteTransitionIndicator();
|
|
2887
|
+
const root = document.getElementById("__resux");
|
|
2888
|
+
if (!loader) {
|
|
2889
|
+
return;
|
|
2890
|
+
}
|
|
2891
|
+
|
|
2892
|
+
if (state === "start") {
|
|
2893
|
+
routeTransitionStartedAt = Date.now();
|
|
2894
|
+
}
|
|
2895
|
+
|
|
2896
|
+
const config = readRouteTransitionConfig(loader);
|
|
2897
|
+
if (routeTransitionHideTimer) {
|
|
2898
|
+
clearTimeout(routeTransitionHideTimer);
|
|
2899
|
+
routeTransitionHideTimer = 0;
|
|
2900
|
+
}
|
|
2901
|
+
|
|
2902
|
+
const progress = transitionProgress(state, options.progress, config.duration);
|
|
2903
|
+
const message = options.message ?? transitionMessage(state);
|
|
2904
|
+
updateRouteTransitionUi(loader, state, progress, message);
|
|
2905
|
+
|
|
2906
|
+
const activeState = state === "start" || state === "fetching" || state === "swapping";
|
|
2907
|
+
if (activeState) {
|
|
2908
|
+
showRouteTransition(loader, config.throttle, false);
|
|
2909
|
+
startRouteTransitionProgressTimer(loader, config.duration);
|
|
2910
|
+
} else {
|
|
2911
|
+
stopRouteTransitionProgressTimer();
|
|
2912
|
+
}
|
|
2913
|
+
|
|
2914
|
+
if (root) {
|
|
2915
|
+
if (state === "idle" || state === "complete" || state === "error") {
|
|
2916
|
+
root.removeAttribute("aria-busy");
|
|
2917
|
+
root.removeAttribute("data-route-transition");
|
|
1984
2918
|
} else {
|
|
1985
2919
|
root.setAttribute("aria-busy", "true");
|
|
1986
2920
|
root.setAttribute("data-route-transition", "loading");
|
|
1987
2921
|
}
|
|
1988
2922
|
}
|
|
1989
|
-
|
|
1990
|
-
dispatchRouteTransition(state, options);
|
|
1991
|
-
|
|
1992
|
-
if (state === "idle" || state === "complete") {
|
|
1993
|
-
|
|
1994
|
-
|
|
1995
|
-
loader
|
|
1996
|
-
|
|
1997
|
-
|
|
1998
|
-
|
|
1999
|
-
|
|
2000
|
-
|
|
2001
|
-
|
|
2002
|
-
|
|
2003
|
-
|
|
2004
|
-
|
|
2005
|
-
|
|
2006
|
-
|
|
2007
|
-
|
|
2008
|
-
|
|
2009
|
-
|
|
2010
|
-
|
|
2011
|
-
|
|
2012
|
-
return
|
|
2013
|
-
}
|
|
2014
|
-
|
|
2015
|
-
function
|
|
2016
|
-
if (
|
|
2017
|
-
|
|
2018
|
-
|
|
2019
|
-
|
|
2020
|
-
|
|
2021
|
-
|
|
2022
|
-
|
|
2923
|
+
|
|
2924
|
+
dispatchRouteTransition(state, options);
|
|
2925
|
+
|
|
2926
|
+
if (state === "idle" || state === "complete" || state === "error") {
|
|
2927
|
+
const hideDelay = state === "complete" ? 160 : state === "error" ? 640 : 0;
|
|
2928
|
+
routeTransitionHideTimer = setTimeout(() => {
|
|
2929
|
+
hideRouteTransition(loader);
|
|
2930
|
+
}, hideDelay);
|
|
2931
|
+
}
|
|
2932
|
+
}
|
|
2933
|
+
|
|
2934
|
+
function getRouteTransitionIndicator() {
|
|
2935
|
+
if (routeTransitionIndicator && routeTransitionIndicator.isConnected) {
|
|
2936
|
+
return routeTransitionIndicator;
|
|
2937
|
+
}
|
|
2938
|
+
|
|
2939
|
+
routeTransitionIndicator = document.querySelector("[data-rx-loading-indicator]");
|
|
2940
|
+
if (routeTransitionIndicator) {
|
|
2941
|
+
return routeTransitionIndicator;
|
|
2942
|
+
}
|
|
2943
|
+
|
|
2944
|
+
const fallback = createFallbackRouteTransitionIndicator();
|
|
2945
|
+
routeTransitionIndicator = fallback;
|
|
2946
|
+
return fallback;
|
|
2947
|
+
}
|
|
2948
|
+
|
|
2949
|
+
function createFallbackRouteTransitionIndicator() {
|
|
2950
|
+
if (!document.body) {
|
|
2951
|
+
return null;
|
|
2952
|
+
}
|
|
2953
|
+
|
|
2954
|
+
const fallback = document.createElement("div");
|
|
2955
|
+
fallback.setAttribute("data-rx-loading-indicator", "true");
|
|
2956
|
+
fallback.setAttribute("hidden", "");
|
|
2957
|
+
fallback.setAttribute("data-state", "idle");
|
|
2958
|
+
fallback.setAttribute("aria-live", "polite");
|
|
2959
|
+
fallback.setAttribute("aria-busy", "false");
|
|
2960
|
+
fallback.setAttribute("data-duration", "2000");
|
|
2961
|
+
fallback.setAttribute("data-throttle", "200");
|
|
2962
|
+
fallback.setAttribute("style", "--resux-loader-height: 3px; --resux-loader-color: #2563eb; --resux-loader-error-color: #dc2626;");
|
|
2963
|
+
fallback.innerHTML = '<div class="rx-loading-bar" role="progressbar" aria-valuemin="0" aria-valuemax="100" aria-valuenow="0" aria-valuetext="Idle"><span class="rx-loading-progress"></span></div>';
|
|
2964
|
+
document.body.appendChild(fallback);
|
|
2965
|
+
return fallback;
|
|
2966
|
+
}
|
|
2967
|
+
|
|
2968
|
+
function readRouteTransitionConfig(loader) {
|
|
2969
|
+
return {
|
|
2970
|
+
duration: readPositiveInt(loader?.dataset?.duration, 2000, 1),
|
|
2971
|
+
throttle: readPositiveInt(loader?.dataset?.throttle, 200, 0)
|
|
2972
|
+
};
|
|
2973
|
+
}
|
|
2974
|
+
|
|
2975
|
+
function readPositiveInt(value, fallback, min) {
|
|
2976
|
+
const parsed = Number.parseInt(String(value ?? ""), 10);
|
|
2977
|
+
if (!Number.isFinite(parsed)) {
|
|
2978
|
+
return fallback;
|
|
2979
|
+
}
|
|
2980
|
+
return Math.max(min, parsed);
|
|
2981
|
+
}
|
|
2982
|
+
|
|
2983
|
+
function showRouteTransition(loader, throttle, force) {
|
|
2984
|
+
if (!loader) {
|
|
2985
|
+
return;
|
|
2986
|
+
}
|
|
2987
|
+
if (routeTransitionShowTimer && !force) {
|
|
2988
|
+
return;
|
|
2989
|
+
}
|
|
2990
|
+
if (routeTransitionShowTimer) {
|
|
2991
|
+
clearTimeout(routeTransitionShowTimer);
|
|
2992
|
+
routeTransitionShowTimer = 0;
|
|
2993
|
+
}
|
|
2994
|
+
|
|
2995
|
+
if (force || throttle <= 0 || routeTransitionVisible) {
|
|
2996
|
+
loader.hidden = false;
|
|
2997
|
+
routeTransitionVisible = true;
|
|
2998
|
+
return;
|
|
2999
|
+
}
|
|
3000
|
+
|
|
3001
|
+
routeTransitionShowTimer = setTimeout(() => {
|
|
3002
|
+
loader.hidden = false;
|
|
3003
|
+
routeTransitionVisible = true;
|
|
3004
|
+
routeTransitionShowTimer = 0;
|
|
3005
|
+
}, throttle);
|
|
3006
|
+
}
|
|
3007
|
+
|
|
3008
|
+
function hideRouteTransition(loader) {
|
|
3009
|
+
if (!loader) {
|
|
3010
|
+
return;
|
|
3011
|
+
}
|
|
3012
|
+
stopRouteTransitionProgressTimer();
|
|
3013
|
+
if (routeTransitionShowTimer) {
|
|
3014
|
+
clearTimeout(routeTransitionShowTimer);
|
|
3015
|
+
routeTransitionShowTimer = 0;
|
|
3016
|
+
}
|
|
3017
|
+
loader.hidden = true;
|
|
3018
|
+
routeTransitionVisible = false;
|
|
3019
|
+
updateRouteTransitionUi(loader, "idle", 0, "Idle");
|
|
3020
|
+
}
|
|
3021
|
+
|
|
3022
|
+
function startRouteTransitionProgressTimer(loader, duration) {
|
|
3023
|
+
if (routeTransitionProgressTimer) {
|
|
3024
|
+
clearInterval(routeTransitionProgressTimer);
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
routeTransitionProgressTimer = setInterval(() => {
|
|
3028
|
+
if (!loader || loader.hidden) {
|
|
3029
|
+
return;
|
|
3030
|
+
}
|
|
3031
|
+
const state = loader.dataset?.state ?? "idle";
|
|
3032
|
+
if (state === "idle" || state === "complete" || state === "error") {
|
|
3033
|
+
return;
|
|
3034
|
+
}
|
|
3035
|
+
updateRouteTransitionUi(
|
|
3036
|
+
loader,
|
|
3037
|
+
state,
|
|
3038
|
+
transitionProgress(state, undefined, duration),
|
|
3039
|
+
transitionMessage(state),
|
|
3040
|
+
);
|
|
3041
|
+
}, 120);
|
|
3042
|
+
}
|
|
3043
|
+
|
|
3044
|
+
function stopRouteTransitionProgressTimer() {
|
|
3045
|
+
if (!routeTransitionProgressTimer) {
|
|
3046
|
+
return;
|
|
3047
|
+
}
|
|
3048
|
+
clearInterval(routeTransitionProgressTimer);
|
|
3049
|
+
routeTransitionProgressTimer = 0;
|
|
3050
|
+
}
|
|
3051
|
+
|
|
3052
|
+
function updateRouteTransitionUi(loader, state, progress, message) {
|
|
3053
|
+
if (!loader) {
|
|
3054
|
+
return;
|
|
3055
|
+
}
|
|
3056
|
+
|
|
3057
|
+
loader.dataset.state = state;
|
|
3058
|
+
loader.style.setProperty("--resux-progress", progress + "%");
|
|
3059
|
+
loader.setAttribute("aria-busy", state === "idle" || state === "complete" || state === "error" ? "false" : "true");
|
|
3060
|
+
|
|
3061
|
+
const progressbar = loader.querySelector("[role='progressbar']");
|
|
3062
|
+
if (progressbar) {
|
|
3063
|
+
progressbar.setAttribute("aria-valuenow", String(progress));
|
|
3064
|
+
progressbar.setAttribute("aria-valuetext", message);
|
|
3065
|
+
}
|
|
3066
|
+
}
|
|
3067
|
+
|
|
3068
|
+
function transitionProgress(state, explicitProgress, duration = 2000) {
|
|
3069
|
+
if (typeof explicitProgress === "number") {
|
|
3070
|
+
return clampProgress(explicitProgress);
|
|
3071
|
+
}
|
|
3072
|
+
|
|
3073
|
+
if (state === "idle") {
|
|
3074
|
+
return 0;
|
|
3075
|
+
}
|
|
3076
|
+
if (state === "complete" || state === "error") {
|
|
3077
|
+
return 100;
|
|
3078
|
+
}
|
|
3079
|
+
|
|
3080
|
+
const elapsed = Math.max(0, Date.now() - routeTransitionStartedAt);
|
|
3081
|
+
const estimated = defaultEstimatedProgress(duration, elapsed);
|
|
3082
|
+
if (state === "start") {
|
|
3083
|
+
return Math.max(8, Math.min(32, estimated));
|
|
3084
|
+
}
|
|
3085
|
+
if (state === "fetching") {
|
|
3086
|
+
return Math.max(18, Math.min(88, estimated));
|
|
3087
|
+
}
|
|
3088
|
+
return Math.max(72, Math.min(97, estimated));
|
|
3089
|
+
}
|
|
3090
|
+
|
|
3091
|
+
function defaultEstimatedProgress(duration, elapsed) {
|
|
3092
|
+
const safeDuration = Math.max(1, duration);
|
|
3093
|
+
const scaled = (elapsed / safeDuration) * 2;
|
|
3094
|
+
const estimated = (2 / Math.PI * 100) * Math.atan(scaled);
|
|
3095
|
+
return clampProgress(estimated);
|
|
3096
|
+
}
|
|
3097
|
+
|
|
3098
|
+
function clampProgress(value) {
|
|
3099
|
+
return Math.max(0, Math.min(100, Math.round(value)));
|
|
3100
|
+
}
|
|
3101
|
+
|
|
3102
|
+
function transitionMessage(state) {
|
|
3103
|
+
if (state === "start" || state === "fetching" || state === "swapping") return "Loading";
|
|
3104
|
+
if (state === "complete") return "Done";
|
|
3105
|
+
if (state === "error") return "Failed";
|
|
3106
|
+
return "Ready";
|
|
3107
|
+
}
|
|
2023
3108
|
|
|
2024
3109
|
function dispatchRouteTransition(state, detail = {}) {
|
|
2025
3110
|
if (typeof window === "undefined" || typeof window.CustomEvent !== "function") {
|
|
@@ -2066,28 +3151,40 @@ function handleNavigationClick(event) {
|
|
|
2066
3151
|
return false;
|
|
2067
3152
|
}
|
|
2068
3153
|
|
|
2069
|
-
const nextPath = target.pathname + target.search;
|
|
2070
|
-
const currentPath = location.pathname + location.search;
|
|
2071
|
-
if (nextPath === currentPath
|
|
2072
|
-
|
|
2073
|
-
|
|
2074
|
-
|
|
2075
|
-
|
|
2076
|
-
|
|
2077
|
-
|
|
2078
|
-
|
|
2079
|
-
|
|
3154
|
+
const nextPath = target.pathname + target.search;
|
|
3155
|
+
const currentPath = location.pathname + location.search;
|
|
3156
|
+
if (nextPath === currentPath) {
|
|
3157
|
+
if (!target.hash || target.hash === location.hash) {
|
|
3158
|
+
event.preventDefault();
|
|
3159
|
+
return true;
|
|
3160
|
+
}
|
|
3161
|
+
return false;
|
|
3162
|
+
}
|
|
3163
|
+
|
|
3164
|
+
event.preventDefault();
|
|
3165
|
+
void navigateTo(nextPath + target.hash);
|
|
3166
|
+
return true;
|
|
3167
|
+
}
|
|
3168
|
+
|
|
2080
3169
|
async function navigateTo(target, options = {}) {
|
|
2081
3170
|
const nextUrl = new URL(target, location.href);
|
|
2082
3171
|
const routePath = nextUrl.pathname + nextUrl.search;
|
|
3172
|
+
const currentUrl = new URL(location.href);
|
|
3173
|
+
const currentRoutePath = currentUrl.pathname + currentUrl.search;
|
|
3174
|
+
if (routePath === currentRoutePath && nextUrl.hash === currentUrl.hash) {
|
|
3175
|
+
return;
|
|
3176
|
+
}
|
|
2083
3177
|
const transitionToken = ++routeTransitionToken;
|
|
2084
3178
|
let completed = false;
|
|
2085
3179
|
abortPendingAsyncData();
|
|
2086
3180
|
setRouteTransition("start", { path: routePath });
|
|
2087
|
-
|
|
3181
|
+
|
|
2088
3182
|
try {
|
|
2089
3183
|
setRouteTransition("fetching", { path: routePath });
|
|
2090
3184
|
const result = await fetchRoutePayload(routePath);
|
|
3185
|
+
if (transitionToken !== routeTransitionToken) {
|
|
3186
|
+
return;
|
|
3187
|
+
}
|
|
2091
3188
|
if (result.redirect) {
|
|
2092
3189
|
await navigateTo(result.redirect, { replace: true });
|
|
2093
3190
|
return;
|
|
@@ -2097,11 +3194,17 @@ async function navigateTo(target, options = {}) {
|
|
|
2097
3194
|
throw new Error("Route payload response is missing payload data.");
|
|
2098
3195
|
}
|
|
2099
3196
|
await ensureClientPlugins(nextPayload);
|
|
3197
|
+
if (transitionToken !== routeTransitionToken) {
|
|
3198
|
+
return;
|
|
3199
|
+
}
|
|
2100
3200
|
const previousPayload = globalThis.__RESUX__;
|
|
2101
3201
|
const middlewareResult = await runClientRouteMiddleware(
|
|
2102
3202
|
nextPayload,
|
|
2103
3203
|
previousPayload?.route ?? { path: "", params: {}, query: {} }
|
|
2104
3204
|
);
|
|
3205
|
+
if (transitionToken !== routeTransitionToken) {
|
|
3206
|
+
return;
|
|
3207
|
+
}
|
|
2105
3208
|
if (middlewareResult?.type === "redirect") {
|
|
2106
3209
|
await navigateTo(middlewareResult.to, { replace: true });
|
|
2107
3210
|
return;
|
|
@@ -2114,8 +3217,12 @@ async function navigateTo(target, options = {}) {
|
|
|
2114
3217
|
if (!root) {
|
|
2115
3218
|
location.href = nextUrl.href;
|
|
2116
3219
|
return;
|
|
2117
|
-
}
|
|
2118
|
-
|
|
3220
|
+
}
|
|
3221
|
+
|
|
3222
|
+
if (transitionToken !== routeTransitionToken) {
|
|
3223
|
+
return;
|
|
3224
|
+
}
|
|
3225
|
+
|
|
2119
3226
|
if (options.replace) {
|
|
2120
3227
|
history.replaceState({ __resux: true, path: routePath }, "", nextUrl.href);
|
|
2121
3228
|
} else {
|
|
@@ -2130,6 +3237,7 @@ async function navigateTo(target, options = {}) {
|
|
|
2130
3237
|
clearScopeCacheExcept(preserved.scopeIds);
|
|
2131
3238
|
void resumePendingAsyncData();
|
|
2132
3239
|
void mountVueIslands(preserved.root);
|
|
3240
|
+
activateDeferredLazyImages(preserved.root);
|
|
2133
3241
|
|
|
2134
3242
|
if (nextUrl.hash) {
|
|
2135
3243
|
document.getElementById(nextUrl.hash.slice(1))?.scrollIntoView();
|
|
@@ -2645,12 +3753,14 @@ function collectPatches(nodes, scope, locals, patches, styleScopeId) {
|
|
|
2645
3753
|
if (node.html) {
|
|
2646
3754
|
patches.push({ type: "html", id: node.html.bindingId, value: sanitizeHtml(evaluateExpression(node.html.expression, scope, locals)) });
|
|
2647
3755
|
}
|
|
2648
|
-
|
|
2649
|
-
|
|
2650
|
-
|
|
2651
|
-
|
|
2652
|
-
|
|
2653
|
-
|
|
3756
|
+
if (node.tag !== "ResuxImg" && node.tag !== "ResuxPicture") {
|
|
3757
|
+
for (const attr of node.attrs) {
|
|
3758
|
+
if (attr.kind === "dynamic" && attr.bindingId) {
|
|
3759
|
+
const attrName = nativeAttributeName(node, attr.name);
|
|
3760
|
+
patches.push({ type: "attr", id: attr.bindingId, attr: attrName, value: stringifyAttributeValue(attrName, evaluateExpression(attr.value, scope, locals)) });
|
|
3761
|
+
}
|
|
3762
|
+
}
|
|
3763
|
+
}
|
|
2654
3764
|
collectPatches(node.children, scope, locals, patches, styleScopeId);
|
|
2655
3765
|
}
|
|
2656
3766
|
}
|
|
@@ -2683,9 +3793,15 @@ function renderNode(node, scope, locals, styleScopeId) {
|
|
|
2683
3793
|
}
|
|
2684
3794
|
|
|
2685
3795
|
function renderElement(node, scope, locals, styleScopeId) {
|
|
3796
|
+
if (node.tag === "ResuxImg") {
|
|
3797
|
+
return renderClientResuxImg(node, scope, locals, styleScopeId);
|
|
3798
|
+
}
|
|
3799
|
+
if (node.tag === "ResuxPicture") {
|
|
3800
|
+
return renderClientResuxPicture(node, scope, locals, styleScopeId);
|
|
3801
|
+
}
|
|
2686
3802
|
const tag = nativeElementTag(node);
|
|
2687
3803
|
const attrs = [];
|
|
2688
|
-
for (const attr of node.attrs) {
|
|
3804
|
+
for (const attr of node.attrs) {
|
|
2689
3805
|
const attrName = nativeAttributeName(node, attr.name);
|
|
2690
3806
|
if (attr.kind === "static") {
|
|
2691
3807
|
attrs.push(attrName + '="' + escapeAttribute(attr.value) + '"');
|
|
@@ -2715,21 +3831,376 @@ function renderElement(node, scope, locals, styleScopeId) {
|
|
|
2715
3831
|
: node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
2716
3832
|
return "<" + tag + attrText + ">" + children + "</" + tag + ">";
|
|
2717
3833
|
}
|
|
2718
|
-
|
|
2719
|
-
|
|
2720
|
-
|
|
2721
|
-
|
|
3834
|
+
|
|
3835
|
+
const clientImageReservedProps = new Set([
|
|
3836
|
+
"src",
|
|
3837
|
+
"alt",
|
|
3838
|
+
"provider",
|
|
3839
|
+
"modifiers",
|
|
3840
|
+
"quality",
|
|
3841
|
+
"fit",
|
|
3842
|
+
"format",
|
|
3843
|
+
"formats",
|
|
3844
|
+
"width",
|
|
3845
|
+
"height",
|
|
3846
|
+
"widths",
|
|
3847
|
+
"sizes",
|
|
3848
|
+
"densities",
|
|
3849
|
+
"priority",
|
|
3850
|
+
"preload",
|
|
3851
|
+
"lazy",
|
|
3852
|
+
"loading",
|
|
3853
|
+
"decoding",
|
|
3854
|
+
"fetchpriority",
|
|
3855
|
+
"fetchPriority"
|
|
3856
|
+
]);
|
|
3857
|
+
|
|
3858
|
+
function renderClientResuxImg(node, scope, locals, styleScopeId) {
|
|
3859
|
+
const input = resolveClientImageRenderInput(node, scope, locals);
|
|
3860
|
+
if (!input.src) {
|
|
3861
|
+
return "";
|
|
3862
|
+
}
|
|
3863
|
+
|
|
3864
|
+
const app = getClientResuxApp();
|
|
3865
|
+
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3866
|
+
const src = builder(input.src, {
|
|
3867
|
+
provider: input.provider,
|
|
3868
|
+
width: input.width,
|
|
3869
|
+
height: input.height,
|
|
3870
|
+
quality: input.quality,
|
|
3871
|
+
fit: input.fit,
|
|
3872
|
+
format: input.format,
|
|
3873
|
+
modifiers: input.modifiers
|
|
3874
|
+
});
|
|
3875
|
+
const srcset = buildClientImageSrcset(builder, input);
|
|
3876
|
+
return renderClientResuxImgTag(input, src, srcset, styleScopeId);
|
|
3877
|
+
}
|
|
3878
|
+
|
|
3879
|
+
function renderClientResuxPicture(node, scope, locals, styleScopeId) {
|
|
3880
|
+
const input = resolveClientImageRenderInput(node, scope, locals);
|
|
3881
|
+
if (!input.src) {
|
|
3882
|
+
return "";
|
|
3883
|
+
}
|
|
3884
|
+
|
|
3885
|
+
const app = getClientResuxApp();
|
|
3886
|
+
const builder = createClientImageBuilder(app.route, app.$config);
|
|
3887
|
+
const fallbackSrc = builder(input.src, {
|
|
3888
|
+
provider: input.provider,
|
|
3889
|
+
width: input.width,
|
|
3890
|
+
height: input.height,
|
|
3891
|
+
quality: input.quality,
|
|
3892
|
+
fit: input.fit,
|
|
3893
|
+
modifiers: input.modifiers
|
|
3894
|
+
});
|
|
3895
|
+
const fallbackSrcset = buildClientImageSrcset(builder, {
|
|
3896
|
+
...input,
|
|
3897
|
+
format: undefined
|
|
3898
|
+
});
|
|
3899
|
+
const manualChildren = node.children.map((child) => renderNode(child, scope, locals, styleScopeId)).join("");
|
|
3900
|
+
const generatedSources = input.formats
|
|
3901
|
+
.map((format) => {
|
|
3902
|
+
const sourceSrcset = buildClientImageSrcset(builder, {
|
|
3903
|
+
...input,
|
|
3904
|
+
format
|
|
3905
|
+
});
|
|
3906
|
+
const resolvedSrcset = sourceSrcset || builder(input.src, {
|
|
3907
|
+
provider: input.provider,
|
|
3908
|
+
width: input.width,
|
|
3909
|
+
height: input.height,
|
|
3910
|
+
quality: input.quality,
|
|
3911
|
+
fit: input.fit,
|
|
3912
|
+
format,
|
|
3913
|
+
modifiers: input.modifiers
|
|
3914
|
+
});
|
|
3915
|
+
if (!resolvedSrcset) {
|
|
3916
|
+
return "";
|
|
3917
|
+
}
|
|
3918
|
+
const sourceAttrs = ['type="' + escapeAttribute(clientImageMimeType(format)) + '"'];
|
|
3919
|
+
if (input.deferLazy) {
|
|
3920
|
+
sourceAttrs.push('data-rx-lazy-srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3921
|
+
if (input.sizes) {
|
|
3922
|
+
sourceAttrs.push('data-rx-lazy-sizes="' + escapeAttribute(input.sizes) + '"');
|
|
3923
|
+
}
|
|
3924
|
+
} else {
|
|
3925
|
+
sourceAttrs.push('srcset="' + escapeAttribute(resolvedSrcset) + '"');
|
|
3926
|
+
if (input.sizes) {
|
|
3927
|
+
sourceAttrs.push('sizes="' + escapeAttribute(input.sizes) + '"');
|
|
3928
|
+
}
|
|
3929
|
+
}
|
|
3930
|
+
return "<source " + sourceAttrs.join(" ") + ">";
|
|
3931
|
+
})
|
|
3932
|
+
.filter(Boolean)
|
|
3933
|
+
.join("");
|
|
3934
|
+
const img = renderClientResuxImgTag(input, fallbackSrc, fallbackSrcset, undefined);
|
|
3935
|
+
const attrs = [];
|
|
3936
|
+
if (styleScopeId) {
|
|
3937
|
+
attrs.push(styleScopeId + '=""');
|
|
3938
|
+
}
|
|
3939
|
+
const attrText = attrs.length ? " " + attrs.join(" ") : "";
|
|
3940
|
+
return "<picture" + attrText + ">" + manualChildren + generatedSources + img + "</picture>";
|
|
3941
|
+
}
|
|
3942
|
+
|
|
3943
|
+
function resolveClientImageRenderInput(node, scope, locals) {
|
|
3944
|
+
const props = {};
|
|
3945
|
+
for (const attr of node.attrs) {
|
|
3946
|
+
const normalizedName = attr.name.replace(/-([a-zA-Z0-9])/g, (_, char) => char.toUpperCase());
|
|
3947
|
+
props[normalizedName] = attr.kind === "static"
|
|
3948
|
+
? attr.value
|
|
3949
|
+
: evaluateExpression(attr.value, scope, locals);
|
|
3950
|
+
}
|
|
3951
|
+
const imageConfig = readClientImageConfig(getClientResuxApp().$config);
|
|
3952
|
+
const explicitFormat = readClientStringProp(props.format);
|
|
3953
|
+
const explicitFormats = parseClientImageFormats(
|
|
3954
|
+
props.formats || (explicitFormat && explicitFormat.includes(",") ? explicitFormat : undefined)
|
|
3955
|
+
);
|
|
3956
|
+
const priority = readClientBooleanProp(props.priority, false);
|
|
3957
|
+
const preload = readClientBooleanProp(props.preload, priority);
|
|
3958
|
+
const explicitLoading = readClientStringProp(props.loading);
|
|
3959
|
+
const explicitLazy = props.lazy === undefined
|
|
3960
|
+
? undefined
|
|
3961
|
+
: readClientBooleanProp(props.lazy, true);
|
|
3962
|
+
const lazy = explicitLazy ?? (explicitLoading ? explicitLoading === "lazy" : !priority);
|
|
3963
|
+
const loading = explicitLoading || (lazy ? "lazy" : "eager");
|
|
3964
|
+
const deferLazy = explicitLoading === "lazy" || explicitLazy === true;
|
|
3965
|
+
const quality = readClientNumberProp(props.quality) || imageConfig.quality;
|
|
3966
|
+
const densities = parseClientImageNumberList(props.densities)
|
|
3967
|
+
|| imageConfig.densities
|
|
3968
|
+
|| [1, 2];
|
|
3969
|
+
return {
|
|
3970
|
+
src: readClientStringProp(props.src) || "",
|
|
3971
|
+
alt: readClientStringProp(props.alt) || "",
|
|
3972
|
+
width: readClientNumberProp(props.width),
|
|
3973
|
+
height: readClientNumberProp(props.height),
|
|
3974
|
+
sizes: readClientStringProp(props.sizes),
|
|
3975
|
+
widths: parseClientImageNumberList(props.widths) || [],
|
|
3976
|
+
densities,
|
|
3977
|
+
loading,
|
|
3978
|
+
decoding: readClientStringProp(props.decoding) || "async",
|
|
3979
|
+
fetchPriority: readClientStringProp(props.fetchpriority || props.fetchPriority) || (priority ? "high" : undefined),
|
|
3980
|
+
provider: readClientStringProp(props.provider),
|
|
3981
|
+
quality,
|
|
3982
|
+
fit: readClientStringProp(props.fit),
|
|
3983
|
+
format: explicitFormats.length ? undefined : explicitFormat || imageConfig.format,
|
|
3984
|
+
formats: explicitFormats,
|
|
3985
|
+
modifiers: normalizeClientImageModifiers(props.modifiers),
|
|
3986
|
+
attrs: collectClientImageAttrs(props),
|
|
3987
|
+
preload,
|
|
3988
|
+
deferLazy
|
|
3989
|
+
};
|
|
3990
|
+
}
|
|
3991
|
+
|
|
3992
|
+
function collectClientImageAttrs(props) {
|
|
3993
|
+
const attrs = {};
|
|
3994
|
+
for (const [name, rawValue] of Object.entries(props)) {
|
|
3995
|
+
if (clientImageReservedProps.has(name)) {
|
|
3996
|
+
continue;
|
|
3997
|
+
}
|
|
3998
|
+
if (rawValue === undefined || rawValue === null || rawValue === false) {
|
|
3999
|
+
continue;
|
|
4000
|
+
}
|
|
4001
|
+
const attrName = name === "className"
|
|
4002
|
+
? "class"
|
|
4003
|
+
: name === "referrerPolicy"
|
|
4004
|
+
? "referrerpolicy"
|
|
4005
|
+
: name === "crossOrigin"
|
|
4006
|
+
? "crossorigin"
|
|
4007
|
+
: name;
|
|
4008
|
+
attrs[attrName] = stringifyAttributeValue(attrName, rawValue);
|
|
4009
|
+
}
|
|
4010
|
+
return attrs;
|
|
4011
|
+
}
|
|
4012
|
+
|
|
4013
|
+
function normalizeClientImageModifiers(value) {
|
|
4014
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
4015
|
+
return {};
|
|
4016
|
+
}
|
|
4017
|
+
const modifiers = {};
|
|
4018
|
+
for (const [key, entry] of Object.entries(value)) {
|
|
4019
|
+
if (entry === undefined || entry === null || entry === false) {
|
|
4020
|
+
continue;
|
|
4021
|
+
}
|
|
4022
|
+
if (key === "width" || key === "height" || key === "quality") {
|
|
4023
|
+
const numeric = Number(entry);
|
|
4024
|
+
if (Number.isFinite(numeric) && numeric > 0) {
|
|
4025
|
+
modifiers[key] = Math.round(numeric);
|
|
4026
|
+
}
|
|
4027
|
+
continue;
|
|
4028
|
+
}
|
|
4029
|
+
modifiers[key] = entry;
|
|
4030
|
+
}
|
|
4031
|
+
return modifiers;
|
|
4032
|
+
}
|
|
4033
|
+
|
|
4034
|
+
function buildClientImageSrcset(builder, input) {
|
|
4035
|
+
const widthCandidates = input.widths.length
|
|
4036
|
+
? [...new Set(input.widths)].sort((left, right) => left - right)
|
|
4037
|
+
: [];
|
|
4038
|
+
if (widthCandidates.length) {
|
|
4039
|
+
return widthCandidates
|
|
4040
|
+
.map((width) => builder(input.src, {
|
|
4041
|
+
provider: input.provider,
|
|
4042
|
+
width,
|
|
4043
|
+
height: input.height,
|
|
4044
|
+
quality: input.quality,
|
|
4045
|
+
fit: input.fit,
|
|
4046
|
+
format: input.format,
|
|
4047
|
+
modifiers: input.modifiers
|
|
4048
|
+
}) + " " + width + "w")
|
|
4049
|
+
.join(", ");
|
|
4050
|
+
}
|
|
4051
|
+
if (!input.width || !input.densities.length) {
|
|
4052
|
+
return undefined;
|
|
4053
|
+
}
|
|
4054
|
+
return [...new Set(input.densities)]
|
|
4055
|
+
.sort((left, right) => left - right)
|
|
4056
|
+
.map((density) => {
|
|
4057
|
+
const width = Math.max(1, Math.round(input.width * density));
|
|
4058
|
+
const height = input.height ? Math.max(1, Math.round(input.height * density)) : undefined;
|
|
4059
|
+
return builder(input.src, {
|
|
4060
|
+
provider: input.provider,
|
|
4061
|
+
width,
|
|
4062
|
+
height,
|
|
4063
|
+
quality: input.quality,
|
|
4064
|
+
fit: input.fit,
|
|
4065
|
+
format: input.format,
|
|
4066
|
+
modifiers: input.modifiers
|
|
4067
|
+
}) + " " + density + "x";
|
|
4068
|
+
})
|
|
4069
|
+
.join(", ");
|
|
4070
|
+
}
|
|
4071
|
+
|
|
4072
|
+
function renderClientResuxImgTag(input, src, srcset, styleScopeId) {
|
|
4073
|
+
const attrs = [];
|
|
4074
|
+
const isDeferredLazy = input.deferLazy && String(input.loading || "").toLowerCase() === "lazy";
|
|
4075
|
+
const mergedAttrs = {
|
|
4076
|
+
...input.attrs,
|
|
4077
|
+
src: isDeferredLazy ? RESUX_LAZY_PLACEHOLDER_SRC : src,
|
|
4078
|
+
alt: input.alt,
|
|
4079
|
+
loading: input.loading,
|
|
4080
|
+
decoding: input.decoding,
|
|
4081
|
+
...(isDeferredLazy ? { "data-rx-lazy-image": "true" } : {}),
|
|
4082
|
+
...(isDeferredLazy ? { "data-rx-lazy-src": src } : {}),
|
|
4083
|
+
...(isDeferredLazy && srcset ? { "data-rx-lazy-srcset": srcset } : {}),
|
|
4084
|
+
...(isDeferredLazy && input.sizes ? { "data-rx-lazy-sizes": input.sizes } : {}),
|
|
4085
|
+
...(input.fetchPriority ? { fetchpriority: input.fetchPriority } : {}),
|
|
4086
|
+
...(input.width ? { width: String(input.width) } : {}),
|
|
4087
|
+
...(input.height ? { height: String(input.height) } : {}),
|
|
4088
|
+
...(!isDeferredLazy && srcset ? { srcset } : {}),
|
|
4089
|
+
...(!isDeferredLazy && input.sizes ? { sizes: input.sizes } : {})
|
|
4090
|
+
};
|
|
4091
|
+
for (const [name, value] of Object.entries(mergedAttrs)) {
|
|
4092
|
+
if (value === undefined || value === null) {
|
|
4093
|
+
continue;
|
|
4094
|
+
}
|
|
4095
|
+
attrs.push(name + '="' + escapeAttribute(String(value)) + '"');
|
|
4096
|
+
}
|
|
4097
|
+
if (styleScopeId) {
|
|
4098
|
+
attrs.push(styleScopeId + '=""');
|
|
4099
|
+
}
|
|
4100
|
+
const attrText = attrs.length ? " " + attrs.join(" ") : "";
|
|
4101
|
+
return "<img" + attrText + ">";
|
|
4102
|
+
}
|
|
4103
|
+
|
|
4104
|
+
function parseClientImageFormats(value) {
|
|
4105
|
+
if (Array.isArray(value)) {
|
|
4106
|
+
return value.map((entry) => String(entry).trim().toLowerCase()).filter(Boolean);
|
|
4107
|
+
}
|
|
4108
|
+
if (typeof value !== "string") {
|
|
4109
|
+
return [];
|
|
4110
|
+
}
|
|
4111
|
+
return value.split(",").map((entry) => entry.trim().toLowerCase()).filter(Boolean);
|
|
4112
|
+
}
|
|
4113
|
+
|
|
4114
|
+
function parseClientImageNumberList(value) {
|
|
4115
|
+
const values = Array.isArray(value)
|
|
4116
|
+
? value
|
|
4117
|
+
: typeof value === "string"
|
|
4118
|
+
? value.split(",")
|
|
4119
|
+
: null;
|
|
4120
|
+
if (!values) {
|
|
4121
|
+
return undefined;
|
|
4122
|
+
}
|
|
4123
|
+
const numbers = values
|
|
4124
|
+
.map((entry) => Number(entry))
|
|
4125
|
+
.filter((entry) => Number.isFinite(entry) && entry > 0)
|
|
4126
|
+
.map((entry) => Math.round(entry));
|
|
4127
|
+
return numbers.length ? numbers : undefined;
|
|
4128
|
+
}
|
|
4129
|
+
|
|
4130
|
+
function readClientStringProp(value) {
|
|
4131
|
+
if (typeof value !== "string") {
|
|
4132
|
+
return undefined;
|
|
4133
|
+
}
|
|
4134
|
+
const trimmed = value.trim();
|
|
4135
|
+
return trimmed.length ? trimmed : undefined;
|
|
4136
|
+
}
|
|
4137
|
+
|
|
4138
|
+
function readClientNumberProp(value) {
|
|
4139
|
+
const parsed = typeof value === "number"
|
|
4140
|
+
? value
|
|
4141
|
+
: typeof value === "string"
|
|
4142
|
+
? Number(value)
|
|
4143
|
+
: Number.NaN;
|
|
4144
|
+
if (!Number.isFinite(parsed) || parsed <= 0) {
|
|
4145
|
+
return undefined;
|
|
4146
|
+
}
|
|
4147
|
+
return Math.round(parsed);
|
|
4148
|
+
}
|
|
4149
|
+
|
|
4150
|
+
function readClientBooleanProp(value, fallback) {
|
|
4151
|
+
if (typeof value === "boolean") {
|
|
4152
|
+
return value;
|
|
4153
|
+
}
|
|
4154
|
+
if (typeof value === "number") {
|
|
4155
|
+
return value !== 0;
|
|
4156
|
+
}
|
|
4157
|
+
if (typeof value === "string") {
|
|
4158
|
+
const normalized = value.trim().toLowerCase();
|
|
4159
|
+
if (normalized === "true" || normalized === "1" || normalized === "yes") {
|
|
4160
|
+
return true;
|
|
4161
|
+
}
|
|
4162
|
+
if (normalized === "false" || normalized === "0" || normalized === "no") {
|
|
4163
|
+
return false;
|
|
4164
|
+
}
|
|
4165
|
+
}
|
|
4166
|
+
return fallback;
|
|
4167
|
+
}
|
|
4168
|
+
|
|
4169
|
+
function clientImageMimeType(format) {
|
|
4170
|
+
const normalized = String(format || "").trim().toLowerCase();
|
|
4171
|
+
if (!normalized) {
|
|
4172
|
+
return "image/*";
|
|
4173
|
+
}
|
|
4174
|
+
if (normalized === "jpg") {
|
|
4175
|
+
return "image/jpeg";
|
|
4176
|
+
}
|
|
4177
|
+
return normalized.startsWith("image/") ? normalized : "image/" + normalized;
|
|
4178
|
+
}
|
|
4179
|
+
|
|
4180
|
+
function nativeElementTag(node) {
|
|
4181
|
+
if (node.tag === "ResuxLink") {
|
|
4182
|
+
return "a";
|
|
4183
|
+
}
|
|
4184
|
+
if (node.tag === "ResuxImg") {
|
|
4185
|
+
return "img";
|
|
4186
|
+
}
|
|
4187
|
+
if (node.tag === "ResuxPicture") {
|
|
4188
|
+
return "picture";
|
|
4189
|
+
}
|
|
4190
|
+
return node.tag;
|
|
4191
|
+
}
|
|
2722
4192
|
|
|
2723
4193
|
function nativeAttributeName(node, name) {
|
|
2724
4194
|
return node.tag === "ResuxLink" && name === "to" ? "href" : name;
|
|
2725
4195
|
}
|
|
2726
4196
|
|
|
2727
|
-
function applyPatches(scopeId, patches) {
|
|
2728
|
-
|
|
2729
|
-
|
|
2730
|
-
|
|
2731
|
-
|
|
2732
|
-
|
|
4197
|
+
function applyPatches(scopeId, patches) {
|
|
4198
|
+
let needsLazyImageActivation = false;
|
|
4199
|
+
for (const patch of patches) {
|
|
4200
|
+
if (patch.type === "text") {
|
|
4201
|
+
document.querySelectorAll('[data-rx-text="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4202
|
+
element.textContent = patch.value;
|
|
4203
|
+
});
|
|
2733
4204
|
continue;
|
|
2734
4205
|
}
|
|
2735
4206
|
if (patch.type === "attr") {
|
|
@@ -2751,21 +4222,26 @@ function applyPatches(scopeId, patches) {
|
|
|
2751
4222
|
});
|
|
2752
4223
|
continue;
|
|
2753
4224
|
}
|
|
2754
|
-
if (patch.type === "html") {
|
|
2755
|
-
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
2756
|
-
unmountVueIslands(element);
|
|
2757
|
-
element.innerHTML = patch.value;
|
|
2758
|
-
void mountVueIslands(element);
|
|
2759
|
-
|
|
2760
|
-
|
|
2761
|
-
|
|
2762
|
-
|
|
2763
|
-
|
|
2764
|
-
element
|
|
2765
|
-
|
|
2766
|
-
|
|
2767
|
-
|
|
2768
|
-
}
|
|
4225
|
+
if (patch.type === "html") {
|
|
4226
|
+
document.querySelectorAll('[data-rx-html-' + patch.id + '="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4227
|
+
unmountVueIslands(element);
|
|
4228
|
+
element.innerHTML = patch.value;
|
|
4229
|
+
void mountVueIslands(element);
|
|
4230
|
+
needsLazyImageActivation = true;
|
|
4231
|
+
});
|
|
4232
|
+
continue;
|
|
4233
|
+
}
|
|
4234
|
+
document.querySelectorAll('[data-rx-block="' + scopeId + ':' + patch.id + '"]').forEach((element) => {
|
|
4235
|
+
unmountVueIslands(element);
|
|
4236
|
+
element.innerHTML = patch.value;
|
|
4237
|
+
void mountVueIslands(element);
|
|
4238
|
+
needsLazyImageActivation = true;
|
|
4239
|
+
});
|
|
4240
|
+
}
|
|
4241
|
+
if (needsLazyImageActivation) {
|
|
4242
|
+
activateDeferredLazyImages();
|
|
4243
|
+
}
|
|
4244
|
+
}
|
|
2769
4245
|
|
|
2770
4246
|
function evaluateExpression(expression, scope, locals) {
|
|
2771
4247
|
return Function("scope", "locals", "with (scope) { with (locals) { return (" + expression + "); } }")(scope, locals);
|