@netless/forge-slide 1.1.4 → 1.1.5

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/slide.js CHANGED
@@ -61544,14 +61544,33 @@ var CurveModel = class extends ElementModel {
61544
61544
  }
61545
61545
  });
61546
61546
  }
61547
+ isPressureValue(value) {
61548
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
61549
+ }
61550
+ pointStride(points) {
61551
+ if (points.length >= 3 && points.length % 3 === 0) {
61552
+ let hasPressureSlot = false;
61553
+ for (let i = 2; i < points.length; i += 3) {
61554
+ if (!this.isPressureValue(points[i])) {
61555
+ return 2;
61556
+ }
61557
+ hasPressureSlot = true;
61558
+ }
61559
+ if (hasPressureSlot) {
61560
+ return 3;
61561
+ }
61562
+ }
61563
+ return 2;
61564
+ }
61547
61565
  matrixedPoints() {
61548
61566
  const points = this.localPoints.length === 0 ? this.points : this.localPoints;
61549
61567
  const matrix = new this.scope.Matrix(this.pointsMatrix);
61550
61568
  const output = [];
61551
- for (let i = 0, len = points.length; i < len; i += 3) {
61569
+ const stride = this.pointStride(points);
61570
+ for (let i = 0, len = points.length; i + 1 < len; i += stride) {
61552
61571
  const p = new this.scope.Point(points[i], points[i + 1]);
61553
61572
  const tp = p.transform(matrix);
61554
- const pressure = points[i + 2] ?? 0;
61573
+ const pressure = stride === 3 ? points[i + 2] ?? 0 : 0;
61555
61574
  output.push([tp.x, tp.y, pressure]);
61556
61575
  }
61557
61576
  return output;
@@ -61627,11 +61646,13 @@ var CurveModel = class extends ElementModel {
61627
61646
  }
61628
61647
  liveCursorPoint() {
61629
61648
  const yArray = this.root.get(ElementModel.KEYS.points);
61630
- if (yArray.length < 3) {
61649
+ const points = yArray.toArray();
61650
+ const stride = this.pointStride(points);
61651
+ if (points.length < stride) {
61631
61652
  return null;
61632
61653
  }
61633
- const len = yArray.length;
61634
- const point = new this.scope.Point(yArray.get(len - 3), yArray.get(len - 2));
61654
+ const len = points.length;
61655
+ const point = new this.scope.Point(points[len - stride], points[len - stride + 1]);
61635
61656
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
61636
61657
  }
61637
61658
  onStyleKeyUpdate(key) {