@hufe921/canvas-editor 0.9.16 → 0.9.17

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/README.md CHANGED
@@ -26,17 +26,16 @@ new Editor(document.querySelector(".canvas-editor"), [
26
26
  ])
27
27
  ```
28
28
 
29
- ## snapshot
29
+ ## next features
30
30
 
31
- ![image](https://github.com/Hufe921/canvas-editor/blob/main/src/assets/snapshots/main_v0.9.8.png)
31
+ 1. improve performance
32
+ 2. page header and footer
33
+ 3. control rules
34
+ 4. table paging
32
35
 
33
- ## next features
36
+ ## snapshot
34
37
 
35
- 1. support mac os
36
- 2. drag text (optimization)
37
- 3. page header and footer
38
- 4. control rules
39
- 5. table paging
38
+ ![image](https://github.com/Hufe921/canvas-editor/blob/main/src/assets/snapshots/main_v0.9.8.png)
40
39
 
41
40
  ## install
42
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.16";
26
+ const version = "0.9.17";
27
27
  const ZERO = "\u200B";
28
28
  const WRAP = "\n";
29
29
  var RowFlex;
@@ -131,6 +131,12 @@ function mergeObject(source, target) {
131
131
  return target;
132
132
  }
133
133
  const CURSOR_AGENT_HEIGHT = 12;
134
+ const defaultCursorOption = {
135
+ width: 1,
136
+ color: "#000000",
137
+ dragWidth: 2,
138
+ dragColor: "#0000FF"
139
+ };
134
140
  const EDITOR_COMPONENT = "editor-component";
135
141
  const EDITOR_PREFIX = "ce";
136
142
  var ElementType;
@@ -3961,12 +3967,12 @@ class Cursor {
3961
3967
  clearAgentDomValue() {
3962
3968
  return this.getAgentDom().value = "";
3963
3969
  }
3964
- drawCursor() {
3965
- const isReadonly = this.draw.isReadonly();
3970
+ drawCursor(payload) {
3966
3971
  const cursorPosition = this.position.getCursorPosition();
3967
3972
  if (!cursorPosition)
3968
3973
  return;
3969
- const { scale } = this.options;
3974
+ const { scale, cursor } = this.options;
3975
+ const { color, width, isBlink = true } = __spreadValues(__spreadValues({}, cursor), payload);
3970
3976
  const height = this.draw.getHeight();
3971
3977
  const pageGap = this.draw.getPageGap();
3972
3978
  const { metrics, coordinate: { leftTop, rightTop }, ascent, pageNo } = cursorPosition;
@@ -3983,13 +3989,21 @@ class Cursor {
3983
3989
  const cursorLeft = rightTop[0];
3984
3990
  agentCursorDom.style.left = `${cursorLeft}px`;
3985
3991
  agentCursorDom.style.top = `${cursorTop + cursorHeight - CURSOR_AGENT_HEIGHT * scale}px`;
3992
+ const isReadonly = this.draw.isReadonly();
3993
+ this.cursorDom.style.width = `${width}px`;
3994
+ this.cursorDom.style.backgroundColor = color;
3986
3995
  this.cursorDom.style.left = `${cursorLeft}px`;
3987
3996
  this.cursorDom.style.top = `${cursorTop}px`;
3988
3997
  this.cursorDom.style.display = isReadonly ? "none" : "block";
3989
3998
  this.cursorDom.style.height = `${cursorHeight}px`;
3990
- setTimeout(() => {
3991
- this.cursorDom.classList.add(`${EDITOR_PREFIX}-cursor--animation`);
3992
- }, 200);
3999
+ const animationClassName = `${EDITOR_PREFIX}-cursor--animation`;
4000
+ if (isBlink) {
4001
+ setTimeout(() => {
4002
+ this.cursorDom.classList.add(animationClassName);
4003
+ }, 200);
4004
+ } else {
4005
+ this.cursorDom.classList.remove(animationClassName);
4006
+ }
3993
4007
  }
3994
4008
  recoveryCursor() {
3995
4009
  this.cursorDom.style.display = "none";
@@ -4674,7 +4688,8 @@ function input(data2, host) {
4674
4688
  if (control.isPartRangeInControlOutside()) {
4675
4689
  return;
4676
4690
  }
4677
- if (!host.isComposing) {
4691
+ const isComposing = host.isComposing;
4692
+ if (!isComposing) {
4678
4693
  const cursor = draw.getCursor();
4679
4694
  cursor.clearAgentDomValue();
4680
4695
  } else {
@@ -4707,7 +4722,7 @@ function input(data2, host) {
4707
4722
  }
4708
4723
  });
4709
4724
  }
4710
- if (host.isComposing) {
4725
+ if (isComposing) {
4711
4726
  newElement.underline = true;
4712
4727
  }
4713
4728
  return newElement;
@@ -4727,9 +4742,10 @@ function input(data2, host) {
4727
4742
  }
4728
4743
  rangeManager.setRange(curIndex, curIndex);
4729
4744
  draw.render({
4730
- curIndex
4745
+ curIndex,
4746
+ isSubmitHistory: !isComposing
4731
4747
  });
4732
- if (host.isComposing) {
4748
+ if (isComposing) {
4733
4749
  host.compositionInfo = {
4734
4750
  elementList,
4735
4751
  value: text,
@@ -4952,7 +4968,12 @@ function dragover(evt, host) {
4952
4968
  position.setCursorPosition(positionList[curIndex]);
4953
4969
  }
4954
4970
  const cursor = draw.getCursor();
4955
- cursor.drawCursor();
4971
+ const { cursor: { dragColor, dragWidth } } = draw.getOptions();
4972
+ cursor.drawCursor({
4973
+ width: dragWidth,
4974
+ color: dragColor,
4975
+ isBlink: false
4976
+ });
4956
4977
  }
4957
4978
  var drag = {
4958
4979
  dragover
@@ -6153,46 +6174,12 @@ class PageNumber {
6153
6174
  class ScrollObserver {
6154
6175
  constructor(draw) {
6155
6176
  __publicField(this, "draw");
6156
- __publicField(this, "options");
6157
- __publicField(this, "pageContainer");
6158
- __publicField(this, "pageHeight");
6159
6177
  __publicField(this, "_observer", debounce(() => {
6160
- const rect = this.pageContainer.getBoundingClientRect();
6161
- const top = Math.abs(rect.top);
6162
- const bottom = top + window.innerHeight;
6163
- const pageList = this.draw.getPageList();
6164
- const visiblePageNoList = [];
6165
- let intersectionPageNo = 0;
6166
- let intersectionMaxHeight = 0;
6167
- for (let i = 0; i < pageList.length; i++) {
6168
- const curTop = i * this.pageHeight;
6169
- const curBottom = (i + 1) * this.pageHeight;
6170
- if (curTop > bottom)
6171
- break;
6172
- if (curBottom < top)
6173
- continue;
6174
- let intersectionHeight = 0;
6175
- if (curTop < top && curBottom < bottom) {
6176
- intersectionHeight = curBottom - top;
6177
- } else if (curTop > top && curBottom > bottom) {
6178
- intersectionHeight = bottom - curTop;
6179
- } else {
6180
- intersectionHeight = rect.height;
6181
- }
6182
- if (intersectionHeight > intersectionMaxHeight) {
6183
- intersectionMaxHeight = intersectionHeight;
6184
- intersectionPageNo = i;
6185
- }
6186
- visiblePageNoList.push(i);
6187
- }
6178
+ const { intersectionPageNo, visiblePageNoList } = this.getPageVisibleInfo();
6188
6179
  this.draw.setIntersectionPageNo(intersectionPageNo);
6189
6180
  this.draw.setVisiblePageNoList(visiblePageNoList);
6190
6181
  }, 150));
6191
6182
  this.draw = draw;
6192
- this.options = draw.getOptions();
6193
- this.pageContainer = draw.getPageContainer();
6194
- const { height, pageGap } = this.options;
6195
- this.pageHeight = height + pageGap;
6196
6183
  setTimeout(() => {
6197
6184
  if (!window.scrollY) {
6198
6185
  this._observer();
@@ -6206,6 +6193,37 @@ class ScrollObserver {
6206
6193
  removeEvent() {
6207
6194
  document.removeEventListener("scroll", this._observer);
6208
6195
  }
6196
+ getElementVisibleInfo(element) {
6197
+ const rect = element.getBoundingClientRect();
6198
+ const viewHeight = Math.max(document.documentElement.clientHeight, window.innerHeight);
6199
+ const visibleHeight = Math.min(rect.bottom, viewHeight) - Math.max(rect.top, 0);
6200
+ return {
6201
+ intersectionHeight: visibleHeight > 0 ? visibleHeight : 0
6202
+ };
6203
+ }
6204
+ getPageVisibleInfo() {
6205
+ const pageList = this.draw.getPageList();
6206
+ const visiblePageNoList = [];
6207
+ let intersectionPageNo = 0;
6208
+ let intersectionMaxHeight = 0;
6209
+ for (let i = 0; i < pageList.length; i++) {
6210
+ const curPage = pageList[i];
6211
+ const { intersectionHeight } = this.getElementVisibleInfo(curPage);
6212
+ if (intersectionMaxHeight && !intersectionHeight)
6213
+ break;
6214
+ if (intersectionHeight) {
6215
+ visiblePageNoList.push(i);
6216
+ }
6217
+ if (intersectionHeight > intersectionMaxHeight) {
6218
+ intersectionMaxHeight = intersectionHeight;
6219
+ intersectionPageNo = i;
6220
+ }
6221
+ }
6222
+ return {
6223
+ intersectionPageNo,
6224
+ visiblePageNoList
6225
+ };
6226
+ }
6209
6227
  }
6210
6228
  var MoveDirection;
6211
6229
  (function(MoveDirection2) {
@@ -12118,6 +12136,7 @@ class Editor {
12118
12136
  const waterMarkOptions = __spreadValues(__spreadValues({}, defaultWatermarkOption), options.watermark);
12119
12137
  const controlOptions = __spreadValues(__spreadValues({}, defaultControlOption), options.control);
12120
12138
  const checkboxOptions = __spreadValues(__spreadValues({}, defaultCheckboxOption), options.checkbox);
12139
+ const cursorOptions = __spreadValues(__spreadValues({}, defaultCursorOption), options.cursor);
12121
12140
  const editorOptions = __spreadProps(__spreadValues({
12122
12141
  mode: EditorMode.EDIT,
12123
12142
  defaultType: "TEXT",
@@ -12156,7 +12175,8 @@ class Editor {
12156
12175
  header: headerOptions,
12157
12176
  watermark: waterMarkOptions,
12158
12177
  control: controlOptions,
12159
- checkbox: checkboxOptions
12178
+ checkbox: checkboxOptions,
12179
+ cursor: cursorOptions
12160
12180
  });
12161
12181
  formatElementList(elementList, {
12162
12182
  editorOptions