@gct-paas/word 0.1.22 → 0.1.23

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.
Files changed (46) hide show
  1. package/dist/capabilities/model-field-runtime/provider/FieldProviderRuntime.d.ts +4 -0
  2. package/dist/capabilities/model-field-runtime/service/FieldService.d.ts +2 -0
  3. package/dist/core/cursor/types/cursor.d.ts +50 -0
  4. package/dist/core/index.d.ts +2 -0
  5. package/dist/core/layout/LayoutMapper.d.ts +2 -2
  6. package/dist/core/layout/handlers/{ImageHandler.d.ts → InlineImageLayoutHandler.d.ts} +2 -3
  7. package/dist/core/layout/handlers/fields/AttachmentHandler.d.ts +3 -2
  8. package/dist/core/layout/handlers/fields/{BaseHandler.d.ts → FieldBaseHandler.d.ts} +2 -5
  9. package/dist/core/layout/handlers/fields/FieldImageHandler.d.ts +7 -0
  10. package/dist/core/layout/handlers/fields/InputHandler.d.ts +3 -2
  11. package/dist/core/layout/handlers/fields/OptionHandler.d.ts +3 -2
  12. package/dist/core/layout/handlers/fields/SignatureHandler.d.ts +3 -2
  13. package/dist/core/layout/handlers/fields/index.d.ts +1 -2
  14. package/dist/core/layout/handlers/index.d.ts +1 -1
  15. package/dist/core/layout/handlers/pageWidgets/BarcodeHandler.d.ts +2 -2
  16. package/dist/core/layout/handlers/pageWidgets/DefaultHandler.d.ts +2 -2
  17. package/dist/core/layout/handlers/pageWidgets/DiagonalHandler.d.ts +2 -2
  18. package/dist/core/layout/handlers/pageWidgets/LineHandler.d.ts +2 -2
  19. package/dist/core/layout/handlers/pageWidgets/PageWidgetImageHandler.d.ts +5 -0
  20. package/dist/core/layout/handlers/pageWidgets/PaginationHandler.d.ts +2 -2
  21. package/dist/core/layout/handlers/pageWidgets/QrCodeHandler.d.ts +2 -2
  22. package/dist/core/layout/handlers/pageWidgets/SerialNumberHandler.d.ts +2 -2
  23. package/dist/core/layout/handlers/{base/BaseHandler.d.ts → pageWidgets/WidgetBaseHandler.d.ts} +2 -5
  24. package/dist/core/layout/handlers/pageWidgets/index.d.ts +1 -1
  25. package/dist/core/layout/logic/LayoutBuilder.d.ts +1 -1
  26. package/dist/core/layout/types/index.d.ts +23 -6
  27. package/dist/core/model/DocModel.d.ts +13 -1
  28. package/dist/core/model/types/index.d.ts +0 -1
  29. package/dist/core/view/Doc.d.ts +8 -1
  30. package/dist/core/view/base/LayoutNode.d.ts +4 -0
  31. package/dist/core/view/runs/TextRun.d.ts +4 -0
  32. package/dist/core/view/types/index.d.ts +2 -0
  33. package/dist/core/view/types/layout-node-by-component.d.ts +38 -0
  34. package/dist/core/view/utils/TextUtil.d.ts +61 -7
  35. package/dist/index.es.js +2052 -1795
  36. package/dist/runtime/_register_/runtime/SuiteRuntime.d.ts +4 -1
  37. package/dist/runtime/canvas/node/text-character.vue.d.ts +3 -1
  38. package/dist/runtime/interface/render.d.ts +1 -1
  39. package/dist/sdk/engine/index.d.ts +1 -1
  40. package/dist/sdk/types/field-model-query.d.ts +19 -0
  41. package/dist/sdk/types/index.d.ts +9 -0
  42. package/dist/utils/func/core.d.ts +15 -0
  43. package/package.json +1 -1
  44. package/dist/core/layout/handlers/fields/ImageHandler.d.ts +0 -5
  45. package/dist/core/layout/handlers/pageWidgets/ImageHandler.d.ts +0 -4
  46. package/dist/core/model/types/model.d.ts +0 -144
package/dist/index.es.js CHANGED
@@ -20617,6 +20617,20 @@ function getLastSegment(str, separator = ".") {
20617
20617
  const index2 = str.lastIndexOf(separator);
20618
20618
  return index2 === -1 ? str : str.slice(index2 + 1);
20619
20619
  }
20620
+ function parseLinkFieldExpression(str) {
20621
+ if (!str) {
20622
+ return {
20623
+ subFieldKey: "",
20624
+ linkFieldKey: ""
20625
+ };
20626
+ }
20627
+ const normalized = str.replace(/^\$\./, "");
20628
+ const [subFieldKey = "", linkFieldKey = ""] = normalized.split(":");
20629
+ return {
20630
+ subFieldKey,
20631
+ linkFieldKey
20632
+ };
20633
+ }
20620
20634
  function getBeforeBracket(str) {
20621
20635
  const reg = /\$\.[a-z_]+\[[^\]]+\]/i;
20622
20636
  return str.match(reg)?.[0] || "";
@@ -26214,437 +26228,1269 @@ function resolveCharHit(node, base, actualX) {
26214
26228
  side: localX < mid ? "before" : "after"
26215
26229
  };
26216
26230
  }
26217
- const AREA_ORDER = {
26218
- overlay: -1,
26219
- header: 0,
26220
- body: 1,
26221
- footer: 2
26222
- };
26223
- function computeCharOffsetsFromMetrics(metrics) {
26224
- const offsets = [0];
26225
- let acc = 0;
26226
- for (const m of metrics) {
26227
- acc += m.width;
26228
- offsets.push(acc);
26231
+ class LayoutNode {
26232
+ /** 唯一标识符 */
26233
+ id;
26234
+ /** 组件类型 */
26235
+ component;
26236
+ /** 所属文档 */
26237
+ doc;
26238
+ /** 父节点 */
26239
+ parent;
26240
+ /** 在父容器中的相对 X 坐标 */
26241
+ x = 0;
26242
+ /** 在父容器中的相对 Y 坐标 */
26243
+ y = 0;
26244
+ /** 布局后的绝对 X 坐标 */
26245
+ layoutX = 0;
26246
+ /** 布局后的绝对 Y 坐标 */
26247
+ layoutY = 0;
26248
+ modelRef;
26249
+ // valuePath?: string;
26250
+ /** 宽度 */
26251
+ _width = 0;
26252
+ /** 高度 */
26253
+ _height = 0;
26254
+ constructor(options) {
26255
+ this.id = options.id ?? uuid();
26256
+ this.doc = options.doc;
26257
+ if (options.x !== void 0) this.x = options.x;
26258
+ if (options.y !== void 0) this.y = options.y;
26259
+ if (options.width !== void 0) this._width = options.width;
26260
+ if (options.height !== void 0) this._height = options.height;
26261
+ this.modelRef = options.modelRef;
26262
+ this.modelRef && this.doc.layoutMapper.recordModelSplit(this.modelRef?.id, this.id);
26229
26263
  }
26230
- return offsets;
26231
- }
26232
- function buildTextMeta(node) {
26233
- const charMetrics = Array.isArray(node.charMetrics) ? node.charMetrics.slice() : [];
26234
- const charLength = Math.max(0, charMetrics.length);
26235
- return {
26236
- text: node.text ?? "",
26237
- charMetrics,
26238
- charLength,
26239
- charOffsets: charMetrics.length > 0 ? computeCharOffsetsFromMetrics(charMetrics) : void 0
26240
- };
26241
- }
26242
- function buildParagraphMeta(node) {
26243
- return {
26244
- lineTop: node.layoutY,
26245
- lineBottom: node.layoutY + node.height
26246
- };
26247
- }
26248
- function buildPosBox(node) {
26249
- const absLeft = node.layoutX ?? 0;
26250
- const absTop = node.layoutY ?? 0;
26251
- const relLeft = node.x ?? 0;
26252
- const relTop = node.y ?? 0;
26253
- const width = node.mergeFromId ? 0 : node.width ?? 0;
26254
- const height = node.mergeFromId ? 0 : node.height ?? 0;
26255
- return {
26256
- width,
26257
- height,
26258
- absbox: {
26259
- left: absLeft,
26260
- top: absTop,
26261
- right: absLeft + width,
26262
- bottom: absTop + height
26263
- },
26264
- relbox: {
26265
- left: relLeft,
26266
- top: relTop,
26267
- right: relLeft + width,
26268
- bottom: relTop + height
26269
- }
26270
- };
26271
- }
26272
- const lineUtils = {
26273
- resetLineCtx(ctx) {
26274
- ctx.lineId = void 0;
26275
- ctx.lineIndex = -1;
26276
- ctx.lineType = void 0;
26277
- },
26278
- resetTableCtx(ctx) {
26279
- ctx.tableId = void 0;
26280
- lineUtils.restTableRowCtx(ctx);
26281
- lineUtils.restTableCellCtx(ctx);
26282
- },
26283
- restTableRowCtx(ctx) {
26284
- ctx.tableRowId = void 0;
26285
- ctx.tableRowIndex = void 0;
26286
- ctx.__rowCounter = 0;
26287
- },
26288
- restTableCellCtx(ctx) {
26289
- ctx.tableCellId = void 0;
26290
- ctx.tableCellIndex = void 0;
26291
- ctx.__cellCounter = 0;
26292
- },
26293
- enterPaper(ctx, pageId) {
26294
- ctx.currentPageId = pageId;
26295
- ctx.area = "body";
26296
- lineUtils.resetLineCtx(ctx);
26297
- lineUtils.resetTableCtx(ctx);
26298
- },
26299
- enterHeader(ctx) {
26300
- ctx.area = "header";
26301
- lineUtils.resetLineCtx(ctx);
26302
- lineUtils.resetTableCtx(ctx);
26303
- },
26304
- enterFooter(ctx) {
26305
- ctx.area = "footer";
26306
- lineUtils.resetLineCtx(ctx);
26307
- lineUtils.resetTableCtx(ctx);
26308
- },
26309
- enterOverlay(ctx) {
26310
- ctx.area = "overlay";
26311
- lineUtils.resetLineCtx(ctx);
26312
- lineUtils.resetTableCtx(ctx);
26313
- },
26314
- enterTable(ctx, tableId) {
26315
- lineUtils.resetTableCtx(ctx);
26316
- ctx.tableId = tableId;
26317
- },
26318
- enterTableRow(ctx, rowId) {
26319
- ctx.lineIndex += 1;
26320
- ctx.lineId = rowId;
26321
- ctx.lineType = "tablerow";
26322
- ctx.tableRowId = rowId;
26323
- ctx.tableRowIndex = ctx.__rowCounter;
26324
- ctx.__rowCounter += 1;
26325
- lineUtils.restTableCellCtx(ctx);
26326
- },
26327
- enterTableCell(ctx, cellId) {
26328
- ctx.tableCellId = cellId;
26329
- ctx.tableCellIndex = ctx.__cellCounter;
26330
- ctx.__cellCounter += 1;
26331
- },
26332
- enterParagraph(ctx, nodeId) {
26333
- ctx.lineIndex += 1;
26334
- ctx.lineId = nodeId;
26335
- ctx.lineType = "paragraph";
26336
- lineUtils.resetTableCtx(ctx);
26264
+ get width() {
26265
+ return this._width;
26337
26266
  }
26338
- };
26339
- function walkPageDFS(pages, cb) {
26340
- pages.forEach((page, pi) => {
26341
- const visit = (node, idx, path2) => {
26342
- cb(node, idx, path2);
26343
- const children = node?.getChildren?.() ?? node.children;
26344
- if (Array.isArray(children)) {
26345
- children.forEach((c2, i) => visit(c2, idx.concat(i), path2.concat(c2.id)));
26346
- }
26347
- };
26348
- visit(page, [pi], [page.id]);
26349
- if (page.headerBand) {
26350
- visit(page.headerBand, [pi, -1], [page.id, page.headerBand.id]);
26351
- }
26352
- if (page.footerBand) {
26353
- visit(page.footerBand, [pi, -2], [page.id, page.footerBand.id]);
26354
- }
26355
- if (page.overlayBand) {
26356
- visit(page.overlayBand, [pi, -3], [page.id, page.overlayBand.id]);
26357
- }
26358
- });
26359
- }
26360
- function buildLayoutMeta(pages) {
26361
- const dataCenter = /* @__PURE__ */ new Map();
26362
- const lineCenter = /* @__PURE__ */ new Map();
26363
- const widgetMetaMap = /* @__PURE__ */ new Map();
26364
- const widgetIds = [];
26365
- const ctx = {
26366
- currentPageId: "",
26367
- lineIndex: -1,
26368
- __cellCounter: 0,
26369
- __rowCounter: 0,
26370
- area: "body"
26371
- };
26372
- let cursor = 0;
26373
- function collectLineInfo(node, type4, ctx2, pageId) {
26374
- const children = node.getChildren();
26375
- if (!children.length) return;
26376
- const childrenBoxes = children.map(buildPosBox);
26377
- const absBoxes = childrenBoxes.map((b2) => ({
26378
- ...b2.absbox,
26379
- lineTop: node.layoutY,
26380
- lineBottom: node.layoutY + node.height
26381
- }));
26382
- const areaOrder = AREA_ORDER[ctx2.area] ?? 1;
26383
- lineCenter.set(node.id, {
26384
- id: node.id,
26385
- type: type4,
26386
- pageId,
26387
- pageArea: ctx2.area,
26388
- sort: areaOrder * 1e5 + ctx2.lineIndex,
26389
- nextIds: children.map((c2) => c2.id),
26390
- size: absBoxes
26391
- });
26267
+ get height() {
26268
+ return this._height;
26392
26269
  }
26393
- walkPageDFS(pages, (node, pathIndex, path2) => {
26394
- if (!node?.id) return;
26395
- const component = node.component;
26396
- const page = pages[pathIndex[0]];
26397
- if (!page) return;
26398
- switch (component) {
26399
- case BuiltinComponentTypeConst.Paper:
26400
- lineUtils.enterPaper(ctx, page.id);
26401
- break;
26402
- case BuiltinComponentTypeConst.Header:
26403
- lineUtils.enterHeader(ctx);
26404
- break;
26405
- case BuiltinComponentTypeConst.Footer:
26406
- lineUtils.enterFooter(ctx);
26407
- break;
26408
- case BuiltinComponentTypeConst.OverlayContainer:
26409
- lineUtils.enterOverlay(ctx);
26410
- break;
26411
- case BuiltinComponentTypeConst.Table:
26412
- lineUtils.enterTable(ctx, node.id);
26413
- break;
26414
- case BuiltinComponentTypeConst.TableRow:
26415
- lineUtils.enterTableRow(ctx, node.id);
26416
- collectLineInfo(node, "tablerow", ctx, page.id);
26417
- break;
26418
- case BuiltinComponentTypeConst.TableCell:
26419
- lineUtils.enterTableCell(ctx, node.id);
26420
- break;
26421
- case BuiltinComponentTypeConst.Paragraph:
26422
- if (node.parent?.component === BuiltinComponentTypeConst.Paper || node.parent?.component === BuiltinComponentTypeConst.Header || node.parent?.component === BuiltinComponentTypeConst.Footer) {
26423
- lineUtils.enterParagraph(ctx, node.id);
26424
- collectLineInfo(node, "paragraph", ctx, page.id);
26425
- }
26426
- break;
26427
- }
26428
- const textMeta = component === BuiltinComponentTypeConst.Text ? buildTextMeta(node) : { charLength: 0 };
26429
- const paragraphMeta = component === BuiltinComponentTypeConst.Paragraph ? buildParagraphMeta(node) : {};
26430
- const pos = buildPosBox(node);
26431
- const fr = {
26432
- id: node.id,
26433
- component,
26434
- raw: node,
26435
- runIndex: dataCenter.size,
26436
- secRefId: page?.section.refId || "",
26437
- pageId: page?.id || "",
26438
- pageArea: ctx.area,
26439
- preId: node.parent?.id ?? "",
26440
- ...pos,
26441
- globalPosStart: cursor,
26442
- globalPosEnd: cursor + textMeta.charLength,
26443
- path: path2.slice(),
26444
- pathIndex: pathIndex.slice(),
26445
- line: isAtom(component) ? {
26446
- lineId: ctx.lineId,
26447
- lineIndex: ctx.lineIndex,
26448
- lineType: ctx.lineType,
26449
- tableId: ctx.tableId,
26450
- tableRowId: ctx.tableRowId,
26451
- tableRowIndex: ctx.tableRowIndex,
26452
- tableCellId: ctx.tableCellId,
26453
- tableCellIndex: ctx.tableCellIndex
26454
- } : void 0,
26455
- ...textMeta,
26456
- ...paragraphMeta
26457
- };
26458
- if (component === BuiltinComponentTypeConst.Text) {
26459
- const widgetMeta = node?.widgetMeta;
26460
- if (widgetMeta) {
26461
- if (!widgetMetaMap.has(widgetMeta.id)) {
26462
- widgetMetaMap.set(widgetMeta.id, []);
26463
- }
26464
- widgetMetaMap.get(widgetMeta.id).push(fr);
26270
+ set width(value) {
26271
+ this._width = value;
26272
+ }
26273
+ set height(value) {
26274
+ this._height = value;
26275
+ }
26276
+ get page() {
26277
+ return this.getPage();
26278
+ }
26279
+ get isWidgetRun() {
26280
+ return "widgetMeta" in this && Boolean(this.widgetMeta);
26281
+ }
26282
+ get isPageWidgetRun() {
26283
+ return "pageWidgetMeta" in this && Boolean(this.pageWidgetMeta);
26284
+ }
26285
+ get isSubRenderer() {
26286
+ return "subRenderer" in this && Boolean(this.subRenderer);
26287
+ }
26288
+ get isPlaceholderRun() {
26289
+ return "isPlaceholder" in this && this.isPlaceholder === true;
26290
+ }
26291
+ /**
26292
+ * 获取实例对应的 page
26293
+ * tips 表格第一次初始化无 page,target 可能为空
26294
+ * @returns
26295
+ */
26296
+ getPage() {
26297
+ let target = this;
26298
+ while (target) {
26299
+ if (target.component === BuiltinComponentTypeConst.Paper) {
26300
+ return target;
26465
26301
  }
26302
+ target = target.parent;
26466
26303
  }
26467
- dataCenter.set(node.id, fr);
26468
- widgetIds.push(node.id);
26469
- cursor += textMeta.charLength;
26470
- });
26471
- return { dataCenter, lineCenter, widgetIds, widgetMetaMap };
26472
- }
26473
- function isAtom(component) {
26474
- return component === BuiltinComponentTypeConst.Text || component === BuiltinComponentTypeConst.InlineImage;
26475
- }
26476
- function isPlaceholderNode(node) {
26477
- if (!node) return false;
26478
- if (node.component !== BuiltinComponentTypeConst.Text) return false;
26479
- const raw = node.raw;
26480
- return !!(raw && raw.isPlaceholder);
26481
- }
26482
- function isClickSelectAllNode(node, checkMarker = true) {
26483
- if (!node) return false;
26484
- if (node.component !== BuiltinComponentTypeConst.Text) return false;
26485
- const raw = node.raw;
26486
- return validateTextWidgetMarker(raw, checkMarker);
26487
- }
26488
- function validateTextWidgetMarker(raw, checkMarker) {
26489
- const baseValid = raw.isWidgetRun;
26490
- if (!checkMarker) {
26491
- return baseValid;
26304
+ return;
26492
26305
  }
26493
- return baseValid && !(raw.widgetFieldLeftMarker || raw.widgetFieldRightMarker);
26494
- }
26495
- function isClickPaperWidgetAllNode(node) {
26496
- if (!node) return false;
26497
- const raw = node.raw;
26498
- return raw.isPageWidgetRun;
26499
- }
26500
- class TextHitHandler {
26501
- handleHitDetection(doc, node, actualX, actualY) {
26502
- const base = getBaseMetaInfo(node);
26503
- if (doc.isInEditMode() && isClickSelectAllNode(node, false)) {
26504
- const raw = node.raw;
26505
- const modelId = raw.modelRef?.id;
26506
- if (raw.widgetFieldLeftMarker || raw.widgetFieldRightMarker) {
26507
- const side2 = raw.widgetFieldLeftMarker ? "before" : "after";
26508
- return {
26509
- ...base,
26510
- offset: 0,
26511
- side: side2
26512
- };
26513
- }
26514
- if (!modelId) return null;
26515
- const widgetIds = doc.layoutMapper.getModelSplitById(modelId);
26516
- const nodes = doc.layoutMapper.getBaseMetaNodeByIds(widgetIds);
26517
- if (!nodes?.length) return null;
26518
- const filterNodes = nodes.filter(
26519
- (node2) => !(node2.raw.widgetFieldLeftMarker || node2.raw.widgetFieldRightMarker)
26520
- );
26521
- const total = filterNodes.length;
26522
- const midIndex = Math.floor(total / 2);
26523
- const clickedIndex = filterNodes.findIndex((n) => n.id === node.id);
26524
- let side = "after";
26525
- if (clickedIndex < midIndex) {
26526
- side = "before";
26527
- } else if (clickedIndex > midIndex) {
26528
- side = "after";
26529
- } else {
26530
- side = resolveMiddleSide(filterNodes[midIndex], actualX);
26306
+ /**
26307
+ * 获取实例对应的 悬浮层
26308
+ * @returns
26309
+ */
26310
+ getOverlayLayout() {
26311
+ let target = this;
26312
+ while (target) {
26313
+ if (target.component === BuiltinComponentTypeConst.OverlayLayout) {
26314
+ return target;
26531
26315
  }
26532
- const targetNode = side === "after" ? filterNodes[total - 1] : filterNodes[0];
26533
- return {
26534
- ...getBaseMetaInfo(targetNode),
26535
- offset: 0,
26536
- side
26537
- };
26538
- }
26539
- if (doc.isInFillMode() && !isClickSelectAllNode(node)) {
26540
- return null;
26541
- }
26542
- if (Array.isArray(node.charOffsets) && node.charOffsets.length > 0) {
26543
- return resolveCharHit(node, base, actualX);
26316
+ target = target.parent;
26544
26317
  }
26545
- return {
26546
- ...base,
26547
- offset: 0,
26548
- side: "after"
26549
- };
26318
+ return;
26550
26319
  }
26551
- isClickSelectAll(doc, node) {
26552
- return {
26553
- type: "cursor"
26554
- };
26320
+ /**
26321
+ * 布局方法:计算并设置节点的绝对位置
26322
+ * @param x 绝对 X 坐标
26323
+ * @param y 绝对 Y 坐标
26324
+ */
26325
+ layout(x2 = 0, y2 = 0) {
26326
+ this.layoutX = x2;
26327
+ this.layoutY = y2;
26555
26328
  }
26556
- // todo 后续文本改成多文字一个节点可以处理
26557
- // resolveCursorIntent(doc: Doc, node: BaseMetaNode, cursor: ICursorPosition) {
26558
- // const base = getBaseMetaInfo(node);
26559
- // const isPlaceholder = !!((node.raw as any).isPlaceholder);
26560
- // if (isPlaceholder) {
26561
- // return { ...base, isPlaceholder: true, offset: 0, side: cursor.side || 'before', };
26562
- // }
26563
- // const offsets = Array.isArray(node.charOffsets) ? node.charOffsets as number[] : undefined;
26564
- // if (offsets && offsets.length > 0) {
26565
- // let off = Number.isFinite(Number(cursor.offset)) ? Math.floor(Number(cursor.offset)) : 0;
26566
- // off = Math.max(0, Math.min(off, offsets.length));
26567
- // const side = off >= offsets.length ? 'after' : (cursor.side || 'before');
26568
- // return { ...base, offset: off, side };
26569
- // }
26570
- // const off = Number.isFinite(Number(cursor.offset)) ? Math.max(0, Math.floor(Number(cursor.offset))) : 0;
26571
- // return { ...base, offset: off, side: cursor.side || 'before' };
26572
- // }
26573
- }
26574
- function toHorizontalIntervals(childMeta) {
26575
- return childMeta.map((i) => {
26576
- if (!i) return null;
26577
- const left = i.absbox.left ?? 0;
26578
- const right = i.absbox.right ?? left;
26579
- return [left, right];
26580
- }).filter(Boolean);
26581
- }
26582
- function toVerticalIntervalsAbs(doc, childMeta, pageId) {
26583
- return childMeta.map((c2) => {
26584
- if (!c2) return null;
26585
- const top = doc.layoutMapper.getAbsoluteCanvasPosition(
26586
- pageId,
26587
- 0,
26588
- c2.absbox.top,
26589
- true
26590
- ).y;
26591
- const bottom = doc.layoutMapper.getAbsoluteCanvasPosition(
26592
- pageId,
26593
- 0,
26594
- c2.absbox.bottom,
26595
- true
26596
- ).y;
26597
- return [top, bottom];
26598
- }).filter(Boolean);
26599
26329
  }
26600
- function findIntervalIndex(intervals, actualX) {
26601
- let left = 0;
26602
- let right = intervals.length - 1;
26603
- while (left <= right) {
26604
- const mid = Math.floor((left + right) / 2);
26605
- const [start, end] = intervals[mid];
26606
- if (actualX >= start && actualX < end) return mid;
26607
- if (actualX < start) right = mid - 1;
26608
- else left = mid + 1;
26330
+ class LayoutGroup extends LayoutNode {
26331
+ /** 子节点列表 */
26332
+ children = [];
26333
+ _padding = [0, 0, 0, 0];
26334
+ constructor(options) {
26335
+ super(options);
26609
26336
  }
26610
- return -1;
26611
- }
26612
- function getIntervalSide(intervals, actualX) {
26613
- if (!intervals || !intervals.length) return null;
26614
- const foundIndex = findIntervalIndex(intervals, actualX);
26615
- if (foundIndex !== -1) {
26616
- const [start, end] = intervals[foundIndex];
26617
- const midpoint = (start + end) / 2;
26618
- return {
26619
- index: foundIndex,
26620
- side: actualX < midpoint ? "before" : "after",
26621
- distance: Math.min(actualX - start, end - actualX)
26622
- };
26337
+ get padding() {
26338
+ return this._padding ?? [0, 0, 0, 0];
26623
26339
  }
26624
- let closestIndex = -1;
26625
- let closestDistance = Infinity;
26626
- let side = "before";
26627
- for (let i = 0; i < intervals.length; i++) {
26628
- const [start, end] = intervals[i];
26629
- const distToStart = Math.abs(actualX - start);
26630
- if (distToStart < closestDistance) {
26631
- closestDistance = distToStart;
26632
- closestIndex = i;
26633
- side = actualX < start ? "before" : "after";
26634
- }
26635
- const distToEnd = Math.abs(actualX - end);
26636
- if (distToEnd < closestDistance) {
26637
- closestDistance = distToEnd;
26638
- closestIndex = i;
26639
- side = actualX < end ? "before" : "after";
26640
- }
26340
+ get pt() {
26341
+ return this.padding[0];
26641
26342
  }
26642
- if (closestIndex !== -1) {
26643
- return {
26644
- index: closestIndex,
26645
- side,
26646
- distance: closestDistance
26647
- };
26343
+ get pr() {
26344
+ return this.padding[1];
26345
+ }
26346
+ get pb() {
26347
+ return this.padding[2];
26348
+ }
26349
+ get pl() {
26350
+ return this.padding[3];
26351
+ }
26352
+ /**
26353
+ * 添加子节点
26354
+ * @param child 要添加的子节点
26355
+ */
26356
+ addChild(child) {
26357
+ this.children.push(child);
26358
+ child.parent = this;
26359
+ }
26360
+ /**
26361
+ * 在指定位置插入子节点
26362
+ * @param index 插入位置
26363
+ * @param child 要插入的子节点
26364
+ */
26365
+ insertChild(index2, child) {
26366
+ this.children.splice(index2, 0, child);
26367
+ child.parent = this;
26368
+ }
26369
+ /**
26370
+ * 批量添加子节点
26371
+ * @param children 要添加的子节点数组
26372
+ */
26373
+ addChildren(children) {
26374
+ children.forEach((child) => {
26375
+ this.children.push(child);
26376
+ child.parent = this;
26377
+ });
26378
+ }
26379
+ /**
26380
+ * 在指定位置批量插入子节点
26381
+ * @param index 插入位置
26382
+ * @param children 要插入的子节点数组
26383
+ */
26384
+ insertChildren(index2, children) {
26385
+ this.children.splice(index2, 0, ...children);
26386
+ children.forEach((child) => {
26387
+ child.parent = this;
26388
+ });
26389
+ }
26390
+ /**
26391
+ * 移除子节点
26392
+ * @param child 要移除的子节点
26393
+ * @returns 是否成功移除
26394
+ */
26395
+ removeChild(child) {
26396
+ const index2 = this.children.indexOf(child);
26397
+ if (index2 !== -1) {
26398
+ this.children.splice(index2, 1);
26399
+ child.parent = void 0;
26400
+ return true;
26401
+ }
26402
+ return false;
26403
+ }
26404
+ /**
26405
+ * 根据索引移除子节点
26406
+ * @param index 子节点索引
26407
+ * @returns 被移除的子节点,如果索引无效则返回 undefined
26408
+ */
26409
+ removeChildAt(index2) {
26410
+ if (index2 >= 0 && index2 < this.children.length) {
26411
+ const child = this.children.splice(index2, 1)[0];
26412
+ if (child) {
26413
+ child.parent = void 0;
26414
+ }
26415
+ return child;
26416
+ }
26417
+ return void 0;
26418
+ }
26419
+ /**
26420
+ * 获取所有子节点(只读)
26421
+ */
26422
+ getChildren() {
26423
+ return this.children;
26424
+ }
26425
+ /**
26426
+ * 获取指定索引的子节点
26427
+ * @param index 子节点索引
26428
+ */
26429
+ getChildAt(index2) {
26430
+ return this.children[index2];
26431
+ }
26432
+ /**
26433
+ * 获取子节点数量
26434
+ */
26435
+ getChildCount() {
26436
+ return this.children.length;
26437
+ }
26438
+ /**
26439
+ * 获取第一个子节点
26440
+ */
26441
+ getFirstChild() {
26442
+ return this.children[0] ?? null;
26443
+ }
26444
+ /**
26445
+ * 获取最后一个子节点
26446
+ */
26447
+ getLastChild() {
26448
+ return this.children[this.children.length - 1] ?? null;
26449
+ }
26450
+ /**
26451
+ * 清空所有子节点
26452
+ */
26453
+ clearChildren() {
26454
+ this.children.forEach((child) => {
26455
+ child.parent = void 0;
26456
+ });
26457
+ this.children = [];
26458
+ }
26459
+ /**
26460
+ * 查找子节点索引
26461
+ * @param child 要查找的子节点
26462
+ * @returns 子节点索引,如果不存在则返回 -1
26463
+ */
26464
+ indexOfChild(child) {
26465
+ return this.children.indexOf(child);
26466
+ }
26467
+ /**
26468
+ * 检查是否包含子节点
26469
+ * @param child 要检查的子节点
26470
+ */
26471
+ hasChild(child) {
26472
+ return this.children.includes(child);
26473
+ }
26474
+ /**
26475
+ * 遍历所有子节点
26476
+ * @param callback 遍历回调函数
26477
+ */
26478
+ forEachChild(callback) {
26479
+ this.children.forEach(callback);
26480
+ }
26481
+ /**
26482
+ * 查找满足条件的子节点
26483
+ * @param predicate 查找条件
26484
+ * @returns 第一个满足条件的子节点,如果没有则返回 undefined
26485
+ */
26486
+ findChild(predicate) {
26487
+ return this.children.find(predicate);
26488
+ }
26489
+ /**
26490
+ * 过滤子节点
26491
+ * @param predicate 过滤条件
26492
+ * @returns 满足条件的子节点数组
26493
+ */
26494
+ filterChildren(predicate) {
26495
+ return this.children.filter(predicate);
26496
+ }
26497
+ }
26498
+ class BandContainer extends LayoutGroup {
26499
+ type;
26500
+ constructor(options) {
26501
+ super(options);
26502
+ this.type = options.type;
26503
+ if (options.type === "header") {
26504
+ this.component = BuiltinComponentTypeConst.Header;
26505
+ } else if (options.type === "footer") {
26506
+ this.component = BuiltinComponentTypeConst.Footer;
26507
+ }
26508
+ this.parent = options.page;
26509
+ }
26510
+ get page() {
26511
+ return this.parent;
26512
+ }
26513
+ /**
26514
+ * 宽度 = 页面正文宽度
26515
+ */
26516
+ get contentMaxWidth() {
26517
+ return this.page.contentMaxWidth;
26518
+ }
26519
+ /**
26520
+ * 页眉页脚不限制高度
26521
+ */
26522
+ get contentMaxHeight() {
26523
+ return Number.POSITIVE_INFINITY;
26524
+ }
26525
+ /** 获取页眉页脚内容高度 */
26526
+ getContentHeight() {
26527
+ return this.getChildren().reduce((sum, child) => sum + child.height, 0);
26528
+ }
26529
+ /** 当前真正推开正文的 inset 高度 */
26530
+ get actualInsetHeight() {
26531
+ return this.type === "header" ? this.page.pt : this.page.pb;
26532
+ }
26533
+ /** 获取剩余空间 */
26534
+ getRemainingSize() {
26535
+ return Number.POSITIVE_INFINITY;
26536
+ }
26537
+ layout(x2, y2) {
26538
+ this.layoutX = x2;
26539
+ this.layoutY = y2;
26540
+ this.forEachChild((child) => {
26541
+ child.layout(this.layoutX + child.x, this.layoutY + child.y);
26542
+ });
26543
+ }
26544
+ /** 距离页面边缘的安全间距(页眉/页脚与页面边缘的距离) */
26545
+ get spacingFromEdge() {
26546
+ return this.type === "header" ? this.page.section.headerSpacing : this.page.section.footerSpacing;
26547
+ }
26548
+ /** 页眉/页脚与正文的分界线 Y 坐标(相对整页) */
26549
+ get guideLineY() {
26550
+ return this.type === "header" ? this.page.pt : this.page.height - this.page.pb;
26551
+ }
26552
+ /** 页眉/页脚占位矩形(用于辅助线渲染),相对整页 */
26553
+ get guideRect() {
26554
+ const y2 = this.type === "header" ? this.spacingFromEdge : this.page.height - this.page.pb;
26555
+ const rawHeight = this.type === "header" ? this.page.pt - this.spacingFromEdge : this.page.pb - this.spacingFromEdge;
26556
+ const height = Math.max(0, rawHeight);
26557
+ return {
26558
+ x: this.page.pl,
26559
+ y: y2,
26560
+ width: this.contentMaxWidth,
26561
+ height
26562
+ };
26563
+ }
26564
+ /** 双击开启/关闭页眉页脚编辑的命中区域(相对整页) */
26565
+ get hitAreaRect() {
26566
+ const isHeader = this.type === "header";
26567
+ return {
26568
+ x: this.page.pl,
26569
+ y: isHeader ? 0 : this.page.height - this.page.pb,
26570
+ width: this.contentMaxWidth,
26571
+ height: isHeader ? this.page.pt : this.page.pb
26572
+ };
26573
+ }
26574
+ }
26575
+ class OverlayLayout extends LayoutGroup {
26576
+ component = BuiltinComponentTypeConst.OverlayLayout;
26577
+ constructor(options) {
26578
+ super(options);
26579
+ }
26580
+ /**
26581
+ * 获取可用宽度
26582
+ */
26583
+ get contentMaxWidth() {
26584
+ return this.width;
26585
+ }
26586
+ /**
26587
+ * 悬浮层不参与文档流布局,但是要设置 layoutX和 layoutY
26588
+ */
26589
+ layout() {
26590
+ this.layoutX = this.x;
26591
+ this.layoutY = this.y;
26592
+ }
26593
+ }
26594
+ class OverlayContainer extends LayoutGroup {
26595
+ component = BuiltinComponentTypeConst.OverlayContainer;
26596
+ parent;
26597
+ constructor(options) {
26598
+ super(options);
26599
+ this.parent = options.page;
26600
+ }
26601
+ get page() {
26602
+ return this.parent;
26603
+ }
26604
+ get width() {
26605
+ return this.page.width;
26606
+ }
26607
+ get height() {
26608
+ return this.page.height;
26609
+ }
26610
+ createOverlayLayout({
26611
+ x: x2,
26612
+ y: y2,
26613
+ width,
26614
+ height,
26615
+ modelRef
26616
+ }) {
26617
+ const newOverlayLayout = new OverlayLayout({
26618
+ doc: this.doc,
26619
+ x: x2,
26620
+ y: y2,
26621
+ width,
26622
+ height,
26623
+ modelRef
26624
+ });
26625
+ newOverlayLayout.layout();
26626
+ this.addChild(newOverlayLayout);
26627
+ return newOverlayLayout;
26628
+ }
26629
+ /**
26630
+ * 悬浮层不参与文档流布局
26631
+ */
26632
+ layout() {
26633
+ }
26634
+ }
26635
+ function normalizeColor(color, defaultColor = "#000000") {
26636
+ if (color === "auto" || !color) {
26637
+ return defaultColor;
26638
+ }
26639
+ if (color.startsWith("#")) {
26640
+ return color;
26641
+ }
26642
+ if (color.length === 8 && /^[0-9A-Fa-f]{8}$/.test(color)) {
26643
+ const alpha = color.substring(0, 2);
26644
+ const rgb = color.substring(2);
26645
+ return `#${rgb}${alpha}`;
26646
+ }
26647
+ if (color.length === 6 && /^[0-9A-Fa-f]{6}$/.test(color)) {
26648
+ return `#${color}`;
26649
+ }
26650
+ if (color.length === 3 && /^[0-9A-Fa-f]{3}$/.test(color)) {
26651
+ return `#${color}`;
26652
+ }
26653
+ return color;
26654
+ }
26655
+ function repeat(count, callback) {
26656
+ for (let i = 0; i < count; i++) {
26657
+ callback(i);
26658
+ }
26659
+ }
26660
+ function distributeInteger(total, count) {
26661
+ if (count <= 0) throw new Error("count must be > 0");
26662
+ if (total < 0) throw new Error("total must be >= 0");
26663
+ const base = Math.floor(total / count);
26664
+ const remainder = total % count;
26665
+ const result = [];
26666
+ for (let i = 0; i < count; i++) {
26667
+ result.push(i < count - remainder ? base : base + 1);
26668
+ }
26669
+ return result;
26670
+ }
26671
+ const mainData2WordData = (data) => {
26672
+ const entries = Object.entries(data).map(([key, value]) => {
26673
+ return [`$.${key}`, value];
26674
+ });
26675
+ return Object.fromEntries(entries);
26676
+ };
26677
+ class TextUtil {
26678
+ /** 字体度量缓存限制 */
26679
+ static FONT_METRICS_CACHE_LIMIT = 50;
26680
+ /** 布局大小缓存限制 */
26681
+ static LAYOUT_SIZE_CACHE_LIMIT = 100;
26682
+ /** 东亚常见全宽字符块 */
26683
+ static EAST_ASIAN_FULL_WIDTH_REGEX = /[\u3000-\u303F\u3040-\u30FF\u31F0-\u31FF\uFF01-\uFF60\uFFE0-\uFFE6]/u;
26684
+ /** 表单/文档中常见的几何符号 */
26685
+ static FULL_WIDTH_SYMBOL_REGEX = /[□■○●△▲▽▼◇◆◎※]/u;
26686
+ /**
26687
+ * 视觉间距系数
26688
+ * 值 = fontSize * ratio
26689
+ *
26690
+ * 解决:
26691
+ * - N·m
26692
+ * - N/A
26693
+ * - kg·m²
26694
+ * 等符号贴太近的问题
26695
+ */
26696
+ static VISUAL_SPACING_MAP = {
26697
+ "·": 0.24,
26698
+ "•": 0.24,
26699
+ "/": 0.16,
26700
+ "/": 0.16,
26701
+ "|": 0.12,
26702
+ ":": 0.06,
26703
+ ":": 0.08
26704
+ };
26705
+ static fontMetricsCache = /* @__PURE__ */ new Map();
26706
+ static layoutSizeCache = /* @__PURE__ */ new Map();
26707
+ /**
26708
+ * 验证中文字符
26709
+ * @param char
26710
+ * @returns
26711
+ */
26712
+ static isHanChar(char) {
26713
+ return new RegExp("\\p{Script=Han}", "u").test(char);
26714
+ }
26715
+ /**
26716
+ * 验证是否为应按 1em 处理的全宽单字符
26717
+ * @param char
26718
+ * @returns
26719
+ */
26720
+ static isFullWidthChar(char) {
26721
+ if ([...char].length !== 1) {
26722
+ return false;
26723
+ }
26724
+ return this.isHanChar(char) || this.EAST_ASIAN_FULL_WIDTH_REGEX.test(char) || this.FULL_WIDTH_SYMBOL_REGEX.test(char);
26725
+ }
26726
+ /**
26727
+ * 获取字符视觉间距
26728
+ *
26729
+ * 注意:
26730
+ * 这里不是 glyph width
26731
+ * 而是用于排版推进的额外 advance width
26732
+ *
26733
+ * 例如:
26734
+ * - N·m
26735
+ * - N/A
26736
+ *
26737
+ * 中间符号真实宽度很小,
26738
+ * 但视觉上需要 breathing space
26739
+ *
26740
+ * @param char
26741
+ * @param fontSize
26742
+ * @returns
26743
+ */
26744
+ static getVisualSpacing(char, fontSize2) {
26745
+ const ratio = this.VISUAL_SPACING_MAP[char];
26746
+ if (!ratio) {
26747
+ return 0;
26748
+ }
26749
+ return fontSize2 * ratio;
26750
+ }
26751
+ /**
26752
+ * 生成文本度量缓存键
26753
+ * @param payload
26754
+ * @param includeText
26755
+ * @returns
26756
+ */
26757
+ static getMeasureCacheKey(payload, includeText = true) {
26758
+ return JSON.stringify({
26759
+ text: includeText ? payload.text ?? "" : "",
26760
+ fontSize: payload.fontSize ?? "",
26761
+ fontFamily: payload.fontFamily ?? "",
26762
+ fontStyle: payload.fontStyle ?? "",
26763
+ fontVariant: payload.fontVariant ?? "",
26764
+ lineHeight: payload.lineHeight ?? "",
26765
+ padding: payload.padding ?? "",
26766
+ letterSpacing: payload.letterSpacing ?? ""
26767
+ });
26768
+ }
26769
+ /**
26770
+ * 计算字体度量
26771
+ * ascent / descent
26772
+ *
26773
+ * @param payload
26774
+ * @returns
26775
+ */
26776
+ static getFontMetrics(payload) {
26777
+ const targetText = "Hg";
26778
+ const config = Object.assign({}, payload, {
26779
+ text: targetText,
26780
+ lineHeight: 1
26781
+ });
26782
+ const cacheKey = this.getMeasureCacheKey(config, false);
26783
+ if (this.fontMetricsCache.has(cacheKey)) {
26784
+ const result2 = this.fontMetricsCache.get(cacheKey);
26785
+ this.fontMetricsCache.delete(cacheKey);
26786
+ this.fontMetricsCache.set(cacheKey, result2);
26787
+ return result2;
26788
+ }
26789
+ const text = new Konva.Text(config);
26790
+ const size = text.measureSize(targetText);
26791
+ const result = {
26792
+ ascent: size.actualBoundingBoxAscent,
26793
+ descent: size.actualBoundingBoxDescent
26794
+ };
26795
+ if (this.fontMetricsCache.size >= this.FONT_METRICS_CACHE_LIMIT) {
26796
+ const firstKey = this.fontMetricsCache.keys().next().value;
26797
+ this.fontMetricsCache.delete(firstKey);
26798
+ }
26799
+ this.fontMetricsCache.set(cacheKey, result);
26800
+ return result;
26801
+ }
26802
+ /**
26803
+ * 获取字符排版推进宽度
26804
+ *
26805
+ * 注意:
26806
+ * 这里返回的是:
26807
+ * advance width
26808
+ *
26809
+ * 而不是:
26810
+ * glyph width
26811
+ *
26812
+ * 用于:
26813
+ * - 自动换行
26814
+ * - 光标推进
26815
+ * - 文本布局
26816
+ * - selection
26817
+ *
26818
+ * @param payload
26819
+ * @returns
26820
+ */
26821
+ static getAdvanceWidth(payload) {
26822
+ const char = payload.text ?? "";
26823
+ const fontSize2 = payload.fontSize ?? 0;
26824
+ if (this.isFullWidthChar(char)) {
26825
+ return fontSize2;
26826
+ }
26827
+ const config = Object.assign({}, payload, {
26828
+ lineHeight: 1
26829
+ });
26830
+ const text = new Konva.Text(config);
26831
+ const glyphWidth = text.width();
26832
+ const visualSpacing = this.getVisualSpacing(char, fontSize2);
26833
+ return glyphWidth + visualSpacing;
26834
+ }
26835
+ /**
26836
+ * 计算单字符布局大小
26837
+ *
26838
+ * 注意:
26839
+ * width 使用 advance width
26840
+ *
26841
+ * @param payload
26842
+ * @returns
26843
+ */
26844
+ static getLayoutSize(payload) {
26845
+ const config = Object.assign({}, payload, {
26846
+ lineHeight: 1
26847
+ });
26848
+ const cacheKey = this.getMeasureCacheKey(config);
26849
+ if (this.layoutSizeCache.has(cacheKey)) {
26850
+ const result2 = this.layoutSizeCache.get(cacheKey);
26851
+ this.layoutSizeCache.delete(cacheKey);
26852
+ this.layoutSizeCache.set(cacheKey, result2);
26853
+ return result2;
26854
+ }
26855
+ const text = new Konva.Text(config);
26856
+ const result = {
26857
+ width: this.getAdvanceWidth(payload),
26858
+ height: text.height()
26859
+ };
26860
+ if (this.layoutSizeCache.size >= this.LAYOUT_SIZE_CACHE_LIMIT) {
26861
+ const firstKey = this.layoutSizeCache.keys().next().value;
26862
+ this.layoutSizeCache.delete(firstKey);
26863
+ }
26864
+ this.layoutSizeCache.set(cacheKey, result);
26865
+ return result;
26866
+ }
26867
+ /**
26868
+ * 清除度量缓存
26869
+ */
26870
+ static clearMeasureCache() {
26871
+ this.fontMetricsCache.clear();
26872
+ this.layoutSizeCache.clear();
26873
+ }
26874
+ /**
26875
+ * 获取缓存大小
26876
+ * @returns
26877
+ */
26878
+ static getMeasureCacheSize() {
26879
+ return {
26880
+ fontMetrics: this.fontMetricsCache.size,
26881
+ layoutSize: this.layoutSizeCache.size
26882
+ };
26883
+ }
26884
+ }
26885
+ class TextRun extends LayoutNode {
26886
+ component = BuiltinComponentTypeConst.Text;
26887
+ /** 文本内容 */
26888
+ text = "";
26889
+ /** 字号 */
26890
+ fontSize = DEFAULT_FONT_SIZE;
26891
+ /** 字体 */
26892
+ fontFamily = DEFAULT_FONT_FAMILY;
26893
+ /** 高亮 */
26894
+ highlight = "none";
26895
+ /** 文字颜色 */
26896
+ color = DEFAULT_TEXT_COLOR;
26897
+ /** 加粗 */
26898
+ bold;
26899
+ /** 斜体 */
26900
+ italic;
26901
+ /** 下划线 */
26902
+ underline;
26903
+ /** 删除线 */
26904
+ strike;
26905
+ /** 字间距 */
26906
+ letterSpacing = 0;
26907
+ /** 文字对齐样式 */
26908
+ textAlign = "left";
26909
+ charMetrics = [];
26910
+ isPlaceholder = false;
26911
+ isComposition = false;
26912
+ lineHeight = 1.6;
26913
+ ascent;
26914
+ descent;
26915
+ style;
26916
+ constructor(options) {
26917
+ super(options);
26918
+ options.doc.increaseTextRunCount();
26919
+ const { text } = options;
26920
+ this.text = text;
26921
+ this.isPlaceholder = options.isPlaceholder || false;
26922
+ this.isComposition = options.isComposition || false;
26923
+ this.ascent = options.ascent ?? 0;
26924
+ this.descent = options.descent ?? 0;
26925
+ if (options.charMetrics) {
26926
+ this.charMetrics = options.charMetrics;
26927
+ } else {
26928
+ this.charMetrics.push({
26929
+ char: options.text,
26930
+ width: options.width,
26931
+ height: options.height
26932
+ });
26933
+ }
26934
+ if (options.style) {
26935
+ Object.assign(this, options.style);
26936
+ }
26937
+ }
26938
+ /**
26939
+ * 计算文字大小 度量
26940
+ * 优化版本
26941
+ * @param payload
26942
+ * @returns
26943
+ */
26944
+ static measureText(payload) {
26945
+ const { width, height } = TextUtil.getLayoutSize(payload);
26946
+ const { ascent, descent } = TextUtil.getFontMetrics(payload);
26947
+ return {
26948
+ width,
26949
+ height,
26950
+ ascent,
26951
+ descent
26952
+ };
26953
+ }
26954
+ /**
26955
+ * 计算文字大小 度量
26956
+ * @param payload
26957
+ * @returns
26958
+ */
26959
+ static __measureText(payload) {
26960
+ let config = {
26961
+ lineHeight: 1
26962
+ };
26963
+ Object.assign(config, payload);
26964
+ const text = new Konva.Text(config);
26965
+ const size = text.measureSize("Hg");
26966
+ const { actualBoundingBoxAscent: ascent, actualBoundingBoxDescent: descent } = size;
26967
+ return {
26968
+ width: text.width(),
26969
+ height: text.height(),
26970
+ ascent,
26971
+ descent
26972
+ };
26973
+ }
26974
+ static createEmptyRun(doc) {
26975
+ const fontSize2 = DEFAULT_FONT_SIZE;
26976
+ const { height, ascent, descent } = TextRun.measureText({
26977
+ text: "0",
26978
+ fontSize: fontSize2
26979
+ });
26980
+ const run = new TextRun({
26981
+ doc,
26982
+ width: 6,
26983
+ height,
26984
+ ascent,
26985
+ descent,
26986
+ text: "",
26987
+ isPlaceholder: true
26988
+ });
26989
+ return run;
26990
+ }
26991
+ /**TextStyle(样式体系的样式)转换为 Layout 层的样式
26992
+ * @param textStyle 经过继承计算的有效字符样式
26993
+ * @returns TextRun 的样式属性
26994
+ */
26995
+ static textStyle2LayoutStyle(textStyle) {
26996
+ if (!textStyle) return {};
26997
+ const layoutStyle = {};
26998
+ if (textStyle.sz !== void 0) {
26999
+ const fontSizeInPt = textStyle.sz / 2;
27000
+ layoutStyle.fontSize = fontSizeInPt * 96 / 72;
27001
+ }
27002
+ if (textStyle.rFonts?.ascii) {
27003
+ layoutStyle.fontFamily = textStyle.rFonts.ascii;
27004
+ }
27005
+ if (textStyle.highlight) {
27006
+ layoutStyle.highlight = normalizeColor(textStyle.highlight, "none");
27007
+ }
27008
+ if (textStyle.color) {
27009
+ layoutStyle.color = normalizeColor(textStyle.color, DEFAULT_TEXT_COLOR);
27010
+ }
27011
+ if (textStyle.b !== void 0) {
27012
+ layoutStyle.bold = textStyle.b;
27013
+ }
27014
+ if (textStyle.i !== void 0) {
27015
+ layoutStyle.italic = textStyle.i;
27016
+ }
27017
+ if (textStyle.u !== void 0 && textStyle.u !== "none") {
27018
+ layoutStyle.underline = true;
27019
+ }
27020
+ if (textStyle.strike !== void 0) {
27021
+ layoutStyle.strike = textStyle.strike;
27022
+ }
27023
+ if (textStyle.spacing !== void 0) {
27024
+ layoutStyle.letterSpacing = parseInt(textStyle.spacing) / 20;
27025
+ }
27026
+ if (textStyle.highlight !== void 0) ;
27027
+ return layoutStyle;
27028
+ }
27029
+ }
27030
+ class TextWidget extends TextRun {
27031
+ widgetMeta;
27032
+ valuePath;
27033
+ isEmptyPlaceholder = false;
27034
+ isIconPlaceholder = false;
27035
+ isSpacePlaceholder = false;
27036
+ widgetFieldLeftMarker;
27037
+ widgetFieldRightMarker;
27038
+ widgetOption;
27039
+ widgetFileItem;
27040
+ pageWidgetMeta;
27041
+ dataIndex;
27042
+ constructor(options) {
27043
+ super(options);
27044
+ this.widgetMeta = options.widgetMeta;
27045
+ this.valuePath = options.valuePath;
27046
+ this.isEmptyPlaceholder = options.isEmptyPlaceholder ?? false;
27047
+ this.isIconPlaceholder = options.isIconPlaceholder ?? false;
27048
+ this.isSpacePlaceholder = options.isSpacePlaceholder ?? false;
27049
+ this.widgetOption = options.widgetOption;
27050
+ this.widgetFileItem = options.widgetFileItem;
27051
+ this.widgetFieldLeftMarker = options.widgetFieldLeftMarker;
27052
+ this.widgetFieldRightMarker = options.widgetFieldRightMarker;
27053
+ this.pageWidgetMeta = options.pageWidgetMeta;
27054
+ this.dataIndex = options.dataIndex;
27055
+ }
27056
+ }
27057
+ function isLayoutTextRun(node) {
27058
+ return node != null && node.component === BuiltinComponentTypeConst.Text;
27059
+ }
27060
+ function isLayoutTextWidget(node) {
27061
+ return node instanceof TextWidget;
27062
+ }
27063
+ const AREA_ORDER = {
27064
+ overlay: -1,
27065
+ header: 0,
27066
+ body: 1,
27067
+ footer: 2
27068
+ };
27069
+ function computeCharOffsetsFromMetrics(metrics) {
27070
+ const offsets = [0];
27071
+ let acc = 0;
27072
+ for (const m of metrics) {
27073
+ acc += m.width;
27074
+ offsets.push(acc);
27075
+ }
27076
+ return offsets;
27077
+ }
27078
+ function buildTextMeta(node) {
27079
+ const charMetrics = Array.isArray(node.charMetrics) ? node.charMetrics.slice() : [];
27080
+ const charLength = Math.max(0, charMetrics.length);
27081
+ return {
27082
+ text: node.text ?? "",
27083
+ charMetrics,
27084
+ charLength,
27085
+ charOffsets: charMetrics.length > 0 ? computeCharOffsetsFromMetrics(charMetrics) : void 0
27086
+ };
27087
+ }
27088
+ function buildParagraphMeta(node) {
27089
+ return {
27090
+ lineTop: node.layoutY,
27091
+ lineBottom: node.layoutY + node.height
27092
+ };
27093
+ }
27094
+ function buildPosBox(node) {
27095
+ const absLeft = node.layoutX ?? 0;
27096
+ const absTop = node.layoutY ?? 0;
27097
+ const relLeft = node.x ?? 0;
27098
+ const relTop = node.y ?? 0;
27099
+ const width = node.mergeFromId ? 0 : node.width ?? 0;
27100
+ const height = node.mergeFromId ? 0 : node.height ?? 0;
27101
+ return {
27102
+ width,
27103
+ height,
27104
+ absbox: {
27105
+ left: absLeft,
27106
+ top: absTop,
27107
+ right: absLeft + width,
27108
+ bottom: absTop + height
27109
+ },
27110
+ relbox: {
27111
+ left: relLeft,
27112
+ top: relTop,
27113
+ right: relLeft + width,
27114
+ bottom: relTop + height
27115
+ }
27116
+ };
27117
+ }
27118
+ const lineUtils = {
27119
+ resetLineCtx(ctx) {
27120
+ ctx.lineId = void 0;
27121
+ ctx.lineIndex = -1;
27122
+ ctx.lineType = void 0;
27123
+ },
27124
+ resetTableCtx(ctx) {
27125
+ ctx.tableId = void 0;
27126
+ lineUtils.restTableRowCtx(ctx);
27127
+ lineUtils.restTableCellCtx(ctx);
27128
+ },
27129
+ restTableRowCtx(ctx) {
27130
+ ctx.tableRowId = void 0;
27131
+ ctx.tableRowIndex = void 0;
27132
+ ctx.__rowCounter = 0;
27133
+ },
27134
+ restTableCellCtx(ctx) {
27135
+ ctx.tableCellId = void 0;
27136
+ ctx.tableCellIndex = void 0;
27137
+ ctx.__cellCounter = 0;
27138
+ },
27139
+ enterPaper(ctx, pageId) {
27140
+ ctx.currentPageId = pageId;
27141
+ ctx.area = "body";
27142
+ lineUtils.resetLineCtx(ctx);
27143
+ lineUtils.resetTableCtx(ctx);
27144
+ },
27145
+ enterHeader(ctx) {
27146
+ ctx.area = "header";
27147
+ lineUtils.resetLineCtx(ctx);
27148
+ lineUtils.resetTableCtx(ctx);
27149
+ },
27150
+ enterFooter(ctx) {
27151
+ ctx.area = "footer";
27152
+ lineUtils.resetLineCtx(ctx);
27153
+ lineUtils.resetTableCtx(ctx);
27154
+ },
27155
+ enterOverlay(ctx) {
27156
+ ctx.area = "overlay";
27157
+ lineUtils.resetLineCtx(ctx);
27158
+ lineUtils.resetTableCtx(ctx);
27159
+ },
27160
+ enterTable(ctx, tableId) {
27161
+ lineUtils.resetTableCtx(ctx);
27162
+ ctx.tableId = tableId;
27163
+ },
27164
+ enterTableRow(ctx, rowId) {
27165
+ ctx.lineIndex += 1;
27166
+ ctx.lineId = rowId;
27167
+ ctx.lineType = "tablerow";
27168
+ ctx.tableRowId = rowId;
27169
+ ctx.tableRowIndex = ctx.__rowCounter;
27170
+ ctx.__rowCounter += 1;
27171
+ lineUtils.restTableCellCtx(ctx);
27172
+ },
27173
+ enterTableCell(ctx, cellId) {
27174
+ ctx.tableCellId = cellId;
27175
+ ctx.tableCellIndex = ctx.__cellCounter;
27176
+ ctx.__cellCounter += 1;
27177
+ },
27178
+ enterParagraph(ctx, nodeId) {
27179
+ ctx.lineIndex += 1;
27180
+ ctx.lineId = nodeId;
27181
+ ctx.lineType = "paragraph";
27182
+ lineUtils.resetTableCtx(ctx);
27183
+ }
27184
+ };
27185
+ function walkPageDFS(pages, cb) {
27186
+ pages.forEach((page, pi) => {
27187
+ const visit = (node, idx, path2) => {
27188
+ cb(node, idx, path2);
27189
+ const children = node?.getChildren?.() ?? node.children;
27190
+ if (Array.isArray(children)) {
27191
+ children.forEach((c2, i) => visit(c2, idx.concat(i), path2.concat(c2.id)));
27192
+ }
27193
+ };
27194
+ visit(page, [pi], [page.id]);
27195
+ if (page.headerBand) {
27196
+ visit(page.headerBand, [pi, -1], [page.id, page.headerBand.id]);
27197
+ }
27198
+ if (page.footerBand) {
27199
+ visit(page.footerBand, [pi, -2], [page.id, page.footerBand.id]);
27200
+ }
27201
+ if (page.overlayBand) {
27202
+ visit(page.overlayBand, [pi, -3], [page.id, page.overlayBand.id]);
27203
+ }
27204
+ });
27205
+ }
27206
+ function buildLayoutMeta(pages) {
27207
+ const dataCenter = /* @__PURE__ */ new Map();
27208
+ const lineCenter = /* @__PURE__ */ new Map();
27209
+ const widgetMetaMap = /* @__PURE__ */ new Map();
27210
+ const widgetIds = [];
27211
+ const ctx = {
27212
+ currentPageId: "",
27213
+ lineIndex: -1,
27214
+ __cellCounter: 0,
27215
+ __rowCounter: 0,
27216
+ area: "body"
27217
+ };
27218
+ let cursor = 0;
27219
+ function collectLineInfo(node, type4, ctx2, pageId) {
27220
+ const children = node.getChildren();
27221
+ if (!children.length) return;
27222
+ const childrenBoxes = children.map(buildPosBox);
27223
+ const absBoxes = childrenBoxes.map((b2) => ({
27224
+ ...b2.absbox,
27225
+ lineTop: node.layoutY,
27226
+ lineBottom: node.layoutY + node.height
27227
+ }));
27228
+ const areaOrder = AREA_ORDER[ctx2.area] ?? 1;
27229
+ lineCenter.set(node.id, {
27230
+ id: node.id,
27231
+ type: type4,
27232
+ pageId,
27233
+ pageArea: ctx2.area,
27234
+ sort: areaOrder * 1e5 + ctx2.lineIndex,
27235
+ nextIds: children.map((c2) => c2.id),
27236
+ size: absBoxes
27237
+ });
27238
+ }
27239
+ walkPageDFS(pages, (node, pathIndex, path2) => {
27240
+ if (!node?.id) return;
27241
+ const component = node.component;
27242
+ const page = pages[pathIndex[0]];
27243
+ if (!page) return;
27244
+ switch (component) {
27245
+ case BuiltinComponentTypeConst.Paper:
27246
+ lineUtils.enterPaper(ctx, page.id);
27247
+ break;
27248
+ case BuiltinComponentTypeConst.Header:
27249
+ lineUtils.enterHeader(ctx);
27250
+ break;
27251
+ case BuiltinComponentTypeConst.Footer:
27252
+ lineUtils.enterFooter(ctx);
27253
+ break;
27254
+ case BuiltinComponentTypeConst.OverlayContainer:
27255
+ lineUtils.enterOverlay(ctx);
27256
+ break;
27257
+ case BuiltinComponentTypeConst.Table:
27258
+ lineUtils.enterTable(ctx, node.id);
27259
+ break;
27260
+ case BuiltinComponentTypeConst.TableRow:
27261
+ lineUtils.enterTableRow(ctx, node.id);
27262
+ collectLineInfo(node, "tablerow", ctx, page.id);
27263
+ break;
27264
+ case BuiltinComponentTypeConst.TableCell:
27265
+ lineUtils.enterTableCell(ctx, node.id);
27266
+ break;
27267
+ case BuiltinComponentTypeConst.Paragraph:
27268
+ if (node.parent?.component === BuiltinComponentTypeConst.Paper || node.parent?.component === BuiltinComponentTypeConst.Header || node.parent?.component === BuiltinComponentTypeConst.Footer) {
27269
+ lineUtils.enterParagraph(ctx, node.id);
27270
+ collectLineInfo(node, "paragraph", ctx, page.id);
27271
+ }
27272
+ break;
27273
+ }
27274
+ const textMeta = component === BuiltinComponentTypeConst.Text ? buildTextMeta(node) : { charLength: 0 };
27275
+ const paragraphMeta = component === BuiltinComponentTypeConst.Paragraph ? buildParagraphMeta(node) : {};
27276
+ const pos = buildPosBox(node);
27277
+ const fr = {
27278
+ id: node.id,
27279
+ component,
27280
+ raw: node,
27281
+ runIndex: dataCenter.size,
27282
+ secRefId: page?.section.refId || "",
27283
+ pageId: page?.id || "",
27284
+ pageArea: ctx.area,
27285
+ preId: node.parent?.id ?? "",
27286
+ ...pos,
27287
+ globalPosStart: cursor,
27288
+ globalPosEnd: cursor + textMeta.charLength,
27289
+ path: path2.slice(),
27290
+ pathIndex: pathIndex.slice(),
27291
+ line: isAtom(component) ? {
27292
+ lineId: ctx.lineId,
27293
+ lineIndex: ctx.lineIndex,
27294
+ lineType: ctx.lineType,
27295
+ tableId: ctx.tableId,
27296
+ tableRowId: ctx.tableRowId,
27297
+ tableRowIndex: ctx.tableRowIndex,
27298
+ tableCellId: ctx.tableCellId,
27299
+ tableCellIndex: ctx.tableCellIndex
27300
+ } : void 0,
27301
+ ...textMeta,
27302
+ ...paragraphMeta
27303
+ };
27304
+ if (component === BuiltinComponentTypeConst.Text) {
27305
+ const widgetMeta = node?.widgetMeta;
27306
+ if (widgetMeta) {
27307
+ if (!widgetMetaMap.has(widgetMeta.id)) {
27308
+ widgetMetaMap.set(widgetMeta.id, []);
27309
+ }
27310
+ widgetMetaMap.get(widgetMeta.id).push(fr);
27311
+ }
27312
+ }
27313
+ dataCenter.set(node.id, fr);
27314
+ widgetIds.push(node.id);
27315
+ cursor += textMeta.charLength;
27316
+ });
27317
+ return { dataCenter, lineCenter, widgetIds, widgetMetaMap };
27318
+ }
27319
+ function isAtom(component) {
27320
+ return component === BuiltinComponentTypeConst.Text || component === BuiltinComponentTypeConst.InlineImage;
27321
+ }
27322
+ function isPlaceholderNode(node) {
27323
+ if (node.component !== BuiltinComponentTypeConst.Text) return false;
27324
+ const raw = node.raw;
27325
+ return !!(raw && "isPlaceholder" in raw && raw.isPlaceholder);
27326
+ }
27327
+ function isClickSelectAllNode(node, checkMarker = true) {
27328
+ if (!node) return false;
27329
+ if (node.component !== BuiltinComponentTypeConst.Text) return false;
27330
+ const raw = node.raw;
27331
+ if (!raw || !isLayoutTextWidget(raw)) return false;
27332
+ return validateTextWidgetMarker(raw, checkMarker);
27333
+ }
27334
+ function validateTextWidgetMarker(raw, checkMarker) {
27335
+ const baseValid = raw.isWidgetRun;
27336
+ if (!checkMarker) {
27337
+ return baseValid;
27338
+ }
27339
+ return baseValid && !(raw.widgetFieldLeftMarker || raw.widgetFieldRightMarker);
27340
+ }
27341
+ function isClickPaperWidgetAllNode(node) {
27342
+ if (!node) return false;
27343
+ const raw = node.raw;
27344
+ return raw.isPageWidgetRun;
27345
+ }
27346
+ class TextHitHandler {
27347
+ handleHitDetection(doc, node, actualX, actualY) {
27348
+ const base = getBaseMetaInfo(node);
27349
+ if (doc.isInEditMode() && isClickSelectAllNode(node, false)) {
27350
+ const raw = node.raw;
27351
+ const modelId = raw.modelRef?.id;
27352
+ if (raw.widgetFieldLeftMarker || raw.widgetFieldRightMarker) {
27353
+ const side2 = raw.widgetFieldLeftMarker ? "before" : "after";
27354
+ return {
27355
+ ...base,
27356
+ offset: 0,
27357
+ side: side2
27358
+ };
27359
+ }
27360
+ if (!modelId) return null;
27361
+ const widgetIds = doc.layoutMapper.getModelSplitById(modelId);
27362
+ const nodes = doc.layoutMapper.getBaseMetaNodeByIds(widgetIds);
27363
+ if (!nodes?.length) return null;
27364
+ const filterNodes = nodes.filter(
27365
+ (node2) => !(node2.raw.widgetFieldLeftMarker || node2.raw.widgetFieldRightMarker)
27366
+ );
27367
+ const total = filterNodes.length;
27368
+ const midIndex = Math.floor(total / 2);
27369
+ const clickedIndex = filterNodes.findIndex((n) => n.id === node.id);
27370
+ let side = "after";
27371
+ if (clickedIndex < midIndex) {
27372
+ side = "before";
27373
+ } else if (clickedIndex > midIndex) {
27374
+ side = "after";
27375
+ } else {
27376
+ side = resolveMiddleSide(filterNodes[midIndex], actualX);
27377
+ }
27378
+ const targetNode = side === "after" ? filterNodes[total - 1] : filterNodes[0];
27379
+ return {
27380
+ ...getBaseMetaInfo(targetNode),
27381
+ offset: 0,
27382
+ side
27383
+ };
27384
+ }
27385
+ if (doc.isInFillMode() && !isClickSelectAllNode(node)) {
27386
+ return null;
27387
+ }
27388
+ if (Array.isArray(node.charOffsets) && node.charOffsets.length > 0) {
27389
+ return resolveCharHit(node, base, actualX);
27390
+ }
27391
+ return {
27392
+ ...base,
27393
+ offset: 0,
27394
+ side: "after"
27395
+ };
27396
+ }
27397
+ isClickSelectAll(doc, node) {
27398
+ return {
27399
+ type: "cursor"
27400
+ };
27401
+ }
27402
+ // todo 后续文本改成多文字一个节点可以处理
27403
+ // resolveCursorIntent(doc: Doc, node: BaseMetaNode, cursor: ICursorPosition) {
27404
+ // const base = getBaseMetaInfo(node);
27405
+ // const isPlaceholder = !!((node.raw as any).isPlaceholder);
27406
+ // if (isPlaceholder) {
27407
+ // return { ...base, isPlaceholder: true, offset: 0, side: cursor.side || 'before', };
27408
+ // }
27409
+ // const offsets = Array.isArray(node.charOffsets) ? node.charOffsets as number[] : undefined;
27410
+ // if (offsets && offsets.length > 0) {
27411
+ // let off = Number.isFinite(Number(cursor.offset)) ? Math.floor(Number(cursor.offset)) : 0;
27412
+ // off = Math.max(0, Math.min(off, offsets.length));
27413
+ // const side = off >= offsets.length ? 'after' : (cursor.side || 'before');
27414
+ // return { ...base, offset: off, side };
27415
+ // }
27416
+ // const off = Number.isFinite(Number(cursor.offset)) ? Math.max(0, Math.floor(Number(cursor.offset))) : 0;
27417
+ // return { ...base, offset: off, side: cursor.side || 'before' };
27418
+ // }
27419
+ }
27420
+ function toHorizontalIntervals(childMeta) {
27421
+ return childMeta.map((i) => {
27422
+ if (!i) return null;
27423
+ const left = i.absbox.left ?? 0;
27424
+ const right = i.absbox.right ?? left;
27425
+ return [left, right];
27426
+ }).filter(Boolean);
27427
+ }
27428
+ function toVerticalIntervalsAbs(doc, childMeta, pageId) {
27429
+ return childMeta.map((c2) => {
27430
+ if (!c2) return null;
27431
+ const top = doc.layoutMapper.getAbsoluteCanvasPosition(
27432
+ pageId,
27433
+ 0,
27434
+ c2.absbox.top,
27435
+ true
27436
+ ).y;
27437
+ const bottom = doc.layoutMapper.getAbsoluteCanvasPosition(
27438
+ pageId,
27439
+ 0,
27440
+ c2.absbox.bottom,
27441
+ true
27442
+ ).y;
27443
+ return [top, bottom];
27444
+ }).filter(Boolean);
27445
+ }
27446
+ function findIntervalIndex(intervals, actualX) {
27447
+ let left = 0;
27448
+ let right = intervals.length - 1;
27449
+ while (left <= right) {
27450
+ const mid = Math.floor((left + right) / 2);
27451
+ const [start, end] = intervals[mid];
27452
+ if (actualX >= start && actualX < end) return mid;
27453
+ if (actualX < start) right = mid - 1;
27454
+ else left = mid + 1;
27455
+ }
27456
+ return -1;
27457
+ }
27458
+ function getIntervalSide(intervals, actualX) {
27459
+ if (!intervals || !intervals.length) return null;
27460
+ const foundIndex = findIntervalIndex(intervals, actualX);
27461
+ if (foundIndex !== -1) {
27462
+ const [start, end] = intervals[foundIndex];
27463
+ const midpoint = (start + end) / 2;
27464
+ return {
27465
+ index: foundIndex,
27466
+ side: actualX < midpoint ? "before" : "after",
27467
+ distance: Math.min(actualX - start, end - actualX)
27468
+ };
27469
+ }
27470
+ let closestIndex = -1;
27471
+ let closestDistance = Infinity;
27472
+ let side = "before";
27473
+ for (let i = 0; i < intervals.length; i++) {
27474
+ const [start, end] = intervals[i];
27475
+ const distToStart = Math.abs(actualX - start);
27476
+ if (distToStart < closestDistance) {
27477
+ closestDistance = distToStart;
27478
+ closestIndex = i;
27479
+ side = actualX < start ? "before" : "after";
27480
+ }
27481
+ const distToEnd = Math.abs(actualX - end);
27482
+ if (distToEnd < closestDistance) {
27483
+ closestDistance = distToEnd;
27484
+ closestIndex = i;
27485
+ side = actualX < end ? "before" : "after";
27486
+ }
27487
+ }
27488
+ if (closestIndex !== -1) {
27489
+ return {
27490
+ index: closestIndex,
27491
+ side,
27492
+ distance: closestDistance
27493
+ };
26648
27494
  }
26649
27495
  return null;
26650
27496
  }
@@ -30915,48 +31761,6 @@ const __vite_glob_0_13$3 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.
30915
31761
  __proto__: null,
30916
31762
  Enter
30917
31763
  }, Symbol.toStringTag, { value: "Module" }));
30918
- function normalizeColor(color, defaultColor = "#000000") {
30919
- if (color === "auto" || !color) {
30920
- return defaultColor;
30921
- }
30922
- if (color.startsWith("#")) {
30923
- return color;
30924
- }
30925
- if (color.length === 8 && /^[0-9A-Fa-f]{8}$/.test(color)) {
30926
- const alpha = color.substring(0, 2);
30927
- const rgb = color.substring(2);
30928
- return `#${rgb}${alpha}`;
30929
- }
30930
- if (color.length === 6 && /^[0-9A-Fa-f]{6}$/.test(color)) {
30931
- return `#${color}`;
30932
- }
30933
- if (color.length === 3 && /^[0-9A-Fa-f]{3}$/.test(color)) {
30934
- return `#${color}`;
30935
- }
30936
- return color;
30937
- }
30938
- function repeat(count, callback) {
30939
- for (let i = 0; i < count; i++) {
30940
- callback(i);
30941
- }
30942
- }
30943
- function distributeInteger(total, count) {
30944
- if (count <= 0) throw new Error("count must be > 0");
30945
- if (total < 0) throw new Error("total must be >= 0");
30946
- const base = Math.floor(total / count);
30947
- const remainder = total % count;
30948
- const result = [];
30949
- for (let i = 0; i < count; i++) {
30950
- result.push(i < count - remainder ? base : base + 1);
30951
- }
30952
- return result;
30953
- }
30954
- const mainData2WordData = (data) => {
30955
- const entries = Object.entries(data).map(([key, value]) => {
30956
- return [`$.${key}`, value];
30957
- });
30958
- return Object.fromEntries(entries);
30959
- };
30960
31764
  class InsertCol extends CommandBase {
30961
31765
  constructor(doc, payload) {
30962
31766
  super(doc, payload);
@@ -31111,10 +31915,11 @@ class InsertField extends CommandBase {
31111
31915
  */
31112
31916
  isConsecutivePath(parentPath, childPath) {
31113
31917
  if (!parentPath || !childPath) return false;
31114
- if (!childPath.startsWith(parentPath)) {
31918
+ const _parentPath = parentPath.includes(":") ? parentPath.split(":")[0] : parentPath;
31919
+ if (!childPath.startsWith(_parentPath)) {
31115
31920
  return false;
31116
31921
  }
31117
- const remainder = childPath.slice(parentPath.length);
31922
+ const remainder = childPath.slice(_parentPath.length);
31118
31923
  if (remainder === "") {
31119
31924
  return false;
31120
31925
  }
@@ -31759,10 +32564,10 @@ class InsertText extends CommandBase {
31759
32564
  side: "after"
31760
32565
  };
31761
32566
  }
31762
- if (validateTextWidgetMarker(run, false) || run.isPageWidgetRun) {
32567
+ if (isLayoutTextWidget(run) && validateTextWidgetMarker(run, false) || run.isPageWidgetRun) {
31763
32568
  const wr2 = mapper.getModelNodeById(run.modelRef.id);
31764
32569
  if (!wr2) return null;
31765
- const raw = run;
32570
+ const raw = isLayoutTextWidget(run) ? run : run;
31766
32571
  if (raw.widgetFieldLeftMarker || raw.widgetFieldRightMarker || run.isPageWidgetRun) {
31767
32572
  const newWr = new WrText({ text });
31768
32573
  if (raw.widgetFieldLeftMarker) {
@@ -31796,6 +32601,7 @@ class InsertText extends CommandBase {
31796
32601
  };
31797
32602
  }
31798
32603
  }
32604
+ if (!isLayoutTextRun(run)) return null;
31799
32605
  const wr = mapper.getModelNodeById(run.modelRef.id);
31800
32606
  if (!wr) return null;
31801
32607
  const oldText = String(run.text || "").trim();
@@ -32128,7 +32934,7 @@ class SetAlign extends CommandBase {
32128
32934
  }
32129
32935
  const paragraphs = [];
32130
32936
  for (const { model } of models) {
32131
- if (model.type === "paragraph") {
32937
+ if (model.name === "w:p") {
32132
32938
  paragraphs.push(model);
32133
32939
  }
32134
32940
  }
@@ -38211,467 +39017,70 @@ const _sfc_main$2$ = /* @__PURE__ */ defineComponent({
38211
39017
  ]),
38212
39018
  _: 1
38213
39019
  }, 8, ["tooltip"]);
38214
- };
38215
- }
38216
- });
38217
- const GctColorPicker = /* @__PURE__ */ _export_sfc(_sfc_main$2$, [["__scopeId", "data-v-a0f4e1cb"]]);
38218
- const DefaultAvatar = "data:image/png;base64,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";
38219
- let urlCacheMap = {};
38220
- function transformUrl(url2, { random = true } = {}) {
38221
- if (!url2) {
38222
- return "/404.png";
38223
- }
38224
- let basePath = "/minio";
38225
- const url22 = `${basePath}${url2.startsWith("/") ? "" : "/"}${url2}`;
38226
- if (!random) return url22;
38227
- if (urlCacheMap[url2] && Date.now() - urlCacheMap[url2].timestamp < 60 * 1e3) {
38228
- return `${url22}?${urlCacheMap[url2].random}`;
38229
- }
38230
- if (Object.keys(urlCacheMap).length > 100) urlCacheMap = {};
38231
- const r = Math.random();
38232
- urlCacheMap[url2] = {
38233
- random: r,
38234
- timestamp: Date.now()
38235
- };
38236
- return `${url22}?${r}`;
38237
- }
38238
- const _hoisted_1$1V = { class: "avatar__avatar" };
38239
- const _hoisted_2$1d = ["src"];
38240
- const _hoisted_3$U = {
38241
- key: 0,
38242
- class: "avatar__name"
38243
- };
38244
- const _sfc_main$2_ = /* @__PURE__ */ defineComponent({
38245
- __name: "Avatar",
38246
- props: {
38247
- avatar: {},
38248
- name: {},
38249
- direction: { default: "vertical" }
38250
- },
38251
- setup(__props) {
38252
- const props = __props;
38253
- const avatarUrl = computed(() => {
38254
- return props.avatar ? transformUrl(props.avatar) : DefaultAvatar;
38255
- });
38256
- return (_ctx, _cache) => {
38257
- return openBlock(), createElementBlock("div", {
38258
- class: normalizeClass(["avatar", `avatar--${__props.direction}`])
38259
- }, [
38260
- createElementVNode("div", _hoisted_1$1V, [
38261
- createElementVNode("img", {
38262
- class: "avatar__avatar-img",
38263
- src: avatarUrl.value
38264
- }, null, 8, _hoisted_2$1d)
38265
- ]),
38266
- __props.name ? (openBlock(), createElementBlock("div", _hoisted_3$U, toDisplayString(__props.name), 1)) : createCommentVNode("", true)
38267
- ], 2);
38268
- };
38269
- }
38270
- });
38271
- const GctAvatar = /* @__PURE__ */ _export_sfc(_sfc_main$2_, [["__scopeId", "data-v-b2773d93"]]);
38272
- class SetBoundedItem extends CommandBase {
38273
- constructor(doc, payload) {
38274
- super(doc, payload);
38275
- }
38276
- async execute() {
38277
- const cursor = this.doc.cursorManager;
38278
- if (cursor.isCollapsed()) return null;
38279
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38280
- if (mode !== SelectionMode.Tds) return null;
38281
- if (models.length === 0) return null;
38282
- const startCell = models[0].model;
38283
- const endCell = models[models.length - 1].model;
38284
- const start = {
38285
- row: startCell.parent?.getCurrentIndex(),
38286
- col: startCell.getCurrentIndex()
38287
- };
38288
- const end = {
38289
- row: endCell.parent?.getCurrentIndex(),
38290
- col: endCell.getCurrentIndex()
38291
- };
38292
- const boundedRegion = this.getBoundedRegion(startCell, endCell);
38293
- if (!boundedRegion) {
38294
- GctMessage.warning("选区不在固定表范围内");
38295
- throw new Error("Cells are not in a bounded region");
38296
- }
38297
- this.output = boundedRegion.setItemRegion({
38298
- start,
38299
- end
38300
- });
38301
- return null;
38302
- }
38303
- /**
38304
- *
38305
- * @param startCell
38306
- * @param endCell
38307
- * @returns
38308
- */
38309
- getBoundedRegion(startCell, endCell) {
38310
- const region = this.getRegion(startCell, endCell);
38311
- if (!region) {
38312
- GctMessage.warning("选区超出子表范围");
38313
- throw new Error("Cells are not in the same region");
38314
- }
38315
- return region.type === "bounded" ? region : void 0;
38316
- }
38317
- /**
38318
- * 获取公共区域
38319
- * @param startCell
38320
- * @param endCell
38321
- * @returns
38322
- */
38323
- getRegion(startCell, endCell) {
38324
- if (startCell === endCell) {
38325
- return startCell.getRegion();
38326
- }
38327
- const startRegion = startCell.getRegion();
38328
- const endRegion = endCell.getRegion();
38329
- if (startRegion && endRegion && startRegion === endRegion) {
38330
- return startRegion;
38331
- }
38332
- return;
38333
- }
38334
- }
38335
- const __vite_glob_0_31$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38336
- __proto__: null,
38337
- SetBoundedItem
38338
- }, Symbol.toStringTag, { value: "Module" }));
38339
- class SetCheckTable extends CommandBase {
38340
- constructor(doc, payload) {
38341
- super(doc, payload);
38342
- }
38343
- async execute() {
38344
- const cursor = this.doc.cursorManager;
38345
- if (cursor.isCollapsed()) return null;
38346
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38347
- if (mode !== SelectionMode.Tds) return null;
38348
- if (models.length === 0) return null;
38349
- const startCell = models[0].model;
38350
- const endCell = models[models.length - 1].model;
38351
- const start = {
38352
- row: startCell.parent?.getCurrentIndex(),
38353
- col: startCell.getCurrentIndex()
38354
- };
38355
- const end = {
38356
- row: endCell.parent?.getCurrentIndex(),
38357
- col: endCell.getCurrentIndex()
38358
- };
38359
- this.output = startCell.table.setCheckTable({
38360
- start,
38361
- end,
38362
- name: this.payload.name,
38363
- valuePath: this.payload.valuePath
38364
- });
38365
- return null;
38366
- }
38367
- }
38368
- const __vite_glob_0_32$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38369
- __proto__: null,
38370
- SetCheckTable
38371
- }, Symbol.toStringTag, { value: "Module" }));
38372
- class SetColor extends SetStyleBase {
38373
- constructor(doc, payload) {
38374
- super(doc, payload);
38375
- }
38376
- applyStyle(run) {
38377
- run.setColor(this.payload.color);
38378
- }
38379
- }
38380
- const __vite_glob_0_33$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38381
- __proto__: null,
38382
- SetColor
38383
- }, Symbol.toStringTag, { value: "Module" }));
38384
- class SetDataGroup2D extends CommandBase {
38385
- constructor(doc, payload) {
38386
- super(doc, payload);
38387
- }
38388
- async execute() {
38389
- const cursor = this.doc.cursorManager;
38390
- if (cursor.isCollapsed()) return null;
38391
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38392
- if (mode !== SelectionMode.Tds) return null;
38393
- if (models.length === 0) return null;
38394
- const startCell = models[0].model;
38395
- const endCell = models[models.length - 1].model;
38396
- const cellList = [...models.map((m) => m.model)];
38397
- const start = {
38398
- row: startCell.parent?.getCurrentIndex(),
38399
- col: startCell.getCurrentIndex()
38400
- };
38401
- const end = {
38402
- row: endCell.parent?.getCurrentIndex(),
38403
- col: endCell.getCurrentIndex()
38404
- };
38405
- const subTableRegion = this.getSubTableRegion(cellList);
38406
- if (!subTableRegion) {
38407
- throw new Error("Cells are not in a sub table region supporting data-group-2d");
38408
- }
38409
- this.output = subTableRegion.setItemRegion({
38410
- start,
38411
- end
38412
- });
38413
- return null;
38414
- }
38415
- /**
38416
- *
38417
- * @param cellList
38418
- * @returns
38419
- */
38420
- getSubTableRegion(cellList) {
38421
- let region;
38422
- cellList.some((cell) => {
38423
- const r = cell.getRegion();
38424
- if (r && ["check-table", "2d-table"].includes(r.type)) {
38425
- region = r;
38426
- return true;
38427
- }
38428
- });
38429
- if (!region) {
38430
- throw new Error("No region found");
38431
- }
38432
- return region;
38433
- }
38434
- }
38435
- const __vite_glob_0_34$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38436
- __proto__: null,
38437
- SetDataGroup2D
38438
- }, Symbol.toStringTag, { value: "Module" }));
38439
- class SetFont extends SetStyleBase {
38440
- constructor(doc, payload) {
38441
- super(doc, payload);
38442
- }
38443
- applyStyle(run) {
38444
- run.setFont(this.payload.fontFamily);
38445
- }
38446
- }
38447
- const __vite_glob_0_35$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38448
- __proto__: null,
38449
- SetFont
38450
- }, Symbol.toStringTag, { value: "Module" }));
38451
- class SetFontSize extends SetStyleBase {
38452
- constructor(doc, payload) {
38453
- super(doc, payload);
38454
- this.needsCalculatePostCommandContext = true;
38455
- }
38456
- applyStyle(run) {
38457
- run.setFontSize(this.payload.fontSize * 2);
38458
- }
38459
- }
38460
- const __vite_glob_0_36$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38461
- __proto__: null,
38462
- SetFontSize
38463
- }, Symbol.toStringTag, { value: "Module" }));
38464
- class SetHeaderFooterConfig extends CommandBase {
38465
- constructor(doc, payload) {
38466
- super(doc, payload);
38467
- }
38468
- async execute() {
38469
- const { headerMargin, footerMargin, titlePg, evenAndOddHeaders } = this.payload;
38470
- this.doc?.eventManager.cursorController.clearCursor();
38471
- const sections = (this.doc.model?.document.body.children ?? []).filter(
38472
- (item) => item.name === "w:secPr"
38473
- );
38474
- if (sections.length === 0) {
38475
- this.isTerminated = true;
38476
- return null;
38477
- }
38478
- for (const section of sections) {
38479
- if (headerMargin !== void 0) {
38480
- section.setHeaderMargin(headerMargin);
38481
- }
38482
- if (footerMargin !== void 0) {
38483
- section.setFooterMargin(footerMargin);
38484
- }
38485
- if (titlePg !== void 0) {
38486
- section.setTitlePg(titlePg);
38487
- }
38488
- }
38489
- if (evenAndOddHeaders !== void 0) {
38490
- this.doc.model?.settings.setEvenAndOddHeaders(evenAndOddHeaders);
38491
- }
38492
- return null;
38493
- }
38494
- }
38495
- const __vite_glob_0_37$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38496
- __proto__: null,
38497
- SetHeaderFooterConfig
38498
- }, Symbol.toStringTag, { value: "Module" }));
38499
- class SetHighlight extends SetStyleBase {
38500
- constructor(doc, payload) {
38501
- super(doc, payload);
38502
- }
38503
- applyStyle(run) {
38504
- run.setHighlight(this.payload.highlight);
38505
- }
38506
- }
38507
- const __vite_glob_0_38$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38508
- __proto__: null,
38509
- SetHighlight
38510
- }, Symbol.toStringTag, { value: "Module" }));
38511
- class SetItalic extends SetStyleBase {
38512
- constructor(doc, payload) {
38513
- super(doc, payload);
38514
- }
38515
- applyStyle(run) {
38516
- run.setItalic(this.payload?.italic ?? true);
38517
- }
38518
- }
38519
- const __vite_glob_0_39$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38520
- __proto__: null,
38521
- SetItalic
38522
- }, Symbol.toStringTag, { value: "Module" }));
38523
- class SetOrient extends CommandBase {
38524
- constructor(doc, payload) {
38525
- super(doc, payload);
38526
- }
38527
- async execute() {
38528
- const { orient, serRefId } = this.payload;
38529
- if (!["portrait", "landscape"].includes(orient)) {
38530
- throw new Error(`Invalid orientation: ${orient}`);
38531
- }
38532
- if (!serRefId) {
38533
- this.isTerminated = true;
38534
- return null;
38535
- }
38536
- const section = this.doc.model?.document.body.children.find(
38537
- (item) => item.id === serRefId
38538
- );
38539
- if (!section) {
38540
- this.isTerminated = true;
38541
- return null;
38542
- }
38543
- section.setOrient(orient);
38544
- return null;
38545
- }
38546
- }
38547
- const __vite_glob_0_40$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38548
- __proto__: null,
38549
- SetOrient
38550
- }, Symbol.toStringTag, { value: "Module" }));
38551
- class SetPadding extends CommandBase {
38552
- constructor(doc, payload) {
38553
- super(doc, payload);
38554
- }
38555
- async execute() {
38556
- const { padding, serRefId } = this.payload;
38557
- if (!serRefId) {
38558
- this.isTerminated = true;
38559
- return null;
38560
- }
38561
- const section = this.doc.model?.document.body.children.find(
38562
- (item) => item.id === serRefId
38563
- );
38564
- if (!section) {
38565
- this.isTerminated = true;
38566
- return null;
38567
- }
38568
- const [top, right, bottom, left] = padding;
38569
- section.setMargins(top, bottom, left, right);
38570
- return null;
38571
- }
38572
- }
38573
- const __vite_glob_0_41$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38574
- __proto__: null,
38575
- SetPadding
38576
- }, Symbol.toStringTag, { value: "Module" }));
38577
- class SetRepeating extends CommandBase {
38578
- constructor(doc, payload) {
38579
- super(doc, payload);
38580
- }
38581
- async execute() {
38582
- const cursor = this.doc.cursorManager;
38583
- if (cursor.isCollapsed()) return null;
38584
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38585
- if (mode !== SelectionMode.Tds) return null;
38586
- if (models.length === 0) return null;
38587
- const startCell = models[0].model;
38588
- const endCell = models[models.length - 1].model;
38589
- const start = {
38590
- row: startCell.parent?.getCurrentIndex(),
38591
- col: startCell.getCurrentIndex()
38592
- };
38593
- const end = {
38594
- row: endCell.parent?.getCurrentIndex(),
38595
- col: endCell.getCurrentIndex()
38596
- };
38597
- this.output = startCell.table.setRepeating({
38598
- start,
38599
- end,
38600
- name: this.payload.name,
38601
- valuePath: this.payload.valuePath
38602
- });
38603
- return null;
38604
- }
38605
- }
38606
- const __vite_glob_0_42$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38607
- __proto__: null,
38608
- SetRepeating
38609
- }, Symbol.toStringTag, { value: "Module" }));
38610
- class SetStrike extends SetStyleBase {
38611
- constructor(doc, payload) {
38612
- super(doc, payload);
38613
- }
38614
- applyStyle(run) {
38615
- run.setStrike(this.payload.strike);
39020
+ };
38616
39021
  }
38617
- }
38618
- const __vite_glob_0_43 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38619
- __proto__: null,
38620
- SetStrike
38621
- }, Symbol.toStringTag, { value: "Module" }));
38622
- class SetSubTableHeader extends CommandBase {
38623
- constructor(doc, payload) {
38624
- super(doc, payload);
39022
+ });
39023
+ const GctColorPicker = /* @__PURE__ */ _export_sfc(_sfc_main$2$, [["__scopeId", "data-v-a0f4e1cb"]]);
39024
+ const DefaultAvatar = "data:image/png;base64,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";
39025
+ let urlCacheMap = {};
39026
+ function transformUrl(url2, { random = true } = {}) {
39027
+ if (!url2) {
39028
+ return "/404.png";
38625
39029
  }
38626
- async execute() {
38627
- const cursor = this.doc.cursorManager;
38628
- const { name } = this.payload;
38629
- if (cursor.isCollapsed()) return null;
38630
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38631
- if (mode !== SelectionMode.Tds) return null;
38632
- if (models.length === 0) return null;
38633
- const startCell = models[0].model;
38634
- const endCell = models[models.length - 1].model;
38635
- const start = {
38636
- row: startCell.parent?.getCurrentIndex(),
38637
- col: startCell.getCurrentIndex()
38638
- };
38639
- const end = {
38640
- row: endCell.parent?.getCurrentIndex(),
38641
- col: endCell.getCurrentIndex()
38642
- };
38643
- const region = this.getSubTableRegion(endCell.table, end.row);
38644
- if (!region) {
38645
- GctMessage.warning("没有找到对应子表");
38646
- return null;
38647
- }
38648
- const crossRegion = startCell.table.findCrossRegion({ start, end });
38649
- crossRegion && startCell.table.deleteRegionById(crossRegion.id);
38650
- this.output = startCell.table.setSubTableHeader({
38651
- start,
38652
- end,
38653
- name,
38654
- subTableId: region.id
38655
- });
38656
- return null;
39030
+ let basePath = "/minio";
39031
+ const url22 = `${basePath}${url2.startsWith("/") ? "" : "/"}${url2}`;
39032
+ if (!random) return url22;
39033
+ if (urlCacheMap[url2] && Date.now() - urlCacheMap[url2].timestamp < 60 * 1e3) {
39034
+ return `${url22}?${urlCacheMap[url2].random}`;
38657
39035
  }
38658
- getSubTableRegion(table, rowIndex) {
38659
- return table.regions.find((region) => {
38660
- return region.start.row === rowIndex + 1 && ["repeating", "bounded", "check-table", "2d-table"].includes(region.type);
39036
+ if (Object.keys(urlCacheMap).length > 100) urlCacheMap = {};
39037
+ const r = Math.random();
39038
+ urlCacheMap[url2] = {
39039
+ random: r,
39040
+ timestamp: Date.now()
39041
+ };
39042
+ return `${url22}?${r}`;
39043
+ }
39044
+ const _hoisted_1$1V = { class: "avatar__avatar" };
39045
+ const _hoisted_2$1d = ["src"];
39046
+ const _hoisted_3$U = {
39047
+ key: 0,
39048
+ class: "avatar__name"
39049
+ };
39050
+ const _sfc_main$2_ = /* @__PURE__ */ defineComponent({
39051
+ __name: "Avatar",
39052
+ props: {
39053
+ avatar: {},
39054
+ name: {},
39055
+ direction: { default: "vertical" }
39056
+ },
39057
+ setup(__props) {
39058
+ const props = __props;
39059
+ const avatarUrl = computed(() => {
39060
+ return props.avatar ? transformUrl(props.avatar) : DefaultAvatar;
38661
39061
  });
39062
+ return (_ctx, _cache) => {
39063
+ return openBlock(), createElementBlock("div", {
39064
+ class: normalizeClass(["avatar", `avatar--${__props.direction}`])
39065
+ }, [
39066
+ createElementVNode("div", _hoisted_1$1V, [
39067
+ createElementVNode("img", {
39068
+ class: "avatar__avatar-img",
39069
+ src: avatarUrl.value
39070
+ }, null, 8, _hoisted_2$1d)
39071
+ ]),
39072
+ __props.name ? (openBlock(), createElementBlock("div", _hoisted_3$U, toDisplayString(__props.name), 1)) : createCommentVNode("", true)
39073
+ ], 2);
39074
+ };
38662
39075
  }
38663
- }
38664
- const __vite_glob_0_44 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38665
- __proto__: null,
38666
- SetSubTableHeader
38667
- }, Symbol.toStringTag, { value: "Module" }));
38668
- class SetTableHeader extends CommandBase {
39076
+ });
39077
+ const GctAvatar = /* @__PURE__ */ _export_sfc(_sfc_main$2_, [["__scopeId", "data-v-b2773d93"]]);
39078
+ class SetBoundedItem extends CommandBase {
38669
39079
  constructor(doc, payload) {
38670
39080
  super(doc, payload);
38671
39081
  }
38672
39082
  async execute() {
38673
39083
  const cursor = this.doc.cursorManager;
38674
- const { name } = this.payload;
38675
39084
  if (cursor.isCollapsed()) return null;
38676
39085
  const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38677
39086
  if (mode !== SelectionMode.Tds) return null;
@@ -38686,889 +39095,618 @@ class SetTableHeader extends CommandBase {
38686
39095
  row: endCell.parent?.getCurrentIndex(),
38687
39096
  col: endCell.getCurrentIndex()
38688
39097
  };
38689
- this.output = startCell.table.setTableHeader({
39098
+ const boundedRegion = this.getBoundedRegion(startCell, endCell);
39099
+ if (!boundedRegion) {
39100
+ GctMessage.warning("选区不在固定表范围内");
39101
+ throw new Error("Cells are not in a bounded region");
39102
+ }
39103
+ this.output = boundedRegion.setItemRegion({
38690
39104
  start,
38691
- end,
38692
- name
39105
+ end
38693
39106
  });
38694
39107
  return null;
38695
39108
  }
38696
- }
38697
- const __vite_glob_0_45 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38698
- __proto__: null,
38699
- SetTableHeader
38700
- }, Symbol.toStringTag, { value: "Module" }));
38701
- class SetUnderline extends SetStyleBase {
38702
- constructor(doc, payload) {
38703
- super(doc, payload);
38704
- }
38705
- applyStyle(run) {
38706
- run.setUnderline(this.payload?.underline ?? "single");
38707
- }
38708
- }
38709
- const __vite_glob_0_46 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38710
- __proto__: null,
38711
- SetUnderline
38712
- }, Symbol.toStringTag, { value: "Module" }));
38713
- class Snapshot extends CommandBase {
38714
- constructor(doc, payload) {
38715
- super(doc, payload);
38716
- }
38717
- async execute() {
38718
- return null;
38719
- }
38720
- }
38721
- const __vite_glob_0_47 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38722
- __proto__: null,
38723
- Snapshot
38724
- }, Symbol.toStringTag, { value: "Module" }));
38725
- class UnmergeCells extends CommandBase {
38726
- constructor(doc, payload) {
38727
- super(doc, payload);
38728
- }
38729
- async execute() {
38730
- const cursor = this.doc.cursorManager;
38731
- if (cursor.isCollapsed()) return;
38732
- const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
38733
- if (mode !== SelectionMode.Tds) return;
38734
- if (models.length === 0) return;
38735
- const roots = models.map(({ model }) => model).filter((cell) => cell.id === cell.mergeId && !cell.mergeFromId);
38736
- if (roots.length === 0) return null;
38737
- const table = roots[0]?.table;
38738
- if (!table) return null;
38739
- table.runConsistencyMutation({
38740
- mutate: () => {
38741
- roots.forEach((cell) => {
38742
- cell.unmerge({ skipConsistency: true });
38743
- });
38744
- }
38745
- });
38746
- const mapper = this.doc.layoutMapper;
38747
- const normalized = this.doc.cursorManager.normalizeRange(cursor.getSelection());
38748
- const start = mapper.getLayoutNodeById(normalized.rangeStart.nodeId);
38749
- if (start?.isPlaceholderRun) {
38750
- const wp = mapper.getModelNodeById(start.parent.modelRef.id);
38751
- return {
38752
- wp,
38753
- pos: -1,
38754
- side: "after"
38755
- };
38756
- }
38757
- const wr = mapper.getModelNodeById(start.modelRef.id);
38758
- return {
38759
- wr,
38760
- pos: -1,
38761
- side: "after"
38762
- };
38763
- }
38764
- }
38765
- const __vite_glob_0_48 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
38766
- __proto__: null,
38767
- UnmergeCells
38768
- }, Symbol.toStringTag, { value: "Module" }));
38769
- const commandModules = /* @__PURE__ */ Object.assign({
38770
- "./commands/Backspace.ts": __vite_glob_0_0$4,
38771
- "./commands/CommitValidateNumber.ts": __vite_glob_0_1$4,
38772
- "./commands/Delete.ts": __vite_glob_0_2$4,
38773
- "./commands/Delete2DTable.ts": __vite_glob_0_3$4,
38774
- "./commands/DeleteBounded.ts": __vite_glob_0_4$4,
38775
- "./commands/DeleteBoundedItem.ts": __vite_glob_0_5$4,
38776
- "./commands/DeleteCheckTable.ts": __vite_glob_0_6$4,
38777
- "./commands/DeleteCol.ts": __vite_glob_0_7$3,
38778
- "./commands/DeleteDataGroup2D.ts": __vite_glob_0_8$3,
38779
- "./commands/DeleteRepeating.ts": __vite_glob_0_9$3,
38780
- "./commands/DeleteRow.ts": __vite_glob_0_10$3,
38781
- "./commands/DeleteTable.ts": __vite_glob_0_11$3,
38782
- "./commands/DeleteTableHeader.ts": __vite_glob_0_12$3,
38783
- "./commands/Enter.ts": __vite_glob_0_13$3,
38784
- "./commands/InsertCol.ts": __vite_glob_0_14$2,
38785
- "./commands/InsertField.ts": __vite_glob_0_15$2,
38786
- "./commands/InsertFloatingOverlay.ts": __vite_glob_0_16$1,
38787
- "./commands/InsertImage.ts": __vite_glob_0_17$1,
38788
- "./commands/InsertPaperWidget.ts": __vite_glob_0_18$1,
38789
- "./commands/InsertRow.ts": __vite_glob_0_19$1,
38790
- "./commands/InsertTable.ts": __vite_glob_0_20$1,
38791
- "./commands/InsertText.ts": __vite_glob_0_21$1,
38792
- "./commands/MergeCells.ts": __vite_glob_0_22$1,
38793
- "./commands/ResizeCol.ts": __vite_glob_0_23$1,
38794
- "./commands/ResizeImage.ts": __vite_glob_0_24$1,
38795
- "./commands/ResizeOverlayLayout.ts": __vite_glob_0_25$1,
38796
- "./commands/ResizeRow.ts": __vite_glob_0_26$1,
38797
- "./commands/Set2DTable.ts": __vite_glob_0_27$1,
38798
- "./commands/SetAlign.ts": __vite_glob_0_28$1,
38799
- "./commands/SetBold.ts": __vite_glob_0_29$1,
38800
- "./commands/SetBounded.ts": __vite_glob_0_30$1,
38801
- "./commands/SetBoundedItem.ts": __vite_glob_0_31$1,
38802
- "./commands/SetCheckTable.ts": __vite_glob_0_32$1,
38803
- "./commands/SetColor.ts": __vite_glob_0_33$1,
38804
- "./commands/SetDataGroup2D.ts": __vite_glob_0_34$1,
38805
- "./commands/SetFont.ts": __vite_glob_0_35$1,
38806
- "./commands/SetFontSize.ts": __vite_glob_0_36$1,
38807
- "./commands/SetHeaderFooterConfig.ts": __vite_glob_0_37$1,
38808
- "./commands/SetHighlight.ts": __vite_glob_0_38$1,
38809
- "./commands/SetItalic.ts": __vite_glob_0_39$1,
38810
- "./commands/SetOrient.ts": __vite_glob_0_40$1,
38811
- "./commands/SetPadding.ts": __vite_glob_0_41$1,
38812
- "./commands/SetRepeating.ts": __vite_glob_0_42$1,
38813
- "./commands/SetStrike.ts": __vite_glob_0_43,
38814
- "./commands/SetSubTableHeader.ts": __vite_glob_0_44,
38815
- "./commands/SetTableHeader.ts": __vite_glob_0_45,
38816
- "./commands/SetUnderline.ts": __vite_glob_0_46,
38817
- "./commands/Snapshot.ts": __vite_glob_0_47,
38818
- "./commands/UnmergeCells.ts": __vite_glob_0_48
38819
- });
38820
- function toCamelCase(pascalCase) {
38821
- return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
38822
- }
38823
- function getClassNameFromPath(path2) {
38824
- return path2.split("/").pop()?.replace(".ts", "") ?? "";
38825
- }
38826
- function buildCommandMap() {
38827
- const map2 = {};
38828
- Object.entries(commandModules).forEach(([path2, module2]) => {
38829
- const expectedClassName = getClassNameFromPath(path2);
38830
- const CommandClass = module2[expectedClassName];
38831
- if (CommandClass && typeof CommandClass === "function") {
38832
- const commandName = toCamelCase(expectedClassName);
38833
- map2[commandName] = CommandClass;
38834
- }
38835
- });
38836
- return map2;
38837
- }
38838
- class CommandManager {
38839
- registry = /* @__PURE__ */ new Map();
38840
- doc;
38841
- undoStack = [];
38842
- redoStack = [];
38843
- composition;
38844
- // 命令注册表 - 通过动态导入构建
38845
- static COMMAND_MAP = buildCommandMap();
38846
- constructor(doc) {
38847
- this.doc = doc;
38848
- Object.entries(CommandManager.COMMAND_MAP).forEach(([name, CommandClass]) => {
38849
- this.register(name, CommandClass);
38850
- });
38851
- }
38852
- register(name, CommandClass) {
38853
- this.registry.set(name, CommandClass);
38854
- }
38855
- async execute(name, payload) {
38856
- const CommandClass = this.registry.get(name);
38857
- if (!CommandClass) throw new Error(`Unknown command: ${name}`);
38858
- const cmd = new CommandClass(this.doc, payload);
38859
- const result = await cmd.do();
38860
- result && this.updateCursor(result);
38861
- payload?.doCallback && this.runCallback(payload.doCallback, result, cmd.output);
38862
- if (cmd.isTerminated) return;
38863
- this.undoStack.push(cmd);
38864
- this.redoStack.length = 0;
38865
- }
38866
- async undo() {
38867
- const cmd = this.undoStack.pop();
38868
- if (!cmd) return;
38869
- const result = await cmd.undo();
38870
- result && this.updateCursor(result);
38871
- cmd.payload?.undoCallback && this.runCallback(cmd.payload?.undoCallback, result);
38872
- this.redoStack.push(cmd);
38873
- }
38874
- async redo() {
38875
- const cmd = this.redoStack.pop();
38876
- if (!cmd) return;
38877
- const result = await cmd.do();
38878
- result && this.updateCursor(result);
38879
- cmd.payload?.doCallback && this.runCallback(cmd.payload?.doCallback, result);
38880
- this.undoStack.push(cmd);
38881
- }
38882
- compositionStart(text) {
38883
- }
38884
- compositionUpdate(text) {
38885
- }
38886
- compositionEnd(text) {
38887
- this.doc.commandManager.execute(CommandType.insertText, {
38888
- text
38889
- });
38890
- }
38891
- updateCursor(data) {
38892
- if (!data) return;
38893
- if (Array.isArray(data)) {
38894
- const [startData, endData] = data;
38895
- this.doc.eventManager.cursorController?.resolveCursorRange(startData, endData);
38896
- } else {
38897
- this.doc.eventManager.cursorController?.resolveCursorAtNode?.(data);
38898
- }
38899
- }
38900
- runCallback(callback, data, output) {
38901
- if (typeof callback === "function") {
38902
- callback(data, output);
38903
- }
38904
- }
38905
- }
38906
- class LayoutNode {
38907
- /** 唯一标识符 */
38908
- id;
38909
- /** 组件类型 */
38910
- component;
38911
- /** 所属文档 */
38912
- doc;
38913
- /** 父节点 */
38914
- parent;
38915
- /** 在父容器中的相对 X 坐标 */
38916
- x = 0;
38917
- /** 在父容器中的相对 Y 坐标 */
38918
- y = 0;
38919
- /** 布局后的绝对 X 坐标 */
38920
- layoutX = 0;
38921
- /** 布局后的绝对 Y 坐标 */
38922
- layoutY = 0;
38923
- modelRef;
38924
- // valuePath?: string;
38925
- /** 宽度 */
38926
- _width = 0;
38927
- /** 高度 */
38928
- _height = 0;
38929
- constructor(options) {
38930
- this.id = options.id ?? uuid();
38931
- this.doc = options.doc;
38932
- if (options.x !== void 0) this.x = options.x;
38933
- if (options.y !== void 0) this.y = options.y;
38934
- if (options.width !== void 0) this._width = options.width;
38935
- if (options.height !== void 0) this._height = options.height;
38936
- this.modelRef = options.modelRef;
38937
- this.modelRef && this.doc.layoutMapper.recordModelSplit(this.modelRef?.id, this.id);
38938
- }
38939
- get width() {
38940
- return this._width;
38941
- }
38942
- get height() {
38943
- return this._height;
38944
- }
38945
- set width(value) {
38946
- this._width = value;
38947
- }
38948
- set height(value) {
38949
- this._height = value;
38950
- }
38951
- get page() {
38952
- return this.getPage();
38953
- }
38954
- get isWidgetRun() {
38955
- return "widgetMeta" in this && !!this.widgetMeta;
38956
- }
38957
- get isPageWidgetRun() {
38958
- return "pageWidgetMeta" in this && !!this.pageWidgetMeta;
38959
- }
38960
- get isSubRenderer() {
38961
- return "subRenderer" in this && !!this.subRenderer;
38962
- }
38963
- get isPlaceholderRun() {
38964
- return "isPlaceholder" in this && this.isPlaceholder === true;
38965
- }
38966
39109
  /**
38967
- * 获取实例对应的 page
38968
- * tips 表格第一次初始化无 page,target 可能为空
39110
+ *
39111
+ * @param startCell
39112
+ * @param endCell
38969
39113
  * @returns
38970
39114
  */
38971
- getPage() {
38972
- let target = this;
38973
- while (target && target.constructor.name !== "Page") {
38974
- target = target.parent;
38975
- }
38976
- return target;
38977
- }
38978
- getOverlayLayout() {
38979
- let target = this;
38980
- while (target && target.constructor.name !== "OverlayLayout") {
38981
- target = target.parent;
39115
+ getBoundedRegion(startCell, endCell) {
39116
+ const region = this.getRegion(startCell, endCell);
39117
+ if (!region) {
39118
+ GctMessage.warning("选区超出子表范围");
39119
+ throw new Error("Cells are not in the same region");
38982
39120
  }
38983
- return target;
38984
- }
38985
- /**
38986
- * 布局方法:计算并设置节点的绝对位置
38987
- * @param x 绝对 X 坐标
38988
- * @param y 绝对 Y 坐标
38989
- */
38990
- layout(x2 = 0, y2 = 0) {
38991
- this.layoutX = x2;
38992
- this.layoutY = y2;
38993
- }
38994
- }
38995
- class LayoutGroup extends LayoutNode {
38996
- /** 子节点列表 */
38997
- children = [];
38998
- _padding = [0, 0, 0, 0];
38999
- constructor(options) {
39000
- super(options);
39001
- }
39002
- get padding() {
39003
- return this._padding ?? [0, 0, 0, 0];
39004
- }
39005
- get pt() {
39006
- return this.padding[0];
39007
- }
39008
- get pr() {
39009
- return this.padding[1];
39010
- }
39011
- get pb() {
39012
- return this.padding[2];
39013
- }
39014
- get pl() {
39015
- return this.padding[3];
39016
- }
39017
- /**
39018
- * 添加子节点
39019
- * @param child 要添加的子节点
39020
- */
39021
- addChild(child) {
39022
- this.children.push(child);
39023
- child.parent = this;
39024
- }
39025
- /**
39026
- * 在指定位置插入子节点
39027
- * @param index 插入位置
39028
- * @param child 要插入的子节点
39029
- */
39030
- insertChild(index2, child) {
39031
- this.children.splice(index2, 0, child);
39032
- child.parent = this;
39033
- }
39034
- /**
39035
- * 批量添加子节点
39036
- * @param children 要添加的子节点数组
39037
- */
39038
- addChildren(children) {
39039
- children.forEach((child) => {
39040
- this.children.push(child);
39041
- child.parent = this;
39042
- });
39043
- }
39044
- /**
39045
- * 在指定位置批量插入子节点
39046
- * @param index 插入位置
39047
- * @param children 要插入的子节点数组
39048
- */
39049
- insertChildren(index2, children) {
39050
- this.children.splice(index2, 0, ...children);
39051
- children.forEach((child) => {
39052
- child.parent = this;
39053
- });
39121
+ return region.type === "bounded" ? region : void 0;
39054
39122
  }
39055
39123
  /**
39056
- * 移除子节点
39057
- * @param child 要移除的子节点
39058
- * @returns 是否成功移除
39124
+ * 获取公共区域
39125
+ * @param startCell
39126
+ * @param endCell
39127
+ * @returns
39059
39128
  */
39060
- removeChild(child) {
39061
- const index2 = this.children.indexOf(child);
39062
- if (index2 !== -1) {
39063
- this.children.splice(index2, 1);
39064
- child.parent = void 0;
39065
- return true;
39129
+ getRegion(startCell, endCell) {
39130
+ if (startCell === endCell) {
39131
+ return startCell.getRegion();
39066
39132
  }
39067
- return false;
39068
- }
39069
- /**
39070
- * 根据索引移除子节点
39071
- * @param index 子节点索引
39072
- * @returns 被移除的子节点,如果索引无效则返回 undefined
39073
- */
39074
- removeChildAt(index2) {
39075
- if (index2 >= 0 && index2 < this.children.length) {
39076
- const child = this.children.splice(index2, 1)[0];
39077
- if (child) {
39078
- child.parent = void 0;
39079
- }
39080
- return child;
39133
+ const startRegion = startCell.getRegion();
39134
+ const endRegion = endCell.getRegion();
39135
+ if (startRegion && endRegion && startRegion === endRegion) {
39136
+ return startRegion;
39081
39137
  }
39082
- return void 0;
39138
+ return;
39083
39139
  }
39084
- /**
39085
- * 获取所有子节点(只读)
39086
- */
39087
- getChildren() {
39088
- return this.children;
39140
+ }
39141
+ const __vite_glob_0_31$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39142
+ __proto__: null,
39143
+ SetBoundedItem
39144
+ }, Symbol.toStringTag, { value: "Module" }));
39145
+ class SetCheckTable extends CommandBase {
39146
+ constructor(doc, payload) {
39147
+ super(doc, payload);
39089
39148
  }
39090
- /**
39091
- * 获取指定索引的子节点
39092
- * @param index 子节点索引
39093
- */
39094
- getChildAt(index2) {
39095
- return this.children[index2];
39149
+ async execute() {
39150
+ const cursor = this.doc.cursorManager;
39151
+ if (cursor.isCollapsed()) return null;
39152
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39153
+ if (mode !== SelectionMode.Tds) return null;
39154
+ if (models.length === 0) return null;
39155
+ const startCell = models[0].model;
39156
+ const endCell = models[models.length - 1].model;
39157
+ const start = {
39158
+ row: startCell.parent?.getCurrentIndex(),
39159
+ col: startCell.getCurrentIndex()
39160
+ };
39161
+ const end = {
39162
+ row: endCell.parent?.getCurrentIndex(),
39163
+ col: endCell.getCurrentIndex()
39164
+ };
39165
+ this.output = startCell.table.setCheckTable({
39166
+ start,
39167
+ end,
39168
+ name: this.payload.name,
39169
+ valuePath: this.payload.valuePath
39170
+ });
39171
+ return null;
39096
39172
  }
39097
- /**
39098
- * 获取子节点数量
39099
- */
39100
- getChildCount() {
39101
- return this.children.length;
39173
+ }
39174
+ const __vite_glob_0_32$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39175
+ __proto__: null,
39176
+ SetCheckTable
39177
+ }, Symbol.toStringTag, { value: "Module" }));
39178
+ class SetColor extends SetStyleBase {
39179
+ constructor(doc, payload) {
39180
+ super(doc, payload);
39102
39181
  }
39103
- /**
39104
- * 获取第一个子节点
39105
- */
39106
- getFirstChild() {
39107
- return this.children[0] ?? null;
39182
+ applyStyle(run) {
39183
+ run.setColor(this.payload.color);
39108
39184
  }
39109
- /**
39110
- * 获取最后一个子节点
39111
- */
39112
- getLastChild() {
39113
- return this.children[this.children.length - 1] ?? null;
39185
+ }
39186
+ const __vite_glob_0_33$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39187
+ __proto__: null,
39188
+ SetColor
39189
+ }, Symbol.toStringTag, { value: "Module" }));
39190
+ class SetDataGroup2D extends CommandBase {
39191
+ constructor(doc, payload) {
39192
+ super(doc, payload);
39114
39193
  }
39115
- /**
39116
- * 清空所有子节点
39117
- */
39118
- clearChildren() {
39119
- this.children.forEach((child) => {
39120
- child.parent = void 0;
39194
+ async execute() {
39195
+ const cursor = this.doc.cursorManager;
39196
+ if (cursor.isCollapsed()) return null;
39197
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39198
+ if (mode !== SelectionMode.Tds) return null;
39199
+ if (models.length === 0) return null;
39200
+ const startCell = models[0].model;
39201
+ const endCell = models[models.length - 1].model;
39202
+ const cellList = [...models.map((m) => m.model)];
39203
+ const start = {
39204
+ row: startCell.parent?.getCurrentIndex(),
39205
+ col: startCell.getCurrentIndex()
39206
+ };
39207
+ const end = {
39208
+ row: endCell.parent?.getCurrentIndex(),
39209
+ col: endCell.getCurrentIndex()
39210
+ };
39211
+ const subTableRegion = this.getSubTableRegion(cellList);
39212
+ if (!subTableRegion) {
39213
+ throw new Error("Cells are not in a sub table region supporting data-group-2d");
39214
+ }
39215
+ this.output = subTableRegion.setItemRegion({
39216
+ start,
39217
+ end
39121
39218
  });
39122
- this.children = [];
39219
+ return null;
39123
39220
  }
39124
39221
  /**
39125
- * 查找子节点索引
39126
- * @param child 要查找的子节点
39127
- * @returns 子节点索引,如果不存在则返回 -1
39222
+ *
39223
+ * @param cellList
39224
+ * @returns
39128
39225
  */
39129
- indexOfChild(child) {
39130
- return this.children.indexOf(child);
39226
+ getSubTableRegion(cellList) {
39227
+ let region;
39228
+ cellList.some((cell) => {
39229
+ const r = cell.getRegion();
39230
+ if (r && ["check-table", "2d-table"].includes(r.type)) {
39231
+ region = r;
39232
+ return true;
39233
+ }
39234
+ });
39235
+ if (!region) {
39236
+ throw new Error("No region found");
39237
+ }
39238
+ return region;
39131
39239
  }
39132
- /**
39133
- * 检查是否包含子节点
39134
- * @param child 要检查的子节点
39135
- */
39136
- hasChild(child) {
39137
- return this.children.includes(child);
39240
+ }
39241
+ const __vite_glob_0_34$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39242
+ __proto__: null,
39243
+ SetDataGroup2D
39244
+ }, Symbol.toStringTag, { value: "Module" }));
39245
+ class SetFont extends SetStyleBase {
39246
+ constructor(doc, payload) {
39247
+ super(doc, payload);
39138
39248
  }
39139
- /**
39140
- * 遍历所有子节点
39141
- * @param callback 遍历回调函数
39142
- */
39143
- forEachChild(callback) {
39144
- this.children.forEach(callback);
39249
+ applyStyle(run) {
39250
+ run.setFont(this.payload.fontFamily);
39145
39251
  }
39146
- /**
39147
- * 查找满足条件的子节点
39148
- * @param predicate 查找条件
39149
- * @returns 第一个满足条件的子节点,如果没有则返回 undefined
39150
- */
39151
- findChild(predicate) {
39152
- return this.children.find(predicate);
39252
+ }
39253
+ const __vite_glob_0_35$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39254
+ __proto__: null,
39255
+ SetFont
39256
+ }, Symbol.toStringTag, { value: "Module" }));
39257
+ class SetFontSize extends SetStyleBase {
39258
+ constructor(doc, payload) {
39259
+ super(doc, payload);
39260
+ this.needsCalculatePostCommandContext = true;
39153
39261
  }
39154
- /**
39155
- * 过滤子节点
39156
- * @param predicate 过滤条件
39157
- * @returns 满足条件的子节点数组
39158
- */
39159
- filterChildren(predicate) {
39160
- return this.children.filter(predicate);
39262
+ applyStyle(run) {
39263
+ run.setFontSize(this.payload.fontSize * 2);
39161
39264
  }
39162
39265
  }
39163
- class BandContainer extends LayoutGroup {
39164
- type;
39165
- constructor(options) {
39166
- super(options);
39167
- this.type = options.type;
39168
- if (options.type === "header") {
39169
- this.component = BuiltinComponentTypeConst.Header;
39170
- } else if (options.type === "footer") {
39171
- this.component = BuiltinComponentTypeConst.Footer;
39266
+ const __vite_glob_0_36$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39267
+ __proto__: null,
39268
+ SetFontSize
39269
+ }, Symbol.toStringTag, { value: "Module" }));
39270
+ class SetHeaderFooterConfig extends CommandBase {
39271
+ constructor(doc, payload) {
39272
+ super(doc, payload);
39273
+ }
39274
+ async execute() {
39275
+ const { headerMargin, footerMargin, titlePg, evenAndOddHeaders } = this.payload;
39276
+ this.doc?.eventManager.cursorController.clearCursor();
39277
+ const sections = (this.doc.model?.document.body.children ?? []).filter(
39278
+ (item) => item.name === "w:secPr"
39279
+ );
39280
+ if (sections.length === 0) {
39281
+ this.isTerminated = true;
39282
+ return null;
39172
39283
  }
39173
- this.parent = options.page;
39284
+ for (const section of sections) {
39285
+ if (headerMargin !== void 0) {
39286
+ section.setHeaderMargin(headerMargin);
39287
+ }
39288
+ if (footerMargin !== void 0) {
39289
+ section.setFooterMargin(footerMargin);
39290
+ }
39291
+ if (titlePg !== void 0) {
39292
+ section.setTitlePg(titlePg);
39293
+ }
39294
+ }
39295
+ if (evenAndOddHeaders !== void 0) {
39296
+ this.doc.model?.settings.setEvenAndOddHeaders(evenAndOddHeaders);
39297
+ }
39298
+ return null;
39174
39299
  }
39175
- get page() {
39176
- return this.parent;
39300
+ }
39301
+ const __vite_glob_0_37$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39302
+ __proto__: null,
39303
+ SetHeaderFooterConfig
39304
+ }, Symbol.toStringTag, { value: "Module" }));
39305
+ class SetHighlight extends SetStyleBase {
39306
+ constructor(doc, payload) {
39307
+ super(doc, payload);
39177
39308
  }
39178
- /**
39179
- * 宽度 = 页面正文宽度
39180
- */
39181
- get contentMaxWidth() {
39182
- return this.page.contentMaxWidth;
39309
+ applyStyle(run) {
39310
+ run.setHighlight(this.payload.highlight);
39183
39311
  }
39184
- /**
39185
- * 页眉页脚不限制高度
39186
- */
39187
- get contentMaxHeight() {
39188
- return Number.POSITIVE_INFINITY;
39312
+ }
39313
+ const __vite_glob_0_38$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39314
+ __proto__: null,
39315
+ SetHighlight
39316
+ }, Symbol.toStringTag, { value: "Module" }));
39317
+ class SetItalic extends SetStyleBase {
39318
+ constructor(doc, payload) {
39319
+ super(doc, payload);
39189
39320
  }
39190
- /** 获取页眉页脚内容高度 */
39191
- getContentHeight() {
39192
- return this.getChildren().reduce((sum, child) => sum + child.height, 0);
39321
+ applyStyle(run) {
39322
+ run.setItalic(this.payload?.italic ?? true);
39193
39323
  }
39194
- /** 当前真正推开正文的 inset 高度 */
39195
- get actualInsetHeight() {
39196
- return this.type === "header" ? this.page.pt : this.page.pb;
39324
+ }
39325
+ const __vite_glob_0_39$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39326
+ __proto__: null,
39327
+ SetItalic
39328
+ }, Symbol.toStringTag, { value: "Module" }));
39329
+ class SetOrient extends CommandBase {
39330
+ constructor(doc, payload) {
39331
+ super(doc, payload);
39197
39332
  }
39198
- /** 获取剩余空间 */
39199
- getRemainingSize() {
39200
- return Number.POSITIVE_INFINITY;
39333
+ async execute() {
39334
+ const { orient, serRefId } = this.payload;
39335
+ if (!["portrait", "landscape"].includes(orient)) {
39336
+ throw new Error(`Invalid orientation: ${orient}`);
39337
+ }
39338
+ if (!serRefId) {
39339
+ this.isTerminated = true;
39340
+ return null;
39341
+ }
39342
+ const section = this.doc.model?.document.body.children.find(
39343
+ (item) => item.id === serRefId
39344
+ );
39345
+ if (!section) {
39346
+ this.isTerminated = true;
39347
+ return null;
39348
+ }
39349
+ section.setOrient(orient);
39350
+ return null;
39201
39351
  }
39202
- layout(x2, y2) {
39203
- this.layoutX = x2;
39204
- this.layoutY = y2;
39205
- this.forEachChild((child) => {
39206
- child.layout(this.layoutX + child.x, this.layoutY + child.y);
39207
- });
39352
+ }
39353
+ const __vite_glob_0_40$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39354
+ __proto__: null,
39355
+ SetOrient
39356
+ }, Symbol.toStringTag, { value: "Module" }));
39357
+ class SetPadding extends CommandBase {
39358
+ constructor(doc, payload) {
39359
+ super(doc, payload);
39208
39360
  }
39209
- /** 距离页面边缘的安全间距(页眉/页脚与页面边缘的距离) */
39210
- get spacingFromEdge() {
39211
- return this.type === "header" ? this.page.section.headerSpacing : this.page.section.footerSpacing;
39361
+ async execute() {
39362
+ const { padding, serRefId } = this.payload;
39363
+ if (!serRefId) {
39364
+ this.isTerminated = true;
39365
+ return null;
39366
+ }
39367
+ const section = this.doc.model?.document.body.children.find(
39368
+ (item) => item.id === serRefId
39369
+ );
39370
+ if (!section) {
39371
+ this.isTerminated = true;
39372
+ return null;
39373
+ }
39374
+ const [top, right, bottom, left] = padding;
39375
+ section.setMargins(top, bottom, left, right);
39376
+ return null;
39212
39377
  }
39213
- /** 页眉/页脚与正文的分界线 Y 坐标(相对整页) */
39214
- get guideLineY() {
39215
- return this.type === "header" ? this.page.pt : this.page.height - this.page.pb;
39378
+ }
39379
+ const __vite_glob_0_41$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39380
+ __proto__: null,
39381
+ SetPadding
39382
+ }, Symbol.toStringTag, { value: "Module" }));
39383
+ class SetRepeating extends CommandBase {
39384
+ constructor(doc, payload) {
39385
+ super(doc, payload);
39216
39386
  }
39217
- /** 页眉/页脚占位矩形(用于辅助线渲染),相对整页 */
39218
- get guideRect() {
39219
- const y2 = this.type === "header" ? this.spacingFromEdge : this.page.height - this.page.pb;
39220
- const rawHeight = this.type === "header" ? this.page.pt - this.spacingFromEdge : this.page.pb - this.spacingFromEdge;
39221
- const height = Math.max(0, rawHeight);
39222
- return {
39223
- x: this.page.pl,
39224
- y: y2,
39225
- width: this.contentMaxWidth,
39226
- height
39387
+ async execute() {
39388
+ const cursor = this.doc.cursorManager;
39389
+ if (cursor.isCollapsed()) return null;
39390
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39391
+ if (mode !== SelectionMode.Tds) return null;
39392
+ if (models.length === 0) return null;
39393
+ const startCell = models[0].model;
39394
+ const endCell = models[models.length - 1].model;
39395
+ const start = {
39396
+ row: startCell.parent?.getCurrentIndex(),
39397
+ col: startCell.getCurrentIndex()
39227
39398
  };
39228
- }
39229
- /** 双击开启/关闭页眉页脚编辑的命中区域(相对整页) */
39230
- get hitAreaRect() {
39231
- const isHeader = this.type === "header";
39232
- return {
39233
- x: this.page.pl,
39234
- y: isHeader ? 0 : this.page.height - this.page.pb,
39235
- width: this.contentMaxWidth,
39236
- height: isHeader ? this.page.pt : this.page.pb
39399
+ const end = {
39400
+ row: endCell.parent?.getCurrentIndex(),
39401
+ col: endCell.getCurrentIndex()
39237
39402
  };
39403
+ this.output = startCell.table.setRepeating({
39404
+ start,
39405
+ end,
39406
+ name: this.payload.name,
39407
+ valuePath: this.payload.valuePath
39408
+ });
39409
+ return null;
39238
39410
  }
39239
39411
  }
39240
- class OverlayLayout extends LayoutGroup {
39241
- component = BuiltinComponentTypeConst.OverlayLayout;
39242
- constructor(options) {
39243
- super(options);
39244
- }
39245
- /**
39246
- * 获取可用宽度
39247
- */
39248
- get contentMaxWidth() {
39249
- return this.width;
39412
+ const __vite_glob_0_42$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39413
+ __proto__: null,
39414
+ SetRepeating
39415
+ }, Symbol.toStringTag, { value: "Module" }));
39416
+ class SetStrike extends SetStyleBase {
39417
+ constructor(doc, payload) {
39418
+ super(doc, payload);
39250
39419
  }
39251
- /**
39252
- * 悬浮层不参与文档流布局,但是要设置 layoutX和 layoutY
39253
- */
39254
- layout() {
39255
- this.layoutX = this.x;
39256
- this.layoutY = this.y;
39420
+ applyStyle(run) {
39421
+ run.setStrike(this.payload.strike);
39257
39422
  }
39258
39423
  }
39259
- class OverlayContainer extends LayoutGroup {
39260
- component = BuiltinComponentTypeConst.OverlayContainer;
39261
- parent;
39262
- constructor(options) {
39263
- super(options);
39264
- this.parent = options.page;
39424
+ const __vite_glob_0_43 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39425
+ __proto__: null,
39426
+ SetStrike
39427
+ }, Symbol.toStringTag, { value: "Module" }));
39428
+ class SetSubTableHeader extends CommandBase {
39429
+ constructor(doc, payload) {
39430
+ super(doc, payload);
39265
39431
  }
39266
- get page() {
39267
- return this.parent;
39432
+ async execute() {
39433
+ const cursor = this.doc.cursorManager;
39434
+ const { name } = this.payload;
39435
+ if (cursor.isCollapsed()) return null;
39436
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39437
+ if (mode !== SelectionMode.Tds) return null;
39438
+ if (models.length === 0) return null;
39439
+ const startCell = models[0].model;
39440
+ const endCell = models[models.length - 1].model;
39441
+ const start = {
39442
+ row: startCell.parent?.getCurrentIndex(),
39443
+ col: startCell.getCurrentIndex()
39444
+ };
39445
+ const end = {
39446
+ row: endCell.parent?.getCurrentIndex(),
39447
+ col: endCell.getCurrentIndex()
39448
+ };
39449
+ const region = this.getSubTableRegion(endCell.table, end.row);
39450
+ if (!region) {
39451
+ GctMessage.warning("没有找到对应子表");
39452
+ return null;
39453
+ }
39454
+ const crossRegion = startCell.table.findCrossRegion({ start, end });
39455
+ crossRegion && startCell.table.deleteRegionById(crossRegion.id);
39456
+ this.output = startCell.table.setSubTableHeader({
39457
+ start,
39458
+ end,
39459
+ name,
39460
+ subTableId: region.id
39461
+ });
39462
+ return null;
39268
39463
  }
39269
- get width() {
39270
- return this.page.width;
39464
+ getSubTableRegion(table, rowIndex) {
39465
+ return table.regions.find((region) => {
39466
+ return region.start.row === rowIndex + 1 && ["repeating", "bounded", "check-table", "2d-table"].includes(region.type);
39467
+ });
39271
39468
  }
39272
- get height() {
39273
- return this.page.height;
39469
+ }
39470
+ const __vite_glob_0_44 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39471
+ __proto__: null,
39472
+ SetSubTableHeader
39473
+ }, Symbol.toStringTag, { value: "Module" }));
39474
+ class SetTableHeader extends CommandBase {
39475
+ constructor(doc, payload) {
39476
+ super(doc, payload);
39274
39477
  }
39275
- createOverlayLayout({
39276
- x: x2,
39277
- y: y2,
39278
- width,
39279
- height,
39280
- modelRef
39281
- }) {
39282
- const newOverlayLayout = new OverlayLayout({
39283
- doc: this.doc,
39284
- x: x2,
39285
- y: y2,
39286
- width,
39287
- height,
39288
- modelRef
39478
+ async execute() {
39479
+ const cursor = this.doc.cursorManager;
39480
+ const { name } = this.payload;
39481
+ if (cursor.isCollapsed()) return null;
39482
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39483
+ if (mode !== SelectionMode.Tds) return null;
39484
+ if (models.length === 0) return null;
39485
+ const startCell = models[0].model;
39486
+ const endCell = models[models.length - 1].model;
39487
+ const start = {
39488
+ row: startCell.parent?.getCurrentIndex(),
39489
+ col: startCell.getCurrentIndex()
39490
+ };
39491
+ const end = {
39492
+ row: endCell.parent?.getCurrentIndex(),
39493
+ col: endCell.getCurrentIndex()
39494
+ };
39495
+ this.output = startCell.table.setTableHeader({
39496
+ start,
39497
+ end,
39498
+ name
39289
39499
  });
39290
- newOverlayLayout.layout();
39291
- this.addChild(newOverlayLayout);
39292
- return newOverlayLayout;
39293
- }
39294
- /**
39295
- * 悬浮层不参与文档流布局
39296
- */
39297
- layout() {
39500
+ return null;
39298
39501
  }
39299
39502
  }
39300
- class TextUtil {
39301
- /** 字体度量缓存限制 */
39302
- static FONT_METRICS_CACHE_LIMIT = 50;
39303
- /** 布局大小缓存限制 */
39304
- static LAYOUT_SIZE_CACHE_LIMIT = 100;
39305
- /** 东亚常见全宽字符块 */
39306
- static EAST_ASIAN_FULL_WIDTH_REGEX = /[\u3000-\u303F\u3040-\u30FF\u31F0-\u31FF\uFF01-\uFF60\uFFE0-\uFFE6]/u;
39307
- /** 表单/文档中常见的几何符号 */
39308
- static FULL_WIDTH_SYMBOL_REGEX = /[□■○●△▲▽▼◇◆◎※]/u;
39309
- static fontMetricsCache = /* @__PURE__ */ new Map();
39310
- static layoutSizeCache = /* @__PURE__ */ new Map();
39311
- /**
39312
- * 验证中文字符
39313
- * @param char
39314
- * @returns
39315
- */
39316
- static isHanChar(char) {
39317
- return new RegExp("\\p{Script=Han}", "u").test(char);
39503
+ const __vite_glob_0_45 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39504
+ __proto__: null,
39505
+ SetTableHeader
39506
+ }, Symbol.toStringTag, { value: "Module" }));
39507
+ class SetUnderline extends SetStyleBase {
39508
+ constructor(doc, payload) {
39509
+ super(doc, payload);
39318
39510
  }
39319
- /**
39320
- * 验证是否为应按 1em 处理的全宽单字符
39321
- * @param char
39322
- * @returns
39323
- */
39324
- static isFullWidthChar(char) {
39325
- if ([...char].length !== 1) {
39326
- return false;
39327
- }
39328
- return this.isHanChar(char) || this.EAST_ASIAN_FULL_WIDTH_REGEX.test(char) || this.FULL_WIDTH_SYMBOL_REGEX.test(char);
39511
+ applyStyle(run) {
39512
+ run.setUnderline(this.payload?.underline ?? "single");
39329
39513
  }
39330
- /**
39331
- * 生成文本度量缓存键
39332
- * @param payload
39333
- * @param includeText
39334
- * @returns
39335
- */
39336
- static getMeasureCacheKey(payload, includeText = true) {
39337
- return JSON.stringify({
39338
- text: includeText ? payload.text ?? "" : "",
39339
- fontSize: payload.fontSize ?? "",
39340
- fontFamily: payload.fontFamily ?? "",
39341
- fontStyle: payload.fontStyle ?? "",
39342
- fontVariant: payload.fontVariant ?? "",
39343
- lineHeight: payload.lineHeight ?? "",
39344
- padding: payload.padding ?? "",
39345
- letterSpacing: payload.letterSpacing ?? ""
39346
- });
39514
+ }
39515
+ const __vite_glob_0_46 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39516
+ __proto__: null,
39517
+ SetUnderline
39518
+ }, Symbol.toStringTag, { value: "Module" }));
39519
+ class Snapshot extends CommandBase {
39520
+ constructor(doc, payload) {
39521
+ super(doc, payload);
39347
39522
  }
39348
- /**
39349
- * 计算度量 - 基于 JSON 序列化的缓存(LRU)
39350
- * 将最终的 config 序列化为缓存键,相同配置直接返回缓存结果
39351
- * 最近使用的项会被移到末尾,超限时删除最古老的项
39352
- * @param payload
39353
- * @returns
39354
- */
39355
- static getFontMetrics(payload) {
39356
- const targetText = "Hg";
39357
- const config = Object.assign({}, payload, {
39358
- text: targetText,
39359
- lineHeight: 1
39360
- });
39361
- const cacheKey = this.getMeasureCacheKey(config, false);
39362
- if (this.fontMetricsCache.has(cacheKey)) {
39363
- const result2 = this.fontMetricsCache.get(cacheKey);
39364
- this.fontMetricsCache.delete(cacheKey);
39365
- this.fontMetricsCache.set(cacheKey, result2);
39366
- return result2;
39367
- }
39368
- const text = new Konva.Text(config);
39369
- const size = text.measureSize(targetText);
39370
- const result = {
39371
- ascent: size.actualBoundingBoxAscent,
39372
- descent: size.actualBoundingBoxDescent
39373
- };
39374
- if (this.fontMetricsCache.size >= this.FONT_METRICS_CACHE_LIMIT) {
39375
- const firstKey = this.fontMetricsCache.keys().next().value;
39376
- this.fontMetricsCache.delete(firstKey);
39377
- }
39378
- this.fontMetricsCache.set(cacheKey, result);
39379
- return result;
39523
+ async execute() {
39524
+ return null;
39380
39525
  }
39381
- /**
39382
- * 计算单个字符布局大小 - 基于 JSON 序列化的缓存(LRU)
39383
- * @param payload
39384
- * @returns
39385
- */
39386
- static getLayoutSize(payload) {
39387
- if (this.isFullWidthChar(payload.text ?? "")) {
39388
- const fontSize2 = payload.fontSize ?? 0;
39526
+ }
39527
+ const __vite_glob_0_47 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39528
+ __proto__: null,
39529
+ Snapshot
39530
+ }, Symbol.toStringTag, { value: "Module" }));
39531
+ class UnmergeCells extends CommandBase {
39532
+ constructor(doc, payload) {
39533
+ super(doc, payload);
39534
+ }
39535
+ async execute() {
39536
+ const cursor = this.doc.cursorManager;
39537
+ if (cursor.isCollapsed()) return;
39538
+ const { mode, models } = CommandBase.getSelectionResult(this.doc, cursor.getSelection());
39539
+ if (mode !== SelectionMode.Tds) return;
39540
+ if (models.length === 0) return;
39541
+ const roots = models.map(({ model }) => model).filter((cell) => cell.id === cell.mergeId && !cell.mergeFromId);
39542
+ if (roots.length === 0) return null;
39543
+ const table = roots[0]?.table;
39544
+ if (!table) return null;
39545
+ table.runConsistencyMutation({
39546
+ mutate: () => {
39547
+ roots.forEach((cell) => {
39548
+ cell.unmerge({ skipConsistency: true });
39549
+ });
39550
+ }
39551
+ });
39552
+ const mapper = this.doc.layoutMapper;
39553
+ const normalized = this.doc.cursorManager.normalizeRange(cursor.getSelection());
39554
+ const start = mapper.getLayoutNodeById(normalized.rangeStart.nodeId);
39555
+ if (start?.isPlaceholderRun) {
39556
+ const wp = mapper.getModelNodeById(start.parent.modelRef.id);
39389
39557
  return {
39390
- width: fontSize2,
39391
- height: fontSize2
39558
+ wp,
39559
+ pos: -1,
39560
+ side: "after"
39392
39561
  };
39393
39562
  }
39394
- const config = Object.assign({}, payload, {
39395
- lineHeight: 1
39396
- });
39397
- const cacheKey = this.getMeasureCacheKey(config);
39398
- if (this.layoutSizeCache.has(cacheKey)) {
39399
- const result2 = this.layoutSizeCache.get(cacheKey);
39400
- this.layoutSizeCache.delete(cacheKey);
39401
- this.layoutSizeCache.set(cacheKey, result2);
39402
- return result2;
39403
- }
39404
- const text = new Konva.Text(config);
39405
- const result = {
39406
- width: text.width(),
39407
- height: text.height()
39408
- };
39409
- if (this.layoutSizeCache.size >= this.LAYOUT_SIZE_CACHE_LIMIT) {
39410
- const firstKey = this.layoutSizeCache.keys().next().value;
39411
- this.layoutSizeCache.delete(firstKey);
39412
- }
39413
- this.layoutSizeCache.set(cacheKey, result);
39414
- return result;
39415
- }
39416
- /**
39417
- * 清除度量结果缓存
39418
- */
39419
- static clearMeasureCache() {
39420
- this.fontMetricsCache.clear();
39421
- this.layoutSizeCache.clear();
39422
- }
39423
- /**
39424
- * 获取缓存大小信息
39425
- * @returns 返回测量缓存的大小 {fontMetrics, layoutSize}
39426
- */
39427
- static getMeasureCacheSize() {
39563
+ const wr = mapper.getModelNodeById(start.modelRef.id);
39428
39564
  return {
39429
- fontMetrics: this.fontMetricsCache.size,
39430
- layoutSize: this.layoutSizeCache.size
39565
+ wr,
39566
+ pos: -1,
39567
+ side: "after"
39431
39568
  };
39432
39569
  }
39433
39570
  }
39434
- class TextRun extends LayoutNode {
39435
- component = BuiltinComponentTypeConst.Text;
39436
- /** 文本内容 */
39437
- text = "";
39438
- /** 字号 */
39439
- fontSize = DEFAULT_FONT_SIZE;
39440
- /** 字体 */
39441
- fontFamily = DEFAULT_FONT_FAMILY;
39442
- /** 文字颜色 */
39443
- color = DEFAULT_TEXT_COLOR;
39444
- /** 加粗 */
39445
- bold;
39446
- /** 斜体 */
39447
- italic;
39448
- /** 下划线 */
39449
- underline;
39450
- /** 删除线 */
39451
- strike;
39452
- /** 字间距 */
39453
- letterSpacing = 0;
39454
- /** 文字对齐样式 */
39455
- textAlign = "left";
39456
- charMetrics = [];
39457
- isPlaceholder = false;
39458
- isComposition = false;
39459
- lineHeight = 1.6;
39460
- ascent;
39461
- descent;
39462
- style;
39463
- constructor(options) {
39464
- super(options);
39465
- options.doc.increaseTextRunCount();
39466
- const { text } = options;
39467
- this.text = text;
39468
- this.isPlaceholder = options.isPlaceholder || false;
39469
- this.isComposition = options.isComposition || false;
39470
- this.ascent = options.ascent ?? 0;
39471
- this.descent = options.descent ?? 0;
39472
- if (options.charMetrics) {
39473
- this.charMetrics = options.charMetrics;
39474
- } else {
39475
- this.charMetrics.push({
39476
- char: options.text,
39477
- width: options.width,
39478
- height: options.height
39479
- });
39480
- }
39481
- if (options.style) {
39482
- Object.assign(this, options.style);
39571
+ const __vite_glob_0_48 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
39572
+ __proto__: null,
39573
+ UnmergeCells
39574
+ }, Symbol.toStringTag, { value: "Module" }));
39575
+ const commandModules = /* @__PURE__ */ Object.assign({
39576
+ "./commands/Backspace.ts": __vite_glob_0_0$4,
39577
+ "./commands/CommitValidateNumber.ts": __vite_glob_0_1$4,
39578
+ "./commands/Delete.ts": __vite_glob_0_2$4,
39579
+ "./commands/Delete2DTable.ts": __vite_glob_0_3$4,
39580
+ "./commands/DeleteBounded.ts": __vite_glob_0_4$4,
39581
+ "./commands/DeleteBoundedItem.ts": __vite_glob_0_5$4,
39582
+ "./commands/DeleteCheckTable.ts": __vite_glob_0_6$4,
39583
+ "./commands/DeleteCol.ts": __vite_glob_0_7$3,
39584
+ "./commands/DeleteDataGroup2D.ts": __vite_glob_0_8$3,
39585
+ "./commands/DeleteRepeating.ts": __vite_glob_0_9$3,
39586
+ "./commands/DeleteRow.ts": __vite_glob_0_10$3,
39587
+ "./commands/DeleteTable.ts": __vite_glob_0_11$3,
39588
+ "./commands/DeleteTableHeader.ts": __vite_glob_0_12$3,
39589
+ "./commands/Enter.ts": __vite_glob_0_13$3,
39590
+ "./commands/InsertCol.ts": __vite_glob_0_14$2,
39591
+ "./commands/InsertField.ts": __vite_glob_0_15$2,
39592
+ "./commands/InsertFloatingOverlay.ts": __vite_glob_0_16$1,
39593
+ "./commands/InsertImage.ts": __vite_glob_0_17$1,
39594
+ "./commands/InsertPaperWidget.ts": __vite_glob_0_18$1,
39595
+ "./commands/InsertRow.ts": __vite_glob_0_19$1,
39596
+ "./commands/InsertTable.ts": __vite_glob_0_20$1,
39597
+ "./commands/InsertText.ts": __vite_glob_0_21$1,
39598
+ "./commands/MergeCells.ts": __vite_glob_0_22$1,
39599
+ "./commands/ResizeCol.ts": __vite_glob_0_23$1,
39600
+ "./commands/ResizeImage.ts": __vite_glob_0_24$1,
39601
+ "./commands/ResizeOverlayLayout.ts": __vite_glob_0_25$1,
39602
+ "./commands/ResizeRow.ts": __vite_glob_0_26$1,
39603
+ "./commands/Set2DTable.ts": __vite_glob_0_27$1,
39604
+ "./commands/SetAlign.ts": __vite_glob_0_28$1,
39605
+ "./commands/SetBold.ts": __vite_glob_0_29$1,
39606
+ "./commands/SetBounded.ts": __vite_glob_0_30$1,
39607
+ "./commands/SetBoundedItem.ts": __vite_glob_0_31$1,
39608
+ "./commands/SetCheckTable.ts": __vite_glob_0_32$1,
39609
+ "./commands/SetColor.ts": __vite_glob_0_33$1,
39610
+ "./commands/SetDataGroup2D.ts": __vite_glob_0_34$1,
39611
+ "./commands/SetFont.ts": __vite_glob_0_35$1,
39612
+ "./commands/SetFontSize.ts": __vite_glob_0_36$1,
39613
+ "./commands/SetHeaderFooterConfig.ts": __vite_glob_0_37$1,
39614
+ "./commands/SetHighlight.ts": __vite_glob_0_38$1,
39615
+ "./commands/SetItalic.ts": __vite_glob_0_39$1,
39616
+ "./commands/SetOrient.ts": __vite_glob_0_40$1,
39617
+ "./commands/SetPadding.ts": __vite_glob_0_41$1,
39618
+ "./commands/SetRepeating.ts": __vite_glob_0_42$1,
39619
+ "./commands/SetStrike.ts": __vite_glob_0_43,
39620
+ "./commands/SetSubTableHeader.ts": __vite_glob_0_44,
39621
+ "./commands/SetTableHeader.ts": __vite_glob_0_45,
39622
+ "./commands/SetUnderline.ts": __vite_glob_0_46,
39623
+ "./commands/Snapshot.ts": __vite_glob_0_47,
39624
+ "./commands/UnmergeCells.ts": __vite_glob_0_48
39625
+ });
39626
+ function toCamelCase(pascalCase) {
39627
+ return pascalCase.charAt(0).toLowerCase() + pascalCase.slice(1);
39628
+ }
39629
+ function getClassNameFromPath(path2) {
39630
+ return path2.split("/").pop()?.replace(".ts", "") ?? "";
39631
+ }
39632
+ function buildCommandMap() {
39633
+ const map2 = {};
39634
+ Object.entries(commandModules).forEach(([path2, module2]) => {
39635
+ const expectedClassName = getClassNameFromPath(path2);
39636
+ const CommandClass = module2[expectedClassName];
39637
+ if (CommandClass && typeof CommandClass === "function") {
39638
+ const commandName = toCamelCase(expectedClassName);
39639
+ map2[commandName] = CommandClass;
39483
39640
  }
39641
+ });
39642
+ return map2;
39643
+ }
39644
+ class CommandManager {
39645
+ registry = /* @__PURE__ */ new Map();
39646
+ doc;
39647
+ undoStack = [];
39648
+ redoStack = [];
39649
+ composition;
39650
+ // 命令注册表 - 通过动态导入构建
39651
+ static COMMAND_MAP = buildCommandMap();
39652
+ constructor(doc) {
39653
+ this.doc = doc;
39654
+ Object.entries(CommandManager.COMMAND_MAP).forEach(([name, CommandClass]) => {
39655
+ this.register(name, CommandClass);
39656
+ });
39484
39657
  }
39485
- /**
39486
- * 计算文字大小 度量
39487
- * 优化版本
39488
- * @param payload
39489
- * @returns
39490
- */
39491
- static measureText(payload) {
39492
- const { width, height } = TextUtil.getLayoutSize(payload);
39493
- const { ascent, descent } = TextUtil.getFontMetrics(payload);
39494
- return {
39495
- width,
39496
- height,
39497
- ascent,
39498
- descent
39499
- };
39658
+ register(name, CommandClass) {
39659
+ this.registry.set(name, CommandClass);
39500
39660
  }
39501
- /**
39502
- * 计算文字大小 度量
39503
- * @param payload
39504
- * @returns
39505
- */
39506
- static __measureText(payload) {
39507
- let config = {
39508
- lineHeight: 1
39509
- };
39510
- Object.assign(config, payload);
39511
- const text = new Konva.Text(config);
39512
- const size = text.measureSize("Hg");
39513
- const { actualBoundingBoxAscent: ascent, actualBoundingBoxDescent: descent } = size;
39514
- return {
39515
- width: text.width(),
39516
- height: text.height(),
39517
- ascent,
39518
- descent
39519
- };
39661
+ async execute(name, payload) {
39662
+ const CommandClass = this.registry.get(name);
39663
+ if (!CommandClass) throw new Error(`Unknown command: ${name}`);
39664
+ const cmd = new CommandClass(this.doc, payload);
39665
+ const result = await cmd.do();
39666
+ result && this.updateCursor(result);
39667
+ payload?.doCallback && this.runCallback(payload.doCallback, result, cmd.output);
39668
+ if (cmd.isTerminated) return;
39669
+ this.undoStack.push(cmd);
39670
+ this.redoStack.length = 0;
39520
39671
  }
39521
- static createEmptyRun(doc) {
39522
- const fontSize2 = DEFAULT_FONT_SIZE;
39523
- const { height, ascent, descent } = TextRun.measureText({
39524
- text: "0",
39525
- fontSize: fontSize2
39526
- });
39527
- const run = new TextRun({
39528
- doc,
39529
- width: 6,
39530
- height,
39531
- ascent,
39532
- descent,
39533
- text: "",
39534
- isPlaceholder: true
39672
+ async undo() {
39673
+ const cmd = this.undoStack.pop();
39674
+ if (!cmd) return;
39675
+ const result = await cmd.undo();
39676
+ result && this.updateCursor(result);
39677
+ cmd.payload?.undoCallback && this.runCallback(cmd.payload?.undoCallback, result);
39678
+ this.redoStack.push(cmd);
39679
+ }
39680
+ async redo() {
39681
+ const cmd = this.redoStack.pop();
39682
+ if (!cmd) return;
39683
+ const result = await cmd.do();
39684
+ result && this.updateCursor(result);
39685
+ cmd.payload?.doCallback && this.runCallback(cmd.payload?.doCallback, result);
39686
+ this.undoStack.push(cmd);
39687
+ }
39688
+ compositionStart(text) {
39689
+ }
39690
+ compositionUpdate(text) {
39691
+ }
39692
+ compositionEnd(text) {
39693
+ this.doc.commandManager.execute(CommandType.insertText, {
39694
+ text
39535
39695
  });
39536
- return run;
39537
39696
  }
39538
- /**TextStyle(样式体系的样式)转换为 Layout 层的样式
39539
- * @param textStyle 经过继承计算的有效字符样式
39540
- * @returns TextRun 的样式属性
39541
- */
39542
- static textStyle2LayoutStyle(textStyle) {
39543
- if (!textStyle) return {};
39544
- const layoutStyle = {};
39545
- if (textStyle.sz !== void 0) {
39546
- const fontSizeInPt = textStyle.sz / 2;
39547
- layoutStyle.fontSize = fontSizeInPt * 96 / 72;
39548
- }
39549
- if (textStyle.rFonts?.ascii) {
39550
- layoutStyle.fontFamily = textStyle.rFonts.ascii;
39551
- }
39552
- if (textStyle.color) {
39553
- layoutStyle.color = normalizeColor(textStyle.color, DEFAULT_TEXT_COLOR);
39554
- }
39555
- if (textStyle.b !== void 0) {
39556
- layoutStyle.bold = textStyle.b;
39557
- }
39558
- if (textStyle.i !== void 0) {
39559
- layoutStyle.italic = textStyle.i;
39560
- }
39561
- if (textStyle.u !== void 0 && textStyle.u !== "none") {
39562
- layoutStyle.underline = true;
39563
- }
39564
- if (textStyle.strike !== void 0) {
39565
- layoutStyle.strike = textStyle.strike;
39697
+ updateCursor(data) {
39698
+ if (!data) return;
39699
+ if (Array.isArray(data)) {
39700
+ const [startData, endData] = data;
39701
+ this.doc.eventManager.cursorController?.resolveCursorRange(startData, endData);
39702
+ } else {
39703
+ this.doc.eventManager.cursorController?.resolveCursorAtNode?.(data);
39566
39704
  }
39567
- if (textStyle.spacing !== void 0) {
39568
- layoutStyle.letterSpacing = parseInt(textStyle.spacing) / 20;
39705
+ }
39706
+ runCallback(callback, data, output) {
39707
+ if (typeof callback === "function") {
39708
+ callback(data, output);
39569
39709
  }
39570
- if (textStyle.highlight !== void 0) ;
39571
- return layoutStyle;
39572
39710
  }
39573
39711
  }
39574
39712
  class EventUtil {
@@ -40295,7 +40433,7 @@ class ImageRun extends LayoutNode {
40295
40433
  this.decorations = options.decorations;
40296
40434
  }
40297
40435
  }
40298
- let ImageHandler$2 = class ImageHandler {
40436
+ class InlineImageLayoutHandler {
40299
40437
  static emuToPixels(emu) {
40300
40438
  return UnitConverter.emuToPixel(emu);
40301
40439
  }
@@ -40306,9 +40444,10 @@ let ImageHandler$2 = class ImageHandler {
40306
40444
  return { imageId };
40307
40445
  }
40308
40446
  let current = wr.parent;
40309
- while (current) {
40310
- if (current.name === "w:hdr" || current.name === "w:ftr") {
40311
- const ownerRelId = current.relId;
40447
+ while (current && typeof current === "object") {
40448
+ const node = current;
40449
+ if (node.name === "w:hdr" || node.name === "w:ftr") {
40450
+ const ownerRelId = node.relId;
40312
40451
  if (!ownerRelId) break;
40313
40452
  return {
40314
40453
  imageId,
@@ -40316,7 +40455,7 @@ let ImageHandler$2 = class ImageHandler {
40316
40455
  ownerRelId
40317
40456
  };
40318
40457
  }
40319
- current = current.parent;
40458
+ current = node.parent;
40320
40459
  }
40321
40460
  return { imageId };
40322
40461
  }
@@ -40343,35 +40482,8 @@ let ImageHandler$2 = class ImageHandler {
40343
40482
  });
40344
40483
  context.addRun(run);
40345
40484
  }
40346
- };
40347
- class TextWidget extends TextRun {
40348
- widgetMeta;
40349
- valuePath;
40350
- isEmptyPlaceholder = false;
40351
- isIconPlaceholder = false;
40352
- isSpacePlaceholder = false;
40353
- widgetFieldLeftMarker;
40354
- widgetFieldRightMarker;
40355
- widgetOption;
40356
- widgetFileItem;
40357
- pageWidgetMeta;
40358
- dataIndex;
40359
- constructor(options) {
40360
- super(options);
40361
- this.widgetMeta = options.widgetMeta;
40362
- this.valuePath = options.valuePath;
40363
- this.isEmptyPlaceholder = options.isEmptyPlaceholder ?? false;
40364
- this.isIconPlaceholder = options.isIconPlaceholder ?? false;
40365
- this.isSpacePlaceholder = options.isSpacePlaceholder ?? false;
40366
- this.widgetOption = options.widgetOption;
40367
- this.widgetFileItem = options.widgetFileItem;
40368
- this.widgetFieldLeftMarker = options.widgetFieldLeftMarker;
40369
- this.widgetFieldRightMarker = options.widgetFieldRightMarker;
40370
- this.pageWidgetMeta = options.pageWidgetMeta;
40371
- this.dataIndex = options.dataIndex;
40372
- }
40373
40485
  }
40374
- let BaseHandler$1 = class BaseHandler {
40486
+ class FieldBaseHandler {
40375
40487
  static hasValue(value) {
40376
40488
  return value !== void 0 && value !== null;
40377
40489
  }
@@ -40696,8 +40808,8 @@ let BaseHandler$1 = class BaseHandler {
40696
40808
  run.x = context.getRunX();
40697
40809
  context.addRun(run);
40698
40810
  }
40699
- };
40700
- class OptionHandler extends BaseHandler$1 {
40811
+ }
40812
+ class OptionHandler extends FieldBaseHandler {
40701
40813
  static layout(ctx) {
40702
40814
  const { context } = ctx;
40703
40815
  if (context.doc.mode === DocModeTypeConst.Print) {
@@ -40807,7 +40919,7 @@ class ImageWidget extends ImageRun {
40807
40919
  this.dataIndex = options.dataIndex;
40808
40920
  }
40809
40921
  }
40810
- let ImageHandler$1 = class ImageHandler2 extends BaseHandler$1 {
40922
+ class FieldImageHandler extends FieldBaseHandler {
40811
40923
  static layout(ctx) {
40812
40924
  this.layoutField(ctx);
40813
40925
  }
@@ -40851,8 +40963,8 @@ let ImageHandler$1 = class ImageHandler2 extends BaseHandler$1 {
40851
40963
  this.layoutNoValueLabel(ctx);
40852
40964
  }
40853
40965
  }
40854
- };
40855
- class SignatureHandler extends BaseHandler$1 {
40966
+ }
40967
+ class SignatureHandler extends FieldBaseHandler {
40856
40968
  static layout(ctx) {
40857
40969
  this.layoutField(ctx);
40858
40970
  }
@@ -40938,7 +41050,7 @@ class SignatureHandler extends BaseHandler$1 {
40938
41050
  }
40939
41051
  }
40940
41052
  }
40941
- class InputHandler extends BaseHandler$1 {
41053
+ class InputHandler extends FieldBaseHandler {
40942
41054
  static layout(ctx) {
40943
41055
  const { context } = ctx;
40944
41056
  if (context.doc.mode === DocModeTypeConst.Print) {
@@ -40999,7 +41111,7 @@ class InputHandler extends BaseHandler$1 {
40999
41111
  });
41000
41112
  }
41001
41113
  }
41002
- class AttachmentHandler extends BaseHandler$1 {
41114
+ class AttachmentHandler extends FieldBaseHandler {
41003
41115
  static layout(ctx) {
41004
41116
  this.layoutField(ctx);
41005
41117
  }
@@ -41085,7 +41197,7 @@ class FieldHandler {
41085
41197
  } else if (wr.widgetMeta?.props?.renderComp === "radio") {
41086
41198
  OptionHandler.layout(ctx);
41087
41199
  } else if (wr.widgetMeta?.type === "fw:image") {
41088
- ImageHandler$1.layout(ctx);
41200
+ FieldImageHandler.layout(ctx);
41089
41201
  } else if (wr.widgetMeta?.type === "fw:signature") {
41090
41202
  SignatureHandler.layout(ctx);
41091
41203
  } else if (wr.widgetMeta?.type === "fw:file") {
@@ -41095,7 +41207,7 @@ class FieldHandler {
41095
41207
  }
41096
41208
  }
41097
41209
  }
41098
- class BaseHandler2 {
41210
+ class WidgetBaseHandler {
41099
41211
  context;
41100
41212
  wr;
41101
41213
  constructor(ctx) {
@@ -41115,11 +41227,7 @@ class BaseHandler2 {
41115
41227
  */
41116
41228
  getDataIndex(init2 = null) {
41117
41229
  const { context } = this;
41118
- const {
41119
- type: type4,
41120
- dataIndex,
41121
- xDataIndex
41122
- } = context.cell?.subRenderer || {};
41230
+ const { type: type4, dataIndex, xDataIndex } = context.cell?.subRenderer || {};
41123
41231
  return (type4 === "2d-table" ? xDataIndex : dataIndex) ?? init2;
41124
41232
  }
41125
41233
  getPaperIndex() {
@@ -41156,7 +41264,7 @@ class BaseHandler2 {
41156
41264
  return layoutStyle;
41157
41265
  }
41158
41266
  }
41159
- class SerialNumberHandler extends BaseHandler2 {
41267
+ class SerialNumberHandler extends WidgetBaseHandler {
41160
41268
  layout() {
41161
41269
  const { wr, context } = this;
41162
41270
  const layoutStyle = this.getLayoutStyle();
@@ -41195,7 +41303,7 @@ class SerialNumberHandler extends BaseHandler2 {
41195
41303
  });
41196
41304
  }
41197
41305
  }
41198
- class DefaultHandler extends BaseHandler2 {
41306
+ class DefaultHandler extends WidgetBaseHandler {
41199
41307
  layout() {
41200
41308
  const { wr, context } = this;
41201
41309
  const layoutStyle = this.getLayoutStyle();
@@ -41234,7 +41342,7 @@ class DefaultHandler extends BaseHandler2 {
41234
41342
  });
41235
41343
  }
41236
41344
  }
41237
- class QrCodeHandler extends BaseHandler2 {
41345
+ class QrCodeHandler extends WidgetBaseHandler {
41238
41346
  layout() {
41239
41347
  const { wr, context } = this;
41240
41348
  const { width = 80, height = 80 } = wr.pageWidgetMeta?.layout || {};
@@ -41256,7 +41364,7 @@ class QrCodeHandler extends BaseHandler2 {
41256
41364
  context.addRun(run);
41257
41365
  }
41258
41366
  }
41259
- class BarcodeHandler extends BaseHandler2 {
41367
+ class BarcodeHandler extends WidgetBaseHandler {
41260
41368
  getDecorationsInfo(width, height, label) {
41261
41369
  const { wr } = this;
41262
41370
  const { justifyContent, showValue } = wr.pageWidgetMeta?.props || {};
@@ -41318,7 +41426,7 @@ class BarcodeHandler extends BaseHandler2 {
41318
41426
  context.addRun(run);
41319
41427
  }
41320
41428
  }
41321
- class ImageHandler3 extends BaseHandler2 {
41429
+ class PageWidgetImageHandler extends WidgetBaseHandler {
41322
41430
  layout() {
41323
41431
  const { wr, context } = this;
41324
41432
  const { width = 120, height = 68 } = wr.pageWidgetMeta?.layout || {};
@@ -41340,7 +41448,7 @@ class ImageHandler3 extends BaseHandler2 {
41340
41448
  context.addRun(run);
41341
41449
  }
41342
41450
  }
41343
- class DiagonalHandler extends BaseHandler2 {
41451
+ class DiagonalHandler extends WidgetBaseHandler {
41344
41452
  layout() {
41345
41453
  const { wr, context } = this;
41346
41454
  const cell = this.getCell();
@@ -41379,7 +41487,7 @@ class DiagonalHandler extends BaseHandler2 {
41379
41487
  });
41380
41488
  }
41381
41489
  }
41382
- class PaginationHandler extends BaseHandler2 {
41490
+ class PaginationHandler extends WidgetBaseHandler {
41383
41491
  layout() {
41384
41492
  const { wr, context } = this;
41385
41493
  const layoutStyle = this.getLayoutStyle();
@@ -41458,7 +41566,7 @@ class PaginationHandler extends BaseHandler2 {
41458
41566
  return string3;
41459
41567
  }
41460
41568
  }
41461
- class LineHandler extends BaseHandler2 {
41569
+ class LineHandler extends WidgetBaseHandler {
41462
41570
  layout() {
41463
41571
  const { wr, context } = this;
41464
41572
  const { width = 120, height = 68 } = wr.pageWidgetMeta?.layout || {};
@@ -41489,7 +41597,7 @@ class PageWidgetHandler {
41489
41597
  } else if (wr.pageWidgetMeta?.type === "pw:barcode") {
41490
41598
  new BarcodeHandler(ctx).layout();
41491
41599
  } else if (wr.pageWidgetMeta?.type === "pw:image") {
41492
- new ImageHandler3(ctx).layout();
41600
+ new PageWidgetImageHandler(ctx).layout();
41493
41601
  } else if (wr.pageWidgetMeta?.type === "pw:diagonal") {
41494
41602
  new DiagonalHandler(ctx).layout();
41495
41603
  } else if (wr.pageWidgetMeta?.type === "pw:pagination") {
@@ -42727,7 +42835,7 @@ class LayoutManager {
42727
42835
  this.doc = doc;
42728
42836
  this.layoutHandlers = /* @__PURE__ */ new Map();
42729
42837
  this.layoutHandlers.set("text", TextHandler);
42730
- this.layoutHandlers.set("image", ImageHandler$2);
42838
+ this.layoutHandlers.set("image", InlineImageLayoutHandler);
42731
42839
  this.pageContext = new LayoutContext({
42732
42840
  type: "page",
42733
42841
  doc: this.doc,
@@ -45363,7 +45471,7 @@ class DataManager {
45363
45471
  values = [{ ...DEFAULT_EMPTY_ITEM }];
45364
45472
  }
45365
45473
  let arr = this.get(path2);
45366
- if (!Array.isArray(arr)) {
45474
+ if (!Array.isArray(arr) || arr.length === 0) {
45367
45475
  arr = [{ ...DEFAULT_EMPTY_ITEM }];
45368
45476
  this.set(path2, arr);
45369
45477
  }
@@ -45965,6 +46073,8 @@ class Doc {
45965
46073
  docRuntimeMeta;
45966
46074
  /** 外部的参数配置 */
45967
46075
  paramsConfig;
46076
+ /** 字段/模型查询(由上层注入 `SuiteRuntime` 等实现) */
46077
+ fieldModelQuery;
45968
46078
  /** 安全距离-上下 */
45969
46079
  SAFE_DIST_Y = 40;
45970
46080
  /** 安全距离-左右 */
@@ -45993,6 +46103,7 @@ class Doc {
45993
46103
  this.paramsConfig = options.paramsConfig;
45994
46104
  this.onLayoutChange = options.onLayoutChange;
45995
46105
  this.onSelectionChange = options.onSelectionChange;
46106
+ this.fieldModelQuery = options.fieldModelQuery;
45996
46107
  this.commandManager = new CommandManager(this);
45997
46108
  this.layoutManager = new LayoutManager(this);
45998
46109
  this.layoutMapper = new LayoutMapper(this);
@@ -47841,6 +47952,14 @@ class DocModel {
47841
47952
  }
47842
47953
  return result;
47843
47954
  }
47955
+ /** 获取所有 children */
47956
+ getAllChildren() {
47957
+ return this.document?.body?.children || [];
47958
+ }
47959
+ /** 获取所有表格 */
47960
+ getAllTables() {
47961
+ return this.getAllChildren().filter((w2) => w2.name === "w:tbl");
47962
+ }
47844
47963
  /**
47845
47964
  * 获取所有同时存在 widgetMeta 和 valuePath 的实例
47846
47965
  * @returns Wr 实例数组(包含 widgetMeta 和 valuePath 的文本或图片 run)
@@ -47856,11 +47975,72 @@ class DocModel {
47856
47975
  node.children.forEach((child) => collectWidgets(child));
47857
47976
  }
47858
47977
  };
47859
- if (this.document?.body?.children) {
47860
- this.document.body.children.forEach((child) => collectWidgets(child));
47861
- }
47978
+ this.getAllChildren().forEach((child) => collectWidgets(child));
47862
47979
  return instances;
47863
47980
  }
47981
+ /** 获取子表信息列表 */
47982
+ getSubTableInfoList() {
47983
+ const tables = this.getAllTables();
47984
+ const dynamicTableRegions = tables.filter((w2) => w2.hasRepeating).flatMap((w2) => w2.repeating).map((item) => {
47985
+ return {
47986
+ field: getLastSegment(item.valuePath),
47987
+ key: "dyn",
47988
+ name: "动态表",
47989
+ subType: "sub-table"
47990
+ };
47991
+ });
47992
+ const fixedTableRegions = tables.filter((w2) => w2.hasBounded).flatMap((w2) => w2.bounded).map((item) => {
47993
+ return {
47994
+ field: getLastSegment(item.valuePath),
47995
+ key: "newfixed",
47996
+ name: "固定表",
47997
+ subType: "fixed-table"
47998
+ };
47999
+ });
48000
+ const table2DRegions = tables.filter((w2) => w2.has2DTable).flatMap((w2) => w2._2DTable).map((item) => {
48001
+ const region = parseLinkFieldExpression(item.valuePath);
48002
+ const result = [];
48003
+ if (region.subFieldKey) {
48004
+ result.push({
48005
+ field: region.subFieldKey,
48006
+ key: "dyn",
48007
+ name: "二维表",
48008
+ subType: "sub-table-2d"
48009
+ });
48010
+ }
48011
+ if (region.linkFieldKey) {
48012
+ result.push({
48013
+ field: region.linkFieldKey,
48014
+ key: "newfixed",
48015
+ name: "二维表-关联",
48016
+ subType: "sub-table-2d-link"
48017
+ });
48018
+ }
48019
+ return result;
48020
+ }).flat();
48021
+ const checkTableRegions = tables.filter((w2) => w2.hasCheckTable).flatMap((w2) => w2.checkTable).map((item) => {
48022
+ const region = parseLinkFieldExpression(item.valuePath);
48023
+ const result = [];
48024
+ if (region.subFieldKey) {
48025
+ result.push({
48026
+ field: region.subFieldKey,
48027
+ key: "newfixed",
48028
+ name: "检验表-动态",
48029
+ subType: "check-table-2d"
48030
+ });
48031
+ }
48032
+ if (region.linkFieldKey) {
48033
+ result.push({
48034
+ field: region.linkFieldKey,
48035
+ key: "newfixed",
48036
+ name: "检验表-关联",
48037
+ subType: "check-table-2d-link"
48038
+ });
48039
+ }
48040
+ return result;
48041
+ }).flat();
48042
+ return [...dynamicTableRegions, ...fixedTableRegions, ...table2DRegions, ...checkTableRegions];
48043
+ }
47864
48044
  /** 根据 pageIndex 获取页眉实例 */
47865
48045
  getHeader(pageIndex, section) {
47866
48046
  const hasEvenOdd = this.settings?.isEvenAndOddEnabled();
@@ -50848,8 +51028,8 @@ const handleCustomDataSource = async (customDataSource, paramsConfig, subTableIn
50848
51028
  }
50849
51029
  return Promise.all(promises);
50850
51030
  };
50851
- const loadDataInitValues = async (designerJson, paramsConfig, subTableInfo, fieldPermission, instanceId) => {
50852
- const { document: document2 } = JSON.parse(designerJson || "{}");
51031
+ const loadDataInitValues = async (runtimeJson, paramsConfig, subTableInfo, fieldPermission, instanceId) => {
51032
+ const { document: document2 } = JSON.parse(runtimeJson || "{}");
50853
51033
  if (!document2?.config?.dataInit) return {};
50854
51034
  const {
50855
51035
  parameterMapping = [],
@@ -51046,12 +51226,11 @@ async function initializeDocumentEngine(props, payload, result) {
51046
51226
  );
51047
51227
  console.log("默认值集合 ===>", defaultDataMap);
51048
51228
  const dataInitMap = await loadDataInitValues(
51049
- requestInfo.designerJson || "",
51229
+ requestInfo.runtimeJson || "",
51050
51230
  paramsConfig,
51051
51231
  [],
51052
51232
  // JSW TODO: subTableInfo
51053
- [],
51054
- // JSW TODO: fieldPermission
51233
+ JSON.parse(requestInfo.processFieldPermission || "[]"),
51055
51234
  id
51056
51235
  );
51057
51236
  console.log("数据初始化集合 ===>", dataInitMap);
@@ -51085,7 +51264,8 @@ async function initializeDocumentEngine(props, payload, result) {
51085
51264
  formType: requestInfo.formType || FormTypeConst.BASE,
51086
51265
  preview: payload.isPreview,
51087
51266
  paramsConfig: paramsConfig ?? {},
51088
- docRuntimeMeta
51267
+ docRuntimeMeta,
51268
+ fieldModelQuery: payload.ctx.runtime
51089
51269
  });
51090
51270
  doc.dataManager.setRawData(rawData, {
51091
51271
  ...defaultDataMap,
@@ -51276,6 +51456,16 @@ class FieldService {
51276
51456
  if (!runtime) return void 0;
51277
51457
  return runtime.getFieldById(id);
51278
51458
  }
51459
+ queryFieldByKeySync(modelKey, fieldKey) {
51460
+ const runtime = this.getRuntime(modelKey);
51461
+ if (!runtime) return void 0;
51462
+ return runtime.getFieldByKeySync(fieldKey);
51463
+ }
51464
+ queryFieldByIdSync(modelKey, id) {
51465
+ const runtime = this.getRuntime(modelKey);
51466
+ if (!runtime) return void 0;
51467
+ return runtime.getFieldByIdSync(id);
51468
+ }
51279
51469
  getFieldList(modelKey) {
51280
51470
  const rt2 = this.getRuntime(modelKey);
51281
51471
  if (!rt2) return [];
@@ -51591,6 +51781,12 @@ class SuiteRuntime {
51591
51781
  getFieldList(modelKey) {
51592
51782
  return this.fieldService.getFieldList(modelKey);
51593
51783
  }
51784
+ getFieldByKeyAsync(modelKey, key) {
51785
+ return this.fieldService.queryFieldByKeySync(modelKey, key);
51786
+ }
51787
+ getFieldByIdAsync(modelKey, id) {
51788
+ return this.fieldService.queryFieldByIdSync(modelKey, id);
51789
+ }
51594
51790
  getModel(modelKey) {
51595
51791
  return this.modelService.getModelSync(modelKey);
51596
51792
  }
@@ -53419,13 +53615,22 @@ const validateAllFields = async (doc) => {
53419
53615
  if (!showFormItem) {
53420
53616
  return;
53421
53617
  }
53618
+ const modelKey = getLastSegment(fieldMeta.modelLink);
53619
+ const fieldKey = getLastSegment(fieldMeta.fieldLink);
53620
+ const fieldInfo = doc.fieldModelQuery.getFieldByKeyAsync(modelKey, fieldKey);
53621
+ const modelInfo = doc.fieldModelQuery.getModel(modelKey);
53422
53622
  const ctx = createValidatorContext(doc, {
53423
53623
  ...widgetProps,
53424
53624
  showRequired: widgetState.required,
53425
53625
  validatorInfo: {
53426
53626
  modelId: widget.modelRef.id,
53427
53627
  runtimeValuePath,
53428
- widgetType: type4
53628
+ widgetType: type4,
53629
+ showModelName: modelInfo?.modelName,
53630
+ showModelKey: fieldInfo?.modelKey,
53631
+ showFieldName: fieldInfo?.name,
53632
+ subFieldKey: fieldMeta.subFieldKey,
53633
+ targetFieldId: fieldInfo?.key
53429
53634
  }
53430
53635
  });
53431
53636
  const rules2 = assembleRules(ctx);
@@ -54470,8 +54675,15 @@ const _sfc_main$2J = /* @__PURE__ */ defineComponent({
54470
54675
  },
54471
54676
  setup(__props) {
54472
54677
  const props = __props;
54678
+ const textRef = ref(null);
54679
+ const rectConfig = ref({
54680
+ width: 0,
54681
+ height: 0,
54682
+ fill: "#f00"
54683
+ });
54473
54684
  const textConfig = computed(() => {
54474
54685
  const widget = props.widget;
54686
+ const { highlight } = widget;
54475
54687
  const fontStyle = [widget.bold && "bold", widget.italic && "italic"].filter(Boolean).join(" ") || void 0;
54476
54688
  const textDecoration = [
54477
54689
  widget.isComposition && "underline",
@@ -54489,17 +54701,51 @@ const _sfc_main$2J = /* @__PURE__ */ defineComponent({
54489
54701
  align: widget.textAlign,
54490
54702
  letterSpacing: widget.letterSpacing,
54491
54703
  textDecoration,
54492
- wrap: "none"
54704
+ wrap: "none",
54705
+ _bgFill: highlight && highlight !== "none" ? highlight : void 0
54493
54706
  };
54494
54707
  });
54708
+ const updateRectSize = async (fill) => {
54709
+ if (!fill) return;
54710
+ await nextTick();
54711
+ if (textRef.value) {
54712
+ const textNode = textRef.value.getNode();
54713
+ const width = textNode.getTextWidth();
54714
+ const height = textNode.getHeight();
54715
+ rectConfig.value = {
54716
+ width,
54717
+ height,
54718
+ fill
54719
+ };
54720
+ }
54721
+ };
54722
+ watch(
54723
+ () => textConfig.value,
54724
+ async () => {
54725
+ await updateRectSize(textConfig.value._bgFill);
54726
+ },
54727
+ {
54728
+ immediate: true
54729
+ }
54730
+ );
54495
54731
  return (_ctx, _cache) => {
54732
+ const _component_v_rect = resolveComponent("v-rect");
54496
54733
  const _component_v_text = resolveComponent("v-text");
54497
54734
  const _component_v_group = resolveComponent("v-group");
54498
54735
  return openBlock(), createBlock(_component_v_group, {
54499
54736
  config: { x: __props.widget.x, y: __props.widget.y, id: __props.widget.id }
54500
54737
  }, {
54501
54738
  default: withCtx(() => [
54502
- createVNode(_component_v_text, { config: textConfig.value }, null, 8, ["config"])
54739
+ textConfig.value._bgFill ? (openBlock(), createBlock(_component_v_rect, {
54740
+ key: 0,
54741
+ config: rectConfig.value
54742
+ }, null, 8, ["config"])) : createCommentVNode("", true),
54743
+ createVNode(_component_v_text, {
54744
+ ref_key: "textRef",
54745
+ ref: textRef,
54746
+ config: textConfig.value,
54747
+ onConfigChange: updateRectSize
54748
+ }, null, 8, ["config"])
54503
54749
  ]),
54504
54750
  _: 1
54505
54751
  }, 8, ["config"]);
@@ -56748,6 +56994,9 @@ function useDocController(factory2, ops) {
56748
56994
  rawData() {
56749
56995
  return doc.dataManager.getRawData();
56750
56996
  },
56997
+ getSubTableInfoList() {
56998
+ return doc.model?.getSubTableInfoList() ?? [];
56999
+ },
56751
57000
  // 业务操作 — 委托给 useDocOperations
56752
57001
  validate() {
56753
57002
  return ops.validate();
@@ -61532,6 +61781,14 @@ class FieldProviderRuntime {
61532
61781
  this.updateCache(res.data, res.total);
61533
61782
  return res;
61534
61783
  }
61784
+ /** 同步获取字段 */
61785
+ getFieldByKeySync(key) {
61786
+ return this.keyMap.get(key);
61787
+ }
61788
+ /** 同步获取字段 */
61789
+ getFieldByIdSync(id) {
61790
+ return this.idMap.get(id);
61791
+ }
61535
61792
  async getFieldByKey(key) {
61536
61793
  if (this.keyMap.has(key)) return this.keyMap.get(key);
61537
61794
  await this.fetchFields();