@netless/forge-whiteboard 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.
@@ -26240,14 +26240,33 @@ var CurveModel = class extends ElementModel {
26240
26240
  }
26241
26241
  });
26242
26242
  }
26243
+ isPressureValue(value) {
26244
+ return typeof value === "number" && Number.isFinite(value) && value >= 0 && value <= 1;
26245
+ }
26246
+ pointStride(points) {
26247
+ if (points.length >= 3 && points.length % 3 === 0) {
26248
+ let hasPressureSlot = false;
26249
+ for (let i = 2; i < points.length; i += 3) {
26250
+ if (!this.isPressureValue(points[i])) {
26251
+ return 2;
26252
+ }
26253
+ hasPressureSlot = true;
26254
+ }
26255
+ if (hasPressureSlot) {
26256
+ return 3;
26257
+ }
26258
+ }
26259
+ return 2;
26260
+ }
26243
26261
  matrixedPoints() {
26244
26262
  const points = this.localPoints.length === 0 ? this.points : this.localPoints;
26245
26263
  const matrix = new this.scope.Matrix(this.pointsMatrix);
26246
26264
  const output = [];
26247
- for (let i = 0, len = points.length; i < len; i += 3) {
26265
+ const stride = this.pointStride(points);
26266
+ for (let i = 0, len = points.length; i + 1 < len; i += stride) {
26248
26267
  const p = new this.scope.Point(points[i], points[i + 1]);
26249
26268
  const tp = p.transform(matrix);
26250
- const pressure = points[i + 2] ?? 0;
26269
+ const pressure = stride === 3 ? points[i + 2] ?? 0 : 0;
26251
26270
  output.push([tp.x, tp.y, pressure]);
26252
26271
  }
26253
26272
  return output;
@@ -26323,11 +26342,13 @@ var CurveModel = class extends ElementModel {
26323
26342
  }
26324
26343
  liveCursorPoint() {
26325
26344
  const yArray = this.root.get(ElementModel.KEYS.points);
26326
- if (yArray.length < 3) {
26345
+ const points = yArray.toArray();
26346
+ const stride = this.pointStride(points);
26347
+ if (points.length < stride) {
26327
26348
  return null;
26328
26349
  }
26329
- const len = yArray.length;
26330
- const point = new this.scope.Point(yArray.get(len - 3), yArray.get(len - 2));
26350
+ const len = points.length;
26351
+ const point = new this.scope.Point(points[len - stride], points[len - stride + 1]);
26331
26352
  return point.transform(new this.scope.Matrix(this.pointsMatrix));
26332
26353
  }
26333
26354
  onStyleKeyUpdate(key) {