@pixldocs/canvas-renderer 0.5.187 → 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,10 +16115,122 @@ 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
+ }
16118
16230
  function stripFieldPrefix(s) {
16119
16231
  return s.startsWith("field_") ? s.slice("field_".length) : s;
16120
16232
  }
16121
- function addAll(val, out) {
16233
+ function addAllToSet(val, out) {
16122
16234
  if (!val) return false;
16123
16235
  if (Array.isArray(val)) {
16124
16236
  for (const v of val) out.add(v);
@@ -16147,12 +16259,18 @@ function resolveBlurElementExactIdsFromFlatFormKeys(config, flatFormKeys, option
16147
16259
  }
16148
16260
  for (const k of candidates) {
16149
16261
  if (k in cloneIdMap) {
16150
- if (addAll(cloneIdMap[k], out)) break;
16262
+ if (addAllToSet(cloneIdMap[k], out)) break;
16151
16263
  }
16152
16264
  }
16153
16265
  }
16154
16266
  return Array.from(out);
16155
16267
  }
16268
+ const previewBlur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
16269
+ __proto__: null,
16270
+ hasAnyPreviewBlur,
16271
+ injectPreviewBlur,
16272
+ resolveBlurElementExactIdsFromFlatFormKeys
16273
+ }, Symbol.toStringTag, { value: "Module" }));
16156
16274
  const PREVIEW_DEBUG_PREFIX = "[canvas-renderer][preview-debug]";
16157
16275
  function computeFontSignature(config) {
16158
16276
  var _a;
@@ -16633,9 +16751,9 @@ function captureFabricCanvasSvgForPdf(fabricInstance, canvasWidth, canvasHeight)
16633
16751
  }
16634
16752
  return svgString;
16635
16753
  }
16636
- const resolvedPackageVersion = "0.5.187";
16754
+ const resolvedPackageVersion = "0.5.188";
16637
16755
  const PACKAGE_VERSION = resolvedPackageVersion;
16638
- const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.187";
16756
+ const DEPLOYMENT_VERSION_MARKER = "__PIXLDOCS_CANVAS_RENDERER_VERSION__:0.5.188";
16639
16757
  const roundParityValue = (value) => {
16640
16758
  if (typeof value !== "number") return value;
16641
16759
  return Number.isFinite(value) ? Number(value.toFixed(3)) : value;
@@ -17143,7 +17261,7 @@ class PixldocsRenderer {
17143
17261
  await this.waitForCanvasScene(container, cloned, i);
17144
17262
  }
17145
17263
  console.log(`[canvas-renderer][pdf-unified] mounted ${cloned.pages.length} page(s), handing off to client exportMultiPagePdf`);
17146
- const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-BkERGCkM.js");
17264
+ const { exportMultiPagePdf, preparePagesForExport } = await import("./vectorPdfExport-CSh0zFox.js");
17147
17265
  const prepared = preparePagesForExport(
17148
17266
  cloned.pages,
17149
17267
  canvasWidth,
@@ -17985,7 +18103,7 @@ function collectFontSpecsFromMarkup(markup) {
17985
18103
  }
17986
18104
  return Array.from(specs);
17987
18105
  }
17988
- function parseColor$1(color) {
18106
+ function parseColor(color) {
17989
18107
  if (!color) return null;
17990
18108
  const raw = color.trim().toLowerCase();
17991
18109
  if (!raw || raw === "transparent" || raw === "none") return null;
@@ -18538,7 +18656,7 @@ function stripSuspiciousFullPageOverlayNodes(svg) {
18538
18656
  if (!(pageWidth > 0 && pageHeight > 0)) return;
18539
18657
  const isNear = (a, b, tolerance = 0.75) => Math.abs(a - b) <= tolerance;
18540
18658
  const isDarkPaint = (value) => {
18541
- const rgb = value ? parseColor$1(value) : null;
18659
+ const rgb = value ? parseColor(value) : null;
18542
18660
  return rgb ? rgb.r <= 32 && rgb.g <= 32 && rgb.b <= 32 : false;
18543
18661
  };
18544
18662
  const removeIfSuspicious = (el) => {
@@ -18651,13 +18769,13 @@ function inlineComputedStyles(svg) {
18651
18769
  const fill = cs.fill;
18652
18770
  const stroke = cs.stroke;
18653
18771
  if (fill && fill !== "none" && fill !== "rgba(0, 0, 0, 0)") {
18654
- const parsed = parseColor$1(fill);
18772
+ const parsed = parseColor(fill);
18655
18773
  if (parsed) el.setAttribute("fill", rgbToHex(parsed.r, parsed.g, parsed.b));
18656
18774
  } else if (fill === "rgba(0, 0, 0, 0)" || fill === "transparent") {
18657
18775
  el.setAttribute("fill", "none");
18658
18776
  }
18659
18777
  if (stroke && stroke !== "none" && stroke !== "rgba(0, 0, 0, 0)") {
18660
- const parsed = parseColor$1(stroke);
18778
+ const parsed = parseColor(stroke);
18661
18779
  if (parsed) el.setAttribute("stroke", rgbToHex(parsed.r, parsed.g, parsed.b));
18662
18780
  }
18663
18781
  }
@@ -18805,7 +18923,7 @@ function setPdfColorFromSvg(pdf, svg, _elementId) {
18805
18923
  const { fill, stroke } = getFirstExplicitColorFromSvg(svg);
18806
18924
  const setColor = (hex, setter) => {
18807
18925
  if (!hex) return;
18808
- const c = parseColor$1(hex);
18926
+ const c = parseColor(hex);
18809
18927
  if (c) pdf[setter](c.r, c.g, c.b);
18810
18928
  };
18811
18929
  setColor(fill, "setFillColor");
@@ -19288,7 +19406,7 @@ async function prepareLiveCanvasSvgForPdf(rawSvg, pageWidth, pageHeight, pageKey
19288
19406
  if (options == null ? void 0 : options.stripPageBackground) stripRootPageBackgroundFromSvg(svgToDraw);
19289
19407
  sanitizeSvgTreeForPdf(svgToDraw);
19290
19408
  try {
19291
- const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-BkERGCkM.js");
19409
+ const { bakeTextAnchorPositionsFromLiveSvg, logTextMeasurementDiagnostic } = await import("./vectorPdfExport-CSh0zFox.js");
19292
19410
  try {
19293
19411
  await logTextMeasurementDiagnostic(svgToDraw);
19294
19412
  } catch {
@@ -19308,7 +19426,7 @@ function drawPageBackground(pdf, pageIndex, pageWidth, pageHeight, backgroundCol
19308
19426
  if (backgroundGradient && ((_a = backgroundGradient.stops) == null ? void 0 : _a.length) >= 2) {
19309
19427
  const grad = backgroundGradient;
19310
19428
  const colorStops = grad.stops.map((s) => {
19311
- const c = parseColor$1(s.color);
19429
+ const c = parseColor(s.color);
19312
19430
  return {
19313
19431
  offset: Math.max(0, Math.min(1, Number(s.offset))),
19314
19432
  color: c ? [c.r, c.g, c.b] : [0, 0, 0]
@@ -19364,7 +19482,7 @@ function drawPageBackground(pdf, pageIndex, pageWidth, pageHeight, backgroundCol
19364
19482
  pdf.rect(0, 0, pageWidth, pageHeight, "F");
19365
19483
  }
19366
19484
  } else {
19367
- const bgColor = parseColor$1(backgroundColor && backgroundColor !== "transparent" ? backgroundColor : "#ffffff");
19485
+ const bgColor = parseColor(backgroundColor && backgroundColor !== "transparent" ? backgroundColor : "#ffffff");
19368
19486
  if (bgColor) {
19369
19487
  pdf.setFillColor(bgColor.r, bgColor.g, bgColor.b);
19370
19488
  pdf.rect(0, 0, pageWidth, pageHeight, "F");
@@ -19487,123 +19605,6 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
19487
19605
  pages: svgResults.map((p) => ({ width: p.width, height: p.height }))
19488
19606
  };
19489
19607
  }
19490
- const OVERLAY_ID_PREFIX = "__pb_";
19491
- function getNumber(v, fallback = 0) {
19492
- return typeof v === "number" && Number.isFinite(v) ? v : fallback;
19493
- }
19494
- function resolveSize(node, key) {
19495
- const v = node == null ? void 0 : node[key];
19496
- if (typeof v === "number" && Number.isFinite(v)) return v;
19497
- return 0;
19498
- }
19499
- function collectOverlays(node, parentLeft, parentTop, inheritedBlur, extraBaseIds, extraExactIds, out) {
19500
- if (!node || typeof node !== "object") return;
19501
- const matchesBase = !!(extraBaseIds && typeof node.id === "string" && extraBaseIds.has(baseId(node.id)));
19502
- const matchesExact = !!(extraExactIds && typeof node.id === "string" && extraExactIds.has(node.id));
19503
- const isBlurred = inheritedBlur || node.previewBlur === true || matchesBase || matchesExact;
19504
- const absLeft = parentLeft + getNumber(node.left, 0);
19505
- const absTop = parentTop + getNumber(node.top, 0);
19506
- if (node.type === "group") {
19507
- const children = node.children || node.elements;
19508
- if (Array.isArray(children)) {
19509
- for (const child of children) {
19510
- collectOverlays(child, absLeft, absTop, isBlurred, extraBaseIds, extraExactIds, out);
19511
- }
19512
- }
19513
- return;
19514
- }
19515
- if (!isBlurred) return;
19516
- const scaleX = getNumber(node.scaleX, 1) || 1;
19517
- const scaleY = getNumber(node.scaleY, 1) || 1;
19518
- const w = Math.max(4, resolveSize(node, "width") * scaleX);
19519
- const h = Math.max(4, resolveSize(node, "height") * scaleY);
19520
- out.push({
19521
- left: absLeft,
19522
- top: absTop,
19523
- width: w,
19524
- height: h,
19525
- hintFill: typeof node.fill === "string" ? node.fill : void 0
19526
- });
19527
- }
19528
- function parseColor(c) {
19529
- if (!c) return null;
19530
- const s = c.trim();
19531
- const hex = s.match(/^#([0-9a-f]{3}|[0-9a-f]{6})$/i);
19532
- if (hex) {
19533
- let h = hex[1];
19534
- if (h.length === 3) h = h.split("").map((x) => x + x).join("");
19535
- return {
19536
- r: parseInt(h.slice(0, 2), 16),
19537
- g: parseInt(h.slice(2, 4), 16),
19538
- b: parseInt(h.slice(4, 6), 16)
19539
- };
19540
- }
19541
- const rgb = s.match(/^rgba?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)/i);
19542
- if (rgb) return { r: +rgb[1], g: +rgb[2], b: +rgb[3] };
19543
- return null;
19544
- }
19545
- function buildOverlay(b, idx) {
19546
- const c = parseColor(b.hintFill);
19547
- const lum = c ? (0.299 * c.r + 0.587 * c.g + 0.114 * c.b) / 255 : 0.2;
19548
- const isLightGlass = lum < 0.5;
19549
- const baseFill = isLightGlass ? "rgba(245,245,245,0.68)" : "rgba(30,30,30,0.62)";
19550
- return {
19551
- id: `${OVERLAY_ID_PREFIX}${idx}`,
19552
- type: "shape",
19553
- shapeType: "rounded-rect",
19554
- left: b.left,
19555
- top: b.top,
19556
- width: b.width,
19557
- height: b.height,
19558
- cornerRadius: 0,
19559
- fill: baseFill,
19560
- stroke: "transparent",
19561
- strokeWidth: 0,
19562
- opacity: 1,
19563
- selectable: false,
19564
- locked: true,
19565
- visible: true,
19566
- scaleX: 1,
19567
- scaleY: 1
19568
- };
19569
- }
19570
- function injectPreviewBlur(config, options) {
19571
- const cloned = typeof structuredClone === "function" ? structuredClone(config) : JSON.parse(JSON.stringify(config));
19572
- const extraBase = (options == null ? void 0 : options.extraElementBaseIds) && options.extraElementBaseIds.size > 0 ? options.extraElementBaseIds : void 0;
19573
- const extraExact = (options == null ? void 0 : options.extraElementExactIds) && options.extraElementExactIds.size > 0 ? options.extraElementExactIds : void 0;
19574
- let idx = 0;
19575
- for (const page of cloned.pages || []) {
19576
- const children = page.children || page.elements;
19577
- if (!Array.isArray(children)) continue;
19578
- const overlays = [];
19579
- for (const child of children) {
19580
- collectOverlays(child, 0, 0, false, extraBase, extraExact, overlays);
19581
- }
19582
- if (overlays.length === 0) continue;
19583
- for (const b of overlays) {
19584
- children.push(buildOverlay(b, idx++));
19585
- }
19586
- }
19587
- return cloned;
19588
- }
19589
- function hasAnyPreviewBlur(config) {
19590
- function walk(node) {
19591
- if (!node || typeof node !== "object") return false;
19592
- if (node.previewBlur === true) return true;
19593
- const children = node.children || node.elements;
19594
- if (Array.isArray(children)) {
19595
- for (const c of children) if (walk(c)) return true;
19596
- }
19597
- return false;
19598
- }
19599
- for (const page of config.pages || []) if (walk(page)) return true;
19600
- return false;
19601
- }
19602
- const previewBlur = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
19603
- __proto__: null,
19604
- hasAnyPreviewBlur,
19605
- injectPreviewBlur
19606
- }, Symbol.toStringTag, { value: "Module" }));
19607
19608
  const SELECT_COLUMNS = "id,name,description,category,thumbnail_url,preview_images,price,download_count,workspace_id,sort_order,created_at,updated_at";
19608
19609
  async function listPublishedTemplates(options) {
19609
19610
  const { workspaceId, supabaseUrl, supabaseAnonKey, category, limit = 200, offset = 0 } = options;
@@ -19804,4 +19805,4 @@ export {
19804
19805
  collectFontDescriptorsFromConfig as y,
19805
19806
  collectFontsFromConfig as z
19806
19807
  };
19807
- //# sourceMappingURL=index-C9H38u7P.js.map
19808
+ //# sourceMappingURL=index-CjZZhQH6.js.map