mce 0.14.0 → 0.14.1
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/dist/index.js +97 -49
- package/dist/plugins/pen.d.ts +1 -0
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -4394,8 +4394,14 @@ const _frame = definePlugin((editor) => {
|
|
|
4394
4394
|
el.style.backgroundColor = "#ffffff";
|
|
4395
4395
|
return {
|
|
4396
4396
|
move: (move) => {
|
|
4397
|
-
|
|
4398
|
-
|
|
4397
|
+
const minX = Math.min(move.x, start.x);
|
|
4398
|
+
const minY = Math.min(move.y, start.y);
|
|
4399
|
+
const maxX = Math.max(move.x, start.x);
|
|
4400
|
+
const maxY = Math.max(move.y, start.y);
|
|
4401
|
+
el.style.left = minX;
|
|
4402
|
+
el.style.top = minY;
|
|
4403
|
+
el.style.width = maxX - minX;
|
|
4404
|
+
el.style.height = maxY - minY;
|
|
4399
4405
|
},
|
|
4400
4406
|
end: () => {
|
|
4401
4407
|
setActiveDrawingTool(void 0);
|
|
@@ -8275,7 +8281,7 @@ function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
|
|
|
8275
8281
|
}
|
|
8276
8282
|
class Curve {
|
|
8277
8283
|
arcLengthDivision = 200;
|
|
8278
|
-
|
|
8284
|
+
_lengths = [];
|
|
8279
8285
|
getPointAt(u, output = new Vector2()) {
|
|
8280
8286
|
return this.getPoint(this.getUToTMapping(u), output);
|
|
8281
8287
|
}
|
|
@@ -8353,10 +8359,10 @@ class Curve {
|
|
|
8353
8359
|
return lengths[lengths.length - 1];
|
|
8354
8360
|
}
|
|
8355
8361
|
getLengths() {
|
|
8356
|
-
if (
|
|
8362
|
+
if (this._lengths.length !== this.arcLengthDivision + 1) {
|
|
8357
8363
|
this.updateLengths();
|
|
8358
8364
|
}
|
|
8359
|
-
return this.
|
|
8365
|
+
return this._lengths;
|
|
8360
8366
|
}
|
|
8361
8367
|
updateLengths() {
|
|
8362
8368
|
const divisions = this.arcLengthDivision;
|
|
@@ -8367,7 +8373,7 @@ class Curve {
|
|
|
8367
8373
|
arcLengths.push(sum);
|
|
8368
8374
|
prev = current;
|
|
8369
8375
|
}
|
|
8370
|
-
this.
|
|
8376
|
+
this._lengths = arcLengths;
|
|
8371
8377
|
}
|
|
8372
8378
|
getUToTMapping(u, distance2) {
|
|
8373
8379
|
const lengths = this.getLengths();
|
|
@@ -8392,14 +8398,14 @@ class Curve {
|
|
|
8392
8398
|
break;
|
|
8393
8399
|
}
|
|
8394
8400
|
}
|
|
8395
|
-
i = high;
|
|
8401
|
+
i = Math.max(0, high);
|
|
8396
8402
|
if (lengths[i] === targetLen) {
|
|
8397
8403
|
return i / (lengthsLen - 1);
|
|
8398
8404
|
}
|
|
8399
8405
|
const before = lengths[i];
|
|
8400
8406
|
const after = lengths[i + 1];
|
|
8401
8407
|
const segmentLength = after - before;
|
|
8402
|
-
const segmentFraction = (targetLen - before) / segmentLength;
|
|
8408
|
+
const segmentFraction = Math.max(0, (targetLen - before) / segmentLength);
|
|
8403
8409
|
return (i + segmentFraction) / (lengthsLen - 1);
|
|
8404
8410
|
}
|
|
8405
8411
|
getTangent(t, output = new Vector2()) {
|
|
@@ -9061,13 +9067,19 @@ class CompositeCurve extends Curve {
|
|
|
9061
9067
|
}
|
|
9062
9068
|
return output;
|
|
9063
9069
|
}
|
|
9070
|
+
getLengths() {
|
|
9071
|
+
if (this._lengths.length !== this.curves.length) {
|
|
9072
|
+
this.updateLengths();
|
|
9073
|
+
}
|
|
9074
|
+
return this._lengths;
|
|
9075
|
+
}
|
|
9064
9076
|
updateLengths() {
|
|
9065
|
-
const
|
|
9077
|
+
const lengths = [];
|
|
9066
9078
|
for (let i = 0, sum = 0, len = this.curves.length; i < len; i++) {
|
|
9067
9079
|
sum += this.curves[i].getLength();
|
|
9068
|
-
|
|
9080
|
+
lengths.push(sum);
|
|
9069
9081
|
}
|
|
9070
|
-
this.
|
|
9082
|
+
this._lengths = lengths;
|
|
9071
9083
|
}
|
|
9072
9084
|
getControlPointRefs() {
|
|
9073
9085
|
return this.curves.flatMap((curve) => curve.getControlPointRefs());
|
|
@@ -9739,9 +9751,11 @@ class Path2D extends CompositeCurve {
|
|
|
9739
9751
|
return this;
|
|
9740
9752
|
}
|
|
9741
9753
|
addPath(path) {
|
|
9742
|
-
|
|
9743
|
-
|
|
9744
|
-
|
|
9754
|
+
if (!this.currentCurve.curves.length) {
|
|
9755
|
+
const index = this.curves.findIndex((v) => v === this.currentCurve);
|
|
9756
|
+
if (index > -1) {
|
|
9757
|
+
this.curves.splice(index, 1);
|
|
9758
|
+
}
|
|
9745
9759
|
}
|
|
9746
9760
|
if (path instanceof Path2D) {
|
|
9747
9761
|
this.curves.push(
|
|
@@ -9750,17 +9764,15 @@ class Path2D extends CompositeCurve {
|
|
|
9750
9764
|
} else if (path.curves.length) {
|
|
9751
9765
|
this.curves.push(path);
|
|
9752
9766
|
}
|
|
9753
|
-
this.curves
|
|
9767
|
+
this.currentCurve = this.curves[this.curves.length - 1];
|
|
9754
9768
|
return this;
|
|
9755
9769
|
}
|
|
9756
9770
|
closePath() {
|
|
9757
9771
|
const startPoint = this.startPoint;
|
|
9758
|
-
if (startPoint) {
|
|
9772
|
+
if (startPoint && this.currentCurve.curves.length) {
|
|
9759
9773
|
this.currentCurve.closePath();
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
this.curves.push(this.currentCurve);
|
|
9763
|
-
}
|
|
9774
|
+
this.currentCurve = new CurvePath().moveTo(startPoint.x, startPoint.y);
|
|
9775
|
+
this.curves.push(this.currentCurve);
|
|
9764
9776
|
}
|
|
9765
9777
|
return this;
|
|
9766
9778
|
}
|
|
@@ -10073,30 +10085,43 @@ class Path2D extends CompositeCurve {
|
|
|
10073
10085
|
}
|
|
10074
10086
|
const _pen = definePlugin((editor) => {
|
|
10075
10087
|
const {
|
|
10076
|
-
addElement
|
|
10088
|
+
addElement,
|
|
10089
|
+
renderEngine,
|
|
10090
|
+
activeDrawingTool,
|
|
10091
|
+
getGlobalPointer,
|
|
10092
|
+
state
|
|
10077
10093
|
} = editor;
|
|
10078
|
-
let pening = false;
|
|
10079
10094
|
let el;
|
|
10080
|
-
let
|
|
10095
|
+
let currentPath;
|
|
10096
|
+
let currentLine;
|
|
10097
|
+
const update = () => {
|
|
10098
|
+
if (el && currentPath) {
|
|
10099
|
+
el.shape.paths = [
|
|
10100
|
+
{ data: currentPath.toData() }
|
|
10101
|
+
];
|
|
10102
|
+
const box = currentPath.getBoundingBox();
|
|
10103
|
+
el.style.left = box.left;
|
|
10104
|
+
el.style.top = box.top;
|
|
10105
|
+
el.style.width = box.width;
|
|
10106
|
+
el.style.height = box.height;
|
|
10107
|
+
}
|
|
10108
|
+
};
|
|
10081
10109
|
return {
|
|
10082
10110
|
name: "mce:pen",
|
|
10083
10111
|
drawingTools: [
|
|
10084
10112
|
{
|
|
10085
10113
|
name: "pen",
|
|
10086
10114
|
handle: (start) => {
|
|
10087
|
-
if (
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
el.style.width = box.width;
|
|
10097
|
-
el.style.height = box.height;
|
|
10115
|
+
if (el) {
|
|
10116
|
+
if (currentPath) {
|
|
10117
|
+
currentLine = new LineCurve(
|
|
10118
|
+
new Vector2(start.x, start.y),
|
|
10119
|
+
new Vector2(start.x, start.y)
|
|
10120
|
+
);
|
|
10121
|
+
currentPath.currentCurve.addCurve(currentLine);
|
|
10122
|
+
update();
|
|
10123
|
+
}
|
|
10098
10124
|
} else {
|
|
10099
|
-
pening = true;
|
|
10100
10125
|
el = addElement({
|
|
10101
10126
|
name: "pen",
|
|
10102
10127
|
outline: {
|
|
@@ -10109,11 +10134,30 @@ const _pen = definePlugin((editor) => {
|
|
|
10109
10134
|
inPptIs: "Shape"
|
|
10110
10135
|
}
|
|
10111
10136
|
}, {
|
|
10112
|
-
active: true,
|
|
10113
10137
|
position: start
|
|
10114
10138
|
});
|
|
10115
|
-
|
|
10116
|
-
|
|
10139
|
+
currentPath = new Path2D();
|
|
10140
|
+
currentLine = new LineCurve(
|
|
10141
|
+
new Vector2(start.x, start.y),
|
|
10142
|
+
new Vector2(start.x, start.y)
|
|
10143
|
+
);
|
|
10144
|
+
currentPath.currentCurve.addCurve(currentLine);
|
|
10145
|
+
const onMove = () => {
|
|
10146
|
+
const move = getGlobalPointer();
|
|
10147
|
+
if (currentLine && move) {
|
|
10148
|
+
currentLine.p2.x = move.x;
|
|
10149
|
+
currentLine.p2.y = move.y;
|
|
10150
|
+
update();
|
|
10151
|
+
}
|
|
10152
|
+
};
|
|
10153
|
+
renderEngine.value.on("pointermove", onMove);
|
|
10154
|
+
const stop = watch([state, activeDrawingTool], () => {
|
|
10155
|
+
renderEngine.value.off("pointermove", onMove);
|
|
10156
|
+
stop();
|
|
10157
|
+
el = void 0;
|
|
10158
|
+
currentPath = void 0;
|
|
10159
|
+
currentLine = void 0;
|
|
10160
|
+
});
|
|
10117
10161
|
}
|
|
10118
10162
|
}
|
|
10119
10163
|
},
|
|
@@ -10134,22 +10178,20 @@ const _pen = definePlugin((editor) => {
|
|
|
10134
10178
|
}, {
|
|
10135
10179
|
position: start
|
|
10136
10180
|
});
|
|
10137
|
-
const
|
|
10138
|
-
|
|
10181
|
+
const path = new Path2D();
|
|
10182
|
+
path.moveTo(start.x, start.y);
|
|
10139
10183
|
return {
|
|
10140
10184
|
move: (move) => {
|
|
10141
|
-
|
|
10142
|
-
|
|
10185
|
+
path.lineTo(move.x, move.y);
|
|
10186
|
+
path.moveTo(move.x, move.y);
|
|
10143
10187
|
el2.shape.paths = [
|
|
10144
|
-
{ data:
|
|
10188
|
+
{ data: path.toData() }
|
|
10145
10189
|
];
|
|
10146
|
-
const box =
|
|
10190
|
+
const box = path.getBoundingBox();
|
|
10147
10191
|
el2.style.left = box.left;
|
|
10148
10192
|
el2.style.top = box.top;
|
|
10149
10193
|
el2.style.width = box.width;
|
|
10150
10194
|
el2.style.height = box.height;
|
|
10151
|
-
},
|
|
10152
|
-
end: () => {
|
|
10153
10195
|
}
|
|
10154
10196
|
};
|
|
10155
10197
|
}
|
|
@@ -10928,8 +10970,14 @@ const _shape = definePlugin((editor) => {
|
|
|
10928
10970
|
});
|
|
10929
10971
|
return {
|
|
10930
10972
|
move: (move) => {
|
|
10931
|
-
|
|
10932
|
-
|
|
10973
|
+
const minX = Math.min(move.x, start.x);
|
|
10974
|
+
const minY = Math.min(move.y, start.y);
|
|
10975
|
+
const maxX = Math.max(move.x, start.x);
|
|
10976
|
+
const maxY = Math.max(move.y, start.y);
|
|
10977
|
+
el.style.left = minX;
|
|
10978
|
+
el.style.top = minY;
|
|
10979
|
+
el.style.width = maxX - minX;
|
|
10980
|
+
el.style.height = maxY - minY;
|
|
10933
10981
|
},
|
|
10934
10982
|
end: () => {
|
|
10935
10983
|
setActiveDrawingTool(void 0);
|
|
@@ -15111,7 +15159,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
15111
15159
|
return (_ctx, _cache) => {
|
|
15112
15160
|
return openBlock(), createBlock(_sfc_main$5, {
|
|
15113
15161
|
class: normalizeClass(["mce-editor", [
|
|
15114
|
-
`mce-editor--${unref(state)}`,
|
|
15162
|
+
unref(state) && `mce-editor--${unref(state)}`,
|
|
15115
15163
|
unref(activeDrawingTool) && `mce-editor--drawing-tool-${unref(activeDrawingTool).name}`,
|
|
15116
15164
|
grabbing.value && `mce-editor--grabbing`
|
|
15117
15165
|
]])
|
package/dist/plugins/pen.d.ts
CHANGED