@netless/forge-whiteboard 1.0.5 → 1.0.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.
@@ -1 +1 @@
1
- {"version":3,"file":"WhiteboardApplication.d.ts","sourceRoot":"","sources":["../src/WhiteboardApplication.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,mBAAmB,EAAO,MAAM,qBAAqB,CAAC;AAS/D,OAAO,EAAgB,YAAY,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AAUhF,OAAO,EAA0C,UAAU,EAAE,MAAM,cAAc,CAAC;AAmBlF;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;;;OAIG;IACH,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB;;OAEG;IACH,mBAAmB,CAAC,EAAE,OAAO,CAAC,YAAY,CAAC,CAAC;IAC5C;;OAEG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB;AAED,eAAO,MAAM,mBAAmB,eAAe,CAAC;AAEhD,MAAM,MAAM,kBAAkB,GAC9B,OAAO,GACL,WAAW,GACX,UAAU,GACV,MAAM,GACN,OAAO,GACP,MAAM,GACN,SAAS,GACT,UAAU,GACV,QAAQ,GACR,OAAO,GACP,MAAM,GACN,SAAS,CAAC;AAEZ,UAAU,sBAAsB;IAC9B,WAAW,EAAE,kBAAkB,CAAC;IAChC,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,GAAG,IAAI,CAAC;IACzB,QAAQ,EAAE,MAAM,CAAC;IACjB,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,EAAE,MAAM,CAAC;IACpB,SAAS,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC;CACpB;AAED,UAAU,aAAa;IACrB,GAAG,CAAC,GAAG,EAAE,MAAM,GAA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jC,MAAM;IAIb,OAAO,CAAC,kCAAkC,CAyBxC;IAGK,gBAAgB,GAAI,YAAY,MAAM,EAAE,aAAa,MAAM,UAwBhE;IAEK,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAKzC,WAAW,IAAI,CAAC,MAAM,EAAE,MAAM,CAAC;IAK/B,gBAAgB,IAAI,MAAM;IAI1B,kCAAkC,CAAC,KAAK,EAAE,OAAO;IAIjD,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM;IAMxC,OAAO,CAAC,YAAY,EAAE,OAAO,GAAG,OAAO,CAAC,IAAI,CAAC;CAoC3D"}
@@ -27871,7 +27871,7 @@ var RenderableModel = class extends EventEmitter {
27871
27871
  confirmPermission() {
27872
27872
  const hasPermission = this.hasPermission(WhiteboardPermissionFlag.draw);
27873
27873
  if (!hasPermission) {
27874
- log("[@netless/forge-whiteboard] no permission to draw", {}, "warning");
27874
+ log("[@netless/forge-whiteboard] no permission to draw", {}, "warn");
27875
27875
  }
27876
27876
  return hasPermission;
27877
27877
  }
@@ -31758,7 +31758,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
31758
31758
  }
31759
31759
  } else {
31760
31760
  console.warn(`[@netless/forge-whiteboard] page ${pageId} not found`);
31761
- log4(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warning");
31761
+ log4(`[@netless/forge-whiteboard] page ${pageId} not found`, {}, "warn");
31762
31762
  }
31763
31763
  await waitUntil(() => this.undoManagers.has(pageId), 1e3);
31764
31764
  if (this.undoManagers.has(pageId)) {
@@ -31770,7 +31770,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
31770
31770
  this.undoManagers.get(pageId).on("stack-item-popped", this.handleStackItemPopped);
31771
31771
  } else {
31772
31772
  console.warn(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`);
31773
- log4(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warning");
31773
+ log4(`[@netless/forge-whiteboard] undo manager for page ${pageId} not found`, {}, "warn");
31774
31774
  }
31775
31775
  this.emitter.emit("redoStackLength", this.undoManager?.redoStack.length ?? 0);
31776
31776
  this.emitter.emit("undoStackLength", this.undoManager?.undoStack.length ?? 0);
@@ -32037,7 +32037,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32037
32037
  this.emitter.setViewModeToFree = (userId) => {
32038
32038
  if (that.disableViewModelUpdate) {
32039
32039
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32040
- log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
32040
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32041
32041
  return;
32042
32042
  }
32043
32043
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32048,7 +32048,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32048
32048
  this.emitter.setViewModeToFlow = (flowId, userId) => {
32049
32049
  if (that.disableViewModelUpdate) {
32050
32050
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32051
- log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
32051
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32052
32052
  return;
32053
32053
  }
32054
32054
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32063,7 +32063,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32063
32063
  this.emitter.setViewModeToMain = (userId) => {
32064
32064
  if (that.disableViewModelUpdate) {
32065
32065
  console.warn("Operation failed. Perspective mode switching is disabled in the current environment.");
32066
- log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warning");
32066
+ log4("Operation failed. Perspective mode switching is disabled in the current environment.", {}, "warn");
32067
32067
  return;
32068
32068
  }
32069
32069
  const targetId = userId ? this.hasPermission(WhiteboardPermissionFlag.setOthersView) ? userId : null : this.userId;
@@ -32079,7 +32079,7 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32079
32079
  if (!/https/.test(src)) {
32080
32080
  log4("[@netless/forge-whiteboard] invalid image url, src needs to be in the HTTPS protocol.", {
32081
32081
  src
32082
- }, "warning");
32082
+ }, "warn");
32083
32083
  return;
32084
32084
  }
32085
32085
  let targetPageId = pageId;
@@ -32087,14 +32087,14 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32087
32087
  targetPageId = this.pageModel.getCurrentPage(this.userManager.selfId);
32088
32088
  }
32089
32089
  if (!targetPageId) {
32090
- log4("[@netless/forge-whiteboard] page not found", {}, "warning");
32090
+ log4("[@netless/forge-whiteboard] page not found", {}, "warn");
32091
32091
  return;
32092
32092
  }
32093
32093
  this.layers.get(targetPageId)?.createImage(src);
32094
32094
  };
32095
32095
  this.emitter.removeElement = (pageId, elementId) => {
32096
32096
  if (!this.layers.has(pageId)) {
32097
- log4("[@netless/forge-whiteboard] page not found", {}, "warning");
32097
+ log4("[@netless/forge-whiteboard] page not found", {}, "warn");
32098
32098
  return;
32099
32099
  }
32100
32100
  this.layers.get(pageId)?.removeElementItem(elementId);
@@ -32292,202 +32292,204 @@ var WhiteboardApplication = class _WhiteboardApplication extends AbstractApplica
32292
32292
  async initialize(option) {
32293
32293
  _WhiteboardApplication.instanceCount.set(this.appId, (_WhiteboardApplication.instanceCount.get(this.appId) ?? 0) + 1);
32294
32294
  log4(`whiteboard ${this.appId} initialize. instance count: ${_WhiteboardApplication.instanceCount.get(this.appId) ?? 0}`, {}, "info");
32295
- this.permissions = new WhiteboardPermissions(this.userManager, (userId) => {
32296
- return this.userMap(userId);
32297
- });
32298
- this.permissions.setPermission(WhiteboardPermissionFlag.all);
32299
- this.emitter["permissions"] = this.permissions;
32300
- this.emitter["selfUserId"] = this.userId;
32301
- this.option = option;
32302
- if (this.option.stretchToFill) {
32303
- this.getMap("attrs").set("viewportWidth", -1);
32304
- this.getMap("attrs").set("viewportHeight", -1);
32305
- } else {
32306
- if (!this.getMap("attrs").has("viewportWidth")) {
32307
- this.getMap("attrs").set("viewportWidth", option.width);
32308
- }
32309
- if (!this.getMap("attrs").has("viewportHeight")) {
32310
- this.getMap("attrs").set("viewportHeight", option.height);
32311
- }
32312
- }
32313
- this.userMap(this.userId).set(WhiteboardKeys.themeColor, "#009688");
32314
- this.userMap(this.userId).observe(this.handleSyncedWhiteboardStatusChange);
32315
- this.shadowEmitter = new ShadowEmitter(this.userMap(this.userId));
32316
- this.pageModel = new PageModel(this.getMap("attrs"), this.userManager, (userId) => {
32317
- return this.userMap(userId);
32318
- }, this.getMap("pages"), this.hasPermission);
32319
- this.pageModel.on("pagesChange", this.handleLayersChange);
32320
- this.pageModel.on("switchPage", this.handlePageSwitch);
32321
- if (option.maxScaleRatio && option.maxScaleRatio < 1 && option.maxScaleRatio !== -1) {
32322
- throw new Error(`[@netless/forge-whiteboard] invalid maxScaleRatio ${option.maxScaleRatio}`);
32323
- }
32324
- this.camera = new Camera(new this.paperScope.Size(option.width, option.height), option.maxScaleRatio ?? -1, this.rootElement, this.userManager, this.paperScope, this.getMap("attrs"), this.hasPermission, (userId) => {
32325
- return this.userMap(userId);
32326
- }, () => {
32327
- return [this.paperScope.project.view.size.width, this.paperScope.project.view.size.height];
32328
- }, () => {
32329
- const rect = this.canvasElement.getBoundingClientRect();
32330
- return [rect.width, rect.height];
32331
- });
32332
- this.camera.on("zoom", (matrix) => {
32333
- this.paperScope.project.view.matrix = matrix;
32334
- this.shadowScope.project.view.matrix = matrix;
32335
- this.editors.forEach((editor) => {
32336
- editor.updateBounds();
32295
+ this.appDoc.transact(() => {
32296
+ this.permissions = new WhiteboardPermissions(this.userManager, (userId) => {
32297
+ return this.userMap(userId);
32337
32298
  });
32338
- });
32339
- this.camera.on("userPageChange", (userId, pageId) => {
32340
- this.emitter.emit("activePageChange", userId, pageId);
32341
- });
32342
- this.camera.on("userViewModeChange", (userId, mode, oldMode) => {
32343
- if (oldMode !== "main" && mode === "main") {
32344
- this.emitter.setViewModeToMain(userId);
32345
- }
32346
- this.emitter.emit("userViewModeChange", userId, mode);
32347
- });
32348
- this.rootElement.style.position = "relative";
32349
- this.rootElement.appendChild(this.canvasElement);
32350
- this.toolbarModel = new ToolbarModel(this.userMap(this.userId), Object.assign({
32351
- tool: "grab",
32352
- strokeColor: "#009688",
32353
- fillColor: null,
32354
- fontSize: 24,
32355
- fontFamily: "Courier New",
32356
- strokeWidth: 4,
32357
- dashArray: []
32358
- }, option.defaultToolbarStyle ?? {}));
32359
- this.trashedElementsModel = new TrashedElementsModel(this.userManager, (userId) => {
32360
- return this.userMap(userId);
32361
- }, this.hasPermission);
32362
- this.selectElementsModel = new SelectElementsModel(this.userManager, (userId) => {
32363
- return this.userMap(userId);
32364
- }, this.hasPermission);
32365
- this.liveCursor = new LiveCursor(this.canvasElement, this.paperScope, this.userManager, (userId) => {
32366
- return this.userMap(userId);
32367
- });
32368
- this.tools = {
32369
- pointer: new PointerTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32370
- curve: new CurveTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32371
- rectangle: new RectangleTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32372
- selector: new SelectorTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.selectElementsModel),
32373
- arrow: new LineTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32374
- line: new StraightLineTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32375
- text: new TextTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.rootElement, this.canvasElement, this.toolbarModel, this.camera),
32376
- ellipse: new EllipseTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32377
- triangle: new TriangleTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32378
- eraser: new EraserTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel, this.shadowScope),
32379
- laser: new LaserPointerTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32380
- grab: new GrabTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.camera)
32381
- };
32382
- this.toolbarModel.on("update", (style) => {
32383
- if (this.tools[style.tool]) {
32384
- this.paperScope.tool = this.tools[style.tool].tool;
32385
- if (style.tool === "pointer") {
32386
- this.rootElement.style.pointerEvents = "none";
32299
+ this.permissions.setPermission(WhiteboardPermissionFlag.all);
32300
+ this.emitter["permissions"] = this.permissions;
32301
+ this.emitter["selfUserId"] = this.userId;
32302
+ this.option = option;
32303
+ if (this.option.stretchToFill) {
32304
+ this.getMap("attrs").set("viewportWidth", -1);
32305
+ this.getMap("attrs").set("viewportHeight", -1);
32306
+ } else {
32307
+ if (!this.getMap("attrs").has("viewportWidth")) {
32308
+ this.getMap("attrs").set("viewportWidth", option.width);
32309
+ }
32310
+ if (!this.getMap("attrs").has("viewportHeight")) {
32311
+ this.getMap("attrs").set("viewportHeight", option.height);
32312
+ }
32313
+ }
32314
+ this.userMap(this.userId).set(WhiteboardKeys.themeColor, "#009688");
32315
+ this.userMap(this.userId).observe(this.handleSyncedWhiteboardStatusChange);
32316
+ this.shadowEmitter = new ShadowEmitter(this.userMap(this.userId));
32317
+ this.pageModel = new PageModel(this.getMap("attrs"), this.userManager, (userId) => {
32318
+ return this.userMap(userId);
32319
+ }, this.getMap("pages"), this.hasPermission);
32320
+ this.pageModel.on("pagesChange", this.handleLayersChange);
32321
+ this.pageModel.on("switchPage", this.handlePageSwitch);
32322
+ if (option.maxScaleRatio && option.maxScaleRatio < 1 && option.maxScaleRatio !== -1) {
32323
+ throw new Error(`[@netless/forge-whiteboard] invalid maxScaleRatio ${option.maxScaleRatio}`);
32324
+ }
32325
+ this.camera = new Camera(new this.paperScope.Size(option.width, option.height), option.maxScaleRatio ?? -1, this.rootElement, this.userManager, this.paperScope, this.getMap("attrs"), this.hasPermission, (userId) => {
32326
+ return this.userMap(userId);
32327
+ }, () => {
32328
+ return [this.paperScope.project.view.size.width, this.paperScope.project.view.size.height];
32329
+ }, () => {
32330
+ const rect = this.canvasElement.getBoundingClientRect();
32331
+ return [rect.width, rect.height];
32332
+ });
32333
+ this.camera.on("zoom", (matrix) => {
32334
+ this.paperScope.project.view.matrix = matrix;
32335
+ this.shadowScope.project.view.matrix = matrix;
32336
+ this.editors.forEach((editor) => {
32337
+ editor.updateBounds();
32338
+ });
32339
+ });
32340
+ this.camera.on("userPageChange", (userId, pageId) => {
32341
+ this.emitter.emit("activePageChange", userId, pageId);
32342
+ });
32343
+ this.camera.on("userViewModeChange", (userId, mode, oldMode) => {
32344
+ if (oldMode !== "main" && mode === "main") {
32345
+ this.emitter.setViewModeToMain(userId);
32346
+ }
32347
+ this.emitter.emit("userViewModeChange", userId, mode);
32348
+ });
32349
+ this.rootElement.style.position = "relative";
32350
+ this.rootElement.appendChild(this.canvasElement);
32351
+ this.toolbarModel = new ToolbarModel(this.userMap(this.userId), Object.assign({
32352
+ tool: "grab",
32353
+ strokeColor: "#009688",
32354
+ fillColor: null,
32355
+ fontSize: 24,
32356
+ fontFamily: "Courier New",
32357
+ strokeWidth: 4,
32358
+ dashArray: []
32359
+ }, option.defaultToolbarStyle ?? {}));
32360
+ this.trashedElementsModel = new TrashedElementsModel(this.userManager, (userId) => {
32361
+ return this.userMap(userId);
32362
+ }, this.hasPermission);
32363
+ this.selectElementsModel = new SelectElementsModel(this.userManager, (userId) => {
32364
+ return this.userMap(userId);
32365
+ }, this.hasPermission);
32366
+ this.liveCursor = new LiveCursor(this.canvasElement, this.paperScope, this.userManager, (userId) => {
32367
+ return this.userMap(userId);
32368
+ });
32369
+ this.tools = {
32370
+ pointer: new PointerTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32371
+ curve: new CurveTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32372
+ rectangle: new RectangleTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32373
+ selector: new SelectorTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.selectElementsModel),
32374
+ arrow: new LineTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32375
+ line: new StraightLineTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32376
+ text: new TextTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.rootElement, this.canvasElement, this.toolbarModel, this.camera),
32377
+ ellipse: new EllipseTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32378
+ triangle: new TriangleTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32379
+ eraser: new EraserTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.trashedElementsModel, this.shadowScope),
32380
+ laser: new LaserPointerTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope),
32381
+ grab: new GrabTool(this.enableToolEvent, this.getCurrentRendererModel, this.shadowEmitter, this.paperScope, this.camera)
32382
+ };
32383
+ this.toolbarModel.on("update", (style) => {
32384
+ if (this.tools[style.tool]) {
32385
+ this.paperScope.tool = this.tools[style.tool].tool;
32386
+ if (style.tool === "pointer") {
32387
+ this.rootElement.style.pointerEvents = "none";
32388
+ } else {
32389
+ this.rootElement.style.pointerEvents = "auto";
32390
+ }
32387
32391
  } else {
32388
- this.rootElement.style.pointerEvents = "auto";
32392
+ this.emitter.emit("error", 300001, `${style.tool} not supported`);
32389
32393
  }
32394
+ this.emitter.emit("toolbarStyleChange", style);
32395
+ });
32396
+ if (this.tools[this.toolbarModel.currentTool]) {
32397
+ this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
32390
32398
  } else {
32391
- this.emitter.emit("error", 300001, `${style.tool} not supported`);
32392
- }
32393
- this.emitter.emit("toolbarStyleChange", style);
32394
- });
32395
- if (this.tools[this.toolbarModel.currentTool]) {
32396
- this.paperScope.tool = this.tools[this.toolbarModel.currentTool].tool;
32397
- } else {
32398
- this.paperScope.tool = this.tools["curve"].tool;
32399
- log4(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32400
- }
32401
- this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
32402
- this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
32403
- this.trashedElementsModel.on("removeElementForSelf", this.handleRemoveTrashedElementForSelf);
32404
- this.canvasElement.style.background = "#FFEB3B";
32405
- this.canvasElement.style.position = "absolute";
32406
- this.canvasElement.style.top = "50%";
32407
- this.canvasElement.style.left = "50%";
32408
- this.canvasElement.style.transform = "translate(-50%, -50%)";
32409
- this.canvasElement.setAttribute("id", `${this.appId}-main`);
32410
- this.paperScope.setup(this.canvasElement);
32411
- this.paperScope.settings.insertItems = false;
32412
- this.shadowCanvasElement.style.position = "absolute";
32413
- this.shadowCanvasElement.style.top = "50%";
32414
- this.shadowCanvasElement.style.left = "50%";
32415
- this.shadowCanvasElement.style.transform = "translate(-50%, -50%)";
32416
- this.shadowCanvasElement.style.pointerEvents = "none";
32417
- this.shadowCanvasElement.setAttribute("id", `${this.appId}-shadow`);
32418
- this.rootElement.appendChild(this.shadowCanvasElement);
32419
- this.shadowScope.setup(this.shadowCanvasElement);
32420
- this.shadowScope.settings.insertItems = false;
32421
- this.snapshotCanvasElement.setAttribute("id", `${this.appId}-snapshot`);
32422
- this.snapshotScope.setup(this.snapshotCanvasElement);
32423
- this.resizeObserver = new ResizeObserver(() => {
32424
- if (this.internalResizeObserver) {
32425
- const rootBounds = this.rootElement.getBoundingClientRect();
32426
- this.adjustByOutFrame(rootBounds.width, rootBounds.height);
32427
- }
32428
- });
32429
- this.resizeObserver.observe(this.rootElement);
32430
- if (!this.getMap("attrs").has(WhiteboardKeys.currentPage)) {
32431
- this.getMap("attrs").set(WhiteboardKeys.currentPage, "_i_");
32432
- }
32433
- this.emitter.indexedNavigation = new IndexedNavigation(this.pageModel, this.userMap(this.userId), this.getMap("indexedNavigation"), this.hasPermission);
32434
- this.emitter.indexedNavigation.initIndexed().then((inited) => {
32435
- if (!inited) {
32436
- this.handleLayersChange(this.pageModel.pageList());
32437
- const currentPage = this.pageModel.getCurrentPage(this.userId);
32438
- if (currentPage) {
32439
- this.userMap(this.userId).set(WhiteboardKeys.currentPage, currentPage);
32440
- this.handlePageSwitch(currentPage);
32399
+ this.paperScope.tool = this.tools["curve"].tool;
32400
+ log4(`${this.toolbarModel.currentTool} not supported, backup to curve`);
32401
+ }
32402
+ this.selectElementsModel.on("elementsChange", this.handleElementsSelect);
32403
+ this.trashedElementsModel.on("elementsChange", this.handleElementsTrash);
32404
+ this.trashedElementsModel.on("removeElementForSelf", this.handleRemoveTrashedElementForSelf);
32405
+ this.canvasElement.style.background = "#FFEB3B";
32406
+ this.canvasElement.style.position = "absolute";
32407
+ this.canvasElement.style.top = "50%";
32408
+ this.canvasElement.style.left = "50%";
32409
+ this.canvasElement.style.transform = "translate(-50%, -50%)";
32410
+ this.canvasElement.setAttribute("id", `${this.appId}-main`);
32411
+ this.paperScope.setup(this.canvasElement);
32412
+ this.paperScope.settings.insertItems = false;
32413
+ this.shadowCanvasElement.style.position = "absolute";
32414
+ this.shadowCanvasElement.style.top = "50%";
32415
+ this.shadowCanvasElement.style.left = "50%";
32416
+ this.shadowCanvasElement.style.transform = "translate(-50%, -50%)";
32417
+ this.shadowCanvasElement.style.pointerEvents = "none";
32418
+ this.shadowCanvasElement.setAttribute("id", `${this.appId}-shadow`);
32419
+ this.rootElement.appendChild(this.shadowCanvasElement);
32420
+ this.shadowScope.setup(this.shadowCanvasElement);
32421
+ this.shadowScope.settings.insertItems = false;
32422
+ this.snapshotCanvasElement.setAttribute("id", `${this.appId}-snapshot`);
32423
+ this.snapshotScope.setup(this.snapshotCanvasElement);
32424
+ this.resizeObserver = new ResizeObserver(() => {
32425
+ if (this.internalResizeObserver) {
32426
+ const rootBounds = this.rootElement.getBoundingClientRect();
32427
+ this.adjustByOutFrame(rootBounds.width, rootBounds.height);
32428
+ }
32429
+ });
32430
+ this.resizeObserver.observe(this.rootElement);
32431
+ if (!this.getMap("attrs").has(WhiteboardKeys.currentPage)) {
32432
+ this.getMap("attrs").set(WhiteboardKeys.currentPage, "_i_");
32433
+ }
32434
+ this.emitter.indexedNavigation = new IndexedNavigation(this.pageModel, this.userMap(this.userId), this.getMap("indexedNavigation"), this.hasPermission);
32435
+ this.emitter.indexedNavigation.initIndexed().then((inited) => {
32436
+ if (!inited) {
32437
+ this.handleLayersChange(this.pageModel.pageList());
32438
+ const currentPage = this.pageModel.getCurrentPage(this.userId);
32439
+ if (currentPage) {
32440
+ this.userMap(this.userId).set(WhiteboardKeys.currentPage, currentPage);
32441
+ this.handlePageSwitch(currentPage);
32442
+ } else {
32443
+ this.userMap(this.userId).set(WhiteboardKeys.currentPage, "_i_");
32444
+ this.handlePageSwitch("_i_");
32445
+ }
32441
32446
  } else {
32442
32447
  this.userMap(this.userId).set(WhiteboardKeys.currentPage, "_i_");
32443
- this.handlePageSwitch("_i_");
32444
32448
  }
32445
- } else {
32446
- this.userMap(this.userId).set(WhiteboardKeys.currentPage, "_i_");
32447
- }
32448
- });
32449
- this.shadowEmitter.on("translateOut", (ids, container) => {
32450
- if (this.delayTranslateOut > 0) {
32451
- setTimeout(() => {
32449
+ });
32450
+ this.shadowEmitter.on("translateOut", (ids, container) => {
32451
+ if (this.delayTranslateOut > 0) {
32452
+ setTimeout(() => {
32453
+ this.handleElementTranslateOut(ids, container);
32454
+ }, this.delayTranslateOut);
32455
+ } else {
32452
32456
  this.handleElementTranslateOut(ids, container);
32453
- }, this.delayTranslateOut);
32454
- } else {
32455
- this.handleElementTranslateOut(ids, container);
32456
- }
32457
- });
32458
- this.shadowEmitter.on("translateIn", (ids, container) => {
32459
- let parent = null;
32460
- if (container === "layer") {
32461
- parent = this.shadowScope.project.activeLayer;
32462
- } else {
32463
- parent = this.shadowScope.project.activeLayer.children.find((child) => child.data.uuid === container) ?? null;
32464
- }
32465
- if (parent) {
32466
- ids.forEach((id) => {
32467
- const target = this.paperScope.project.activeLayer.children.find((child) => child.data.uuid === id);
32468
- if (target) {
32469
- target.remove();
32470
- this.insertElementToParent(target, parent);
32471
- }
32457
+ }
32458
+ });
32459
+ this.shadowEmitter.on("translateIn", (ids, container) => {
32460
+ let parent = null;
32461
+ if (container === "layer") {
32462
+ parent = this.shadowScope.project.activeLayer;
32463
+ } else {
32464
+ parent = this.shadowScope.project.activeLayer.children.find((child) => child.data.uuid === container) ?? null;
32465
+ }
32466
+ if (parent) {
32467
+ ids.forEach((id) => {
32468
+ const target = this.paperScope.project.activeLayer.children.find((child) => child.data.uuid === id);
32469
+ if (target) {
32470
+ target.remove();
32471
+ this.insertElementToParent(target, parent);
32472
+ }
32473
+ });
32474
+ }
32475
+ });
32476
+ this.shadowEmitter.on("grabDown", () => {
32477
+ this.emitter.emit("grabDown");
32478
+ });
32479
+ this.shadowEmitter.on("grabUp", () => {
32480
+ this.emitter.emit("grabUp");
32481
+ });
32482
+ this.clearElements();
32483
+ if (this.option.stretchToFill) {
32484
+ window.addEventListener("resize", () => {
32485
+ const bounds = this.rootElement.getBoundingClientRect();
32486
+ this.updateOptionSize(bounds.width, bounds.height);
32487
+ this.adjustByOutFrame(bounds.width, bounds.height);
32472
32488
  });
32473
32489
  }
32474
- });
32475
- this.shadowEmitter.on("grabDown", () => {
32476
- this.emitter.emit("grabDown");
32477
- });
32478
- this.shadowEmitter.on("grabUp", () => {
32479
- this.emitter.emit("grabUp");
32480
- });
32481
- this.clearElements();
32482
- if (this.option.stretchToFill) {
32483
- window.addEventListener("resize", () => {
32484
- const bounds = this.rootElement.getBoundingClientRect();
32485
- this.updateOptionSize(bounds.width, bounds.height);
32486
- this.adjustByOutFrame(bounds.width, bounds.height);
32487
- });
32488
- }
32489
- this.rootElement.appendChild(this.liveCursor.container);
32490
- this.getMap("attrs").observe(this.handleViewportUpdate);
32490
+ this.rootElement.appendChild(this.liveCursor.container);
32491
+ this.getMap("attrs").observe(this.handleViewportUpdate);
32492
+ }, "whiteboard-initialize");
32491
32493
  }
32492
32494
  clearElements() {
32493
32495
  const userIds = this.userManager.userIdList();