@pixldocs/canvas-renderer 0.5.186 → 0.5.188

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.
@@ -16115,6 +16115,162 @@ async function getTemplateForm(options) {
16115
16115
  initialSectionState
16116
16116
  };
16117
16117
  }
16118
+ const OVERLAY_ID_PREFIX = "__pb_";
16119
+ function getNumber(v, fallback = 0) {
16120
+ return typeof v === "number" && Number.isFinite(v) ? v : fallback;
16121
+ }
16122
+ function resolveSize(node, key) {
16123
+ const v = node == null ? void 0 : node[key];
16124
+ if (typeof v === "number" && Number.isFinite(v)) return v;
16125
+ return 0;
16126
+ }
16127
+ function collectOverlays(node, parentLeft, parentTop, inheritedBlur, extraBaseIds, extraExactIds, out) {
16128
+ if (!node || typeof node !== "object") return;
16129
+ const matchesBase = !!(extraBaseIds && typeof node.id === "string" && extraBaseIds.has(baseId(node.id)));
16130
+ const matchesExact = !!(extraExactIds && typeof node.id === "string" && extraExactIds.has(node.id));
16131
+ const isBlurred = inheritedBlur || node.previewBlur === true || matchesBase || matchesExact;
16132
+ const absLeft = parentLeft + getNumber(node.left, 0);
16133
+ const absTop = parentTop + getNumber(node.top, 0);
16134
+ if (node.type === "group") {
16135
+ const children = node.children || node.elements;
16136
+ if (Array.isArray(children)) {
16137
+ for (const child of children) {
16138
+ collectOverlays(child, absLeft, absTop, isBlurred, extraBaseIds, extraExactIds, out);
16139
+ }
16140
+ }
16141
+ return;
16142
+ }
16143
+ if (!isBlurred) return;
16144
+ const scaleX = getNumber(node.scaleX, 1) || 1;
16145
+ const scaleY = getNumber(node.scaleY, 1) || 1;
16146
+ const w = Math.max(4, resolveSize(node, "width") * scaleX);
16147
+ const h = Math.max(4, resolveSize(node, "height") * scaleY);
16148
+ out.push({
16149
+ left: absLeft,
16150
+ top: absTop,
16151
+ width: w,
16152
+ height: h,
16153
+ hintFill: typeof node.fill === "string" ? node.fill : void 0
16154
+ });
16155
+ }
16156
+ function parseColor$1(c) {
16157
+ if (!c) return null;
16158
+ const s = c.trim();
16159
+ const hex = s.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
16160
+ if (hex) {
16161
+ let h = hex[1];
16162
+ if (h.length === 3) h = h.split("").map((x) => x + x).join("");
16163
+ return {
16164
+ r: parseInt(h.slice(0, 2), 16),
16165
+ g: parseInt(h.slice(2, 4), 16),
16166
+ b: parseInt(h.slice(4, 6), 16)
16167
+ };
16168
+ }
16169
+ const rgb = s.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);
16170
+ if (rgb) return { r: +rgb[1], g: +rgb[2], b: +rgb[3] };
16171
+ return null;
16172
+ }
16173
+ function buildOverlay(b, idx) {
16174
+ const c = parseColor$1(b.hintFill);
16175
+ const lum = c ? (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) / 255 : 0.2;
16176
+ const isLightGlass = lum < 0.5;
16177
+ const baseFill = isLightGlass ? "rgba(245,245,245,0.68)" : "rgba(30,30,30,0.62)";
16178
+ return {
16179
+ id: `${OVERLAY_ID_PREFIX}${idx}`,
16180
+ type: "shape",
16181
+ shapeType: "rounded-rect",
16182
+ left: b.left,
16183
+ top: b.top,
16184
+ width: b.width,
16185
+ height: b.height,
16186
+ cornerRadius: 0,
16187
+ fill: baseFill,
16188
+ stroke: "transparent",
16189
+ strokeWidth: 0,
16190
+ opacity: 1,
16191
+ selectable: false,
16192
+ locked: true,
16193
+ visible: true,
16194
+ scaleX: 1,
16195
+ scaleY: 1
16196
+ };
16197
+ }
16198
+ function injectPreviewBlur(config, options) {
16199
+ const cloned = typeof structuredClone === "function" ? structuredClone(config) : JSON.parse(JSON.stringify(config));
16200
+ const extraBase = (options == null ? void 0 : options.extraElementBaseIds) && options.extraElementBaseIds.size > 0 ? options.extraElementBaseIds : void 0;
16201
+ const extraExact = (options == null ? void 0 : options.extraElementExactIds) && options.extraElementExactIds.size > 0 ? options.extraElementExactIds : void 0;
16202
+ let idx = 0;
16203
+ for (const page of cloned.pages || []) {
16204
+ const children = page.children || page.elements;
16205
+ if (!Array.isArray(children)) continue;
16206
+ const overlays = [];
16207
+ for (const child of children) {
16208
+ collectOverlays(child, 0, 0, false, extraBase, extraExact, overlays);
16209
+ }
16210
+ if (overlays.length === 0) continue;
16211
+ for (const b of overlays) {
16212
+ children.push(buildOverlay(b, idx++));
16213
+ }
16214
+ }
16215
+ return cloned;
16216
+ }
16217
+ function hasAnyPreviewBlur(config) {
16218
+ function walk(node) {
16219
+ if (!node || typeof node !== "object") return false;
16220
+ if (node.previewBlur === true) return true;
16221
+ const children = node.children || node.elements;
16222
+ if (Array.isArray(children)) {
16223
+ for (const c of children) if (walk(c)) return true;
16224
+ }
16225
+ return false;
16226
+ }
16227
+ for (const page of config.pages || []) if (walk(page)) return true;
16228
+ return false;
16229
+ }
16230
+ function stripFieldPrefix(s) {
16231
+ return s.startsWith("field_") ? s.slice("field_".length) : s;
16232
+ }
16233
+ function addAllToSet(val, out) {
16234
+ if (!val) return false;
16235
+ if (Array.isArray(val)) {
16236
+ for (const v of val) out.add(v);
16237
+ return val.length > 0;
16238
+ }
16239
+ out.add(val);
16240
+ return true;
16241
+ }
16242
+ function resolveBlurElementExactIdsFromFlatFormKeys(config, flatFormKeys, options) {
16243
+ const cloneIdMap = (config == null ? void 0 : config.__cloneIdMap) || {};
16244
+ if (!cloneIdMap || typeof cloneIdMap !== "object") return [];
16245
+ const bindings = (options == null ? void 0 : options.bindings) ?? "value";
16246
+ const out = /* @__PURE__ */ new Set();
16247
+ for (const rawId of flatFormKeys) {
16248
+ if (typeof rawId !== "string" || !rawId) continue;
16249
+ if (bindings === "value" && !rawId.endsWith("_value")) continue;
16250
+ const candidates = [rawId];
16251
+ if (rawId.startsWith("field_")) {
16252
+ const topStripped = stripFieldPrefix(rawId);
16253
+ candidates.push(topStripped);
16254
+ const nestedIdx = topStripped.indexOf("_field_");
16255
+ if (nestedIdx >= 0) {
16256
+ const nestedStripped = topStripped.slice(0, nestedIdx + 1) + topStripped.slice(nestedIdx + 1 + "field_".length);
16257
+ candidates.push(nestedStripped);
16258
+ }
16259
+ }
16260
+ for (const k of candidates) {
16261
+ if (k in cloneIdMap) {
16262
+ if (addAllToSet(cloneIdMap[k], out)) break;
16263
+ }
16264
+ }
16265
+ }
16266
+ return Array.from(out);
16267
+ }
16268
+ const previewBlur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
16269
+ __proto__: null,
16270
+ hasAnyPreviewBlur,
16271
+ injectPreviewBlur,
16272
+ resolveBlurElementExactIdsFromFlatFormKeys
16273
+ }, Symbol.toStringTag, { value: "Module" }));
16118
16274
  const PREVIEW_DEBUG_PREFIX = "[canvas-renderer][preview-debug]";
16119
16275
  function computeFontSignature(config) {
16120
16276
  var _a;
@@ -16208,7 +16364,9 @@ function PixldocsPreview(props) {
16208
16364
  frostedBlur = true,
16209
16365
  frostedBlurOptions,
16210
16366
  blurFieldIds,
16211
- blurElementExactIds
16367
+ blurElementExactIds,
16368
+ blurFlatFormKeys,
16369
+ blurFlatFormKeyOptions
16212
16370
  } = props;
16213
16371
  useEffect(() => {
16214
16372
  setPackageApiUrl(imageProxyUrl);
@@ -16329,8 +16487,26 @@ function PixldocsPreview(props) {
16329
16487
  [blurFieldIds ? blurFieldIds.join("|") : ""]
16330
16488
  );
16331
16489
  const blurExactSet = useMemo(
16332
- () => blurElementExactIds && blurElementExactIds.length ? new Set(blurElementExactIds) : void 0,
16333
- [blurElementExactIds ? blurElementExactIds.join("|") : ""]
16490
+ () => {
16491
+ const merged = /* @__PURE__ */ new Set();
16492
+ if (blurElementExactIds) for (const id of blurElementExactIds) merged.add(id);
16493
+ if (config && blurFlatFormKeys && blurFlatFormKeys.length) {
16494
+ for (const id of resolveBlurElementExactIdsFromFlatFormKeys(
16495
+ config,
16496
+ blurFlatFormKeys,
16497
+ blurFlatFormKeyOptions
16498
+ )) {
16499
+ merged.add(id);
16500
+ }
16501
+ }
16502
+ return merged.size > 0 ? merged : void 0;
16503
+ },
16504
+ [
16505
+ blurElementExactIds ? blurElementExactIds.join("|") : "",
16506
+ blurFlatFormKeys ? blurFlatFormKeys.join("|") : "",
16507
+ blurFlatFormKeyOptions == null ? void 0 : blurFlatFormKeyOptions.bindings,
16508
+ config
16509
+ ]
16334
16510
  );
16335
16511
  const frostedBounds = useMemo(
16336
16512
  () => frostedBlur ? computeFrostedBoundsForPage(config, pageIndex, blurBaseSet, blurExactSet) : [],
@@ -16575,9 +16751,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16575
16751
  }
16576
16752
  return svgString;
16577
16753
  }
16578
- const resolvedPackageVersion = "0.5.186";
16754
+ const resolvedPackageVersion = "0.5.188";
16579
16755
  const PACKAGE_VERSION = resolvedPackageVersion;
16580
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.186";
16756
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.188";
16581
16757
  const roundParityValue = (value) => {
16582
16758
  if (typeof value !== "number") return value;
16583
16759
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -16876,8 +17052,8 @@ class PixldocsRenderer {
16876
17052
  if (shouldWatermark) {
16877
17053
  const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
16878
17054
  configToRender = injectWatermark(configToRender, watermarkOptions);
16879
- const { injectPreviewBlur } = await import("./previewBlur-CDBjIIjX.js");
16880
- configToRender = injectPreviewBlur(configToRender);
17055
+ const { injectPreviewBlur: injectPreviewBlur2 } = await Promise.resolve().then(() => previewBlur);
17056
+ configToRender = injectPreviewBlur2(configToRender);
16881
17057
  }
16882
17058
  return this.renderAllPages(configToRender, renderOpts);
16883
17059
  }
@@ -16935,8 +17111,8 @@ class PixldocsRenderer {
16935
17111
  if (shouldWatermark) {
16936
17112
  const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
16937
17113
  configToRender = injectWatermark(configToRender, watermarkOptions);
16938
- const { injectPreviewBlur } = await import("./previewBlur-CDBjIIjX.js");
16939
- configToRender = injectPreviewBlur(configToRender);
17114
+ const { injectPreviewBlur: injectPreviewBlur2 } = await Promise.resolve().then(() => previewBlur);
17115
+ configToRender = injectPreviewBlur2(configToRender);
16940
17116
  }
16941
17117
  return this.renderAllPageSvgs(configToRender);
16942
17118
  }
@@ -16979,8 +17155,8 @@ class PixldocsRenderer {
16979
17155
  if (shouldWatermark) {
16980
17156
  const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
16981
17157
  configToRender = injectWatermark(configToRender, watermarkOptions);
16982
- const { injectPreviewBlur } = await import("./previewBlur-CDBjIIjX.js");
16983
- configToRender = injectPreviewBlur(configToRender);
17158
+ const { injectPreviewBlur: injectPreviewBlur2 } = await Promise.resolve().then(() => previewBlur);
17159
+ configToRender = injectPreviewBlur2(configToRender);
16984
17160
  }
16985
17161
  return this.renderPdfViaClientExport(configToRender, {
16986
17162
  title: title ?? resolved.config.name,
@@ -17085,7 +17261,7 @@ class PixldocsRenderer {
17085
17261
  await this.waitForCanvasScene(container, cloned, i);
17086
17262
  }
17087
17263
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
17088
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-v3mr9nks.js");
17264
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CSh0zFox.js");
17089
17265
  const prepared = preparePagesForExport(
17090
17266
  cloned.pages,
17091
17267
  canvasWidth,
@@ -19230,7 +19406,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
19230
19406
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
19231
19407
  sanitizeSvgTreeForPdf(svgToDraw);
19232
19408
  try {
19233
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-v3mr9nks.js");
19409
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CSh0zFox.js");
19234
19410
  try {
19235
19411
  await logTextMeasurementDiagnostic(svgToDraw);
19236
19412
  } catch {
@@ -19568,63 +19744,65 @@ function setAutoShrinkDebug(enabled) {
19568
19744
  }
19569
19745
  }
19570
19746
  export {
19571
- setAutoShrinkDebug as $,
19747
+ resolveTemplateData as $,
19572
19748
  API_URL as A,
19573
- collectFontsFromConfig as B,
19574
- collectImageUrls as C,
19749
+ collectImageUrls as B,
19750
+ configHasAutoShrinkText$1 as C,
19575
19751
  DEPLOYMENT_VERSION_MARKER as D,
19576
- configHasAutoShrinkText$1 as E,
19752
+ dumpSvgTextDiagnostics as E,
19577
19753
  FONT_FALLBACK_DEVANAGARI as F,
19578
- dumpSvgTextDiagnostics as G,
19579
- embedFont as H,
19580
- embedFontsForConfig as I,
19581
- embedFontsInPdf as J,
19582
- ensureFontsForResolvedConfig as K,
19583
- extractFontFamiliesFromSvgs as L,
19584
- getEmbeddedJsPDFFontName as M,
19585
- getPublishedTemplate as N,
19586
- getTemplateForm as O,
19754
+ embedFont as G,
19755
+ embedFontsForConfig as H,
19756
+ embedFontsInPdf as I,
19757
+ ensureFontsForResolvedConfig as J,
19758
+ extractFontFamiliesFromSvgs as K,
19759
+ getEmbeddedJsPDFFontName as L,
19760
+ getPublishedTemplate as M,
19761
+ getTemplateForm as N,
19762
+ hasAnyPreviewBlur as O,
19587
19763
  PACKAGE_VERSION as P,
19588
- isBundledAssetUrl as Q,
19589
- isFontAvailable as R,
19590
- isPrivateUrl as S,
19764
+ injectPreviewBlur as Q,
19765
+ isBundledAssetUrl as R,
19766
+ isFontAvailable as S,
19591
19767
  TRIANGLE_STROKE_MITER_LIMIT as T,
19592
- listPublishedTemplates as U,
19593
- loadGoogleFontCSS as V,
19594
- normalizeFontFamily as W,
19595
- resolveFontWeight as X,
19596
- resolveFromForm as Y,
19597
- resolveTemplateData as Z,
19598
- rewriteSvgFontsForJsPDF as _,
19768
+ isPrivateUrl as U,
19769
+ listPublishedTemplates as V,
19770
+ loadGoogleFontCSS as W,
19771
+ normalizeFontFamily as X,
19772
+ resolveBlurElementExactIdsFromFlatFormKeys as Y,
19773
+ resolveFontWeight as Z,
19774
+ resolveFromForm as _,
19599
19775
  getAbsoluteBounds as a,
19600
- setBundledAssetPrefixes as a0,
19601
- warmResolvedTemplateForPreview as a1,
19602
- warmTemplateFromForm as a2,
19603
- canvasImageLoader as a3,
19604
- baseId as b,
19776
+ rewriteSvgFontsForJsPDF as a0,
19777
+ setAutoShrinkDebug as a1,
19778
+ setBundledAssetPrefixes as a2,
19779
+ warmResolvedTemplateForPreview as a3,
19780
+ warmTemplateFromForm as a4,
19781
+ canvasImageLoader as a5,
19782
+ getProxiedImageUrl as b,
19605
19783
  captureFabricCanvasSvgForPdf as c,
19606
- getProxiedImageUrl as d,
19607
- bakeEdgeFade as e,
19784
+ bakeEdgeFade as d,
19785
+ isGroup as e,
19608
19786
  findNodeById as f,
19609
19787
  getCanvasForPage as g,
19610
19788
  hasEdgeFade as h,
19611
19789
  isElement as i,
19612
- isGroup as j,
19613
- buildRoundedTrianglePath as k,
19614
- getImageProxyFetchOptions as l,
19615
- getRoundedRectRadii as m,
19790
+ buildRoundedTrianglePath as j,
19791
+ getImageProxyFetchOptions as k,
19792
+ getRoundedRectRadii as l,
19793
+ getTrianglePoints as m,
19616
19794
  normalizeShapeType as n,
19617
- getTrianglePoints as o,
19795
+ FONT_FALLBACK_MATH as o,
19618
19796
  parseTextMarkdown as p,
19619
- FONT_FALLBACK_MATH as q,
19797
+ FONT_FALLBACK_SYMBOLS as q,
19620
19798
  renderSmartElementToSvg as r,
19621
- FONT_FALLBACK_SYMBOLS as s,
19622
- FONT_FILES as t,
19623
- PixldocsPreview as u,
19624
- PixldocsRenderer as v,
19625
- applyThemeToConfig as w,
19626
- assemblePdfFromSvgs as x,
19627
- awaitFontsForConfig as y,
19628
- collectFontDescriptorsFromConfig as z
19799
+ FONT_FILES as s,
19800
+ PixldocsPreview as t,
19801
+ PixldocsRenderer as u,
19802
+ applyThemeToConfig as v,
19803
+ assemblePdfFromSvgs as w,
19804
+ awaitFontsForConfig as x,
19805
+ collectFontDescriptorsFromConfig as y,
19806
+ collectFontsFromConfig as z
19629
19807
  };
19630
- //# sourceMappingURL=index-Xg0sHfrw.js.map
19808
+ //# sourceMappingURL=index-CjZZhQH6.js.map