mce 0.14.0 → 0.14.2
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 +140 -96
- package/dist/plugins/pen.d.ts +1 -0
- package/package.json +2 -2
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);
|
|
@@ -5084,7 +5090,7 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
|
|
|
5084
5090
|
const node = props.node;
|
|
5085
5091
|
if (isFrame(node)) {
|
|
5086
5092
|
return "$frame";
|
|
5087
|
-
} else if (node.children.length) {
|
|
5093
|
+
} else if (node.children.filter(isElement).length) {
|
|
5088
5094
|
return "$group";
|
|
5089
5095
|
} else if (isElement(node)) {
|
|
5090
5096
|
if (node.foreground.isValid() && node.foreground.image) {
|
|
@@ -5103,47 +5109,45 @@ const _sfc_main$w = /* @__PURE__ */ defineComponent({
|
|
|
5103
5109
|
}
|
|
5104
5110
|
function onClickContent(e) {
|
|
5105
5111
|
selecting.value = true;
|
|
5106
|
-
if (
|
|
5107
|
-
|
|
5108
|
-
|
|
5109
|
-
|
|
5110
|
-
|
|
5111
|
-
|
|
5112
|
-
|
|
5113
|
-
|
|
5114
|
-
|
|
5115
|
-
|
|
5116
|
-
|
|
5117
|
-
|
|
5118
|
-
|
|
5112
|
+
if (e.shiftKey) {
|
|
5113
|
+
const _nodes = [
|
|
5114
|
+
...selection.value.filter((v) => !v.equal(props.node)),
|
|
5115
|
+
props.node
|
|
5116
|
+
];
|
|
5117
|
+
let min;
|
|
5118
|
+
let max;
|
|
5119
|
+
_nodes.forEach((el) => {
|
|
5120
|
+
const index = nodeIndexMap.get(el.id);
|
|
5121
|
+
if (index !== void 0) {
|
|
5122
|
+
min = min === void 0 ? index : Math.min(min, index);
|
|
5123
|
+
max = max === void 0 ? index : Math.max(max, index);
|
|
5124
|
+
}
|
|
5125
|
+
});
|
|
5126
|
+
if (min !== void 0 && max !== void 0) {
|
|
5127
|
+
let _selection = nodes.value.slice(min, max + 1);
|
|
5128
|
+
const result = new Set(_selection.map((node) => node.id));
|
|
5129
|
+
const parents = /* @__PURE__ */ new Set();
|
|
5130
|
+
_selection.forEach((node) => node.parent && parents.add(node.parent));
|
|
5131
|
+
parents.forEach((parent) => {
|
|
5132
|
+
if (parent.children.every((ch) => result.has(ch.id))) {
|
|
5133
|
+
const ids = new Set(parent.children.map((ch) => ch.id));
|
|
5134
|
+
_selection = [
|
|
5135
|
+
..._selection.filter((v) => !ids.has(v.id)),
|
|
5136
|
+
parent
|
|
5137
|
+
];
|
|
5119
5138
|
}
|
|
5120
5139
|
});
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
if (parent.children.every((ch) => result.has(ch.id))) {
|
|
5128
|
-
const ids = new Set(parent.children.map((ch) => ch.id));
|
|
5129
|
-
_selection = [
|
|
5130
|
-
..._selection.filter((v) => !ids.has(v.id)),
|
|
5131
|
-
parent
|
|
5132
|
-
];
|
|
5133
|
-
}
|
|
5134
|
-
});
|
|
5135
|
-
selection.value = _selection;
|
|
5136
|
-
}
|
|
5137
|
-
} else if (e.ctrlKey || e.metaKey) {
|
|
5138
|
-
const filtered = selection.value.filter((v) => !v.equal(props.node));
|
|
5139
|
-
if (filtered.length !== selection.value.length) {
|
|
5140
|
-
selection.value = filtered;
|
|
5141
|
-
} else {
|
|
5142
|
-
selection.value = [...filtered, props.node];
|
|
5143
|
-
}
|
|
5140
|
+
selection.value = _selection;
|
|
5141
|
+
}
|
|
5142
|
+
} else if (e.ctrlKey || e.metaKey) {
|
|
5143
|
+
const filtered = selection.value.filter((v) => !v.equal(props.node));
|
|
5144
|
+
if (filtered.length !== selection.value.length) {
|
|
5145
|
+
selection.value = filtered;
|
|
5144
5146
|
} else {
|
|
5145
|
-
selection.value = [props.node];
|
|
5147
|
+
selection.value = [...filtered, props.node];
|
|
5146
5148
|
}
|
|
5149
|
+
} else {
|
|
5150
|
+
selection.value = [props.node];
|
|
5147
5151
|
}
|
|
5148
5152
|
nextTick().then(() => {
|
|
5149
5153
|
selecting.value = false;
|
|
@@ -8275,7 +8279,7 @@ function round(cx, cy, sx, sy, ex, ey, verts, clockwise) {
|
|
|
8275
8279
|
}
|
|
8276
8280
|
class Curve {
|
|
8277
8281
|
arcLengthDivision = 200;
|
|
8278
|
-
|
|
8282
|
+
_lengths = [];
|
|
8279
8283
|
getPointAt(u, output = new Vector2()) {
|
|
8280
8284
|
return this.getPoint(this.getUToTMapping(u), output);
|
|
8281
8285
|
}
|
|
@@ -8353,10 +8357,10 @@ class Curve {
|
|
|
8353
8357
|
return lengths[lengths.length - 1];
|
|
8354
8358
|
}
|
|
8355
8359
|
getLengths() {
|
|
8356
|
-
if (
|
|
8360
|
+
if (this._lengths.length !== this.arcLengthDivision + 1) {
|
|
8357
8361
|
this.updateLengths();
|
|
8358
8362
|
}
|
|
8359
|
-
return this.
|
|
8363
|
+
return this._lengths;
|
|
8360
8364
|
}
|
|
8361
8365
|
updateLengths() {
|
|
8362
8366
|
const divisions = this.arcLengthDivision;
|
|
@@ -8367,7 +8371,7 @@ class Curve {
|
|
|
8367
8371
|
arcLengths.push(sum);
|
|
8368
8372
|
prev = current;
|
|
8369
8373
|
}
|
|
8370
|
-
this.
|
|
8374
|
+
this._lengths = arcLengths;
|
|
8371
8375
|
}
|
|
8372
8376
|
getUToTMapping(u, distance2) {
|
|
8373
8377
|
const lengths = this.getLengths();
|
|
@@ -8392,14 +8396,14 @@ class Curve {
|
|
|
8392
8396
|
break;
|
|
8393
8397
|
}
|
|
8394
8398
|
}
|
|
8395
|
-
i = high;
|
|
8399
|
+
i = Math.max(0, high);
|
|
8396
8400
|
if (lengths[i] === targetLen) {
|
|
8397
8401
|
return i / (lengthsLen - 1);
|
|
8398
8402
|
}
|
|
8399
8403
|
const before = lengths[i];
|
|
8400
8404
|
const after = lengths[i + 1];
|
|
8401
8405
|
const segmentLength = after - before;
|
|
8402
|
-
const segmentFraction = (targetLen - before) / segmentLength;
|
|
8406
|
+
const segmentFraction = Math.max(0, (targetLen - before) / segmentLength);
|
|
8403
8407
|
return (i + segmentFraction) / (lengthsLen - 1);
|
|
8404
8408
|
}
|
|
8405
8409
|
getTangent(t, output = new Vector2()) {
|
|
@@ -9061,13 +9065,19 @@ class CompositeCurve extends Curve {
|
|
|
9061
9065
|
}
|
|
9062
9066
|
return output;
|
|
9063
9067
|
}
|
|
9068
|
+
getLengths() {
|
|
9069
|
+
if (this._lengths.length !== this.curves.length) {
|
|
9070
|
+
this.updateLengths();
|
|
9071
|
+
}
|
|
9072
|
+
return this._lengths;
|
|
9073
|
+
}
|
|
9064
9074
|
updateLengths() {
|
|
9065
|
-
const
|
|
9075
|
+
const lengths = [];
|
|
9066
9076
|
for (let i = 0, sum = 0, len = this.curves.length; i < len; i++) {
|
|
9067
9077
|
sum += this.curves[i].getLength();
|
|
9068
|
-
|
|
9078
|
+
lengths.push(sum);
|
|
9069
9079
|
}
|
|
9070
|
-
this.
|
|
9080
|
+
this._lengths = lengths;
|
|
9071
9081
|
}
|
|
9072
9082
|
getControlPointRefs() {
|
|
9073
9083
|
return this.curves.flatMap((curve) => curve.getControlPointRefs());
|
|
@@ -9739,28 +9749,26 @@ class Path2D extends CompositeCurve {
|
|
|
9739
9749
|
return this;
|
|
9740
9750
|
}
|
|
9741
9751
|
addPath(path) {
|
|
9742
|
-
const
|
|
9743
|
-
if (
|
|
9744
|
-
this
|
|
9752
|
+
const curvePaths = path instanceof Path2D ? path.curves : [path];
|
|
9753
|
+
if (curvePaths.filter((curvePath) => curvePath.curves.length).length === 0) {
|
|
9754
|
+
return this;
|
|
9745
9755
|
}
|
|
9746
|
-
if (
|
|
9747
|
-
this.curves.
|
|
9748
|
-
|
|
9749
|
-
|
|
9750
|
-
|
|
9751
|
-
this.curves.push(path);
|
|
9756
|
+
if (!this.currentCurve.curves.length) {
|
|
9757
|
+
const index = this.curves.findIndex((v) => v === this.currentCurve);
|
|
9758
|
+
if (index > -1) {
|
|
9759
|
+
this.curves.splice(index, 1);
|
|
9760
|
+
}
|
|
9752
9761
|
}
|
|
9753
|
-
this.curves.push(
|
|
9762
|
+
this.curves.push(...curvePaths.map((v) => v.clone()));
|
|
9763
|
+
this.currentCurve = this.curves[this.curves.length - 1];
|
|
9754
9764
|
return this;
|
|
9755
9765
|
}
|
|
9756
9766
|
closePath() {
|
|
9757
9767
|
const startPoint = this.startPoint;
|
|
9758
|
-
if (startPoint) {
|
|
9768
|
+
if (startPoint && this.currentCurve.curves.length) {
|
|
9759
9769
|
this.currentCurve.closePath();
|
|
9760
|
-
|
|
9761
|
-
|
|
9762
|
-
this.curves.push(this.currentCurve);
|
|
9763
|
-
}
|
|
9770
|
+
this.currentCurve = new CurvePath().moveTo(startPoint.x, startPoint.y);
|
|
9771
|
+
this.curves.push(this.currentCurve);
|
|
9764
9772
|
}
|
|
9765
9773
|
return this;
|
|
9766
9774
|
}
|
|
@@ -10073,30 +10081,43 @@ class Path2D extends CompositeCurve {
|
|
|
10073
10081
|
}
|
|
10074
10082
|
const _pen = definePlugin((editor) => {
|
|
10075
10083
|
const {
|
|
10076
|
-
addElement
|
|
10084
|
+
addElement,
|
|
10085
|
+
renderEngine,
|
|
10086
|
+
activeDrawingTool,
|
|
10087
|
+
getGlobalPointer,
|
|
10088
|
+
state
|
|
10077
10089
|
} = editor;
|
|
10078
|
-
let pening = false;
|
|
10079
10090
|
let el;
|
|
10080
|
-
let
|
|
10091
|
+
let currentPath;
|
|
10092
|
+
let currentLine;
|
|
10093
|
+
const update = () => {
|
|
10094
|
+
if (el && currentPath) {
|
|
10095
|
+
el.shape.paths = [
|
|
10096
|
+
{ data: currentPath.toData() }
|
|
10097
|
+
];
|
|
10098
|
+
const box = currentPath.getBoundingBox();
|
|
10099
|
+
el.style.left = box.left;
|
|
10100
|
+
el.style.top = box.top;
|
|
10101
|
+
el.style.width = box.width;
|
|
10102
|
+
el.style.height = box.height;
|
|
10103
|
+
}
|
|
10104
|
+
};
|
|
10081
10105
|
return {
|
|
10082
10106
|
name: "mce:pen",
|
|
10083
10107
|
drawingTools: [
|
|
10084
10108
|
{
|
|
10085
10109
|
name: "pen",
|
|
10086
10110
|
handle: (start) => {
|
|
10087
|
-
if (
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
el.style.width = box.width;
|
|
10097
|
-
el.style.height = box.height;
|
|
10111
|
+
if (el) {
|
|
10112
|
+
if (currentPath) {
|
|
10113
|
+
currentLine = new LineCurve(
|
|
10114
|
+
new Vector2(start.x, start.y),
|
|
10115
|
+
new Vector2(start.x, start.y)
|
|
10116
|
+
);
|
|
10117
|
+
currentPath.currentCurve.addCurve(currentLine);
|
|
10118
|
+
update();
|
|
10119
|
+
}
|
|
10098
10120
|
} else {
|
|
10099
|
-
pening = true;
|
|
10100
10121
|
el = addElement({
|
|
10101
10122
|
name: "pen",
|
|
10102
10123
|
outline: {
|
|
@@ -10109,11 +10130,30 @@ const _pen = definePlugin((editor) => {
|
|
|
10109
10130
|
inPptIs: "Shape"
|
|
10110
10131
|
}
|
|
10111
10132
|
}, {
|
|
10112
|
-
active: true,
|
|
10113
10133
|
position: start
|
|
10114
10134
|
});
|
|
10115
|
-
|
|
10116
|
-
|
|
10135
|
+
currentPath = new Path2D();
|
|
10136
|
+
currentLine = new LineCurve(
|
|
10137
|
+
new Vector2(start.x, start.y),
|
|
10138
|
+
new Vector2(start.x, start.y)
|
|
10139
|
+
);
|
|
10140
|
+
currentPath.currentCurve.addCurve(currentLine);
|
|
10141
|
+
const onMove = () => {
|
|
10142
|
+
const move = getGlobalPointer();
|
|
10143
|
+
if (currentLine && move) {
|
|
10144
|
+
currentLine.p2.x = move.x;
|
|
10145
|
+
currentLine.p2.y = move.y;
|
|
10146
|
+
update();
|
|
10147
|
+
}
|
|
10148
|
+
};
|
|
10149
|
+
renderEngine.value.on("pointermove", onMove);
|
|
10150
|
+
const stop = watch([state, activeDrawingTool], () => {
|
|
10151
|
+
renderEngine.value.off("pointermove", onMove);
|
|
10152
|
+
stop();
|
|
10153
|
+
el = void 0;
|
|
10154
|
+
currentPath = void 0;
|
|
10155
|
+
currentLine = void 0;
|
|
10156
|
+
});
|
|
10117
10157
|
}
|
|
10118
10158
|
}
|
|
10119
10159
|
},
|
|
@@ -10134,22 +10174,20 @@ const _pen = definePlugin((editor) => {
|
|
|
10134
10174
|
}, {
|
|
10135
10175
|
position: start
|
|
10136
10176
|
});
|
|
10137
|
-
const
|
|
10138
|
-
|
|
10177
|
+
const path = new Path2D();
|
|
10178
|
+
path.moveTo(start.x, start.y);
|
|
10139
10179
|
return {
|
|
10140
10180
|
move: (move) => {
|
|
10141
|
-
|
|
10142
|
-
|
|
10181
|
+
path.lineTo(move.x, move.y);
|
|
10182
|
+
path.moveTo(move.x, move.y);
|
|
10143
10183
|
el2.shape.paths = [
|
|
10144
|
-
{ data:
|
|
10184
|
+
{ data: path.toData() }
|
|
10145
10185
|
];
|
|
10146
|
-
const box =
|
|
10186
|
+
const box = path.getBoundingBox();
|
|
10147
10187
|
el2.style.left = box.left;
|
|
10148
10188
|
el2.style.top = box.top;
|
|
10149
10189
|
el2.style.width = box.width;
|
|
10150
10190
|
el2.style.height = box.height;
|
|
10151
|
-
},
|
|
10152
|
-
end: () => {
|
|
10153
10191
|
}
|
|
10154
10192
|
};
|
|
10155
10193
|
}
|
|
@@ -10928,8 +10966,14 @@ const _shape = definePlugin((editor) => {
|
|
|
10928
10966
|
});
|
|
10929
10967
|
return {
|
|
10930
10968
|
move: (move) => {
|
|
10931
|
-
|
|
10932
|
-
|
|
10969
|
+
const minX = Math.min(move.x, start.x);
|
|
10970
|
+
const minY = Math.min(move.y, start.y);
|
|
10971
|
+
const maxX = Math.max(move.x, start.x);
|
|
10972
|
+
const maxY = Math.max(move.y, start.y);
|
|
10973
|
+
el.style.left = minX;
|
|
10974
|
+
el.style.top = minY;
|
|
10975
|
+
el.style.width = maxX - minX;
|
|
10976
|
+
el.style.height = maxY - minY;
|
|
10933
10977
|
},
|
|
10934
10978
|
end: () => {
|
|
10935
10979
|
setActiveDrawingTool(void 0);
|
|
@@ -13435,7 +13479,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
|
13435
13479
|
setup(__props, { expose: __expose }) {
|
|
13436
13480
|
const props = __props;
|
|
13437
13481
|
const {
|
|
13438
|
-
|
|
13482
|
+
elementSelection,
|
|
13439
13483
|
selectionAabbInDrawboard,
|
|
13440
13484
|
isFrame
|
|
13441
13485
|
} = useEditor();
|
|
@@ -13455,7 +13499,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
|
13455
13499
|
return {};
|
|
13456
13500
|
});
|
|
13457
13501
|
const offset2 = computed(() => {
|
|
13458
|
-
if (
|
|
13502
|
+
if (elementSelection.value.some((v) => isFrame(v)) || props.location?.startsWith("bottom")) {
|
|
13459
13503
|
return 32;
|
|
13460
13504
|
}
|
|
13461
13505
|
return 8;
|
|
@@ -13480,7 +13524,7 @@ const _sfc_main$b = /* @__PURE__ */ defineComponent({
|
|
|
13480
13524
|
"model-value": true
|
|
13481
13525
|
}, {
|
|
13482
13526
|
default: withCtx(() => [
|
|
13483
|
-
unref(
|
|
13527
|
+
unref(elementSelection).length > 0 ? renderSlot(_ctx.$slots, "default", { key: 0 }) : createCommentVNode("", true)
|
|
13484
13528
|
]),
|
|
13485
13529
|
_: 3
|
|
13486
13530
|
}, 8, ["style", "location", "middlewares", "offset", "target"]);
|
|
@@ -15111,7 +15155,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
|
15111
15155
|
return (_ctx, _cache) => {
|
|
15112
15156
|
return openBlock(), createBlock(_sfc_main$5, {
|
|
15113
15157
|
class: normalizeClass(["mce-editor", [
|
|
15114
|
-
`mce-editor--${unref(state)}`,
|
|
15158
|
+
unref(state) && `mce-editor--${unref(state)}`,
|
|
15115
15159
|
unref(activeDrawingTool) && `mce-editor--drawing-tool-${unref(activeDrawingTool).name}`,
|
|
15116
15160
|
grabbing.value && `mce-editor--grabbing`
|
|
15117
15161
|
]])
|
package/dist/plugins/pen.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.14.
|
|
4
|
+
"version": "0.14.2",
|
|
5
5
|
"description": "The headless canvas editor framework. only the ESM.",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -61,7 +61,7 @@
|
|
|
61
61
|
"diff": "^8.0.2",
|
|
62
62
|
"file-saver": "^2.0.5",
|
|
63
63
|
"lodash-es": "^4.17.21",
|
|
64
|
-
"modern-canvas": "^0.14.
|
|
64
|
+
"modern-canvas": "^0.14.5",
|
|
65
65
|
"modern-font": "^0.4.4",
|
|
66
66
|
"modern-idoc": "^0.10.6",
|
|
67
67
|
"modern-text": "^1.10.4",
|