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