@hufe921/canvas-editor 0.9.36 → 0.9.37
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 +23 -0
- package/README.md +1 -1
- package/dist/canvas-editor.es.js +78 -1
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +28 -20
- 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 +2 -1
- package/dist/src/editor/core/draw/Draw.d.ts +1 -0
- package/dist/src/editor/core/draw/particle/ImageParticle.d.ts +1 -0
- package/dist/src/editor/core/history/HistoryManager.d.ts +1 -0
- package/dist/src/editor/core/plugin/Plugin.d.ts +7 -0
- package/dist/src/editor/index.d.ts +3 -1
- package/dist/src/editor/interface/Plugin.d.ts +3 -0
- package/dist/src/editor/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,26 @@
|
|
|
1
|
+
## [0.9.37](https://github.com/Hufe921/canvas-editor/compare/v0.9.36...v0.9.37) (2023-07-02)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Chores
|
|
5
|
+
|
|
6
|
+
* add plugin demo ([107c4b8](https://github.com/Hufe921/canvas-editor/commit/107c4b86a8703bd1ab01ab7fc9d3cc8a1078591d))
|
|
7
|
+
* update next features roadmap ([ca28454](https://github.com/Hufe921/canvas-editor/commit/ca284540493b985081c86623b569eeef4bf9dcdc))
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Documentation
|
|
11
|
+
|
|
12
|
+
* add plugin ([d0e1c9b](https://github.com/Hufe921/canvas-editor/commit/d0e1c9b5267e15c0afa94bbd400502735846050b))
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
### Features
|
|
16
|
+
|
|
17
|
+
* add fallback placeholder image ([366374e](https://github.com/Hufe921/canvas-editor/commit/366374eb105a49360f7ddecfdb63420e48254698))
|
|
18
|
+
* add plugin interface ([ad0bb32](https://github.com/Hufe921/canvas-editor/commit/ad0bb32b70cd2a7b8cf2c25a83091e92cc13f53b))
|
|
19
|
+
* add setValue command api #210 ([193bd21](https://github.com/Hufe921/canvas-editor/commit/193bd21f7049a565abddd3ae9be761d95d49fea1)), closes [#210](https://github.com/Hufe921/canvas-editor/issues/210)
|
|
20
|
+
* smooth signature drawing ([c328778](https://github.com/Hufe921/canvas-editor/commit/c3287783abfb27670e3572db8c431f23cc04c6ce))
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
|
|
1
24
|
## [0.9.36](https://github.com/Hufe921/canvas-editor/compare/v0.9.35...v0.9.36) (2023-06-16)
|
|
2
25
|
|
|
3
26
|
|
package/README.md
CHANGED
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.37";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -184,6 +184,13 @@ function cloneProperty(properties, sourceElement, targetElement) {
|
|
|
184
184
|
}
|
|
185
185
|
}
|
|
186
186
|
}
|
|
187
|
+
function convertStringToBase64(input2) {
|
|
188
|
+
const encoder = new TextEncoder();
|
|
189
|
+
const data2 = encoder.encode(input2);
|
|
190
|
+
const charArray = Array.from(data2, (byte) => String.fromCharCode(byte));
|
|
191
|
+
const base64 = window.btoa(charArray.join(""));
|
|
192
|
+
return base64;
|
|
193
|
+
}
|
|
187
194
|
const CURSOR_AGENT_HEIGHT = 12;
|
|
188
195
|
const defaultCursorOption = {
|
|
189
196
|
width: 1,
|
|
@@ -419,6 +426,23 @@ class ImageParticle {
|
|
|
419
426
|
addImageObserver(promise) {
|
|
420
427
|
this.draw.getImageObserver().add(promise);
|
|
421
428
|
}
|
|
429
|
+
getFallbackImage(width, height) {
|
|
430
|
+
const tileSize = 8;
|
|
431
|
+
const x = (width - Math.ceil(width / tileSize) * tileSize) / 2;
|
|
432
|
+
const y = (height - Math.ceil(height / tileSize) * tileSize) / 2;
|
|
433
|
+
const svg = `<svg xmlns="http://www.w3.org/2000/svg" width="${width}" height="${height}" viewBox="0 0 ${width} ${height}">
|
|
434
|
+
<rect width="${width}" height="${height}" fill="url(#mosaic)" />
|
|
435
|
+
<defs>
|
|
436
|
+
<pattern id="mosaic" x="${x}" y="${y}" width="${tileSize * 2}" height="${tileSize * 2}" patternUnits="userSpaceOnUse">
|
|
437
|
+
<rect width="${tileSize}" height="${tileSize}" fill="#cccccc" />
|
|
438
|
+
<rect width="${tileSize}" height="${tileSize}" fill="#cccccc" transform="translate(${tileSize}, ${tileSize})" />
|
|
439
|
+
</pattern>
|
|
440
|
+
</defs>
|
|
441
|
+
</svg>`;
|
|
442
|
+
const fallbackImage = new Image();
|
|
443
|
+
fallbackImage.src = `data:image/svg+xml;base64,${convertStringToBase64(svg)}`;
|
|
444
|
+
return fallbackImage;
|
|
445
|
+
}
|
|
422
446
|
render(ctx, element, x, y) {
|
|
423
447
|
const { scale } = this.options;
|
|
424
448
|
const width = element.width * scale;
|
|
@@ -437,6 +461,11 @@ class ImageParticle {
|
|
|
437
461
|
resolve(element);
|
|
438
462
|
};
|
|
439
463
|
img.onerror = (error) => {
|
|
464
|
+
const fallbackImage = this.getFallbackImage(width, height);
|
|
465
|
+
fallbackImage.onload = () => {
|
|
466
|
+
ctx.drawImage(fallbackImage, x, y, width, height);
|
|
467
|
+
this.imageCache.set(element.id, fallbackImage);
|
|
468
|
+
};
|
|
440
469
|
reject(error);
|
|
441
470
|
};
|
|
442
471
|
});
|
|
@@ -5887,6 +5916,10 @@ class HistoryManager {
|
|
|
5887
5916
|
isCanRedo() {
|
|
5888
5917
|
return !!this.redoStack.length;
|
|
5889
5918
|
}
|
|
5919
|
+
recovery() {
|
|
5920
|
+
this.undoStack = [];
|
|
5921
|
+
this.redoStack = [];
|
|
5922
|
+
}
|
|
5890
5923
|
}
|
|
5891
5924
|
var EditorComponent;
|
|
5892
5925
|
(function(EditorComponent2) {
|
|
@@ -10930,6 +10963,33 @@ class Draw {
|
|
|
10930
10963
|
data: data2
|
|
10931
10964
|
};
|
|
10932
10965
|
}
|
|
10966
|
+
setValue(payload) {
|
|
10967
|
+
const { header, main, footer } = payload;
|
|
10968
|
+
if (!header && !main && !footer)
|
|
10969
|
+
return;
|
|
10970
|
+
if (header) {
|
|
10971
|
+
formatElementList(header, {
|
|
10972
|
+
editorOptions: this.options
|
|
10973
|
+
});
|
|
10974
|
+
this.header.setElementList(header);
|
|
10975
|
+
}
|
|
10976
|
+
if (main) {
|
|
10977
|
+
formatElementList(main, {
|
|
10978
|
+
editorOptions: this.options
|
|
10979
|
+
});
|
|
10980
|
+
this.elementList = main;
|
|
10981
|
+
}
|
|
10982
|
+
if (footer) {
|
|
10983
|
+
formatElementList(footer, {
|
|
10984
|
+
editorOptions: this.options
|
|
10985
|
+
});
|
|
10986
|
+
this.footer.setElementList(footer);
|
|
10987
|
+
}
|
|
10988
|
+
this.historyManager.recovery();
|
|
10989
|
+
this.render({
|
|
10990
|
+
isSetCursor: false
|
|
10991
|
+
});
|
|
10992
|
+
}
|
|
10933
10993
|
_wrapContainer(rootContainer) {
|
|
10934
10994
|
const container = document.createElement("div");
|
|
10935
10995
|
rootContainer.append(container);
|
|
@@ -11692,6 +11752,7 @@ class Command {
|
|
|
11692
11752
|
__publicField(this, "executePaperDirection");
|
|
11693
11753
|
__publicField(this, "executeSetPaperMargin");
|
|
11694
11754
|
__publicField(this, "executeInsertElementList");
|
|
11755
|
+
__publicField(this, "executeSetValue");
|
|
11695
11756
|
__publicField(this, "executeRemoveControl");
|
|
11696
11757
|
__publicField(this, "executeSetLocale");
|
|
11697
11758
|
__publicField(this, "executeLocationCatalog");
|
|
@@ -11769,6 +11830,7 @@ class Command {
|
|
|
11769
11830
|
this.executePaperDirection = adapt.paperDirection.bind(adapt);
|
|
11770
11831
|
this.executeSetPaperMargin = adapt.setPaperMargin.bind(adapt);
|
|
11771
11832
|
this.executeInsertElementList = adapt.insertElementList.bind(adapt);
|
|
11833
|
+
this.executeSetValue = adapt.setValue.bind(adapt);
|
|
11772
11834
|
this.executeRemoveControl = adapt.removeControl.bind(adapt);
|
|
11773
11835
|
this.executeSetLocale = adapt.setLocale.bind(adapt);
|
|
11774
11836
|
this.executeLocationCatalog = adapt.locationCatalog.bind(adapt);
|
|
@@ -13381,6 +13443,9 @@ class CommandAdapt {
|
|
|
13381
13443
|
formatElementContext(elementList, payload, startIndex);
|
|
13382
13444
|
this.draw.insertElementList(payload);
|
|
13383
13445
|
}
|
|
13446
|
+
setValue(payload) {
|
|
13447
|
+
this.draw.setValue(payload);
|
|
13448
|
+
}
|
|
13384
13449
|
removeControl() {
|
|
13385
13450
|
const { startIndex, endIndex } = this.range.getRange();
|
|
13386
13451
|
if (startIndex !== endIndex)
|
|
@@ -14274,12 +14339,22 @@ const defaultPlaceholderOption = {
|
|
|
14274
14339
|
size: 16,
|
|
14275
14340
|
font: "Yahei"
|
|
14276
14341
|
};
|
|
14342
|
+
class Plugin {
|
|
14343
|
+
constructor(editor) {
|
|
14344
|
+
__publicField(this, "editor");
|
|
14345
|
+
this.editor = editor;
|
|
14346
|
+
}
|
|
14347
|
+
use(pluginFunction, options) {
|
|
14348
|
+
pluginFunction(this.editor, options);
|
|
14349
|
+
}
|
|
14350
|
+
}
|
|
14277
14351
|
class Editor {
|
|
14278
14352
|
constructor(container, data2, options = {}) {
|
|
14279
14353
|
__publicField(this, "command");
|
|
14280
14354
|
__publicField(this, "listener");
|
|
14281
14355
|
__publicField(this, "register");
|
|
14282
14356
|
__publicField(this, "destroy");
|
|
14357
|
+
__publicField(this, "use");
|
|
14283
14358
|
const headerOptions = __spreadValues(__spreadValues({}, defaultHeaderOption), options.header);
|
|
14284
14359
|
const footerOptions = __spreadValues(__spreadValues({}, defaultFooterOption), options.footer);
|
|
14285
14360
|
const pageNumberOptions = __spreadValues(__spreadValues({}, defaultPageNumberOption), options.pageNumber);
|
|
@@ -14369,6 +14444,8 @@ class Editor {
|
|
|
14369
14444
|
shortcut.removeEvent();
|
|
14370
14445
|
contextMenu.removeEvent();
|
|
14371
14446
|
};
|
|
14447
|
+
const plugin = new Plugin(this);
|
|
14448
|
+
this.use = plugin.use.bind(plugin);
|
|
14372
14449
|
}
|
|
14373
14450
|
}
|
|
14374
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 };
|