@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/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import { definePrintDesignPluginRenderer, renderPrintDesignHtmlFrame, rotatePoint, resolvePrintDesignElementData, PrintDesignComponentRegistry, resolveDesignText, cssFont, PRINT_DESIGN_DEFAULT_FONT_FAMILY, resolvePrintDesignBinding, isPrintDesignColorValue, resolvePrintDesignDataPath, cssNumber, cssColor, escapeHtml, getPrintDesignElementDataConfig, elementTransformHomography, projectTransformPoint, resolvePrintDesignElementVisible, hitTestPrintDesignPage, transformRect, elementTransformCss, pixelsToMillimeters, PRINT_DESIGN_CSS_DPI, isPrintDesignRecordCollection, clonePrintDesignDocument, getSelectionRect, toDisplayUnit, fromDisplayUnit, inverseTransformPoint, stringifyPrintDesignBinding } from '@canvas-components/print-design';
1
+ import { definePrintDesignPluginRenderer, renderPrintDesignHtmlFrame, rotatePoint, resolvePrintDesignElementData, PrintDesignComponentRegistry, resolveDesignText, cssFont, resolvePrintDesignBinding, isPrintDesignColorValue, cssNumber, escapeHtml, cssColor, PRINT_DESIGN_DEFAULT_FONT_FAMILY, resolvePrintDesignDataPath, getPrintDesignElementDataConfig, elementTransformHomography, projectTransformPoint, resolvePrintDesignElementVisible, hitTestPrintDesignPage, transformRect, elementTransformCss, pixelsToMillimeters, PRINT_DESIGN_CSS_DPI, isPrintDesignRecordCollection, clonePrintDesignDocument, getSelectionRect, resolvePrintDesignFontFamily, fromDisplayUnit, toDisplayUnit, inverseTransformPoint, stringifyPrintDesignBinding } from '@canvas-components/print-design';
2
2
  import { drawBarcodeToCanvas, encodeBarcodePattern, exportBarcodeToSvg } from '@canvas-components/barcode';
3
3
  import { drawQrCodeToCanvas, encodeQrCodeMatrix, exportQrCodeToSvg } from '@canvas-components/qrcode';
4
4
  import { drawCanvasChartToCanvas, exportCanvasChartToSvg } from '@canvas-components/chart';
@@ -44,7 +44,9 @@ function assertNativePluginDependencies(plugins) {
44
44
  function validateTextElement(value) {
45
45
  if (!value || typeof value !== "object") return false;
46
46
  const element = value;
47
- return element.type === "text" && typeof element.text === "string" && (element.colorMode === void 0 || ["static", "binding"].includes(element.colorMode)) && (element.fontSizeMode === void 0 || ["static", "binding"].includes(element.fontSizeMode)) && (element.colorPath === void 0 || typeof element.colorPath === "string") && (element.fontSizePath === void 0 || typeof element.fontSizePath === "string") && (element.fontSizeBindingUnit === void 0 || ["mm", "cm", "in", "pt", "px"].includes(element.fontSizeBindingUnit)) && (element.heightOverflow === void 0 || ["clip", "flow", "ellipsis"].includes(element.heightOverflow)) && (element.underlineStyle === void 0 || ["solid", "dashed", "dotted", "wavy"].includes(element.underlineStyle)) && (element.underlineCount === void 0 || Number.isInteger(element.underlineCount) && element.underlineCount >= 0 && element.underlineCount <= 5) && (element.fontSource === void 0 || typeof element.fontSource === "string") && (element.borderWidth === void 0 || Number.isFinite(element.borderWidth) && element.borderWidth >= 0) && (element.borderColor === void 0 || typeof element.borderColor === "string") && (element.fontSizeRules === void 0 || Array.isArray(element.fontSizeRules) && element.fontSizeRules.every(
47
+ return element.type === "text" && typeof element.text === "string" && (element.fontStyle === void 0 || ["normal", "italic"].includes(element.fontStyle)) && (element.colorMode === void 0 || ["static", "binding"].includes(element.colorMode)) && (element.fontSizeMode === void 0 || ["static", "binding"].includes(element.fontSizeMode)) && (element.colorPath === void 0 || typeof element.colorPath === "string") && (element.fontSizePath === void 0 || typeof element.fontSizePath === "string") && (element.fontSizeBindingUnit === void 0 || ["mm", "cm", "in", "pt", "px"].includes(element.fontSizeBindingUnit)) && (element.heightOverflow === void 0 || ["clip", "flow", "ellipsis"].includes(element.heightOverflow)) && (element.indentMode === void 0 || ["none", "firstLine", "hanging"].includes(element.indentMode)) && (element.indentValue === void 0 || Number.isFinite(element.indentValue) && element.indentValue >= 0) && (element.indentUnit === void 0 || ["char", "mm", "cm", "in", "pt", "px"].includes(element.indentUnit)) && (element.prewrappedIndents === void 0 || Array.isArray(element.prewrappedIndents) && element.prewrappedIndents.every(
48
+ (value2) => Number.isFinite(value2) && value2 >= 0
49
+ )) && (element.underlineStyle === void 0 || ["solid", "dashed", "dotted", "wavy"].includes(element.underlineStyle)) && (element.underlineCount === void 0 || Number.isInteger(element.underlineCount) && element.underlineCount >= 0 && element.underlineCount <= 5) && (element.fontSource === void 0 || typeof element.fontSource === "string") && (element.borderWidth === void 0 || Number.isFinite(element.borderWidth) && element.borderWidth >= 0) && (element.borderColor === void 0 || typeof element.borderColor === "string") && (element.fontSizeRules === void 0 || Array.isArray(element.fontSizeRules) && element.fontSizeRules.every(
48
50
  (rule) => rule && Number.isInteger(rule.maxChars) && rule.maxChars >= 1 && Number.isFinite(rule.fontSize) && rule.fontSize > 0
49
51
  ));
50
52
  }
@@ -60,23 +62,36 @@ function graphemes(text) {
60
62
  function drawVerticalText(ctx, text, box, options) {
61
63
  if (box.width <= 0 || box.height <= 0) return;
62
64
  const step = Math.max(1, options.fontSize * options.lineHeight);
63
- const capacity = Math.max(1, Math.floor(box.height / step));
64
65
  const paragraphs = text.split(/\r?\n/).map(graphemes);
65
66
  const columns = paragraphs.flatMap((chars) => {
66
- if (!options.wrap || chars.length <= capacity) return [chars];
67
67
  const chunks = [];
68
- for (let index = 0; index < chars.length; index += capacity)
69
- chunks.push(chars.slice(index, index + capacity));
68
+ let offset = 0;
69
+ do {
70
+ const indent = options.indentMode === "firstLine" ? chunks.length === 0 ? options.indent ?? 0 : 0 : options.indentMode === "hanging" && chunks.length > 0 ? options.indent ?? 0 : 0;
71
+ const capacity = Math.max(1, Math.floor((box.height - indent) / step));
72
+ chunks.push({
73
+ chars: options.wrap === false ? chars.slice(offset) : chars.slice(offset, offset + capacity),
74
+ indent
75
+ });
76
+ offset += capacity;
77
+ } while (options.wrap !== false && offset < chars.length);
70
78
  return chunks;
71
79
  });
72
80
  const visibleCount = Math.max(1, Math.floor(box.width / step));
73
81
  const visible = columns.slice(0, visibleCount);
74
- const overflowed = columns.length > visibleCount || !options.wrap && visible.some((chars) => chars.length > capacity);
82
+ const overflowed = columns.length > visibleCount || !options.wrap && visible.some(
83
+ ({ chars, indent }) => chars.length > Math.max(1, Math.floor((box.height - indent) / step))
84
+ );
75
85
  if (options.ellipsis && overflowed && visible.length) {
76
- const last = [...visible[visible.length - 1]];
86
+ const previous = visible[visible.length - 1];
87
+ const capacity = Math.max(
88
+ 1,
89
+ Math.floor((box.height - previous.indent) / step)
90
+ );
91
+ const last = [...previous.chars];
77
92
  last.length = Math.min(last.length, capacity);
78
93
  last[Math.max(0, Math.min(last.length, capacity) - 1)] = "\u2026";
79
- visible[visible.length - 1] = last;
94
+ visible[visible.length - 1] = { ...previous, chars: last };
80
95
  }
81
96
  const blockWidth = visible.length * step;
82
97
  const left = options.align === "left" ? box.x : options.align === "center" ? box.x + (box.width - blockWidth) / 2 : box.x + box.width - blockWidth;
@@ -86,12 +101,17 @@ function drawVerticalText(ctx, text, box, options) {
86
101
  ctx.clip();
87
102
  ctx.textAlign = "center";
88
103
  ctx.textBaseline = "middle";
89
- visible.forEach((chars, column) => {
104
+ visible.forEach(({ chars, indent }, column) => {
90
105
  const textHeight = chars.length * step;
91
- const offset = options.verticalAlign === "bottom" ? Math.max(0, box.height - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (box.height - textHeight) / 2) : 0;
106
+ const availableHeight = Math.max(0, box.height - indent);
107
+ const offset = options.verticalAlign === "bottom" ? Math.max(0, availableHeight - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (availableHeight - textHeight) / 2) : 0;
92
108
  const centerX = left + blockWidth - (column + 0.5) * step;
93
109
  chars.forEach(
94
- (char, index) => ctx.fillText(char, centerX, box.y + offset + (index + 0.5) * step)
110
+ (char, index) => ctx.fillText(
111
+ char,
112
+ centerX,
113
+ box.y + indent + offset + (index + 0.5) * step
114
+ )
95
115
  );
96
116
  });
97
117
  ctx.restore();
@@ -132,15 +152,16 @@ function getTextLayoutCache(ctx) {
132
152
  }
133
153
  return entry;
134
154
  }
135
- function layoutSpacedText(ctx, text, width, prewrapped = false) {
155
+ function layoutSpacedText(ctx, text, width, prewrapped = false, indent) {
136
156
  const cache = getTextLayoutCache(ctx);
137
- const key = `${prewrapped}:${width}\0${text}`;
157
+ const key = `${prewrapped}:${width}:${indent?.mode ?? "none"}:${indent?.value ?? 0}\0${text}`;
138
158
  let lines = cache.lines.get(key);
139
159
  if (!lines) {
140
160
  lines = prewrapped ? text.split("\n").map((text2) => ({ text: text2, last: true })) : layoutAlignedText(
141
161
  text,
142
162
  width,
143
- (value) => measureSpacedText(ctx, value)
163
+ (value) => measureSpacedText(ctx, value),
164
+ indent
144
165
  );
145
166
  if (cache.lines.size >= 128) cache.lines.clear();
146
167
  cache.lines.set(key, lines);
@@ -194,28 +215,30 @@ function drawSpacedText(ctx, text, x, y) {
194
215
  });
195
216
  ctx.textAlign = align;
196
217
  }
197
- function layoutAlignedText(text, width, measure) {
218
+ function layoutAlignedText(text, width, measure, indent) {
198
219
  return text.split("\n").flatMap((paragraph) => {
199
220
  const lines = [];
200
221
  let line = "";
222
+ const indentation = (index) => indent?.mode === "firstLine" ? index === 0 ? indent.value : 0 : indent?.mode === "hanging" && index > 0 ? indent.value : 0;
201
223
  const tokens = paragraph.match(
202
224
  /[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}]+|\s+|[^\p{Script=Latin}\p{N}\s]+/gu
203
225
  ) ?? [];
204
226
  const pieces = tokens.flatMap(
205
227
  (token) => /^(?:[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}\s]+)$/u.test(
206
228
  token
207
- ) && measure(token) <= width ? [token] : graphemes(token)
229
+ ) && measure(token) <= Math.max(1, width - Math.max(0, indent?.value ?? 0)) ? [token] : graphemes(token)
208
230
  );
209
231
  for (const piece of pieces) {
210
- if (line && measure(line + piece) > width) {
211
- lines.push(line.trimEnd());
232
+ if (line && measure(line + piece) > Math.max(1, width - indentation(lines.length))) {
233
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
212
234
  line = "";
213
235
  }
214
236
  if (line || piece.trim()) line += piece;
215
237
  }
216
- lines.push(line.trimEnd());
238
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
217
239
  return lines.map((value, index) => ({
218
- text: value,
240
+ text: value.text,
241
+ ...indent && indent.mode !== "none" && indent.value > 0 ? { indent: value.indent } : {},
219
242
  last: index === lines.length - 1
220
243
  }));
221
244
  });
@@ -241,13 +264,7 @@ function drawAlignedTextLine(ctx, text, x, y, width, distributed) {
241
264
  });
242
265
  }
243
266
  function resolveTextFontFamily(family) {
244
- const selected = family?.trim();
245
- if (!selected) return PRINT_DESIGN_DEFAULT_FONT_FAMILY;
246
- if (/\bPrintDesignNotoSansSC\b/i.test(selected)) return selected;
247
- if (!/(?:^|,)\s*['"]?Times New Roman['"]?(?:,|$)/i.test(selected) && !/(?:^|,)\s*serif\s*$/i.test(selected))
248
- return selected;
249
- const generic = /,\s*(sans-serif|serif|monospace|cursive|fantasy|system-ui)\s*$/i;
250
- return generic.test(selected) ? selected.replace(generic, ", PrintDesignNotoSansSC, $1") : `${selected}, PrintDesignNotoSansSC`;
267
+ return resolvePrintDesignFontFamily(family);
251
268
  }
252
269
 
253
270
  // src/plugins/text/layout/measure.ts
@@ -265,7 +282,7 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
265
282
  widths = /* @__PURE__ */ new Map();
266
283
  widthCaches.set(ownerDocument, widths);
267
284
  }
268
- const font = `${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
285
+ const font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
269
286
  let span;
270
287
  return {
271
288
  measure: (value) => {
@@ -296,6 +313,12 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
296
313
  dispose: () => span?.remove()
297
314
  };
298
315
  }
316
+ function resolveTextIndentMm(element, fontSizePt) {
317
+ if (!element.indentMode || element.indentMode === "none") return 0;
318
+ const value = Math.max(0, element.indentValue ?? 0);
319
+ if (!Number.isFinite(value)) return 0;
320
+ return element.indentUnit === "char" || !element.indentUnit ? value * fontSizePt * 25.4 / 72 : fromDisplayUnit(value, element.indentUnit);
321
+ }
299
322
 
300
323
  // src/plugins/text/rendering/formatting.ts
301
324
  function resolveTextFontSize(element, text) {
@@ -315,15 +338,15 @@ function ellipsizeTextLine(text, maxWidth, measure) {
315
338
 
316
339
  // src/plugins/text/rendering/draw.ts
317
340
  var loadedFonts = /* @__PURE__ */ new WeakMap();
318
- var DEFAULT_TEXT_BASELINE_CORRECTION_RATIO = 0.05;
319
341
  function prepareTextFont(element, signal) {
320
342
  const family = element.fontFamily?.trim();
321
343
  const source = element.fontSource?.trim();
322
344
  if (!family || !source) return Promise.resolve();
323
345
  if (typeof document === "undefined" || typeof FontFace === "undefined")
324
- return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u52A0\u8F7D\u6253\u5370\u5B57\u4F53\u3002"));
346
+ return Promise.resolve();
325
347
  signal?.throwIfAborted();
326
- const ready = ensureTextFont(element, document);
348
+ const ready = ensureTextFont(element, document).catch(() => {
349
+ });
327
350
  if (!signal) return ready;
328
351
  return new Promise((resolve, reject) => {
329
352
  const onAbort = () => reject(signal.reason);
@@ -390,7 +413,7 @@ var drawTextElement = (element, context) => {
390
413
  const resolvedFontSize = resolveTextFontSize(element, resolvedText);
391
414
  const fontSize = resolvedFontSize * 25.4 * scale / 72;
392
415
  ctx.fillStyle = element.color ?? "#1f2937";
393
- ctx.font = `${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
416
+ ctx.font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
394
417
  const expanded = element.textAlign === "justify" || element.textAlign === "distributed";
395
418
  ctx.textAlign = expanded ? "left" : element.textAlign ?? "left";
396
419
  ctx.textBaseline = "alphabetic";
@@ -405,7 +428,9 @@ var drawTextElement = (element, context) => {
405
428
  align: element.textAlign === "left" || element.textAlign === "center" ? element.textAlign : "right",
406
429
  verticalAlign: element.verticalAlign,
407
430
  wrap: true,
408
- ellipsis: element.heightOverflow === "ellipsis"
431
+ ellipsis: element.heightOverflow === "ellipsis",
432
+ indentMode: element.indentMode,
433
+ indent: resolveTextIndentMm(element, resolvedFontSize) * scale
409
434
  }
410
435
  );
411
436
  return;
@@ -414,19 +439,31 @@ var drawTextElement = (element, context) => {
414
439
  const fontMetrics = ctx.measureText?.("Hg");
415
440
  const ascent = fontMetrics?.fontBoundingBoxAscent ?? fontSize * 0.8;
416
441
  const descent = fontMetrics?.fontBoundingBoxDescent ?? fontSize * 0.2;
417
- const defaultFont = !element.fontFamily || element.fontFamily === PRINT_DESIGN_DEFAULT_FONT_FAMILY;
418
- const regularNoto = element.fontFamily?.startsWith("PrintDesignNotoSansSC") && !/^(?:bold|[6-9]00)$/i.test(element.fontWeight ?? "400");
419
- const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent - (defaultFont || regularNoto ? fontSize * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO : 0);
442
+ const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent;
420
443
  const measure = (text) => measureSpacedText(ctx, text);
421
- let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped);
444
+ const indentPx = resolveTextIndentMm(element, resolvedFontSize) * scale;
445
+ let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped, {
446
+ mode: element.indentMode ?? "none",
447
+ value: indentPx
448
+ });
449
+ if (element.prewrappedIndents)
450
+ lines = lines.map((line, index) => ({
451
+ ...line,
452
+ indent: (element.prewrappedIndents?.[index] ?? 0) * scale
453
+ }));
422
454
  if (element.heightOverflow) {
423
455
  const fit = Math.max(0, Math.floor(height / lineHeight));
424
456
  if (lines.length > fit) {
425
457
  lines = lines.slice(0, fit);
426
458
  if (fit && element.heightOverflow === "ellipsis")
427
459
  lines[fit - 1] = {
428
- text: ellipsizeTextLine(lines[fit - 1].text, width, measure),
429
- last: true
460
+ text: ellipsizeTextLine(
461
+ lines[fit - 1].text,
462
+ Math.max(1, width - (lines[fit - 1].indent ?? 0)),
463
+ measure
464
+ ),
465
+ last: true,
466
+ indent: lines[fit - 1].indent
430
467
  };
431
468
  }
432
469
  ctx.beginPath();
@@ -434,16 +471,22 @@ var drawTextElement = (element, context) => {
434
471
  ctx.clip();
435
472
  }
436
473
  const verticalOffset = element.verticalAlign === "middle" ? Math.max(0, (height - lines.length * lineHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - lines.length * lineHeight) : 0;
437
- const textX = element.textAlign === "center" ? x + width / 2 : element.textAlign === "right" ? x + width : x;
438
474
  lines.forEach((line, index) => {
439
475
  const lineY = y + verticalOffset + index * lineHeight + baselineOffset;
476
+ const lineIndent = Math.min(
477
+ Math.max(0, line.indent ?? 0),
478
+ Math.max(0, width)
479
+ );
480
+ const lineLeft = x + lineIndent;
481
+ const lineWidth = Math.max(0, width - lineIndent);
482
+ const textX = element.textAlign === "center" ? lineLeft + lineWidth / 2 : element.textAlign === "right" ? x + width : lineLeft;
440
483
  if (expanded && (element.textAlign === "distributed" || !line.last)) {
441
484
  drawAlignedTextLine(
442
485
  ctx,
443
486
  line.text,
444
- x,
487
+ lineLeft,
445
488
  lineY,
446
- width,
489
+ lineWidth,
447
490
  element.textAlign === "distributed"
448
491
  );
449
492
  } else {
@@ -454,8 +497,8 @@ var drawTextElement = (element, context) => {
454
497
  Math.max(0, Math.floor(element.underlineCount ?? 0))
455
498
  );
456
499
  if (!count || !line.text) return;
457
- const textWidth = Math.min(width, measure(line.text));
458
- const left = expanded && (element.textAlign === "distributed" || !line.last) ? x : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
500
+ const textWidth = Math.min(lineWidth, measure(line.text));
501
+ const left = expanded && (element.textAlign === "distributed" || !line.last) ? lineLeft : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
459
502
  ctx.save();
460
503
  ctx.strokeStyle = element.underlineColor ?? element.color ?? "#1f2937";
461
504
  ctx.lineWidth = Math.max(0.5, (element.underlineWidth ?? 0.2) * scale);
@@ -506,13 +549,24 @@ function textMarkup(text, element, size = 14, color2 = "#1f2937") {
506
549
  const weight = /^(?:[1-9]00|normal|bold)$/.test(
507
550
  textElement?.fontWeight ?? "400"
508
551
  ) ? textElement?.fontWeight ?? "400" : "400";
552
+ const fontStyle = textElement?.fontStyle === "italic" ? "italic" : "normal";
509
553
  const fontSize = textElement ? resolveTextFontSize(textElement, text) : cssNumber(size, 14);
510
- if (textElement?.textDirection === "vertical")
511
- return `<div class="pd-text" style="display:block;font:${weight} ${fontSize}pt ${escapeHtml(cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${cssNumber(textElement.lineHeight, 1.35)}">${escapeHtml(text)}</div>`;
554
+ if (textElement?.textDirection === "vertical") {
555
+ const indentMm2 = resolveTextIndentMm(textElement, fontSize);
556
+ const paragraphStyle = indentMm2 <= 0 ? "" : textElement.indentMode === "firstLine" ? `text-indent:${cssNumber(indentMm2, 0)}mm;` : `padding-top:${cssNumber(indentMm2, 0)}mm;text-indent:-${cssNumber(indentMm2, 0)}mm;box-sizing:border-box;`;
557
+ const content = indentMm2 > 0 ? text.split("\n").map(
558
+ (paragraph) => `<div style="${paragraphStyle}">${escapeHtml(paragraph) || "<br>"}</div>`
559
+ ).join("") : escapeHtml(text);
560
+ return `<div class="pd-text" style="display:block;font:${fontStyle} ${weight} ${fontSize}pt ${escapeHtml(cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${cssNumber(textElement.lineHeight, 1.35)}">${content}</div>`;
561
+ }
562
+ const indentMm = textElement ? resolveTextIndentMm(textElement, fontSize) : 0;
563
+ const indentStyle = (lineIndex) => indentMm > 0 && textElement ? textElement.indentMode === "firstLine" ? lineIndex === 0 ? `text-indent:${cssNumber(indentMm, 0)}mm;` : "" : textElement.indentMode === "hanging" ? `padding-left:${cssNumber(indentMm, 0)}mm;text-indent:${`-${cssNumber(indentMm, 0)}mm` };box-sizing:border-box;` : "" : "";
512
564
  const lines = textElement?.prewrapped ? text.split("\n").map(
513
- (line) => `<div style="white-space:pre;overflow:hidden;flex:none"><span style="${underlineCss(textElement)}">${escapeHtml(line) || "<br>"}</span></div>`
565
+ (line, index) => `<div style="white-space:pre;overflow:hidden;flex:none${textElement.prewrappedIndents ? `;box-sizing:border-box;padding-left:${cssNumber(textElement.prewrappedIndents[index] ?? 0, 0)}mm` : ""}"><span style="${underlineCss(textElement)}">${escapeHtml(line) || "<br>"}</span></div>`
566
+ ).join("") : indentMm > 0 ? text.split("\n").map(
567
+ (paragraph) => `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere;${indentStyle(0)}"><span style="${textElement ? underlineCss(textElement) : ""}">${escapeHtml(paragraph) || "<br>"}</span></div>`
514
568
  ).join("") : `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere"><span style="${textElement ? underlineCss(textElement) : ""}">${escapeHtml(text)}</span></div>`;
515
- return `<div class="pd-text" style="font:${weight} ${fontSize}pt ${escapeHtml(cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${cssColor(color2, "#1f2937")};text-align:${align};line-height:${cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
569
+ return `<div class="pd-text" style="font:${fontStyle} ${weight} ${fontSize}pt ${escapeHtml(cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${cssColor(color2, "#1f2937")};text-align:${align};line-height:${cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
516
570
  }
517
571
  function underlineCss(element) {
518
572
  const count = Math.min(
@@ -547,6 +601,18 @@ function textFontCss(element) {
547
601
  return `@font-face{font-family:${cssFont(element.fontFamily)};src:url("${source}")}`;
548
602
  }
549
603
  var PT_TO_MM = 25.4 / 72;
604
+ function layoutText(element, text, measure) {
605
+ if (element.prewrapped)
606
+ return text.split("\n").map((line, index) => ({
607
+ text: line,
608
+ last: true,
609
+ indent: element.prewrappedIndents?.[index] ?? 0
610
+ }));
611
+ return layoutAlignedText(text, element.width, measure, {
612
+ mode: element.indentMode ?? "none",
613
+ value: resolveTextIndentMm(element, resolveTextFontSize(element, text))
614
+ });
615
+ }
550
616
  function paginateText(element, { data, startPage, startY, top, bottom, pageAt }) {
551
617
  const text = element.dataConfig?.mode === "binding" ? element.text : resolveDesignText(element.text, data);
552
618
  if (element.textDirection === "vertical") {
@@ -574,9 +640,7 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
574
640
  );
575
641
  let lines;
576
642
  try {
577
- lines = layoutAlignedText(text, element.width, measurement.measure).map(
578
- (line) => line.text
579
- );
643
+ lines = layoutText(element, text, measurement.measure);
580
644
  } finally {
581
645
  measurement.dispose();
582
646
  }
@@ -605,7 +669,8 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
605
669
  previewSourceId: element.previewSourceId ?? element.id,
606
670
  y,
607
671
  height,
608
- text: chunk.join("\n"),
672
+ text: chunk.map((line) => line.text).join("\n"),
673
+ ...element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? { prewrappedIndents: chunk.map((line) => line.indent ?? 0) } : {},
609
674
  prewrapped: true,
610
675
  verticalAlign: "top",
611
676
  dataConfig: void 0
@@ -633,7 +698,11 @@ function prewrapText(element) {
633
698
  (value) => estimateTextWidth(value, fontMm)
634
699
  );
635
700
  try {
636
- return layoutAlignedText(element.text, element.width, measurement.measure).map((line) => line.text).join("\n");
701
+ const lines = layoutText(element, element.text, measurement.measure);
702
+ return {
703
+ text: lines.map((line) => line.text).join("\n"),
704
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? lines.map((line) => line.indent ?? 0) : void 0
705
+ };
637
706
  } finally {
638
707
  measurement.dispose();
639
708
  }
@@ -646,12 +715,12 @@ function estimateTextHeight(element) {
646
715
  (value) => estimateTextWidth(value, fontMm)
647
716
  );
648
717
  try {
649
- return layoutAlignedText(element.text, element.width, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
718
+ return layoutText(element, element.text, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
650
719
  } finally {
651
720
  measurement.dispose();
652
721
  }
653
722
  }
654
- function truncateText(element, height, mode) {
723
+ function truncateTextLayout(element, height, mode) {
655
724
  const fontMm = Math.max(1, (element.fontSize ?? 14) * PT_TO_MM);
656
725
  const lineMm = fontMm * (element.lineHeight ?? 1.35);
657
726
  const measurement = createHtmlTextMeasure(
@@ -660,21 +729,21 @@ function truncateText(element, height, mode) {
660
729
  (value) => estimateTextWidth(value, fontMm)
661
730
  );
662
731
  try {
663
- const lines = layoutAlignedText(
664
- element.text,
665
- element.width,
666
- measurement.measure
667
- );
732
+ const lines = layoutText(element, element.text, measurement.measure);
668
733
  const fit = Math.max(0, Math.floor(height / lineMm));
669
- if (lines.length <= fit) return element.text;
670
- const visible = lines.slice(0, fit).map((line) => line.text);
734
+ const visibleLines = lines.slice(0, fit);
735
+ const visible = visibleLines.map((line) => line.text);
671
736
  if (fit && mode === "ellipsis")
672
737
  visible[fit - 1] = ellipsizeTextLine(
673
738
  visible[fit - 1],
674
- element.width,
739
+ Math.max(1, element.width - (lines[fit - 1]?.indent ?? 0)),
675
740
  measurement.measure
676
741
  );
677
- return visible.join("\n");
742
+ return {
743
+ text: visible.join("\n"),
744
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? visibleLines.map((line) => line.indent ?? 0) : void 0,
745
+ overflowed: lines.length > fit
746
+ };
678
747
  } finally {
679
748
  measurement.dispose();
680
749
  }
@@ -704,11 +773,13 @@ function prepareTextPagination(element, data) {
704
773
  };
705
774
  if (element.textDirection === "vertical" || element.overflowPolicy === "split" || element.heightOverflow === "flow" && element.overflowPolicy !== "nextPage")
706
775
  return prepared;
707
- const printable = element.heightOverflow && element.heightOverflow !== "flow" ? {
776
+ const wrapped = element.heightOverflow && element.heightOverflow !== "flow" ? truncateTextLayout(prepared, prepared.height, element.heightOverflow) : prewrapText(prepared);
777
+ return {
708
778
  ...prepared,
709
- text: truncateText(prepared, prepared.height, element.heightOverflow)
710
- } : prepared;
711
- return { ...printable, text: prewrapText(printable), prewrapped: true };
779
+ text: wrapped.text,
780
+ ...wrapped.indents ? { prewrappedIndents: wrapped.indents } : {},
781
+ prewrapped: true
782
+ };
712
783
  }
713
784
  function measureTextFlowHeight(element, data) {
714
785
  if (element.heightOverflow && element.heightOverflow !== "flow")
@@ -717,7 +788,13 @@ function measureTextFlowHeight(element, data) {
717
788
  return Math.max(prepared.height, estimateTextHeight(prepared));
718
789
  }
719
790
  function truncateTextOverflow(element, height, mode) {
720
- return { ...element, text: truncateText(element, height, mode) };
791
+ const truncated = truncateTextLayout(element, height, mode);
792
+ return {
793
+ ...element,
794
+ text: truncated.text,
795
+ prewrapped: true,
796
+ ...truncated.indents ? { prewrappedIndents: truncated.indents } : {}
797
+ };
721
798
  }
722
799
  function registeredFieldBindingInfo(element, fields) {
723
800
  const config = getPrintDesignElementDataConfig(element, fields);
@@ -790,14 +867,14 @@ function resolveTextFontSizeValue(value, defaultUnit = "mm") {
790
867
  // src/plugins/text/data/binding.ts
791
868
  function getTextBindingInfo(element) {
792
869
  const content = registeredFieldBindingInfo(element, textDataFields);
793
- const paths = [
870
+ const paths2 = [
794
871
  ...content.paths,
795
872
  element.colorMode === "binding" ? element.colorPath : void 0,
796
873
  element.fontSizeMode === "binding" ? element.fontSizePath : void 0
797
874
  ].filter((path) => !!path?.trim());
798
875
  return {
799
876
  bound: content.bound || element.colorMode === "binding" || element.fontSizeMode === "binding",
800
- paths
877
+ paths: paths2
801
878
  };
802
879
  }
803
880
  function missingExpressionPath(expression, data) {
@@ -857,7 +934,7 @@ function resolveTextData(element, data) {
857
934
  // src/plugins/text/native.ts
858
935
  var textNativePlugin = defineNativePlugin(
859
936
  "text",
860
- "0.1.34",
937
+ "0.1.38",
861
938
  definePrintDesignPluginRenderer({
862
939
  type: "text",
863
940
  dataFields: textDataFields,
@@ -880,6 +957,268 @@ var textNativePlugin = defineNativePlugin(
880
957
  inlineTextEditor: textInlineEditor
881
958
  })
882
959
  );
960
+
961
+ // src/plugins/rich-text/model.ts
962
+ function validateRichTextElement(value) {
963
+ if (!value || typeof value !== "object") return false;
964
+ const element = value;
965
+ return element.type === "richText" && (element.dataConfig === void 0 || element.dataConfig.mode === "static") && Array.isArray(element.runs) && element.runs.length <= 2e3 && element.runs.reduce(
966
+ (length, run) => length + (typeof run?.text === "string" ? run.text.length : 0),
967
+ 0
968
+ ) <= 1e5 && element.runs.every(
969
+ (run) => run && typeof run.text === "string" && run.text.length > 0 && Object.keys(run).every((key) => key === "text" || key === "style") && (run.style === void 0 || run.style && typeof run.style === "object" && !Array.isArray(run.style) && Object.keys(run.style).every(
970
+ (key) => ["fontFamily", "fontSize", "fontWeight", "fontStyle", "color"].includes(key)
971
+ ) && (run.style.fontFamily === void 0 || typeof run.style.fontFamily === "string" && run.style.fontFamily.length <= 200 && /^[\p{L}\p{N}_\s,'"-]+$/u.test(run.style.fontFamily)) && (run.style.fontSize === void 0 || Number.isFinite(run.style.fontSize) && run.style.fontSize > 0 && run.style.fontSize <= 240) && (run.style.fontWeight === void 0 || typeof run.style.fontWeight === "string" && /^(?:[1-9]00|normal|bold)$/.test(run.style.fontWeight)) && (run.style.fontStyle === void 0 || ["normal", "italic"].includes(run.style.fontStyle)) && (run.style.color === void 0 || typeof run.style.color === "string" && /^#[0-9a-fA-F]{3,8}$/.test(run.style.color)))
972
+ ) && (element.fontSize === void 0 || Number.isFinite(element.fontSize) && element.fontSize > 0 && element.fontSize <= 240) && (element.fontFamily === void 0 || typeof element.fontFamily === "string" && element.fontFamily.length <= 200 && /^[\p{L}\p{N}_\s,'"-]+$/u.test(element.fontFamily)) && (element.fontWeight === void 0 || typeof element.fontWeight === "string" && /^(?:[1-9]00|normal|bold)$/.test(element.fontWeight)) && (element.fontStyle === void 0 || ["normal", "italic"].includes(element.fontStyle)) && (element.color === void 0 || typeof element.color === "string" && /^#[0-9a-fA-F]{3,8}$/.test(element.color)) && (element.textAlign === void 0 || ["left", "center", "right"].includes(element.textAlign)) && (element.verticalAlign === void 0 || ["top", "middle", "bottom"].includes(element.verticalAlign)) && (element.lineHeight === void 0 || Number.isFinite(element.lineHeight) && element.lineHeight >= 0.5 && element.lineHeight <= 4) && (element.indentMode === void 0 || ["none", "firstLine", "hanging"].includes(element.indentMode)) && (element.indentValue === void 0 || Number.isFinite(element.indentValue) && element.indentValue >= 0) && (element.indentUnit === void 0 || ["char", "mm", "cm", "in", "pt", "px"].includes(element.indentUnit)) && (element.prewrapped === void 0 || typeof element.prewrapped === "boolean") && (element.prewrappedIndents === void 0 || Array.isArray(element.prewrappedIndents) && element.prewrappedIndents.every(
973
+ (indent) => Number.isFinite(indent) && indent >= 0
974
+ ));
975
+ }
976
+ function richTextIndentMm(element) {
977
+ if (!element.indentMode || element.indentMode === "none") return 0;
978
+ const value = Math.max(0, element.indentValue ?? 0);
979
+ return element.indentUnit === "char" || !element.indentUnit ? value * (element.fontSize ?? 14) * 25.4 / 72 : fromDisplayUnit(value, element.indentUnit);
980
+ }
981
+ function richTextGraphemes(text) {
982
+ const Segmenter = Intl.Segmenter;
983
+ return Segmenter ? Array.from(
984
+ new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
985
+ (part) => part.segment
986
+ ) : Array.from(text);
987
+ }
988
+
989
+ // src/plugins/rich-text/rendering.ts
990
+ function runStyle(element, run) {
991
+ return {
992
+ fontFamily: resolvePrintDesignFontFamily(
993
+ run.style?.fontFamily ?? element.fontFamily
994
+ ),
995
+ fontSize: run.style?.fontSize ?? element.fontSize ?? 14,
996
+ fontWeight: run.style?.fontWeight ?? element.fontWeight ?? "400",
997
+ fontStyle: run.style?.fontStyle ?? element.fontStyle ?? "normal",
998
+ color: run.style?.color ?? element.color ?? "#1f2937"
999
+ };
1000
+ }
1001
+ function layoutRichTextLines(element, width, scale, measure) {
1002
+ const indent = richTextIndentMm(element) * scale;
1003
+ const lineHeight = element.lineHeight ?? 1.35;
1004
+ const lines = [];
1005
+ let paragraphLine = 0;
1006
+ const addLine = () => {
1007
+ const inset = element.prewrapped ? (element.prewrappedIndents?.[lines.length] ?? 0) * scale : element.indentMode === "firstLine" && paragraphLine === 0 || element.indentMode === "hanging" && paragraphLine > 0 ? indent : 0;
1008
+ lines.push({
1009
+ chars: [],
1010
+ width: 0,
1011
+ indent: inset,
1012
+ height: (element.fontSize ?? 14) * 25.4 / 72 * scale * lineHeight
1013
+ });
1014
+ };
1015
+ addLine();
1016
+ for (const run of element.runs) {
1017
+ const style = runStyle(element, run);
1018
+ const fontSize = style.fontSize * 25.4 / 72 * scale;
1019
+ for (const char of richTextGraphemes(run.text.replace(/\r\n?/g, "\n"))) {
1020
+ if (char === "\n") {
1021
+ paragraphLine = 0;
1022
+ addLine();
1023
+ continue;
1024
+ }
1025
+ const charWidth = measure(char, style, fontSize);
1026
+ let line = lines[lines.length - 1];
1027
+ if (!element.prewrapped && line.chars.length && line.width + charWidth > Math.max(1, width - line.indent)) {
1028
+ paragraphLine++;
1029
+ addLine();
1030
+ line = lines[lines.length - 1];
1031
+ }
1032
+ line.chars.push({ text: char, width: charWidth, style });
1033
+ line.width += charWidth;
1034
+ line.height = Math.max(line.height, fontSize * lineHeight);
1035
+ }
1036
+ }
1037
+ return lines;
1038
+ }
1039
+ function drawRichTextElement(element, { ctx, scale, x, y, width, height }) {
1040
+ const lineHeight = element.lineHeight ?? 1.35;
1041
+ const lines = layoutRichTextLines(
1042
+ element,
1043
+ width,
1044
+ scale,
1045
+ (char, style, fontSize) => {
1046
+ ctx.font = `${style.fontStyle} ${style.fontWeight} ${fontSize}px ${style.fontFamily}`;
1047
+ return ctx.measureText(char).width;
1048
+ }
1049
+ );
1050
+ const totalHeight = lines.reduce((sum, line) => sum + line.height, 0);
1051
+ let top = y + (element.verticalAlign === "middle" ? Math.max(0, (height - totalHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - totalHeight) : 0);
1052
+ ctx.save();
1053
+ ctx.beginPath();
1054
+ ctx.rect(x, y, width, height);
1055
+ ctx.clip();
1056
+ ctx.textAlign = "left";
1057
+ ctx.textBaseline = "alphabetic";
1058
+ for (const line of lines) {
1059
+ let left = x + line.indent;
1060
+ const available = Math.max(0, width - line.indent);
1061
+ if (element.textAlign === "center") left += (available - line.width) / 2;
1062
+ if (element.textAlign === "right") left += available - line.width;
1063
+ for (const char of line.chars) {
1064
+ const fontSize = char.style.fontSize * 25.4 / 72 * scale;
1065
+ ctx.font = `${char.style.fontStyle} ${char.style.fontWeight} ${fontSize}px ${char.style.fontFamily}`;
1066
+ ctx.fillStyle = char.style.color;
1067
+ ctx.fillText(
1068
+ char.text,
1069
+ left,
1070
+ top + (line.height - fontSize * lineHeight) / 2 + fontSize
1071
+ );
1072
+ left += char.width;
1073
+ }
1074
+ top += line.height;
1075
+ }
1076
+ ctx.restore();
1077
+ }
1078
+ function renderRichTextHtml(element) {
1079
+ const baseSize = cssNumber(element.fontSize, 14);
1080
+ const indent = richTextIndentMm(element);
1081
+ const paragraphs = [""];
1082
+ for (const run of element.runs) {
1083
+ const style = runStyle(element, run);
1084
+ const css = `font-family:${escapeHtml(cssFont(style.fontFamily))};font-size:${cssNumber(style.fontSize, baseSize)}pt;font-weight:${escapeHtml(style.fontWeight)};font-style:${style.fontStyle};color:${cssColor(style.color, "#1f2937")}`;
1085
+ const chunks = run.text.replace(/\r\n?/g, "\n").split("\n");
1086
+ chunks.forEach((chunk, index) => {
1087
+ if (index) paragraphs.push("");
1088
+ paragraphs[paragraphs.length - 1] += `<span style="${css}">${escapeHtml(chunk)}</span>`;
1089
+ });
1090
+ }
1091
+ const paragraphCss = element.indentMode === "firstLine" && indent > 0 ? `text-indent:${cssNumber(indent, 0)}mm;` : element.indentMode === "hanging" && indent > 0 ? `padding-left:${cssNumber(indent, 0)}mm;text-indent:-${cssNumber(indent, 0)}mm;box-sizing:border-box;` : "";
1092
+ const body = paragraphs.map(
1093
+ (paragraph, index) => `<div style="${element.prewrapped ? `white-space:pre;overflow:hidden;flex:none;box-sizing:border-box;padding-left:${cssNumber(element.prewrappedIndents?.[index], 0)}mm;` : paragraphCss}">${paragraph || "<br>"}</div>`
1094
+ ).join("");
1095
+ return renderPrintDesignHtmlFrame(
1096
+ element,
1097
+ `<div style="width:100%;height:100%;overflow:hidden;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-all;text-spacing-trim:space-all;text-autospace:no-autospace;line-height:${cssNumber(element.lineHeight, 1.35)};font-family:${escapeHtml(cssFont(element.fontFamily))};font-size:${baseSize}pt;font-weight:${escapeHtml(element.fontWeight ?? "400")};font-style:${element.fontStyle ?? "normal"};color:${cssColor(element.color, "#1f2937")};text-align:${element.textAlign ?? "left"};display:flex;flex-direction:column;justify-content:${element.verticalAlign === "middle" ? "center" : element.verticalAlign === "bottom" ? "flex-end" : "flex-start"}">${body}</div>`
1098
+ );
1099
+ }
1100
+
1101
+ // src/plugins/rich-text/pagination.ts
1102
+ function measureLines(element) {
1103
+ const canvas = typeof document !== "undefined" ? document.createElement("canvas") : null;
1104
+ const context = canvas?.getContext("2d");
1105
+ return layoutRichTextLines(element, element.width, 1, (text, style, size) => {
1106
+ if (context) {
1107
+ context.font = `${style.fontStyle} ${style.fontWeight} ${size}px ${style.fontFamily}`;
1108
+ return context.measureText(text).width;
1109
+ }
1110
+ return size * (/[^\p{ASCII}]/u.test(text) ? 1 : 0.55);
1111
+ });
1112
+ }
1113
+ function linesToRuns(lines) {
1114
+ const result = [];
1115
+ for (const [index, line] of lines.entries()) {
1116
+ if (index) result.push({ text: "\n" });
1117
+ for (const char of line.chars) {
1118
+ const previous = result[result.length - 1];
1119
+ const style = char.style;
1120
+ if (previous && JSON.stringify(previous.style) === JSON.stringify(style))
1121
+ previous.text += char.text;
1122
+ else result.push({ text: char.text, style });
1123
+ }
1124
+ }
1125
+ return result;
1126
+ }
1127
+ function truncateRichTextOverflow(element, height, mode) {
1128
+ const lines = measureLines(element);
1129
+ const visible = [];
1130
+ let used = 0;
1131
+ for (const line of lines) {
1132
+ if (visible.length && used + line.height > height) break;
1133
+ visible.push({ ...line, chars: [...line.chars] });
1134
+ used += line.height;
1135
+ }
1136
+ if (mode === "ellipsis" && visible.length < lines.length && visible.length) {
1137
+ const last = visible[visible.length - 1];
1138
+ const style = last.chars[last.chars.length - 1]?.style ?? {
1139
+ fontFamily: element.fontFamily ?? "Arial, sans-serif",
1140
+ fontSize: element.fontSize ?? 14,
1141
+ fontWeight: element.fontWeight ?? "400",
1142
+ fontStyle: element.fontStyle ?? "normal",
1143
+ color: element.color ?? "#1f2937"
1144
+ };
1145
+ const ellipsisWidth = style.fontSize * 25.4 / 72;
1146
+ while (last.chars.length && last.width + ellipsisWidth > element.width - last.indent) {
1147
+ last.width -= last.chars.pop().width;
1148
+ }
1149
+ last.chars.push({ text: "\u2026", style, width: ellipsisWidth });
1150
+ last.width += ellipsisWidth;
1151
+ }
1152
+ return {
1153
+ ...element,
1154
+ runs: linesToRuns(visible),
1155
+ prewrapped: true,
1156
+ prewrappedIndents: visible.map((line) => line.indent),
1157
+ verticalAlign: "top"
1158
+ };
1159
+ }
1160
+ function paginateRichText(element, context) {
1161
+ const lines = measureLines(element);
1162
+ let pageIndex = context.startPage;
1163
+ let y = context.startY;
1164
+ let offset = 0;
1165
+ do {
1166
+ const remaining = () => context.bottom - y;
1167
+ if (remaining() < (lines[offset]?.height ?? 0) && y > context.top) {
1168
+ pageIndex++;
1169
+ y = context.top;
1170
+ }
1171
+ const chunk = [];
1172
+ let height = 0;
1173
+ while (offset < lines.length && (!chunk.length || height + lines[offset].height <= remaining())) {
1174
+ chunk.push(lines[offset]);
1175
+ height += lines[offset].height;
1176
+ offset++;
1177
+ }
1178
+ const continues = offset < lines.length;
1179
+ const finalHeight = continues ? Math.max(0, remaining()) : Math.max(height, element.height);
1180
+ context.pageAt(pageIndex).elements.push({
1181
+ ...element,
1182
+ id: `${element.id}:flow:${pageIndex}`,
1183
+ previewSourceId: element.previewSourceId ?? element.id,
1184
+ y,
1185
+ height: Math.min(Math.max(0, remaining()), finalHeight),
1186
+ runs: linesToRuns(chunk),
1187
+ prewrapped: true,
1188
+ prewrappedIndents: chunk.map((line) => line.indent),
1189
+ verticalAlign: "top"
1190
+ });
1191
+ y += Math.min(Math.max(0, remaining()), finalHeight);
1192
+ if (continues) {
1193
+ pageIndex++;
1194
+ y = context.top;
1195
+ }
1196
+ } while (offset < lines.length);
1197
+ return {
1198
+ logicalEnd: pageIndex * (context.bottom - context.top) + (y - context.top)
1199
+ };
1200
+ }
1201
+ function measureRichTextFlowHeight(element) {
1202
+ return Math.max(
1203
+ element.height,
1204
+ measureLines(element).reduce((height, line) => height + line.height, 0)
1205
+ );
1206
+ }
1207
+
1208
+ // src/plugins/rich-text/native.ts
1209
+ var richTextNativePlugin = defineNativePlugin(
1210
+ "richText",
1211
+ "0.1.1",
1212
+ definePrintDesignPluginRenderer({
1213
+ type: "richText",
1214
+ validate: validateRichTextElement,
1215
+ drawCanvas: drawRichTextElement,
1216
+ renderHtml: (element) => renderRichTextHtml(element),
1217
+ paginate: paginateRichText,
1218
+ measureFlowHeight: measureRichTextFlowHeight,
1219
+ truncateOverflow: truncateRichTextOverflow
1220
+ })
1221
+ );
883
1222
  var drawListElement = (element, context) => {
884
1223
  const { ctx, x, y, width, height, scale, data } = context;
885
1224
  const row = Math.max(1, element.rowHeight ?? 8) * scale;
@@ -980,8 +1319,8 @@ function itemPaths(text) {
980
1319
  return [...text.matchAll(LIST_EXPRESSION)].map((match) => match[1]);
981
1320
  }
982
1321
  function listBindingInfo(element) {
983
- const paths = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
984
- return { bound: paths.length > 0, paths };
1322
+ const paths2 = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
1323
+ return { bound: paths2.length > 0, paths: paths2 };
985
1324
  }
986
1325
  function validateListTemplateData(element, data) {
987
1326
  if (!data) return [];
@@ -992,13 +1331,45 @@ function validateListTemplateData(element, data) {
992
1331
  );
993
1332
  }
994
1333
 
1334
+ // src/plugins/list/interaction/commands.ts
1335
+ var listCommands = {
1336
+ execute(element, command, payload) {
1337
+ if (element.locked || !payload || typeof payload !== "object") return;
1338
+ const args = payload;
1339
+ const index = args.index;
1340
+ if (!Number.isInteger(index)) return;
1341
+ const at = index;
1342
+ const items = [...element.items];
1343
+ if (command === "remove-item") {
1344
+ if (at < 0 || at >= items.length) return;
1345
+ items.splice(at, 1);
1346
+ } else if (command === "insert-item") {
1347
+ if (at < 0 || at > items.length || typeof args.text !== "string") return;
1348
+ items.splice(at, 0, { text: args.text, checked: false });
1349
+ } else if (command === "update-item") {
1350
+ if (at < 0 || at >= items.length) return;
1351
+ if (args.text !== void 0 && typeof args.text !== "string") return;
1352
+ if (args.checked !== void 0 && typeof args.checked !== "boolean")
1353
+ return;
1354
+ items[at] = {
1355
+ ...items[at],
1356
+ ...args.text === void 0 ? {} : { text: args.text },
1357
+ ...args.checked === void 0 ? {} : { checked: args.checked }
1358
+ };
1359
+ } else return;
1360
+ const next = { ...element, items };
1361
+ return validateListElement(next) ? next : void 0;
1362
+ }
1363
+ };
1364
+
995
1365
  // src/plugins/list/native.ts
996
1366
  var listNativePlugin = defineNativePlugin(
997
1367
  "list",
998
- "0.1.8",
1368
+ "0.1.9",
999
1369
  definePrintDesignPluginRenderer({
1000
1370
  type: "list",
1001
1371
  validate: validateListElement,
1372
+ commands: listCommands,
1002
1373
  bindingInfo: listBindingInfo,
1003
1374
  validateTemplateData: validateListTemplateData,
1004
1375
  drawCanvas: drawListElement,
@@ -1064,9 +1435,9 @@ function dateTimeBindingInfo(element) {
1064
1435
  }
1065
1436
  function validateDateTimeTemplateData(element, data) {
1066
1437
  if (!data) return [];
1067
- const { bound, paths } = dateTimeBindingInfo(element);
1438
+ const { bound, paths: paths2 } = dateTimeBindingInfo(element);
1068
1439
  if (!bound) return [];
1069
- const expression = paths[0];
1440
+ const expression = paths2[0];
1070
1441
  if (!expression) return ["\u672A\u914D\u7F6E\u65E5\u671F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
1071
1442
  const value = resolvePrintDesignBinding(data, expression);
1072
1443
  const text = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
@@ -1193,9 +1564,9 @@ function moneyUpperBindingInfo(element) {
1193
1564
  }
1194
1565
  function validateMoneyUpperTemplateData(element, data) {
1195
1566
  if (!data) return [];
1196
- const { bound, paths } = moneyUpperBindingInfo(element);
1567
+ const { bound, paths: paths2 } = moneyUpperBindingInfo(element);
1197
1568
  if (!bound) return [];
1198
- const expression = paths[0];
1569
+ const expression = paths2[0];
1199
1570
  if (!expression) return ["\u672A\u914D\u7F6E\u91D1\u989D\u7ED1\u5B9A\u5B57\u6BB5"];
1200
1571
  const value = resolvePrintDesignBinding(data, expression);
1201
1572
  const numeric2 = typeof value === "number" || typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
@@ -1275,9 +1646,9 @@ function pageNumberBindingInfo(element) {
1275
1646
  }
1276
1647
  function validatePageNumberTemplateData(element, data) {
1277
1648
  if (!data) return [];
1278
- const { bound, paths } = pageNumberBindingInfo(element);
1649
+ const { bound, paths: paths2 } = pageNumberBindingInfo(element);
1279
1650
  if (!bound) return [];
1280
- const expression = paths[0];
1651
+ const expression = paths2[0];
1281
1652
  if (!expression) return ["\u672A\u914D\u7F6E\u9875\u7801\u524D\u7F00\u7ED1\u5B9A\u5B57\u6BB5"];
1282
1653
  const value = resolvePrintDesignBinding(data, expression);
1283
1654
  return typeof value === "string" && value.trim() !== "" || typeof value === "number" || typeof value === "boolean" ? [] : [`\u7684\u9875\u7801\u524D\u7F00\u5B57\u6BB5\u300C${expression}\u300D\u5728\u5F53\u524D\u6570\u636E\u4E2D\u4E0D\u5B58\u5728`];
@@ -1379,23 +1750,18 @@ function renderWatermarkHtml(element, data, preciseClip = false) {
1379
1750
  const text = escapeHtml(
1380
1751
  element.dataConfig ? element.text : resolveDesignText(element.text, data)
1381
1752
  );
1382
- if (!preciseClip) {
1383
- const fontSize2 = cssNumber(element.fontSize, 24);
1384
- const cell = `<span style="color:${cssColor(element.color, "#94a3b8")};font-size:${fontSize2}pt;transform:rotate(${cssNumber(element.textRotation, 45)}deg) translateY(-${fontSize2 * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO}pt)">${text}</span>`;
1385
- const content2 = `<div class="pd-watermark" style="grid-template-columns:repeat(${columns},1fr);grid-template-rows:repeat(${rows},1fr)">${cell.repeat(rows * columns)}</div>`;
1386
- return renderPrintDesignHtmlFrame(element, content2);
1387
- }
1388
1753
  const width = Math.max(0, element.width);
1389
1754
  const height = Math.max(0, element.height);
1390
1755
  const fontSize = cssNumber(element.fontSize, 24) * 25.4 / 72;
1391
1756
  const color2 = cssColor(element.color, "#94a3b8");
1392
1757
  const rotation = cssNumber(element.textRotation, 45);
1758
+ const baselineFactor = preciseClip ? 0.3 : 0.39;
1393
1759
  const cells = Array.from({ length: rows * columns }, (_, index) => {
1394
1760
  const centerX = (index % columns + 0.5) * (width / columns);
1395
1761
  const centerY = (Math.floor(index / columns) + 0.5) * (height / rows);
1396
- return `<text x="${centerX}" y="${centerY + fontSize * 0.3}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1762
+ return `<text x="${centerX}" y="${centerY + fontSize * baselineFactor}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1397
1763
  }).join("");
1398
- const content = `<svg class="pd-watermark" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${escapeHtml(PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1764
+ const content = `<svg class="pd-watermark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${escapeHtml(PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1399
1765
  return renderPrintDesignHtmlFrame(element, content);
1400
1766
  }
1401
1767
 
@@ -1420,9 +1786,9 @@ function watermarkBindingInfo(element) {
1420
1786
  }
1421
1787
  function validateWatermarkTemplateData(element, data) {
1422
1788
  if (!data) return [];
1423
- const { bound, paths } = watermarkBindingInfo(element);
1789
+ const { bound, paths: paths2 } = watermarkBindingInfo(element);
1424
1790
  if (!bound) return [];
1425
- const expression = paths[0];
1791
+ const expression = paths2[0];
1426
1792
  if (!expression) return ["\u672A\u914D\u7F6E\u6C34\u5370\u6587\u5B57\u7ED1\u5B9A\u5B57\u6BB5"];
1427
1793
  for (const match of expression.matchAll(
1428
1794
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -1437,7 +1803,7 @@ function validateWatermarkTemplateData(element, data) {
1437
1803
  // src/plugins/watermark/native.ts
1438
1804
  var watermarkNativePlugin = defineNativePlugin(
1439
1805
  "watermark",
1440
- "0.1.9",
1806
+ "0.1.10",
1441
1807
  definePrintDesignPluginRenderer({
1442
1808
  type: "watermark",
1443
1809
  validate: validateWatermarkElement,
@@ -1457,8 +1823,7 @@ var watermarkNativePlugin = defineNativePlugin(
1457
1823
  physical && physical.y + physical.height > context.page.height
1458
1824
  )
1459
1825
  );
1460
- },
1461
- htmlCss: ".pd-watermark{display:grid;overflow:hidden;width:100%;height:100%}.pd-watermark span{display:flex;align-items:center;justify-content:center;white-space:nowrap}"
1826
+ }
1462
1827
  }),
1463
1828
  [{ id: "builtin.text", minVersion: "0.1.16" }]
1464
1829
  );
@@ -2635,16 +3000,51 @@ function pointToSegmentDistance(point, a, b) {
2635
3000
  return Math.hypot(point.x - a.x - t * dx, point.y - a.y - t * dy);
2636
3001
  }
2637
3002
 
3003
+ // src/plugins/shape/interaction/commands.ts
3004
+ var validPoints = (value) => Array.isArray(value) && value.every(
3005
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
3006
+ );
3007
+ var shapeCommands = {
3008
+ execute(element, command, payload) {
3009
+ if (element.locked || !payload || typeof payload !== "object") return;
3010
+ const args = payload;
3011
+ if (!validPoints(args.points)) return;
3012
+ const points = args.points;
3013
+ let next;
3014
+ if (command === "set-polygon-points") {
3015
+ if (!["triangle", "polygon", "star"].includes(element.shape) || points.length < 3)
3016
+ return;
3017
+ next = { ...element, polygonPoints: points };
3018
+ } else if (command === "set-curve-points") {
3019
+ if (!["curve-quadratic", "curve-cubic", "curve-multi"].includes(
3020
+ element.shape
3021
+ ) || points.length < 2)
3022
+ return;
3023
+ next = { ...element, curvePoints: points };
3024
+ } else if (command === "set-path-points") {
3025
+ if (element.shape !== "curve-path") return;
3026
+ if (args.closed !== void 0 && typeof args.closed !== "boolean") return;
3027
+ next = {
3028
+ ...element,
3029
+ pathPoints: points,
3030
+ ...args.closed === void 0 ? {} : { pathClosed: args.closed }
3031
+ };
3032
+ } else return;
3033
+ return validateShapeElement(next) ? next : void 0;
3034
+ }
3035
+ };
3036
+
2638
3037
  // src/plugins/shape/native.ts
2639
3038
  var shapeNativePlugin = defineNativePlugin(
2640
3039
  "shape",
2641
- "0.1.20",
3040
+ "0.1.21",
2642
3041
  definePrintDesignPluginRenderer({
2643
3042
  type: "shape",
2644
3043
  dataFields: shapeDataFields,
2645
3044
  bindingInfo: (element) => registeredFieldBindingInfo(element, shapeDataFields),
2646
3045
  validateTemplateData: (element, data) => validateRegisteredFieldBindings(element, shapeDataFields, data),
2647
3046
  validate: validateShapeElement,
3047
+ commands: shapeCommands,
2648
3048
  drawCanvas: drawShapeElement,
2649
3049
  renderHtml: (element, context) => renderShapeHtml(element, context.data),
2650
3050
  hitTest: hitShape,
@@ -2986,13 +3386,42 @@ var brushPointerStroke = {
2986
3386
  }
2987
3387
  };
2988
3388
 
3389
+ // src/plugins/brush/interaction/commands.ts
3390
+ var brushCommands = {
3391
+ execute(element, command, payload) {
3392
+ if (element.locked || !payload || typeof payload !== "object") return;
3393
+ const args = payload;
3394
+ if (command === "append-stroke") {
3395
+ if (!Array.isArray(args.points) || args.points.length < 2) return;
3396
+ const next2 = {
3397
+ ...element,
3398
+ strokes: [
3399
+ ...element.strokes,
3400
+ args.points
3401
+ ]
3402
+ };
3403
+ return validateBrushElement(next2) ? next2 : void 0;
3404
+ }
3405
+ if (command !== "remove-stroke" || !Number.isInteger(args.index)) return;
3406
+ const index = args.index;
3407
+ if (index < 0 || index >= element.strokes.length) return;
3408
+ const next = {
3409
+ ...element,
3410
+ strokes: element.strokes.filter((_, at) => at !== index),
3411
+ strokeStyles: element.strokeStyles?.filter((_, at) => at !== index)
3412
+ };
3413
+ return validateBrushElement(next) ? next : void 0;
3414
+ }
3415
+ };
3416
+
2989
3417
  // src/plugins/brush/native.ts
2990
3418
  var brushNativePlugin = defineNativePlugin(
2991
3419
  "brush",
2992
- "0.1.4",
3420
+ "0.1.5",
2993
3421
  definePrintDesignPluginRenderer({
2994
3422
  type: "brush",
2995
3423
  validate: validateBrushElement,
3424
+ commands: brushCommands,
2996
3425
  drawCanvas: drawBrushElement,
2997
3426
  renderHtml: (element) => renderBrushHtml(element),
2998
3427
  hitTest: hitBrush,
@@ -3988,6 +4417,46 @@ function validateConnectorElement(value) {
3988
4417
  const validPoint = (point) => !!point && Number.isFinite(point.x) && Number.isFinite(point.y);
3989
4418
  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);
3990
4419
  }
4420
+
4421
+ // src/plugins/connector/interaction/commands.ts
4422
+ var validEndpoint = (value) => {
4423
+ if (!value || typeof value !== "object" || Array.isArray(value)) return false;
4424
+ const endpoint2 = value;
4425
+ return (endpoint2.elementId === void 0 || typeof endpoint2.elementId === "string") && (endpoint2.anchor === void 0 || typeof endpoint2.anchor === "string" && ([
4426
+ "auto",
4427
+ "top",
4428
+ "right",
4429
+ "bottom",
4430
+ "left",
4431
+ "top-left",
4432
+ "top-right",
4433
+ "bottom-right",
4434
+ "bottom-left"
4435
+ ].includes(endpoint2.anchor) || /^(edge|vertex):\d+$/.test(endpoint2.anchor)));
4436
+ };
4437
+ var connectorCommands = {
4438
+ execute(element, command, payload) {
4439
+ if (element.locked || !payload || typeof payload !== "object") return;
4440
+ const args = payload;
4441
+ if (command === "set-endpoint") {
4442
+ if (args.side !== "start" && args.side !== "end") return;
4443
+ if (!validEndpoint(args.endpoint)) return;
4444
+ const next2 = { ...element, [args.side]: args.endpoint };
4445
+ return validateConnectorElement(next2) ? next2 : void 0;
4446
+ }
4447
+ if (command !== "set-waypoints" || element.lineType !== "polyline")
4448
+ return;
4449
+ if (!Array.isArray(args.points) || !args.points.every(
4450
+ (point) => point && typeof point === "object" && Number.isFinite(point.x) && Number.isFinite(point.y)
4451
+ ))
4452
+ return;
4453
+ const next = {
4454
+ ...element,
4455
+ polylinePoints: args.points
4456
+ };
4457
+ return validateConnectorElement(next) ? next : void 0;
4458
+ }
4459
+ };
3991
4460
  var CONNECTOR_EXPRESSION = /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g;
3992
4461
  function labelPaths(element) {
3993
4462
  return [...(element.text ?? "").matchAll(CONNECTOR_EXPRESSION)].map(
@@ -3995,8 +4464,8 @@ function labelPaths(element) {
3995
4464
  );
3996
4465
  }
3997
4466
  function connectorBindingInfo(element) {
3998
- const paths = [...new Set(labelPaths(element))];
3999
- return { bound: paths.length > 0, paths };
4467
+ const paths2 = [...new Set(labelPaths(element))];
4468
+ return { bound: paths2.length > 0, paths: paths2 };
4000
4469
  }
4001
4470
  function validateConnectorTemplateData(element, data) {
4002
4471
  if (!data) return [];
@@ -4008,10 +4477,11 @@ function validateConnectorTemplateData(element, data) {
4008
4477
  // src/plugins/connector/native.ts
4009
4478
  var connectorNativePlugin = defineNativePlugin(
4010
4479
  "connector",
4011
- "0.1.31",
4480
+ "0.1.32",
4012
4481
  definePrintDesignPluginRenderer({
4013
4482
  type: "connector",
4014
4483
  validate: validateConnectorElement,
4484
+ commands: connectorCommands,
4015
4485
  bindingInfo: connectorBindingInfo,
4016
4486
  validateTemplateData: validateConnectorTemplateData,
4017
4487
  allowSignedSize: true,
@@ -4797,13 +5267,13 @@ function gridMarkup(element, data) {
4797
5267
 
4798
5268
  // src/plugins/grid/data/binding.ts
4799
5269
  function getGridBindingInfo(element) {
4800
- const paths = [
5270
+ const paths2 = [
4801
5271
  element.contentPath,
4802
5272
  element.loopsPath,
4803
5273
  element.columnLoopsPath,
4804
5274
  ...(element.cells ?? []).filter((cell) => cell.contentMode === "binding").map((cell) => cell.contentPath)
4805
5275
  ].map((path) => path?.trim()).filter((path) => !!path);
4806
- return { bound: paths.length > 0, paths };
5276
+ return { bound: paths2.length > 0, paths: paths2 };
4807
5277
  }
4808
5278
  function validateGridTemplateData(element, data) {
4809
5279
  if (!data) return [];
@@ -4890,13 +5360,68 @@ function gridDebugRegions(element, context, hitElement = element) {
4890
5360
  return [...cells, ...loops, ...columnLoops];
4891
5361
  }
4892
5362
 
5363
+ // src/plugins/grid/interaction/commands.ts
5364
+ function executeGridCommand(element, command, payload, validate) {
5365
+ if (element.locked || !payload || typeof payload !== "object") return;
5366
+ const args = payload;
5367
+ if (command === "resize-grid") {
5368
+ const rows = args.rows;
5369
+ const columns = args.columns;
5370
+ if (!Number.isInteger(rows) || !Number.isInteger(columns)) return;
5371
+ if (rows < 1 || rows > 50 || columns < 1 || columns > 50)
5372
+ return;
5373
+ const cells2 = Array.from(
5374
+ { length: rows * columns },
5375
+ (_, index2) => {
5376
+ const row = Math.floor(index2 / columns);
5377
+ const column = index2 % columns;
5378
+ return element.cells?.[row * element.columns + column] ?? {};
5379
+ }
5380
+ );
5381
+ const next2 = {
5382
+ ...element,
5383
+ rows,
5384
+ columns,
5385
+ cells: cells2
5386
+ };
5387
+ return validate(next2) ? next2 : void 0;
5388
+ }
5389
+ if (command !== "set-cell") return;
5390
+ const rowIndex = args.rowIndex;
5391
+ const columnIndex = args.columnIndex;
5392
+ if (!Number.isInteger(rowIndex) || !Number.isInteger(columnIndex)) return;
5393
+ if (rowIndex < 0 || rowIndex >= element.rows || columnIndex < 0 || columnIndex >= element.columns)
5394
+ return;
5395
+ const cell = args.cell;
5396
+ if (!cell || typeof cell !== "object" || Array.isArray(cell)) return;
5397
+ const index = rowIndex * element.columns + columnIndex;
5398
+ const cells = Array.from(
5399
+ { length: element.rows * element.columns },
5400
+ (_, at) => ({ ...element.cells?.[at] })
5401
+ );
5402
+ cells[index] = { ...cells[index], ...cell };
5403
+ const next = { ...element, cells };
5404
+ return validate(next) ? next : void 0;
5405
+ }
5406
+ var gridCommands = {
5407
+ execute(element, command, payload) {
5408
+ return executeGridCommand(
5409
+ element,
5410
+ command,
5411
+ payload,
5412
+ (value) => !!value && typeof value === "object" && value.type === "grid" && validateGridSettings(value)
5413
+ );
5414
+ }
5415
+ };
5416
+
4893
5417
  // src/plugins/grid/native.ts
4894
5418
  var gridNativePlugin = defineNativePlugin(
4895
5419
  "grid",
4896
- "0.1.15",
5420
+ "0.1.16",
4897
5421
  definePrintDesignPluginRenderer({
4898
5422
  type: "grid",
4899
5423
  validate: validateGridElement,
5424
+ commands: gridCommands,
4900
5425
  validateTemplateData: validateGridTemplateData,
4901
5426
  bindingInfo: getGridBindingInfo,
4902
5427
  drawCanvas: drawGridElement,
@@ -5207,10 +5732,18 @@ function coordinateDebugRegions(element, context) {
5207
5732
  // src/plugins/coordinate/native.ts
5208
5733
  var coordinateNativePlugin = defineNativePlugin(
5209
5734
  "coordinate",
5210
- "0.1.15",
5735
+ "0.1.16",
5211
5736
  definePrintDesignPluginRenderer({
5212
5737
  type: "coordinate",
5213
5738
  validate: validateCoordinateElement,
5739
+ commands: {
5740
+ execute: (element, command, payload) => executeGridCommand(
5741
+ element,
5742
+ command,
5743
+ payload,
5744
+ validateCoordinateElement
5745
+ )
5746
+ },
5214
5747
  validateTemplateData: validateGridTemplateData,
5215
5748
  bindingInfo: getGridBindingInfo,
5216
5749
  drawCanvas: drawCoordinateElement,
@@ -5707,17 +6240,48 @@ function validateFlowTemplateData(element, data) {
5707
6240
  return [];
5708
6241
  }
5709
6242
 
6243
+ // src/plugins/flow/interaction/commands.ts
6244
+ var flowCommands = {
6245
+ execute(element, command, payload) {
6246
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
6247
+ return;
6248
+ const args = payload;
6249
+ const index = args.index;
6250
+ if (!Number.isInteger(index)) return;
6251
+ const at = index;
6252
+ if (command === "remove-item") {
6253
+ if (at < 0 || at >= element.items.length) return;
6254
+ return { ...element, items: element.items.filter((_, i) => i !== at) };
6255
+ }
6256
+ const item = args.item;
6257
+ if (!item || typeof item !== "object" || Array.isArray(item)) return;
6258
+ const items = [...element.items];
6259
+ if (command === "insert-item") {
6260
+ if (at < 0 || at > items.length) return;
6261
+ items.splice(at, 0, item);
6262
+ } else if (command === "update-item") {
6263
+ if (at < 0 || at >= items.length) return;
6264
+ items[at] = { ...items[at], ...item };
6265
+ } else return;
6266
+ const next = { ...element, items };
6267
+ return validateFlowElement(next) ? next : void 0;
6268
+ }
6269
+ };
6270
+
5710
6271
  // src/plugins/flow/native.ts
5711
6272
  var flowNativePlugin = defineNativePlugin(
5712
6273
  "flow",
5713
- "0.1.6",
6274
+ "0.1.7",
5714
6275
  definePrintDesignPluginRenderer({
5715
6276
  type: "flow",
5716
6277
  validate: validateFlowElement,
6278
+ commands: flowCommands,
5717
6279
  validateTemplateData: validateFlowTemplateData,
5718
6280
  bindingInfo: (element) => ({
5719
6281
  bound: (element.dataMode ?? element.dataConfig?.mode) === "binding",
5720
- paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [element.dataPath ?? element.dataConfig?.bindings?.items ?? ""].filter(Boolean) : []
6282
+ paths: (element.dataMode ?? element.dataConfig?.mode) === "binding" ? [
6283
+ element.dataPath ?? element.dataConfig?.bindings?.items ?? ""
6284
+ ].filter(Boolean) : []
5721
6285
  }),
5722
6286
  drawCanvas: drawFlowElement,
5723
6287
  renderHtml: (element, context) => renderFlowHtml(element, context.data)
@@ -5957,9 +6521,9 @@ function clockBindingInfo(element) {
5957
6521
  }
5958
6522
  function validateClockTemplateData(element, data) {
5959
6523
  if (!data) return [];
5960
- const { bound, paths } = clockBindingInfo(element);
6524
+ const { bound, paths: paths2 } = clockBindingInfo(element);
5961
6525
  if (!bound) return [];
5962
- const expression = paths[0];
6526
+ const expression = paths2[0];
5963
6527
  if (!expression) return ["\u672A\u914D\u7F6E\u65F6\u949F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
5964
6528
  for (const match of expression.matchAll(
5965
6529
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6198,9 +6762,9 @@ function imageBindingInfo(element) {
6198
6762
  }
6199
6763
  function validateImageTemplateData(element, data) {
6200
6764
  if (!data) return [];
6201
- const { bound, paths } = imageBindingInfo(element);
6765
+ const { bound, paths: paths2 } = imageBindingInfo(element);
6202
6766
  if (!bound) return [];
6203
- const expression = paths[0];
6767
+ const expression = paths2[0];
6204
6768
  if (!expression) return ["\u672A\u914D\u7F6E\u56FE\u7247\u5730\u5740\u7ED1\u5B9A\u5B57\u6BB5"];
6205
6769
  for (const match of expression.matchAll(
6206
6770
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6433,6 +6997,19 @@ function fitImageToPage(image, page, current) {
6433
6997
  return { x, y, width, height };
6434
6998
  }
6435
6999
 
7000
+ // src/plugins/image/interaction/commands.ts
7001
+ var imageCommands = {
7002
+ execute(element, command, payload) {
7003
+ if (element.locked) return;
7004
+ if (command === "clear-crop") return { ...element, crop: void 0 };
7005
+ if (command !== "set-crop" || !payload || typeof payload !== "object")
7006
+ return;
7007
+ const crop = payload;
7008
+ const next = { ...element, crop };
7009
+ return validateImageElement(next) ? next : void 0;
7010
+ }
7011
+ };
7012
+
6436
7013
  // src/plugins/image/native.ts
6437
7014
  var componentCropBehavior = {
6438
7015
  source: (element) => element.src,
@@ -6453,7 +7030,7 @@ var componentCropBehavior = {
6453
7030
  };
6454
7031
  var imageNativePlugin = defineNativePlugin(
6455
7032
  "image",
6456
- "0.1.16",
7033
+ "0.1.17",
6457
7034
  definePrintDesignPluginRenderer({
6458
7035
  type: "image",
6459
7036
  dataFields: imageDataFields,
@@ -6462,6 +7039,7 @@ var imageNativePlugin = defineNativePlugin(
6462
7039
  replaceResourceUri: (element, uri, replacement) => element.src === uri ? { ...element, src: replacement } : element,
6463
7040
  validateTemplateData: validateImageTemplateData,
6464
7041
  validate: validateImageElement,
7042
+ commands: imageCommands,
6465
7043
  drawCanvas: drawImageElement,
6466
7044
  prepareCanvas: (element, { signal }) => prepareImage(element.src, signal),
6467
7045
  needsCanvasPreparation: (element) => Boolean(element.src && !getLoadedImageSize(element.src)),
@@ -6540,9 +7118,9 @@ function barcodeBindingInfo(element) {
6540
7118
  }
6541
7119
  function validateBarcodeTemplateData(element, data) {
6542
7120
  if (!data) return [];
6543
- const { bound, paths } = barcodeBindingInfo(element);
7121
+ const { bound, paths: paths2 } = barcodeBindingInfo(element);
6544
7122
  if (!bound) return [];
6545
- const expression = paths[0];
7123
+ const expression = paths2[0];
6546
7124
  if (!expression) return ["\u672A\u914D\u7F6E\u6761\u5F62\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6547
7125
  for (const match of expression.matchAll(
6548
7126
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6642,9 +7220,9 @@ function qrcodeBindingInfo(element) {
6642
7220
  }
6643
7221
  function validateQrCodeTemplateData(element, data) {
6644
7222
  if (!data) return [];
6645
- const { bound, paths } = qrcodeBindingInfo(element);
7223
+ const { bound, paths: paths2 } = qrcodeBindingInfo(element);
6646
7224
  if (!bound) return [];
6647
- const expression = paths[0];
7225
+ const expression = paths2[0];
6648
7226
  if (!expression) return ["\u672A\u914D\u7F6E\u4E8C\u7EF4\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6649
7227
  for (const match of expression.matchAll(
6650
7228
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6731,6 +7309,45 @@ function validateChartTemplateData(element, data) {
6731
7309
  var record = (value) => value && typeof value === "object" && !Array.isArray(value) ? value : {};
6732
7310
  var seriesList = (value) => (Array.isArray(value) ? value : value ? [value] : []).map(record);
6733
7311
  var numeric = (value) => typeof value === "number" && Number.isFinite(value) ? value : typeof value === "string" && value.trim() && Number.isFinite(Number(value)) ? Number(value) : 0;
7312
+ function readChartData(element) {
7313
+ if (element.chartData) return element.chartData;
7314
+ const option = record(element.option);
7315
+ const series = seriesList(option.series);
7316
+ const first = series[0] ?? {};
7317
+ if (element.chartType === "pie" || element.chartType === "gauge") {
7318
+ const items = Array.isArray(first.data) ? first.data : [];
7319
+ return {
7320
+ mode: "static",
7321
+ categories: items.map((d) => String(record(d).name ?? "")),
7322
+ series: [
7323
+ {
7324
+ name: first.name ?? "\u7CFB\u5217 1",
7325
+ values: items.map((d) => numeric(record(d).value))
7326
+ }
7327
+ ]
7328
+ };
7329
+ }
7330
+ if (element.chartType === "radar") {
7331
+ const indicators = record(option.radar).indicator ?? [];
7332
+ return {
7333
+ mode: "static",
7334
+ categories: indicators.map((d) => String(record(d).name ?? "")),
7335
+ max: indicators[0]?.max ?? 100,
7336
+ series: (first.data ?? []).map((d, i) => ({
7337
+ name: record(d).name ?? `\u7CFB\u5217 ${i + 1}`,
7338
+ values: (record(d).value ?? []).map(numeric)
7339
+ }))
7340
+ };
7341
+ }
7342
+ return {
7343
+ mode: "static",
7344
+ categories: (record(option.xAxis).data ?? []).map(String),
7345
+ series: series.map((s, i) => ({
7346
+ name: s.name ?? `\u7CFB\u5217 ${i + 1}`,
7347
+ values: (s.data ?? []).map(numeric)
7348
+ }))
7349
+ };
7350
+ }
6734
7351
  function resolveChartOption(element, data = {}) {
6735
7352
  const option = record(element.option);
6736
7353
  const singleSeries = ["pie", "radar", "gauge"].includes(element.chartType);
@@ -6839,13 +7456,58 @@ function renderChartHtml(element, data) {
6839
7456
  });
6840
7457
  }
6841
7458
 
7459
+ // src/plugins/chart/interaction/commands.ts
7460
+ var chartCommands = {
7461
+ execute(element, command, payload) {
7462
+ if (element.locked || !payload || typeof payload !== "object") return;
7463
+ const args = payload;
7464
+ const chartData = readChartData(element);
7465
+ if (command === "set-categories") {
7466
+ if (!Array.isArray(args.categories) || !args.categories.every((item) => typeof item === "string"))
7467
+ return;
7468
+ const categories = args.categories;
7469
+ const next2 = {
7470
+ ...element,
7471
+ chartData: {
7472
+ ...chartData,
7473
+ categories,
7474
+ series: chartData.series.map((series2) => ({
7475
+ ...series2,
7476
+ values: categories.map((_, index2) => series2.values[index2] ?? 0)
7477
+ }))
7478
+ }
7479
+ };
7480
+ return validateChartElement(next2) ? next2 : void 0;
7481
+ }
7482
+ if (command !== "set-series") return;
7483
+ const index = args.index;
7484
+ if (!Number.isInteger(index) || index < 0 || index > chartData.series.length)
7485
+ return;
7486
+ if (typeof args.name !== "string" || !Array.isArray(args.values) || args.values.length !== chartData.categories.length || !args.values.every(
7487
+ (value) => typeof value === "number" && Number.isFinite(value)
7488
+ ))
7489
+ return;
7490
+ if (["pie", "gauge"].includes(element.chartType) && index > 0)
7491
+ return;
7492
+ const series = [...chartData.series];
7493
+ series[index] = {
7494
+ name: args.name,
7495
+ values: args.values,
7496
+ ...typeof args.field === "string" ? { field: args.field } : {}
7497
+ };
7498
+ const next = { ...element, chartData: { ...chartData, series } };
7499
+ return validateChartElement(next) ? next : void 0;
7500
+ }
7501
+ };
7502
+
6842
7503
  // src/plugins/chart/native.ts
6843
7504
  var chartNativePlugin = defineNativePlugin(
6844
7505
  "chart",
6845
- "0.1.8",
7506
+ "0.1.9",
6846
7507
  definePrintDesignPluginRenderer({
6847
7508
  type: "chart",
6848
7509
  validate: validateChartElement,
7510
+ commands: chartCommands,
6849
7511
  validateTemplateData: validateChartTemplateData,
6850
7512
  bindingInfo: (element) => ({
6851
7513
  bound: element.chartData?.mode === "binding",
@@ -7486,7 +8148,7 @@ function resolveDiagonalCount(count) {
7486
8148
  function diagonalCellLayout(direction, count, corner) {
7487
8149
  const lineCount = resolveDiagonalCount(count);
7488
8150
  const activeCorner = lineCount === 1 ? direction === "down" ? "top-left" : "bottom-left" : corner ?? (direction === "down" ? "top-left" : "bottom-left");
7489
- const paths = {
8151
+ const paths2 = {
7490
8152
  "top-left": [
7491
8153
  [0, 0],
7492
8154
  [1, 0],
@@ -7512,7 +8174,7 @@ function diagonalCellLayout(direction, count, corner) {
7512
8174
  [0, 1]
7513
8175
  ]
7514
8176
  };
7515
- const [apex, first, bend, last] = paths[activeCorner];
8177
+ const [apex, first, bend, last] = paths2[activeCorner];
7516
8178
  const farPoint = (position) => position <= 1 ? [
7517
8179
  first[0] + (bend[0] - first[0]) * position,
7518
8180
  first[1] + (bend[1] - first[1]) * position
@@ -9048,6 +9710,10 @@ function hitTableColumnBoundary(element, point, scale, includeSelector = false,
9048
9710
  }
9049
9711
  return nearest;
9050
9712
  }
9713
+ function boundaryHitRadius(height, scale, selector) {
9714
+ const radius = 5 / scale;
9715
+ return selector || height * scale >= 12 ? radius : Math.min(radius, height / 4);
9716
+ }
9051
9717
  function unmergedBoundarySegments(element, rowIndex, merges) {
9052
9718
  if (!merges.length) return [{ x: element.x + 3, width: element.width - 6 }];
9053
9719
  const columns = tableLeafColumns(
@@ -9089,11 +9755,25 @@ function tableHeaderResizeLayout(element, scale, data = {}) {
9089
9755
  for (let index = 0; index < depth; index++) {
9090
9756
  const edge = element.y + (index + 1) * height;
9091
9757
  if (edge > visibleBottom + 1e-9) break;
9092
- const shared = { rowIndex: index, edge, height, y: edge - 5 / scale };
9093
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9758
+ const shared = { rowIndex: index, edge, height };
9759
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9760
+ regions.push({
9761
+ ...shared,
9762
+ x: element.x - 6,
9763
+ width: 6,
9764
+ selector: true,
9765
+ radius: selectorRadius,
9766
+ y: edge - selectorRadius
9767
+ });
9094
9768
  if (edge < visibleBottom - 1e-9 && element.width > 6)
9095
9769
  for (const segment of unmergedBoundarySegments(element, index, headers))
9096
- regions.push({ ...shared, ...segment, selector: false });
9770
+ regions.push({
9771
+ ...shared,
9772
+ ...segment,
9773
+ selector: false,
9774
+ radius: boundaryHitRadius(height, scale, false),
9775
+ y: edge - boundaryHitRadius(height, scale, false)
9776
+ });
9097
9777
  }
9098
9778
  return regions;
9099
9779
  }
@@ -9108,7 +9788,7 @@ function hitTableHeaderBoundary(element, point, scale, data = {}) {
9108
9788
  -(element.rotation ?? 0) * Math.PI / 180
9109
9789
  );
9110
9790
  const region = tableHeaderResizeLayout(element, scale, data).filter(
9111
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9791
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9112
9792
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9113
9793
  return region && {
9114
9794
  elementId: element.id,
@@ -9140,13 +9820,26 @@ function tableRowResizeLayout(element, scale, data = {}) {
9140
9820
  const shared = {
9141
9821
  rowIndex: index + (element.sourceRowOffset ?? 0),
9142
9822
  edge: boundary,
9143
- height,
9144
- y: boundary - 5 / scale
9823
+ height
9145
9824
  };
9146
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9825
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9826
+ regions.push({
9827
+ ...shared,
9828
+ x: element.x - 6,
9829
+ width: 6,
9830
+ selector: true,
9831
+ radius: selectorRadius,
9832
+ y: boundary - selectorRadius
9833
+ });
9147
9834
  if (index < heights.length - 1 && element.width > 6)
9148
9835
  for (const segment of unmergedBoundarySegments(element, index, cells))
9149
- regions.push({ ...shared, ...segment, selector: false });
9836
+ regions.push({
9837
+ ...shared,
9838
+ ...segment,
9839
+ selector: false,
9840
+ radius: boundaryHitRadius(height, scale, false),
9841
+ y: boundary - boundaryHitRadius(height, scale, false)
9842
+ });
9150
9843
  }
9151
9844
  return regions;
9152
9845
  }
@@ -9161,7 +9854,7 @@ function hitTableRowBoundary(element, point, scale, data = {}) {
9161
9854
  -(element.rotation ?? 0) * Math.PI / 180
9162
9855
  );
9163
9856
  const region = tableRowResizeLayout(element, scale, data).filter(
9164
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9857
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9165
9858
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9166
9859
  return region && {
9167
9860
  elementId: element.id,
@@ -9296,12 +9989,12 @@ function tableDebugRegions(table, context, options = {}) {
9296
9989
  ...owner,
9297
9990
  id: `${area}-resize:${index}`,
9298
9991
  category: "resize",
9299
- label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB15px${hit ? " \u547D\u4E2D" : ""}`,
9992
+ label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB1${Math.round(region.radius * scale)}px${hit ? " \u547D\u4E2D" : ""}`,
9300
9993
  bounds: {
9301
9994
  x: region.x,
9302
9995
  y: region.y,
9303
9996
  width: region.width,
9304
- height: 10 / scale
9997
+ height: region.radius * 2
9305
9998
  },
9306
9999
  interactive: true,
9307
10000
  hit,
@@ -10272,11 +10965,227 @@ function emptyTableRow(element) {
10272
10965
  );
10273
10966
  }
10274
10967
 
10968
+ // src/plugins/table/data/packed-report-defaults.ts
10969
+ function fillPackedReportDefaults(columns, rows, current) {
10970
+ const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
10971
+ const keys2 = visible.map(
10972
+ (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
10973
+ );
10974
+ const repeats = /* @__PURE__ */ new Map();
10975
+ keys2.forEach((key) => {
10976
+ const match = /^(.+?)([1-9]\d*)$/.exec(key);
10977
+ if (!match) return;
10978
+ const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
10979
+ slots.add(Number(match[2]));
10980
+ repeats.set(match[1], slots);
10981
+ });
10982
+ const series = [...repeats].filter(
10983
+ ([, slots]) => slots.has(1) && slots.has(2)
10984
+ );
10985
+ const itemsPerRow = Math.max(
10986
+ 1,
10987
+ ...series.map(([, slots]) => Math.max(...slots))
10988
+ );
10989
+ const sample = rows.find((row) => row && typeof row === "object") ?? {};
10990
+ const groupFields = {};
10991
+ keys2.forEach((key, index) => {
10992
+ const repeated = series.some(
10993
+ ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
10994
+ );
10995
+ if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
10996
+ groupFields[key] = key in sample ? key : "";
10997
+ }
10998
+ });
10999
+ const itemFields = series.map(([prefix]) => ({
11000
+ prefix,
11001
+ .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
11002
+ }));
11003
+ const totals = {};
11004
+ visible.forEach((column, index) => {
11005
+ const key = keys2[index];
11006
+ const summary = column.summary;
11007
+ const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
11008
+ if (key && summary && type === "sum") {
11009
+ const prefix = series.find(
11010
+ ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
11011
+ )?.[0];
11012
+ totals[key] = {
11013
+ sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
11014
+ ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
11015
+ };
11016
+ }
11017
+ });
11018
+ const subtotalLabelKey = keys2.find(
11019
+ (key) => key && !(key in totals) && !(key in groupFields)
11020
+ );
11021
+ const totalLabelKey = keys2.find((key) => key && !(key in totals));
11022
+ const subtotal = { ...totals };
11023
+ if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
11024
+ if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
11025
+ return {
11026
+ groupBy: current?.groupBy ?? [],
11027
+ itemsPerRow: current?.itemsPerRow ?? itemsPerRow,
11028
+ groupFields: Object.keys(current?.groupFields ?? {}).length ? current.groupFields : groupFields,
11029
+ groupMergeColumns: Object.keys(current?.groupFields ?? {}).length ? current.groupMergeColumns : keys2.flatMap(
11030
+ (key, index) => key && key in groupFields ? [index] : []
11031
+ ),
11032
+ itemFields: current?.itemFields?.length ? current.itemFields : itemFields,
11033
+ subtotal: Object.keys(current?.subtotal ?? {}).length ? current.subtotal : subtotal,
11034
+ subtotalMerges: current?.subtotalMerges ?? [],
11035
+ total: Object.keys(current?.total ?? {}).length ? current.total : totals,
11036
+ totalMerges: current?.totalMerges ?? [],
11037
+ appendRows: current?.appendRows ?? [],
11038
+ ...current?.footerElementIds ? { footerElementIds: current.footerElementIds } : {}
11039
+ };
11040
+ }
11041
+
11042
+ // src/plugins/table/interaction/agent-commands.ts
11043
+ function object(input) {
11044
+ if (!input || typeof input !== "object" || Array.isArray(input))
11045
+ throw new TypeError("\u8868\u683C\u547D\u4EE4\u53C2\u6570\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
11046
+ return input;
11047
+ }
11048
+ function safePart(value) {
11049
+ return !!value.trim() && !value.split(/[.[\]]/).some((part) => ["__proto__", "prototype", "constructor"].includes(part));
11050
+ }
11051
+ function fieldPath(input, label) {
11052
+ if (typeof input === "string" && safePart(input)) return input.trim();
11053
+ if (Array.isArray(input) && input.length > 0 && input.every(
11054
+ (part) => typeof part === "string" && safePart(part) || typeof part === "number" && Number.isInteger(part) && part >= 0
11055
+ ))
11056
+ return input;
11057
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D\u6216\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11058
+ }
11059
+ function paths(input, label) {
11060
+ if (input === void 0) return [];
11061
+ if (!Array.isArray(input)) throw new TypeError(`${label} \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
11062
+ return input.map((value) => fieldPath(value, label));
11063
+ }
11064
+ function stringPaths(input, label) {
11065
+ if (!Array.isArray(input) || !input.length)
11066
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11067
+ return input.map((value) => {
11068
+ if (typeof value !== "string" || !safePart(value))
11069
+ throw new TypeError(`${label} \u4E2D\u7684\u5B57\u6BB5\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`);
11070
+ return value.trim();
11071
+ });
11072
+ }
11073
+ function configureTableAutoMerge(element, rawPayload) {
11074
+ const payload = object(rawPayload);
11075
+ if (payload.enabled === false) return { ...element, mergeCell: void 0 };
11076
+ const rowKeys = paths(payload.rowKeys, "rowKeys");
11077
+ const rowColumns = paths(payload.rowColumns, "rowColumns");
11078
+ const columnKeys = paths(payload.columnKeys, "columnKeys");
11079
+ if (!rowKeys.length && !columnKeys.length)
11080
+ throw new TypeError(
11081
+ "\u81F3\u5C11\u63D0\u4F9B rowKeys \u6216 columnKeys\uFF1B\u5173\u95ED\u65F6\u4F20 enabled=false\u3002"
11082
+ );
11083
+ if (rowColumns.length && !rowKeys.length)
11084
+ throw new TypeError("\u8BBE\u7F6E rowColumns \u65F6\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B rowKeys\u3002");
11085
+ const visible = tableLeafColumns(element.columns).filter((column) => !column.hidden).map((column) => JSON.stringify(column.dataIndex));
11086
+ for (const path of [
11087
+ ...rowColumns.length ? rowColumns : rowKeys,
11088
+ ...columnKeys
11089
+ ])
11090
+ if (!visible.includes(JSON.stringify(path)))
11091
+ throw new TypeError(`\u5408\u5E76\u76EE\u6807\u5217\u4E0D\u5B58\u5728\uFF1A${JSON.stringify(path)}\u3002`);
11092
+ return {
11093
+ ...element,
11094
+ mergeCell: {
11095
+ ...rowKeys.length ? {
11096
+ row: {
11097
+ keys: rowKeys,
11098
+ ...rowColumns.length ? { columns: rowColumns } : {}
11099
+ }
11100
+ } : {},
11101
+ ...columnKeys.length ? { column: { keys: columnKeys } } : {}
11102
+ }
11103
+ };
11104
+ }
11105
+ function configureTableGroupAggregation(element, rawPayload, data) {
11106
+ const payload = object(rawPayload);
11107
+ if (payload.enabled === false) return { ...element, packedReport: void 0 };
11108
+ const groupBy = stringPaths(payload.groupBy, "groupBy");
11109
+ if (payload.itemsPerRow !== void 0 && (!Number.isInteger(payload.itemsPerRow) || Number(payload.itemsPerRow) < 1))
11110
+ throw new TypeError("itemsPerRow \u5FC5\u987B\u662F\u5927\u4E8E\u96F6\u7684\u6574\u6570\u3002");
11111
+ if (payload.sums !== void 0 && !Array.isArray(payload.sums))
11112
+ throw new TypeError("sums \u5FC5\u987B\u662F\u6570\u7EC4\u3002");
11113
+ const source = element.dataMode === "binding" ? resolveTableDataSource(data, element.dataPath) : element.dataSource;
11114
+ const rows = Array.isArray(source) ? source.filter(
11115
+ (row) => !!row && typeof row === "object" && !Array.isArray(row)
11116
+ ) : element.dataSource;
11117
+ for (const path of groupBy)
11118
+ if (rows.length && !rows.some((row) => resolvePrintDesignDataPath(row, path) !== void 0))
11119
+ throw new TypeError(`\u5206\u7EC4\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${path}\u3002`);
11120
+ const report = fillPackedReportDefaults(
11121
+ element.columns,
11122
+ rows,
11123
+ element.packedReport
11124
+ );
11125
+ const visible = tableLeafColumns(element.columns).filter(
11126
+ (column) => !column.hidden
11127
+ );
11128
+ const groupFields = { ...report.groupFields };
11129
+ const subtotal = { ...report.subtotal };
11130
+ const total = { ...report.total };
11131
+ const sumColumns = /* @__PURE__ */ new Set();
11132
+ for (const raw of payload.sums ?? []) {
11133
+ const sum = object(raw);
11134
+ if (typeof sum.column !== "string" || !safePart(sum.column))
11135
+ throw new TypeError("sums.column \u5FC5\u987B\u662F\u8868\u683C\u5217\u7684 dataIndex \u5B57\u7B26\u4E32\u3002");
11136
+ const column = sum.column.trim();
11137
+ if (!visible.some((item) => item.dataIndex === column))
11138
+ throw new TypeError(`\u6C47\u603B\u5217\u4E0D\u5B58\u5728\uFF1A${column}\u3002`);
11139
+ if (sumColumns.has(column)) throw new TypeError(`\u6C47\u603B\u5217\u91CD\u590D\uFF1A${column}\u3002`);
11140
+ if (typeof sum.path !== "string" || !safePart(sum.path))
11141
+ throw new TypeError("sums.path \u5FC5\u987B\u662F\u539F\u59CB\u6570\u636E\u7684\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u3002");
11142
+ if (rows.length && !rows.some(
11143
+ (row) => resolvePrintDesignDataPath(row, sum.path) !== void 0
11144
+ ))
11145
+ throw new TypeError(`\u6C42\u548C\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${sum.path}\u3002`);
11146
+ if (sum.decimals !== void 0 && (!Number.isInteger(sum.decimals) || Number(sum.decimals) < 0 || Number(sum.decimals) > 10))
11147
+ throw new TypeError("sums.decimals \u5FC5\u987B\u662F 0 \u5230 10 \u7684\u6574\u6570\u3002");
11148
+ sumColumns.add(column);
11149
+ delete groupFields[column];
11150
+ const rule = {
11151
+ sumPath: sum.path.trim(),
11152
+ ...sum.decimals === void 0 ? {} : { decimals: sum.decimals }
11153
+ };
11154
+ subtotal[column] = rule;
11155
+ total[column] = rule;
11156
+ }
11157
+ if (sumColumns.size && !Object.values(subtotal).some((rule) => rule.text === "\u5C0F\u8BA1")) {
11158
+ const labelColumn = visible.find(
11159
+ (column) => typeof column.dataIndex === "string" && !sumColumns.has(column.dataIndex)
11160
+ );
11161
+ if (typeof labelColumn?.dataIndex === "string")
11162
+ subtotal[labelColumn.dataIndex] = { text: "\u5C0F\u8BA1" };
11163
+ }
11164
+ return {
11165
+ ...element,
11166
+ packedReport: {
11167
+ ...report,
11168
+ groupBy,
11169
+ ...payload.itemsPerRow === void 0 ? {} : { itemsPerRow: payload.itemsPerRow },
11170
+ groupFields,
11171
+ groupMergeColumns: report.groupMergeColumns.filter(
11172
+ (index) => !sumColumns.has(String(visible[index]?.dataIndex ?? ""))
11173
+ ),
11174
+ subtotal,
11175
+ total
11176
+ }
11177
+ };
11178
+ }
11179
+
10275
11180
  // src/plugins/table/interaction/commands.ts
10276
11181
  var tableCommands = {
10277
11182
  execute(element, command, rawPayload, context) {
10278
11183
  if (element.locked) return;
10279
11184
  if (!rawPayload || typeof rawPayload !== "object") return;
11185
+ if (command === "configure-auto-merge")
11186
+ return configureTableAutoMerge(element, rawPayload);
11187
+ if (command === "configure-group-aggregation")
11188
+ return configureTableGroupAggregation(element, rawPayload, context.data);
10280
11189
  const payload = rawPayload;
10281
11190
  const rowIndex = payload.rowIndex ?? 0;
10282
11191
  const columnIndex = payload.columnIndex ?? 0;
@@ -10671,7 +11580,7 @@ function validateTableTemplateData(element, data) {
10671
11580
  // src/plugins/table/native.ts
10672
11581
  var tableNativePlugin = defineNativePlugin(
10673
11582
  "table",
10674
- "0.1.68",
11583
+ "0.1.70",
10675
11584
  definePrintDesignPluginRenderer({
10676
11585
  type: "table",
10677
11586
  validate: validateTableElement,
@@ -10715,6 +11624,37 @@ var tableNativePlugin = defineNativePlugin(
10715
11624
  );
10716
11625
 
10717
11626
  // src/plugins/pivot-table/layout/field-layout.ts
11627
+ function movePivotField(layout, fieldKey, area, index, sourceArea) {
11628
+ const next = {
11629
+ filters: [...layout.filters],
11630
+ columns: [...layout.columns],
11631
+ rows: [...layout.rows],
11632
+ values: [...layout.values]
11633
+ };
11634
+ const areaKey = (value) => value === "filter" ? "filters" : value === "column" ? "columns" : value === "row" ? "rows" : "values";
11635
+ const targets = area === "value" ? ["values"] : ["filters", "columns", "rows"];
11636
+ for (const target2 of targets)
11637
+ next[target2] = next[target2].filter((key) => key !== fieldKey);
11638
+ if (sourceArea && sourceArea !== area) {
11639
+ const source = areaKey(sourceArea);
11640
+ next[source] = next[source].filter((key) => key !== fieldKey);
11641
+ }
11642
+ const target = next[areaKey(area)];
11643
+ target.splice(
11644
+ Math.max(0, Math.min(index ?? target.length, target.length)),
11645
+ 0,
11646
+ fieldKey
11647
+ );
11648
+ return next;
11649
+ }
11650
+ function removePivotField(layout, fieldKey) {
11651
+ return {
11652
+ filters: layout.filters.filter((key) => key !== fieldKey),
11653
+ columns: layout.columns.filter((key) => key !== fieldKey),
11654
+ rows: layout.rows.filter((key) => key !== fieldKey),
11655
+ values: layout.values.filter((key) => key !== fieldKey)
11656
+ };
11657
+ }
10718
11658
  function pivotFieldTitle(field) {
10719
11659
  return field.title ?? field.key;
10720
11660
  }
@@ -10966,6 +11906,41 @@ var pivotTableBoundaryResize = {
10966
11906
  }
10967
11907
  };
10968
11908
 
11909
+ // src/plugins/pivot-table/interaction/commands.ts
11910
+ var areas = ["filter", "column", "row", "value"];
11911
+ var pivotTableCommands = {
11912
+ execute(element, command, payload) {
11913
+ if (element.locked || !payload || typeof payload !== "object") return;
11914
+ const args = payload;
11915
+ const fieldKey = args.fieldKey;
11916
+ if (typeof fieldKey !== "string" || !element.fields.some((field) => field.key === fieldKey))
11917
+ return;
11918
+ if (command === "remove-field")
11919
+ return {
11920
+ ...element,
11921
+ layout: removePivotField(element.layout, fieldKey)
11922
+ };
11923
+ if (command !== "move-field" || !areas.includes(args.area))
11924
+ return;
11925
+ const index = args.index;
11926
+ if (index !== void 0 && (!Number.isInteger(index) || index < 0))
11927
+ return;
11928
+ const sourceArea = args.sourceArea;
11929
+ if (sourceArea !== void 0 && !areas.includes(sourceArea))
11930
+ return;
11931
+ return {
11932
+ ...element,
11933
+ layout: movePivotField(
11934
+ element.layout,
11935
+ fieldKey,
11936
+ args.area,
11937
+ index,
11938
+ sourceArea
11939
+ )
11940
+ };
11941
+ }
11942
+ };
11943
+
10969
11944
  // src/plugins/pivot-table/model.ts
10970
11945
  function validatePivotTableElement(value) {
10971
11946
  if (!value || typeof value !== "object") return false;
@@ -10979,11 +11954,12 @@ function validatePivotTableElement(value) {
10979
11954
  // src/plugins/pivot-table/native.ts
10980
11955
  var pivotTableNativePlugin = defineNativePlugin(
10981
11956
  "pivotTable",
10982
- "0.1.18",
11957
+ "0.1.19",
10983
11958
  definePrintDesignPluginRenderer({
10984
11959
  type: "pivotTable",
10985
11960
  htmlCss: tableHtmlCss,
10986
11961
  validate: validatePivotTableElement,
11962
+ commands: pivotTableCommands,
10987
11963
  validateTemplateData: validatePivotTemplateData,
10988
11964
  bindingInfo: (element) => ({
10989
11965
  bound: element.dataMode === "binding",
@@ -11494,13 +12470,49 @@ function ganttMarkup(element, data, pageNumber) {
11494
12470
  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="${cssColor(theme.backgroundColor, "transparent")}"/>${header > 0 ? `<rect width="${width}" height="${header}" fill="${cssColor(theme.headerBackgroundColor, "transparent")}"/>` : ""}${ticks}${taskSplit}${headerEdges}${headerTitle}${maskedDependencies}${bars}${frame}</svg>`;
11495
12471
  }
11496
12472
 
12473
+ // src/plugins/gantt/interaction/commands.ts
12474
+ var ganttCommands = {
12475
+ execute(element, command, payload) {
12476
+ if (element.locked || element.dataMode === "binding" || !payload || typeof payload !== "object")
12477
+ return;
12478
+ const args = payload;
12479
+ const tasks = [...element.tasks];
12480
+ if (command === "insert-task") {
12481
+ const index = args.index;
12482
+ if (!Number.isInteger(index) || index < 0 || index > tasks.length)
12483
+ return;
12484
+ if (!args.task || typeof args.task !== "object" || Array.isArray(args.task))
12485
+ return;
12486
+ const task = args.task;
12487
+ if (tasks.some((existing) => existing.id === task.id)) return;
12488
+ tasks.splice(index, 0, task);
12489
+ } else {
12490
+ const taskId = args.taskId;
12491
+ if (typeof taskId !== "string") return;
12492
+ const index = tasks.findIndex((task) => task.id === taskId);
12493
+ if (index < 0) return;
12494
+ if (command === "remove-task") tasks.splice(index, 1);
12495
+ else if (command === "update-task") {
12496
+ if (!args.patch || typeof args.patch !== "object" || Array.isArray(args.patch))
12497
+ return;
12498
+ const patch = args.patch;
12499
+ if (patch.id !== void 0 || patch.tasks !== void 0) return;
12500
+ tasks[index] = { ...tasks[index], ...patch };
12501
+ } else return;
12502
+ }
12503
+ const next = { ...element, tasks };
12504
+ return validateGanttElement(next) ? next : void 0;
12505
+ }
12506
+ };
12507
+
11497
12508
  // src/plugins/gantt/native.ts
11498
12509
  var ganttNativePlugin = defineNativePlugin(
11499
12510
  "gantt",
11500
- "0.1.6",
12511
+ "0.1.7",
11501
12512
  definePrintDesignPluginRenderer({
11502
12513
  type: "gantt",
11503
12514
  validate: validateGanttElement,
12515
+ commands: ganttCommands,
11504
12516
  validateTemplateData: validateGanttTemplateData,
11505
12517
  bindingInfo: (element) => ({
11506
12518
  bound: element.dataMode === "binding",
@@ -11514,6 +12526,7 @@ var ganttNativePlugin = defineNativePlugin(
11514
12526
  // src/native.ts
11515
12527
  var builtinNativeComponentPlugins = [
11516
12528
  textNativePlugin,
12529
+ richTextNativePlugin,
11517
12530
  listNativePlugin,
11518
12531
  dateTimeNativePlugin,
11519
12532
  moneyUpperNativePlugin,