@pixldocs/canvas-renderer 0.5.39 → 0.5.41

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
@@ -221,7 +221,7 @@ export declare function normalizeFontFamily(fontStack: string): string;
221
221
  * Package version banner. Bump alongside package.json so we can confirm
222
222
  * (via browser:log) that the deployed bundle matches the expected build.
223
223
  */
224
- export declare const PACKAGE_VERSION = "0.5.39";
224
+ export declare const PACKAGE_VERSION = "0.5.40";
225
225
 
226
226
  export declare interface PageSettings {
227
227
  backgroundColor?: string;
@@ -249,6 +249,8 @@ export declare interface PdfFromFormOptions {
249
249
  themeId?: string;
250
250
  /** Whether to inject watermark. Default: auto (true for paid templates, false for free). */
251
251
  watermark?: boolean;
252
+ /** Customize watermark text/opacity/fontSize/angle. Defaults preserve current behavior. */
253
+ watermarkOptions?: WatermarkOptions;
252
254
  /** Optional prefetched rows from a trusted server to skip browser-side REST fetching. */
253
255
  prefetched?: ResolveFromFormOptions['prefetched'];
254
256
  /** PDF document title */
@@ -418,6 +420,8 @@ export declare interface RenderFromFormOptions extends Omit<RenderOptions, 'page
418
420
  themeId?: string;
419
421
  /** Whether to inject watermark on preview. Default: auto (true for paid templates, false for free). */
420
422
  watermark?: boolean;
423
+ /** Customize watermark text/opacity/fontSize/angle. Defaults preserve current behavior. */
424
+ watermarkOptions?: WatermarkOptions;
421
425
  /** Optional prefetched rows from a trusted server to skip browser-side REST fetching. */
422
426
  prefetched?: ResolveFromFormOptions['prefetched'];
423
427
  }
@@ -638,4 +642,12 @@ export declare function warmResolvedTemplateForPreview(config: TemplateConfig, o
638
642
  */
639
643
  export declare function warmTemplateFromForm(options: ResolveFromFormOptions & WarmOptions): Promise<void>;
640
644
 
645
+ /** Watermark appearance overrides (mirrors src/lib/canvasWatermark WatermarkOptions). */
646
+ declare interface WatermarkOptions {
647
+ text?: string;
648
+ opacity?: number;
649
+ fontSize?: number;
650
+ angle?: number;
651
+ }
652
+
641
653
  export { }
package/dist/index.js CHANGED
@@ -12053,7 +12053,7 @@ function PixldocsPreview(props) {
12053
12053
  !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..." }) })
12054
12054
  ] });
12055
12055
  }
12056
- const PACKAGE_VERSION = "0.5.39";
12056
+ const PACKAGE_VERSION = "0.5.40";
12057
12057
  let __underlineFixInstalled = false;
12058
12058
  function installUnderlineFix(fab) {
12059
12059
  var _a;
@@ -12061,6 +12061,24 @@ function installUnderlineFix(fab) {
12061
12061
  const TextProto = (_a = fab.Text) == null ? void 0 : _a.prototype;
12062
12062
  if (!TextProto || typeof TextProto._renderTextDecoration !== "function") return;
12063
12063
  const original = TextProto._renderTextDecoration;
12064
+ const measureLineTextWidth = (obj, ctx, lineIndex) => {
12065
+ var _a2, _b, _c, _d, _e, _f;
12066
+ const rawLine = (_a2 = obj._textLines) == null ? void 0 : _a2[lineIndex];
12067
+ const lineText = Array.isArray(rawLine) ? rawLine.join("") : String(rawLine ?? "");
12068
+ if (!lineText) return 0;
12069
+ const fontSize = Number(((_b = obj.getValueOfPropertyAt) == null ? void 0 : _b.call(obj, lineIndex, 0, "fontSize")) ?? obj.fontSize ?? 0);
12070
+ const fontStyle = String(((_c = obj.getValueOfPropertyAt) == null ? void 0 : _c.call(obj, lineIndex, 0, "fontStyle")) ?? obj.fontStyle ?? "normal");
12071
+ const fontWeight = String(((_d = obj.getValueOfPropertyAt) == null ? void 0 : _d.call(obj, lineIndex, 0, "fontWeight")) ?? obj.fontWeight ?? "400");
12072
+ const fontFamily = String(((_e = obj.getValueOfPropertyAt) == null ? void 0 : _e.call(obj, lineIndex, 0, "fontFamily")) ?? obj.fontFamily ?? "sans-serif");
12073
+ const charSpacing = Number(((_f = obj.getValueOfPropertyAt) == null ? void 0 : _f.call(obj, lineIndex, 0, "charSpacing")) ?? obj.charSpacing ?? 0);
12074
+ ctx.save();
12075
+ ctx.font = `${fontStyle} normal ${fontWeight} ${fontSize}px ${fontFamily}`;
12076
+ const measured = ctx.measureText(lineText).width;
12077
+ ctx.restore();
12078
+ const graphemeCount = Array.from(lineText).length;
12079
+ const spacingWidth = graphemeCount > 1 ? charSpacing / 1e3 * fontSize * (graphemeCount - 1) : 0;
12080
+ return Math.max(0, measured + spacingWidth);
12081
+ };
12064
12082
  TextProto._renderTextDecoration = function patchedRenderTextDecoration(ctx, type) {
12065
12083
  try {
12066
12084
  const hasOwn = !!this[type];
@@ -12091,20 +12109,16 @@ function installUnderlineFix(fab) {
12091
12109
  topOffset += heightOfLine;
12092
12110
  continue;
12093
12111
  }
12094
- if (Array.isArray(this.__lineWidths)) {
12095
- this.__lineWidths[i] = void 0;
12096
- }
12097
- let lineWidth = 0;
12098
- try {
12099
- lineWidth = this.getLineWidth(i);
12100
- } catch {
12101
- lineWidth = 0;
12102
- }
12112
+ const lineWidth = measureLineTextWidth(this, ctx, i);
12103
12113
  if (!lineWidth) {
12104
12114
  topOffset += heightOfLine;
12105
12115
  continue;
12106
12116
  }
12107
- const lineLeftOffset = this._getLineLeftOffset(i);
12117
+ const availableWidth = Number(this.width ?? lineWidth);
12118
+ let lineLeftOffset = 0;
12119
+ const align = String(this.textAlign ?? "left");
12120
+ if (align === "center") lineLeftOffset = (availableWidth - lineWidth) / 2;
12121
+ else if (align === "right" || align === "end") lineLeftOffset = availableWidth - lineWidth;
12108
12122
  let drawStart = leftOffset + lineLeftOffset;
12109
12123
  if (this.direction === "rtl") {
12110
12124
  drawStart = this.width - drawStart - lineWidth;
@@ -12194,7 +12208,7 @@ class PixldocsRenderer {
12194
12208
  * This is the primary external API for the package.
12195
12209
  */
12196
12210
  async renderFromForm(options) {
12197
- const { templateId, formSchemaId, sectionState, themeId, watermark, prefetched, ...renderOpts } = options;
12211
+ const { templateId, formSchemaId, sectionState, themeId, watermark, watermarkOptions, prefetched, ...renderOpts } = options;
12198
12212
  const resolved = await resolveFromForm({
12199
12213
  templateId,
12200
12214
  formSchemaId,
@@ -12207,8 +12221,8 @@ class PixldocsRenderer {
12207
12221
  const shouldWatermark = watermark ?? resolved.price > 0;
12208
12222
  let configToRender = resolved.config;
12209
12223
  if (shouldWatermark) {
12210
- const { injectWatermark } = await import("./canvasWatermark-CM85x4k7.js");
12211
- configToRender = injectWatermark(configToRender);
12224
+ const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
12225
+ configToRender = injectWatermark(configToRender, watermarkOptions);
12212
12226
  }
12213
12227
  return this.renderAllPages(configToRender, renderOpts);
12214
12228
  }
@@ -12247,7 +12261,7 @@ class PixldocsRenderer {
12247
12261
  * Resolve from V2 sectionState and return SVGs for all pages (for server vector PDF).
12248
12262
  */
12249
12263
  async renderSvgsFromForm(options) {
12250
- const { templateId, formSchemaId, sectionState, themeId, watermark, prefetched } = options;
12264
+ const { templateId, formSchemaId, sectionState, themeId, watermark, watermarkOptions, prefetched } = options;
12251
12265
  const resolved = await resolveFromForm({
12252
12266
  templateId,
12253
12267
  formSchemaId,
@@ -12260,8 +12274,8 @@ class PixldocsRenderer {
12260
12274
  const shouldWatermark = watermark ?? resolved.price > 0;
12261
12275
  let configToRender = resolved.config;
12262
12276
  if (shouldWatermark) {
12263
- const { injectWatermark } = await import("./canvasWatermark-CM85x4k7.js");
12264
- configToRender = injectWatermark(configToRender);
12277
+ const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
12278
+ configToRender = injectWatermark(configToRender, watermarkOptions);
12265
12279
  }
12266
12280
  return this.renderAllPageSvgs(configToRender);
12267
12281
  }
@@ -12279,7 +12293,7 @@ class PixldocsRenderer {
12279
12293
  * This is the primary PDF export API — mirrors renderFromForm() but returns a PDF.
12280
12294
  */
12281
12295
  async renderPdfFromForm(options) {
12282
- const { templateId, formSchemaId, sectionState, themeId, watermark, prefetched, title, fontBaseUrl } = options;
12296
+ const { templateId, formSchemaId, sectionState, themeId, watermark, watermarkOptions, prefetched, title, fontBaseUrl } = options;
12283
12297
  const resolved = await resolveFromForm({
12284
12298
  templateId,
12285
12299
  formSchemaId,
@@ -12292,8 +12306,8 @@ class PixldocsRenderer {
12292
12306
  const shouldWatermark = watermark ?? resolved.price > 0;
12293
12307
  let configToRender = resolved.config;
12294
12308
  if (shouldWatermark) {
12295
- const { injectWatermark } = await import("./canvasWatermark-CM85x4k7.js");
12296
- configToRender = injectWatermark(configToRender);
12309
+ const { injectWatermark } = await import("./canvasWatermark-pkhacGge.js");
12310
+ configToRender = injectWatermark(configToRender, watermarkOptions);
12297
12311
  }
12298
12312
  const svgs = await this.renderAllPageSvgs(configToRender);
12299
12313
  const { assemblePdfFromSvgs: assemblePdfFromSvgs2 } = await Promise.resolve().then(() => pdfExport);