@canvas-components/print-design-plugin 0.1.8 → 0.1.9

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.cjs CHANGED
@@ -46,7 +46,9 @@ function assertNativePluginDependencies(plugins) {
46
46
  function validateTextElement(value) {
47
47
  if (!value || typeof value !== "object") return false;
48
48
  const element = value;
49
- return element.type === "text" && typeof element.text === "string" && (element.colorMode === void 0 || ["static", "binding"].includes(element.colorMode)) && (element.fontSizeMode === void 0 || ["static", "binding"].includes(element.fontSizeMode)) && (element.colorPath === void 0 || typeof element.colorPath === "string") && (element.fontSizePath === void 0 || typeof element.fontSizePath === "string") && (element.fontSizeBindingUnit === void 0 || ["mm", "cm", "in", "pt", "px"].includes(element.fontSizeBindingUnit)) && (element.heightOverflow === void 0 || ["clip", "flow", "ellipsis"].includes(element.heightOverflow)) && (element.underlineStyle === void 0 || ["solid", "dashed", "dotted", "wavy"].includes(element.underlineStyle)) && (element.underlineCount === void 0 || Number.isInteger(element.underlineCount) && element.underlineCount >= 0 && element.underlineCount <= 5) && (element.fontSource === void 0 || typeof element.fontSource === "string") && (element.borderWidth === void 0 || Number.isFinite(element.borderWidth) && element.borderWidth >= 0) && (element.borderColor === void 0 || typeof element.borderColor === "string") && (element.fontSizeRules === void 0 || Array.isArray(element.fontSizeRules) && element.fontSizeRules.every(
49
+ return element.type === "text" && typeof element.text === "string" && (element.fontStyle === void 0 || ["normal", "italic"].includes(element.fontStyle)) && (element.colorMode === void 0 || ["static", "binding"].includes(element.colorMode)) && (element.fontSizeMode === void 0 || ["static", "binding"].includes(element.fontSizeMode)) && (element.colorPath === void 0 || typeof element.colorPath === "string") && (element.fontSizePath === void 0 || typeof element.fontSizePath === "string") && (element.fontSizeBindingUnit === void 0 || ["mm", "cm", "in", "pt", "px"].includes(element.fontSizeBindingUnit)) && (element.heightOverflow === void 0 || ["clip", "flow", "ellipsis"].includes(element.heightOverflow)) && (element.indentMode === void 0 || ["none", "firstLine", "hanging"].includes(element.indentMode)) && (element.indentValue === void 0 || Number.isFinite(element.indentValue) && element.indentValue >= 0) && (element.indentUnit === void 0 || ["char", "mm", "cm", "in", "pt", "px"].includes(element.indentUnit)) && (element.prewrappedIndents === void 0 || Array.isArray(element.prewrappedIndents) && element.prewrappedIndents.every(
50
+ (value2) => Number.isFinite(value2) && value2 >= 0
51
+ )) && (element.underlineStyle === void 0 || ["solid", "dashed", "dotted", "wavy"].includes(element.underlineStyle)) && (element.underlineCount === void 0 || Number.isInteger(element.underlineCount) && element.underlineCount >= 0 && element.underlineCount <= 5) && (element.fontSource === void 0 || typeof element.fontSource === "string") && (element.borderWidth === void 0 || Number.isFinite(element.borderWidth) && element.borderWidth >= 0) && (element.borderColor === void 0 || typeof element.borderColor === "string") && (element.fontSizeRules === void 0 || Array.isArray(element.fontSizeRules) && element.fontSizeRules.every(
50
52
  (rule) => rule && Number.isInteger(rule.maxChars) && rule.maxChars >= 1 && Number.isFinite(rule.fontSize) && rule.fontSize > 0
51
53
  ));
52
54
  }
@@ -62,23 +64,36 @@ function graphemes(text) {
62
64
  function drawVerticalText(ctx, text, box, options) {
63
65
  if (box.width <= 0 || box.height <= 0) return;
64
66
  const step = Math.max(1, options.fontSize * options.lineHeight);
65
- const capacity = Math.max(1, Math.floor(box.height / step));
66
67
  const paragraphs = text.split(/\r?\n/).map(graphemes);
67
68
  const columns = paragraphs.flatMap((chars) => {
68
- if (!options.wrap || chars.length <= capacity) return [chars];
69
69
  const chunks = [];
70
- for (let index = 0; index < chars.length; index += capacity)
71
- chunks.push(chars.slice(index, index + capacity));
70
+ let offset = 0;
71
+ do {
72
+ const indent = options.indentMode === "firstLine" ? chunks.length === 0 ? options.indent ?? 0 : 0 : options.indentMode === "hanging" && chunks.length > 0 ? options.indent ?? 0 : 0;
73
+ const capacity = Math.max(1, Math.floor((box.height - indent) / step));
74
+ chunks.push({
75
+ chars: options.wrap === false ? chars.slice(offset) : chars.slice(offset, offset + capacity),
76
+ indent
77
+ });
78
+ offset += capacity;
79
+ } while (options.wrap !== false && offset < chars.length);
72
80
  return chunks;
73
81
  });
74
82
  const visibleCount = Math.max(1, Math.floor(box.width / step));
75
83
  const visible = columns.slice(0, visibleCount);
76
- const overflowed = columns.length > visibleCount || !options.wrap && visible.some((chars) => chars.length > capacity);
84
+ const overflowed = columns.length > visibleCount || !options.wrap && visible.some(
85
+ ({ chars, indent }) => chars.length > Math.max(1, Math.floor((box.height - indent) / step))
86
+ );
77
87
  if (options.ellipsis && overflowed && visible.length) {
78
- const last = [...visible[visible.length - 1]];
88
+ const previous = visible[visible.length - 1];
89
+ const capacity = Math.max(
90
+ 1,
91
+ Math.floor((box.height - previous.indent) / step)
92
+ );
93
+ const last = [...previous.chars];
79
94
  last.length = Math.min(last.length, capacity);
80
95
  last[Math.max(0, Math.min(last.length, capacity) - 1)] = "\u2026";
81
- visible[visible.length - 1] = last;
96
+ visible[visible.length - 1] = { ...previous, chars: last };
82
97
  }
83
98
  const blockWidth = visible.length * step;
84
99
  const left = options.align === "left" ? box.x : options.align === "center" ? box.x + (box.width - blockWidth) / 2 : box.x + box.width - blockWidth;
@@ -88,12 +103,17 @@ function drawVerticalText(ctx, text, box, options) {
88
103
  ctx.clip();
89
104
  ctx.textAlign = "center";
90
105
  ctx.textBaseline = "middle";
91
- visible.forEach((chars, column) => {
106
+ visible.forEach(({ chars, indent }, column) => {
92
107
  const textHeight = chars.length * step;
93
- const offset = options.verticalAlign === "bottom" ? Math.max(0, box.height - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (box.height - textHeight) / 2) : 0;
108
+ const availableHeight = Math.max(0, box.height - indent);
109
+ const offset = options.verticalAlign === "bottom" ? Math.max(0, availableHeight - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (availableHeight - textHeight) / 2) : 0;
94
110
  const centerX = left + blockWidth - (column + 0.5) * step;
95
111
  chars.forEach(
96
- (char, index) => ctx.fillText(char, centerX, box.y + offset + (index + 0.5) * step)
112
+ (char, index) => ctx.fillText(
113
+ char,
114
+ centerX,
115
+ box.y + indent + offset + (index + 0.5) * step
116
+ )
97
117
  );
98
118
  });
99
119
  ctx.restore();
@@ -134,15 +154,16 @@ function getTextLayoutCache(ctx) {
134
154
  }
135
155
  return entry;
136
156
  }
137
- function layoutSpacedText(ctx, text, width, prewrapped = false) {
157
+ function layoutSpacedText(ctx, text, width, prewrapped = false, indent) {
138
158
  const cache = getTextLayoutCache(ctx);
139
- const key = `${prewrapped}:${width}\0${text}`;
159
+ const key = `${prewrapped}:${width}:${indent?.mode ?? "none"}:${indent?.value ?? 0}\0${text}`;
140
160
  let lines = cache.lines.get(key);
141
161
  if (!lines) {
142
162
  lines = prewrapped ? text.split("\n").map((text2) => ({ text: text2, last: true })) : layoutAlignedText(
143
163
  text,
144
164
  width,
145
- (value) => measureSpacedText(ctx, value)
165
+ (value) => measureSpacedText(ctx, value),
166
+ indent
146
167
  );
147
168
  if (cache.lines.size >= 128) cache.lines.clear();
148
169
  cache.lines.set(key, lines);
@@ -196,28 +217,30 @@ function drawSpacedText(ctx, text, x, y) {
196
217
  });
197
218
  ctx.textAlign = align;
198
219
  }
199
- function layoutAlignedText(text, width, measure) {
220
+ function layoutAlignedText(text, width, measure, indent) {
200
221
  return text.split("\n").flatMap((paragraph) => {
201
222
  const lines = [];
202
223
  let line = "";
224
+ const indentation = (index) => indent?.mode === "firstLine" ? index === 0 ? indent.value : 0 : indent?.mode === "hanging" && index > 0 ? indent.value : 0;
203
225
  const tokens = paragraph.match(
204
226
  /[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}]+|\s+|[^\p{Script=Latin}\p{N}\s]+/gu
205
227
  ) ?? [];
206
228
  const pieces = tokens.flatMap(
207
229
  (token) => /^(?:[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}\s]+)$/u.test(
208
230
  token
209
- ) && measure(token) <= width ? [token] : graphemes(token)
231
+ ) && measure(token) <= Math.max(1, width - Math.max(0, indent?.value ?? 0)) ? [token] : graphemes(token)
210
232
  );
211
233
  for (const piece of pieces) {
212
- if (line && measure(line + piece) > width) {
213
- lines.push(line.trimEnd());
234
+ if (line && measure(line + piece) > Math.max(1, width - indentation(lines.length))) {
235
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
214
236
  line = "";
215
237
  }
216
238
  if (line || piece.trim()) line += piece;
217
239
  }
218
- lines.push(line.trimEnd());
240
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
219
241
  return lines.map((value, index) => ({
220
- text: value,
242
+ text: value.text,
243
+ ...indent && indent.mode !== "none" && indent.value > 0 ? { indent: value.indent } : {},
221
244
  last: index === lines.length - 1
222
245
  }));
223
246
  });
@@ -243,13 +266,7 @@ function drawAlignedTextLine(ctx, text, x, y, width, distributed) {
243
266
  });
244
267
  }
245
268
  function resolveTextFontFamily(family) {
246
- const selected = family?.trim();
247
- if (!selected) return printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY;
248
- if (/\bPrintDesignNotoSansSC\b/i.test(selected)) return selected;
249
- if (!/(?:^|,)\s*['"]?Times New Roman['"]?(?:,|$)/i.test(selected) && !/(?:^|,)\s*serif\s*$/i.test(selected))
250
- return selected;
251
- const generic = /,\s*(sans-serif|serif|monospace|cursive|fantasy|system-ui)\s*$/i;
252
- return generic.test(selected) ? selected.replace(generic, ", PrintDesignNotoSansSC, $1") : `${selected}, PrintDesignNotoSansSC`;
269
+ return printDesign.resolvePrintDesignFontFamily(family);
253
270
  }
254
271
 
255
272
  // src/plugins/text/layout/measure.ts
@@ -267,7 +284,7 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
267
284
  widths = /* @__PURE__ */ new Map();
268
285
  widthCaches.set(ownerDocument, widths);
269
286
  }
270
- const font = `${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
287
+ const font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
271
288
  let span;
272
289
  return {
273
290
  measure: (value) => {
@@ -298,6 +315,12 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
298
315
  dispose: () => span?.remove()
299
316
  };
300
317
  }
318
+ function resolveTextIndentMm(element, fontSizePt) {
319
+ if (!element.indentMode || element.indentMode === "none") return 0;
320
+ const value = Math.max(0, element.indentValue ?? 0);
321
+ if (!Number.isFinite(value)) return 0;
322
+ return element.indentUnit === "char" || !element.indentUnit ? value * fontSizePt * 25.4 / 72 : printDesign.fromDisplayUnit(value, element.indentUnit);
323
+ }
301
324
 
302
325
  // src/plugins/text/rendering/formatting.ts
303
326
  function resolveTextFontSize(element, text) {
@@ -317,15 +340,15 @@ function ellipsizeTextLine(text, maxWidth, measure) {
317
340
 
318
341
  // src/plugins/text/rendering/draw.ts
319
342
  var loadedFonts = /* @__PURE__ */ new WeakMap();
320
- var DEFAULT_TEXT_BASELINE_CORRECTION_RATIO = 0.05;
321
343
  function prepareTextFont(element, signal) {
322
344
  const family = element.fontFamily?.trim();
323
345
  const source = element.fontSource?.trim();
324
346
  if (!family || !source) return Promise.resolve();
325
347
  if (typeof document === "undefined" || typeof FontFace === "undefined")
326
- return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u52A0\u8F7D\u6253\u5370\u5B57\u4F53\u3002"));
348
+ return Promise.resolve();
327
349
  signal?.throwIfAborted();
328
- const ready = ensureTextFont(element, document);
350
+ const ready = ensureTextFont(element, document).catch(() => {
351
+ });
329
352
  if (!signal) return ready;
330
353
  return new Promise((resolve, reject) => {
331
354
  const onAbort = () => reject(signal.reason);
@@ -392,7 +415,7 @@ var drawTextElement = (element, context) => {
392
415
  const resolvedFontSize = resolveTextFontSize(element, resolvedText);
393
416
  const fontSize = resolvedFontSize * 25.4 * scale / 72;
394
417
  ctx.fillStyle = element.color ?? "#1f2937";
395
- ctx.font = `${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
418
+ ctx.font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
396
419
  const expanded = element.textAlign === "justify" || element.textAlign === "distributed";
397
420
  ctx.textAlign = expanded ? "left" : element.textAlign ?? "left";
398
421
  ctx.textBaseline = "alphabetic";
@@ -407,7 +430,9 @@ var drawTextElement = (element, context) => {
407
430
  align: element.textAlign === "left" || element.textAlign === "center" ? element.textAlign : "right",
408
431
  verticalAlign: element.verticalAlign,
409
432
  wrap: true,
410
- ellipsis: element.heightOverflow === "ellipsis"
433
+ ellipsis: element.heightOverflow === "ellipsis",
434
+ indentMode: element.indentMode,
435
+ indent: resolveTextIndentMm(element, resolvedFontSize) * scale
411
436
  }
412
437
  );
413
438
  return;
@@ -416,19 +441,31 @@ var drawTextElement = (element, context) => {
416
441
  const fontMetrics = ctx.measureText?.("Hg");
417
442
  const ascent = fontMetrics?.fontBoundingBoxAscent ?? fontSize * 0.8;
418
443
  const descent = fontMetrics?.fontBoundingBoxDescent ?? fontSize * 0.2;
419
- const defaultFont = !element.fontFamily || element.fontFamily === printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY;
420
- const regularNoto = element.fontFamily?.startsWith("PrintDesignNotoSansSC") && !/^(?:bold|[6-9]00)$/i.test(element.fontWeight ?? "400");
421
- const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent - (defaultFont || regularNoto ? fontSize * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO : 0);
444
+ const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent;
422
445
  const measure = (text) => measureSpacedText(ctx, text);
423
- let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped);
446
+ const indentPx = resolveTextIndentMm(element, resolvedFontSize) * scale;
447
+ let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped, {
448
+ mode: element.indentMode ?? "none",
449
+ value: indentPx
450
+ });
451
+ if (element.prewrappedIndents)
452
+ lines = lines.map((line, index) => ({
453
+ ...line,
454
+ indent: (element.prewrappedIndents?.[index] ?? 0) * scale
455
+ }));
424
456
  if (element.heightOverflow) {
425
457
  const fit = Math.max(0, Math.floor(height / lineHeight));
426
458
  if (lines.length > fit) {
427
459
  lines = lines.slice(0, fit);
428
460
  if (fit && element.heightOverflow === "ellipsis")
429
461
  lines[fit - 1] = {
430
- text: ellipsizeTextLine(lines[fit - 1].text, width, measure),
431
- last: true
462
+ text: ellipsizeTextLine(
463
+ lines[fit - 1].text,
464
+ Math.max(1, width - (lines[fit - 1].indent ?? 0)),
465
+ measure
466
+ ),
467
+ last: true,
468
+ indent: lines[fit - 1].indent
432
469
  };
433
470
  }
434
471
  ctx.beginPath();
@@ -436,16 +473,22 @@ var drawTextElement = (element, context) => {
436
473
  ctx.clip();
437
474
  }
438
475
  const verticalOffset = element.verticalAlign === "middle" ? Math.max(0, (height - lines.length * lineHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - lines.length * lineHeight) : 0;
439
- const textX = element.textAlign === "center" ? x + width / 2 : element.textAlign === "right" ? x + width : x;
440
476
  lines.forEach((line, index) => {
441
477
  const lineY = y + verticalOffset + index * lineHeight + baselineOffset;
478
+ const lineIndent = Math.min(
479
+ Math.max(0, line.indent ?? 0),
480
+ Math.max(0, width)
481
+ );
482
+ const lineLeft = x + lineIndent;
483
+ const lineWidth = Math.max(0, width - lineIndent);
484
+ const textX = element.textAlign === "center" ? lineLeft + lineWidth / 2 : element.textAlign === "right" ? x + width : lineLeft;
442
485
  if (expanded && (element.textAlign === "distributed" || !line.last)) {
443
486
  drawAlignedTextLine(
444
487
  ctx,
445
488
  line.text,
446
- x,
489
+ lineLeft,
447
490
  lineY,
448
- width,
491
+ lineWidth,
449
492
  element.textAlign === "distributed"
450
493
  );
451
494
  } else {
@@ -456,8 +499,8 @@ var drawTextElement = (element, context) => {
456
499
  Math.max(0, Math.floor(element.underlineCount ?? 0))
457
500
  );
458
501
  if (!count || !line.text) return;
459
- const textWidth = Math.min(width, measure(line.text));
460
- const left = expanded && (element.textAlign === "distributed" || !line.last) ? x : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
502
+ const textWidth = Math.min(lineWidth, measure(line.text));
503
+ const left = expanded && (element.textAlign === "distributed" || !line.last) ? lineLeft : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
461
504
  ctx.save();
462
505
  ctx.strokeStyle = element.underlineColor ?? element.color ?? "#1f2937";
463
506
  ctx.lineWidth = Math.max(0.5, (element.underlineWidth ?? 0.2) * scale);
@@ -508,13 +551,24 @@ function textMarkup(text, element, size = 14, color2 = "#1f2937") {
508
551
  const weight = /^(?:[1-9]00|normal|bold)$/.test(
509
552
  textElement?.fontWeight ?? "400"
510
553
  ) ? textElement?.fontWeight ?? "400" : "400";
554
+ const fontStyle = textElement?.fontStyle === "italic" ? "italic" : "normal";
511
555
  const fontSize = textElement ? resolveTextFontSize(textElement, text) : printDesign.cssNumber(size, 14);
512
- if (textElement?.textDirection === "vertical")
513
- return `<div class="pd-text" style="display:block;font:${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${printDesign.cssNumber(textElement.lineHeight, 1.35)}">${printDesign.escapeHtml(text)}</div>`;
556
+ if (textElement?.textDirection === "vertical") {
557
+ const indentMm2 = resolveTextIndentMm(textElement, fontSize);
558
+ const paragraphStyle = indentMm2 <= 0 ? "" : textElement.indentMode === "firstLine" ? `text-indent:${printDesign.cssNumber(indentMm2, 0)}mm;` : `padding-top:${printDesign.cssNumber(indentMm2, 0)}mm;text-indent:-${printDesign.cssNumber(indentMm2, 0)}mm;box-sizing:border-box;`;
559
+ const content = indentMm2 > 0 ? text.split("\n").map(
560
+ (paragraph) => `<div style="${paragraphStyle}">${printDesign.escapeHtml(paragraph) || "<br>"}</div>`
561
+ ).join("") : printDesign.escapeHtml(text);
562
+ return `<div class="pd-text" style="display:block;font:${fontStyle} ${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${printDesign.cssNumber(textElement.lineHeight, 1.35)}">${content}</div>`;
563
+ }
564
+ const indentMm = textElement ? resolveTextIndentMm(textElement, fontSize) : 0;
565
+ const indentStyle = (lineIndex) => indentMm > 0 && textElement ? textElement.indentMode === "firstLine" ? lineIndex === 0 ? `text-indent:${printDesign.cssNumber(indentMm, 0)}mm;` : "" : textElement.indentMode === "hanging" ? `padding-left:${printDesign.cssNumber(indentMm, 0)}mm;text-indent:${`-${printDesign.cssNumber(indentMm, 0)}mm` };box-sizing:border-box;` : "" : "";
514
566
  const lines = textElement?.prewrapped ? text.split("\n").map(
515
- (line) => `<div style="white-space:pre;overflow:hidden;flex:none"><span style="${underlineCss(textElement)}">${printDesign.escapeHtml(line) || "<br>"}</span></div>`
567
+ (line, index) => `<div style="white-space:pre;overflow:hidden;flex:none${textElement.prewrappedIndents ? `;box-sizing:border-box;padding-left:${printDesign.cssNumber(textElement.prewrappedIndents[index] ?? 0, 0)}mm` : ""}"><span style="${underlineCss(textElement)}">${printDesign.escapeHtml(line) || "<br>"}</span></div>`
568
+ ).join("") : indentMm > 0 ? text.split("\n").map(
569
+ (paragraph) => `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere;${indentStyle(0)}"><span style="${textElement ? underlineCss(textElement) : ""}">${printDesign.escapeHtml(paragraph) || "<br>"}</span></div>`
516
570
  ).join("") : `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere"><span style="${textElement ? underlineCss(textElement) : ""}">${printDesign.escapeHtml(text)}</span></div>`;
517
- return `<div class="pd-text" style="font:${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};text-align:${align};line-height:${printDesign.cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
571
+ return `<div class="pd-text" style="font:${fontStyle} ${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};text-align:${align};line-height:${printDesign.cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
518
572
  }
519
573
  function underlineCss(element) {
520
574
  const count = Math.min(
@@ -549,6 +603,18 @@ function textFontCss(element) {
549
603
  return `@font-face{font-family:${printDesign.cssFont(element.fontFamily)};src:url("${source}")}`;
550
604
  }
551
605
  var PT_TO_MM = 25.4 / 72;
606
+ function layoutText(element, text, measure) {
607
+ if (element.prewrapped)
608
+ return text.split("\n").map((line, index) => ({
609
+ text: line,
610
+ last: true,
611
+ indent: element.prewrappedIndents?.[index] ?? 0
612
+ }));
613
+ return layoutAlignedText(text, element.width, measure, {
614
+ mode: element.indentMode ?? "none",
615
+ value: resolveTextIndentMm(element, resolveTextFontSize(element, text))
616
+ });
617
+ }
552
618
  function paginateText(element, { data, startPage, startY, top, bottom, pageAt }) {
553
619
  const text = element.dataConfig?.mode === "binding" ? element.text : printDesign.resolveDesignText(element.text, data);
554
620
  if (element.textDirection === "vertical") {
@@ -576,9 +642,7 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
576
642
  );
577
643
  let lines;
578
644
  try {
579
- lines = layoutAlignedText(text, element.width, measurement.measure).map(
580
- (line) => line.text
581
- );
645
+ lines = layoutText(element, text, measurement.measure);
582
646
  } finally {
583
647
  measurement.dispose();
584
648
  }
@@ -607,7 +671,8 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
607
671
  previewSourceId: element.previewSourceId ?? element.id,
608
672
  y,
609
673
  height,
610
- text: chunk.join("\n"),
674
+ text: chunk.map((line) => line.text).join("\n"),
675
+ ...element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? { prewrappedIndents: chunk.map((line) => line.indent ?? 0) } : {},
611
676
  prewrapped: true,
612
677
  verticalAlign: "top",
613
678
  dataConfig: void 0
@@ -635,7 +700,11 @@ function prewrapText(element) {
635
700
  (value) => estimateTextWidth(value, fontMm)
636
701
  );
637
702
  try {
638
- return layoutAlignedText(element.text, element.width, measurement.measure).map((line) => line.text).join("\n");
703
+ const lines = layoutText(element, element.text, measurement.measure);
704
+ return {
705
+ text: lines.map((line) => line.text).join("\n"),
706
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? lines.map((line) => line.indent ?? 0) : void 0
707
+ };
639
708
  } finally {
640
709
  measurement.dispose();
641
710
  }
@@ -648,12 +717,12 @@ function estimateTextHeight(element) {
648
717
  (value) => estimateTextWidth(value, fontMm)
649
718
  );
650
719
  try {
651
- return layoutAlignedText(element.text, element.width, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
720
+ return layoutText(element, element.text, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
652
721
  } finally {
653
722
  measurement.dispose();
654
723
  }
655
724
  }
656
- function truncateText(element, height, mode) {
725
+ function truncateTextLayout(element, height, mode) {
657
726
  const fontMm = Math.max(1, (element.fontSize ?? 14) * PT_TO_MM);
658
727
  const lineMm = fontMm * (element.lineHeight ?? 1.35);
659
728
  const measurement = createHtmlTextMeasure(
@@ -662,21 +731,21 @@ function truncateText(element, height, mode) {
662
731
  (value) => estimateTextWidth(value, fontMm)
663
732
  );
664
733
  try {
665
- const lines = layoutAlignedText(
666
- element.text,
667
- element.width,
668
- measurement.measure
669
- );
734
+ const lines = layoutText(element, element.text, measurement.measure);
670
735
  const fit = Math.max(0, Math.floor(height / lineMm));
671
- if (lines.length <= fit) return element.text;
672
- const visible = lines.slice(0, fit).map((line) => line.text);
736
+ const visibleLines = lines.slice(0, fit);
737
+ const visible = visibleLines.map((line) => line.text);
673
738
  if (fit && mode === "ellipsis")
674
739
  visible[fit - 1] = ellipsizeTextLine(
675
740
  visible[fit - 1],
676
- element.width,
741
+ Math.max(1, element.width - (lines[fit - 1]?.indent ?? 0)),
677
742
  measurement.measure
678
743
  );
679
- return visible.join("\n");
744
+ return {
745
+ text: visible.join("\n"),
746
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? visibleLines.map((line) => line.indent ?? 0) : void 0,
747
+ overflowed: lines.length > fit
748
+ };
680
749
  } finally {
681
750
  measurement.dispose();
682
751
  }
@@ -706,11 +775,13 @@ function prepareTextPagination(element, data) {
706
775
  };
707
776
  if (element.textDirection === "vertical" || element.overflowPolicy === "split" || element.heightOverflow === "flow" && element.overflowPolicy !== "nextPage")
708
777
  return prepared;
709
- const printable = element.heightOverflow && element.heightOverflow !== "flow" ? {
778
+ const wrapped = element.heightOverflow && element.heightOverflow !== "flow" ? truncateTextLayout(prepared, prepared.height, element.heightOverflow) : prewrapText(prepared);
779
+ return {
710
780
  ...prepared,
711
- text: truncateText(prepared, prepared.height, element.heightOverflow)
712
- } : prepared;
713
- return { ...printable, text: prewrapText(printable), prewrapped: true };
781
+ text: wrapped.text,
782
+ ...wrapped.indents ? { prewrappedIndents: wrapped.indents } : {},
783
+ prewrapped: true
784
+ };
714
785
  }
715
786
  function measureTextFlowHeight(element, data) {
716
787
  if (element.heightOverflow && element.heightOverflow !== "flow")
@@ -719,7 +790,13 @@ function measureTextFlowHeight(element, data) {
719
790
  return Math.max(prepared.height, estimateTextHeight(prepared));
720
791
  }
721
792
  function truncateTextOverflow(element, height, mode) {
722
- return { ...element, text: truncateText(element, height, mode) };
793
+ const truncated = truncateTextLayout(element, height, mode);
794
+ return {
795
+ ...element,
796
+ text: truncated.text,
797
+ prewrapped: true,
798
+ ...truncated.indents ? { prewrappedIndents: truncated.indents } : {}
799
+ };
723
800
  }
724
801
  function registeredFieldBindingInfo(element, fields) {
725
802
  const config = printDesign.getPrintDesignElementDataConfig(element, fields);
@@ -792,14 +869,14 @@ function resolveTextFontSizeValue(value, defaultUnit = "mm") {
792
869
  // src/plugins/text/data/binding.ts
793
870
  function getTextBindingInfo(element) {
794
871
  const content = registeredFieldBindingInfo(element, textDataFields);
795
- const paths = [
872
+ const paths2 = [
796
873
  ...content.paths,
797
874
  element.colorMode === "binding" ? element.colorPath : void 0,
798
875
  element.fontSizeMode === "binding" ? element.fontSizePath : void 0
799
876
  ].filter((path) => !!path?.trim());
800
877
  return {
801
878
  bound: content.bound || element.colorMode === "binding" || element.fontSizeMode === "binding",
802
- paths
879
+ paths: paths2
803
880
  };
804
881
  }
805
882
  function missingExpressionPath(expression, data) {
@@ -859,7 +936,7 @@ function resolveTextData(element, data) {
859
936
  // src/plugins/text/native.ts
860
937
  var textNativePlugin = defineNativePlugin(
861
938
  "text",
862
- "0.1.34",
939
+ "0.1.38",
863
940
  printDesign.definePrintDesignPluginRenderer({
864
941
  type: "text",
865
942
  dataFields: textDataFields,
@@ -882,6 +959,268 @@ var textNativePlugin = defineNativePlugin(
882
959
  inlineTextEditor: textInlineEditor
883
960
  })
884
961
  );
962
+
963
+ // src/plugins/rich-text/model.ts
964
+ function validateRichTextElement(value) {
965
+ if (!value || typeof value !== "object") return false;
966
+ const element = value;
967
+ return element.type === "richText" && (element.dataConfig === void 0 || element.dataConfig.mode === "static") && Array.isArray(element.runs) && element.runs.length <= 2e3 && element.runs.reduce(
968
+ (length, run) => length + (typeof run?.text === "string" ? run.text.length : 0),
969
+ 0
970
+ ) <= 1e5 && element.runs.every(
971
+ (run) => run && typeof run.text === "string" && run.text.length > 0 && Object.keys(run).every((key) => key === "text" || key === "style") && (run.style === void 0 || run.style && typeof run.style === "object" && !Array.isArray(run.style) && Object.keys(run.style).every(
972
+ (key) => ["fontFamily", "fontSize", "fontWeight", "fontStyle", "color"].includes(key)
973
+ ) && (run.style.fontFamily === void 0 || typeof run.style.fontFamily === "string" && run.style.fontFamily.length <= 200 && /^[\p{L}\p{N}_\s,'"-]+$/u.test(run.style.fontFamily)) && (run.style.fontSize === void 0 || Number.isFinite(run.style.fontSize) && run.style.fontSize > 0 && run.style.fontSize <= 240) && (run.style.fontWeight === void 0 || typeof run.style.fontWeight === "string" && /^(?:[1-9]00|normal|bold)$/.test(run.style.fontWeight)) && (run.style.fontStyle === void 0 || ["normal", "italic"].includes(run.style.fontStyle)) && (run.style.color === void 0 || typeof run.style.color === "string" && /^#[0-9a-fA-F]{3,8}$/.test(run.style.color)))
974
+ ) && (element.fontSize === void 0 || Number.isFinite(element.fontSize) && element.fontSize > 0 && element.fontSize <= 240) && (element.fontFamily === void 0 || typeof element.fontFamily === "string" && element.fontFamily.length <= 200 && /^[\p{L}\p{N}_\s,'"-]+$/u.test(element.fontFamily)) && (element.fontWeight === void 0 || typeof element.fontWeight === "string" && /^(?:[1-9]00|normal|bold)$/.test(element.fontWeight)) && (element.fontStyle === void 0 || ["normal", "italic"].includes(element.fontStyle)) && (element.color === void 0 || typeof element.color === "string" && /^#[0-9a-fA-F]{3,8}$/.test(element.color)) && (element.textAlign === void 0 || ["left", "center", "right"].includes(element.textAlign)) && (element.verticalAlign === void 0 || ["top", "middle", "bottom"].includes(element.verticalAlign)) && (element.lineHeight === void 0 || Number.isFinite(element.lineHeight) && element.lineHeight >= 0.5 && element.lineHeight <= 4) && (element.indentMode === void 0 || ["none", "firstLine", "hanging"].includes(element.indentMode)) && (element.indentValue === void 0 || Number.isFinite(element.indentValue) && element.indentValue >= 0) && (element.indentUnit === void 0 || ["char", "mm", "cm", "in", "pt", "px"].includes(element.indentUnit)) && (element.prewrapped === void 0 || typeof element.prewrapped === "boolean") && (element.prewrappedIndents === void 0 || Array.isArray(element.prewrappedIndents) && element.prewrappedIndents.every(
975
+ (indent) => Number.isFinite(indent) && indent >= 0
976
+ ));
977
+ }
978
+ function richTextIndentMm(element) {
979
+ if (!element.indentMode || element.indentMode === "none") return 0;
980
+ const value = Math.max(0, element.indentValue ?? 0);
981
+ return element.indentUnit === "char" || !element.indentUnit ? value * (element.fontSize ?? 14) * 25.4 / 72 : printDesign.fromDisplayUnit(value, element.indentUnit);
982
+ }
983
+ function richTextGraphemes(text) {
984
+ const Segmenter = Intl.Segmenter;
985
+ return Segmenter ? Array.from(
986
+ new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
987
+ (part) => part.segment
988
+ ) : Array.from(text);
989
+ }
990
+
991
+ // src/plugins/rich-text/rendering.ts
992
+ function runStyle(element, run) {
993
+ return {
994
+ fontFamily: printDesign.resolvePrintDesignFontFamily(
995
+ run.style?.fontFamily ?? element.fontFamily
996
+ ),
997
+ fontSize: run.style?.fontSize ?? element.fontSize ?? 14,
998
+ fontWeight: run.style?.fontWeight ?? element.fontWeight ?? "400",
999
+ fontStyle: run.style?.fontStyle ?? element.fontStyle ?? "normal",
1000
+ color: run.style?.color ?? element.color ?? "#1f2937"
1001
+ };
1002
+ }
1003
+ function layoutRichTextLines(element, width, scale, measure) {
1004
+ const indent = richTextIndentMm(element) * scale;
1005
+ const lineHeight = element.lineHeight ?? 1.35;
1006
+ const lines = [];
1007
+ let paragraphLine = 0;
1008
+ const addLine = () => {
1009
+ const inset = element.prewrapped ? (element.prewrappedIndents?.[lines.length] ?? 0) * scale : element.indentMode === "firstLine" && paragraphLine === 0 || element.indentMode === "hanging" && paragraphLine > 0 ? indent : 0;
1010
+ lines.push({
1011
+ chars: [],
1012
+ width: 0,
1013
+ indent: inset,
1014
+ height: (element.fontSize ?? 14) * 25.4 / 72 * scale * lineHeight
1015
+ });
1016
+ };
1017
+ addLine();
1018
+ for (const run of element.runs) {
1019
+ const style = runStyle(element, run);
1020
+ const fontSize = style.fontSize * 25.4 / 72 * scale;
1021
+ for (const char of richTextGraphemes(run.text.replace(/\r\n?/g, "\n"))) {
1022
+ if (char === "\n") {
1023
+ paragraphLine = 0;
1024
+ addLine();
1025
+ continue;
1026
+ }
1027
+ const charWidth = measure(char, style, fontSize);
1028
+ let line = lines[lines.length - 1];
1029
+ if (!element.prewrapped && line.chars.length && line.width + charWidth > Math.max(1, width - line.indent)) {
1030
+ paragraphLine++;
1031
+ addLine();
1032
+ line = lines[lines.length - 1];
1033
+ }
1034
+ line.chars.push({ text: char, width: charWidth, style });
1035
+ line.width += charWidth;
1036
+ line.height = Math.max(line.height, fontSize * lineHeight);
1037
+ }
1038
+ }
1039
+ return lines;
1040
+ }
1041
+ function drawRichTextElement(element, { ctx, scale, x, y, width, height }) {
1042
+ const lineHeight = element.lineHeight ?? 1.35;
1043
+ const lines = layoutRichTextLines(
1044
+ element,
1045
+ width,
1046
+ scale,
1047
+ (char, style, fontSize) => {
1048
+ ctx.font = `${style.fontStyle} ${style.fontWeight} ${fontSize}px ${style.fontFamily}`;
1049
+ return ctx.measureText(char).width;
1050
+ }
1051
+ );
1052
+ const totalHeight = lines.reduce((sum, line) => sum + line.height, 0);
1053
+ let top = y + (element.verticalAlign === "middle" ? Math.max(0, (height - totalHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - totalHeight) : 0);
1054
+ ctx.save();
1055
+ ctx.beginPath();
1056
+ ctx.rect(x, y, width, height);
1057
+ ctx.clip();
1058
+ ctx.textAlign = "left";
1059
+ ctx.textBaseline = "alphabetic";
1060
+ for (const line of lines) {
1061
+ let left = x + line.indent;
1062
+ const available = Math.max(0, width - line.indent);
1063
+ if (element.textAlign === "center") left += (available - line.width) / 2;
1064
+ if (element.textAlign === "right") left += available - line.width;
1065
+ for (const char of line.chars) {
1066
+ const fontSize = char.style.fontSize * 25.4 / 72 * scale;
1067
+ ctx.font = `${char.style.fontStyle} ${char.style.fontWeight} ${fontSize}px ${char.style.fontFamily}`;
1068
+ ctx.fillStyle = char.style.color;
1069
+ ctx.fillText(
1070
+ char.text,
1071
+ left,
1072
+ top + (line.height - fontSize * lineHeight) / 2 + fontSize
1073
+ );
1074
+ left += char.width;
1075
+ }
1076
+ top += line.height;
1077
+ }
1078
+ ctx.restore();
1079
+ }
1080
+ function renderRichTextHtml(element) {
1081
+ const baseSize = printDesign.cssNumber(element.fontSize, 14);
1082
+ const indent = richTextIndentMm(element);
1083
+ const paragraphs = [""];
1084
+ for (const run of element.runs) {
1085
+ const style = runStyle(element, run);
1086
+ const css = `font-family:${printDesign.escapeHtml(printDesign.cssFont(style.fontFamily))};font-size:${printDesign.cssNumber(style.fontSize, baseSize)}pt;font-weight:${printDesign.escapeHtml(style.fontWeight)};font-style:${style.fontStyle};color:${printDesign.cssColor(style.color, "#1f2937")}`;
1087
+ const chunks = run.text.replace(/\r\n?/g, "\n").split("\n");
1088
+ chunks.forEach((chunk, index) => {
1089
+ if (index) paragraphs.push("");
1090
+ paragraphs[paragraphs.length - 1] += `<span style="${css}">${printDesign.escapeHtml(chunk)}</span>`;
1091
+ });
1092
+ }
1093
+ const paragraphCss = element.indentMode === "firstLine" && indent > 0 ? `text-indent:${printDesign.cssNumber(indent, 0)}mm;` : element.indentMode === "hanging" && indent > 0 ? `padding-left:${printDesign.cssNumber(indent, 0)}mm;text-indent:-${printDesign.cssNumber(indent, 0)}mm;box-sizing:border-box;` : "";
1094
+ const body = paragraphs.map(
1095
+ (paragraph, index) => `<div style="${element.prewrapped ? `white-space:pre;overflow:hidden;flex:none;box-sizing:border-box;padding-left:${printDesign.cssNumber(element.prewrappedIndents?.[index], 0)}mm;` : paragraphCss}">${paragraph || "<br>"}</div>`
1096
+ ).join("");
1097
+ return printDesign.renderPrintDesignHtmlFrame(
1098
+ element,
1099
+ `<div style="width:100%;height:100%;overflow:hidden;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-all;text-spacing-trim:space-all;text-autospace:no-autospace;line-height:${printDesign.cssNumber(element.lineHeight, 1.35)};font-family:${printDesign.escapeHtml(printDesign.cssFont(element.fontFamily))};font-size:${baseSize}pt;font-weight:${printDesign.escapeHtml(element.fontWeight ?? "400")};font-style:${element.fontStyle ?? "normal"};color:${printDesign.cssColor(element.color, "#1f2937")};text-align:${element.textAlign ?? "left"};display:flex;flex-direction:column;justify-content:${element.verticalAlign === "middle" ? "center" : element.verticalAlign === "bottom" ? "flex-end" : "flex-start"}">${body}</div>`
1100
+ );
1101
+ }
1102
+
1103
+ // src/plugins/rich-text/pagination.ts
1104
+ function measureLines(element) {
1105
+ const canvas = typeof document !== "undefined" ? document.createElement("canvas") : null;
1106
+ const context = canvas?.getContext("2d");
1107
+ return layoutRichTextLines(element, element.width, 1, (text, style, size) => {
1108
+ if (context) {
1109
+ context.font = `${style.fontStyle} ${style.fontWeight} ${size}px ${style.fontFamily}`;
1110
+ return context.measureText(text).width;
1111
+ }
1112
+ return size * (/[^\p{ASCII}]/u.test(text) ? 1 : 0.55);
1113
+ });
1114
+ }
1115
+ function linesToRuns(lines) {
1116
+ const result = [];
1117
+ for (const [index, line] of lines.entries()) {
1118
+ if (index) result.push({ text: "\n" });
1119
+ for (const char of line.chars) {
1120
+ const previous = result[result.length - 1];
1121
+ const style = char.style;
1122
+ if (previous && JSON.stringify(previous.style) === JSON.stringify(style))
1123
+ previous.text += char.text;
1124
+ else result.push({ text: char.text, style });
1125
+ }
1126
+ }
1127
+ return result;
1128
+ }
1129
+ function truncateRichTextOverflow(element, height, mode) {
1130
+ const lines = measureLines(element);
1131
+ const visible = [];
1132
+ let used = 0;
1133
+ for (const line of lines) {
1134
+ if (visible.length && used + line.height > height) break;
1135
+ visible.push({ ...line, chars: [...line.chars] });
1136
+ used += line.height;
1137
+ }
1138
+ if (mode === "ellipsis" && visible.length < lines.length && visible.length) {
1139
+ const last = visible[visible.length - 1];
1140
+ const style = last.chars[last.chars.length - 1]?.style ?? {
1141
+ fontFamily: element.fontFamily ?? "Arial, sans-serif",
1142
+ fontSize: element.fontSize ?? 14,
1143
+ fontWeight: element.fontWeight ?? "400",
1144
+ fontStyle: element.fontStyle ?? "normal",
1145
+ color: element.color ?? "#1f2937"
1146
+ };
1147
+ const ellipsisWidth = style.fontSize * 25.4 / 72;
1148
+ while (last.chars.length && last.width + ellipsisWidth > element.width - last.indent) {
1149
+ last.width -= last.chars.pop().width;
1150
+ }
1151
+ last.chars.push({ text: "\u2026", style, width: ellipsisWidth });
1152
+ last.width += ellipsisWidth;
1153
+ }
1154
+ return {
1155
+ ...element,
1156
+ runs: linesToRuns(visible),
1157
+ prewrapped: true,
1158
+ prewrappedIndents: visible.map((line) => line.indent),
1159
+ verticalAlign: "top"
1160
+ };
1161
+ }
1162
+ function paginateRichText(element, context) {
1163
+ const lines = measureLines(element);
1164
+ let pageIndex = context.startPage;
1165
+ let y = context.startY;
1166
+ let offset = 0;
1167
+ do {
1168
+ const remaining = () => context.bottom - y;
1169
+ if (remaining() < (lines[offset]?.height ?? 0) && y > context.top) {
1170
+ pageIndex++;
1171
+ y = context.top;
1172
+ }
1173
+ const chunk = [];
1174
+ let height = 0;
1175
+ while (offset < lines.length && (!chunk.length || height + lines[offset].height <= remaining())) {
1176
+ chunk.push(lines[offset]);
1177
+ height += lines[offset].height;
1178
+ offset++;
1179
+ }
1180
+ const continues = offset < lines.length;
1181
+ const finalHeight = continues ? Math.max(0, remaining()) : Math.max(height, element.height);
1182
+ context.pageAt(pageIndex).elements.push({
1183
+ ...element,
1184
+ id: `${element.id}:flow:${pageIndex}`,
1185
+ previewSourceId: element.previewSourceId ?? element.id,
1186
+ y,
1187
+ height: Math.min(Math.max(0, remaining()), finalHeight),
1188
+ runs: linesToRuns(chunk),
1189
+ prewrapped: true,
1190
+ prewrappedIndents: chunk.map((line) => line.indent),
1191
+ verticalAlign: "top"
1192
+ });
1193
+ y += Math.min(Math.max(0, remaining()), finalHeight);
1194
+ if (continues) {
1195
+ pageIndex++;
1196
+ y = context.top;
1197
+ }
1198
+ } while (offset < lines.length);
1199
+ return {
1200
+ logicalEnd: pageIndex * (context.bottom - context.top) + (y - context.top)
1201
+ };
1202
+ }
1203
+ function measureRichTextFlowHeight(element) {
1204
+ return Math.max(
1205
+ element.height,
1206
+ measureLines(element).reduce((height, line) => height + line.height, 0)
1207
+ );
1208
+ }
1209
+
1210
+ // src/plugins/rich-text/native.ts
1211
+ var richTextNativePlugin = defineNativePlugin(
1212
+ "richText",
1213
+ "0.1.1",
1214
+ printDesign.definePrintDesignPluginRenderer({
1215
+ type: "richText",
1216
+ validate: validateRichTextElement,
1217
+ drawCanvas: drawRichTextElement,
1218
+ renderHtml: (element) => renderRichTextHtml(element),
1219
+ paginate: paginateRichText,
1220
+ measureFlowHeight: measureRichTextFlowHeight,
1221
+ truncateOverflow: truncateRichTextOverflow
1222
+ })
1223
+ );
885
1224
  var drawListElement = (element, context) => {
886
1225
  const { ctx, x, y, width, height, scale, data } = context;
887
1226
  const row = Math.max(1, element.rowHeight ?? 8) * scale;
@@ -982,8 +1321,8 @@ function itemPaths(text) {
982
1321
  return [...text.matchAll(LIST_EXPRESSION)].map((match) => match[1]);
983
1322
  }
984
1323
  function listBindingInfo(element) {
985
- const paths = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
986
- return { bound: paths.length > 0, paths };
1324
+ const paths2 = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
1325
+ return { bound: paths2.length > 0, paths: paths2 };
987
1326
  }
988
1327
  function validateListTemplateData(element, data) {
989
1328
  if (!data) return [];
@@ -1098,9 +1437,9 @@ function dateTimeBindingInfo(element) {
1098
1437
  }
1099
1438
  function validateDateTimeTemplateData(element, data) {
1100
1439
  if (!data) return [];
1101
- const { bound, paths } = dateTimeBindingInfo(element);
1440
+ const { bound, paths: paths2 } = dateTimeBindingInfo(element);
1102
1441
  if (!bound) return [];
1103
- const expression = paths[0];
1442
+ const expression = paths2[0];
1104
1443
  if (!expression) return ["\u672A\u914D\u7F6E\u65E5\u671F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
1105
1444
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1106
1445
  const text = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
@@ -1227,9 +1566,9 @@ function moneyUpperBindingInfo(element) {
1227
1566
  }
1228
1567
  function validateMoneyUpperTemplateData(element, data) {
1229
1568
  if (!data) return [];
1230
- const { bound, paths } = moneyUpperBindingInfo(element);
1569
+ const { bound, paths: paths2 } = moneyUpperBindingInfo(element);
1231
1570
  if (!bound) return [];
1232
- const expression = paths[0];
1571
+ const expression = paths2[0];
1233
1572
  if (!expression) return ["\u672A\u914D\u7F6E\u91D1\u989D\u7ED1\u5B9A\u5B57\u6BB5"];
1234
1573
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1235
1574
  const numeric2 = typeof value === "number" || typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
@@ -1309,9 +1648,9 @@ function pageNumberBindingInfo(element) {
1309
1648
  }
1310
1649
  function validatePageNumberTemplateData(element, data) {
1311
1650
  if (!data) return [];
1312
- const { bound, paths } = pageNumberBindingInfo(element);
1651
+ const { bound, paths: paths2 } = pageNumberBindingInfo(element);
1313
1652
  if (!bound) return [];
1314
- const expression = paths[0];
1653
+ const expression = paths2[0];
1315
1654
  if (!expression) return ["\u672A\u914D\u7F6E\u9875\u7801\u524D\u7F00\u7ED1\u5B9A\u5B57\u6BB5"];
1316
1655
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1317
1656
  return typeof value === "string" && value.trim() !== "" || typeof value === "number" || typeof value === "boolean" ? [] : [`\u7684\u9875\u7801\u524D\u7F00\u5B57\u6BB5\u300C${expression}\u300D\u5728\u5F53\u524D\u6570\u636E\u4E2D\u4E0D\u5B58\u5728`];
@@ -1413,23 +1752,18 @@ function renderWatermarkHtml(element, data, preciseClip = false) {
1413
1752
  const text = printDesign.escapeHtml(
1414
1753
  element.dataConfig ? element.text : printDesign.resolveDesignText(element.text, data)
1415
1754
  );
1416
- if (!preciseClip) {
1417
- const fontSize2 = printDesign.cssNumber(element.fontSize, 24);
1418
- const cell = `<span style="color:${printDesign.cssColor(element.color, "#94a3b8")};font-size:${fontSize2}pt;transform:rotate(${printDesign.cssNumber(element.textRotation, 45)}deg) translateY(-${fontSize2 * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO}pt)">${text}</span>`;
1419
- const content2 = `<div class="pd-watermark" style="grid-template-columns:repeat(${columns},1fr);grid-template-rows:repeat(${rows},1fr)">${cell.repeat(rows * columns)}</div>`;
1420
- return printDesign.renderPrintDesignHtmlFrame(element, content2);
1421
- }
1422
1755
  const width = Math.max(0, element.width);
1423
1756
  const height = Math.max(0, element.height);
1424
1757
  const fontSize = printDesign.cssNumber(element.fontSize, 24) * 25.4 / 72;
1425
1758
  const color2 = printDesign.cssColor(element.color, "#94a3b8");
1426
1759
  const rotation = printDesign.cssNumber(element.textRotation, 45);
1760
+ const baselineFactor = preciseClip ? 0.3 : 0.39;
1427
1761
  const cells = Array.from({ length: rows * columns }, (_, index) => {
1428
1762
  const centerX = (index % columns + 0.5) * (width / columns);
1429
1763
  const centerY = (Math.floor(index / columns) + 0.5) * (height / rows);
1430
- return `<text x="${centerX}" y="${centerY + fontSize * 0.3}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1764
+ return `<text x="${centerX}" y="${centerY + fontSize * baselineFactor}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1431
1765
  }).join("");
1432
- const content = `<svg class="pd-watermark" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${printDesign.escapeHtml(printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1766
+ const content = `<svg class="pd-watermark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${printDesign.escapeHtml(printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1433
1767
  return printDesign.renderPrintDesignHtmlFrame(element, content);
1434
1768
  }
1435
1769
 
@@ -1454,9 +1788,9 @@ function watermarkBindingInfo(element) {
1454
1788
  }
1455
1789
  function validateWatermarkTemplateData(element, data) {
1456
1790
  if (!data) return [];
1457
- const { bound, paths } = watermarkBindingInfo(element);
1791
+ const { bound, paths: paths2 } = watermarkBindingInfo(element);
1458
1792
  if (!bound) return [];
1459
- const expression = paths[0];
1793
+ const expression = paths2[0];
1460
1794
  if (!expression) return ["\u672A\u914D\u7F6E\u6C34\u5370\u6587\u5B57\u7ED1\u5B9A\u5B57\u6BB5"];
1461
1795
  for (const match of expression.matchAll(
1462
1796
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -1471,7 +1805,7 @@ function validateWatermarkTemplateData(element, data) {
1471
1805
  // src/plugins/watermark/native.ts
1472
1806
  var watermarkNativePlugin = defineNativePlugin(
1473
1807
  "watermark",
1474
- "0.1.9",
1808
+ "0.1.10",
1475
1809
  printDesign.definePrintDesignPluginRenderer({
1476
1810
  type: "watermark",
1477
1811
  validate: validateWatermarkElement,
@@ -1491,8 +1825,7 @@ var watermarkNativePlugin = defineNativePlugin(
1491
1825
  physical && physical.y + physical.height > context.page.height
1492
1826
  )
1493
1827
  );
1494
- },
1495
- htmlCss: ".pd-watermark{display:grid;overflow:hidden;width:100%;height:100%}.pd-watermark span{display:flex;align-items:center;justify-content:center;white-space:nowrap}"
1828
+ }
1496
1829
  }),
1497
1830
  [{ id: "builtin.text", minVersion: "0.1.16" }]
1498
1831
  );
@@ -4133,8 +4466,8 @@ function labelPaths(element) {
4133
4466
  );
4134
4467
  }
4135
4468
  function connectorBindingInfo(element) {
4136
- const paths = [...new Set(labelPaths(element))];
4137
- return { bound: paths.length > 0, paths };
4469
+ const paths2 = [...new Set(labelPaths(element))];
4470
+ return { bound: paths2.length > 0, paths: paths2 };
4138
4471
  }
4139
4472
  function validateConnectorTemplateData(element, data) {
4140
4473
  if (!data) return [];
@@ -4936,13 +5269,13 @@ function gridMarkup(element, data) {
4936
5269
 
4937
5270
  // src/plugins/grid/data/binding.ts
4938
5271
  function getGridBindingInfo(element) {
4939
- const paths = [
5272
+ const paths2 = [
4940
5273
  element.contentPath,
4941
5274
  element.loopsPath,
4942
5275
  element.columnLoopsPath,
4943
5276
  ...(element.cells ?? []).filter((cell) => cell.contentMode === "binding").map((cell) => cell.contentPath)
4944
5277
  ].map((path) => path?.trim()).filter((path) => !!path);
4945
- return { bound: paths.length > 0, paths };
5278
+ return { bound: paths2.length > 0, paths: paths2 };
4946
5279
  }
4947
5280
  function validateGridTemplateData(element, data) {
4948
5281
  if (!data) return [];
@@ -6190,9 +6523,9 @@ function clockBindingInfo(element) {
6190
6523
  }
6191
6524
  function validateClockTemplateData(element, data) {
6192
6525
  if (!data) return [];
6193
- const { bound, paths } = clockBindingInfo(element);
6526
+ const { bound, paths: paths2 } = clockBindingInfo(element);
6194
6527
  if (!bound) return [];
6195
- const expression = paths[0];
6528
+ const expression = paths2[0];
6196
6529
  if (!expression) return ["\u672A\u914D\u7F6E\u65F6\u949F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
6197
6530
  for (const match of expression.matchAll(
6198
6531
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6431,9 +6764,9 @@ function imageBindingInfo(element) {
6431
6764
  }
6432
6765
  function validateImageTemplateData(element, data) {
6433
6766
  if (!data) return [];
6434
- const { bound, paths } = imageBindingInfo(element);
6767
+ const { bound, paths: paths2 } = imageBindingInfo(element);
6435
6768
  if (!bound) return [];
6436
- const expression = paths[0];
6769
+ const expression = paths2[0];
6437
6770
  if (!expression) return ["\u672A\u914D\u7F6E\u56FE\u7247\u5730\u5740\u7ED1\u5B9A\u5B57\u6BB5"];
6438
6771
  for (const match of expression.matchAll(
6439
6772
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6787,9 +7120,9 @@ function barcodeBindingInfo(element) {
6787
7120
  }
6788
7121
  function validateBarcodeTemplateData(element, data) {
6789
7122
  if (!data) return [];
6790
- const { bound, paths } = barcodeBindingInfo(element);
7123
+ const { bound, paths: paths2 } = barcodeBindingInfo(element);
6791
7124
  if (!bound) return [];
6792
- const expression = paths[0];
7125
+ const expression = paths2[0];
6793
7126
  if (!expression) return ["\u672A\u914D\u7F6E\u6761\u5F62\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6794
7127
  for (const match of expression.matchAll(
6795
7128
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6889,9 +7222,9 @@ function qrcodeBindingInfo(element) {
6889
7222
  }
6890
7223
  function validateQrCodeTemplateData(element, data) {
6891
7224
  if (!data) return [];
6892
- const { bound, paths } = qrcodeBindingInfo(element);
7225
+ const { bound, paths: paths2 } = qrcodeBindingInfo(element);
6893
7226
  if (!bound) return [];
6894
- const expression = paths[0];
7227
+ const expression = paths2[0];
6895
7228
  if (!expression) return ["\u672A\u914D\u7F6E\u4E8C\u7EF4\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6896
7229
  for (const match of expression.matchAll(
6897
7230
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -7817,7 +8150,7 @@ function resolveDiagonalCount(count) {
7817
8150
  function diagonalCellLayout(direction, count, corner) {
7818
8151
  const lineCount = resolveDiagonalCount(count);
7819
8152
  const activeCorner = lineCount === 1 ? direction === "down" ? "top-left" : "bottom-left" : corner ?? (direction === "down" ? "top-left" : "bottom-left");
7820
- const paths = {
8153
+ const paths2 = {
7821
8154
  "top-left": [
7822
8155
  [0, 0],
7823
8156
  [1, 0],
@@ -7843,7 +8176,7 @@ function diagonalCellLayout(direction, count, corner) {
7843
8176
  [0, 1]
7844
8177
  ]
7845
8178
  };
7846
- const [apex, first, bend, last] = paths[activeCorner];
8179
+ const [apex, first, bend, last] = paths2[activeCorner];
7847
8180
  const farPoint = (position) => position <= 1 ? [
7848
8181
  first[0] + (bend[0] - first[0]) * position,
7849
8182
  first[1] + (bend[1] - first[1]) * position
@@ -9379,6 +9712,10 @@ function hitTableColumnBoundary(element, point, scale, includeSelector = false,
9379
9712
  }
9380
9713
  return nearest;
9381
9714
  }
9715
+ function boundaryHitRadius(height, scale, selector) {
9716
+ const radius = 5 / scale;
9717
+ return selector || height * scale >= 12 ? radius : Math.min(radius, height / 4);
9718
+ }
9382
9719
  function unmergedBoundarySegments(element, rowIndex, merges) {
9383
9720
  if (!merges.length) return [{ x: element.x + 3, width: element.width - 6 }];
9384
9721
  const columns = tableLeafColumns(
@@ -9420,11 +9757,25 @@ function tableHeaderResizeLayout(element, scale, data = {}) {
9420
9757
  for (let index = 0; index < depth; index++) {
9421
9758
  const edge = element.y + (index + 1) * height;
9422
9759
  if (edge > visibleBottom + 1e-9) break;
9423
- const shared = { rowIndex: index, edge, height, y: edge - 5 / scale };
9424
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9760
+ const shared = { rowIndex: index, edge, height };
9761
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9762
+ regions.push({
9763
+ ...shared,
9764
+ x: element.x - 6,
9765
+ width: 6,
9766
+ selector: true,
9767
+ radius: selectorRadius,
9768
+ y: edge - selectorRadius
9769
+ });
9425
9770
  if (edge < visibleBottom - 1e-9 && element.width > 6)
9426
9771
  for (const segment of unmergedBoundarySegments(element, index, headers))
9427
- regions.push({ ...shared, ...segment, selector: false });
9772
+ regions.push({
9773
+ ...shared,
9774
+ ...segment,
9775
+ selector: false,
9776
+ radius: boundaryHitRadius(height, scale, false),
9777
+ y: edge - boundaryHitRadius(height, scale, false)
9778
+ });
9428
9779
  }
9429
9780
  return regions;
9430
9781
  }
@@ -9439,7 +9790,7 @@ function hitTableHeaderBoundary(element, point, scale, data = {}) {
9439
9790
  -(element.rotation ?? 0) * Math.PI / 180
9440
9791
  );
9441
9792
  const region = tableHeaderResizeLayout(element, scale, data).filter(
9442
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9793
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9443
9794
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9444
9795
  return region && {
9445
9796
  elementId: element.id,
@@ -9471,13 +9822,26 @@ function tableRowResizeLayout(element, scale, data = {}) {
9471
9822
  const shared = {
9472
9823
  rowIndex: index + (element.sourceRowOffset ?? 0),
9473
9824
  edge: boundary,
9474
- height,
9475
- y: boundary - 5 / scale
9825
+ height
9476
9826
  };
9477
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9827
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9828
+ regions.push({
9829
+ ...shared,
9830
+ x: element.x - 6,
9831
+ width: 6,
9832
+ selector: true,
9833
+ radius: selectorRadius,
9834
+ y: boundary - selectorRadius
9835
+ });
9478
9836
  if (index < heights.length - 1 && element.width > 6)
9479
9837
  for (const segment of unmergedBoundarySegments(element, index, cells))
9480
- regions.push({ ...shared, ...segment, selector: false });
9838
+ regions.push({
9839
+ ...shared,
9840
+ ...segment,
9841
+ selector: false,
9842
+ radius: boundaryHitRadius(height, scale, false),
9843
+ y: boundary - boundaryHitRadius(height, scale, false)
9844
+ });
9481
9845
  }
9482
9846
  return regions;
9483
9847
  }
@@ -9492,7 +9856,7 @@ function hitTableRowBoundary(element, point, scale, data = {}) {
9492
9856
  -(element.rotation ?? 0) * Math.PI / 180
9493
9857
  );
9494
9858
  const region = tableRowResizeLayout(element, scale, data).filter(
9495
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9859
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9496
9860
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9497
9861
  return region && {
9498
9862
  elementId: element.id,
@@ -9627,12 +9991,12 @@ function tableDebugRegions(table, context, options = {}) {
9627
9991
  ...owner,
9628
9992
  id: `${area}-resize:${index}`,
9629
9993
  category: "resize",
9630
- label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB15px${hit ? " \u547D\u4E2D" : ""}`,
9994
+ label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB1${Math.round(region.radius * scale)}px${hit ? " \u547D\u4E2D" : ""}`,
9631
9995
  bounds: {
9632
9996
  x: region.x,
9633
9997
  y: region.y,
9634
9998
  width: region.width,
9635
- height: 10 / scale
9999
+ height: region.radius * 2
9636
10000
  },
9637
10001
  interactive: true,
9638
10002
  hit,
@@ -10603,11 +10967,227 @@ function emptyTableRow(element) {
10603
10967
  );
10604
10968
  }
10605
10969
 
10970
+ // src/plugins/table/data/packed-report-defaults.ts
10971
+ function fillPackedReportDefaults(columns, rows, current) {
10972
+ const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
10973
+ const keys2 = visible.map(
10974
+ (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
10975
+ );
10976
+ const repeats = /* @__PURE__ */ new Map();
10977
+ keys2.forEach((key) => {
10978
+ const match = /^(.+?)([1-9]\d*)$/.exec(key);
10979
+ if (!match) return;
10980
+ const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
10981
+ slots.add(Number(match[2]));
10982
+ repeats.set(match[1], slots);
10983
+ });
10984
+ const series = [...repeats].filter(
10985
+ ([, slots]) => slots.has(1) && slots.has(2)
10986
+ );
10987
+ const itemsPerRow = Math.max(
10988
+ 1,
10989
+ ...series.map(([, slots]) => Math.max(...slots))
10990
+ );
10991
+ const sample = rows.find((row) => row && typeof row === "object") ?? {};
10992
+ const groupFields = {};
10993
+ keys2.forEach((key, index) => {
10994
+ const repeated = series.some(
10995
+ ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
10996
+ );
10997
+ if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
10998
+ groupFields[key] = key in sample ? key : "";
10999
+ }
11000
+ });
11001
+ const itemFields = series.map(([prefix]) => ({
11002
+ prefix,
11003
+ .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
11004
+ }));
11005
+ const totals = {};
11006
+ visible.forEach((column, index) => {
11007
+ const key = keys2[index];
11008
+ const summary = column.summary;
11009
+ const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
11010
+ if (key && summary && type === "sum") {
11011
+ const prefix = series.find(
11012
+ ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
11013
+ )?.[0];
11014
+ totals[key] = {
11015
+ sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
11016
+ ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
11017
+ };
11018
+ }
11019
+ });
11020
+ const subtotalLabelKey = keys2.find(
11021
+ (key) => key && !(key in totals) && !(key in groupFields)
11022
+ );
11023
+ const totalLabelKey = keys2.find((key) => key && !(key in totals));
11024
+ const subtotal = { ...totals };
11025
+ if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
11026
+ if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
11027
+ return {
11028
+ groupBy: current?.groupBy ?? [],
11029
+ itemsPerRow: current?.itemsPerRow ?? itemsPerRow,
11030
+ groupFields: Object.keys(current?.groupFields ?? {}).length ? current.groupFields : groupFields,
11031
+ groupMergeColumns: Object.keys(current?.groupFields ?? {}).length ? current.groupMergeColumns : keys2.flatMap(
11032
+ (key, index) => key && key in groupFields ? [index] : []
11033
+ ),
11034
+ itemFields: current?.itemFields?.length ? current.itemFields : itemFields,
11035
+ subtotal: Object.keys(current?.subtotal ?? {}).length ? current.subtotal : subtotal,
11036
+ subtotalMerges: current?.subtotalMerges ?? [],
11037
+ total: Object.keys(current?.total ?? {}).length ? current.total : totals,
11038
+ totalMerges: current?.totalMerges ?? [],
11039
+ appendRows: current?.appendRows ?? [],
11040
+ ...current?.footerElementIds ? { footerElementIds: current.footerElementIds } : {}
11041
+ };
11042
+ }
11043
+
11044
+ // src/plugins/table/interaction/agent-commands.ts
11045
+ function object(input) {
11046
+ if (!input || typeof input !== "object" || Array.isArray(input))
11047
+ throw new TypeError("\u8868\u683C\u547D\u4EE4\u53C2\u6570\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
11048
+ return input;
11049
+ }
11050
+ function safePart(value) {
11051
+ return !!value.trim() && !value.split(/[.[\]]/).some((part) => ["__proto__", "prototype", "constructor"].includes(part));
11052
+ }
11053
+ function fieldPath(input, label) {
11054
+ if (typeof input === "string" && safePart(input)) return input.trim();
11055
+ if (Array.isArray(input) && input.length > 0 && input.every(
11056
+ (part) => typeof part === "string" && safePart(part) || typeof part === "number" && Number.isInteger(part) && part >= 0
11057
+ ))
11058
+ return input;
11059
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D\u6216\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11060
+ }
11061
+ function paths(input, label) {
11062
+ if (input === void 0) return [];
11063
+ if (!Array.isArray(input)) throw new TypeError(`${label} \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
11064
+ return input.map((value) => fieldPath(value, label));
11065
+ }
11066
+ function stringPaths(input, label) {
11067
+ if (!Array.isArray(input) || !input.length)
11068
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11069
+ return input.map((value) => {
11070
+ if (typeof value !== "string" || !safePart(value))
11071
+ throw new TypeError(`${label} \u4E2D\u7684\u5B57\u6BB5\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`);
11072
+ return value.trim();
11073
+ });
11074
+ }
11075
+ function configureTableAutoMerge(element, rawPayload) {
11076
+ const payload = object(rawPayload);
11077
+ if (payload.enabled === false) return { ...element, mergeCell: void 0 };
11078
+ const rowKeys = paths(payload.rowKeys, "rowKeys");
11079
+ const rowColumns = paths(payload.rowColumns, "rowColumns");
11080
+ const columnKeys = paths(payload.columnKeys, "columnKeys");
11081
+ if (!rowKeys.length && !columnKeys.length)
11082
+ throw new TypeError(
11083
+ "\u81F3\u5C11\u63D0\u4F9B rowKeys \u6216 columnKeys\uFF1B\u5173\u95ED\u65F6\u4F20 enabled=false\u3002"
11084
+ );
11085
+ if (rowColumns.length && !rowKeys.length)
11086
+ throw new TypeError("\u8BBE\u7F6E rowColumns \u65F6\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B rowKeys\u3002");
11087
+ const visible = tableLeafColumns(element.columns).filter((column) => !column.hidden).map((column) => JSON.stringify(column.dataIndex));
11088
+ for (const path of [
11089
+ ...rowColumns.length ? rowColumns : rowKeys,
11090
+ ...columnKeys
11091
+ ])
11092
+ if (!visible.includes(JSON.stringify(path)))
11093
+ throw new TypeError(`\u5408\u5E76\u76EE\u6807\u5217\u4E0D\u5B58\u5728\uFF1A${JSON.stringify(path)}\u3002`);
11094
+ return {
11095
+ ...element,
11096
+ mergeCell: {
11097
+ ...rowKeys.length ? {
11098
+ row: {
11099
+ keys: rowKeys,
11100
+ ...rowColumns.length ? { columns: rowColumns } : {}
11101
+ }
11102
+ } : {},
11103
+ ...columnKeys.length ? { column: { keys: columnKeys } } : {}
11104
+ }
11105
+ };
11106
+ }
11107
+ function configureTableGroupAggregation(element, rawPayload, data) {
11108
+ const payload = object(rawPayload);
11109
+ if (payload.enabled === false) return { ...element, packedReport: void 0 };
11110
+ const groupBy = stringPaths(payload.groupBy, "groupBy");
11111
+ if (payload.itemsPerRow !== void 0 && (!Number.isInteger(payload.itemsPerRow) || Number(payload.itemsPerRow) < 1))
11112
+ throw new TypeError("itemsPerRow \u5FC5\u987B\u662F\u5927\u4E8E\u96F6\u7684\u6574\u6570\u3002");
11113
+ if (payload.sums !== void 0 && !Array.isArray(payload.sums))
11114
+ throw new TypeError("sums \u5FC5\u987B\u662F\u6570\u7EC4\u3002");
11115
+ const source = element.dataMode === "binding" ? resolveTableDataSource(data, element.dataPath) : element.dataSource;
11116
+ const rows = Array.isArray(source) ? source.filter(
11117
+ (row) => !!row && typeof row === "object" && !Array.isArray(row)
11118
+ ) : element.dataSource;
11119
+ for (const path of groupBy)
11120
+ if (rows.length && !rows.some((row) => printDesign.resolvePrintDesignDataPath(row, path) !== void 0))
11121
+ throw new TypeError(`\u5206\u7EC4\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${path}\u3002`);
11122
+ const report = fillPackedReportDefaults(
11123
+ element.columns,
11124
+ rows,
11125
+ element.packedReport
11126
+ );
11127
+ const visible = tableLeafColumns(element.columns).filter(
11128
+ (column) => !column.hidden
11129
+ );
11130
+ const groupFields = { ...report.groupFields };
11131
+ const subtotal = { ...report.subtotal };
11132
+ const total = { ...report.total };
11133
+ const sumColumns = /* @__PURE__ */ new Set();
11134
+ for (const raw of payload.sums ?? []) {
11135
+ const sum = object(raw);
11136
+ if (typeof sum.column !== "string" || !safePart(sum.column))
11137
+ throw new TypeError("sums.column \u5FC5\u987B\u662F\u8868\u683C\u5217\u7684 dataIndex \u5B57\u7B26\u4E32\u3002");
11138
+ const column = sum.column.trim();
11139
+ if (!visible.some((item) => item.dataIndex === column))
11140
+ throw new TypeError(`\u6C47\u603B\u5217\u4E0D\u5B58\u5728\uFF1A${column}\u3002`);
11141
+ if (sumColumns.has(column)) throw new TypeError(`\u6C47\u603B\u5217\u91CD\u590D\uFF1A${column}\u3002`);
11142
+ if (typeof sum.path !== "string" || !safePart(sum.path))
11143
+ throw new TypeError("sums.path \u5FC5\u987B\u662F\u539F\u59CB\u6570\u636E\u7684\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u3002");
11144
+ if (rows.length && !rows.some(
11145
+ (row) => printDesign.resolvePrintDesignDataPath(row, sum.path) !== void 0
11146
+ ))
11147
+ throw new TypeError(`\u6C42\u548C\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${sum.path}\u3002`);
11148
+ if (sum.decimals !== void 0 && (!Number.isInteger(sum.decimals) || Number(sum.decimals) < 0 || Number(sum.decimals) > 10))
11149
+ throw new TypeError("sums.decimals \u5FC5\u987B\u662F 0 \u5230 10 \u7684\u6574\u6570\u3002");
11150
+ sumColumns.add(column);
11151
+ delete groupFields[column];
11152
+ const rule = {
11153
+ sumPath: sum.path.trim(),
11154
+ ...sum.decimals === void 0 ? {} : { decimals: sum.decimals }
11155
+ };
11156
+ subtotal[column] = rule;
11157
+ total[column] = rule;
11158
+ }
11159
+ if (sumColumns.size && !Object.values(subtotal).some((rule) => rule.text === "\u5C0F\u8BA1")) {
11160
+ const labelColumn = visible.find(
11161
+ (column) => typeof column.dataIndex === "string" && !sumColumns.has(column.dataIndex)
11162
+ );
11163
+ if (typeof labelColumn?.dataIndex === "string")
11164
+ subtotal[labelColumn.dataIndex] = { text: "\u5C0F\u8BA1" };
11165
+ }
11166
+ return {
11167
+ ...element,
11168
+ packedReport: {
11169
+ ...report,
11170
+ groupBy,
11171
+ ...payload.itemsPerRow === void 0 ? {} : { itemsPerRow: payload.itemsPerRow },
11172
+ groupFields,
11173
+ groupMergeColumns: report.groupMergeColumns.filter(
11174
+ (index) => !sumColumns.has(String(visible[index]?.dataIndex ?? ""))
11175
+ ),
11176
+ subtotal,
11177
+ total
11178
+ }
11179
+ };
11180
+ }
11181
+
10606
11182
  // src/plugins/table/interaction/commands.ts
10607
11183
  var tableCommands = {
10608
11184
  execute(element, command, rawPayload, context) {
10609
11185
  if (element.locked) return;
10610
11186
  if (!rawPayload || typeof rawPayload !== "object") return;
11187
+ if (command === "configure-auto-merge")
11188
+ return configureTableAutoMerge(element, rawPayload);
11189
+ if (command === "configure-group-aggregation")
11190
+ return configureTableGroupAggregation(element, rawPayload, context.data);
10611
11191
  const payload = rawPayload;
10612
11192
  const rowIndex = payload.rowIndex ?? 0;
10613
11193
  const columnIndex = payload.columnIndex ?? 0;
@@ -11002,7 +11582,7 @@ function validateTableTemplateData(element, data) {
11002
11582
  // src/plugins/table/native.ts
11003
11583
  var tableNativePlugin = defineNativePlugin(
11004
11584
  "table",
11005
- "0.1.69",
11585
+ "0.1.70",
11006
11586
  printDesign.definePrintDesignPluginRenderer({
11007
11587
  type: "table",
11008
11588
  validate: validateTableElement,
@@ -11948,6 +12528,7 @@ var ganttNativePlugin = defineNativePlugin(
11948
12528
  // src/native.ts
11949
12529
  var builtinNativeComponentPlugins = [
11950
12530
  textNativePlugin,
12531
+ richTextNativePlugin,
11951
12532
  listNativePlugin,
11952
12533
  dateTimeNativePlugin,
11953
12534
  moneyUpperNativePlugin,