@windoc/core 0.2.8 → 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,25 +3896,14 @@ 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
- defaultFirstSize: 26,
3902
- defaultSecondSize: 24,
3903
- defaultThirdSize: 22,
3904
- defaultFourthSize: 20,
3905
- defaultFifthSize: 18,
3906
- defaultSixthSize: 16
3901
+ defaultFirstSize: 20,
3902
+ defaultSecondSize: 16,
3903
+ defaultThirdSize: 14,
3904
+ defaultFourthSize: 12,
3905
+ defaultFifthSize: 11,
3906
+ defaultSixthSize: 11
3907
3907
  };
3908
3908
  var titleSizeMapping = {
3909
3909
  ["first" /* FIRST */]: "defaultFirstSize",
@@ -5324,7 +5324,7 @@ function convertElementToDom(element, options) {
5324
5324
  if (element.italic) {
5325
5325
  dom.style.fontStyle = "italic";
5326
5326
  }
5327
- dom.style.fontSize = `${element.size || options.defaultSize}px`;
5327
+ dom.style.fontSize = `${element.size || options.defaultSize}pt`;
5328
5328
  if (element.highlight) {
5329
5329
  dom.style.backgroundColor = element.highlight;
5330
5330
  }
@@ -5650,7 +5650,7 @@ function convertTextNodeToElement(textNode) {
5650
5650
  color: style.color,
5651
5651
  bold: Number(style.fontWeight) > 500,
5652
5652
  italic: style.fontStyle.includes("italic"),
5653
- size: Math.floor(parseFloat(style.fontSize))
5653
+ size: Math.round(parseFloat(style.fontSize) * 0.75)
5654
5654
  };
5655
5655
  if (anchorNode.nodeName === "SUB" || style.verticalAlign === "sub") {
5656
5656
  element.type = "subscript" /* SUBSCRIPT */;
@@ -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
  }
@@ -21091,7 +21092,8 @@ var Draw = class {
21091
21092
  const { defaultSize, defaultFont } = this.options;
21092
21093
  const font = el.font || defaultFont;
21093
21094
  const size = el.actualSize || el.size || defaultSize;
21094
- return `${el.italic ? "italic " : ""}${el.bold ? "bold " : ""}${size * scale}px ${font}`;
21095
+ const sizePx = size * (96 / 72) * scale;
21096
+ return `${el.italic ? "italic " : ""}${el.bold ? "bold " : ""}${sizePx}px ${font}`;
21095
21097
  }
21096
21098
  getElementSize(el) {
21097
21099
  return el.actualSize || el.size || this.options.defaultSize;
@@ -21732,6 +21734,28 @@ var Draw = class {
21732
21734
  }
21733
21735
  return rowList;
21734
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
+ }
21735
21759
  _computePageList() {
21736
21760
  const pageRowList = [[]];
21737
21761
  const {
@@ -21748,7 +21772,7 @@ var Draw = class {
21748
21772
  this.rowList[i].columnNo = 0;
21749
21773
  }
21750
21774
  pageHeight += this.rowList.reduce(
21751
- (pre, cur) => pre + cur.height + (cur.offsetY || 0),
21775
+ (pre, cur) => pre + cur.height + (cur.offsetY || 0) + (cur.spaceAbove || 0) + (cur.spaceBelow || 0),
21752
21776
  0
21753
21777
  );
21754
21778
  const dpr = this.getPagePixelRatio();
@@ -21771,10 +21795,11 @@ var Draw = class {
21771
21795
  const rowOffsetY = row.offsetY || 0;
21772
21796
  const isPageBreak = this.rowList[i - 1]?.isPageBreak;
21773
21797
  const isColumnBreak = this.rowList[i - 1]?.isColumnBreak;
21774
- 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) {
21775
21800
  if ((!isPageBreak || isColumnBreak) && columnCount > 1 && columnNo < columnCount - 1) {
21776
21801
  columnNo++;
21777
- pageHeight = marginHeight + row.height + rowOffsetY;
21802
+ pageHeight = marginHeight + rowTotalHeight;
21778
21803
  row.columnNo = columnNo;
21779
21804
  pageRowList[pageNo].push(row);
21780
21805
  } else {
@@ -21783,14 +21808,14 @@ var Draw = class {
21783
21808
  break;
21784
21809
  }
21785
21810
  columnNo = 0;
21786
- pageHeight = marginHeight + row.height + rowOffsetY;
21811
+ pageHeight = marginHeight + rowTotalHeight;
21787
21812
  row.columnNo = columnNo;
21788
21813
  pageRowList.push([row]);
21789
21814
  pageNo++;
21790
21815
  }
21791
21816
  } else {
21792
21817
  row.columnNo = columnNo;
21793
- pageHeight += row.height + rowOffsetY;
21818
+ pageHeight += rowTotalHeight;
21794
21819
  pageRowList[pageNo].push(row);
21795
21820
  }
21796
21821
  }
@@ -22313,6 +22338,7 @@ var Draw = class {
22313
22338
  surroundElementList,
22314
22339
  elementList: this.elementList
22315
22340
  });
22341
+ this._applyRowSpacing();
22316
22342
  this.pageRowList = this._computePageList();
22317
22343
  this.position.computePositionList();
22318
22344
  this.area.compute();
@@ -23640,6 +23666,13 @@ var CommandAdapt = class {
23640
23666
  ]);
23641
23667
  curIndex = startIndex;
23642
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;
23643
23676
  }
23644
23677
  this.range.setRange(curIndex, curIndex);
23645
23678
  this.draw.render({ curIndex });