@mce/bigesj 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.
Files changed (2) hide show
  1. package/dist/index.js +65 -51
  2. package/package.json +2 -2
package/dist/index.js CHANGED
@@ -1626,7 +1626,7 @@ function signedArea(data, start, end, dim) {
1626
1626
  return sum;
1627
1627
  }
1628
1628
  //#endregion
1629
- //#region ../../node_modules/.pnpm/modern-path2d@1.5.6/node_modules/modern-path2d/dist/index.mjs
1629
+ //#region ../../node_modules/.pnpm/modern-path2d@1.6.0/node_modules/modern-path2d/dist/index.mjs
1630
1630
  function drawPoint(ctx, x, y, options = {}) {
1631
1631
  const { radius = 1 } = options;
1632
1632
  ctx.moveTo(x, y);
@@ -1795,9 +1795,7 @@ var Vector2 = class Vector2 {
1795
1795
  x: 0,
1796
1796
  y: 0
1797
1797
  }) {
1798
- const x = sx < 0 ? origin.x - this._x + origin.x : this._x;
1799
- const y = sy < 0 ? origin.y - this._y + origin.y : this._y;
1800
- return this.set(x * Math.abs(sx), y * Math.abs(sy));
1798
+ return this.set(origin.x + (this._x - origin.x) * sx, origin.y + (this._y - origin.y) * sy);
1801
1799
  }
1802
1800
  skew(ax, ay = 0, origin = {
1803
1801
  x: 0,
@@ -3110,8 +3108,11 @@ function getReflection(a, b) {
3110
3108
  function svgPathCommandsAddToPath2D(commands, path) {
3111
3109
  const current = new Vector2();
3112
3110
  const control = new Vector2();
3111
+ let prevType = "";
3113
3112
  for (let i = 0, l = commands.length; i < l; i++) {
3114
3113
  const cmd = commands[i];
3114
+ if ((cmd.type === "s" || cmd.type === "S") && !"CcSs".includes(prevType)) control.copyFrom(current);
3115
+ else if ((cmd.type === "t" || cmd.type === "T") && !"QqTt".includes(prevType)) control.copyFrom(current);
3115
3116
  if (cmd.type === "m" || cmd.type === "M") {
3116
3117
  if (cmd.type === "m") current.add(cmd);
3117
3118
  else current.copyFrom(cmd);
@@ -3192,6 +3193,7 @@ function svgPathCommandsAddToPath2D(commands, path) {
3192
3193
  if (path.startPoint) current.copyFrom(path.startPoint);
3193
3194
  path.closePath();
3194
3195
  } else console.warn("Unsupported commands", cmd);
3196
+ prevType = cmd.type;
3195
3197
  }
3196
3198
  }
3197
3199
  function svgPathCommandsToData(commands) {
@@ -3572,10 +3574,14 @@ function parsePolylineNode(node) {
3572
3574
  function parseRectNode(node) {
3573
3575
  const x = parseFloatWithUnits(node.getAttribute("x") || 0);
3574
3576
  const y = parseFloatWithUnits(node.getAttribute("y") || 0);
3575
- const rx = parseFloatWithUnits(node.getAttribute("rx") || node.getAttribute("ry") || 0);
3576
- const ry = parseFloatWithUnits(node.getAttribute("ry") || node.getAttribute("rx") || 0);
3577
+ const rxAttr = node.getAttribute("rx");
3578
+ const ryAttr = node.getAttribute("ry");
3579
+ let rx = parseFloatWithUnits(rxAttr ?? ryAttr ?? 0);
3580
+ let ry = parseFloatWithUnits(ryAttr ?? rxAttr ?? 0);
3577
3581
  const w = parseFloatWithUnits(node.getAttribute("width"));
3578
3582
  const h = parseFloatWithUnits(node.getAttribute("height"));
3583
+ rx = Math.max(0, Math.min(rx, w / 2));
3584
+ ry = Math.max(0, Math.min(ry, h / 2));
3579
3585
  const bci = .448084975506;
3580
3586
  const path = new Path2D();
3581
3587
  path.moveTo(x + rx, y);
@@ -4271,8 +4277,11 @@ function eigenDecomposition(A, B, C) {
4271
4277
  rt1 = .5 * (sm + rt);
4272
4278
  t = 1 / rt1;
4273
4279
  rt2 = A * t * C - B * t * B;
4274
- } else if (sm < 0) rt2 = .5 * (sm - rt);
4275
- else {
4280
+ } else if (sm < 0) {
4281
+ rt2 = .5 * (sm - rt);
4282
+ t = 1 / rt2;
4283
+ rt1 = A * t * C - B * t * B;
4284
+ } else {
4276
4285
  rt1 = .5 * rt;
4277
4286
  rt2 = -.5 * rt;
4278
4287
  }
@@ -4416,17 +4425,19 @@ var CompositeCurve = class CompositeCurve extends Curve {
4416
4425
  getPoint(t, output = new Vector2()) {
4417
4426
  const d = t * this.getLength();
4418
4427
  const lengths = this.getLengths();
4419
- let i = 0;
4420
- while (i < lengths.length) {
4421
- if (lengths[i] >= d) {
4422
- const diff = lengths[i] - d;
4423
- const curve = this.curves[i];
4424
- const length = curve.getLength();
4425
- return curve.getPointAt(length === 0 ? 0 : 1 - diff / length, output);
4426
- }
4427
- i++;
4428
+ const n = lengths.length;
4429
+ if (n === 0) return output;
4430
+ let lo = 0;
4431
+ let hi = n - 1;
4432
+ while (lo < hi) {
4433
+ const mid = lo + hi >>> 1;
4434
+ if (lengths[mid] < d) lo = mid + 1;
4435
+ else hi = mid;
4428
4436
  }
4429
- return output;
4437
+ const diff = lengths[lo] - d;
4438
+ const curve = this.curves[lo];
4439
+ const length = curve.getLength();
4440
+ return curve.getPointAt(length === 0 ? 0 : 1 - diff / length, output);
4430
4441
  }
4431
4442
  getLengths() {
4432
4443
  if (this._lengths.length !== this.curves.length) this.updateLengths();
@@ -4544,6 +4555,11 @@ var CubicBezierCurve = class CubicBezierCurve extends Curve {
4544
4555
  ];
4545
4556
  }
4546
4557
  _solveQuadratic(a, b, c) {
4558
+ if (Math.abs(a) < 1e-12) {
4559
+ if (Math.abs(b) < 1e-12) return [];
4560
+ const t = -c / b;
4561
+ return t >= 0 && t <= 1 ? [t] : [];
4562
+ }
4547
4563
  const discriminant = b * b - 4 * a * c;
4548
4564
  if (discriminant < 0) return [];
4549
4565
  const sqrtDiscriminant = Math.sqrt(discriminant);
@@ -4551,26 +4567,21 @@ var CubicBezierCurve = class CubicBezierCurve extends Curve {
4551
4567
  }
4552
4568
  getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
4553
4569
  const { p1, cp1, cp2, p2 } = this;
4554
- const dxRoots = this._solveQuadratic(3 * (cp1.x - p1.x), 6 * (cp2.x - cp1.x), 3 * (p2.x - cp2.x));
4555
- const dyRoots = this._solveQuadratic(3 * (cp1.y - p1.y), 6 * (cp2.y - cp1.y), 3 * (p2.y - cp2.y));
4570
+ 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));
4571
+ 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));
4556
4572
  const tValues = [
4557
4573
  0,
4558
4574
  1,
4559
4575
  ...dxRoots,
4560
4576
  ...dyRoots
4561
4577
  ];
4562
- const samplePoints = (tValues2, precision) => {
4563
- for (const t of tValues2) for (let i = 0; i <= precision; i++) {
4564
- const delta = i / precision - .5;
4565
- const refinedT = Math.min(1, Math.max(0, t + delta));
4566
- const point = this.getPoint(refinedT);
4567
- min.x = Math.min(min.x, point.x);
4568
- min.y = Math.min(min.y, point.y);
4569
- max.x = Math.max(max.x, point.x);
4570
- max.y = Math.max(max.y, point.y);
4571
- }
4572
- };
4573
- samplePoints(tValues, 10);
4578
+ for (const t of tValues) {
4579
+ const point = this.getPoint(t);
4580
+ min.x = Math.min(min.x, point.x);
4581
+ min.y = Math.min(min.y, point.y);
4582
+ max.x = Math.max(max.x, point.x);
4583
+ max.y = Math.max(max.y, point.y);
4584
+ }
4574
4585
  return {
4575
4586
  min: min.finite(),
4576
4587
  max: max.finite()
@@ -4616,7 +4627,7 @@ var EllipseCurve = class extends RoundCurve {
4616
4627
  return this;
4617
4628
  }
4618
4629
  };
4619
- var PloygonCurve = class extends CompositeCurve {};
4630
+ var PolygonCurve = class extends CompositeCurve {};
4620
4631
  var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
4621
4632
  constructor(p1 = new Vector2(), cp = new Vector2(), p2 = new Vector2()) {
4622
4633
  super();
@@ -4644,14 +4655,22 @@ var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
4644
4655
  }
4645
4656
  getMinMax(min = Vector2.MAX, max = Vector2.MIN) {
4646
4657
  const { p1, cp, p2 } = this;
4647
- const x1 = .5 * (p1.x + cp.x);
4648
- const y1 = .5 * (p1.y + cp.y);
4649
- const x2 = .5 * (p1.x + p2.x);
4650
- const y2 = .5 * (p1.y + p2.y);
4651
- min.x = Math.min(min.x, p1.x, p2.x, x1, x2);
4652
- min.y = Math.min(min.y, p1.y, p2.y, y1, y2);
4653
- max.x = Math.max(max.x, p1.x, p2.x, x1, x2);
4654
- max.y = Math.max(max.y, p1.y, p2.y, y1, y2);
4658
+ const extrema = (a, b, c) => {
4659
+ const denom = a - 2 * b + c;
4660
+ if (Math.abs(denom) < 1e-12) return null;
4661
+ const t = (a - b) / denom;
4662
+ return t > 0 && t < 1 ? t : null;
4663
+ };
4664
+ const tx = extrema(p1.x, cp.x, p2.x);
4665
+ const ty = extrema(p1.y, cp.y, p2.y);
4666
+ const xs = [p1.x, p2.x];
4667
+ const ys = [p1.y, p2.y];
4668
+ if (tx !== null) xs.push(quadraticBezier(tx, p1.x, cp.x, p2.x));
4669
+ if (ty !== null) ys.push(quadraticBezier(ty, p1.y, cp.y, p2.y));
4670
+ min.x = Math.min(min.x, ...xs);
4671
+ min.y = Math.min(min.y, ...ys);
4672
+ max.x = Math.max(max.x, ...xs);
4673
+ max.y = Math.max(max.y, ...ys);
4655
4674
  return {
4656
4675
  min: min.finite(),
4657
4676
  max: max.finite()
@@ -4685,7 +4704,7 @@ var QuadraticBezierCurve = class QuadraticBezierCurve extends Curve {
4685
4704
  return this;
4686
4705
  }
4687
4706
  };
4688
- var RectangleCurve = class extends PloygonCurve {
4707
+ var RectangleCurve = class extends PolygonCurve {
4689
4708
  constructor(x = 0, y = 0, width = 0, height = 0) {
4690
4709
  super();
4691
4710
  this.x = x;
@@ -5027,16 +5046,11 @@ var Path2D = class Path2D extends CompositeCurve {
5027
5046
  return this;
5028
5047
  }
5029
5048
  moveTo(x, y) {
5030
- if (!this.currentCurve.currentPoint?.equals({
5031
- x,
5032
- y
5033
- })) {
5034
- if (this.currentCurve.curves.length) {
5035
- this.currentCurve = new CurvePath();
5036
- this.curves.push(this.currentCurve);
5037
- }
5038
- this.currentCurve.moveTo(x, y);
5049
+ if (this.currentCurve.curves.length) {
5050
+ this.currentCurve = new CurvePath();
5051
+ this.curves.push(this.currentCurve);
5039
5052
  }
5053
+ this.currentCurve.moveTo(x, y);
5040
5054
  return this;
5041
5055
  }
5042
5056
  lineTo(x, y) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@mce/bigesj",
3
3
  "type": "module",
4
- "version": "0.18.1",
4
+ "version": "0.18.2",
5
5
  "description": "Plugin for mce",
6
6
  "author": "wxm",
7
7
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  "modern-openxml": "^1.10.1"
50
50
  },
51
51
  "devDependencies": {
52
- "mce": "0.18.1"
52
+ "mce": "0.18.2"
53
53
  },
54
54
  "peerDependencies": {
55
55
  "mce": "^0"