mce 0.18.1 → 0.18.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 +69 -53
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -858,7 +858,7 @@ function signedArea(data, start, end, dim) {
|
|
|
858
858
|
return sum;
|
|
859
859
|
}
|
|
860
860
|
//#endregion
|
|
861
|
-
//#region ../../node_modules/.pnpm/modern-path2d@1.
|
|
861
|
+
//#region ../../node_modules/.pnpm/modern-path2d@1.6.0/node_modules/modern-path2d/dist/index.mjs
|
|
862
862
|
function drawPoint(ctx, x, y, options = {}) {
|
|
863
863
|
const { radius = 1 } = options;
|
|
864
864
|
ctx.moveTo(x, y);
|
|
@@ -1027,9 +1027,7 @@ var Vector2 = class Vector2 {
|
|
|
1027
1027
|
x: 0,
|
|
1028
1028
|
y: 0
|
|
1029
1029
|
}) {
|
|
1030
|
-
|
|
1031
|
-
const y = sy < 0 ? origin.y - this._y + origin.y : this._y;
|
|
1032
|
-
return this.set(x * Math.abs(sx), y * Math.abs(sy));
|
|
1030
|
+
return this.set(origin.x + (this._x - origin.x) * sx, origin.y + (this._y - origin.y) * sy);
|
|
1033
1031
|
}
|
|
1034
1032
|
skew(ax, ay = 0, origin = {
|
|
1035
1033
|
x: 0,
|
|
@@ -2342,8 +2340,11 @@ function getReflection(a, b) {
|
|
|
2342
2340
|
function svgPathCommandsAddToPath2D(commands, path) {
|
|
2343
2341
|
const current = new Vector2();
|
|
2344
2342
|
const control = new Vector2();
|
|
2343
|
+
let prevType = "";
|
|
2345
2344
|
for (let i = 0, l = commands.length; i < l; i++) {
|
|
2346
2345
|
const cmd = commands[i];
|
|
2346
|
+
if ((cmd.type === "s" || cmd.type === "S") && !"CcSs".includes(prevType)) control.copyFrom(current);
|
|
2347
|
+
else if ((cmd.type === "t" || cmd.type === "T") && !"QqTt".includes(prevType)) control.copyFrom(current);
|
|
2347
2348
|
if (cmd.type === "m" || cmd.type === "M") {
|
|
2348
2349
|
if (cmd.type === "m") current.add(cmd);
|
|
2349
2350
|
else current.copyFrom(cmd);
|
|
@@ -2424,6 +2425,7 @@ function svgPathCommandsAddToPath2D(commands, path) {
|
|
|
2424
2425
|
if (path.startPoint) current.copyFrom(path.startPoint);
|
|
2425
2426
|
path.closePath();
|
|
2426
2427
|
} else console.warn("Unsupported commands", cmd);
|
|
2428
|
+
prevType = cmd.type;
|
|
2427
2429
|
}
|
|
2428
2430
|
}
|
|
2429
2431
|
function svgPathCommandsToData(commands) {
|
|
@@ -3194,8 +3196,11 @@ function eigenDecomposition(A, B, C) {
|
|
|
3194
3196
|
rt1 = .5 * (sm + rt);
|
|
3195
3197
|
t = 1 / rt1;
|
|
3196
3198
|
rt2 = A * t * C - B * t * B;
|
|
3197
|
-
} else if (sm < 0)
|
|
3198
|
-
|
|
3199
|
+
} else if (sm < 0) {
|
|
3200
|
+
rt2 = .5 * (sm - rt);
|
|
3201
|
+
t = 1 / rt2;
|
|
3202
|
+
rt1 = A * t * C - B * t * B;
|
|
3203
|
+
} else {
|
|
3199
3204
|
rt1 = .5 * rt;
|
|
3200
3205
|
rt2 = -.5 * rt;
|
|
3201
3206
|
}
|
|
@@ -3339,17 +3344,19 @@ var CompositeCurve = class CompositeCurve extends Curve {
|
|
|
3339
3344
|
getPoint(t, output = new Vector2()) {
|
|
3340
3345
|
const d = t * this.getLength();
|
|
3341
3346
|
const lengths = this.getLengths();
|
|
3342
|
-
|
|
3343
|
-
|
|
3344
|
-
|
|
3345
|
-
|
|
3346
|
-
|
|
3347
|
-
|
|
3348
|
-
|
|
3349
|
-
|
|
3350
|
-
|
|
3351
|
-
|
|
3352
|
-
|
|
3347
|
+
const n = lengths.length;
|
|
3348
|
+
if (n === 0) return output;
|
|
3349
|
+
let lo = 0;
|
|
3350
|
+
let hi = n - 1;
|
|
3351
|
+
while (lo < hi) {
|
|
3352
|
+
const mid = lo + hi >>> 1;
|
|
3353
|
+
if (lengths[mid] < d) lo = mid + 1;
|
|
3354
|
+
else hi = mid;
|
|
3355
|
+
}
|
|
3356
|
+
const diff = lengths[lo] - d;
|
|
3357
|
+
const curve = this.curves[lo];
|
|
3358
|
+
const length = curve.getLength();
|
|
3359
|
+
return curve.getPointAt(length === 0 ? 0 : 1 - diff / length, output);
|
|
3353
3360
|
}
|
|
3354
3361
|
getLengths() {
|
|
3355
3362
|
if (this._lengths.length !== this.curves.length) this.updateLengths();
|
|
@@ -3467,6 +3474,11 @@ var CubicBezierCurve = class CubicBezierCurve extends Curve {
|
|
|
3467
3474
|
];
|
|
3468
3475
|
}
|
|
3469
3476
|
_solveQuadratic(a, b, c) {
|
|
3477
|
+
if (Math.abs(a) < 1e-12) {
|
|
3478
|
+
if (Math.abs(b) < 1e-12) return [];
|
|
3479
|
+
const t = -c / b;
|
|
3480
|
+
return t >= 0 && t <= 1 ? [t] : [];
|
|
3481
|
+
}
|
|
3470
3482
|
const discriminant = b * b - 4 * a * c;
|
|
3471
3483
|
if (discriminant < 0) return [];
|
|
3472
3484
|
const sqrtDiscriminant = Math.sqrt(discriminant);
|
|
@@ -3474,26 +3486,21 @@ var CubicBezierCurve = class CubicBezierCurve extends Curve {
|
|
|
3474
3486
|
}
|
|
3475
3487
|
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
3476
3488
|
const { p1, cp1, cp2, p2 } = this;
|
|
3477
|
-
const dxRoots = this._solveQuadratic(3 * (cp1.x -
|
|
3478
|
-
const dyRoots = this._solveQuadratic(3 * (cp1.y -
|
|
3489
|
+
const dxRoots = this._solveQuadratic(3 * (-p1.x + 3 * cp1.x - 3 * cp2.x + p2.x), 6 * (p1.x - 2 * cp1.x + cp2.x), 3 * (cp1.x - p1.x));
|
|
3490
|
+
const dyRoots = this._solveQuadratic(3 * (-p1.y + 3 * cp1.y - 3 * cp2.y + p2.y), 6 * (p1.y - 2 * cp1.y + cp2.y), 3 * (cp1.y - p1.y));
|
|
3479
3491
|
const tValues = [
|
|
3480
3492
|
0,
|
|
3481
3493
|
1,
|
|
3482
3494
|
...dxRoots,
|
|
3483
3495
|
...dyRoots
|
|
3484
3496
|
];
|
|
3485
|
-
const
|
|
3486
|
-
|
|
3487
|
-
|
|
3488
|
-
|
|
3489
|
-
|
|
3490
|
-
|
|
3491
|
-
|
|
3492
|
-
max.x = Math.max(max.x, point.x);
|
|
3493
|
-
max.y = Math.max(max.y, point.y);
|
|
3494
|
-
}
|
|
3495
|
-
};
|
|
3496
|
-
samplePoints(tValues, 10);
|
|
3497
|
+
for (const t of tValues) {
|
|
3498
|
+
const point = this.getPoint(t);
|
|
3499
|
+
min.x = Math.min(min.x, point.x);
|
|
3500
|
+
min.y = Math.min(min.y, point.y);
|
|
3501
|
+
max.x = Math.max(max.x, point.x);
|
|
3502
|
+
max.y = Math.max(max.y, point.y);
|
|
3503
|
+
}
|
|
3497
3504
|
return {
|
|
3498
3505
|
min: min.finite(),
|
|
3499
3506
|
max: max.finite()
|
|
@@ -3539,7 +3546,7 @@ var EllipseCurve = class extends RoundCurve {
|
|
|
3539
3546
|
return this;
|
|
3540
3547
|
}
|
|
3541
3548
|
};
|
|
3542
|
-
var
|
|
3549
|
+
var PolygonCurve = class extends CompositeCurve {};
|
|
3543
3550
|
var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
|
|
3544
3551
|
constructor(p1 = new Vector2(), cp = new Vector2(), p2 = new Vector2()) {
|
|
3545
3552
|
super();
|
|
@@ -3567,14 +3574,22 @@ var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
|
|
|
3567
3574
|
}
|
|
3568
3575
|
getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
|
|
3569
3576
|
const { p1, cp, p2 } = this;
|
|
3570
|
-
const
|
|
3571
|
-
|
|
3572
|
-
|
|
3573
|
-
|
|
3574
|
-
|
|
3575
|
-
|
|
3576
|
-
|
|
3577
|
-
|
|
3577
|
+
const extrema = (a, b, c) => {
|
|
3578
|
+
const denom = a - 2 * b + c;
|
|
3579
|
+
if (Math.abs(denom) < 1e-12) return null;
|
|
3580
|
+
const t = (a - b) / denom;
|
|
3581
|
+
return t > 0 && t < 1 ? t : null;
|
|
3582
|
+
};
|
|
3583
|
+
const tx = extrema(p1.x, cp.x, p2.x);
|
|
3584
|
+
const ty = extrema(p1.y, cp.y, p2.y);
|
|
3585
|
+
const xs = [p1.x, p2.x];
|
|
3586
|
+
const ys = [p1.y, p2.y];
|
|
3587
|
+
if (tx !== null) xs.push(quadraticBezier(tx, p1.x, cp.x, p2.x));
|
|
3588
|
+
if (ty !== null) ys.push(quadraticBezier(ty, p1.y, cp.y, p2.y));
|
|
3589
|
+
min.x = Math.min(min.x, ...xs);
|
|
3590
|
+
min.y = Math.min(min.y, ...ys);
|
|
3591
|
+
max.x = Math.max(max.x, ...xs);
|
|
3592
|
+
max.y = Math.max(max.y, ...ys);
|
|
3578
3593
|
return {
|
|
3579
3594
|
min: min.finite(),
|
|
3580
3595
|
max: max.finite()
|
|
@@ -3608,7 +3623,7 @@ var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
|
|
|
3608
3623
|
return this;
|
|
3609
3624
|
}
|
|
3610
3625
|
};
|
|
3611
|
-
var RectangleCurve = class extends
|
|
3626
|
+
var RectangleCurve = class extends PolygonCurve {
|
|
3612
3627
|
constructor(x = 0, y = 0, width = 0, height = 0) {
|
|
3613
3628
|
super();
|
|
3614
3629
|
this.x = x;
|
|
@@ -3950,16 +3965,11 @@ var Path2D = class Path2D extends CompositeCurve {
|
|
|
3950
3965
|
return this;
|
|
3951
3966
|
}
|
|
3952
3967
|
moveTo(x, y) {
|
|
3953
|
-
if (
|
|
3954
|
-
|
|
3955
|
-
|
|
3956
|
-
})) {
|
|
3957
|
-
if (this.currentCurve.curves.length) {
|
|
3958
|
-
this.currentCurve = new CurvePath();
|
|
3959
|
-
this.curves.push(this.currentCurve);
|
|
3960
|
-
}
|
|
3961
|
-
this.currentCurve.moveTo(x, y);
|
|
3968
|
+
if (this.currentCurve.curves.length) {
|
|
3969
|
+
this.currentCurve = new CurvePath();
|
|
3970
|
+
this.curves.push(this.currentCurve);
|
|
3962
3971
|
}
|
|
3972
|
+
this.currentCurve.moveTo(x, y);
|
|
3963
3973
|
return this;
|
|
3964
3974
|
}
|
|
3965
3975
|
lineTo(x, y) {
|
|
@@ -4366,6 +4376,8 @@ function storeState(idbPersistence, forceStore = true) {
|
|
|
4366
4376
|
});
|
|
4367
4377
|
}
|
|
4368
4378
|
var IndexeddbProvider = class extends Observable {
|
|
4379
|
+
name;
|
|
4380
|
+
doc;
|
|
4369
4381
|
db = null;
|
|
4370
4382
|
synced = false;
|
|
4371
4383
|
whenSynced;
|
|
@@ -4450,6 +4462,7 @@ var IndexeddbProvider = class extends Observable {
|
|
|
4450
4462
|
//#endregion
|
|
4451
4463
|
//#region src/crdt/YDoc.ts
|
|
4452
4464
|
var YDoc = class extends Observable {
|
|
4465
|
+
id;
|
|
4453
4466
|
_transacting;
|
|
4454
4467
|
_yDoc;
|
|
4455
4468
|
_yProps;
|
|
@@ -14846,12 +14859,12 @@ var TextEditor_default = /* @__PURE__ */ defineComponent({
|
|
|
14846
14859
|
}
|
|
14847
14860
|
});
|
|
14848
14861
|
//#endregion
|
|
14849
|
-
//#region \0@oxc-project+runtime@0.
|
|
14862
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/decorateMetadata.js
|
|
14850
14863
|
function __decorateMetadata(k, v) {
|
|
14851
14864
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
14852
14865
|
}
|
|
14853
14866
|
//#endregion
|
|
14854
|
-
//#region \0@oxc-project+runtime@0.
|
|
14867
|
+
//#region \0@oxc-project+runtime@0.130.0/helpers/decorate.js
|
|
14855
14868
|
function __decorate(decorators, target, key, desc) {
|
|
14856
14869
|
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
|
|
14857
14870
|
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
|
|
@@ -15239,7 +15252,10 @@ var TextEditor = class extends HTMLElement {
|
|
|
15239
15252
|
}
|
|
15240
15253
|
_findNearest(options) {
|
|
15241
15254
|
const isVertical = this.text.isVertical;
|
|
15242
|
-
const {
|
|
15255
|
+
const { boundingBox } = this.text;
|
|
15256
|
+
const { xWeight = 1, yWeight = 1 } = options;
|
|
15257
|
+
const x = options.x + boundingBox.left;
|
|
15258
|
+
const y = options.y + boundingBox.top;
|
|
15243
15259
|
const char = this._chars.reduce((prev, current, index) => {
|
|
15244
15260
|
const diff = Math.abs(current.left + current.width / 2 - x) * xWeight + Math.abs(current.top + current.height / 2 - y) * yWeight;
|
|
15245
15261
|
if (diff < prev.diff) return {
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mce",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.18.
|
|
4
|
+
"version": "0.18.2",
|
|
5
5
|
"description": "A headless infinite canvas editor framework built on WebGL rendering, supports exporting to image, video, and PPT. Only the ESM.",
|
|
6
6
|
"author": "wxm",
|
|
7
7
|
"license": "MIT",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
"modern-canvas": "^0.17.2",
|
|
64
64
|
"modern-font": "^0.5.0",
|
|
65
65
|
"modern-idoc": "^0.11.4",
|
|
66
|
-
"modern-text": "^1.11.
|
|
66
|
+
"modern-text": "^1.11.1",
|
|
67
67
|
"y-protocols": "^1.0.7",
|
|
68
68
|
"yjs": "^13.6.30"
|
|
69
69
|
},
|
|
@@ -86,7 +86,7 @@
|
|
|
86
86
|
},
|
|
87
87
|
"devDependencies": {
|
|
88
88
|
"@types/lodash-es": "^4.17.12",
|
|
89
|
-
"@vitejs/plugin-vue": "^6.0.
|
|
89
|
+
"@vitejs/plugin-vue": "^6.0.7",
|
|
90
90
|
"jiti": "^2.7.0",
|
|
91
91
|
"sass-embedded": "^1.99.0",
|
|
92
92
|
"typedoc": "^0.28.19",
|