@pixldocs/canvas-renderer 0.5.124 → 0.5.126

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.
@@ -15642,7 +15642,128 @@ function PixldocsPreview(props) {
15642
15642
  !canvasSettled && /* @__PURE__ */ jsx("div", { style: { position: "absolute", inset: 0, display: "flex", alignItems: "center", justifyContent: "center", minHeight: 200 }, children: /* @__PURE__ */ jsx("div", { style: { color: "#888", fontSize: 14 }, children: "Loading preview..." }) })
15643
15643
  ] });
15644
15644
  }
15645
- const PACKAGE_VERSION = "0.5.124";
15645
+ function normalizeSvgDimensions(svg, targetWidth, targetHeight) {
15646
+ let normalized = svg;
15647
+ if (/\bwidth="[^"]*"/i.test(normalized)) {
15648
+ normalized = normalized.replace(/(<svg[^>]*\b)width="[^"]*"/i, `$1width="${targetWidth}"`);
15649
+ } else {
15650
+ normalized = normalized.replace(/<svg\b/i, `<svg width="${targetWidth}"`);
15651
+ }
15652
+ if (/\bheight="[^"]*"/i.test(normalized)) {
15653
+ normalized = normalized.replace(/(<svg[^>]*\b)height="[^"]*"/i, `$1height="${targetHeight}"`);
15654
+ } else {
15655
+ normalized = normalized.replace(/<svg\b/i, `<svg height="${targetHeight}"`);
15656
+ }
15657
+ const viewBox = `0 0 ${targetWidth} ${targetHeight}`;
15658
+ if (/\bviewBox="[^"]*"/i.test(normalized)) {
15659
+ normalized = normalized.replace(/viewBox="[^"]*"/i, `viewBox="${viewBox}"`);
15660
+ } else {
15661
+ normalized = normalized.replace(/<svg\b/i, `<svg viewBox="${viewBox}"`);
15662
+ }
15663
+ normalized = normalized.replace(/="undefined"/g, '="0"');
15664
+ normalized = normalized.replace(/="NaN"/g, '="0"');
15665
+ if (/\bx="[^"]*"/i.test(normalized)) {
15666
+ normalized = normalized.replace(/(<svg[^>]*\b)x="[^"]*"/i, '$1x="0"');
15667
+ } else {
15668
+ normalized = normalized.replace(/<svg\b/i, '<svg x="0"');
15669
+ }
15670
+ if (/\by="[^"]*"/i.test(normalized)) {
15671
+ normalized = normalized.replace(/(<svg[^>]*\b)y="[^"]*"/i, '$1y="0"');
15672
+ } else {
15673
+ normalized = normalized.replace(/<svg\b/i, '<svg y="0"');
15674
+ }
15675
+ normalized = normalized.replace(/\bpreserveAspectRatio="[^"]*"/i, 'preserveAspectRatio="none"');
15676
+ if (!/\bpreserveAspectRatio="[^"]*"/i.test(normalized)) {
15677
+ normalized = normalized.replace(/<svg\b/i, '<svg preserveAspectRatio="none"');
15678
+ }
15679
+ return normalized;
15680
+ }
15681
+ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight) {
15682
+ const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
15683
+ const prevSvgVPT = fabricInstance.svgViewportTransformation;
15684
+ const prevRetina = fabricInstance.enableRetinaScaling;
15685
+ const prevWidth = fabricInstance.width;
15686
+ const prevHeight = fabricInstance.height;
15687
+ fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
15688
+ fabricInstance.svgViewportTransformation = false;
15689
+ fabricInstance.enableRetinaScaling = false;
15690
+ try {
15691
+ fabricInstance.setDimensions(
15692
+ { width: canvasWidth, height: canvasHeight },
15693
+ { cssOnly: false, backstoreOnly: false }
15694
+ );
15695
+ } catch {
15696
+ }
15697
+ const fadeBakeRecords = [];
15698
+ try {
15699
+ const objs = fabricInstance.getObjects().slice();
15700
+ for (const obj of objs) {
15701
+ const isGroupLike = obj instanceof fabric.Group || (obj == null ? void 0 : obj.type) === "group" || Array.isArray(obj == null ? void 0 : obj._objects);
15702
+ const isFadedCropGroup = isGroupLike && (Boolean(obj.__edgeFadeRenderConfig) || Boolean(obj.__edgeFadeKey) || Boolean(obj.__edgeFadeInputKey));
15703
+ if (!isFadedCropGroup) continue;
15704
+ try {
15705
+ const baked = obj.toCanvasElement({
15706
+ multiplier: 2,
15707
+ enableRetinaScaling: false
15708
+ });
15709
+ const rect = obj.getBoundingRect();
15710
+ const replacement = new fabric.FabricImage(baked, {
15711
+ left: rect.left,
15712
+ top: rect.top,
15713
+ originX: "left",
15714
+ originY: "top",
15715
+ scaleX: rect.width / baked.width,
15716
+ scaleY: rect.height / baked.height,
15717
+ selectable: false,
15718
+ evented: false,
15719
+ objectCaching: false
15720
+ });
15721
+ const insertIndex = fabricInstance._objects.indexOf(obj);
15722
+ const prevExclude = obj.excludeFromExport;
15723
+ obj.excludeFromExport = true;
15724
+ if (insertIndex >= 0) {
15725
+ fabricInstance.insertAt(insertIndex + 1, replacement);
15726
+ } else {
15727
+ fabricInstance.add(replacement);
15728
+ }
15729
+ fadeBakeRecords.push({ original: obj, replacement, prevExclude, insertIndex });
15730
+ } catch (bakeErr) {
15731
+ console.warn("[canvas-svg-capture][edgeFade] bake failed:", bakeErr);
15732
+ }
15733
+ }
15734
+ if (fadeBakeRecords.length) {
15735
+ fabricInstance.renderAll();
15736
+ console.log(`[canvas-svg-capture][edgeFade] baked ${fadeBakeRecords.length} faded object(s)`);
15737
+ }
15738
+ } catch (e) {
15739
+ console.warn("[canvas-svg-capture][edgeFade] bake pass error:", e);
15740
+ }
15741
+ let svgString = "";
15742
+ try {
15743
+ const raw = fabricInstance.toSVG();
15744
+ svgString = normalizeSvgDimensions(raw, canvasWidth, canvasHeight);
15745
+ } finally {
15746
+ for (const rec of fadeBakeRecords) {
15747
+ try {
15748
+ fabricInstance.remove(rec.replacement);
15749
+ rec.original.excludeFromExport = rec.prevExclude;
15750
+ } catch {
15751
+ }
15752
+ }
15753
+ try {
15754
+ fabricInstance.enableRetinaScaling = prevRetina;
15755
+ fabricInstance.setDimensions(
15756
+ { width: prevWidth, height: prevHeight },
15757
+ { cssOnly: false, backstoreOnly: false }
15758
+ );
15759
+ } catch {
15760
+ }
15761
+ if (prevVPT) fabricInstance.viewportTransform = prevVPT;
15762
+ fabricInstance.svgViewportTransformation = prevSvgVPT;
15763
+ }
15764
+ return svgString;
15765
+ }
15766
+ const PACKAGE_VERSION = "0.5.126";
15646
15767
  const roundParityValue = (value) => {
15647
15768
  if (typeof value !== "number") return value;
15648
15769
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16061,7 +16182,7 @@ class PixldocsRenderer {
16061
16182
  await this.waitForCanvasScene(container, cloned, i);
16062
16183
  }
16063
16184
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
16064
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CWJRsyl0.js");
16185
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-ix7Z1pGO.js");
16065
16186
  const prepared = preparePagesForExport(
16066
16187
  cloned.pages,
16067
16188
  canvasWidth,
@@ -16539,88 +16660,11 @@ class PixldocsRenderer {
16539
16660
  reject(new Error("No Fabric canvas instance found for SVG capture"));
16540
16661
  return;
16541
16662
  }
16542
- const prevVPT = fabricInstance.viewportTransform ? [...fabricInstance.viewportTransform] : void 0;
16543
- const prevSvgVPT = fabricInstance.svgViewportTransformation;
16544
- const prevRetina = fabricInstance.enableRetinaScaling;
16545
- const prevWidth = fabricInstance.width;
16546
- const prevHeight = fabricInstance.height;
16547
- fabricInstance.viewportTransform = [1, 0, 0, 1, 0, 0];
16548
- fabricInstance.svgViewportTransformation = false;
16549
- fabricInstance.enableRetinaScaling = false;
16550
- fabricInstance.setDimensions(
16551
- { width: canvasWidth, height: canvasHeight },
16552
- { cssOnly: false, backstoreOnly: false }
16553
- );
16554
- const fadeBakeRecords = [];
16555
- try {
16556
- const objs = fabricInstance.getObjects().slice();
16557
- for (const obj of objs) {
16558
- const isFadedCropGroup = obj instanceof fabric.Group && (Boolean(obj.__edgeFadeRenderConfig) || Boolean(obj.__edgeFadeKey) || Boolean(obj.__edgeFadeInputKey));
16559
- if (!isFadedCropGroup) continue;
16560
- try {
16561
- const baked = obj.toCanvasElement({
16562
- multiplier: 2,
16563
- enableRetinaScaling: false
16564
- });
16565
- const rect = obj.getBoundingRect();
16566
- const replacement = new fabric.FabricImage(baked, {
16567
- left: rect.left,
16568
- top: rect.top,
16569
- originX: "left",
16570
- originY: "top",
16571
- scaleX: rect.width / baked.width,
16572
- scaleY: rect.height / baked.height,
16573
- selectable: false,
16574
- evented: false,
16575
- objectCaching: false
16576
- });
16577
- const insertIndex = fabricInstance._objects.indexOf(obj);
16578
- const prevExclude = obj.excludeFromExport;
16579
- obj.excludeFromExport = true;
16580
- if (insertIndex >= 0) {
16581
- fabricInstance.insertAt(insertIndex + 1, replacement);
16582
- } else {
16583
- fabricInstance.add(replacement);
16584
- }
16585
- fadeBakeRecords.push({
16586
- original: obj,
16587
- replacement,
16588
- prevExclude,
16589
- insertIndex
16590
- });
16591
- } catch (bakeErr) {
16592
- console.warn("[canvas-renderer][edgeFade] bake-for-svg failed:", bakeErr);
16593
- }
16594
- }
16595
- if (fadeBakeRecords.length) {
16596
- fabricInstance.renderAll();
16597
- console.log(
16598
- `[canvas-renderer][edgeFade] baked ${fadeBakeRecords.length} faded object(s) for SVG capture`
16599
- );
16600
- }
16601
- } catch (e) {
16602
- console.warn("[canvas-renderer][edgeFade] bake pass failed:", e);
16603
- }
16604
- const rawSvgString = fabricInstance.toSVG();
16605
- const svgString = this.normalizeSvgDimensions(
16606
- rawSvgString,
16663
+ const svgString = captureFabricCanvasSvgForPdf(
16664
+ fabricInstance,
16607
16665
  canvasWidth,
16608
16666
  canvasHeight
16609
16667
  );
16610
- for (const rec of fadeBakeRecords) {
16611
- try {
16612
- fabricInstance.remove(rec.replacement);
16613
- rec.original.excludeFromExport = rec.prevExclude;
16614
- } catch {
16615
- }
16616
- }
16617
- fabricInstance.enableRetinaScaling = prevRetina;
16618
- fabricInstance.setDimensions(
16619
- { width: prevWidth, height: prevHeight },
16620
- { cssOnly: false, backstoreOnly: false }
16621
- );
16622
- if (prevVPT) fabricInstance.viewportTransform = prevVPT;
16623
- fabricInstance.svgViewportTransformation = prevSvgVPT;
16624
16668
  const page = renderConfig.pages[pageIndex];
16625
16669
  const backgroundColor = ((_a = page == null ? void 0 : page.settings) == null ? void 0 : _a.backgroundColor) || "#ffffff";
16626
16670
  const backgroundGradient = (_b = page == null ? void 0 : page.settings) == null ? void 0 : _b.backgroundGradient;
@@ -18417,56 +18461,57 @@ function setAutoShrinkDebug(enabled) {
18417
18461
  }
18418
18462
  export {
18419
18463
  API_URL as A,
18420
- configHasAutoShrinkText$1 as B,
18421
- dumpSvgTextDiagnostics as C,
18422
- embedFont as D,
18423
- embedFontsForConfig as E,
18464
+ collectImageUrls as B,
18465
+ configHasAutoShrinkText$1 as C,
18466
+ dumpSvgTextDiagnostics as D,
18467
+ embedFont as E,
18424
18468
  FONT_FALLBACK_DEVANAGARI as F,
18425
- embedFontsInPdf as G,
18426
- ensureFontsForResolvedConfig as H,
18427
- extractFontFamiliesFromSvgs as I,
18428
- getEmbeddedJsPDFFontName as J,
18429
- isBundledAssetUrl as K,
18430
- isFontAvailable as L,
18431
- isPrivateUrl as M,
18432
- loadGoogleFontCSS as N,
18433
- normalizeFontFamily as O,
18469
+ embedFontsForConfig as G,
18470
+ embedFontsInPdf as H,
18471
+ ensureFontsForResolvedConfig as I,
18472
+ extractFontFamiliesFromSvgs as J,
18473
+ getEmbeddedJsPDFFontName as K,
18474
+ isBundledAssetUrl as L,
18475
+ isFontAvailable as M,
18476
+ isPrivateUrl as N,
18477
+ loadGoogleFontCSS as O,
18434
18478
  PACKAGE_VERSION as P,
18435
- resolveFontWeight as Q,
18436
- resolveFromForm as R,
18437
- resolveTemplateData as S,
18479
+ normalizeFontFamily as Q,
18480
+ resolveFontWeight as R,
18481
+ resolveFromForm as S,
18438
18482
  TRIANGLE_STROKE_MITER_LIMIT as T,
18439
- rewriteSvgFontsForJsPDF as U,
18440
- setAutoShrinkDebug as V,
18441
- setBundledAssetPrefixes as W,
18442
- warmResolvedTemplateForPreview as X,
18443
- warmTemplateFromForm as Y,
18444
- canvasImageLoader as Z,
18483
+ resolveTemplateData as U,
18484
+ rewriteSvgFontsForJsPDF as V,
18485
+ setAutoShrinkDebug as W,
18486
+ setBundledAssetPrefixes as X,
18487
+ warmResolvedTemplateForPreview as Y,
18488
+ warmTemplateFromForm as Z,
18489
+ canvasImageLoader as _,
18445
18490
  getAbsoluteBounds as a,
18446
18491
  getProxiedImageUrl as b,
18447
- bakeEdgeFade as c,
18448
- isGroup as d,
18449
- buildRoundedTrianglePath as e,
18492
+ captureFabricCanvasSvgForPdf as c,
18493
+ bakeEdgeFade as d,
18494
+ isGroup as e,
18450
18495
  findNodeById as f,
18451
18496
  getCanvasForPage as g,
18452
18497
  hasEdgeFade as h,
18453
18498
  isElement as i,
18454
- getImageProxyFetchOptions as j,
18455
- getRoundedRectRadii as k,
18456
- getTrianglePoints as l,
18457
- FONT_FALLBACK_MATH as m,
18499
+ buildRoundedTrianglePath as j,
18500
+ getImageProxyFetchOptions as k,
18501
+ getRoundedRectRadii as l,
18502
+ getTrianglePoints as m,
18458
18503
  normalizeShapeType as n,
18459
- FONT_FALLBACK_SYMBOLS as o,
18504
+ FONT_FALLBACK_MATH as o,
18460
18505
  parseTextMarkdown as p,
18461
- FONT_FILES as q,
18506
+ FONT_FALLBACK_SYMBOLS as q,
18462
18507
  renderSmartElementToSvg as r,
18463
- PixldocsPreview as s,
18464
- PixldocsRenderer as t,
18465
- applyThemeToConfig as u,
18466
- assemblePdfFromSvgs as v,
18467
- awaitFontsForConfig as w,
18468
- collectFontDescriptorsFromConfig as x,
18469
- collectFontsFromConfig as y,
18470
- collectImageUrls as z
18508
+ FONT_FILES as s,
18509
+ PixldocsPreview as t,
18510
+ PixldocsRenderer as u,
18511
+ applyThemeToConfig as v,
18512
+ assemblePdfFromSvgs as w,
18513
+ awaitFontsForConfig as x,
18514
+ collectFontDescriptorsFromConfig as y,
18515
+ collectFontsFromConfig as z
18471
18516
  };
18472
- //# sourceMappingURL=index-HIMi3Y6V.js.map
18517
+ //# sourceMappingURL=index-D-lngEWM.js.map