@hailin-zheng/editor-core 2.0.13 → 2.0.15
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 +91 -48
- package/index-cjs.js.map +1 -1
- package/index.js +91 -48
- package/index.js.map +1 -1
- package/med_editor/doc-editor.d.ts +4 -2
- package/med_editor/framework/document-template.d.ts +9 -0
- package/package.json +1 -1
- package/med_editor/framework/document-restriction.d.ts +0 -17
package/index-cjs.js
CHANGED
@@ -4810,45 +4810,23 @@ class TextGroupRenderObject extends LeafRenderObject {
|
|
4810
4810
|
if (this.element.props.background) {
|
4811
4811
|
const bgX = event.relativePagePos.x;
|
4812
4812
|
const bgY = event.relativePagePos.y;
|
4813
|
-
event.highlights.push(
|
4814
|
-
sel: 'path',
|
4815
|
-
data: {
|
4816
|
-
ns: "http://www.w3.org/2000/svg",
|
4817
|
-
attrs: {
|
4818
|
-
d: `M${bgX} ${bgY} h${width} v${this.rect.height} h-${width}z`,
|
4819
|
-
fill: this.element.props.background,
|
4820
|
-
}
|
4821
|
-
}
|
4822
|
-
});
|
4813
|
+
event.highlights.push(ElementUtil.getFillSvgRect(bgX, bgY, this.rect.width, this.rect.height, this.element.props.background));
|
4823
4814
|
}
|
4824
4815
|
if (this.element.props.underline) {
|
4825
4816
|
const underHeight = this.element.props.fontSize * 1.2;
|
4826
|
-
event.
|
4827
|
-
|
4828
|
-
data: {
|
4829
|
-
ns: "http://www.w3.org/2000/svg",
|
4830
|
-
attrs: {
|
4831
|
-
d: `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + underHeight}`,
|
4832
|
-
stroke: '#000',
|
4833
|
-
'stroke-width': 1,
|
4834
|
-
fill: 'none'
|
4835
|
-
}
|
4836
|
-
}
|
4837
|
-
});
|
4817
|
+
const path = `M${event.relativePagePos.x} ${event.relativePagePos.y + underHeight} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + underHeight}`;
|
4818
|
+
event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
|
4838
4819
|
}
|
4839
4820
|
if (this.element.props.linethrough) {
|
4840
|
-
event.
|
4841
|
-
|
4842
|
-
|
4843
|
-
|
4844
|
-
|
4845
|
-
|
4846
|
-
|
4847
|
-
|
4848
|
-
|
4849
|
-
}
|
4850
|
-
}
|
4851
|
-
});
|
4821
|
+
const path = `M${event.relativePagePos.x} ${event.relativePagePos.y + this.rect.height / 2} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y + this.rect.height / 2}`;
|
4822
|
+
event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
|
4823
|
+
}
|
4824
|
+
if (this.element.props.border) {
|
4825
|
+
event.highlights.push(ElementUtil.getStrokeSvgPath(ElementUtil.getRectPath(event.relativePagePos.x, event.relativePagePos.y, this.rect.width, this.rect.height), '#000', 1));
|
4826
|
+
}
|
4827
|
+
if (this.element.props.overline) {
|
4828
|
+
const path = `M${event.relativePagePos.x} ${event.relativePagePos.y} L${event.relativePagePos.x + this.rect.width} ${event.relativePagePos.y}`;
|
4829
|
+
event.highlights.push(ElementUtil.getStrokeSvgPath(path, '#000', 1));
|
4852
4830
|
}
|
4853
4831
|
return t;
|
4854
4832
|
}
|
@@ -19829,17 +19807,81 @@ function printNodes(printNodes, options, printEvent = null) {
|
|
19829
19807
|
|
19830
19808
|
class DocumentTemplate {
|
19831
19809
|
static createA4Doc() {
|
19810
|
+
return DocumentTemplate.createDoc('A4');
|
19811
|
+
}
|
19812
|
+
static createDoc(name = 'A4') {
|
19832
19813
|
const doc = new DocumentElement();
|
19833
19814
|
doc.props = new DocumentProps();
|
19834
|
-
|
19835
|
-
doc.props.
|
19836
|
-
doc.props.
|
19815
|
+
const paper = DocumentTemplate.getPaper(name);
|
19816
|
+
doc.props.width = paper.width;
|
19817
|
+
doc.props.height = paper.height;
|
19818
|
+
doc.props.padding = new PaddingProps(paper.top, paper.bottom, paper.left, paper.right);
|
19837
19819
|
doc.addChild(new DocumentHeaderElement());
|
19838
19820
|
doc.addChild(new DocumentBodyElement());
|
19839
19821
|
doc.addChild(new DocumentFooterElement());
|
19840
19822
|
return doc;
|
19841
19823
|
}
|
19842
|
-
|
19824
|
+
static getPaper(name) {
|
19825
|
+
let top = 25.4, bottom = 25.4, left = 19.1, right = 19.1;
|
19826
|
+
const paper = PageSize.find(item => item.name.toUpperCase() === name.toUpperCase());
|
19827
|
+
if (paper) {
|
19828
|
+
if (top + bottom + 30 > paper.height) {
|
19829
|
+
top = bottom = 0;
|
19830
|
+
}
|
19831
|
+
if (left + right + 30 > paper.width) {
|
19832
|
+
left = right = 0;
|
19833
|
+
}
|
19834
|
+
return {
|
19835
|
+
width: paper.width,
|
19836
|
+
height: paper.height,
|
19837
|
+
top, left, right, bottom
|
19838
|
+
};
|
19839
|
+
}
|
19840
|
+
return { width: PageSize[0].width, height: PageSize[0].height, top, left, right, bottom };
|
19841
|
+
}
|
19842
|
+
}
|
19843
|
+
const PageSize = [
|
19844
|
+
{ name: 'A4', width: 210, height: 297 },
|
19845
|
+
{ name: 'A5', width: 148, height: 210 },
|
19846
|
+
{ name: 'A6', width: 105, height: 148 },
|
19847
|
+
{ name: 'B5', width: 176, height: 250 },
|
19848
|
+
{ name: 'B6', width: 125, height: 176 },
|
19849
|
+
{ name: 'Letter', width: 216, height: 279 },
|
19850
|
+
{ name: 'Legal', width: 216, height: 356 },
|
19851
|
+
{ name: 'Executive', width: 184, height: 267 },
|
19852
|
+
{ name: 'Folio', width: 210, height: 330 },
|
19853
|
+
{ name: 'Quarto', width: 215, height: 275 },
|
19854
|
+
{ name: '10x15cm', width: 100, height: 150 },
|
19855
|
+
{ name: '13x18cm', width: 130, height: 180 },
|
19856
|
+
{ name: '15x20cm', width: 150, height: 200 },
|
19857
|
+
{ name: '20x25cm', width: 200, height: 250 },
|
19858
|
+
{ name: '20x30cm', width: 200, height: 300 },
|
19859
|
+
{ name: '25x35cm', width: 250, height: 350 },
|
19860
|
+
{ name: '30x40cm', width: 300, height: 400 },
|
19861
|
+
{ name: 'A0', width: 841, height: 1189 },
|
19862
|
+
{ name: 'A1', width: 594, height: 841 },
|
19863
|
+
{ name: 'A2', width: 420, height: 594 },
|
19864
|
+
{ name: 'A3', width: 297, height: 420 },
|
19865
|
+
{ name: 'A7', width: 74, height: 105 },
|
19866
|
+
{ name: 'A8', width: 52, height: 74 },
|
19867
|
+
{ name: 'A9', width: 37, height: 52 },
|
19868
|
+
{ name: 'A10', width: 26, height: 37 },
|
19869
|
+
{ name: 'B0', width: 1000, height: 1414 },
|
19870
|
+
{ name: 'B1', width: 707, height: 1000 },
|
19871
|
+
{ name: 'B2', width: 500, height: 707 },
|
19872
|
+
{ name: 'B3', width: 353, height: 500 },
|
19873
|
+
{ name: 'B4', width: 250, height: 353 },
|
19874
|
+
{ name: 'B7', width: 88, height: 125 },
|
19875
|
+
{ name: 'B8', width: 62, height: 88 },
|
19876
|
+
{ name: 'B9', width: 44, height: 62 },
|
19877
|
+
{ name: 'B10', width: 31, height: 44 },
|
19878
|
+
{ name: 'C5E', width: 163, height: 229 },
|
19879
|
+
{ name: 'Comm10E', width: 105, height: 241 },
|
19880
|
+
{ name: 'DLE', width: 110, height: 220 },
|
19881
|
+
{ name: 'Folio', width: 210, height: 330 },
|
19882
|
+
{ name: 'Ledger', width: 432, height: 279 },
|
19883
|
+
{ name: 'Tabloid', width: 279, height: 432 }
|
19884
|
+
];
|
19843
19885
|
|
19844
19886
|
/**
|
19845
19887
|
* 处理文档批注
|
@@ -27003,7 +27045,7 @@ class DocEditor {
|
|
27003
27045
|
return null;
|
27004
27046
|
}
|
27005
27047
|
const dataEle = ElementUtil.getParent(startControl, validateDataEle);
|
27006
|
-
if (IsInSideDataElement(startControl, startOffset)) {
|
27048
|
+
if (dataEle instanceof DataElementLeaf || IsInSideDataElement(startControl, startOffset)) {
|
27007
27049
|
return dataEle;
|
27008
27050
|
}
|
27009
27051
|
else {
|
@@ -27011,8 +27053,7 @@ class DocEditor {
|
|
27011
27053
|
}
|
27012
27054
|
}
|
27013
27055
|
else if (!collapsed && ancestorCommonControl) {
|
27014
|
-
|
27015
|
-
return dataEle;
|
27056
|
+
return ElementUtil.getParent(startControl, validateDataEle);
|
27016
27057
|
}
|
27017
27058
|
return null;
|
27018
27059
|
}
|
@@ -27153,10 +27194,11 @@ class DocEditor {
|
|
27153
27194
|
/**
|
27154
27195
|
* 新建文档
|
27155
27196
|
* @param doc
|
27197
|
+
* @param name
|
27156
27198
|
*/
|
27157
|
-
createNewDoc(doc = null) {
|
27199
|
+
createNewDoc(doc = null, name = 'A4') {
|
27158
27200
|
//this.docCtx.clear();
|
27159
|
-
const newDoc = doc ?? DocumentTemplate.
|
27201
|
+
const newDoc = doc ?? DocumentTemplate.createDoc(name);
|
27160
27202
|
// this.elementReader.setDocument(newDoc);
|
27161
27203
|
// this.refreshDocument('content');
|
27162
27204
|
this.loadDoc(ElementSerialize.serialize(newDoc, this.viewOptions));
|
@@ -27380,12 +27422,13 @@ class DocEditor {
|
|
27380
27422
|
this.resetViewer('force');
|
27381
27423
|
this.selectionState.clear();
|
27382
27424
|
}
|
27383
|
-
/**
|
27384
|
-
* 设置纸张大小,单位为毫米(mm)
|
27385
|
-
* @param width
|
27386
|
-
* @param height
|
27387
|
-
*/
|
27388
27425
|
setPaperSize(width, height) {
|
27426
|
+
if (typeof width === 'string') {
|
27427
|
+
const paperSize = DocumentTemplate.getPaper(width);
|
27428
|
+
width = paperSize.width;
|
27429
|
+
height = paperSize.height;
|
27430
|
+
}
|
27431
|
+
height = height;
|
27389
27432
|
const docProps = this.docCtx.document.props;
|
27390
27433
|
docProps.width = width;
|
27391
27434
|
docProps.height = height;
|