@windoc/core 0.3.27 → 0.3.28

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
@@ -1,5 +1,5 @@
1
1
  // src/version.ts
2
- var version = "0.3.27";
2
+ var version = "0.3.28";
3
3
 
4
4
  // src/dataset/enum/Common.ts
5
5
  var MaxHeightRatio = /* @__PURE__ */ ((MaxHeightRatio2) => {
@@ -18995,10 +18995,11 @@ var ListParticle = class {
18995
18995
  const curIndex = isSetCursor ? endIndex : startIndex;
18996
18996
  this.draw.render({ curIndex, isSetCursor });
18997
18997
  }
18998
- getListIndentWidth(element) {
18999
- const { scale } = this.options;
18998
+ // Each level indents by the list's marker column, so a nested marker starts
18999
+ // exactly where its parent's text starts
19000
+ getListIndentWidth(element, markerWidth) {
19000
19001
  const level = element.listLevel ?? 0;
19001
- return level * INDENT_PER_LEVEL * scale;
19002
+ return level * markerWidth;
19002
19003
  }
19003
19004
  _getListMarkerStyleElement(elementList, startIndex = 0) {
19004
19005
  const startElement = elementList[startIndex];
@@ -19128,8 +19129,9 @@ var ListParticle = class {
19128
19129
  leftTop: [startX]
19129
19130
  }
19130
19131
  } = position;
19131
- const indentWidth = this.getListIndentWidth(startElement);
19132
- return startX - offsetX + tabWidth + indentWidth;
19132
+ const level = startElement.listLevel ?? 0;
19133
+ const markerWidth = offsetX / (level + 1);
19134
+ return startX - markerWidth + tabWidth;
19133
19135
  }
19134
19136
  getListMarker(row) {
19135
19137
  const startElement = row.elementList[0];
@@ -22412,8 +22414,9 @@ var Draw = class {
22412
22414
  boundingBoxAscent: 0,
22413
22415
  boundingBoxDescent: 0
22414
22416
  };
22415
- const listIndentWidth = element.listId ? this.listParticle.getListIndentWidth(element) : 0;
22416
- const offsetX = curRow.offsetX || (element.listId && listStyleMap.get(element.listId) || 0) + listIndentWidth || 0;
22417
+ const listMarkerWidth = element.listId && listStyleMap.get(element.listId) || 0;
22418
+ const listIndentWidth = element.listId ? this.listParticle.getListIndentWidth(element, listMarkerWidth) : 0;
22419
+ const offsetX = curRow.offsetX || listMarkerWidth + listIndentWidth || 0;
22417
22420
  const availableWidth = innerWidth - offsetX;
22418
22421
  const isStartElement = curRow.elementList.length === 1;
22419
22422
  x += isStartElement ? offsetX : 0;
@@ -23161,7 +23164,10 @@ var Draw = class {
23161
23164
  if (element.listId) {
23162
23165
  row.isList = true;
23163
23166
  const baseListOffset = listStyleMap.get(element.listId) || 0;
23164
- const rowListIndent = this.listParticle.getListIndentWidth(element);
23167
+ const rowListIndent = this.listParticle.getListIndentWidth(
23168
+ element,
23169
+ baseListOffset
23170
+ );
23165
23171
  row.offsetX = baseListOffset + rowListIndent;
23166
23172
  row.listIndex = listState.listIndex;
23167
23173
  }
@@ -24652,6 +24658,8 @@ async function createDocument(ctx) {
24652
24658
  });
24653
24659
  const footerChildren = opts.footer.disabled ? [] : await serializeFooter(ctx, width, height, margins);
24654
24660
  const { pageNumber } = draw.getOptions();
24661
+ endWithParagraph(headerChildren);
24662
+ endWithParagraph(footerChildren);
24655
24663
  return new Document2({
24656
24664
  compatabilityModeVersion: 15,
24657
24665
  // LibreOffice formats PAGE/NUMPAGES results from the paragraph style
@@ -24878,6 +24886,7 @@ async function serializeRow(ctx, row, zone, options, suffix) {
24878
24886
  }
24879
24887
  return new Paragraph({
24880
24888
  children,
24889
+ run: hasInlineImage(row) ? { size: IMAGE_MARK_HALF_POINTS } : void 0,
24881
24890
  style: suffix?.style,
24882
24891
  pageBreakBefore,
24883
24892
  widowControl: false,
@@ -24887,9 +24896,23 @@ async function serializeRow(ctx, row, zone, options, suffix) {
24887
24896
  });
24888
24897
  }
24889
24898
  var EXACT_BASELINE_RATIO = 0.8;
24899
+ var IMAGE_MARK_HALF_POINTS = 2;
24900
+ var IMAGE_MARK_DESCENT_PX = 0.3;
24901
+ function hasInlineImage(row) {
24902
+ return row.elementList.some((el) => el.type === "image" /* IMAGE */);
24903
+ }
24890
24904
  function rowLine(ctx, row, baseline = row.ascent / ctx.scale) {
24891
24905
  const { scale } = ctx;
24892
24906
  const height = row.height / scale;
24907
+ if (hasInlineImage(row)) {
24908
+ const lineTw2 = pxTw(Math.min(baseline, height) + IMAGE_MARK_DESCENT_PX);
24909
+ return {
24910
+ lineTw: lineTw2,
24911
+ beforeTw: 0,
24912
+ afterTw: Math.max(0, pxTw(height) - lineTw2),
24913
+ atLeast: true
24914
+ };
24915
+ }
24893
24916
  const ascent = Math.min(baseline, height);
24894
24917
  const line = Math.min(
24895
24918
  ascent / EXACT_BASELINE_RATIO,
@@ -24901,7 +24924,7 @@ function rowLine(ctx, row, baseline = row.ascent / ctx.scale) {
24901
24924
  pxTw(ascent) - Math.round(lineTw * EXACT_BASELINE_RATIO)
24902
24925
  );
24903
24926
  const afterTw = Math.max(0, pxTw(height) - lineTw - beforeTw);
24904
- return { lineTw, beforeTw, afterTw };
24927
+ return { lineTw, beforeTw, afterTw, atLeast: false };
24905
24928
  }
24906
24929
  function rowLead(ctx, row, options) {
24907
24930
  const separator = row.elementList.find(
@@ -24916,12 +24939,12 @@ function rowLead(ctx, row, options) {
24916
24939
  return rowLine(ctx, row, baseline).beforeTw + tw(ctx, (row.offsetY || 0) + (row.spaceAbove || 0)) + pxTw(options.padTop || 0);
24917
24940
  }
24918
24941
  function rowSpacing(ctx, row, options) {
24919
- const { lineTw, afterTw } = rowLine(ctx, row);
24942
+ const { lineTw, afterTw, atLeast } = rowLine(ctx, row);
24920
24943
  return {
24921
24944
  before: options.skipLead ? 0 : rowLead(ctx, row, options),
24922
24945
  after: afterTw + tw(ctx, row.spaceBelow || 0) + pxTw(options.padBottom || 0) + (options.extraAfter || 0),
24923
24946
  line: lineTw,
24924
- lineRule: LineRuleType.EXACT
24947
+ lineRule: atLeast ? LineRuleType.AT_LEAST : LineRuleType.EXACT
24925
24948
  };
24926
24949
  }
24927
24950
  function createSeparatorParagraph(ctx, row, element, x, rowY2, zone, options) {
@@ -24973,6 +24996,12 @@ function createLineImage(width, height, color, dashArray) {
24973
24996
  for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
24974
24997
  return bytes;
24975
24998
  }
24999
+ function endWithParagraph(children) {
25000
+ if (children[children.length - 1] instanceof Table) {
25001
+ children.push(createSpacerParagraph(false));
25002
+ }
25003
+ return children;
25004
+ }
24976
25005
  function createSpacerParagraph(pageBreakBefore, height = 0) {
24977
25006
  return new Paragraph({
24978
25007
  pageBreakBefore,
@@ -25015,7 +25044,7 @@ async function serializeTable(ctx, element, position, zone) {
25015
25044
  );
25016
25045
  cells.push(
25017
25046
  new TableCell({
25018
- children: cellChildren.length ? cellChildren : [createSpacerParagraph(false)],
25047
+ children: cellChildren.length ? endWithParagraph(cellChildren) : [createSpacerParagraph(false)],
25019
25048
  columnSpan: td.colspan > 1 ? td.colspan : void 0,
25020
25049
  rowSpan: td.rowspan > 1 ? td.rowspan : void 0,
25021
25050
  width: { size: pxTw(td.width), type: WidthType.DXA },