@hufe921/canvas-editor 0.9.37 → 0.9.38
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/CHANGELOG.md +22 -0
- package/README.md +7 -7
- package/dist/canvas-editor.es.js +81 -9
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +22 -22
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/command/Command.d.ts +1 -0
- package/dist/src/editor/core/command/CommandAdapt.d.ts +4 -3
- package/dist/src/editor/core/draw/Draw.d.ts +5 -4
- package/dist/src/editor/core/draw/particle/TextParticle.d.ts +5 -0
- package/dist/src/editor/dataset/constant/Regular.d.ts +1 -0
- package/dist/src/editor/dataset/enum/Editor.d.ts +4 -0
- package/dist/src/editor/index.d.ts +2 -2
- package/dist/src/editor/interface/Draw.d.ts +7 -1
- package/dist/src/editor/interface/Editor.d.ts +2 -1
- package/package.json +1 -4
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [0.9.38](https://github.com/Hufe921/canvas-editor/compare/v0.9.37...v0.9.38) (2023-07-12)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* limit word break element type #212 ([d7424f8](https://github.com/Hufe921/canvas-editor/commit/d7424f8b8798cc889df3b54748523c1367af2776)), closes [#212](https://github.com/Hufe921/canvas-editor/issues/212)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
### Chores
|
|
10
|
+
|
|
11
|
+
* add plugin tip ([8c6eee1](https://github.com/Hufe921/canvas-editor/commit/8c6eee1a57f5130919d1bdfa6a1067615f3a95e3))
|
|
12
|
+
* update README.md ([ccb1aa7](https://github.com/Hufe921/canvas-editor/commit/ccb1aa70abacd9398f9ff0e5b066ad51cfc27274))
|
|
13
|
+
* update release script ([4d1ad65](https://github.com/Hufe921/canvas-editor/commit/4d1ad650746ff2c4aa58dde2b725704ab9e7a639))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add word break option #212 ([d471165](https://github.com/Hufe921/canvas-editor/commit/d471165430e27e5322160e22da5a5f53fc969b0f)), closes [#212](https://github.com/Hufe921/canvas-editor/issues/212)
|
|
19
|
+
* get page value and append element api #211 ([85a9dcb](https://github.com/Hufe921/canvas-editor/commit/85a9dcbcf29a2fc0e1f89293c4f3ecbc976868b7)), closes [#211](https://github.com/Hufe921/canvas-editor/issues/211)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
1
23
|
## [0.9.37](https://github.com/Hufe921/canvas-editor/compare/v0.9.36...v0.9.37) (2023-07-02)
|
|
2
24
|
|
|
3
25
|
|
package/README.md
CHANGED
|
@@ -5,8 +5,9 @@
|
|
|
5
5
|
## tips
|
|
6
6
|
|
|
7
7
|
1. [docs](https://hufe.club/canvas-editor-docs/)
|
|
8
|
-
2.
|
|
9
|
-
3. The
|
|
8
|
+
2. [canvas-editor-plugin](https://github.com/Hufe921/canvas-editor-plugin)
|
|
9
|
+
3. The render layer by svg is under development, see [feature/svg](https://github.com/Hufe921/canvas-editor/tree/feature/svg)
|
|
10
|
+
4. The export pdf feature is available now, see [feature/pdf](https://github.com/Hufe921/canvas-editor/tree/feature/pdf)
|
|
10
11
|
|
|
11
12
|
## usage
|
|
12
13
|
|
|
@@ -28,11 +29,10 @@ new Editor(document.querySelector(".canvas-editor"), [
|
|
|
28
29
|
|
|
29
30
|
## next features
|
|
30
31
|
|
|
31
|
-
1.
|
|
32
|
-
2.
|
|
33
|
-
3.
|
|
34
|
-
4.
|
|
35
|
-
5. [CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT)
|
|
32
|
+
1. improve performance
|
|
33
|
+
2. control rules
|
|
34
|
+
3. table paging
|
|
35
|
+
4. [CRDT](https://github.com/Hufe921/canvas-editor/tree/feature/CRDT)
|
|
36
36
|
|
|
37
37
|
## snapshot
|
|
38
38
|
|
package/dist/canvas-editor.es.js
CHANGED
|
@@ -23,7 +23,7 @@ var __publicField = (obj, key, value) => {
|
|
|
23
23
|
return value;
|
|
24
24
|
};
|
|
25
25
|
var index = "";
|
|
26
|
-
const version = "0.9.
|
|
26
|
+
const version = "0.9.38";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -5464,6 +5464,7 @@ function drop(evt, host) {
|
|
|
5464
5464
|
}
|
|
5465
5465
|
const LETTER_REG = /[a-zA-Z]/;
|
|
5466
5466
|
const NUMBER_LIKE_REG = /[0-9.]/;
|
|
5467
|
+
const WORD_LIKE_REG = /[^a-zA-Z][a-zA-Z]/;
|
|
5467
5468
|
function dblclick(host, evt) {
|
|
5468
5469
|
const draw = host.getDraw();
|
|
5469
5470
|
const position = draw.getPosition();
|
|
@@ -5958,6 +5959,11 @@ var PaperDirection;
|
|
|
5958
5959
|
PaperDirection2["VERTICAL"] = "vertical";
|
|
5959
5960
|
PaperDirection2["HORIZONTAL"] = "horizontal";
|
|
5960
5961
|
})(PaperDirection || (PaperDirection = {}));
|
|
5962
|
+
var WordBreak;
|
|
5963
|
+
(function(WordBreak2) {
|
|
5964
|
+
WordBreak2["BREAK_ALL"] = "break-all";
|
|
5965
|
+
WordBreak2["BREAK_WORD"] = "break-word";
|
|
5966
|
+
})(WordBreak || (WordBreak = {}));
|
|
5961
5967
|
class Position {
|
|
5962
5968
|
constructor(draw) {
|
|
5963
5969
|
__publicField(this, "cursorPosition");
|
|
@@ -7065,6 +7071,24 @@ class TextParticle {
|
|
|
7065
7071
|
this.curStyle = "";
|
|
7066
7072
|
this.cacheMeasureText = new Map();
|
|
7067
7073
|
}
|
|
7074
|
+
measureWord(ctx, elementList, curIndex) {
|
|
7075
|
+
let width = 0;
|
|
7076
|
+
let endElement = elementList[curIndex];
|
|
7077
|
+
let i = curIndex;
|
|
7078
|
+
while (i < elementList.length) {
|
|
7079
|
+
const element = elementList[i];
|
|
7080
|
+
if (!LETTER_REG.test(element.value)) {
|
|
7081
|
+
endElement = element;
|
|
7082
|
+
break;
|
|
7083
|
+
}
|
|
7084
|
+
width += this.measureText(ctx, element).width;
|
|
7085
|
+
i++;
|
|
7086
|
+
}
|
|
7087
|
+
return {
|
|
7088
|
+
width,
|
|
7089
|
+
endElement
|
|
7090
|
+
};
|
|
7091
|
+
}
|
|
7068
7092
|
measurePunctuationWidth(ctx, element) {
|
|
7069
7093
|
if (!element || !PUNCTUATION_LIST.includes(element.value))
|
|
7070
7094
|
return 0;
|
|
@@ -10733,6 +10757,27 @@ class Draw {
|
|
|
10733
10757
|
});
|
|
10734
10758
|
}
|
|
10735
10759
|
}
|
|
10760
|
+
appendElementList(elementList, options = {}) {
|
|
10761
|
+
if (!elementList.length)
|
|
10762
|
+
return;
|
|
10763
|
+
formatElementList(elementList, {
|
|
10764
|
+
isHandleFirstElement: false,
|
|
10765
|
+
editorOptions: this.options
|
|
10766
|
+
});
|
|
10767
|
+
let curIndex;
|
|
10768
|
+
const { isPrepend } = options;
|
|
10769
|
+
if (isPrepend) {
|
|
10770
|
+
this.elementList.splice(1, 0, ...elementList);
|
|
10771
|
+
curIndex = elementList.length;
|
|
10772
|
+
} else {
|
|
10773
|
+
this.elementList.push(...elementList);
|
|
10774
|
+
curIndex = this.elementList.length - 1;
|
|
10775
|
+
}
|
|
10776
|
+
this.range.setRange(curIndex, curIndex);
|
|
10777
|
+
this.render({
|
|
10778
|
+
curIndex
|
|
10779
|
+
});
|
|
10780
|
+
}
|
|
10736
10781
|
spliceElementList(elementList, start, deleteCount, ...items) {
|
|
10737
10782
|
var _a;
|
|
10738
10783
|
if (deleteCount > 0) {
|
|
@@ -10947,11 +10992,16 @@ class Draw {
|
|
|
10947
10992
|
isSetCursor: false
|
|
10948
10993
|
});
|
|
10949
10994
|
}
|
|
10950
|
-
getValue() {
|
|
10995
|
+
getValue(options = {}) {
|
|
10951
10996
|
const { width, height, margins, watermark } = this.options;
|
|
10997
|
+
const { pageNo } = options;
|
|
10998
|
+
let mainElementList = this.elementList;
|
|
10999
|
+
if (Number.isInteger(pageNo) && pageNo >= 0 && pageNo < this.pageRowList.length) {
|
|
11000
|
+
mainElementList = this.pageRowList[pageNo].flatMap((row) => row.elementList);
|
|
11001
|
+
}
|
|
10952
11002
|
const data2 = {
|
|
10953
11003
|
header: zipElementList(this.headerElementList),
|
|
10954
|
-
main: zipElementList(
|
|
11004
|
+
main: zipElementList(mainElementList),
|
|
10955
11005
|
footer: zipElementList(this.footerElementList)
|
|
10956
11006
|
};
|
|
10957
11007
|
return {
|
|
@@ -11265,8 +11315,19 @@ class Draw {
|
|
|
11265
11315
|
style: this._getFont(element, scale)
|
|
11266
11316
|
});
|
|
11267
11317
|
const preElement = elementList[i - 1];
|
|
11268
|
-
|
|
11269
|
-
|
|
11318
|
+
let nextElement = elementList[i + 1];
|
|
11319
|
+
let curRowWidth = curRow.width + metrics.width;
|
|
11320
|
+
if (this.options.wordBreak === WordBreak.BREAK_WORD) {
|
|
11321
|
+
if ((!(preElement == null ? void 0 : preElement.type) || (preElement == null ? void 0 : preElement.type) === ElementType.TEXT) && (!element.type || element.type === ElementType.TEXT)) {
|
|
11322
|
+
const word = `${(preElement == null ? void 0 : preElement.value) || ""}${element.value}`;
|
|
11323
|
+
if (WORD_LIKE_REG.test(word)) {
|
|
11324
|
+
const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i);
|
|
11325
|
+
curRowWidth += width;
|
|
11326
|
+
nextElement = endElement;
|
|
11327
|
+
}
|
|
11328
|
+
curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement);
|
|
11329
|
+
}
|
|
11330
|
+
}
|
|
11270
11331
|
if (element.listId) {
|
|
11271
11332
|
if (element.listId !== listId) {
|
|
11272
11333
|
listIndex = 0;
|
|
@@ -11752,6 +11813,7 @@ class Command {
|
|
|
11752
11813
|
__publicField(this, "executePaperDirection");
|
|
11753
11814
|
__publicField(this, "executeSetPaperMargin");
|
|
11754
11815
|
__publicField(this, "executeInsertElementList");
|
|
11816
|
+
__publicField(this, "executeAppendElementList");
|
|
11755
11817
|
__publicField(this, "executeSetValue");
|
|
11756
11818
|
__publicField(this, "executeRemoveControl");
|
|
11757
11819
|
__publicField(this, "executeSetLocale");
|
|
@@ -11830,6 +11892,7 @@ class Command {
|
|
|
11830
11892
|
this.executePaperDirection = adapt.paperDirection.bind(adapt);
|
|
11831
11893
|
this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt);
|
|
11832
11894
|
this.executeInsertElementList = adapt.insertElementList.bind(adapt);
|
|
11895
|
+
this.executeAppendElementList = adapt.appendElementList.bind(adapt);
|
|
11833
11896
|
this.executeSetValue = adapt.setValue.bind(adapt);
|
|
11834
11897
|
this.executeRemoveControl = adapt.removeControl.bind(adapt);
|
|
11835
11898
|
this.executeSetLocale = adapt.setLocale.bind(adapt);
|
|
@@ -13388,8 +13451,8 @@ class CommandAdapt {
|
|
|
13388
13451
|
getImage() {
|
|
13389
13452
|
return this.draw.getDataURL();
|
|
13390
13453
|
}
|
|
13391
|
-
getValue() {
|
|
13392
|
-
return this.draw.getValue();
|
|
13454
|
+
getValue(options) {
|
|
13455
|
+
return this.draw.getValue(options);
|
|
13393
13456
|
}
|
|
13394
13457
|
getWordCount() {
|
|
13395
13458
|
return this.workerManager.getWordCount();
|
|
@@ -13443,6 +13506,14 @@ class CommandAdapt {
|
|
|
13443
13506
|
formatElementContext(elementList, payload, startIndex);
|
|
13444
13507
|
this.draw.insertElementList(payload);
|
|
13445
13508
|
}
|
|
13509
|
+
appendElementList(elementList, options) {
|
|
13510
|
+
if (!elementList.length)
|
|
13511
|
+
return;
|
|
13512
|
+
const isReadonly = this.draw.isReadonly();
|
|
13513
|
+
if (isReadonly)
|
|
13514
|
+
return;
|
|
13515
|
+
this.draw.appendElementList(elementList, options);
|
|
13516
|
+
}
|
|
13446
13517
|
setValue(payload) {
|
|
13447
13518
|
this.draw.setValue(payload);
|
|
13448
13519
|
}
|
|
@@ -14398,7 +14469,8 @@ class Editor {
|
|
|
14398
14469
|
defaultHyperlinkColor: "#0000FF",
|
|
14399
14470
|
paperDirection: PaperDirection.VERTICAL,
|
|
14400
14471
|
inactiveAlpha: 0.6,
|
|
14401
|
-
historyMaxRecordCount: 100
|
|
14472
|
+
historyMaxRecordCount: 100,
|
|
14473
|
+
wordBreak: WordBreak.BREAK_WORD
|
|
14402
14474
|
}, options), {
|
|
14403
14475
|
header: headerOptions,
|
|
14404
14476
|
footer: footerOptions,
|
|
@@ -14448,5 +14520,5 @@ class Editor {
|
|
|
14448
14520
|
this.use = plugin.use.bind(plugin);
|
|
14449
14521
|
}
|
|
14450
14522
|
}
|
|
14451
|
-
export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, ImageDisplay, KeyMap, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TitleLevel, VerticalAlign, Editor as default };
|
|
14523
|
+
export { BlockType, Command, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, ImageDisplay, KeyMap, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TitleLevel, VerticalAlign, WordBreak, Editor as default };
|
|
14452
14524
|
//# sourceMappingURL=canvas-editor.es.js.map
|