@hailin-zheng/editor-core 2.2.21 → 2.2.23

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
@@ -14130,10 +14136,10 @@ class DynamicExecute {
14130
14136
  this.depItems = undefined;
14131
14137
  }
14132
14138
  cacheList;
14133
- getControlById(id) {
14139
+ getControlById(id, options) {
14134
14140
  if (!this.cacheList) {
14135
14141
  const ctx = new DocumentContext(this.doc, this.ss);
14136
- this.cacheList = ctx.getDataElementModelList();
14142
+ this.cacheList = ctx.getDataElementModelList(options);
14137
14143
  }
14138
14144
  const f = this.cacheList.find(item => item.id === id);
14139
14145
  return f;
@@ -14144,11 +14150,10 @@ 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
  }
14151
- const control = this.getControlById(id);
14156
+ const control = this.getControlById(id, { includeChildren: true });
14152
14157
  return {
14153
14158
  get value() {
14154
14159
  if (control) {
@@ -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) {
@@ -21805,14 +21813,15 @@ class DocEditor {
21805
21813
  * @private
21806
21814
  */
21807
21815
  updateInputFont() {
21808
- const { startControl } = this.selectionState;
21816
+ const { startControl, startOffset } = this.selectionState;
21809
21817
  if (startControl instanceof TextGroupElement) {
21810
21818
  this.viewOptions.currentFontSize = startControl.props.fontSize;
21811
21819
  this.viewOptions.currentFontName = startControl.props.fontName;
21812
21820
  }
21813
21821
  else {
21814
- this.viewOptions.currentFontSize = this.viewOptions.defaultFontSize;
21815
- this.viewOptions.currentFontName = this.viewOptions.defaultFontName;
21822
+ const inputTextProps = this.documentChange.getDefaultTextProps(startControl, startOffset);
21823
+ this.viewOptions.currentFontSize = inputTextProps.fontSize;
21824
+ this.viewOptions.currentFontName = inputTextProps.fontName;
21816
21825
  }
21817
21826
  }
21818
21827
  hitInfoChanged(hitInfo) {
@@ -23034,7 +23043,7 @@ class DocEditor {
23034
23043
  rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
23035
23044
  }
23036
23045
  version() {
23037
- return "2.2.21";
23046
+ return "2.2.23";
23038
23047
  }
23039
23048
  switchPageHeaderEditor() {
23040
23049
  this.docCtx.document.switchPageHeaderEditor(this.selectionState, null);