@netless/forge-whiteboard 0.1.5 → 0.1.7
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.
|
@@ -34,6 +34,8 @@ export declare class WhiteboardApplication extends AbstractApplication<Whiteboar
|
|
|
34
34
|
private paperScope;
|
|
35
35
|
private canvasElement;
|
|
36
36
|
private shadowScope;
|
|
37
|
+
private snapshotCanvasElement;
|
|
38
|
+
private snapshotScope;
|
|
37
39
|
private shadowCanvasElement;
|
|
38
40
|
private shadowEmitter;
|
|
39
41
|
private tools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"WhiteboardApplication.d.ts","sourceRoot":"","sources":["../src/WhiteboardApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,
|
|
1
|
+
{"version":3,"file":"WhiteboardApplication.d.ts","sourceRoot":"","sources":["../src/WhiteboardApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,mBAAmB,EAAM,MAAM,qBAAqB,CAAC;AAS7D,OAAO,EAAC,YAAY,EAAE,YAAY,EAAC,MAAM,sBAAsB,CAAC;AAUhE,OAAO,EAAyC,UAAU,EAAC,MAAM,cAAc,CAAC;AAchF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC7B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;CAC/C;AAED,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAC1B,OAAO,GACL,WAAW,GACX,UAAU,GACV,MAAM,GACN,OAAO,GACP,MAAM,GACN,SAAS,GACT,UAAU,GACV,QAAQ,GACR,OAAO,GACP,MAAM,CAAC;AAEb,qBAAa,qBAAsB,SAAQ,mBAAmB,CAAC,gBAAgB,EAAE,UAAU,CAAC;IAExF,MAAM,C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AkB,CAExB;IAEF,OAAO,CAAC,gBAAgB;IAmBxB,OAAO,CAAC,mBAAmB,CAazB;IAEF,OAAO,CAAC,qBAAqB;IAY7B,OAAO,CAAC,mBAAmB,CAUzB;IAEF,OAAO,CAAC,iCAAiC,CAGvC;IAEF,OAAO,CAAC,mBAAmB,CAczB;IAEF,OAAO,CAAC,oBAAoB,CAqD1B;IAEK,SAAS,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,GAAG,OAAO,CAAC,MAAM,GAAG,IAAI,CAAC;IA4C9D,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC;CAexC"}
|
package/dist/whiteboard.esm.js
CHANGED
|
@@ -25362,7 +25362,7 @@ var require_lodash = __commonJS({
|
|
|
25362
25362
|
|
|
25363
25363
|
// src/WhiteboardApplication.ts
|
|
25364
25364
|
var import_paper = __toESM(require_paper_full(), 1);
|
|
25365
|
-
import { AbstractApplication } from "@netless/forge-room";
|
|
25365
|
+
import { AbstractApplication, log as log3 } from "@netless/forge-room";
|
|
25366
25366
|
import * as Y15 from "yjs";
|
|
25367
25367
|
|
|
25368
25368
|
// src/model/RenderableModel.ts
|
|
@@ -27751,7 +27751,7 @@ var ToolbarModel = class extends EventEmitter3 {
|
|
|
27751
27751
|
this.root = root;
|
|
27752
27752
|
this.root.observe(this.handleRootUpdate);
|
|
27753
27753
|
Object.keys(defaultStyle).forEach((key) => {
|
|
27754
|
-
if (!this.root.has(key)) {
|
|
27754
|
+
if (!this.root.has(key) || this.root.get(key) === void 0) {
|
|
27755
27755
|
this.root.set(key, defaultStyle[key]);
|
|
27756
27756
|
}
|
|
27757
27757
|
});
|
|
@@ -29983,6 +29983,8 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
29983
29983
|
paperScope = new import_paper.default.PaperScope();
|
|
29984
29984
|
canvasElement = document.createElement("canvas");
|
|
29985
29985
|
shadowScope = new import_paper.default.PaperScope();
|
|
29986
|
+
snapshotCanvasElement = document.createElement("canvas");
|
|
29987
|
+
snapshotScope = new import_paper.default.PaperScope();
|
|
29986
29988
|
shadowCanvasElement = document.createElement("canvas");
|
|
29987
29989
|
shadowEmitter;
|
|
29988
29990
|
tools;
|
|
@@ -30137,6 +30139,12 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30137
30139
|
this.inputType = type;
|
|
30138
30140
|
this.emitter.emit("inputTypeChange", this.inputType);
|
|
30139
30141
|
};
|
|
30142
|
+
this.emitter.on("error", (errorCode, errorMessage) => {
|
|
30143
|
+
log3("WhiteboardApplicationError", {
|
|
30144
|
+
errorCode,
|
|
30145
|
+
errorMessage
|
|
30146
|
+
});
|
|
30147
|
+
});
|
|
30140
30148
|
const that = this;
|
|
30141
30149
|
Object.defineProperty(this.emitter, "tool", {
|
|
30142
30150
|
get() {
|
|
@@ -30282,10 +30290,19 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30282
30290
|
grab: new GrabTool(this.enableToolEvent, this.getCurrentRenderableModel, this.shadowEmitter, this.paperScope, this.camera)
|
|
30283
30291
|
};
|
|
30284
30292
|
this.toolbarModel.on("update", (style) => {
|
|
30285
|
-
|
|
30293
|
+
if (this.tools[style.tool]) {
|
|
30294
|
+
this.paperScope.tool = this.tools[style.tool].tool;
|
|
30295
|
+
} else {
|
|
30296
|
+
this.emitter.emit("error", 300001, `${style.tool} not supported`);
|
|
30297
|
+
}
|
|
30286
30298
|
this.emitter.emit("toolbarStyleChange", style);
|
|
30287
30299
|
});
|
|
30288
|
-
|
|
30300
|
+
if (this.tools[this.toolbarModel.currentTool]) {
|
|
30301
|
+
this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
|
|
30302
|
+
} else {
|
|
30303
|
+
this.paperScope.tool = this.tools["curve"].tool;
|
|
30304
|
+
log3(`${this.toolbarModel.currentTool} not supported, backup to curve`);
|
|
30305
|
+
}
|
|
30289
30306
|
this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
|
|
30290
30307
|
this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
|
|
30291
30308
|
this.trashedElementsModel.on("removeElementForSelf", this.handleRemoveTrashedElementForSelf);
|
|
@@ -30304,6 +30321,7 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30304
30321
|
this.rootElement.appendChild(this.shadowCanvasElement);
|
|
30305
30322
|
this.shadowScope.setup(this.shadowCanvasElement);
|
|
30306
30323
|
this.shadowScope.settings.insertItems = false;
|
|
30324
|
+
this.snapshotScope.setup(this.snapshotCanvasElement);
|
|
30307
30325
|
this.resizeObserver = new ResizeObserver(() => {
|
|
30308
30326
|
const rootBounds = this.rootElement.getBoundingClientRect();
|
|
30309
30327
|
const minWidth = Math.max(rootBounds.width, 10);
|
|
@@ -30503,7 +30521,7 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30503
30521
|
getCurrentRenderableModel = () => {
|
|
30504
30522
|
let layerId = this.userMap(this.userId).get(WhiteboardKeys.currentPage);
|
|
30505
30523
|
if (!this.layers.has(layerId)) {
|
|
30506
|
-
this.emitter.emit("error",
|
|
30524
|
+
this.emitter.emit("error", 300002, `target page: ${layerId} not found`);
|
|
30507
30525
|
}
|
|
30508
30526
|
return this.layers.get(layerId);
|
|
30509
30527
|
};
|
|
@@ -30640,11 +30658,9 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30640
30658
|
if (!renderableModel) {
|
|
30641
30659
|
return Promise.resolve(null);
|
|
30642
30660
|
}
|
|
30643
|
-
|
|
30644
|
-
|
|
30645
|
-
|
|
30646
|
-
scope.view.matrix = this.paperScope.project.view.matrix.clone();
|
|
30647
|
-
scope.view.viewSize = this.paperScope.project.view.viewSize.clone();
|
|
30661
|
+
this.snapshotScope.project.activeLayer.removeChildren();
|
|
30662
|
+
this.snapshotScope.view.matrix = this.paperScope.project.view.matrix.clone();
|
|
30663
|
+
this.snapshotScope.view.viewSize = this.paperScope.project.view.viewSize.clone();
|
|
30648
30664
|
for (const key of Array.from(renderableModel.elements.keys())) {
|
|
30649
30665
|
let elementModel = null;
|
|
30650
30666
|
if (renderableModel.elementModels.has(key)) {
|
|
@@ -30661,14 +30677,13 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30661
30677
|
}
|
|
30662
30678
|
if (elementModel.item) {
|
|
30663
30679
|
const paperItem = elementModel.item.clone({ insert: false });
|
|
30664
|
-
|
|
30680
|
+
this.snapshotScope.project.activeLayer.addChild(paperItem);
|
|
30665
30681
|
}
|
|
30666
30682
|
}
|
|
30667
30683
|
}
|
|
30668
|
-
document.body.appendChild(scope.view.element);
|
|
30669
30684
|
return new Promise((resolve) => {
|
|
30670
30685
|
setTimeout(() => {
|
|
30671
|
-
resolve(
|
|
30686
|
+
resolve(this.snapshotScope.view.element.toDataURL("image/png"));
|
|
30672
30687
|
}, 32);
|
|
30673
30688
|
});
|
|
30674
30689
|
}
|
|
@@ -30684,6 +30699,7 @@ var WhiteboardApplication = class extends AbstractApplication {
|
|
|
30684
30699
|
this.rootElement.removeChild(this.shadowCanvasElement);
|
|
30685
30700
|
this.paperScope.project.clear();
|
|
30686
30701
|
this.shadowScope.project.clear();
|
|
30702
|
+
this.snapshotScope.project.clear();
|
|
30687
30703
|
this.resizeObserver.disconnect();
|
|
30688
30704
|
}
|
|
30689
30705
|
};
|