@hufe921/canvas-editor 0.9.89 → 0.9.91

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.
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.89";
26
+ const version = "0.9.91";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -42,6 +42,11 @@ var ImageDisplay;
42
42
  ImageDisplay2["FLOAT_TOP"] = "float-top";
43
43
  ImageDisplay2["FLOAT_BOTTOM"] = "float-bottom";
44
44
  })(ImageDisplay || (ImageDisplay = {}));
45
+ var LocationPosition;
46
+ (function(LocationPosition2) {
47
+ LocationPosition2["BEFORE"] = "before";
48
+ LocationPosition2["AFTER"] = "after";
49
+ })(LocationPosition || (LocationPosition = {}));
45
50
  const ZERO = "\u200B";
46
51
  const WRAP = "\n";
47
52
  const NBSP = " ";
@@ -508,8 +513,7 @@ const CONTROL_STYLE_ATTR = [
508
513
  const EDITOR_ELEMENT_CONTEXT_ATTR = [
509
514
  ...TABLE_CONTEXT_ATTR,
510
515
  ...TITLE_CONTEXT_ATTR,
511
- ...LIST_CONTEXT_ATTR,
512
- ...EDITOR_ROW_ATTR
516
+ ...LIST_CONTEXT_ATTR
513
517
  ];
514
518
  const TEXTLIKE_ELEMENT_TYPE = [
515
519
  ElementType.TEXT,
@@ -3764,11 +3768,9 @@ function unzipElementList(elementList) {
3764
3768
  return result;
3765
3769
  }
3766
3770
  function formatElementList(elementList, options) {
3767
- const { isHandleFirstElement, editorOptions } = __spreadValues({
3768
- isHandleFirstElement: true
3769
- }, options);
3771
+ const { isHandleFirstElement = true, isForceCompensation = false, editorOptions } = options;
3770
3772
  const startElement = elementList[0];
3771
- if (isHandleFirstElement && (startElement == null ? void 0 : startElement.type) !== ElementType.LIST && ((startElement == null ? void 0 : startElement.type) && startElement.type !== ElementType.TEXT || !START_LINE_BREAK_REG.test(startElement == null ? void 0 : startElement.value))) {
3773
+ if (isForceCompensation || isHandleFirstElement && (startElement == null ? void 0 : startElement.type) !== ElementType.LIST && ((startElement == null ? void 0 : startElement.type) && startElement.type !== ElementType.TEXT || !START_LINE_BREAK_REG.test(startElement == null ? void 0 : startElement.value))) {
3772
3774
  elementList.unshift({
3773
3775
  value: ZERO
3774
3776
  });
@@ -3780,7 +3782,8 @@ function formatElementList(elementList, options) {
3780
3782
  elementList.splice(i, 1);
3781
3783
  const valueList = el.valueList || [];
3782
3784
  formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3783
- isHandleFirstElement: false
3785
+ isHandleFirstElement: false,
3786
+ isForceCompensation: false
3784
3787
  }));
3785
3788
  if (valueList.length) {
3786
3789
  const titleId = getUUID();
@@ -3809,7 +3812,8 @@ function formatElementList(elementList, options) {
3809
3812
  elementList.splice(i, 1);
3810
3813
  const valueList = el.valueList || [];
3811
3814
  formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3812
- isHandleFirstElement: true
3815
+ isHandleFirstElement: true,
3816
+ isForceCompensation: false
3813
3817
  }));
3814
3818
  if (valueList.length) {
3815
3819
  const listId = getUUID();
@@ -3843,7 +3847,8 @@ function formatElementList(elementList, options) {
3843
3847
  const tdId = getUUID();
3844
3848
  td.id = tdId;
3845
3849
  formatElementList(td.value, __spreadProps(__spreadValues({}, options), {
3846
- isHandleFirstElement: true
3850
+ isHandleFirstElement: true,
3851
+ isForceCompensation: true
3847
3852
  }));
3848
3853
  for (let v = 0; v < td.value.length; v++) {
3849
3854
  const value = td.value[v];
@@ -3893,7 +3898,10 @@ function formatElementList(elementList, options) {
3893
3898
  const { editorOptions: { control: controlOption, checkbox: checkboxOption, radio: radioOption } } = options;
3894
3899
  const controlId = getUUID();
3895
3900
  elementList.splice(i, 1);
3896
- const controlContext = pickObject(el, EDITOR_ELEMENT_CONTEXT_ATTR);
3901
+ const controlContext = pickObject(el, [
3902
+ ...EDITOR_ELEMENT_CONTEXT_ATTR,
3903
+ ...EDITOR_ROW_ATTR
3904
+ ]);
3897
3905
  const controlDefaultStyle = pickObject(el.control, CONTROL_STYLE_ATTR);
3898
3906
  const thePrePostfixArg = __spreadProps(__spreadValues({}, controlDefaultStyle), {
3899
3907
  color: editorOptions.control.bracketColor
@@ -3995,7 +4003,8 @@ function formatElementList(elementList, options) {
3995
4003
  }
3996
4004
  }
3997
4005
  formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3998
- isHandleFirstElement: false
4006
+ isHandleFirstElement: false,
4007
+ isForceCompensation: false
3999
4008
  }));
4000
4009
  for (let v = 0; v < valueList.length; v++) {
4001
4010
  const element = valueList[v];
@@ -4048,7 +4057,7 @@ function formatElementList(elementList, options) {
4048
4057
  }
4049
4058
  el = elementList[i];
4050
4059
  }
4051
- if (el.value === "\n") {
4060
+ if (el.value === "\n" || el.value == "\r\n") {
4052
4061
  el.value = ZERO;
4053
4062
  }
4054
4063
  if (el.type === ElementType.IMAGE || el.type === ElementType.BLOCK) {
@@ -4358,17 +4367,21 @@ function formatElementContext(sourceElementList, formatElementList2, anchorIndex
4358
4367
  isBreakWarped = true;
4359
4368
  }
4360
4369
  if (isBreakWarped || !copyElement.listId && targetElement.type === ElementType.LIST) {
4361
- const cloneAttr = [...TABLE_CONTEXT_ATTR, ...EDITOR_ROW_ATTR];
4362
- cloneProperty(cloneAttr, copyElement, targetElement);
4370
+ const cloneAttr2 = [...TABLE_CONTEXT_ATTR, ...EDITOR_ROW_ATTR];
4371
+ cloneProperty(cloneAttr2, copyElement, targetElement);
4363
4372
  (_b = targetElement.valueList) == null ? void 0 : _b.forEach((valueItem) => {
4364
- cloneProperty(cloneAttr, copyElement, valueItem);
4373
+ cloneProperty(cloneAttr2, copyElement, valueItem);
4365
4374
  });
4366
4375
  continue;
4367
4376
  }
4368
4377
  if ((_c = targetElement.valueList) == null ? void 0 : _c.length) {
4369
4378
  formatElementContext(sourceElementList, targetElement.valueList, anchorIndex);
4370
4379
  }
4371
- cloneProperty(EDITOR_ELEMENT_CONTEXT_ATTR, copyElement, targetElement);
4380
+ const cloneAttr = [...EDITOR_ELEMENT_CONTEXT_ATTR];
4381
+ if (!getIsBlockElement(targetElement)) {
4382
+ cloneAttr.push(...EDITOR_ROW_ATTR);
4383
+ }
4384
+ cloneProperty(cloneAttr, copyElement, targetElement);
4372
4385
  }
4373
4386
  }
4374
4387
  function convertElementToDom(element, options) {
@@ -5647,7 +5660,40 @@ function setRangeCache(host) {
5647
5660
  host.cachePositionList = position.getPositionList();
5648
5661
  host.cachePositionContext = position.getPositionContext();
5649
5662
  }
5663
+ function hitCheckbox(element, draw) {
5664
+ const { checkbox, control } = element;
5665
+ if (!control) {
5666
+ draw.getCheckboxParticle().setSelect(element);
5667
+ } else {
5668
+ const codes = (control == null ? void 0 : control.code) ? control.code.split(",") : [];
5669
+ if (checkbox == null ? void 0 : checkbox.value) {
5670
+ const codeIndex = codes.findIndex((c) => c === checkbox.code);
5671
+ codes.splice(codeIndex, 1);
5672
+ } else {
5673
+ if (checkbox == null ? void 0 : checkbox.code) {
5674
+ codes.push(checkbox.code);
5675
+ }
5676
+ }
5677
+ const activeControl = draw.getControl().getActiveControl();
5678
+ if (activeControl instanceof CheckboxControl) {
5679
+ activeControl.setSelect(codes);
5680
+ }
5681
+ }
5682
+ }
5683
+ function hitRadio(element, draw) {
5684
+ const { radio, control } = element;
5685
+ if (!control) {
5686
+ draw.getRadioParticle().setSelect(element);
5687
+ } else {
5688
+ const codes = (radio == null ? void 0 : radio.code) ? [radio.code] : [];
5689
+ const activeControl = draw.getControl().getActiveControl();
5690
+ if (activeControl instanceof RadioControl) {
5691
+ activeControl.setSelect(codes);
5692
+ }
5693
+ }
5694
+ }
5650
5695
  function mousedown(evt, host) {
5696
+ var _a, _b;
5651
5697
  if (evt.button === MouseEventButton.RIGHT)
5652
5698
  return;
5653
5699
  const draw = host.getDraw();
@@ -5708,37 +5754,22 @@ function mousedown(evt, host) {
5708
5754
  }
5709
5755
  rangeManager.setRange(startIndex, endIndex);
5710
5756
  position.setCursorPosition(positionList[curIndex]);
5711
- const isSetCheckbox = isDirectHitCheckbox && !isReadonly;
5712
- const isSetRadio = isDirectHitRadio && !isReadonly;
5713
- if (isSetCheckbox) {
5714
- const { checkbox, control } = curElement;
5715
- if (!control) {
5716
- draw.getCheckboxParticle().setSelect(curElement);
5717
- } else {
5718
- const codes = (control == null ? void 0 : control.code) ? control.code.split(",") : [];
5719
- if (checkbox == null ? void 0 : checkbox.value) {
5720
- const codeIndex = codes.findIndex((c) => c === checkbox.code);
5721
- codes.splice(codeIndex, 1);
5722
- } else {
5723
- if (checkbox == null ? void 0 : checkbox.code) {
5724
- codes.push(checkbox.code);
5725
- }
5726
- }
5727
- const activeControl = draw.getControl().getActiveControl();
5728
- if (activeControl instanceof CheckboxControl) {
5729
- activeControl.setSelect(codes);
5730
- }
5731
- }
5732
- } else if (isSetRadio) {
5733
- const { control, radio } = curElement;
5734
- if (!control) {
5735
- draw.getRadioParticle().setSelect(curElement);
5736
- } else {
5737
- const codes = (radio == null ? void 0 : radio.code) ? [radio.code] : [];
5738
- const activeControl = draw.getControl().getActiveControl();
5739
- if (activeControl instanceof RadioControl) {
5740
- activeControl.setSelect(codes);
5757
+ if (isDirectHitCheckbox && !isReadonly) {
5758
+ hitCheckbox(curElement, draw);
5759
+ } else if (isDirectHitRadio && !isReadonly) {
5760
+ hitRadio(curElement, draw);
5761
+ } else if (curElement.controlComponent === ControlComponent.VALUE && (((_a = curElement.control) == null ? void 0 : _a.type) === ControlType.CHECKBOX || ((_b = curElement.control) == null ? void 0 : _b.type) === ControlType.RADIO)) {
5762
+ let preIndex = curIndex;
5763
+ while (preIndex > 0) {
5764
+ const preElement = elementList[preIndex];
5765
+ if (preElement.controlComponent === ControlComponent.CHECKBOX) {
5766
+ hitCheckbox(preElement, draw);
5767
+ break;
5768
+ } else if (preElement.controlComponent === ControlComponent.RADIO) {
5769
+ hitRadio(preElement, draw);
5770
+ break;
5741
5771
  }
5772
+ preIndex--;
5742
5773
  }
5743
5774
  } else {
5744
5775
  draw.render({
@@ -6112,13 +6143,13 @@ function backspace(evt, host) {
6112
6143
  }
6113
6144
  const startElement = elementList[startIndex];
6114
6145
  if (isCollapsed && startElement.rowFlex && startElement.value === ZERO) {
6115
- const rowList = draw.getRowList();
6116
- const positionList = position.getPositionList();
6117
- const rowNo = positionList[startIndex].rowNo;
6118
- const rowFlexElementList = rowList[rowNo].elementList;
6119
- rowFlexElementList.forEach((element) => {
6120
- delete element.rowFlex;
6121
- });
6146
+ const rowFlexElementList = rangeManager.getRangeRowElementList();
6147
+ if (rowFlexElementList) {
6148
+ const preElement = elementList[startIndex - 1];
6149
+ rowFlexElementList.forEach((element) => {
6150
+ element.rowFlex = preElement == null ? void 0 : preElement.rowFlex;
6151
+ });
6152
+ }
6122
6153
  }
6123
6154
  if (!isCollapsed) {
6124
6155
  draw.spliceElementList(elementList, startIndex + 1, endIndex - startIndex);
@@ -8351,7 +8382,8 @@ class RangeManager {
8351
8382
  }
8352
8383
  start--;
8353
8384
  }
8354
- if (startIndex !== endIndex) {
8385
+ const isCollapsed = startIndex === endIndex;
8386
+ if (!isCollapsed) {
8355
8387
  let middle = startIndex + 1;
8356
8388
  while (middle < endIndex) {
8357
8389
  const { pageNo, rowNo } = positionList[middle];
@@ -8367,6 +8399,9 @@ class RangeManager {
8367
8399
  }
8368
8400
  }
8369
8401
  let end = endIndex;
8402
+ if (isCollapsed && elementList[startIndex].value === ZERO) {
8403
+ end += 1;
8404
+ }
8370
8405
  while (end < positionList.length) {
8371
8406
  const element = elementList[end];
8372
8407
  const nextElement = elementList[end + 1];
@@ -8511,7 +8546,7 @@ class RangeManager {
8511
8546
  this.setRange(range.startIndex, range.endIndex, range.tableId, range.startTdIndex, range.endTdIndex, range.startTrIndex, range.endTrIndex);
8512
8547
  }
8513
8548
  setRangeStyle() {
8514
- var _a;
8549
+ var _a, _b;
8515
8550
  const rangeStyleChangeListener = this.listener.rangeStyleChange;
8516
8551
  const isSubscribeRangeStyleChange = this.eventBus.isSubscribe("rangeStyleChange");
8517
8552
  if (!rangeStyleChangeListener && !isSubscribeRangeStyleChange)
@@ -8545,7 +8580,7 @@ class RangeManager {
8545
8580
  const color = curElement.color || null;
8546
8581
  const highlight = curElement.highlight || null;
8547
8582
  const rowFlex = curElement.rowFlex || null;
8548
- const rowMargin = curElement.rowMargin || this.options.defaultRowMargin;
8583
+ const rowMargin = (_a = curElement.rowMargin) != null ? _a : this.options.defaultRowMargin;
8549
8584
  const dashArray = curElement.dashArray || [];
8550
8585
  const level = curElement.level || null;
8551
8586
  const listType = curElement.listType || null;
@@ -8555,7 +8590,7 @@ class RangeManager {
8555
8590
  const undo = this.historyManager.isCanUndo();
8556
8591
  const redo = this.historyManager.isCanRedo();
8557
8592
  const groupIds = curElement.groupIds || null;
8558
- const extension = (_a = curElement.extension) != null ? _a : null;
8593
+ const extension = (_b = curElement.extension) != null ? _b : null;
8559
8594
  const rangeStyle = {
8560
8595
  type,
8561
8596
  undo,
@@ -12491,7 +12526,8 @@ class Control {
12491
12526
  const elementList = zipElementList(pageComponentData[pageComponentKey]);
12492
12527
  pageComponentData[pageComponentKey] = elementList;
12493
12528
  formatElementList(elementList, {
12494
- editorOptions: this.options
12529
+ editorOptions: this.options,
12530
+ isForceCompensation: true
12495
12531
  });
12496
12532
  }
12497
12533
  this.draw.setEditorData(pageComponentData);
@@ -12774,6 +12810,12 @@ class Control {
12774
12810
  });
12775
12811
  }
12776
12812
  }
12813
+ var VerticalAlign;
12814
+ (function(VerticalAlign2) {
12815
+ VerticalAlign2["TOP"] = "top";
12816
+ VerticalAlign2["MIDDLE"] = "middle";
12817
+ VerticalAlign2["BOTTOM"] = "bottom";
12818
+ })(VerticalAlign || (VerticalAlign = {}));
12777
12819
  class CheckboxParticle {
12778
12820
  constructor(draw) {
12779
12821
  __publicField(this, "draw");
@@ -12795,9 +12837,32 @@ class CheckboxParticle {
12795
12837
  isSetCursor: false
12796
12838
  });
12797
12839
  }
12798
- render(ctx, element, x, y) {
12799
- const { checkbox: { gap, lineWidth, fillStyle, strokeStyle }, scale } = this.options;
12800
- const { metrics, checkbox } = element;
12840
+ render(payload) {
12841
+ const { ctx, x, index: index2, row } = payload;
12842
+ let { y } = payload;
12843
+ const { checkbox: { gap, lineWidth, fillStyle, strokeStyle, verticalAlign }, scale } = this.options;
12844
+ const { metrics, checkbox } = row.elementList[index2];
12845
+ if (verticalAlign === VerticalAlign.TOP || verticalAlign === VerticalAlign.MIDDLE) {
12846
+ let nextIndex = index2 + 1;
12847
+ let nextElement = null;
12848
+ while (nextIndex < row.elementList.length) {
12849
+ nextElement = row.elementList[nextIndex];
12850
+ if (nextElement.value !== ZERO && nextElement.value !== NBSP)
12851
+ break;
12852
+ nextIndex++;
12853
+ }
12854
+ if (nextElement) {
12855
+ const { metrics: { boundingBoxAscent, boundingBoxDescent } } = nextElement;
12856
+ const textHeight = boundingBoxAscent + boundingBoxDescent;
12857
+ if (textHeight > metrics.height) {
12858
+ if (verticalAlign === VerticalAlign.TOP) {
12859
+ y -= boundingBoxAscent - metrics.height;
12860
+ } else if (verticalAlign === VerticalAlign.MIDDLE) {
12861
+ y -= (textHeight - metrics.height) / 2;
12862
+ }
12863
+ }
12864
+ }
12865
+ }
12801
12866
  const left2 = Math.round(x + gap * scale);
12802
12867
  const top = Math.round(y - metrics.height + lineWidth);
12803
12868
  const width = metrics.width - gap * 2 * scale;
@@ -12850,9 +12915,32 @@ class RadioParticle {
12850
12915
  isSetCursor: false
12851
12916
  });
12852
12917
  }
12853
- render(ctx, element, x, y) {
12854
- const { radio: { gap, lineWidth, fillStyle, strokeStyle }, scale } = this.options;
12855
- const { metrics, radio } = element;
12918
+ render(payload) {
12919
+ const { ctx, x, index: index2, row } = payload;
12920
+ let { y } = payload;
12921
+ const { radio: { gap, lineWidth, fillStyle, strokeStyle, verticalAlign }, scale } = this.options;
12922
+ const { metrics, radio } = row.elementList[index2];
12923
+ if (verticalAlign === VerticalAlign.TOP || verticalAlign === VerticalAlign.MIDDLE) {
12924
+ let nextIndex = index2 + 1;
12925
+ let nextElement = null;
12926
+ while (nextIndex < row.elementList.length) {
12927
+ nextElement = row.elementList[nextIndex];
12928
+ if (nextElement.value !== ZERO && nextElement.value !== NBSP)
12929
+ break;
12930
+ nextIndex++;
12931
+ }
12932
+ if (nextElement) {
12933
+ const { metrics: { boundingBoxAscent, boundingBoxDescent } } = nextElement;
12934
+ const textHeight = boundingBoxAscent + boundingBoxDescent;
12935
+ if (textHeight > metrics.height) {
12936
+ if (verticalAlign === VerticalAlign.TOP) {
12937
+ y -= boundingBoxAscent - metrics.height;
12938
+ } else if (verticalAlign === VerticalAlign.MIDDLE) {
12939
+ y -= (textHeight - metrics.height) / 2;
12940
+ }
12941
+ }
12942
+ }
12943
+ }
12856
12944
  const left2 = Math.round(x + gap * scale);
12857
12945
  const top = Math.round(y - metrics.height + lineWidth);
12858
12946
  const width = metrics.width - gap * 2 * scale;
@@ -14279,7 +14367,15 @@ class ListParticle {
14279
14367
  height: height * scale
14280
14368
  })
14281
14369
  });
14282
- this.draw.getCheckboxParticle().render(ctx, checkboxRowElement, x - gap * scale, y);
14370
+ this.draw.getCheckboxParticle().render({
14371
+ ctx,
14372
+ x: x - gap * scale,
14373
+ y,
14374
+ index: 0,
14375
+ row: __spreadProps(__spreadValues({}, row), {
14376
+ elementList: [checkboxRowElement, ...row.elementList]
14377
+ })
14378
+ });
14283
14379
  } else {
14284
14380
  let text = "";
14285
14381
  if (startElement.listType === ListType.UL) {
@@ -14397,7 +14493,8 @@ class Placeholder {
14397
14493
  }
14398
14494
  ];
14399
14495
  formatElementList(this.elementList, {
14400
- editorOptions: this.options
14496
+ editorOptions: this.options,
14497
+ isForceCompensation: true
14401
14498
  });
14402
14499
  this._compute();
14403
14500
  const innerWidth = this.draw.getInnerWidth();
@@ -14640,6 +14737,33 @@ class LineNumber {
14640
14737
  ctx.restore();
14641
14738
  }
14642
14739
  }
14740
+ class PageBorder {
14741
+ constructor(draw) {
14742
+ __publicField(this, "draw");
14743
+ __publicField(this, "header");
14744
+ __publicField(this, "footer");
14745
+ __publicField(this, "options");
14746
+ this.draw = draw;
14747
+ this.header = draw.getHeader();
14748
+ this.footer = draw.getFooter();
14749
+ this.options = draw.getOptions();
14750
+ }
14751
+ render(ctx) {
14752
+ const { scale, pageBorder: { color, lineWidth, padding } } = this.options;
14753
+ ctx.save();
14754
+ ctx.translate(0.5, 0.5);
14755
+ ctx.strokeStyle = color;
14756
+ ctx.lineWidth = lineWidth * scale;
14757
+ const margins = this.draw.getMargins();
14758
+ const x = margins[3] - padding[3] * scale;
14759
+ const y = margins[0] + this.header.getExtraHeight() - padding[0] * scale;
14760
+ const width = this.draw.getInnerWidth() + (padding[1] + padding[3]) * scale;
14761
+ const height = this.draw.getHeight() - y - this.footer.getExtraHeight() - margins[2] + padding[2] * scale;
14762
+ ctx.rect(x, y, width, height);
14763
+ ctx.stroke();
14764
+ ctx.restore();
14765
+ }
14766
+ }
14643
14767
  class Draw {
14644
14768
  constructor(rootContainer, options, data2, listener, eventBus, override) {
14645
14769
  __publicField(this, "container");
@@ -14693,6 +14817,7 @@ class Draw {
14693
14817
  __publicField(this, "listParticle");
14694
14818
  __publicField(this, "lineBreakParticle");
14695
14819
  __publicField(this, "control");
14820
+ __publicField(this, "pageBorder");
14696
14821
  __publicField(this, "workerManager");
14697
14822
  __publicField(this, "scrollObserver");
14698
14823
  __publicField(this, "selectionObserver");
@@ -14757,6 +14882,7 @@ class Draw {
14757
14882
  this.listParticle = new ListParticle(this);
14758
14883
  this.lineBreakParticle = new LineBreakParticle(this);
14759
14884
  this.control = new Control(this);
14885
+ this.pageBorder = new PageBorder(this);
14760
14886
  this.scrollObserver = new ScrollObserver(this);
14761
14887
  this.selectionObserver = new SelectionObserver(this);
14762
14888
  this.imageObserver = new ImageObserver();
@@ -14813,6 +14939,7 @@ class Draw {
14813
14939
  this.clearSideEffect();
14814
14940
  this.range.clearRange();
14815
14941
  this.mode = payload;
14942
+ this.options.mode = payload;
14816
14943
  this.render({
14817
14944
  isSetCursor: false,
14818
14945
  isSubmitHistory: false
@@ -14886,6 +15013,17 @@ class Draw {
14886
15013
  const margins = this.getOriginalMargins();
14887
15014
  return width - margins[1] - margins[3];
14888
15015
  }
15016
+ getContextInnerWidth() {
15017
+ const positionContext = this.position.getPositionContext();
15018
+ if (positionContext.isTable) {
15019
+ const { index: index2, trIndex, tdIndex } = positionContext;
15020
+ const elementList = this.getOriginalElementList();
15021
+ const td = elementList[index2].trList[trIndex].tdList[tdIndex];
15022
+ const tdPadding = this.getTdPadding();
15023
+ return td.width - tdPadding[1] - tdPadding[3];
15024
+ }
15025
+ return this.getOriginalInnerWidth();
15026
+ }
14889
15027
  getMargins() {
14890
15028
  return this.getOriginalMargins().map((m) => m * this.options.scale);
14891
15029
  }
@@ -15426,7 +15564,8 @@ class Draw {
15426
15564
  if (!data2)
15427
15565
  return;
15428
15566
  formatElementList(data2, {
15429
- editorOptions: this.options
15567
+ editorOptions: this.options,
15568
+ isForceCompensation: true
15430
15569
  });
15431
15570
  });
15432
15571
  this.setEditorData({
@@ -15510,11 +15649,12 @@ class Draw {
15510
15649
  return el.actualSize || el.size || this.options.defaultSize;
15511
15650
  }
15512
15651
  getElementRowMargin(el) {
15652
+ var _a;
15513
15653
  const { defaultBasicRowMarginHeight, defaultRowMargin, scale } = this.options;
15514
- return defaultBasicRowMarginHeight * (el.rowMargin || defaultRowMargin) * scale;
15654
+ return defaultBasicRowMarginHeight * ((_a = el.rowMargin) != null ? _a : defaultRowMargin) * scale;
15515
15655
  }
15516
15656
  computeRowList(payload) {
15517
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
15657
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
15518
15658
  const { innerWidth, elementList, isPagingMode = false } = payload;
15519
15659
  const { defaultSize, defaultRowMargin, scale, table: { tdPadding }, defaultTabWidth } = this.options;
15520
15660
  const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
@@ -15539,7 +15679,7 @@ class Draw {
15539
15679
  for (let i = 0; i < elementList.length; i++) {
15540
15680
  const curRow = rowList[rowList.length - 1];
15541
15681
  const element = elementList[i];
15542
- const rowMargin = defaultBasicRowMarginHeight * (element.rowMargin || defaultRowMargin);
15682
+ const rowMargin = defaultBasicRowMarginHeight * ((_c = element.rowMargin) != null ? _c : defaultRowMargin);
15543
15683
  const metrics = {
15544
15684
  width: 0,
15545
15685
  height: 0,
@@ -15592,7 +15732,7 @@ class Draw {
15592
15732
  elementList.splice(i + 1, combineCount);
15593
15733
  }
15594
15734
  }
15595
- element.pagingIndex = (_c = element.pagingIndex) != null ? _c : 0;
15735
+ element.pagingIndex = (_d = element.pagingIndex) != null ? _d : 0;
15596
15736
  this.tableParticle.computeRowColInfo(element);
15597
15737
  const trList = element.trList;
15598
15738
  for (let t = 0; t < trList.length; t++) {
@@ -15668,7 +15808,7 @@ class Draw {
15668
15808
  let curPagePreHeight = marginHeight;
15669
15809
  for (let r = 0; r < rowList.length; r++) {
15670
15810
  const row = rowList[r];
15671
- if (row.height + curPagePreHeight > height2 || ((_d = rowList[r - 1]) == null ? void 0 : _d.isPageBreak)) {
15811
+ if (row.height + curPagePreHeight > height2 || ((_e = rowList[r - 1]) == null ? void 0 : _e.isPageBreak)) {
15672
15812
  curPagePreHeight = marginHeight + row.height;
15673
15813
  } else {
15674
15814
  curPagePreHeight += row.height;
@@ -15689,7 +15829,7 @@ class Draw {
15689
15829
  const trHeight = tr.height * scale;
15690
15830
  if (curPagePreHeight + rowMarginHeight + preTrHeight + trHeight > height2) {
15691
15831
  const rowColCount = tr.tdList.reduce((pre, cur) => pre + cur.colspan, 0);
15692
- if (((_e = element.colgroup) == null ? void 0 : _e.length) !== rowColCount) {
15832
+ if (((_f = element.colgroup) == null ? void 0 : _f.length) !== rowColCount) {
15693
15833
  deleteCount = 0;
15694
15834
  }
15695
15835
  break;
@@ -15812,7 +15952,7 @@ class Draw {
15812
15952
  metrics,
15813
15953
  style: this.getElementFont(element, scale)
15814
15954
  });
15815
- if ((_f = rowElement.control) == null ? void 0 : _f.minWidth) {
15955
+ if ((_g = rowElement.control) == null ? void 0 : _g.minWidth) {
15816
15956
  if (rowElement.controlComponent) {
15817
15957
  controlRealWidth += metrics.width;
15818
15958
  }
@@ -15865,10 +16005,10 @@ class Draw {
15865
16005
  elementList: [rowElement],
15866
16006
  ascent,
15867
16007
  rowIndex: curRow.rowIndex + 1,
15868
- rowFlex: ((_g = elementList[i]) == null ? void 0 : _g.rowFlex) || ((_h = elementList[i + 1]) == null ? void 0 : _h.rowFlex),
16008
+ rowFlex: ((_h = elementList[i]) == null ? void 0 : _h.rowFlex) || ((_i = elementList[i + 1]) == null ? void 0 : _i.rowFlex),
15869
16009
  isPageBreak: element.type === ElementType.PAGE_BREAK
15870
16010
  };
15871
- if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_i = rowElement.control) == null ? void 0 : _i.indentation) === ControlIndentation.VALUE_START) {
16011
+ if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_j = rowElement.control) == null ? void 0 : _j.indentation) === ControlIndentation.VALUE_START) {
15872
16012
  const preStartIndex = curRow.elementList.findIndex((el) => el.controlId === rowElement.controlId && el.controlComponent !== ControlComponent.PREFIX);
15873
16013
  if (~preStartIndex) {
15874
16014
  const preRowPositionList = this.position.computeRowPosition({
@@ -15901,7 +16041,7 @@ class Draw {
15901
16041
  if (isForceBreak || isWidthNotEnough || i === elementList.length - 1) {
15902
16042
  curRow.isWidthNotEnough = isWidthNotEnough && !isForceBreak;
15903
16043
  if ((preElement == null ? void 0 : preElement.rowFlex) === RowFlex.JUSTIFY || (preElement == null ? void 0 : preElement.rowFlex) === RowFlex.ALIGNMENT && isWidthNotEnough) {
15904
- const rowElementList = ((_j = curRow.elementList[0]) == null ? void 0 : _j.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
16044
+ const rowElementList = ((_k = curRow.elementList[0]) == null ? void 0 : _k.value) === ZERO ? curRow.elementList.slice(1) : curRow.elementList;
15905
16045
  const gap = (availableWidth - curRow.width) / (rowElementList.length - 1);
15906
16046
  for (let e = 0; e < rowElementList.length - 1; e++) {
15907
16047
  const el = rowElementList[e];
@@ -16039,10 +16179,22 @@ class Draw {
16039
16179
  }
16040
16180
  } else if (element.type === ElementType.CHECKBOX || element.controlComponent === ControlComponent.CHECKBOX) {
16041
16181
  this.textParticle.complete();
16042
- this.checkboxParticle.render(ctx, element, x, y + offsetY);
16182
+ this.checkboxParticle.render({
16183
+ ctx,
16184
+ x,
16185
+ y: y + offsetY,
16186
+ index: j,
16187
+ row: curRow
16188
+ });
16043
16189
  } else if (element.type === ElementType.RADIO || element.controlComponent === ControlComponent.RADIO) {
16044
16190
  this.textParticle.complete();
16045
- this.radioParticle.render(ctx, element, x, y + offsetY);
16191
+ this.radioParticle.render({
16192
+ ctx,
16193
+ x,
16194
+ y: y + offsetY,
16195
+ index: j,
16196
+ row: curRow
16197
+ });
16046
16198
  } else if (element.type === ElementType.TAB) {
16047
16199
  this.textParticle.complete();
16048
16200
  } else if (element.rowFlex === RowFlex.ALIGNMENT || element.rowFlex === RowFlex.JUSTIFY) {
@@ -16175,6 +16327,7 @@ class Draw {
16175
16327
  }
16176
16328
  }
16177
16329
  _drawFloat(ctx, payload) {
16330
+ const { scale } = this.options;
16178
16331
  const floatPositionList = this.position.getFloatPositionList();
16179
16332
  const { imgDisplay, pageNo } = payload;
16180
16333
  for (let e = 0; e < floatPositionList.length; e++) {
@@ -16182,7 +16335,7 @@ class Draw {
16182
16335
  const element = floatPosition.element;
16183
16336
  if ((pageNo === floatPosition.pageNo || floatPosition.zone === EditorZone.HEADER || floatPosition.zone == EditorZone.FOOTER) && element.imgDisplay === imgDisplay && element.type === ElementType.IMAGE) {
16184
16337
  const imgFloatPosition = element.imgFloatPosition;
16185
- this.imageParticle.render(ctx, element, imgFloatPosition.x, imgFloatPosition.y);
16338
+ this.imageParticle.render(ctx, element, imgFloatPosition.x * scale, imgFloatPosition.y * scale);
16186
16339
  }
16187
16340
  }
16188
16341
  }
@@ -16195,7 +16348,7 @@ class Draw {
16195
16348
  _drawPage(payload) {
16196
16349
  var _a, _b;
16197
16350
  const { elementList, positionList, rowList, pageNo } = payload;
16198
- const { inactiveAlpha, pageMode, header, footer, pageNumber, lineNumber } = this.options;
16351
+ const { inactiveAlpha, pageMode, header, footer, pageNumber, lineNumber, pageBorder } = this.options;
16199
16352
  const innerWidth = this.getInnerWidth();
16200
16353
  const ctx = this.ctxList[pageNo];
16201
16354
  ctx.globalAlpha = !this.zone.isMainActive() ? inactiveAlpha : 1;
@@ -16246,6 +16399,9 @@ class Draw {
16246
16399
  if (!lineNumber.disabled) {
16247
16400
  this.lineNumber.render(ctx, pageNo);
16248
16401
  }
16402
+ if (!pageBorder.disabled) {
16403
+ this.pageBorder.render(ctx);
16404
+ }
16249
16405
  }
16250
16406
  _disconnectLazyRender() {
16251
16407
  var _a;
@@ -16673,12 +16829,6 @@ const defaultWatermarkOption = {
16673
16829
  size: 200,
16674
16830
  font: "Microsoft YaHei"
16675
16831
  };
16676
- var VerticalAlign;
16677
- (function(VerticalAlign2) {
16678
- VerticalAlign2["TOP"] = "top";
16679
- VerticalAlign2["MIDDLE"] = "middle";
16680
- VerticalAlign2["BOTTOM"] = "bottom";
16681
- })(VerticalAlign || (VerticalAlign = {}));
16682
16832
  const defaultBackground = {
16683
16833
  color: "#FFFFFF",
16684
16834
  image: "",
@@ -16692,7 +16842,8 @@ const defaultCheckboxOption = {
16692
16842
  gap: 5,
16693
16843
  lineWidth: 1,
16694
16844
  fillStyle: "#5175f4",
16695
- strokeStyle: "#ffffff"
16845
+ strokeStyle: "#ffffff",
16846
+ verticalAlign: VerticalAlign.BOTTOM
16696
16847
  };
16697
16848
  const defaultControlOption = {
16698
16849
  placeholderColor: "#9c9b9b",
@@ -16742,7 +16893,8 @@ const defaultRadioOption = {
16742
16893
  gap: 5,
16743
16894
  lineWidth: 1,
16744
16895
  fillStyle: "#5175f4",
16745
- strokeStyle: "#000000"
16896
+ strokeStyle: "#000000",
16897
+ verticalAlign: VerticalAlign.BOTTOM
16746
16898
  };
16747
16899
  const defaultSeparatorOption = {
16748
16900
  lineWidth: 1,
@@ -16764,6 +16916,12 @@ const defaultLineNumberOption = {
16764
16916
  right: 20,
16765
16917
  type: LineNumberType.CONTINUITY
16766
16918
  };
16919
+ const defaultPageBorderOption = {
16920
+ color: "#000000",
16921
+ lineWidth: 1,
16922
+ padding: [0, 5, 0, 5],
16923
+ disabled: true
16924
+ };
16767
16925
  function mergeOption(options = {}) {
16768
16926
  const tableOptions = __spreadValues(__spreadValues({}, defaultTableOption), options.table);
16769
16927
  const headerOptions = __spreadValues(__spreadValues({}, defaultHeaderOption), options.header);
@@ -16783,6 +16941,7 @@ function mergeOption(options = {}) {
16783
16941
  const lineBreakOptions = __spreadValues(__spreadValues({}, defaultLineBreak), options.lineBreak);
16784
16942
  const separatorOptions = __spreadValues(__spreadValues({}, defaultSeparatorOption), options.separator);
16785
16943
  const lineNumberOptions = __spreadValues(__spreadValues({}, defaultLineNumberOption), options.lineNumber);
16944
+ const pageBorderOptions = __spreadValues(__spreadValues({}, defaultPageBorderOption), options.pageBorder);
16786
16945
  return __spreadProps(__spreadValues({
16787
16946
  mode: EditorMode.EDIT,
16788
16947
  defaultType: "TEXT",
@@ -16842,9 +17001,38 @@ function mergeOption(options = {}) {
16842
17001
  background: backgroundOptions,
16843
17002
  lineBreak: lineBreakOptions,
16844
17003
  separator: separatorOptions,
16845
- lineNumber: lineNumberOptions
17004
+ lineNumber: lineNumberOptions,
17005
+ pageBorder: pageBorderOptions
16846
17006
  });
16847
17007
  }
17008
+ function convertPxToPaperSize(width, height) {
17009
+ if (width === 1125 && height === 1593) {
17010
+ return {
17011
+ size: "a3",
17012
+ width: "297mm",
17013
+ height: "420mm"
17014
+ };
17015
+ }
17016
+ if (width === 794 && height === 1123) {
17017
+ return {
17018
+ size: "a4",
17019
+ width: "210mm",
17020
+ height: "297mm"
17021
+ };
17022
+ }
17023
+ if (width === 565 && height === 796) {
17024
+ return {
17025
+ size: "a5",
17026
+ width: "148mm",
17027
+ height: "210mm"
17028
+ };
17029
+ }
17030
+ return {
17031
+ size: "",
17032
+ width: `${width}px`,
17033
+ height: `${height}px`
17034
+ };
17035
+ }
16848
17036
  function printImageBase64(base64List, options) {
16849
17037
  const { width, height, direction = PaperDirection.VERTICAL } = options;
16850
17038
  const iframe = document.createElement("iframe");
@@ -16860,10 +17048,11 @@ function printImageBase64(base64List, options) {
16860
17048
  const doc = contentWindow.document;
16861
17049
  doc.open();
16862
17050
  const container = document.createElement("div");
17051
+ const paperSize = convertPxToPaperSize(width, height);
16863
17052
  base64List.forEach((base64) => {
16864
17053
  const image = document.createElement("img");
16865
- image.style.width = `${width}px`;
16866
- image.style.height = `${height}px`;
17054
+ image.style.width = direction === PaperDirection.HORIZONTAL ? paperSize.height : paperSize.width;
17055
+ image.style.height = direction === PaperDirection.HORIZONTAL ? paperSize.width : paperSize.height;
16867
17056
  image.src = base64;
16868
17057
  container.append(image);
16869
17058
  });
@@ -16875,7 +17064,7 @@ function printImageBase64(base64List, options) {
16875
17064
  }
16876
17065
  @page {
16877
17066
  margin: 0;
16878
- size: ${direction === PaperDirection.HORIZONTAL ? `landscape` : `portrait`};
17067
+ size: ${paperSize.size} ${direction === PaperDirection.HORIZONTAL ? `landscape` : `portrait`};
16879
17068
  }`;
16880
17069
  style.append(document.createTextNode(stylesheet));
16881
17070
  setTimeout(() => {
@@ -17509,7 +17698,7 @@ class CommandAdapt {
17509
17698
  const row2 = rowList[rowIndex];
17510
17699
  offsetX = (row2 == null ? void 0 : row2.offsetX) || 0;
17511
17700
  }
17512
- const innerWidth = this.draw.getOriginalInnerWidth() - offsetX;
17701
+ const innerWidth = this.draw.getContextInnerWidth() - offsetX;
17513
17702
  const colgroup = [];
17514
17703
  const colWidth = innerWidth / col;
17515
17704
  for (let c = 0; c < col; c++) {
@@ -17528,7 +17717,7 @@ class CommandAdapt {
17528
17717
  tdList.push({
17529
17718
  colspan: 1,
17530
17719
  rowspan: 1,
17531
- value: [{ value: ZERO, size: 16 }]
17720
+ value: []
17532
17721
  });
17533
17722
  }
17534
17723
  trList.push(tr);
@@ -18578,12 +18767,10 @@ class CommandAdapt {
18578
18767
  });
18579
18768
  }
18580
18769
  async print() {
18581
- const { scale, printPixelRatio, paperDirection } = this.options;
18770
+ const { scale, printPixelRatio, paperDirection, width, height } = this.options;
18582
18771
  if (scale !== 1) {
18583
18772
  this.draw.setPageScale(1);
18584
18773
  }
18585
- const width = this.draw.getOriginalWidth();
18586
- const height = this.draw.getOriginalHeight();
18587
18774
  const base64List = await this.draw.getDataURL({
18588
18775
  pixelRatio: printPixelRatio,
18589
18776
  mode: EditorMode.PRINT
@@ -19015,7 +19202,8 @@ class CommandAdapt {
19015
19202
  getControlList() {
19016
19203
  return this.draw.getControl().getList();
19017
19204
  }
19018
- locationControl(controlId) {
19205
+ locationControl(controlId, options) {
19206
+ const isLocationAfter = (options == null ? void 0 : options.position) === LocationPosition.AFTER;
19019
19207
  function location(elementList, zone2) {
19020
19208
  let i = 0;
19021
19209
  while (i < elementList.length) {
@@ -19046,7 +19234,13 @@ class CommandAdapt {
19046
19234
  }
19047
19235
  if ((element == null ? void 0 : element.controlId) !== controlId)
19048
19236
  continue;
19049
- const curIndex = i - 1;
19237
+ let curIndex = i - 1;
19238
+ if (isLocationAfter) {
19239
+ curIndex -= 1;
19240
+ if (element.controlComponent !== ControlComponent.PLACEHOLDER && element.controlComponent !== ControlComponent.POSTFIX) {
19241
+ continue;
19242
+ }
19243
+ }
19050
19244
  return {
19051
19245
  zone: zone2,
19052
19246
  range: {
@@ -20340,7 +20534,8 @@ class Editor {
20340
20534
  ];
20341
20535
  pageComponentData.forEach((elementList) => {
20342
20536
  formatElementList(elementList, {
20343
- editorOptions
20537
+ editorOptions,
20538
+ isForceCompensation: true
20344
20539
  });
20345
20540
  });
20346
20541
  this.listener = new Listener();
@@ -20368,5 +20563,5 @@ class Editor {
20368
20563
  this.use = plugin.use.bind(plugin);
20369
20564
  }
20370
20565
  }
20371
- export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
20566
+ export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, LineNumberType, ListStyle, ListType, LocationPosition, MaxHeightRatio, NumberType, PageMode, PaperDirection, RenderMode, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
20372
20567
  //# sourceMappingURL=canvas-editor.es.js.map