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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/react.cjs CHANGED
@@ -10,6 +10,7 @@ var utils = require('@canvas-components/utils');
10
10
  var react = require('react');
11
11
  var reactComponents = require('@canvas-components/react-components');
12
12
  var jsxRuntime = require('react/jsx-runtime');
13
+ var acorn = require('acorn');
13
14
 
14
15
  // src/react.ts
15
16
 
@@ -50,7 +51,9 @@ function assertNativePluginDependencies(plugins) {
50
51
  function validateTextElement(value) {
51
52
  if (!value || typeof value !== "object") return false;
52
53
  const element = value;
53
- 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(
54
+ 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(
55
+ (value2) => Number.isFinite(value2) && value2 >= 0
56
+ )) && (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(
54
57
  (rule) => rule && Number.isInteger(rule.maxChars) && rule.maxChars >= 1 && Number.isFinite(rule.fontSize) && rule.fontSize > 0
55
58
  ));
56
59
  }
@@ -66,23 +69,36 @@ function graphemes(text) {
66
69
  function drawVerticalText(ctx, text, box, options) {
67
70
  if (box.width <= 0 || box.height <= 0) return;
68
71
  const step = Math.max(1, options.fontSize * options.lineHeight);
69
- const capacity = Math.max(1, Math.floor(box.height / step));
70
72
  const paragraphs = text.split(/\r?\n/).map(graphemes);
71
73
  const columns = paragraphs.flatMap((chars) => {
72
- if (!options.wrap || chars.length <= capacity) return [chars];
73
74
  const chunks = [];
74
- for (let index = 0; index < chars.length; index += capacity)
75
- chunks.push(chars.slice(index, index + capacity));
75
+ let offset = 0;
76
+ do {
77
+ const indent = options.indentMode === "firstLine" ? chunks.length === 0 ? options.indent ?? 0 : 0 : options.indentMode === "hanging" && chunks.length > 0 ? options.indent ?? 0 : 0;
78
+ const capacity = Math.max(1, Math.floor((box.height - indent) / step));
79
+ chunks.push({
80
+ chars: options.wrap === false ? chars.slice(offset) : chars.slice(offset, offset + capacity),
81
+ indent
82
+ });
83
+ offset += capacity;
84
+ } while (options.wrap !== false && offset < chars.length);
76
85
  return chunks;
77
86
  });
78
87
  const visibleCount = Math.max(1, Math.floor(box.width / step));
79
88
  const visible = columns.slice(0, visibleCount);
80
- const overflowed = columns.length > visibleCount || !options.wrap && visible.some((chars) => chars.length > capacity);
89
+ const overflowed = columns.length > visibleCount || !options.wrap && visible.some(
90
+ ({ chars, indent }) => chars.length > Math.max(1, Math.floor((box.height - indent) / step))
91
+ );
81
92
  if (options.ellipsis && overflowed && visible.length) {
82
- const last = [...visible[visible.length - 1]];
93
+ const previous = visible[visible.length - 1];
94
+ const capacity = Math.max(
95
+ 1,
96
+ Math.floor((box.height - previous.indent) / step)
97
+ );
98
+ const last = [...previous.chars];
83
99
  last.length = Math.min(last.length, capacity);
84
100
  last[Math.max(0, Math.min(last.length, capacity) - 1)] = "\u2026";
85
- visible[visible.length - 1] = last;
101
+ visible[visible.length - 1] = { ...previous, chars: last };
86
102
  }
87
103
  const blockWidth = visible.length * step;
88
104
  const left = options.align === "left" ? box.x : options.align === "center" ? box.x + (box.width - blockWidth) / 2 : box.x + box.width - blockWidth;
@@ -92,12 +108,17 @@ function drawVerticalText(ctx, text, box, options) {
92
108
  ctx.clip();
93
109
  ctx.textAlign = "center";
94
110
  ctx.textBaseline = "middle";
95
- visible.forEach((chars, column) => {
111
+ visible.forEach(({ chars, indent }, column) => {
96
112
  const textHeight = chars.length * step;
97
- const offset = options.verticalAlign === "bottom" ? Math.max(0, box.height - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (box.height - textHeight) / 2) : 0;
113
+ const availableHeight = Math.max(0, box.height - indent);
114
+ const offset = options.verticalAlign === "bottom" ? Math.max(0, availableHeight - textHeight) : options.verticalAlign === "middle" ? Math.max(0, (availableHeight - textHeight) / 2) : 0;
98
115
  const centerX = left + blockWidth - (column + 0.5) * step;
99
116
  chars.forEach(
100
- (char, index) => ctx.fillText(char, centerX, box.y + offset + (index + 0.5) * step)
117
+ (char, index) => ctx.fillText(
118
+ char,
119
+ centerX,
120
+ box.y + indent + offset + (index + 0.5) * step
121
+ )
101
122
  );
102
123
  });
103
124
  ctx.restore();
@@ -138,15 +159,16 @@ function getTextLayoutCache(ctx) {
138
159
  }
139
160
  return entry;
140
161
  }
141
- function layoutSpacedText(ctx, text, width, prewrapped = false) {
162
+ function layoutSpacedText(ctx, text, width, prewrapped = false, indent) {
142
163
  const cache = getTextLayoutCache(ctx);
143
- const key = `${prewrapped}:${width}\0${text}`;
164
+ const key = `${prewrapped}:${width}:${indent?.mode ?? "none"}:${indent?.value ?? 0}\0${text}`;
144
165
  let lines = cache.lines.get(key);
145
166
  if (!lines) {
146
167
  lines = prewrapped ? text.split("\n").map((text2) => ({ text: text2, last: true })) : layoutAlignedText(
147
168
  text,
148
169
  width,
149
- (value) => measureSpacedText(ctx, value)
170
+ (value) => measureSpacedText(ctx, value),
171
+ indent
150
172
  );
151
173
  if (cache.lines.size >= 128) cache.lines.clear();
152
174
  cache.lines.set(key, lines);
@@ -200,28 +222,30 @@ function drawSpacedText(ctx, text, x, y) {
200
222
  });
201
223
  ctx.textAlign = align;
202
224
  }
203
- function layoutAlignedText(text, width, measure) {
225
+ function layoutAlignedText(text, width, measure, indent) {
204
226
  return text.split("\n").flatMap((paragraph) => {
205
227
  const lines = [];
206
228
  let line = "";
229
+ const indentation = (index) => indent?.mode === "firstLine" ? index === 0 ? indent.value : 0 : indent?.mode === "hanging" && index > 0 ? indent.value : 0;
207
230
  const tokens = paragraph.match(
208
231
  /[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}]+|\s+|[^\p{Script=Latin}\p{N}\s]+/gu
209
232
  ) ?? [];
210
233
  const pieces = tokens.flatMap(
211
234
  (token) => /^(?:[¥¥$€£]?\p{N}+(?:[.,:/-]\p{N}+)*(?:[%%])?|[\p{Script=Latin}\p{N}\s]+)$/u.test(
212
235
  token
213
- ) && measure(token) <= width ? [token] : graphemes(token)
236
+ ) && measure(token) <= Math.max(1, width - Math.max(0, indent?.value ?? 0)) ? [token] : graphemes(token)
214
237
  );
215
238
  for (const piece of pieces) {
216
- if (line && measure(line + piece) > width) {
217
- lines.push(line.trimEnd());
239
+ if (line && measure(line + piece) > Math.max(1, width - indentation(lines.length))) {
240
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
218
241
  line = "";
219
242
  }
220
243
  if (line || piece.trim()) line += piece;
221
244
  }
222
- lines.push(line.trimEnd());
245
+ lines.push({ text: line.trimEnd(), indent: indentation(lines.length) });
223
246
  return lines.map((value, index) => ({
224
- text: value,
247
+ text: value.text,
248
+ ...indent && indent.mode !== "none" && indent.value > 0 ? { indent: value.indent } : {},
225
249
  last: index === lines.length - 1
226
250
  }));
227
251
  });
@@ -247,13 +271,7 @@ function drawAlignedTextLine(ctx, text, x, y, width, distributed) {
247
271
  });
248
272
  }
249
273
  function resolveTextFontFamily(family) {
250
- const selected = family?.trim();
251
- if (!selected) return printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY;
252
- if (/\bPrintDesignNotoSansSC\b/i.test(selected)) return selected;
253
- if (!/(?:^|,)\s*['"]?Times New Roman['"]?(?:,|$)/i.test(selected) && !/(?:^|,)\s*serif\s*$/i.test(selected))
254
- return selected;
255
- const generic = /,\s*(sans-serif|serif|monospace|cursive|fantasy|system-ui)\s*$/i;
256
- return generic.test(selected) ? selected.replace(generic, ", PrintDesignNotoSansSC, $1") : `${selected}, PrintDesignNotoSansSC`;
274
+ return printDesign.resolvePrintDesignFontFamily(family);
257
275
  }
258
276
 
259
277
  // src/plugins/text/layout/measure.ts
@@ -271,7 +289,7 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
271
289
  widths = /* @__PURE__ */ new Map();
272
290
  widthCaches.set(ownerDocument, widths);
273
291
  }
274
- const font = `${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
292
+ const font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}pt ${resolveTextFontFamily(element.fontFamily)}`;
275
293
  let span;
276
294
  return {
277
295
  measure: (value) => {
@@ -302,6 +320,12 @@ function createHtmlTextMeasure(element, fontSize, fallback) {
302
320
  dispose: () => span?.remove()
303
321
  };
304
322
  }
323
+ function resolveTextIndentMm(element, fontSizePt) {
324
+ if (!element.indentMode || element.indentMode === "none") return 0;
325
+ const value = Math.max(0, element.indentValue ?? 0);
326
+ if (!Number.isFinite(value)) return 0;
327
+ return element.indentUnit === "char" || !element.indentUnit ? value * fontSizePt * 25.4 / 72 : printDesign.fromDisplayUnit(value, element.indentUnit);
328
+ }
305
329
 
306
330
  // src/plugins/text/rendering/formatting.ts
307
331
  function resolveTextFontSize(element, text) {
@@ -321,20 +345,20 @@ function ellipsizeTextLine(text, maxWidth, measure) {
321
345
 
322
346
  // src/plugins/text/rendering/draw.ts
323
347
  var loadedFonts = /* @__PURE__ */ new WeakMap();
324
- var DEFAULT_TEXT_BASELINE_CORRECTION_RATIO = 0.05;
325
348
  function prepareTextFont(element, signal) {
326
349
  const family = element.fontFamily?.trim();
327
350
  const source = element.fontSource?.trim();
328
351
  if (!family || !source) return Promise.resolve();
329
352
  if (typeof document === "undefined" || typeof FontFace === "undefined")
330
- return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u52A0\u8F7D\u6253\u5370\u5B57\u4F53\u3002"));
353
+ return Promise.resolve();
331
354
  signal?.throwIfAborted();
332
- const ready = ensureTextFont(element, document);
355
+ const ready = ensureTextFont(element, document).catch(() => {
356
+ });
333
357
  if (!signal) return ready;
334
- return new Promise((resolve, reject) => {
358
+ return new Promise((resolve2, reject) => {
335
359
  const onAbort = () => reject(signal.reason);
336
360
  signal.addEventListener("abort", onAbort, { once: true });
337
- void ready.then(resolve, reject).finally(() => signal.removeEventListener("abort", onAbort));
361
+ void ready.then(resolve2, reject).finally(() => signal.removeEventListener("abort", onAbort));
338
362
  });
339
363
  }
340
364
  function loadTextFont(element, ctx, onLoad) {
@@ -396,7 +420,7 @@ var drawTextElement = (element, context) => {
396
420
  const resolvedFontSize = resolveTextFontSize(element, resolvedText);
397
421
  const fontSize = resolvedFontSize * 25.4 * scale / 72;
398
422
  ctx.fillStyle = element.color ?? "#1f2937";
399
- ctx.font = `${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
423
+ ctx.font = `${element.fontStyle ?? "normal"} ${element.fontWeight ?? "400"} ${fontSize}px ${resolveTextFontFamily(element.fontFamily)}`;
400
424
  const expanded = element.textAlign === "justify" || element.textAlign === "distributed";
401
425
  ctx.textAlign = expanded ? "left" : element.textAlign ?? "left";
402
426
  ctx.textBaseline = "alphabetic";
@@ -411,7 +435,9 @@ var drawTextElement = (element, context) => {
411
435
  align: element.textAlign === "left" || element.textAlign === "center" ? element.textAlign : "right",
412
436
  verticalAlign: element.verticalAlign,
413
437
  wrap: true,
414
- ellipsis: element.heightOverflow === "ellipsis"
438
+ ellipsis: element.heightOverflow === "ellipsis",
439
+ indentMode: element.indentMode,
440
+ indent: resolveTextIndentMm(element, resolvedFontSize) * scale
415
441
  }
416
442
  );
417
443
  return;
@@ -420,19 +446,31 @@ var drawTextElement = (element, context) => {
420
446
  const fontMetrics = ctx.measureText?.("Hg");
421
447
  const ascent = fontMetrics?.fontBoundingBoxAscent ?? fontSize * 0.8;
422
448
  const descent = fontMetrics?.fontBoundingBoxDescent ?? fontSize * 0.2;
423
- const defaultFont = !element.fontFamily || element.fontFamily === printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY;
424
- const regularNoto = element.fontFamily?.startsWith("PrintDesignNotoSansSC") && !/^(?:bold|[6-9]00)$/i.test(element.fontWeight ?? "400");
425
- const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent - (defaultFont || regularNoto ? fontSize * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO : 0);
449
+ const baselineOffset = (lineHeight - ascent - descent) / 2 + ascent;
426
450
  const measure = (text) => measureSpacedText(ctx, text);
427
- let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped);
451
+ const indentPx = resolveTextIndentMm(element, resolvedFontSize) * scale;
452
+ let lines = layoutSpacedText(ctx, resolvedText, width, element.prewrapped, {
453
+ mode: element.indentMode ?? "none",
454
+ value: indentPx
455
+ });
456
+ if (element.prewrappedIndents)
457
+ lines = lines.map((line, index) => ({
458
+ ...line,
459
+ indent: (element.prewrappedIndents?.[index] ?? 0) * scale
460
+ }));
428
461
  if (element.heightOverflow) {
429
462
  const fit = Math.max(0, Math.floor(height / lineHeight));
430
463
  if (lines.length > fit) {
431
464
  lines = lines.slice(0, fit);
432
465
  if (fit && element.heightOverflow === "ellipsis")
433
466
  lines[fit - 1] = {
434
- text: ellipsizeTextLine(lines[fit - 1].text, width, measure),
435
- last: true
467
+ text: ellipsizeTextLine(
468
+ lines[fit - 1].text,
469
+ Math.max(1, width - (lines[fit - 1].indent ?? 0)),
470
+ measure
471
+ ),
472
+ last: true,
473
+ indent: lines[fit - 1].indent
436
474
  };
437
475
  }
438
476
  ctx.beginPath();
@@ -440,16 +478,22 @@ var drawTextElement = (element, context) => {
440
478
  ctx.clip();
441
479
  }
442
480
  const verticalOffset = element.verticalAlign === "middle" ? Math.max(0, (height - lines.length * lineHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - lines.length * lineHeight) : 0;
443
- const textX = element.textAlign === "center" ? x + width / 2 : element.textAlign === "right" ? x + width : x;
444
481
  lines.forEach((line, index) => {
445
482
  const lineY = y + verticalOffset + index * lineHeight + baselineOffset;
483
+ const lineIndent = Math.min(
484
+ Math.max(0, line.indent ?? 0),
485
+ Math.max(0, width)
486
+ );
487
+ const lineLeft = x + lineIndent;
488
+ const lineWidth = Math.max(0, width - lineIndent);
489
+ const textX = element.textAlign === "center" ? lineLeft + lineWidth / 2 : element.textAlign === "right" ? x + width : lineLeft;
446
490
  if (expanded && (element.textAlign === "distributed" || !line.last)) {
447
491
  drawAlignedTextLine(
448
492
  ctx,
449
493
  line.text,
450
- x,
494
+ lineLeft,
451
495
  lineY,
452
- width,
496
+ lineWidth,
453
497
  element.textAlign === "distributed"
454
498
  );
455
499
  } else {
@@ -460,8 +504,8 @@ var drawTextElement = (element, context) => {
460
504
  Math.max(0, Math.floor(element.underlineCount ?? 0))
461
505
  );
462
506
  if (!count || !line.text) return;
463
- const textWidth = Math.min(width, measure(line.text));
464
- const left = expanded && (element.textAlign === "distributed" || !line.last) ? x : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
507
+ const textWidth = Math.min(lineWidth, measure(line.text));
508
+ const left = expanded && (element.textAlign === "distributed" || !line.last) ? lineLeft : element.textAlign === "center" ? textX - textWidth / 2 : element.textAlign === "right" ? textX - textWidth : textX;
465
509
  ctx.save();
466
510
  ctx.strokeStyle = element.underlineColor ?? element.color ?? "#1f2937";
467
511
  ctx.lineWidth = Math.max(0.5, (element.underlineWidth ?? 0.2) * scale);
@@ -512,13 +556,24 @@ function textMarkup(text, element, size = 14, color2 = "#1f2937") {
512
556
  const weight = /^(?:[1-9]00|normal|bold)$/.test(
513
557
  textElement?.fontWeight ?? "400"
514
558
  ) ? textElement?.fontWeight ?? "400" : "400";
559
+ const fontStyle = textElement?.fontStyle === "italic" ? "italic" : "normal";
515
560
  const fontSize = textElement ? resolveTextFontSize(textElement, text) : printDesign.cssNumber(size, 14);
516
- if (textElement?.textDirection === "vertical")
517
- return `<div class="pd-text" style="display:block;font:${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${printDesign.cssNumber(textElement.lineHeight, 1.35)}">${printDesign.escapeHtml(text)}</div>`;
561
+ if (textElement?.textDirection === "vertical") {
562
+ const indentMm2 = resolveTextIndentMm(textElement, fontSize);
563
+ const paragraphStyle = indentMm2 <= 0 ? "" : textElement.indentMode === "firstLine" ? `text-indent:${printDesign.cssNumber(indentMm2, 0)}mm;` : `padding-top:${printDesign.cssNumber(indentMm2, 0)}mm;text-indent:-${printDesign.cssNumber(indentMm2, 0)}mm;box-sizing:border-box;`;
564
+ const content = indentMm2 > 0 ? text.split("\n").map(
565
+ (paragraph) => `<div style="${paragraphStyle}">${printDesign.escapeHtml(paragraph) || "<br>"}</div>`
566
+ ).join("") : printDesign.escapeHtml(text);
567
+ return `<div class="pd-text" style="display:block;font:${fontStyle} ${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};writing-mode:vertical-rl;text-orientation:upright;white-space:pre-wrap;text-align:${vertical === "middle" ? "center" : vertical === "bottom" ? "end" : "start"};line-height:${printDesign.cssNumber(textElement.lineHeight, 1.35)}">${content}</div>`;
568
+ }
569
+ const indentMm = textElement ? resolveTextIndentMm(textElement, fontSize) : 0;
570
+ const indentStyle = (lineIndex) => indentMm > 0 && textElement ? textElement.indentMode === "firstLine" ? lineIndex === 0 ? `text-indent:${printDesign.cssNumber(indentMm, 0)}mm;` : "" : textElement.indentMode === "hanging" ? `padding-left:${printDesign.cssNumber(indentMm, 0)}mm;text-indent:${`-${printDesign.cssNumber(indentMm, 0)}mm` };box-sizing:border-box;` : "" : "";
518
571
  const lines = textElement?.prewrapped ? text.split("\n").map(
519
- (line) => `<div style="white-space:pre;overflow:hidden;flex:none"><span style="${underlineCss(textElement)}">${printDesign.escapeHtml(line) || "<br>"}</span></div>`
572
+ (line, index) => `<div style="white-space:pre;overflow:hidden;flex:none${textElement.prewrappedIndents ? `;box-sizing:border-box;padding-left:${printDesign.cssNumber(textElement.prewrappedIndents[index] ?? 0, 0)}mm` : ""}"><span style="${underlineCss(textElement)}">${printDesign.escapeHtml(line) || "<br>"}</span></div>`
573
+ ).join("") : indentMm > 0 ? text.split("\n").map(
574
+ (paragraph) => `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere;${indentStyle(0)}"><span style="${textElement ? underlineCss(textElement) : ""}">${printDesign.escapeHtml(paragraph) || "<br>"}</span></div>`
520
575
  ).join("") : `<div style="min-width:0;white-space:pre-wrap;overflow-wrap:anywhere"><span style="${textElement ? underlineCss(textElement) : ""}">${printDesign.escapeHtml(text)}</span></div>`;
521
- return `<div class="pd-text" style="font:${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};text-align:${align};line-height:${printDesign.cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
576
+ return `<div class="pd-text" style="font:${fontStyle} ${weight} ${fontSize}pt ${printDesign.escapeHtml(printDesign.cssFont(resolveTextFontFamily(textElement?.fontFamily)))};color:${printDesign.cssColor(color2, "#1f2937")};text-align:${align};line-height:${printDesign.cssNumber(textElement?.lineHeight, 1.35)};justify-content:${vertical === "middle" ? "center" : vertical === "bottom" ? "flex-end" : "flex-start"}">${lines}</div>`;
522
577
  }
523
578
  function underlineCss(element) {
524
579
  const count = Math.min(
@@ -553,6 +608,18 @@ function textFontCss(element) {
553
608
  return `@font-face{font-family:${printDesign.cssFont(element.fontFamily)};src:url("${source}")}`;
554
609
  }
555
610
  var PT_TO_MM = 25.4 / 72;
611
+ function layoutText(element, text, measure) {
612
+ if (element.prewrapped)
613
+ return text.split("\n").map((line, index) => ({
614
+ text: line,
615
+ last: true,
616
+ indent: element.prewrappedIndents?.[index] ?? 0
617
+ }));
618
+ return layoutAlignedText(text, element.width, measure, {
619
+ mode: element.indentMode ?? "none",
620
+ value: resolveTextIndentMm(element, resolveTextFontSize(element, text))
621
+ });
622
+ }
556
623
  function paginateText(element, { data, startPage, startY, top, bottom, pageAt }) {
557
624
  const text = element.dataConfig?.mode === "binding" ? element.text : printDesign.resolveDesignText(element.text, data);
558
625
  if (element.textDirection === "vertical") {
@@ -580,9 +647,7 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
580
647
  );
581
648
  let lines;
582
649
  try {
583
- lines = layoutAlignedText(text, element.width, measurement.measure).map(
584
- (line) => line.text
585
- );
650
+ lines = layoutText(element, text, measurement.measure);
586
651
  } finally {
587
652
  measurement.dispose();
588
653
  }
@@ -611,7 +676,8 @@ function paginateText(element, { data, startPage, startY, top, bottom, pageAt })
611
676
  previewSourceId: element.previewSourceId ?? element.id,
612
677
  y,
613
678
  height,
614
- text: chunk.join("\n"),
679
+ text: chunk.map((line) => line.text).join("\n"),
680
+ ...element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? { prewrappedIndents: chunk.map((line) => line.indent ?? 0) } : {},
615
681
  prewrapped: true,
616
682
  verticalAlign: "top",
617
683
  dataConfig: void 0
@@ -639,7 +705,11 @@ function prewrapText(element) {
639
705
  (value) => estimateTextWidth(value, fontMm)
640
706
  );
641
707
  try {
642
- return layoutAlignedText(element.text, element.width, measurement.measure).map((line) => line.text).join("\n");
708
+ const lines = layoutText(element, element.text, measurement.measure);
709
+ return {
710
+ text: lines.map((line) => line.text).join("\n"),
711
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? lines.map((line) => line.indent ?? 0) : void 0
712
+ };
643
713
  } finally {
644
714
  measurement.dispose();
645
715
  }
@@ -652,12 +722,12 @@ function estimateTextHeight(element) {
652
722
  (value) => estimateTextWidth(value, fontMm)
653
723
  );
654
724
  try {
655
- return layoutAlignedText(element.text, element.width, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
725
+ return layoutText(element, element.text, measurement.measure).length * fontMm * (element.lineHeight ?? 1.35);
656
726
  } finally {
657
727
  measurement.dispose();
658
728
  }
659
729
  }
660
- function truncateText(element, height, mode) {
730
+ function truncateTextLayout(element, height, mode) {
661
731
  const fontMm = Math.max(1, (element.fontSize ?? 14) * PT_TO_MM);
662
732
  const lineMm = fontMm * (element.lineHeight ?? 1.35);
663
733
  const measurement = createHtmlTextMeasure(
@@ -666,21 +736,21 @@ function truncateText(element, height, mode) {
666
736
  (value) => estimateTextWidth(value, fontMm)
667
737
  );
668
738
  try {
669
- const lines = layoutAlignedText(
670
- element.text,
671
- element.width,
672
- measurement.measure
673
- );
739
+ const lines = layoutText(element, element.text, measurement.measure);
674
740
  const fit = Math.max(0, Math.floor(height / lineMm));
675
- if (lines.length <= fit) return element.text;
676
- const visible = lines.slice(0, fit).map((line) => line.text);
741
+ const visibleLines = lines.slice(0, fit);
742
+ const visible = visibleLines.map((line) => line.text);
677
743
  if (fit && mode === "ellipsis")
678
744
  visible[fit - 1] = ellipsizeTextLine(
679
745
  visible[fit - 1],
680
- element.width,
746
+ Math.max(1, element.width - (lines[fit - 1]?.indent ?? 0)),
681
747
  measurement.measure
682
748
  );
683
- return visible.join("\n");
749
+ return {
750
+ text: visible.join("\n"),
751
+ indents: element.indentMode && element.indentMode !== "none" && (element.indentValue ?? 0) > 0 ? visibleLines.map((line) => line.indent ?? 0) : void 0,
752
+ overflowed: lines.length > fit
753
+ };
684
754
  } finally {
685
755
  measurement.dispose();
686
756
  }
@@ -710,11 +780,13 @@ function prepareTextPagination(element, data) {
710
780
  };
711
781
  if (element.textDirection === "vertical" || element.overflowPolicy === "split" || element.heightOverflow === "flow" && element.overflowPolicy !== "nextPage")
712
782
  return prepared;
713
- const printable = element.heightOverflow && element.heightOverflow !== "flow" ? {
783
+ const wrapped = element.heightOverflow && element.heightOverflow !== "flow" ? truncateTextLayout(prepared, prepared.height, element.heightOverflow) : prewrapText(prepared);
784
+ return {
714
785
  ...prepared,
715
- text: truncateText(prepared, prepared.height, element.heightOverflow)
716
- } : prepared;
717
- return { ...printable, text: prewrapText(printable), prewrapped: true };
786
+ text: wrapped.text,
787
+ ...wrapped.indents ? { prewrappedIndents: wrapped.indents } : {},
788
+ prewrapped: true
789
+ };
718
790
  }
719
791
  function measureTextFlowHeight(element, data) {
720
792
  if (element.heightOverflow && element.heightOverflow !== "flow")
@@ -723,7 +795,13 @@ function measureTextFlowHeight(element, data) {
723
795
  return Math.max(prepared.height, estimateTextHeight(prepared));
724
796
  }
725
797
  function truncateTextOverflow(element, height, mode) {
726
- return { ...element, text: truncateText(element, height, mode) };
798
+ const truncated = truncateTextLayout(element, height, mode);
799
+ return {
800
+ ...element,
801
+ text: truncated.text,
802
+ prewrapped: true,
803
+ ...truncated.indents ? { prewrappedIndents: truncated.indents } : {}
804
+ };
727
805
  }
728
806
  function registeredFieldBindingInfo(element, fields) {
729
807
  const config = printDesign.getPrintDesignElementDataConfig(element, fields);
@@ -796,14 +874,14 @@ function resolveTextFontSizeValue(value, defaultUnit = "mm") {
796
874
  // src/plugins/text/data/binding.ts
797
875
  function getTextBindingInfo(element) {
798
876
  const content = registeredFieldBindingInfo(element, textDataFields);
799
- const paths = [
877
+ const paths2 = [
800
878
  ...content.paths,
801
879
  element.colorMode === "binding" ? element.colorPath : void 0,
802
880
  element.fontSizeMode === "binding" ? element.fontSizePath : void 0
803
881
  ].filter((path) => !!path?.trim());
804
882
  return {
805
883
  bound: content.bound || element.colorMode === "binding" || element.fontSizeMode === "binding",
806
- paths
884
+ paths: paths2
807
885
  };
808
886
  }
809
887
  function missingExpressionPath(expression, data) {
@@ -863,7 +941,7 @@ function resolveTextData(element, data) {
863
941
  // src/plugins/text/native.ts
864
942
  var textNativePlugin = defineNativePlugin(
865
943
  "text",
866
- "0.1.34",
944
+ "0.1.38",
867
945
  printDesign.definePrintDesignPluginRenderer({
868
946
  type: "text",
869
947
  dataFields: textDataFields,
@@ -886,6 +964,268 @@ var textNativePlugin = defineNativePlugin(
886
964
  inlineTextEditor: textInlineEditor
887
965
  })
888
966
  );
967
+
968
+ // src/plugins/rich-text/model.ts
969
+ function validateRichTextElement(value) {
970
+ if (!value || typeof value !== "object") return false;
971
+ const element = value;
972
+ return element.type === "richText" && (element.dataConfig === void 0 || element.dataConfig.mode === "static") && Array.isArray(element.runs) && element.runs.length <= 2e3 && element.runs.reduce(
973
+ (length, run) => length + (typeof run?.text === "string" ? run.text.length : 0),
974
+ 0
975
+ ) <= 1e5 && element.runs.every(
976
+ (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(
977
+ (key) => ["fontFamily", "fontSize", "fontWeight", "fontStyle", "color"].includes(key)
978
+ ) && (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)))
979
+ ) && (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(
980
+ (indent) => Number.isFinite(indent) && indent >= 0
981
+ ));
982
+ }
983
+ function richTextIndentMm(element) {
984
+ if (!element.indentMode || element.indentMode === "none") return 0;
985
+ const value = Math.max(0, element.indentValue ?? 0);
986
+ return element.indentUnit === "char" || !element.indentUnit ? value * (element.fontSize ?? 14) * 25.4 / 72 : printDesign.fromDisplayUnit(value, element.indentUnit);
987
+ }
988
+ function richTextGraphemes(text) {
989
+ const Segmenter = Intl.Segmenter;
990
+ return Segmenter ? Array.from(
991
+ new Segmenter(void 0, { granularity: "grapheme" }).segment(text),
992
+ (part) => part.segment
993
+ ) : Array.from(text);
994
+ }
995
+
996
+ // src/plugins/rich-text/rendering.ts
997
+ function runStyle(element, run) {
998
+ return {
999
+ fontFamily: printDesign.resolvePrintDesignFontFamily(
1000
+ run.style?.fontFamily ?? element.fontFamily
1001
+ ),
1002
+ fontSize: run.style?.fontSize ?? element.fontSize ?? 14,
1003
+ fontWeight: run.style?.fontWeight ?? element.fontWeight ?? "400",
1004
+ fontStyle: run.style?.fontStyle ?? element.fontStyle ?? "normal",
1005
+ color: run.style?.color ?? element.color ?? "#1f2937"
1006
+ };
1007
+ }
1008
+ function layoutRichTextLines(element, width, scale, measure) {
1009
+ const indent = richTextIndentMm(element) * scale;
1010
+ const lineHeight = element.lineHeight ?? 1.35;
1011
+ const lines = [];
1012
+ let paragraphLine = 0;
1013
+ const addLine = () => {
1014
+ const inset = element.prewrapped ? (element.prewrappedIndents?.[lines.length] ?? 0) * scale : element.indentMode === "firstLine" && paragraphLine === 0 || element.indentMode === "hanging" && paragraphLine > 0 ? indent : 0;
1015
+ lines.push({
1016
+ chars: [],
1017
+ width: 0,
1018
+ indent: inset,
1019
+ height: (element.fontSize ?? 14) * 25.4 / 72 * scale * lineHeight
1020
+ });
1021
+ };
1022
+ addLine();
1023
+ for (const run of element.runs) {
1024
+ const style = runStyle(element, run);
1025
+ const fontSize = style.fontSize * 25.4 / 72 * scale;
1026
+ for (const char of richTextGraphemes(run.text.replace(/\r\n?/g, "\n"))) {
1027
+ if (char === "\n") {
1028
+ paragraphLine = 0;
1029
+ addLine();
1030
+ continue;
1031
+ }
1032
+ const charWidth = measure(char, style, fontSize);
1033
+ let line = lines[lines.length - 1];
1034
+ if (!element.prewrapped && line.chars.length && line.width + charWidth > Math.max(1, width - line.indent)) {
1035
+ paragraphLine++;
1036
+ addLine();
1037
+ line = lines[lines.length - 1];
1038
+ }
1039
+ line.chars.push({ text: char, width: charWidth, style });
1040
+ line.width += charWidth;
1041
+ line.height = Math.max(line.height, fontSize * lineHeight);
1042
+ }
1043
+ }
1044
+ return lines;
1045
+ }
1046
+ function drawRichTextElement(element, { ctx, scale, x, y, width, height }) {
1047
+ const lineHeight = element.lineHeight ?? 1.35;
1048
+ const lines = layoutRichTextLines(
1049
+ element,
1050
+ width,
1051
+ scale,
1052
+ (char, style, fontSize) => {
1053
+ ctx.font = `${style.fontStyle} ${style.fontWeight} ${fontSize}px ${style.fontFamily}`;
1054
+ return ctx.measureText(char).width;
1055
+ }
1056
+ );
1057
+ const totalHeight = lines.reduce((sum, line) => sum + line.height, 0);
1058
+ let top = y + (element.verticalAlign === "middle" ? Math.max(0, (height - totalHeight) / 2) : element.verticalAlign === "bottom" ? Math.max(0, height - totalHeight) : 0);
1059
+ ctx.save();
1060
+ ctx.beginPath();
1061
+ ctx.rect(x, y, width, height);
1062
+ ctx.clip();
1063
+ ctx.textAlign = "left";
1064
+ ctx.textBaseline = "alphabetic";
1065
+ for (const line of lines) {
1066
+ let left = x + line.indent;
1067
+ const available = Math.max(0, width - line.indent);
1068
+ if (element.textAlign === "center") left += (available - line.width) / 2;
1069
+ if (element.textAlign === "right") left += available - line.width;
1070
+ for (const char of line.chars) {
1071
+ const fontSize = char.style.fontSize * 25.4 / 72 * scale;
1072
+ ctx.font = `${char.style.fontStyle} ${char.style.fontWeight} ${fontSize}px ${char.style.fontFamily}`;
1073
+ ctx.fillStyle = char.style.color;
1074
+ ctx.fillText(
1075
+ char.text,
1076
+ left,
1077
+ top + (line.height - fontSize * lineHeight) / 2 + fontSize
1078
+ );
1079
+ left += char.width;
1080
+ }
1081
+ top += line.height;
1082
+ }
1083
+ ctx.restore();
1084
+ }
1085
+ function renderRichTextHtml(element) {
1086
+ const baseSize = printDesign.cssNumber(element.fontSize, 14);
1087
+ const indent = richTextIndentMm(element);
1088
+ const paragraphs = [""];
1089
+ for (const run of element.runs) {
1090
+ const style = runStyle(element, run);
1091
+ const css = `font-family:${printDesign.escapeHtml(printDesign.cssFont(style.fontFamily))};font-size:${printDesign.cssNumber(style.fontSize, baseSize)}pt;font-weight:${printDesign.escapeHtml(style.fontWeight)};font-style:${style.fontStyle};color:${printDesign.cssColor(style.color, "#1f2937")}`;
1092
+ const chunks = run.text.replace(/\r\n?/g, "\n").split("\n");
1093
+ chunks.forEach((chunk, index) => {
1094
+ if (index) paragraphs.push("");
1095
+ paragraphs[paragraphs.length - 1] += `<span style="${css}">${printDesign.escapeHtml(chunk)}</span>`;
1096
+ });
1097
+ }
1098
+ const paragraphCss = element.indentMode === "firstLine" && indent > 0 ? `text-indent:${printDesign.cssNumber(indent, 0)}mm;` : element.indentMode === "hanging" && indent > 0 ? `padding-left:${printDesign.cssNumber(indent, 0)}mm;text-indent:-${printDesign.cssNumber(indent, 0)}mm;box-sizing:border-box;` : "";
1099
+ const body = paragraphs.map(
1100
+ (paragraph, index) => `<div style="${element.prewrapped ? `white-space:pre;overflow:hidden;flex:none;box-sizing:border-box;padding-left:${printDesign.cssNumber(element.prewrappedIndents?.[index], 0)}mm;` : paragraphCss}">${paragraph || "<br>"}</div>`
1101
+ ).join("");
1102
+ return printDesign.renderPrintDesignHtmlFrame(
1103
+ element,
1104
+ `<div style="width:100%;height:100%;overflow:hidden;white-space:pre-wrap;overflow-wrap:anywhere;word-break:break-all;text-spacing-trim:space-all;text-autospace:no-autospace;line-height:${printDesign.cssNumber(element.lineHeight, 1.35)};font-family:${printDesign.escapeHtml(printDesign.cssFont(element.fontFamily))};font-size:${baseSize}pt;font-weight:${printDesign.escapeHtml(element.fontWeight ?? "400")};font-style:${element.fontStyle ?? "normal"};color:${printDesign.cssColor(element.color, "#1f2937")};text-align:${element.textAlign ?? "left"};display:flex;flex-direction:column;justify-content:${element.verticalAlign === "middle" ? "center" : element.verticalAlign === "bottom" ? "flex-end" : "flex-start"}">${body}</div>`
1105
+ );
1106
+ }
1107
+
1108
+ // src/plugins/rich-text/pagination.ts
1109
+ function measureLines(element) {
1110
+ const canvas = typeof document !== "undefined" ? document.createElement("canvas") : null;
1111
+ const context = canvas?.getContext("2d");
1112
+ return layoutRichTextLines(element, element.width, 1, (text, style, size) => {
1113
+ if (context) {
1114
+ context.font = `${style.fontStyle} ${style.fontWeight} ${size}px ${style.fontFamily}`;
1115
+ return context.measureText(text).width;
1116
+ }
1117
+ return size * (/[^\p{ASCII}]/u.test(text) ? 1 : 0.55);
1118
+ });
1119
+ }
1120
+ function linesToRuns(lines) {
1121
+ const result = [];
1122
+ for (const [index, line] of lines.entries()) {
1123
+ if (index) result.push({ text: "\n" });
1124
+ for (const char of line.chars) {
1125
+ const previous = result[result.length - 1];
1126
+ const style = char.style;
1127
+ if (previous && JSON.stringify(previous.style) === JSON.stringify(style))
1128
+ previous.text += char.text;
1129
+ else result.push({ text: char.text, style });
1130
+ }
1131
+ }
1132
+ return result;
1133
+ }
1134
+ function truncateRichTextOverflow(element, height, mode) {
1135
+ const lines = measureLines(element);
1136
+ const visible = [];
1137
+ let used = 0;
1138
+ for (const line of lines) {
1139
+ if (visible.length && used + line.height > height) break;
1140
+ visible.push({ ...line, chars: [...line.chars] });
1141
+ used += line.height;
1142
+ }
1143
+ if (mode === "ellipsis" && visible.length < lines.length && visible.length) {
1144
+ const last = visible[visible.length - 1];
1145
+ const style = last.chars[last.chars.length - 1]?.style ?? {
1146
+ fontFamily: element.fontFamily ?? "Arial, sans-serif",
1147
+ fontSize: element.fontSize ?? 14,
1148
+ fontWeight: element.fontWeight ?? "400",
1149
+ fontStyle: element.fontStyle ?? "normal",
1150
+ color: element.color ?? "#1f2937"
1151
+ };
1152
+ const ellipsisWidth = style.fontSize * 25.4 / 72;
1153
+ while (last.chars.length && last.width + ellipsisWidth > element.width - last.indent) {
1154
+ last.width -= last.chars.pop().width;
1155
+ }
1156
+ last.chars.push({ text: "\u2026", style, width: ellipsisWidth });
1157
+ last.width += ellipsisWidth;
1158
+ }
1159
+ return {
1160
+ ...element,
1161
+ runs: linesToRuns(visible),
1162
+ prewrapped: true,
1163
+ prewrappedIndents: visible.map((line) => line.indent),
1164
+ verticalAlign: "top"
1165
+ };
1166
+ }
1167
+ function paginateRichText(element, context) {
1168
+ const lines = measureLines(element);
1169
+ let pageIndex = context.startPage;
1170
+ let y = context.startY;
1171
+ let offset = 0;
1172
+ do {
1173
+ const remaining = () => context.bottom - y;
1174
+ if (remaining() < (lines[offset]?.height ?? 0) && y > context.top) {
1175
+ pageIndex++;
1176
+ y = context.top;
1177
+ }
1178
+ const chunk = [];
1179
+ let height = 0;
1180
+ while (offset < lines.length && (!chunk.length || height + lines[offset].height <= remaining())) {
1181
+ chunk.push(lines[offset]);
1182
+ height += lines[offset].height;
1183
+ offset++;
1184
+ }
1185
+ const continues = offset < lines.length;
1186
+ const finalHeight = continues ? Math.max(0, remaining()) : Math.max(height, element.height);
1187
+ context.pageAt(pageIndex).elements.push({
1188
+ ...element,
1189
+ id: `${element.id}:flow:${pageIndex}`,
1190
+ previewSourceId: element.previewSourceId ?? element.id,
1191
+ y,
1192
+ height: Math.min(Math.max(0, remaining()), finalHeight),
1193
+ runs: linesToRuns(chunk),
1194
+ prewrapped: true,
1195
+ prewrappedIndents: chunk.map((line) => line.indent),
1196
+ verticalAlign: "top"
1197
+ });
1198
+ y += Math.min(Math.max(0, remaining()), finalHeight);
1199
+ if (continues) {
1200
+ pageIndex++;
1201
+ y = context.top;
1202
+ }
1203
+ } while (offset < lines.length);
1204
+ return {
1205
+ logicalEnd: pageIndex * (context.bottom - context.top) + (y - context.top)
1206
+ };
1207
+ }
1208
+ function measureRichTextFlowHeight(element) {
1209
+ return Math.max(
1210
+ element.height,
1211
+ measureLines(element).reduce((height, line) => height + line.height, 0)
1212
+ );
1213
+ }
1214
+
1215
+ // src/plugins/rich-text/native.ts
1216
+ var richTextNativePlugin = defineNativePlugin(
1217
+ "richText",
1218
+ "0.1.1",
1219
+ printDesign.definePrintDesignPluginRenderer({
1220
+ type: "richText",
1221
+ validate: validateRichTextElement,
1222
+ drawCanvas: drawRichTextElement,
1223
+ renderHtml: (element) => renderRichTextHtml(element),
1224
+ paginate: paginateRichText,
1225
+ measureFlowHeight: measureRichTextFlowHeight,
1226
+ truncateOverflow: truncateRichTextOverflow
1227
+ })
1228
+ );
889
1229
  var drawListElement = (element, context) => {
890
1230
  const { ctx, x, y, width, height, scale, data } = context;
891
1231
  const row = Math.max(1, element.rowHeight ?? 8) * scale;
@@ -986,8 +1326,8 @@ function itemPaths(text) {
986
1326
  return [...text.matchAll(LIST_EXPRESSION)].map((match) => match[1]);
987
1327
  }
988
1328
  function listBindingInfo(element) {
989
- const paths = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
990
- return { bound: paths.length > 0, paths };
1329
+ const paths2 = [...new Set(element.items.flatMap((item) => itemPaths(item.text)))];
1330
+ return { bound: paths2.length > 0, paths: paths2 };
991
1331
  }
992
1332
  function validateListTemplateData(element, data) {
993
1333
  if (!data) return [];
@@ -1102,9 +1442,9 @@ function dateTimeBindingInfo(element) {
1102
1442
  }
1103
1443
  function validateDateTimeTemplateData(element, data) {
1104
1444
  if (!data) return [];
1105
- const { bound, paths } = dateTimeBindingInfo(element);
1445
+ const { bound, paths: paths2 } = dateTimeBindingInfo(element);
1106
1446
  if (!bound) return [];
1107
- const expression = paths[0];
1447
+ const expression = paths2[0];
1108
1448
  if (!expression) return ["\u672A\u914D\u7F6E\u65E5\u671F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
1109
1449
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1110
1450
  const text = typeof value === "string" || typeof value === "number" || typeof value === "boolean" ? String(value).trim() : "";
@@ -1231,9 +1571,9 @@ function moneyUpperBindingInfo(element) {
1231
1571
  }
1232
1572
  function validateMoneyUpperTemplateData(element, data) {
1233
1573
  if (!data) return [];
1234
- const { bound, paths } = moneyUpperBindingInfo(element);
1574
+ const { bound, paths: paths2 } = moneyUpperBindingInfo(element);
1235
1575
  if (!bound) return [];
1236
- const expression = paths[0];
1576
+ const expression = paths2[0];
1237
1577
  if (!expression) return ["\u672A\u914D\u7F6E\u91D1\u989D\u7ED1\u5B9A\u5B57\u6BB5"];
1238
1578
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1239
1579
  const numeric2 = typeof value === "number" || typeof value === "string" && value.trim() !== "" ? Number(value) : NaN;
@@ -1313,9 +1653,9 @@ function pageNumberBindingInfo(element) {
1313
1653
  }
1314
1654
  function validatePageNumberTemplateData(element, data) {
1315
1655
  if (!data) return [];
1316
- const { bound, paths } = pageNumberBindingInfo(element);
1656
+ const { bound, paths: paths2 } = pageNumberBindingInfo(element);
1317
1657
  if (!bound) return [];
1318
- const expression = paths[0];
1658
+ const expression = paths2[0];
1319
1659
  if (!expression) return ["\u672A\u914D\u7F6E\u9875\u7801\u524D\u7F00\u7ED1\u5B9A\u5B57\u6BB5"];
1320
1660
  const value = printDesign.resolvePrintDesignBinding(data, expression);
1321
1661
  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`];
@@ -1417,23 +1757,18 @@ function renderWatermarkHtml(element, data, preciseClip = false) {
1417
1757
  const text = printDesign.escapeHtml(
1418
1758
  element.dataConfig ? element.text : printDesign.resolveDesignText(element.text, data)
1419
1759
  );
1420
- if (!preciseClip) {
1421
- const fontSize2 = printDesign.cssNumber(element.fontSize, 24);
1422
- const cell = `<span style="color:${printDesign.cssColor(element.color, "#94a3b8")};font-size:${fontSize2}pt;transform:rotate(${printDesign.cssNumber(element.textRotation, 45)}deg) translateY(-${fontSize2 * DEFAULT_TEXT_BASELINE_CORRECTION_RATIO}pt)">${text}</span>`;
1423
- const content2 = `<div class="pd-watermark" style="grid-template-columns:repeat(${columns},1fr);grid-template-rows:repeat(${rows},1fr)">${cell.repeat(rows * columns)}</div>`;
1424
- return printDesign.renderPrintDesignHtmlFrame(element, content2);
1425
- }
1426
1760
  const width = Math.max(0, element.width);
1427
1761
  const height = Math.max(0, element.height);
1428
1762
  const fontSize = printDesign.cssNumber(element.fontSize, 24) * 25.4 / 72;
1429
1763
  const color2 = printDesign.cssColor(element.color, "#94a3b8");
1430
1764
  const rotation = printDesign.cssNumber(element.textRotation, 45);
1765
+ const baselineFactor = preciseClip ? 0.3 : 0.39;
1431
1766
  const cells = Array.from({ length: rows * columns }, (_, index) => {
1432
1767
  const centerX = (index % columns + 0.5) * (width / columns);
1433
1768
  const centerY = (Math.floor(index / columns) + 0.5) * (height / rows);
1434
- return `<text x="${centerX}" y="${centerY + fontSize * 0.3}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1769
+ return `<text x="${centerX}" y="${centerY + fontSize * baselineFactor}" text-anchor="middle" transform="rotate(${rotation} ${centerX} ${centerY})">${text}</text>`;
1435
1770
  }).join("");
1436
- const content = `<svg class="pd-watermark" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${printDesign.escapeHtml(printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1771
+ const content = `<svg class="pd-watermark" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 ${width} ${height}" preserveAspectRatio="none" font-size="${fontSize}" font-family="${printDesign.escapeHtml(printDesign.PRINT_DESIGN_DEFAULT_FONT_FAMILY)}" fill="${color2}" style="display:block;width:100%;height:100%;overflow:hidden">${cells}</svg>`;
1437
1772
  return printDesign.renderPrintDesignHtmlFrame(element, content);
1438
1773
  }
1439
1774
 
@@ -1458,9 +1793,9 @@ function watermarkBindingInfo(element) {
1458
1793
  }
1459
1794
  function validateWatermarkTemplateData(element, data) {
1460
1795
  if (!data) return [];
1461
- const { bound, paths } = watermarkBindingInfo(element);
1796
+ const { bound, paths: paths2 } = watermarkBindingInfo(element);
1462
1797
  if (!bound) return [];
1463
- const expression = paths[0];
1798
+ const expression = paths2[0];
1464
1799
  if (!expression) return ["\u672A\u914D\u7F6E\u6C34\u5370\u6587\u5B57\u7ED1\u5B9A\u5B57\u6BB5"];
1465
1800
  for (const match of expression.matchAll(
1466
1801
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -1475,7 +1810,7 @@ function validateWatermarkTemplateData(element, data) {
1475
1810
  // src/plugins/watermark/native.ts
1476
1811
  var watermarkNativePlugin = defineNativePlugin(
1477
1812
  "watermark",
1478
- "0.1.9",
1813
+ "0.1.10",
1479
1814
  printDesign.definePrintDesignPluginRenderer({
1480
1815
  type: "watermark",
1481
1816
  validate: validateWatermarkElement,
@@ -1495,8 +1830,7 @@ var watermarkNativePlugin = defineNativePlugin(
1495
1830
  physical && physical.y + physical.height > context.page.height
1496
1831
  )
1497
1832
  );
1498
- },
1499
- 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}"
1833
+ }
1500
1834
  }),
1501
1835
  [{ id: "builtin.text", minVersion: "0.1.16" }]
1502
1836
  );
@@ -4148,8 +4482,8 @@ function labelPaths(element) {
4148
4482
  );
4149
4483
  }
4150
4484
  function connectorBindingInfo(element) {
4151
- const paths = [...new Set(labelPaths(element))];
4152
- return { bound: paths.length > 0, paths };
4485
+ const paths2 = [...new Set(labelPaths(element))];
4486
+ return { bound: paths2.length > 0, paths: paths2 };
4153
4487
  }
4154
4488
  function validateConnectorTemplateData(element, data) {
4155
4489
  if (!data) return [];
@@ -4960,13 +5294,13 @@ function gridMarkup(element, data) {
4960
5294
 
4961
5295
  // src/plugins/grid/data/binding.ts
4962
5296
  function getGridBindingInfo(element) {
4963
- const paths = [
5297
+ const paths2 = [
4964
5298
  element.contentPath,
4965
5299
  element.loopsPath,
4966
5300
  element.columnLoopsPath,
4967
5301
  ...(element.cells ?? []).filter((cell) => cell.contentMode === "binding").map((cell) => cell.contentPath)
4968
5302
  ].map((path) => path?.trim()).filter((path) => !!path);
4969
- return { bound: paths.length > 0, paths };
5303
+ return { bound: paths2.length > 0, paths: paths2 };
4970
5304
  }
4971
5305
  function validateGridTemplateData(element, data) {
4972
5306
  if (!data) return [];
@@ -5791,7 +6125,7 @@ function layoutFlow(element, data = {}) {
5791
6125
  const leftWidth = Math.max(1, axis - gutter - inset);
5792
6126
  const rightWidth = Math.max(1, width - axis - gutter - inset);
5793
6127
  const gap = Math.max(0, element.itemGap ?? 3);
5794
- const nodes = items.map((item, index) => {
6128
+ const nodes2 = items.map((item, index) => {
5795
6129
  const position = item.position ?? (mode === "alternate" ? index % 2 ? "end" : "start" : mode);
5796
6130
  const onRight = position === "start";
5797
6131
  const lines = wrapFlowText(
@@ -5809,11 +6143,11 @@ function layoutFlow(element, data = {}) {
5809
6143
  y: 0
5810
6144
  };
5811
6145
  });
5812
- const naturalHeight = nodes.reduce((sum, node) => sum + node.height, 0) + gap * Math.max(0, nodes.length - 1);
6146
+ const naturalHeight = nodes2.reduce((sum, node2) => sum + node2.height, 0) + gap * Math.max(0, nodes2.length - 1);
5813
6147
  let cursor = Math.max(0, (height - naturalHeight) / 2);
5814
- for (const node of nodes) {
5815
- node.y = cursor;
5816
- cursor += node.height + gap;
6148
+ for (const node2 of nodes2) {
6149
+ node2.y = cursor;
6150
+ cursor += node2.height + gap;
5817
6151
  }
5818
6152
  return {
5819
6153
  width,
@@ -5824,7 +6158,7 @@ function layoutFlow(element, data = {}) {
5824
6158
  axis,
5825
6159
  gutter,
5826
6160
  inset,
5827
- nodes
6161
+ nodes: nodes2
5828
6162
  };
5829
6163
  }
5830
6164
 
@@ -5838,15 +6172,15 @@ var drawFlowElement = (element, context) => {
5838
6172
  ctx.clip();
5839
6173
  ctx.font = `${layout.fontSize * scale}px Arial, sans-serif`;
5840
6174
  ctx.textBaseline = "middle";
5841
- layout.nodes.forEach((node, index) => {
5842
- const centerY = y + (node.y + layout.lineHeight / 2) * scale;
6175
+ layout.nodes.forEach((node2, index) => {
6176
+ const centerY = y + (node2.y + layout.lineHeight / 2) * scale;
5843
6177
  const axisX = x + layout.axis * scale;
5844
6178
  const next = layout.nodes[index + 1];
5845
6179
  if (next) {
5846
6180
  ctx.beginPath();
5847
6181
  ctx.strokeStyle = element.lineColor ?? "#d9e1ec";
5848
6182
  ctx.lineWidth = Math.max(0.2 * scale, 1);
5849
- ctx.setLineDash(node.item.loading || next.item.loading ? [3, 3] : []);
6183
+ ctx.setLineDash(node2.item.loading || next.item.loading ? [3, 3] : []);
5850
6184
  ctx.moveTo(axisX, centerY + (layout.dot / 2 + 0.5) * scale);
5851
6185
  ctx.lineTo(
5852
6186
  axisX,
@@ -5855,7 +6189,7 @@ var drawFlowElement = (element, context) => {
5855
6189
  ctx.stroke();
5856
6190
  ctx.setLineDash([]);
5857
6191
  }
5858
- const color2 = flowItemColor(node.item);
6192
+ const color2 = flowItemColor(node2.item);
5859
6193
  const radius = layout.dot / 2 * scale;
5860
6194
  ctx.beginPath();
5861
6195
  ctx.arc(axisX, centerY, radius, 0, Math.PI * 2);
@@ -5864,7 +6198,7 @@ var drawFlowElement = (element, context) => {
5864
6198
  ctx.fillStyle = element.variant === "filled" ? color2 : "#ffffff";
5865
6199
  ctx.fill();
5866
6200
  ctx.stroke();
5867
- const glyph = node.item.loading ? "\u25CC" : { check: "\u2713", clock: "\u25F7", cross: "\xD7" }[node.item.icon];
6201
+ const glyph = node2.item.loading ? "\u25CC" : { check: "\u2713", clock: "\u25F7", cross: "\xD7" }[node2.item.icon];
5868
6202
  if (glyph) {
5869
6203
  ctx.fillStyle = element.variant === "filled" ? "#ffffff" : color2;
5870
6204
  ctx.font = `${radius * 1.4}px Arial, sans-serif`;
@@ -5886,8 +6220,8 @@ var drawFlowElement = (element, context) => {
5886
6220
  )
5887
6221
  );
5888
6222
  };
5889
- drawLines(node.lines, node.onRight, element.textColor ?? "#1f2937");
5890
- drawLines(node.titles, !node.onRight, element.titleColor ?? "#64748b");
6223
+ drawLines(node2.lines, node2.onRight, element.textColor ?? "#1f2937");
6224
+ drawLines(node2.titles, !node2.onRight, element.titleColor ?? "#64748b");
5891
6225
  });
5892
6226
  ctx.restore();
5893
6227
  };
@@ -5896,20 +6230,20 @@ function renderFlowHtml(element, data) {
5896
6230
  }
5897
6231
  function flowMarkup(element, data) {
5898
6232
  const layout = layoutFlow(element, data);
5899
- const nodes = layout.nodes.map((node, index) => {
5900
- const cy = node.y + layout.lineHeight / 2;
6233
+ const nodes2 = layout.nodes.map((node2, index) => {
6234
+ const cy = node2.y + layout.lineHeight / 2;
5901
6235
  const next = layout.nodes[index + 1];
5902
- const line = next ? `<line x1="${layout.axis}" y1="${cy + layout.dot / 2 + 0.5}" x2="${layout.axis}" y2="${next.y + layout.lineHeight / 2 - layout.dot / 2 - 0.5}" stroke="${printDesign.cssColor(element.lineColor, "#d9e1ec")}" stroke-width="0.25"${node.item.loading || next.item.loading ? ' stroke-dasharray="0.8 0.8"' : ""}/>` : "";
5903
- const color2 = printDesign.cssColor(flowItemColor(node.item), "#1677ff");
6236
+ const line = next ? `<line x1="${layout.axis}" y1="${cy + layout.dot / 2 + 0.5}" x2="${layout.axis}" y2="${next.y + layout.lineHeight / 2 - layout.dot / 2 - 0.5}" stroke="${printDesign.cssColor(element.lineColor, "#d9e1ec")}" stroke-width="0.25"${node2.item.loading || next.item.loading ? ' stroke-dasharray="0.8 0.8"' : ""}/>` : "";
6237
+ const color2 = printDesign.cssColor(flowItemColor(node2.item), "#1677ff");
5904
6238
  const marker2 = `<circle cx="${layout.axis}" cy="${cy}" r="${layout.dot / 2}" fill="${element.variant === "filled" ? color2 : "#ffffff"}" stroke="${color2}" stroke-width="0.3"/>`;
5905
- const glyph = node.item.loading ? "\u25CC" : { check: "\u2713", clock: "\u25F7", cross: "\xD7" }[node.item.icon];
6239
+ const glyph = node2.item.loading ? "\u25CC" : { check: "\u2713", clock: "\u25F7", cross: "\xD7" }[node2.item.icon];
5906
6240
  const symbol = glyph ? `<text x="${layout.axis}" y="${cy}" text-anchor="middle" dominant-baseline="middle" font-size="${layout.dot * 0.7}" fill="${element.variant === "filled" ? "#ffffff" : color2}">${glyph}</text>` : "";
5907
6241
  const lines = (values, right, textColor) => values.map(
5908
6242
  (value, lineIndex) => `<text x="${right ? layout.axis + layout.gutter : layout.axis - layout.gutter}" y="${cy + lineIndex * layout.lineHeight}" text-anchor="${right ? "start" : "end"}" dominant-baseline="middle" font-size="${layout.fontSize}" fill="${printDesign.cssColor(textColor, "#1f2937")}">${printDesign.escapeHtml(value)}</text>`
5909
6243
  ).join("");
5910
- return line + marker2 + symbol + lines(node.lines, node.onRight, element.textColor ?? "#1f2937") + lines(node.titles, !node.onRight, element.titleColor ?? "#64748b");
6244
+ return line + marker2 + symbol + lines(node2.lines, node2.onRight, element.textColor ?? "#1f2937") + lines(node2.titles, !node2.onRight, element.titleColor ?? "#64748b");
5911
6245
  });
5912
- return `<svg class="pd-media" viewBox="0 0 ${layout.width} ${layout.height}" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg"><g font-family="Arial, sans-serif">${nodes.join("")}</g></svg>`;
6246
+ return `<svg class="pd-media" viewBox="0 0 ${layout.width} ${layout.height}" preserveAspectRatio="none" xmlns="http://www.w3.org/2000/svg"><g font-family="Arial, sans-serif">${nodes2.join("")}</g></svg>`;
5913
6247
  }
5914
6248
  function validateFlowTemplateData(element, data) {
5915
6249
  if (!data || (element.dataMode ?? element.dataConfig?.mode) !== "binding")
@@ -6214,9 +6548,9 @@ function clockBindingInfo(element) {
6214
6548
  }
6215
6549
  function validateClockTemplateData(element, data) {
6216
6550
  if (!data) return [];
6217
- const { bound, paths } = clockBindingInfo(element);
6551
+ const { bound, paths: paths2 } = clockBindingInfo(element);
6218
6552
  if (!bound) return [];
6219
- const expression = paths[0];
6553
+ const expression = paths2[0];
6220
6554
  if (!expression) return ["\u672A\u914D\u7F6E\u65F6\u949F\u65F6\u95F4\u7ED1\u5B9A\u5B57\u6BB5"];
6221
6555
  for (const match of expression.matchAll(
6222
6556
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6263,7 +6597,7 @@ function prepareImage(src, signal) {
6263
6597
  return Promise.reject(new Error("\u5F53\u524D\u73AF\u5883\u65E0\u6CD5\u52A0\u8F7D\u6253\u5370\u56FE\u7247\u3002"));
6264
6598
  signal?.throwIfAborted();
6265
6599
  if (imageCache.has(src)) return Promise.resolve();
6266
- return new Promise((resolve, reject) => {
6600
+ return new Promise((resolve2, reject) => {
6267
6601
  const errors = pendingErrors.get(src) ?? /* @__PURE__ */ new Set();
6268
6602
  pendingErrors.set(src, errors);
6269
6603
  const cleanup = () => {
@@ -6274,7 +6608,7 @@ function prepareImage(src, signal) {
6274
6608
  };
6275
6609
  const onLoad = () => {
6276
6610
  cleanup();
6277
- resolve();
6611
+ resolve2();
6278
6612
  };
6279
6613
  const onError = (cause) => {
6280
6614
  cleanup();
@@ -6455,9 +6789,9 @@ function imageBindingInfo(element) {
6455
6789
  }
6456
6790
  function validateImageTemplateData(element, data) {
6457
6791
  if (!data) return [];
6458
- const { bound, paths } = imageBindingInfo(element);
6792
+ const { bound, paths: paths2 } = imageBindingInfo(element);
6459
6793
  if (!bound) return [];
6460
- const expression = paths[0];
6794
+ const expression = paths2[0];
6461
6795
  if (!expression) return ["\u672A\u914D\u7F6E\u56FE\u7247\u5730\u5740\u7ED1\u5B9A\u5B57\u6BB5"];
6462
6796
  for (const match of expression.matchAll(
6463
6797
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6811,9 +7145,9 @@ function barcodeBindingInfo(element) {
6811
7145
  }
6812
7146
  function validateBarcodeTemplateData(element, data) {
6813
7147
  if (!data) return [];
6814
- const { bound, paths } = barcodeBindingInfo(element);
7148
+ const { bound, paths: paths2 } = barcodeBindingInfo(element);
6815
7149
  if (!bound) return [];
6816
- const expression = paths[0];
7150
+ const expression = paths2[0];
6817
7151
  if (!expression) return ["\u672A\u914D\u7F6E\u6761\u5F62\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6818
7152
  for (const match of expression.matchAll(
6819
7153
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -6913,9 +7247,9 @@ function qrcodeBindingInfo(element) {
6913
7247
  }
6914
7248
  function validateQrCodeTemplateData(element, data) {
6915
7249
  if (!data) return [];
6916
- const { bound, paths } = qrcodeBindingInfo(element);
7250
+ const { bound, paths: paths2 } = qrcodeBindingInfo(element);
6917
7251
  if (!bound) return [];
6918
- const expression = paths[0];
7252
+ const expression = paths2[0];
6919
7253
  if (!expression) return ["\u672A\u914D\u7F6E\u4E8C\u7EF4\u7801\u5185\u5BB9\u7ED1\u5B9A\u5B57\u6BB5"];
6920
7254
  for (const match of expression.matchAll(
6921
7255
  /\{\{\s*([\w.[\]-]+)(?:\|(?:date|dateSlash))?\s*\}\}/g
@@ -7257,7 +7591,7 @@ function tableHeaderDepth(columns) {
7257
7591
  function tableHeaderCells(element) {
7258
7592
  const depth = tableHeaderDepth(element.columns);
7259
7593
  const cells = [];
7260
- const walk = (columns, level, start) => {
7594
+ const walk2 = (columns, level, start) => {
7261
7595
  let index = start;
7262
7596
  for (const column of columns) {
7263
7597
  if (column.hidden) continue;
@@ -7271,11 +7605,11 @@ function tableHeaderCells(element) {
7271
7605
  colSpan: span,
7272
7606
  column
7273
7607
  });
7274
- if (children.length) walk(children, level + 1, index);
7608
+ if (children.length) walk2(children, level + 1, index);
7275
7609
  index += span;
7276
7610
  }
7277
7611
  };
7278
- walk(element.columns, 0, 0);
7612
+ walk2(element.columns, 0, 0);
7279
7613
  for (const merge of element.headerCells ?? []) {
7280
7614
  const rowSpan = Math.max(1, merge.rowSpan ?? 1);
7281
7615
  const colSpan = Math.max(1, merge.colSpan ?? 1);
@@ -7438,12 +7772,12 @@ function formatPrintTableValue(value, column) {
7438
7772
  function escapeSvgAttribute(value) {
7439
7773
  return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;");
7440
7774
  }
7441
- function printIconNode(node, color2) {
7442
- const attrs = Object.entries(node.attrs).map(([name, value]) => {
7775
+ function printIconNode(node2, color2) {
7776
+ const attrs = Object.entries(node2.attrs).map(([name, value]) => {
7443
7777
  const resolved = value.replace(/__CC_REACT_ICON_PRIMARY__/g, color2).replace(/__CC_REACT_ICON_SECONDARY__/g, "#e6f4ff");
7444
7778
  return `${name}="${escapeSvgAttribute(resolved)}"`;
7445
7779
  }).join(" ");
7446
- return `<${node.tag}${attrs ? ` ${attrs}` : ""}>${(node.children ?? []).map((child) => printIconNode(child, color2)).join("")}</${node.tag}>`;
7780
+ return `<${node2.tag}${attrs ? ` ${attrs}` : ""}>${(node2.children ?? []).map((child) => printIconNode(child, color2)).join("")}</${node2.tag}>`;
7447
7781
  }
7448
7782
  function printTableIconSvg(name, color2 = "#1f2937") {
7449
7783
  const key = `${name}\0${color2}`;
@@ -7841,7 +8175,7 @@ function resolveDiagonalCount(count) {
7841
8175
  function diagonalCellLayout(direction, count, corner) {
7842
8176
  const lineCount = resolveDiagonalCount(count);
7843
8177
  const activeCorner = lineCount === 1 ? direction === "down" ? "top-left" : "bottom-left" : corner ?? (direction === "down" ? "top-left" : "bottom-left");
7844
- const paths = {
8178
+ const paths2 = {
7845
8179
  "top-left": [
7846
8180
  [0, 0],
7847
8181
  [1, 0],
@@ -7867,7 +8201,7 @@ function diagonalCellLayout(direction, count, corner) {
7867
8201
  [0, 1]
7868
8202
  ]
7869
8203
  };
7870
- const [apex, first, bend, last] = paths[activeCorner];
8204
+ const [apex, first, bend, last] = paths2[activeCorner];
7871
8205
  const farPoint = (position) => position <= 1 ? [
7872
8206
  first[0] + (bend[0] - first[0]) * position,
7873
8207
  first[1] + (bend[1] - first[1]) * position
@@ -9403,6 +9737,10 @@ function hitTableColumnBoundary(element, point, scale, includeSelector = false,
9403
9737
  }
9404
9738
  return nearest;
9405
9739
  }
9740
+ function boundaryHitRadius(height, scale, selector) {
9741
+ const radius = 5 / scale;
9742
+ return selector || height * scale >= 12 ? radius : Math.min(radius, height / 4);
9743
+ }
9406
9744
  function unmergedBoundarySegments(element, rowIndex, merges) {
9407
9745
  if (!merges.length) return [{ x: element.x + 3, width: element.width - 6 }];
9408
9746
  const columns = tableLeafColumns(
@@ -9444,11 +9782,25 @@ function tableHeaderResizeLayout(element, scale, data = {}) {
9444
9782
  for (let index = 0; index < depth; index++) {
9445
9783
  const edge = element.y + (index + 1) * height;
9446
9784
  if (edge > visibleBottom + 1e-9) break;
9447
- const shared = { rowIndex: index, edge, height, y: edge - 5 / scale };
9448
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9785
+ const shared = { rowIndex: index, edge, height };
9786
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9787
+ regions.push({
9788
+ ...shared,
9789
+ x: element.x - 6,
9790
+ width: 6,
9791
+ selector: true,
9792
+ radius: selectorRadius,
9793
+ y: edge - selectorRadius
9794
+ });
9449
9795
  if (edge < visibleBottom - 1e-9 && element.width > 6)
9450
9796
  for (const segment of unmergedBoundarySegments(element, index, headers))
9451
- regions.push({ ...shared, ...segment, selector: false });
9797
+ regions.push({
9798
+ ...shared,
9799
+ ...segment,
9800
+ selector: false,
9801
+ radius: boundaryHitRadius(height, scale, false),
9802
+ y: edge - boundaryHitRadius(height, scale, false)
9803
+ });
9452
9804
  }
9453
9805
  return regions;
9454
9806
  }
@@ -9463,7 +9815,7 @@ function hitTableHeaderBoundary(element, point, scale, data = {}) {
9463
9815
  -(element.rotation ?? 0) * Math.PI / 180
9464
9816
  );
9465
9817
  const region = tableHeaderResizeLayout(element, scale, data).filter(
9466
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9818
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9467
9819
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9468
9820
  return region && {
9469
9821
  elementId: element.id,
@@ -9495,13 +9847,26 @@ function tableRowResizeLayout(element, scale, data = {}) {
9495
9847
  const shared = {
9496
9848
  rowIndex: index + (element.sourceRowOffset ?? 0),
9497
9849
  edge: boundary,
9498
- height,
9499
- y: boundary - 5 / scale
9850
+ height
9500
9851
  };
9501
- regions.push({ ...shared, x: element.x - 6, width: 6, selector: true });
9852
+ const selectorRadius = boundaryHitRadius(height, scale, true);
9853
+ regions.push({
9854
+ ...shared,
9855
+ x: element.x - 6,
9856
+ width: 6,
9857
+ selector: true,
9858
+ radius: selectorRadius,
9859
+ y: boundary - selectorRadius
9860
+ });
9502
9861
  if (index < heights.length - 1 && element.width > 6)
9503
9862
  for (const segment of unmergedBoundarySegments(element, index, cells))
9504
- regions.push({ ...shared, ...segment, selector: false });
9863
+ regions.push({
9864
+ ...shared,
9865
+ ...segment,
9866
+ selector: false,
9867
+ radius: boundaryHitRadius(height, scale, false),
9868
+ y: boundary - boundaryHitRadius(height, scale, false)
9869
+ });
9505
9870
  }
9506
9871
  return regions;
9507
9872
  }
@@ -9516,7 +9881,7 @@ function hitTableRowBoundary(element, point, scale, data = {}) {
9516
9881
  -(element.rotation ?? 0) * Math.PI / 180
9517
9882
  );
9518
9883
  const region = tableRowResizeLayout(element, scale, data).filter(
9519
- (item) => local.x >= item.x && local.x < item.x + item.width && local.y >= item.y && local.y <= item.y + 10 / scale
9884
+ (item) => local.x >= item.x && local.x < item.x + item.width && Math.abs(local.y - item.edge) <= item.radius
9520
9885
  ).sort((a, b) => Math.abs(local.y - a.edge) - Math.abs(local.y - b.edge))[0];
9521
9886
  return region && {
9522
9887
  elementId: element.id,
@@ -9651,12 +10016,12 @@ function tableDebugRegions(table2, context, options = {}) {
9651
10016
  ...owner,
9652
10017
  id: `${area}-resize:${index}`,
9653
10018
  category: "resize",
9654
- label: `${area === "header" ? `\u8868\u5934 H${region.rowIndex + 1}` : `\u884C ${region.rowIndex + 1}`} \u5E95\u7EBF \xB15px${hit ? " \u547D\u4E2D" : ""}`,
10019
+ 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" : ""}`,
9655
10020
  bounds: {
9656
10021
  x: region.x,
9657
10022
  y: region.y,
9658
10023
  width: region.width,
9659
- height: 10 / scale
10024
+ height: region.radius * 2
9660
10025
  },
9661
10026
  interactive: true,
9662
10027
  hit,
@@ -10033,12 +10398,12 @@ function tableColumnBands(element, availableWidth) {
10033
10398
  const fixed = element.columnWidthMode === "fixed";
10034
10399
  const makeTree = (start, end) => {
10035
10400
  let index = 0;
10036
- const walk = (items) => {
10401
+ const walk2 = (items) => {
10037
10402
  const selected = [];
10038
10403
  for (const column of items) {
10039
10404
  if (column.hidden) continue;
10040
10405
  if (column.children?.length) {
10041
- const children = walk(column.children);
10406
+ const children = walk2(column.children);
10042
10407
  if (children.length) selected.push({ ...column, children });
10043
10408
  continue;
10044
10409
  }
@@ -10048,7 +10413,7 @@ function tableColumnBands(element, availableWidth) {
10048
10413
  }
10049
10414
  return selected;
10050
10415
  };
10051
- return walk(element.columns);
10416
+ return walk2(element.columns);
10052
10417
  };
10053
10418
  if (!fixed || fullWidth <= availableWidth || element.wideTableMode !== "paginate") {
10054
10419
  return [
@@ -10597,13 +10962,13 @@ function selectionArea(selector) {
10597
10962
  function insertTableColumn(columns, index, column) {
10598
10963
  const copy = structuredClone(columns);
10599
10964
  let position = 0;
10600
- const walk = (items) => {
10965
+ const walk2 = (items) => {
10601
10966
  for (let i = 0; i < items.length; i++) {
10602
10967
  const item = items[i];
10603
10968
  if (item.hidden) continue;
10604
10969
  const children = item.children?.filter((child) => !child.hidden);
10605
10970
  if (children?.length) {
10606
- if (walk(item.children)) return true;
10971
+ if (walk2(item.children)) return true;
10607
10972
  } else {
10608
10973
  if (position === index) {
10609
10974
  items.splice(i, 0, column);
@@ -10618,7 +10983,7 @@ function insertTableColumn(columns, index, column) {
10618
10983
  }
10619
10984
  return false;
10620
10985
  };
10621
- walk(copy);
10986
+ walk2(copy);
10622
10987
  return copy;
10623
10988
  }
10624
10989
  function shiftTableCells(cells, axis, index) {
@@ -10646,11 +11011,227 @@ function emptyTableRow(element) {
10646
11011
  );
10647
11012
  }
10648
11013
 
11014
+ // src/plugins/table/data/packed-report-defaults.ts
11015
+ function fillPackedReportDefaults(columns, rows, current2) {
11016
+ const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
11017
+ const keys2 = visible.map(
11018
+ (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
11019
+ );
11020
+ const repeats = /* @__PURE__ */ new Map();
11021
+ keys2.forEach((key) => {
11022
+ const match = /^(.+?)([1-9]\d*)$/.exec(key);
11023
+ if (!match) return;
11024
+ const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
11025
+ slots.add(Number(match[2]));
11026
+ repeats.set(match[1], slots);
11027
+ });
11028
+ const series = [...repeats].filter(
11029
+ ([, slots]) => slots.has(1) && slots.has(2)
11030
+ );
11031
+ const itemsPerRow = Math.max(
11032
+ 1,
11033
+ ...series.map(([, slots]) => Math.max(...slots))
11034
+ );
11035
+ const sample = rows.find((row) => row && typeof row === "object") ?? {};
11036
+ const groupFields = {};
11037
+ keys2.forEach((key, index) => {
11038
+ const repeated = series.some(
11039
+ ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
11040
+ );
11041
+ if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
11042
+ groupFields[key] = key in sample ? key : "";
11043
+ }
11044
+ });
11045
+ const itemFields = series.map(([prefix]) => ({
11046
+ prefix,
11047
+ .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
11048
+ }));
11049
+ const totals = {};
11050
+ visible.forEach((column, index) => {
11051
+ const key = keys2[index];
11052
+ const summary = column.summary;
11053
+ const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
11054
+ if (key && summary && type === "sum") {
11055
+ const prefix = series.find(
11056
+ ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
11057
+ )?.[0];
11058
+ totals[key] = {
11059
+ sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
11060
+ ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
11061
+ };
11062
+ }
11063
+ });
11064
+ const subtotalLabelKey = keys2.find(
11065
+ (key) => key && !(key in totals) && !(key in groupFields)
11066
+ );
11067
+ const totalLabelKey = keys2.find((key) => key && !(key in totals));
11068
+ const subtotal = { ...totals };
11069
+ if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
11070
+ if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
11071
+ return {
11072
+ groupBy: current2?.groupBy ?? [],
11073
+ itemsPerRow: current2?.itemsPerRow ?? itemsPerRow,
11074
+ groupFields: Object.keys(current2?.groupFields ?? {}).length ? current2.groupFields : groupFields,
11075
+ groupMergeColumns: Object.keys(current2?.groupFields ?? {}).length ? current2.groupMergeColumns : keys2.flatMap(
11076
+ (key, index) => key && key in groupFields ? [index] : []
11077
+ ),
11078
+ itemFields: current2?.itemFields?.length ? current2.itemFields : itemFields,
11079
+ subtotal: Object.keys(current2?.subtotal ?? {}).length ? current2.subtotal : subtotal,
11080
+ subtotalMerges: current2?.subtotalMerges ?? [],
11081
+ total: Object.keys(current2?.total ?? {}).length ? current2.total : totals,
11082
+ totalMerges: current2?.totalMerges ?? [],
11083
+ appendRows: current2?.appendRows ?? [],
11084
+ ...current2?.footerElementIds ? { footerElementIds: current2.footerElementIds } : {}
11085
+ };
11086
+ }
11087
+
11088
+ // src/plugins/table/interaction/agent-commands.ts
11089
+ function object(input) {
11090
+ if (!input || typeof input !== "object" || Array.isArray(input))
11091
+ throw new TypeError("\u8868\u683C\u547D\u4EE4\u53C2\u6570\u5FC5\u987B\u662F\u5BF9\u8C61\u3002");
11092
+ return input;
11093
+ }
11094
+ function safePart(value) {
11095
+ return !!value.trim() && !value.split(/[.[\]]/).some((part) => ["__proto__", "prototype", "constructor"].includes(part));
11096
+ }
11097
+ function fieldPath(input, label) {
11098
+ if (typeof input === "string" && safePart(input)) return input.trim();
11099
+ if (Array.isArray(input) && input.length > 0 && input.every(
11100
+ (part) => typeof part === "string" && safePart(part) || typeof part === "number" && Number.isInteger(part) && part >= 0
11101
+ ))
11102
+ return input;
11103
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u540D\u6216\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11104
+ }
11105
+ function paths(input, label) {
11106
+ if (input === void 0) return [];
11107
+ if (!Array.isArray(input)) throw new TypeError(`${label} \u5FC5\u987B\u662F\u6570\u7EC4\u3002`);
11108
+ return input.map((value) => fieldPath(value, label));
11109
+ }
11110
+ function stringPaths(input, label) {
11111
+ if (!Array.isArray(input) || !input.length)
11112
+ throw new TypeError(`${label} \u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u6570\u7EC4\u3002`);
11113
+ return input.map((value) => {
11114
+ if (typeof value !== "string" || !safePart(value))
11115
+ throw new TypeError(`${label} \u4E2D\u7684\u5B57\u6BB5\u8DEF\u5F84\u5FC5\u987B\u662F\u975E\u7A7A\u5B57\u7B26\u4E32\u3002`);
11116
+ return value.trim();
11117
+ });
11118
+ }
11119
+ function configureTableAutoMerge(element, rawPayload) {
11120
+ const payload = object(rawPayload);
11121
+ if (payload.enabled === false) return { ...element, mergeCell: void 0 };
11122
+ const rowKeys = paths(payload.rowKeys, "rowKeys");
11123
+ const rowColumns = paths(payload.rowColumns, "rowColumns");
11124
+ const columnKeys = paths(payload.columnKeys, "columnKeys");
11125
+ if (!rowKeys.length && !columnKeys.length)
11126
+ throw new TypeError(
11127
+ "\u81F3\u5C11\u63D0\u4F9B rowKeys \u6216 columnKeys\uFF1B\u5173\u95ED\u65F6\u4F20 enabled=false\u3002"
11128
+ );
11129
+ if (rowColumns.length && !rowKeys.length)
11130
+ throw new TypeError("\u8BBE\u7F6E rowColumns \u65F6\u5FC5\u987B\u540C\u65F6\u63D0\u4F9B rowKeys\u3002");
11131
+ const visible = tableLeafColumns(element.columns).filter((column) => !column.hidden).map((column) => JSON.stringify(column.dataIndex));
11132
+ for (const path of [
11133
+ ...rowColumns.length ? rowColumns : rowKeys,
11134
+ ...columnKeys
11135
+ ])
11136
+ if (!visible.includes(JSON.stringify(path)))
11137
+ throw new TypeError(`\u5408\u5E76\u76EE\u6807\u5217\u4E0D\u5B58\u5728\uFF1A${JSON.stringify(path)}\u3002`);
11138
+ return {
11139
+ ...element,
11140
+ mergeCell: {
11141
+ ...rowKeys.length ? {
11142
+ row: {
11143
+ keys: rowKeys,
11144
+ ...rowColumns.length ? { columns: rowColumns } : {}
11145
+ }
11146
+ } : {},
11147
+ ...columnKeys.length ? { column: { keys: columnKeys } } : {}
11148
+ }
11149
+ };
11150
+ }
11151
+ function configureTableGroupAggregation(element, rawPayload, data) {
11152
+ const payload = object(rawPayload);
11153
+ if (payload.enabled === false) return { ...element, packedReport: void 0 };
11154
+ const groupBy = stringPaths(payload.groupBy, "groupBy");
11155
+ if (payload.itemsPerRow !== void 0 && (!Number.isInteger(payload.itemsPerRow) || Number(payload.itemsPerRow) < 1))
11156
+ throw new TypeError("itemsPerRow \u5FC5\u987B\u662F\u5927\u4E8E\u96F6\u7684\u6574\u6570\u3002");
11157
+ if (payload.sums !== void 0 && !Array.isArray(payload.sums))
11158
+ throw new TypeError("sums \u5FC5\u987B\u662F\u6570\u7EC4\u3002");
11159
+ const source = element.dataMode === "binding" ? resolveTableDataSource(data, element.dataPath) : element.dataSource;
11160
+ const rows = Array.isArray(source) ? source.filter(
11161
+ (row) => !!row && typeof row === "object" && !Array.isArray(row)
11162
+ ) : element.dataSource;
11163
+ for (const path of groupBy)
11164
+ if (rows.length && !rows.some((row) => printDesign.resolvePrintDesignDataPath(row, path) !== void 0))
11165
+ throw new TypeError(`\u5206\u7EC4\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${path}\u3002`);
11166
+ const report = fillPackedReportDefaults(
11167
+ element.columns,
11168
+ rows,
11169
+ element.packedReport
11170
+ );
11171
+ const visible = tableLeafColumns(element.columns).filter(
11172
+ (column) => !column.hidden
11173
+ );
11174
+ const groupFields = { ...report.groupFields };
11175
+ const subtotal = { ...report.subtotal };
11176
+ const total = { ...report.total };
11177
+ const sumColumns = /* @__PURE__ */ new Set();
11178
+ for (const raw of payload.sums ?? []) {
11179
+ const sum = object(raw);
11180
+ if (typeof sum.column !== "string" || !safePart(sum.column))
11181
+ throw new TypeError("sums.column \u5FC5\u987B\u662F\u8868\u683C\u5217\u7684 dataIndex \u5B57\u7B26\u4E32\u3002");
11182
+ const column = sum.column.trim();
11183
+ if (!visible.some((item) => item.dataIndex === column))
11184
+ throw new TypeError(`\u6C47\u603B\u5217\u4E0D\u5B58\u5728\uFF1A${column}\u3002`);
11185
+ if (sumColumns.has(column)) throw new TypeError(`\u6C47\u603B\u5217\u91CD\u590D\uFF1A${column}\u3002`);
11186
+ if (typeof sum.path !== "string" || !safePart(sum.path))
11187
+ throw new TypeError("sums.path \u5FC5\u987B\u662F\u539F\u59CB\u6570\u636E\u7684\u975E\u7A7A\u5B57\u6BB5\u8DEF\u5F84\u3002");
11188
+ if (rows.length && !rows.some(
11189
+ (row) => printDesign.resolvePrintDesignDataPath(row, sum.path) !== void 0
11190
+ ))
11191
+ throw new TypeError(`\u6C42\u548C\u5B57\u6BB5\u5728\u6570\u636E\u4E2D\u4E0D\u5B58\u5728\uFF1A${sum.path}\u3002`);
11192
+ if (sum.decimals !== void 0 && (!Number.isInteger(sum.decimals) || Number(sum.decimals) < 0 || Number(sum.decimals) > 10))
11193
+ throw new TypeError("sums.decimals \u5FC5\u987B\u662F 0 \u5230 10 \u7684\u6574\u6570\u3002");
11194
+ sumColumns.add(column);
11195
+ delete groupFields[column];
11196
+ const rule = {
11197
+ sumPath: sum.path.trim(),
11198
+ ...sum.decimals === void 0 ? {} : { decimals: sum.decimals }
11199
+ };
11200
+ subtotal[column] = rule;
11201
+ total[column] = rule;
11202
+ }
11203
+ if (sumColumns.size && !Object.values(subtotal).some((rule) => rule.text === "\u5C0F\u8BA1")) {
11204
+ const labelColumn = visible.find(
11205
+ (column) => typeof column.dataIndex === "string" && !sumColumns.has(column.dataIndex)
11206
+ );
11207
+ if (typeof labelColumn?.dataIndex === "string")
11208
+ subtotal[labelColumn.dataIndex] = { text: "\u5C0F\u8BA1" };
11209
+ }
11210
+ return {
11211
+ ...element,
11212
+ packedReport: {
11213
+ ...report,
11214
+ groupBy,
11215
+ ...payload.itemsPerRow === void 0 ? {} : { itemsPerRow: payload.itemsPerRow },
11216
+ groupFields,
11217
+ groupMergeColumns: report.groupMergeColumns.filter(
11218
+ (index) => !sumColumns.has(String(visible[index]?.dataIndex ?? ""))
11219
+ ),
11220
+ subtotal,
11221
+ total
11222
+ }
11223
+ };
11224
+ }
11225
+
10649
11226
  // src/plugins/table/interaction/commands.ts
10650
11227
  var tableCommands = {
10651
11228
  execute(element, command, rawPayload, context) {
10652
11229
  if (element.locked) return;
10653
11230
  if (!rawPayload || typeof rawPayload !== "object") return;
11231
+ if (command === "configure-auto-merge")
11232
+ return configureTableAutoMerge(element, rawPayload);
11233
+ if (command === "configure-group-aggregation")
11234
+ return configureTableGroupAggregation(element, rawPayload, context.data);
10654
11235
  const payload = rawPayload;
10655
11236
  const rowIndex = payload.rowIndex ?? 0;
10656
11237
  const columnIndex = payload.columnIndex ?? 0;
@@ -11045,7 +11626,7 @@ function validateTableTemplateData(element, data) {
11045
11626
  // src/plugins/table/native.ts
11046
11627
  var tableNativePlugin = defineNativePlugin(
11047
11628
  "table",
11048
- "0.1.69",
11629
+ "0.1.70",
11049
11630
  printDesign.definePrintDesignPluginRenderer({
11050
11631
  type: "table",
11051
11632
  validate: validateTableElement,
@@ -11998,6 +12579,7 @@ var ganttNativePlugin = defineNativePlugin(
11998
12579
  // src/native.ts
11999
12580
  var builtinNativeComponentPlugins = [
12000
12581
  textNativePlugin,
12582
+ richTextNativePlugin,
12001
12583
  listNativePlugin,
12002
12584
  dateTimeNativePlugin,
12003
12585
  moneyUpperNativePlugin,
@@ -12250,7 +12832,7 @@ var propertySections = [{
12250
12832
  defaultValue: "",
12251
12833
  ariaLabel: "\u6DFB\u52A0\u672C\u5730\u5B57\u4F53\u6587\u4EF6",
12252
12834
  accept: ".woff,.woff2,.ttf,.otf",
12253
- filePatch: (_element, file, dataUrl) => ({ fontFamily: file.name.replace(/\.[^.]+$/, "").replace(/[^\p{L}\p{N}_-]+/gu, " ").trim(), fontSource: dataUrl })
12835
+ filePatch: (_element, file, dataUrl2) => ({ fontFamily: file.name.replace(/\.[^.]+$/, "").replace(/[^\p{L}\p{N}_-]+/gu, " ").trim(), fontSource: dataUrl2 })
12254
12836
  },
12255
12837
  {
12256
12838
  path: "removeFontFile",
@@ -12260,8 +12842,36 @@ var propertySections = [{
12260
12842
  visibleWhen: (element) => element.type === "text" && Boolean(element.fontSource),
12261
12843
  toPatch: () => ({ fontSource: "" })
12262
12844
  },
12263
- { path: "fontWeight", label: "\u5B57\u91CD", kind: "select", defaultValue: "400", ariaLabel: "\u6587\u672C\u5B57\u91CD", options: FONT_WEIGHT_OPTIONS },
12264
- { 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" },
12845
+ { path: "fontWeight", label: "\u52A0\u7C97", kind: "select", defaultValue: "400", ariaLabel: "\u6587\u672C\u5B57\u91CD", options: FONT_WEIGHT_OPTIONS, fullWidth: false },
12846
+ { path: "fontStyle", label: "\u503E\u659C", kind: "select", defaultValue: "normal", ariaLabel: "\u6587\u672C\u503E\u659C", fullWidth: false, options: [
12847
+ { label: "\u5E38\u89C4", value: "normal" },
12848
+ { label: "\u503E\u659C", value: "italic" }
12849
+ ] },
12850
+ { 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" },
12851
+ { path: "indentMode", label: "\u7F29\u8FDB", kind: "select", defaultValue: "none", fullWidth: false, options: [
12852
+ { label: "\u65E0", value: "none" },
12853
+ { label: "\u9996\u884C\u7F29\u8FDB", value: "firstLine" },
12854
+ { label: "\u60AC\u6302\u7F29\u8FDB", value: "hanging" }
12855
+ ] },
12856
+ {
12857
+ path: "indentValue",
12858
+ label: "\u7F29\u8FDB\u5EA6\u91CF\u503C",
12859
+ kind: "number",
12860
+ defaultValue: 0,
12861
+ min: 0,
12862
+ max: 1e4,
12863
+ precision: 2,
12864
+ fullWidth: false,
12865
+ unitSelector: { path: "indentUnit", label: "\u7F29\u8FDB\u5355\u4F4D", defaultValue: "char", options: [
12866
+ { label: "\u5B57\u7B26", value: "char" },
12867
+ { label: "mm", value: "mm" },
12868
+ { label: "cm", value: "cm" },
12869
+ { label: "in", value: "in" },
12870
+ { label: "pt", value: "pt" },
12871
+ { label: "px", value: "px" }
12872
+ ] },
12873
+ visibleWhen: (element) => element.type === "text" && element.indentMode !== void 0 && element.indentMode !== "none"
12874
+ },
12265
12875
  { 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 },
12266
12876
  { path: "underlineCount", label: "\u4E0B\u5212\u7EBF\u6761\u6570", kind: "number", defaultValue: 0, min: 0, max: 5, precision: 0, ariaLabel: "\u4E0B\u5212\u7EBF\u6761\u6570" },
12267
12877
  { path: "underlineStyle", label: "\u4E0B\u5212\u7EBF\u7EBF\u578B", kind: "select", defaultValue: "solid", ariaLabel: "\u4E0B\u5212\u7EBF\u7EBF\u578B", options: UNDERLINE_STYLE_OPTIONS },
@@ -12300,15 +12910,168 @@ var textPlugin = defineBuiltinReactPlugin(textNativePlugin, {
12300
12910
  menuGroups,
12301
12911
  propertySections
12302
12912
  });
12303
-
12304
- // src/plugins/list/factory.ts
12305
- var listFactory = {
12306
- type: "list",
12307
- label: "\u5217\u8868",
12308
- agentCommands: [
12309
- {
12310
- name: "insert-item",
12311
- description: "\u5728\u5217\u8868\u6307\u5B9A\u4F4D\u7F6E\u63D2\u5165\u9879\u3002payload: { index: 0 \u8D77\u59CB\u63D2\u5165\u4F4D\u7F6E, text: \u9879\u6587\u5B57 }\u3002"
12913
+ function RichTextInlineEditor(props) {
12914
+ const [runs, setRuns] = react.useState(props.element.runs);
12915
+ const runsRef = react.useRef(runs);
12916
+ runsRef.current = runs;
12917
+ const editorRef = react.useRef(null);
12918
+ const overlayRef = react.useRef(null);
12919
+ const finishedRef = react.useRef(false);
12920
+ const finish = (commit) => {
12921
+ if (finishedRef.current) return;
12922
+ finishedRef.current = true;
12923
+ if (commit && JSON.stringify(runsRef.current) !== JSON.stringify(props.element.runs))
12924
+ props.onCommit(runsRef.current);
12925
+ else props.onClose();
12926
+ };
12927
+ react.useEffect(() => {
12928
+ const containsEditorUi = (target) => target instanceof Node && (overlayRef.current?.contains(target) || target instanceof Element && !!target.closest(".canvas-react-rich-text-popup"));
12929
+ const onPointerDown = (event) => {
12930
+ if (!containsEditorUi(event.target)) finish(true);
12931
+ };
12932
+ const onFocusIn = (event) => {
12933
+ if (!containsEditorUi(event.target)) finish(true);
12934
+ };
12935
+ const onKeyDown = (event) => {
12936
+ if (event.key !== "Escape") return;
12937
+ event.preventDefault();
12938
+ event.stopPropagation();
12939
+ finish(false);
12940
+ };
12941
+ document.addEventListener("pointerdown", onPointerDown, true);
12942
+ document.addEventListener("focusin", onFocusIn, true);
12943
+ document.addEventListener("keydown", onKeyDown, true);
12944
+ editorRef.current?.focus();
12945
+ return () => {
12946
+ document.removeEventListener("pointerdown", onPointerDown, true);
12947
+ document.removeEventListener("focusin", onFocusIn, true);
12948
+ document.removeEventListener("keydown", onKeyDown, true);
12949
+ };
12950
+ }, []);
12951
+ const scale = props.element.width > 0 ? props.rect.width / props.element.width : 1;
12952
+ const ptToPx = (size) => `${size * 25.4 / 72 * scale}px`;
12953
+ const indentPx = richTextIndentMm(props.element) * scale;
12954
+ const transform = props.element.transform ? (() => {
12955
+ const matrix = printDesign.elementTransformHomography(props.element);
12956
+ 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)`;
12957
+ 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)` : "";
12958
+ return perspective + rotation;
12959
+ })() : `rotate(${props.element.rotation ?? 0}deg)`;
12960
+ return /* @__PURE__ */ jsxRuntime.jsx(
12961
+ "div",
12962
+ {
12963
+ ref: overlayRef,
12964
+ className: "cc-print-design-rich-text-overlay",
12965
+ style: {
12966
+ position: "fixed",
12967
+ zIndex: 1e4,
12968
+ left: props.rect.left,
12969
+ top: props.rect.top,
12970
+ width: props.rect.width,
12971
+ height: props.rect.height,
12972
+ background: "transparent",
12973
+ outline: "1px solid #1677ff",
12974
+ transform,
12975
+ transformOrigin: props.element.transform ? "0 0" : "center"
12976
+ },
12977
+ onKeyDownCapture: (event) => {
12978
+ event.stopPropagation();
12979
+ if (event.key === "Escape") {
12980
+ event.preventDefault();
12981
+ finish(false);
12982
+ }
12983
+ },
12984
+ children: /* @__PURE__ */ jsxRuntime.jsx(
12985
+ reactComponents.ReactRichText,
12986
+ {
12987
+ ref: editorRef,
12988
+ value: runs,
12989
+ onChange: setRuns,
12990
+ toolbarPopupZIndex: 10001,
12991
+ fontFamilyOptions: reactPrintDesign.FONT_FAMILY_OPTIONS.map((option) => ({ label: option.label, value: String(option.value) })),
12992
+ defaultStyle: {
12993
+ fontFamily: printDesign.resolvePrintDesignFontFamily(props.element.fontFamily),
12994
+ fontSize: props.element.fontSize ?? 14,
12995
+ fontWeight: props.element.fontWeight ?? "400",
12996
+ fontStyle: props.element.fontStyle ?? "normal",
12997
+ color: props.element.color ?? "#1f2937"
12998
+ },
12999
+ fontSizeCss: ptToPx,
13000
+ editorStyle: {
13001
+ width: "100%",
13002
+ height: "100%",
13003
+ minHeight: 0,
13004
+ overflow: "hidden",
13005
+ backgroundColor: "transparent",
13006
+ lineHeight: props.element.lineHeight ?? 1.35,
13007
+ textAlign: props.element.textAlign ?? "left",
13008
+ textIndent: props.element.indentMode === "firstLine" ? `${indentPx}px` : props.element.indentMode === "hanging" ? `-${indentPx}px` : void 0,
13009
+ paddingLeft: props.element.indentMode === "hanging" ? `${indentPx}px` : void 0
13010
+ }
13011
+ }
13012
+ )
13013
+ }
13014
+ );
13015
+ }
13016
+
13017
+ // src/plugins/rich-text/factory.ts
13018
+ var richTextFactory = {
13019
+ type: "richText",
13020
+ label: "\u5BCC\u6587\u672C",
13021
+ showDataPanel: false,
13022
+ defaultOverflowPolicy: "split",
13023
+ overflowPolicyOptions: [
13024
+ { label: "\u81EA\u52A8\u6EA2\u51FA\u5230\u7EED\u9875", value: "split" },
13025
+ { label: "\u6574\u4F53\u653E\u5230\u4E0B\u4E00\u9875", value: "nextPage" },
13026
+ { label: "\u88C1\u5207", value: "clip" },
13027
+ { label: "\u8D85\u51FA\u663E\u793A...", value: "ellipsis" }
13028
+ ],
13029
+ renderInlineEditor: ({ element, rect, onCommit, onClose }) => react.createElement(RichTextInlineEditor, {
13030
+ element,
13031
+ rect,
13032
+ onCommit: (runs) => onCommit({ runs }),
13033
+ onClose
13034
+ }),
13035
+ create: () => ({
13036
+ ...createCommonElementDefaults(),
13037
+ type: "richText",
13038
+ name: "\u5BCC\u6587\u672C",
13039
+ runs: [{ text: "\u53CC\u51FB\u7F16\u8F91\u5BCC\u6587\u672C" }],
13040
+ fontSize: 14,
13041
+ color: "#1f2937"
13042
+ })
13043
+ };
13044
+ var menuGroups2 = [
13045
+ {
13046
+ id: "basic",
13047
+ title: "\u57FA\u7840\u5143\u7D20",
13048
+ order: 0,
13049
+ items: [
13050
+ {
13051
+ id: "richText",
13052
+ type: "richText",
13053
+ label: "\u5BCC\u6587\u672C",
13054
+ icon: react.createElement(reactComponents.ReactFontSizeOutlined, { "aria-hidden": true }),
13055
+ order: 1
13056
+ }
13057
+ ]
13058
+ }
13059
+ ];
13060
+
13061
+ // src/plugins/rich-text/react.ts
13062
+ var richTextPlugin = defineBuiltinReactPlugin(richTextNativePlugin, {
13063
+ factory: richTextFactory,
13064
+ menuGroups: menuGroups2
13065
+ });
13066
+
13067
+ // src/plugins/list/factory.ts
13068
+ var listFactory = {
13069
+ type: "list",
13070
+ label: "\u5217\u8868",
13071
+ agentCommands: [
13072
+ {
13073
+ name: "insert-item",
13074
+ description: "\u5728\u5217\u8868\u6307\u5B9A\u4F4D\u7F6E\u63D2\u5165\u9879\u3002payload: { index: 0 \u8D77\u59CB\u63D2\u5165\u4F4D\u7F6E, text: \u9879\u6587\u5B57 }\u3002"
12312
13075
  },
12313
13076
  {
12314
13077
  name: "update-item",
@@ -12350,7 +13113,7 @@ var listFactory = {
12350
13113
  };
12351
13114
 
12352
13115
  // src/plugins/list/menu.ts
12353
- var menuGroups2 = [
13116
+ var menuGroups3 = [
12354
13117
  {
12355
13118
  id: "list",
12356
13119
  title: "\u5217\u8868\u7EC4\u4EF6",
@@ -12452,7 +13215,7 @@ var propertySections2 = [
12452
13215
  // src/plugins/list/react.ts
12453
13216
  var listPlugin = defineBuiltinReactPlugin(listNativePlugin, {
12454
13217
  factory: listFactory,
12455
- menuGroups: menuGroups2,
13218
+ menuGroups: menuGroups3,
12456
13219
  propertySections: propertySections2
12457
13220
  });
12458
13221
 
@@ -12475,7 +13238,7 @@ var dateTimeFactory = {
12475
13238
  };
12476
13239
  }
12477
13240
  };
12478
- var menuGroups3 = [
13241
+ var menuGroups4 = [
12479
13242
  {
12480
13243
  id: "date-time",
12481
13244
  title: "\u65E5\u671F\u65F6\u95F4",
@@ -12516,7 +13279,7 @@ var propertySections3 = [
12516
13279
  ];
12517
13280
  var dateTimePlugin = defineBuiltinReactPlugin(dateTimeNativePlugin, {
12518
13281
  factory: dateTimeFactory,
12519
- menuGroups: menuGroups3,
13282
+ menuGroups: menuGroups4,
12520
13283
  propertySections: propertySections3
12521
13284
  });
12522
13285
 
@@ -12539,7 +13302,7 @@ var moneyUpperFactory = {
12539
13302
  };
12540
13303
  }
12541
13304
  };
12542
- var menuGroups4 = [
13305
+ var menuGroups5 = [
12543
13306
  {
12544
13307
  id: "basic",
12545
13308
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12593,7 +13356,7 @@ var propertySections4 = [
12593
13356
  ];
12594
13357
  var moneyUpperPlugin = defineBuiltinReactPlugin(
12595
13358
  moneyUpperNativePlugin,
12596
- { factory: moneyUpperFactory, menuGroups: menuGroups4, propertySections: propertySections4 }
13359
+ { factory: moneyUpperFactory, menuGroups: menuGroups5, propertySections: propertySections4 }
12597
13360
  );
12598
13361
 
12599
13362
  // src/plugins/page-number/factory.ts
@@ -12615,7 +13378,7 @@ var pageNumberFactory = {
12615
13378
  };
12616
13379
  }
12617
13380
  };
12618
- var menuGroups5 = [
13381
+ var menuGroups6 = [
12619
13382
  {
12620
13383
  id: "basic",
12621
13384
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12664,7 +13427,7 @@ var propertySections5 = [
12664
13427
  ];
12665
13428
  var pageNumberPlugin = defineBuiltinReactPlugin(
12666
13429
  pageNumberNativePlugin,
12667
- { factory: pageNumberFactory, menuGroups: menuGroups5, propertySections: propertySections5 }
13430
+ { factory: pageNumberFactory, menuGroups: menuGroups6, propertySections: propertySections5 }
12668
13431
  );
12669
13432
 
12670
13433
  // src/plugins/watermark/factory.ts
@@ -12704,7 +13467,7 @@ var watermarkFactory = {
12704
13467
  };
12705
13468
  }
12706
13469
  };
12707
- var menuGroups6 = [
13470
+ var menuGroups7 = [
12708
13471
  {
12709
13472
  id: "basic",
12710
13473
  title: "\u57FA\u7840\u5143\u7D20",
@@ -12758,7 +13521,7 @@ var propertySections6 = [
12758
13521
  ];
12759
13522
  var watermarkPlugin = defineBuiltinReactPlugin(watermarkNativePlugin, {
12760
13523
  factory: watermarkFactory,
12761
- menuGroups: menuGroups6,
13524
+ menuGroups: menuGroups7,
12762
13525
  propertySections: propertySections6
12763
13526
  });
12764
13527
 
@@ -12899,7 +13662,7 @@ var shapeFactory = {
12899
13662
  };
12900
13663
 
12901
13664
  // src/plugins/shape/menu.ts
12902
- var menuGroups7 = [
13665
+ var menuGroups8 = [
12903
13666
  {
12904
13667
  id: "shape",
12905
13668
  title: "\u5F62\u72B6\u7EC4\u4EF6",
@@ -13045,15 +13808,15 @@ var menuGroups7 = [
13045
13808
 
13046
13809
  // src/plugins/shape/layout/options.ts
13047
13810
  var SHAPE_OPTIONS = [
13048
- ...(menuGroups7.find((group) => group.id === "shape")?.items ?? []).map(
13811
+ ...(menuGroups8.find((group) => group.id === "shape")?.items ?? []).map(
13049
13812
  ({ id, label }) => ({ value: id, label })
13050
13813
  ),
13051
13814
  { value: "ellipse", label: "\u692D\u5706" },
13052
13815
  { value: "line", label: "\u76F4\u7EBF" },
13053
- ...(menuGroups7.find((group) => group.id === "bracket")?.items ?? []).map(
13816
+ ...(menuGroups8.find((group) => group.id === "bracket")?.items ?? []).map(
13054
13817
  ({ id, label }) => ({ value: id, label })
13055
13818
  ),
13056
- ...(menuGroups7.find((group) => group.id === "curve")?.items ?? []).map(
13819
+ ...(menuGroups8.find((group) => group.id === "curve")?.items ?? []).map(
13057
13820
  ({ id, label }) => ({ value: id, label })
13058
13821
  ),
13059
13822
  { value: "curve-path", label: "\u8DEF\u5F84" }
@@ -13271,7 +14034,7 @@ var propertySections7 = [
13271
14034
  // src/plugins/shape/react.ts
13272
14035
  var shapePlugin = defineBuiltinReactPlugin(shapeNativePlugin, {
13273
14036
  factory: shapeFactory,
13274
- menuGroups: menuGroups7,
14037
+ menuGroups: menuGroups8,
13275
14038
  propertySections: propertySections7
13276
14039
  });
13277
14040
 
@@ -13302,6 +14065,7 @@ function BrushToolbarButton({
13302
14065
  title: active ? "\u9000\u51FA\u753B\u7B14\u6A21\u5F0F" : "\u65B0\u5EFA\u753B\u7B14\u56FE\u5C42\u5E76\u7ED8\u5236",
13303
14066
  "aria-label": "\u753B\u7B14\u6A21\u5F0F",
13304
14067
  "aria-pressed": active,
14068
+ type: active ? "primary" : "default",
13305
14069
  disabled: readonly,
13306
14070
  icon: /* @__PURE__ */ jsxRuntime.jsxs(
13307
14071
  "svg",
@@ -13353,7 +14117,7 @@ var brushFactory = {
13353
14117
  };
13354
14118
 
13355
14119
  // src/plugins/brush/menu.ts
13356
- var menuGroups8 = [];
14120
+ var menuGroups9 = [];
13357
14121
 
13358
14122
  // src/plugins/brush/properties.ts
13359
14123
  var propertySections8 = [
@@ -13437,7 +14201,7 @@ var propertySections8 = [
13437
14201
  // src/plugins/brush/react.ts
13438
14202
  var brushPlugin = defineBuiltinReactPlugin(brushNativePlugin, {
13439
14203
  factory: brushFactory,
13440
- menuGroups: menuGroups8,
14204
+ menuGroups: menuGroups9,
13441
14205
  propertySections: propertySections8
13442
14206
  });
13443
14207
 
@@ -13475,7 +14239,7 @@ var connectorFactory = {
13475
14239
  };
13476
14240
 
13477
14241
  // src/plugins/connector/menu.ts
13478
- var menuGroups9 = [
14242
+ var menuGroups10 = [
13479
14243
  {
13480
14244
  id: "connector",
13481
14245
  title: "\u8FDE\u63A5\u7EBF",
@@ -13590,7 +14354,7 @@ var propertySections9 = [
13590
14354
  // src/plugins/connector/react.ts
13591
14355
  var connectorPlugin = defineBuiltinReactPlugin(connectorNativePlugin, {
13592
14356
  factory: connectorFactory,
13593
- menuGroups: menuGroups9,
14357
+ menuGroups: menuGroups10,
13594
14358
  propertySections: propertySections9
13595
14359
  });
13596
14360
 
@@ -13615,7 +14379,7 @@ var dividerFactory = {
13615
14379
  };
13616
14380
  }
13617
14381
  };
13618
- var menuGroups10 = [
14382
+ var menuGroups11 = [
13619
14383
  {
13620
14384
  id: "basic",
13621
14385
  title: "\u57FA\u7840\u5143\u7D20",
@@ -13674,7 +14438,7 @@ var propertySections10 = [
13674
14438
  // src/plugins/divider/react.ts
13675
14439
  var dividerPlugin = defineBuiltinReactPlugin(dividerNativePlugin, {
13676
14440
  factory: dividerFactory,
13677
- menuGroups: menuGroups10,
14441
+ menuGroups: menuGroups11,
13678
14442
  propertySections: propertySections10
13679
14443
  });
13680
14444
 
@@ -13711,7 +14475,7 @@ var rulerFactory = {
13711
14475
  };
13712
14476
 
13713
14477
  // src/plugins/ruler/menu.ts
13714
- var menuGroups11 = [
14478
+ var menuGroups12 = [
13715
14479
  {
13716
14480
  id: "ruler",
13717
14481
  title: "\u523B\u5EA6\u5C3A\u7EC4\u4EF6",
@@ -13804,7 +14568,7 @@ var propertySections11 = [
13804
14568
  // src/plugins/ruler/react.ts
13805
14569
  var rulerPlugin = defineBuiltinReactPlugin(rulerNativePlugin, {
13806
14570
  factory: rulerFactory,
13807
- menuGroups: menuGroups11,
14571
+ menuGroups: menuGroups12,
13808
14572
  propertySections: propertySections11
13809
14573
  });
13810
14574
 
@@ -13846,7 +14610,7 @@ var gridFactory = {
13846
14610
  };
13847
14611
  }
13848
14612
  };
13849
- var menuGroups12 = [
14613
+ var menuGroups13 = [
13850
14614
  {
13851
14615
  id: "grid",
13852
14616
  title: "\u7F51\u683C\u7EC4\u4EF6",
@@ -14056,7 +14820,7 @@ var propertySections12 = [
14056
14820
  // src/plugins/grid/react.ts
14057
14821
  var gridPlugin = defineBuiltinReactPlugin(gridNativePlugin, {
14058
14822
  factory: gridFactory,
14059
- menuGroups: menuGroups12,
14823
+ menuGroups: menuGroups13,
14060
14824
  propertySections: propertySections12
14061
14825
  });
14062
14826
 
@@ -14118,7 +14882,7 @@ var coordinateFactory = {
14118
14882
  };
14119
14883
  }
14120
14884
  };
14121
- var menuGroups13 = [
14885
+ var menuGroups14 = [
14122
14886
  {
14123
14887
  id: "grid",
14124
14888
  title: "\u7F51\u683C\u7EC4\u4EF6",
@@ -14269,7 +15033,7 @@ var propertySections13 = [
14269
15033
  // src/plugins/coordinate/react.ts
14270
15034
  var coordinatePlugin = defineBuiltinReactPlugin(
14271
15035
  coordinateNativePlugin,
14272
- { factory: coordinateFactory, menuGroups: menuGroups13, propertySections: propertySections13 }
15036
+ { factory: coordinateFactory, menuGroups: menuGroups14, propertySections: propertySections13 }
14273
15037
  );
14274
15038
 
14275
15039
  // src/plugins/progress/factory.ts
@@ -14304,7 +15068,7 @@ var progressFactory = {
14304
15068
  };
14305
15069
 
14306
15070
  // src/plugins/progress/menu.ts
14307
- var menuGroups14 = [
15071
+ var menuGroups15 = [
14308
15072
  {
14309
15073
  id: "progress",
14310
15074
  title: "\u8FDB\u5EA6\u7EC4\u4EF6",
@@ -14436,7 +15200,7 @@ var propertySections14 = [
14436
15200
  // src/plugins/progress/react.ts
14437
15201
  var progressPlugin = defineBuiltinReactPlugin(progressNativePlugin, {
14438
15202
  factory: progressFactory,
14439
- menuGroups: menuGroups14,
15203
+ menuGroups: menuGroups15,
14440
15204
  propertySections: propertySections14
14441
15205
  });
14442
15206
 
@@ -14486,7 +15250,7 @@ var flowFactory = {
14486
15250
  };
14487
15251
  }
14488
15252
  };
14489
- var menuGroups15 = [
15253
+ var menuGroups16 = [
14490
15254
  {
14491
15255
  id: "basic",
14492
15256
  title: "\u57FA\u7840\u5143\u7D20",
@@ -14622,7 +15386,7 @@ var propertySections15 = [{
14622
15386
  // src/plugins/flow/react.ts
14623
15387
  var flowPlugin = defineBuiltinReactPlugin(flowNativePlugin, {
14624
15388
  factory: flowFactory,
14625
- menuGroups: menuGroups15,
15389
+ menuGroups: menuGroups16,
14626
15390
  propertySections: propertySections15
14627
15391
  });
14628
15392
 
@@ -14664,7 +15428,7 @@ var clockFactory = {
14664
15428
  };
14665
15429
  }
14666
15430
  };
14667
- var menuGroups16 = [
15431
+ var menuGroups17 = [
14668
15432
  {
14669
15433
  id: "date-time",
14670
15434
  title: "\u65E5\u671F\u65F6\u95F4",
@@ -14763,7 +15527,7 @@ var propertySections16 = [
14763
15527
  // src/plugins/clock/react.ts
14764
15528
  var clockPlugin = defineBuiltinReactPlugin(clockNativePlugin, {
14765
15529
  factory: clockFactory,
14766
- menuGroups: menuGroups16,
15530
+ menuGroups: menuGroups17,
14767
15531
  propertySections: propertySections16
14768
15532
  });
14769
15533
 
@@ -14783,7 +15547,7 @@ function getExternalImageFiles(transfer) {
14783
15547
  );
14784
15548
  }
14785
15549
  function readExternalImageFile(file) {
14786
- return new Promise((resolve, reject) => {
15550
+ return new Promise((resolve2, reject) => {
14787
15551
  const reader = new FileReader();
14788
15552
  reader.onerror = () => reject(reader.error ?? new Error("\u56FE\u7247\u8BFB\u53D6\u5931\u8D25"));
14789
15553
  reader.onload = () => {
@@ -14799,7 +15563,7 @@ function readExternalImageFile(file) {
14799
15563
  reject(new Error("\u56FE\u7247\u5C3A\u5BF8\u65E0\u6548"));
14800
15564
  return;
14801
15565
  }
14802
- resolve({
15566
+ resolve2({
14803
15567
  src,
14804
15568
  name: file.name.replace(/\.[^.]+$/, "") || "\u56FE\u7247",
14805
15569
  naturalWidth: image.naturalWidth,
@@ -14882,7 +15646,7 @@ var imageFactory = {
14882
15646
  return { ...common, type, name: "\u56FE\u7247", src: "", fit: "contain" };
14883
15647
  }
14884
15648
  };
14885
- var menuGroups17 = [
15649
+ var menuGroups18 = [
14886
15650
  {
14887
15651
  id: "basic",
14888
15652
  title: "\u57FA\u7840\u5143\u7D20",
@@ -14937,7 +15701,7 @@ var propertySections17 = [
14937
15701
  // src/plugins/image/react.ts
14938
15702
  var imagePlugin = defineBuiltinReactPlugin(imageNativePlugin, {
14939
15703
  factory: imageFactory,
14940
- menuGroups: menuGroups17,
15704
+ menuGroups: menuGroups18,
14941
15705
  propertySections: propertySections17
14942
15706
  });
14943
15707
  var barcodeFactory = {
@@ -14967,7 +15731,7 @@ var barcodeFactory = {
14967
15731
  };
14968
15732
  }
14969
15733
  };
14970
- var menuGroups18 = [
15734
+ var menuGroups19 = [
14971
15735
  {
14972
15736
  id: "basic",
14973
15737
  title: "\u57FA\u7840\u5143\u7D20",
@@ -15027,7 +15791,7 @@ var propertySections18 = [
15027
15791
  // src/plugins/barcode/react.ts
15028
15792
  var barcodePlugin = defineBuiltinReactPlugin(barcodeNativePlugin, {
15029
15793
  factory: barcodeFactory,
15030
- menuGroups: menuGroups18,
15794
+ menuGroups: menuGroups19,
15031
15795
  propertySections: propertySections18
15032
15796
  });
15033
15797
 
@@ -15049,7 +15813,7 @@ var qrcodeFactory = {
15049
15813
  };
15050
15814
  }
15051
15815
  };
15052
- var menuGroups19 = [
15816
+ var menuGroups20 = [
15053
15817
  {
15054
15818
  id: "basic",
15055
15819
  title: "\u57FA\u7840\u5143\u7D20",
@@ -15208,7 +15972,7 @@ var propertySections19 = [
15208
15972
  // src/plugins/qrcode/react.ts
15209
15973
  var qrcodePlugin = defineBuiltinReactPlugin(qrcodeNativePlugin, {
15210
15974
  factory: qrcodeFactory,
15211
- menuGroups: menuGroups19,
15975
+ menuGroups: menuGroups20,
15212
15976
  propertySections: propertySections19
15213
15977
  });
15214
15978
 
@@ -15314,7 +16078,7 @@ var chartFactory = {
15314
16078
  };
15315
16079
  }
15316
16080
  };
15317
- var menuGroups20 = [
16081
+ var menuGroups21 = [
15318
16082
  {
15319
16083
  id: "chart",
15320
16084
  title: "\u56FE\u8868\u7EC4\u4EF6",
@@ -15577,30 +16341,129 @@ var propertySections20 = [{
15577
16341
  // src/plugins/chart/react.ts
15578
16342
  var chartPlugin = defineBuiltinReactPlugin(chartNativePlugin, {
15579
16343
  factory: chartFactory,
15580
- menuGroups: menuGroups20,
16344
+ menuGroups: menuGroups21,
15581
16345
  propertySections: propertySections20
15582
16346
  });
15583
16347
 
15584
16348
  // src/plugins/table/factory.ts
16349
+ var fieldPathSchema = {
16350
+ anyOf: [
16351
+ { type: "string", minLength: 1 },
16352
+ {
16353
+ type: "array",
16354
+ items: {
16355
+ anyOf: [
16356
+ { type: "string", minLength: 1 },
16357
+ { type: "integer", minimum: 0 }
16358
+ ]
16359
+ },
16360
+ minItems: 1
16361
+ }
16362
+ ]
16363
+ };
15585
16364
  var tableFactory = {
15586
16365
  type: "table",
15587
16366
  label: "\u8868\u683C",
15588
16367
  agentCommands: [
15589
16368
  {
15590
16369
  name: "insert-row",
15591
- description: "\u5728\u9759\u6001\u8868\u683C\u7684 rowIndex \u884C\u524D\u63D2\u5165\u884C\uFF1Bafter=true \u65F6\u63D2\u5728\u884C\u540E\u3002"
16370
+ description: "\u5728\u9759\u6001\u8868\u683C\u7684 rowIndex \u884C\u524D\u63D2\u5165\u884C\uFF1Bafter=true \u65F6\u63D2\u5728\u884C\u540E\u3002",
16371
+ parameters: {
16372
+ type: "object",
16373
+ properties: {
16374
+ rowIndex: { type: "integer", minimum: 0 },
16375
+ after: { type: "boolean" }
16376
+ },
16377
+ required: ["rowIndex"],
16378
+ additionalProperties: false
16379
+ }
15592
16380
  },
15593
16381
  {
15594
16382
  name: "insert-column",
15595
- description: "\u5728 columnIndex \u5217\u524D\u63D2\u5165\u5217\uFF1Bafter=true \u65F6\u63D2\u5728\u5217\u540E\u3002"
16383
+ description: "\u5728 columnIndex \u5217\u524D\u63D2\u5165\u5217\uFF1Bafter=true \u65F6\u63D2\u5728\u5217\u540E\u3002",
16384
+ parameters: {
16385
+ type: "object",
16386
+ properties: {
16387
+ columnIndex: { type: "integer", minimum: 0 },
16388
+ after: { type: "boolean" }
16389
+ },
16390
+ required: ["columnIndex"],
16391
+ additionalProperties: false
16392
+ }
15596
16393
  },
15597
16394
  {
15598
16395
  name: "merge-body",
15599
- description: "\u5408\u5E76\u8868\u4F53\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
16396
+ description: "\u5408\u5E76\u8868\u4F53\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002",
16397
+ parameters: {
16398
+ type: "object",
16399
+ properties: {
16400
+ rowIndex: { type: "integer", minimum: 0 },
16401
+ columnIndex: { type: "integer", minimum: 0 },
16402
+ rowSpan: { type: "integer", minimum: 1 },
16403
+ colSpan: { type: "integer", minimum: 1 }
16404
+ },
16405
+ required: ["rowIndex", "columnIndex", "rowSpan", "colSpan"],
16406
+ additionalProperties: false
16407
+ }
15600
16408
  },
15601
16409
  {
15602
16410
  name: "merge-header",
15603
- description: "\u5408\u5E76\u8868\u5934\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002"
16411
+ description: "\u5408\u5E76\u8868\u5934\u5355\u5143\u683C\uFF1B\u4F20 rowIndex\u3001columnIndex\u3001rowSpan\u3001colSpan\u3002",
16412
+ parameters: {
16413
+ type: "object",
16414
+ properties: {
16415
+ rowIndex: { type: "integer", minimum: 0 },
16416
+ columnIndex: { type: "integer", minimum: 0 },
16417
+ rowSpan: { type: "integer", minimum: 1 },
16418
+ colSpan: { type: "integer", minimum: 1 }
16419
+ },
16420
+ required: ["rowIndex", "columnIndex", "rowSpan", "colSpan"],
16421
+ additionalProperties: false
16422
+ }
16423
+ },
16424
+ {
16425
+ name: "configure-auto-merge",
16426
+ 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',
16427
+ parameters: {
16428
+ type: "object",
16429
+ properties: {
16430
+ enabled: { type: "boolean" },
16431
+ rowKeys: { type: "array", items: fieldPathSchema },
16432
+ rowColumns: { type: "array", items: fieldPathSchema },
16433
+ columnKeys: { type: "array", items: fieldPathSchema }
16434
+ },
16435
+ additionalProperties: false
16436
+ }
16437
+ },
16438
+ {
16439
+ name: "configure-group-aggregation",
16440
+ 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',
16441
+ parameters: {
16442
+ type: "object",
16443
+ properties: {
16444
+ enabled: { type: "boolean" },
16445
+ groupBy: {
16446
+ type: "array",
16447
+ items: { type: "string", minLength: 1 },
16448
+ minItems: 1
16449
+ },
16450
+ sums: {
16451
+ type: "array",
16452
+ items: {
16453
+ type: "object",
16454
+ properties: {
16455
+ column: { type: "string", minLength: 1 },
16456
+ path: { type: "string", minLength: 1 },
16457
+ decimals: { type: "integer", minimum: 0, maximum: 10 }
16458
+ },
16459
+ required: ["column", "path"],
16460
+ additionalProperties: false
16461
+ }
16462
+ },
16463
+ itemsPerRow: { type: "integer", minimum: 1 }
16464
+ },
16465
+ additionalProperties: false
16466
+ }
15604
16467
  }
15605
16468
  ],
15606
16469
  defaultOverflowPolicy: "split",
@@ -15684,7 +16547,7 @@ var tableFactory = {
15684
16547
  };
15685
16548
  }
15686
16549
  };
15687
- var menuGroups21 = [
16550
+ var menuGroups22 = [
15688
16551
  {
15689
16552
  id: "table",
15690
16553
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -17562,6 +18425,7 @@ function TableCellsPanel({
17562
18425
  title: label,
17563
18426
  "aria-label": `${name}\u6587\u672C${label}`,
17564
18427
  "aria-pressed": (textStyle.textAlign ?? "center") === value,
18428
+ type: (textStyle.textAlign ?? "center") === value ? "primary" : "default",
17565
18429
  onClick: () => updateStyle({ textAlign: value })
17566
18430
  },
17567
18431
  value
@@ -17585,6 +18449,7 @@ function TableCellsPanel({
17585
18449
  title: "\u52A0\u7C97",
17586
18450
  "aria-label": `${name}\u6587\u672C\u52A0\u7C97`,
17587
18451
  "aria-pressed": textStyle.bold === true,
18452
+ type: textStyle.bold === true ? "primary" : "default",
17588
18453
  onClick: () => updateStyle({ bold: !textStyle.bold })
17589
18454
  }
17590
18455
  ),
@@ -17595,6 +18460,7 @@ function TableCellsPanel({
17595
18460
  title: "\u503E\u659C",
17596
18461
  "aria-label": `${name}\u6587\u672C\u503E\u659C`,
17597
18462
  "aria-pressed": textStyle.italic === true,
18463
+ type: textStyle.italic === true ? "primary" : "default",
17598
18464
  onClick: () => updateStyle({ italic: !textStyle.italic })
17599
18465
  }
17600
18466
  )
@@ -17611,80 +18477,6 @@ function TableCellsPanel({
17611
18477
  )
17612
18478
  ] });
17613
18479
  }
17614
-
17615
- // src/plugins/table/data/packed-report-defaults.ts
17616
- function fillPackedReportDefaults(columns, rows, current2) {
17617
- const visible = tableLeafColumns(columns).filter((column) => !column.hidden);
17618
- const keys2 = visible.map(
17619
- (column) => typeof column.dataIndex === "string" ? column.dataIndex : ""
17620
- );
17621
- const repeats = /* @__PURE__ */ new Map();
17622
- keys2.forEach((key) => {
17623
- const match = /^(.+?)([1-9]\d*)$/.exec(key);
17624
- if (!match) return;
17625
- const slots = repeats.get(match[1]) ?? /* @__PURE__ */ new Set();
17626
- slots.add(Number(match[2]));
17627
- repeats.set(match[1], slots);
17628
- });
17629
- const series = [...repeats].filter(
17630
- ([, slots]) => slots.has(1) && slots.has(2)
17631
- );
17632
- const itemsPerRow = Math.max(
17633
- 1,
17634
- ...series.map(([, slots]) => Math.max(...slots))
17635
- );
17636
- const sample = rows.find((row) => row && typeof row === "object") ?? {};
17637
- const groupFields = {};
17638
- keys2.forEach((key, index) => {
17639
- const repeated = series.some(
17640
- ([prefix, slots]) => [...slots].some((slot) => key === `${prefix}${slot}`)
17641
- );
17642
- if (key && !repeated && !visible[index]?.summary && visible[index]?.summaryTitle == null) {
17643
- groupFields[key] = key in sample ? key : "";
17644
- }
17645
- });
17646
- const itemFields = series.map(([prefix]) => ({
17647
- prefix,
17648
- .../^(sequence|seq|index|序号)$/i.test(prefix) ? { mode: "index" } : { mode: "value", path: prefix in sample ? prefix : "" }
17649
- }));
17650
- const totals = {};
17651
- visible.forEach((column, index) => {
17652
- const key = keys2[index];
17653
- const summary = column.summary;
17654
- const type = typeof summary === "object" ? summary.type ?? "sum" : "sum";
17655
- if (key && summary && type === "sum") {
17656
- const prefix = series.find(
17657
- ([name, slots]) => [...slots].some((slot) => key === `${name}${slot}`)
17658
- )?.[0];
17659
- totals[key] = {
17660
- sumPath: key in sample ? key : prefix && prefix in sample ? prefix : "",
17661
- ...typeof summary === "object" && summary.precision != null ? { decimals: summary.precision } : {}
17662
- };
17663
- }
17664
- });
17665
- const subtotalLabelKey = keys2.find(
17666
- (key) => key && !(key in totals) && !(key in groupFields)
17667
- );
17668
- const totalLabelKey = keys2.find((key) => key && !(key in totals));
17669
- const subtotal = { ...totals };
17670
- if (subtotalLabelKey) subtotal[subtotalLabelKey] = { text: "\u5C0F\u8BA1" };
17671
- if (totalLabelKey) totals[totalLabelKey] = { text: "\u603B\u8BA1" };
17672
- return {
17673
- groupBy: current2?.groupBy ?? [],
17674
- itemsPerRow: current2?.itemsPerRow ?? itemsPerRow,
17675
- groupFields: Object.keys(current2?.groupFields ?? {}).length ? current2.groupFields : groupFields,
17676
- groupMergeColumns: Object.keys(current2?.groupFields ?? {}).length ? current2.groupMergeColumns : keys2.flatMap(
17677
- (key, index) => key && key in groupFields ? [index] : []
17678
- ),
17679
- itemFields: current2?.itemFields?.length ? current2.itemFields : itemFields,
17680
- subtotal: Object.keys(current2?.subtotal ?? {}).length ? current2.subtotal : subtotal,
17681
- subtotalMerges: current2?.subtotalMerges ?? [],
17682
- total: Object.keys(current2?.total ?? {}).length ? current2.total : totals,
17683
- totalMerges: current2?.totalMerges ?? [],
17684
- appendRows: current2?.appendRows ?? [],
17685
- ...current2?.footerElementIds ? { footerElementIds: current2.footerElementIds } : {}
17686
- };
17687
- }
17688
18480
  var isTableRows = (value) => Array.isArray(value) && value.every(
17689
18481
  (row) => row !== null && typeof row === "object" && !Array.isArray(row)
17690
18482
  );
@@ -18841,7 +19633,7 @@ function PackedReportPanel({
18841
19633
  ] })
18842
19634
  ] });
18843
19635
  }
18844
- var fieldPath = (value) => Array.isArray(value) ? value.join(".") : String(value);
19636
+ var fieldPath2 = (value) => Array.isArray(value) ? value.join(".") : String(value);
18845
19637
  function TableAutoMergePanel({
18846
19638
  element,
18847
19639
  samples = [],
@@ -18894,7 +19686,7 @@ function TableAutoMergePanel({
18894
19686
  reactPrintDesign.DataPathPicker,
18895
19687
  {
18896
19688
  label: `${label} ${index + 1}`,
18897
- value: fieldPath(value),
19689
+ value: fieldPath2(value),
18898
19690
  samples,
18899
19691
  onChange: (path) => set(
18900
19692
  values.map(
@@ -19477,16 +20269,19 @@ function TableColumnsPanel({
19477
20269
  ] });
19478
20270
  }
19479
20271
  function fixedTableWidth(columns) {
19480
- return tableLeafColumns(columns).filter((column) => !column.hidden).reduce((sum, column) => sum + Math.min(
19481
- column.maxWidth ?? Number.POSITIVE_INFINITY,
19482
- Math.max(column.minWidth ?? 1, column.width ?? 100)
19483
- ), 0) * 25.4 / 96;
20272
+ return tableLeafColumns(columns).filter((column) => !column.hidden).reduce(
20273
+ (sum, column) => sum + Math.min(
20274
+ column.maxWidth ?? Number.POSITIVE_INFINITY,
20275
+ Math.max(column.minWidth ?? 1, column.width ?? 100)
20276
+ ),
20277
+ 0
20278
+ ) * 25.4 / 96;
19484
20279
  }
19485
20280
  function TableColumnsControl(context) {
19486
20281
  if (context.element.type !== "table") return null;
19487
20282
  const element = context.element;
19488
20283
  const page = context.page;
19489
- return /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
20284
+ return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-column-control cc-print-design-field-full", children: [
19490
20285
  /* @__PURE__ */ jsxRuntime.jsx(
19491
20286
  TableColumnsPanel,
19492
20287
  {
@@ -19518,10 +20313,18 @@ function TableColumnsControl(context) {
19518
20313
  {
19519
20314
  icon: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactPlusOutlined, { "aria-hidden": "true" }),
19520
20315
  disabled: context.readonly,
19521
- onClick: () => context.onChange({ columns: [
19522
- ...element.columns,
19523
- { key: crypto.randomUUID(), title: "\u65B0\u5217", dataIndex: `field${element.columns.length + 1}`, cellType: "text", width: 100 }
19524
- ] }),
20316
+ onClick: () => context.onChange({
20317
+ columns: [
20318
+ ...element.columns,
20319
+ {
20320
+ key: crypto.randomUUID(),
20321
+ title: "\u65B0\u5217",
20322
+ dataIndex: `field${element.columns.length + 1}`,
20323
+ cellType: "text",
20324
+ width: 100
20325
+ }
20326
+ ]
20327
+ }),
19525
20328
  children: "\u6DFB\u52A0\u5217"
19526
20329
  }
19527
20330
  ),
@@ -19741,7 +20544,7 @@ var propertySections21 = [
19741
20544
  // src/plugins/table/react.ts
19742
20545
  var tablePlugin = defineBuiltinReactPlugin(tableNativePlugin, {
19743
20546
  factory: tableFactory,
19744
- menuGroups: menuGroups21,
20547
+ menuGroups: menuGroups22,
19745
20548
  contextMenu: tableContextMenu,
19746
20549
  propertySections: propertySections21
19747
20550
  });
@@ -19817,7 +20620,7 @@ var pivotTableFactory = {
19817
20620
  };
19818
20621
  }
19819
20622
  };
19820
- var menuGroups22 = [
20623
+ var menuGroups23 = [
19821
20624
  {
19822
20625
  id: "table",
19823
20626
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -20522,7 +21325,7 @@ var pivotTablePlugin = defineBuiltinReactPlugin(
20522
21325
  pivotTableNativePlugin,
20523
21326
  {
20524
21327
  factory: pivotTableFactory,
20525
- menuGroups: menuGroups22,
21328
+ menuGroups: menuGroups23,
20526
21329
  propertySections: propertySections22
20527
21330
  }
20528
21331
  );
@@ -20597,7 +21400,7 @@ var ganttFactory = {
20597
21400
  };
20598
21401
  }
20599
21402
  };
20600
- var menuGroups23 = [
21403
+ var menuGroups24 = [
20601
21404
  {
20602
21405
  id: "table",
20603
21406
  title: "\u8868\u683C\u7EC4\u4EF6",
@@ -20971,7 +21774,7 @@ var propertySections23 = [
20971
21774
  // src/plugins/gantt/react.ts
20972
21775
  var ganttPlugin = defineBuiltinReactPlugin(ganttNativePlugin, {
20973
21776
  factory: ganttFactory,
20974
- menuGroups: menuGroups23,
21777
+ menuGroups: menuGroups24,
20975
21778
  propertySections: propertySections23
20976
21779
  });
20977
21780
  function formatTime(value) {
@@ -21745,6 +22548,7 @@ var pagePropertyPanels = new reactPrintDesign.PrintDesignScopedPropertyRegistry(
21745
22548
  reactComponents.ReactButton,
21746
22549
  {
21747
22550
  "aria-pressed": settings?.showGrid ?? false,
22551
+ type: settings?.showGrid ? "primary" : "default",
21748
22552
  disabled: readonly,
21749
22553
  onClick: () => onSettingsChange?.({
21750
22554
  showGrid: !(settings?.showGrid ?? false)
@@ -21884,9 +22688,9 @@ var themeSettingsSections = [{
21884
22688
  render: ({ preferences }, readonly, onChange) => /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cc-print-design-theme-options", role: "group", "aria-label": "\u7F16\u8F91\u5668\u4E3B\u9898", children: Object.keys(reactPrintDesign.editorThemes).map((key) => {
21885
22689
  const theme = reactPrintDesign.editorThemes[key];
21886
22690
  return /* @__PURE__ */ jsxRuntime.jsxs(
21887
- "button",
22691
+ reactComponents.ReactButton,
21888
22692
  {
21889
- type: "button",
22693
+ type: (preferences.theme ?? "light") === key ? "primary" : "default",
21890
22694
  className: "cc-print-design-theme-option",
21891
22695
  "aria-pressed": (preferences.theme ?? "light") === key,
21892
22696
  disabled: readonly,
@@ -22311,23 +23115,97 @@ var settingsInteractionTool = {
22311
23115
  sectionId: "interaction",
22312
23116
  settingsSections: interactionSettingsSections
22313
23117
  };
22314
-
22315
- // src/tools/settings-indicators/properties.ts
22316
- var indicatorSettingsSections = [{
22317
- sectionId: "indicators",
22318
- title: "\u56FE\u5C42\u72B6\u6001\u6807\u7B7E",
22319
- fields: [
22320
- {
22321
- path: "canvas.indicatorColor",
22322
- label: "\u6807\u7B7E\u989C\u8272",
22323
- kind: "color",
22324
- persistence: "local",
22325
- read: ({ settings }) => settings.indicatorColor ?? "#ffffff",
22326
- write: (indicatorColor) => ({ kind: "canvas", patch: { indicatorColor } })
22327
- },
22328
- {
22329
- path: "canvas.indicatorBackground",
22330
- label: "\u6807\u7B7E\u80CC\u666F\u8272",
23118
+ var keyboardMoveSettingsSections = [
23119
+ {
23120
+ sectionId: "keyboard-move",
23121
+ title: "\u952E\u76D8\u79FB\u52A8",
23122
+ fields: [
23123
+ {
23124
+ path: "canvas.keyboardMoveStep",
23125
+ label: "\u65B9\u5411\u952E\u6B65\u957F",
23126
+ kind: "number",
23127
+ persistence: "local",
23128
+ min: 1e-3,
23129
+ read: ({ settings, preferences }) => printDesign.toDisplayUnit(
23130
+ settings.keyboardMoveStep ?? 1,
23131
+ preferences.displayUnit
23132
+ ),
23133
+ write: (value, { preferences }) => ({
23134
+ kind: "canvas",
23135
+ patch: {
23136
+ keyboardMoveStep: Math.max(
23137
+ 0.01,
23138
+ printDesign.fromDisplayUnit(value, preferences.displayUnit)
23139
+ )
23140
+ }
23141
+ })
23142
+ },
23143
+ {
23144
+ path: "canvas.keyboardMoveAcceleration",
23145
+ label: "\u957F\u6309\u52A0\u901F",
23146
+ kind: "toggle",
23147
+ persistence: "local",
23148
+ onLabel: "\u5F00\u542F",
23149
+ offLabel: "\u5173\u95ED",
23150
+ read: ({ settings }) => settings.keyboardMoveAcceleration ?? false,
23151
+ write: (keyboardMoveAcceleration) => ({
23152
+ kind: "canvas",
23153
+ patch: { keyboardMoveAcceleration }
23154
+ })
23155
+ },
23156
+ {
23157
+ path: "help.keyboardMove",
23158
+ label: "\u64CD\u4F5C\u63D0\u793A",
23159
+ kind: "hint",
23160
+ persistence: "session",
23161
+ 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"
23162
+ }
23163
+ ]
23164
+ }
23165
+ ];
23166
+
23167
+ // src/tools/settings-keyboard-move/react.tsx
23168
+ var settingsKeyboardMoveTool = {
23169
+ toolId: "builtin.settings.keyboard-move",
23170
+ version: "0.1.0",
23171
+ label: "\u952E\u76D8\u79FB\u52A8",
23172
+ order: 60,
23173
+ placement: "section",
23174
+ parentToolId: "builtin.settings",
23175
+ sectionId: "keyboard-move",
23176
+ settingsSections: keyboardMoveSettingsSections,
23177
+ resolveKeyboardMove(event, heldMs, settings) {
23178
+ const direction = {
23179
+ ArrowLeft: { dx: -1, dy: 0 },
23180
+ ArrowRight: { dx: 1, dy: 0 },
23181
+ ArrowUp: { dx: 0, dy: -1 },
23182
+ ArrowDown: { dx: 0, dy: 1 }
23183
+ }[event.key];
23184
+ if (!direction) return null;
23185
+ const configuredStep = settings.keyboardMoveStep ?? 1;
23186
+ const baseStep = Number.isFinite(configuredStep) && configuredStep > 0 ? configuredStep : 1;
23187
+ const acceleration = settings.keyboardMoveAcceleration === true ? heldMs >= 1800 ? 10 : heldMs >= 1e3 ? 5 : heldMs >= 500 ? 2 : 1 : 1;
23188
+ const step = baseStep * acceleration * (event.shiftKey ? 10 : 1);
23189
+ return { dx: direction.dx * step, dy: direction.dy * step };
23190
+ }
23191
+ };
23192
+
23193
+ // src/tools/settings-indicators/properties.ts
23194
+ var indicatorSettingsSections = [{
23195
+ sectionId: "indicators",
23196
+ title: "\u56FE\u5C42\u72B6\u6001\u6807\u7B7E",
23197
+ fields: [
23198
+ {
23199
+ path: "canvas.indicatorColor",
23200
+ label: "\u6807\u7B7E\u989C\u8272",
23201
+ kind: "color",
23202
+ persistence: "local",
23203
+ read: ({ settings }) => settings.indicatorColor ?? "#ffffff",
23204
+ write: (indicatorColor) => ({ kind: "canvas", patch: { indicatorColor } })
23205
+ },
23206
+ {
23207
+ path: "canvas.indicatorBackground",
23208
+ label: "\u6807\u7B7E\u80CC\u666F\u8272",
22331
23209
  kind: "color",
22332
23210
  persistence: "local",
22333
23211
  read: ({ settings }) => settings.indicatorBackground ?? "#2563eb",
@@ -22503,7 +23381,7 @@ function parsePrintDesignAiChatSettings(value) {
22503
23381
  }
22504
23382
 
22505
23383
  // src/ai-chat/providers/stream-chat-completion.ts
22506
- async function readChatCompletionStream(response, onDelta) {
23384
+ async function readChatCompletionStream(response, onDelta, pause, signal) {
22507
23385
  const toolCalls = /* @__PURE__ */ new Map();
22508
23386
  let content = "";
22509
23387
  let reasoning = "";
@@ -22544,6 +23422,7 @@ async function readChatCompletionStream(response, onDelta) {
22544
23422
  }
22545
23423
  };
22546
23424
  if (!response.body) {
23425
+ await pause?.waitIfPaused(signal);
22547
23426
  accept(await response.json());
22548
23427
  finished = true;
22549
23428
  } else {
@@ -22552,7 +23431,8 @@ async function readChatCompletionStream(response, onDelta) {
22552
23431
  let buffer = "";
22553
23432
  let pendingJson = "";
22554
23433
  let rawJsonAccepted = false;
22555
- const consumeLine = (rawLine) => {
23434
+ const consumeLine = async (rawLine) => {
23435
+ await pause?.waitIfPaused(signal);
22556
23436
  const line = rawLine.replace(/\r$/, "").trimStart();
22557
23437
  if (!line || line.startsWith("event:") || line.startsWith(":")) return;
22558
23438
  const data = line.startsWith("data:") ? line.slice(5).trimStart() : line;
@@ -22578,12 +23458,13 @@ ${data}` : data;
22578
23458
  };
22579
23459
  try {
22580
23460
  while (true) {
23461
+ await pause?.waitIfPaused(signal);
22581
23462
  const { done, value } = await reader.read();
22582
23463
  if (done) break;
22583
23464
  buffer += decoder.decode(value, { stream: true });
22584
23465
  let lineEnd = buffer.indexOf("\n");
22585
23466
  while (lineEnd >= 0) {
22586
- consumeLine(buffer.slice(0, lineEnd));
23467
+ await consumeLine(buffer.slice(0, lineEnd));
22587
23468
  buffer = buffer.slice(lineEnd + 1);
22588
23469
  if (finished) break;
22589
23470
  lineEnd = buffer.indexOf("\n");
@@ -22594,7 +23475,7 @@ ${data}` : data;
22594
23475
  }
22595
23476
  }
22596
23477
  buffer += decoder.decode();
22597
- if (!finished && buffer.trim()) consumeLine(buffer);
23478
+ if (!finished && buffer.trim()) await consumeLine(buffer);
22598
23479
  if (pendingJson) throw new Error("\u6A21\u578B\u6D41\u5305\u542B\u65E0\u6CD5\u89E3\u6790\u7684\u6570\u636E\u3002");
22599
23480
  if (!finished && rawJsonAccepted) finished = true;
22600
23481
  } finally {
@@ -22609,14 +23490,68 @@ ${data}` : data;
22609
23490
  };
22610
23491
  }
22611
23492
 
23493
+ // src/ai-chat/model/message-payload.ts
23494
+ function safeName(name) {
23495
+ return name.replace(/[\r\n\t]/g, " ").slice(0, 160);
23496
+ }
23497
+ function chatMessageContent(message) {
23498
+ if (message.role !== "user" || !message.attachments?.length)
23499
+ return message.content;
23500
+ const body = [message.content.trim()];
23501
+ for (const attachment of message.attachments)
23502
+ if (attachment.kind === "text")
23503
+ body.push(
23504
+ `\u9644\u4EF6\u300C${safeName(attachment.name)}\u300D\u5185\u5BB9\uFF1A
23505
+ ${attachment.text}
23506
+ \u9644\u4EF6\u5185\u5BB9\u7ED3\u675F\u3002`
23507
+ );
23508
+ const text = body.filter(Boolean).join("\n\n") || "\u8BF7\u5206\u6790\u9644\u4EF6\u3002";
23509
+ const images = message.attachments.filter(
23510
+ (attachment) => attachment.kind === "image"
23511
+ );
23512
+ if (!images.length) return text;
23513
+ return [
23514
+ { type: "text", text },
23515
+ ...images.map((attachment) => ({
23516
+ type: "image_url",
23517
+ image_url: { url: attachment.dataUrl }
23518
+ }))
23519
+ ];
23520
+ }
23521
+ function unsupportedImageRequest(messages, status) {
23522
+ return [400, 415, 422].includes(status) && messages.some(
23523
+ (message) => message.attachments?.some((attachment) => attachment.kind === "image")
23524
+ );
23525
+ }
23526
+
22612
23527
  // src/ai-chat/providers/openai-compatible.ts
22613
- function agentSystemContent(selection) {
22614
- const base = "\u4F60\u662F\u6253\u5370\u8BBE\u8BA1\u5668\u52A9\u624B\u3002\u9875\u9762\u548C\u5143\u7D20\u5750\u6807\u5355\u4F4D\u4E3A\u6BEB\u7C73\u3002\u9700\u8981\u67E5\u770B\u6216\u4FEE\u6539\u753B\u5E03\u65F6\u8C03\u7528\u5DE5\u5177\uFF0C\u4E0D\u8981\u731C\u6D4B\u9875\u9762\u6216\u5143\u7D20 ID\u3002\u521B\u5EFA\u8868\u683C\u7B49\u63D2\u4EF6\u7EC4\u4EF6\u524D\u5148\u8C03\u7528 list_components \u548C get_component_template\uFF1B\u4FEE\u6539\u5DF2\u6709\u5143\u7D20\u5148\u8C03\u7528 get_element\uFF1B\u7EC4\u4EF6\u4E13\u7528\u64CD\u4F5C\u4F7F\u7528 execute_component_command\u3002";
22615
- if (!selection) return base;
23528
+ var toolActivity = {
23529
+ get_document: "\u6B63\u5728\u67E5\u770B\u8BBE\u8BA1\u6587\u6863\u2026",
23530
+ get_selection: "\u6B63\u5728\u67E5\u770B\u9009\u533A\u2026",
23531
+ list_components: "\u6B63\u5728\u67E5\u770B\u7EC4\u4EF6\u2026",
23532
+ get_component_template: "\u6B63\u5728\u67E5\u770B\u7EC4\u4EF6\u6A21\u677F\u2026",
23533
+ get_element: "\u6B63\u5728\u67E5\u770B\u5143\u7D20\u2026",
23534
+ set_active_page: "\u6B63\u5728\u5207\u6362\u9875\u9762\u2026",
23535
+ select_elements: "\u6B63\u5728\u9009\u62E9\u5143\u7D20\u2026",
23536
+ add_element: "\u6B63\u5728\u6DFB\u52A0\u5143\u7D20\u2026",
23537
+ update_element: "\u6B63\u5728\u4FEE\u6539\u5143\u7D20\u2026",
23538
+ remove_elements: "\u6B63\u5728\u79FB\u9664\u5143\u7D20\u2026",
23539
+ execute_component_command: "\u6B63\u5728\u7F16\u8F91\u7EC4\u4EF6\u2026",
23540
+ undo: "\u6B63\u5728\u64A4\u9500\u2026",
23541
+ redo: "\u6B63\u5728\u91CD\u505A\u2026",
23542
+ get_plugin_structure: "\u6B63\u5728\u67E5\u770B\u63D2\u4EF6\u76EE\u5F55\u7ED3\u6784\u2026",
23543
+ list_plugin_sources: "\u6B63\u5728\u67E5\u627E\u5DF2\u6709\u63D2\u4EF6\u2026",
23544
+ get_plugin_source: "\u6B63\u5728\u8BFB\u53D6\u5DF2\u6709\u63D2\u4EF6\u6E90\u7801\u2026",
23545
+ create_plugin_archive: "\u6B63\u5728\u6784\u5EFA\u63D2\u4EF6 ZIP\u2026"
23546
+ };
23547
+ function agentSystemContent(selection, pluginAuthoring = false, pluginSource = false) {
23548
+ const base = "\u4F60\u662F\u6253\u5370\u8BBE\u8BA1\u5668\u52A9\u624B\u3002\u9875\u9762\u5C3A\u5BF8\u53CA\u5143\u7D20\u901A\u7528 x\u3001y\u3001width\u3001height \u4F7F\u7528\u8BBE\u8BA1\u5668\u7684\u5168\u5C40\u663E\u793A\u5355\u4F4D\uFF1B\u5148\u8C03\u7528 get_document \u67E5\u770B displayUnit\uFF0C\u518D\u6309\u8BE5\u5355\u4F4D\u8BFB\u5199\u8FD9\u4E9B\u6570\u503C\u3002\u7EC4\u4EF6\u4E13\u5C5E\u5B57\u6BB5\u9075\u5FAA\u7EC4\u4EF6\u6A21\u677F\u8BF4\u660E\u3002\u9700\u8981\u67E5\u770B\u6216\u4FEE\u6539\u753B\u5E03\u65F6\u8C03\u7528\u5DE5\u5177\uFF0C\u4E0D\u8981\u731C\u6D4B\u9875\u9762\u6216\u5143\u7D20 ID\u3002\u521B\u5EFA\u8868\u683C\u7B49\u63D2\u4EF6\u7EC4\u4EF6\u524D\u5148\u8C03\u7528 list_components \u548C get_component_template\uFF1B\u4FEE\u6539\u5DF2\u6709\u5143\u7D20\u5148\u8C03\u7528 get_element\uFF1B\u7EC4\u4EF6\u4E13\u7528\u64CD\u4F5C\u5148\u67E5\u770B\u6A21\u677F\u4E2D\u7684\u547D\u4EE4\u53CA payload \u53C2\u6570\u683C\u5F0F\uFF0C\u518D\u4F7F\u7528 execute_component_command\u3002\u8868\u683C\u7684\u5408\u5E76\u3001\u81EA\u52A8\u5408\u5E76\u548C\u5206\u7EC4\u805A\u5408\u4F18\u5148\u4F7F\u7528\u5BF9\u5E94\u547D\u4EE4\u3002";
23549
+ const content = pluginAuthoring ? `${base} \u5982\u679C\u7528\u6237\u8981\u4F60\u7F16\u5199\u63D2\u4EF6\uFF0C\u5148\u8C03\u7528 get_plugin_structure\uFF0C\u6309\u8FD4\u56DE\u7684\u76EE\u5F55\u7ED3\u6784\u7F16\u5199\u6E90\u7801\uFF1B${pluginSource ? "\u5347\u7EA7\u5DF2\u6709\u63D2\u4EF6\u65F6\uFF0C\u82E5\u7528\u6237\u53EA\u7ED9\u540D\u79F0\uFF0C\u5148\u8C03\u7528 list_plugin_sources \u786E\u8BA4 packageId\uFF0C\u518D\u8C03\u7528 get_plugin_source \u8BFB\u53D6\u5DF2\u6709\u6E90\u7801\uFF0C\u5E76\u4EE5\u5B83\u4E3A\u57FA\u7840\u4FEE\u6539\uFF1B\u5FC5\u987B\u4FDD\u7559\u539F packageId \u548C\u7EC4\u4EF6 type\u3001\u63D0\u9AD8 version\uFF0C\u4E0D\u5F97\u53E6\u8D77\u65B0\u5305\u6216\u4ECE 0.1.0 \u91CD\u5EFA\u3002" : ""}\u7136\u540E\u8C03\u7528 create_plugin_archive \u6784\u5EFA\u5F52\u6863\u3002React \u5165\u53E3\u5FC5\u987B\u4E3A\u7EC4\u4EF6\u6CE8\u518C propertySections\uFF0C\u5217\u51FA\u7EC4\u4EF6\u4E13\u5C5E\u914D\u7F6E\u9879\uFF1Bfields \u7684 path \u8981\u4E0E\u521B\u5EFA\u5668\u9ED8\u8BA4\u5143\u7D20\u5B57\u6BB5\u4E00\u81F4\u3002\u53EA\u5411\u7528\u6237\u62A5\u544A\u5DE5\u5177\u771F\u5B9E\u8FD4\u56DE\u7684\u6784\u5EFA\u7ED3\u679C\uFF1B\u4E0D\u8981\u7F16\u9020\u4E0B\u8F7D\u94FE\u63A5\u3001\u5B89\u88C5\u6216\u53D1\u5E03\u72B6\u6001\u3002\u63D2\u4EF6\u6E90\u7801\u5FC5\u987B\u4FDD\u6301\u539F\u751F\u5165\u53E3\u4E0E React \u5165\u53E3\u5206\u79BB\u3002` : base;
23550
+ if (!selection) return content;
22616
23551
  if (!selection.elements.length)
22617
- return `${base} \u672C\u6B21\u6D88\u606F\u6CA1\u6709\u9644\u5E26\u753B\u5E03\u5143\u7D20\u3002\u4E0D\u8981\u628A\u753B\u5E03\u4E2D\u4ECD\u7136\u9009\u4E2D\u7684\u5143\u7D20\u5F53\u4F5C\u804A\u5929\u4FEE\u6539\u76EE\u6807\uFF1B\u5982\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\uFF0C\u8BF7\u5148\u8BF7\u7528\u6237\u91CD\u65B0\u9009\u62E9\u76EE\u6807\u3002`;
23552
+ return `${content} \u672C\u6B21\u6D88\u606F\u6CA1\u6709\u9644\u5E26\u753B\u5E03\u5143\u7D20\u3002\u4E0D\u8981\u628A\u753B\u5E03\u4E2D\u4ECD\u7136\u9009\u4E2D\u7684\u5143\u7D20\u5F53\u4F5C\u804A\u5929\u4FEE\u6539\u76EE\u6807\uFF1B\u5982\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\uFF0C\u8BF7\u5148\u8BF7\u7528\u6237\u91CD\u65B0\u9009\u62E9\u76EE\u6807\u3002`;
22618
23553
  const targets = selection.elements.map(({ id, type }) => ({ id, type }));
22619
- return `${base} \u672C\u6B21\u7528\u6237\u53D1\u9001\u6D88\u606F\u65F6\u9009\u4E2D\u7684\u9875\u9762 ID \u4E3A ${JSON.stringify(selection.pageId)}\uFF0C\u5143\u7D20\u4E3A ${JSON.stringify(targets)}\u3002\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\u65F6\uFF0C\u5148\u7528 get_element \u8BFB\u53D6\u8FD9\u4E9B\u5143\u7D20\uFF0C\u518D\u6839\u636E\u8BF7\u6C42\u4FEE\u6539\uFF1B\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u4E0D\u4FEE\u6539\u5176\u4ED6\u5143\u7D20\u3002`;
23554
+ return `${content} \u672C\u6B21\u7528\u6237\u53D1\u9001\u6D88\u606F\u65F6\u9009\u4E2D\u7684\u9875\u9762 ID \u4E3A ${JSON.stringify(selection.pageId)}\uFF0C\u5143\u7D20\u4E3A ${JSON.stringify(targets)}\u3002\u7528\u6237\u8981\u6C42\u4FEE\u6539\u9009\u4E2D\u5185\u5BB9\u65F6\uFF0C\u5148\u7528 get_element \u8BFB\u53D6\u8FD9\u4E9B\u5143\u7D20\uFF0C\u518D\u6839\u636E\u8BF7\u6C42\u4FEE\u6539\uFF1B\u9664\u975E\u7528\u6237\u660E\u786E\u8981\u6C42\uFF0C\u4E0D\u4FEE\u6539\u5176\u4ED6\u5143\u7D20\u3002`;
22620
23555
  }
22621
23556
  function endpoint2(baseUrl, path) {
22622
23557
  const base = baseUrl.trim().replace(/\/+$/, "");
@@ -22636,6 +23571,7 @@ async function requestJson(url, key, init = {}) {
22636
23571
  return response.json();
22637
23572
  }
22638
23573
  var defaultPrintDesignAiChatProvider = {
23574
+ supportsPause: true,
22639
23575
  async listModels(config, signal) {
22640
23576
  const value = await requestJson(
22641
23577
  endpoint2(config.baseUrl, "models"),
@@ -22650,21 +23586,30 @@ var defaultPrintDesignAiChatProvider = {
22650
23586
  (id) => typeof id === "string" && id.length > 0
22651
23587
  ).sort();
22652
23588
  },
22653
- async complete(config, messages, signal, agentApi) {
23589
+ async complete(config, messages, signal, agentApi, pause) {
22654
23590
  const history = [
22655
23591
  ...agentApi ? [
22656
23592
  {
22657
23593
  role: "system",
22658
- content: agentSystemContent(config.selection)
23594
+ content: agentSystemContent(
23595
+ config.selection,
23596
+ agentApi.tools.some(
23597
+ (tool) => tool.name === "create_plugin_archive"
23598
+ ),
23599
+ agentApi.tools.some(
23600
+ (tool) => tool.name === "get_plugin_source"
23601
+ )
23602
+ )
22659
23603
  }
22660
23604
  ] : [],
22661
- ...messages.map(({ role, content, reasoning }) => ({
22662
- role,
22663
- content,
22664
- ...agentApi && role === "assistant" && reasoning ? { reasoning_content: reasoning } : {}
23605
+ ...messages.map((message) => ({
23606
+ role: message.role,
23607
+ content: chatMessageContent(message),
23608
+ ...agentApi && message.role === "assistant" && message.reasoning ? { reasoning_content: message.reasoning } : {}
22665
23609
  }))
22666
23610
  ];
22667
23611
  for (let turn = 0; turn < 8; turn++) {
23612
+ await pause?.waitIfPaused(signal);
22668
23613
  const value = await requestJson(
22669
23614
  endpoint2(config.baseUrl, "chat/completions"),
22670
23615
  config.key,
@@ -22684,7 +23629,15 @@ var defaultPrintDesignAiChatProvider = {
22684
23629
  } : {}
22685
23630
  })
22686
23631
  }
22687
- );
23632
+ ).catch((cause) => {
23633
+ const status = Number(
23634
+ cause instanceof Error ? cause.message.match(/((\d+))/)?.[1] : NaN
23635
+ );
23636
+ if (unsupportedImageRequest(messages, status))
23637
+ throw new Error("\u5F53\u524D\u6A21\u578B\u6682\u4E0D\u652F\u6301\u56FE\u7247\u6D88\u606F\u3002");
23638
+ throw cause;
23639
+ });
23640
+ await pause?.waitIfPaused(signal);
22688
23641
  const message = value && typeof value === "object" && "choices" in value && Array.isArray(value.choices) ? value.choices[0]?.message : null;
22689
23642
  if (!message || typeof message !== "object")
22690
23643
  throw new Error("\u6A21\u578B\u6CA1\u6709\u8FD4\u56DE\u6709\u6548\u6D88\u606F\u3002");
@@ -22701,13 +23654,15 @@ var defaultPrintDesignAiChatProvider = {
22701
23654
  const name = call?.function?.name;
22702
23655
  let result;
22703
23656
  try {
23657
+ await pause?.waitIfPaused(signal);
22704
23658
  if (!id || typeof name !== "string")
22705
23659
  throw new TypeError("\u6A21\u578B\u5DE5\u5177\u8C03\u7528\u683C\u5F0F\u65E0\u6548\u3002");
22706
- result = agentApi.call(
23660
+ result = await agentApi.call(
22707
23661
  name,
22708
23662
  JSON.parse(call.function.arguments ?? "{}")
22709
23663
  );
22710
23664
  } catch (cause) {
23665
+ if (signal?.aborted) throw cause;
22711
23666
  result = {
22712
23667
  error: cause instanceof Error ? cause.message : "\u5DE5\u5177\u6267\u884C\u5931\u8D25\u3002"
22713
23668
  };
@@ -22721,23 +23676,32 @@ var defaultPrintDesignAiChatProvider = {
22721
23676
  }
22722
23677
  throw new Error("Agent \u5DE5\u5177\u8C03\u7528\u6B21\u6570\u8FC7\u591A\uFF0C\u8BF7\u7F29\u5C0F\u4EFB\u52A1\u8303\u56F4\u3002");
22723
23678
  },
22724
- async stream(config, messages, onDelta, signal, agentApi) {
23679
+ async stream(config, messages, onDelta, signal, agentApi, pause) {
22725
23680
  const history = [
22726
23681
  ...agentApi ? [
22727
23682
  {
22728
23683
  role: "system",
22729
- content: agentSystemContent(config.selection)
23684
+ content: agentSystemContent(
23685
+ config.selection,
23686
+ agentApi.tools.some(
23687
+ (tool) => tool.name === "create_plugin_archive"
23688
+ ),
23689
+ agentApi.tools.some(
23690
+ (tool) => tool.name === "get_plugin_source"
23691
+ )
23692
+ )
22730
23693
  }
22731
23694
  ] : [],
22732
- ...messages.map(({ role, content: content2, reasoning: reasoning2 }) => ({
22733
- role,
22734
- content: content2,
22735
- ...agentApi && role === "assistant" && reasoning2 ? { reasoning_content: reasoning2 } : {}
23695
+ ...messages.map((message) => ({
23696
+ role: message.role,
23697
+ content: chatMessageContent(message),
23698
+ ...agentApi && message.role === "assistant" && message.reasoning ? { reasoning_content: message.reasoning } : {}
22736
23699
  }))
22737
23700
  ];
22738
23701
  let content = "";
22739
23702
  let reasoning = "";
22740
23703
  for (let turn = 0; turn < 8; turn++) {
23704
+ await pause?.waitIfPaused(signal);
22741
23705
  const response = await fetch(
22742
23706
  endpoint2(config.baseUrl, "chat/completions"),
22743
23707
  {
@@ -22762,9 +23726,17 @@ var defaultPrintDesignAiChatProvider = {
22762
23726
  })
22763
23727
  }
22764
23728
  );
23729
+ if (unsupportedImageRequest(messages, response.status) && !response.ok)
23730
+ throw new Error("\u5F53\u524D\u6A21\u578B\u6682\u4E0D\u652F\u6301\u56FE\u7247\u6D88\u606F\u3002");
22765
23731
  if (!response.ok)
22766
23732
  throw new Error(`\u6A21\u578B\u670D\u52A1\u8BF7\u6C42\u5931\u8D25\uFF08${response.status}\uFF09\u3002`);
22767
- const result = await readChatCompletionStream(response, onDelta);
23733
+ await pause?.waitIfPaused(signal);
23734
+ const result = await readChatCompletionStream(
23735
+ response,
23736
+ onDelta,
23737
+ pause,
23738
+ signal
23739
+ );
22768
23740
  content += result.content;
22769
23741
  reasoning += result.reasoning;
22770
23742
  if (!result.toolCalls.length) {
@@ -22781,17 +23753,23 @@ var defaultPrintDesignAiChatProvider = {
22781
23753
  for (const call of result.toolCalls) {
22782
23754
  let output;
22783
23755
  try {
23756
+ await pause?.waitIfPaused(signal);
22784
23757
  if (!call.id || !call.function.name)
22785
23758
  throw new TypeError("\u6A21\u578B\u5DE5\u5177\u8C03\u7528\u683C\u5F0F\u65E0\u6548\u3002");
22786
- output = agentApi.call(
23759
+ onDelta({
23760
+ activity: toolActivity[call.function.name] ?? "\u6B63\u5728\u64CD\u4F5C\u753B\u5E03\u2026"
23761
+ });
23762
+ output = await agentApi.call(
22787
23763
  call.function.name,
22788
23764
  JSON.parse(call.function.arguments || "{}")
22789
23765
  );
22790
23766
  } catch (cause) {
23767
+ if (signal?.aborted) throw cause;
22791
23768
  output = {
22792
23769
  error: cause instanceof Error ? cause.message : "\u5DE5\u5177\u6267\u884C\u5931\u8D25\u3002"
22793
23770
  };
22794
23771
  }
23772
+ onDelta({ activity: "" });
22795
23773
  history.push({
22796
23774
  role: "tool",
22797
23775
  tool_call_id: call.id,
@@ -22807,17 +23785,17 @@ var defaultPrintDesignAiChatProvider = {
22807
23785
  var DATABASE = "canvas-components-print-design-ai-chat";
22808
23786
  var STORE = "private-config";
22809
23787
  function openDatabase() {
22810
- return new Promise((resolve, reject) => {
23788
+ return new Promise((resolve2, reject) => {
22811
23789
  const request = indexedDB.open(DATABASE, 1);
22812
23790
  request.onupgradeneeded = () => request.result.createObjectStore(STORE);
22813
- request.onsuccess = () => resolve(request.result);
23791
+ request.onsuccess = () => resolve2(request.result);
22814
23792
  request.onerror = () => reject(request.error);
22815
23793
  });
22816
23794
  }
22817
23795
  function read(database, key) {
22818
- return new Promise((resolve, reject) => {
23796
+ return new Promise((resolve2, reject) => {
22819
23797
  const request = database.transaction(STORE, "readonly").objectStore(STORE).get(key);
22820
- request.onsuccess = () => resolve(request.result);
23798
+ request.onsuccess = () => resolve2(request.result);
22821
23799
  request.onerror = () => reject(request.error);
22822
23800
  });
22823
23801
  }
@@ -22838,11 +23816,11 @@ async function savePrintDesignAiChatSettings(settings) {
22838
23816
  key,
22839
23817
  bytes
22840
23818
  );
22841
- await new Promise((resolve, reject) => {
23819
+ await new Promise((resolve2, reject) => {
22842
23820
  const transaction = database.transaction(STORE, "readwrite");
22843
23821
  transaction.objectStore(STORE).put(key, "key");
22844
23822
  transaction.objectStore(STORE).put({ iv, ciphertext }, "config");
22845
- transaction.oncomplete = () => resolve();
23823
+ transaction.oncomplete = () => resolve2();
22846
23824
  transaction.onerror = () => reject(transaction.error);
22847
23825
  transaction.onabort = () => reject(transaction.error);
22848
23826
  });
@@ -22875,14 +23853,37 @@ async function readPrintDesignAiChatSettings() {
22875
23853
 
22876
23854
  // src/ai-chat/model/reasoning.ts
22877
23855
  var LIVE_REASONING_LIMIT = 8e3;
23856
+
23857
+ // src/ai-chat/model/message-format.ts
23858
+ function formatAssistantMessage(content, reasoning = "") {
23859
+ const extracted = [];
23860
+ const body = content.replace(
23861
+ /<(think|thinking)>([\s\S]*?)<\/\1>/gi,
23862
+ (_match, _tag, text) => {
23863
+ if (text.trim()) extracted.push(text.trim());
23864
+ return "";
23865
+ }
23866
+ ).replace(/<(?:think|thinking)>[\s\S]*$/i, "").trim();
23867
+ const thought = [reasoning, ...extracted.filter((text) => !reasoning.includes(text))].filter(Boolean).join("\n").replace(/<\/?(?:think|thinking)>/gi, "").replace(/\*\*\s*\*\*/g, "**\n**").trim();
23868
+ return { content: body, reasoning: thought };
23869
+ }
23870
+ function FormattedAiText({ text }) {
23871
+ const pieces = text.split(/(\*\*[^*]+\*\*|`[^`]+`)/g);
23872
+ return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, { children: pieces.map(
23873
+ (piece, index) => piece.startsWith("**") && piece.endsWith("**") ? /* @__PURE__ */ jsxRuntime.jsx("strong", { children: piece.slice(2, -2) }, index) : piece.startsWith("`") && piece.endsWith("`") ? /* @__PURE__ */ jsxRuntime.jsx("code", { children: piece.slice(1, -1) }, index) : /* @__PURE__ */ jsxRuntime.jsx(react.Fragment, { children: piece }, index)
23874
+ ) });
23875
+ }
22878
23876
  var ESTIMATED_HEIGHT = 104;
22879
23877
  var OVERSCAN = 3;
22880
23878
  function VirtualMessages({
22881
23879
  messages,
22882
23880
  currentModel,
22883
23881
  busy = false,
23882
+ paused = false,
22884
23883
  pendingModel,
22885
- streaming
23884
+ streaming,
23885
+ onPreviewImage,
23886
+ onDownloadArtifact
22886
23887
  }) {
22887
23888
  const viewport = react.useRef(null);
22888
23889
  const followTail = react.useRef(true);
@@ -22890,6 +23891,10 @@ function VirtualMessages({
22890
23891
  const [viewportHeight, setViewportHeight] = react.useState(500);
22891
23892
  const [heights, setHeights] = react.useState({});
22892
23893
  const showThinking = busy && messages[messages.length - 1]?.role !== "assistant";
23894
+ const liveMessage = formatAssistantMessage(
23895
+ streaming?.content ?? "",
23896
+ streaming?.reasoning ?? ""
23897
+ );
22893
23898
  const offsets = react.useMemo(() => {
22894
23899
  const next = [0];
22895
23900
  for (const message of messages)
@@ -22949,6 +23954,8 @@ function VirtualMessages({
22949
23954
  {
22950
23955
  message,
22951
23956
  currentModel,
23957
+ onPreviewImage,
23958
+ onDownloadArtifact,
22952
23959
  top: offsets[first + index],
22953
23960
  onHeight: (height) => setHeights(
22954
23961
  (current2) => current2[message.id] === height ? current2 : { ...current2, [message.id]: height }
@@ -22959,20 +23966,20 @@ function VirtualMessages({
22959
23966
  showThinking && /* @__PURE__ */ jsxRuntime.jsxs(
22960
23967
  "div",
22961
23968
  {
22962
- className: "cc-print-design-ai-message cc-print-design-ai-message-assistant cc-print-design-ai-message-thinking",
23969
+ className: `cc-print-design-ai-message cc-print-design-ai-message-assistant cc-print-design-ai-message-thinking${paused ? " is-paused" : ""}`,
22963
23970
  role: "status",
22964
23971
  "aria-live": "polite",
22965
23972
  children: [
22966
23973
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: pendingModel?.trim() || currentModel?.trim() || "AI" }),
22967
- streaming?.reasoning && /* @__PURE__ */ jsxRuntime.jsx(
23974
+ liveMessage.reasoning && /* @__PURE__ */ jsxRuntime.jsx(
22968
23975
  ReasoningBlock,
22969
23976
  {
22970
- text: streaming.reasoning,
22971
- totalLength: streaming.reasoningLength,
23977
+ text: liveMessage.reasoning,
23978
+ totalLength: streaming?.reasoningLength ?? liveMessage.reasoning.length,
22972
23979
  live: true
22973
23980
  }
22974
23981
  ),
22975
- streaming?.content && /* @__PURE__ */ jsxRuntime.jsx("p", { children: streaming.content }),
23982
+ liveMessage.content && /* @__PURE__ */ jsxRuntime.jsx("p", { children: /* @__PURE__ */ jsxRuntime.jsx(FormattedAiText, { text: liveMessage.content }) }),
22976
23983
  /* @__PURE__ */ jsxRuntime.jsxs("p", { className: "cc-print-design-ai-thinking-indicator", children: [
22977
23984
  /* @__PURE__ */ jsxRuntime.jsxs(
22978
23985
  "span",
@@ -22986,7 +23993,7 @@ function VirtualMessages({
22986
23993
  ]
22987
23994
  }
22988
23995
  ),
22989
- streaming?.content ? "\u751F\u6210\u4E2D\u2026" : "\u601D\u8003\u4E2D\u2026"
23996
+ paused ? "\u5DF2\u6682\u505C" : streaming?.activity || (liveMessage.content ? "\u751F\u6210\u4E2D\u2026" : "\u601D\u8003\u4E2D\u2026")
22990
23997
  ] })
22991
23998
  ]
22992
23999
  }
@@ -22998,10 +24005,13 @@ function VirtualMessages({
22998
24005
  function MeasuredMessage({
22999
24006
  message,
23000
24007
  currentModel,
24008
+ onPreviewImage,
24009
+ onDownloadArtifact,
23001
24010
  top,
23002
24011
  onHeight
23003
24012
  }) {
23004
24013
  const ref = react.useRef(null);
24014
+ const formatted = message.role === "assistant" ? formatAssistantMessage(message.content, message.reasoning) : { content: message.content, reasoning: "" };
23005
24015
  react.useEffect(() => {
23006
24016
  const element = ref.current;
23007
24017
  if (!element) return;
@@ -23019,8 +24029,57 @@ function MeasuredMessage({
23019
24029
  style: { position: "absolute", top, width: "100%" },
23020
24030
  children: [
23021
24031
  /* @__PURE__ */ jsxRuntime.jsx("span", { children: message.role === "user" ? "\u4F60" : message.model?.trim() || currentModel?.trim() || "AI" }),
23022
- message.role === "assistant" && message.reasoning && /* @__PURE__ */ jsxRuntime.jsx(ReasoningBlock, { text: message.reasoning }),
23023
- /* @__PURE__ */ jsxRuntime.jsx("p", { children: message.content })
24032
+ message.role === "assistant" && formatted.reasoning && /* @__PURE__ */ jsxRuntime.jsx(ReasoningBlock, { text: formatted.reasoning }),
24033
+ formatted.content && /* @__PURE__ */ jsxRuntime.jsx("p", { children: message.role === "assistant" ? /* @__PURE__ */ jsxRuntime.jsx(FormattedAiText, { text: formatted.content }) : formatted.content }),
24034
+ message.role === "assistant" && message.artifacts?.map((artifact) => /* @__PURE__ */ jsxRuntime.jsxs(
24035
+ "button",
24036
+ {
24037
+ type: "button",
24038
+ className: "cc-print-design-ai-artifact",
24039
+ "aria-label": `\u4E0B\u8F7D\u63D2\u4EF6 ${artifact.name} ZIP`,
24040
+ disabled: !onDownloadArtifact,
24041
+ onClick: () => onDownloadArtifact?.(artifact),
24042
+ children: [
24043
+ /* @__PURE__ */ jsxRuntime.jsxs("strong", { children: [
24044
+ "\u{1F4E6} ",
24045
+ artifact.name
24046
+ ] }),
24047
+ /* @__PURE__ */ jsxRuntime.jsxs("span", { children: [
24048
+ artifact.packageId,
24049
+ " \xB7 ",
24050
+ artifact.version
24051
+ ] }),
24052
+ /* @__PURE__ */ jsxRuntime.jsx("small", { children: "\u4E0B\u8F7D\u540E\u5728\u201C\u63D2\u4EF6\u5217\u8868 \u2192 \u5BFC\u5165\u63D2\u4EF6\u5305\u201D\u5B89\u88C5\uFF0C\u9009\u4E2D\u7EC4\u4EF6\u5373\u53EF\u67E5\u770B\u53F3\u4FA7\u914D\u7F6E\u3002" }),
24053
+ /* @__PURE__ */ jsxRuntime.jsx("span", { children: "\u4E0B\u8F7D ZIP" })
24054
+ ]
24055
+ },
24056
+ artifact.id
24057
+ )),
24058
+ message.role === "user" && message.attachments?.length ? /* @__PURE__ */ jsxRuntime.jsx(
24059
+ "div",
24060
+ {
24061
+ className: "cc-print-design-ai-message-attachments",
24062
+ "aria-label": "\u6D88\u606F\u9644\u4EF6",
24063
+ children: message.attachments.map(
24064
+ (attachment, index) => attachment.kind === "image" ? /* @__PURE__ */ jsxRuntime.jsxs("figure", { children: [
24065
+ /* @__PURE__ */ jsxRuntime.jsx(
24066
+ "button",
24067
+ {
24068
+ type: "button",
24069
+ className: "cc-print-design-ai-image-trigger",
24070
+ "aria-label": `\u9884\u89C8\u56FE\u7247 ${attachment.name}`,
24071
+ onClick: () => onPreviewImage?.(attachment.dataUrl, attachment.name),
24072
+ children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: attachment.dataUrl, alt: "" })
24073
+ }
24074
+ ),
24075
+ /* @__PURE__ */ jsxRuntime.jsx("figcaption", { children: attachment.name })
24076
+ ] }, `${index}:${attachment.name}`) : /* @__PURE__ */ jsxRuntime.jsxs("span", { title: attachment.name, children: [
24077
+ "\u{1F4C4} ",
24078
+ attachment.name
24079
+ ] }, `${index}:${attachment.name}`)
24080
+ )
24081
+ }
24082
+ ) : null
23024
24083
  ]
23025
24084
  }
23026
24085
  );
@@ -23031,19 +24090,42 @@ function ReasoningBlock({
23031
24090
  live = false
23032
24091
  }) {
23033
24092
  const viewport = react.useRef(null);
24093
+ const contentId = react.useId();
24094
+ const [expanded, setExpanded] = react.useState(live);
23034
24095
  const visible = live ? text.slice(-LIVE_REASONING_LIMIT) : text;
23035
24096
  const hidden = live ? Math.max(0, totalLength - visible.length) : 0;
23036
24097
  react.useEffect(() => {
23037
24098
  if (live && viewport.current)
23038
24099
  viewport.current.scrollTop = viewport.current.scrollHeight;
23039
24100
  }, [live, totalLength]);
23040
- return /* @__PURE__ */ jsxRuntime.jsxs("details", { className: "cc-print-design-ai-reasoning", open: live || void 0, children: [
23041
- /* @__PURE__ */ jsxRuntime.jsx("summary", { children: "\u601D\u8003\u8FC7\u7A0B" }),
23042
- /* @__PURE__ */ jsxRuntime.jsxs("div", { ref: viewport, children: [
23043
- hidden ? `\u524D ${hidden} \u5B57\u6682\u4E0D\u663E\u793A\uFF0C\u56DE\u590D\u5B8C\u6210\u540E\u53EF\u5C55\u5F00\u5168\u6587\u3002
24101
+ return /* @__PURE__ */ jsxRuntime.jsxs("section", { className: "cc-print-design-ai-reasoning", children: [
24102
+ /* @__PURE__ */ jsxRuntime.jsxs(
24103
+ "button",
24104
+ {
24105
+ type: "button",
24106
+ className: "cc-print-design-ai-reasoning-trigger",
24107
+ "aria-expanded": expanded,
24108
+ "aria-controls": contentId,
24109
+ onClick: () => setExpanded((current2) => !current2),
24110
+ children: [
24111
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactRightOutlined, { "aria-hidden": "true" }),
24112
+ "\u601D\u8003\u8FC7\u7A0B"
24113
+ ]
24114
+ }
24115
+ ),
24116
+ /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactCollapseMotion, { open: expanded, children: /* @__PURE__ */ jsxRuntime.jsxs(
24117
+ "div",
24118
+ {
24119
+ id: contentId,
24120
+ ref: viewport,
24121
+ className: "cc-print-design-ai-reasoning-content",
24122
+ children: [
24123
+ hidden ? `\u524D ${hidden} \u5B57\u6682\u4E0D\u663E\u793A\uFF0C\u56DE\u590D\u5B8C\u6210\u540E\u53EF\u5C55\u5F00\u5168\u6587\u3002
23044
24124
  ` : "",
23045
- visible
23046
- ] })
24125
+ /* @__PURE__ */ jsxRuntime.jsx(FormattedAiText, { text: visible })
24126
+ ]
24127
+ }
24128
+ ) })
23047
24129
  ] });
23048
24130
  }
23049
24131
  function ChatSettings({
@@ -23360,17 +24442,23 @@ function ChatSettingsDialog(props) {
23360
24442
  }
23361
24443
  function ChatComposer({
23362
24444
  input,
24445
+ attachments = [],
24446
+ attaching = false,
23363
24447
  model,
23364
24448
  models,
23365
24449
  reasoningEffort,
23366
24450
  selection,
23367
24451
  onInputChange,
24452
+ onAddFiles,
24453
+ onRemoveAttachment,
24454
+ onPreviewImage,
23368
24455
  onModelChange,
23369
24456
  onReasoningEffortChange,
23370
24457
  onRemoveSelectedElement,
23371
24458
  onOpenSettings,
23372
24459
  onSend
23373
24460
  }) {
24461
+ const fileInput = react.useRef(null);
23374
24462
  const handleKeyDown = (event) => {
23375
24463
  if (event.key === "Enter" && !event.shiftKey) {
23376
24464
  event.preventDefault();
@@ -23401,6 +24489,35 @@ function ChatComposer({
23401
24489
  element.id
23402
24490
  )) })
23403
24491
  ] }) : null,
24492
+ attachments.length ? /* @__PURE__ */ jsxRuntime.jsx("div", { className: "cc-print-design-ai-attachments", "aria-label": "\u5F85\u53D1\u9001\u9644\u4EF6", children: attachments.map((attachment, index) => /* @__PURE__ */ jsxRuntime.jsxs(
24493
+ "div",
24494
+ {
24495
+ className: "cc-print-design-ai-attachment",
24496
+ children: [
24497
+ attachment.kind === "image" ? /* @__PURE__ */ jsxRuntime.jsx(
24498
+ "button",
24499
+ {
24500
+ type: "button",
24501
+ className: "cc-print-design-ai-image-trigger",
24502
+ "aria-label": `\u9884\u89C8\u56FE\u7247 ${attachment.name}`,
24503
+ onClick: () => onPreviewImage?.(attachment.dataUrl, attachment.name),
24504
+ children: /* @__PURE__ */ jsxRuntime.jsx("img", { src: attachment.dataUrl, alt: "" })
24505
+ }
24506
+ ) : /* @__PURE__ */ jsxRuntime.jsx("span", { "aria-hidden": "true", children: "\u6587" }),
24507
+ /* @__PURE__ */ jsxRuntime.jsx("span", { title: attachment.name, children: attachment.name }),
24508
+ /* @__PURE__ */ jsxRuntime.jsx(
24509
+ "button",
24510
+ {
24511
+ type: "button",
24512
+ "aria-label": `\u79FB\u9664\u9644\u4EF6 ${attachment.name}`,
24513
+ onClick: () => onRemoveAttachment?.(index),
24514
+ children: "\xD7"
24515
+ }
24516
+ )
24517
+ ]
24518
+ },
24519
+ `${index}:${attachment.name}`
24520
+ )) }) : null,
23404
24521
  /* @__PURE__ */ jsxRuntime.jsx(
23405
24522
  "textarea",
23406
24523
  {
@@ -23408,47 +24525,84 @@ function ChatComposer({
23408
24525
  value: input,
23409
24526
  onChange: (event) => onInputChange(event.target.value),
23410
24527
  onKeyDown: handleKeyDown,
24528
+ onPaste: (event) => {
24529
+ const files = Array.from(event.clipboardData.files);
24530
+ if (files.length) {
24531
+ event.preventDefault();
24532
+ onAddFiles?.(files);
24533
+ }
24534
+ },
23411
24535
  placeholder: "\u8F93\u5165\u6D88\u606F\uFF0CEnter \u53D1\u9001\uFF0CShift+Enter \u6362\u884C",
23412
24536
  rows: 3
23413
24537
  }
23414
24538
  ),
23415
24539
  /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-composer-tools", children: [
23416
24540
  /* @__PURE__ */ jsxRuntime.jsx(
23417
- "button",
24541
+ "input",
23418
24542
  {
23419
- type: "button",
23420
- className: "cc-print-design-ai-composer-more",
23421
- "aria-label": "\u66F4\u591A AI \u8BBE\u7F6E",
23422
- title: "\u6A21\u578B\u914D\u7F6E",
23423
- onClick: onOpenSettings,
23424
- children: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactMoreOutlined, { "aria-hidden": "true" })
23425
- }
23426
- ),
23427
- /* @__PURE__ */ jsxRuntime.jsx(
23428
- reactComponents.ReactSelect,
23429
- {
23430
- "aria-label": "AI \u5F53\u524D\u6A21\u578B",
23431
- value: model,
23432
- options: models.map((item) => ({ label: item, value: item })),
23433
- allowClear: false,
23434
- allowCustomValue: true,
23435
- placeholder: "\u9009\u62E9\u6A21\u578B",
23436
- popupZIndex: 1100,
23437
- onChange: onModelChange
24543
+ ref: fileInput,
24544
+ type: "file",
24545
+ multiple: true,
24546
+ hidden: true,
24547
+ "aria-label": "\u9009\u62E9\u804A\u5929\u9644\u4EF6",
24548
+ onChange: (event) => {
24549
+ onAddFiles?.(Array.from(event.currentTarget.files ?? []));
24550
+ event.currentTarget.value = "";
24551
+ }
23438
24552
  }
23439
24553
  ),
23440
- /* @__PURE__ */ jsxRuntime.jsx(
23441
- reactComponents.ReactSelect,
23442
- {
23443
- "aria-label": "AI \u5F53\u524D\u601D\u8003\u7A0B\u5EA6",
23444
- value: reasoningEffort ?? "",
23445
- options: reasoningEffortOptions,
23446
- allowClear: false,
23447
- showSearch: false,
23448
- popupZIndex: 1100,
23449
- onChange: (value) => onReasoningEffortChange(parseReasoningEffort(value))
23450
- }
23451
- )
24554
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-composer-options", children: [
24555
+ /* @__PURE__ */ jsxRuntime.jsx(
24556
+ reactComponents.ReactSelect,
24557
+ {
24558
+ "aria-label": "AI \u5F53\u524D\u6A21\u578B",
24559
+ value: model,
24560
+ options: models.map((item) => ({ label: item, value: item })),
24561
+ allowClear: false,
24562
+ allowCustomValue: true,
24563
+ placeholder: "\u9009\u62E9\u6A21\u578B",
24564
+ popupZIndex: 1100,
24565
+ onChange: onModelChange
24566
+ }
24567
+ ),
24568
+ /* @__PURE__ */ jsxRuntime.jsx(
24569
+ reactComponents.ReactSelect,
24570
+ {
24571
+ "aria-label": "AI \u5F53\u524D\u601D\u8003\u7A0B\u5EA6",
24572
+ value: reasoningEffort ?? "",
24573
+ options: reasoningEffortOptions,
24574
+ allowClear: false,
24575
+ showSearch: false,
24576
+ popupZIndex: 1100,
24577
+ onChange: (value) => onReasoningEffortChange(parseReasoningEffort(value))
24578
+ }
24579
+ )
24580
+ ] }),
24581
+ /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "cc-print-design-ai-composer-actions", children: [
24582
+ /* @__PURE__ */ jsxRuntime.jsx(
24583
+ "button",
24584
+ {
24585
+ type: "button",
24586
+ className: "cc-print-design-ai-composer-attach",
24587
+ "aria-label": "\u6DFB\u52A0\u9644\u4EF6",
24588
+ title: "\u6DFB\u52A0\u56FE\u7247\u6216\u6587\u672C\u9644\u4EF6",
24589
+ disabled: attaching,
24590
+ onClick: () => fileInput.current?.click(),
24591
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactPaperClipOutlined, { "aria-hidden": "true" })
24592
+ }
24593
+ ),
24594
+ /* @__PURE__ */ jsxRuntime.jsx(
24595
+ "button",
24596
+ {
24597
+ type: "button",
24598
+ className: "cc-print-design-ai-composer-more",
24599
+ "aria-label": "\u66F4\u591A AI \u8BBE\u7F6E",
24600
+ title: "\u6A21\u578B\u914D\u7F6E",
24601
+ onClick: onOpenSettings,
24602
+ children: /* @__PURE__ */ jsxRuntime.jsx(reactComponents.ReactMoreOutlined, { "aria-hidden": "true" })
24603
+ }
24604
+ )
24605
+ ] })
23452
24606
  ] })
23453
24607
  ] });
23454
24608
  }
@@ -23469,6 +24623,40 @@ function ChatNoticeDialog({ message, onClose }) {
23469
24623
  );
23470
24624
  }
23471
24625
 
24626
+ // src/ai-chat/model/pause-control.ts
24627
+ function createPrintDesignAiChatPauseControl() {
24628
+ let paused = false;
24629
+ const waiters = /* @__PURE__ */ new Set();
24630
+ return {
24631
+ pause() {
24632
+ paused = true;
24633
+ },
24634
+ resume() {
24635
+ paused = false;
24636
+ for (const release of waiters) release();
24637
+ waiters.clear();
24638
+ },
24639
+ waitIfPaused(signal) {
24640
+ if (signal?.aborted)
24641
+ return Promise.reject(signal.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
24642
+ if (!paused) return Promise.resolve();
24643
+ return new Promise((resolve2, reject) => {
24644
+ const release = () => {
24645
+ signal?.removeEventListener("abort", onAbort);
24646
+ waiters.delete(release);
24647
+ resolve2();
24648
+ };
24649
+ const onAbort = () => {
24650
+ waiters.delete(release);
24651
+ reject(signal?.reason ?? new Error("\u64CD\u4F5C\u5DF2\u53D6\u6D88\u3002"));
24652
+ };
24653
+ waiters.add(release);
24654
+ signal?.addEventListener("abort", onAbort, { once: true });
24655
+ });
24656
+ }
24657
+ };
24658
+ }
24659
+
23472
24660
  // src/ai-chat/model/selection-agent-api.ts
23473
24661
  var changesSelection = /* @__PURE__ */ new Set([
23474
24662
  "set_active_page",
@@ -23501,17 +24689,17 @@ var DATABASE2 = "canvas-components-print-design-ai-chat-history";
23501
24689
  var STORE2 = "conversations";
23502
24690
  async function openDatabase2() {
23503
24691
  if (typeof indexedDB === "undefined") return null;
23504
- return new Promise((resolve, reject) => {
24692
+ return new Promise((resolve2, reject) => {
23505
24693
  const request = indexedDB.open(DATABASE2, 1);
23506
24694
  request.onupgradeneeded = () => request.result.createObjectStore(STORE2, { keyPath: "id" });
23507
- request.onsuccess = () => resolve(request.result);
24695
+ request.onsuccess = () => resolve2(request.result);
23508
24696
  request.onerror = () => reject(request.error);
23509
24697
  });
23510
24698
  }
23511
24699
  async function access(mode, action, fallback) {
23512
24700
  const database = await openDatabase2();
23513
24701
  if (!database) return fallback;
23514
- return new Promise((resolve, reject) => {
24702
+ return new Promise((resolve2, reject) => {
23515
24703
  const transaction = database.transaction(STORE2, mode);
23516
24704
  let result = fallback;
23517
24705
  action(transaction.objectStore(STORE2), (value) => {
@@ -23519,7 +24707,7 @@ async function access(mode, action, fallback) {
23519
24707
  });
23520
24708
  transaction.oncomplete = () => {
23521
24709
  database.close();
23522
- resolve(result);
24710
+ resolve2(result);
23523
24711
  };
23524
24712
  transaction.onerror = () => {
23525
24713
  database.close();
@@ -23584,11 +24772,13 @@ function useChatSession(provider, agentApi) {
23584
24772
  const [activeId, setActiveId] = react.useState(null);
23585
24773
  const [messages, setMessages] = react.useState([]);
23586
24774
  const [busy, setBusy] = react.useState(false);
24775
+ const [paused, setPaused] = react.useState(false);
23587
24776
  const [pendingModel, setPendingModel] = react.useState("");
23588
24777
  const [streaming, setStreaming] = react.useState(null);
23589
24778
  const [error, setError] = react.useState("");
23590
24779
  const nextMessageId = react.useRef(1);
23591
24780
  const controller = react.useRef(null);
24781
+ const pauseControl = react.useRef(null);
23592
24782
  const activeConversation = react.useRef(null);
23593
24783
  const pendingWrite = react.useRef(Promise.resolve());
23594
24784
  react.useEffect(() => {
@@ -23624,8 +24814,8 @@ function useChatSession(provider, agentApi) {
23624
24814
  setError("\u5386\u53F2\u5BF9\u8BDD\u65E0\u6CD5\u4FDD\u5B58\u5230\u5F53\u524D\u6D4F\u89C8\u5668\u3002");
23625
24815
  }
23626
24816
  };
23627
- const send = async (content, config) => {
23628
- if (!content.trim() || busy) return;
24817
+ const send = async (content, config, attachments = []) => {
24818
+ if (!content.trim() && !attachments.length || busy) return;
23629
24819
  if (!config.baseUrl || !config.model) {
23630
24820
  setError("\u8BF7\u5148\u914D\u7F6E\u6A21\u578B\u3002");
23631
24821
  return;
@@ -23633,13 +24823,14 @@ function useChatSession(provider, agentApi) {
23633
24823
  const user = {
23634
24824
  id: nextMessageId.current++,
23635
24825
  role: "user",
23636
- content: content.trim()
24826
+ content: content.trim(),
24827
+ ...attachments.length ? { attachments: [...attachments] } : {}
23637
24828
  };
23638
24829
  const now = Date.now();
23639
24830
  const previous = activeConversation.current;
23640
24831
  const conversation = {
23641
24832
  id: previous?.id ?? conversationId(),
23642
- title: previous?.title ?? content.trim().slice(0, 36),
24833
+ title: previous?.title ?? (content.trim().slice(0, 36) || `\u9644\u4EF6\uFF1A${attachments[0]?.name ?? "\u6D88\u606F"}`),
23643
24834
  createdAt: previous?.createdAt ?? now,
23644
24835
  updatedAt: now,
23645
24836
  messages: [...messages, user]
@@ -23648,23 +24839,43 @@ function useChatSession(provider, agentApi) {
23648
24839
  setMessages(conversation.messages);
23649
24840
  setBusy(true);
23650
24841
  setPendingModel(config.model);
23651
- setStreaming({ content: "", reasoning: "", reasoningLength: 0 });
24842
+ setStreaming({
24843
+ content: "",
24844
+ reasoning: "",
24845
+ reasoningLength: 0,
24846
+ activity: ""
24847
+ });
23652
24848
  setError("");
23653
- void persist(conversation);
23654
24849
  const abort = new AbortController();
23655
24850
  controller.current = abort;
24851
+ const pause2 = createPrintDesignAiChatPauseControl();
24852
+ pauseControl.current = pause2;
24853
+ const artifacts = [];
23656
24854
  try {
23657
24855
  const requestMessages = conversation.messages.map(
23658
- ({ role, content: text, reasoning }) => ({
24856
+ ({ role, content: text, reasoning, attachments: attached }) => ({
23659
24857
  role,
23660
24858
  content: text,
23661
- ...reasoning ? { reasoning } : {}
24859
+ ...reasoning ? { reasoning } : {},
24860
+ ...attached?.length ? { attachments: attached } : {}
23662
24861
  })
23663
24862
  );
23664
- const requestAgentApi = createSelectionScopedAgentApi(
24863
+ const scopedAgentApi = createSelectionScopedAgentApi(
23665
24864
  agentApi,
23666
24865
  config.selection
23667
24866
  );
24867
+ const requestAgentApi = {
24868
+ tools: scopedAgentApi.tools,
24869
+ call(name, input) {
24870
+ const capture = (result2) => {
24871
+ if (name === "create_plugin_archive" && result2 && typeof result2 === "object" && "id" in result2 && typeof result2.id === "string" && "sha256" in result2 && typeof result2.sha256 === "string")
24872
+ artifacts.push(result2);
24873
+ return result2;
24874
+ };
24875
+ const result = scopedAgentApi.call(name, input);
24876
+ return result instanceof Promise ? result.then(capture) : capture(result);
24877
+ }
24878
+ };
23668
24879
  const answer = provider.stream ? await provider.stream(
23669
24880
  config,
23670
24881
  requestMessages,
@@ -23672,17 +24883,20 @@ function useChatSession(provider, agentApi) {
23672
24883
  (current2) => current2 ? {
23673
24884
  content: current2.content + (delta.content ?? ""),
23674
24885
  reasoning: (current2.reasoning + (delta.reasoning ?? "")).slice(-LIVE_REASONING_LIMIT),
23675
- reasoningLength: current2.reasoningLength + (delta.reasoning?.length ?? 0)
24886
+ reasoningLength: current2.reasoningLength + (delta.reasoning?.length ?? 0),
24887
+ activity: delta.activity ?? current2.activity
23676
24888
  } : current2
23677
24889
  ),
23678
24890
  abort.signal,
23679
- requestAgentApi
24891
+ requestAgentApi,
24892
+ pause2
23680
24893
  ) : {
23681
24894
  content: await provider.complete(
23682
24895
  config,
23683
24896
  requestMessages,
23684
24897
  abort.signal,
23685
- requestAgentApi
24898
+ requestAgentApi,
24899
+ pause2
23686
24900
  )
23687
24901
  };
23688
24902
  const completed = {
@@ -23695,6 +24909,7 @@ function useChatSession(provider, agentApi) {
23695
24909
  role: "assistant",
23696
24910
  content: answer.content,
23697
24911
  model: config.model,
24912
+ ...artifacts.length ? { artifacts } : {},
23698
24913
  ..."reasoning" in answer && answer.reasoning ? { reasoning: answer.reasoning } : {}
23699
24914
  }
23700
24915
  ]
@@ -23702,11 +24917,36 @@ function useChatSession(provider, agentApi) {
23702
24917
  setMessages(completed.messages);
23703
24918
  await persist(completed);
23704
24919
  } catch (cause) {
24920
+ if (artifacts.length) {
24921
+ const completed = {
24922
+ ...conversation,
24923
+ updatedAt: Date.now(),
24924
+ messages: [
24925
+ ...conversation.messages,
24926
+ {
24927
+ id: nextMessageId.current++,
24928
+ role: "assistant",
24929
+ content: "\u63D2\u4EF6 ZIP \u5DF2\u751F\u6210\uFF0C\u53EF\u4ECE\u4E0B\u65B9\u4E0B\u8F7D\u3002\u540E\u7EED\u56DE\u590D\u672A\u80FD\u5B8C\u6210\u3002",
24930
+ model: config.model,
24931
+ artifacts
24932
+ }
24933
+ ]
24934
+ };
24935
+ setMessages(completed.messages);
24936
+ await persist(completed);
24937
+ } else {
24938
+ setMessages(messages);
24939
+ setActiveId(previous?.id ?? null);
24940
+ }
23705
24941
  if (!abort.signal.aborted)
23706
24942
  setError(cause instanceof Error ? cause.message : "\u5BF9\u8BDD\u5931\u8D25\u3002");
24943
+ throw cause;
23707
24944
  } finally {
24945
+ pause2.resume();
24946
+ pauseControl.current = null;
23708
24947
  controller.current = null;
23709
24948
  setBusy(false);
24949
+ setPaused(false);
23710
24950
  setPendingModel("");
23711
24951
  setStreaming(null);
23712
24952
  }
@@ -23740,11 +24980,22 @@ function useChatSession(provider, agentApi) {
23740
24980
  nextMessageId.current = 1;
23741
24981
  setError("");
23742
24982
  };
24983
+ const pause = () => {
24984
+ if (!busy || !provider.supportsPause || !pauseControl.current) return;
24985
+ pauseControl.current.pause();
24986
+ setPaused(true);
24987
+ };
24988
+ const resume = () => {
24989
+ pauseControl.current?.resume();
24990
+ setPaused(false);
24991
+ };
23743
24992
  return {
23744
24993
  conversations,
23745
24994
  activeId,
23746
24995
  messages,
23747
24996
  busy,
24997
+ paused,
24998
+ canPause: provider.supportsPause === true,
23748
24999
  pendingModel,
23749
25000
  streaming,
23750
25001
  error,
@@ -23752,7 +25003,227 @@ function useChatSession(provider, agentApi) {
23752
25003
  send,
23753
25004
  select,
23754
25005
  remove,
23755
- newConversation
25006
+ newConversation,
25007
+ pause,
25008
+ resume
25009
+ };
25010
+ }
25011
+
25012
+ // src/ai-chat/model/attachments.ts
25013
+ var MAX_CHAT_ATTACHMENTS = 4;
25014
+ var MAX_IMAGE_BYTES = 4 * 1024 * 1024;
25015
+ var MAX_TEXT_BYTES = 100 * 1024;
25016
+ var MAX_TOTAL_BYTES = 8 * 1024 * 1024;
25017
+ var imageTypes = {
25018
+ ".png": "image/png",
25019
+ ".jpg": "image/jpeg",
25020
+ ".jpeg": "image/jpeg",
25021
+ ".webp": "image/webp"
25022
+ };
25023
+ var textTypes = {
25024
+ ".txt": "text/plain",
25025
+ ".md": "text/markdown",
25026
+ ".json": "application/json",
25027
+ ".csv": "text/csv"
25028
+ };
25029
+ function extension(name) {
25030
+ return name.toLowerCase().match(/\.[^.]+$/)?.[0] ?? "";
25031
+ }
25032
+ function dataUrl(file) {
25033
+ return new Promise((resolve2, reject) => {
25034
+ const reader = new FileReader();
25035
+ reader.onload = () => typeof reader.result === "string" ? resolve2(reader.result) : reject(new TypeError("\u56FE\u7247\u8BFB\u53D6\u5931\u8D25\u3002"));
25036
+ reader.onerror = () => reject(reader.error ?? new Error("\u56FE\u7247\u8BFB\u53D6\u5931\u8D25\u3002"));
25037
+ reader.readAsDataURL(file);
25038
+ });
25039
+ }
25040
+ async function readChatAttachment(file, existing) {
25041
+ if (existing.length >= MAX_CHAT_ATTACHMENTS)
25042
+ throw new RangeError(`\u6BCF\u6761\u6D88\u606F\u6700\u591A\u6DFB\u52A0 ${MAX_CHAT_ATTACHMENTS} \u4E2A\u9644\u4EF6\u3002`);
25043
+ const suffix = extension(file.name);
25044
+ const imageType = imageTypes[suffix];
25045
+ const textType = textTypes[suffix];
25046
+ const allowedImage = imageType && (!file.type || file.type === imageType);
25047
+ const allowedText = textType && (!file.type || file.type === textType || file.type === "text/plain" || suffix === ".csv" && file.type === "application/vnd.ms-excel");
25048
+ if (!allowedImage && !allowedText)
25049
+ throw new TypeError(`\u6682\u4E0D\u652F\u6301 ${suffix || file.type || "\u8BE5\u7C7B\u578B"} \u9644\u4EF6\u3002`);
25050
+ if (existing.reduce((sum, item) => sum + item.size, 0) + file.size > MAX_TOTAL_BYTES)
25051
+ throw new RangeError("\u9644\u4EF6\u603B\u5927\u5C0F\u4E0D\u80FD\u8D85\u8FC7 8 MB\u3002");
25052
+ if (allowedImage) {
25053
+ if (file.size > MAX_IMAGE_BYTES)
25054
+ throw new RangeError("\u56FE\u7247\u4E0D\u80FD\u8D85\u8FC7 4 MB\u3002");
25055
+ return {
25056
+ kind: "image",
25057
+ name: file.name,
25058
+ mimeType: imageType,
25059
+ size: file.size,
25060
+ dataUrl: await dataUrl(file)
25061
+ };
25062
+ }
25063
+ if (allowedText) {
25064
+ if (file.size > MAX_TEXT_BYTES)
25065
+ throw new RangeError("\u6587\u672C\u9644\u4EF6\u4E0D\u80FD\u8D85\u8FC7 100 KB\u3002");
25066
+ const text = await file.text();
25067
+ if (!text.trim()) throw new TypeError("\u6587\u672C\u9644\u4EF6\u6CA1\u6709\u53EF\u8BFB\u53D6\u7684\u5185\u5BB9\u3002");
25068
+ return {
25069
+ kind: "text",
25070
+ name: file.name,
25071
+ mimeType: textType,
25072
+ size: file.size,
25073
+ text
25074
+ };
25075
+ }
25076
+ throw new TypeError("\u6682\u4E0D\u652F\u6301\u8BE5\u7C7B\u578B\u7684\u9644\u4EF6\u3002");
25077
+ }
25078
+
25079
+ // src/ai-chat/model/plugin-authoring-api.ts
25080
+ var structure = {
25081
+ directories: {
25082
+ "src/native.js": "\u5FC5\u987B\u5BFC\u51FA printDesignNativePlugin\uFF1B\u53EA\u4F9D\u8D56\u7EAF\u539F\u751F API\uFF0C\u4E0D\u5BFC\u5165 React\u3002",
25083
+ "src/react.js": "\u5FC5\u987B\u5BFC\u51FA printDesignReactPlugin\uFF1B\u6CE8\u518C componentFactories\u3001componentMenu \u548C propertySections\u3002\u5C5E\u6027\u914D\u7F6E\u9762\u677F\u4E0E\u914D\u7F6E\u9879\u5199\u5728\u6B64\u5165\u53E3\u3002",
25084
+ "src/*.js": "\u53EF\u9009\u7684\u5171\u4EAB\u6E90\u7801\u3002\u76F8\u5BF9\u5BFC\u5165\u4F7F\u7528 ./model.js \u5F62\u5F0F\u3002",
25085
+ "dist/*.js": "\u6D4F\u89C8\u5668\u590D\u5236\u5E76\u6821\u9A8C\u751F\u6210\uFF0C\u4E0D\u8981\u63D0\u4EA4\u6784\u5EFA\u4EA7\u7269\u3002",
25086
+ "package.json": "\u6D4F\u89C8\u5668\u751F\u6210\u8FD0\u884C\u65F6\u5305\u58F0\u660E\uFF0C\u4E0D\u8981\u63D0\u4EA4\u3002",
25087
+ "manifest.json": "\u6D4F\u89C8\u5668\u751F\u6210\u6587\u4EF6\u6458\u8981\u548C\u6CE8\u518C\u6E05\u5355\uFF0C\u4E0D\u8981\u63D0\u4EA4\u3002"
25088
+ },
25089
+ rules: [
25090
+ "\u7B2C\u4E00\u7248\u4EC5\u652F\u6301\u4E00\u4E2A\u7EC4\u4EF6\uFF0C\u4E0D\u652F\u6301\u989D\u5916 npm \u4F9D\u8D56\u3001\u5DE5\u5177\u63D2\u4EF6\u6216\u81EA\u5B9A\u4E49\u6784\u5EFA\u811A\u672C\u3002",
25091
+ "\u6E90\u7801\u5FC5\u987B\u662F\u6807\u51C6 ESM JavaScript\uFF1B\u4E0D\u8981\u5199 TypeScript \u7C7B\u578B\u3001TSX \u6216 JSX\u3002",
25092
+ "packageId \u5FC5\u987B\u4E3A @agent/<\u5C0F\u5199\u77ED\u540D>\uFF1BcomponentType \u5FC5\u987B\u4E3A agent.<\u5C0F\u5199\u77ED\u540D>\u3002",
25093
+ "\u539F\u751F\u5165\u53E3\u4F7F\u7528 definePrintDesignPluginRenderer\uFF0C\u63D0\u4F9B validate\u3001drawCanvas \u548C renderHtml\u3002",
25094
+ "React \u5165\u53E3\u5FC5\u987B\u63D0\u4F9B\u4E0E componentType \u4E00\u81F4\u7684 componentFactories\u3001componentMenu \u548C propertySections\uFF1B\u6BCF\u4E2A\u5C5E\u6027\u5206\u7EC4\u5FC5\u987B\u6709\u975E\u7A7A fields\uFF0C\u81F3\u5C11\u914D\u7F6E\u4E00\u4E2A\u7EC4\u4EF6\u4E13\u5C5E\u5B57\u6BB5\u3002",
25095
+ "propertySections \u4EE5\u7EC4\u4EF6 type \u4E3A\u952E\uFF1Bfields \u7684 path \u5BF9\u5E94 create() \u751F\u6210\u7684\u5143\u7D20\u5B57\u6BB5\uFF0C\u586B\u5199 label\u3001kind\u3001defaultValue\uFF0C\u53EF\u6309\u9700\u8865\u5145 min\u3001max\u3001step\u3001options\u3002",
25096
+ "\u4E24\u4E2A\u5165\u53E3\u7684 packageId\u3001version\u3001\u7EC4\u4EF6 type \u5FC5\u987B\u4E0E\u63D0\u4EA4\u53C2\u6570\u5B8C\u5168\u4E00\u81F4\uFF1B\u53EF\u4EE5\u4ECE\u5171\u4EAB\u6E90\u7801\u5BFC\u5165\u8FD9\u4E9B\u5E38\u91CF\u3002",
25097
+ "\u5347\u7EA7\u5DF2\u6709\u63D2\u4EF6\u5FC5\u987B\u4FDD\u7559\u539F packageId \u548C\u7EC4\u4EF6 type\uFF0C\u5E76\u5C06 version \u63D0\u9AD8\uFF1B\u4E0D\u80FD\u4EE5\u65B0\u5305\u540D\u6216 0.1.0 \u4EE3\u66FF\u5347\u7EA7\u3002",
25098
+ "\u63D2\u4EF6\u5143\u7D20\u5185\u90E8\u7684 x\u3001y\u3001width\u3001height \u9075\u5FAA\u6253\u5370\u8BBE\u8BA1\u6587\u6863\u7684\u539F\u751F\u6BEB\u7C73\u5355\u4F4D\uFF1B\u804A\u5929\u753B\u5E03\u5DE5\u5177\u4ECD\u9075\u5FAA\u5168\u5C40\u663E\u793A\u5355\u4F4D\u3002"
25099
+ ],
25100
+ example: {
25101
+ "src/native.js": `import { definePrintDesignPluginRenderer, escapeHtml } from "@canvas-components/print-design";
25102
+ const type = "agent.badge";
25103
+ const version = "0.1.0";
25104
+ const renderer = definePrintDesignPluginRenderer({
25105
+ type,
25106
+ validate: (value) => !!value && typeof value === "object" && "type" in value && value.type === type && "text" in value && typeof value.text === "string",
25107
+ drawCanvas: (element, { ctx, x, y, scale }) => {
25108
+ ctx.fillStyle = "#e8f1ff";
25109
+ ctx.fillRect(x, y, element.width * scale, element.height * scale);
25110
+ ctx.fillStyle = "#1d4ed8";
25111
+ ctx.fillText(String(element.text ?? "\u5FBD\u6807"), x + 4 * scale, y + 8 * scale);
25112
+ },
25113
+ renderHtml: (element) => "<div>" + escapeHtml(element.text) + "</div>",
25114
+ });
25115
+ export const printDesignNativePlugin = {
25116
+ packageId: "@agent/badge", version,
25117
+ components: [{ type, version, renderer }],
25118
+ };`,
25119
+ "src/react.js": `import { createPrintDesignId } from "@canvas-components/print-design";
25120
+ const sections = [{
25121
+ id: "agent.badge.settings", title: "\u5FBD\u6807\u8BBE\u7F6E",
25122
+ fields: [{ path: "text", label: "\u6587\u5B57", kind: "text", defaultValue: "\u5FBD\u6807" }],
25123
+ }];
25124
+ export const printDesignReactPlugin = {
25125
+ packageId: "@agent/badge", version: "0.1.0",
25126
+ componentFactories: [{
25127
+ type: "agent.badge", label: "\u5FBD\u6807",
25128
+ create: () => ({ id: createPrintDesignId("badge"), type: "agent.badge", name: "\u5FBD\u6807", x: 15, y: 15, width: 45, height: 12, text: "\u5FBD\u6807" }),
25129
+ }],
25130
+ componentMenu: [{ id: "agent", title: "Agent \u63D2\u4EF6", items: [{ id: "agent.badge", type: "agent.badge", label: "\u5FBD\u6807", icon: "\u25A3" }] }],
25131
+ propertySections: { "agent.badge": sections },
25132
+ };`
25133
+ }
25134
+ };
25135
+ function createPluginAuthoringAgentApi(base, authoring) {
25136
+ if (!authoring) return base;
25137
+ let structureViewed = false;
25138
+ return {
25139
+ tools: [
25140
+ ...base.tools,
25141
+ {
25142
+ name: "get_plugin_structure",
25143
+ description: "\u8BFB\u53D6\u5355\u7EC4\u4EF6\u63D2\u4EF6\u7684\u56FA\u5B9A\u76EE\u5F55\u7ED3\u6784\u3001\u5165\u53E3\u8981\u6C42\u4E0E\u6700\u5C0F\u6E90\u7801\u793A\u4F8B\uFF1B\u7F16\u5199\u63D2\u4EF6\u524D\u5FC5\u987B\u8C03\u7528\u3002",
25144
+ parameters: {
25145
+ type: "object",
25146
+ properties: {},
25147
+ additionalProperties: false
25148
+ }
25149
+ },
25150
+ ...authoring.listSources ? [
25151
+ {
25152
+ name: "list_plugin_sources",
25153
+ description: "\u5217\u51FA\u5BBF\u4E3B\u5DF2\u751F\u6210\u4E14\u53EF\u8BFB\u53D6\u6E90\u7801\u7684\u63D2\u4EF6\u53CA\u6700\u65B0\u7248\u672C\u3002\u7528\u6237\u53EA\u7ED9\u51FA\u63D2\u4EF6\u540D\u79F0\u65F6\uFF0C\u5148\u7528\u6B64\u5DE5\u5177\u786E\u5B9A packageId\u3002",
25154
+ parameters: {
25155
+ type: "object",
25156
+ properties: {},
25157
+ additionalProperties: false
25158
+ }
25159
+ }
25160
+ ] : [],
25161
+ ...authoring.getSource ? [
25162
+ {
25163
+ name: "get_plugin_source",
25164
+ description: "\u8BFB\u53D6\u5BBF\u4E3B\u5DF2\u751F\u6210\u63D2\u4EF6\u7684\u6E90\u7801\u3002\u5347\u7EA7\u5DF2\u6709\u63D2\u4EF6\u65F6\uFF0C\u5148\u7528 packageId \u8BFB\u53D6\u6700\u65B0\u7248\u672C\uFF0C\u4E5F\u53EF\u6307\u5B9A version\uFF1B\u5728\u8FD4\u56DE\u7684\u6E90\u7801\u57FA\u7840\u4E0A\u4FEE\u6539\uFF0C\u5E76\u628A\u63D0\u4EA4\u7248\u672C\u6539\u4E3A\u65B0\u7248\u672C\u3002",
25165
+ parameters: {
25166
+ type: "object",
25167
+ properties: {
25168
+ packageId: { type: "string" },
25169
+ version: { type: "string" }
25170
+ },
25171
+ required: ["packageId"]
25172
+ }
25173
+ }
25174
+ ] : [],
25175
+ {
25176
+ name: "create_plugin_archive",
25177
+ description: "\u63D0\u4EA4\u6807\u51C6 ESM JavaScript \u6E90\u7801\uFF0C\u5728\u6D4F\u89C8\u5668\u672C\u5730\u6821\u9A8C\u5E76\u751F\u6210\u53EF\u4E0B\u8F7D ZIP\u3002\u5148\u8C03\u7528 get_plugin_structure\uFF1BReact \u5165\u53E3\u5FC5\u987B\u6709 propertySections \u548C\u5B9E\u9645\u914D\u7F6E\u9879\uFF1B\u4E0D\u8981\u81EA\u884C\u62FC\u63A5\u4E0B\u8F7D\u94FE\u63A5\u3002",
25178
+ parameters: {
25179
+ type: "object",
25180
+ properties: {
25181
+ packageId: { type: "string" },
25182
+ version: { type: "string" },
25183
+ componentType: { type: "string" },
25184
+ name: { type: "string" },
25185
+ description: { type: "string" },
25186
+ files: {
25187
+ type: "array",
25188
+ items: {
25189
+ type: "object",
25190
+ properties: {
25191
+ path: { type: "string" },
25192
+ content: { type: "string" }
25193
+ },
25194
+ required: ["path", "content"]
25195
+ }
25196
+ }
25197
+ },
25198
+ required: [
25199
+ "packageId",
25200
+ "version",
25201
+ "componentType",
25202
+ "name",
25203
+ "description",
25204
+ "files"
25205
+ ]
25206
+ }
25207
+ }
25208
+ ],
25209
+ call(name, input) {
25210
+ if (name === "get_plugin_structure") {
25211
+ structureViewed = true;
25212
+ return structure;
25213
+ }
25214
+ if (name === "get_plugin_source" && authoring.getSource)
25215
+ return authoring.getSource(
25216
+ input
25217
+ );
25218
+ if (name === "list_plugin_sources" && authoring.listSources)
25219
+ return authoring.listSources();
25220
+ if (name === "create_plugin_archive") {
25221
+ if (!structureViewed)
25222
+ throw new Error("\u8BF7\u5148\u8C03\u7528 get_plugin_structure \u67E5\u770B\u63D2\u4EF6\u76EE\u5F55\u7ED3\u6784\u3002");
25223
+ return authoring.create(input);
25224
+ }
25225
+ return base.call(name, input);
25226
+ }
23756
25227
  };
23757
25228
  }
23758
25229
  function PrintDesignAiChatPanel({
@@ -23773,6 +25244,11 @@ function PrintDesignAiChatPanel({
23773
25244
  const [settingsOpen, setSettingsOpen] = react.useState(false);
23774
25245
  const [modelLoading, setModelLoading] = react.useState(false);
23775
25246
  const [input, setInput] = react.useState("");
25247
+ const [attachments, setAttachments] = react.useState(
25248
+ []
25249
+ );
25250
+ const [attaching, setAttaching] = react.useState(false);
25251
+ const [previewImage, setPreviewImage] = react.useState(null);
23776
25252
  const selectionKey = selection ? JSON.stringify([
23777
25253
  selection.pageId,
23778
25254
  ...selection.elements.map((item) => item.id)
@@ -23785,7 +25261,11 @@ function PrintDesignAiChatPanel({
23785
25261
  (item) => !removedIds.includes(item.id)
23786
25262
  )
23787
25263
  } : void 0;
23788
- const session = useChatSession(provider, agentApi);
25264
+ const augmentedAgentApi = react.useMemo(
25265
+ () => createPluginAuthoringAgentApi(agentApi, options.pluginAuthoring),
25266
+ [agentApi, options.pluginAuthoring]
25267
+ );
25268
+ const session = useChatSession(provider, augmentedAgentApi);
23789
25269
  const { messages, busy, error, setError } = session;
23790
25270
  const activeProfile = activePrintDesignAiChatProfile(settings);
23791
25271
  const draftProfile = activePrintDesignAiChatProfile(draftSettings);
@@ -23864,10 +25344,26 @@ function PrintDesignAiChatPanel({
23864
25344
  setError("\u6A21\u578B\u914D\u7F6E\u4EC5\u5728\u672C\u6B21\u4F1A\u8BDD\u53EF\u7528\uFF1B\u52A0\u5BC6\u4FDD\u5B58\u9700\u8981 HTTPS \u6216 localhost\u3002");
23865
25345
  }
23866
25346
  };
25347
+ const addFiles = async (files) => {
25348
+ if (!files.length || attaching) return;
25349
+ setAttaching(true);
25350
+ try {
25351
+ const next = [...attachments];
25352
+ for (const file of files) next.push(await readChatAttachment(file, next));
25353
+ setAttachments(next);
25354
+ setError("");
25355
+ } catch (cause) {
25356
+ setError(
25357
+ cause instanceof Error ? cause.message : "\u6682\u4E0D\u652F\u6301\u8BE5\u7C7B\u578B\u7684\u9644\u4EF6\u3002"
25358
+ );
25359
+ } finally {
25360
+ setAttaching(false);
25361
+ }
25362
+ };
23867
25363
  const send = (event) => {
23868
25364
  event.preventDefault();
23869
25365
  const content = input.trim();
23870
- if (!content || busy) return;
25366
+ if (!content && !attachments.length || busy || attaching) return;
23871
25367
  const selected = activePrintDesignAiChatProfile(settings);
23872
25368
  if (!selected.baseUrl || !selected.model) {
23873
25369
  setSettingsOpen(true);
@@ -23875,9 +25371,20 @@ function PrintDesignAiChatPanel({
23875
25371
  return;
23876
25372
  }
23877
25373
  setInput("");
23878
- void session.send(content, {
23879
- ...selected,
23880
- ...attachedSelection ? { selection: attachedSelection } : {}
25374
+ const submittedAttachments = attachments;
25375
+ setAttachments([]);
25376
+ void session.send(
25377
+ content,
25378
+ {
25379
+ ...selected,
25380
+ ...attachedSelection ? { selection: attachedSelection } : {}
25381
+ },
25382
+ submittedAttachments
25383
+ ).catch(() => {
25384
+ setInput((current2) => current2 || content);
25385
+ setAttachments(
25386
+ (current2) => current2.length ? current2 : submittedAttachments
25387
+ );
23881
25388
  });
23882
25389
  };
23883
25390
  const updateActiveProfile = (patch) => {
@@ -23897,6 +25404,16 @@ function PrintDesignAiChatPanel({
23897
25404
  /* @__PURE__ */ jsxRuntime.jsxs("header", { className: "cc-print-design-ai-header", children: [
23898
25405
  /* @__PURE__ */ jsxRuntime.jsx("strong", { children: "AI \u5BF9\u8BDD" }),
23899
25406
  /* @__PURE__ */ jsxRuntime.jsxs("div", { children: [
25407
+ busy && session.canPause ? /* @__PURE__ */ jsxRuntime.jsx(
25408
+ "button",
25409
+ {
25410
+ type: "button",
25411
+ "aria-label": session.paused ? "\u7EE7\u7EED Agent" : "\u6682\u505C Agent",
25412
+ "aria-pressed": session.paused,
25413
+ onClick: session.paused ? session.resume : session.pause,
25414
+ children: session.paused ? "\u7EE7\u7EED" : "\u6682\u505C"
25415
+ }
25416
+ ) : null,
23900
25417
  /* @__PURE__ */ jsxRuntime.jsx(
23901
25418
  "button",
23902
25419
  {
@@ -23915,8 +25432,28 @@ function PrintDesignAiChatPanel({
23915
25432
  messages,
23916
25433
  currentModel: activeProfile.model,
23917
25434
  busy,
25435
+ paused: session.paused,
23918
25436
  pendingModel: session.pendingModel,
23919
- streaming: session.streaming
25437
+ streaming: session.streaming,
25438
+ onPreviewImage: (src, name) => setPreviewImage({ src, name }),
25439
+ onDownloadArtifact: options.pluginAuthoring ? (artifact) => {
25440
+ void options.pluginAuthoring.getArchive(artifact.id).then((bytes) => {
25441
+ const url = URL.createObjectURL(
25442
+ new Blob([Uint8Array.from(bytes)], {
25443
+ type: "application/zip"
25444
+ })
25445
+ );
25446
+ const link = document.createElement("a");
25447
+ link.href = url;
25448
+ link.download = `${artifact.packageId.replace(/[^a-z0-9-]/gi, "-").replace(/^-+/, "")}-${artifact.version}.zip`;
25449
+ link.click();
25450
+ window.setTimeout(() => URL.revokeObjectURL(url), 1e3);
25451
+ }).catch(
25452
+ (cause) => setError(
25453
+ cause instanceof Error ? cause.message : "\u4E0B\u8F7D\u63D2\u4EF6 ZIP \u5931\u8D25\u3002"
25454
+ )
25455
+ );
25456
+ } : void 0
23920
25457
  }
23921
25458
  ),
23922
25459
  /* @__PURE__ */ jsxRuntime.jsx(
@@ -23958,6 +25495,11 @@ function PrintDesignAiChatPanel({
23958
25495
  ChatComposer,
23959
25496
  {
23960
25497
  input,
25498
+ attachments,
25499
+ attaching,
25500
+ onAddFiles: (files) => void addFiles(files),
25501
+ onRemoveAttachment: (index) => setAttachments((current2) => current2.filter((_, i) => i !== index)),
25502
+ onPreviewImage: (src, name) => setPreviewImage({ src, name }),
23961
25503
  model: activeProfile.model,
23962
25504
  models: modelsFor(activeProfile),
23963
25505
  reasoningEffort: activeProfile.reasoningEffort,
@@ -23976,9 +25518,404 @@ function PrintDesignAiChatPanel({
23976
25518
  },
23977
25519
  onSend: (event) => void send(event)
23978
25520
  }
25521
+ ),
25522
+ /* @__PURE__ */ jsxRuntime.jsx(
25523
+ reactComponents.ReactImagePreview,
25524
+ {
25525
+ open: previewImage !== null,
25526
+ src: previewImage?.src ?? "",
25527
+ alt: previewImage?.name,
25528
+ onClose: () => setPreviewImage(null)
25529
+ }
23979
25530
  )
23980
25531
  ] });
23981
25532
  }
25533
+ var SLUG = /^[a-z][a-z0-9-]{1,39}$/;
25534
+ var VERSION = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/;
25535
+ var SOURCE_PATH = /^src\/[a-z][a-z0-9-]*\.js$/;
25536
+ var RELATIVE_IMPORT = /^\.\/[a-z][a-z0-9-]*\.js$/;
25537
+ var ALLOWED_IMPORTS = /* @__PURE__ */ new Set([
25538
+ "@canvas-components/print-design",
25539
+ "@canvas-components/react-print-design",
25540
+ "react",
25541
+ "react/jsx-runtime"
25542
+ ]);
25543
+ var PROPERTY_KINDS = /* @__PURE__ */ new Set([
25544
+ "text",
25545
+ "textArea",
25546
+ "select",
25547
+ "number",
25548
+ "color",
25549
+ "toggle",
25550
+ "mode",
25551
+ "dataPath",
25552
+ "repeat",
25553
+ "action",
25554
+ "hint",
25555
+ "jsonPreview",
25556
+ "jsonEditor",
25557
+ "button",
25558
+ "file",
25559
+ "iconSelect",
25560
+ "buttonGroup"
25561
+ ]);
25562
+ var MAX_SOURCE_BYTES = 256 * 1024;
25563
+ var encoder = new TextEncoder();
25564
+ function node(value) {
25565
+ return value && typeof value === "object" && "type" in value && typeof value.type === "string" ? value : null;
25566
+ }
25567
+ function nodes(value) {
25568
+ return Array.isArray(value) ? value.map(node).filter((item) => !!item) : [];
25569
+ }
25570
+ function stringValue(value) {
25571
+ const item = node(value);
25572
+ return item?.type === "Literal" && typeof item.value === "string" ? item.value : null;
25573
+ }
25574
+ function identifier(value) {
25575
+ const item = node(value);
25576
+ return item?.type === "Identifier" && typeof item.name === "string" ? item.name : null;
25577
+ }
25578
+ function property(object2, name) {
25579
+ if (object2.type !== "ObjectExpression") return null;
25580
+ for (const item of nodes(object2.properties)) {
25581
+ const key = identifier(item.key) ?? stringValue(item.key);
25582
+ if (item.type === "Property" && key === name) return node(item.value);
25583
+ }
25584
+ return null;
25585
+ }
25586
+ function walk(value, visit) {
25587
+ const item = node(value);
25588
+ if (!item) return;
25589
+ visit(item);
25590
+ for (const child of Object.values(item)) {
25591
+ if (Array.isArray(child)) child.forEach((part) => walk(part, visit));
25592
+ else if (child && typeof child === "object") walk(child, visit);
25593
+ }
25594
+ }
25595
+ function validateBrowserPluginDraft(value) {
25596
+ if (!value || typeof value !== "object" || Array.isArray(value))
25597
+ throw new TypeError("\u63D2\u4EF6\u8349\u7A3F\u683C\u5F0F\u65E0\u6548\u3002");
25598
+ const draft2 = value;
25599
+ if (typeof draft2.packageId !== "string" || !draft2.packageId.startsWith("@agent/") || !SLUG.test(draft2.packageId.slice(7)) || draft2.componentType !== `agent.${draft2.packageId.slice(7)}` || typeof draft2.version !== "string" || !VERSION.test(draft2.version) || typeof draft2.name !== "string" || !draft2.name.trim() || draft2.name.length > 80 || typeof draft2.description !== "string" || draft2.description.length > 500 || !Array.isArray(draft2.files) || draft2.files.length < 2 || draft2.files.length > 12)
25600
+ throw new TypeError("\u63D2\u4EF6\u6807\u8BC6\u3001\u7248\u672C\u6216\u6E90\u7801\u6570\u91CF\u65E0\u6548\u3002");
25601
+ const paths2 = /* @__PURE__ */ new Set();
25602
+ let size = 0;
25603
+ for (const file of draft2.files) {
25604
+ if (!file || typeof file.path !== "string" || !SOURCE_PATH.test(file.path) || typeof file.content !== "string" || paths2.has(file.path))
25605
+ throw new TypeError("\u63D2\u4EF6\u6E90\u7801\u8DEF\u5F84\u65E0\u6548\u6216\u91CD\u590D\u3002\u53EA\u5141\u8BB8 src \u4E0B\u7684 .js \u6587\u4EF6\u3002");
25606
+ paths2.add(file.path);
25607
+ size += encoder.encode(file.content).byteLength;
25608
+ if (size > MAX_SOURCE_BYTES) throw new RangeError("\u63D2\u4EF6\u6E90\u7801\u8D85\u8FC7\u5927\u5C0F\u9650\u5236\u3002");
25609
+ }
25610
+ if (!paths2.has("src/native.js") || !paths2.has("src/react.js"))
25611
+ throw new TypeError("\u63D2\u4EF6\u5FC5\u987B\u5305\u542B src/native.js \u548C src/react.js\u3002");
25612
+ return draft2;
25613
+ }
25614
+ function declarations(program) {
25615
+ const values = /* @__PURE__ */ new Map();
25616
+ for (const statement of nodes(program.body)) {
25617
+ const declaration = statement.type === "ExportNamedDeclaration" ? node(statement.declaration) : statement;
25618
+ if (declaration?.type !== "VariableDeclaration") continue;
25619
+ for (const item of nodes(declaration.declarations)) {
25620
+ const name = identifier(item.id);
25621
+ const initial = node(item.init);
25622
+ if (name && initial) values.set(name, initial);
25623
+ }
25624
+ }
25625
+ return values;
25626
+ }
25627
+ function resolve(value, values, depth = 0) {
25628
+ if (!value || depth > 8) return null;
25629
+ const name = identifier(value);
25630
+ return name && values.has(name) ? resolve(values.get(name), values, depth + 1) : value;
25631
+ }
25632
+ function validatePropertySections(program, componentType) {
25633
+ const values = declarations(program);
25634
+ const plugin = resolve(values.get("printDesignReactPlugin") ?? null, values);
25635
+ const registry = plugin && resolve(property(plugin, "propertySections"), values);
25636
+ if (registry?.type !== "ObjectExpression")
25637
+ throw new TypeError(
25638
+ "src/react.js \u5FC5\u987B\u5728 printDesignReactPlugin.propertySections \u4E2D\u6CE8\u518C\u7EC4\u4EF6\u914D\u7F6E\u9762\u677F\u3002"
25639
+ );
25640
+ const entry = nodes(registry.properties).find((item) => {
25641
+ const key = identifier(item.key) ?? stringValue(item.key);
25642
+ const resolvedKey = key && resolve(values.get(key) ?? null, values);
25643
+ return item.type === "Property" && (key === componentType || stringValue(resolvedKey) === componentType);
25644
+ });
25645
+ const sections = entry && resolve(node(entry.value), values);
25646
+ if (sections?.type !== "ArrayExpression" || !nodes(sections.elements).length)
25647
+ throw new TypeError(
25648
+ `\u7EC4\u4EF6 ${componentType} \u7684 propertySections \u5FC5\u987B\u5305\u542B\u5C5E\u6027\u5206\u7EC4\u3002`
25649
+ );
25650
+ let customFields = 0;
25651
+ for (const rawSection of nodes(sections.elements)) {
25652
+ const section = resolve(rawSection, values);
25653
+ if (section?.type !== "ObjectExpression")
25654
+ throw new TypeError("\u63D2\u4EF6\u5C5E\u6027\u5206\u7EC4\u5FC5\u987B\u4F7F\u7528\u53EF\u68C0\u67E5\u7684\u5BF9\u8C61\u5B57\u9762\u91CF\u3002");
25655
+ const fields = resolve(property(section, "fields"), values);
25656
+ if (fields?.type !== "ArrayExpression" || !nodes(fields.elements).length)
25657
+ throw new TypeError("\u63D2\u4EF6\u5C5E\u6027\u5206\u7EC4\u5FC5\u987B\u5305\u542B\u975E\u7A7A fields \u914D\u7F6E\u9879\u3002");
25658
+ for (const rawField of nodes(fields.elements)) {
25659
+ const field = resolve(rawField, values);
25660
+ if (field?.type !== "ObjectExpression")
25661
+ throw new TypeError("\u63D2\u4EF6\u5C5E\u6027\u914D\u7F6E\u9879\u5FC5\u987B\u4F7F\u7528\u53EF\u68C0\u67E5\u7684\u5BF9\u8C61\u5B57\u9762\u91CF\u3002");
25662
+ const path = stringValue(resolve(property(field, "path"), values));
25663
+ const kind = stringValue(resolve(property(field, "kind"), values));
25664
+ if (!path?.trim() || !kind || !PROPERTY_KINDS.has(kind) || !property(field, "defaultValue"))
25665
+ throw new TypeError(
25666
+ "\u63D2\u4EF6\u5C5E\u6027\u914D\u7F6E\u9879\u5FC5\u987B\u5305\u542B path\u3001kind \u548C defaultValue\u3002"
25667
+ );
25668
+ if (!["x", "y", "width", "height"].includes(path)) customFields++;
25669
+ }
25670
+ }
25671
+ if (!customFields)
25672
+ throw new TypeError("\u63D2\u4EF6\u914D\u7F6E\u9762\u677F\u81F3\u5C11\u9700\u8981\u4E00\u4E2A\u7EC4\u4EF6\u4E13\u5C5E\u914D\u7F6E\u9879\u3002");
25673
+ }
25674
+ function compileBrowserPluginSources(draft2) {
25675
+ const paths2 = new Set(draft2.files.map((file) => file.path));
25676
+ const output = /* @__PURE__ */ new Map();
25677
+ for (const file of draft2.files) {
25678
+ let program;
25679
+ try {
25680
+ program = acorn.parse(file.content, {
25681
+ ecmaVersion: "latest",
25682
+ sourceType: "module"
25683
+ });
25684
+ } catch (cause) {
25685
+ throw new TypeError(
25686
+ `${file.path} JavaScript \u8BED\u6CD5\u65E0\u6548\uFF1A${cause instanceof Error ? cause.message : "\u89E3\u6790\u5931\u8D25"}`
25687
+ );
25688
+ }
25689
+ for (const statement of nodes(program.body)) {
25690
+ if (![
25691
+ "ImportDeclaration",
25692
+ "ExportNamedDeclaration",
25693
+ "ExportAllDeclaration"
25694
+ ].includes(statement.type))
25695
+ continue;
25696
+ const target = stringValue(statement.source);
25697
+ if (!target) continue;
25698
+ if (target.startsWith(".")) {
25699
+ if (!RELATIVE_IMPORT.test(target) || !paths2.has(`src/${target.slice(2)}`))
25700
+ throw new TypeError(
25701
+ `${file.path} \u5F15\u7528\u4E86\u4E0D\u5B58\u5728\u6216\u65E0\u6548\u7684\u6E90\u7801\uFF1A${target}`
25702
+ );
25703
+ } else if (!ALLOWED_IMPORTS.has(target) || file.path !== "src/react.js" && target !== "@canvas-components/print-design")
25704
+ throw new TypeError(`${file.path} \u5F15\u7528\u4E86\u4E0D\u652F\u6301\u7684\u4F9D\u8D56\uFF1A${target}`);
25705
+ }
25706
+ walk(program, (item) => {
25707
+ if (item.type === "ImportExpression" || item.type === "CallExpression" && identifier(item.callee) === "require")
25708
+ throw new TypeError(`${file.path} \u4E0D\u652F\u6301\u52A8\u6001\u5BFC\u5165\u6216 require\u3002`);
25709
+ });
25710
+ const exportName = file.path === "src/native.js" ? "printDesignNativePlugin" : file.path === "src/react.js" ? "printDesignReactPlugin" : null;
25711
+ if (exportName && !nodes(program.body).some(
25712
+ (statement) => statement.type === "ExportNamedDeclaration" && node(statement.declaration)?.type === "VariableDeclaration" && nodes(node(statement.declaration)?.declarations).some(
25713
+ (item) => identifier(item.id) === exportName
25714
+ )
25715
+ ))
25716
+ throw new TypeError(`${file.path} \u5FC5\u987B\u5BFC\u51FA ${exportName}\u3002`);
25717
+ if (file.path === "src/react.js")
25718
+ validatePropertySections(program, draft2.componentType);
25719
+ output.set(file.path, encoder.encode(file.content));
25720
+ output.set(
25721
+ file.path.replace(/^src\//, "dist/"),
25722
+ encoder.encode(file.content)
25723
+ );
25724
+ }
25725
+ return output;
25726
+ }
25727
+
25728
+ // src/ai-chat/model/browser-plugin-authoring.ts
25729
+ var DATABASE3 = "canvas-components-print-design-ai-plugin-artifacts";
25730
+ var STORE3 = "artifacts";
25731
+ var encoder2 = new TextEncoder();
25732
+ async function openDatabase3() {
25733
+ if (typeof indexedDB === "undefined")
25734
+ throw new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u672C\u5730\u63D2\u4EF6\u5F52\u6863\u5B58\u50A8\u3002");
25735
+ return new Promise((resolve2, reject) => {
25736
+ const request = indexedDB.open(DATABASE3, 1);
25737
+ request.onupgradeneeded = () => request.result.createObjectStore(STORE3, { keyPath: "artifact.id" });
25738
+ request.onsuccess = () => resolve2(request.result);
25739
+ request.onerror = () => reject(request.error);
25740
+ });
25741
+ }
25742
+ async function access2(mode, action, fallback) {
25743
+ const database = await openDatabase3();
25744
+ return new Promise((resolve2, reject) => {
25745
+ const transaction = database.transaction(STORE3, mode);
25746
+ let result = fallback;
25747
+ action(transaction.objectStore(STORE3), (value) => {
25748
+ result = value;
25749
+ });
25750
+ transaction.oncomplete = () => {
25751
+ database.close();
25752
+ resolve2(result);
25753
+ };
25754
+ transaction.onerror = () => {
25755
+ database.close();
25756
+ reject(transaction.error);
25757
+ };
25758
+ transaction.onabort = () => {
25759
+ database.close();
25760
+ reject(transaction.error);
25761
+ };
25762
+ });
25763
+ }
25764
+ var indexedDbStorage = {
25765
+ save: (value) => access2(
25766
+ "readwrite",
25767
+ (store) => {
25768
+ store.put(value);
25769
+ },
25770
+ void 0
25771
+ ),
25772
+ list: () => access2(
25773
+ "readonly",
25774
+ (store, setResult) => {
25775
+ const request = store.getAll();
25776
+ request.onsuccess = () => setResult(request.result);
25777
+ },
25778
+ []
25779
+ ),
25780
+ read: (id) => access2(
25781
+ "readonly",
25782
+ (store, setResult) => {
25783
+ const request = store.get(id);
25784
+ request.onsuccess = () => setResult(request.result ?? null);
25785
+ },
25786
+ null
25787
+ )
25788
+ };
25789
+ function compareVersions(left, right) {
25790
+ const a = left.split(".").map(Number);
25791
+ const b = right.split(".").map(Number);
25792
+ for (let index = 0; index < 3; index++) {
25793
+ const difference = b[index] - a[index];
25794
+ if (difference) return difference;
25795
+ }
25796
+ return 0;
25797
+ }
25798
+ async function digest(bytes) {
25799
+ if (!globalThis.crypto?.subtle)
25800
+ throw new Error("\u5F53\u524D\u6D4F\u89C8\u5668\u4E0D\u652F\u6301\u63D2\u4EF6\u5F52\u6863\u6458\u8981\u6821\u9A8C\u3002");
25801
+ const result = await globalThis.crypto.subtle.digest(
25802
+ "SHA-256",
25803
+ Uint8Array.from(bytes)
25804
+ );
25805
+ return Array.from(
25806
+ new Uint8Array(result),
25807
+ (part) => part.toString(16).padStart(2, "0")
25808
+ ).join("");
25809
+ }
25810
+ function createBrowserPluginAuthoring(storage = indexedDbStorage) {
25811
+ return {
25812
+ async create(value) {
25813
+ const draft2 = validateBrowserPluginDraft(value);
25814
+ const files = await compileBrowserPluginSources(draft2);
25815
+ files.set(
25816
+ "package.json",
25817
+ encoder2.encode(
25818
+ JSON.stringify(
25819
+ {
25820
+ name: draft2.packageId,
25821
+ version: draft2.version,
25822
+ type: "module",
25823
+ license: "UNLICENSED",
25824
+ exports: {
25825
+ "./native": "./dist/native.js",
25826
+ "./react": "./dist/react.js"
25827
+ },
25828
+ peerDependencies: {
25829
+ "@canvas-components/print-design": `>=${printDesign.PRINT_DESIGN_VERSION}`,
25830
+ "@canvas-components/react-print-design": `>=${reactPrintDesign.REACT_PRINT_DESIGN_VERSION}`,
25831
+ react: ">=16.8.0"
25832
+ }
25833
+ },
25834
+ null,
25835
+ 2
25836
+ )
25837
+ )
25838
+ );
25839
+ const bytes = await reactPrintDesign.createPrintDesignPluginArchive(
25840
+ {
25841
+ format: reactPrintDesign.PRINT_DESIGN_PLUGIN_ARCHIVE_FORMAT,
25842
+ formatVersion: reactPrintDesign.PRINT_DESIGN_PLUGIN_ARCHIVE_VERSION,
25843
+ packageId: draft2.packageId,
25844
+ version: draft2.version,
25845
+ author: "AI Agent",
25846
+ license: "UNLICENSED",
25847
+ redistributable: false,
25848
+ permissions: ["editor-local"],
25849
+ compatibility: {
25850
+ printDesign: `>=${printDesign.PRINT_DESIGN_VERSION}`,
25851
+ reactPrintDesign: `>=${reactPrintDesign.REACT_PRINT_DESIGN_VERSION}`
25852
+ },
25853
+ entries: { native: "dist/native.js", react: "dist/react.js" },
25854
+ components: [
25855
+ {
25856
+ type: draft2.componentType,
25857
+ version: draft2.version,
25858
+ name: draft2.name,
25859
+ description: draft2.description
25860
+ }
25861
+ ],
25862
+ tools: [],
25863
+ dependencies: [],
25864
+ resources: []
25865
+ },
25866
+ files
25867
+ );
25868
+ await reactPrintDesign.inspectPrintDesignPluginArchive(bytes);
25869
+ const artifact = {
25870
+ id: globalThis.crypto.randomUUID(),
25871
+ packageId: draft2.packageId,
25872
+ version: draft2.version,
25873
+ name: draft2.name,
25874
+ sha256: await digest(bytes)
25875
+ };
25876
+ await storage.save({ artifact, draft: draft2, bytes, createdAt: Date.now() });
25877
+ return artifact;
25878
+ },
25879
+ async listSources() {
25880
+ const entries = await storage.list();
25881
+ entries.sort(
25882
+ (a, b) => compareVersions(a.draft.version, b.draft.version) || b.createdAt - a.createdAt
25883
+ );
25884
+ const seen = /* @__PURE__ */ new Set();
25885
+ return entries.flatMap(({ draft: draft2 }) => {
25886
+ if (seen.has(draft2.packageId)) return [];
25887
+ seen.add(draft2.packageId);
25888
+ return [
25889
+ {
25890
+ packageId: draft2.packageId,
25891
+ version: draft2.version,
25892
+ componentType: draft2.componentType,
25893
+ name: draft2.name
25894
+ }
25895
+ ];
25896
+ });
25897
+ },
25898
+ async getSource(query) {
25899
+ if (!query.packageId || query.version && !/^\d+\.\d+\.\d+$/.test(query.version))
25900
+ throw new TypeError("\u63D2\u4EF6\u6807\u8BC6\u6216\u7248\u672C\u65E0\u6548\u3002");
25901
+ const entries = (await storage.list()).filter(
25902
+ ({ draft: draft2 }) => draft2.packageId === query.packageId && (!query.version || draft2.version === query.version)
25903
+ ).sort(
25904
+ (a, b) => compareVersions(a.draft.version, b.draft.version) || b.createdAt - a.createdAt
25905
+ );
25906
+ if (!entries[0])
25907
+ throw new Error(`\u672A\u627E\u5230\u63D2\u4EF6 ${query.packageId} \u7684\u5DF2\u751F\u6210\u5F52\u6863\u3002`);
25908
+ return entries[0].draft;
25909
+ },
25910
+ async getArchive(id) {
25911
+ const entry = await storage.read(id);
25912
+ if (!entry) throw new Error("\u672C\u5730\u63D2\u4EF6 ZIP \u4E0D\u5B58\u5728\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210\u3002");
25913
+ if (await digest(entry.bytes) !== entry.artifact.sha256)
25914
+ throw new Error("\u672C\u5730\u63D2\u4EF6 ZIP \u6821\u9A8C\u5931\u8D25\uFF0C\u8BF7\u91CD\u65B0\u751F\u6210\u3002");
25915
+ return entry.bytes;
25916
+ }
25917
+ };
25918
+ }
23982
25919
 
23983
25920
  // src/ai-chat/index.ts
23984
25921
  function createPrintDesignAiChatPlugin(options = {}) {
@@ -24009,11 +25946,13 @@ var builtinReactTools = [
24009
25946
  settingsRulersTool,
24010
25947
  settingsGuidesTool,
24011
25948
  settingsInteractionTool,
25949
+ settingsKeyboardMoveTool,
24012
25950
  settingsIndicatorsTool,
24013
25951
  pluginmarketTool
24014
25952
  ];
24015
25953
  var builtinReactComponentPlugins = [
24016
25954
  textPlugin,
25955
+ richTextPlugin,
24017
25956
  listPlugin,
24018
25957
  dateTimePlugin,
24019
25958
  moneyUpperPlugin,
@@ -24037,17 +25976,17 @@ var builtinReactComponentPlugins = [
24037
25976
  pivotTablePlugin,
24038
25977
  ganttPlugin
24039
25978
  ];
24040
- var menuGroups24 = /* @__PURE__ */ new Map();
25979
+ var menuGroups25 = /* @__PURE__ */ new Map();
24041
25980
  for (const plugin of builtinReactComponentPlugins) {
24042
25981
  for (const group of plugin.menuGroups) {
24043
- const current2 = menuGroups24.get(group.id);
25982
+ const current2 = menuGroups25.get(group.id);
24044
25983
  if (current2) {
24045
25984
  if (current2.title !== group.title || current2.order !== group.order) {
24046
25985
  throw new Error(`\u83DC\u5355\u5206\u7EC4\u5B9A\u4E49\u4E0D\u4E00\u81F4\uFF1A${group.id}`);
24047
25986
  }
24048
25987
  current2.items.push(...group.items);
24049
25988
  } else {
24050
- menuGroups24.set(group.id, { ...group, items: [...group.items] });
25989
+ menuGroups25.set(group.id, { ...group, items: [...group.items] });
24051
25990
  }
24052
25991
  }
24053
25992
  }
@@ -24088,7 +26027,7 @@ var builtinPrintDesignPlugins = Object.freeze({
24088
26027
  componentFactories: new reactPrintDesign.PrintDesignComponentFactoryRegistry(
24089
26028
  builtinReactComponentPlugins.map((plugin) => plugin.factory)
24090
26029
  ),
24091
- componentMenu: [...menuGroups24.values()].sort((a, b) => a.order - b.order).map((group) => ({
26030
+ componentMenu: [...menuGroups25.values()].sort((a, b) => a.order - b.order).map((group) => ({
24092
26031
  id: group.id,
24093
26032
  title: group.title,
24094
26033
  items: group.items.sort((a, b) => a.order - b.order)
@@ -24107,4 +26046,5 @@ var builtinPrintDesignPlugins = Object.freeze({
24107
26046
 
24108
26047
  exports.builtinPrintDesignPlugins = builtinPrintDesignPlugins;
24109
26048
  exports.builtinReactComponentPlugins = builtinReactComponentPlugins;
26049
+ exports.createBrowserPluginAuthoring = createBrowserPluginAuthoring;
24110
26050
  exports.createPrintDesignAiChatPlugin = createPrintDesignAiChatPlugin;