@canvas-components/print-design-plugin 0.1.7 → 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/native.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 [];
@@ -994,13 +1333,45 @@ function validateListTemplateData(element, data) {
994
1333
  );
995
1334
  }
996
1335
 
1336
+ // src/plugins/list/interaction/commands.ts
1337
+ var listCommands = {
1338
+ execute(element, command, payload) {
1339
+ if (element.locked || !payload || typeof payload !== "object") return;
1340
+ const args = payload;
1341
+ const index = args.index;
1342
+ if (!Number.isInteger(index)) return;
1343
+ const at = index;
1344
+ const items = [...element.items];
1345
+ if (command === "remove-item") {
1346
+ if (at < 0 || at >= items.length) return;
1347
+ items.splice(at, 1);
1348
+ } else if (command === "insert-item") {
1349
+ if (at < 0 || at > items.length || typeof args.text !== "string") return;
1350
+ items.splice(at, 0, { text: args.text, checked: false });
1351
+ } else if (command === "update-item") {
1352
+ if (at < 0 || at >= items.length) return;
1353
+ if (args.text !== void 0 && typeof args.text !== "string") return;
1354
+ if (args.checked !== void 0 && typeof args.checked !== "boolean")
1355
+ return;
1356
+ items[at] = {
1357
+ ...items[at],
1358
+ ...args.text === void 0 ? {} : { text: args.text },
1359
+ ...args.checked === void 0 ? {} : { checked: args.checked }
1360
+ };
1361
+ } else return;
1362
+ const next = { ...element, items };
1363
+ return validateListElement(next) ? next : void 0;
1364
+ }
1365
+ };
1366
+
997
1367
  // src/plugins/list/native.ts
998
1368
  var listNativePlugin = defineNativePlugin(
999
1369
  "list",
1000
- "0.1.8",
1370
+ "0.1.9",
1001
1371
  printDesign.definePrintDesignPluginRenderer({
1002
1372
  type: "list",
1003
1373
  validate: validateListElement,
1374
+ commands: listCommands,
1004
1375
  bindingInfo: listBindingInfo,
1005
1376
  validateTemplateData: validateListTemplateData,
1006
1377
  drawCanvas: drawListElement,
@@ -1066,9 +1437,9 @@ function dateTimeBindingInfo(element) {
1066
1437
  }
1067
1438
  function validateDateTimeTemplateData(element, data) {
1068
1439
  if (!data) return [];
1069
- const { bound, paths } = dateTimeBindingInfo(element);
1440
+ const { bound, paths: paths2 } = dateTimeBindingInfo(element);
1070
1441
  if (!bound) return [];
1071
- const expression = paths[0];
1442
+ const expression = paths2[0];
1072
1443
  if (!expression) return ["\u672A\u914D\u7F6E\u65E5\u671F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
1073
1444
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1074
1445
  const text = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
@@ -1195,9 +1566,9 @@ function moneyUpperBindingInfo(element) {
1195
1566
  }
1196
1567
  function validateMoneyUpperTemplateData(element, data) {
1197
1568
  if (!data) return [];
1198
- const { bound, paths } = moneyUpperBindingInfo(element);
1569
+ const { bound, paths: paths2 } = moneyUpperBindingInfo(element);
1199
1570
  if (!bound) return [];
1200
- const expression = paths[0];
1571
+ const expression = paths2[0];
1201
1572
  if (!expression) return ["\u672A\u914D\u7F6E\u91D1\u989D\u7ED1\u5B9A\u5B57\u6BB5"];
1202
1573
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1203
1574
  const numeric2 = typeof value === "number" || typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
@@ -1277,9 +1648,9 @@ function pageNumberBindingInfo(element) {
1277
1648
  }
1278
1649
  function validatePageNumberTemplateData(element, data) {
1279
1650
  if (!data) return [];
1280
- const { bound, paths } = pageNumberBindingInfo(element);
1651
+ const { bound, paths: paths2 } = pageNumberBindingInfo(element);
1281
1652
  if (!bound) return [];
1282
- const expression = paths[0];
1653
+ const expression = paths2[0];
1283
1654
  if (!expression) return ["\u672A\u914D\u7F6E\u9875\u7801\u524D\u7F00\u7ED1\u5B9A\u5B57\u6BB5"];
1284
1655
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1285
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`];
@@ -1381,23 +1752,18 @@ function renderWatermarkHtml(element, data, preciseClip = false) {
1381
1752
  const text = printDesign.escapeHtml(
1382
1753
  element.dataConfig ? element.text : printDesign.resolveDesignText(element.text, data)
1383
1754
  );
1384
- if (!preciseClip) {
1385
- const fontSize2 = printDesign.cssNumber(element.fontSize, 24);
1386
- 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>`;
1387
- const content2 = `<div class="pd-watermark" style="grid-template-columns:repeat(${columns},1fr);grid-template-rows:repeat(${rows},1fr)">${cell.repeat(rows * columns)}</div>`;
1388
- return printDesign.renderPrintDesignHtmlFrame(element, content2);
1389
- }
1390
1755
  const width = Math.max(0, element.width);
1391
1756
  const height = Math.max(0, element.height);
1392
1757
  const fontSize = printDesign.cssNumber(element.fontSize, 24) * 25.4 / 72;
1393
1758
  const color2 = printDesign.cssColor(element.color, "#94a3b8");
1394
1759
  const rotation = printDesign.cssNumber(element.textRotation, 45);
1760
+ const baselineFactor = preciseClip ? 0.3 : 0.39;
1395
1761
  const cells = Array.from({ length: rows * columns }, (_, index) => {
1396
1762
  const centerX = (index % columns + 0.5) * (width / columns);
1397
1763
  const centerY = (Math.floor(index / columns) + 0.5) * (height / rows);
1398
- 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>`;
1399
1765
  }).join("");
1400
- 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>`;
1401
1767
  return printDesign.renderPrintDesignHtmlFrame(element, content);
1402
1768
  }
1403
1769
 
@@ -1422,9 +1788,9 @@ function watermarkBindingInfo(element) {
1422
1788
  }
1423
1789
  function validateWatermarkTemplateData(element, data) {
1424
1790
  if (!data) return [];
1425
- const { bound, paths } = watermarkBindingInfo(element);
1791
+ const { bound, paths: paths2 } = watermarkBindingInfo(element);
1426
1792
  if (!bound) return [];
1427
- const expression = paths[0];
1793
+ const expression = paths2[0];
1428
1794
  if (!expression) return ["\u672A\u914D\u7F6E\u6C34\u5370\u6587\u5B57\u7ED1\u5B9A\u5B57\u6BB5"];
1429
1795
  for (const match of expression.matchAll(
1430
1796
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -1439,7 +1805,7 @@ function validateWatermarkTemplateData(element, data) {
1439
1805
  // src/plugins/watermark/native.ts
1440
1806
  var watermarkNativePlugin = defineNativePlugin(
1441
1807
  "watermark",
1442
- "0.1.9",
1808
+ "0.1.10",
1443
1809
  printDesign.definePrintDesignPluginRenderer({
1444
1810
  type: "watermark",
1445
1811
  validate: validateWatermarkElement,
@@ -1459,8 +1825,7 @@ var watermarkNativePlugin = defineNativePlugin(
1459
1825
  physical && physical.y + physical.height > context.page.height
1460
1826
  )
1461
1827
  );
1462
- },
1463
- 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
+ }
1464
1829
  }),
1465
1830
  [{ id: "builtin.text", minVersion: "0.1.16" }]
1466
1831
  );
@@ -2637,16 +3002,51 @@ function pointToSegmentDistance(point, a, b) {
2637
3002
  return Math.hypot(point.x - a.x - t * dx, point.y - a.y - t * dy);
2638
3003
  }
2639
3004
 
3005
+ // src/plugins/shape/interaction/commands.ts
3006
+ var validPoints = (value) => Array.isArray(value) && value.every(
3007
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
3008
+ );
3009
+ var shapeCommands = {
3010
+ execute(element, command, payload) {
3011
+ if (element.locked || !payload || typeof payload !== "object") return;
3012
+ const args = payload;
3013
+ if (!validPoints(args.points)) return;
3014
+ const points = args.points;
3015
+ let next;
3016
+ if (command === "set-polygon-points") {
3017
+ if (!["triangle", "polygon", "star"].includes(element.shape) || points.length < 3)
3018
+ return;
3019
+ next = { ...element, polygonPoints: points };
3020
+ } else if (command === "set-curve-points") {
3021
+ if (!["curve-quadratic", "curve-cubic", "curve-multi"].includes(
3022
+ element.shape
3023
+ ) || points.length < 2)
3024
+ return;
3025
+ next = { ...element, curvePoints: points };
3026
+ } else if (command === "set-path-points") {
3027
+ if (element.shape !== "curve-path") return;
3028
+ if (args.closed !== void 0 && typeof args.closed !== "boolean") return;
3029
+ next = {
3030
+ ...element,
3031
+ pathPoints: points,
3032
+ ...args.closed === void 0 ? {} : { pathClosed: args.closed }
3033
+ };
3034
+ } else return;
3035
+ return validateShapeElement(next) ? next : void 0;
3036
+ }
3037
+ };
3038
+
2640
3039
  // src/plugins/shape/native.ts
2641
3040
  var shapeNativePlugin = defineNativePlugin(
2642
3041
  "shape",
2643
- "0.1.20",
3042
+ "0.1.21",
2644
3043
  printDesign.definePrintDesignPluginRenderer({
2645
3044
  type: "shape",
2646
3045
  dataFields: shapeDataFields,
2647
3046
  bindingInfo: (element) => registeredFieldBindingInfo(element, shapeDataFields),
2648
3047
  validateTemplateData: (element, data) => validateRegisteredFieldBindings(element, shapeDataFields, data),
2649
3048
  validate: validateShapeElement,
3049
+ commands: shapeCommands,
2650
3050
  drawCanvas: drawShapeElement,
2651
3051
  renderHtml: (element, context) => renderShapeHtml(element, context.data),
2652
3052
  hitTest: hitShape,
@@ -2988,13 +3388,42 @@ var brushPointerStroke = {
2988
3388
  }
2989
3389
  };
2990
3390
 
3391
+ // src/plugins/brush/interaction/commands.ts
3392
+ var brushCommands = {
3393
+ execute(element, command, payload) {
3394
+ if (element.locked || !payload || typeof payload !== "object") return;
3395
+ const args = payload;
3396
+ if (command === "append-stroke") {
3397
+ if (!Array.isArray(args.points) || args.points.length < 2) return;
3398
+ const next2 = {
3399
+ ...element,
3400
+ strokes: [
3401
+ ...element.strokes,
3402
+ args.points
3403
+ ]
3404
+ };
3405
+ return validateBrushElement(next2) ? next2 : void 0;
3406
+ }
3407
+ if (command !== "remove-stroke" || !Number.isInteger(args.index)) return;
3408
+ const index = args.index;
3409
+ if (index < 0 || index >= element.strokes.length) return;
3410
+ const next = {
3411
+ ...element,
3412
+ strokes: element.strokes.filter((_, at) => at !== index),
3413
+ strokeStyles: element.strokeStyles?.filter((_, at) => at !== index)
3414
+ };
3415
+ return validateBrushElement(next) ? next : void 0;
3416
+ }
3417
+ };
3418
+
2991
3419
  // src/plugins/brush/native.ts
2992
3420
  var brushNativePlugin = defineNativePlugin(
2993
3421
  "brush",
2994
- "0.1.4",
3422
+ "0.1.5",
2995
3423
  printDesign.definePrintDesignPluginRenderer({
2996
3424
  type: "brush",
2997
3425
  validate: validateBrushElement,
3426
+ commands: brushCommands,
2998
3427
  drawCanvas: drawBrushElement,
2999
3428
  renderHtml: (element) => renderBrushHtml(element),
3000
3429
  hitTest: hitBrush,
@@ -3990,6 +4419,46 @@ function validateConnectorElement(value) {
3990
4419
  const validPoint = (point) => !!point && Number.isFinite(point.x) && Number.isFinite(point.y);
3991
4420
  return element.type === "connector" && (element.lineType === void 0 || ["straight", "curve", "polyline"].includes(element.lineType)) && (element.polylinePoints === void 0 || Array.isArray(element.polylinePoints) && element.polylinePoints.every(validPoint)) && (element.strokeWidth === void 0 || Number.isFinite(element.strokeWidth) && element.strokeWidth >= 0) && (element.textPosition === void 0 || Number.isFinite(element.textPosition) && element.textPosition >= 0 && element.textPosition <= 1);
3992
4421
  }
4422
+
4423
+ // src/plugins/connector/interaction/commands.ts
4424
+ var validEndpoint = (value) => {
4425
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
4426
+ const endpoint2 = value;
4427
+ return (endpoint2.elementId === void 0 || typeof endpoint2.elementId === "string") && (endpoint2.anchor === void 0 || typeof endpoint2.anchor === "string" && ([
4428
+ "auto",
4429
+ "top",
4430
+ "right",
4431
+ "bottom",
4432
+ "left",
4433
+ "top-left",
4434
+ "top-right",
4435
+ "bottom-right",
4436
+ "bottom-left"
4437
+ ].includes(endpoint2.anchor) || /^(edge|vertex):\d+$/.test(endpoint2.anchor)));
4438
+ };
4439
+ var connectorCommands = {
4440
+ execute(element, command, payload) {
4441
+ if (element.locked || !payload || typeof payload !== "object") return;
4442
+ const args = payload;
4443
+ if (command === "set-endpoint") {
4444
+ if (args.side !== "start" && args.side !== "end") return;
4445
+ if (!validEndpoint(args.endpoint)) return;
4446
+ const next2 = { ...element, [args.side]: args.endpoint };
4447
+ return validateConnectorElement(next2) ? next2 : void 0;
4448
+ }
4449
+ if (command !== "set-waypoints" || element.lineType !== "polyline")
4450
+ return;
4451
+ if (!Array.isArray(args.points) || !args.points.every(
4452
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
4453
+ ))
4454
+ return;
4455
+ const next = {
4456
+ ...element,
4457
+ polylinePoints: args.points
4458
+ };
4459
+ return validateConnectorElement(next) ? next : void 0;
4460
+ }
4461
+ };
3993
4462
  var CONNECTOR_EXPRESSION = /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g;
3994
4463
  function labelPaths(element) {
3995
4464
  return [...(element.text ?? "").matchAll(CONNECTOR_EXPRESSION)].map(
@@ -3997,8 +4466,8 @@ function labelPaths(element) {
3997
4466
  );
3998
4467
  }
3999
4468
  function connectorBindingInfo(element) {
4000
- const paths = [...new Set(labelPaths(element))];
4001
- return { bound: paths.length > 0, paths };
4469
+ const paths2 = [...new Set(labelPaths(element))];
4470
+ return { bound: paths2.length > 0, paths: paths2 };
4002
4471
  }
4003
4472
  function validateConnectorTemplateData(element, data) {
4004
4473
  if (!data) return [];
@@ -4010,10 +4479,11 @@ function validateConnectorTemplateData(element, data) {
4010
4479
  // src/plugins/connector/native.ts
4011
4480
  var connectorNativePlugin = defineNativePlugin(
4012
4481
  "connector",
4013
- "0.1.31",
4482
+ "0.1.32",
4014
4483
  printDesign.definePrintDesignPluginRenderer({
4015
4484
  type: "connector",
4016
4485
  validate: validateConnectorElement,
4486
+ commands: connectorCommands,
4017
4487
  bindingInfo: connectorBindingInfo,
4018
4488
  validateTemplateData: validateConnectorTemplateData,
4019
4489
  allowSignedSize: true,
@@ -4799,13 +5269,13 @@ function gridMarkup(element, data) {
4799
5269
 
4800
5270
  // src/plugins/grid/data/binding.ts
4801
5271
  function getGridBindingInfo(element) {
4802
- const paths = [
5272
+ const paths2 = [
4803
5273
  element.contentPath,
4804
5274
  element.loopsPath,
4805
5275
  element.columnLoopsPath,
4806
5276
  ...(element.cells ?? []).filter((cell) => cell.contentMode === "binding").map((cell) => cell.contentPath)
4807
5277
  ].map((path) => path?.trim()).filter((path) => !!path);
4808
- return { bound: paths.length > 0, paths };
5278
+ return { bound: paths2.length > 0, paths: paths2 };
4809
5279
  }
4810
5280
  function validateGridTemplateData(element, data) {
4811
5281
  if (!data) return [];
@@ -4892,13 +5362,68 @@ function gridDebugRegions(element, context, hitElement = element) {
4892
5362
  return [...cells, ...loops, ...columnLoops];
4893
5363
  }
4894
5364
 
5365
+ // src/plugins/grid/interaction/commands.ts
5366
+ function executeGridCommand(element, command, payload, validate) {
5367
+ if (element.locked || !payload || typeof payload !== "object") return;
5368
+ const args = payload;
5369
+ if (command === "resize-grid") {
5370
+ const rows = args.rows;
5371
+ const columns = args.columns;
5372
+ if (!Number.isInteger(rows) || !Number.isInteger(columns)) return;
5373
+ if (rows < 1 || rows > 50 || columns < 1 || columns > 50)
5374
+ return;
5375
+ const cells2 = Array.from(
5376
+ { length: rows * columns },
5377
+ (_, index2) => {
5378
+ const row = Math.floor(index2 / columns);
5379
+ const column = index2 % columns;
5380
+ return element.cells?.[row * element.columns + column] ?? {};
5381
+ }
5382
+ );
5383
+ const next2 = {
5384
+ ...element,
5385
+ rows,
5386
+ columns,
5387
+ cells: cells2
5388
+ };
5389
+ return validate(next2) ? next2 : void 0;
5390
+ }
5391
+ if (command !== "set-cell") return;
5392
+ const rowIndex = args.rowIndex;
5393
+ const columnIndex = args.columnIndex;
5394
+ if (!Number.isInteger(rowIndex) || !Number.isInteger(columnIndex)) return;
5395
+ if (rowIndex < 0 || rowIndex >= element.rows || columnIndex < 0 || columnIndex >= element.columns)
5396
+ return;
5397
+ const cell = args.cell;
5398
+ if (!cell || typeof cell !== "object" || Array.isArray(cell)) return;
5399
+ const index = rowIndex * element.columns + columnIndex;
5400
+ const cells = Array.from(
5401
+ { length: element.rows * element.columns },
5402
+ (_, at) => ({ ...element.cells?.[at] })
5403
+ );
5404
+ cells[index] = { ...cells[index], ...cell };
5405
+ const next = { ...element, cells };
5406
+ return validate(next) ? next : void 0;
5407
+ }
5408
+ var gridCommands = {
5409
+ execute(element, command, payload) {
5410
+ return executeGridCommand(
5411
+ element,
5412
+ command,
5413
+ payload,
5414
+ (value) => !!value && typeof value === "object" && value.type === "grid" && validateGridSettings(value)
5415
+ );
5416
+ }
5417
+ };
5418
+
4895
5419
  // src/plugins/grid/native.ts
4896
5420
  var gridNativePlugin = defineNativePlugin(
4897
5421
  "grid",
4898
- "0.1.15",
5422
+ "0.1.16",
4899
5423
  printDesign.definePrintDesignPluginRenderer({
4900
5424
  type: "grid",
4901
5425
  validate: validateGridElement,
5426
+ commands: gridCommands,
4902
5427
  validateTemplateData: validateGridTemplateData,
4903
5428
  bindingInfo: getGridBindingInfo,
4904
5429
  drawCanvas: drawGridElement,
@@ -5209,10 +5734,18 @@ function coordinateDebugRegions(element, context) {
5209
5734
  // src/plugins/coordinate/native.ts
5210
5735
  var coordinateNativePlugin = defineNativePlugin(
5211
5736
  "coordinate",
5212
- "0.1.15",
5737
+ "0.1.16",
5213
5738
  printDesign.definePrintDesignPluginRenderer({
5214
5739
  type: "coordinate",
5215
5740
  validate: validateCoordinateElement,
5741
+ commands: {
5742
+ execute: (element, command, payload) => executeGridCommand(
5743
+ element,
5744
+ command,
5745
+ payload,
5746
+ validateCoordinateElement
5747
+ )
5748
+ },
5216
5749
  validateTemplateData: validateGridTemplateData,
5217
5750
  bindingInfo: getGridBindingInfo,
5218
5751
  drawCanvas: drawCoordinateElement,
@@ -5709,17 +6242,48 @@ function validateFlowTemplateData(element, data) {
5709
6242
  return [];
5710
6243
  }
5711
6244
 
6245
+ // src/plugins/flow/interaction/commands.ts
6246
+ var flowCommands = {
6247
+ execute(element, command, payload) {
6248
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
6249
+ return;
6250
+ const args = payload;
6251
+ const index = args.index;
6252
+ if (!Number.isInteger(index)) return;
6253
+ const at = index;
6254
+ if (command === "remove-item") {
6255
+ if (at < 0 || at >= element.items.length) return;
6256
+ return { ...element, items: element.items.filter((_, i) => i !== at) };
6257
+ }
6258
+ const item = args.item;
6259
+ if (!item || typeof item !== "object" || Array.isArray(item)) return;
6260
+ const items = [...element.items];
6261
+ if (command === "insert-item") {
6262
+ if (at < 0 || at > items.length) return;
6263
+ items.splice(at, 0, item);
6264
+ } else if (command === "update-item") {
6265
+ if (at < 0 || at >= items.length) return;
6266
+ items[at] = { ...items[at], ...item };
6267
+ } else return;
6268
+ const next = { ...element, items };
6269
+ return validateFlowElement(next) ? next : void 0;
6270
+ }
6271
+ };
6272
+
5712
6273
  // src/plugins/flow/native.ts
5713
6274
  var flowNativePlugin = defineNativePlugin(
5714
6275
  "flow",
5715
- "0.1.6",
6276
+ "0.1.7",
5716
6277
  printDesign.definePrintDesignPluginRenderer({
5717
6278
  type: "flow",
5718
6279
  validate: validateFlowElement,
6280
+ commands: flowCommands,
5719
6281
  validateTemplateData: validateFlowTemplateData,
5720
6282
  bindingInfo: (element) => ({
5721
6283
  bound: (element.dataMode ?? element.dataConfig?.mode) === "binding",
5722
- paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [element.dataPath ?? element.dataConfig?.bindings?.items ?? ""].filter(Boolean) : []
6284
+ paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [
6285
+ element.dataPath ?? element.dataConfig?.bindings?.items ?? ""
6286
+ ].filter(Boolean) : []
5723
6287
  }),
5724
6288
  drawCanvas: drawFlowElement,
5725
6289
  renderHtml: (element, context) => renderFlowHtml(element, context.data)
@@ -5959,9 +6523,9 @@ function clockBindingInfo(element) {
5959
6523
  }
5960
6524
  function validateClockTemplateData(element, data) {
5961
6525
  if (!data) return [];
5962
- const { bound, paths } = clockBindingInfo(element);
6526
+ const { bound, paths: paths2 } = clockBindingInfo(element);
5963
6527
  if (!bound) return [];
5964
- const expression = paths[0];
6528
+ const expression = paths2[0];
5965
6529
  if (!expression) return ["\u672A\u914D\u7F6E\u65F6\u949F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
5966
6530
  for (const match of expression.matchAll(
5967
6531
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6200,9 +6764,9 @@ function imageBindingInfo(element) {
6200
6764
  }
6201
6765
  function validateImageTemplateData(element, data) {
6202
6766
  if (!data) return [];
6203
- const { bound, paths } = imageBindingInfo(element);
6767
+ const { bound, paths: paths2 } = imageBindingInfo(element);
6204
6768
  if (!bound) return [];
6205
- const expression = paths[0];
6769
+ const expression = paths2[0];
6206
6770
  if (!expression) return ["\u672A\u914D\u7F6E\u56FE\u7247\u5730\u5740\u7ED1\u5B9A\u5B57\u6BB5"];
6207
6771
  for (const match of expression.matchAll(
6208
6772
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6435,6 +6999,19 @@ function fitImageToPage(image, page, current) {
6435
6999
  return { x, y, width, height };
6436
7000
  }
6437
7001
 
7002
+ // src/plugins/image/interaction/commands.ts
7003
+ var imageCommands = {
7004
+ execute(element, command, payload) {
7005
+ if (element.locked) return;
7006
+ if (command === "clear-crop") return { ...element, crop: void 0 };
7007
+ if (command !== "set-crop" || !payload || typeof payload !== "object")
7008
+ return;
7009
+ const crop = payload;
7010
+ const next = { ...element, crop };
7011
+ return validateImageElement(next) ? next : void 0;
7012
+ }
7013
+ };
7014
+
6438
7015
  // src/plugins/image/native.ts
6439
7016
  var componentCropBehavior = {
6440
7017
  source: (element) => element.src,
@@ -6455,7 +7032,7 @@ var componentCropBehavior = {
6455
7032
  };
6456
7033
  var imageNativePlugin = defineNativePlugin(
6457
7034
  "image",
6458
- "0.1.16",
7035
+ "0.1.17",
6459
7036
  printDesign.definePrintDesignPluginRenderer({
6460
7037
  type: "image",
6461
7038
  dataFields: imageDataFields,
@@ -6464,6 +7041,7 @@ var imageNativePlugin = defineNativePlugin(
6464
7041
  replaceResourceUri: (element, uri, replacement) => element.src === uri ? { ...element, src: replacement } : element,
6465
7042
  validateTemplateData: validateImageTemplateData,
6466
7043
  validate: validateImageElement,
7044
+ commands: imageCommands,
6467
7045
  drawCanvas: drawImageElement,
6468
7046
  prepareCanvas: (element, { signal }) => prepareImage(element.src, signal),
6469
7047
  needsCanvasPreparation: (element) => Boolean(element.src && !getLoadedImageSize(element.src)),
@@ -6542,9 +7120,9 @@ function barcodeBindingInfo(element) {
6542
7120
  }
6543
7121
  function validateBarcodeTemplateData(element, data) {
6544
7122
  if (!data) return [];
6545
- const { bound, paths } = barcodeBindingInfo(element);
7123
+ const { bound, paths: paths2 } = barcodeBindingInfo(element);
6546
7124
  if (!bound) return [];
6547
- const expression = paths[0];
7125
+ const expression = paths2[0];
6548
7126
  if (!expression) return ["\u672A\u914D\u7F6E\u6761\u5F62\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6549
7127
  for (const match of expression.matchAll(
6550
7128
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6644,9 +7222,9 @@ function qrcodeBindingInfo(element) {
6644
7222
  }
6645
7223
  function validateQrCodeTemplateData(element, data) {
6646
7224
  if (!data) return [];
6647
- const { bound, paths } = qrcodeBindingInfo(element);
7225
+ const { bound, paths: paths2 } = qrcodeBindingInfo(element);
6648
7226
  if (!bound) return [];
6649
- const expression = paths[0];
7227
+ const expression = paths2[0];
6650
7228
  if (!expression) return ["\u672A\u914D\u7F6E\u4E8C\u7EF4\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6651
7229
  for (const match of expression.matchAll(
6652
7230
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6733,6 +7311,45 @@ function validateChartTemplateData(element, data) {
6733
7311
  var record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
6734
7312
  var seriesList = (value) => (Array.isArray(value) ? value : value ? [value] : []).map(record);
6735
7313
  var numeric = (value) => typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.trim() && Number.isFinite(Number(value)) ? Number(value) : 0;
7314
+ function readChartData(element) {
7315
+ if (element.chartData) return element.chartData;
7316
+ const option = record(element.option);
7317
+ const series = seriesList(option.series);
7318
+ const first = series[0] ?? {};
7319
+ if (element.chartType === "pie" || element.chartType === "gauge") {
7320
+ const items = Array.isArray(first.data) ? first.data : [];
7321
+ return {
7322
+ mode: "static",
7323
+ categories: items.map((d) => String(record(d).name ?? "")),
7324
+ series: [
7325
+ {
7326
+ name: first.name ?? "\u7CFB\u5217 1",
7327
+ values: items.map((d) => numeric(record(d).value))
7328
+ }
7329
+ ]
7330
+ };
7331
+ }
7332
+ if (element.chartType === "radar") {
7333
+ const indicators = record(option.radar).indicator ?? [];
7334
+ return {
7335
+ mode: "static",
7336
+ categories: indicators.map((d) => String(record(d).name ?? "")),
7337
+ max: indicators[0]?.max ?? 100,
7338
+ series: (first.data ?? []).map((d, i) => ({
7339
+ name: record(d).name ?? `\u7CFB\u5217 ${i + 1}`,
7340
+ values: (record(d).value ?? []).map(numeric)
7341
+ }))
7342
+ };
7343
+ }
7344
+ return {
7345
+ mode: "static",
7346
+ categories: (record(option.xAxis).data ?? []).map(String),
7347
+ series: series.map((s, i) => ({
7348
+ name: s.name ?? `\u7CFB\u5217 ${i + 1}`,
7349
+ values: (s.data ?? []).map(numeric)
7350
+ }))
7351
+ };
7352
+ }
6736
7353
  function resolveChartOption(element, data = {}) {
6737
7354
  const option = record(element.option);
6738
7355
  const singleSeries = ["pie", "radar", "gauge"].includes(element.chartType);
@@ -6841,13 +7458,58 @@ function renderChartHtml(element, data) {
6841
7458
  });
6842
7459
  }
6843
7460
 
7461
+ // src/plugins/chart/interaction/commands.ts
7462
+ var chartCommands = {
7463
+ execute(element, command, payload) {
7464
+ if (element.locked || !payload || typeof payload !== "object") return;
7465
+ const args = payload;
7466
+ const chartData = readChartData(element);
7467
+ if (command === "set-categories") {
7468
+ if (!Array.isArray(args.categories) || !args.categories.every((item) => typeof item === "string"))
7469
+ return;
7470
+ const categories = args.categories;
7471
+ const next2 = {
7472
+ ...element,
7473
+ chartData: {
7474
+ ...chartData,
7475
+ categories,
7476
+ series: chartData.series.map((series2) => ({
7477
+ ...series2,
7478
+ values: categories.map((_, index2) => series2.values[index2] ?? 0)
7479
+ }))
7480
+ }
7481
+ };
7482
+ return validateChartElement(next2) ? next2 : void 0;
7483
+ }
7484
+ if (command !== "set-series") return;
7485
+ const index = args.index;
7486
+ if (!Number.isInteger(index) || index < 0 || index > chartData.series.length)
7487
+ return;
7488
+ if (typeof args.name !== "string" || !Array.isArray(args.values) || args.values.length !== chartData.categories.length || !args.values.every(
7489
+ (value) => typeof value === "number" && Number.isFinite(value)
7490
+ ))
7491
+ return;
7492
+ if (["pie", "gauge"].includes(element.chartType) && index > 0)
7493
+ return;
7494
+ const series = [...chartData.series];
7495
+ series[index] = {
7496
+ name: args.name,
7497
+ values: args.values,
7498
+ ...typeof args.field === "string" ? { field: args.field } : {}
7499
+ };
7500
+ const next = { ...element, chartData: { ...chartData, series } };
7501
+ return validateChartElement(next) ? next : void 0;
7502
+ }
7503
+ };
7504
+
6844
7505
  // src/plugins/chart/native.ts
6845
7506
  var chartNativePlugin = defineNativePlugin(
6846
7507
  "chart",
6847
- "0.1.8",
7508
+ "0.1.9",
6848
7509
  printDesign.definePrintDesignPluginRenderer({
6849
7510
  type: "chart",
6850
7511
  validate: validateChartElement,
7512
+ commands: chartCommands,
6851
7513
  validateTemplateData: validateChartTemplateData,
6852
7514
  bindingInfo: (element) => ({
6853
7515
  bound: element.chartData?.mode === "binding",
@@ -7488,7 +8150,7 @@ function resolveDiagonalCount(count) {
7488
8150
  function diagonalCellLayout(direction, count, corner) {
7489
8151
  const lineCount = resolveDiagonalCount(count);
7490
8152
  const activeCorner = lineCount === 1 ? direction === "down" ? "top-left" : "bottom-left" : corner ?? (direction === "down" ? "top-left" : "bottom-left");
7491
- const paths = {
8153
+ const paths2 = {
7492
8154
  "top-left": [
7493
8155
  [0, 0],
7494
8156
  [1, 0],
@@ -7514,7 +8176,7 @@ function diagonalCellLayout(direction, count, corner) {
7514
8176
  [0, 1]
7515
8177
  ]
7516
8178
  };
7517
- const [apex, first, bend, last] = paths[activeCorner];
8179
+ const [apex, first, bend, last] = paths2[activeCorner];
7518
8180
  const farPoint = (position) => position <= 1 ? [
7519
8181
  first[0] + (bend[0] - first[0]) * position,
7520
8182
  first[1] + (bend[1] - first[1]) * position
@@ -9050,6 +9712,10 @@ function hitTableColumnBoundary(element, point, scale, includeSelector = false,
9050
9712
  }
9051
9713
  return nearest;
9052
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
+ }
9053
9719
  function unmergedBoundarySegments(element, rowIndex, merges) {
9054
9720
  if (!merges.length) return [{ x: element.x + 3, width: element.width - 6 }];
9055
9721
  const columns = tableLeafColumns(
@@ -9091,11 +9757,25 @@ function tableHeaderResizeLayout(element, scale, data = {}) {
9091
9757
  for (let index = 0; index < depth; index++) {
9092
9758
  const edge = element.y + (index + 1) * height;
9093
9759
  if (edge > visibleBottom + 1e-9) break;
9094
- const shared = { rowIndex: index, edge, height, y: edge - 5 / scale };
9095
- 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
+ });
9096
9770
  if (edge < visibleBottom - 1e-9 && element.width > 6)
9097
9771
  for (const segment of unmergedBoundarySegments(element, index, headers))
9098
- 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
+ });
9099
9779
  }
9100
9780
  return regions;
9101
9781
  }
@@ -9110,7 +9790,7 @@ function hitTableHeaderBoundary(element, point, scale, data = {}) {
9110
9790
  -(element.rotation ?? 0) * Math.PI / 180
9111
9791
  );
9112
9792
  const region = tableHeaderResizeLayout(element, scale, data).filter(
9113
- (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
9114
9794
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9115
9795
  return region && {
9116
9796
  elementId: element.id,
@@ -9142,13 +9822,26 @@ function tableRowResizeLayout(element, scale, data = {}) {
9142
9822
  const shared = {
9143
9823
  rowIndex: index + (element.sourceRowOffset ?? 0),
9144
9824
  edge: boundary,
9145
- height,
9146
- y: boundary - 5 / scale
9825
+ height
9147
9826
  };
9148
- 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
+ });
9149
9836
  if (index < heights.length - 1 && element.width > 6)
9150
9837
  for (const segment of unmergedBoundarySegments(element, index, cells))
9151
- 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
+ });
9152
9845
  }
9153
9846
  return regions;
9154
9847
  }
@@ -9163,7 +9856,7 @@ function hitTableRowBoundary(element, point, scale, data = {}) {
9163
9856
  -(element.rotation ?? 0) * Math.PI / 180
9164
9857
  );
9165
9858
  const region = tableRowResizeLayout(element, scale, data).filter(
9166
- (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
9167
9860
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9168
9861
  return region && {
9169
9862
  elementId: element.id,
@@ -9298,12 +9991,12 @@ function tableDebugRegions(table, context, options = {}) {
9298
9991
  ...owner,
9299
9992
  id: `${area}-resize:${index}`,
9300
9993
  category: "resize",
9301
- 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" : ""}`,
9302
9995
  bounds: {
9303
9996
  x: region.x,
9304
9997
  y: region.y,
9305
9998
  width: region.width,
9306
- height: 10 / scale
9999
+ height: region.radius * 2
9307
10000
  },
9308
10001
  interactive: true,
9309
10002
  hit,
@@ -10274,11 +10967,227 @@ function emptyTableRow(element) {
10274
10967
  );
10275
10968
  }
10276
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
+
10277
11182
  // src/plugins/table/interaction/commands.ts
10278
11183
  var tableCommands = {
10279
11184
  execute(element, command, rawPayload, context) {
10280
11185
  if (element.locked) return;
10281
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);
10282
11191
  const payload = rawPayload;
10283
11192
  const rowIndex = payload.rowIndex ?? 0;
10284
11193
  const columnIndex = payload.columnIndex ?? 0;
@@ -10673,7 +11582,7 @@ function validateTableTemplateData(element, data) {
10673
11582
  // src/plugins/table/native.ts
10674
11583
  var tableNativePlugin = defineNativePlugin(
10675
11584
  "table",
10676
- "0.1.68",
11585
+ "0.1.70",
10677
11586
  printDesign.definePrintDesignPluginRenderer({
10678
11587
  type: "table",
10679
11588
  validate: validateTableElement,
@@ -10717,6 +11626,37 @@ var tableNativePlugin = defineNativePlugin(
10717
11626
  );
10718
11627
 
10719
11628
  // src/plugins/pivot-table/layout/field-layout.ts
11629
+ function movePivotField(layout, fieldKey, area, index, sourceArea) {
11630
+ const next = {
11631
+ filters: [...layout.filters],
11632
+ columns: [...layout.columns],
11633
+ rows: [...layout.rows],
11634
+ values: [...layout.values]
11635
+ };
11636
+ const areaKey = (value) => value === "filter" ? "filters" : value === "column" ? "columns" : value === "row" ? "rows" : "values";
11637
+ const targets = area === "value" ? ["values"] : ["filters", "columns", "rows"];
11638
+ for (const target2 of targets)
11639
+ next[target2] = next[target2].filter((key) => key !== fieldKey);
11640
+ if (sourceArea && sourceArea !== area) {
11641
+ const source = areaKey(sourceArea);
11642
+ next[source] = next[source].filter((key) => key !== fieldKey);
11643
+ }
11644
+ const target = next[areaKey(area)];
11645
+ target.splice(
11646
+ Math.max(0, Math.min(index ?? target.length, target.length)),
11647
+ 0,
11648
+ fieldKey
11649
+ );
11650
+ return next;
11651
+ }
11652
+ function removePivotField(layout, fieldKey) {
11653
+ return {
11654
+ filters: layout.filters.filter((key) => key !== fieldKey),
11655
+ columns: layout.columns.filter((key) => key !== fieldKey),
11656
+ rows: layout.rows.filter((key) => key !== fieldKey),
11657
+ values: layout.values.filter((key) => key !== fieldKey)
11658
+ };
11659
+ }
10720
11660
  function pivotFieldTitle(field) {
10721
11661
  return field.title ?? field.key;
10722
11662
  }
@@ -10968,6 +11908,41 @@ var pivotTableBoundaryResize = {
10968
11908
  }
10969
11909
  };
10970
11910
 
11911
+ // src/plugins/pivot-table/interaction/commands.ts
11912
+ var areas = ["filter", "column", "row", "value"];
11913
+ var pivotTableCommands = {
11914
+ execute(element, command, payload) {
11915
+ if (element.locked || !payload || typeof payload !== "object") return;
11916
+ const args = payload;
11917
+ const fieldKey = args.fieldKey;
11918
+ if (typeof fieldKey !== "string" || !element.fields.some((field) => field.key === fieldKey))
11919
+ return;
11920
+ if (command === "remove-field")
11921
+ return {
11922
+ ...element,
11923
+ layout: removePivotField(element.layout, fieldKey)
11924
+ };
11925
+ if (command !== "move-field" || !areas.includes(args.area))
11926
+ return;
11927
+ const index = args.index;
11928
+ if (index !== void 0 && (!Number.isInteger(index) || index < 0))
11929
+ return;
11930
+ const sourceArea = args.sourceArea;
11931
+ if (sourceArea !== void 0 && !areas.includes(sourceArea))
11932
+ return;
11933
+ return {
11934
+ ...element,
11935
+ layout: movePivotField(
11936
+ element.layout,
11937
+ fieldKey,
11938
+ args.area,
11939
+ index,
11940
+ sourceArea
11941
+ )
11942
+ };
11943
+ }
11944
+ };
11945
+
10971
11946
  // src/plugins/pivot-table/model.ts
10972
11947
  function validatePivotTableElement(value) {
10973
11948
  if (!value || typeof value !== "object") return false;
@@ -10981,11 +11956,12 @@ function validatePivotTableElement(value) {
10981
11956
  // src/plugins/pivot-table/native.ts
10982
11957
  var pivotTableNativePlugin = defineNativePlugin(
10983
11958
  "pivotTable",
10984
- "0.1.18",
11959
+ "0.1.19",
10985
11960
  printDesign.definePrintDesignPluginRenderer({
10986
11961
  type: "pivotTable",
10987
11962
  htmlCss: tableHtmlCss,
10988
11963
  validate: validatePivotTableElement,
11964
+ commands: pivotTableCommands,
10989
11965
  validateTemplateData: validatePivotTemplateData,
10990
11966
  bindingInfo: (element) => ({
10991
11967
  bound: element.dataMode === "binding",
@@ -11496,13 +12472,49 @@ function ganttMarkup(element, data, pageNumber) {
11496
12472
  return `<svg class="pd-media" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none"><rect width="${width}" height="${height}" fill="${printDesign.cssColor(theme.backgroundColor, "transparent")}"/>${header > 0 ? `<rect width="${width}" height="${header}" fill="${printDesign.cssColor(theme.headerBackgroundColor, "transparent")}"/>` : ""}${ticks}${taskSplit}${headerEdges}${headerTitle}${maskedDependencies}${bars}${frame}</svg>`;
11497
12473
  }
11498
12474
 
12475
+ // src/plugins/gantt/interaction/commands.ts
12476
+ var ganttCommands = {
12477
+ execute(element, command, payload) {
12478
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
12479
+ return;
12480
+ const args = payload;
12481
+ const tasks = [...element.tasks];
12482
+ if (command === "insert-task") {
12483
+ const index = args.index;
12484
+ if (!Number.isInteger(index) || index < 0 || index > tasks.length)
12485
+ return;
12486
+ if (!args.task || typeof args.task !== "object" || Array.isArray(args.task))
12487
+ return;
12488
+ const task = args.task;
12489
+ if (tasks.some((existing) => existing.id === task.id)) return;
12490
+ tasks.splice(index, 0, task);
12491
+ } else {
12492
+ const taskId = args.taskId;
12493
+ if (typeof taskId !== "string") return;
12494
+ const index = tasks.findIndex((task) => task.id === taskId);
12495
+ if (index < 0) return;
12496
+ if (command === "remove-task") tasks.splice(index, 1);
12497
+ else if (command === "update-task") {
12498
+ if (!args.patch || typeof args.patch !== "object" || Array.isArray(args.patch))
12499
+ return;
12500
+ const patch = args.patch;
12501
+ if (patch.id !== void 0 || patch.tasks !== void 0) return;
12502
+ tasks[index] = { ...tasks[index], ...patch };
12503
+ } else return;
12504
+ }
12505
+ const next = { ...element, tasks };
12506
+ return validateGanttElement(next) ? next : void 0;
12507
+ }
12508
+ };
12509
+
11499
12510
  // src/plugins/gantt/native.ts
11500
12511
  var ganttNativePlugin = defineNativePlugin(
11501
12512
  "gantt",
11502
- "0.1.6",
12513
+ "0.1.7",
11503
12514
  printDesign.definePrintDesignPluginRenderer({
11504
12515
  type: "gantt",
11505
12516
  validate: validateGanttElement,
12517
+ commands: ganttCommands,
11506
12518
  validateTemplateData: validateGanttTemplateData,
11507
12519
  bindingInfo: (element) => ({
11508
12520
  bound: element.dataMode === "binding",
@@ -11516,6 +12528,7 @@ var ganttNativePlugin = defineNativePlugin(
11516
12528
  // src/native.ts
11517
12529
  var builtinNativeComponentPlugins = [
11518
12530
  textNativePlugin,
12531
+ richTextNativePlugin,
11519
12532
  listNativePlugin,
11520
12533
  dateTimeNativePlugin,
11521
12534
  moneyUpperNativePlugin,