@hufe921/canvas-editor 0.9.28 → 0.9.29

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/CHANGELOG.md CHANGED
@@ -1,3 +1,26 @@
1
+ ## [0.9.29](https://github.com/Hufe921/canvas-editor/compare/v0.9.28...v0.9.29) (2023-04-01)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * delete rowFlex when row position change #164 ([5c3ce57](https://github.com/Hufe921/canvas-editor/commit/5c3ce57c24253cfe9b16ddc682f0f75aaab653fd)), closes [#164](https://github.com/Hufe921/canvas-editor/issues/164)
7
+ * failed to execute 'toDataURL' #163 ([f11d5c8](https://github.com/Hufe921/canvas-editor/commit/f11d5c806ea5cc308b59df4eaa58bf82998a3c50)), closes [#163](https://github.com/Hufe921/canvas-editor/issues/163)
8
+ * render composing text error ([310e0e9](https://github.com/Hufe921/canvas-editor/commit/310e0e91fbe4ef64343b5cc746ec4e7d471df974))
9
+ * table cell text render position error #166 ([266915a](https://github.com/Hufe921/canvas-editor/commit/266915af09be90a1a12092fdff2d266d62f3c90d)), closes [#166](https://github.com/Hufe921/canvas-editor/issues/166)
10
+ * table cell vertical align error after page scaled #165 ([1fa1d10](https://github.com/Hufe921/canvas-editor/commit/1fa1d10fc9c279eb1d91b804484019d02fec945d)), closes [#165](https://github.com/Hufe921/canvas-editor/issues/165)
11
+
12
+
13
+ ### Documentation
14
+
15
+ * update snapshot ([e0791cf](https://github.com/Hufe921/canvas-editor/commit/e0791cf5f74341547a86809e80c647a3f0fa5a2a))
16
+
17
+
18
+ ### Features
19
+
20
+ * avoid punctuation at the beginning of a row ([29a988a](https://github.com/Hufe921/canvas-editor/commit/29a988a1d4d57a98068a299986ddbe38a52d80a4))
21
+
22
+
23
+
1
24
  ## [0.9.28](https://github.com/Hufe921/canvas-editor/compare/v0.9.27...v0.9.28) (2023-03-27)
2
25
 
3
26
 
package/README.md CHANGED
@@ -35,7 +35,7 @@ new Editor(document.querySelector(".canvas-editor"), [
35
35
 
36
36
  ## snapshot
37
37
 
38
- ![image](https://github.com/Hufe921/canvas-editor/blob/main/src/assets/snapshots/main_v0.9.23.png)
38
+ ![image](https://github.com/Hufe921/canvas-editor/blob/main/src/assets/snapshots/main_v0.9.29.png)
39
39
 
40
40
  ## install
41
41
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.28";
26
+ const version = "0.9.29";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -32,6 +32,7 @@ var MaxHeightRatio;
32
32
  })(MaxHeightRatio || (MaxHeightRatio = {}));
33
33
  const ZERO = "\u200B";
34
34
  const WRAP = "\n";
35
+ const PUNCTUATION_LIST = ["\xB7", "\u3001", ":", "\uFF1A", ",", "\uFF0C", ".", "\u3002", ";", "\uFF1B", "?", "\uFF1F", "!", "\uFF01"];
35
36
  const maxHeightRadioMapping = {
36
37
  [MaxHeightRatio.HALF]: 1 / 2,
37
38
  [MaxHeightRatio.ONE_THIRD]: 1 / 3,
@@ -231,6 +232,12 @@ const TEXTLIKE_ELEMENT_TYPE = [
231
232
  ElementType.CONTROL,
232
233
  ElementType.DATE
233
234
  ];
235
+ const INLINE_ELEMENT_TYPE = [
236
+ ElementType.BLOCK,
237
+ ElementType.PAGE_BREAK,
238
+ ElementType.SEPARATOR,
239
+ ElementType.TABLE
240
+ ];
234
241
  var ControlType;
235
242
  (function(ControlType2) {
236
243
  ControlType2["TEXT"] = "text";
@@ -272,6 +279,7 @@ class ImageParticle {
272
279
  } else {
273
280
  const imageLoadPromise = new Promise((resolve, reject) => {
274
281
  const img = new Image();
282
+ img.setAttribute("crossOrigin", "Anonymous");
275
283
  img.src = element.value;
276
284
  img.onload = () => {
277
285
  ctx.drawImage(img, x, y, width, height);
@@ -4570,6 +4578,15 @@ function keydown(evt, host) {
4570
4578
  evt.preventDefault();
4571
4579
  return;
4572
4580
  }
4581
+ const startElement = elementList[startIndex];
4582
+ if (isCollapsed && startElement.rowFlex && startElement.value === ZERO) {
4583
+ const rowList = draw.getRowList();
4584
+ const rowNo = positionList[startIndex].rowNo;
4585
+ const rowFlexElementList = rowList[rowNo].elementList;
4586
+ rowFlexElementList.forEach((element) => {
4587
+ delete element.rowFlex;
4588
+ });
4589
+ }
4573
4590
  if (!isCollapsed) {
4574
4591
  elementList.splice(startIndex + 1, endIndex - startIndex);
4575
4592
  } else {
@@ -4803,6 +4820,7 @@ function keydown(evt, host) {
4803
4820
  }
4804
4821
  }
4805
4822
  function input(data2, host) {
4823
+ var _a;
4806
4824
  const draw = host.getDraw();
4807
4825
  const isReadonly = draw.isReadonly();
4808
4826
  if (isReadonly)
@@ -4811,16 +4829,17 @@ function input(data2, host) {
4811
4829
  const cursorPosition = position.getCursorPosition();
4812
4830
  if (!data2 || !cursorPosition)
4813
4831
  return;
4832
+ const isComposing = host.isComposing;
4833
+ if (isComposing && ((_a = host.compositionInfo) == null ? void 0 : _a.value) === data2)
4834
+ return;
4814
4835
  const control = draw.getControl();
4815
4836
  if (control.isPartRangeInControlOutside()) {
4816
4837
  return;
4817
4838
  }
4818
- const isComposing = host.isComposing;
4839
+ removeComposingInput(host);
4819
4840
  if (!isComposing) {
4820
4841
  const cursor = draw.getCursor();
4821
4842
  cursor.clearAgentDomValue();
4822
- } else {
4823
- removeComposingInput(host);
4824
4843
  }
4825
4844
  const activeControl = control.getActiveControl();
4826
4845
  const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType;
@@ -4835,15 +4854,17 @@ function input(data2, host) {
4835
4854
  restArg = { tdId, trId, tableId };
4836
4855
  }
4837
4856
  const elementList = draw.getElementList();
4838
- const element = elementList[endIndex];
4857
+ const endElement = elementList[endIndex];
4858
+ const endNextElement = elementList[endIndex + 1];
4859
+ const copyElement = endElement.value === ZERO && endNextElement ? endNextElement : endElement;
4839
4860
  const inputData = splitText(text).map((value) => {
4840
4861
  const newElement = __spreadValues({
4841
4862
  value
4842
4863
  }, restArg);
4843
4864
  const nextElement = elementList[endIndex + 1];
4844
- if (element.type === TEXT || !element.type && element.value !== ZERO || element.type === HYPERLINK && (nextElement == null ? void 0 : nextElement.type) === HYPERLINK || element.type === DATE && (nextElement == null ? void 0 : nextElement.type) === DATE || element.type === SUBSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUBSCRIPT || element.type === SUPERSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUPERSCRIPT) {
4865
+ if (copyElement.type === TEXT || !copyElement.type && copyElement.value !== ZERO || copyElement.type === HYPERLINK && (nextElement == null ? void 0 : nextElement.type) === HYPERLINK || copyElement.type === DATE && (nextElement == null ? void 0 : nextElement.type) === DATE || copyElement.type === SUBSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUBSCRIPT || copyElement.type === SUPERSCRIPT && (nextElement == null ? void 0 : nextElement.type) === SUPERSCRIPT) {
4845
4866
  EDITOR_ELEMENT_COPY_ATTR.forEach((attr) => {
4846
- const value2 = element[attr];
4867
+ const value2 = copyElement[attr];
4847
4868
  if (value2 !== void 0) {
4848
4869
  newElement[attr] = value2;
4849
4870
  }
@@ -5056,21 +5077,23 @@ function compositionstart(host) {
5056
5077
  }
5057
5078
  function compositionend(host, evt) {
5058
5079
  host.isComposing = false;
5059
- removeComposingInput(host);
5060
5080
  const draw = host.getDraw();
5061
- const cursor = draw.getCursor();
5062
5081
  if (!evt.data) {
5063
- const agentText = cursor.getAgentDomValue();
5064
- if (agentText) {
5065
- input(agentText, host);
5066
- } else {
5067
- const rangeManager = draw.getRange();
5068
- const { endIndex: curIndex } = rangeManager.getRange();
5069
- draw.render({
5070
- curIndex
5071
- });
5072
- }
5082
+ removeComposingInput(host);
5083
+ const rangeManager = draw.getRange();
5084
+ const { endIndex: curIndex } = rangeManager.getRange();
5085
+ draw.render({
5086
+ curIndex,
5087
+ isSubmitHistory: false
5088
+ });
5089
+ } else {
5090
+ setTimeout(() => {
5091
+ if (host.compositionInfo) {
5092
+ input(evt.data, host);
5093
+ }
5094
+ });
5073
5095
  }
5096
+ const cursor = draw.getCursor();
5074
5097
  cursor.clearAgentDomValue();
5075
5098
  }
5076
5099
  var composition = {
@@ -5531,7 +5554,7 @@ class Position {
5531
5554
  });
5532
5555
  if (td.verticalAlign === VerticalAlign.MIDDLE || td.verticalAlign == VerticalAlign.BOTTOM) {
5533
5556
  const rowsHeight = rowList2.reduce((pre, cur) => pre + cur.height, 0);
5534
- const blankHeight = td.height - tdGap - rowsHeight;
5557
+ const blankHeight = (td.height - tdGap) * scale - rowsHeight;
5535
5558
  const offsetHeight = td.verticalAlign === VerticalAlign.MIDDLE ? blankHeight / 2 : blankHeight;
5536
5559
  if (Math.floor(offsetHeight) > 0) {
5537
5560
  td.positionList.forEach((tdPosition) => {
@@ -6429,6 +6452,11 @@ class TextParticle {
6429
6452
  this.curStyle = "";
6430
6453
  this.cacheMeasureText = new Map();
6431
6454
  }
6455
+ measurePunctuationWidth(ctx, element) {
6456
+ if (!element || !PUNCTUATION_LIST.includes(element.value))
6457
+ return 0;
6458
+ return this.measureText(ctx, element).width;
6459
+ }
6432
6460
  measureText(ctx, element) {
6433
6461
  const id = `${element.value}${ctx.font}`;
6434
6462
  const cacheTextMetrics = this.cacheMeasureText.get(id);
@@ -7199,6 +7227,9 @@ class Header {
7199
7227
  this.rowList = [];
7200
7228
  this.positionList = [];
7201
7229
  }
7230
+ getRowList() {
7231
+ return this.rowList;
7232
+ }
7202
7233
  setElementList(elementList) {
7203
7234
  this.elementList = elementList;
7204
7235
  }
@@ -9343,6 +9374,9 @@ class Footer {
9343
9374
  this.rowList = [];
9344
9375
  this.positionList = [];
9345
9376
  }
9377
+ getRowList() {
9378
+ return this.rowList;
9379
+ }
9346
9380
  setElementList(elementList) {
9347
9381
  this.elementList = elementList;
9348
9382
  }
@@ -9660,9 +9694,25 @@ class Draw {
9660
9694
  getPageList() {
9661
9695
  return this.pageList;
9662
9696
  }
9663
- getRowList() {
9697
+ getTableRowList(sourceElementList) {
9698
+ const positionContext = this.position.getPositionContext();
9699
+ const { index: index2, trIndex, tdIndex } = positionContext;
9700
+ return sourceElementList[index2].trList[trIndex].tdList[tdIndex].rowList;
9701
+ }
9702
+ getOriginalRowList() {
9703
+ const zoneManager = this.getZone();
9704
+ if (zoneManager.isHeaderActive()) {
9705
+ return this.header.getRowList();
9706
+ }
9707
+ if (zoneManager.isFooterActive()) {
9708
+ return this.footer.getRowList();
9709
+ }
9664
9710
  return this.rowList;
9665
9711
  }
9712
+ getRowList() {
9713
+ const positionContext = this.position.getPositionContext();
9714
+ return positionContext.isTable ? this.getTableRowList(this.getOriginalElementList()) : this.getOriginalRowList();
9715
+ }
9666
9716
  getPageRowList() {
9667
9717
  return this.pageRowList;
9668
9718
  }
@@ -10035,9 +10085,9 @@ class Draw {
10035
10085
  if (element.type === ElementType.IMAGE || element.type === ElementType.LATEX) {
10036
10086
  const elementWidth = element.width * scale;
10037
10087
  const elementHeight = element.height * scale;
10038
- const curRowWidth = element.imgDisplay === ImageDisplay.INLINE ? 0 : curRow.width;
10039
- if (curRowWidth + elementWidth > innerWidth) {
10040
- const surplusWidth = innerWidth - curRowWidth;
10088
+ const curRowWidth2 = element.imgDisplay === ImageDisplay.INLINE ? 0 : curRow.width;
10089
+ if (curRowWidth2 + elementWidth > innerWidth) {
10090
+ const surplusWidth = innerWidth - curRowWidth2;
10041
10091
  element.width = surplusWidth;
10042
10092
  element.height = elementHeight * surplusWidth / elementWidth;
10043
10093
  metrics.width = element.width;
@@ -10227,8 +10277,13 @@ class Draw {
10227
10277
  style: this._getFont(element, scale)
10228
10278
  });
10229
10279
  const preElement = elementList[i - 1];
10230
- if ((preElement == null ? void 0 : preElement.type) === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.BLOCK || element.type === ElementType.BLOCK || (preElement == null ? void 0 : preElement.imgDisplay) === ImageDisplay.INLINE || element.imgDisplay === ImageDisplay.INLINE || curRow.width + metrics.width > innerWidth || i !== 0 && element.value === ZERO) {
10231
- if ((preElement == null ? void 0 : preElement.rowFlex) === RowFlex.ALIGNMENT && curRow.width + metrics.width > innerWidth) {
10280
+ const nextElement = elementList[i + 1];
10281
+ const curRowWidth = curRow.width + metrics.width + this.textParticle.measurePunctuationWidth(ctx, nextElement);
10282
+ if (element.type === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.BLOCK || element.type === ElementType.BLOCK || (preElement == null ? void 0 : preElement.imgDisplay) === ImageDisplay.INLINE || element.imgDisplay === ImageDisplay.INLINE || curRowWidth > innerWidth || i !== 0 && element.value === ZERO) {
10283
+ if (curRow.startIndex === 0 && curRow.elementList.length === 1 && INLINE_ELEMENT_TYPE.includes(element.type)) {
10284
+ curRow.height = defaultBasicRowMarginHeight;
10285
+ }
10286
+ if ((preElement == null ? void 0 : preElement.rowFlex) === RowFlex.ALIGNMENT && curRowWidth > innerWidth) {
10232
10287
  const gap = (innerWidth - curRow.width) / curRow.elementList.length;
10233
10288
  for (let e = 0; e < curRow.elementList.length; e++) {
10234
10289
  const el = curRow.elementList[e];
@@ -11479,7 +11534,7 @@ class CommandAdapt {
11479
11534
  }
11480
11535
  const element = {
11481
11536
  type: ElementType.TABLE,
11482
- value: !startIndex ? "" : ZERO,
11537
+ value: "",
11483
11538
  colgroup,
11484
11539
  trList
11485
11540
  };