@pixldocs/canvas-renderer 0.3.13 → 0.3.14
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 +100 -75
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +100 -75
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -10369,79 +10369,6 @@ function paintRepeatableSections(config, repeatableSections) {
|
|
|
10369
10369
|
}
|
|
10370
10370
|
}
|
|
10371
10371
|
}
|
|
10372
|
-
function PixldocsPreview(props) {
|
|
10373
|
-
const {
|
|
10374
|
-
pageIndex = 0,
|
|
10375
|
-
zoom = 1,
|
|
10376
|
-
absoluteZoom = false,
|
|
10377
|
-
imageProxyUrl,
|
|
10378
|
-
className,
|
|
10379
|
-
style,
|
|
10380
|
-
onDynamicFieldClick,
|
|
10381
|
-
onReady,
|
|
10382
|
-
onError
|
|
10383
|
-
} = props;
|
|
10384
|
-
useEffect(() => {
|
|
10385
|
-
setPackageApiUrl(imageProxyUrl);
|
|
10386
|
-
}, [imageProxyUrl]);
|
|
10387
|
-
const [resolvedConfig, setResolvedConfig] = useState(null);
|
|
10388
|
-
const [isLoading, setIsLoading] = useState(false);
|
|
10389
|
-
const isResolveMode = !("config" in props && props.config);
|
|
10390
|
-
useEffect(() => {
|
|
10391
|
-
if (!isResolveMode) {
|
|
10392
|
-
setResolvedConfig(null);
|
|
10393
|
-
return;
|
|
10394
|
-
}
|
|
10395
|
-
const p = props;
|
|
10396
|
-
if (!p.templateId || !p.formSchemaId || !p.supabaseUrl || !p.supabaseAnonKey) return;
|
|
10397
|
-
let cancelled = false;
|
|
10398
|
-
setIsLoading(true);
|
|
10399
|
-
resolveFromForm({
|
|
10400
|
-
templateId: p.templateId,
|
|
10401
|
-
formSchemaId: p.formSchemaId,
|
|
10402
|
-
sectionState: p.sectionState,
|
|
10403
|
-
themeId: p.themeId,
|
|
10404
|
-
supabaseUrl: p.supabaseUrl,
|
|
10405
|
-
supabaseAnonKey: p.supabaseAnonKey
|
|
10406
|
-
}).then((resolved) => {
|
|
10407
|
-
if (!cancelled) {
|
|
10408
|
-
setResolvedConfig(resolved.config);
|
|
10409
|
-
setIsLoading(false);
|
|
10410
|
-
}
|
|
10411
|
-
}).catch((err) => {
|
|
10412
|
-
if (!cancelled) {
|
|
10413
|
-
setIsLoading(false);
|
|
10414
|
-
onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
|
|
10415
|
-
}
|
|
10416
|
-
});
|
|
10417
|
-
return () => {
|
|
10418
|
-
cancelled = true;
|
|
10419
|
-
};
|
|
10420
|
-
}, [
|
|
10421
|
-
isResolveMode,
|
|
10422
|
-
// For resolve mode, re-resolve when these change
|
|
10423
|
-
isResolveMode ? props.templateId : void 0,
|
|
10424
|
-
isResolveMode ? props.formSchemaId : void 0,
|
|
10425
|
-
isResolveMode ? JSON.stringify(props.sectionState) : void 0,
|
|
10426
|
-
isResolveMode ? props.themeId : void 0
|
|
10427
|
-
]);
|
|
10428
|
-
const config = isResolveMode ? resolvedConfig : props.config;
|
|
10429
|
-
if (isLoading) {
|
|
10430
|
-
return /* @__PURE__ */ jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
|
|
10431
|
-
}
|
|
10432
|
-
if (!config) return null;
|
|
10433
|
-
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
|
|
10434
|
-
PreviewCanvas,
|
|
10435
|
-
{
|
|
10436
|
-
config,
|
|
10437
|
-
pageIndex,
|
|
10438
|
-
zoom,
|
|
10439
|
-
absoluteZoom,
|
|
10440
|
-
onDynamicFieldClick,
|
|
10441
|
-
onReady
|
|
10442
|
-
}
|
|
10443
|
-
) });
|
|
10444
|
-
}
|
|
10445
10372
|
function normalizeFontFamily(fontStack) {
|
|
10446
10373
|
const first = fontStack.split(",")[0].trim();
|
|
10447
10374
|
return first.replace(/^['"]|['"]$/g, "");
|
|
@@ -10490,6 +10417,7 @@ function collectFontsFromConfig(config) {
|
|
|
10490
10417
|
var _a;
|
|
10491
10418
|
const fonts = /* @__PURE__ */ new Set();
|
|
10492
10419
|
fonts.add("Open Sans");
|
|
10420
|
+
fonts.add("Hind");
|
|
10493
10421
|
function walk(nodes) {
|
|
10494
10422
|
var _a2;
|
|
10495
10423
|
if (!nodes) return;
|
|
@@ -10542,12 +10470,18 @@ function collectFontDescriptorsFromConfig(config) {
|
|
|
10542
10470
|
for (const node of nodes) {
|
|
10543
10471
|
if (node.fontFamily) {
|
|
10544
10472
|
add(node.fontFamily, node.fontWeight, node.fontStyle);
|
|
10473
|
+
if (node.type === "text") {
|
|
10474
|
+
for (const w of [300, 400, 500, 600, 700]) {
|
|
10475
|
+
add(node.fontFamily, w, node.fontStyle);
|
|
10476
|
+
}
|
|
10477
|
+
}
|
|
10545
10478
|
}
|
|
10546
10479
|
if ((_a2 = node.smartProps) == null ? void 0 : _a2.fontFamily) {
|
|
10547
10480
|
add(node.smartProps.fontFamily, node.smartProps.fontWeight, node.smartProps.fontStyle);
|
|
10548
10481
|
}
|
|
10549
|
-
if (node.styles
|
|
10550
|
-
|
|
10482
|
+
if (node.styles) {
|
|
10483
|
+
const styleEntries = Array.isArray(node.styles) ? node.styles : Object.values(node.styles);
|
|
10484
|
+
for (const lineStyle of styleEntries) {
|
|
10551
10485
|
if (lineStyle && typeof lineStyle === "object") {
|
|
10552
10486
|
for (const charStyle of Object.values(lineStyle)) {
|
|
10553
10487
|
if (charStyle == null ? void 0 : charStyle.fontFamily) {
|
|
@@ -10561,6 +10495,8 @@ function collectFontDescriptorsFromConfig(config) {
|
|
|
10561
10495
|
}
|
|
10562
10496
|
}
|
|
10563
10497
|
add("Open Sans", 400, "normal");
|
|
10498
|
+
add("Hind", 400, "normal");
|
|
10499
|
+
add("Hind", 700, "normal");
|
|
10564
10500
|
for (const page of config.pages || []) {
|
|
10565
10501
|
walk(page.children || []);
|
|
10566
10502
|
}
|
|
@@ -10592,6 +10528,95 @@ async function ensureFontsForResolvedConfig(config) {
|
|
|
10592
10528
|
await document.fonts.ready;
|
|
10593
10529
|
}
|
|
10594
10530
|
}
|
|
10531
|
+
function PixldocsPreview(props) {
|
|
10532
|
+
const {
|
|
10533
|
+
pageIndex = 0,
|
|
10534
|
+
zoom = 1,
|
|
10535
|
+
absoluteZoom = false,
|
|
10536
|
+
imageProxyUrl,
|
|
10537
|
+
className,
|
|
10538
|
+
style,
|
|
10539
|
+
onDynamicFieldClick,
|
|
10540
|
+
onReady,
|
|
10541
|
+
onError
|
|
10542
|
+
} = props;
|
|
10543
|
+
useEffect(() => {
|
|
10544
|
+
setPackageApiUrl(imageProxyUrl);
|
|
10545
|
+
}, [imageProxyUrl]);
|
|
10546
|
+
const [resolvedConfig, setResolvedConfig] = useState(null);
|
|
10547
|
+
const [isLoading, setIsLoading] = useState(false);
|
|
10548
|
+
const [fontsReady, setFontsReady] = useState(false);
|
|
10549
|
+
const isResolveMode = !("config" in props && props.config);
|
|
10550
|
+
useEffect(() => {
|
|
10551
|
+
if (!isResolveMode) {
|
|
10552
|
+
setResolvedConfig(null);
|
|
10553
|
+
return;
|
|
10554
|
+
}
|
|
10555
|
+
const p = props;
|
|
10556
|
+
if (!p.templateId || !p.formSchemaId || !p.supabaseUrl || !p.supabaseAnonKey) return;
|
|
10557
|
+
let cancelled = false;
|
|
10558
|
+
setIsLoading(true);
|
|
10559
|
+
resolveFromForm({
|
|
10560
|
+
templateId: p.templateId,
|
|
10561
|
+
formSchemaId: p.formSchemaId,
|
|
10562
|
+
sectionState: p.sectionState,
|
|
10563
|
+
themeId: p.themeId,
|
|
10564
|
+
supabaseUrl: p.supabaseUrl,
|
|
10565
|
+
supabaseAnonKey: p.supabaseAnonKey
|
|
10566
|
+
}).then((resolved) => {
|
|
10567
|
+
if (!cancelled) {
|
|
10568
|
+
setResolvedConfig(resolved.config);
|
|
10569
|
+
ensureFontsForResolvedConfig(resolved.config).then(() => {
|
|
10570
|
+
if (!cancelled) {
|
|
10571
|
+
setFontsReady(true);
|
|
10572
|
+
setIsLoading(false);
|
|
10573
|
+
}
|
|
10574
|
+
}).catch(() => {
|
|
10575
|
+
if (!cancelled) {
|
|
10576
|
+
setFontsReady(true);
|
|
10577
|
+
setIsLoading(false);
|
|
10578
|
+
}
|
|
10579
|
+
});
|
|
10580
|
+
}
|
|
10581
|
+
}).catch((err) => {
|
|
10582
|
+
if (!cancelled) {
|
|
10583
|
+
setIsLoading(false);
|
|
10584
|
+
onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
|
|
10585
|
+
}
|
|
10586
|
+
});
|
|
10587
|
+
return () => {
|
|
10588
|
+
cancelled = true;
|
|
10589
|
+
};
|
|
10590
|
+
}, [
|
|
10591
|
+
isResolveMode,
|
|
10592
|
+
// For resolve mode, re-resolve when these change
|
|
10593
|
+
isResolveMode ? props.templateId : void 0,
|
|
10594
|
+
isResolveMode ? props.formSchemaId : void 0,
|
|
10595
|
+
isResolveMode ? JSON.stringify(props.sectionState) : void 0,
|
|
10596
|
+
isResolveMode ? props.themeId : void 0
|
|
10597
|
+
]);
|
|
10598
|
+
const config = isResolveMode ? resolvedConfig : props.config;
|
|
10599
|
+
useEffect(() => {
|
|
10600
|
+
if (isResolveMode || !config) return;
|
|
10601
|
+
setFontsReady(false);
|
|
10602
|
+
ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
|
|
10603
|
+
}, [isResolveMode, config]);
|
|
10604
|
+
if (isLoading) {
|
|
10605
|
+
return /* @__PURE__ */ jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
|
|
10606
|
+
}
|
|
10607
|
+
if (!config) return null;
|
|
10608
|
+
return /* @__PURE__ */ jsx("div", { className, style, children: /* @__PURE__ */ jsx(
|
|
10609
|
+
PreviewCanvas,
|
|
10610
|
+
{
|
|
10611
|
+
config,
|
|
10612
|
+
pageIndex,
|
|
10613
|
+
zoom,
|
|
10614
|
+
absoluteZoom,
|
|
10615
|
+
onDynamicFieldClick,
|
|
10616
|
+
onReady
|
|
10617
|
+
}
|
|
10618
|
+
) });
|
|
10619
|
+
}
|
|
10595
10620
|
class PixldocsRenderer {
|
|
10596
10621
|
constructor(config) {
|
|
10597
10622
|
__publicField(this, "config");
|