@hufe921/canvas-editor 0.9.62 → 0.9.63

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,19 @@
1
+ ## [0.9.63](https://github.com/Hufe921/canvas-editor/compare/v0.9.62...v0.9.63) (2024-01-19)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * copy row properties on input #415 ([55a43e6](https://github.com/Hufe921/canvas-editor/commit/55a43e61bf6aded9f50644e86d3a1c276ee7a53a)), closes [#415](https://github.com/Hufe921/canvas-editor/issues/415)
7
+ * format list element boundary error ([094af57](https://github.com/Hufe921/canvas-editor/commit/094af57302a7db0c83cb3dd8a5eb9bbe5581b8f8))
8
+ * image render error within the control #406 ([d175f92](https://github.com/Hufe921/canvas-editor/commit/d175f920e8887cc3b1f5132e8ac7443b0d556204)), closes [#406](https://github.com/Hufe921/canvas-editor/issues/406)
9
+
10
+
11
+ ### Features
12
+
13
+ * keep aspect ratio when drag image #414 ([e8684da](https://github.com/Hufe921/canvas-editor/commit/e8684daffd40a8efda0342809846451afa0027a2)), closes [#414](https://github.com/Hufe921/canvas-editor/issues/414)
14
+
15
+
16
+
1
17
  ## [0.9.62](https://github.com/Hufe921/canvas-editor/compare/v0.9.61...v0.9.62) (2024-01-12)
2
18
 
3
19
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.62";
26
+ const version = "0.9.63";
27
27
  var MaxHeightRatio;
28
28
  (function(MaxHeightRatio2) {
29
29
  MaxHeightRatio2["HALF"] = "half";
@@ -363,6 +363,7 @@ const EDITOR_ELEMENT_STYLE_ATTR = [
363
363
  "underline",
364
364
  "strikeout"
365
365
  ];
366
+ const EDITOR_ROW_ATTR = ["rowFlex", "rowMargin"];
366
367
  const EDITOR_ELEMENT_COPY_ATTR = [
367
368
  "type",
368
369
  "font",
@@ -378,7 +379,9 @@ const EDITOR_ELEMENT_COPY_ATTR = [
378
379
  "hyperlinkId",
379
380
  "dateId",
380
381
  "dateFormat",
381
- "groupIds"
382
+ "groupIds",
383
+ "rowFlex",
384
+ "rowMargin"
382
385
  ];
383
386
  const EDITOR_ELEMENT_ZIP_ATTR = [
384
387
  "type",
@@ -3668,7 +3671,9 @@ function formatElementList(elementList, options) {
3668
3671
  } else if (el.type === ElementType.LIST) {
3669
3672
  elementList.splice(i, 1);
3670
3673
  const valueList = el.valueList || [];
3671
- formatElementList(valueList, __spreadValues({}, options));
3674
+ formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3675
+ isHandleFirstElement: true
3676
+ }));
3672
3677
  if (valueList.length) {
3673
3678
  const listId = getUUID();
3674
3679
  for (let v = 0; v < valueList.length; v++) {
@@ -3812,20 +3817,20 @@ function formatElementList(elementList, options) {
3812
3817
  }
3813
3818
  }
3814
3819
  }
3820
+ formatElementList(valueList, __spreadProps(__spreadValues({}, options), {
3821
+ isHandleFirstElement: false
3822
+ }));
3815
3823
  for (let v = 0; v < valueList.length; v++) {
3816
3824
  const element = valueList[v];
3817
- const valueStrList = splitText(element.value);
3818
- for (let e = 0; e < valueStrList.length; e++) {
3819
- const value2 = valueStrList[e];
3820
- elementList.splice(i, 0, __spreadProps(__spreadValues({}, element), {
3821
- controlId,
3822
- value: value2 === "\n" ? ZERO : value2,
3823
- type: element.type || ElementType.TEXT,
3824
- control: el.control,
3825
- controlComponent: ControlComponent.VALUE
3826
- }));
3827
- i++;
3828
- }
3825
+ const value2 = element.value;
3826
+ elementList.splice(i, 0, __spreadProps(__spreadValues({}, element), {
3827
+ controlId,
3828
+ value: value2 === "\n" ? ZERO : value2,
3829
+ type: element.type || ElementType.TEXT,
3830
+ control: el.control,
3831
+ controlComponent: ControlComponent.VALUE
3832
+ }));
3833
+ i++;
3829
3834
  }
3830
3835
  }
3831
3836
  } else if (placeholder) {
@@ -5467,7 +5472,8 @@ function enter(evt, host) {
5467
5472
  }
5468
5473
  const copyElement = getAnchorElement(elementList, endIndex);
5469
5474
  if (copyElement) {
5470
- EDITOR_ELEMENT_STYLE_ATTR.forEach((attr) => {
5475
+ const copyAttr = [...EDITOR_ELEMENT_STYLE_ATTR, ...EDITOR_ROW_ATTR];
5476
+ copyAttr.forEach((attr) => {
5471
5477
  const value = copyElement[attr];
5472
5478
  if (value !== void 0) {
5473
5479
  enterText[attr] = value;
@@ -10330,15 +10336,31 @@ class Previewer {
10330
10336
  let dy = 0;
10331
10337
  switch (this.curHandleIndex) {
10332
10338
  case 0:
10333
- dx = this.mousedownX - evt.x;
10334
- dy = this.mousedownY - evt.y;
10339
+ {
10340
+ const offsetX = this.mousedownX - evt.x;
10341
+ const offsetY = this.mousedownY - evt.y;
10342
+ dx = Math.cbrt(offsetX ** 3 + offsetY ** 3);
10343
+ dy = this.curElement.height * dx / this.curElement.width;
10344
+ }
10335
10345
  break;
10336
10346
  case 1:
10337
10347
  dy = this.mousedownY - evt.y;
10338
10348
  break;
10339
10349
  case 2:
10340
- dx = evt.x - this.mousedownX;
10341
- dy = this.mousedownY - evt.y;
10350
+ {
10351
+ const offsetX = evt.x - this.mousedownX;
10352
+ const offsetY = this.mousedownY - evt.y;
10353
+ dx = Math.cbrt(offsetX ** 3 + offsetY ** 3);
10354
+ dy = this.curElement.height * dx / this.curElement.width;
10355
+ }
10356
+ break;
10357
+ case 4:
10358
+ {
10359
+ const offsetX = evt.x - this.mousedownX;
10360
+ const offsetY = evt.y - this.mousedownY;
10361
+ dx = Math.cbrt(offsetX ** 3 + offsetY ** 3);
10362
+ dy = this.curElement.height * dx / this.curElement.width;
10363
+ }
10342
10364
  break;
10343
10365
  case 3:
10344
10366
  dx = evt.x - this.mousedownX;
@@ -10347,16 +10369,16 @@ class Previewer {
10347
10369
  dy = evt.y - this.mousedownY;
10348
10370
  break;
10349
10371
  case 6:
10350
- dx = this.mousedownX - evt.x;
10351
- dy = evt.y - this.mousedownY;
10372
+ {
10373
+ const offsetX = this.mousedownX - evt.x;
10374
+ const offsetY = evt.y - this.mousedownY;
10375
+ dx = Math.cbrt(offsetX ** 3 + offsetY ** 3);
10376
+ dy = this.curElement.height * dx / this.curElement.width;
10377
+ }
10352
10378
  break;
10353
10379
  case 7:
10354
10380
  dx = this.mousedownX - evt.x;
10355
10381
  break;
10356
- default:
10357
- dx = evt.x - this.mousedownX;
10358
- dy = evt.y - this.mousedownY;
10359
- break;
10360
10382
  }
10361
10383
  const dw = this.curElement.width + dx / scale;
10362
10384
  const dh = this.curElement.height + dy / scale;
@@ -12960,7 +12982,7 @@ class Draw {
12960
12982
  return `${el.italic ? "italic " : ""}${el.bold ? "bold " : ""}${size * scale}px ${font}`;
12961
12983
  }
12962
12984
  computeRowList(innerWidth, elementList) {
12963
- var _a, _b, _c, _d, _e, _f;
12985
+ var _a, _b, _c, _d, _e, _f, _g, _h;
12964
12986
  const { defaultSize, defaultRowMargin, scale, tdPadding, defaultTabWidth } = this.options;
12965
12987
  const defaultBasicRowMarginHeight = this.getDefaultBasicRowMarginHeight();
12966
12988
  const canvas = document.createElement("canvas");
@@ -12974,7 +12996,7 @@ class Draw {
12974
12996
  ascent: 0,
12975
12997
  elementList: [],
12976
12998
  startIndex: 0,
12977
- rowFlex: (_a = elementList == null ? void 0 : elementList[1]) == null ? void 0 : _a.rowFlex
12999
+ rowFlex: ((_a = elementList == null ? void 0 : elementList[0]) == null ? void 0 : _a.rowFlex) || ((_b = elementList == null ? void 0 : elementList[1]) == null ? void 0 : _b.rowFlex)
12978
13000
  });
12979
13001
  }
12980
13002
  let listId;
@@ -13083,7 +13105,7 @@ class Draw {
13083
13105
  let curPagePreHeight = marginHeight;
13084
13106
  for (let r = 0; r < rowList.length; r++) {
13085
13107
  const row = rowList[r];
13086
- if (row.height + curPagePreHeight > height2 || ((_b = rowList[r - 1]) == null ? void 0 : _b.isPageBreak)) {
13108
+ if (row.height + curPagePreHeight > height2 || ((_c = rowList[r - 1]) == null ? void 0 : _c.isPageBreak)) {
13087
13109
  curPagePreHeight = marginHeight + row.height;
13088
13110
  } else {
13089
13111
  curPagePreHeight += row.height;
@@ -13100,7 +13122,7 @@ class Draw {
13100
13122
  const tr = trList2[r];
13101
13123
  const trHeight = tr.height * scale;
13102
13124
  if (curPagePreHeight + rowMarginHeight + preTrHeight + trHeight > height2) {
13103
- if (((_c = element.colgroup) == null ? void 0 : _c.length) !== tr.tdList.length) {
13125
+ if (((_d = element.colgroup) == null ? void 0 : _d.length) !== tr.tdList.length) {
13104
13126
  deleteCount = 0;
13105
13127
  }
13106
13128
  break;
@@ -13186,7 +13208,7 @@ class Draw {
13186
13208
  metrics,
13187
13209
  style: this._getFont(element, scale)
13188
13210
  });
13189
- if ((_d = rowElement.control) == null ? void 0 : _d.minWidth) {
13211
+ if ((_e = rowElement.control) == null ? void 0 : _e.minWidth) {
13190
13212
  if (rowElement.controlComponent) {
13191
13213
  controlRealWidth += metrics.width;
13192
13214
  }
@@ -13243,10 +13265,10 @@ class Draw {
13243
13265
  startIndex: i,
13244
13266
  elementList: [rowElement],
13245
13267
  ascent,
13246
- rowFlex: (_e = elementList[i + 1]) == null ? void 0 : _e.rowFlex,
13268
+ rowFlex: ((_f = elementList[i]) == null ? void 0 : _f.rowFlex) || ((_g = elementList[i + 1]) == null ? void 0 : _g.rowFlex),
13247
13269
  isPageBreak: element.type === ElementType.PAGE_BREAK
13248
13270
  };
13249
- if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_f = rowElement.control) == null ? void 0 : _f.indentation) === ControlIndentation.VALUE_START) {
13271
+ if (rowElement.controlComponent !== ControlComponent.PREFIX && ((_h = rowElement.control) == null ? void 0 : _h.indentation) === ControlIndentation.VALUE_START) {
13250
13272
  const preStartIndex = curRow.elementList.findIndex((el) => el.controlId === rowElement.controlId && el.controlComponent !== ControlComponent.PREFIX);
13251
13273
  if (~preStartIndex) {
13252
13274
  const preRowPositionList = this.position.computeRowPosition({