@pixldocs/canvas-renderer 0.5.97 → 0.5.98
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 +34 -1
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +34 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -13103,7 +13103,7 @@ function PixldocsPreview(props) {
|
|
|
13103
13103
|
!canvasSettled && /* @__PURE__ */ jsxRuntime.jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
|
|
13104
13104
|
] });
|
|
13105
13105
|
}
|
|
13106
|
-
const PACKAGE_VERSION = "0.5.
|
|
13106
|
+
const PACKAGE_VERSION = "0.5.98";
|
|
13107
13107
|
const roundParityValue = (value) => {
|
|
13108
13108
|
if (typeof value !== "number") return value;
|
|
13109
13109
|
return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
|
|
@@ -14064,6 +14064,7 @@ class PixldocsRenderer {
|
|
|
14064
14064
|
this.logFabricTextParitySnapshot("after-stable-text-metrics", fabricInstance);
|
|
14065
14065
|
}
|
|
14066
14066
|
}
|
|
14067
|
+
const __vite_import_meta_env__ = {};
|
|
14067
14068
|
const FONT_WEIGHT_LABELS = {
|
|
14068
14069
|
300: "Light",
|
|
14069
14070
|
400: "Regular",
|
|
@@ -14690,10 +14691,36 @@ function bytesToBase64(bytes) {
|
|
|
14690
14691
|
for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i]);
|
|
14691
14692
|
return btoa(binary);
|
|
14692
14693
|
}
|
|
14694
|
+
function getFontProxyUrl() {
|
|
14695
|
+
var _a;
|
|
14696
|
+
const viteUrl = (__vite_import_meta_env__ == null ? void 0 : __vite_import_meta_env__.VITE_SUPABASE_URL) || "";
|
|
14697
|
+
const runtimeUrl = typeof globalThis !== "undefined" ? ((_a = globalThis.__CONFIG__) == null ? void 0 : _a.supabaseUrl) || globalThis.__PIXLDOCS_SUPABASE_URL || "" : "";
|
|
14698
|
+
const baseUrl = (viteUrl || runtimeUrl || "").replace(/\/$/, "");
|
|
14699
|
+
return baseUrl ? `${baseUrl}/functions/v1/font-proxy` : null;
|
|
14700
|
+
}
|
|
14701
|
+
async function fetchTtfViaProxy(family, weight, isItalic, source) {
|
|
14702
|
+
const proxyUrl = getFontProxyUrl();
|
|
14703
|
+
if (!proxyUrl) return null;
|
|
14704
|
+
try {
|
|
14705
|
+
const url = `${proxyUrl}?family=${encodeURIComponent(family)}&weight=${weight}&italic=${isItalic ? 1 : 0}&source=${source}`;
|
|
14706
|
+
const res = await fetch(url);
|
|
14707
|
+
if (!res.ok) return null;
|
|
14708
|
+
const bytes = new Uint8Array(await res.arrayBuffer());
|
|
14709
|
+
return isJsPdfEmbeddableTrueType(bytes) ? bytes : null;
|
|
14710
|
+
} catch {
|
|
14711
|
+
return null;
|
|
14712
|
+
}
|
|
14713
|
+
}
|
|
14693
14714
|
async function fetchGoogleFontTTF(fontFamily, weight, isItalic = false) {
|
|
14694
14715
|
const cacheKey = `gf:${fontFamily}:${weight}:${isItalic ? "i" : "n"}`;
|
|
14695
14716
|
if (ttfCache.has(cacheKey)) return ttfCache.get(cacheKey);
|
|
14696
14717
|
if (googleFontNotFound.has(fontFamily)) return null;
|
|
14718
|
+
const proxyBytes = await fetchTtfViaProxy(fontFamily, weight, isItalic, "google");
|
|
14719
|
+
if (proxyBytes) {
|
|
14720
|
+
const b64 = bytesToBase64(proxyBytes);
|
|
14721
|
+
ttfCache.set(cacheKey, b64);
|
|
14722
|
+
return b64;
|
|
14723
|
+
}
|
|
14697
14724
|
try {
|
|
14698
14725
|
const ital = isItalic ? "1" : "0";
|
|
14699
14726
|
const cssUrl = `https://fonts.googleapis.com/css2?family=${encodeURIComponent(
|
|
@@ -14733,6 +14760,12 @@ async function fetchFontshareTTF(fontFamily, weight, isItalic = false) {
|
|
|
14733
14760
|
if (ttfCache.has(cacheKey)) return ttfCache.get(cacheKey);
|
|
14734
14761
|
if (fontshareNotFound.has(fontFamily)) return null;
|
|
14735
14762
|
const slug = fontFamily.trim().toLowerCase().replace(/\s+/g, "-");
|
|
14763
|
+
const proxyBytes = await fetchTtfViaProxy(fontFamily, weight, isItalic, "fontshare");
|
|
14764
|
+
if (proxyBytes) {
|
|
14765
|
+
const b64 = bytesToBase64(proxyBytes);
|
|
14766
|
+
ttfCache.set(cacheKey, b64);
|
|
14767
|
+
return b64;
|
|
14768
|
+
}
|
|
14736
14769
|
try {
|
|
14737
14770
|
const styleSuffix = isItalic ? "i" : "";
|
|
14738
14771
|
const cssUrl = `https://api.fontshare.com/v2/css?f[]=${slug}@${weight}${styleSuffix}&display=swap`;
|