@pixldocs/canvas-renderer 0.5.125 → 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.125";
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-BBV3abJi.js");
16185
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-ix7Z1pGO.js");
16065
16186
  const prepared = preparePagesForExport(
16066
16187
  cloned.pages,
16067
16188
  canvasWidth,
@@ -16539,89 +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 isGroupLike = obj instanceof fabric.Group || (obj == null ? void 0 : obj.type) === "group" || Array.isArray(obj == null ? void 0 : obj._objects);
16559
- const isFadedCropGroup = isGroupLike && (Boolean(obj.__edgeFadeRenderConfig) || Boolean(obj.__edgeFadeKey) || Boolean(obj.__edgeFadeInputKey));
16560
- if (!isFadedCropGroup) continue;
16561
- try {
16562
- const baked = obj.toCanvasElement({
16563
- multiplier: 2,
16564
- enableRetinaScaling: false
16565
- });
16566
- const rect = obj.getBoundingRect();
16567
- const replacement = new fabric.FabricImage(baked, {
16568
- left: rect.left,
16569
- top: rect.top,
16570
- originX: "left",
16571
- originY: "top",
16572
- scaleX: rect.width / baked.width,
16573
- scaleY: rect.height / baked.height,
16574
- selectable: false,
16575
- evented: false,
16576
- objectCaching: false
16577
- });
16578
- const insertIndex = fabricInstance._objects.indexOf(obj);
16579
- const prevExclude = obj.excludeFromExport;
16580
- obj.excludeFromExport = true;
16581
- if (insertIndex >= 0) {
16582
- fabricInstance.insertAt(insertIndex + 1, replacement);
16583
- } else {
16584
- fabricInstance.add(replacement);
16585
- }
16586
- fadeBakeRecords.push({
16587
- original: obj,
16588
- replacement,
16589
- prevExclude,
16590
- insertIndex
16591
- });
16592
- } catch (bakeErr) {
16593
- console.warn("[canvas-renderer][edgeFade] bake-for-svg failed:", bakeErr);
16594
- }
16595
- }
16596
- if (fadeBakeRecords.length) {
16597
- fabricInstance.renderAll();
16598
- console.log(
16599
- `[canvas-renderer][edgeFade] baked ${fadeBakeRecords.length} faded object(s) for SVG capture`
16600
- );
16601
- }
16602
- } catch (e) {
16603
- console.warn("[canvas-renderer][edgeFade] bake pass failed:", e);
16604
- }
16605
- const rawSvgString = fabricInstance.toSVG();
16606
- const svgString = this.normalizeSvgDimensions(
16607
- rawSvgString,
16663
+ const svgString = captureFabricCanvasSvgForPdf(
16664
+ fabricInstance,
16608
16665
  canvasWidth,
16609
16666
  canvasHeight
16610
16667
  );
16611
- for (const rec of fadeBakeRecords) {
16612
- try {
16613
- fabricInstance.remove(rec.replacement);
16614
- rec.original.excludeFromExport = rec.prevExclude;
16615
- } catch {
16616
- }
16617
- }
16618
- fabricInstance.enableRetinaScaling = prevRetina;
16619
- fabricInstance.setDimensions(
16620
- { width: prevWidth, height: prevHeight },
16621
- { cssOnly: false, backstoreOnly: false }
16622
- );
16623
- if (prevVPT) fabricInstance.viewportTransform = prevVPT;
16624
- fabricInstance.svgViewportTransformation = prevSvgVPT;
16625
16668
  const page = renderConfig.pages[pageIndex];
16626
16669
  const backgroundColor = ((_a = page == null ? void 0 : page.settings) == null ? void 0 : _a.backgroundColor) || "#ffffff";
16627
16670
  const backgroundGradient = (_b = page == null ? void 0 : page.settings) == null ? void 0 : _b.backgroundGradient;
@@ -18418,56 +18461,57 @@ function setAutoShrinkDebug(enabled) {
18418
18461
  }
18419
18462
  export {
18420
18463
  API_URL as A,
18421
- configHasAutoShrinkText$1 as B,
18422
- dumpSvgTextDiagnostics as C,
18423
- embedFont as D,
18424
- embedFontsForConfig as E,
18464
+ collectImageUrls as B,
18465
+ configHasAutoShrinkText$1 as C,
18466
+ dumpSvgTextDiagnostics as D,
18467
+ embedFont as E,
18425
18468
  FONT_FALLBACK_DEVANAGARI as F,
18426
- embedFontsInPdf as G,
18427
- ensureFontsForResolvedConfig as H,
18428
- extractFontFamiliesFromSvgs as I,
18429
- getEmbeddedJsPDFFontName as J,
18430
- isBundledAssetUrl as K,
18431
- isFontAvailable as L,
18432
- isPrivateUrl as M,
18433
- loadGoogleFontCSS as N,
18434
- 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,
18435
18478
  PACKAGE_VERSION as P,
18436
- resolveFontWeight as Q,
18437
- resolveFromForm as R,
18438
- resolveTemplateData as S,
18479
+ normalizeFontFamily as Q,
18480
+ resolveFontWeight as R,
18481
+ resolveFromForm as S,
18439
18482
  TRIANGLE_STROKE_MITER_LIMIT as T,
18440
- rewriteSvgFontsForJsPDF as U,
18441
- setAutoShrinkDebug as V,
18442
- setBundledAssetPrefixes as W,
18443
- warmResolvedTemplateForPreview as X,
18444
- warmTemplateFromForm as Y,
18445
- 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 _,
18446
18490
  getAbsoluteBounds as a,
18447
18491
  getProxiedImageUrl as b,
18448
- bakeEdgeFade as c,
18449
- isGroup as d,
18450
- buildRoundedTrianglePath as e,
18492
+ captureFabricCanvasSvgForPdf as c,
18493
+ bakeEdgeFade as d,
18494
+ isGroup as e,
18451
18495
  findNodeById as f,
18452
18496
  getCanvasForPage as g,
18453
18497
  hasEdgeFade as h,
18454
18498
  isElement as i,
18455
- getImageProxyFetchOptions as j,
18456
- getRoundedRectRadii as k,
18457
- getTrianglePoints as l,
18458
- FONT_FALLBACK_MATH as m,
18499
+ buildRoundedTrianglePath as j,
18500
+ getImageProxyFetchOptions as k,
18501
+ getRoundedRectRadii as l,
18502
+ getTrianglePoints as m,
18459
18503
  normalizeShapeType as n,
18460
- FONT_FALLBACK_SYMBOLS as o,
18504
+ FONT_FALLBACK_MATH as o,
18461
18505
  parseTextMarkdown as p,
18462
- FONT_FILES as q,
18506
+ FONT_FALLBACK_SYMBOLS as q,
18463
18507
  renderSmartElementToSvg as r,
18464
- PixldocsPreview as s,
18465
- PixldocsRenderer as t,
18466
- applyThemeToConfig as u,
18467
- assemblePdfFromSvgs as v,
18468
- awaitFontsForConfig as w,
18469
- collectFontDescriptorsFromConfig as x,
18470
- collectFontsFromConfig as y,
18471
- 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
18472
18516
  };
18473
- //# sourceMappingURL=index-D7cGwzxX.js.map
18517
+ //# sourceMappingURL=index-D-lngEWM.js.map