@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 CHANGED
@@ -10388,79 +10388,6 @@ function paintRepeatableSections(config, repeatableSections) {
10388
10388
  }
10389
10389
  }
10390
10390
  }
10391
- function PixldocsPreview(props) {
10392
- const {
10393
- pageIndex = 0,
10394
- zoom = 1,
10395
- absoluteZoom = false,
10396
- imageProxyUrl,
10397
- className,
10398
- style,
10399
- onDynamicFieldClick,
10400
- onReady,
10401
- onError
10402
- } = props;
10403
- react.useEffect(() => {
10404
- setPackageApiUrl(imageProxyUrl);
10405
- }, [imageProxyUrl]);
10406
- const [resolvedConfig, setResolvedConfig] = react.useState(null);
10407
- const [isLoading, setIsLoading] = react.useState(false);
10408
- const isResolveMode = !("config" in props && props.config);
10409
- react.useEffect(() => {
10410
- if (!isResolveMode) {
10411
- setResolvedConfig(null);
10412
- return;
10413
- }
10414
- const p = props;
10415
- if (!p.templateId || !p.formSchemaId || !p.supabaseUrl || !p.supabaseAnonKey) return;
10416
- let cancelled = false;
10417
- setIsLoading(true);
10418
- resolveFromForm({
10419
- templateId: p.templateId,
10420
- formSchemaId: p.formSchemaId,
10421
- sectionState: p.sectionState,
10422
- themeId: p.themeId,
10423
- supabaseUrl: p.supabaseUrl,
10424
- supabaseAnonKey: p.supabaseAnonKey
10425
- }).then((resolved) => {
10426
- if (!cancelled) {
10427
- setResolvedConfig(resolved.config);
10428
- setIsLoading(false);
10429
- }
10430
- }).catch((err) => {
10431
- if (!cancelled) {
10432
- setIsLoading(false);
10433
- onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
10434
- }
10435
- });
10436
- return () => {
10437
- cancelled = true;
10438
- };
10439
- }, [
10440
- isResolveMode,
10441
- // For resolve mode, re-resolve when these change
10442
- isResolveMode ? props.templateId : void 0,
10443
- isResolveMode ? props.formSchemaId : void 0,
10444
- isResolveMode ? JSON.stringify(props.sectionState) : void 0,
10445
- isResolveMode ? props.themeId : void 0
10446
- ]);
10447
- const config = isResolveMode ? resolvedConfig : props.config;
10448
- if (isLoading) {
10449
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
10450
- }
10451
- if (!config) return null;
10452
- return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style, children: /* @__PURE__ */ jsxRuntime.jsx(
10453
- PreviewCanvas,
10454
- {
10455
- config,
10456
- pageIndex,
10457
- zoom,
10458
- absoluteZoom,
10459
- onDynamicFieldClick,
10460
- onReady
10461
- }
10462
- ) });
10463
- }
10464
10391
  function normalizeFontFamily(fontStack) {
10465
10392
  const first = fontStack.split(",")[0].trim();
10466
10393
  return first.replace(/^['"]|['"]$/g, "");
@@ -10509,6 +10436,7 @@ function collectFontsFromConfig(config) {
10509
10436
  var _a;
10510
10437
  const fonts = /* @__PURE__ */ new Set();
10511
10438
  fonts.add("Open Sans");
10439
+ fonts.add("Hind");
10512
10440
  function walk(nodes) {
10513
10441
  var _a2;
10514
10442
  if (!nodes) return;
@@ -10561,12 +10489,18 @@ function collectFontDescriptorsFromConfig(config) {
10561
10489
  for (const node of nodes) {
10562
10490
  if (node.fontFamily) {
10563
10491
  add(node.fontFamily, node.fontWeight, node.fontStyle);
10492
+ if (node.type === "text") {
10493
+ for (const w of [300, 400, 500, 600, 700]) {
10494
+ add(node.fontFamily, w, node.fontStyle);
10495
+ }
10496
+ }
10564
10497
  }
10565
10498
  if ((_a2 = node.smartProps) == null ? void 0 : _a2.fontFamily) {
10566
10499
  add(node.smartProps.fontFamily, node.smartProps.fontWeight, node.smartProps.fontStyle);
10567
10500
  }
10568
- if (node.styles && Array.isArray(node.styles)) {
10569
- for (const lineStyle of node.styles) {
10501
+ if (node.styles) {
10502
+ const styleEntries = Array.isArray(node.styles) ? node.styles : Object.values(node.styles);
10503
+ for (const lineStyle of styleEntries) {
10570
10504
  if (lineStyle && typeof lineStyle === "object") {
10571
10505
  for (const charStyle of Object.values(lineStyle)) {
10572
10506
  if (charStyle == null ? void 0 : charStyle.fontFamily) {
@@ -10580,6 +10514,8 @@ function collectFontDescriptorsFromConfig(config) {
10580
10514
  }
10581
10515
  }
10582
10516
  add("Open Sans", 400, "normal");
10517
+ add("Hind", 400, "normal");
10518
+ add("Hind", 700, "normal");
10583
10519
  for (const page of config.pages || []) {
10584
10520
  walk(page.children || []);
10585
10521
  }
@@ -10611,6 +10547,95 @@ async function ensureFontsForResolvedConfig(config) {
10611
10547
  await document.fonts.ready;
10612
10548
  }
10613
10549
  }
10550
+ function PixldocsPreview(props) {
10551
+ const {
10552
+ pageIndex = 0,
10553
+ zoom = 1,
10554
+ absoluteZoom = false,
10555
+ imageProxyUrl,
10556
+ className,
10557
+ style,
10558
+ onDynamicFieldClick,
10559
+ onReady,
10560
+ onError
10561
+ } = props;
10562
+ react.useEffect(() => {
10563
+ setPackageApiUrl(imageProxyUrl);
10564
+ }, [imageProxyUrl]);
10565
+ const [resolvedConfig, setResolvedConfig] = react.useState(null);
10566
+ const [isLoading, setIsLoading] = react.useState(false);
10567
+ const [fontsReady, setFontsReady] = react.useState(false);
10568
+ const isResolveMode = !("config" in props && props.config);
10569
+ react.useEffect(() => {
10570
+ if (!isResolveMode) {
10571
+ setResolvedConfig(null);
10572
+ return;
10573
+ }
10574
+ const p = props;
10575
+ if (!p.templateId || !p.formSchemaId || !p.supabaseUrl || !p.supabaseAnonKey) return;
10576
+ let cancelled = false;
10577
+ setIsLoading(true);
10578
+ resolveFromForm({
10579
+ templateId: p.templateId,
10580
+ formSchemaId: p.formSchemaId,
10581
+ sectionState: p.sectionState,
10582
+ themeId: p.themeId,
10583
+ supabaseUrl: p.supabaseUrl,
10584
+ supabaseAnonKey: p.supabaseAnonKey
10585
+ }).then((resolved) => {
10586
+ if (!cancelled) {
10587
+ setResolvedConfig(resolved.config);
10588
+ ensureFontsForResolvedConfig(resolved.config).then(() => {
10589
+ if (!cancelled) {
10590
+ setFontsReady(true);
10591
+ setIsLoading(false);
10592
+ }
10593
+ }).catch(() => {
10594
+ if (!cancelled) {
10595
+ setFontsReady(true);
10596
+ setIsLoading(false);
10597
+ }
10598
+ });
10599
+ }
10600
+ }).catch((err) => {
10601
+ if (!cancelled) {
10602
+ setIsLoading(false);
10603
+ onError == null ? void 0 : onError(err instanceof Error ? err : new Error(String(err)));
10604
+ }
10605
+ });
10606
+ return () => {
10607
+ cancelled = true;
10608
+ };
10609
+ }, [
10610
+ isResolveMode,
10611
+ // For resolve mode, re-resolve when these change
10612
+ isResolveMode ? props.templateId : void 0,
10613
+ isResolveMode ? props.formSchemaId : void 0,
10614
+ isResolveMode ? JSON.stringify(props.sectionState) : void 0,
10615
+ isResolveMode ? props.themeId : void 0
10616
+ ]);
10617
+ const config = isResolveMode ? resolvedConfig : props.config;
10618
+ react.useEffect(() => {
10619
+ if (isResolveMode || !config) return;
10620
+ setFontsReady(false);
10621
+ ensureFontsForResolvedConfig(config).then(() => setFontsReady(true)).catch(() => setFontsReady(true));
10622
+ }, [isResolveMode, config]);
10623
+ if (isLoading) {
10624
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style: { ...style, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsxRuntime.jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) });
10625
+ }
10626
+ if (!config) return null;
10627
+ return /* @__PURE__ */ jsxRuntime.jsx("div", { className, style, children: /* @__PURE__ */ jsxRuntime.jsx(
10628
+ PreviewCanvas,
10629
+ {
10630
+ config,
10631
+ pageIndex,
10632
+ zoom,
10633
+ absoluteZoom,
10634
+ onDynamicFieldClick,
10635
+ onReady
10636
+ }
10637
+ ) });
10638
+ }
10614
10639
  class PixldocsRenderer {
10615
10640
  constructor(config) {
10616
10641
  __publicField(this, "config");