@gct-paas/word 0.1.2 → 0.1.4

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 (36) hide show
  1. package/dist/index.es.js +1379 -1052
  2. package/dist/word.css +16 -16
  3. package/package.json +3 -3
  4. package/dist/base/utils/asset-helper-util.d.ts +0 -19
  5. package/dist/index.d.ts +0 -3
  6. package/dist/runtime/designer/doc-design-layout.vue.d.ts +0 -2
  7. package/dist/runtime/designer/main/preview-container.vue.d.ts +0 -2
  8. package/dist/runtime/designer/main/view-layer/__common__/widget-component.vue.d.ts +0 -2
  9. package/dist/runtime/designer/main/view-layer/builtin/paper/paper-group.vue.d.ts +0 -2
  10. package/dist/runtime/designer/main/view-layer/builtin/paper/themes.d.ts +0 -37
  11. package/dist/runtime/designer/main/view-layer/render-entry.vue.d.ts +0 -2
  12. package/dist/runtime/designer/panel/panel.vue.d.ts +0 -2
  13. package/dist/runtime/designer/ribbon/common/button-icon.vue.d.ts +0 -2
  14. package/dist/runtime/designer/ribbon/components/bullet-point-select.vue.d.ts +0 -2
  15. package/dist/runtime/designer/ribbon/components/insert-table-form-modal.vue.d.ts +0 -2
  16. package/dist/runtime/designer/ribbon/components/marker-color-select.vue.d.ts +0 -2
  17. package/dist/runtime/designer/ribbon/components/multistage-no-select.vue.d.ts +0 -2
  18. package/dist/runtime/designer/ribbon/components/sub-table-form-modal.vue.d.ts +0 -2
  19. package/dist/runtime/designer/ribbon/components/text-color-select.vue.d.ts +0 -2
  20. package/dist/runtime/designer/ribbon/constant/color.d.ts +0 -62
  21. package/dist/runtime/designer/ribbon/constant/font.d.ts +0 -31
  22. package/dist/runtime/designer/ribbon/constant/word.d.ts +0 -26
  23. package/dist/runtime/designer/ribbon/ribbon.vue.d.ts +0 -2
  24. package/dist/runtime/designer/ribbon/svg/bj-marker-svg.vue.d.ts +0 -2
  25. package/dist/runtime/designer/ribbon/svg/color-wheel-svg.vue.d.ts +0 -2
  26. package/dist/runtime/designer/ribbon/svg/font-color-svg.vue.d.ts +0 -2
  27. package/dist/runtime/designer/ribbon/tabs/home-tab.vue.d.ts +0 -2
  28. package/dist/runtime/designer/ribbon/tabs/insert-tab.vue.d.ts +0 -2
  29. package/dist/runtime/designer/ribbon/tabs/layout-tab.vue.d.ts +0 -2
  30. package/dist/runtime/designer/ribbon/tabs/structured-tab.vue.d.ts +0 -2
  31. package/dist/runtime/designer/ribbon/tabs/table-tab.vue.d.ts +0 -2
  32. package/dist/runtime/designer/toolkit/renderer/toolkit-content-fields.vue.d.ts +0 -2
  33. package/dist/runtime/designer/toolkit/renderer/toolkit-content-widgets.vue.d.ts +0 -2
  34. package/dist/runtime/designer/toolkit/toolkit-item.vue.d.ts +0 -19
  35. package/dist/runtime/designer/toolkit/toolkit.vue.d.ts +0 -2
  36. package/dist/setup.d.ts +0 -5
package/dist/index.es.js CHANGED
@@ -1,8 +1,7 @@
1
- var _a;
2
1
  import { defineComponent, useSlots, computed, createElementBlock, openBlock, normalizeClass, createCommentVNode, createElementVNode, unref, renderSlot, cloneVNode, provide, Fragment, renderList, createBlock, resolveDynamicComponent, inject, ref, watch, createVNode, withModifiers, toDisplayString, Transition, withCtx, withDirectives, createTextVNode, vModelCheckbox, vModelText, vShow, mergeProps, normalizeStyle, onMounted, nextTick, onBeforeUnmount, Teleport, reactive, createApp, h as h$1, getCurrentInstance, onUnmounted, resolveComponent, normalizeProps, guardReactiveProps, createStaticVNode, isRef, withKeys, useCssVars, mergeModels, useModel, readonly, getCurrentScope, onScopeDispose, watchEffect, toValue, toRef, shallowRef, onBeforeMount, toRaw, createSlots } from "vue";
3
2
  import FloatingVue, { PopperWrapper } from "floating-vue";
4
- import exifr from "exifr";
5
3
  import Konva from "konva";
4
+ import exifr from "exifr";
6
5
  import { jsPDF } from "jspdf";
7
6
  import VueDraggable from "vuedraggable";
8
7
  import VueKonva from "vue-konva";
@@ -3470,8 +3469,8 @@ var MapShim = (function() {
3470
3469
  if (ctx === void 0) {
3471
3470
  ctx = null;
3472
3471
  }
3473
- for (var _i = 0, _a2 = this.__entries__; _i < _a2.length; _i++) {
3474
- var entry = _a2[_i];
3472
+ for (var _i = 0, _a = this.__entries__; _i < _a.length; _i++) {
3473
+ var entry = _a[_i];
3475
3474
  callback.call(ctx, entry[1], entry[0]);
3476
3475
  }
3477
3476
  };
@@ -3616,8 +3615,8 @@ var ResizeObserverController = (
3616
3615
  this.mutationEventsAdded_ = false;
3617
3616
  this.connected_ = false;
3618
3617
  };
3619
- ResizeObserverController2.prototype.onTransitionEnd_ = function(_a2) {
3620
- var _b = _a2.propertyName, propertyName = _b === void 0 ? "" : _b;
3618
+ ResizeObserverController2.prototype.onTransitionEnd_ = function(_a) {
3619
+ var _b = _a.propertyName, propertyName = _b === void 0 ? "" : _b;
3621
3620
  var isReflowProperty = transitionKeys.some(function(key) {
3622
3621
  return !!~propertyName.indexOf(key);
3623
3622
  });
@@ -3636,8 +3635,8 @@ var ResizeObserverController = (
3636
3635
  })()
3637
3636
  );
3638
3637
  var defineConfigurable = (function(target, props) {
3639
- for (var _i = 0, _a2 = Object.keys(props); _i < _a2.length; _i++) {
3640
- var key = _a2[_i];
3638
+ for (var _i = 0, _a = Object.keys(props); _i < _a.length; _i++) {
3639
+ var key = _a[_i];
3641
3640
  Object.defineProperty(target, key, {
3642
3641
  value: props[key],
3643
3642
  enumerable: false,
@@ -3731,8 +3730,8 @@ function getContentRect(target) {
3731
3730
  }
3732
3731
  return getHTMLElementContentRect(target);
3733
3732
  }
3734
- function createReadOnlyRect(_a2) {
3735
- var x2 = _a2.x, y2 = _a2.y, width = _a2.width, height = _a2.height;
3733
+ function createReadOnlyRect(_a) {
3734
+ var x2 = _a.x, y2 = _a.y, width = _a.width, height = _a.height;
3736
3735
  var Constr = typeof DOMRectReadOnly !== "undefined" ? DOMRectReadOnly : Object;
3737
3736
  var rect = Object.create(Constr.prototype);
3738
3737
  defineConfigurable(rect, {
@@ -3891,8 +3890,8 @@ var ResizeObserver = (
3891
3890
  "disconnect"
3892
3891
  ].forEach(function(method4) {
3893
3892
  ResizeObserver.prototype[method4] = function() {
3894
- var _a2;
3895
- return (_a2 = observers.get(this))[method4].apply(_a2, arguments);
3893
+ var _a;
3894
+ return (_a = observers.get(this))[method4].apply(_a, arguments);
3896
3895
  };
3897
3896
  });
3898
3897
  var index = (function() {
@@ -9241,8 +9240,10 @@ function remove(self2) {
9241
9240
  }
9242
9241
  }
9243
9242
  class ModelNode {
9243
+ id;
9244
+ type = "";
9245
+ parent;
9244
9246
  constructor(id) {
9245
- this.type = "";
9246
9247
  this.id = id || uuid();
9247
9248
  }
9248
9249
  /**
@@ -9312,9 +9313,9 @@ class ModelNode {
9312
9313
  }
9313
9314
  }
9314
9315
  class ModelGroup extends ModelNode {
9316
+ children = [];
9315
9317
  constructor(id) {
9316
9318
  super(id);
9317
- this.children = [];
9318
9319
  }
9319
9320
  /**
9320
9321
  * 在指定位置插入子节点
@@ -9534,10 +9535,28 @@ const TABLE_CELL_TEMPLATE = {
9534
9535
  ]
9535
9536
  };
9536
9537
  class Wtc extends ModelGroup {
9538
+ type = "tableCell";
9539
+ attrs;
9540
+ rawProperties;
9541
+ // children: Wp[]; // 单元格内的段落
9542
+ colspan;
9543
+ // 水平合并的列数
9544
+ rowspan;
9545
+ // 垂直合并的行数
9546
+ mergeFromId;
9547
+ // 被合并单元格指向源头单元格的 ID
9548
+ mergeId;
9549
+ // 属于哪个合并区域的 ID(所有属于同一合并区域的单元格都有相同值)
9550
+ repeatingId;
9551
+ // 属于哪个重复区域的 ID
9552
+ boundedId;
9553
+ // 属于哪个有界区域的 ID
9554
+ boundedItemId;
9555
+ // 有界区域内的项目 ID
9556
+ vMergeType;
9537
9557
  // 父节点引用(Wtr)
9538
9558
  constructor(options) {
9539
9559
  super(options.id);
9540
- this.type = "tableCell";
9541
9560
  this.children = options.children;
9542
9561
  this.children.forEach((para) => {
9543
9562
  para.parent = this;
@@ -9944,10 +9963,16 @@ const TABLE_ROW_TEMPLATE = {
9944
9963
  ]
9945
9964
  };
9946
9965
  class Wtr extends ModelGroup {
9966
+ type = "tableRow";
9967
+ attrs;
9968
+ rawProperties;
9969
+ // 行高相关属性
9970
+ rowHeight;
9971
+ // 行高(twips 单位)
9972
+ rowHeightRule;
9947
9973
  // 父节点引用(Wtbl)
9948
9974
  constructor(options) {
9949
9975
  super(options.id);
9950
- this.type = "tableRow";
9951
9976
  this.children = options.cells;
9952
9977
  this.children.forEach((cell) => {
9953
9978
  cell.parent = this;
@@ -10136,6 +10161,201 @@ class Wtr extends ModelGroup {
10136
10161
  });
10137
10162
  }
10138
10163
  }
10164
+ class Region {
10165
+ id;
10166
+ table;
10167
+ start = {
10168
+ row: 0,
10169
+ col: 0
10170
+ };
10171
+ end = {
10172
+ row: 0,
10173
+ col: 0
10174
+ };
10175
+ get rowCount() {
10176
+ return this.end.row - this.start.row + 1;
10177
+ }
10178
+ get colCount() {
10179
+ return this.end.col - this.start.col + 1;
10180
+ }
10181
+ get cellCount() {
10182
+ return this.table.getCellCount({
10183
+ startColIdx: this.start.col,
10184
+ startRowIdx: this.start.row,
10185
+ endColIdx: this.end.col,
10186
+ endRowIdx: this.end.row
10187
+ });
10188
+ }
10189
+ constructor(options) {
10190
+ this.id = options.id ?? uuid();
10191
+ this.table = options.table;
10192
+ if (options.start) {
10193
+ this.start = options.start;
10194
+ }
10195
+ if (options.end) {
10196
+ this.end = options.end;
10197
+ }
10198
+ }
10199
+ /**
10200
+ * 检查指定的行列位置是否在当前区域内
10201
+ * @param row 行号
10202
+ * @param col 列号
10203
+ * @returns 是否在区域内
10204
+ */
10205
+ contains(row, col) {
10206
+ return row >= this.start.row && row <= this.end.row && col >= this.start.col && col <= this.end.col;
10207
+ }
10208
+ toJSON() {
10209
+ return {
10210
+ type: this.type,
10211
+ start: {
10212
+ row: this.start.row,
10213
+ col: this.start.col
10214
+ },
10215
+ end: {
10216
+ row: this.end.row,
10217
+ col: this.end.col
10218
+ }
10219
+ };
10220
+ }
10221
+ }
10222
+ class RepeatingRegion extends Region {
10223
+ type = "repeating";
10224
+ name;
10225
+ valuePath;
10226
+ widgetMeta;
10227
+ constructor(options) {
10228
+ super(options);
10229
+ this.valuePath = options.valuePath;
10230
+ this.name = options.name;
10231
+ this.widgetMeta = {
10232
+ props: {
10233
+ quickFill: false
10234
+ }
10235
+ };
10236
+ }
10237
+ /**
10238
+ * 序列化为 JSON 对象
10239
+ */
10240
+ toJSON() {
10241
+ const json = super.toJSON();
10242
+ return Object.assign(json, {
10243
+ name: this.name,
10244
+ valuePath: this.valuePath
10245
+ });
10246
+ }
10247
+ /**
10248
+ * 从 JSON 对象还原
10249
+ */
10250
+ static fromJSON(json, table) {
10251
+ const region = new RepeatingRegion({
10252
+ table,
10253
+ start: {
10254
+ row: json.start.row,
10255
+ col: json.start.col
10256
+ },
10257
+ end: {
10258
+ row: json.end.row,
10259
+ col: json.end.col
10260
+ },
10261
+ name: json.name,
10262
+ valuePath: json.valuePath
10263
+ });
10264
+ return region;
10265
+ }
10266
+ }
10267
+ class BoundedItemRegion extends Region {
10268
+ type = "boundedItem";
10269
+ parent;
10270
+ constructor(options) {
10271
+ super(options);
10272
+ if (options.parent) {
10273
+ this.parent = options.parent;
10274
+ }
10275
+ }
10276
+ remove() {
10277
+ this.parent.removeItemRegion();
10278
+ }
10279
+ }
10280
+ class BoundedRegion extends Region {
10281
+ type = "bounded";
10282
+ name;
10283
+ valuePath;
10284
+ itemRegion;
10285
+ widgetMeta;
10286
+ constructor(options) {
10287
+ super(options);
10288
+ this.name = options.name;
10289
+ this.valuePath = options.valuePath;
10290
+ this.widgetMeta = {
10291
+ props: {
10292
+ autoFill: true,
10293
+ fillDirection: "x"
10294
+ }
10295
+ };
10296
+ }
10297
+ /**
10298
+ * 序列化为 JSON 对象
10299
+ */
10300
+ toJSON() {
10301
+ const json = super.toJSON();
10302
+ return Object.assign(json, {
10303
+ name: this.name,
10304
+ valuePath: this.valuePath
10305
+ });
10306
+ }
10307
+ /**
10308
+ * 从 JSON 对象还原
10309
+ */
10310
+ static fromJSON(json, table) {
10311
+ const region = new BoundedRegion({
10312
+ table,
10313
+ start: {
10314
+ row: json.start.row,
10315
+ col: json.start.col
10316
+ },
10317
+ end: {
10318
+ row: json.end.row,
10319
+ col: json.end.col
10320
+ },
10321
+ name: json.name,
10322
+ valuePath: json.valuePath
10323
+ });
10324
+ return region;
10325
+ }
10326
+ setItemRegion(options) {
10327
+ const region = new BoundedItemRegion({
10328
+ table: this.table,
10329
+ parent: this,
10330
+ ...options
10331
+ });
10332
+ this.itemRegion = region;
10333
+ this.table.forEachCell({
10334
+ startRowIdx: options.start.row,
10335
+ startColIdx: options.start.col,
10336
+ endRowIdx: options.end.row,
10337
+ endColIdx: options.end.col,
10338
+ callback: (cell) => {
10339
+ cell.boundedItemId = region.id;
10340
+ }
10341
+ });
10342
+ return region;
10343
+ }
10344
+ removeItemRegion() {
10345
+ if (this.itemRegion) {
10346
+ this.table.forEachCell({
10347
+ startRowIdx: this.itemRegion.start.row,
10348
+ startColIdx: this.itemRegion.start.col,
10349
+ endRowIdx: this.itemRegion.end.row,
10350
+ endColIdx: this.itemRegion.end.col,
10351
+ callback: (cell) => {
10352
+ cell.boundedItemId = void 0;
10353
+ }
10354
+ });
10355
+ }
10356
+ this.itemRegion = void 0;
10357
+ }
10358
+ }
10139
10359
  const TABLE_TEMPLATE = {
10140
10360
  name: "w:tbl",
10141
10361
  type: "element",
@@ -10271,7 +10491,22 @@ const TABLE_TEMPLATE = {
10271
10491
  // 由 fromTemplate() 构造并插入
10272
10492
  ]
10273
10493
  };
10274
- let UnitConverter$1 = (_a = class {
10494
+ let UnitConverter$1 = class UnitConverter {
10495
+ // ==================== 常量定义 ====================
10496
+ /** 1 inch = 2.54 cm */
10497
+ static INCH_TO_CM = 2.54;
10498
+ /** 1 inch = 72 points */
10499
+ static INCH_TO_POINTS = 72;
10500
+ /** 1 twip = 1/20 point */
10501
+ static TWIP_TO_POINT = 1 / 20;
10502
+ /** 1 point = 1/72 inch */
10503
+ static POINT_TO_INCH = 1 / 72;
10504
+ /** 屏幕 DPI(像素/英寸) */
10505
+ static DEFAULT_DPI = 96;
10506
+ /** EMU (English Metric Units) - Word 内部单位,1 inch = 914400 EMU */
10507
+ static EMU_PER_INCH = 914400;
10508
+ /** DXA (twips) 单位,1 inch = 1440 DXA */
10509
+ static DXA_PER_INCH = 1440;
10275
10510
  // ==================== Twips ↔ Pixels ====================
10276
10511
  /**
10277
10512
  * 将 twips 转换为像素
@@ -10281,8 +10516,8 @@ let UnitConverter$1 = (_a = class {
10281
10516
  * @example
10282
10517
  * UnitConverter.twipToPixel(1440) // 96
10283
10518
  */
10284
- static twipToPixel(twips, dpi = _a.DEFAULT_DPI) {
10285
- return Math.round(twips * dpi / _a.DXA_PER_INCH);
10519
+ static twipToPixel(twips, dpi = UnitConverter.DEFAULT_DPI) {
10520
+ return Math.round(twips * dpi / UnitConverter.DXA_PER_INCH);
10286
10521
  }
10287
10522
  /**
10288
10523
  * 将像素转换为 twips
@@ -10292,8 +10527,8 @@ let UnitConverter$1 = (_a = class {
10292
10527
  * @example
10293
10528
  * UnitConverter.pixelToTwip(96) // 1440
10294
10529
  */
10295
- static pixelToTwip(pixel, dpi = _a.DEFAULT_DPI) {
10296
- return Math.round(pixel * _a.DXA_PER_INCH / dpi);
10530
+ static pixelToTwip(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10531
+ return Math.round(pixel * UnitConverter.DXA_PER_INCH / dpi);
10297
10532
  }
10298
10533
  // ==================== DXA ↔ Pixels ====================
10299
10534
  /**
@@ -10304,8 +10539,8 @@ let UnitConverter$1 = (_a = class {
10304
10539
  * @example
10305
10540
  * UnitConverter.dxaToPixel(1440) // 96
10306
10541
  */
10307
- static dxaToPixel(dxa, dpi = _a.DEFAULT_DPI) {
10308
- return Math.round(dxa * dpi / _a.DXA_PER_INCH);
10542
+ static dxaToPixel(dxa, dpi = UnitConverter.DEFAULT_DPI) {
10543
+ return Math.round(dxa * dpi / UnitConverter.DXA_PER_INCH);
10309
10544
  }
10310
10545
  /**
10311
10546
  * 将像素转换为 DXA (twips)
@@ -10315,8 +10550,8 @@ let UnitConverter$1 = (_a = class {
10315
10550
  * @example
10316
10551
  * UnitConverter.pixelToDxa(96) // 1440
10317
10552
  */
10318
- static pixelToDxa(pixel, dpi = _a.DEFAULT_DPI) {
10319
- return Math.round(pixel * _a.DXA_PER_INCH / dpi);
10553
+ static pixelToDxa(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10554
+ return Math.round(pixel * UnitConverter.DXA_PER_INCH / dpi);
10320
10555
  }
10321
10556
  // ==================== EMU ↔ Pixels ====================
10322
10557
  /**
@@ -10327,8 +10562,8 @@ let UnitConverter$1 = (_a = class {
10327
10562
  * @example
10328
10563
  * UnitConverter.emuToPixel(914400) // 96
10329
10564
  */
10330
- static emuToPixel(emu, dpi = _a.DEFAULT_DPI) {
10331
- return Math.round(emu * dpi / _a.EMU_PER_INCH);
10565
+ static emuToPixel(emu, dpi = UnitConverter.DEFAULT_DPI) {
10566
+ return Math.round(emu * dpi / UnitConverter.EMU_PER_INCH);
10332
10567
  }
10333
10568
  /**
10334
10569
  * 将像素转换为 EMU
@@ -10338,8 +10573,8 @@ let UnitConverter$1 = (_a = class {
10338
10573
  * @example
10339
10574
  * UnitConverter.pixelToEmu(96) // 914400
10340
10575
  */
10341
- static pixelToEmu(pixel, dpi = _a.DEFAULT_DPI) {
10342
- return Math.round(pixel * _a.EMU_PER_INCH / dpi);
10576
+ static pixelToEmu(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10577
+ return Math.round(pixel * UnitConverter.EMU_PER_INCH / dpi);
10343
10578
  }
10344
10579
  // ==================== EMU ↔ Twips ====================
10345
10580
  /**
@@ -10350,7 +10585,7 @@ let UnitConverter$1 = (_a = class {
10350
10585
  * UnitConverter.emuToTwip(914400) // 1440
10351
10586
  */
10352
10587
  static emuToTwip(emu) {
10353
- return Math.round(emu * _a.DXA_PER_INCH / _a.EMU_PER_INCH);
10588
+ return Math.round(emu * UnitConverter.DXA_PER_INCH / UnitConverter.EMU_PER_INCH);
10354
10589
  }
10355
10590
  /**
10356
10591
  * 将 twips 转换为 EMU
@@ -10360,7 +10595,7 @@ let UnitConverter$1 = (_a = class {
10360
10595
  * UnitConverter.twipToEmu(1440) // 914400
10361
10596
  */
10362
10597
  static twipToEmu(twips) {
10363
- return Math.round(twips * _a.EMU_PER_INCH / _a.DXA_PER_INCH);
10598
+ return Math.round(twips * UnitConverter.EMU_PER_INCH / UnitConverter.DXA_PER_INCH);
10364
10599
  }
10365
10600
  // ==================== Points ↔ Pixels ====================
10366
10601
  /**
@@ -10371,8 +10606,8 @@ let UnitConverter$1 = (_a = class {
10371
10606
  * @example
10372
10607
  * UnitConverter.pointToPixel(72) // 96
10373
10608
  */
10374
- static pointToPixel(points, dpi = _a.DEFAULT_DPI) {
10375
- return Math.round(points * dpi / _a.INCH_TO_POINTS);
10609
+ static pointToPixel(points, dpi = UnitConverter.DEFAULT_DPI) {
10610
+ return Math.round(points * dpi / UnitConverter.INCH_TO_POINTS);
10376
10611
  }
10377
10612
  /**
10378
10613
  * 将像素转换为 points
@@ -10382,8 +10617,8 @@ let UnitConverter$1 = (_a = class {
10382
10617
  * @example
10383
10618
  * UnitConverter.pixelToPoint(96) // 72
10384
10619
  */
10385
- static pixelToPoint(pixel, dpi = _a.DEFAULT_DPI) {
10386
- return Math.round(pixel * _a.INCH_TO_POINTS / dpi);
10620
+ static pixelToPoint(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10621
+ return Math.round(pixel * UnitConverter.INCH_TO_POINTS / dpi);
10387
10622
  }
10388
10623
  // ==================== Inches ↔ Pixels ====================
10389
10624
  /**
@@ -10394,7 +10629,7 @@ let UnitConverter$1 = (_a = class {
10394
10629
  * @example
10395
10630
  * UnitConverter.inchToPixel(1) // 96
10396
10631
  */
10397
- static inchToPixel(inches, dpi = _a.DEFAULT_DPI) {
10632
+ static inchToPixel(inches, dpi = UnitConverter.DEFAULT_DPI) {
10398
10633
  return Math.round(inches * dpi);
10399
10634
  }
10400
10635
  /**
@@ -10405,7 +10640,7 @@ let UnitConverter$1 = (_a = class {
10405
10640
  * @example
10406
10641
  * UnitConverter.pixelToInch(96) // 1
10407
10642
  */
10408
- static pixelToInch(pixel, dpi = _a.DEFAULT_DPI) {
10643
+ static pixelToInch(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10409
10644
  return pixel / dpi;
10410
10645
  }
10411
10646
  // ==================== Centimeters ↔ Inches ====================
@@ -10417,7 +10652,7 @@ let UnitConverter$1 = (_a = class {
10417
10652
  * UnitConverter.cmToInch(2.54) // 1
10418
10653
  */
10419
10654
  static cmToInch(cm) {
10420
- return cm / _a.INCH_TO_CM;
10655
+ return cm / UnitConverter.INCH_TO_CM;
10421
10656
  }
10422
10657
  /**
10423
10658
  * 将 inches 转换为厘米
@@ -10427,7 +10662,7 @@ let UnitConverter$1 = (_a = class {
10427
10662
  * UnitConverter.inchToCm(1) // 2.54
10428
10663
  */
10429
10664
  static inchToCm(inches) {
10430
- return inches * _a.INCH_TO_CM;
10665
+ return inches * UnitConverter.INCH_TO_CM;
10431
10666
  }
10432
10667
  // ==================== Centimeters ↔ Pixels ====================
10433
10668
  /**
@@ -10438,9 +10673,9 @@ let UnitConverter$1 = (_a = class {
10438
10673
  * @example
10439
10674
  * UnitConverter.cmToPixel(2.54) // 96
10440
10675
  */
10441
- static cmToPixel(cm, dpi = _a.DEFAULT_DPI) {
10442
- const inches = _a.cmToInch(cm);
10443
- return _a.inchToPixel(inches, dpi);
10676
+ static cmToPixel(cm, dpi = UnitConverter.DEFAULT_DPI) {
10677
+ const inches = UnitConverter.cmToInch(cm);
10678
+ return UnitConverter.inchToPixel(inches, dpi);
10444
10679
  }
10445
10680
  /**
10446
10681
  * 将像素转换为厘米
@@ -10450,9 +10685,9 @@ let UnitConverter$1 = (_a = class {
10450
10685
  * @example
10451
10686
  * UnitConverter.pixelToCm(96) // 2.54
10452
10687
  */
10453
- static pixelToCm(pixel, dpi = _a.DEFAULT_DPI) {
10454
- const inches = _a.pixelToInch(pixel, dpi);
10455
- return _a.inchToCm(inches);
10688
+ static pixelToCm(pixel, dpi = UnitConverter.DEFAULT_DPI) {
10689
+ const inches = UnitConverter.pixelToInch(pixel, dpi);
10690
+ return UnitConverter.inchToCm(inches);
10456
10691
  }
10457
10692
  // ==================== Points ↔ Twips ====================
10458
10693
  /**
@@ -10463,7 +10698,7 @@ let UnitConverter$1 = (_a = class {
10463
10698
  * UnitConverter.pointToTwip(72) // 1440
10464
10699
  */
10465
10700
  static pointToTwip(points) {
10466
- return Math.round(points / _a.TWIP_TO_POINT);
10701
+ return Math.round(points / UnitConverter.TWIP_TO_POINT);
10467
10702
  }
10468
10703
  /**
10469
10704
  * 将 twips 转换为 points
@@ -10473,7 +10708,7 @@ let UnitConverter$1 = (_a = class {
10473
10708
  * UnitConverter.twipToPoint(1440) // 72
10474
10709
  */
10475
10710
  static twipToPoint(twips) {
10476
- return twips * _a.TWIP_TO_POINT;
10711
+ return twips * UnitConverter.TWIP_TO_POINT;
10477
10712
  }
10478
10713
  // ==================== 批量转换 ====================
10479
10714
  /**
@@ -10484,8 +10719,8 @@ let UnitConverter$1 = (_a = class {
10484
10719
  * @example
10485
10720
  * UnitConverter.pixelsToTwips([96, 192, 288]) // [1440, 2880, 4320]
10486
10721
  */
10487
- static pixelsToTwips(pixels, dpi = _a.DEFAULT_DPI) {
10488
- return pixels.map((px) => _a.pixelToTwip(px, dpi));
10722
+ static pixelsToTwips(pixels, dpi = UnitConverter.DEFAULT_DPI) {
10723
+ return pixels.map((px) => UnitConverter.pixelToTwip(px, dpi));
10489
10724
  }
10490
10725
  /**
10491
10726
  * 将 twips 数组转换为像素数组
@@ -10495,10 +10730,10 @@ let UnitConverter$1 = (_a = class {
10495
10730
  * @example
10496
10731
  * UnitConverter.twipsToPixels([1440, 2880, 4320]) // [96, 192, 288]
10497
10732
  */
10498
- static twipsToPixels(twips, dpi = _a.DEFAULT_DPI) {
10499
- return twips.map((t) => _a.twipToPixel(t, dpi));
10733
+ static twipsToPixels(twips, dpi = UnitConverter.DEFAULT_DPI) {
10734
+ return twips.map((t) => UnitConverter.twipToPixel(t, dpi));
10500
10735
  }
10501
- }, _a.INCH_TO_CM = 2.54, _a.INCH_TO_POINTS = 72, _a.TWIP_TO_POINT = 1 / 20, _a.POINT_TO_INCH = 1 / 72, _a.DEFAULT_DPI = 96, _a.EMU_PER_INCH = 914400, _a.DXA_PER_INCH = 1440, _a);
10736
+ };
10502
10737
  const DEFAULT_WIDTH = UnitConverter$1.pixelToDxa(100);
10503
10738
  class WtblRowColumnOps {
10504
10739
  /**
@@ -10716,191 +10951,6 @@ class WtblCellIterator {
10716
10951
  }
10717
10952
  }
10718
10953
  }
10719
- class Region {
10720
- constructor(options) {
10721
- this.start = {
10722
- row: 0,
10723
- col: 0
10724
- };
10725
- this.end = {
10726
- row: 0,
10727
- col: 0
10728
- };
10729
- this.id = options.id ?? uuid();
10730
- this.table = options.table;
10731
- if (options.start) {
10732
- this.start = options.start;
10733
- }
10734
- if (options.end) {
10735
- this.end = options.end;
10736
- }
10737
- }
10738
- get rowCount() {
10739
- return this.end.row - this.start.row + 1;
10740
- }
10741
- get colCount() {
10742
- return this.end.col - this.start.col + 1;
10743
- }
10744
- get cellCount() {
10745
- return this.table.getCellCount({
10746
- startColIdx: this.start.col,
10747
- startRowIdx: this.start.row,
10748
- endColIdx: this.end.col,
10749
- endRowIdx: this.end.row
10750
- });
10751
- }
10752
- /**
10753
- * 检查指定的行列位置是否在当前区域内
10754
- * @param row 行号
10755
- * @param col 列号
10756
- * @returns 是否在区域内
10757
- */
10758
- contains(row, col) {
10759
- return row >= this.start.row && row <= this.end.row && col >= this.start.col && col <= this.end.col;
10760
- }
10761
- toJSON() {
10762
- return {
10763
- type: this.type,
10764
- start: {
10765
- row: this.start.row,
10766
- col: this.start.col
10767
- },
10768
- end: {
10769
- row: this.end.row,
10770
- col: this.end.col
10771
- }
10772
- };
10773
- }
10774
- }
10775
- class RepeatingRegion extends Region {
10776
- constructor(options) {
10777
- super(options);
10778
- this.type = "repeating";
10779
- this.valuePath = options.valuePath;
10780
- this.name = options.name;
10781
- this.widgetMeta = {
10782
- props: {
10783
- quickFill: false
10784
- }
10785
- };
10786
- }
10787
- /**
10788
- * 序列化为 JSON 对象
10789
- */
10790
- toJSON() {
10791
- const json = super.toJSON();
10792
- return Object.assign(json, {
10793
- name: this.name,
10794
- valuePath: this.valuePath
10795
- });
10796
- }
10797
- /**
10798
- * 从 JSON 对象还原
10799
- */
10800
- static fromJSON(json, table) {
10801
- const region = new RepeatingRegion({
10802
- table,
10803
- start: {
10804
- row: json.start.row,
10805
- col: json.start.col
10806
- },
10807
- end: {
10808
- row: json.end.row,
10809
- col: json.end.col
10810
- },
10811
- name: json.name,
10812
- valuePath: json.valuePath
10813
- });
10814
- return region;
10815
- }
10816
- }
10817
- class BoundedItemRegion extends Region {
10818
- constructor(options) {
10819
- super(options);
10820
- this.type = "boundedItem";
10821
- if (options.parent) {
10822
- this.parent = options.parent;
10823
- }
10824
- }
10825
- remove() {
10826
- this.parent.removeItemRegion();
10827
- }
10828
- }
10829
- class BoundedRegion extends Region {
10830
- constructor(options) {
10831
- super(options);
10832
- this.type = "bounded";
10833
- this.name = options.name;
10834
- this.valuePath = options.valuePath;
10835
- this.widgetMeta = {
10836
- props: {
10837
- autoFill: true,
10838
- fillDirection: "x"
10839
- }
10840
- };
10841
- }
10842
- /**
10843
- * 序列化为 JSON 对象
10844
- */
10845
- toJSON() {
10846
- const json = super.toJSON();
10847
- return Object.assign(json, {
10848
- name: this.name,
10849
- valuePath: this.valuePath
10850
- });
10851
- }
10852
- /**
10853
- * 从 JSON 对象还原
10854
- */
10855
- static fromJSON(json, table) {
10856
- const region = new BoundedRegion({
10857
- table,
10858
- start: {
10859
- row: json.start.row,
10860
- col: json.start.col
10861
- },
10862
- end: {
10863
- row: json.end.row,
10864
- col: json.end.col
10865
- },
10866
- name: json.name,
10867
- valuePath: json.valuePath
10868
- });
10869
- return region;
10870
- }
10871
- setItemRegion(options) {
10872
- const region = new BoundedItemRegion({
10873
- table: this.table,
10874
- parent: this,
10875
- ...options
10876
- });
10877
- this.itemRegion = region;
10878
- this.table.forEachCell({
10879
- startRowIdx: options.start.row,
10880
- startColIdx: options.start.col,
10881
- endRowIdx: options.end.row,
10882
- endColIdx: options.end.col,
10883
- callback: (cell) => {
10884
- cell.boundedItemId = region.id;
10885
- }
10886
- });
10887
- return region;
10888
- }
10889
- removeItemRegion() {
10890
- if (this.itemRegion) {
10891
- this.table.forEachCell({
10892
- startRowIdx: this.itemRegion.start.row,
10893
- startColIdx: this.itemRegion.start.col,
10894
- endRowIdx: this.itemRegion.end.row,
10895
- endColIdx: this.itemRegion.end.col,
10896
- callback: (cell) => {
10897
- cell.boundedItemId = void 0;
10898
- }
10899
- });
10900
- }
10901
- this.itemRegion = void 0;
10902
- }
10903
- }
10904
10954
  class WtblRegionManager {
10905
10955
  /**
10906
10956
  * 根据 region id 查找对应的 region
@@ -10984,6 +11034,10 @@ class CellCollector {
10984
11034
  this.boundedItemGroups = /* @__PURE__ */ new Map();
10985
11035
  this.collect();
10986
11036
  }
11037
+ mergeGroups;
11038
+ repeatingGroups;
11039
+ boundedGroups;
11040
+ boundedItemGroups;
10987
11041
  /**
10988
11042
  * 单次遍历收集所有数据
10989
11043
  */
@@ -11368,11 +11422,18 @@ class WtblSerialization {
11368
11422
  }
11369
11423
  }
11370
11424
  class Wtbl extends ModelGroup {
11425
+ type = "table";
11426
+ attrs;
11427
+ style;
11428
+ sectionId;
11429
+ rawProperties;
11430
+ colWidths;
11431
+ tableProperties;
11432
+ // 显式声明继承自 ModelGroup
11433
+ regions = [];
11434
+ pendingRecalculate = false;
11371
11435
  constructor(options) {
11372
11436
  super(options.id);
11373
- this.type = "table";
11374
- this.regions = [];
11375
- this.pendingRecalculate = false;
11376
11437
  this.children = options.rows;
11377
11438
  this.children.forEach((row) => {
11378
11439
  row.parent = this;
@@ -11570,6 +11631,22 @@ const DEFAULT_FONT_SIZE = 16;
11570
11631
  const DEFAULT_TEXT_COLOR = "black";
11571
11632
  const ZERO_WIDTH_SPACE = "​";
11572
11633
  class WrText extends ModelNode {
11634
+ text;
11635
+ rPr;
11636
+ // 字符属性(Run Properties)
11637
+ rawProperties;
11638
+ extra;
11639
+ widgetMeta;
11640
+ fieldMeta;
11641
+ valuePath;
11642
+ isComposition;
11643
+ isPlaceholder;
11644
+ /** 缓存的有效样式 */
11645
+ _cachedEffectiveRPr;
11646
+ /** 缓存依赖的样式 ID */
11647
+ _cachedStyleId;
11648
+ /** 缓存依赖的 rPr 引用 */
11649
+ _cachedRPr;
11573
11650
  constructor(options) {
11574
11651
  const {
11575
11652
  text,
@@ -12292,6 +12369,10 @@ const IMAGE_TEMPLATE = {
12292
12369
  ]
12293
12370
  };
12294
12371
  class WrImage extends ModelNode {
12372
+ image;
12373
+ rawProperties;
12374
+ extra;
12375
+ widgetMeta;
12295
12376
  constructor(options) {
12296
12377
  const { image, rawProperties, extra, widgetMeta, id, parent } = options;
12297
12378
  super(id);
@@ -12473,9 +12554,25 @@ class WrImage extends ModelNode {
12473
12554
  }
12474
12555
  }
12475
12556
  class Wp extends ModelGroup {
12557
+ type = "paragraph";
12558
+ attrs;
12559
+ styleId;
12560
+ sectionId;
12561
+ // 所属 section 的 id
12562
+ pPr;
12563
+ // 段落属性(Paragraph Properties)
12564
+ rawProperties;
12565
+ // 父节点引用(Wbody 或 Wtc)
12566
+ /** 缓存的样式集合引用 */
12567
+ _cachedStyles;
12568
+ /** 缓存的有效段落样式 */
12569
+ _cachedEffectivePPr;
12570
+ /** 缓存依赖的样式 ID */
12571
+ _cachedStyleId;
12572
+ /** 缓存依赖的 pPr 引用 */
12573
+ _cachedPPr;
12476
12574
  constructor(runs, attrs, pPr, rawProperties, styleId, id) {
12477
12575
  super(id);
12478
- this.type = "paragraph";
12479
12576
  this.children = runs;
12480
12577
  if (attrs) this.attrs = attrs;
12481
12578
  if (pPr) this.pPr = pPr;
@@ -12820,8 +12917,17 @@ class Wp extends ModelGroup {
12820
12917
  }
12821
12918
  }
12822
12919
  class Wsection {
12920
+ id;
12921
+ type = "section";
12922
+ // 页面配置属性
12923
+ pageSize;
12924
+ margins;
12925
+ columns;
12926
+ docGrid;
12927
+ // 原始属性和数据
12928
+ attrs;
12929
+ rawProperties;
12823
12930
  constructor(attrs, pageSize, margins, columns, docGrid, rawProperties, id) {
12824
- this.type = "section";
12825
12931
  this.id = id || uuid();
12826
12932
  if (attrs) this.attrs = attrs;
12827
12933
  if (pageSize) this.pageSize = pageSize;
@@ -13004,10 +13110,10 @@ class Wsection {
13004
13110
  }
13005
13111
  }
13006
13112
  class Wbody extends ModelGroup {
13113
+ type = "body";
13007
13114
  // 父节点引用(Wdocument)
13008
13115
  constructor(children, id) {
13009
13116
  super(id);
13010
- this.type = "body";
13011
13117
  this.children = children;
13012
13118
  this.children.forEach((child) => {
13013
13119
  child.parent = this;
@@ -13091,8 +13197,13 @@ class Wbody extends ModelGroup {
13091
13197
  }
13092
13198
  }
13093
13199
  class Wdocument {
13200
+ id;
13201
+ type = "document";
13202
+ attrs;
13203
+ modelMeta;
13204
+ body;
13205
+ root;
13094
13206
  constructor(options) {
13095
- this.type = "document";
13096
13207
  this.id = options.id || uuid();
13097
13208
  this.body = options.body;
13098
13209
  this.body.parent = this;
@@ -13173,9 +13284,7 @@ function getBaseMetaInfo(node) {
13173
13284
  };
13174
13285
  }
13175
13286
  class HitHandlerRegistry {
13176
- constructor() {
13177
- this.handlers = /* @__PURE__ */ new Map();
13178
- }
13287
+ handlers = /* @__PURE__ */ new Map();
13179
13288
  register(component, handler) {
13180
13289
  this.handlers.set(component, handler);
13181
13290
  }
@@ -13609,6 +13718,7 @@ function getIntervalSide(intervals, actualX) {
13609
13718
  return null;
13610
13719
  }
13611
13720
  class PageHitHandler {
13721
+ registry;
13612
13722
  constructor(registry2) {
13613
13723
  this.registry = registry2;
13614
13724
  }
@@ -13672,6 +13782,7 @@ class PageHitHandler {
13672
13782
  }
13673
13783
  }
13674
13784
  class ParagraphHitHandler {
13785
+ registry;
13675
13786
  constructor(registry2) {
13676
13787
  this.registry = registry2;
13677
13788
  }
@@ -13696,6 +13807,7 @@ class ParagraphHitHandler {
13696
13807
  }
13697
13808
  }
13698
13809
  class TableCellHitHandler {
13810
+ registry;
13699
13811
  constructor(registry2) {
13700
13812
  this.registry = registry2;
13701
13813
  }
@@ -14275,8 +14387,11 @@ const SelectionMode = {
14275
14387
  Tds: "Tds"
14276
14388
  };
14277
14389
  class CommandBase {
14390
+ doc;
14391
+ snapshot;
14392
+ postCommandContext = null;
14393
+ output;
14278
14394
  constructor(doc, payload) {
14279
- this.postCommandContext = null;
14280
14395
  this.doc = doc;
14281
14396
  this.payload = payload;
14282
14397
  }
@@ -14839,6 +14954,11 @@ class CommandBase {
14839
14954
  }
14840
14955
  }
14841
14956
  class InputComposition {
14957
+ doc;
14958
+ modelId;
14959
+ modelType;
14960
+ wrid;
14961
+ cloneNode;
14842
14962
  constructor(doc, text) {
14843
14963
  this.doc = doc;
14844
14964
  this.create(text);
@@ -15970,7 +16090,10 @@ const __vite_glob_0_9$2 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.d
15970
16090
  __proto__: null,
15971
16091
  InsertField
15972
16092
  }, Symbol.toStringTag, { value: "Module" }));
15973
- const _AssetHelper = class _AssetHelper {
16093
+ class AssetHelper {
16094
+ static minioBasePath = "/minio";
16095
+ static transfer = null;
16096
+ static fileUrlMap = /* @__PURE__ */ new Map();
15974
16097
  static init(opts) {
15975
16098
  this.transfer = opts.transfer;
15976
16099
  }
@@ -16030,11 +16153,7 @@ const _AssetHelper = class _AssetHelper {
16030
16153
  this.fileUrlMap.forEach((url2) => URL.revokeObjectURL(url2));
16031
16154
  this.fileUrlMap.clear();
16032
16155
  }
16033
- };
16034
- _AssetHelper.minioBasePath = "/minio";
16035
- _AssetHelper.transfer = null;
16036
- _AssetHelper.fileUrlMap = /* @__PURE__ */ new Map();
16037
- let AssetHelper = _AssetHelper;
16156
+ }
16038
16157
  class InsertImage extends CommandBase {
16039
16158
  constructor(doc, payload) {
16040
16159
  super(doc, payload);
@@ -16235,6 +16354,7 @@ function distributeInteger(total, count) {
16235
16354
  return result;
16236
16355
  }
16237
16356
  class InsertTable extends CommandBase {
16357
+ wpid;
16238
16358
  constructor(doc, payload) {
16239
16359
  super(doc, payload);
16240
16360
  }
@@ -16556,9 +16676,13 @@ const __vite_glob_0_18$1 = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.
16556
16676
  SetAlign
16557
16677
  }, Symbol.toStringTag, { value: "Module" }));
16558
16678
  class SetStyleBase extends CommandBase {
16679
+ /**
16680
+ * 是否需要在执行后重新计算 postCommandContext
16681
+ * 子类可以在构造函数中设置此属性,默认 true
16682
+ */
16683
+ needsCalculatePostCommandContext = true;
16559
16684
  constructor(doc, payload) {
16560
16685
  super(doc, payload);
16561
- this.needsCalculatePostCommandContext = true;
16562
16686
  }
16563
16687
  async execute() {
16564
16688
  const cursor = this.doc.cursorManager;
@@ -16934,13 +17058,17 @@ function buildCommandMap() {
16934
17058
  });
16935
17059
  return map;
16936
17060
  }
16937
- const _CommandManager = class _CommandManager {
17061
+ class CommandManager {
17062
+ registry = /* @__PURE__ */ new Map();
17063
+ doc;
17064
+ undoStack = [];
17065
+ redoStack = [];
17066
+ composition;
17067
+ // 命令注册表 - 通过动态导入构建
17068
+ static COMMAND_MAP = buildCommandMap();
16938
17069
  constructor(doc) {
16939
- this.registry = /* @__PURE__ */ new Map();
16940
- this.undoStack = [];
16941
- this.redoStack = [];
16942
17070
  this.doc = doc;
16943
- Object.entries(_CommandManager.COMMAND_MAP).forEach(([name, CommandClass]) => {
17071
+ Object.entries(CommandManager.COMMAND_MAP).forEach(([name, CommandClass]) => {
16944
17072
  this.register(name, CommandClass);
16945
17073
  });
16946
17074
  }
@@ -17003,17 +17131,31 @@ const _CommandManager = class _CommandManager {
17003
17131
  callback(data, output);
17004
17132
  }
17005
17133
  }
17006
- };
17007
- _CommandManager.COMMAND_MAP = buildCommandMap();
17008
- let CommandManager = _CommandManager;
17134
+ }
17009
17135
  class LayoutNode {
17136
+ /** 唯一标识符 */
17137
+ id;
17138
+ /** 组件类型 */
17139
+ component;
17140
+ /** 所属文档 */
17141
+ doc;
17142
+ /** 父节点 */
17143
+ parent;
17144
+ /** 在父容器中的相对 X 坐标 */
17145
+ x = 0;
17146
+ /** 在父容器中的相对 Y 坐标 */
17147
+ y = 0;
17148
+ /** 布局后的绝对 X 坐标 */
17149
+ layoutX = 0;
17150
+ /** 布局后的绝对 Y 坐标 */
17151
+ layoutY = 0;
17152
+ modelRef;
17153
+ // valuePath?: string;
17154
+ /** 宽度 */
17155
+ _width = 0;
17156
+ /** 高度 */
17157
+ _height = 0;
17010
17158
  constructor(options) {
17011
- this.x = 0;
17012
- this.y = 0;
17013
- this.layoutX = 0;
17014
- this.layoutY = 0;
17015
- this._width = 0;
17016
- this._height = 0;
17017
17159
  this.id = options.id ?? uuid();
17018
17160
  this.doc = options.doc;
17019
17161
  if (options.x !== void 0) this.x = options.x;
@@ -17070,10 +17212,11 @@ class LayoutNode {
17070
17212
  }
17071
17213
  }
17072
17214
  class LayoutGroup extends LayoutNode {
17215
+ /** 子节点列表 */
17216
+ children = [];
17217
+ _padding = [0, 0, 0, 0];
17073
17218
  constructor(options) {
17074
17219
  super(options);
17075
- this.children = [];
17076
- this._padding = [0, 0, 0, 0];
17077
17220
  }
17078
17221
  get padding() {
17079
17222
  return this._padding ?? [0, 0, 0, 0];
@@ -17216,19 +17359,35 @@ class LayoutGroup extends LayoutNode {
17216
17359
  }
17217
17360
  }
17218
17361
  class TextRun extends LayoutNode {
17362
+ component = BuiltinComponentTypeConst.Text;
17363
+ /** 文本内容 */
17364
+ text = "";
17365
+ /** 字号 */
17366
+ fontSize = DEFAULT_FONT_SIZE;
17367
+ /** 字体 */
17368
+ fontFamily = "Roboto,RobotoDraft,Helvetica,Arial,sans-serif";
17369
+ /** 文字颜色 */
17370
+ color = DEFAULT_TEXT_COLOR;
17371
+ /** 加粗 */
17372
+ bold;
17373
+ /** 斜体 */
17374
+ italic;
17375
+ /** 下划线 */
17376
+ underline;
17377
+ /** 删除线 */
17378
+ strike;
17379
+ /** 字间距 */
17380
+ letterSpacing = 0;
17381
+ /** 文字对齐样式 */
17382
+ textAlign = "left";
17383
+ charMetrics = [];
17384
+ isPlaceholder = false;
17385
+ isComposition = false;
17386
+ lineHeight = 1.6;
17387
+ ascent;
17388
+ descent;
17219
17389
  constructor(options) {
17220
17390
  super(options);
17221
- this.component = BuiltinComponentTypeConst.Text;
17222
- this.text = "";
17223
- this.fontSize = DEFAULT_FONT_SIZE;
17224
- this.fontFamily = "Roboto,RobotoDraft,Helvetica,Arial,sans-serif";
17225
- this.color = DEFAULT_TEXT_COLOR;
17226
- this.letterSpacing = 0;
17227
- this.textAlign = "left";
17228
- this.charMetrics = [];
17229
- this.isPlaceholder = false;
17230
- this.isComposition = false;
17231
- this.lineHeight = 1.6;
17232
17391
  const { text, modelRef } = options;
17233
17392
  this.text = text;
17234
17393
  this.isPlaceholder = options.isPlaceholder || false;
@@ -17316,12 +17475,377 @@ class TextRun extends LayoutNode {
17316
17475
  return layoutStyle;
17317
17476
  }
17318
17477
  }
17478
+ class Paragraph extends LayoutGroup {
17479
+ type = "paragraph";
17480
+ component = BuiltinComponentTypeConst.Paragraph;
17481
+ baseline = 0;
17482
+ // 基线位置,默认为 0,表示与段落顶部对齐
17483
+ // backgroundColor?: string = 'rgba(0,0,0,0.06)';
17484
+ // borderTop?: Border = {
17485
+ // color: '#f30',
17486
+ // width: 1,
17487
+ // };
17488
+ // borderLeft?: Border = {
17489
+ // color: '#f90',
17490
+ // width: 1,
17491
+ // };
17492
+ // borderRight?: Border = {
17493
+ // color: '#f444',
17494
+ // width: 1,
17495
+ // };
17496
+ // borderBottom?: Border = {
17497
+ // color: '#f90',
17498
+ // width: 1,
17499
+ // };
17500
+ constructor(options) {
17501
+ super(options);
17502
+ const run = TextRun.createEmptyRun(this.doc);
17503
+ this.addChild(run);
17504
+ }
17505
+ /**
17506
+ * 重写 addChild 方法,添加后置钩子
17507
+ */
17508
+ addChild(child) {
17509
+ const firstChild = this.getFirstChild();
17510
+ if (firstChild instanceof TextRun && firstChild.isPlaceholder) {
17511
+ this.removeChildAt(0);
17512
+ }
17513
+ super.addChild(child);
17514
+ this.onChildAdded(child);
17515
+ }
17516
+ /**
17517
+ * 子节点添加后的钩子
17518
+ * @param child 新添加的子节点
17519
+ */
17520
+ onChildAdded(child) {
17521
+ const lineHeight = "lineHeight" in child ? child.lineHeight : 1;
17522
+ this.height = Math.max(this.height, child.height * lineHeight);
17523
+ }
17524
+ get width() {
17525
+ return this.parent.contentMaxWidth;
17526
+ }
17527
+ getContextWidth() {
17528
+ return this.getChildren().reduce((sum, run) => sum + run.width, 0);
17529
+ }
17530
+ /**
17531
+ * 获取剩余空间
17532
+ */
17533
+ getRemainingSize() {
17534
+ const contentWidth = this.getContextWidth();
17535
+ return this.width - contentWidth;
17536
+ }
17537
+ layout(x2, y2) {
17538
+ this.layoutX = x2;
17539
+ this.layoutY = y2;
17540
+ this.applyStyle();
17541
+ this.applyBaseline();
17542
+ this.forEachChild((child) => {
17543
+ if (child instanceof TextRun) {
17544
+ child.layout(this.layoutX + child.x, this.layoutY + child.y);
17545
+ }
17546
+ });
17547
+ }
17548
+ applyStyle() {
17549
+ const wp = this.doc.layoutMapper.getModelNodeById(this.modelRef.id);
17550
+ let offset2 = 0;
17551
+ if (wp?.pPr?.alignment === "center") {
17552
+ offset2 = (this.width - this.getContextWidth()) / 2;
17553
+ } else if (wp?.pPr?.alignment === "right") {
17554
+ offset2 = this.width - this.getContextWidth();
17555
+ }
17556
+ this.forEachChild((child) => {
17557
+ child.x += offset2;
17558
+ });
17559
+ }
17560
+ /**
17561
+ * 基于基线调整文本垂直位置
17562
+ */
17563
+ applyBaseline() {
17564
+ const maxTextRun = this.getMaxTextRun();
17565
+ if (!maxTextRun) return;
17566
+ const extra = this.height - (maxTextRun.ascent + maxTextRun.descent);
17567
+ const baseLine = extra / 2 + maxTextRun.ascent;
17568
+ this.baseline = baseLine;
17569
+ this.forEachChild((child) => {
17570
+ if (child instanceof TextRun) {
17571
+ child.y = baseLine - (child.ascent ?? 0);
17572
+ }
17573
+ });
17574
+ }
17575
+ /**
17576
+ * 获取段落中 height*lineHeight 最大的文本 run
17577
+ */
17578
+ getMaxTextRun() {
17579
+ let maxTextRun = null;
17580
+ let maxHeight = 0;
17581
+ this.forEachChild((child) => {
17582
+ if (child instanceof TextRun) {
17583
+ const height = child.height * child.lineHeight;
17584
+ if (height > maxHeight) {
17585
+ maxHeight = height;
17586
+ maxTextRun = child;
17587
+ }
17588
+ }
17589
+ });
17590
+ return maxTextRun;
17591
+ }
17592
+ }
17593
+ class Table extends LayoutGroup {
17594
+ type = "table";
17595
+ component = BuiltinComponentTypeConst.Table;
17596
+ cellPadding = [...DEFAULT_CELL_PADDING];
17597
+ // 列宽定义(DXA 单位,类似 HTML colgroup)
17598
+ colWidths;
17599
+ /** 表格边框 */
17600
+ border;
17601
+ /** 表格背景色 */
17602
+ backgroundColor;
17603
+ constructor(options) {
17604
+ super(options);
17605
+ this.colWidths = options.colWidths;
17606
+ }
17607
+ get width() {
17608
+ const totalWidth = this.colWidths?.reduce((a, b2) => a + b2, 0) || 0;
17609
+ return totalWidth;
17610
+ }
17611
+ redistribute() {
17612
+ const rows = this.getChildren();
17613
+ const multiRowCells = [];
17614
+ rows.forEach((row, rowIndex) => {
17615
+ row.getChildren().forEach((cell, cellIndex) => {
17616
+ if (cell.isMerged) {
17617
+ return;
17618
+ }
17619
+ const cellHeight = cell.getMinHeight();
17620
+ const rowspan = cell.rowspan || 1;
17621
+ if (rowspan === 1) {
17622
+ row.height = Math.max(row.height, cellHeight);
17623
+ } else {
17624
+ multiRowCells.push({
17625
+ cellHeight,
17626
+ rowIndex,
17627
+ rowspan
17628
+ });
17629
+ }
17630
+ });
17631
+ });
17632
+ multiRowCells.forEach((e) => {
17633
+ const { cellHeight, rowIndex, rowspan } = e;
17634
+ const crossRows = rows.slice(rowIndex, rowIndex + rowspan);
17635
+ const currentTotalHeight = crossRows.reduce((sum, r) => sum + r.height, 0);
17636
+ if (cellHeight > currentTotalHeight) {
17637
+ const extraHeight = cellHeight - currentTotalHeight;
17638
+ const lastRow = crossRows[crossRows.length - 1];
17639
+ if (lastRow) {
17640
+ lastRow.height += extraHeight;
17641
+ }
17642
+ }
17643
+ });
17644
+ const MIN_ROW_HEIGHT = 20;
17645
+ rows.forEach((row) => {
17646
+ if (row.height === 0) {
17647
+ const hasContent = row.getChildren().some((cell) => !cell.isMerged);
17648
+ if (hasContent) {
17649
+ row.height = MIN_ROW_HEIGHT;
17650
+ }
17651
+ }
17652
+ });
17653
+ this.height = rows.reduce((sum, row) => {
17654
+ row.y = sum;
17655
+ return sum + row.height;
17656
+ }, 0);
17657
+ }
17658
+ layout(x2, y2) {
17659
+ this.layoutX = x2;
17660
+ this.layoutY = y2;
17661
+ this.forEachChild((child) => {
17662
+ child.layout(this.layoutX, this.layoutY + child.y);
17663
+ });
17664
+ }
17665
+ updateCellOffsetInfo() {
17666
+ const map = /* @__PURE__ */ new Map();
17667
+ const rows = this.getChildren();
17668
+ rows.forEach((row, rowIndex) => {
17669
+ row.getChildren().forEach((cell, colIndex) => {
17670
+ if (cell.mergeFromId) {
17671
+ cell.mergeRefColOffset = colIndex - map.get(cell.mergeFromId).colIndex;
17672
+ cell.mergeRefRowOffset = rowIndex - map.get(cell.mergeFromId).rowIndex;
17673
+ } else {
17674
+ map.set(cell.id, { rowIndex, colIndex });
17675
+ }
17676
+ });
17677
+ });
17678
+ map.clear();
17679
+ }
17680
+ }
17681
+ class Page extends LayoutGroup {
17682
+ // doc: Doc;
17683
+ section;
17684
+ component = BuiltinComponentTypeConst.Paper;
17685
+ constructor(options) {
17686
+ super(options);
17687
+ this.section = options.section;
17688
+ }
17689
+ get width() {
17690
+ return this.section.pageSize?.width;
17691
+ }
17692
+ get height() {
17693
+ return this.section.pageSize?.height;
17694
+ }
17695
+ get padding() {
17696
+ return this.section.pagePadding;
17697
+ }
17698
+ get contentMaxWidth() {
17699
+ return this.width - this.padding[1] - this.padding[3];
17700
+ }
17701
+ get contentMaxHeight() {
17702
+ return this.height - this.padding[0] - this.padding[2];
17703
+ }
17704
+ getContentHeight() {
17705
+ const contentHeight = this.getChildren().reduce((sum, child) => sum + child.height, 0);
17706
+ return contentHeight;
17707
+ }
17708
+ getRemainingSize() {
17709
+ return this.contentMaxHeight - this.getContentHeight();
17710
+ }
17711
+ layout() {
17712
+ this.forEachChild((child) => {
17713
+ child.layout(this.pl, this.pt + child.y);
17714
+ });
17715
+ }
17716
+ }
17717
+ class Section {
17718
+ id;
17719
+ pageSize = {
17720
+ height: 842,
17721
+ // A4 height in px (297mm ≈ 842px at 96 DPI)
17722
+ width: 595
17723
+ // A4 width in px (210mm ≈ 595px at 96 DPI)
17724
+ };
17725
+ pagePadding = [0, 0, 0, 0];
17726
+ // 上右下左 (px)
17727
+ bgColor;
17728
+ constructor(options = {}) {
17729
+ this.id = uuid();
17730
+ const { pageSize, pagePadding } = options;
17731
+ this.pageSize = pageSize ?? this.pageSize;
17732
+ this.pagePadding = pagePadding ?? this.pagePadding;
17733
+ this.bgColor = options.bgColor ?? "#ffffff";
17734
+ }
17735
+ /**
17736
+ * 从 Wsection 模型创建 Section 视图
17737
+ * @param wsection Word 文档的分节模型
17738
+ * @param dpi 屏幕 DPI(默认 96)
17739
+ * @returns Section 视图实例
17740
+ */
17741
+ static fromXML(wsection, dpi = 96) {
17742
+ const section = new Section();
17743
+ if (wsection.pageSize?.width && wsection.pageSize?.height) {
17744
+ section.pageSize = {
17745
+ width: UnitConverter$1.twipToPixel(wsection.pageSize.width, dpi),
17746
+ height: UnitConverter$1.twipToPixel(wsection.pageSize.height, dpi)
17747
+ };
17748
+ }
17749
+ if (wsection.margins) {
17750
+ const top = wsection.margins.top ? UnitConverter$1.twipToPixel(wsection.margins.top, dpi) : 0;
17751
+ const right = wsection.margins.right ? UnitConverter$1.twipToPixel(wsection.margins.right, dpi) : 0;
17752
+ const bottom = wsection.margins.bottom ? UnitConverter$1.twipToPixel(wsection.margins.bottom, dpi) : 0;
17753
+ const left = wsection.margins.left ? UnitConverter$1.twipToPixel(wsection.margins.left, dpi) : 0;
17754
+ section.pagePadding = [top, right, bottom, left];
17755
+ }
17756
+ return section;
17757
+ }
17758
+ /**
17759
+ * 获取内容区域宽度(页面宽度 - 左边距 - 右边距)
17760
+ * @returns 内容宽度(px)
17761
+ */
17762
+ getContentWidth() {
17763
+ const padding = this.pagePadding ?? [0, 0, 0, 0];
17764
+ const [, right, , left] = padding;
17765
+ return this.pageSize?.width ? this.pageSize.width - left - right : 0;
17766
+ }
17767
+ /**
17768
+ * 获取内容区域高度(页面高度 - 上边距 - 下边距)
17769
+ * @returns 内容高度(px)
17770
+ */
17771
+ getContentHeight() {
17772
+ const padding = this.pagePadding ?? [0, 0, 0, 0];
17773
+ const [top, , bottom] = padding;
17774
+ return this.pageSize?.height ? this.pageSize.height - top - bottom : 0;
17775
+ }
17776
+ /**
17777
+ * 解析数值:支持多种单位格式
17778
+ * @param value 数值字符串或数字
17779
+ * @param defaultUnit 默认单位('twip' | 'px' | 'mm' | 'cm' | 'inch')
17780
+ * @param dpi 屏幕 DPI(默认 96)
17781
+ * @returns 转换后的 px 值
17782
+ */
17783
+ static parseValue(value, defaultUnit = "px", dpi = 96) {
17784
+ if (typeof value === "number") {
17785
+ return Section.convertToPixel(value, defaultUnit, dpi);
17786
+ }
17787
+ const valueStr = String(value).trim();
17788
+ const unitMatch = valueStr.match(/^([\d.]+)\s*(twip|pt|px|mm|cm|in|inch)?$/i);
17789
+ if (!unitMatch) {
17790
+ return 0;
17791
+ }
17792
+ const numValue = parseFloat(unitMatch[1] ?? "0");
17793
+ const unit = (unitMatch[2] || defaultUnit).toLowerCase();
17794
+ return Section.convertToPixel(numValue, unit, dpi);
17795
+ }
17796
+ /**
17797
+ * 单位转换为 px
17798
+ * @param value 数值
17799
+ * @param unit 单位
17800
+ * @param dpi 屏幕 DPI(默认 96)
17801
+ * @returns px 值
17802
+ */
17803
+ static convertToPixel(value, unit, dpi) {
17804
+ switch (unit) {
17805
+ case "twip":
17806
+ return UnitConverter$1.twipToPixel(value, dpi);
17807
+ case "pt":
17808
+ return UnitConverter$1.pointToPixel(value, dpi);
17809
+ case "px":
17810
+ return Math.round(value);
17811
+ case "mm":
17812
+ return UnitConverter$1.cmToPixel(value / 10, dpi);
17813
+ case "cm":
17814
+ return UnitConverter$1.cmToPixel(value, dpi);
17815
+ case "in":
17816
+ case "inch":
17817
+ return UnitConverter$1.inchToPixel(value, dpi);
17818
+ default:
17819
+ return Math.round(value);
17820
+ }
17821
+ }
17822
+ /**
17823
+ * 获取页面尺寸信息(用于调试)
17824
+ * @returns 格式化的页面信息
17825
+ */
17826
+ toString() {
17827
+ const width = this.pageSize?.width ?? 0;
17828
+ const height = this.pageSize?.height ?? 0;
17829
+ const padding = this.pagePadding ?? [0, 0, 0, 0];
17830
+ const [top, right, bottom, left] = padding;
17831
+ const contentWidth = this.getContentWidth();
17832
+ const contentHeight = this.getContentHeight();
17833
+ return [
17834
+ `Page Size: ${width}px × ${height}px`,
17835
+ `Margins: top=${top}px, right=${right}px, bottom=${bottom}px, left=${left}px`,
17836
+ `Content: ${contentWidth}px × ${contentHeight}px`
17837
+ ].join("\n");
17838
+ }
17839
+ }
17319
17840
  class TextWidget extends TextRun {
17841
+ widgetMeta;
17842
+ valuePath;
17843
+ isEmptyPlaceholder = false;
17844
+ isIconPlaceholder = false;
17845
+ isSpacePlaceholder = false;
17846
+ widgetOption;
17320
17847
  constructor(options) {
17321
17848
  super(options);
17322
- this.isEmptyPlaceholder = false;
17323
- this.isIconPlaceholder = false;
17324
- this.isSpacePlaceholder = false;
17325
17849
  this.widgetMeta = options.widgetMeta;
17326
17850
  this.valuePath = options.valuePath;
17327
17851
  this.isEmptyPlaceholder = options.isEmptyPlaceholder ?? false;
@@ -17330,6 +17854,150 @@ class TextWidget extends TextRun {
17330
17854
  this.widgetOption = options.widgetOption;
17331
17855
  }
17332
17856
  }
17857
+ class LayoutContext {
17858
+ type = "page";
17859
+ doc;
17860
+ section;
17861
+ page;
17862
+ cell;
17863
+ paragraph;
17864
+ layoutRun;
17865
+ modelRef;
17866
+ constructor(options) {
17867
+ const { type: type4, doc, section, page, cell, paragraph, layoutRun } = options;
17868
+ this.type = type4;
17869
+ this.doc = doc;
17870
+ this.section = section;
17871
+ this.page = page;
17872
+ this.cell = cell;
17873
+ this.paragraph = paragraph;
17874
+ this.layoutRun = layoutRun;
17875
+ }
17876
+ get container() {
17877
+ if (this.type === "cell") {
17878
+ return this.cell;
17879
+ } else {
17880
+ return this.page;
17881
+ }
17882
+ }
17883
+ updateSection(section) {
17884
+ this.section = section;
17885
+ }
17886
+ updatePage(page) {
17887
+ this.page = page;
17888
+ this.paragraph = page.getChildAt(0);
17889
+ this.layoutRun = void 0;
17890
+ }
17891
+ updateParagraph(paragraph) {
17892
+ this.paragraph = paragraph;
17893
+ this.layoutRun = void 0;
17894
+ }
17895
+ ensureCellParagraphSpace(itemWidth) {
17896
+ let widthFits = true;
17897
+ let paragraph = this.paragraph ?? this.createNewParagraph();
17898
+ const remainingWidth = paragraph.getRemainingSize();
17899
+ widthFits = itemWidth <= remainingWidth;
17900
+ if (widthFits) {
17901
+ return;
17902
+ }
17903
+ const newLineY = paragraph.y + paragraph.height;
17904
+ const newParagraph = this.createNewParagraph(newLineY);
17905
+ this.paragraph = newParagraph;
17906
+ this.layoutRun = void 0;
17907
+ }
17908
+ ensurePageParagraphSpace(itemWidth, itemHeight) {
17909
+ let widthFits = true;
17910
+ let paragraph = this.paragraph ?? this.createNewParagraph();
17911
+ if (paragraph instanceof Table) {
17912
+ widthFits = false;
17913
+ } else if (paragraph instanceof Paragraph) {
17914
+ const remainingWidth = paragraph.getRemainingSize();
17915
+ widthFits = itemWidth <= remainingWidth;
17916
+ }
17917
+ if (widthFits) {
17918
+ return;
17919
+ }
17920
+ const currentParagraphY = paragraph.y;
17921
+ const potentialParagraphHeight = Math.max(paragraph.height, itemHeight);
17922
+ const wouldExceedPage = currentParagraphY + potentialParagraphHeight > this.page.contentMaxHeight;
17923
+ if (widthFits && !wouldExceedPage) {
17924
+ return;
17925
+ }
17926
+ const newLineY = this.page.getContentHeight();
17927
+ const wouldNewLineExceedPage = newLineY + itemHeight > this.page.contentMaxHeight;
17928
+ if (wouldNewLineExceedPage) {
17929
+ this.createNewPage();
17930
+ } else {
17931
+ this.createNewParagraph(newLineY);
17932
+ }
17933
+ }
17934
+ ensureParagraphSpace(itemWidth, itemHeight) {
17935
+ if (this.type === "cell") {
17936
+ this.ensureCellParagraphSpace(itemWidth);
17937
+ } else {
17938
+ this.ensurePageParagraphSpace(itemWidth, itemHeight);
17939
+ }
17940
+ }
17941
+ createNewPage(payload = {}) {
17942
+ console.log("createNewPage ===========");
17943
+ const newPage = new Page({
17944
+ doc: this.doc,
17945
+ section: this.section,
17946
+ ...payload
17947
+ });
17948
+ this.doc.addPage(newPage);
17949
+ this.updatePage(newPage);
17950
+ return newPage;
17951
+ }
17952
+ createNewParagraph(y2 = 0) {
17953
+ const newParagraph = new Paragraph({
17954
+ doc: this.doc,
17955
+ x: 0,
17956
+ y: y2,
17957
+ modelRef: this.modelRef
17958
+ });
17959
+ const wp = this.doc.layoutMapper.getModelNodeById(this.modelRef.id);
17960
+ if (wp?.pPr?.spacing) {
17961
+ const height = UnitConverter$1.twipToPixel(Number(wp.pPr.spacing.line || 0));
17962
+ console.log("height ===", height, wp.pPr.spacing.line);
17963
+ console.log("height ===", height, wp.pPr.spacing);
17964
+ newParagraph.height = height;
17965
+ }
17966
+ if (this.type === "page") {
17967
+ if (newParagraph.height > this.page.getRemainingSize()) {
17968
+ this.createNewPage({ initParagraph: false });
17969
+ newParagraph.y = 0;
17970
+ }
17971
+ }
17972
+ this.container.addChild(newParagraph);
17973
+ this.updateParagraph(newParagraph);
17974
+ return newParagraph;
17975
+ }
17976
+ resetModelRef(id) {
17977
+ this.modelRef = { id };
17978
+ }
17979
+ getRunX() {
17980
+ return this.layoutRun ? this.layoutRun.x + this.layoutRun.width : 0;
17981
+ }
17982
+ addRun(run) {
17983
+ this.paragraph?.addChild(run);
17984
+ this.layoutRun = run;
17985
+ }
17986
+ /**
17987
+ * 根据 dataIndex 替换 path 中的 [n] 为实际值
17988
+ * @param path 包含 [n] 的路径,如 "$.items[n].name"
17989
+ * @returns 替换后的路径,如 "$.items[0].name",若无 dataIndex 则返回 undefined
17990
+ */
17991
+ getValuePath(path2) {
17992
+ if (!path2) return void 0;
17993
+ if (!path2.includes("[n]")) {
17994
+ return path2;
17995
+ }
17996
+ const dataIndex = this.cell?.subRenderer?.dataIndex;
17997
+ if (dataIndex === void 0) return void 0;
17998
+ return path2.replace(/\[n\]/g, `[${dataIndex}]`);
17999
+ }
18000
+ }
17333
18001
  class TextHandler {
17334
18002
  static getValue(context, wr) {
17335
18003
  if (!wr.valuePath) return void 0;
@@ -17604,11 +18272,12 @@ class TextHandler {
17604
18272
  }
17605
18273
  }
17606
18274
  class ImageRun extends LayoutNode {
18275
+ component = BuiltinComponentTypeConst.InlineImage;
18276
+ src = "";
18277
+ /** 是否保持等比 */
18278
+ keepAspect = true;
17607
18279
  constructor(options) {
17608
18280
  super(options);
17609
- this.component = BuiltinComponentTypeConst.InlineImage;
17610
- this.src = "";
17611
- this.keepAspect = true;
17612
18281
  this.src = options.src;
17613
18282
  }
17614
18283
  }
@@ -17635,92 +18304,10 @@ class ImageHandler {
17635
18304
  context.addRun(run);
17636
18305
  }
17637
18306
  }
17638
- class Table extends LayoutGroup {
17639
- constructor(options) {
17640
- super(options);
17641
- this.type = "table";
17642
- this.component = BuiltinComponentTypeConst.Table;
17643
- this.cellPadding = [...DEFAULT_CELL_PADDING];
17644
- this.colWidths = options.colWidths;
17645
- }
17646
- get width() {
17647
- const totalWidth = this.colWidths?.reduce((a, b2) => a + b2, 0) || 0;
17648
- return totalWidth;
17649
- }
17650
- redistribute() {
17651
- const rows = this.getChildren();
17652
- const multiRowCells = [];
17653
- rows.forEach((row, rowIndex) => {
17654
- row.getChildren().forEach((cell, cellIndex) => {
17655
- if (cell.isMerged) {
17656
- return;
17657
- }
17658
- const cellHeight = cell.getMinHeight();
17659
- const rowspan = cell.rowspan || 1;
17660
- if (rowspan === 1) {
17661
- row.height = Math.max(row.height, cellHeight);
17662
- } else {
17663
- multiRowCells.push({
17664
- cellHeight,
17665
- rowIndex,
17666
- rowspan
17667
- });
17668
- }
17669
- });
17670
- });
17671
- multiRowCells.forEach((e) => {
17672
- const { cellHeight, rowIndex, rowspan } = e;
17673
- const crossRows = rows.slice(rowIndex, rowIndex + rowspan);
17674
- const currentTotalHeight = crossRows.reduce((sum, r) => sum + r.height, 0);
17675
- if (cellHeight > currentTotalHeight) {
17676
- const extraHeight = cellHeight - currentTotalHeight;
17677
- const lastRow = crossRows[crossRows.length - 1];
17678
- if (lastRow) {
17679
- lastRow.height += extraHeight;
17680
- }
17681
- }
17682
- });
17683
- const MIN_ROW_HEIGHT = 20;
17684
- rows.forEach((row) => {
17685
- if (row.height === 0) {
17686
- const hasContent = row.getChildren().some((cell) => !cell.isMerged);
17687
- if (hasContent) {
17688
- row.height = MIN_ROW_HEIGHT;
17689
- }
17690
- }
17691
- });
17692
- this.height = rows.reduce((sum, row) => {
17693
- row.y = sum;
17694
- return sum + row.height;
17695
- }, 0);
17696
- }
17697
- layout(x2, y2) {
17698
- this.layoutX = x2;
17699
- this.layoutY = y2;
17700
- this.forEachChild((child) => {
17701
- child.layout(this.layoutX, this.layoutY + child.y);
17702
- });
17703
- }
17704
- updateCellOffsetInfo() {
17705
- const map = /* @__PURE__ */ new Map();
17706
- const rows = this.getChildren();
17707
- rows.forEach((row, rowIndex) => {
17708
- row.getChildren().forEach((cell, colIndex) => {
17709
- if (cell.mergeFromId) {
17710
- cell.mergeRefColOffset = colIndex - map.get(cell.mergeFromId).colIndex;
17711
- cell.mergeRefRowOffset = rowIndex - map.get(cell.mergeFromId).rowIndex;
17712
- } else {
17713
- map.set(cell.id, { rowIndex, colIndex });
17714
- }
17715
- });
17716
- });
17717
- map.clear();
17718
- }
17719
- }
17720
18307
  class TableRow extends LayoutGroup {
18308
+ component = BuiltinComponentTypeConst.TableRow;
17721
18309
  constructor(options) {
17722
18310
  super(options);
17723
- this.component = BuiltinComponentTypeConst.TableRow;
17724
18311
  }
17725
18312
  get width() {
17726
18313
  return this.parent.width;
@@ -17751,11 +18338,30 @@ class TableRow extends LayoutGroup {
17751
18338
  }
17752
18339
  }
17753
18340
  class TableCell extends LayoutGroup {
18341
+ component = BuiltinComponentTypeConst.TableCell;
18342
+ // 单元格属性
18343
+ colspan = 1;
18344
+ rowspan = 1;
18345
+ // 合并关系
18346
+ // id: string;
18347
+ mergeFromId;
18348
+ // 合并相对位置信息
18349
+ mergeRefRowOffset;
18350
+ // 相对于源单元格的行偏移
18351
+ mergeRefColOffset;
18352
+ // 相对于源单元格的列偏移
18353
+ backgroundColor;
18354
+ border;
18355
+ /** 设计渲染时 */
18356
+ subRenderer;
18357
+ get table() {
18358
+ return this.parent.parent;
18359
+ }
18360
+ get padding() {
18361
+ return this.table.cellPadding;
18362
+ }
17754
18363
  constructor(options) {
17755
18364
  super(options);
17756
- this.component = BuiltinComponentTypeConst.TableCell;
17757
- this.colspan = 1;
17758
- this.rowspan = 1;
17759
18365
  this.colspan = options.colspan ?? 1;
17760
18366
  this.rowspan = options.rowspan ?? 1;
17761
18367
  if (options.mergeFromId !== void 0) this.mergeFromId = options.mergeFromId;
@@ -17763,12 +18369,6 @@ class TableCell extends LayoutGroup {
17763
18369
  if (options.mergeRefColOffset !== void 0) this.mergeRefColOffset = options.mergeRefColOffset;
17764
18370
  if (options.subRenderer !== void 0) this.subRenderer = options.subRenderer;
17765
18371
  }
17766
- get table() {
17767
- return this.parent.parent;
17768
- }
17769
- get padding() {
17770
- return this.table.cellPadding;
17771
- }
17772
18372
  get width() {
17773
18373
  const cellIndex = this.parent.indexOfChild(this);
17774
18374
  const size = [];
@@ -17815,12 +18415,23 @@ class TableCell extends LayoutGroup {
17815
18415
  }
17816
18416
  }
17817
18417
  class TableSplitter {
18418
+ table;
18419
+ maxHeight;
18420
+ // 中间状态变量
18421
+ cellInstanceMap = /* @__PURE__ */ new Map();
18422
+ // 原始单元格 ID 映射
18423
+ splitRowIndex = -1;
18424
+ // 切分行索引
18425
+ splitCellIndex = -1;
18426
+ // 切分行中能容纳内容的单元格索引
18427
+ accumulatedHeight = 0;
18428
+ // 累积高度
18429
+ // 结果表格
18430
+ curTable;
18431
+ nextTable;
18432
+ // 单元格映射:用于内容回填(原始单元格 -> 新单元格数组)
18433
+ cellMapping = /* @__PURE__ */ new Map();
17818
18434
  constructor(table, maxHeight) {
17819
- this.cellInstanceMap = /* @__PURE__ */ new Map();
17820
- this.splitRowIndex = -1;
17821
- this.splitCellIndex = -1;
17822
- this.accumulatedHeight = 0;
17823
- this.cellMapping = /* @__PURE__ */ new Map();
17824
18435
  this.table = table;
17825
18436
  this.maxHeight = maxHeight;
17826
18437
  }
@@ -18239,300 +18850,17 @@ function splitTableByHeight(table, maxHeight) {
18239
18850
  console.timeEnd(key);
18240
18851
  return result;
18241
18852
  }
18242
- class Page extends LayoutGroup {
18243
- constructor(options) {
18244
- super(options);
18245
- this.component = BuiltinComponentTypeConst.Paper;
18246
- this.section = options.section;
18247
- }
18248
- get width() {
18249
- return this.section.pageSize?.width;
18250
- }
18251
- get height() {
18252
- return this.section.pageSize?.height;
18253
- }
18254
- get padding() {
18255
- return this.section.pagePadding;
18256
- }
18257
- get contentMaxWidth() {
18258
- return this.width - this.padding[1] - this.padding[3];
18259
- }
18260
- get contentMaxHeight() {
18261
- return this.height - this.padding[0] - this.padding[2];
18262
- }
18263
- getContentHeight() {
18264
- const contentHeight = this.getChildren().reduce((sum, child) => sum + child.height, 0);
18265
- return contentHeight;
18266
- }
18267
- getRemainingSize() {
18268
- return this.contentMaxHeight - this.getContentHeight();
18269
- }
18270
- layout() {
18271
- this.forEachChild((child) => {
18272
- child.layout(this.pl, this.pt + child.y);
18273
- });
18274
- }
18275
- }
18276
- class Paragraph extends LayoutGroup {
18277
- // 基线位置,默认为 0,表示与段落顶部对齐
18278
- // backgroundColor?: string = 'rgba(0,0,0,0.06)';
18279
- // borderTop?: Border = {
18280
- // color: '#f30',
18281
- // width: 1,
18282
- // };
18283
- // borderLeft?: Border = {
18284
- // color: '#f90',
18285
- // width: 1,
18286
- // };
18287
- // borderRight?: Border = {
18288
- // color: '#f444',
18289
- // width: 1,
18290
- // };
18291
- // borderBottom?: Border = {
18292
- // color: '#f90',
18293
- // width: 1,
18294
- // };
18295
- constructor(options) {
18296
- super(options);
18297
- this.type = "paragraph";
18298
- this.component = BuiltinComponentTypeConst.Paragraph;
18299
- this.baseline = 0;
18300
- const run = TextRun.createEmptyRun(this.doc);
18301
- this.addChild(run);
18302
- }
18303
- /**
18304
- * 重写 addChild 方法,添加后置钩子
18305
- */
18306
- addChild(child) {
18307
- const firstChild = this.getFirstChild();
18308
- if (firstChild instanceof TextRun && firstChild.isPlaceholder) {
18309
- this.removeChildAt(0);
18310
- }
18311
- super.addChild(child);
18312
- this.onChildAdded(child);
18313
- }
18314
- /**
18315
- * 子节点添加后的钩子
18316
- * @param child 新添加的子节点
18317
- */
18318
- onChildAdded(child) {
18319
- const lineHeight = "lineHeight" in child ? child.lineHeight : 1;
18320
- this.height = Math.max(this.height, child.height * lineHeight);
18321
- }
18322
- get width() {
18323
- return this.parent.contentMaxWidth;
18324
- }
18325
- getContextWidth() {
18326
- return this.getChildren().reduce((sum, run) => sum + run.width, 0);
18327
- }
18328
- /**
18329
- * 获取剩余空间
18330
- */
18331
- getRemainingSize() {
18332
- const contentWidth = this.getContextWidth();
18333
- return this.width - contentWidth;
18334
- }
18335
- layout(x2, y2) {
18336
- this.layoutX = x2;
18337
- this.layoutY = y2;
18338
- this.applyStyle();
18339
- this.applyBaseline();
18340
- this.forEachChild((child) => {
18341
- if (child instanceof TextRun) {
18342
- child.layout(this.layoutX + child.x, this.layoutY + child.y);
18343
- }
18344
- });
18345
- }
18346
- applyStyle() {
18347
- const wp = this.doc.layoutMapper.getModelNodeById(this.modelRef.id);
18348
- let offset2 = 0;
18349
- if (wp?.pPr?.alignment === "center") {
18350
- offset2 = (this.width - this.getContextWidth()) / 2;
18351
- } else if (wp?.pPr?.alignment === "right") {
18352
- offset2 = this.width - this.getContextWidth();
18353
- }
18354
- this.forEachChild((child) => {
18355
- child.x += offset2;
18356
- });
18357
- }
18358
- /**
18359
- * 基于基线调整文本垂直位置
18360
- */
18361
- applyBaseline() {
18362
- const maxTextRun = this.getMaxTextRun();
18363
- if (!maxTextRun) return;
18364
- const extra = this.height - (maxTextRun.ascent + maxTextRun.descent);
18365
- const baseLine = extra / 2 + maxTextRun.ascent;
18366
- this.baseline = baseLine;
18367
- this.forEachChild((child) => {
18368
- if (child instanceof TextRun) {
18369
- child.y = baseLine - (child.ascent ?? 0);
18370
- }
18371
- });
18372
- }
18373
- /**
18374
- * 获取段落中 height*lineHeight 最大的文本 run
18375
- */
18376
- getMaxTextRun() {
18377
- let maxTextRun = null;
18378
- let maxHeight = 0;
18379
- this.forEachChild((child) => {
18380
- if (child instanceof TextRun) {
18381
- const height = child.height * child.lineHeight;
18382
- if (height > maxHeight) {
18383
- maxHeight = height;
18384
- maxTextRun = child;
18385
- }
18386
- }
18387
- });
18388
- return maxTextRun;
18389
- }
18390
- }
18391
- class LayoutContext {
18392
- constructor(options) {
18393
- this.type = "page";
18394
- const { type: type4, doc, section, page, cell, paragraph, layoutRun } = options;
18395
- this.type = type4;
18396
- this.doc = doc;
18397
- this.section = section;
18398
- this.page = page;
18399
- this.cell = cell;
18400
- this.paragraph = paragraph;
18401
- this.layoutRun = layoutRun;
18402
- }
18403
- get container() {
18404
- if (this.type === "cell") {
18405
- return this.cell;
18406
- } else {
18407
- return this.page;
18408
- }
18409
- }
18410
- updateSection(section) {
18411
- this.section = section;
18412
- }
18413
- updatePage(page) {
18414
- this.page = page;
18415
- this.paragraph = page.getChildAt(0);
18416
- this.layoutRun = void 0;
18417
- }
18418
- updateParagraph(paragraph) {
18419
- this.paragraph = paragraph;
18420
- this.layoutRun = void 0;
18421
- }
18422
- ensureCellParagraphSpace(itemWidth) {
18423
- let widthFits = true;
18424
- let paragraph = this.paragraph ?? this.createNewParagraph();
18425
- const remainingWidth = paragraph.getRemainingSize();
18426
- widthFits = itemWidth <= remainingWidth;
18427
- if (widthFits) {
18428
- return;
18429
- }
18430
- const newLineY = paragraph.y + paragraph.height;
18431
- const newParagraph = this.createNewParagraph(newLineY);
18432
- this.paragraph = newParagraph;
18433
- this.layoutRun = void 0;
18434
- }
18435
- ensurePageParagraphSpace(itemWidth, itemHeight) {
18436
- let widthFits = true;
18437
- let paragraph = this.paragraph ?? this.createNewParagraph();
18438
- if (paragraph instanceof Table) {
18439
- widthFits = false;
18440
- } else if (paragraph instanceof Paragraph) {
18441
- const remainingWidth = paragraph.getRemainingSize();
18442
- widthFits = itemWidth <= remainingWidth;
18443
- }
18444
- if (widthFits) {
18445
- return;
18446
- }
18447
- const currentParagraphY = paragraph.y;
18448
- const potentialParagraphHeight = Math.max(paragraph.height, itemHeight);
18449
- const wouldExceedPage = currentParagraphY + potentialParagraphHeight > this.page.contentMaxHeight;
18450
- if (widthFits && !wouldExceedPage) {
18451
- return;
18452
- }
18453
- const newLineY = this.page.getContentHeight();
18454
- const wouldNewLineExceedPage = newLineY + itemHeight > this.page.contentMaxHeight;
18455
- if (wouldNewLineExceedPage) {
18456
- this.createNewPage();
18457
- } else {
18458
- this.createNewParagraph(newLineY);
18459
- }
18460
- }
18461
- ensureParagraphSpace(itemWidth, itemHeight) {
18462
- if (this.type === "cell") {
18463
- this.ensureCellParagraphSpace(itemWidth);
18464
- } else {
18465
- this.ensurePageParagraphSpace(itemWidth, itemHeight);
18466
- }
18467
- }
18468
- createNewPage(payload = {}) {
18469
- console.log("createNewPage ===========");
18470
- const newPage = new Page({
18471
- doc: this.doc,
18472
- section: this.section,
18473
- ...payload
18474
- });
18475
- this.doc.addPage(newPage);
18476
- this.updatePage(newPage);
18477
- return newPage;
18478
- }
18479
- createNewParagraph(y2 = 0) {
18480
- const newParagraph = new Paragraph({
18481
- doc: this.doc,
18482
- x: 0,
18483
- y: y2,
18484
- modelRef: this.modelRef
18485
- });
18486
- const wp = this.doc.layoutMapper.getModelNodeById(this.modelRef.id);
18487
- if (wp?.pPr?.spacing) {
18488
- const height = UnitConverter$1.twipToPixel(Number(wp.pPr.spacing.line || 0));
18489
- console.log("height ===", height, wp.pPr.spacing.line);
18490
- console.log("height ===", height, wp.pPr.spacing);
18491
- newParagraph.height = height;
18492
- }
18493
- if (this.type === "page") {
18494
- if (newParagraph.height > this.page.getRemainingSize()) {
18495
- this.createNewPage({ initParagraph: false });
18496
- newParagraph.y = 0;
18497
- }
18498
- }
18499
- this.container.addChild(newParagraph);
18500
- this.updateParagraph(newParagraph);
18501
- return newParagraph;
18502
- }
18503
- resetModelRef(id) {
18504
- this.modelRef = { id };
18505
- }
18506
- getRunX() {
18507
- return this.layoutRun ? this.layoutRun.x + this.layoutRun.width : 0;
18508
- }
18509
- addRun(run) {
18510
- this.paragraph?.addChild(run);
18511
- this.layoutRun = run;
18512
- }
18513
- /**
18514
- * 根据 dataIndex 替换 path 中的 [n] 为实际值
18515
- * @param path 包含 [n] 的路径,如 "$.items[n].name"
18516
- * @returns 替换后的路径,如 "$.items[0].name",若无 dataIndex 则返回 undefined
18517
- */
18518
- getValuePath(path2) {
18519
- if (!path2) return void 0;
18520
- if (!path2.includes("[n]")) {
18521
- return path2;
18522
- }
18523
- const dataIndex = this.cell?.subRenderer?.dataIndex;
18524
- if (dataIndex === void 0) return void 0;
18525
- return path2.replace(/\[n\]/g, `[${dataIndex}]`);
18526
- }
18527
- }
18528
18853
  class TableExpander {
18854
+ table;
18855
+ doc;
18856
+ data;
18857
+ modelMapper = /* @__PURE__ */ new Map();
18858
+ instanceMapper = /* @__PURE__ */ new Map();
18859
+ rowIndexRepeatingMapper = /* @__PURE__ */ new Map();
18860
+ rowIndexBoundedMapper = /* @__PURE__ */ new Map();
18861
+ boundedCellDataIndexMap = /* @__PURE__ */ new Map();
18862
+ rows = [];
18529
18863
  constructor(table, doc) {
18530
- this.modelMapper = /* @__PURE__ */ new Map();
18531
- this.instanceMapper = /* @__PURE__ */ new Map();
18532
- this.rowIndexRepeatingMapper = /* @__PURE__ */ new Map();
18533
- this.rowIndexBoundedMapper = /* @__PURE__ */ new Map();
18534
- this.boundedCellDataIndexMap = /* @__PURE__ */ new Map();
18535
- this.rows = [];
18536
18864
  this.table = table;
18537
18865
  this.doc = doc;
18538
18866
  this.data = doc.dataManager;
@@ -18749,6 +19077,8 @@ class TableExpander {
18749
19077
  }
18750
19078
  }
18751
19079
  class TableInfoProvider {
19080
+ wtbl;
19081
+ tableExpander;
18752
19082
  constructor(wtbl, tableExpander) {
18753
19083
  this.wtbl = wtbl;
18754
19084
  this.tableExpander = tableExpander;
@@ -18793,127 +19123,11 @@ class TableInfoProvider {
18793
19123
  }
18794
19124
  }
18795
19125
  }
18796
- class Section {
18797
- constructor(options = {}) {
18798
- this.pageSize = {
18799
- height: 842,
18800
- // A4 height in px (297mm ≈ 842px at 96 DPI)
18801
- width: 595
18802
- // A4 width in px (210mm ≈ 595px at 96 DPI)
18803
- };
18804
- this.pagePadding = [0, 0, 0, 0];
18805
- this.id = uuid();
18806
- const { pageSize, pagePadding } = options;
18807
- this.pageSize = pageSize ?? this.pageSize;
18808
- this.pagePadding = pagePadding ?? this.pagePadding;
18809
- this.bgColor = options.bgColor ?? "#ffffff";
18810
- }
18811
- /**
18812
- * 从 Wsection 模型创建 Section 视图
18813
- * @param wsection Word 文档的分节模型
18814
- * @param dpi 屏幕 DPI(默认 96)
18815
- * @returns Section 视图实例
18816
- */
18817
- static fromXML(wsection, dpi = 96) {
18818
- const section = new Section();
18819
- if (wsection.pageSize?.width && wsection.pageSize?.height) {
18820
- section.pageSize = {
18821
- width: UnitConverter$1.twipToPixel(wsection.pageSize.width, dpi),
18822
- height: UnitConverter$1.twipToPixel(wsection.pageSize.height, dpi)
18823
- };
18824
- }
18825
- if (wsection.margins) {
18826
- const top = wsection.margins.top ? UnitConverter$1.twipToPixel(wsection.margins.top, dpi) : 0;
18827
- const right = wsection.margins.right ? UnitConverter$1.twipToPixel(wsection.margins.right, dpi) : 0;
18828
- const bottom = wsection.margins.bottom ? UnitConverter$1.twipToPixel(wsection.margins.bottom, dpi) : 0;
18829
- const left = wsection.margins.left ? UnitConverter$1.twipToPixel(wsection.margins.left, dpi) : 0;
18830
- section.pagePadding = [top, right, bottom, left];
18831
- }
18832
- return section;
18833
- }
18834
- /**
18835
- * 获取内容区域宽度(页面宽度 - 左边距 - 右边距)
18836
- * @returns 内容宽度(px)
18837
- */
18838
- getContentWidth() {
18839
- const padding = this.pagePadding ?? [0, 0, 0, 0];
18840
- const [, right, , left] = padding;
18841
- return this.pageSize?.width ? this.pageSize.width - left - right : 0;
18842
- }
18843
- /**
18844
- * 获取内容区域高度(页面高度 - 上边距 - 下边距)
18845
- * @returns 内容高度(px)
18846
- */
18847
- getContentHeight() {
18848
- const padding = this.pagePadding ?? [0, 0, 0, 0];
18849
- const [top, , bottom] = padding;
18850
- return this.pageSize?.height ? this.pageSize.height - top - bottom : 0;
18851
- }
18852
- /**
18853
- * 解析数值:支持多种单位格式
18854
- * @param value 数值字符串或数字
18855
- * @param defaultUnit 默认单位('twip' | 'px' | 'mm' | 'cm' | 'inch')
18856
- * @param dpi 屏幕 DPI(默认 96)
18857
- * @returns 转换后的 px 值
18858
- */
18859
- static parseValue(value, defaultUnit = "px", dpi = 96) {
18860
- if (typeof value === "number") {
18861
- return Section.convertToPixel(value, defaultUnit, dpi);
18862
- }
18863
- const valueStr = String(value).trim();
18864
- const unitMatch = valueStr.match(/^([\d.]+)\s*(twip|pt|px|mm|cm|in|inch)?$/i);
18865
- if (!unitMatch) {
18866
- return 0;
18867
- }
18868
- const numValue = parseFloat(unitMatch[1] ?? "0");
18869
- const unit = (unitMatch[2] || defaultUnit).toLowerCase();
18870
- return Section.convertToPixel(numValue, unit, dpi);
18871
- }
18872
- /**
18873
- * 单位转换为 px
18874
- * @param value 数值
18875
- * @param unit 单位
18876
- * @param dpi 屏幕 DPI(默认 96)
18877
- * @returns px 值
18878
- */
18879
- static convertToPixel(value, unit, dpi) {
18880
- switch (unit) {
18881
- case "twip":
18882
- return UnitConverter$1.twipToPixel(value, dpi);
18883
- case "pt":
18884
- return UnitConverter$1.pointToPixel(value, dpi);
18885
- case "px":
18886
- return Math.round(value);
18887
- case "mm":
18888
- return UnitConverter$1.cmToPixel(value / 10, dpi);
18889
- case "cm":
18890
- return UnitConverter$1.cmToPixel(value, dpi);
18891
- case "in":
18892
- case "inch":
18893
- return UnitConverter$1.inchToPixel(value, dpi);
18894
- default:
18895
- return Math.round(value);
18896
- }
18897
- }
18898
- /**
18899
- * 获取页面尺寸信息(用于调试)
18900
- * @returns 格式化的页面信息
18901
- */
18902
- toString() {
18903
- const width = this.pageSize?.width ?? 0;
18904
- const height = this.pageSize?.height ?? 0;
18905
- const padding = this.pagePadding ?? [0, 0, 0, 0];
18906
- const [top, right, bottom, left] = padding;
18907
- const contentWidth = this.getContentWidth();
18908
- const contentHeight = this.getContentHeight();
18909
- return [
18910
- `Page Size: ${width}px × ${height}px`,
18911
- `Margins: top=${top}px, right=${right}px, bottom=${bottom}px, left=${left}px`,
18912
- `Content: ${contentWidth}px × ${contentHeight}px`
18913
- ].join("\n");
18914
- }
18915
- }
18916
19126
  class LayoutManager {
19127
+ doc;
19128
+ pageContext;
19129
+ // Run 类型到布局处理函数的映射(表格单元格和段落通用)
19130
+ layoutHandlers;
18917
19131
  constructor(doc) {
18918
19132
  this.doc = doc;
18919
19133
  this.layoutHandlers = /* @__PURE__ */ new Map();
@@ -19068,17 +19282,22 @@ function generateModelMap(node, map = /* @__PURE__ */ new Map()) {
19068
19282
  return map;
19069
19283
  }
19070
19284
  class LayoutMapper {
19285
+ doc;
19071
19286
  constructor(doc) {
19072
- this.dataCenter = /* @__PURE__ */ new Map();
19073
- this.widgetIds = [];
19074
- this.lineCenter = /* @__PURE__ */ new Map();
19075
- this.lineIdByPage = /* @__PURE__ */ new Map();
19076
- this.widgetMetaIds = /* @__PURE__ */ new Set();
19077
- this.widgetMetaMap = /* @__PURE__ */ new Map();
19078
- this.modelMap = /* @__PURE__ */ new Map();
19079
- this.modelSplitMap = /* @__PURE__ */ new Map();
19080
19287
  this.doc = doc;
19081
19288
  }
19289
+ /** 节点信息中心 */
19290
+ dataCenter = /* @__PURE__ */ new Map();
19291
+ /** page 内所有 widget 的顺序 id */
19292
+ widgetIds = [];
19293
+ /** 行信息中心 */
19294
+ lineCenter = /* @__PURE__ */ new Map();
19295
+ lineIdByPage = /* @__PURE__ */ new Map();
19296
+ /** 组件信息中心 */
19297
+ widgetMetaIds = /* @__PURE__ */ new Set();
19298
+ widgetMetaMap = /* @__PURE__ */ new Map();
19299
+ modelMap = /* @__PURE__ */ new Map();
19300
+ modelSplitMap = /* @__PURE__ */ new Map();
19082
19301
  /** 扁平处理 layout 数据 */
19083
19302
  buildLayoutIndex() {
19084
19303
  const { dataCenter, lineCenter, widgetIds, widgetMetaIds, widgetMetaMap } = buildLayoutMeta(
@@ -19239,9 +19458,9 @@ class LayoutMapper {
19239
19458
  class Transaction {
19240
19459
  constructor(emitFn) {
19241
19460
  this.emitFn = emitFn;
19242
- this.suppress = 0;
19243
- this.queuedPayload = null;
19244
19461
  }
19462
+ suppress = 0;
19463
+ queuedPayload = null;
19245
19464
  batch(fn) {
19246
19465
  this.suppress++;
19247
19466
  try {
@@ -19271,9 +19490,11 @@ class Transaction {
19271
19490
  }
19272
19491
  }
19273
19492
  class CursorManager {
19493
+ doc;
19494
+ batcher;
19495
+ cursor = null;
19496
+ selection = null;
19274
19497
  constructor(doc) {
19275
- this.cursor = null;
19276
- this.selection = null;
19277
19498
  this.doc = doc;
19278
19499
  this.batcher = new Transaction((q2) => {
19279
19500
  this.broadcastChange(q2.prevCursor, q2.prevSelection, q2.reason);
@@ -19768,9 +19989,7 @@ if (typeof window != "undefined") {
19768
19989
  K.noConflict = (t) => (t && window.hotkeys === K && (window.hotkeys = e), K), window.hotkeys = K;
19769
19990
  }
19770
19991
  class MovementRegistry {
19771
- constructor() {
19772
- this.handlers = /* @__PURE__ */ new Map();
19773
- }
19992
+ handlers = /* @__PURE__ */ new Map();
19774
19993
  register(component, handler) {
19775
19994
  this.handlers.set(component, handler);
19776
19995
  }
@@ -19925,12 +20144,10 @@ function getMovementRegistry() {
19925
20144
  return movementRegistry;
19926
20145
  }
19927
20146
  class CursorDragSession {
19928
- constructor() {
19929
- this.pointerId = null;
19930
- this.anchor = null;
19931
- this.dragging = false;
19932
- this.lastMove = null;
19933
- }
20147
+ pointerId = null;
20148
+ anchor = null;
20149
+ dragging = false;
20150
+ lastMove = null;
19934
20151
  start(pointerId, anchor) {
19935
20152
  this.pointerId = pointerId;
19936
20153
  this.anchor = anchor;
@@ -19949,10 +20166,11 @@ class CursorDragSession {
19949
20166
  }
19950
20167
  }
19951
20168
  class CursorController {
20169
+ doc;
20170
+ dragRaf = createRafOnce();
20171
+ caretRaf = createRafOnce();
20172
+ dragSession = new CursorDragSession();
19952
20173
  constructor(doc) {
19953
- this.dragRaf = createRafOnce();
19954
- this.caretRaf = createRafOnce();
19955
- this.dragSession = new CursorDragSession();
19956
20174
  this.doc = doc;
19957
20175
  this.flushDragMove = this.flushDragMove.bind(this);
19958
20176
  }
@@ -20201,6 +20419,7 @@ class CursorController {
20201
20419
  }
20202
20420
  }
20203
20421
  class InteractionController {
20422
+ doc;
20204
20423
  constructor(doc) {
20205
20424
  this.doc = doc;
20206
20425
  }
@@ -20289,6 +20508,7 @@ class InteractionController {
20289
20508
  }
20290
20509
  }
20291
20510
  class InteractionHandler {
20511
+ eventManager;
20292
20512
  constructor(eventManager) {
20293
20513
  this.eventManager = eventManager;
20294
20514
  }
@@ -20330,6 +20550,7 @@ class InteractionHandler {
20330
20550
  }
20331
20551
  }
20332
20552
  class KonvaHandler {
20553
+ eventManager;
20333
20554
  constructor(eventManager) {
20334
20555
  this.eventManager = eventManager;
20335
20556
  }
@@ -20437,13 +20658,14 @@ class KonvaHandler {
20437
20658
  }
20438
20659
  }
20439
20660
  class IMEHandler {
20661
+ eventManager;
20662
+ isComposing = false;
20663
+ lastComposedText = null;
20664
+ lastCompositionCommitTime = 0;
20665
+ compositionDedupeMs = 200;
20666
+ pendingInsert = "";
20667
+ rafOnce = createRafOnce();
20440
20668
  constructor(eventManager) {
20441
- this.isComposing = false;
20442
- this.lastComposedText = null;
20443
- this.lastCompositionCommitTime = 0;
20444
- this.compositionDedupeMs = 200;
20445
- this.pendingInsert = "";
20446
- this.rafOnce = createRafOnce();
20447
20669
  this.eventManager = eventManager;
20448
20670
  }
20449
20671
  getHandlers() {
@@ -20558,9 +20780,7 @@ class IMEHandler {
20558
20780
  }
20559
20781
  }
20560
20782
  class EventBus {
20561
- constructor() {
20562
- this.handlers = /* @__PURE__ */ new Map();
20563
- }
20783
+ handlers = /* @__PURE__ */ new Map();
20564
20784
  on(event2, handler) {
20565
20785
  if (!this.handlers.has(event2)) {
20566
20786
  this.handlers.set(event2, []);
@@ -20595,10 +20815,14 @@ class EventBus {
20595
20815
  }
20596
20816
  }
20597
20817
  class EventManager {
20818
+ doc;
20819
+ handlers = [];
20820
+ cleanupFns = [];
20821
+ customHandlers = /* @__PURE__ */ new Map();
20822
+ eventBus;
20823
+ interactionController;
20824
+ cursorController;
20598
20825
  constructor(doc) {
20599
- this.handlers = [];
20600
- this.cleanupFns = [];
20601
- this.customHandlers = /* @__PURE__ */ new Map();
20602
20826
  this.doc = doc;
20603
20827
  this.eventBus = new EventBus();
20604
20828
  this.interactionController = new InteractionController(doc);
@@ -20723,11 +20947,17 @@ class EventManager {
20723
20947
  const LABEL_SUFFIX = "_lb_";
20724
20948
  const DEFAULT_EMPTY_ITEM = Object.freeze({ __default_render__: true });
20725
20949
  class DataManager {
20950
+ doc;
20951
+ subscriptions = /* @__PURE__ */ new Map();
20952
+ layoutScheduled = false;
20953
+ rawData = {};
20954
+ /**
20955
+ * 默认值 Map
20956
+ * key: jsonpath 路径 (支持 [n] 数组索引)
20957
+ * value: 默认值
20958
+ */
20959
+ defaults = /* @__PURE__ */ new Map();
20726
20960
  constructor(_doc, data = {}) {
20727
- this.subscriptions = /* @__PURE__ */ new Map();
20728
- this.layoutScheduled = false;
20729
- this.rawData = {};
20730
- this.defaults = /* @__PURE__ */ new Map();
20731
20961
  this.doc = _doc;
20732
20962
  this.rawData = this.deepClone(data);
20733
20963
  }
@@ -21271,10 +21501,14 @@ class DataManager {
21271
21501
  }
21272
21502
  }
21273
21503
  class InteractionManager {
21504
+ doc;
21505
+ batcher;
21506
+ /** 当前选中的表格(行 / 列 / 全选) */
21507
+ tableSelection = null;
21508
+ /** 当前拖拽的id 用来进行处理单个单元格选中 */
21509
+ dragHoverId = "";
21510
+ panelData = null;
21274
21511
  constructor(doc) {
21275
- this.tableSelection = null;
21276
- this.dragHoverId = "";
21277
- this.panelData = null;
21278
21512
  this.doc = doc;
21279
21513
  this.panelData = {
21280
21514
  panelType: "panel:paper",
@@ -21386,17 +21620,35 @@ class InteractionManager {
21386
21620
  }
21387
21621
  }
21388
21622
  class Doc {
21623
+ id;
21624
+ mode;
21625
+ model;
21626
+ sections = [];
21627
+ pages = [];
21628
+ commandManager;
21629
+ layoutManager;
21630
+ layoutMapper;
21631
+ cursorManager;
21632
+ eventManager;
21633
+ dataManager;
21634
+ interactionManager;
21635
+ pageSize = {
21636
+ ...DEFAULT_PAGE_SIZE
21637
+ };
21638
+ pagePadding = [...DEFAULT_PAGE_PADDING];
21639
+ /** 当前表单主模型 key */
21640
+ mainModelKey;
21641
+ /** 安全距离 */
21642
+ SAFE_DIST = 2;
21643
+ /** 纸张之间的间距 */
21644
+ PAGE_GAP = 20;
21645
+ /** 缩放值 */
21646
+ scale = 1;
21647
+ /** 每页的偏移量 */
21648
+ pageOffsets = {};
21649
+ onLayoutChange;
21650
+ onSelectionChange;
21389
21651
  constructor(options) {
21390
- this.sections = [];
21391
- this.pages = [];
21392
- this.pageSize = {
21393
- ...DEFAULT_PAGE_SIZE
21394
- };
21395
- this.pagePadding = [...DEFAULT_PAGE_PADDING];
21396
- this.SAFE_DIST = 2;
21397
- this.PAGE_GAP = 20;
21398
- this.scale = 1;
21399
- this.pageOffsets = {};
21400
21652
  this.id = uuid();
21401
21653
  this.mode = options.mode ?? DocModeTypeConst.Edit;
21402
21654
  this.model = options.model;
@@ -21689,7 +21941,7 @@ function requireCssUnitConverter() {
21689
21941
  }
21690
21942
  var cssUnitConverterExports = requireCssUnitConverter();
21691
21943
  const convert = /* @__PURE__ */ getDefaultExportFromCjs(cssUnitConverterExports);
21692
- class UnitConverter {
21944
+ class UnitConverter2 {
21693
21945
  /**
21694
21946
  * 转换CSS单位
21695
21947
  */
@@ -21718,8 +21970,8 @@ async function usePagesToPdf(stage, pages, pageGroupRefs, options) {
21718
21970
  }
21719
21971
  paper = customSize;
21720
21972
  }
21721
- const pageWidthPx = UnitConverter.mmToPx(paper[0]);
21722
- const pageHeightPx = UnitConverter.mmToPx(paper[1]);
21973
+ const pageWidthPx = UnitConverter2.mmToPx(paper[0]);
21974
+ const pageHeightPx = UnitConverter2.mmToPx(paper[1]);
21723
21975
  const pdf = new jsPDF({
21724
21976
  orientation: pageWidthPx > pageHeightPx ? "landscape" : "portrait",
21725
21977
  unit: "px",
@@ -21792,6 +22044,24 @@ function useInteraction(publicDocApi) {
21792
22044
  return readonly(state);
21793
22045
  }
21794
22046
  class WrunProperties {
22047
+ rFonts;
22048
+ sz;
22049
+ // 字号(半磅单位)
22050
+ color;
22051
+ // 颜色(hex,无 #)
22052
+ b;
22053
+ // 粗体
22054
+ i;
22055
+ // 斜体
22056
+ u;
22057
+ // 下划线
22058
+ strike;
22059
+ // 删除线
22060
+ kern;
22061
+ // 字间距
22062
+ highlight;
22063
+ // 高亮颜色
22064
+ lang;
21795
22065
  constructor(props) {
21796
22066
  if (props) {
21797
22067
  Object.assign(this, props);
@@ -21974,6 +22244,13 @@ class WrunProperties {
21974
22244
  }
21975
22245
  }
21976
22246
  class WparagraphProperties {
22247
+ alignment;
22248
+ indent;
22249
+ spacing;
22250
+ outlineLevel;
22251
+ keepNext;
22252
+ keepLines;
22253
+ widowControl;
21977
22254
  constructor(props) {
21978
22255
  if (props) {
21979
22256
  Object.assign(this, props);
@@ -22133,6 +22410,18 @@ class WparagraphProperties {
22133
22410
  }
22134
22411
  }
22135
22412
  class WstyleDefinition {
22413
+ styleId;
22414
+ type;
22415
+ name;
22416
+ basedOn;
22417
+ next;
22418
+ isDefault;
22419
+ qFormat;
22420
+ semiHidden;
22421
+ uiPriority;
22422
+ pPr;
22423
+ rPr;
22424
+ attrs;
22136
22425
  constructor(styleId, type4, options) {
22137
22426
  this.styleId = styleId;
22138
22427
  this.type = type4;
@@ -22274,6 +22563,8 @@ class WstyleDefinition {
22274
22563
  }
22275
22564
  }
22276
22565
  class WdocDefaults {
22566
+ rPrDefault;
22567
+ pPrDefault;
22277
22568
  constructor(props) {
22278
22569
  if (props) {
22279
22570
  Object.assign(this, props);
@@ -22334,9 +22625,11 @@ class WdocDefaults {
22334
22625
  }
22335
22626
  }
22336
22627
  class Wstyles {
22628
+ type = "styles";
22629
+ attrs;
22630
+ docDefaults;
22631
+ styles = [];
22337
22632
  constructor(styles2, docDefaults, attrs) {
22338
- this.type = "styles";
22339
- this.styles = [];
22340
22633
  this.styles = styles2;
22341
22634
  if (docDefaults) this.docDefaults = docDefaults;
22342
22635
  if (attrs) this.attrs = attrs;
@@ -22520,6 +22813,7 @@ class Wstyles {
22520
22813
  }
22521
22814
  }
22522
22815
  class Wimages {
22816
+ images;
22523
22817
  constructor(images = []) {
22524
22818
  this.images = images;
22525
22819
  }
@@ -22600,6 +22894,9 @@ class Wimages {
22600
22894
  }
22601
22895
  }
22602
22896
  class DocModel {
22897
+ document;
22898
+ styles;
22899
+ images;
22603
22900
  constructor(options) {
22604
22901
  this.document = options.document;
22605
22902
  this.styles = options.styles;
@@ -22718,99 +23015,36 @@ class ModelConverter {
22718
23015
  }
22719
23016
  }
22720
23017
  class DocumentEventBridge {
23018
+ doc;
23019
+ stage;
23020
+ layer;
23021
+ scrollContainer = null;
23022
+ padding = 48;
23023
+ // 光标离可视边缘的安全距离
23024
+ smooth = true;
23025
+ pointerDown = false;
23026
+ hasDragged = false;
23027
+ downClientX = 0;
23028
+ downClientY = 0;
23029
+ lastMoveEvent = null;
23030
+ dragThreshold = 4;
23031
+ // 拖拽阈值
23032
+ dragRaf = createRafOnce();
23033
+ scrollRaf = createRafOnce();
23034
+ autoScrollRaf = createRafOnce();
23035
+ activePointerId = null;
23036
+ // 最近一次指针在 浏览器视口坐标系 中的位置
23037
+ lastClientX = 0;
23038
+ lastClientY = 0;
23039
+ AUTO_EDGE = 60;
23040
+ // 边缘触发距离
23041
+ AUTO_MAX_SPEED = 24;
23042
+ // 最大滚动速度
23043
+ unsubRequestScroll = null;
23044
+ unsubAutoStart = null;
23045
+ unsubAutoMove = null;
23046
+ unsubAutoStop = null;
22721
23047
  constructor(doc, options) {
22722
- this.scrollContainer = null;
22723
- this.padding = 48;
22724
- this.smooth = true;
22725
- this.pointerDown = false;
22726
- this.hasDragged = false;
22727
- this.downClientX = 0;
22728
- this.downClientY = 0;
22729
- this.lastMoveEvent = null;
22730
- this.dragThreshold = 4;
22731
- this.dragRaf = createRafOnce();
22732
- this.scrollRaf = createRafOnce();
22733
- this.autoScrollRaf = createRafOnce();
22734
- this.activePointerId = null;
22735
- this.lastClientX = 0;
22736
- this.lastClientY = 0;
22737
- this.AUTO_EDGE = 60;
22738
- this.AUTO_MAX_SPEED = 24;
22739
- this.unsubRequestScroll = null;
22740
- this.unsubAutoStart = null;
22741
- this.unsubAutoMove = null;
22742
- this.unsubAutoStop = null;
22743
- this.onDown = (ev) => {
22744
- if (ev?.button !== void 0 && ev?.button !== 0) return;
22745
- if (!this.isInStage(ev)) return;
22746
- this.pointerDown = true;
22747
- this.hasDragged = false;
22748
- this.downClientX = ev.clientX;
22749
- this.downClientY = ev.clientY;
22750
- ev.preventDefault();
22751
- };
22752
- this.onMove = (ev) => {
22753
- if (!this.pointerDown) return;
22754
- const dx = ev.clientX - this.downClientX;
22755
- const dy = ev.clientY - this.downClientY;
22756
- const dist = Math.hypot(dx, dy);
22757
- if (!this.hasDragged && dist < this.dragThreshold) return;
22758
- if (!this.hasDragged) {
22759
- this.hasDragged = true;
22760
- this.emit("konva:dragstart", {
22761
- clientX: this.downClientX,
22762
- clientY: this.downClientY,
22763
- pointerId: ev.pointerId
22764
- });
22765
- }
22766
- this.lastMoveEvent = ev;
22767
- this.dragRaf.schedule(() => {
22768
- if (!this.lastMoveEvent) return;
22769
- this.emit("konva:dragmove", {
22770
- clientX: this.lastMoveEvent.clientX,
22771
- clientY: this.lastMoveEvent.clientY,
22772
- pointerId: this.lastMoveEvent.pointerId
22773
- });
22774
- this.lastMoveEvent = null;
22775
- });
22776
- ev.preventDefault();
22777
- };
22778
- this.onUp = (ev) => {
22779
- if (!this.pointerDown) return;
22780
- this.pointerDown = false;
22781
- const pos = { clientX: ev.clientX, clientY: ev.clientY, pointerId: ev.pointerId };
22782
- if (this.hasDragged) {
22783
- this.emit("konva:dragend", pos);
22784
- } else {
22785
- this.emit("konva:click", pos);
22786
- }
22787
- this.hasDragged = false;
22788
- this.lastMoveEvent = null;
22789
- ev.preventDefault();
22790
- };
22791
- this.onScroll = (_e) => {
22792
- this.scrollRaf.schedule(() => {
22793
- console.log("tangjian 1111111 onScroll 滚动事件,后续可以补充功能");
22794
- });
22795
- };
22796
- this.onRequestScroll = (payload) => {
22797
- if (payload?.source !== "keyboard") return;
22798
- queueMicrotask(() => this.ensureCaretVisibleByHiddenInput());
22799
- };
22800
- this.onAutoStart = (payload) => {
22801
- this.activePointerId = payload?.pointerId ?? null;
22802
- this.updatePointerPosition(payload);
22803
- this.startAutoScrollLoop();
22804
- };
22805
- this.onAutoMove = (payload) => {
22806
- if (!this.isForeignPointer(payload)) return;
22807
- this.updatePointerPosition(payload);
22808
- };
22809
- this.onAutoStop = (payload) => {
22810
- if (!this.isForeignPointer(payload)) return;
22811
- this.activePointerId = null;
22812
- this.stopAutoScrollLoop();
22813
- };
22814
23048
  this.doc = doc;
22815
23049
  if (options?.padding != null) this.padding = options.padding;
22816
23050
  if (options?.smooth != null) this.smooth = options.smooth;
@@ -22866,6 +23100,54 @@ class DocumentEventBridge {
22866
23100
  const el = stageNode?.container?.();
22867
23101
  return el && el.contains(ev.target);
22868
23102
  }
23103
+ onDown = (ev) => {
23104
+ if (ev?.button !== void 0 && ev?.button !== 0) return;
23105
+ if (!this.isInStage(ev)) return;
23106
+ this.pointerDown = true;
23107
+ this.hasDragged = false;
23108
+ this.downClientX = ev.clientX;
23109
+ this.downClientY = ev.clientY;
23110
+ ev.preventDefault();
23111
+ };
23112
+ onMove = (ev) => {
23113
+ if (!this.pointerDown) return;
23114
+ const dx = ev.clientX - this.downClientX;
23115
+ const dy = ev.clientY - this.downClientY;
23116
+ const dist = Math.hypot(dx, dy);
23117
+ if (!this.hasDragged && dist < this.dragThreshold) return;
23118
+ if (!this.hasDragged) {
23119
+ this.hasDragged = true;
23120
+ this.emit("konva:dragstart", {
23121
+ clientX: this.downClientX,
23122
+ clientY: this.downClientY,
23123
+ pointerId: ev.pointerId
23124
+ });
23125
+ }
23126
+ this.lastMoveEvent = ev;
23127
+ this.dragRaf.schedule(() => {
23128
+ if (!this.lastMoveEvent) return;
23129
+ this.emit("konva:dragmove", {
23130
+ clientX: this.lastMoveEvent.clientX,
23131
+ clientY: this.lastMoveEvent.clientY,
23132
+ pointerId: this.lastMoveEvent.pointerId
23133
+ });
23134
+ this.lastMoveEvent = null;
23135
+ });
23136
+ ev.preventDefault();
23137
+ };
23138
+ onUp = (ev) => {
23139
+ if (!this.pointerDown) return;
23140
+ this.pointerDown = false;
23141
+ const pos = { clientX: ev.clientX, clientY: ev.clientY, pointerId: ev.pointerId };
23142
+ if (this.hasDragged) {
23143
+ this.emit("konva:dragend", pos);
23144
+ } else {
23145
+ this.emit("konva:click", pos);
23146
+ }
23147
+ this.hasDragged = false;
23148
+ this.lastMoveEvent = null;
23149
+ ev.preventDefault();
23150
+ };
22869
23151
  emit(type4, pos) {
22870
23152
  const stageNode = this.stage.value?.getNode?.();
22871
23153
  const layerNode = this.layer.value?.getNode?.();
@@ -22875,6 +23157,15 @@ class DocumentEventBridge {
22875
23157
  layer: layerNode
22876
23158
  });
22877
23159
  }
23160
+ onScroll = (_e) => {
23161
+ this.scrollRaf.schedule(() => {
23162
+ console.log("tangjian 1111111 onScroll 滚动事件,后续可以补充功能");
23163
+ });
23164
+ };
23165
+ onRequestScroll = (payload) => {
23166
+ if (payload?.source !== "keyboard") return;
23167
+ queueMicrotask(() => this.ensureCaretVisibleByHiddenInput());
23168
+ };
22878
23169
  ensureCaretVisibleByHiddenInput() {
22879
23170
  const container = this.scrollContainer;
22880
23171
  if (!container) return;
@@ -22898,6 +23189,20 @@ class DocumentEventBridge {
22898
23189
  });
22899
23190
  }
22900
23191
  }
23192
+ onAutoStart = (payload) => {
23193
+ this.activePointerId = payload?.pointerId ?? null;
23194
+ this.updatePointerPosition(payload);
23195
+ this.startAutoScrollLoop();
23196
+ };
23197
+ onAutoMove = (payload) => {
23198
+ if (!this.isForeignPointer(payload)) return;
23199
+ this.updatePointerPosition(payload);
23200
+ };
23201
+ onAutoStop = (payload) => {
23202
+ if (!this.isForeignPointer(payload)) return;
23203
+ this.activePointerId = null;
23204
+ this.stopAutoScrollLoop();
23205
+ };
22901
23206
  isForeignPointer(payload) {
22902
23207
  return this.activePointerId == null || payload?.pointerId == null || payload.pointerId === this.activePointerId;
22903
23208
  }
@@ -24182,9 +24487,8 @@ var FIELD_TYPE = /* @__PURE__ */ ((FIELD_TYPE2) => {
24182
24487
  return FIELD_TYPE2;
24183
24488
  })(FIELD_TYPE || {});
24184
24489
  class FieldRegistry {
24185
- constructor() {
24186
- this.providers = /* @__PURE__ */ new Map();
24187
- }
24490
+ static instance;
24491
+ providers = /* @__PURE__ */ new Map();
24188
24492
  static getInstance() {
24189
24493
  if (!this.instance) this.instance = new FieldRegistry();
24190
24494
  return this.instance;
@@ -24200,9 +24504,8 @@ class FieldRegistry {
24200
24504
  }
24201
24505
  }
24202
24506
  class ModelRegistry {
24203
- constructor() {
24204
- this.providers = /* @__PURE__ */ new Map();
24205
- }
24507
+ static instance;
24508
+ providers = /* @__PURE__ */ new Map();
24206
24509
  static getInstance() {
24207
24510
  if (!this.instance) this.instance = new ModelRegistry();
24208
24511
  return this.instance;
@@ -24217,7 +24520,8 @@ class ModelRegistry {
24217
24520
  this.providers.clear();
24218
24521
  }
24219
24522
  }
24220
- const _FieldEngine = class _FieldEngine {
24523
+ class FieldEngine {
24524
+ static bootedSuites = /* @__PURE__ */ new Set();
24221
24525
  static bootstrap(opts) {
24222
24526
  const { suiteKey, fieldProvider, modelProvider } = opts;
24223
24527
  if (this.bootedSuites.has(suiteKey)) return;
@@ -24225,9 +24529,7 @@ const _FieldEngine = class _FieldEngine {
24225
24529
  modelProvider && ModelRegistry.getInstance().register(modelProvider);
24226
24530
  this.bootedSuites.add(suiteKey);
24227
24531
  }
24228
- };
24229
- _FieldEngine.bootedSuites = /* @__PURE__ */ new Set();
24230
- let FieldEngine = _FieldEngine;
24532
+ }
24231
24533
  function pLimit(concurrency) {
24232
24534
  const queue = [];
24233
24535
  let active = 0;
@@ -24258,75 +24560,12 @@ function pLimit(concurrency) {
24258
24560
  });
24259
24561
  };
24260
24562
  }
24261
- class FieldScope {
24262
- constructor(modelKeys, fieldService, modelService) {
24263
- this.fieldService = fieldService;
24264
- this.modelService = modelService;
24265
- this.modelKeys = /* @__PURE__ */ new Set();
24266
- this.modelStatus = /* @__PURE__ */ new Map();
24267
- this.fieldStatus = /* @__PURE__ */ new Map();
24268
- modelKeys.forEach((k) => {
24269
- this.modelKeys.add(k);
24270
- this.modelStatus.set(k, "idle");
24271
- this.fieldStatus.set(k, "idle");
24272
- });
24273
- }
24274
- /**
24275
- * 预加载
24276
- */
24277
- async preload(concurrency = 4) {
24278
- const limit = pLimit(concurrency);
24279
- const tasks = Array.from(this.modelKeys).map((k) => limit(() => this.run(k)));
24280
- await Promise.all(tasks);
24281
- }
24282
- async run(modelKey) {
24283
- try {
24284
- this.modelStatus.set(modelKey, "loading");
24285
- await this.modelService.queryModelInfo(modelKey);
24286
- this.modelStatus.set(modelKey, "completed");
24287
- this.fieldStatus.set(modelKey, "loading");
24288
- await this.fieldService.queryFieldList(modelKey);
24289
- this.fieldStatus.set(modelKey, "completed");
24290
- } catch (e) {
24291
- this.modelStatus.set(modelKey, "failed");
24292
- this.fieldStatus.set(modelKey, "failed");
24293
- throw e;
24294
- }
24295
- }
24296
- async addModel(modelKey, autoLoad = true) {
24297
- if (this.modelKeys.has(modelKey)) return;
24298
- this.modelKeys.add(modelKey);
24299
- this.modelStatus.set(modelKey, "idle");
24300
- this.fieldStatus.set(modelKey, "idle");
24301
- if (autoLoad) {
24302
- await this.run(modelKey);
24303
- }
24304
- }
24305
- /** 刷新某一个模型 */
24306
- async reloadModelKey(modelKey) {
24307
- this.modelService.clear(modelKey);
24308
- this.fieldService.clear(modelKey);
24309
- await this.run(modelKey);
24310
- }
24311
- getModelKeys() {
24312
- return Array.from(this.modelKeys);
24313
- }
24314
- dispose() {
24315
- this.modelKeys.forEach((k) => {
24316
- this.modelService.clear(k);
24317
- this.fieldService.clear(k);
24318
- });
24319
- this.modelKeys.clear();
24320
- this.modelStatus.clear();
24321
- this.fieldStatus.clear();
24322
- }
24323
- }
24324
24563
  class FieldService {
24325
24564
  constructor(suiteKey) {
24326
24565
  this.suiteKey = suiteKey;
24327
- this.registry = FieldRegistry.getInstance();
24328
- this.runtimes = /* @__PURE__ */ new Map();
24329
24566
  }
24567
+ registry = FieldRegistry.getInstance();
24568
+ runtimes = /* @__PURE__ */ new Map();
24330
24569
  runtimeKey(modelKey) {
24331
24570
  return `${this.suiteKey}:${modelKey}`;
24332
24571
  }
@@ -24370,9 +24609,9 @@ class FieldService {
24370
24609
  class ModelService {
24371
24610
  constructor(suiteKey) {
24372
24611
  this.suiteKey = suiteKey;
24373
- this.registry = ModelRegistry.getInstance();
24374
- this.cache = /* @__PURE__ */ new Map();
24375
24612
  }
24613
+ registry = ModelRegistry.getInstance();
24614
+ cache = /* @__PURE__ */ new Map();
24376
24615
  runtimeKey(modelKey) {
24377
24616
  return `${this.suiteKey}:${modelKey}`;
24378
24617
  }
@@ -24395,9 +24634,73 @@ class ModelService {
24395
24634
  this.cache.clear();
24396
24635
  }
24397
24636
  }
24398
- const _BaseRegistry = class _BaseRegistry {
24637
+ class FieldScope {
24638
+ constructor(modelKeys, fieldService, modelService) {
24639
+ this.fieldService = fieldService;
24640
+ this.modelService = modelService;
24641
+ modelKeys.forEach((k) => {
24642
+ this.modelKeys.add(k);
24643
+ this.modelStatus.set(k, "idle");
24644
+ this.fieldStatus.set(k, "idle");
24645
+ });
24646
+ }
24647
+ modelKeys = /* @__PURE__ */ new Set();
24648
+ modelStatus = /* @__PURE__ */ new Map();
24649
+ fieldStatus = /* @__PURE__ */ new Map();
24650
+ /**
24651
+ * 预加载
24652
+ */
24653
+ async preload(concurrency = 4) {
24654
+ const limit = pLimit(concurrency);
24655
+ const tasks = Array.from(this.modelKeys).map((k) => limit(() => this.run(k)));
24656
+ await Promise.all(tasks);
24657
+ }
24658
+ async run(modelKey) {
24659
+ try {
24660
+ this.modelStatus.set(modelKey, "loading");
24661
+ await this.modelService.queryModelInfo(modelKey);
24662
+ this.modelStatus.set(modelKey, "completed");
24663
+ this.fieldStatus.set(modelKey, "loading");
24664
+ await this.fieldService.queryFieldList(modelKey);
24665
+ this.fieldStatus.set(modelKey, "completed");
24666
+ } catch (e) {
24667
+ this.modelStatus.set(modelKey, "failed");
24668
+ this.fieldStatus.set(modelKey, "failed");
24669
+ throw e;
24670
+ }
24671
+ }
24672
+ async addModel(modelKey, autoLoad = true) {
24673
+ if (this.modelKeys.has(modelKey)) return;
24674
+ this.modelKeys.add(modelKey);
24675
+ this.modelStatus.set(modelKey, "idle");
24676
+ this.fieldStatus.set(modelKey, "idle");
24677
+ if (autoLoad) {
24678
+ await this.run(modelKey);
24679
+ }
24680
+ }
24681
+ /** 刷新某一个模型 */
24682
+ async reloadModelKey(modelKey) {
24683
+ this.modelService.clear(modelKey);
24684
+ this.fieldService.clear(modelKey);
24685
+ await this.run(modelKey);
24686
+ }
24687
+ getModelKeys() {
24688
+ return Array.from(this.modelKeys);
24689
+ }
24690
+ dispose() {
24691
+ this.modelKeys.forEach((k) => {
24692
+ this.modelService.clear(k);
24693
+ this.fieldService.clear(k);
24694
+ });
24695
+ this.modelKeys.clear();
24696
+ this.modelStatus.clear();
24697
+ this.fieldStatus.clear();
24698
+ }
24699
+ }
24700
+ class BaseRegistry {
24701
+ static instances = /* @__PURE__ */ new Map();
24702
+ store = /* @__PURE__ */ new Map();
24399
24703
  constructor() {
24400
- this.store = /* @__PURE__ */ new Map();
24401
24704
  }
24402
24705
  /**
24403
24706
  * 获取单例实例
@@ -24405,10 +24708,10 @@ const _BaseRegistry = class _BaseRegistry {
24405
24708
  */
24406
24709
  static getInstance() {
24407
24710
  const className = this.name;
24408
- if (!_BaseRegistry.instances.has(className)) {
24409
- _BaseRegistry.instances.set(className, new this());
24711
+ if (!BaseRegistry.instances.has(className)) {
24712
+ BaseRegistry.instances.set(className, new this());
24410
24713
  }
24411
- return _BaseRegistry.instances.get(className);
24714
+ return BaseRegistry.instances.get(className);
24412
24715
  }
24413
24716
  /**
24414
24717
  * 通用注册逻辑:按 suiteKey 注册一批 K-V 映射
@@ -24460,9 +24763,7 @@ const _BaseRegistry = class _BaseRegistry {
24460
24763
  clear() {
24461
24764
  this.store.clear();
24462
24765
  }
24463
- };
24464
- _BaseRegistry.instances = /* @__PURE__ */ new Map();
24465
- let BaseRegistry = _BaseRegistry;
24766
+ }
24466
24767
  class ComponentRegistry extends BaseRegistry {
24467
24768
  register(suiteKey, components) {
24468
24769
  super.register(suiteKey, components);
@@ -24470,6 +24771,9 @@ class ComponentRegistry extends BaseRegistry {
24470
24771
  }
24471
24772
  const componentRegistry = ComponentRegistry.getInstance();
24472
24773
  class BaseService {
24774
+ suiteKey;
24775
+ registry;
24776
+ suiteMap;
24473
24777
  constructor(suiteKey, registry2) {
24474
24778
  this.suiteKey = suiteKey;
24475
24779
  this.registry = registry2;
@@ -24568,6 +24872,14 @@ class SuiteRuntime {
24568
24872
  console.log("=====> fieldManifestService", this.fieldManifestService);
24569
24873
  console.log("=====> fieldScope", this.fieldScope);
24570
24874
  }
24875
+ fieldService;
24876
+ modelService;
24877
+ fieldScope;
24878
+ componentService;
24879
+ panelRouterService;
24880
+ panelSchemaService;
24881
+ panelConfigService;
24882
+ fieldManifestService;
24571
24883
  preload() {
24572
24884
  return this.fieldScope.preload();
24573
24885
  }
@@ -27819,7 +28131,7 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
27819
28131
  modelKeys: [props.modelKey]
27820
28132
  });
27821
28133
  const val = ref();
27822
- const radioVal2 = ref();
28134
+ const radioVal = ref();
27823
28135
  const checked = ref();
27824
28136
  const list = ref();
27825
28137
  const sliderVal = ref();
@@ -27882,8 +28194,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
27882
28194
  ]),
27883
28195
  createElementVNode("div", _hoisted_8$4, [
27884
28196
  createVNode(unref(GctRadioGroup), {
27885
- modelValue: radioVal2.value,
27886
- "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => radioVal2.value = $event)
28197
+ modelValue: radioVal.value,
28198
+ "onUpdate:modelValue": _cache[3] || (_cache[3] = ($event) => radioVal.value = $event)
27887
28199
  }, {
27888
28200
  default: withCtx(() => [
27889
28201
  createVNode(unref(GctRadio), { value: "a" }, {
@@ -27904,8 +28216,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
27904
28216
  ]),
27905
28217
  createElementVNode("div", _hoisted_9$3, [
27906
28218
  createVNode(unref(GctRadioGroup), {
27907
- modelValue: radioVal2.value,
27908
- "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => radioVal2.value = $event),
28219
+ modelValue: radioVal.value,
28220
+ "onUpdate:modelValue": _cache[4] || (_cache[4] = ($event) => radioVal.value = $event),
27909
28221
  optionType: "button"
27910
28222
  }, {
27911
28223
  default: withCtx(() => [
@@ -27933,8 +28245,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
27933
28245
  ]),
27934
28246
  createElementVNode("div", _hoisted_10$3, [
27935
28247
  createVNode(unref(GctRadioGroup), {
27936
- modelValue: radioVal2.value,
27937
- "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => radioVal2.value = $event),
28248
+ modelValue: radioVal.value,
28249
+ "onUpdate:modelValue": _cache[5] || (_cache[5] = ($event) => radioVal.value = $event),
27938
28250
  size: "small"
27939
28251
  }, {
27940
28252
  default: withCtx(() => [
@@ -27957,8 +28269,8 @@ const _sfc_main$J = /* @__PURE__ */ defineComponent({
27957
28269
  createElementVNode("div", _hoisted_11$2, [
27958
28270
  createVNode(unref(GctRadio), {
27959
28271
  value: "333",
27960
- modelValue: radioVal2.value,
27961
- "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => radioVal2.value = $event)
28272
+ modelValue: radioVal.value,
28273
+ "onUpdate:modelValue": _cache[6] || (_cache[6] = ($event) => radioVal.value = $event)
27962
28274
  }, {
27963
28275
  default: withCtx(() => [..._cache[22] || (_cache[22] = [
27964
28276
  createTextVNode("333", -1)
@@ -48360,16 +48672,25 @@ const api = {
48360
48672
  platform: new ApiManage("/gct-platform/api", apiConfig)
48361
48673
  };
48362
48674
  class FieldProviderBase {
48675
+ /** 套件标识 */
48676
+ suiteKey;
48677
+ /** 缓存有效期(毫秒,-1 表示永久缓存) */
48678
+ cacheTime;
48363
48679
  constructor(cfg) {
48364
48680
  this.suiteKey = cfg.suiteKey;
48365
48681
  this.cacheTime = cfg.cacheTime ?? -1;
48366
48682
  }
48367
48683
  }
48368
48684
  class FieldProviderRuntime {
48685
+ base;
48686
+ modelKey;
48687
+ // 缓存字段列表结果
48688
+ listCache = null;
48689
+ // 缓存字段映射(key: FieldKey, value: FieldMeta)- 快速通过 key 查询
48690
+ keyMap = /* @__PURE__ */ new Map();
48691
+ // 缓存字段映射(key: FieldId, value: FieldMeta)- 快速通过 id 查询
48692
+ idMap = /* @__PURE__ */ new Map();
48369
48693
  constructor(base, modelKey) {
48370
- this.listCache = null;
48371
- this.keyMap = /* @__PURE__ */ new Map();
48372
- this.idMap = /* @__PURE__ */ new Map();
48373
48694
  this.base = base;
48374
48695
  this.modelKey = modelKey;
48375
48696
  }
@@ -48423,6 +48744,8 @@ class FieldProviderRuntime {
48423
48744
  }
48424
48745
  }
48425
48746
  class EdhrFieldRuntime extends FieldProviderRuntime {
48747
+ fetcher;
48748
+ filterFn;
48426
48749
  constructor(base, modelKey, fetcher, filterFn2) {
48427
48750
  super(base, modelKey);
48428
48751
  this.fetcher = fetcher;
@@ -48442,6 +48765,8 @@ class EdhrFieldRuntime extends FieldProviderRuntime {
48442
48765
  }
48443
48766
  }
48444
48767
  class EdhrFieldProvider extends FieldProviderBase {
48768
+ fetcherFactory;
48769
+ filterFn;
48445
48770
  constructor(cfg, fetcherFactory2, filterFn2) {
48446
48771
  super(cfg);
48447
48772
  this.fetcherFactory = fetcherFactory2;
@@ -48597,6 +48922,8 @@ const edhrFieldProvider = new EdhrFieldProvider(
48597
48922
  filterFn
48598
48923
  );
48599
48924
  class ModelProviderBase {
48925
+ /** 套件标识 */
48926
+ suiteKey;
48600
48927
  constructor(opts) {
48601
48928
  this.suiteKey = opts.suiteKey;
48602
48929
  }
@@ -50138,7 +50465,7 @@ const _hoisted_5$6 = { class: "content" };
50138
50465
  const _sfc_main$C = /* @__PURE__ */ defineComponent({
50139
50466
  __name: "PaperPanel",
50140
50467
  setup(__props) {
50141
- const radioVal2 = ref(OrientationTypeConst.Portrait);
50468
+ const radioVal = ref(OrientationTypeConst.Portrait);
50142
50469
  const padding = ref({ l: 9, r: 9, t: 9, b: 9 });
50143
50470
  const headerBool = ref(false);
50144
50471
  return (_ctx, _cache) => {
@@ -50192,8 +50519,8 @@ const _sfc_main$C = /* @__PURE__ */ defineComponent({
50192
50519
  }, {
50193
50520
  default: withCtx(() => [
50194
50521
  createVNode(_sfc_main$F, {
50195
- orientation: radioVal2.value,
50196
- "onUpdate:orientation": _cache[0] || (_cache[0] = ($event) => radioVal2.value = $event)
50522
+ orientation: radioVal.value,
50523
+ "onUpdate:orientation": _cache[0] || (_cache[0] = ($event) => radioVal.value = $event)
50197
50524
  }, null, 8, ["orientation"])
50198
50525
  ]),
50199
50526
  _: 1
@@ -52004,7 +52331,6 @@ const _hoisted_16 = {
52004
52331
  key: 0,
52005
52332
  class: "error"
52006
52333
  };
52007
- const radioVal = "formula";
52008
52334
  const _sfc_main$y = /* @__PURE__ */ defineComponent({
52009
52335
  __name: "field-dependency-modal",
52010
52336
  props: {
@@ -52022,6 +52348,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
52022
52348
  expression: "",
52023
52349
  strategy: AssignmentStrategyTypeConst.AlwaysCover
52024
52350
  });
52351
+ const radioVal = ref("formula");
52025
52352
  const errors = reactive({
52026
52353
  prerequisites: "",
52027
52354
  assignment: ""
@@ -52141,8 +52468,8 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
52141
52468
  _cache[10] || (_cache[10] = createElementVNode("div", { class: "label" }, "赋值类型", -1)),
52142
52469
  createElementVNode("div", _hoisted_8$3, [
52143
52470
  createVNode(unref(GctRadioGroup), {
52144
- modelValue: radioVal,
52145
- "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => radioVal = $event)
52471
+ modelValue: radioVal.value,
52472
+ "onUpdate:modelValue": _cache[1] || (_cache[1] = ($event) => radioVal.value = $event)
52146
52473
  }, {
52147
52474
  default: withCtx(() => [
52148
52475
  createVNode(unref(GctRadio), { value: "formula" }, {
@@ -52153,7 +52480,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
52153
52480
  })
52154
52481
  ]),
52155
52482
  _: 1
52156
- })
52483
+ }, 8, ["modelValue"])
52157
52484
  ])
52158
52485
  ]),
52159
52486
  createElementVNode("div", _hoisted_9$2, [
@@ -52209,7 +52536,7 @@ const _sfc_main$y = /* @__PURE__ */ defineComponent({
52209
52536
  };
52210
52537
  }
52211
52538
  });
52212
- const FieldDependencyModal = /* @__PURE__ */ _export_sfc(_sfc_main$y, [["__scopeId", "data-v-4e05828e"]]);
52539
+ const FieldDependencyModal = /* @__PURE__ */ _export_sfc(_sfc_main$y, [["__scopeId", "data-v-f7304cea"]]);
52213
52540
  const _hoisted_1$q = { class: "field-dependency-module" };
52214
52541
  const _hoisted_2$c = { class: "field-dependency-list" };
52215
52542
  const _hoisted_3$7 = { class: "item-header" };