@netless/app-slide 0.2.103 → 0.2.105-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/main.es.js CHANGED
@@ -39791,7 +39791,8 @@ const EmptyAttributes = {
39791
39791
  customLinks: [],
39792
39792
  slideScale: 1,
39793
39793
  translateX: 0.5,
39794
- translateY: 0.5
39794
+ translateY: 0.5,
39795
+ originSize: null
39795
39796
  };
39796
39797
  const noop$1 = function noop2() {
39797
39798
  };
@@ -41417,6 +41418,7 @@ class ResizableContainer {
41417
41418
  constructor(parent, context, enableResize, _box) {
41418
41419
  this.onScaleChanged = null;
41419
41420
  this.onLayoutUpdated = null;
41421
+ this.scaleChangedListeners = /* @__PURE__ */ new Set();
41420
41422
  this.whiteboardContainer = null;
41421
41423
  this.slide = null;
41422
41424
  this.scale = 1;
@@ -41467,6 +41469,12 @@ class ResizableContainer {
41467
41469
  getScale() {
41468
41470
  return this.scale;
41469
41471
  }
41472
+ addScaleChangedListener(listener) {
41473
+ this.scaleChangedListeners.add(listener);
41474
+ return () => {
41475
+ this.scaleChangedListeners.delete(listener);
41476
+ };
41477
+ }
41470
41478
  renderScrollBar(width, overflowWidth, height, overflowHeight) {
41471
41479
  if (this.scrollBar) {
41472
41480
  this.scrollBar.render(width, height, overflowWidth, overflowHeight);
@@ -41478,6 +41486,7 @@ class ResizableContainer {
41478
41486
  }
41479
41487
  updateResizableContainer() {
41480
41488
  var _a, _b;
41489
+ this.cancelScheduledLayoutUpdate();
41481
41490
  const parentBounds = this.scrollContainer.getBoundingClientRect();
41482
41491
  this.container.style.width = `${parentBounds.width * this.scale}px`;
41483
41492
  this.container.style.height = `${parentBounds.height * this.scale}px`;
@@ -41528,6 +41537,7 @@ class ResizableContainer {
41528
41537
  }
41529
41538
  }
41530
41539
  scaleContainer(applyScale) {
41540
+ var _a;
41531
41541
  if (Math.abs(this.scale - applyScale) < 1e-3 || !this.enableResize) {
41532
41542
  return;
41533
41543
  }
@@ -41539,13 +41549,25 @@ class ResizableContainer {
41539
41549
  this.scrollContainer.style.height = "100%";
41540
41550
  }
41541
41551
  applyScale = this.enableResize ? applyScale : 1;
41542
- if (this.onScaleChanged && this.enableResize) {
41543
- this.onScaleChanged(applyScale);
41544
- }
41545
41552
  this.scale = applyScale;
41546
- setTimeout(() => {
41547
- this.updateResizableContainer();
41548
- });
41553
+ if (this.enableResize) {
41554
+ (_a = this.onScaleChanged) == null ? void 0 : _a.call(this, this.scale);
41555
+ for (const listener of this.scaleChangedListeners) {
41556
+ listener(this.scale);
41557
+ }
41558
+ }
41559
+ if (this.layoutFrameId === void 0) {
41560
+ this.layoutFrameId = requestAnimationFrame(() => {
41561
+ this.layoutFrameId = void 0;
41562
+ this.updateResizableContainer();
41563
+ });
41564
+ }
41565
+ }
41566
+ cancelScheduledLayoutUpdate() {
41567
+ if (this.layoutFrameId !== void 0) {
41568
+ cancelAnimationFrame(this.layoutFrameId);
41569
+ this.layoutFrameId = void 0;
41570
+ }
41549
41571
  }
41550
41572
  addSlideContainer(slideContainer) {
41551
41573
  this.container.appendChild(slideContainer);
@@ -41559,7 +41581,9 @@ class ResizableContainer {
41559
41581
  }
41560
41582
  destroy(_box) {
41561
41583
  var _a;
41584
+ this.cancelScheduledLayoutUpdate();
41562
41585
  this.onLayoutUpdated = null;
41586
+ this.scaleChangedListeners.clear();
41563
41587
  (_a = this.scrollBar) == null ? void 0 : _a.destroy();
41564
41588
  }
41565
41589
  }
@@ -42187,24 +42211,29 @@ class SlideDocsViewer {
42187
42211
  };
42188
42212
  this.scaleDocsToFit = () => {
42189
42213
  if (this.slideController) {
42190
- const { width, height } = this.slideController.slide;
42191
- if (width && height) {
42192
- this.whiteboardView.moveCameraToContain({
42193
- originX: -width / 2,
42194
- originY: -height / 2,
42195
- width,
42196
- height,
42197
- animationMode: "immediately"
42198
- });
42199
- this.whiteboardView.setCameraBound({
42200
- damping: 1,
42201
- maxContentMode: () => this.whiteboardView.camera.scale,
42202
- minContentMode: () => this.whiteboardView.camera.scale,
42203
- centerX: 0,
42204
- centerY: 0,
42205
- width,
42206
- height
42207
- });
42214
+ const { width: slideWidth, height: slideHeight } = this.slideController.slide;
42215
+ if (slideWidth && slideHeight) {
42216
+ const originSize = this.context.storage.state.originSize;
42217
+ const { width, height } = originSize && originSize.width > 0 && originSize.height > 0 ? originSize : { width: slideWidth, height: slideHeight };
42218
+ if (width > 0 && height > 0) {
42219
+ this.whiteboardView.moveCameraToContain({
42220
+ originX: -width / 2,
42221
+ originY: -height / 2,
42222
+ width,
42223
+ height,
42224
+ animationMode: "immediately"
42225
+ });
42226
+ const scale = this.whiteboardView.camera.scale;
42227
+ this.whiteboardView.setCameraBound({
42228
+ damping: 1,
42229
+ maxContentMode: () => scale,
42230
+ minContentMode: () => scale,
42231
+ centerX: 0,
42232
+ centerY: 0,
42233
+ width: slideWidth,
42234
+ height: slideHeight
42235
+ });
42236
+ }
42208
42237
  if (!this.isViewMounted) {
42209
42238
  this.isViewMounted = true;
42210
42239
  console.log("[Slide] mount whiteboard view");
@@ -42824,7 +42853,7 @@ class SlidePreviewer {
42824
42853
  }
42825
42854
  }
42826
42855
  const usePlugin = /* @__PURE__ */ Slide.Slide.usePlugin.bind(Slide.Slide);
42827
- const version = "0.2.103";
42856
+ const version = "0.2.105-beta.0";
42828
42857
  const SlideApp = {
42829
42858
  kind: "Slide",
42830
42859
  setup(context) {
@@ -42936,7 +42965,15 @@ const SlideApp = {
42936
42965
  return () => room.callbacks.off("onRoomStateChanged", onRoomStateChanged);
42937
42966
  });
42938
42967
  }
42939
- context.emitter.on("destroy", () => {
42968
+ let disposed = false;
42969
+ let offDestroy;
42970
+ const teardown = () => {
42971
+ if (disposed)
42972
+ return;
42973
+ disposed = true;
42974
+ const removeDestroy = offDestroy;
42975
+ offDestroy = void 0;
42976
+ removeDestroy == null ? void 0 : removeDestroy();
42940
42977
  log("[Slide] destroy", context.appId);
42941
42978
  if (useFreezer)
42942
42979
  apps.delete(context.appId);
@@ -42945,29 +42982,31 @@ const SlideApp = {
42945
42982
  docsViewer.destroy();
42946
42983
  docsViewer = null;
42947
42984
  }
42948
- });
42985
+ };
42986
+ offDestroy = context.emitter.on("destroy", teardown);
42949
42987
  docsViewer.mount();
42988
+ SlideApp.__teardownByContext || (SlideApp.__teardownByContext = /* @__PURE__ */ new WeakMap());
42989
+ SlideApp.__teardownByContext.set(context, teardown);
42950
42990
  return {
42951
42991
  onScaleChanged: (cb) => {
42952
42992
  if (!docsViewer) {
42953
- return;
42993
+ return () => void 0;
42954
42994
  }
42955
- docsViewer.resizableContainer.onScaleChanged = cb;
42995
+ return docsViewer.resizableContainer.addScaleChangedListener(cb);
42956
42996
  },
42957
42997
  scaleView: (to) => {
42958
- let applyScale = Number(to);
42959
- if (Number.isNaN(applyScale)) {
42960
- applyScale = 1;
42961
- }
42962
- if (applyScale < 1) {
42963
- applyScale = 1;
42964
- }
42965
- if (applyScale > 4) {
42966
- applyScale = 4;
42967
- }
42968
- context.storage.setState({ slideScale: applyScale });
42969
- context.storage.setState({ translateX: 0.5, translateY: 0.5 });
42970
- docsViewer == null ? void 0 : docsViewer.resizableContainer.scaleContainer(applyScale);
42998
+ const applyScale = Number(to);
42999
+ if (!Number.isFinite(applyScale) || applyScale <= 0)
43000
+ return;
43001
+ const container = docsViewer == null ? void 0 : docsViewer.resizableContainer;
43002
+ if (!container || Math.abs(container.getScale() - applyScale) < 1e-3)
43003
+ return;
43004
+ context.storage.setState({
43005
+ slideScale: applyScale,
43006
+ translateX: 0.5,
43007
+ translateY: 0.5
43008
+ });
43009
+ container.scaleContainer(applyScale);
42971
43010
  },
42972
43011
  getViewScale: () => {
42973
43012
  return docsViewer == null ? void 0 : docsViewer.resizableContainer.getScale();
@@ -43067,6 +43106,11 @@ const SlideApp = {
43067
43106
  return false;
43068
43107
  }
43069
43108
  };
43109
+ },
43110
+ teardown(context) {
43111
+ var _a, _b, _c;
43112
+ (_b = (_a = SlideApp.__teardownByContext) == null ? void 0 : _a.get(context)) == null ? void 0 : _b();
43113
+ (_c = SlideApp.__teardownByContext) == null ? void 0 : _c.delete(context);
43070
43114
  }
43071
43115
  };
43072
43116
  var Slide$1 = Slide.Slide;