@hufe921/canvas-editor 0.9.21 → 0.9.22

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,27 @@
1
+ ## [0.9.22](https://github.com/Hufe921/canvas-editor/compare/v0.9.21...v0.9.22) (2023-03-15)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * init page context when paper change ([bb63eeb](https://github.com/Hufe921/canvas-editor/commit/bb63eeb335e45899cf5b6906f26fc1bb7599356e))
7
+
8
+
9
+ ### Documentation
10
+
11
+ * set paper direction api ([0963fc1](https://github.com/Hufe921/canvas-editor/commit/0963fc1adfeda7e3938bf7fbe2bfab1433f401d5))
12
+ * update command execute api ([82b5256](https://github.com/Hufe921/canvas-editor/commit/82b525649fea0793fc54897e9befba1b91efe782))
13
+ * next features roadmap ([dd7a768](https://github.com/Hufe921/canvas-editor/commit/dd7a7686af40b0a99f388961ff302ea41de4c905))
14
+
15
+
16
+ ### Features
17
+
18
+ * adjust background when paper direction change ([f076f2b](https://github.com/Hufe921/canvas-editor/commit/f076f2bd00eae6f3adf56559e40807898a8de229))
19
+ * adjust margins when paper direction change ([1eefa57](https://github.com/Hufe921/canvas-editor/commit/1eefa570b23a3330971c595dde8cef0e6ec2f530))
20
+ * add paper direction ([9aeb928](https://github.com/Hufe921/canvas-editor/commit/9aeb928b35c90c0a5a6040b34b77e2d6b91343d5))
21
+ * drag and drop date element ([780a40c](https://github.com/Hufe921/canvas-editor/commit/780a40caae3cabd9ceea347ae796ccfda9e9b3ef))
22
+
23
+
24
+
1
25
  ## [0.9.21](https://github.com/Hufe921/canvas-editor/compare/v0.9.20...v0.9.21) (2023-03-11)
2
26
 
3
27
 
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
23
23
  return value;
24
24
  };
25
25
  var index = "";
26
- const version = "0.9.21";
26
+ const version = "0.9.22";
27
27
  const ZERO = "\u200B";
28
28
  const WRAP = "\n";
29
29
  var RowFlex;
@@ -4350,11 +4350,11 @@ function mouseup(evt, host) {
4350
4350
  const cachePositionList = host.cachePositionList;
4351
4351
  const range = rangeManager.getRange();
4352
4352
  const dragElementList = cacheElementList.slice(cacheRange.startIndex + 1, cacheRange.endIndex + 1);
4353
- const isContainControl = dragElementList.find((element) => element.type === ElementType.CONTROL || element.type === ElementType.DATE);
4353
+ const isContainControl = dragElementList.find((element) => element.type === ElementType.CONTROL);
4354
4354
  if (isContainControl) {
4355
4355
  const cacheStartElement2 = cacheElementList[cacheRange.startIndex + 1];
4356
4356
  const cacheEndElement2 = cacheElementList[cacheRange.endIndex];
4357
- const isAllowDragControl = (cacheStartElement2.type !== ElementType.CONTROL || cacheStartElement2.controlComponent === ControlComponent.PREFIX) && (cacheEndElement2.type !== ElementType.CONTROL || cacheEndElement2.controlComponent === ControlComponent.POSTFIX) && cacheStartElement2.type !== ElementType.DATE && cacheEndElement2.type !== ElementType.DATE || cacheStartElement2.controlId === cacheEndElement2.controlId && cacheStartElement2.controlComponent === ControlComponent.PREFIX && cacheEndElement2.controlComponent === ControlComponent.POSTFIX || ((_a = cacheStartElement2.control) == null ? void 0 : _a.type) === ControlType.TEXT && cacheStartElement2.controlComponent === ControlComponent.VALUE && ((_b = cacheEndElement2.control) == null ? void 0 : _b.type) === ControlType.TEXT && cacheEndElement2.controlComponent === ControlComponent.VALUE;
4357
+ const isAllowDragControl = (cacheStartElement2.type !== ElementType.CONTROL || cacheStartElement2.controlComponent === ControlComponent.PREFIX) && (cacheEndElement2.type !== ElementType.CONTROL || cacheEndElement2.controlComponent === ControlComponent.POSTFIX) || cacheStartElement2.controlId === cacheEndElement2.controlId && cacheStartElement2.controlComponent === ControlComponent.PREFIX && cacheEndElement2.controlComponent === ControlComponent.POSTFIX || ((_a = cacheStartElement2.control) == null ? void 0 : _a.type) === ControlType.TEXT && cacheStartElement2.controlComponent === ControlComponent.VALUE && ((_b = cacheEndElement2.control) == null ? void 0 : _b.type) === ControlType.TEXT && cacheEndElement2.controlComponent === ControlComponent.VALUE;
4358
4358
  if (!isAllowDragControl) {
4359
4359
  draw.render({
4360
4360
  curIndex: range.startIndex,
@@ -5876,11 +5876,12 @@ class RangeManager {
5876
5876
  }
5877
5877
  class Background {
5878
5878
  constructor(draw) {
5879
- __publicField(this, "options");
5880
- this.options = draw.getOptions();
5879
+ __publicField(this, "draw");
5880
+ this.draw = draw;
5881
5881
  }
5882
5882
  render(ctx) {
5883
- const { width, height } = this.options;
5883
+ const width = this.draw.getOriginalWidth();
5884
+ const height = this.draw.getOriginalHeight();
5884
5885
  ctx.save();
5885
5886
  ctx.fillStyle = "#ffffff";
5886
5887
  ctx.fillRect(0, 0, width, height);
@@ -5964,6 +5965,11 @@ var PageMode;
5964
5965
  PageMode2["PAGING"] = "paging";
5965
5966
  PageMode2["CONTINUITY"] = "continuity";
5966
5967
  })(PageMode || (PageMode = {}));
5968
+ var PaperDirection;
5969
+ (function(PaperDirection2) {
5970
+ PaperDirection2["VERTICAL"] = "vertical";
5971
+ PaperDirection2["HORIZONTAL"] = "horizontal";
5972
+ })(PaperDirection || (PaperDirection = {}));
5967
5973
  class Margin {
5968
5974
  constructor(draw) {
5969
5975
  __publicField(this, "draw");
@@ -9003,11 +9009,19 @@ class Draw {
9003
9009
  isReadonly() {
9004
9010
  return this.mode === EditorMode.READONLY;
9005
9011
  }
9012
+ getOriginalWidth() {
9013
+ const { paperDirection, width, height } = this.options;
9014
+ return paperDirection === PaperDirection.VERTICAL ? width : height;
9015
+ }
9016
+ getOriginalHeight() {
9017
+ const { paperDirection, width, height } = this.options;
9018
+ return paperDirection === PaperDirection.VERTICAL ? height : width;
9019
+ }
9006
9020
  getWidth() {
9007
- return Math.floor(this.options.width * this.options.scale);
9021
+ return Math.floor(this.getOriginalWidth() * this.options.scale);
9008
9022
  }
9009
9023
  getHeight() {
9010
- return Math.floor(this.options.height * this.options.scale);
9024
+ return Math.floor(this.getOriginalHeight() * this.options.scale);
9011
9025
  }
9012
9026
  getCanvasWidth(pageNo = -1) {
9013
9027
  const page = this.getPage(pageNo);
@@ -9023,14 +9037,16 @@ class Draw {
9023
9037
  return width - margins[1] - margins[3];
9024
9038
  }
9025
9039
  getOriginalInnerWidth() {
9026
- const { width, margins } = this.options;
9040
+ const width = this.getOriginalWidth();
9041
+ const margins = this.getOriginalMargins();
9027
9042
  return width - margins[1] - margins[3];
9028
9043
  }
9029
9044
  getMargins() {
9030
- return this.options.margins.map((m) => m * this.options.scale);
9045
+ return this.getOriginalMargins().map((m) => m * this.options.scale);
9031
9046
  }
9032
9047
  getOriginalMargins() {
9033
- return this.options.margins;
9048
+ const { margins, paperDirection } = this.options;
9049
+ return paperDirection === PaperDirection.VERTICAL ? margins : [margins[1], margins[2], margins[3], margins[0]];
9034
9050
  }
9035
9051
  getPageGap() {
9036
9052
  return this.options.pageGap * this.options.scale;
@@ -9264,14 +9280,12 @@ class Draw {
9264
9280
  const height = this.getHeight();
9265
9281
  this.container.style.width = `${width}px`;
9266
9282
  this.pageList.forEach((p, i) => {
9267
- p.width = width;
9268
- p.height = height;
9283
+ p.width = width * dpr;
9284
+ p.height = height * dpr;
9269
9285
  p.style.width = `${width}px`;
9270
9286
  p.style.height = `${height}px`;
9271
9287
  p.style.marginBottom = `${this.getPageGap()}px`;
9272
- p.width = width * dpr;
9273
- p.height = height * dpr;
9274
- this.ctxList[i].scale(dpr, dpr);
9288
+ this._initPageContext(this.ctxList[i]);
9275
9289
  });
9276
9290
  this.render({
9277
9291
  isSubmitHistory: false,
@@ -9288,7 +9302,7 @@ class Draw {
9288
9302
  this.pageList.forEach((p, i) => {
9289
9303
  p.width = width * dpr;
9290
9304
  p.height = height * dpr;
9291
- this.ctxList[i].scale(dpr, dpr);
9305
+ this._initPageContext(this.ctxList[i]);
9292
9306
  });
9293
9307
  this.render({
9294
9308
  isSubmitHistory: false,
@@ -9296,14 +9310,34 @@ class Draw {
9296
9310
  });
9297
9311
  }
9298
9312
  setPaperSize(width, height) {
9313
+ const dpr = window.devicePixelRatio;
9299
9314
  this.options.width = width;
9300
9315
  this.options.height = height;
9301
9316
  this.container.style.width = `${width}px`;
9302
- this.pageList.forEach((p) => {
9303
- p.width = width;
9304
- p.height = height;
9317
+ this.pageList.forEach((p, i) => {
9318
+ p.width = width * dpr;
9319
+ p.height = height * dpr;
9320
+ p.style.width = `${width}px`;
9321
+ p.style.height = `${height}px`;
9322
+ this._initPageContext(this.ctxList[i]);
9323
+ });
9324
+ this.render({
9325
+ isSubmitHistory: false,
9326
+ isSetCursor: false
9327
+ });
9328
+ }
9329
+ setPaperDirection(payload) {
9330
+ const dpr = window.devicePixelRatio;
9331
+ this.options.paperDirection = payload;
9332
+ const width = this.getWidth();
9333
+ const height = this.getHeight();
9334
+ this.container.style.width = `${width}px`;
9335
+ this.pageList.forEach((p, i) => {
9336
+ p.width = width * dpr;
9337
+ p.height = height * dpr;
9305
9338
  p.style.width = `${width}px`;
9306
9339
  p.style.height = `${height}px`;
9340
+ this._initPageContext(this.ctxList[i]);
9307
9341
  });
9308
9342
  this.render({
9309
9343
  isSubmitHistory: false,
@@ -9983,6 +10017,7 @@ const _Command = class {
9983
10017
  _Command.pageScaleMinus = adapt.pageScaleMinus.bind(adapt);
9984
10018
  _Command.pageScaleAdd = adapt.pageScaleAdd.bind(adapt);
9985
10019
  _Command.paperSize = adapt.paperSize.bind(adapt);
10020
+ _Command.paperDirection = adapt.paperDirection.bind(adapt);
9986
10021
  _Command.getPaperMargin = adapt.getPaperMargin.bind(adapt);
9987
10022
  _Command.setPaperMargin = adapt.setPaperMargin.bind(adapt);
9988
10023
  _Command.insertElementList = adapt.insertElementList.bind(adapt);
@@ -10184,6 +10219,9 @@ const _Command = class {
10184
10219
  executePaperSize(width, height) {
10185
10220
  return _Command.paperSize(width, height);
10186
10221
  }
10222
+ executePaperDirection(payload) {
10223
+ return _Command.paperDirection(payload);
10224
+ }
10187
10225
  getPaperMargin() {
10188
10226
  return _Command.getPaperMargin();
10189
10227
  }
@@ -10266,6 +10304,7 @@ __publicField(Command, "pageScaleRecovery");
10266
10304
  __publicField(Command, "pageScaleMinus");
10267
10305
  __publicField(Command, "pageScaleAdd");
10268
10306
  __publicField(Command, "paperSize");
10307
+ __publicField(Command, "paperDirection");
10269
10308
  __publicField(Command, "getPaperMargin");
10270
10309
  __publicField(Command, "setPaperMargin");
10271
10310
  __publicField(Command, "insertElementList");
@@ -10699,8 +10738,7 @@ class CommandAdapt {
10699
10738
  if (!~startIndex && !~endIndex)
10700
10739
  return;
10701
10740
  const elementList = this.draw.getElementList();
10702
- const { width, margins } = this.options;
10703
- const innerWidth = width - margins[1] - margins[3];
10741
+ const innerWidth = this.draw.getInnerWidth();
10704
10742
  const colgroup = [];
10705
10743
  const colWidth = innerWidth / col;
10706
10744
  for (let c = 0; c < col; c++) {
@@ -11609,10 +11647,12 @@ class CommandAdapt {
11609
11647
  });
11610
11648
  }
11611
11649
  async print() {
11612
- const { width, height, scale } = this.options;
11650
+ const { scale } = this.options;
11613
11651
  if (scale !== 1) {
11614
11652
  this.draw.setPageScale(1);
11615
11653
  }
11654
+ const width = this.draw.getOriginalWidth();
11655
+ const height = this.draw.getOriginalHeight();
11616
11656
  const base64List = await this.draw.getDataURL();
11617
11657
  printImageBase64(base64List, width, height);
11618
11658
  if (scale !== 1) {
@@ -11686,8 +11726,11 @@ class CommandAdapt {
11686
11726
  paperSize(width, height) {
11687
11727
  this.draw.setPaperSize(width, height);
11688
11728
  }
11729
+ paperDirection(payload) {
11730
+ this.draw.setPaperDirection(payload);
11731
+ }
11689
11732
  getPaperMargin() {
11690
- return this.draw.getOriginalMargins();
11733
+ return this.options.margins;
11691
11734
  }
11692
11735
  setPaperMargin(payload) {
11693
11736
  return this.draw.setPaperMargin(payload);
@@ -12431,7 +12474,8 @@ class Editor {
12431
12474
  tdPadding: 5,
12432
12475
  defaultTdHeight: 40,
12433
12476
  defaultHyperlinkColor: "#0000FF",
12434
- headerTop: 50
12477
+ headerTop: 50,
12478
+ paperDirection: PaperDirection.VERTICAL
12435
12479
  }, options), {
12436
12480
  header: headerOptions,
12437
12481
  watermark: waterMarkOptions,
@@ -12459,5 +12503,5 @@ class Editor {
12459
12503
  };
12460
12504
  }
12461
12505
  }
12462
- export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, ElementType, ImageDisplay, KeyMap, PageMode, RowFlex, Editor as default };
12506
+ export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, ElementType, ImageDisplay, KeyMap, PageMode, PaperDirection, RowFlex, Editor as default };
12463
12507
  //# sourceMappingURL=canvas-editor.es.js.map