@pixldocs/canvas-renderer 0.5.52 → 0.5.53

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.d.ts CHANGED
@@ -1,8 +1,12 @@
1
1
  import { FormConfig } from '../../../src/lib/formsApi';
2
+ import { getProxiedImageUrl } from '../../../src/lib/canvasImageLoader';
2
3
  import { InferredSection } from '../../../src/lib/inferFormSchemaFromTemplate';
4
+ import { isBundledAssetUrl } from '../../../src/lib/canvasImageLoader';
5
+ import { isPrivateUrl } from '../../../src/lib/canvasImageLoader';
3
6
  import { jsPDF } from 'jspdf';
4
7
  import { JSX as JSX_2 } from 'react/jsx-runtime';
5
8
  import { SectionFormState } from '../../../src/lib/inferFormSchemaFromTemplate';
9
+ import { setBundledAssetPrefixes } from '../../../src/lib/canvasImageLoader';
6
10
  import { SmartElementProps } from '../../../shared/smart-elements/types';
7
11
  import { SmartElementType } from '../../../shared/smart-elements/types';
8
12
 
@@ -200,11 +204,17 @@ declare type FormDefSection = {
200
204
  */
201
205
  export declare function getEmbeddedJsPDFFontName(fontName: string, weight: number, isItalic?: boolean): string;
202
206
 
207
+ export { getProxiedImageUrl }
208
+
203
209
  export { InferredSection }
204
210
 
211
+ export { isBundledAssetUrl }
212
+
205
213
  /** Check if a font is in our local mapping */
206
214
  export declare function isFontAvailable(fontName: string): boolean;
207
215
 
216
+ export { isPrivateUrl }
217
+
208
218
  /**
209
219
  * Load a Google Font by injecting a <link> stylesheet.
210
220
  * Resolves when the font is ready for use.
@@ -540,6 +550,8 @@ export declare function rewriteSvgFontsForJsPDF(svgStr: string): string;
540
550
 
541
551
  export { SectionFormState }
542
552
 
553
+ export { setBundledAssetPrefixes }
554
+
543
555
  export { SmartElementProps }
544
556
 
545
557
  export { SmartElementType }
package/dist/index.js CHANGED
@@ -2839,6 +2839,49 @@ function isPrivateUrl(url) {
2839
2839
  return false;
2840
2840
  }
2841
2841
  }
2842
+ const DEFAULT_BUNDLED_PREFIXES = ["/pixldocs-bundled-assets/"];
2843
+ let bundledPrefixes = [...DEFAULT_BUNDLED_PREFIXES];
2844
+ function setBundledAssetPrefixes(prefixes) {
2845
+ const combined = /* @__PURE__ */ new Set([...DEFAULT_BUNDLED_PREFIXES]);
2846
+ for (const p of prefixes || []) {
2847
+ if (typeof p === "string" && p.startsWith("/")) combined.add(p);
2848
+ }
2849
+ bundledPrefixes = Array.from(combined);
2850
+ }
2851
+ function pathnameStartsWithBundledPrefix(pathname) {
2852
+ return bundledPrefixes.some((prefix) => pathname.startsWith(prefix));
2853
+ }
2854
+ function isBundledAssetUrl(url) {
2855
+ if (!url) return false;
2856
+ if (url.startsWith("/") && !url.startsWith("//")) {
2857
+ return pathnameStartsWithBundledPrefix(url);
2858
+ }
2859
+ try {
2860
+ const parsed = new URL(url);
2861
+ if (typeof window !== "undefined" && parsed.origin !== window.location.origin) {
2862
+ return false;
2863
+ }
2864
+ return pathnameStartsWithBundledPrefix(parsed.pathname);
2865
+ } catch {
2866
+ return false;
2867
+ }
2868
+ }
2869
+ function resolveBundledAssetUrl(url) {
2870
+ if (!url) return null;
2871
+ if (url.startsWith("/") && !url.startsWith("//") && pathnameStartsWithBundledPrefix(url)) {
2872
+ const origin = typeof window !== "undefined" ? window.location.origin : "";
2873
+ return origin ? new URL(url, origin).toString() : url;
2874
+ }
2875
+ try {
2876
+ const parsed = new URL(url);
2877
+ if (typeof window !== "undefined" && parsed.origin !== window.location.origin) return null;
2878
+ if (pathnameStartsWithBundledPrefix(parsed.pathname)) return parsed.toString();
2879
+ } catch {
2880
+ return null;
2881
+ }
2882
+ return null;
2883
+ }
2884
+ const loggedPrivateSkips = /* @__PURE__ */ new Set();
2842
2885
  function toPublicStorageUrl(url) {
2843
2886
  try {
2844
2887
  const parsed = new URL(url);
@@ -2856,8 +2899,17 @@ function toPublicStorageUrl(url) {
2856
2899
  function getProxiedImageUrl(imageUrl) {
2857
2900
  if (!imageUrl) return "";
2858
2901
  if (imageUrl.startsWith("data:") || imageUrl.startsWith("blob:")) return imageUrl;
2902
+ const bundled = resolveBundledAssetUrl(imageUrl);
2903
+ if (bundled) return bundled;
2904
+ if (imageUrl.startsWith("/") && !imageUrl.startsWith("//")) {
2905
+ if (typeof window !== "undefined") return new URL(imageUrl, window.location.origin).toString();
2906
+ return imageUrl;
2907
+ }
2859
2908
  if (isPrivateUrl(imageUrl)) {
2860
- console.warn("[image-proxy] Skipping private URL:", imageUrl.substring(0, 80));
2909
+ if (!loggedPrivateSkips.has(imageUrl)) {
2910
+ loggedPrivateSkips.add(imageUrl);
2911
+ console.debug("[image-proxy] Skipping private URL:", imageUrl.substring(0, 80));
2912
+ }
2861
2913
  return "";
2862
2914
  }
2863
2915
  const publicUrl = toPublicStorageUrl(imageUrl);
@@ -4799,7 +4851,13 @@ function extractTextBgConfig(element) {
4799
4851
  rxTL: Math.max(0, Number(element.textBgRxTL ?? 0)) || 0,
4800
4852
  rxTR: Math.max(0, Number(element.textBgRxTR ?? 0)) || 0,
4801
4853
  rxBR: Math.max(0, Number(element.textBgRxBR ?? 0)) || 0,
4802
- rxBL: Math.max(0, Number(element.textBgRxBL ?? 0)) || 0
4854
+ rxBL: Math.max(0, Number(element.textBgRxBL ?? 0)) || 0,
4855
+ opacity: (() => {
4856
+ const n = Number(element.textBgOpacity);
4857
+ if (!Number.isFinite(n)) return void 0;
4858
+ return Math.max(0, Math.min(1, n));
4859
+ })(),
4860
+ shadowAffectsBg: element.textShadowAffectsBg !== false
4803
4861
  };
4804
4862
  }
4805
4863
  function hasTextBackground(cfg) {
@@ -4860,6 +4918,13 @@ function applyTextBackground(obj, cfg) {
4860
4918
  const bgW = w + pL + pR;
4861
4919
  const bgH = h + pT + pB;
4862
4920
  ctx.save();
4921
+ const suppressShadowOnBg = bg.shadowAffectsBg === false;
4922
+ if (suppressShadowOnBg) {
4923
+ ctx.shadowColor = "transparent";
4924
+ ctx.shadowBlur = 0;
4925
+ ctx.shadowOffsetX = 0;
4926
+ ctx.shadowOffsetY = 0;
4927
+ }
4863
4928
  buildRoundedRectPath2D(
4864
4929
  ctx,
4865
4930
  x,
@@ -4871,6 +4936,8 @@ function applyTextBackground(obj, cfg) {
4871
4936
  bg.rxBR ?? 0,
4872
4937
  bg.rxBL ?? 0
4873
4938
  );
4939
+ const op = typeof bg.opacity === "number" ? Math.max(0, Math.min(1, bg.opacity)) : 1;
4940
+ if (op < 1) ctx.globalAlpha = (ctx.globalAlpha ?? 1) * op;
4874
4941
  ctx.fillStyle = bg.color;
4875
4942
  ctx.fill();
4876
4943
  ctx.restore();
@@ -4916,7 +4983,9 @@ function applyTextBackground(obj, cfg) {
4916
4983
  (bg == null ? void 0 : bg.rxBL) ?? 0
4917
4984
  );
4918
4985
  const bgFill = (bg == null ? void 0 : bg.color) || "";
4919
- const bgPath = hasBg ? `<path d="${bgD}" fill="${escapeXmlAttr(bgFill)}" />` : "";
4986
+ const bgOpacity = typeof (bg == null ? void 0 : bg.opacity) === "number" ? Math.max(0, Math.min(1, bg.opacity)) : 1;
4987
+ const bgOpacityAttr = bgOpacity < 1 ? ` fill-opacity="${bgOpacity}"` : "";
4988
+ const bgPath = hasBg ? `<path d="${bgD}" fill="${escapeXmlAttr(bgFill)}"${bgOpacityAttr} />` : "";
4920
4989
  svg = svg.replace(/style="[^"]*filter:\s*url\([^)]+\)[^"]*"/i, "");
4921
4990
  svg = svg.replace(/<filter[\s\S]*?<\/filter>/gi, "");
4922
4991
  let bgShadowMarker = "";
@@ -4933,7 +5002,7 @@ function applyTextBackground(obj, cfg) {
4933
5002
  const bh = h + pT + pB + pad * 2;
4934
5003
  const dataAttrs = `data-blur="${blur.toFixed(3)}" data-ox="${ox.toFixed(3)}" data-oy="${oy.toFixed(3)}" data-bx="${bx.toFixed(3)}" data-by="${by.toFixed(3)}" data-bw="${bw.toFixed(3)}" data-bh="${bh.toFixed(3)}" data-color="${escapeXmlAttr(shadowColor)}"`;
4935
5004
  const wrapShadow = (markup) => blur <= 0 ? `<g transform="translate(${ox.toFixed(3)} ${oy.toFixed(3)})">${markup}</g>` : `<g class="__pdShadowRaster" ${dataAttrs}>${markup}</g>`;
4936
- if (hasBg) {
5005
+ if (hasBg && (bg == null ? void 0 : bg.shadowAffectsBg) !== false) {
4937
5006
  const shadowBgPath = `<path d="${bgD}" fill="${escapeXmlAttr(shadowColor)}" />`;
4938
5007
  bgShadowMarker = wrapShadow(shadowBgPath);
4939
5008
  }
@@ -15245,7 +15314,14 @@ async function assemblePdfFromSvgs(svgResults, options = {}) {
15245
15314
  const hasGradient = !!((_b = (_a = page.backgroundGradient) == null ? void 0 : _a.stops) == null ? void 0 : _b.length);
15246
15315
  drawPageBackground(pdf, i, page.width, page.height, page.backgroundColor, page.backgroundGradient);
15247
15316
  const shouldStripBg = stripPageBackground ?? hasGradient;
15248
- let processedSvg = await prepareLiveCanvasSvgForPdf(page.svg, page.width, page.height, `page-${i + 1}`, {
15317
+ let pageSvg = page.svg;
15318
+ try {
15319
+ const mod = await import("./svgTextToPath-BP0Kppla.js");
15320
+ pageSvg = await mod.convertAllTextToPath(pageSvg, fontBaseUrl);
15321
+ } catch (outlineErr) {
15322
+ console.warn(`[canvas-renderer pdf] page ${i + 1}: text outliner unavailable, continuing with text-as-text`, outlineErr);
15323
+ }
15324
+ let processedSvg = await prepareLiveCanvasSvgForPdf(pageSvg, page.width, page.height, `page-${i + 1}`, {
15249
15325
  stripPageBackground: shouldStripBg
15250
15326
  });
15251
15327
  if (processedSvg) {
@@ -15304,9 +15380,16 @@ function collectImageUrls(config) {
15304
15380
  function normalizeAssetUrl(rawUrl, imageProxyUrl) {
15305
15381
  if (!rawUrl) return null;
15306
15382
  if (rawUrl.startsWith("data:") || rawUrl.startsWith("blob:")) return null;
15383
+ if (rawUrl.startsWith("/") && !rawUrl.startsWith("//")) {
15384
+ if (typeof window !== "undefined") return new URL(rawUrl, window.location.origin).toString();
15385
+ return null;
15386
+ }
15307
15387
  try {
15308
15388
  const h = new URL(rawUrl).hostname.toLowerCase();
15309
15389
  if (h === "localhost" || h === "127.0.0.1" || h === "0.0.0.0" || h.endsWith(".local") || /^(10\.|192\.168\.|169\.254\.)/.test(h)) {
15390
+ if (typeof window !== "undefined" && new URL(rawUrl).origin === window.location.origin) {
15391
+ return rawUrl;
15392
+ }
15310
15393
  return null;
15311
15394
  }
15312
15395
  } catch {
@@ -15374,13 +15457,17 @@ export {
15374
15457
  ensureFontsForResolvedConfig,
15375
15458
  extractFontFamiliesFromSvgs,
15376
15459
  getEmbeddedJsPDFFontName,
15460
+ getProxiedImageUrl,
15461
+ isBundledAssetUrl,
15377
15462
  isFontAvailable,
15463
+ isPrivateUrl,
15378
15464
  loadGoogleFontCSS,
15379
15465
  normalizeFontFamily,
15380
15466
  resolveFontWeight,
15381
15467
  resolveFromForm,
15382
15468
  resolveTemplateData,
15383
15469
  rewriteSvgFontsForJsPDF,
15470
+ setBundledAssetPrefixes,
15384
15471
  warmResolvedTemplateForPreview,
15385
15472
  warmTemplateFromForm
15386
15473
  };