@pixldocs/canvas-renderer 0.3.18 → 0.3.19
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/index.cjs +79 -0
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +58 -0
- package/dist/index.js +80 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -10942,14 +10942,93 @@ class PixldocsRenderer {
|
|
|
10942
10942
|
});
|
|
10943
10943
|
}
|
|
10944
10944
|
}
|
|
10945
|
+
function collectImageUrls(config) {
|
|
10946
|
+
const urls = [];
|
|
10947
|
+
const walk = (nodes) => {
|
|
10948
|
+
for (const node of nodes) {
|
|
10949
|
+
if (!node || node.visible === false) continue;
|
|
10950
|
+
const src = typeof node.src === "string" ? node.src.trim() : "";
|
|
10951
|
+
const imageUrl = typeof node.imageUrl === "string" ? node.imageUrl.trim() : "";
|
|
10952
|
+
if (node.type === "image") {
|
|
10953
|
+
const url = src || imageUrl;
|
|
10954
|
+
if (url) urls.push(url);
|
|
10955
|
+
}
|
|
10956
|
+
if (Array.isArray(node.children) && node.children.length > 0) {
|
|
10957
|
+
walk(node.children);
|
|
10958
|
+
}
|
|
10959
|
+
}
|
|
10960
|
+
};
|
|
10961
|
+
for (const page of config.pages || []) {
|
|
10962
|
+
walk(page.children || []);
|
|
10963
|
+
}
|
|
10964
|
+
return urls;
|
|
10965
|
+
}
|
|
10966
|
+
function normalizeAssetUrl(rawUrl, imageProxyUrl) {
|
|
10967
|
+
if (!rawUrl) return null;
|
|
10968
|
+
if (rawUrl.startsWith("data:") || rawUrl.startsWith("blob:")) return null;
|
|
10969
|
+
try {
|
|
10970
|
+
const h = new URL(rawUrl).hostname.toLowerCase();
|
|
10971
|
+
if (h === "localhost" || h === "127.0.0.1" || h === "0.0.0.0" || h.endsWith(".local") || /^(10\.|192\.168\.|169\.254\.)/.test(h)) {
|
|
10972
|
+
return null;
|
|
10973
|
+
}
|
|
10974
|
+
} catch {
|
|
10975
|
+
return null;
|
|
10976
|
+
}
|
|
10977
|
+
const supabaseUrl = typeof globalThis.__VITE_SUPABASE_URL === "string" ? globalThis.__VITE_SUPABASE_URL : "";
|
|
10978
|
+
if (supabaseUrl && rawUrl.includes(supabaseUrl)) {
|
|
10979
|
+
const signedMatch = rawUrl.match(/\/storage\/v1\/object\/sign\/([^?]+)/);
|
|
10980
|
+
if (signedMatch) return `${supabaseUrl}/storage/v1/object/public/${signedMatch[1]}`;
|
|
10981
|
+
if (rawUrl.includes("/storage/v1/object/public/")) return rawUrl;
|
|
10982
|
+
}
|
|
10983
|
+
const proxyBase = imageProxyUrl ? imageProxyUrl.replace(/\/image-proxy(?:\?.*)?$/, "") : API_URL;
|
|
10984
|
+
if (proxyBase) {
|
|
10985
|
+
return `${proxyBase}/image-proxy?url=${encodeURIComponent(rawUrl)}`;
|
|
10986
|
+
}
|
|
10987
|
+
return rawUrl;
|
|
10988
|
+
}
|
|
10989
|
+
const CONCURRENCY = 6;
|
|
10990
|
+
async function prefetchUrls(urls, signal) {
|
|
10991
|
+
const unique = [...new Set(urls)];
|
|
10992
|
+
if (unique.length === 0) return;
|
|
10993
|
+
let i = 0;
|
|
10994
|
+
const next = async () => {
|
|
10995
|
+
while (i < unique.length) {
|
|
10996
|
+
if (signal == null ? void 0 : signal.aborted) return;
|
|
10997
|
+
const url = unique[i++];
|
|
10998
|
+
try {
|
|
10999
|
+
await fetch(url, { signal, mode: "cors", credentials: "omit" });
|
|
11000
|
+
} catch {
|
|
11001
|
+
}
|
|
11002
|
+
}
|
|
11003
|
+
};
|
|
11004
|
+
const workers = Array.from({ length: Math.min(CONCURRENCY, unique.length) }, () => next());
|
|
11005
|
+
await Promise.all(workers);
|
|
11006
|
+
}
|
|
11007
|
+
async function warmResolvedTemplateForPreview(config, options) {
|
|
11008
|
+
const { signal, imageProxyUrl } = options ?? {};
|
|
11009
|
+
await ensureFontsForResolvedConfig(config);
|
|
11010
|
+
if (signal == null ? void 0 : signal.aborted) return;
|
|
11011
|
+
const rawUrls = collectImageUrls(config);
|
|
11012
|
+
const resolvedUrls = rawUrls.map((u) => normalizeAssetUrl(u, imageProxyUrl)).filter((u) => u !== null);
|
|
11013
|
+
await prefetchUrls(resolvedUrls, signal);
|
|
11014
|
+
}
|
|
11015
|
+
async function warmTemplateFromForm(options) {
|
|
11016
|
+
const { signal, imageProxyUrl, ...resolveOpts } = options;
|
|
11017
|
+
const resolved = await resolveFromForm(resolveOpts);
|
|
11018
|
+
if (signal == null ? void 0 : signal.aborted) return;
|
|
11019
|
+
await warmResolvedTemplateForPreview(resolved.config, { signal, imageProxyUrl });
|
|
11020
|
+
}
|
|
10945
11021
|
exports.PixldocsPreview = PixldocsPreview;
|
|
10946
11022
|
exports.PixldocsRenderer = PixldocsRenderer;
|
|
10947
11023
|
exports.applyThemeToConfig = applyThemeToConfig;
|
|
10948
11024
|
exports.collectFontDescriptorsFromConfig = collectFontDescriptorsFromConfig;
|
|
10949
11025
|
exports.collectFontsFromConfig = collectFontsFromConfig;
|
|
11026
|
+
exports.collectImageUrls = collectImageUrls;
|
|
10950
11027
|
exports.ensureFontsForResolvedConfig = ensureFontsForResolvedConfig;
|
|
10951
11028
|
exports.loadGoogleFontCSS = loadGoogleFontCSS;
|
|
10952
11029
|
exports.normalizeFontFamily = normalizeFontFamily;
|
|
10953
11030
|
exports.resolveFromForm = resolveFromForm;
|
|
10954
11031
|
exports.resolveTemplateData = resolveTemplateData;
|
|
11032
|
+
exports.warmResolvedTemplateForPreview = warmResolvedTemplateForPreview;
|
|
11033
|
+
exports.warmTemplateFromForm = warmTemplateFromForm;
|
|
10955
11034
|
//# sourceMappingURL=index.cjs.map
|