@hailin-zheng/editor-core 2.2.22 → 2.2.24

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/index-cjs.js CHANGED
@@ -12082,81 +12082,87 @@ class ElementUtil {
12082
12082
  }
12083
12083
  return true;
12084
12084
  }
12085
- /**
12086
- * 获取一个点到一个矩形最短的距离
12087
- * @param rect
12088
- * @param p
12089
- * @returns
12090
- */
12091
- static getDistanceToRect(rect, p) {
12092
- const lines = [];
12093
- lines.push({
12094
- f: {
12095
- x: rect.x,
12096
- y: rect.y
12097
- },
12098
- s: {
12099
- x: rect.x + rect.width,
12100
- y: rect.y
12101
- }
12102
- }, {
12103
- f: {
12104
- x: rect.x,
12105
- y: rect.y
12106
- },
12107
- s: {
12108
- x: rect.x,
12109
- y: rect.y + rect.height
12110
- }
12111
- }, {
12112
- f: {
12113
- x: rect.x,
12114
- y: rect.y + rect.height
12115
- },
12116
- s: {
12117
- x: rect.x + rect.width,
12118
- y: rect.y + rect.height
12119
- }
12120
- }, {
12121
- f: {
12122
- x: rect.x + rect.width,
12123
- y: rect.y
12124
- },
12125
- s: {
12126
- x: rect.x + rect.width,
12127
- y: rect.y + rect.height
12128
- }
12129
- });
12130
- const distances = lines.map(item => this.minDistance(item.f, item.s, p));
12131
- return Math.min(...distances);
12132
- }
12133
- static minDistance(A, B, E) {
12134
- const AB = { x: B.x - A.x, y: B.y - A.y };
12135
- const BE = { x: E.x - B.x, y: E.y - B.y };
12136
- const AE = { x: E.x - A.x, y: E.y - A.y };
12137
- const AB_BE = (AB.x * BE.x + AB.y * BE.y);
12138
- const AB_AE = (AB.x * AE.x + AB.y * AE.y);
12139
- let reqAns = 0;
12140
- if (AB_BE > 0) {
12141
- const y = E.y - B.y;
12142
- const x = E.x - B.x;
12143
- reqAns = Math.sqrt(x * x + y * y);
12144
- }
12145
- else if (AB_AE < 0) {
12146
- const y = E.y - A.y;
12147
- const x = E.x - A.x;
12148
- reqAns = Math.sqrt(x * x + y * y);
12149
- }
12150
- else {
12151
- const x1 = AB.x;
12152
- const y1 = AB.y;
12153
- const x2 = AE.x;
12154
- const y2 = AE.y;
12155
- const mod = Math.sqrt(x1 * x1 + y1 * y1);
12156
- reqAns = Math.abs(x1 * y2 - y1 * x2) / mod;
12157
- }
12158
- return reqAns;
12085
+ static getDistanceToRect(rect, point) {
12086
+ // 点到矩形左边的距离
12087
+ const dx = Math.max(rect.x - point.x, 0, point.x - (rect.x + rect.width));
12088
+ // 点到矩形上边的距离
12089
+ const dy = Math.max(rect.y - point.y, 0, point.y - (rect.y + rect.height));
12090
+ // 距离公式
12091
+ return Math.sqrt(dx * dx + dy * dy);
12159
12092
  }
12093
+ // /**
12094
+ // * 获取一个点到一个矩形最短的距离
12095
+ // * @param rect
12096
+ // * @param p
12097
+ // * @returns
12098
+ // */
12099
+ // static getDistanceToRect(rect: Rect, p: Position) {
12100
+ // const lines: Array<{ f: PAIR, s: PAIR }> = [];
12101
+ // lines.push({
12102
+ // f: {
12103
+ // x: rect.x,
12104
+ // y: rect.y
12105
+ // },
12106
+ // s: {
12107
+ // x: rect.x + rect.width,
12108
+ // y: rect.y
12109
+ // }
12110
+ // }, {
12111
+ // f: {
12112
+ // x: rect.x,
12113
+ // y: rect.y
12114
+ // },
12115
+ // s: {
12116
+ // x: rect.x,
12117
+ // y: rect.y + rect.height
12118
+ // }
12119
+ // }, {
12120
+ // f: {
12121
+ // x: rect.x,
12122
+ // y: rect.y + rect.height
12123
+ // },
12124
+ // s: {
12125
+ // x: rect.x + rect.width,
12126
+ // y: rect.y + rect.height
12127
+ // }
12128
+ // }, {
12129
+ // f: {
12130
+ // x: rect.x + rect.width,
12131
+ // y: rect.y
12132
+ // },
12133
+ // s: {
12134
+ // x: rect.x + rect.width,
12135
+ // y: rect.y + rect.height
12136
+ // }
12137
+ // })
12138
+ // const distances = lines.map(item => this.minDistance(item.f, item.s, p))
12139
+ // return Math.min(...distances);
12140
+ // }
12141
+ // static minDistance(A: PAIR, B: PAIR, E: PAIR) {
12142
+ // const AB: PAIR = { x: B.x - A.x, y: B.y - A.y }
12143
+ // const BE: PAIR = { x: E.x - B.x, y: E.y - B.y };
12144
+ // const AE: PAIR = { x: E.x - A.x, y: E.y - A.y }
12145
+ // const AB_BE = (AB.x * BE.x + AB.y * BE.y);
12146
+ // const AB_AE = (AB.x * AE.x + AB.y * AE.y);
12147
+ // let reqAns = 0;
12148
+ // if (AB_BE > 0) {
12149
+ // const y = E.y - B.y;
12150
+ // const x = E.x - B.x;
12151
+ // reqAns = Math.sqrt(x * x + y * y);
12152
+ // } else if (AB_AE < 0) {
12153
+ // const y = E.y - A.y;
12154
+ // const x = E.x - A.x;
12155
+ // reqAns = Math.sqrt(x * x + y * y);
12156
+ // } else {
12157
+ // const x1 = AB.x;
12158
+ // const y1 = AB.y;
12159
+ // const x2 = AE.x;
12160
+ // const y2 = AE.y;
12161
+ // const mod = Math.sqrt(x1 * x1 + y1 * y1);
12162
+ // reqAns = Math.abs(x1 * y2 - y1 * x2) / mod;
12163
+ // }
12164
+ // return reqAns;
12165
+ // }
12160
12166
  /**
12161
12167
  * 获取父级层级渲染对象
12162
12168
  * @param render
@@ -14144,7 +14150,6 @@ class DynamicExecute {
14144
14150
  if (this.depItems && this.depItems.has(id)) {
14145
14151
  return this.depItems.get(id);
14146
14152
  }
14147
- new DocumentContext(this.doc, this.ss);
14148
14153
  if (id.startsWith('$')) {
14149
14154
  id = id.slice(1);
14150
14155
  }
@@ -17613,6 +17618,9 @@ class DocumentChange {
17613
17618
  });
17614
17619
  }
17615
17620
  newInput(data) {
17621
+ if (data.data === '啊' || data.data === 'a') {
17622
+ debugger;
17623
+ }
17616
17624
  const { startControl, startOffset, collapsed } = this.selectionState;
17617
17625
  const enableTrackChanges = this.viewOptions.enableTrackChanges;
17618
17626
  if (!collapsed) {
@@ -21703,8 +21711,12 @@ class DocEditor {
21703
21711
  // }
21704
21712
  this.flushTask = () => {
21705
21713
  //读取变更记录,可能会同步影响文档内容
21706
- this.readDocChangeLog();
21714
+ const isChanged = this.readDocChangeLog();
21707
21715
  this.refreshDocument();
21716
+ //触发文档改变
21717
+ if (isChanged) {
21718
+ this.triggerDocChange();
21719
+ }
21708
21720
  this.flushTask = null;
21709
21721
  //回调
21710
21722
  // let cbs = [...this.docCtx.nextViewFns];
@@ -21805,14 +21817,15 @@ class DocEditor {
21805
21817
  * @private
21806
21818
  */
21807
21819
  updateInputFont() {
21808
- const { startControl } = this.selectionState;
21820
+ const { startControl, startOffset } = this.selectionState;
21809
21821
  if (startControl instanceof TextGroupElement) {
21810
21822
  this.viewOptions.currentFontSize = startControl.props.fontSize;
21811
21823
  this.viewOptions.currentFontName = startControl.props.fontName;
21812
21824
  }
21813
21825
  else {
21814
- this.viewOptions.currentFontSize = this.viewOptions.defaultFontSize;
21815
- this.viewOptions.currentFontName = this.viewOptions.defaultFontName;
21826
+ const inputTextProps = this.documentChange.getDefaultTextProps(startControl, startOffset);
21827
+ this.viewOptions.currentFontSize = inputTextProps.fontSize;
21828
+ this.viewOptions.currentFontName = inputTextProps.fontName;
21816
21829
  }
21817
21830
  }
21818
21831
  hitInfoChanged(hitInfo) {
@@ -23034,7 +23047,7 @@ class DocEditor {
23034
23047
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
23035
23048
  }
23036
23049
  version() {
23037
- return "2.2.22";
23050
+ return "2.2.24";
23038
23051
  }
23039
23052
  switchPageHeaderEditor() {
23040
23053
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);
@@ -23114,6 +23127,10 @@ class DocEditor {
23114
23127
  ])
23115
23128
  ]);
23116
23129
  }
23130
+ /**
23131
+ * 读取操作日志,并返回是否修改的标志
23132
+ * @returns
23133
+ */
23117
23134
  readDocChangeLog() {
23118
23135
  //获取文档的变更日志
23119
23136
  const ops = generatePatch(this.docCtx.document, false);
@@ -23152,9 +23169,10 @@ class DocEditor {
23152
23169
  else {
23153
23170
  this.docCtx.suggestions.clear();
23154
23171
  }
23155
- if (ops.length) {
23156
- this.triggerDocChange();
23157
- }
23172
+ return ops.length;
23173
+ // if (ops.length) {
23174
+ // this.triggerDocChange();
23175
+ // }
23158
23176
  }
23159
23177
  /**
23160
23178
  * 处理候选词