@netless/forge-slide 1.1.4 → 1.2.0-beta.0
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.esm.js +79 -11
- package/dist/slide.esm.js.map +2 -2
- package/dist/slide.js +79 -11
- package/dist/slide.js.map +2 -2
- package/package.json +3 -3
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
|
-
|
|
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
|
-
|
|
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 =
|
|
61634
|
-
const point = new this.scope.Point(
|
|
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) {
|
|
@@ -63254,6 +63275,7 @@ var ImageModel = class extends ElementModel {
|
|
|
63254
63275
|
}
|
|
63255
63276
|
if (!this.imageSets.querySelector(`[id='${this.uuid}']`)) {
|
|
63256
63277
|
const img = document.createElement("img");
|
|
63278
|
+
img.crossOrigin = "anonymous";
|
|
63257
63279
|
img.src = this.src;
|
|
63258
63280
|
img.id = this.uuid;
|
|
63259
63281
|
this.imageSets.appendChild(img);
|
|
@@ -63458,14 +63480,55 @@ var RenderableModel = class extends import_eventemitter3.default {
|
|
|
63458
63480
|
const model = new ImageModel(yMap, this.scope, this.imageSets, this.liveCursor, this.isPerformanceMode);
|
|
63459
63481
|
model.bindObserver();
|
|
63460
63482
|
model.root.set("src", src);
|
|
63461
|
-
|
|
63483
|
+
model.ownerId = this.userManager.selfId;
|
|
63484
|
+
this.fitImageToViewport(src, model);
|
|
63485
|
+
}
|
|
63486
|
+
fitImageToViewport(src, model) {
|
|
63462
63487
|
const center = this.scope.project.view.center;
|
|
63463
|
-
|
|
63488
|
+
const fallbackMatrix = new this.scope.Matrix();
|
|
63489
|
+
fallbackMatrix.translate({
|
|
63464
63490
|
x: center.x,
|
|
63465
63491
|
y: center.y
|
|
63466
63492
|
});
|
|
63467
|
-
|
|
63468
|
-
|
|
63493
|
+
this.setElementPointsMatrix(model, fallbackMatrix);
|
|
63494
|
+
const img = document.createElement("img");
|
|
63495
|
+
img.crossOrigin = "anonymous";
|
|
63496
|
+
img.onload = () => {
|
|
63497
|
+
const naturalWidth = img.naturalWidth || img.width;
|
|
63498
|
+
const naturalHeight = img.naturalHeight || img.height;
|
|
63499
|
+
if (naturalWidth <= 0 || naturalHeight <= 0) {
|
|
63500
|
+
return;
|
|
63501
|
+
}
|
|
63502
|
+
const viewportBounds = this.scope.project.view.bounds;
|
|
63503
|
+
const maxWidth = viewportBounds.width * 2 / 3;
|
|
63504
|
+
const maxHeight = viewportBounds.height * 2 / 3;
|
|
63505
|
+
const fitScale = Math.min(maxWidth / naturalWidth, maxHeight / naturalHeight, 1);
|
|
63506
|
+
const nextMatrix = new this.scope.Matrix();
|
|
63507
|
+
nextMatrix.translate({
|
|
63508
|
+
x: center.x,
|
|
63509
|
+
y: center.y
|
|
63510
|
+
});
|
|
63511
|
+
if (fitScale > 0 && Number.isFinite(fitScale)) {
|
|
63512
|
+
nextMatrix.scale(fitScale);
|
|
63513
|
+
}
|
|
63514
|
+
this.setElementPointsMatrix(model, nextMatrix);
|
|
63515
|
+
};
|
|
63516
|
+
img.onerror = () => {
|
|
63517
|
+
(0, import_forge_room2.log)("[@netless/forge-whiteboard] failed to preload image for viewport fitting", {
|
|
63518
|
+
src
|
|
63519
|
+
}, "warn");
|
|
63520
|
+
};
|
|
63521
|
+
img.src = src;
|
|
63522
|
+
}
|
|
63523
|
+
setElementPointsMatrix(model, matrix) {
|
|
63524
|
+
const values = [matrix.a, matrix.b, matrix.c, matrix.d, matrix.tx, matrix.ty];
|
|
63525
|
+
if (model.root.doc) {
|
|
63526
|
+
model.root.doc.transact(() => {
|
|
63527
|
+
model.root.set(ElementModel.KEYS.pointsMatrix, values);
|
|
63528
|
+
}, elementsUndoOrigin);
|
|
63529
|
+
} else {
|
|
63530
|
+
model.root.set(ElementModel.KEYS.pointsMatrix, values);
|
|
63531
|
+
}
|
|
63469
63532
|
}
|
|
63470
63533
|
createCurve() {
|
|
63471
63534
|
let shadow = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : false;
|
|
@@ -68285,9 +68348,14 @@ var WhiteboardApplication = class _WhiteboardApplication extends import_forge_ro
|
|
|
68285
68348
|
this.snapshotScope.view.matrix.scale(scale, this.paperScope.project.view.bounds.topLeft);
|
|
68286
68349
|
this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone().multiply(scale);
|
|
68287
68350
|
}
|
|
68288
|
-
return new Promise((resolve) => {
|
|
68351
|
+
return new Promise((resolve, reject) => {
|
|
68289
68352
|
setTimeout(() => {
|
|
68290
|
-
|
|
68353
|
+
try {
|
|
68354
|
+
const res = this.snapshotScope.view.element.toDataURL("image/png");
|
|
68355
|
+
resolve(res);
|
|
68356
|
+
} catch (error) {
|
|
68357
|
+
reject(error);
|
|
68358
|
+
}
|
|
68291
68359
|
}, 32);
|
|
68292
68360
|
});
|
|
68293
68361
|
}
|