@hufe921/canvas-editor 0.9.74 → 0.9.75
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/dist/canvas-editor.es.js +85 -21
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +27 -27
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/draw/Draw.d.ts +3 -0
- package/dist/src/editor/core/draw/particle/LineBreakParticle.d.ts +10 -0
- package/dist/src/editor/dataset/constant/LineBreak.d.ts +2 -0
- package/dist/src/editor/interface/Draw.d.ts +1 -0
- package/dist/src/editor/interface/Editor.d.ts +2 -0
- package/dist/src/editor/interface/LineBreak.d.ts +5 -0
- package/dist/src/editor/interface/Row.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [0.9.75](https://github.com/Hufe921/canvas-editor/compare/v0.9.74...v0.9.75) (2024-04-27)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* control element rendering boundary error in table #527 ([f41cea2](https://github.com/Hufe921/canvas-editor/commit/f41cea244309e98ca880c74aaa4e0f3a2811ad66)), closes [#527](https://github.com/Hufe921/canvas-editor/issues/527)
|
|
7
|
+
* list position error when setting row flex #523 ([3fdd4de](https://github.com/Hufe921/canvas-editor/commit/3fdd4dedf434a45ded0c7114cf1cd0c8a1e94a18)), closes [#523](https://github.com/Hufe921/canvas-editor/issues/523)
|
|
8
|
+
* search for duplicate keyword boundary error #528 ([d4c6cd2](https://github.com/Hufe921/canvas-editor/commit/d4c6cd25f639ea5d933e2c4a2d006c96e3138219)), closes [#528](https://github.com/Hufe921/canvas-editor/issues/528)
|
|
9
|
+
* word break boundary error #521 ([4d1a0b6](https://github.com/Hufe921/canvas-editor/commit/4d1a0b69f876eada2d0c5d866bd25464d2587a79)), closes [#521](https://github.com/Hufe921/canvas-editor/issues/521)
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
### Chores
|
|
13
|
+
|
|
14
|
+
* add editor option settings in the demo ([07956ca](https://github.com/Hufe921/canvas-editor/commit/07956caec20eea75c994e968429028ebcfb174f4))
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
### Features
|
|
18
|
+
|
|
19
|
+
* draw line break marker #520 ([4c2b8fc](https://github.com/Hufe921/canvas-editor/commit/4c2b8fc20af98533796d5c4fec0d8d0c3d876116)), closes [#520](https://github.com/Hufe921/canvas-editor/issues/520)
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
1
23
|
## [0.9.74](https://github.com/Hufe921/canvas-editor/compare/v0.9.73...v0.9.74) (2024-04-19)
|
|
2
24
|
|
|
3
25
|
|
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.75";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -3866,6 +3866,7 @@ function formatElementList(elementList, options) {
|
|
|
3866
3866
|
const { editorOptions: { control: controlOption, checkbox: checkboxOption } } = options;
|
|
3867
3867
|
const controlId = getUUID();
|
|
3868
3868
|
elementList.splice(i, 1);
|
|
3869
|
+
const controlContext = pickObject(el, EDITOR_ELEMENT_CONTEXT_ATTR);
|
|
3869
3870
|
const controlDefaultStyle = pickObject(el.control, CONTROL_STYLE_ATTR);
|
|
3870
3871
|
const thePrePostfixArg = __spreadProps(__spreadValues({}, controlDefaultStyle), {
|
|
3871
3872
|
color: editorOptions.control.bracketColor
|
|
@@ -3873,7 +3874,7 @@ function formatElementList(elementList, options) {
|
|
|
3873
3874
|
const prefixStrList = splitText(prefix || controlOption.prefix);
|
|
3874
3875
|
for (let p = 0; p < prefixStrList.length; p++) {
|
|
3875
3876
|
const value2 = prefixStrList[p];
|
|
3876
|
-
elementList.splice(i, 0, __spreadProps(__spreadValues({}, thePrePostfixArg), {
|
|
3877
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues({}, controlContext), thePrePostfixArg), {
|
|
3877
3878
|
controlId,
|
|
3878
3879
|
value: value2,
|
|
3879
3880
|
type: el.type,
|
|
@@ -3891,7 +3892,7 @@ function formatElementList(elementList, options) {
|
|
|
3891
3892
|
let valueStyleIndex = 0;
|
|
3892
3893
|
for (let v = 0; v < valueSets.length; v++) {
|
|
3893
3894
|
const valueSet = valueSets[v];
|
|
3894
|
-
elementList.splice(i, 0, {
|
|
3895
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues({}, controlContext), {
|
|
3895
3896
|
controlId,
|
|
3896
3897
|
value: "",
|
|
3897
3898
|
type: el.type,
|
|
@@ -3901,13 +3902,13 @@ function formatElementList(elementList, options) {
|
|
|
3901
3902
|
code: valueSet.code,
|
|
3902
3903
|
value: codeList.includes(valueSet.code)
|
|
3903
3904
|
}
|
|
3904
|
-
});
|
|
3905
|
+
}));
|
|
3905
3906
|
i++;
|
|
3906
3907
|
const valueStrList = splitText(valueSet.value);
|
|
3907
3908
|
for (let e = 0; e < valueStrList.length; e++) {
|
|
3908
3909
|
const value2 = valueStrList[e];
|
|
3909
3910
|
const isLastLetter = e === valueStrList.length - 1;
|
|
3910
|
-
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues({}, controlDefaultStyle), valueStyleList[valueStyleIndex]), {
|
|
3911
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, controlContext), controlDefaultStyle), valueStyleList[valueStyleIndex]), {
|
|
3911
3912
|
controlId,
|
|
3912
3913
|
value: value2 === "\n" ? ZERO : value2,
|
|
3913
3914
|
letterSpacing: isLastLetter ? checkboxOption.gap : 0,
|
|
@@ -3938,7 +3939,7 @@ function formatElementList(elementList, options) {
|
|
|
3938
3939
|
for (let v = 0; v < valueList.length; v++) {
|
|
3939
3940
|
const element = valueList[v];
|
|
3940
3941
|
const value2 = element.value;
|
|
3941
|
-
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues({}, controlDefaultStyle), element), {
|
|
3942
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues(__spreadValues({}, controlContext), controlDefaultStyle), element), {
|
|
3942
3943
|
controlId,
|
|
3943
3944
|
value: value2 === "\n" ? ZERO : value2,
|
|
3944
3945
|
type: element.type || ElementType.TEXT,
|
|
@@ -3955,7 +3956,7 @@ function formatElementList(elementList, options) {
|
|
|
3955
3956
|
const placeholderStrList = splitText(placeholder);
|
|
3956
3957
|
for (let p = 0; p < placeholderStrList.length; p++) {
|
|
3957
3958
|
const value2 = placeholderStrList[p];
|
|
3958
|
-
elementList.splice(i, 0, __spreadProps(__spreadValues({}, thePlaceholderArgs), {
|
|
3959
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues({}, controlContext), thePlaceholderArgs), {
|
|
3959
3960
|
controlId,
|
|
3960
3961
|
value: value2 === "\n" ? ZERO : value2,
|
|
3961
3962
|
type: el.type,
|
|
@@ -3968,7 +3969,7 @@ function formatElementList(elementList, options) {
|
|
|
3968
3969
|
const postfixStrList = splitText(postfix || controlOption.postfix);
|
|
3969
3970
|
for (let p = 0; p < postfixStrList.length; p++) {
|
|
3970
3971
|
const value2 = postfixStrList[p];
|
|
3971
|
-
elementList.splice(i, 0, __spreadProps(__spreadValues({}, thePrePostfixArg), {
|
|
3972
|
+
elementList.splice(i, 0, __spreadProps(__spreadValues(__spreadValues({}, controlContext), thePrePostfixArg), {
|
|
3972
3973
|
controlId,
|
|
3973
3974
|
value: value2,
|
|
3974
3975
|
type: el.type,
|
|
@@ -7329,10 +7330,11 @@ class Position {
|
|
|
7329
7330
|
let index2 = startIndex;
|
|
7330
7331
|
for (let i = 0; i < rowList.length; i++) {
|
|
7331
7332
|
const curRow = rowList[i];
|
|
7333
|
+
const curRowWidth = curRow.width + (curRow.offsetX || 0);
|
|
7332
7334
|
if (curRow.rowFlex === RowFlex.CENTER) {
|
|
7333
|
-
x += (innerWidth -
|
|
7335
|
+
x += (innerWidth - curRowWidth) / 2;
|
|
7334
7336
|
} else if (curRow.rowFlex === RowFlex.RIGHT) {
|
|
7335
|
-
x += innerWidth -
|
|
7337
|
+
x += innerWidth - curRowWidth;
|
|
7336
7338
|
}
|
|
7337
7339
|
x += curRow.offsetX || 0;
|
|
7338
7340
|
const tablePreX = x;
|
|
@@ -8575,7 +8577,7 @@ class Search {
|
|
|
8575
8577
|
let index2 = text.indexOf(payload2);
|
|
8576
8578
|
while (index2 !== -1) {
|
|
8577
8579
|
matchStartIndexList.push(index2);
|
|
8578
|
-
index2 = text.indexOf(payload2, index2 +
|
|
8580
|
+
index2 = text.indexOf(payload2, index2 + payload2.length);
|
|
8579
8581
|
}
|
|
8580
8582
|
for (let m = 0; m < matchStartIndexList.length; m++) {
|
|
8581
8583
|
const startIndex = matchStartIndexList[m];
|
|
@@ -13089,6 +13091,41 @@ class ListParticle {
|
|
|
13089
13091
|
}
|
|
13090
13092
|
}
|
|
13091
13093
|
}
|
|
13094
|
+
const _LineBreakParticle = class {
|
|
13095
|
+
constructor(draw) {
|
|
13096
|
+
__publicField(this, "options");
|
|
13097
|
+
this.options = draw.getOptions();
|
|
13098
|
+
}
|
|
13099
|
+
render(ctx, element, x, y) {
|
|
13100
|
+
const { scale, lineBreak: { color, lineWidth } } = this.options;
|
|
13101
|
+
ctx.save();
|
|
13102
|
+
ctx.beginPath();
|
|
13103
|
+
const top = y - _LineBreakParticle.HEIGHT * scale / 2;
|
|
13104
|
+
const left2 = x + element.metrics.width;
|
|
13105
|
+
ctx.translate(left2, top);
|
|
13106
|
+
ctx.scale(scale, scale);
|
|
13107
|
+
ctx.strokeStyle = color;
|
|
13108
|
+
ctx.lineWidth = lineWidth;
|
|
13109
|
+
ctx.lineCap = "round";
|
|
13110
|
+
ctx.lineJoin = "round";
|
|
13111
|
+
ctx.beginPath();
|
|
13112
|
+
ctx.moveTo(8, 0);
|
|
13113
|
+
ctx.lineTo(12, 0);
|
|
13114
|
+
ctx.lineTo(12, 6);
|
|
13115
|
+
ctx.lineTo(3, 6);
|
|
13116
|
+
ctx.moveTo(3, 6);
|
|
13117
|
+
ctx.lineTo(6, 3);
|
|
13118
|
+
ctx.moveTo(3, 6);
|
|
13119
|
+
ctx.lineTo(6, 9);
|
|
13120
|
+
ctx.stroke();
|
|
13121
|
+
ctx.closePath();
|
|
13122
|
+
ctx.restore();
|
|
13123
|
+
}
|
|
13124
|
+
};
|
|
13125
|
+
let LineBreakParticle = _LineBreakParticle;
|
|
13126
|
+
__publicField(LineBreakParticle, "WIDTH", 12);
|
|
13127
|
+
__publicField(LineBreakParticle, "HEIGHT", 9);
|
|
13128
|
+
__publicField(LineBreakParticle, "GAP", 3);
|
|
13092
13129
|
class Placeholder {
|
|
13093
13130
|
constructor(draw) {
|
|
13094
13131
|
__publicField(this, "draw");
|
|
@@ -13121,10 +13158,14 @@ class Placeholder {
|
|
|
13121
13158
|
});
|
|
13122
13159
|
}
|
|
13123
13160
|
_computePositionList() {
|
|
13161
|
+
const { lineBreak, scale } = this.options;
|
|
13124
13162
|
const headerExtraHeight = this.draw.getHeader().getExtraHeight();
|
|
13125
13163
|
const innerWidth = this.draw.getInnerWidth();
|
|
13126
13164
|
const margins = this.draw.getMargins();
|
|
13127
|
-
|
|
13165
|
+
let startX = margins[3];
|
|
13166
|
+
if (!lineBreak.disabled) {
|
|
13167
|
+
startX += (LineBreakParticle.WIDTH + LineBreakParticle.GAP) * scale;
|
|
13168
|
+
}
|
|
13128
13169
|
const startY = margins[0] + headerExtraHeight;
|
|
13129
13170
|
this.position.computePageRowPosition({
|
|
13130
13171
|
positionList: this.positionList,
|
|
@@ -13163,7 +13204,8 @@ class Placeholder {
|
|
|
13163
13204
|
rowList: this.rowList,
|
|
13164
13205
|
pageNo: 0,
|
|
13165
13206
|
startIndex: 0,
|
|
13166
|
-
innerWidth
|
|
13207
|
+
innerWidth,
|
|
13208
|
+
isDrawLineBreak: false
|
|
13167
13209
|
});
|
|
13168
13210
|
ctx.restore();
|
|
13169
13211
|
}
|
|
@@ -13378,6 +13420,7 @@ class Draw {
|
|
|
13378
13420
|
__publicField(this, "checkboxParticle");
|
|
13379
13421
|
__publicField(this, "blockParticle");
|
|
13380
13422
|
__publicField(this, "listParticle");
|
|
13423
|
+
__publicField(this, "lineBreakParticle");
|
|
13381
13424
|
__publicField(this, "control");
|
|
13382
13425
|
__publicField(this, "workerManager");
|
|
13383
13426
|
__publicField(this, "scrollObserver");
|
|
@@ -13439,6 +13482,7 @@ class Draw {
|
|
|
13439
13482
|
this.checkboxParticle = new CheckboxParticle(this);
|
|
13440
13483
|
this.blockParticle = new BlockParticle(this);
|
|
13441
13484
|
this.listParticle = new ListParticle(this);
|
|
13485
|
+
this.lineBreakParticle = new LineBreakParticle(this);
|
|
13442
13486
|
this.control = new Control(this);
|
|
13443
13487
|
this.scrollObserver = new ScrollObserver(this);
|
|
13444
13488
|
this.selectionObserver = new SelectionObserver(this);
|
|
@@ -13492,6 +13536,7 @@ class Draw {
|
|
|
13492
13536
|
this.setEditorData(this.printModeData);
|
|
13493
13537
|
this.printModeData = null;
|
|
13494
13538
|
}
|
|
13539
|
+
this.range.clearRange();
|
|
13495
13540
|
this.mode = payload;
|
|
13496
13541
|
this.render({
|
|
13497
13542
|
isSetCursor: false,
|
|
@@ -13669,6 +13714,9 @@ class Draw {
|
|
|
13669
13714
|
getRange() {
|
|
13670
13715
|
return this.range;
|
|
13671
13716
|
}
|
|
13717
|
+
getLineBreakParticle() {
|
|
13718
|
+
return this.lineBreakParticle;
|
|
13719
|
+
}
|
|
13672
13720
|
getHeaderElementList() {
|
|
13673
13721
|
return this.header.getElementList();
|
|
13674
13722
|
}
|
|
@@ -14462,8 +14510,10 @@ class Draw {
|
|
|
14462
14510
|
const word = `${(preElement == null ? void 0 : preElement.value) || ""}${element.value}`;
|
|
14463
14511
|
if (this.WORD_LIKE_REG.test(word)) {
|
|
14464
14512
|
const { width, endElement } = this.textParticle.measureWord(ctx, elementList, i);
|
|
14465
|
-
|
|
14466
|
-
|
|
14513
|
+
if (width <= availableWidth) {
|
|
14514
|
+
curRowWidth += width;
|
|
14515
|
+
nextElement = endElement;
|
|
14516
|
+
}
|
|
14467
14517
|
}
|
|
14468
14518
|
curRowWidth += this.textParticle.measurePunctuationWidth(ctx, nextElement);
|
|
14469
14519
|
}
|
|
@@ -14476,7 +14526,10 @@ class Draw {
|
|
|
14476
14526
|
}
|
|
14477
14527
|
}
|
|
14478
14528
|
listId = element.listId;
|
|
14479
|
-
|
|
14529
|
+
const isForceBreak = element.type === ElementType.SEPARATOR || element.type === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.TABLE || (preElement == null ? void 0 : preElement.type) === ElementType.BLOCK || element.type === ElementType.BLOCK || (preElement == null ? void 0 : preElement.imgDisplay) === ImageDisplay.INLINE || element.imgDisplay === ImageDisplay.INLINE || (preElement == null ? void 0 : preElement.listId) !== element.listId || i !== 0 && element.value === ZERO;
|
|
14530
|
+
const isWidthNotEnough = curRowWidth > availableWidth;
|
|
14531
|
+
if (isForceBreak || isWidthNotEnough) {
|
|
14532
|
+
curRow.isWidthNotEnough = isWidthNotEnough && !isForceBreak;
|
|
14480
14533
|
if (curRow.startIndex === 0 && curRow.elementList.length === 1 && INLINE_ELEMENT_TYPE.includes(element.type)) {
|
|
14481
14534
|
curRow.height = defaultBasicRowMarginHeight;
|
|
14482
14535
|
}
|
|
@@ -14588,9 +14641,9 @@ class Draw {
|
|
|
14588
14641
|
drawRow(ctx, payload) {
|
|
14589
14642
|
var _a, _b, _c, _d, _e, _f;
|
|
14590
14643
|
this._drawHighlight(ctx, payload);
|
|
14591
|
-
const {
|
|
14644
|
+
const { scale, tdPadding, group: group2, lineBreak } = this.options;
|
|
14645
|
+
const { rowList, pageNo, elementList, positionList, startIndex, zone: zone2, isDrawLineBreak = !lineBreak.disabled } = payload;
|
|
14592
14646
|
const isPrintMode = this.mode === EditorMode.PRINT;
|
|
14593
|
-
const { scale, tdPadding, group: group2 } = this.options;
|
|
14594
14647
|
const { isCrossRowCol, tableId } = this.range.getRange();
|
|
14595
14648
|
let index2 = startIndex;
|
|
14596
14649
|
for (let i = 0; i < rowList.length; i++) {
|
|
@@ -14668,6 +14721,9 @@ class Draw {
|
|
|
14668
14721
|
this.textParticle.complete();
|
|
14669
14722
|
}
|
|
14670
14723
|
}
|
|
14724
|
+
if (isDrawLineBreak && !curRow.isWidthNotEnough && j === curRow.elementList.length - 1) {
|
|
14725
|
+
this.lineBreakParticle.render(ctx, element, x, y + curRow.height / 2);
|
|
14726
|
+
}
|
|
14671
14727
|
if ((_a = element.control) == null ? void 0 : _a.border) {
|
|
14672
14728
|
if (((_b = preElement == null ? void 0 : preElement.control) == null ? void 0 : _b.border) && preElement.controlId !== element.controlId) {
|
|
14673
14729
|
this.control.drawBorder(ctx);
|
|
@@ -14754,7 +14810,8 @@ class Draw {
|
|
|
14754
14810
|
pageNo,
|
|
14755
14811
|
startIndex: 0,
|
|
14756
14812
|
innerWidth: (td.width - tdPaddingWidth) * scale,
|
|
14757
|
-
zone: zone2
|
|
14813
|
+
zone: zone2,
|
|
14814
|
+
isDrawLineBreak
|
|
14758
14815
|
});
|
|
14759
14816
|
}
|
|
14760
14817
|
}
|
|
@@ -16845,7 +16902,7 @@ class CommandAdapt {
|
|
|
16845
16902
|
if (!~startIndex && !~endIndex)
|
|
16846
16903
|
return;
|
|
16847
16904
|
const { value, width, height } = payload;
|
|
16848
|
-
this.
|
|
16905
|
+
this.insertElementList([
|
|
16849
16906
|
{
|
|
16850
16907
|
value,
|
|
16851
16908
|
width,
|
|
@@ -18480,6 +18537,11 @@ const defaultBackground = {
|
|
|
18480
18537
|
size: BackgroundSize.COVER,
|
|
18481
18538
|
repeat: BackgroundRepeat.NO_REPEAT
|
|
18482
18539
|
};
|
|
18540
|
+
const defaultLineBreak = {
|
|
18541
|
+
disabled: true,
|
|
18542
|
+
color: "#CCCCCC",
|
|
18543
|
+
lineWidth: 1.5
|
|
18544
|
+
};
|
|
18483
18545
|
class Editor {
|
|
18484
18546
|
constructor(container, data2, options = {}) {
|
|
18485
18547
|
__publicField(this, "command");
|
|
@@ -18502,6 +18564,7 @@ class Editor {
|
|
|
18502
18564
|
const pageBreakOptions = __spreadValues(__spreadValues({}, defaultPageBreakOption), options.pageBreak);
|
|
18503
18565
|
const zoneOptions = __spreadValues(__spreadValues({}, defaultZoneOption), options.zone);
|
|
18504
18566
|
const backgroundOptions = __spreadValues(__spreadValues({}, defaultBackground), options.background);
|
|
18567
|
+
const lineBreakOptions = __spreadValues(__spreadValues({}, defaultLineBreak), options.lineBreak);
|
|
18505
18568
|
const editorOptions = __spreadProps(__spreadValues({
|
|
18506
18569
|
mode: EditorMode.EDIT,
|
|
18507
18570
|
defaultType: "TEXT",
|
|
@@ -18558,7 +18621,8 @@ class Editor {
|
|
|
18558
18621
|
group: groupOptions,
|
|
18559
18622
|
pageBreak: pageBreakOptions,
|
|
18560
18623
|
zone: zoneOptions,
|
|
18561
|
-
background: backgroundOptions
|
|
18624
|
+
background: backgroundOptions,
|
|
18625
|
+
lineBreak: lineBreakOptions
|
|
18562
18626
|
});
|
|
18563
18627
|
data2 = deepClone(data2);
|
|
18564
18628
|
let headerElementList = [];
|