@hufe921/canvas-editor 0.9.15 → 0.9.16

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.15";
26
+ const version = "0.9.16";
27
27
  const ZERO = "\u200B";
28
28
  const WRAP = "\n";
29
29
  var RowFlex;
@@ -3928,8 +3928,8 @@ class CursorAgent {
3928
3928
  _compositionstart() {
3929
3929
  this.canvasEvent.compositionstart();
3930
3930
  }
3931
- _compositionend() {
3932
- this.canvasEvent.compositionend();
3931
+ _compositionend(evt) {
3932
+ this.canvasEvent.compositionend(evt);
3933
3933
  }
3934
3934
  }
3935
3935
  class Cursor {
@@ -3955,6 +3955,12 @@ class Cursor {
3955
3955
  getAgentDom() {
3956
3956
  return this.cursorAgent.getAgentCursorDom();
3957
3957
  }
3958
+ getAgentDomValue() {
3959
+ return this.getAgentDom().value;
3960
+ }
3961
+ clearAgentDomValue() {
3962
+ return this.getAgentDom().value = "";
3963
+ }
3958
3964
  drawCursor() {
3959
3965
  const isReadonly = this.draw.isReadonly();
3960
3966
  const cursorPosition = this.position.getCursorPosition();
@@ -4399,6 +4405,8 @@ function isMod(evt) {
4399
4405
  }
4400
4406
  function keydown(evt, host) {
4401
4407
  var _a;
4408
+ if (host.isComposing)
4409
+ return;
4402
4410
  const draw = host.getDraw();
4403
4411
  const position = draw.getPosition();
4404
4412
  const cursorPosition = position.getCursorPosition();
@@ -4660,23 +4668,24 @@ function input(data2, host) {
4660
4668
  return;
4661
4669
  const position = draw.getPosition();
4662
4670
  const cursorPosition = position.getCursorPosition();
4663
- if (!data2 || !cursorPosition || host.isCompositing)
4671
+ if (!data2 || !cursorPosition)
4664
4672
  return;
4665
4673
  const control = draw.getControl();
4666
4674
  if (control.isPartRangeInControlOutside()) {
4667
4675
  return;
4668
4676
  }
4677
+ if (!host.isComposing) {
4678
+ const cursor = draw.getCursor();
4679
+ cursor.clearAgentDomValue();
4680
+ } else {
4681
+ removeComposingInput(host);
4682
+ }
4669
4683
  const activeControl = control.getActiveControl();
4670
4684
  const { TEXT, HYPERLINK, SUBSCRIPT, SUPERSCRIPT, DATE } = ElementType;
4671
4685
  const text = data2.replaceAll(`
4672
4686
  `, ZERO);
4673
- const cursor = draw.getCursor();
4674
- const agentDom = cursor.getAgentDom();
4675
- agentDom.value = "";
4676
- const { index: index2 } = cursorPosition;
4677
4687
  const rangeManager = draw.getRange();
4678
4688
  const { startIndex, endIndex } = rangeManager.getRange();
4679
- const isCollapsed = startIndex === endIndex;
4680
4689
  const positionContext = position.getPositionContext();
4681
4690
  let restArg = {};
4682
4691
  if (positionContext.isTable) {
@@ -4698,26 +4707,45 @@ function input(data2, host) {
4698
4707
  }
4699
4708
  });
4700
4709
  }
4710
+ if (host.isComposing) {
4711
+ newElement.underline = true;
4712
+ }
4701
4713
  return newElement;
4702
4714
  });
4703
4715
  let curIndex;
4704
4716
  if (activeControl && ((_a = elementList[endIndex + 1]) == null ? void 0 : _a.controlId) === element.controlId) {
4705
4717
  curIndex = control.setValue(inputData);
4706
4718
  } else {
4707
- let start = 0;
4708
- if (isCollapsed) {
4709
- start = index2 + 1;
4710
- } else {
4711
- start = startIndex + 1;
4712
- elementList.splice(startIndex + 1, endIndex - startIndex);
4719
+ const start = startIndex + 1;
4720
+ if (startIndex !== endIndex) {
4721
+ elementList.splice(start, endIndex - startIndex);
4713
4722
  }
4714
4723
  for (let i = 0; i < inputData.length; i++) {
4715
4724
  elementList.splice(start + i, 0, inputData[i]);
4716
4725
  }
4717
- curIndex = (isCollapsed ? index2 : startIndex) + inputData.length;
4726
+ curIndex = startIndex + inputData.length;
4718
4727
  }
4719
4728
  rangeManager.setRange(curIndex, curIndex);
4720
- draw.render({ curIndex });
4729
+ draw.render({
4730
+ curIndex
4731
+ });
4732
+ if (host.isComposing) {
4733
+ host.compositionInfo = {
4734
+ elementList,
4735
+ value: text,
4736
+ startIndex: curIndex - inputData.length,
4737
+ endIndex: curIndex
4738
+ };
4739
+ }
4740
+ }
4741
+ function removeComposingInput(host) {
4742
+ if (!host.compositionInfo)
4743
+ return;
4744
+ const { elementList, startIndex, endIndex } = host.compositionInfo;
4745
+ elementList.splice(startIndex + 1, endIndex - startIndex);
4746
+ const rangeManager = host.getDraw().getRange();
4747
+ rangeManager.setRange(startIndex, startIndex);
4748
+ host.compositionInfo = null;
4721
4749
  }
4722
4750
  function cut(host) {
4723
4751
  const draw = host.getDraw();
@@ -4871,10 +4899,26 @@ var click = {
4871
4899
  threeClick
4872
4900
  };
4873
4901
  function compositionstart(host) {
4874
- host.isCompositing = true;
4902
+ host.isComposing = true;
4875
4903
  }
4876
- function compositionend(host) {
4877
- host.isCompositing = false;
4904
+ function compositionend(host, evt) {
4905
+ host.isComposing = false;
4906
+ removeComposingInput(host);
4907
+ const draw = host.getDraw();
4908
+ const cursor = draw.getCursor();
4909
+ if (!evt.data) {
4910
+ const agentText = cursor.getAgentDomValue();
4911
+ if (agentText) {
4912
+ input(agentText, host);
4913
+ } else {
4914
+ const rangeManager = draw.getRange();
4915
+ const { endIndex: curIndex } = rangeManager.getRange();
4916
+ draw.render({
4917
+ curIndex
4918
+ });
4919
+ }
4920
+ }
4921
+ cursor.clearAgentDomValue();
4878
4922
  }
4879
4923
  var composition = {
4880
4924
  compositionstart,
@@ -4916,7 +4960,8 @@ var drag = {
4916
4960
  class CanvasEvent {
4917
4961
  constructor(draw) {
4918
4962
  __publicField(this, "isAllowSelection");
4919
- __publicField(this, "isCompositing");
4963
+ __publicField(this, "isComposing");
4964
+ __publicField(this, "compositionInfo");
4920
4965
  __publicField(this, "isAllowDrag");
4921
4966
  __publicField(this, "isAllowDrop");
4922
4967
  __publicField(this, "cacheRange");
@@ -4934,7 +4979,8 @@ class CanvasEvent {
4934
4979
  this.range = this.draw.getRange();
4935
4980
  this.position = this.draw.getPosition();
4936
4981
  this.isAllowSelection = false;
4937
- this.isCompositing = false;
4982
+ this.isComposing = false;
4983
+ this.compositionInfo = null;
4938
4984
  this.isAllowDrag = false;
4939
4985
  this.isAllowDrop = false;
4940
4986
  this.cacheRange = null;
@@ -5033,8 +5079,8 @@ class CanvasEvent {
5033
5079
  compositionstart() {
5034
5080
  composition.compositionstart(this);
5035
5081
  }
5036
- compositionend() {
5037
- composition.compositionend(this);
5082
+ compositionend(evt) {
5083
+ composition.compositionend(this, evt);
5038
5084
  }
5039
5085
  drop(evt) {
5040
5086
  drop(evt, this);
@@ -5056,6 +5102,7 @@ class GlobalEvent {
5056
5102
  __publicField(this, "hyperlinkParticle");
5057
5103
  __publicField(this, "control");
5058
5104
  __publicField(this, "dateParticle");
5105
+ __publicField(this, "dprMediaQueryList");
5059
5106
  __publicField(this, "recoverEffect", (evt) => {
5060
5107
  if (!this.cursor)
5061
5108
  return;
@@ -5109,6 +5156,9 @@ class GlobalEvent {
5109
5156
  (_a = this.cursor) == null ? void 0 : _a.drawCursor();
5110
5157
  }
5111
5158
  });
5159
+ __publicField(this, "_handleDprChange", () => {
5160
+ this.draw.setPageDevicePixel();
5161
+ });
5112
5162
  this.draw = draw;
5113
5163
  this.canvas = draw.getPage();
5114
5164
  this.options = draw.getOptions();
@@ -5120,6 +5170,7 @@ class GlobalEvent {
5120
5170
  this.hyperlinkParticle = draw.getHyperlinkParticle();
5121
5171
  this.dateParticle = draw.getDateParticle();
5122
5172
  this.control = draw.getControl();
5173
+ this.dprMediaQueryList = window.matchMedia(`(resolution: ${window.devicePixelRatio}dppx)`);
5123
5174
  }
5124
5175
  register() {
5125
5176
  this.cursor = this.draw.getCursor();
@@ -5132,6 +5183,7 @@ class GlobalEvent {
5132
5183
  document.addEventListener("mouseup", this.setCanvasEventAbility);
5133
5184
  document.addEventListener("wheel", this.setPageScale, { passive: false });
5134
5185
  document.addEventListener("visibilitychange", this._handleVisibilityChange);
5186
+ this.dprMediaQueryList.addEventListener("change", this._handleDprChange);
5135
5187
  }
5136
5188
  removeEvent() {
5137
5189
  window.removeEventListener("blur", this.recoverEffect);
@@ -5140,6 +5192,7 @@ class GlobalEvent {
5140
5192
  document.removeEventListener("mouseup", this.setCanvasEventAbility);
5141
5193
  document.removeEventListener("wheel", this.setPageScale);
5142
5194
  document.removeEventListener("visibilitychange", this._handleVisibilityChange);
5195
+ this.dprMediaQueryList.removeEventListener("change", this._handleDprChange);
5143
5196
  }
5144
5197
  }
5145
5198
  class HistoryManager {
@@ -8937,16 +8990,20 @@ class Draw {
8937
8990
  });
8938
8991
  }
8939
8992
  setPageScale(payload) {
8993
+ const dpr = window.devicePixelRatio;
8940
8994
  this.options.scale = payload;
8941
8995
  const width = this.getWidth();
8942
8996
  const height = this.getHeight();
8943
8997
  this.container.style.width = `${width}px`;
8944
- this.pageList.forEach((p) => {
8998
+ this.pageList.forEach((p, i) => {
8945
8999
  p.width = width;
8946
9000
  p.height = height;
8947
9001
  p.style.width = `${width}px`;
8948
9002
  p.style.height = `${height}px`;
8949
9003
  p.style.marginBottom = `${this.getPageGap()}px`;
9004
+ p.width = width * dpr;
9005
+ p.height = height * dpr;
9006
+ this.ctxList[i].scale(dpr, dpr);
8950
9007
  });
8951
9008
  this.render({
8952
9009
  isSubmitHistory: false,
@@ -8956,6 +9013,20 @@ class Draw {
8956
9013
  this.listener.pageScaleChange(payload);
8957
9014
  }
8958
9015
  }
9016
+ setPageDevicePixel() {
9017
+ const dpr = window.devicePixelRatio;
9018
+ const width = this.getWidth();
9019
+ const height = this.getHeight();
9020
+ this.pageList.forEach((p, i) => {
9021
+ p.width = width * dpr;
9022
+ p.height = height * dpr;
9023
+ this.ctxList[i].scale(dpr, dpr);
9024
+ });
9025
+ this.render({
9026
+ isSubmitHistory: false,
9027
+ isSetCursor: false
9028
+ });
9029
+ }
8959
9030
  setPaperSize(width, height) {
8960
9031
  this.options.width = width;
8961
9032
  this.options.height = height;
@@ -11420,7 +11491,7 @@ const controlMenus = [
11420
11491
  const globalMenus = [
11421
11492
  {
11422
11493
  i18nPath: "contextmenu.global.cut",
11423
- shortCut: "Ctrl + X",
11494
+ shortCut: `${isApple ? "\u2318" : "Ctrl"} + X`,
11424
11495
  when: (payload) => {
11425
11496
  return !payload.isReadonly;
11426
11497
  },
@@ -11430,7 +11501,7 @@ const globalMenus = [
11430
11501
  },
11431
11502
  {
11432
11503
  i18nPath: "contextmenu.global.copy",
11433
- shortCut: "Ctrl + C",
11504
+ shortCut: `${isApple ? "\u2318" : "Ctrl"} + C`,
11434
11505
  when: (payload) => {
11435
11506
  return payload.editorHasSelection;
11436
11507
  },
@@ -11440,7 +11511,7 @@ const globalMenus = [
11440
11511
  },
11441
11512
  {
11442
11513
  i18nPath: "contextmenu.global.paste",
11443
- shortCut: "Ctrl + V",
11514
+ shortCut: `${isApple ? "\u2318" : "Ctrl"} + V`,
11444
11515
  when: (payload) => {
11445
11516
  return !payload.isReadonly && payload.editorTextFocus;
11446
11517
  },
@@ -11450,7 +11521,7 @@ const globalMenus = [
11450
11521
  },
11451
11522
  {
11452
11523
  i18nPath: "contextmenu.global.selectAll",
11453
- shortCut: "Ctrl + A",
11524
+ shortCut: `${isApple ? "\u2318" : "Ctrl"} + A`,
11454
11525
  when: (payload) => {
11455
11526
  return payload.editorTextFocus;
11456
11527
  },