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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,12 +1,12 @@
1
1
  import { LINE_STYLE_OPTIONS, FONT_FAMILY_OPTIONS, PrintDesignScopedPropertyRegistry, LayerAlignmentControls, ElementLayerControls, GroupControls, GuidePositionField, PreprintModeHelp, PropertyToggleButton, PaperSizeField, isBuiltinPaperSize, NumberField, PrintDesignComponentFactoryRegistry, PrintDesignToolRegistry, readPrintDesignTemplates, getPropertyFieldPatch, builtinPrintDesignComponentFactories, findSelectedGroup, DebuggerToolButton, TemplatePropertiesPanel, TemplatesTool, ComponentsTool, SavedGroupsTool, MultiSelectionPropertiesPanel, LayersTool, GuidePropertiesPanel, GuidesTool, PagePropertiesPanel, PagesTool, SettingsPropertiesPanel, SettingsTool, editorThemes, withEditorTheme, PluginMarketTool, JsonField, isPrintDesignDocumentCompatible, isPrintDesignTemplateInvalid, getPrintDesignTemplateInvalidLocations, ReactPrintDesign, DataModeButtons, DataPathPicker, useEditorPreferences } from '@canvas-components/react-print-design';
2
- import { definePrintDesignPluginRenderer, renderPrintDesignHtmlFrame, rotatePoint, resolvePrintDesignElementData, PrintDesignComponentRegistry, resolvePrintDesignBinding, resolvePrintDesignElementVisible, resolvePrintDesignPageVisible, resolveDesignText, cssFont, PRINT_DESIGN_DEFAULT_FONT_FAMILY, isPrintDesignColorValue, resolvePrintDesignDataPath, cssNumber, cssColor, escapeHtml, getPrintDesignElementDataConfig, elementTransformHomography, projectTransformPoint, hitTestPrintDesignPage, transformRect, elementTransformCss, pixelsToMillimeters, PRINT_DESIGN_CSS_DPI, isPrintDesignRecordCollection, clonePrintDesignDocument, getSelectionRect, fromDisplayUnit, toDisplayUnit, inverseTransformPoint, stringifyPrintDesignBinding, createPrintDesignId, transformPrintDesignToHtmlBatches, createPrintDesignDocument, createPrintDesignPage } from '@canvas-components/print-design';
2
+ import { definePrintDesignPluginRenderer, renderPrintDesignHtmlFrame, rotatePoint, resolvePrintDesignElementData, PrintDesignComponentRegistry, resolvePrintDesignBinding, resolvePrintDesignElementVisible, resolvePrintDesignPageVisible, resolveDesignText, cssFont, isPrintDesignColorValue, cssNumber, escapeHtml, cssColor, PRINT_DESIGN_DEFAULT_FONT_FAMILY, resolvePrintDesignDataPath, getPrintDesignElementDataConfig, elementTransformHomography, projectTransformPoint, hitTestPrintDesignPage, transformRect, elementTransformCss, pixelsToMillimeters, PRINT_DESIGN_CSS_DPI, isPrintDesignRecordCollection, clonePrintDesignDocument, getSelectionRect, fromDisplayUnit, toDisplayUnit, resolvePrintDesignFontFamily, inverseTransformPoint, stringifyPrintDesignBinding, createPrintDesignId, transformPrintDesignToHtmlBatches, createPrintDesignDocument, createPrintDesignPage } from '@canvas-components/print-design';
3
3
  import { encodeBarcodePattern, drawBarcodeToCanvas, exportBarcodeToSvg } from '@canvas-components/barcode';
4
4
  import { drawQrCodeToCanvas, encodeQrCodeMatrix, exportQrCodeToSvg, buildQrCodeContent, getQrCodeMatrix } from '@canvas-components/qrcode';
5
5
  import { drawCanvasChartToCanvas, exportCanvasChartToSvg } from '@canvas-components/chart';
6
6
  import { getIconDefinition } from '@canvas-components/icons';
7
7
  import { roundPreciseNumber, mapInBatches } from '@canvas-components/utils';
8
- import { createElement, useState, useEffect, useMemo, useCallback, useRef } from 'react';
9
- import { ReactFontSizeOutlined, ReactAlignLeftOutlined, ReactAlignCenterOutlined, ReactAlignRightOutlined, ReactMenuOutlined, ReactColumnWidthOutlined, ReactVerticalAlignTopOutlined, ReactVerticalAlignMiddleOutlined, ReactVerticalAlignBottomOutlined, ReactCalendarOutlined, ReactDollarOutlined, ReactNumberOutlined, ReactHighlightOutlined, ReactLineOutlined, ReactTableOutlined, ReactFileImageOutlined, ReactBarcodeOutlined, ReactQrcodeOutlined, ReactBarChartOutlined, ReactInputNumber, ReactButton, ReactColorPicker, ReactPlusOutlined, ReactInput, ReactModal, ReactCollapsePanel, ReactSelect, ReactReloadOutlined, ReactBoldOutlined, ReactItalicOutlined, ReactEyeOutlined, ReactEyeInvisibleOutlined, ReactDeleteOutlined, ReactPopup, ReactBorderLeftOutlined, ReactBorderBottomOutlined, ReactBorderRightOutlined, ReactBorderTopOutlined, ReactBorderInnerOutlined, ReactProgress } from '@canvas-components/react-components';
8
+ import { createElement, useState, useEffect, useRef, useMemo, useCallback } from 'react';
9
+ import { ReactFontSizeOutlined, ReactAlignLeftOutlined, ReactAlignCenterOutlined, ReactAlignRightOutlined, ReactMenuOutlined, ReactColumnWidthOutlined, ReactVerticalAlignTopOutlined, ReactVerticalAlignMiddleOutlined, ReactVerticalAlignBottomOutlined, ReactCalendarOutlined, ReactDollarOutlined, ReactNumberOutlined, ReactHighlightOutlined, ReactLineOutlined, ReactTableOutlined, ReactFileImageOutlined, ReactBarcodeOutlined, ReactQrcodeOutlined, ReactBarChartOutlined, ReactInputNumber, ReactButton, ReactColorPicker, ReactPlusOutlined, ReactInput, ReactModal, ReactRichText, ReactCollapsePanel, ReactSelect, ReactReloadOutlined, ReactBoldOutlined, ReactItalicOutlined, ReactEyeOutlined, ReactEyeInvisibleOutlined, ReactDeleteOutlined, ReactPopup, ReactBorderLeftOutlined, ReactBorderBottomOutlined, ReactBorderRightOutlined, ReactBorderTopOutlined, ReactBorderInnerOutlined, ReactProgress } from '@canvas-components/react-components';
10
10
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
11
  import { BROWSER_PRINT_PAPER_SIZES } from '@canvas-components/print';
12
12
  import { createRoot } from 'react-dom/client';
@@ -53,7 +53,9 @@ function assertNativePluginDependencies(plugins) {
53
53
  function validateTextElement(value) {
54
54
  if (!value || typeof value !== "object") return false;
55
55
  const element = value;
56
- 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(
56
+ 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(
57
+ (value2) => Number.isFinite(value2) && value2 >= 0
58
+ )) && (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(
57
59
  (rule) => rule && Number.isInteger(rule.maxChars) && rule.maxChars >= 1 && Number.isFinite(rule.fontSize) && rule.fontSize > 0
58
60
  ));
59
61
  }
@@ -69,23 +71,36 @@ function graphemes(text) {
69
71
  function drawVerticalText(ctx, text, box, options) {
70
72
  if (box.width <= 0 || box.height <= 0) return;
71
73
  const step = Math.max(1, options.fontSize * options.lineHeight);
72
- const capacity = Math.max(1, Math.floor(box.height / step));
73
74
  const paragraphs = text.split(/\r?\n/).map(graphemes);
74
75
  const columns = paragraphs.flatMap((chars) => {
75
- if (!options.wrap || chars.length <= capacity) return [chars];
76
76
  const chunks = [];
77
- for (let index = 0; index < chars.length; index += capacity)
78
- chunks.push(chars.slice(index, index + capacity));
77
+ let offset = 0;
78
+ do {
79
+ const indent = options.indentMode === "firstLine" ? chunks.length === 0 ? options.indent ?? 0 : 0 : options.indentMode === "hanging" && chunks.length > 0 ? options.indent ?? 0 : 0;
80
+ const capacity = Math.max(1, Math.floor((box.height - indent) / step));
81
+ chunks.push({
82
+ chars: options.wrap === false ? chars.slice(offset) : chars.slice(offset, offset + capacity),
83
+ indent
84
+ });
85
+ offset += capacity;
86
+ } while (options.wrap !== false && offset < chars.length);
79
87
  return chunks;
80
88
  });
81
89
  const visibleCount = Math.max(1, Math.floor(box.width / step));
82
90
  const visible = columns.slice(0, visibleCount);
83
- const overflowed = columns.length > visibleCount || !options.wrap && visible.some((chars) => chars.length > capacity);
91
+ const overflowed = columns.length > visibleCount || !options.wrap && visible.some(
92
+ ({ chars, indent }) => chars.length > Math.max(1, Math.floor((box.height - indent) / step))
93
+ );
84
94
  if (options.ellipsis && overflowed && visible.length) {
85
- const last = [...visible[visible.length - 1]];
95
+ const previous = visible[visible.length - 1];
96
+ const capacity = Math.max(
97
+ 1,
98
+ Math.floor((box.height - previous.indent) / step)
99
+ );
100
+ const last = [...previous.chars];
86
101
  last.length = Math.min(last.length, capacity);
87
102
  last[Math.max(0, Math.min(last.length, capacity) - 1)] = "\u2026";
88
- visible[visible.length - 1] = last;
103
+ visible[visible.length - 1] = { ...previous, chars: last };
89
104
  }
90
105
  const blockWidth = visible.length * step;
91
106
  const left = options.align === "left" ? box.x : options.align === "center" ? box.x + (box.width - blockWidth) / 2 : box.x + box.width - blockWidth;
@@ -95,12 +110,17 @@ function drawVerticalText(ctx, text, box, options) {
95
110
  ctx.clip();
96
111
  ctx.textAlign = "center";
97
112
  ctx.textBaseline = "middle";
98
- visible.forEach((chars, column) => {
113
+ visible.forEach(({ chars, indent }, column) => {
99
114
  const textHeight = chars.length * step;
100
- const offset = options.verticalAlign === "bottom" ? Math.max(0, box.height - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (box.height - textHeight) / 2) : 0;
115
+ const availableHeight = Math.max(0, box.height - indent);
116
+ const offset = options.verticalAlign === "bottom" ? Math.max(0, availableHeight - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (availableHeight - textHeight) / 2) : 0;
101
117
  const centerX = left + blockWidth - (column + 0.5) * step;
102
118
  chars.forEach(
103
- (char, index) => ctx.fillText(char, centerX, box.y + offset + (index + 0.5) * step)
119
+ (char, index) => ctx.fillText(
120
+ char,
121
+ centerX,
122
+ box.y + indent + offset + (index + 0.5) * step
123
+ )
104
124
  );
105
125
  });
106
126
  ctx.restore();
@@ -141,15 +161,16 @@ function getTextLayoutCache(ctx) {
141
161
  }
142
162
  return entry;
143
163
  }
144
- function layoutSpacedText(ctx, text, width, prewrapped = false) {
164
+ function layoutSpacedText(ctx, text, width, prewrapped = false, indent) {
145
165
  const cache = getTextLayoutCache(ctx);
146
- const key = `${prewrapped}:${width}\0${text}`;
166
+ const key = `${prewrapped}:${width}:${indent?.mode ?? "none"}:${indent?.value ?? 0}\0${text}`;
147
167
  let lines = cache.lines.get(key);
148
168
  if (!lines) {
149
169
  lines = prewrapped ? text.split("\n").map((text2) => ({ text: text2, last: true })) : layoutAlignedText(
150
170
  text,
151
171
  width,
152
- (value) => measureSpacedText(ctx, value)
172
+ (value) => measureSpacedText(ctx, value),
173
+ indent
153
174
  );
154
175
  if (cache.lines.size >= 128) cache.lines.clear();
155
176
  cache.lines.set(key, lines);
@@ -203,28 +224,30 @@ function drawSpacedText(ctx, text, x, y) {
203
224
  });
204
225
  ctx.textAlign = align;
205
226
  }
206
- function layoutAlignedText(text, width, measure) {
227
+ function layoutAlignedText(text, width, measure, indent) {
207
228
  return text.split("\n").flatMap((paragraph) => {
208
229
  const lines = [];
209
230
  let line = "";
231
+ const indentation = (index) => indent?.mode === "firstLine" ? index === 0 ? indent.value : 0 : indent?.mode === "hanging" && index > 0 ? indent.value : 0;
210
232
  const tokens = paragraph.match(
211
233
  /[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}]+|\s+|[^\p{Script=Latin}\p{N}\s]+/gu
212
234
  ) ?? [];
213
235
  const pieces = tokens.flatMap(
214
236
  (token) => /^(?:[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}\s]+)$/u.test(
215
237
  token
216
- ) && measure(token) <= width ? [token] : graphemes(token)
238
+ ) && measure(token) <= Math.max(1, width - Math.max(0, indent?.value ?? 0)) ? [token] : graphemes(token)
217
239
  );
218
240
  for (const piece of pieces) {
219
- if (line && measure(line + piece) > width) {
220
- lines.push(line.trimEnd());
241
+ if (line && measure(line + piece) > Math.max(1, width - indentation(lines.length))) {
242
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
221
243
  line = "";
222
244
  }
223
245
  if (line || piece.trim()) line += piece;
224
246
  }
225
- lines.push(line.trimEnd());
247
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
226
248
  return lines.map((value, index) => ({
227
- text: value,
249
+ text: value.text,
250
+ ...indent && indent.mode !== "none" && indent.value > 0 ? { indent: value.indent } : {},
228
251
  last: index === lines.length - 1
229
252
  }));
230
253
  });
@@ -250,13 +273,7 @@ function drawAlignedTextLine(ctx, text, x, y, width, distributed) {
250
273
  });
251
274
  }
252
275
  function resolveTextFontFamily(family) {
253
- const selected = family?.trim();
254
- if (!selected) return PRINT_DESIGN_DEFAULT_FONT_FAMILY;
255
- if (/\bPrintDesignNotoSansSC\b/i.test(selected)) return selected;
256
- if (!/(?:^|,)\s*['"]?Times New Roman['"]?(?:,|$)/i.test(selected) && !/(?:^|,)\s*serif\s*$/i.test(selected))
257
- return selected;
258
- const generic = /,\s*(sans-serif|serif|monospace|cursive|fantasy|system-ui)\s*$/i;
259
- return generic.test(selected) ? selected.replace(generic, ", PrintDesignNotoSansSC, $1") : `${selected}, PrintDesignNotoSansSC`;
276
+ return resolvePrintDesignFontFamily(family);
260
277
  }
261
278
 
262
279
  // src/plugins/text/layout/measure.ts
@@ -274,7 +291,7 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
274
291
  widths = /* @__PURE__ */ new Map();
275
292
  widthCaches.set(ownerDocument, widths);
276
293
  }
277
- const font = `${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
294
+ const font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
278
295
  let span;
279
296
  return {
280
297
  measure: (value) => {
@@ -305,6 +322,12 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
305
322
  dispose: () => span?.remove()
306
323
  };
307
324
  }
325
+ function resolveTextIndentMm(element, fontSizePt) {
326
+ if (!element.indentMode || element.indentMode === "none") return 0;
327
+ const value = Math.max(0, element.indentValue ?? 0);
328
+ if (!Number.isFinite(value)) return 0;
329
+ return element.indentUnit === "char" || !element.indentUnit ? value * fontSizePt * 25.4 / 72 : fromDisplayUnit(value, element.indentUnit);
330
+ }
308
331
 
309
332
  // src/plugins/text/rendering/formatting.ts
310
333
  function resolveTextFontSize(element, text) {
@@ -324,15 +347,15 @@ function ellipsizeTextLine(text, maxWidth, measure) {
324
347
 
325
348
  // src/plugins/text/rendering/draw.ts
326
349
  var loadedFonts = /* @__PURE__ */ new WeakMap();
327
- var DEFAULT_TEXT_BASELINE_CORRECTION_RATIO = 0.05;
328
350
  function prepareTextFont(element, signal) {
329
351
  const family = element.fontFamily?.trim();
330
352
  const source = element.fontSource?.trim();
331
353
  if (!family || !source) return Promise.resolve();
332
354
  if (typeof document === "undefined" || typeof FontFace === "undefined")
333
- return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u52A0\u8F7D\u6253\u5370\u5B57\u4F53\u3002"));
355
+ return Promise.resolve();
334
356
  signal?.throwIfAborted();
335
- const ready = ensureTextFont(element, document);
357
+ const ready = ensureTextFont(element, document).catch(() => {
358
+ });
336
359
  if (!signal) return ready;
337
360
  return new Promise((resolve, reject) => {
338
361
  const onAbort = () => reject(signal.reason);
@@ -399,7 +422,7 @@ var drawTextElement = (element, context) => {
399
422
  const resolvedFontSize = resolveTextFontSize(element, resolvedText);
400
423
  const fontSize = resolvedFontSize * 25.4 * scale / 72;
401
424
  ctx.fillStyle = element.color ?? "#1f2937";
402
- ctx.font = `${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
425
+ ctx.font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
403
426
  const expanded = element.textAlign === "justify" || element.textAlign === "distributed";
404
427
  ctx.textAlign = expanded ? "left" : element.textAlign ?? "left";
405
428
  ctx.textBaseline = "alphabetic";
@@ -414,7 +437,9 @@ var drawTextElement = (element, context) => {
414
437
  align: element.textAlign === "left" || element.textAlign === "center" ? element.textAlign : "right",
415
438
  verticalAlign: element.verticalAlign,
416
439
  wrap: true,
417
- ellipsis: element.heightOverflow === "ellipsis"
440
+ ellipsis: element.heightOverflow === "ellipsis",
441
+ indentMode: element.indentMode,
442
+ indent: resolveTextIndentMm(element, resolvedFontSize) * scale
418
443
  }
419
444
  );
420
445
  return;
@@ -423,19 +448,31 @@ var drawTextElement = (element, context) => {
423
448
  const fontMetrics = ctx.measureText?.("Hg");
424
449
  const ascent = fontMetrics?.fontBoundingBoxAscent ?? fontSize * 0.8;
425
450
  const descent = fontMetrics?.fontBoundingBoxDescent ?? fontSize * 0.2;
426
- const defaultFont = !element.fontFamily || element.fontFamily === PRINT_DESIGN_DEFAULT_FONT_FAMILY;
427
- const regularNoto = element.fontFamily?.startsWith("PrintDesignNotoSansSC") && !/^(?:bold|[6-9]00)$/i.test(element.fontWeight ?? "400");
428
- const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent - (defaultFont || regularNoto ? fontSize * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO : 0);
451
+ const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent;
429
452
  const measure = (text) => measureSpacedText(ctx, text);
430
- let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped);
453
+ const indentPx = resolveTextIndentMm(element, resolvedFontSize) * scale;
454
+ let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped, {
455
+ mode: element.indentMode ?? "none",
456
+ value: indentPx
457
+ });
458
+ if (element.prewrappedIndents)
459
+ lines = lines.map((line, index) => ({
460
+ ...line,
461
+ indent: (element.prewrappedIndents?.[index] ?? 0) * scale
462
+ }));
431
463
  if (element.heightOverflow) {
432
464
  const fit = Math.max(0, Math.floor(height / lineHeight));
433
465
  if (lines.length > fit) {
434
466
  lines = lines.slice(0, fit);
435
467
  if (fit && element.heightOverflow === "ellipsis")
436
468
  lines[fit - 1] = {
437
- text: ellipsizeTextLine(lines[fit - 1].text, width, measure),
438
- last: true
469
+ text: ellipsizeTextLine(
470
+ lines[fit - 1].text,
471
+ Math.max(1, width - (lines[fit - 1].indent ?? 0)),
472
+ measure
473
+ ),
474
+ last: true,
475
+ indent: lines[fit - 1].indent
439
476
  };
440
477
  }
441
478
  ctx.beginPath();
@@ -443,16 +480,22 @@ var drawTextElement = (element, context) => {
443
480
  ctx.clip();
444
481
  }
445
482
  const verticalOffset = element.verticalAlign === "middle" ? Math.max(0, (height - lines.length * lineHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - lines.length * lineHeight) : 0;
446
- const textX = element.textAlign === "center" ? x + width / 2 : element.textAlign === "right" ? x + width : x;
447
483
  lines.forEach((line, index) => {
448
484
  const lineY = y + verticalOffset + index * lineHeight + baselineOffset;
485
+ const lineIndent = Math.min(
486
+ Math.max(0, line.indent ?? 0),
487
+ Math.max(0, width)
488
+ );
489
+ const lineLeft = x + lineIndent;
490
+ const lineWidth = Math.max(0, width - lineIndent);
491
+ const textX = element.textAlign === "center" ? lineLeft + lineWidth / 2 : element.textAlign === "right" ? x + width : lineLeft;
449
492
  if (expanded && (element.textAlign === "distributed" || !line.last)) {
450
493
  drawAlignedTextLine(
451
494
  ctx,
452
495
  line.text,
453
- x,
496
+ lineLeft,
454
497
  lineY,
455
- width,
498
+ lineWidth,
456
499
  element.textAlign === "distributed"
457
500
  );
458
501
  } else {
@@ -463,8 +506,8 @@ var drawTextElement = (element, context) => {
463
506
  Math.max(0, Math.floor(element.underlineCount ?? 0))
464
507
  );
465
508
  if (!count || !line.text) return;
466
- const textWidth = Math.min(width, measure(line.text));
467
- const left = expanded && (element.textAlign === "distributed" || !line.last) ? x : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
509
+ const textWidth = Math.min(lineWidth, measure(line.text));
510
+ const left = expanded && (element.textAlign === "distributed" || !line.last) ? lineLeft : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
468
511
  ctx.save();
469
512
  ctx.strokeStyle = element.underlineColor ?? element.color ?? "#1f2937";
470
513
  ctx.lineWidth = Math.max(0.5, (element.underlineWidth ?? 0.2) * scale);
@@ -515,13 +558,24 @@ function textMarkup(text, element, size = 14, color2 = "#1f2937") {
515
558
  const weight = /^(?:[1-9]00|normal|bold)$/.test(
516
559
  textElement?.fontWeight ?? "400"
517
560
  ) ? textElement?.fontWeight ?? "400" : "400";
561
+ const fontStyle = textElement?.fontStyle === "italic" ? "italic" : "normal";
518
562
  const fontSize = textElement ? resolveTextFontSize(textElement, text) : cssNumber(size, 14);
519
- if (textElement?.textDirection === "vertical")
520
- 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>`;
563
+ if (textElement?.textDirection === "vertical") {
564
+ const indentMm2 = resolveTextIndentMm(textElement, fontSize);
565
+ 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;`;
566
+ const content = indentMm2 > 0 ? text.split("\n").map(
567
+ (paragraph) => `<div style="${paragraphStyle}">${escapeHtml(paragraph) || "<br>"}</div>`
568
+ ).join("") : escapeHtml(text);
569
+ 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>`;
570
+ }
571
+ const indentMm = textElement ? resolveTextIndentMm(textElement, fontSize) : 0;
572
+ 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;` : "" : "";
521
573
  const lines = textElement?.prewrapped ? text.split("\n").map(
522
- (line) => `<div style="white-space:pre;overflow:hidden;flex:none"><span style="${underlineCss(textElement)}">${escapeHtml(line) || "<br>"}</span></div>`
574
+ (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>`
575
+ ).join("") : indentMm > 0 ? text.split("\n").map(
576
+ (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>`
523
577
  ).join("") : `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere"><span style="${textElement ? underlineCss(textElement) : ""}">${escapeHtml(text)}</span></div>`;
524
- 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>`;
578
+ 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>`;
525
579
  }
526
580
  function underlineCss(element) {
527
581
  const count = Math.min(
@@ -556,6 +610,18 @@ function textFontCss(element) {
556
610
  return `@font-face{font-family:${cssFont(element.fontFamily)};src:url("${source}")}`;
557
611
  }
558
612
  var PT_TO_MM = 25.4 / 72;
613
+ function layoutText(element, text, measure) {
614
+ if (element.prewrapped)
615
+ return text.split("\n").map((line, index) => ({
616
+ text: line,
617
+ last: true,
618
+ indent: element.prewrappedIndents?.[index] ?? 0
619
+ }));
620
+ return layoutAlignedText(text, element.width, measure, {
621
+ mode: element.indentMode ?? "none",
622
+ value: resolveTextIndentMm(element, resolveTextFontSize(element, text))
623
+ });
624
+ }
559
625
  function paginateText(element, { data, startPage, startY, top, bottom, pageAt }) {
560
626
  const text = element.dataConfig?.mode === "binding" ? element.text : resolveDesignText(element.text, data);
561
627
  if (element.textDirection === "vertical") {
@@ -583,9 +649,7 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
583
649
  );
584
650
  let lines;
585
651
  try {
586
- lines = layoutAlignedText(text, element.width, measurement.measure).map(
587
- (line) => line.text
588
- );
652
+ lines = layoutText(element, text, measurement.measure);
589
653
  } finally {
590
654
  measurement.dispose();
591
655
  }
@@ -614,7 +678,8 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
614
678
  previewSourceId: element.previewSourceId ?? element.id,
615
679
  y,
616
680
  height,
617
- text: chunk.join("\n"),
681
+ text: chunk.map((line) => line.text).join("\n"),
682
+ ...element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? { prewrappedIndents: chunk.map((line) => line.indent ?? 0) } : {},
618
683
  prewrapped: true,
619
684
  verticalAlign: "top",
620
685
  dataConfig: void 0
@@ -642,7 +707,11 @@ function prewrapText(element) {
642
707
  (value) => estimateTextWidth(value, fontMm)
643
708
  );
644
709
  try {
645
- return layoutAlignedText(element.text, element.width, measurement.measure).map((line) => line.text).join("\n");
710
+ const lines = layoutText(element, element.text, measurement.measure);
711
+ return {
712
+ text: lines.map((line) => line.text).join("\n"),
713
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? lines.map((line) => line.indent ?? 0) : void 0
714
+ };
646
715
  } finally {
647
716
  measurement.dispose();
648
717
  }
@@ -655,12 +724,12 @@ function estimateTextHeight(element) {
655
724
  (value) => estimateTextWidth(value, fontMm)
656
725
  );
657
726
  try {
658
- return layoutAlignedText(element.text, element.width, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
727
+ return layoutText(element, element.text, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
659
728
  } finally {
660
729
  measurement.dispose();
661
730
  }
662
731
  }
663
- function truncateText(element, height, mode) {
732
+ function truncateTextLayout(element, height, mode) {
664
733
  const fontMm = Math.max(1, (element.fontSize ?? 14) * PT_TO_MM);
665
734
  const lineMm = fontMm * (element.lineHeight ?? 1.35);
666
735
  const measurement = createHtmlTextMeasure(
@@ -669,21 +738,21 @@ function truncateText(element, height, mode) {
669
738
  (value) => estimateTextWidth(value, fontMm)
670
739
  );
671
740
  try {
672
- const lines = layoutAlignedText(
673
- element.text,
674
- element.width,
675
- measurement.measure
676
- );
741
+ const lines = layoutText(element, element.text, measurement.measure);
677
742
  const fit = Math.max(0, Math.floor(height / lineMm));
678
- if (lines.length <= fit) return element.text;
679
- const visible = lines.slice(0, fit).map((line) => line.text);
743
+ const visibleLines = lines.slice(0, fit);
744
+ const visible = visibleLines.map((line) => line.text);
680
745
  if (fit && mode === "ellipsis")
681
746
  visible[fit - 1] = ellipsizeTextLine(
682
747
  visible[fit - 1],
683
- element.width,
748
+ Math.max(1, element.width - (lines[fit - 1]?.indent ?? 0)),
684
749
  measurement.measure
685
750
  );
686
- return visible.join("\n");
751
+ return {
752
+ text: visible.join("\n"),
753
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? visibleLines.map((line) => line.indent ?? 0) : void 0,
754
+ overflowed: lines.length > fit
755
+ };
687
756
  } finally {
688
757
  measurement.dispose();
689
758
  }
@@ -713,11 +782,13 @@ function prepareTextPagination(element, data) {
713
782
  };
714
783
  if (element.textDirection === "vertical" || element.overflowPolicy === "split" || element.heightOverflow === "flow" && element.overflowPolicy !== "nextPage")
715
784
  return prepared;
716
- const printable = element.heightOverflow && element.heightOverflow !== "flow" ? {
785
+ const wrapped = element.heightOverflow && element.heightOverflow !== "flow" ? truncateTextLayout(prepared, prepared.height, element.heightOverflow) : prewrapText(prepared);
786
+ return {
717
787
  ...prepared,
718
- text: truncateText(prepared, prepared.height, element.heightOverflow)
719
- } : prepared;
720
- return { ...printable, text: prewrapText(printable), prewrapped: true };
788
+ text: wrapped.text,
789
+ ...wrapped.indents ? { prewrappedIndents: wrapped.indents } : {},
790
+ prewrapped: true
791
+ };
721
792
  }
722
793
  function measureTextFlowHeight(element, data) {
723
794
  if (element.heightOverflow && element.heightOverflow !== "flow")
@@ -726,7 +797,13 @@ function measureTextFlowHeight(element, data) {
726
797
  return Math.max(prepared.height, estimateTextHeight(prepared));
727
798
  }
728
799
  function truncateTextOverflow(element, height, mode) {
729
- return { ...element, text: truncateText(element, height, mode) };
800
+ const truncated = truncateTextLayout(element, height, mode);
801
+ return {
802
+ ...element,
803
+ text: truncated.text,
804
+ prewrapped: true,
805
+ ...truncated.indents ? { prewrappedIndents: truncated.indents } : {}
806
+ };
730
807
  }
731
808
  function registeredFieldBindingInfo(element, fields) {
732
809
  const config = getPrintDesignElementDataConfig(element, fields);
@@ -799,14 +876,14 @@ function resolveTextFontSizeValue(value, defaultUnit = "mm") {
799
876
  // src/plugins/text/data/binding.ts
800
877
  function getTextBindingInfo(element) {
801
878
  const content = registeredFieldBindingInfo(element, textDataFields);
802
- const paths = [
879
+ const paths2 = [
803
880
  ...content.paths,
804
881
  element.colorMode === "binding" ? element.colorPath : void 0,
805
882
  element.fontSizeMode === "binding" ? element.fontSizePath : void 0
806
883
  ].filter((path) => !!path?.trim());
807
884
  return {
808
885
  bound: content.bound || element.colorMode === "binding" || element.fontSizeMode === "binding",
809
- paths
886
+ paths: paths2
810
887
  };
811
888
  }
812
889
  function missingExpressionPath(expression, data) {
@@ -866,7 +943,7 @@ function resolveTextData(element, data) {
866
943
  // src/plugins/text/native.ts
867
944
  var textNativePlugin = defineNativePlugin(
868
945
  "text",
869
- "0.1.34",
946
+ "0.1.38",
870
947
  definePrintDesignPluginRenderer({
871
948
  type: "text",
872
949
  dataFields: textDataFields,
@@ -889,6 +966,268 @@ var textNativePlugin = defineNativePlugin(
889
966
  inlineTextEditor: textInlineEditor
890
967
  })
891
968
  );
969
+
970
+ // src/plugins/rich-text/model.ts
971
+ function validateRichTextElement(value) {
972
+ if (!value || typeof value !== "object") return false;
973
+ const element = value;
974
+ return element.type === "richText" && (element.dataConfig === void 0 || element.dataConfig.mode === "static") && Array.isArray(element.runs) && element.runs.length <= 2e3 && element.runs.reduce(
975
+ (length, run) => length + (typeof run?.text === "string" ? run.text.length : 0),
976
+ 0
977
+ ) <= 1e5 && element.runs.every(
978
+ (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(
979
+ (key) => ["fontFamily", "fontSize", "fontWeight", "fontStyle", "color"].includes(key)
980
+ ) && (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)))
981
+ ) && (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(
982
+ (indent) => Number.isFinite(indent) && indent >= 0
983
+ ));
984
+ }
985
+ function richTextIndentMm(element) {
986
+ if (!element.indentMode || element.indentMode === "none") return 0;
987
+ const value = Math.max(0, element.indentValue ?? 0);
988
+ return element.indentUnit === "char" || !element.indentUnit ? value * (element.fontSize ?? 14) * 25.4 / 72 : fromDisplayUnit(value, element.indentUnit);
989
+ }
990
+ function richTextGraphemes(text) {
991
+ const Segmenter = Intl.Segmenter;
992
+ return Segmenter ? Array.from(
993
+ new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
994
+ (part) => part.segment
995
+ ) : Array.from(text);
996
+ }
997
+
998
+ // src/plugins/rich-text/rendering.ts
999
+ function runStyle(element, run) {
1000
+ return {
1001
+ fontFamily: resolvePrintDesignFontFamily(
1002
+ run.style?.fontFamily ?? element.fontFamily
1003
+ ),
1004
+ fontSize: run.style?.fontSize ?? element.fontSize ?? 14,
1005
+ fontWeight: run.style?.fontWeight ?? element.fontWeight ?? "400",
1006
+ fontStyle: run.style?.fontStyle ?? element.fontStyle ?? "normal",
1007
+ color: run.style?.color ?? element.color ?? "#1f2937"
1008
+ };
1009
+ }
1010
+ function layoutRichTextLines(element, width, scale, measure) {
1011
+ const indent = richTextIndentMm(element) * scale;
1012
+ const lineHeight = element.lineHeight ?? 1.35;
1013
+ const lines = [];
1014
+ let paragraphLine = 0;
1015
+ const addLine = () => {
1016
+ const inset = element.prewrapped ? (element.prewrappedIndents?.[lines.length] ?? 0) * scale : element.indentMode === "firstLine" && paragraphLine === 0 || element.indentMode === "hanging" && paragraphLine > 0 ? indent : 0;
1017
+ lines.push({
1018
+ chars: [],
1019
+ width: 0,
1020
+ indent: inset,
1021
+ height: (element.fontSize ?? 14) * 25.4 / 72 * scale * lineHeight
1022
+ });
1023
+ };
1024
+ addLine();
1025
+ for (const run of element.runs) {
1026
+ const style = runStyle(element, run);
1027
+ const fontSize = style.fontSize * 25.4 / 72 * scale;
1028
+ for (const char of richTextGraphemes(run.text.replace(/\r\n?/g, "\n"))) {
1029
+ if (char === "\n") {
1030
+ paragraphLine = 0;
1031
+ addLine();
1032
+ continue;
1033
+ }
1034
+ const charWidth = measure(char, style, fontSize);
1035
+ let line = lines[lines.length - 1];
1036
+ if (!element.prewrapped && line.chars.length && line.width + charWidth > Math.max(1, width - line.indent)) {
1037
+ paragraphLine++;
1038
+ addLine();
1039
+ line = lines[lines.length - 1];
1040
+ }
1041
+ line.chars.push({ text: char, width: charWidth, style });
1042
+ line.width += charWidth;
1043
+ line.height = Math.max(line.height, fontSize * lineHeight);
1044
+ }
1045
+ }
1046
+ return lines;
1047
+ }
1048
+ function drawRichTextElement(element, { ctx, scale, x, y, width, height }) {
1049
+ const lineHeight = element.lineHeight ?? 1.35;
1050
+ const lines = layoutRichTextLines(
1051
+ element,
1052
+ width,
1053
+ scale,
1054
+ (char, style, fontSize) => {
1055
+ ctx.font = `${style.fontStyle} ${style.fontWeight} ${fontSize}px ${style.fontFamily}`;
1056
+ return ctx.measureText(char).width;
1057
+ }
1058
+ );
1059
+ const totalHeight = lines.reduce((sum, line) => sum + line.height, 0);
1060
+ let top = y + (element.verticalAlign === "middle" ? Math.max(0, (height - totalHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - totalHeight) : 0);
1061
+ ctx.save();
1062
+ ctx.beginPath();
1063
+ ctx.rect(x, y, width, height);
1064
+ ctx.clip();
1065
+ ctx.textAlign = "left";
1066
+ ctx.textBaseline = "alphabetic";
1067
+ for (const line of lines) {
1068
+ let left = x + line.indent;
1069
+ const available = Math.max(0, width - line.indent);
1070
+ if (element.textAlign === "center") left += (available - line.width) / 2;
1071
+ if (element.textAlign === "right") left += available - line.width;
1072
+ for (const char of line.chars) {
1073
+ const fontSize = char.style.fontSize * 25.4 / 72 * scale;
1074
+ ctx.font = `${char.style.fontStyle} ${char.style.fontWeight} ${fontSize}px ${char.style.fontFamily}`;
1075
+ ctx.fillStyle = char.style.color;
1076
+ ctx.fillText(
1077
+ char.text,
1078
+ left,
1079
+ top + (line.height - fontSize * lineHeight) / 2 + fontSize
1080
+ );
1081
+ left += char.width;
1082
+ }
1083
+ top += line.height;
1084
+ }
1085
+ ctx.restore();
1086
+ }
1087
+ function renderRichTextHtml(element) {
1088
+ const baseSize = cssNumber(element.fontSize, 14);
1089
+ const indent = richTextIndentMm(element);
1090
+ const paragraphs = [""];
1091
+ for (const run of element.runs) {
1092
+ const style = runStyle(element, run);
1093
+ 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")}`;
1094
+ const chunks = run.text.replace(/\r\n?/g, "\n").split("\n");
1095
+ chunks.forEach((chunk, index) => {
1096
+ if (index) paragraphs.push("");
1097
+ paragraphs[paragraphs.length - 1] += `<span style="${css}">${escapeHtml(chunk)}</span>`;
1098
+ });
1099
+ }
1100
+ 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;` : "";
1101
+ const body = paragraphs.map(
1102
+ (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>`
1103
+ ).join("");
1104
+ return renderPrintDesignHtmlFrame(
1105
+ element,
1106
+ `<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>`
1107
+ );
1108
+ }
1109
+
1110
+ // src/plugins/rich-text/pagination.ts
1111
+ function measureLines(element) {
1112
+ const canvas = typeof document !== "undefined" ? document.createElement("canvas") : null;
1113
+ const context = canvas?.getContext("2d");
1114
+ return layoutRichTextLines(element, element.width, 1, (text, style, size) => {
1115
+ if (context) {
1116
+ context.font = `${style.fontStyle} ${style.fontWeight} ${size}px ${style.fontFamily}`;
1117
+ return context.measureText(text).width;
1118
+ }
1119
+ return size * (/[^\p{ASCII}]/u.test(text) ? 1 : 0.55);
1120
+ });
1121
+ }
1122
+ function linesToRuns(lines) {
1123
+ const result = [];
1124
+ for (const [index, line] of lines.entries()) {
1125
+ if (index) result.push({ text: "\n" });
1126
+ for (const char of line.chars) {
1127
+ const previous = result[result.length - 1];
1128
+ const style = char.style;
1129
+ if (previous && JSON.stringify(previous.style) === JSON.stringify(style))
1130
+ previous.text += char.text;
1131
+ else result.push({ text: char.text, style });
1132
+ }
1133
+ }
1134
+ return result;
1135
+ }
1136
+ function truncateRichTextOverflow(element, height, mode) {
1137
+ const lines = measureLines(element);
1138
+ const visible = [];
1139
+ let used = 0;
1140
+ for (const line of lines) {
1141
+ if (visible.length && used + line.height > height) break;
1142
+ visible.push({ ...line, chars: [...line.chars] });
1143
+ used += line.height;
1144
+ }
1145
+ if (mode === "ellipsis" && visible.length < lines.length && visible.length) {
1146
+ const last = visible[visible.length - 1];
1147
+ const style = last.chars[last.chars.length - 1]?.style ?? {
1148
+ fontFamily: element.fontFamily ?? "Arial, sans-serif",
1149
+ fontSize: element.fontSize ?? 14,
1150
+ fontWeight: element.fontWeight ?? "400",
1151
+ fontStyle: element.fontStyle ?? "normal",
1152
+ color: element.color ?? "#1f2937"
1153
+ };
1154
+ const ellipsisWidth = style.fontSize * 25.4 / 72;
1155
+ while (last.chars.length && last.width + ellipsisWidth > element.width - last.indent) {
1156
+ last.width -= last.chars.pop().width;
1157
+ }
1158
+ last.chars.push({ text: "\u2026", style, width: ellipsisWidth });
1159
+ last.width += ellipsisWidth;
1160
+ }
1161
+ return {
1162
+ ...element,
1163
+ runs: linesToRuns(visible),
1164
+ prewrapped: true,
1165
+ prewrappedIndents: visible.map((line) => line.indent),
1166
+ verticalAlign: "top"
1167
+ };
1168
+ }
1169
+ function paginateRichText(element, context) {
1170
+ const lines = measureLines(element);
1171
+ let pageIndex = context.startPage;
1172
+ let y = context.startY;
1173
+ let offset = 0;
1174
+ do {
1175
+ const remaining = () => context.bottom - y;
1176
+ if (remaining() < (lines[offset]?.height ?? 0) && y > context.top) {
1177
+ pageIndex++;
1178
+ y = context.top;
1179
+ }
1180
+ const chunk = [];
1181
+ let height = 0;
1182
+ while (offset < lines.length && (!chunk.length || height + lines[offset].height <= remaining())) {
1183
+ chunk.push(lines[offset]);
1184
+ height += lines[offset].height;
1185
+ offset++;
1186
+ }
1187
+ const continues = offset < lines.length;
1188
+ const finalHeight = continues ? Math.max(0, remaining()) : Math.max(height, element.height);
1189
+ context.pageAt(pageIndex).elements.push({
1190
+ ...element,
1191
+ id: `${element.id}:flow:${pageIndex}`,
1192
+ previewSourceId: element.previewSourceId ?? element.id,
1193
+ y,
1194
+ height: Math.min(Math.max(0, remaining()), finalHeight),
1195
+ runs: linesToRuns(chunk),
1196
+ prewrapped: true,
1197
+ prewrappedIndents: chunk.map((line) => line.indent),
1198
+ verticalAlign: "top"
1199
+ });
1200
+ y += Math.min(Math.max(0, remaining()), finalHeight);
1201
+ if (continues) {
1202
+ pageIndex++;
1203
+ y = context.top;
1204
+ }
1205
+ } while (offset < lines.length);
1206
+ return {
1207
+ logicalEnd: pageIndex * (context.bottom - context.top) + (y - context.top)
1208
+ };
1209
+ }
1210
+ function measureRichTextFlowHeight(element) {
1211
+ return Math.max(
1212
+ element.height,
1213
+ measureLines(element).reduce((height, line) => height + line.height, 0)
1214
+ );
1215
+ }
1216
+
1217
+ // src/plugins/rich-text/native.ts
1218
+ var richTextNativePlugin = defineNativePlugin(
1219
+ "richText",
1220
+ "0.1.1",
1221
+ definePrintDesignPluginRenderer({
1222
+ type: "richText",
1223
+ validate: validateRichTextElement,
1224
+ drawCanvas: drawRichTextElement,
1225
+ renderHtml: (element) => renderRichTextHtml(element),
1226
+ paginate: paginateRichText,
1227
+ measureFlowHeight: measureRichTextFlowHeight,
1228
+ truncateOverflow: truncateRichTextOverflow
1229
+ })
1230
+ );
892
1231
  var drawListElement = (element, context) => {
893
1232
  const { ctx, x, y, width, height, scale, data } = context;
894
1233
  const row = Math.max(1, element.rowHeight ?? 8) * scale;
@@ -989,8 +1328,8 @@ function itemPaths(text) {
989
1328
  return [...text.matchAll(LIST_EXPRESSION)].map((match) => match[1]);
990
1329
  }
991
1330
  function listBindingInfo(element) {
992
- const paths = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
993
- return { bound: paths.length > 0, paths };
1331
+ const paths2 = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
1332
+ return { bound: paths2.length > 0, paths: paths2 };
994
1333
  }
995
1334
  function validateListTemplateData(element, data) {
996
1335
  if (!data) return [];
@@ -1105,9 +1444,9 @@ function dateTimeBindingInfo(element) {
1105
1444
  }
1106
1445
  function validateDateTimeTemplateData(element, data) {
1107
1446
  if (!data) return [];
1108
- const { bound, paths } = dateTimeBindingInfo(element);
1447
+ const { bound, paths: paths2 } = dateTimeBindingInfo(element);
1109
1448
  if (!bound) return [];
1110
- const expression = paths[0];
1449
+ const expression = paths2[0];
1111
1450
  if (!expression) return ["\u672A\u914D\u7F6E\u65E5\u671F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
1112
1451
  const value = resolvePrintDesignBinding(data, expression);
1113
1452
  const text = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
@@ -1234,9 +1573,9 @@ function moneyUpperBindingInfo(element) {
1234
1573
  }
1235
1574
  function validateMoneyUpperTemplateData(element, data) {
1236
1575
  if (!data) return [];
1237
- const { bound, paths } = moneyUpperBindingInfo(element);
1576
+ const { bound, paths: paths2 } = moneyUpperBindingInfo(element);
1238
1577
  if (!bound) return [];
1239
- const expression = paths[0];
1578
+ const expression = paths2[0];
1240
1579
  if (!expression) return ["\u672A\u914D\u7F6E\u91D1\u989D\u7ED1\u5B9A\u5B57\u6BB5"];
1241
1580
  const value = resolvePrintDesignBinding(data, expression);
1242
1581
  const numeric2 = typeof value === "number" || typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
@@ -1316,9 +1655,9 @@ function pageNumberBindingInfo(element) {
1316
1655
  }
1317
1656
  function validatePageNumberTemplateData(element, data) {
1318
1657
  if (!data) return [];
1319
- const { bound, paths } = pageNumberBindingInfo(element);
1658
+ const { bound, paths: paths2 } = pageNumberBindingInfo(element);
1320
1659
  if (!bound) return [];
1321
- const expression = paths[0];
1660
+ const expression = paths2[0];
1322
1661
  if (!expression) return ["\u672A\u914D\u7F6E\u9875\u7801\u524D\u7F00\u7ED1\u5B9A\u5B57\u6BB5"];
1323
1662
  const value = resolvePrintDesignBinding(data, expression);
1324
1663
  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`];
@@ -1420,23 +1759,18 @@ function renderWatermarkHtml(element, data, preciseClip = false) {
1420
1759
  const text = escapeHtml(
1421
1760
  element.dataConfig ? element.text : resolveDesignText(element.text, data)
1422
1761
  );
1423
- if (!preciseClip) {
1424
- const fontSize2 = cssNumber(element.fontSize, 24);
1425
- 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>`;
1426
- const content2 = `<div class="pd-watermark" style="grid-template-columns:repeat(${columns},1fr);grid-template-rows:repeat(${rows},1fr)">${cell.repeat(rows * columns)}</div>`;
1427
- return renderPrintDesignHtmlFrame(element, content2);
1428
- }
1429
1762
  const width = Math.max(0, element.width);
1430
1763
  const height = Math.max(0, element.height);
1431
1764
  const fontSize = cssNumber(element.fontSize, 24) * 25.4 / 72;
1432
1765
  const color2 = cssColor(element.color, "#94a3b8");
1433
1766
  const rotation = cssNumber(element.textRotation, 45);
1767
+ const baselineFactor = preciseClip ? 0.3 : 0.39;
1434
1768
  const cells = Array.from({ length: rows * columns }, (_, index) => {
1435
1769
  const centerX = (index % columns + 0.5) * (width / columns);
1436
1770
  const centerY = (Math.floor(index / columns) + 0.5) * (height / rows);
1437
- return `<text x="${centerX}" y="${centerY + fontSize * 0.3}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1771
+ return `<text x="${centerX}" y="${centerY + fontSize * baselineFactor}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1438
1772
  }).join("");
1439
- 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>`;
1773
+ 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>`;
1440
1774
  return renderPrintDesignHtmlFrame(element, content);
1441
1775
  }
1442
1776
 
@@ -1461,9 +1795,9 @@ function watermarkBindingInfo(element) {
1461
1795
  }
1462
1796
  function validateWatermarkTemplateData(element, data) {
1463
1797
  if (!data) return [];
1464
- const { bound, paths } = watermarkBindingInfo(element);
1798
+ const { bound, paths: paths2 } = watermarkBindingInfo(element);
1465
1799
  if (!bound) return [];
1466
- const expression = paths[0];
1800
+ const expression = paths2[0];
1467
1801
  if (!expression) return ["\u672A\u914D\u7F6E\u6C34\u5370\u6587\u5B57\u7ED1\u5B9A\u5B57\u6BB5"];
1468
1802
  for (const match of expression.matchAll(
1469
1803
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -1478,7 +1812,7 @@ function validateWatermarkTemplateData(element, data) {
1478
1812
  // src/plugins/watermark/native.ts
1479
1813
  var watermarkNativePlugin = defineNativePlugin(
1480
1814
  "watermark",
1481
- "0.1.9",
1815
+ "0.1.10",
1482
1816
  definePrintDesignPluginRenderer({
1483
1817
  type: "watermark",
1484
1818
  validate: validateWatermarkElement,
@@ -1498,8 +1832,7 @@ var watermarkNativePlugin = defineNativePlugin(
1498
1832
  physical && physical.y + physical.height > context.page.height
1499
1833
  )
1500
1834
  );
1501
- },
1502
- 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}"
1835
+ }
1503
1836
  }),
1504
1837
  [{ id: "builtin.text", minVersion: "0.1.16" }]
1505
1838
  );
@@ -4151,8 +4484,8 @@ function labelPaths(element) {
4151
4484
  );
4152
4485
  }
4153
4486
  function connectorBindingInfo(element) {
4154
- const paths = [...new Set(labelPaths(element))];
4155
- return { bound: paths.length > 0, paths };
4487
+ const paths2 = [...new Set(labelPaths(element))];
4488
+ return { bound: paths2.length > 0, paths: paths2 };
4156
4489
  }
4157
4490
  function validateConnectorTemplateData(element, data) {
4158
4491
  if (!data) return [];
@@ -4963,13 +5296,13 @@ function gridMarkup(element, data) {
4963
5296
 
4964
5297
  // src/plugins/grid/data/binding.ts
4965
5298
  function getGridBindingInfo(element) {
4966
- const paths = [
5299
+ const paths2 = [
4967
5300
  element.contentPath,
4968
5301
  element.loopsPath,
4969
5302
  element.columnLoopsPath,
4970
5303
  ...(element.cells ?? []).filter((cell) => cell.contentMode === "binding").map((cell) => cell.contentPath)
4971
5304
  ].map((path) => path?.trim()).filter((path) => !!path);
4972
- return { bound: paths.length > 0, paths };
5305
+ return { bound: paths2.length > 0, paths: paths2 };
4973
5306
  }
4974
5307
  function validateGridTemplateData(element, data) {
4975
5308
  if (!data) return [];
@@ -6217,9 +6550,9 @@ function clockBindingInfo(element) {
6217
6550
  }
6218
6551
  function validateClockTemplateData(element, data) {
6219
6552
  if (!data) return [];
6220
- const { bound, paths } = clockBindingInfo(element);
6553
+ const { bound, paths: paths2 } = clockBindingInfo(element);
6221
6554
  if (!bound) return [];
6222
- const expression = paths[0];
6555
+ const expression = paths2[0];
6223
6556
  if (!expression) return ["\u672A\u914D\u7F6E\u65F6\u949F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
6224
6557
  for (const match of expression.matchAll(
6225
6558
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6458,9 +6791,9 @@ function imageBindingInfo(element) {
6458
6791
  }
6459
6792
  function validateImageTemplateData(element, data) {
6460
6793
  if (!data) return [];
6461
- const { bound, paths } = imageBindingInfo(element);
6794
+ const { bound, paths: paths2 } = imageBindingInfo(element);
6462
6795
  if (!bound) return [];
6463
- const expression = paths[0];
6796
+ const expression = paths2[0];
6464
6797
  if (!expression) return ["\u672A\u914D\u7F6E\u56FE\u7247\u5730\u5740\u7ED1\u5B9A\u5B57\u6BB5"];
6465
6798
  for (const match of expression.matchAll(
6466
6799
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6814,9 +7147,9 @@ function barcodeBindingInfo(element) {
6814
7147
  }
6815
7148
  function validateBarcodeTemplateData(element, data) {
6816
7149
  if (!data) return [];
6817
- const { bound, paths } = barcodeBindingInfo(element);
7150
+ const { bound, paths: paths2 } = barcodeBindingInfo(element);
6818
7151
  if (!bound) return [];
6819
- const expression = paths[0];
7152
+ const expression = paths2[0];
6820
7153
  if (!expression) return ["\u672A\u914D\u7F6E\u6761\u5F62\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6821
7154
  for (const match of expression.matchAll(
6822
7155
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6916,9 +7249,9 @@ function qrcodeBindingInfo(element) {
6916
7249
  }
6917
7250
  function validateQrCodeTemplateData(element, data) {
6918
7251
  if (!data) return [];
6919
- const { bound, paths } = qrcodeBindingInfo(element);
7252
+ const { bound, paths: paths2 } = qrcodeBindingInfo(element);
6920
7253
  if (!bound) return [];
6921
- const expression = paths[0];
7254
+ const expression = paths2[0];
6922
7255
  if (!expression) return ["\u672A\u914D\u7F6E\u4E8C\u7EF4\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6923
7256
  for (const match of expression.matchAll(
6924
7257
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -7844,7 +8177,7 @@ function resolveDiagonalCount(count) {
7844
8177
  function diagonalCellLayout(direction, count, corner) {
7845
8178
  const lineCount = resolveDiagonalCount(count);
7846
8179
  const activeCorner = lineCount === 1 ? direction === "down" ? "top-left" : "bottom-left" : corner ?? (direction === "down" ? "top-left" : "bottom-left");
7847
- const paths = {
8180
+ const paths2 = {
7848
8181
  "top-left": [
7849
8182
  [0, 0],
7850
8183
  [1, 0],
@@ -7870,7 +8203,7 @@ function diagonalCellLayout(direction, count, corner) {
7870
8203
  [0, 1]
7871
8204
  ]
7872
8205
  };
7873
- const [apex, first, bend, last] = paths[activeCorner];
8206
+ const [apex, first, bend, last] = paths2[activeCorner];
7874
8207
  const farPoint = (position) => position <= 1 ? [
7875
8208
  first[0] + (bend[0] - first[0]) * position,
7876
8209
  first[1] + (bend[1] - first[1]) * position
@@ -9406,6 +9739,10 @@ function hitTableColumnBoundary(element, point, scale, includeSelector = false,
9406
9739
  }
9407
9740
  return nearest;
9408
9741
  }
9742
+ function boundaryHitRadius(height, scale, selector) {
9743
+ const radius = 5 / scale;
9744
+ return selector || height * scale >= 12 ? radius : Math.min(radius, height / 4);
9745
+ }
9409
9746
  function unmergedBoundarySegments(element, rowIndex, merges) {
9410
9747
  if (!merges.length) return [{ x: element.x + 3, width: element.width - 6 }];
9411
9748
  const columns = tableLeafColumns(
@@ -9447,11 +9784,25 @@ function tableHeaderResizeLayout(element, scale, data = {}) {
9447
9784
  for (let index = 0; index < depth; index++) {
9448
9785
  const edge = element.y + (index + 1) * height;
9449
9786
  if (edge > visibleBottom + 1e-9) break;
9450
- const shared = { rowIndex: index, edge, height, y: edge - 5 / scale };
9451
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9787
+ const shared = { rowIndex: index, edge, height };
9788
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9789
+ regions.push({
9790
+ ...shared,
9791
+ x: element.x - 6,
9792
+ width: 6,
9793
+ selector: true,
9794
+ radius: selectorRadius,
9795
+ y: edge - selectorRadius
9796
+ });
9452
9797
  if (edge < visibleBottom - 1e-9 && element.width > 6)
9453
9798
  for (const segment of unmergedBoundarySegments(element, index, headers))
9454
- regions.push({ ...shared, ...segment, selector: false });
9799
+ regions.push({
9800
+ ...shared,
9801
+ ...segment,
9802
+ selector: false,
9803
+ radius: boundaryHitRadius(height, scale, false),
9804
+ y: edge - boundaryHitRadius(height, scale, false)
9805
+ });
9455
9806
  }
9456
9807
  return regions;
9457
9808
  }
@@ -9466,7 +9817,7 @@ function hitTableHeaderBoundary(element, point, scale, data = {}) {
9466
9817
  -(element.rotation ?? 0) * Math.PI / 180
9467
9818
  );
9468
9819
  const region = tableHeaderResizeLayout(element, scale, data).filter(
9469
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9820
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9470
9821
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9471
9822
  return region && {
9472
9823
  elementId: element.id,
@@ -9498,13 +9849,26 @@ function tableRowResizeLayout(element, scale, data = {}) {
9498
9849
  const shared = {
9499
9850
  rowIndex: index + (element.sourceRowOffset ?? 0),
9500
9851
  edge: boundary,
9501
- height,
9502
- y: boundary - 5 / scale
9852
+ height
9503
9853
  };
9504
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9854
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9855
+ regions.push({
9856
+ ...shared,
9857
+ x: element.x - 6,
9858
+ width: 6,
9859
+ selector: true,
9860
+ radius: selectorRadius,
9861
+ y: boundary - selectorRadius
9862
+ });
9505
9863
  if (index < heights.length - 1 && element.width > 6)
9506
9864
  for (const segment of unmergedBoundarySegments(element, index, cells))
9507
- regions.push({ ...shared, ...segment, selector: false });
9865
+ regions.push({
9866
+ ...shared,
9867
+ ...segment,
9868
+ selector: false,
9869
+ radius: boundaryHitRadius(height, scale, false),
9870
+ y: boundary - boundaryHitRadius(height, scale, false)
9871
+ });
9508
9872
  }
9509
9873
  return regions;
9510
9874
  }
@@ -9519,7 +9883,7 @@ function hitTableRowBoundary(element, point, scale, data = {}) {
9519
9883
  -(element.rotation ?? 0) * Math.PI / 180
9520
9884
  );
9521
9885
  const region = tableRowResizeLayout(element, scale, data).filter(
9522
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9886
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9523
9887
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9524
9888
  return region && {
9525
9889
  elementId: element.id,
@@ -9654,12 +10018,12 @@ function tableDebugRegions(table2, context, options = {}) {
9654
10018
  ...owner,
9655
10019
  id: `${area}-resize:${index}`,
9656
10020
  category: "resize",
9657
- label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB15px${hit ? " \u547D\u4E2D" : ""}`,
10021
+ 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" : ""}`,
9658
10022
  bounds: {
9659
10023
  x: region.x,
9660
10024
  y: region.y,
9661
10025
  width: region.width,
9662
- height: 10 / scale
10026
+ height: region.radius * 2
9663
10027
  },
9664
10028
  interactive: true,
9665
10029
  hit,
@@ -10649,11 +11013,227 @@ function emptyTableRow(element) {
10649
11013
  );
10650
11014
  }
10651
11015
 
11016
+ // src/plugins/table/data/packed-report-defaults.ts
11017
+ function fillPackedReportDefaults(columns, rows, current2) {
11018
+ const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
11019
+ const keys2 = visible.map(
11020
+ (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
11021
+ );
11022
+ const repeats = /* @__PURE__ */ new Map();
11023
+ keys2.forEach((key) => {
11024
+ const match = /^(.+?)([1-9]\d*)$/.exec(key);
11025
+ if (!match) return;
11026
+ const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
11027
+ slots.add(Number(match[2]));
11028
+ repeats.set(match[1], slots);
11029
+ });
11030
+ const series = [...repeats].filter(
11031
+ ([, slots]) => slots.has(1) && slots.has(2)
11032
+ );
11033
+ const itemsPerRow = Math.max(
11034
+ 1,
11035
+ ...series.map(([, slots]) => Math.max(...slots))
11036
+ );
11037
+ const sample = rows.find((row) => row && typeof row === "object") ?? {};
11038
+ const groupFields = {};
11039
+ keys2.forEach((key, index) => {
11040
+ const repeated = series.some(
11041
+ ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
11042
+ );
11043
+ if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
11044
+ groupFields[key] = key in sample ? key : "";
11045
+ }
11046
+ });
11047
+ const itemFields = series.map(([prefix]) => ({
11048
+ prefix,
11049
+ .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
11050
+ }));
11051
+ const totals = {};
11052
+ visible.forEach((column, index) => {
11053
+ const key = keys2[index];
11054
+ const summary = column.summary;
11055
+ const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
11056
+ if (key && summary && type === "sum") {
11057
+ const prefix = series.find(
11058
+ ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
11059
+ )?.[0];
11060
+ totals[key] = {
11061
+ sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
11062
+ ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
11063
+ };
11064
+ }
11065
+ });
11066
+ const subtotalLabelKey = keys2.find(
11067
+ (key) => key && !(key in totals) && !(key in groupFields)
11068
+ );
11069
+ const totalLabelKey = keys2.find((key) => key && !(key in totals));
11070
+ const subtotal = { ...totals };
11071
+ if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
11072
+ if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
11073
+ return {
11074
+ groupBy: current2?.groupBy ?? [],
11075
+ itemsPerRow: current2?.itemsPerRow ?? itemsPerRow,
11076
+ groupFields: Object.keys(current2?.groupFields ?? {}).length ? current2.groupFields : groupFields,
11077
+ groupMergeColumns: Object.keys(current2?.groupFields ?? {}).length ? current2.groupMergeColumns : keys2.flatMap(
11078
+ (key, index) => key && key in groupFields ? [index] : []
11079
+ ),
11080
+ itemFields: current2?.itemFields?.length ? current2.itemFields : itemFields,
11081
+ subtotal: Object.keys(current2?.subtotal ?? {}).length ? current2.subtotal : subtotal,
11082
+ subtotalMerges: current2?.subtotalMerges ?? [],
11083
+ total: Object.keys(current2?.total ?? {}).length ? current2.total : totals,
11084
+ totalMerges: current2?.totalMerges ?? [],
11085
+ appendRows: current2?.appendRows ?? [],
11086
+ ...current2?.footerElementIds ? { footerElementIds: current2.footerElementIds } : {}
11087
+ };
11088
+ }
11089
+
11090
+ // src/plugins/table/interaction/agent-commands.ts
11091
+ function object(input) {
11092
+ if (!input || typeof input !== "object" || Array.isArray(input))
11093
+ throw new TypeError("\u8868\u683C\u547D\u4EE4\u53C2\u6570\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
11094
+ return input;
11095
+ }
11096
+ function safePart(value) {
11097
+ return !!value.trim() && !value.split(/[.[\]]/).some((part) => ["__proto__", "prototype", "constructor"].includes(part));
11098
+ }
11099
+ function fieldPath(input, label) {
11100
+ if (typeof input === "string" && safePart(input)) return input.trim();
11101
+ if (Array.isArray(input) && input.length > 0 && input.every(
11102
+ (part) => typeof part === "string" && safePart(part) || typeof part === "number" && Number.isInteger(part) && part >= 0
11103
+ ))
11104
+ return input;
11105
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D\u6216\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11106
+ }
11107
+ function paths(input, label) {
11108
+ if (input === void 0) return [];
11109
+ if (!Array.isArray(input)) throw new TypeError(`${label} \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
11110
+ return input.map((value) => fieldPath(value, label));
11111
+ }
11112
+ function stringPaths(input, label) {
11113
+ if (!Array.isArray(input) || !input.length)
11114
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11115
+ return input.map((value) => {
11116
+ if (typeof value !== "string" || !safePart(value))
11117
+ throw new TypeError(`${label} \u4E2D\u7684\u5B57\u6BB5\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`);
11118
+ return value.trim();
11119
+ });
11120
+ }
11121
+ function configureTableAutoMerge(element, rawPayload) {
11122
+ const payload = object(rawPayload);
11123
+ if (payload.enabled === false) return { ...element, mergeCell: void 0 };
11124
+ const rowKeys = paths(payload.rowKeys, "rowKeys");
11125
+ const rowColumns = paths(payload.rowColumns, "rowColumns");
11126
+ const columnKeys = paths(payload.columnKeys, "columnKeys");
11127
+ if (!rowKeys.length && !columnKeys.length)
11128
+ throw new TypeError(
11129
+ "\u81F3\u5C11\u63D0\u4F9B rowKeys \u6216 columnKeys\uFF1B\u5173\u95ED\u65F6\u4F20 enabled=false\u3002"
11130
+ );
11131
+ if (rowColumns.length && !rowKeys.length)
11132
+ throw new TypeError("\u8BBE\u7F6E rowColumns \u65F6\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B rowKeys\u3002");
11133
+ const visible = tableLeafColumns(element.columns).filter((column) => !column.hidden).map((column) => JSON.stringify(column.dataIndex));
11134
+ for (const path of [
11135
+ ...rowColumns.length ? rowColumns : rowKeys,
11136
+ ...columnKeys
11137
+ ])
11138
+ if (!visible.includes(JSON.stringify(path)))
11139
+ throw new TypeError(`\u5408\u5E76\u76EE\u6807\u5217\u4E0D\u5B58\u5728\uFF1A${JSON.stringify(path)}\u3002`);
11140
+ return {
11141
+ ...element,
11142
+ mergeCell: {
11143
+ ...rowKeys.length ? {
11144
+ row: {
11145
+ keys: rowKeys,
11146
+ ...rowColumns.length ? { columns: rowColumns } : {}
11147
+ }
11148
+ } : {},
11149
+ ...columnKeys.length ? { column: { keys: columnKeys } } : {}
11150
+ }
11151
+ };
11152
+ }
11153
+ function configureTableGroupAggregation(element, rawPayload, data) {
11154
+ const payload = object(rawPayload);
11155
+ if (payload.enabled === false) return { ...element, packedReport: void 0 };
11156
+ const groupBy = stringPaths(payload.groupBy, "groupBy");
11157
+ if (payload.itemsPerRow !== void 0 && (!Number.isInteger(payload.itemsPerRow) || Number(payload.itemsPerRow) < 1))
11158
+ throw new TypeError("itemsPerRow \u5FC5\u987B\u662F\u5927\u4E8E\u96F6\u7684\u6574\u6570\u3002");
11159
+ if (payload.sums !== void 0 && !Array.isArray(payload.sums))
11160
+ throw new TypeError("sums \u5FC5\u987B\u662F\u6570\u7EC4\u3002");
11161
+ const source = element.dataMode === "binding" ? resolveTableDataSource(data, element.dataPath) : element.dataSource;
11162
+ const rows = Array.isArray(source) ? source.filter(
11163
+ (row) => !!row && typeof row === "object" && !Array.isArray(row)
11164
+ ) : element.dataSource;
11165
+ for (const path of groupBy)
11166
+ if (rows.length && !rows.some((row) => resolvePrintDesignDataPath(row, path) !== void 0))
11167
+ throw new TypeError(`\u5206\u7EC4\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${path}\u3002`);
11168
+ const report = fillPackedReportDefaults(
11169
+ element.columns,
11170
+ rows,
11171
+ element.packedReport
11172
+ );
11173
+ const visible = tableLeafColumns(element.columns).filter(
11174
+ (column) => !column.hidden
11175
+ );
11176
+ const groupFields = { ...report.groupFields };
11177
+ const subtotal = { ...report.subtotal };
11178
+ const total = { ...report.total };
11179
+ const sumColumns = /* @__PURE__ */ new Set();
11180
+ for (const raw of payload.sums ?? []) {
11181
+ const sum = object(raw);
11182
+ if (typeof sum.column !== "string" || !safePart(sum.column))
11183
+ throw new TypeError("sums.column \u5FC5\u987B\u662F\u8868\u683C\u5217\u7684 dataIndex \u5B57\u7B26\u4E32\u3002");
11184
+ const column = sum.column.trim();
11185
+ if (!visible.some((item) => item.dataIndex === column))
11186
+ throw new TypeError(`\u6C47\u603B\u5217\u4E0D\u5B58\u5728\uFF1A${column}\u3002`);
11187
+ if (sumColumns.has(column)) throw new TypeError(`\u6C47\u603B\u5217\u91CD\u590D\uFF1A${column}\u3002`);
11188
+ if (typeof sum.path !== "string" || !safePart(sum.path))
11189
+ throw new TypeError("sums.path \u5FC5\u987B\u662F\u539F\u59CB\u6570\u636E\u7684\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u3002");
11190
+ if (rows.length && !rows.some(
11191
+ (row) => resolvePrintDesignDataPath(row, sum.path) !== void 0
11192
+ ))
11193
+ throw new TypeError(`\u6C42\u548C\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${sum.path}\u3002`);
11194
+ if (sum.decimals !== void 0 && (!Number.isInteger(sum.decimals) || Number(sum.decimals) < 0 || Number(sum.decimals) > 10))
11195
+ throw new TypeError("sums.decimals \u5FC5\u987B\u662F 0 \u5230 10 \u7684\u6574\u6570\u3002");
11196
+ sumColumns.add(column);
11197
+ delete groupFields[column];
11198
+ const rule = {
11199
+ sumPath: sum.path.trim(),
11200
+ ...sum.decimals === void 0 ? {} : { decimals: sum.decimals }
11201
+ };
11202
+ subtotal[column] = rule;
11203
+ total[column] = rule;
11204
+ }
11205
+ if (sumColumns.size && !Object.values(subtotal).some((rule) => rule.text === "\u5C0F\u8BA1")) {
11206
+ const labelColumn = visible.find(
11207
+ (column) => typeof column.dataIndex === "string" && !sumColumns.has(column.dataIndex)
11208
+ );
11209
+ if (typeof labelColumn?.dataIndex === "string")
11210
+ subtotal[labelColumn.dataIndex] = { text: "\u5C0F\u8BA1" };
11211
+ }
11212
+ return {
11213
+ ...element,
11214
+ packedReport: {
11215
+ ...report,
11216
+ groupBy,
11217
+ ...payload.itemsPerRow === void 0 ? {} : { itemsPerRow: payload.itemsPerRow },
11218
+ groupFields,
11219
+ groupMergeColumns: report.groupMergeColumns.filter(
11220
+ (index) => !sumColumns.has(String(visible[index]?.dataIndex ?? ""))
11221
+ ),
11222
+ subtotal,
11223
+ total
11224
+ }
11225
+ };
11226
+ }
11227
+
10652
11228
  // src/plugins/table/interaction/commands.ts
10653
11229
  var tableCommands = {
10654
11230
  execute(element, command, rawPayload, context) {
10655
11231
  if (element.locked) return;
10656
11232
  if (!rawPayload || typeof rawPayload !== "object") return;
11233
+ if (command === "configure-auto-merge")
11234
+ return configureTableAutoMerge(element, rawPayload);
11235
+ if (command === "configure-group-aggregation")
11236
+ return configureTableGroupAggregation(element, rawPayload, context.data);
10657
11237
  const payload = rawPayload;
10658
11238
  const rowIndex = payload.rowIndex ?? 0;
10659
11239
  const columnIndex = payload.columnIndex ?? 0;
@@ -11048,7 +11628,7 @@ function validateTableTemplateData(element, data) {
11048
11628
  // src/plugins/table/native.ts
11049
11629
  var tableNativePlugin = defineNativePlugin(
11050
11630
  "table",
11051
- "0.1.69",
11631
+ "0.1.70",
11052
11632
  definePrintDesignPluginRenderer({
11053
11633
  type: "table",
11054
11634
  validate: validateTableElement,
@@ -12001,6 +12581,7 @@ var ganttNativePlugin = defineNativePlugin(
12001
12581
  // src/native.ts
12002
12582
  var builtinNativeComponentPlugins = [
12003
12583
  textNativePlugin,
12584
+ richTextNativePlugin,
12004
12585
  listNativePlugin,
12005
12586
  dateTimeNativePlugin,
12006
12587
  moneyUpperNativePlugin,
@@ -12263,8 +12844,36 @@ var propertySections = [{
12263
12844
  visibleWhen: (element) => element.type === "text" && Boolean(element.fontSource),
12264
12845
  toPatch: () => ({ fontSource: "" })
12265
12846
  },
12266
- { path: "fontWeight", label: "\u5B57\u91CD", kind: "select", defaultValue: "400", ariaLabel: "\u6587\u672C\u5B57\u91CD", options: FONT_WEIGHT_OPTIONS },
12267
- { path: "lineHeight", label: "\u884C\u9AD8\u500D\u6570", kind: "number", defaultValue: 1.35, min: 0.5, max: 4, precision: 2, ariaLabel: "\u6587\u672C\u884C\u9AD8\u500D\u6570" },
12847
+ { path: "fontWeight", label: "\u52A0\u7C97", kind: "select", defaultValue: "400", ariaLabel: "\u6587\u672C\u5B57\u91CD", options: FONT_WEIGHT_OPTIONS, fullWidth: false },
12848
+ { path: "fontStyle", label: "\u503E\u659C", kind: "select", defaultValue: "normal", ariaLabel: "\u6587\u672C\u503E\u659C", fullWidth: false, options: [
12849
+ { label: "\u5E38\u89C4", value: "normal" },
12850
+ { label: "\u503E\u659C", value: "italic" }
12851
+ ] },
12852
+ { path: "lineHeight", label: "\u884C\u9AD8\u500D\u6570", kind: "number", defaultValue: 1.35, min: 0.5, max: 4, precision: 2, fullWidth: true, ariaLabel: "\u6587\u672C\u884C\u9AD8\u500D\u6570" },
12853
+ { path: "indentMode", label: "\u7F29\u8FDB", kind: "select", defaultValue: "none", fullWidth: false, options: [
12854
+ { label: "\u65E0", value: "none" },
12855
+ { label: "\u9996\u884C\u7F29\u8FDB", value: "firstLine" },
12856
+ { label: "\u60AC\u6302\u7F29\u8FDB", value: "hanging" }
12857
+ ] },
12858
+ {
12859
+ path: "indentValue",
12860
+ label: "\u7F29\u8FDB\u5EA6\u91CF\u503C",
12861
+ kind: "number",
12862
+ defaultValue: 0,
12863
+ min: 0,
12864
+ max: 1e4,
12865
+ precision: 2,
12866
+ fullWidth: false,
12867
+ unitSelector: { path: "indentUnit", label: "\u7F29\u8FDB\u5355\u4F4D", defaultValue: "char", options: [
12868
+ { label: "\u5B57\u7B26", value: "char" },
12869
+ { label: "mm", value: "mm" },
12870
+ { label: "cm", value: "cm" },
12871
+ { label: "in", value: "in" },
12872
+ { label: "pt", value: "pt" },
12873
+ { label: "px", value: "px" }
12874
+ ] },
12875
+ visibleWhen: (element) => element.type === "text" && element.indentMode !== void 0 && element.indentMode !== "none"
12876
+ },
12268
12877
  { path: "heightOverflow", label: "\u8D85\u51FA\u56FA\u5B9A\u9AD8\u5EA6", kind: "select", defaultValue: "flow", ariaLabel: "\u6587\u672C\u8D85\u51FA\u56FA\u5B9A\u9AD8\u5EA6\u5904\u7406\u65B9\u5F0F", options: TEXT_OVERFLOW_OPTIONS },
12269
12878
  { path: "underlineCount", label: "\u4E0B\u5212\u7EBF\u6761\u6570", kind: "number", defaultValue: 0, min: 0, max: 5, precision: 0, ariaLabel: "\u4E0B\u5212\u7EBF\u6761\u6570" },
12270
12879
  { path: "underlineStyle", label: "\u4E0B\u5212\u7EBF\u7EBF\u578B", kind: "select", defaultValue: "solid", ariaLabel: "\u4E0B\u5212\u7EBF\u7EBF\u578B", options: UNDERLINE_STYLE_OPTIONS },
@@ -12303,6 +12912,159 @@ var textPlugin = defineBuiltinReactPlugin(textNativePlugin, {
12303
12912
  menuGroups,
12304
12913
  propertySections
12305
12914
  });
12915
+ function RichTextInlineEditor(props) {
12916
+ const [runs, setRuns] = useState(props.element.runs);
12917
+ const runsRef = useRef(runs);
12918
+ runsRef.current = runs;
12919
+ const editorRef = useRef(null);
12920
+ const overlayRef = useRef(null);
12921
+ const finishedRef = useRef(false);
12922
+ const finish = (commit) => {
12923
+ if (finishedRef.current) return;
12924
+ finishedRef.current = true;
12925
+ if (commit && JSON.stringify(runsRef.current) !== JSON.stringify(props.element.runs))
12926
+ props.onCommit(runsRef.current);
12927
+ else props.onClose();
12928
+ };
12929
+ useEffect(() => {
12930
+ const containsEditorUi = (target) => target instanceof Node && (overlayRef.current?.contains(target) || target instanceof Element && !!target.closest(".canvas-react-rich-text-popup"));
12931
+ const onPointerDown = (event) => {
12932
+ if (!containsEditorUi(event.target)) finish(true);
12933
+ };
12934
+ const onFocusIn = (event) => {
12935
+ if (!containsEditorUi(event.target)) finish(true);
12936
+ };
12937
+ const onKeyDown = (event) => {
12938
+ if (event.key !== "Escape") return;
12939
+ event.preventDefault();
12940
+ event.stopPropagation();
12941
+ finish(false);
12942
+ };
12943
+ document.addEventListener("pointerdown", onPointerDown, true);
12944
+ document.addEventListener("focusin", onFocusIn, true);
12945
+ document.addEventListener("keydown", onKeyDown, true);
12946
+ editorRef.current?.focus();
12947
+ return () => {
12948
+ document.removeEventListener("pointerdown", onPointerDown, true);
12949
+ document.removeEventListener("focusin", onFocusIn, true);
12950
+ document.removeEventListener("keydown", onKeyDown, true);
12951
+ };
12952
+ }, []);
12953
+ const scale = props.element.width > 0 ? props.rect.width / props.element.width : 1;
12954
+ const ptToPx = (size) => `${size * 25.4 / 72 * scale}px`;
12955
+ const indentPx = richTextIndentMm(props.element) * scale;
12956
+ const transform = props.element.transform ? (() => {
12957
+ const matrix = elementTransformHomography(props.element);
12958
+ const perspective = `matrix3d(${matrix.a},${matrix.b},0,${matrix.g / scale},${matrix.c},${matrix.d},0,${matrix.h / scale},0,0,1,0,${matrix.e * scale},${matrix.f * scale},0,1)`;
12959
+ const rotation = props.element.rotation ? ` translate(${props.rect.width / 2}px,${props.rect.height / 2}px) rotate(${props.element.rotation}deg) translate(${-props.rect.width / 2}px,${-props.rect.height / 2}px)` : "";
12960
+ return perspective + rotation;
12961
+ })() : `rotate(${props.element.rotation ?? 0}deg)`;
12962
+ return /* @__PURE__ */ jsx(
12963
+ "div",
12964
+ {
12965
+ ref: overlayRef,
12966
+ className: "cc-print-design-rich-text-overlay",
12967
+ style: {
12968
+ position: "fixed",
12969
+ zIndex: 1e4,
12970
+ left: props.rect.left,
12971
+ top: props.rect.top,
12972
+ width: props.rect.width,
12973
+ height: props.rect.height,
12974
+ background: "transparent",
12975
+ outline: "1px solid #1677ff",
12976
+ transform,
12977
+ transformOrigin: props.element.transform ? "0 0" : "center"
12978
+ },
12979
+ onKeyDownCapture: (event) => {
12980
+ event.stopPropagation();
12981
+ if (event.key === "Escape") {
12982
+ event.preventDefault();
12983
+ finish(false);
12984
+ }
12985
+ },
12986
+ children: /* @__PURE__ */ jsx(
12987
+ ReactRichText,
12988
+ {
12989
+ ref: editorRef,
12990
+ value: runs,
12991
+ onChange: setRuns,
12992
+ toolbarPopupZIndex: 10001,
12993
+ fontFamilyOptions: FONT_FAMILY_OPTIONS.map((option) => ({ label: option.label, value: String(option.value) })),
12994
+ defaultStyle: {
12995
+ fontFamily: resolvePrintDesignFontFamily(props.element.fontFamily),
12996
+ fontSize: props.element.fontSize ?? 14,
12997
+ fontWeight: props.element.fontWeight ?? "400",
12998
+ fontStyle: props.element.fontStyle ?? "normal",
12999
+ color: props.element.color ?? "#1f2937"
13000
+ },
13001
+ fontSizeCss: ptToPx,
13002
+ editorStyle: {
13003
+ width: "100%",
13004
+ height: "100%",
13005
+ minHeight: 0,
13006
+ overflow: "hidden",
13007
+ backgroundColor: "transparent",
13008
+ lineHeight: props.element.lineHeight ?? 1.35,
13009
+ textAlign: props.element.textAlign ?? "left",
13010
+ textIndent: props.element.indentMode === "firstLine" ? `${indentPx}px` : props.element.indentMode === "hanging" ? `-${indentPx}px` : void 0,
13011
+ paddingLeft: props.element.indentMode === "hanging" ? `${indentPx}px` : void 0
13012
+ }
13013
+ }
13014
+ )
13015
+ }
13016
+ );
13017
+ }
13018
+
13019
+ // src/plugins/rich-text/factory.ts
13020
+ var richTextFactory = {
13021
+ type: "richText",
13022
+ label: "\u5BCC\u6587\u672C",
13023
+ showDataPanel: false,
13024
+ defaultOverflowPolicy: "split",
13025
+ overflowPolicyOptions: [
13026
+ { label: "\u81EA\u52A8\u6EA2\u51FA\u5230\u7EED\u9875", value: "split" },
13027
+ { label: "\u6574\u4F53\u653E\u5230\u4E0B\u4E00\u9875", value: "nextPage" },
13028
+ { label: "\u88C1\u5207", value: "clip" },
13029
+ { label: "\u8D85\u51FA\u663E\u793A...", value: "ellipsis" }
13030
+ ],
13031
+ renderInlineEditor: ({ element, rect, onCommit, onClose }) => createElement(RichTextInlineEditor, {
13032
+ element,
13033
+ rect,
13034
+ onCommit: (runs) => onCommit({ runs }),
13035
+ onClose
13036
+ }),
13037
+ create: () => ({
13038
+ ...createCommonElementDefaults(),
13039
+ type: "richText",
13040
+ name: "\u5BCC\u6587\u672C",
13041
+ runs: [{ text: "\u53CC\u51FB\u7F16\u8F91\u5BCC\u6587\u672C" }],
13042
+ fontSize: 14,
13043
+ color: "#1f2937"
13044
+ })
13045
+ };
13046
+ var menuGroups2 = [
13047
+ {
13048
+ id: "basic",
13049
+ title: "\u57FA\u7840\u5143\u7D20",
13050
+ order: 0,
13051
+ items: [
13052
+ {
13053
+ id: "richText",
13054
+ type: "richText",
13055
+ label: "\u5BCC\u6587\u672C",
13056
+ icon: createElement(ReactFontSizeOutlined, { "aria-hidden": true }),
13057
+ order: 1
13058
+ }
13059
+ ]
13060
+ }
13061
+ ];
13062
+
13063
+ // src/plugins/rich-text/react.ts
13064
+ var richTextPlugin = defineBuiltinReactPlugin(richTextNativePlugin, {
13065
+ factory: richTextFactory,
13066
+ menuGroups: menuGroups2
13067
+ });
12306
13068
 
12307
13069
  // src/plugins/list/factory.ts
12308
13070
  var listFactory = {
@@ -12353,7 +13115,7 @@ var listFactory = {
12353
13115
  };
12354
13116
 
12355
13117
  // src/plugins/list/menu.ts
12356
- var menuGroups2 = [
13118
+ var menuGroups3 = [
12357
13119
  {
12358
13120
  id: "list",
12359
13121
  title: "\u5217\u8868\u7EC4\u4EF6",
@@ -12455,7 +13217,7 @@ var propertySections2 = [
12455
13217
  // src/plugins/list/react.ts
12456
13218
  var listPlugin = defineBuiltinReactPlugin(listNativePlugin, {
12457
13219
  factory: listFactory,
12458
- menuGroups: menuGroups2,
13220
+ menuGroups: menuGroups3,
12459
13221
  propertySections: propertySections2
12460
13222
  });
12461
13223
 
@@ -12478,7 +13240,7 @@ var dateTimeFactory = {
12478
13240
  };
12479
13241
  }
12480
13242
  };
12481
- var menuGroups3 = [
13243
+ var menuGroups4 = [
12482
13244
  {
12483
13245
  id: "date-time",
12484
13246
  title: "\u65E5\u671F\u65F6\u95F4",
@@ -12519,7 +13281,7 @@ var propertySections3 = [
12519
13281
  ];
12520
13282
  var dateTimePlugin = defineBuiltinReactPlugin(dateTimeNativePlugin, {
12521
13283
  factory: dateTimeFactory,
12522
- menuGroups: menuGroups3,
13284
+ menuGroups: menuGroups4,
12523
13285
  propertySections: propertySections3
12524
13286
  });
12525
13287
 
@@ -12542,7 +13304,7 @@ var moneyUpperFactory = {
12542
13304
  };
12543
13305
  }
12544
13306
  };
12545
- var menuGroups4 = [
13307
+ var menuGroups5 = [
12546
13308
  {
12547
13309
  id: "basic",
12548
13310
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12596,7 +13358,7 @@ var propertySections4 = [
12596
13358
  ];
12597
13359
  var moneyUpperPlugin = defineBuiltinReactPlugin(
12598
13360
  moneyUpperNativePlugin,
12599
- { factory: moneyUpperFactory, menuGroups: menuGroups4, propertySections: propertySections4 }
13361
+ { factory: moneyUpperFactory, menuGroups: menuGroups5, propertySections: propertySections4 }
12600
13362
  );
12601
13363
 
12602
13364
  // src/plugins/page-number/factory.ts
@@ -12618,7 +13380,7 @@ var pageNumberFactory = {
12618
13380
  };
12619
13381
  }
12620
13382
  };
12621
- var menuGroups5 = [
13383
+ var menuGroups6 = [
12622
13384
  {
12623
13385
  id: "basic",
12624
13386
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12667,7 +13429,7 @@ var propertySections5 = [
12667
13429
  ];
12668
13430
  var pageNumberPlugin = defineBuiltinReactPlugin(
12669
13431
  pageNumberNativePlugin,
12670
- { factory: pageNumberFactory, menuGroups: menuGroups5, propertySections: propertySections5 }
13432
+ { factory: pageNumberFactory, menuGroups: menuGroups6, propertySections: propertySections5 }
12671
13433
  );
12672
13434
 
12673
13435
  // src/plugins/watermark/factory.ts
@@ -12707,7 +13469,7 @@ var watermarkFactory = {
12707
13469
  };
12708
13470
  }
12709
13471
  };
12710
- var menuGroups6 = [
13472
+ var menuGroups7 = [
12711
13473
  {
12712
13474
  id: "basic",
12713
13475
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12761,7 +13523,7 @@ var propertySections6 = [
12761
13523
  ];
12762
13524
  var watermarkPlugin = defineBuiltinReactPlugin(watermarkNativePlugin, {
12763
13525
  factory: watermarkFactory,
12764
- menuGroups: menuGroups6,
13526
+ menuGroups: menuGroups7,
12765
13527
  propertySections: propertySections6
12766
13528
  });
12767
13529
 
@@ -12902,7 +13664,7 @@ var shapeFactory = {
12902
13664
  };
12903
13665
 
12904
13666
  // src/plugins/shape/menu.ts
12905
- var menuGroups7 = [
13667
+ var menuGroups8 = [
12906
13668
  {
12907
13669
  id: "shape",
12908
13670
  title: "\u5F62\u72B6\u7EC4\u4EF6",
@@ -13048,15 +13810,15 @@ var menuGroups7 = [
13048
13810
 
13049
13811
  // src/plugins/shape/layout/options.ts
13050
13812
  var SHAPE_OPTIONS = [
13051
- ...(menuGroups7.find((group) => group.id === "shape")?.items ?? []).map(
13813
+ ...(menuGroups8.find((group) => group.id === "shape")?.items ?? []).map(
13052
13814
  ({ id, label }) => ({ value: id, label })
13053
13815
  ),
13054
13816
  { value: "ellipse", label: "\u692D\u5706" },
13055
13817
  { value: "line", label: "\u76F4\u7EBF" },
13056
- ...(menuGroups7.find((group) => group.id === "bracket")?.items ?? []).map(
13818
+ ...(menuGroups8.find((group) => group.id === "bracket")?.items ?? []).map(
13057
13819
  ({ id, label }) => ({ value: id, label })
13058
13820
  ),
13059
- ...(menuGroups7.find((group) => group.id === "curve")?.items ?? []).map(
13821
+ ...(menuGroups8.find((group) => group.id === "curve")?.items ?? []).map(
13060
13822
  ({ id, label }) => ({ value: id, label })
13061
13823
  ),
13062
13824
  { value: "curve-path", label: "\u8DEF\u5F84" }
@@ -13274,7 +14036,7 @@ var propertySections7 = [
13274
14036
  // src/plugins/shape/react.ts
13275
14037
  var shapePlugin = defineBuiltinReactPlugin(shapeNativePlugin, {
13276
14038
  factory: shapeFactory,
13277
- menuGroups: menuGroups7,
14039
+ menuGroups: menuGroups8,
13278
14040
  propertySections: propertySections7
13279
14041
  });
13280
14042
 
@@ -13305,6 +14067,7 @@ function BrushToolbarButton({
13305
14067
  title: active ? "\u9000\u51FA\u753B\u7B14\u6A21\u5F0F" : "\u65B0\u5EFA\u753B\u7B14\u56FE\u5C42\u5E76\u7ED8\u5236",
13306
14068
  "aria-label": "\u753B\u7B14\u6A21\u5F0F",
13307
14069
  "aria-pressed": active,
14070
+ type: active ? "primary" : "default",
13308
14071
  disabled: readonly,
13309
14072
  icon: /* @__PURE__ */ jsxs(
13310
14073
  "svg",
@@ -13356,7 +14119,7 @@ var brushFactory = {
13356
14119
  };
13357
14120
 
13358
14121
  // src/plugins/brush/menu.ts
13359
- var menuGroups8 = [];
14122
+ var menuGroups9 = [];
13360
14123
 
13361
14124
  // src/plugins/brush/properties.ts
13362
14125
  var propertySections8 = [
@@ -13440,7 +14203,7 @@ var propertySections8 = [
13440
14203
  // src/plugins/brush/react.ts
13441
14204
  var brushPlugin = defineBuiltinReactPlugin(brushNativePlugin, {
13442
14205
  factory: brushFactory,
13443
- menuGroups: menuGroups8,
14206
+ menuGroups: menuGroups9,
13444
14207
  propertySections: propertySections8
13445
14208
  });
13446
14209
 
@@ -13478,7 +14241,7 @@ var connectorFactory = {
13478
14241
  };
13479
14242
 
13480
14243
  // src/plugins/connector/menu.ts
13481
- var menuGroups9 = [
14244
+ var menuGroups10 = [
13482
14245
  {
13483
14246
  id: "connector",
13484
14247
  title: "\u8FDE\u63A5\u7EBF",
@@ -13593,7 +14356,7 @@ var propertySections9 = [
13593
14356
  // src/plugins/connector/react.ts
13594
14357
  var connectorPlugin = defineBuiltinReactPlugin(connectorNativePlugin, {
13595
14358
  factory: connectorFactory,
13596
- menuGroups: menuGroups9,
14359
+ menuGroups: menuGroups10,
13597
14360
  propertySections: propertySections9
13598
14361
  });
13599
14362
 
@@ -13618,7 +14381,7 @@ var dividerFactory = {
13618
14381
  };
13619
14382
  }
13620
14383
  };
13621
- var menuGroups10 = [
14384
+ var menuGroups11 = [
13622
14385
  {
13623
14386
  id: "basic",
13624
14387
  title: "\u57FA\u7840\u5143\u7D20",
@@ -13677,7 +14440,7 @@ var propertySections10 = [
13677
14440
  // src/plugins/divider/react.ts
13678
14441
  var dividerPlugin = defineBuiltinReactPlugin(dividerNativePlugin, {
13679
14442
  factory: dividerFactory,
13680
- menuGroups: menuGroups10,
14443
+ menuGroups: menuGroups11,
13681
14444
  propertySections: propertySections10
13682
14445
  });
13683
14446
 
@@ -13714,7 +14477,7 @@ var rulerFactory = {
13714
14477
  };
13715
14478
 
13716
14479
  // src/plugins/ruler/menu.ts
13717
- var menuGroups11 = [
14480
+ var menuGroups12 = [
13718
14481
  {
13719
14482
  id: "ruler",
13720
14483
  title: "\u523B\u5EA6\u5C3A\u7EC4\u4EF6",
@@ -13807,7 +14570,7 @@ var propertySections11 = [
13807
14570
  // src/plugins/ruler/react.ts
13808
14571
  var rulerPlugin = defineBuiltinReactPlugin(rulerNativePlugin, {
13809
14572
  factory: rulerFactory,
13810
- menuGroups: menuGroups11,
14573
+ menuGroups: menuGroups12,
13811
14574
  propertySections: propertySections11
13812
14575
  });
13813
14576
 
@@ -13849,7 +14612,7 @@ var gridFactory = {
13849
14612
  };
13850
14613
  }
13851
14614
  };
13852
- var menuGroups12 = [
14615
+ var menuGroups13 = [
13853
14616
  {
13854
14617
  id: "grid",
13855
14618
  title: "\u7F51\u683C\u7EC4\u4EF6",
@@ -14059,7 +14822,7 @@ var propertySections12 = [
14059
14822
  // src/plugins/grid/react.ts
14060
14823
  var gridPlugin = defineBuiltinReactPlugin(gridNativePlugin, {
14061
14824
  factory: gridFactory,
14062
- menuGroups: menuGroups12,
14825
+ menuGroups: menuGroups13,
14063
14826
  propertySections: propertySections12
14064
14827
  });
14065
14828
 
@@ -14121,7 +14884,7 @@ var coordinateFactory = {
14121
14884
  };
14122
14885
  }
14123
14886
  };
14124
- var menuGroups13 = [
14887
+ var menuGroups14 = [
14125
14888
  {
14126
14889
  id: "grid",
14127
14890
  title: "\u7F51\u683C\u7EC4\u4EF6",
@@ -14272,7 +15035,7 @@ var propertySections13 = [
14272
15035
  // src/plugins/coordinate/react.ts
14273
15036
  var coordinatePlugin = defineBuiltinReactPlugin(
14274
15037
  coordinateNativePlugin,
14275
- { factory: coordinateFactory, menuGroups: menuGroups13, propertySections: propertySections13 }
15038
+ { factory: coordinateFactory, menuGroups: menuGroups14, propertySections: propertySections13 }
14276
15039
  );
14277
15040
 
14278
15041
  // src/plugins/progress/factory.ts
@@ -14307,7 +15070,7 @@ var progressFactory = {
14307
15070
  };
14308
15071
 
14309
15072
  // src/plugins/progress/menu.ts
14310
- var menuGroups14 = [
15073
+ var menuGroups15 = [
14311
15074
  {
14312
15075
  id: "progress",
14313
15076
  title: "\u8FDB\u5EA6\u7EC4\u4EF6",
@@ -14439,7 +15202,7 @@ var propertySections14 = [
14439
15202
  // src/plugins/progress/react.ts
14440
15203
  var progressPlugin = defineBuiltinReactPlugin(progressNativePlugin, {
14441
15204
  factory: progressFactory,
14442
- menuGroups: menuGroups14,
15205
+ menuGroups: menuGroups15,
14443
15206
  propertySections: propertySections14
14444
15207
  });
14445
15208
 
@@ -14489,7 +15252,7 @@ var flowFactory = {
14489
15252
  };
14490
15253
  }
14491
15254
  };
14492
- var menuGroups15 = [
15255
+ var menuGroups16 = [
14493
15256
  {
14494
15257
  id: "basic",
14495
15258
  title: "\u57FA\u7840\u5143\u7D20",
@@ -14625,7 +15388,7 @@ var propertySections15 = [{
14625
15388
  // src/plugins/flow/react.ts
14626
15389
  var flowPlugin = defineBuiltinReactPlugin(flowNativePlugin, {
14627
15390
  factory: flowFactory,
14628
- menuGroups: menuGroups15,
15391
+ menuGroups: menuGroups16,
14629
15392
  propertySections: propertySections15
14630
15393
  });
14631
15394
 
@@ -14667,7 +15430,7 @@ var clockFactory = {
14667
15430
  };
14668
15431
  }
14669
15432
  };
14670
- var menuGroups16 = [
15433
+ var menuGroups17 = [
14671
15434
  {
14672
15435
  id: "date-time",
14673
15436
  title: "\u65E5\u671F\u65F6\u95F4",
@@ -14766,7 +15529,7 @@ var propertySections16 = [
14766
15529
  // src/plugins/clock/react.ts
14767
15530
  var clockPlugin = defineBuiltinReactPlugin(clockNativePlugin, {
14768
15531
  factory: clockFactory,
14769
- menuGroups: menuGroups16,
15532
+ menuGroups: menuGroups17,
14770
15533
  propertySections: propertySections16
14771
15534
  });
14772
15535
 
@@ -14885,7 +15648,7 @@ var imageFactory = {
14885
15648
  return { ...common, type, name: "\u56FE\u7247", src: "", fit: "contain" };
14886
15649
  }
14887
15650
  };
14888
- var menuGroups17 = [
15651
+ var menuGroups18 = [
14889
15652
  {
14890
15653
  id: "basic",
14891
15654
  title: "\u57FA\u7840\u5143\u7D20",
@@ -14940,7 +15703,7 @@ var propertySections17 = [
14940
15703
  // src/plugins/image/react.ts
14941
15704
  var imagePlugin = defineBuiltinReactPlugin(imageNativePlugin, {
14942
15705
  factory: imageFactory,
14943
- menuGroups: menuGroups17,
15706
+ menuGroups: menuGroups18,
14944
15707
  propertySections: propertySections17
14945
15708
  });
14946
15709
  var barcodeFactory = {
@@ -14970,7 +15733,7 @@ var barcodeFactory = {
14970
15733
  };
14971
15734
  }
14972
15735
  };
14973
- var menuGroups18 = [
15736
+ var menuGroups19 = [
14974
15737
  {
14975
15738
  id: "basic",
14976
15739
  title: "\u57FA\u7840\u5143\u7D20",
@@ -15030,7 +15793,7 @@ var propertySections18 = [
15030
15793
  // src/plugins/barcode/react.ts
15031
15794
  var barcodePlugin = defineBuiltinReactPlugin(barcodeNativePlugin, {
15032
15795
  factory: barcodeFactory,
15033
- menuGroups: menuGroups18,
15796
+ menuGroups: menuGroups19,
15034
15797
  propertySections: propertySections18
15035
15798
  });
15036
15799
 
@@ -15052,7 +15815,7 @@ var qrcodeFactory = {
15052
15815
  };
15053
15816
  }
15054
15817
  };
15055
- var menuGroups19 = [
15818
+ var menuGroups20 = [
15056
15819
  {
15057
15820
  id: "basic",
15058
15821
  title: "\u57FA\u7840\u5143\u7D20",
@@ -15211,7 +15974,7 @@ var propertySections19 = [
15211
15974
  // src/plugins/qrcode/react.ts
15212
15975
  var qrcodePlugin = defineBuiltinReactPlugin(qrcodeNativePlugin, {
15213
15976
  factory: qrcodeFactory,
15214
- menuGroups: menuGroups19,
15977
+ menuGroups: menuGroups20,
15215
15978
  propertySections: propertySections19
15216
15979
  });
15217
15980
 
@@ -15317,7 +16080,7 @@ var chartFactory = {
15317
16080
  };
15318
16081
  }
15319
16082
  };
15320
- var menuGroups20 = [
16083
+ var menuGroups21 = [
15321
16084
  {
15322
16085
  id: "chart",
15323
16086
  title: "\u56FE\u8868\u7EC4\u4EF6",
@@ -15580,30 +16343,129 @@ var propertySections20 = [{
15580
16343
  // src/plugins/chart/react.ts
15581
16344
  var chartPlugin = defineBuiltinReactPlugin(chartNativePlugin, {
15582
16345
  factory: chartFactory,
15583
- menuGroups: menuGroups20,
16346
+ menuGroups: menuGroups21,
15584
16347
  propertySections: propertySections20
15585
16348
  });
15586
16349
 
15587
16350
  // src/plugins/table/factory.ts
16351
+ var fieldPathSchema = {
16352
+ anyOf: [
16353
+ { type: "string", minLength: 1 },
16354
+ {
16355
+ type: "array",
16356
+ items: {
16357
+ anyOf: [
16358
+ { type: "string", minLength: 1 },
16359
+ { type: "integer", minimum: 0 }
16360
+ ]
16361
+ },
16362
+ minItems: 1
16363
+ }
16364
+ ]
16365
+ };
15588
16366
  var tableFactory = {
15589
16367
  type: "table",
15590
16368
  label: "\u8868\u683C",
15591
16369
  agentCommands: [
15592
16370
  {
15593
16371
  name: "insert-row",
15594
- description: "\u5728\u9759\u6001\u8868\u683C\u7684 rowIndex \u884C\u524D\u63D2\u5165\u884C\uFF1Bafter=true \u65F6\u63D2\u5728\u884C\u540E\u3002"
16372
+ description: "\u5728\u9759\u6001\u8868\u683C\u7684 rowIndex \u884C\u524D\u63D2\u5165\u884C\uFF1Bafter=true \u65F6\u63D2\u5728\u884C\u540E\u3002",
16373
+ parameters: {
16374
+ type: "object",
16375
+ properties: {
16376
+ rowIndex: { type: "integer", minimum: 0 },
16377
+ after: { type: "boolean" }
16378
+ },
16379
+ required: ["rowIndex"],
16380
+ additionalProperties: false
16381
+ }
15595
16382
  },
15596
16383
  {
15597
16384
  name: "insert-column",
15598
- description: "\u5728 columnIndex \u5217\u524D\u63D2\u5165\u5217\uFF1Bafter=true \u65F6\u63D2\u5728\u5217\u540E\u3002"
16385
+ description: "\u5728 columnIndex \u5217\u524D\u63D2\u5165\u5217\uFF1Bafter=true \u65F6\u63D2\u5728\u5217\u540E\u3002",
16386
+ parameters: {
16387
+ type: "object",
16388
+ properties: {
16389
+ columnIndex: { type: "integer", minimum: 0 },
16390
+ after: { type: "boolean" }
16391
+ },
16392
+ required: ["columnIndex"],
16393
+ additionalProperties: false
16394
+ }
15599
16395
  },
15600
16396
  {
15601
16397
  name: "merge-body",
15602
- description: "\u5408\u5E76\u8868\u4F53\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
16398
+ description: "\u5408\u5E76\u8868\u4F53\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002",
16399
+ parameters: {
16400
+ type: "object",
16401
+ properties: {
16402
+ rowIndex: { type: "integer", minimum: 0 },
16403
+ columnIndex: { type: "integer", minimum: 0 },
16404
+ rowSpan: { type: "integer", minimum: 1 },
16405
+ colSpan: { type: "integer", minimum: 1 }
16406
+ },
16407
+ required: ["rowIndex", "columnIndex", "rowSpan", "colSpan"],
16408
+ additionalProperties: false
16409
+ }
15603
16410
  },
15604
16411
  {
15605
16412
  name: "merge-header",
15606
- description: "\u5408\u5E76\u8868\u5934\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
16413
+ description: "\u5408\u5E76\u8868\u5934\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002",
16414
+ parameters: {
16415
+ type: "object",
16416
+ properties: {
16417
+ rowIndex: { type: "integer", minimum: 0 },
16418
+ columnIndex: { type: "integer", minimum: 0 },
16419
+ rowSpan: { type: "integer", minimum: 1 },
16420
+ colSpan: { type: "integer", minimum: 1 }
16421
+ },
16422
+ required: ["rowIndex", "columnIndex", "rowSpan", "colSpan"],
16423
+ additionalProperties: false
16424
+ }
16425
+ },
16426
+ {
16427
+ name: "configure-auto-merge",
16428
+ description: '\u6309\u6570\u636E\u5B57\u6BB5\u81EA\u52A8\u5408\u5E76\u8FDE\u7EED\u884C\u6216\u540C\u884C\u76F8\u90BB\u5217\u3002payload \u793A\u4F8B\uFF1A{rowKeys:["group"],rowColumns:["group"],columnKeys:["name"]}\uFF1B\u5B57\u6BB5\u53EF\u7528\u975E\u7A7A\u5B57\u7B26\u4E32\u6216\u8DEF\u5F84\u6570\u7EC4\uFF0C\u76EE\u6807\u5217\u987B\u5B58\u5728\u3002\u53EA\u9700\u884C\u5408\u5E76\u6216\u5217\u5408\u5E76\u65F6\u7701\u7565\u53E6\u4E00\u7C7B\u5B57\u6BB5\uFF1B\u4F20 {enabled:false} \u5173\u95ED\u3002\u914D\u7F6E\u4F1A\u6574\u4F53\u66FF\u6362\u539F\u81EA\u52A8\u5408\u5E76\u89C4\u5219\u3002',
16429
+ parameters: {
16430
+ type: "object",
16431
+ properties: {
16432
+ enabled: { type: "boolean" },
16433
+ rowKeys: { type: "array", items: fieldPathSchema },
16434
+ rowColumns: { type: "array", items: fieldPathSchema },
16435
+ columnKeys: { type: "array", items: fieldPathSchema }
16436
+ },
16437
+ additionalProperties: false
16438
+ }
16439
+ },
16440
+ {
16441
+ name: "configure-group-aggregation",
16442
+ description: '\u542F\u7528\u5206\u7EC4\u805A\u5408\u62A5\u8868\u5E76\u81EA\u52A8\u8865\u9F50\u660E\u7EC6\u3001\u5C0F\u8BA1\u548C\u603B\u8BA1\u89C4\u5219\u3002payload \u793A\u4F8B\uFF1A{groupBy:["region"],sums:[{column:"amount",path:"amount",decimals:2}],itemsPerRow:1}\uFF1BgroupBy \u4E3A\u539F\u59CB\u6570\u636E\u5B57\u6BB5\u8DEF\u5F84\uFF0Csums.column \u4E3A\u73B0\u6709\u53EF\u89C1\u5217 dataIndex\uFF0Csums.path \u4E3A\u6C42\u548C\u6E90\u5B57\u6BB5\u3002\u4F20 {enabled:false} \u5173\u95ED\u3002',
16443
+ parameters: {
16444
+ type: "object",
16445
+ properties: {
16446
+ enabled: { type: "boolean" },
16447
+ groupBy: {
16448
+ type: "array",
16449
+ items: { type: "string", minLength: 1 },
16450
+ minItems: 1
16451
+ },
16452
+ sums: {
16453
+ type: "array",
16454
+ items: {
16455
+ type: "object",
16456
+ properties: {
16457
+ column: { type: "string", minLength: 1 },
16458
+ path: { type: "string", minLength: 1 },
16459
+ decimals: { type: "integer", minimum: 0, maximum: 10 }
16460
+ },
16461
+ required: ["column", "path"],
16462
+ additionalProperties: false
16463
+ }
16464
+ },
16465
+ itemsPerRow: { type: "integer", minimum: 1 }
16466
+ },
16467
+ additionalProperties: false
16468
+ }
15607
16469
  }
15608
16470
  ],
15609
16471
  defaultOverflowPolicy: "split",
@@ -15687,7 +16549,7 @@ var tableFactory = {
15687
16549
  };
15688
16550
  }
15689
16551
  };
15690
- var menuGroups21 = [
16552
+ var menuGroups22 = [
15691
16553
  {
15692
16554
  id: "table",
15693
16555
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -17565,6 +18427,7 @@ function TableCellsPanel({
17565
18427
  title: label,
17566
18428
  "aria-label": `${name}\u6587\u672C${label}`,
17567
18429
  "aria-pressed": (textStyle.textAlign ?? "center") === value,
18430
+ type: (textStyle.textAlign ?? "center") === value ? "primary" : "default",
17568
18431
  onClick: () => updateStyle({ textAlign: value })
17569
18432
  },
17570
18433
  value
@@ -17588,6 +18451,7 @@ function TableCellsPanel({
17588
18451
  title: "\u52A0\u7C97",
17589
18452
  "aria-label": `${name}\u6587\u672C\u52A0\u7C97`,
17590
18453
  "aria-pressed": textStyle.bold === true,
18454
+ type: textStyle.bold === true ? "primary" : "default",
17591
18455
  onClick: () => updateStyle({ bold: !textStyle.bold })
17592
18456
  }
17593
18457
  ),
@@ -17598,6 +18462,7 @@ function TableCellsPanel({
17598
18462
  title: "\u503E\u659C",
17599
18463
  "aria-label": `${name}\u6587\u672C\u503E\u659C`,
17600
18464
  "aria-pressed": textStyle.italic === true,
18465
+ type: textStyle.italic === true ? "primary" : "default",
17601
18466
  onClick: () => updateStyle({ italic: !textStyle.italic })
17602
18467
  }
17603
18468
  )
@@ -17614,80 +18479,6 @@ function TableCellsPanel({
17614
18479
  )
17615
18480
  ] });
17616
18481
  }
17617
-
17618
- // src/plugins/table/data/packed-report-defaults.ts
17619
- function fillPackedReportDefaults(columns, rows, current2) {
17620
- const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
17621
- const keys2 = visible.map(
17622
- (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
17623
- );
17624
- const repeats = /* @__PURE__ */ new Map();
17625
- keys2.forEach((key) => {
17626
- const match = /^(.+?)([1-9]\d*)$/.exec(key);
17627
- if (!match) return;
17628
- const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
17629
- slots.add(Number(match[2]));
17630
- repeats.set(match[1], slots);
17631
- });
17632
- const series = [...repeats].filter(
17633
- ([, slots]) => slots.has(1) && slots.has(2)
17634
- );
17635
- const itemsPerRow = Math.max(
17636
- 1,
17637
- ...series.map(([, slots]) => Math.max(...slots))
17638
- );
17639
- const sample = rows.find((row) => row && typeof row === "object") ?? {};
17640
- const groupFields = {};
17641
- keys2.forEach((key, index) => {
17642
- const repeated = series.some(
17643
- ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
17644
- );
17645
- if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
17646
- groupFields[key] = key in sample ? key : "";
17647
- }
17648
- });
17649
- const itemFields = series.map(([prefix]) => ({
17650
- prefix,
17651
- .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
17652
- }));
17653
- const totals = {};
17654
- visible.forEach((column, index) => {
17655
- const key = keys2[index];
17656
- const summary = column.summary;
17657
- const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
17658
- if (key && summary && type === "sum") {
17659
- const prefix = series.find(
17660
- ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
17661
- )?.[0];
17662
- totals[key] = {
17663
- sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
17664
- ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
17665
- };
17666
- }
17667
- });
17668
- const subtotalLabelKey = keys2.find(
17669
- (key) => key && !(key in totals) && !(key in groupFields)
17670
- );
17671
- const totalLabelKey = keys2.find((key) => key && !(key in totals));
17672
- const subtotal = { ...totals };
17673
- if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
17674
- if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
17675
- return {
17676
- groupBy: current2?.groupBy ?? [],
17677
- itemsPerRow: current2?.itemsPerRow ?? itemsPerRow,
17678
- groupFields: Object.keys(current2?.groupFields ?? {}).length ? current2.groupFields : groupFields,
17679
- groupMergeColumns: Object.keys(current2?.groupFields ?? {}).length ? current2.groupMergeColumns : keys2.flatMap(
17680
- (key, index) => key && key in groupFields ? [index] : []
17681
- ),
17682
- itemFields: current2?.itemFields?.length ? current2.itemFields : itemFields,
17683
- subtotal: Object.keys(current2?.subtotal ?? {}).length ? current2.subtotal : subtotal,
17684
- subtotalMerges: current2?.subtotalMerges ?? [],
17685
- total: Object.keys(current2?.total ?? {}).length ? current2.total : totals,
17686
- totalMerges: current2?.totalMerges ?? [],
17687
- appendRows: current2?.appendRows ?? [],
17688
- ...current2?.footerElementIds ? { footerElementIds: current2.footerElementIds } : {}
17689
- };
17690
- }
17691
18482
  var isTableRows = (value) => Array.isArray(value) && value.every(
17692
18483
  (row) => row !== null && typeof row === "object" && !Array.isArray(row)
17693
18484
  );
@@ -18844,7 +19635,7 @@ function PackedReportPanel({
18844
19635
  ] })
18845
19636
  ] });
18846
19637
  }
18847
- var fieldPath = (value) => Array.isArray(value) ? value.join(".") : String(value);
19638
+ var fieldPath2 = (value) => Array.isArray(value) ? value.join(".") : String(value);
18848
19639
  function TableAutoMergePanel({
18849
19640
  element,
18850
19641
  samples = [],
@@ -18897,7 +19688,7 @@ function TableAutoMergePanel({
18897
19688
  DataPathPicker,
18898
19689
  {
18899
19690
  label: `${label} ${index + 1}`,
18900
- value: fieldPath(value),
19691
+ value: fieldPath2(value),
18901
19692
  samples,
18902
19693
  onChange: (path) => set(
18903
19694
  values.map(
@@ -19480,16 +20271,19 @@ function TableColumnsPanel({
19480
20271
  ] });
19481
20272
  }
19482
20273
  function fixedTableWidth(columns) {
19483
- return tableLeafColumns(columns).filter((column) => !column.hidden).reduce((sum, column) => sum + Math.min(
19484
- column.maxWidth ?? Number.POSITIVE_INFINITY,
19485
- Math.max(column.minWidth ?? 1, column.width ?? 100)
19486
- ), 0) * 25.4 / 96;
20274
+ return tableLeafColumns(columns).filter((column) => !column.hidden).reduce(
20275
+ (sum, column) => sum + Math.min(
20276
+ column.maxWidth ?? Number.POSITIVE_INFINITY,
20277
+ Math.max(column.minWidth ?? 1, column.width ?? 100)
20278
+ ),
20279
+ 0
20280
+ ) * 25.4 / 96;
19487
20281
  }
19488
20282
  function TableColumnsControl(context) {
19489
20283
  if (context.element.type !== "table") return null;
19490
20284
  const element = context.element;
19491
20285
  const page = context.page;
19492
- return /* @__PURE__ */ jsxs(Fragment, { children: [
20286
+ return /* @__PURE__ */ jsxs("div", { className: "cc-print-design-column-control cc-print-design-field-full", children: [
19493
20287
  /* @__PURE__ */ jsx(
19494
20288
  TableColumnsPanel,
19495
20289
  {
@@ -19521,10 +20315,18 @@ function TableColumnsControl(context) {
19521
20315
  {
19522
20316
  icon: /* @__PURE__ */ jsx(ReactPlusOutlined, { "aria-hidden": "true" }),
19523
20317
  disabled: context.readonly,
19524
- onClick: () => context.onChange({ columns: [
19525
- ...element.columns,
19526
- { key: crypto.randomUUID(), title: "\u65B0\u5217", dataIndex: `field${element.columns.length + 1}`, cellType: "text", width: 100 }
19527
- ] }),
20318
+ onClick: () => context.onChange({
20319
+ columns: [
20320
+ ...element.columns,
20321
+ {
20322
+ key: crypto.randomUUID(),
20323
+ title: "\u65B0\u5217",
20324
+ dataIndex: `field${element.columns.length + 1}`,
20325
+ cellType: "text",
20326
+ width: 100
20327
+ }
20328
+ ]
20329
+ }),
19528
20330
  children: "\u6DFB\u52A0\u5217"
19529
20331
  }
19530
20332
  ),
@@ -19744,7 +20546,7 @@ var propertySections21 = [
19744
20546
  // src/plugins/table/react.ts
19745
20547
  var tablePlugin = defineBuiltinReactPlugin(tableNativePlugin, {
19746
20548
  factory: tableFactory,
19747
- menuGroups: menuGroups21,
20549
+ menuGroups: menuGroups22,
19748
20550
  contextMenu: tableContextMenu,
19749
20551
  propertySections: propertySections21
19750
20552
  });
@@ -19820,7 +20622,7 @@ var pivotTableFactory = {
19820
20622
  };
19821
20623
  }
19822
20624
  };
19823
- var menuGroups22 = [
20625
+ var menuGroups23 = [
19824
20626
  {
19825
20627
  id: "table",
19826
20628
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -20525,7 +21327,7 @@ var pivotTablePlugin = defineBuiltinReactPlugin(
20525
21327
  pivotTableNativePlugin,
20526
21328
  {
20527
21329
  factory: pivotTableFactory,
20528
- menuGroups: menuGroups22,
21330
+ menuGroups: menuGroups23,
20529
21331
  propertySections: propertySections22
20530
21332
  }
20531
21333
  );
@@ -20600,7 +21402,7 @@ var ganttFactory = {
20600
21402
  };
20601
21403
  }
20602
21404
  };
20603
- var menuGroups23 = [
21405
+ var menuGroups24 = [
20604
21406
  {
20605
21407
  id: "table",
20606
21408
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -20974,7 +21776,7 @@ var propertySections23 = [
20974
21776
  // src/plugins/gantt/react.ts
20975
21777
  var ganttPlugin = defineBuiltinReactPlugin(ganttNativePlugin, {
20976
21778
  factory: ganttFactory,
20977
- menuGroups: menuGroups23,
21779
+ menuGroups: menuGroups24,
20978
21780
  propertySections: propertySections23
20979
21781
  });
20980
21782
  function formatTime(value) {
@@ -21748,6 +22550,7 @@ var pagePropertyPanels = new PrintDesignScopedPropertyRegistry([
21748
22550
  ReactButton,
21749
22551
  {
21750
22552
  "aria-pressed": settings?.showGrid ?? false,
22553
+ type: settings?.showGrid ? "primary" : "default",
21751
22554
  disabled: readonly,
21752
22555
  onClick: () => onSettingsChange?.({
21753
22556
  showGrid: !(settings?.showGrid ?? false)
@@ -21887,9 +22690,9 @@ var themeSettingsSections = [{
21887
22690
  render: ({ preferences }, readonly, onChange) => /* @__PURE__ */ jsx("div", { className: "cc-print-design-theme-options", role: "group", "aria-label": "\u7F16\u8F91\u5668\u4E3B\u9898", children: Object.keys(editorThemes).map((key) => {
21888
22691
  const theme = editorThemes[key];
21889
22692
  return /* @__PURE__ */ jsxs(
21890
- "button",
22693
+ ReactButton,
21891
22694
  {
21892
- type: "button",
22695
+ type: (preferences.theme ?? "light") === key ? "primary" : "default",
21893
22696
  className: "cc-print-design-theme-option",
21894
22697
  "aria-pressed": (preferences.theme ?? "light") === key,
21895
22698
  disabled: readonly,
@@ -22314,6 +23117,80 @@ var settingsInteractionTool = {
22314
23117
  sectionId: "interaction",
22315
23118
  settingsSections: interactionSettingsSections
22316
23119
  };
23120
+ var keyboardMoveSettingsSections = [
23121
+ {
23122
+ sectionId: "keyboard-move",
23123
+ title: "\u952E\u76D8\u79FB\u52A8",
23124
+ fields: [
23125
+ {
23126
+ path: "canvas.keyboardMoveStep",
23127
+ label: "\u65B9\u5411\u952E\u6B65\u957F",
23128
+ kind: "number",
23129
+ persistence: "local",
23130
+ min: 1e-3,
23131
+ read: ({ settings, preferences }) => toDisplayUnit(
23132
+ settings.keyboardMoveStep ?? 1,
23133
+ preferences.displayUnit
23134
+ ),
23135
+ write: (value, { preferences }) => ({
23136
+ kind: "canvas",
23137
+ patch: {
23138
+ keyboardMoveStep: Math.max(
23139
+ 0.01,
23140
+ fromDisplayUnit(value, preferences.displayUnit)
23141
+ )
23142
+ }
23143
+ })
23144
+ },
23145
+ {
23146
+ path: "canvas.keyboardMoveAcceleration",
23147
+ label: "\u957F\u6309\u52A0\u901F",
23148
+ kind: "toggle",
23149
+ persistence: "local",
23150
+ onLabel: "\u5F00\u542F",
23151
+ offLabel: "\u5173\u95ED",
23152
+ read: ({ settings }) => settings.keyboardMoveAcceleration ?? false,
23153
+ write: (keyboardMoveAcceleration) => ({
23154
+ kind: "canvas",
23155
+ patch: { keyboardMoveAcceleration }
23156
+ })
23157
+ },
23158
+ {
23159
+ path: "help.keyboardMove",
23160
+ label: "\u64CD\u4F5C\u63D0\u793A",
23161
+ kind: "hint",
23162
+ persistence: "session",
23163
+ read: () => "\u9009\u4E2D\u7EC4\u4EF6\u540E\u7528\u65B9\u5411\u952E\u79FB\u52A8\uFF1B\u6309\u4F4F\u65B9\u5411\u952E\u8FDE\u7EED\u79FB\u52A8\uFF0C\u53EF\u914D\u7F6E\u662F\u5426\u52A0\u901F\uFF1B\u6309\u4F4F Shift \u53EF\u6309\u5341\u500D\u6B65\u957F\u79FB\u52A8\u3002"
23164
+ }
23165
+ ]
23166
+ }
23167
+ ];
23168
+
23169
+ // src/tools/settings-keyboard-move/react.tsx
23170
+ var settingsKeyboardMoveTool = {
23171
+ toolId: "builtin.settings.keyboard-move",
23172
+ version: "0.1.0",
23173
+ label: "\u952E\u76D8\u79FB\u52A8",
23174
+ order: 60,
23175
+ placement: "section",
23176
+ parentToolId: "builtin.settings",
23177
+ sectionId: "keyboard-move",
23178
+ settingsSections: keyboardMoveSettingsSections,
23179
+ resolveKeyboardMove(event, heldMs, settings) {
23180
+ const direction = {
23181
+ ArrowLeft: { dx: -1, dy: 0 },
23182
+ ArrowRight: { dx: 1, dy: 0 },
23183
+ ArrowUp: { dx: 0, dy: -1 },
23184
+ ArrowDown: { dx: 0, dy: 1 }
23185
+ }[event.key];
23186
+ if (!direction) return null;
23187
+ const configuredStep = settings.keyboardMoveStep ?? 1;
23188
+ const baseStep = Number.isFinite(configuredStep) && configuredStep > 0 ? configuredStep : 1;
23189
+ const acceleration = settings.keyboardMoveAcceleration === true ? heldMs >= 1800 ? 10 : heldMs >= 1e3 ? 5 : heldMs >= 500 ? 2 : 1 : 1;
23190
+ const step = baseStep * acceleration * (event.shiftKey ? 10 : 1);
23191
+ return { dx: direction.dx * step, dy: direction.dy * step };
23192
+ }
23193
+ };
22317
23194
 
22318
23195
  // src/tools/settings-indicators/properties.ts
22319
23196
  var indicatorSettingsSections = [{
@@ -22405,11 +23282,13 @@ var builtinReactTools = [
22405
23282
  settingsRulersTool,
22406
23283
  settingsGuidesTool,
22407
23284
  settingsInteractionTool,
23285
+ settingsKeyboardMoveTool,
22408
23286
  settingsIndicatorsTool,
22409
23287
  pluginmarketTool
22410
23288
  ];
22411
23289
  var builtinReactComponentPlugins = [
22412
23290
  textPlugin,
23291
+ richTextPlugin,
22413
23292
  listPlugin,
22414
23293
  dateTimePlugin,
22415
23294
  moneyUpperPlugin,
@@ -22433,17 +23312,17 @@ var builtinReactComponentPlugins = [
22433
23312
  pivotTablePlugin,
22434
23313
  ganttPlugin
22435
23314
  ];
22436
- var menuGroups24 = /* @__PURE__ */ new Map();
23315
+ var menuGroups25 = /* @__PURE__ */ new Map();
22437
23316
  for (const plugin of builtinReactComponentPlugins) {
22438
23317
  for (const group of plugin.menuGroups) {
22439
- const current2 = menuGroups24.get(group.id);
23318
+ const current2 = menuGroups25.get(group.id);
22440
23319
  if (current2) {
22441
23320
  if (current2.title !== group.title || current2.order !== group.order) {
22442
23321
  throw new Error(`\u83DC\u5355\u5206\u7EC4\u5B9A\u4E49\u4E0D\u4E00\u81F4\uFF1A${group.id}`);
22443
23322
  }
22444
23323
  current2.items.push(...group.items);
22445
23324
  } else {
22446
- menuGroups24.set(group.id, { ...group, items: [...group.items] });
23325
+ menuGroups25.set(group.id, { ...group, items: [...group.items] });
22447
23326
  }
22448
23327
  }
22449
23328
  }
@@ -22484,7 +23363,7 @@ var builtinPrintDesignPlugins = Object.freeze({
22484
23363
  componentFactories: new PrintDesignComponentFactoryRegistry(
22485
23364
  builtinReactComponentPlugins.map((plugin) => plugin.factory)
22486
23365
  ),
22487
- componentMenu: [...menuGroups24.values()].sort((a, b) => a.order - b.order).map((group) => ({
23366
+ componentMenu: [...menuGroups25.values()].sort((a, b) => a.order - b.order).map((group) => ({
22488
23367
  id: group.id,
22489
23368
  title: group.title,
22490
23369
  items: group.items.sort((a, b) => a.order - b.order)