@hufe921/canvas-editor 0.9.129 → 0.9.130
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 +17 -0
- package/dist/canvas-editor.es.js +70 -5
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +31 -31
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/draw/particle/block/BlockParticle.d.ts +1 -0
- package/dist/src/editor/interface/Draw.d.ts +1 -0
- package/dist/src/editor/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,20 @@
|
|
|
1
|
+
## [0.9.130](https://github.com/Hufe921/canvas-editor/compare/v0.9.129...v0.9.130) (2026-03-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* correct duplicate variable check in TextParticle render ([4b72161](https://github.com/Hufe921/canvas-editor/commit/4b721618d10ef484e92b79f52ea27ee4be316814))
|
|
7
|
+
* ensure trailing line break in element list formatting #1378 ([30074b6](https://github.com/Hufe921/canvas-editor/commit/30074b6b703b3da581c5446a75edb38f4bff56b7)), closes [#1378](https://github.com/Hufe921/canvas-editor/issues/1378)
|
|
8
|
+
* optimize cursor positioning for left/right key handlers #1378 ([a79928f](https://github.com/Hufe921/canvas-editor/commit/a79928fc507cac0302e105110bc31f2baeefb74c)), closes [#1378](https://github.com/Hufe921/canvas-editor/issues/1378)
|
|
9
|
+
* prevent extra line break when list is first element in table #1381 ([bae2394](https://github.com/Hufe921/canvas-editor/commit/bae2394ceffee5e1a5b8f55d5ef8d60f7edc44b9)), closes [#1381](https://github.com/Hufe921/canvas-editor/issues/1381)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Features
|
|
13
|
+
|
|
14
|
+
* support iframe snapshot in getImage api #1380 ([d980298](https://github.com/Hufe921/canvas-editor/commit/d9802988587333b8b624112f554d2b4e9d702e00)), closes [#1380](https://github.com/Hufe921/canvas-editor/issues/1380)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
|
|
1
18
|
## [0.9.129](https://github.com/Hufe921/canvas-editor/compare/v0.9.128...v0.9.129) (2026-03-13)
|
|
2
19
|
|
|
3
20
|
|
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.130";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -414,6 +414,14 @@ function isRectIntersect(rect1, rect2) {
|
|
|
414
414
|
function isNonValue(value) {
|
|
415
415
|
return value === void 0 || value === null;
|
|
416
416
|
}
|
|
417
|
+
function loadImage(src) {
|
|
418
|
+
return new Promise((resolve, reject) => {
|
|
419
|
+
const img = new Image();
|
|
420
|
+
img.onload = () => resolve(img);
|
|
421
|
+
img.onerror = reject;
|
|
422
|
+
img.src = src;
|
|
423
|
+
});
|
|
424
|
+
}
|
|
417
425
|
function normalizeLineBreak(text) {
|
|
418
426
|
return text.replace(/\r\n|\r/g, "\n");
|
|
419
427
|
}
|
|
@@ -4443,7 +4451,7 @@ function formatElementList(elementList, options) {
|
|
|
4443
4451
|
var _a, _b;
|
|
4444
4452
|
const { isHandleFirstElement = true, isForceCompensation = false, editorOptions } = options;
|
|
4445
4453
|
const startElement = elementList[0];
|
|
4446
|
-
if (
|
|
4454
|
+
if ((startElement == null ? void 0 : startElement.type) !== ElementType.LIST && (isForceCompensation || isHandleFirstElement && ((startElement == null ? void 0 : startElement.type) && startElement.type !== ElementType.TEXT || !START_LINE_BREAK_REG.test(startElement == null ? void 0 : startElement.value)))) {
|
|
4447
4455
|
elementList.unshift({
|
|
4448
4456
|
value: ZERO
|
|
4449
4457
|
});
|
|
@@ -4498,6 +4506,12 @@ function formatElementList(elementList, options) {
|
|
|
4498
4506
|
elementList.splice(i, 0, value);
|
|
4499
4507
|
i++;
|
|
4500
4508
|
}
|
|
4509
|
+
if (elementList[i] && !START_LINE_BREAK_REG.test(elementList[i].value)) {
|
|
4510
|
+
elementList.splice(i, 0, {
|
|
4511
|
+
value: ZERO
|
|
4512
|
+
});
|
|
4513
|
+
i++;
|
|
4514
|
+
}
|
|
4501
4515
|
}
|
|
4502
4516
|
i--;
|
|
4503
4517
|
} else if (el.type === ElementType.AREA) {
|
|
@@ -7533,6 +7547,20 @@ function left(evt, host) {
|
|
|
7533
7547
|
isSubmitHistory: false,
|
|
7534
7548
|
isCompute: false
|
|
7535
7549
|
});
|
|
7550
|
+
if (isAnchorCollapsed) {
|
|
7551
|
+
const positionList = position.getPositionList();
|
|
7552
|
+
const anchorPosition = positionList[anchorStartIndex];
|
|
7553
|
+
if ((anchorPosition == null ? void 0 : anchorPosition.isLastLetter) && anchorPosition.value !== ZERO && anchorStartIndex + 1 < positionList.length) {
|
|
7554
|
+
const nextPosition = positionList[anchorStartIndex + 1];
|
|
7555
|
+
const element = newElementList[anchorStartIndex];
|
|
7556
|
+
const nextElement = newElementList[anchorStartIndex + 1];
|
|
7557
|
+
if (nextPosition.value !== ZERO && !getIsBlockElement(nextElement) && element.listId === nextElement.listId) {
|
|
7558
|
+
draw.getCursor().drawCursor({
|
|
7559
|
+
hitLineStartIndex: anchorStartIndex + 1
|
|
7560
|
+
});
|
|
7561
|
+
}
|
|
7562
|
+
}
|
|
7563
|
+
}
|
|
7536
7564
|
evt.preventDefault();
|
|
7537
7565
|
}
|
|
7538
7566
|
function right(evt, host) {
|
|
@@ -7677,6 +7705,19 @@ function right(evt, host) {
|
|
|
7677
7705
|
isSubmitHistory: false,
|
|
7678
7706
|
isCompute: false
|
|
7679
7707
|
});
|
|
7708
|
+
if (isAnchorCollapsed) {
|
|
7709
|
+
const anchorPosition = positionList[anchorStartIndex];
|
|
7710
|
+
if ((anchorPosition == null ? void 0 : anchorPosition.isLastLetter) && anchorPosition.value !== ZERO && anchorStartIndex + 1 < positionList.length) {
|
|
7711
|
+
const nextPosition = positionList[anchorStartIndex + 1];
|
|
7712
|
+
const element = elementList[anchorStartIndex];
|
|
7713
|
+
const nextElement = elementList[anchorStartIndex + 1];
|
|
7714
|
+
if (nextPosition.value !== ZERO && !getIsBlockElement(nextElement) && element.listId === nextElement.listId) {
|
|
7715
|
+
draw.getCursor().drawCursor({
|
|
7716
|
+
hitLineStartIndex: anchorStartIndex + 1
|
|
7717
|
+
});
|
|
7718
|
+
}
|
|
7719
|
+
}
|
|
7720
|
+
}
|
|
7680
7721
|
evt.preventDefault();
|
|
7681
7722
|
}
|
|
7682
7723
|
function tab(evt, host) {
|
|
@@ -10973,7 +11014,7 @@ class TextParticle {
|
|
|
10973
11014
|
this.curY = y;
|
|
10974
11015
|
}
|
|
10975
11016
|
_render() {
|
|
10976
|
-
if (!this.text || !~this.curX || !~this.
|
|
11017
|
+
if (!this.text || !~this.curX || !~this.curY)
|
|
10977
11018
|
return;
|
|
10978
11019
|
this.ctx.save();
|
|
10979
11020
|
this.ctx.font = this.curStyle;
|
|
@@ -16574,7 +16615,6 @@ class BaseBlock {
|
|
|
16574
16615
|
}
|
|
16575
16616
|
} else if (block.type === BlockType.IFRAME) {
|
|
16576
16617
|
this.setClientRects(pageNo, x, y);
|
|
16577
|
-
this.positionInfo = { pageNo, x, y };
|
|
16578
16618
|
}
|
|
16579
16619
|
}
|
|
16580
16620
|
render() {
|
|
@@ -16597,6 +16637,7 @@ class BaseBlock {
|
|
|
16597
16637
|
this.blockItem.style.height = `${metrics.height}px`;
|
|
16598
16638
|
this.blockItem.style.left = `${x}px`;
|
|
16599
16639
|
this.blockItem.style.top = `${preY + y}px`;
|
|
16640
|
+
this.positionInfo = { pageNo, x, y };
|
|
16600
16641
|
}
|
|
16601
16642
|
setStatus() {
|
|
16602
16643
|
if (this.block instanceof IFrameBlock) {
|
|
@@ -16678,6 +16719,27 @@ class BlockParticle {
|
|
|
16678
16719
|
}
|
|
16679
16720
|
});
|
|
16680
16721
|
}
|
|
16722
|
+
async drawIframeToPage(pageList, snapDomFunction) {
|
|
16723
|
+
const tasks = [];
|
|
16724
|
+
this.blockMap.forEach((cacheBlock) => {
|
|
16725
|
+
var _a, _b, _c;
|
|
16726
|
+
if (((_a = cacheBlock.getBlockElement().block) == null ? void 0 : _a.type) !== BlockType.IFRAME)
|
|
16727
|
+
return;
|
|
16728
|
+
const positionInfo = cacheBlock.getPositionInfo();
|
|
16729
|
+
if (!positionInfo)
|
|
16730
|
+
return;
|
|
16731
|
+
const iframe = (_b = cacheBlock.getIFrameBlock()) == null ? void 0 : _b.getIframe();
|
|
16732
|
+
if (!iframe)
|
|
16733
|
+
return;
|
|
16734
|
+
const { pageNo, x, y } = positionInfo;
|
|
16735
|
+
const ctx = (_c = pageList[pageNo]) == null ? void 0 : _c.getContext("2d");
|
|
16736
|
+
if (!ctx)
|
|
16737
|
+
return;
|
|
16738
|
+
const { width, height } = cacheBlock.getBlockElement().metrics;
|
|
16739
|
+
tasks.push(snapDomFunction(iframe).then((base64) => loadImage(base64)).then((img) => ctx.drawImage(img, x, y, width, height)));
|
|
16740
|
+
});
|
|
16741
|
+
await Promise.allSettled(tasks);
|
|
16742
|
+
}
|
|
16681
16743
|
pickIframeInfo() {
|
|
16682
16744
|
const result = [];
|
|
16683
16745
|
const { scale } = this.options;
|
|
@@ -19874,7 +19936,7 @@ class Draw {
|
|
|
19874
19936
|
return this.getRowList().length;
|
|
19875
19937
|
}
|
|
19876
19938
|
async getDataURL(payload = {}) {
|
|
19877
|
-
const { pixelRatio, mode } = payload;
|
|
19939
|
+
const { pixelRatio, mode, snapDomFunction } = payload;
|
|
19878
19940
|
if (pixelRatio) {
|
|
19879
19941
|
this.setPagePixelRatio(pixelRatio);
|
|
19880
19942
|
}
|
|
@@ -19890,6 +19952,9 @@ class Draw {
|
|
|
19890
19952
|
isSubmitHistory: false
|
|
19891
19953
|
});
|
|
19892
19954
|
await this.imageObserver.allSettled();
|
|
19955
|
+
if (snapDomFunction) {
|
|
19956
|
+
await this.blockParticle.drawIframeToPage(this.pageList, snapDomFunction);
|
|
19957
|
+
}
|
|
19893
19958
|
const dataUrlList = this.pageList.map((c) => c.toDataURL());
|
|
19894
19959
|
if (pixelRatio) {
|
|
19895
19960
|
this.setPagePixelRatio(null);
|