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

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