@hufe921/canvas-editor 0.9.66 → 0.9.67
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 +124 -28
- package/dist/canvas-editor.es.js.map +1 -1
- package/dist/canvas-editor.umd.js +28 -28
- package/dist/canvas-editor.umd.js.map +1 -1
- package/dist/src/editor/core/command/CommandAdapt.d.ts +2 -1
- package/dist/src/editor/core/draw/control/text/TextControl.d.ts +1 -1
- package/dist/src/editor/core/draw/richtext/AbstractRichText.d.ts +5 -3
- package/dist/src/editor/core/draw/richtext/Underline.d.ts +3 -0
- package/dist/src/editor/dataset/constant/Element.d.ts +1 -0
- package/dist/src/editor/dataset/enum/Text.d.ts +12 -0
- package/dist/src/editor/index.d.ts +2 -1
- package/dist/src/editor/interface/Element.d.ts +2 -0
- package/dist/src/editor/interface/Listener.d.ts +2 -0
- package/dist/src/editor/interface/Text.d.ts +4 -0
- package/dist/src/editor/utils/index.d.ts +1 -0
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,25 @@
|
|
|
1
|
+
## [0.9.67](https://github.com/Hufe921/canvas-editor/compare/v0.9.66...v0.9.67) (2024-03-01)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* dragging image boundary error within the control ([52590f6](https://github.com/Hufe921/canvas-editor/commit/52590f6d92746e30aaf92efe85b0486ddd3cb467))
|
|
7
|
+
* text control clear value range context error #439 (#443) ([c299290](https://github.com/Hufe921/canvas-editor/commit/c2992909b6c7ff94d6685007d09fa9611b5e6d8d)), closes [#439](https://github.com/Hufe921/canvas-editor/issues/439) [#443](https://github.com/Hufe921/canvas-editor/issues/443)
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
### Chores
|
|
11
|
+
|
|
12
|
+
* add underline decoration type demo ([aa12296](https://github.com/Hufe921/canvas-editor/commit/aa12296ef67aa66e46d6615e91833199746c8bae))
|
|
13
|
+
* update FUNDING.yml ([dc2804c](https://github.com/Hufe921/canvas-editor/commit/dc2804c492b1d5d745ec58276e4ff8bc1ed825b3))
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
### Features
|
|
17
|
+
|
|
18
|
+
* add text decoration property ([f1570f2](https://github.com/Hufe921/canvas-editor/commit/f1570f2180086c1d4f9bf92e06edf5baecbd436c))
|
|
19
|
+
* add textDecoration property to the rangeStyleChange event ([a7fa847](https://github.com/Hufe921/canvas-editor/commit/a7fa847b198010cc5c7b8af9c860a04fe1c4250d))
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
|
|
1
23
|
## [0.9.66](https://github.com/Hufe921/canvas-editor/compare/v0.9.65...v0.9.66) (2024-02-24)
|
|
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.67";
|
|
27
27
|
var MaxHeightRatio;
|
|
28
28
|
(function(MaxHeightRatio2) {
|
|
29
29
|
MaxHeightRatio2["HALF"] = "half";
|
|
@@ -325,6 +325,16 @@ function isArrayEqual(arr1, arr2) {
|
|
|
325
325
|
}
|
|
326
326
|
return !arr1.some((item) => !arr2.includes(item));
|
|
327
327
|
}
|
|
328
|
+
function isObjectEqual(obj1, obj2) {
|
|
329
|
+
if (!isObject(obj1) || !isObject(obj2))
|
|
330
|
+
return false;
|
|
331
|
+
const obj1Keys = Object.keys(obj1);
|
|
332
|
+
const obj2Keys = Object.keys(obj2);
|
|
333
|
+
if (obj1Keys.length !== obj2Keys.length) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
return !obj1Keys.some((key) => obj2[key] !== obj1[key]);
|
|
337
|
+
}
|
|
328
338
|
const CURSOR_AGENT_OFFSET_HEIGHT = 12;
|
|
329
339
|
const defaultCursorOption = {
|
|
330
340
|
width: 1,
|
|
@@ -369,7 +379,8 @@ const EDITOR_ELEMENT_STYLE_ATTR = [
|
|
|
369
379
|
"size",
|
|
370
380
|
"italic",
|
|
371
381
|
"underline",
|
|
372
|
-
"strikeout"
|
|
382
|
+
"strikeout",
|
|
383
|
+
"textDecoration"
|
|
373
384
|
];
|
|
374
385
|
const EDITOR_ROW_ATTR = ["rowFlex", "rowMargin"];
|
|
375
386
|
const EDITOR_ELEMENT_COPY_ATTR = [
|
|
@@ -389,7 +400,8 @@ const EDITOR_ELEMENT_COPY_ATTR = [
|
|
|
389
400
|
"dateFormat",
|
|
390
401
|
"groupIds",
|
|
391
402
|
"rowFlex",
|
|
392
|
-
"rowMargin"
|
|
403
|
+
"rowMargin",
|
|
404
|
+
"textDecoration"
|
|
393
405
|
];
|
|
394
406
|
const EDITOR_ELEMENT_ZIP_ATTR = [
|
|
395
407
|
"type",
|
|
@@ -422,7 +434,8 @@ const EDITOR_ELEMENT_ZIP_ATTR = [
|
|
|
422
434
|
"groupIds",
|
|
423
435
|
"conceptId",
|
|
424
436
|
"imgDisplay",
|
|
425
|
-
"imgFloatPosition"
|
|
437
|
+
"imgFloatPosition",
|
|
438
|
+
"textDecoration"
|
|
426
439
|
];
|
|
427
440
|
const TABLE_TD_ZIP_ATTR = [
|
|
428
441
|
"verticalAlign",
|
|
@@ -441,6 +454,11 @@ const LIST_CONTEXT_ATTR = [
|
|
|
441
454
|
"listType",
|
|
442
455
|
"listStyle"
|
|
443
456
|
];
|
|
457
|
+
const CONTROL_CONTEXT_ATTR = [
|
|
458
|
+
"control",
|
|
459
|
+
"controlId",
|
|
460
|
+
"controlComponent"
|
|
461
|
+
];
|
|
444
462
|
const EDITOR_ELEMENT_CONTEXT_ATTR = [
|
|
445
463
|
...TABLE_CONTEXT_ATTR,
|
|
446
464
|
...TITLE_CONTEXT_ATTR,
|
|
@@ -5426,8 +5444,7 @@ function mouseup(evt, host) {
|
|
|
5426
5444
|
const editorOptions = draw.getOptions();
|
|
5427
5445
|
const elementList = draw.getElementList();
|
|
5428
5446
|
const replaceElementList = dragElementList.map((el) => {
|
|
5429
|
-
|
|
5430
|
-
if (!el.type || el.type === ElementType.TEXT || ((_a2 = el.control) == null ? void 0 : _a2.type) === ControlType.TEXT) {
|
|
5447
|
+
if (!el.type || el.type === ElementType.TEXT) {
|
|
5431
5448
|
const newElement = {
|
|
5432
5449
|
value: el.value
|
|
5433
5450
|
};
|
|
@@ -5439,7 +5456,7 @@ function mouseup(evt, host) {
|
|
|
5439
5456
|
});
|
|
5440
5457
|
return newElement;
|
|
5441
5458
|
} else {
|
|
5442
|
-
const newElement = deepClone(el);
|
|
5459
|
+
const newElement = omitObject(deepClone(el), CONTROL_CONTEXT_ATTR);
|
|
5443
5460
|
formatElementList([newElement], {
|
|
5444
5461
|
isHandleFirstElement: false,
|
|
5445
5462
|
editorOptions
|
|
@@ -7443,6 +7460,7 @@ class RangeManager {
|
|
|
7443
7460
|
const level = curElement.level || null;
|
|
7444
7461
|
const listType = curElement.listType || null;
|
|
7445
7462
|
const listStyle = curElement.listStyle || null;
|
|
7463
|
+
const textDecoration = underline ? curElement.textDecoration || null : null;
|
|
7446
7464
|
const painter = !!this.draw.getPainterStyle();
|
|
7447
7465
|
const undo = this.historyManager.isCanUndo();
|
|
7448
7466
|
const redo = this.historyManager.isCanRedo();
|
|
@@ -7466,7 +7484,8 @@ class RangeManager {
|
|
|
7466
7484
|
level,
|
|
7467
7485
|
listType,
|
|
7468
7486
|
listStyle,
|
|
7469
|
-
groupIds
|
|
7487
|
+
groupIds,
|
|
7488
|
+
textDecoration
|
|
7470
7489
|
};
|
|
7471
7490
|
if (rangeStyleChangeListener) {
|
|
7472
7491
|
rangeStyleChangeListener(rangeStyle);
|
|
@@ -7505,7 +7524,8 @@ class RangeManager {
|
|
|
7505
7524
|
level: null,
|
|
7506
7525
|
listType: null,
|
|
7507
7526
|
listStyle: null,
|
|
7508
|
-
groupIds: null
|
|
7527
|
+
groupIds: null,
|
|
7528
|
+
textDecoration: null
|
|
7509
7529
|
};
|
|
7510
7530
|
if (rangeStyleChangeListener) {
|
|
7511
7531
|
rangeStyleChangeListener(rangeStyle);
|
|
@@ -7681,10 +7701,12 @@ class AbstractRichText {
|
|
|
7681
7701
|
constructor() {
|
|
7682
7702
|
__publicField(this, "fillRect");
|
|
7683
7703
|
__publicField(this, "fillColor");
|
|
7704
|
+
__publicField(this, "fillDecorationStyle");
|
|
7684
7705
|
this.fillRect = this.clearFillInfo();
|
|
7685
7706
|
}
|
|
7686
7707
|
clearFillInfo() {
|
|
7687
7708
|
this.fillColor = void 0;
|
|
7709
|
+
this.fillDecorationStyle = void 0;
|
|
7688
7710
|
this.fillRect = {
|
|
7689
7711
|
x: 0,
|
|
7690
7712
|
y: 0,
|
|
@@ -7693,12 +7715,12 @@ class AbstractRichText {
|
|
|
7693
7715
|
};
|
|
7694
7716
|
return this.fillRect;
|
|
7695
7717
|
}
|
|
7696
|
-
recordFillInfo(ctx, x, y, width, height, color) {
|
|
7718
|
+
recordFillInfo(ctx, x, y, width, height, color, decorationStyle) {
|
|
7697
7719
|
const isFirstRecord = !this.fillRect.width;
|
|
7698
|
-
if (!isFirstRecord && this.fillColor !== color) {
|
|
7720
|
+
if (!isFirstRecord && (this.fillColor !== color || this.fillDecorationStyle !== decorationStyle)) {
|
|
7699
7721
|
this.render(ctx);
|
|
7700
7722
|
this.clearFillInfo();
|
|
7701
|
-
this.recordFillInfo(ctx, x, y, width, height, color);
|
|
7723
|
+
this.recordFillInfo(ctx, x, y, width, height, color, decorationStyle);
|
|
7702
7724
|
return;
|
|
7703
7725
|
}
|
|
7704
7726
|
if (isFirstRecord) {
|
|
@@ -7710,6 +7732,7 @@ class AbstractRichText {
|
|
|
7710
7732
|
}
|
|
7711
7733
|
this.fillRect.width += width;
|
|
7712
7734
|
this.fillColor = color;
|
|
7735
|
+
this.fillDecorationStyle = decorationStyle;
|
|
7713
7736
|
}
|
|
7714
7737
|
}
|
|
7715
7738
|
class Highlight extends AbstractRichText {
|
|
@@ -8041,24 +8064,92 @@ class Strikeout extends AbstractRichText {
|
|
|
8041
8064
|
this.clearFillInfo();
|
|
8042
8065
|
}
|
|
8043
8066
|
}
|
|
8067
|
+
var TextDecorationStyle;
|
|
8068
|
+
(function(TextDecorationStyle2) {
|
|
8069
|
+
TextDecorationStyle2["SOLID"] = "solid";
|
|
8070
|
+
TextDecorationStyle2["DOUBLE"] = "double";
|
|
8071
|
+
TextDecorationStyle2["DASHED"] = "dashed";
|
|
8072
|
+
TextDecorationStyle2["DOTTED"] = "dotted";
|
|
8073
|
+
TextDecorationStyle2["WAVY"] = "wavy";
|
|
8074
|
+
})(TextDecorationStyle || (TextDecorationStyle = {}));
|
|
8075
|
+
var DashType;
|
|
8076
|
+
(function(DashType2) {
|
|
8077
|
+
DashType2["SOLID"] = "solid";
|
|
8078
|
+
DashType2["DASHED"] = "dashed";
|
|
8079
|
+
DashType2["DOTTED"] = "dotted";
|
|
8080
|
+
})(DashType || (DashType = {}));
|
|
8044
8081
|
class Underline extends AbstractRichText {
|
|
8045
8082
|
constructor(draw) {
|
|
8046
8083
|
super();
|
|
8047
8084
|
__publicField(this, "options");
|
|
8048
8085
|
this.options = draw.getOptions();
|
|
8049
8086
|
}
|
|
8087
|
+
_drawLine(ctx, startX, startY, width, dashType) {
|
|
8088
|
+
const endX = startX + width;
|
|
8089
|
+
ctx.beginPath();
|
|
8090
|
+
switch (dashType) {
|
|
8091
|
+
case DashType.DASHED:
|
|
8092
|
+
ctx.setLineDash([3, 1]);
|
|
8093
|
+
break;
|
|
8094
|
+
case DashType.DOTTED:
|
|
8095
|
+
ctx.setLineDash([1, 1]);
|
|
8096
|
+
break;
|
|
8097
|
+
}
|
|
8098
|
+
ctx.moveTo(startX, startY);
|
|
8099
|
+
ctx.lineTo(endX, startY);
|
|
8100
|
+
ctx.stroke();
|
|
8101
|
+
}
|
|
8102
|
+
_drawDouble(ctx, startX, startY, width) {
|
|
8103
|
+
const SPACING = 3;
|
|
8104
|
+
const endX = startX + width;
|
|
8105
|
+
const endY = startY + SPACING * this.options.scale;
|
|
8106
|
+
ctx.beginPath();
|
|
8107
|
+
ctx.moveTo(startX, startY);
|
|
8108
|
+
ctx.lineTo(endX, startY);
|
|
8109
|
+
ctx.stroke();
|
|
8110
|
+
ctx.beginPath();
|
|
8111
|
+
ctx.moveTo(startX, endY);
|
|
8112
|
+
ctx.lineTo(endX, endY);
|
|
8113
|
+
ctx.stroke();
|
|
8114
|
+
}
|
|
8115
|
+
_drawWave(ctx, startX, startY, width) {
|
|
8116
|
+
const { scale } = this.options;
|
|
8117
|
+
const AMPLITUDE = 1.2 * scale;
|
|
8118
|
+
const FREQUENCY = 1 / scale;
|
|
8119
|
+
const adjustY = startY + 2 * AMPLITUDE;
|
|
8120
|
+
ctx.beginPath();
|
|
8121
|
+
for (let x = 0; x < width; x++) {
|
|
8122
|
+
const y = AMPLITUDE * Math.sin(FREQUENCY * x);
|
|
8123
|
+
ctx.lineTo(startX + x, adjustY + y);
|
|
8124
|
+
}
|
|
8125
|
+
ctx.stroke();
|
|
8126
|
+
}
|
|
8050
8127
|
render(ctx) {
|
|
8051
8128
|
if (!this.fillRect.width)
|
|
8052
8129
|
return;
|
|
8053
|
-
const { underlineColor } = this.options;
|
|
8130
|
+
const { underlineColor, scale } = this.options;
|
|
8054
8131
|
const { x, y, width } = this.fillRect;
|
|
8055
8132
|
ctx.save();
|
|
8056
8133
|
ctx.strokeStyle = this.fillColor || underlineColor;
|
|
8134
|
+
ctx.lineWidth = scale;
|
|
8057
8135
|
const adjustY = Math.floor(y + 2 * ctx.lineWidth) + 0.5;
|
|
8058
|
-
|
|
8059
|
-
|
|
8060
|
-
|
|
8061
|
-
|
|
8136
|
+
switch (this.fillDecorationStyle) {
|
|
8137
|
+
case TextDecorationStyle.WAVY:
|
|
8138
|
+
this._drawWave(ctx, x, adjustY, width);
|
|
8139
|
+
break;
|
|
8140
|
+
case TextDecorationStyle.DOUBLE:
|
|
8141
|
+
this._drawDouble(ctx, x, adjustY, width);
|
|
8142
|
+
break;
|
|
8143
|
+
case TextDecorationStyle.DASHED:
|
|
8144
|
+
this._drawLine(ctx, x, adjustY, width, DashType.DASHED);
|
|
8145
|
+
break;
|
|
8146
|
+
case TextDecorationStyle.DOTTED:
|
|
8147
|
+
this._drawLine(ctx, x, adjustY, width, DashType.DOTTED);
|
|
8148
|
+
break;
|
|
8149
|
+
default:
|
|
8150
|
+
this._drawLine(ctx, x, adjustY, width);
|
|
8151
|
+
break;
|
|
8152
|
+
}
|
|
8062
8153
|
ctx.restore();
|
|
8063
8154
|
this.clearFillInfo();
|
|
8064
8155
|
}
|
|
@@ -9613,9 +9704,9 @@ class TextControl {
|
|
|
9613
9704
|
getElement() {
|
|
9614
9705
|
return this.element;
|
|
9615
9706
|
}
|
|
9616
|
-
getValue() {
|
|
9617
|
-
const elementList = this.control.getElementList();
|
|
9618
|
-
const { startIndex } = this.control.getRange();
|
|
9707
|
+
getValue(context = {}) {
|
|
9708
|
+
const elementList = context.elementList || this.control.getElementList();
|
|
9709
|
+
const { startIndex } = context.range || this.control.getRange();
|
|
9619
9710
|
const startElement = elementList[startIndex];
|
|
9620
9711
|
const data2 = [];
|
|
9621
9712
|
let preIndex = startIndex;
|
|
@@ -9676,7 +9767,7 @@ class TextControl {
|
|
|
9676
9767
|
const range = context.range || this.control.getRange();
|
|
9677
9768
|
const { startIndex, endIndex } = range;
|
|
9678
9769
|
this.control.getDraw().spliceElementList(elementList, startIndex + 1, endIndex - startIndex);
|
|
9679
|
-
const value = this.getValue();
|
|
9770
|
+
const value = this.getValue(context);
|
|
9680
9771
|
if (!value.length) {
|
|
9681
9772
|
this.control.addPlaceholder(startIndex);
|
|
9682
9773
|
}
|
|
@@ -13682,7 +13773,7 @@ class Draw {
|
|
|
13682
13773
|
this.textParticle.complete();
|
|
13683
13774
|
}
|
|
13684
13775
|
drawRow(ctx, payload) {
|
|
13685
|
-
var _a, _b;
|
|
13776
|
+
var _a, _b, _c;
|
|
13686
13777
|
const { rowList, pageNo, elementList, positionList, startIndex, zone: zone2 } = payload;
|
|
13687
13778
|
const isPrintMode = this.mode === EditorMode.PRINT;
|
|
13688
13779
|
const { scale, tdPadding, defaultBasicRowMarginHeight, defaultRowMargin, group: group2 } = this.options;
|
|
@@ -13776,8 +13867,8 @@ class Draw {
|
|
|
13776
13867
|
offsetY2 = this.superscriptParticle.getOffsetY(element);
|
|
13777
13868
|
}
|
|
13778
13869
|
const color = element.controlComponent === ControlComponent.PLACEHOLDER ? void 0 : element.color;
|
|
13779
|
-
this.underline.recordFillInfo(ctx, x - offsetX, y + curRow.height - rowMargin + offsetY2, metrics.width + offsetX, 0, color);
|
|
13780
|
-
} else if ((preElement == null ? void 0 : preElement.underline) || ((
|
|
13870
|
+
this.underline.recordFillInfo(ctx, x - offsetX, y + curRow.height - rowMargin + offsetY2, metrics.width + offsetX, 0, color, (_b = element.textDecoration) == null ? void 0 : _b.style);
|
|
13871
|
+
} else if ((preElement == null ? void 0 : preElement.underline) || ((_c = preElement == null ? void 0 : preElement.control) == null ? void 0 : _c.underline)) {
|
|
13781
13872
|
this.underline.render(ctx);
|
|
13782
13873
|
}
|
|
13783
13874
|
if (element.strikeout) {
|
|
@@ -14706,15 +14797,20 @@ class CommandAdapt {
|
|
|
14706
14797
|
}
|
|
14707
14798
|
}
|
|
14708
14799
|
}
|
|
14709
|
-
underline() {
|
|
14800
|
+
underline(textDecoration) {
|
|
14710
14801
|
const isDisabled = this.draw.isReadonly() || this.control.isDisabledControl();
|
|
14711
14802
|
if (isDisabled)
|
|
14712
14803
|
return;
|
|
14713
14804
|
const selection = this.range.getSelectionElementList();
|
|
14714
14805
|
if (selection == null ? void 0 : selection.length) {
|
|
14715
|
-
const
|
|
14806
|
+
const isSetUnderline = selection.some((s) => !s.underline || !textDecoration && s.textDecoration || textDecoration && !s.textDecoration || textDecoration && s.textDecoration && !isObjectEqual(s.textDecoration, textDecoration));
|
|
14716
14807
|
selection.forEach((el) => {
|
|
14717
|
-
el.underline =
|
|
14808
|
+
el.underline = isSetUnderline;
|
|
14809
|
+
if (isSetUnderline && textDecoration) {
|
|
14810
|
+
el.textDecoration = textDecoration;
|
|
14811
|
+
} else {
|
|
14812
|
+
delete el.textDecoration;
|
|
14813
|
+
}
|
|
14718
14814
|
});
|
|
14719
14815
|
this.draw.render({
|
|
14720
14816
|
isSetCursor: false,
|
|
@@ -17626,5 +17722,5 @@ class Editor {
|
|
|
17626
17722
|
this.use = plugin.use.bind(plugin);
|
|
17627
17723
|
}
|
|
17628
17724
|
}
|
|
17629
|
-
export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TdBorder, TdSlash, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
|
|
17725
|
+
export { BackgroundRepeat, BackgroundSize, BlockType, Command, ControlIndentation, ControlType, EDITOR_COMPONENT, Editor, EditorComponent, EditorMode, EditorZone, ElementType, INTERNAL_CONTEXT_MENU_KEY, ImageDisplay, KeyMap, LETTER_CLASS, ListStyle, ListType, MaxHeightRatio, NumberType, PageMode, PaperDirection, RowFlex, TableBorder, TdBorder, TdSlash, TextDecorationStyle, TitleLevel, VerticalAlign, WordBreak, Editor as default, splitText };
|
|
17630
17726
|
//# sourceMappingURL=canvas-editor.es.js.map
|