@hailin-zheng/editor-core 2.1.1 → 2.1.3
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 +174 -4
- package/index-cjs.js.map +1 -1
- package/index.js +174 -4
- package/index.js.map +1 -1
- package/med_editor/framework/common-util.d.ts +1 -0
- package/med_editor/framework/document-svg.d.ts +6 -0
- package/med_editor/framework/element-define.d.ts +1 -0
- package/med_editor/framework/impl/media-formula/permanent-teeth.d.ts +19 -15
- package/package.json +1 -1
package/index.js
CHANGED
@@ -651,6 +651,23 @@ class CommonUtil {
|
|
651
651
|
}
|
652
652
|
return this.findParent(curr.parentElement, predicate);
|
653
653
|
}
|
654
|
+
static isIntersect(rect1, rect2) {
|
655
|
+
const left1 = rect1.x;
|
656
|
+
const top1 = rect1.y;
|
657
|
+
const right1 = rect1.x + rect1.width;
|
658
|
+
const bottom1 = rect1.y + rect1.height;
|
659
|
+
const left2 = rect2.x;
|
660
|
+
const top2 = rect2.y;
|
661
|
+
const right2 = rect2.x + rect2.width;
|
662
|
+
const bottom2 = rect2.y + rect2.height;
|
663
|
+
if (left1 >= right2 || left2 >= right1) {
|
664
|
+
return false;
|
665
|
+
}
|
666
|
+
if (top1 >= bottom2 || top2 >= bottom1) {
|
667
|
+
return false;
|
668
|
+
}
|
669
|
+
return true;
|
670
|
+
}
|
654
671
|
}
|
655
672
|
|
656
673
|
const docOpsMap = new Map();
|
@@ -1517,6 +1534,8 @@ class ViewOptions {
|
|
1517
1534
|
paraSymbolColor = 'rgb(128,128,128)';
|
1518
1535
|
dataGroupColor = 'rgb(0,80,179)';
|
1519
1536
|
defaultLineHeight = 1;
|
1537
|
+
//虚拟视图模式,处理可视区域内的元素
|
1538
|
+
virtualViewMode = false;
|
1520
1539
|
//新增-留痕块文本颜色
|
1521
1540
|
trackInsColor = '#ff4d4f';
|
1522
1541
|
//删除-留痕块文本颜色
|
@@ -16156,13 +16175,13 @@ class DocumentPaint {
|
|
16156
16175
|
this.docContainer.clear();
|
16157
16176
|
const { pageLayoutMode, viewSettings: { width: viewWidth } } = this.viewOptions;
|
16158
16177
|
//文档内容区宽度
|
16159
|
-
const contentWidth = this.viewOptions
|
16178
|
+
const { contentWidth, scale } = this.viewOptions;
|
16160
16179
|
//文档容器总宽度等于内容宽度
|
16161
16180
|
//单页模式,docContainer居中
|
16162
16181
|
this.docContainer.rect.width = viewWidth;
|
16163
16182
|
//let docLeft = Math.floor((viewWidth - contentWidth) / 2);
|
16164
16183
|
//处理由于缩放问题,transform-origin:left-top,因此需要提前计算需要偏移的位置
|
16165
|
-
let docLeft = Math.floor((viewWidth - contentWidth *
|
16184
|
+
let docLeft = Math.floor((viewWidth - contentWidth * scale) / 2) / scale;
|
16166
16185
|
docLeft = docLeft < 0 ? 0 : docLeft;
|
16167
16186
|
pages.forEach(item => item.rect.x = docLeft);
|
16168
16187
|
this.docContainer.rect.x = 0;
|
@@ -16313,6 +16332,132 @@ class PageBreakFactory extends ElementFactory {
|
|
16313
16332
|
}
|
16314
16333
|
}
|
16315
16334
|
|
16335
|
+
const fontSize = 12;
|
16336
|
+
const verPadding = 2;
|
16337
|
+
/**
|
16338
|
+
* 恒牙牙位图
|
16339
|
+
*/
|
16340
|
+
class PermanentTeethElement extends LeafElement {
|
16341
|
+
constructor() {
|
16342
|
+
super('permanent-teeth');
|
16343
|
+
this.props = new PermanentTeethProps();
|
16344
|
+
this.props.topLeft = '';
|
16345
|
+
this.props.topRight = '';
|
16346
|
+
this.props.bottomLeft = '';
|
16347
|
+
this.props.bottomRight = '';
|
16348
|
+
}
|
16349
|
+
clone(data) {
|
16350
|
+
const clone = new PermanentTeethElement();
|
16351
|
+
clone.props = this.props.clone();
|
16352
|
+
return clone;
|
16353
|
+
}
|
16354
|
+
createRenderObject(data) {
|
16355
|
+
const clone = new PermanentTeethRenderObject(this);
|
16356
|
+
clone.rect.width = 150;
|
16357
|
+
//字体大小*2+上下间距2*2
|
16358
|
+
clone.rect.height = fontSize * 2 + verPadding * 2;
|
16359
|
+
//clone.rect= ElementUtil.cloneRect(this.rect);
|
16360
|
+
return clone;
|
16361
|
+
}
|
16362
|
+
serialize(viewOptions) {
|
16363
|
+
return {
|
16364
|
+
type: this.type,
|
16365
|
+
props: this.props.getSerializeProps(viewOptions)
|
16366
|
+
};
|
16367
|
+
}
|
16368
|
+
}
|
16369
|
+
class PermanentTeethRenderObject extends LeafRenderObject {
|
16370
|
+
render(e) {
|
16371
|
+
}
|
16372
|
+
clone() {
|
16373
|
+
const clone = new PermanentTeethRenderObject(this.element);
|
16374
|
+
clone.rect = ElementUtil.cloneRect(this.rect);
|
16375
|
+
return clone;
|
16376
|
+
}
|
16377
|
+
// measure(): { width: number, height: number } {
|
16378
|
+
// const ele = this.element;
|
16379
|
+
//
|
16380
|
+
// }
|
16381
|
+
exportHTML(event) {
|
16382
|
+
const ele = this.element;
|
16383
|
+
const g = super.exportHTML(event);
|
16384
|
+
const contentHorPadding = 4;
|
16385
|
+
g.children = [];
|
16386
|
+
// g.children.push(ElementUtil.getFillSvgPath(`M 0 ${this.rect.height / 2} h${this.rect.width}`, '#000', 1));
|
16387
|
+
// g.children.push(ElementUtil.getFillSvgPath(`M ${this.rect.width / 2} 0 v${this.rect.height}`, '#000', 1));
|
16388
|
+
//
|
16389
|
+
g.children.push(ElementUtil.getFillSvgRect(0, this.rect.height / 2, this.rect.width, 1, '#000'));
|
16390
|
+
g.children.push(ElementUtil.getFillSvgRect(this.rect.width / 2, 0, 1, this.rect.height, '#000'));
|
16391
|
+
const getSvgText = (text, x, y) => {
|
16392
|
+
return {
|
16393
|
+
sel: 'text',
|
16394
|
+
text: text,
|
16395
|
+
data: {
|
16396
|
+
ns: "http://www.w3.org/2000/svg",
|
16397
|
+
attrs: {
|
16398
|
+
'dominant-baseline': 'hanging',
|
16399
|
+
'font-family': 'Arial',
|
16400
|
+
'font-size': fontSize,
|
16401
|
+
x,
|
16402
|
+
y,
|
16403
|
+
}
|
16404
|
+
},
|
16405
|
+
};
|
16406
|
+
};
|
16407
|
+
const topLeftWidth = event.renderCtx.mainContext.measureTextWidth(ele.props.topLeft, {
|
16408
|
+
fontSize: fontSize,
|
16409
|
+
fontName: 'Arial'
|
16410
|
+
});
|
16411
|
+
const bottomLeftWidth = event.renderCtx.mainContext.measureTextWidth(ele.props.bottomLeft, {
|
16412
|
+
fontSize: fontSize,
|
16413
|
+
fontName: 'Arial'
|
16414
|
+
});
|
16415
|
+
g.children.push(getSvgText(ele.props.topLeft, this.rect.width / 2 - topLeftWidth - contentHorPadding, verPadding));
|
16416
|
+
g.children.push(getSvgText(ele.props.topRight, this.rect.width / 2 + contentHorPadding, verPadding));
|
16417
|
+
g.children.push(getSvgText(ele.props.bottomLeft, this.rect.width / 2 - bottomLeftWidth - contentHorPadding, this.rect.height - fontSize + verPadding));
|
16418
|
+
g.children.push(getSvgText(ele.props.bottomRight, this.rect.width / 2 + contentHorPadding, this.rect.height - fontSize + verPadding));
|
16419
|
+
return g;
|
16420
|
+
}
|
16421
|
+
}
|
16422
|
+
class PermanentTeethFactory extends ElementFactory {
|
16423
|
+
match(type) {
|
16424
|
+
return type === 'permanent-teeth';
|
16425
|
+
}
|
16426
|
+
createElement(data) {
|
16427
|
+
const ele = new PermanentTeethElement();
|
16428
|
+
ele.props.bottomLeft = data.props?.bottomLeft ?? '';
|
16429
|
+
ele.props.bottomRight = data.props?.bottomRight ?? '';
|
16430
|
+
ele.props.topLeft = data.props?.topLeft ?? '';
|
16431
|
+
ele.props.topRight = data.props?.topRight ?? '';
|
16432
|
+
return ele;
|
16433
|
+
}
|
16434
|
+
}
|
16435
|
+
/**
|
16436
|
+
* 恒牙牙位图属性
|
16437
|
+
*/
|
16438
|
+
class PermanentTeethProps extends INotifyPropertyChanged {
|
16439
|
+
topLeft;
|
16440
|
+
topRight;
|
16441
|
+
bottomLeft;
|
16442
|
+
bottomRight;
|
16443
|
+
getSerializeProps(viewOptions) {
|
16444
|
+
return {
|
16445
|
+
topLeft: this.topLeft,
|
16446
|
+
topRight: this.topRight,
|
16447
|
+
bottomLeft: this.bottomLeft,
|
16448
|
+
bottomRight: this.bottomRight,
|
16449
|
+
};
|
16450
|
+
}
|
16451
|
+
clone(dest) {
|
16452
|
+
dest = dest || new PermanentTeethProps();
|
16453
|
+
dest.topLeft = this.topLeft;
|
16454
|
+
dest.topRight = this.topRight;
|
16455
|
+
dest.bottomLeft = this.bottomLeft;
|
16456
|
+
dest.bottomRight = this.bottomRight;
|
16457
|
+
return dest;
|
16458
|
+
}
|
16459
|
+
}
|
16460
|
+
|
16316
16461
|
class ElementReader {
|
16317
16462
|
docCtx;
|
16318
16463
|
constructor(docCtx) {
|
@@ -16354,6 +16499,7 @@ class ElementReader {
|
|
16354
16499
|
this.addFactory(DocumentBodyPartFactory);
|
16355
16500
|
this.addFactory(PageBreakFactory);
|
16356
16501
|
this.addFactory(TabFactory);
|
16502
|
+
this.addFactory(PermanentTeethFactory);
|
16357
16503
|
// this.registerReadFunc<TrackRunProps>('ins-run', (data) => {
|
16358
16504
|
// const props = new TrackRunProps(data.type);
|
16359
16505
|
// props.userId = data.userId;
|
@@ -17047,6 +17193,7 @@ class DocumentEvent {
|
|
17047
17193
|
docEvent.shift = evt.shiftKey;
|
17048
17194
|
docEvent.ctrl = evt.ctrlKey;
|
17049
17195
|
this.ismousedown = false;
|
17196
|
+
this.mousedownPos = { x: docEvent.globalX, y: docEvent.globalY };
|
17050
17197
|
//console.log('松开了')
|
17051
17198
|
this.edgeRenderInfo = null;
|
17052
17199
|
}
|
@@ -20945,7 +21092,7 @@ class DocumentSvg {
|
|
20945
21092
|
}
|
20946
21093
|
getHTMLVNode(docRenders) {
|
20947
21094
|
this.counterMap = {};
|
20948
|
-
const pageNodes = docRenders.map(item => {
|
21095
|
+
const pageNodes = docRenders.filter(item => this.checkInViewBox(item)).map(item => {
|
20949
21096
|
const pageSvg = this.getPageSvgVNode(item);
|
20950
21097
|
const pageUnit = {
|
20951
21098
|
sel: 'div.page-unit',
|
@@ -20970,6 +21117,29 @@ class DocumentSvg {
|
|
20970
21117
|
});
|
20971
21118
|
return pageNodes;
|
20972
21119
|
}
|
21120
|
+
/**
|
21121
|
+
* 判断当前元素是否在视窗内
|
21122
|
+
* @param rect
|
21123
|
+
* @private
|
21124
|
+
*/
|
21125
|
+
checkInViewBox(item) {
|
21126
|
+
if (!this.viewOptions.virtualViewMode || this.mode === 'print') {
|
21127
|
+
return true;
|
21128
|
+
}
|
21129
|
+
const { scale } = this.viewOptions;
|
21130
|
+
const viewBoxRect = {
|
21131
|
+
x: this.viewOptions.pageOffset.x,
|
21132
|
+
y: this.viewOptions.pageOffset.y,
|
21133
|
+
width: this.viewOptions.viewSettings.width,
|
21134
|
+
height: this.viewOptions.viewSettings.height
|
21135
|
+
};
|
21136
|
+
const eleRect = { ...item.rect };
|
21137
|
+
eleRect.x = eleRect.x * scale;
|
21138
|
+
eleRect.y = eleRect.y * scale;
|
21139
|
+
eleRect.width = eleRect.width * scale;
|
21140
|
+
eleRect.height = eleRect.height * scale;
|
21141
|
+
return CommonUtil.isIntersect(viewBoxRect, eleRect);
|
21142
|
+
}
|
20973
21143
|
getPageSvgVNode(item) {
|
20974
21144
|
this.highlights = [];
|
20975
21145
|
const rects = [];
|
@@ -28454,7 +28624,7 @@ class DocEditor {
|
|
28454
28624
|
rule.setRuleOptions({ width: this.viewOptions.docPageSettings.width, pagePL, pagePR, docLeft });
|
28455
28625
|
}
|
28456
28626
|
version() {
|
28457
|
-
return "2.1.
|
28627
|
+
return "2.1.3";
|
28458
28628
|
}
|
28459
28629
|
}
|
28460
28630
|
|