@windoc/core 0.2.9 → 0.2.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -66,6 +66,17 @@ var LETTER_CLASS = {
66
66
  };
67
67
  var METRICS_BASIS_TEXT = "M";
68
68
 
69
+ // src/dataset/enum/Title.ts
70
+ var TitleLevel = /* @__PURE__ */ ((TitleLevel2) => {
71
+ TitleLevel2["FIRST"] = "first";
72
+ TitleLevel2["SECOND"] = "second";
73
+ TitleLevel2["THIRD"] = "third";
74
+ TitleLevel2["FOURTH"] = "fourth";
75
+ TitleLevel2["FIFTH"] = "fifth";
76
+ TitleLevel2["SIXTH"] = "sixth";
77
+ return TitleLevel2;
78
+ })(TitleLevel || {});
79
+
69
80
  // src/dataset/enum/Row.ts
70
81
  var RowFlex = /* @__PURE__ */ ((RowFlex2) => {
71
82
  RowFlex2["LEFT"] = "left";
@@ -3885,17 +3896,6 @@ var ulPresetCycles = {
3885
3896
  var INDENT_PER_LEVEL = 20;
3886
3897
  var MAX_LIST_LEVEL = 8;
3887
3898
 
3888
- // src/dataset/enum/Title.ts
3889
- var TitleLevel = /* @__PURE__ */ ((TitleLevel2) => {
3890
- TitleLevel2["FIRST"] = "first";
3891
- TitleLevel2["SECOND"] = "second";
3892
- TitleLevel2["THIRD"] = "third";
3893
- TitleLevel2["FOURTH"] = "fourth";
3894
- TitleLevel2["FIFTH"] = "fifth";
3895
- TitleLevel2["SIXTH"] = "sixth";
3896
- return TitleLevel2;
3897
- })(TitleLevel || {});
3898
-
3899
3899
  // src/dataset/constant/Title.ts
3900
3900
  var defaultTitleOption = {
3901
3901
  defaultFirstSize: 20,
@@ -6436,11 +6436,13 @@ var Cursor = class {
6436
6436
  const curIndex = cursorPosition.index;
6437
6437
  const curElement = elementList[curIndex];
6438
6438
  const nextElement = elementList[curIndex + 1];
6439
- if (curElement && curElement.type === "image" /* IMAGE */ || nextElement && nextElement.type === "image" /* IMAGE */) {
6439
+ const isNearImage = curElement && curElement.type === "image" /* IMAGE */ || nextElement && nextElement.type === "image" /* IMAGE */;
6440
+ const isNearSeparator = curElement && curElement.type === "separator" /* SEPARATOR */ || nextElement && nextElement.type === "separator" /* SEPARATOR */;
6441
+ if (isNearImage || isNearSeparator) {
6440
6442
  const { defaultSize, defaultFont } = this.options;
6441
6443
  const ctx = this.draw.getCtx();
6442
6444
  ctx.save();
6443
- ctx.font = `${defaultSize * scale}px ${defaultFont}`;
6445
+ ctx.font = `${defaultSize * (96 / 72) * scale}px ${defaultFont}`;
6444
6446
  const textMetrics = ctx.measureText("M");
6445
6447
  ctx.restore();
6446
6448
  const textHeight = textMetrics.actualBoundingBoxAscent + textMetrics.actualBoundingBoxDescent;
@@ -6451,10 +6453,9 @@ var Cursor = class {
6451
6453
  boundingBoxDescent: textMetrics.actualBoundingBoxDescent
6452
6454
  };
6453
6455
  }
6454
- const descent = effectiveMetrics.boundingBoxDescent < 0 ? 0 : effectiveMetrics.boundingBoxDescent;
6455
6456
  const cursorPadding = 2 * scale;
6456
- const cursorHeight = effectiveMetrics.height + descent + cursorPadding;
6457
- const cursorTop = leftTop[1] + ascent - effectiveMetrics.height + cursorPadding / 2 + preY;
6457
+ const cursorHeight = effectiveMetrics.boundingBoxAscent + effectiveMetrics.boundingBoxDescent + cursorPadding;
6458
+ const cursorTop = isNearImage ? leftTop[1] + cursorPosition.lineHeight - effectiveMetrics.boundingBoxDescent - cursorPadding / 2 + preY : leftTop[1] + ascent - effectiveMetrics.boundingBoxAscent - cursorPadding / 2 + preY;
6458
6459
  const cursorLeft = hitLineStartIndex ? leftTop[0] : rightTop[0];
6459
6460
  agentCursorDom.style.left = `${cursorLeft}px`;
6460
6461
  agentCursorDom.style.top = `${cursorTop}px`;
@@ -9231,7 +9232,7 @@ var Position = class {
9231
9232
  }
9232
9233
  }
9233
9234
  x += curRow.offsetX || 0;
9234
- y += curRow.offsetY || 0;
9235
+ y += (curRow.offsetY || 0) + (curRow.spaceAbove || 0);
9235
9236
  const tablePreX = x;
9236
9237
  const tablePreY = y;
9237
9238
  for (let j = 0; j < curRow.elementList.length; j++) {
@@ -9344,7 +9345,7 @@ var Position = class {
9344
9345
  }
9345
9346
  }
9346
9347
  x = startX;
9347
- y += curRow.height;
9348
+ y += curRow.height + (curRow.spaceBelow || 0);
9348
9349
  }
9349
9350
  return { x, y, index };
9350
9351
  }
@@ -21733,6 +21734,28 @@ var Draw = class {
21733
21734
  }
21734
21735
  return rowList;
21735
21736
  }
21737
+ _applyRowSpacing() {
21738
+ const { scale } = this.options;
21739
+ const PT_TO_PX = 96 / 72;
21740
+ const HEADING_SPACE = {
21741
+ ["first" /* FIRST */]: { above: 20, below: 6 },
21742
+ ["second" /* SECOND */]: { above: 18, below: 6 },
21743
+ ["third" /* THIRD */]: { above: 16, below: 4 },
21744
+ ["fourth" /* FOURTH */]: { above: 14, below: 4 },
21745
+ ["fifth" /* FIFTH */]: { above: 12, below: 4 },
21746
+ ["sixth" /* SIXTH */]: { above: 12, below: 4 }
21747
+ };
21748
+ for (const row of this.rowList) {
21749
+ const headingEl = row.elementList.find((el) => el.level != null);
21750
+ if (headingEl?.level != null) {
21751
+ const space = HEADING_SPACE[headingEl.level];
21752
+ if (space) {
21753
+ row.spaceAbove = space.above * PT_TO_PX * scale;
21754
+ row.spaceBelow = space.below * PT_TO_PX * scale;
21755
+ }
21756
+ }
21757
+ }
21758
+ }
21736
21759
  _computePageList() {
21737
21760
  const pageRowList = [[]];
21738
21761
  const {
@@ -21749,7 +21772,7 @@ var Draw = class {
21749
21772
  this.rowList[i].columnNo = 0;
21750
21773
  }
21751
21774
  pageHeight += this.rowList.reduce(
21752
- (pre, cur) => pre + cur.height + (cur.offsetY || 0),
21775
+ (pre, cur) => pre + cur.height + (cur.offsetY || 0) + (cur.spaceAbove || 0) + (cur.spaceBelow || 0),
21753
21776
  0
21754
21777
  );
21755
21778
  const dpr = this.getPagePixelRatio();
@@ -21772,10 +21795,11 @@ var Draw = class {
21772
21795
  const rowOffsetY = row.offsetY || 0;
21773
21796
  const isPageBreak = this.rowList[i - 1]?.isPageBreak;
21774
21797
  const isColumnBreak = this.rowList[i - 1]?.isColumnBreak;
21775
- if (row.height + rowOffsetY + pageHeight > height || isPageBreak || isColumnBreak) {
21798
+ const rowTotalHeight = row.height + rowOffsetY + (row.spaceAbove || 0) + (row.spaceBelow || 0);
21799
+ if (rowTotalHeight + pageHeight > height || isPageBreak || isColumnBreak) {
21776
21800
  if ((!isPageBreak || isColumnBreak) && columnCount > 1 && columnNo < columnCount - 1) {
21777
21801
  columnNo++;
21778
- pageHeight = marginHeight + row.height + rowOffsetY;
21802
+ pageHeight = marginHeight + rowTotalHeight;
21779
21803
  row.columnNo = columnNo;
21780
21804
  pageRowList[pageNo].push(row);
21781
21805
  } else {
@@ -21784,14 +21808,14 @@ var Draw = class {
21784
21808
  break;
21785
21809
  }
21786
21810
  columnNo = 0;
21787
- pageHeight = marginHeight + row.height + rowOffsetY;
21811
+ pageHeight = marginHeight + rowTotalHeight;
21788
21812
  row.columnNo = columnNo;
21789
21813
  pageRowList.push([row]);
21790
21814
  pageNo++;
21791
21815
  }
21792
21816
  } else {
21793
21817
  row.columnNo = columnNo;
21794
- pageHeight += row.height + rowOffsetY;
21818
+ pageHeight += rowTotalHeight;
21795
21819
  pageRowList[pageNo].push(row);
21796
21820
  }
21797
21821
  }
@@ -22314,6 +22338,7 @@ var Draw = class {
22314
22338
  surroundElementList,
22315
22339
  elementList: this.elementList
22316
22340
  });
22341
+ this._applyRowSpacing();
22317
22342
  this.pageRowList = this._computePageList();
22318
22343
  this.position.computePositionList();
22319
22344
  this.area.compute();
@@ -23641,6 +23666,13 @@ var CommandAdapt = class {
23641
23666
  ]);
23642
23667
  curIndex = startIndex;
23643
23668
  }
23669
+ const afterSepIndex = curIndex + 2;
23670
+ if (elementList[afterSepIndex]?.value !== ZERO) {
23671
+ this.draw.spliceElementList(elementList, afterSepIndex, 0, [
23672
+ { value: ZERO }
23673
+ ]);
23674
+ }
23675
+ curIndex = afterSepIndex - 1;
23644
23676
  }
23645
23677
  this.range.setRange(curIndex, curIndex);
23646
23678
  this.draw.render({ curIndex });