@netless/window-manager 1.0.0-canary.53 → 1.0.0-canary.54

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.
Files changed (44) hide show
  1. package/dist/index.cjs.js +381 -444
  2. package/dist/index.es.js +427 -490
  3. package/dist/index.umd.js +381 -445
  4. package/dist/src/App/AppContext.d.ts +8 -8
  5. package/dist/src/AppManager.d.ts +5 -1
  6. package/dist/src/Cursor/index.d.ts +1 -0
  7. package/dist/src/Utils/Reactive.d.ts +1 -1
  8. package/dist/src/View/CameraSynchronizer.d.ts +3 -2
  9. package/dist/src/View/ScrollMode.d.ts +32 -0
  10. package/dist/src/View/ViewSync.d.ts +3 -2
  11. package/dist/src/callback.d.ts +3 -0
  12. package/dist/src/constants.d.ts +2 -0
  13. package/dist/src/index.d.ts +21 -11
  14. package/dist/src/storage.d.ts +7 -0
  15. package/dist/src/typings.d.ts +5 -4
  16. package/dist/style.css +2 -1
  17. package/docs/api.md +10 -0
  18. package/package.json +4 -3
  19. package/pnpm-lock.yaml +28 -73
  20. package/src/App/AppContext.ts +19 -8
  21. package/src/App/WhiteboardView.ts +4 -2
  22. package/src/AppListener.ts +1 -10
  23. package/src/AppManager.ts +19 -1
  24. package/src/Cursor/index.ts +6 -2
  25. package/src/Utils/Reactive.ts +2 -1
  26. package/src/View/CameraSynchronizer.ts +33 -22
  27. package/src/View/MainView.ts +1 -0
  28. package/src/View/ScrollMode.ts +229 -0
  29. package/src/View/ViewSync.ts +24 -16
  30. package/src/callback.ts +3 -0
  31. package/src/constants.ts +3 -0
  32. package/src/index.ts +56 -63
  33. package/src/storage.ts +15 -0
  34. package/src/style.css +1 -1
  35. package/src/typings.ts +6 -3
  36. package/vite.config.js +1 -1
  37. package/dist/src/App/Storage/StorageEvent.d.ts +0 -8
  38. package/dist/src/App/Storage/index.d.ts +0 -39
  39. package/dist/src/App/Storage/typings.d.ts +0 -22
  40. package/dist/src/App/Storage/utils.d.ts +0 -5
  41. package/src/App/Storage/StorageEvent.ts +0 -21
  42. package/src/App/Storage/index.ts +0 -295
  43. package/src/App/Storage/typings.ts +0 -23
  44. package/src/App/Storage/utils.ts +0 -17
package/dist/index.umd.js CHANGED
@@ -30,8 +30,8 @@ var __objRest = (source, exclude) => {
30
30
  return target;
31
31
  };
32
32
  (function(global, factory) {
33
- typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("p-retry"), require("emittery"), require("lodash"), require("white-web-sdk"), require("uuid"), require("side-effect-manager"), require("value-enhancer"), require("@juggle/resize-observer")) : typeof define === "function" && define.amd ? define(["exports", "p-retry", "emittery", "lodash", "white-web-sdk", "uuid", "side-effect-manager", "value-enhancer", "@juggle/resize-observer"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.WindowManager = {}, global.pRetry, global.Emittery, global.lodash, global.whiteWebSdk, global.uuid, global.sideEffectManager, global.valueEnhancer, global.resizeObserver));
34
- })(this, function(exports2, pRetry, Emittery, lodash, whiteWebSdk, uuid, sideEffectManager, valueEnhancer, resizeObserver) {
33
+ typeof exports === "object" && typeof module !== "undefined" ? factory(exports, require("p-retry"), require("emittery"), require("lodash"), require("white-web-sdk"), require("uuid"), require("@netless/synced-store"), require("value-enhancer"), require("side-effect-manager"), require("@juggle/resize-observer")) : typeof define === "function" && define.amd ? define(["exports", "p-retry", "emittery", "lodash", "white-web-sdk", "uuid", "@netless/synced-store", "value-enhancer", "side-effect-manager", "@juggle/resize-observer"], factory) : (global = typeof globalThis !== "undefined" ? globalThis : global || self, factory(global.WindowManager = {}, global.pRetry, global.Emittery, global.lodash, global.whiteWebSdk, global.uuid, global.syncedStore, global.valueEnhancer, global.sideEffectManager, global.resizeObserver));
34
+ })(this, function(exports2, pRetry, Emittery, lodash, whiteWebSdk, uuid, syncedStore, valueEnhancer, sideEffectManager, resizeObserver) {
35
35
  "use strict";
36
36
  function _interopDefaultLegacy(e) {
37
37
  return e && typeof e === "object" && "default" in e ? e : { "default": e };
@@ -96,6 +96,8 @@ var __objRest = (source, exclude) => {
96
96
  const INIT_DIR = "/init";
97
97
  const SETUP_APP_DELAY = 50;
98
98
  const MAX_PAGE_SIZE = 500;
99
+ const SCROLL_MODE_BASE_WIDTH = 1600;
100
+ const SCROLL_MODE_BASE_HEIGHT = SCROLL_MODE_BASE_WIDTH * 3;
99
101
  const callbacks = new Emittery__default["default"]();
100
102
  class AppCreateQueue {
101
103
  constructor() {
@@ -516,67 +518,6 @@ var __objRest = (source, exclude) => {
516
518
  }, 0);
517
519
  return delimiterCount === 1;
518
520
  };
519
- class CameraSynchronizer {
520
- constructor(saveCamera) {
521
- this.saveCamera = saveCamera;
522
- this.setRect = (rect, updateCamera = true) => {
523
- this.rect = rect;
524
- if (this.remoteCamera && this.remoteSize && updateCamera) {
525
- this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
526
- }
527
- };
528
- this.onRemoteUpdate = lodash.throttle((camera, size) => {
529
- this.remoteCamera = camera;
530
- this.remoteSize = size;
531
- if (this.remoteSize && this.rect) {
532
- const nextScale = camera.scale * computedMinScale(size, this.rect);
533
- const config = {
534
- scale: nextScale
535
- };
536
- if (camera.centerX !== null) {
537
- config.centerX = camera.centerX;
538
- }
539
- if (camera.centerY !== null) {
540
- config.centerY = camera.centerY;
541
- }
542
- console.trace("moveCamera");
543
- this.moveCamera(config);
544
- }
545
- }, 10);
546
- }
547
- setView(view) {
548
- this.view = view;
549
- }
550
- onRemoteSizeUpdate(size) {
551
- var _a;
552
- this.remoteSize = size;
553
- const needMoveCamera = !lodash.isEqual(lodash.pick(this.rect, ["width", "height"]), lodash.pick(size, ["width", "height"]));
554
- if (this.rect && this.remoteCamera && needMoveCamera) {
555
- if (!this.view)
556
- return;
557
- const currentCamera = this.view.camera;
558
- (_a = this.view) == null ? void 0 : _a.moveCameraToContain({
559
- width: size.width,
560
- height: size.height,
561
- originX: currentCamera.centerX - size.width / 2,
562
- originY: currentCamera.centerY - size.height / 2
563
- });
564
- }
565
- }
566
- onLocalCameraUpdate(camera) {
567
- this.saveCamera(camera);
568
- this.remoteCamera = camera;
569
- }
570
- moveCamera(camera) {
571
- var _a;
572
- (_a = this.view) == null ? void 0 : _a.moveCamera(__spreadProps(__spreadValues({}, camera), { animationMode: whiteWebSdk.AnimationMode.Immediately }));
573
- }
574
- }
575
- const computedMinScale = (remoteSize, currentSize) => {
576
- const wScale = currentSize.width / remoteSize.width;
577
- const hScale = currentSize.height / remoteSize.height;
578
- return Math.min(wScale, hScale);
579
- };
580
521
  class AppListeners {
581
522
  constructor(manager) {
582
523
  this.manager = manager;
@@ -677,16 +618,7 @@ var __objRest = (source, exclude) => {
677
618
  }
678
619
  };
679
620
  this.moveCameraHandler = (payload) => {
680
- var _a;
681
- const cameraPayload = payload;
682
- if (payload.scale) {
683
- const remoteSize = this.manager.mainViewProxy.size$.value;
684
- const currentSize = (_a = this.manager.boxManager) == null ? void 0 : _a.stageRect;
685
- if (remoteSize && currentSize) {
686
- cameraPayload.scale = payload.scale * computedMinScale(remoteSize, currentSize);
687
- }
688
- }
689
- this.manager.mainView.moveCamera(cameraPayload);
621
+ this.manager.mainView.moveCamera(payload);
690
622
  };
691
623
  this.moveCameraToContainHandler = (payload) => {
692
624
  this.manager.mainView.moveCameraToContain(payload);
@@ -754,292 +686,6 @@ var __objRest = (source, exclude) => {
754
686
  this.message = "[WindowManager]: room phase only Connected can be bindContainer";
755
687
  }
756
688
  }
757
- const onObjectByEvent = (event) => {
758
- return (object, func) => {
759
- if (object === void 0)
760
- return;
761
- if (whiteWebSdk.listenUpdated) {
762
- const listener = (events) => {
763
- const kinds = events.map((e) => e.kind);
764
- if (kinds.includes(event)) {
765
- func();
766
- }
767
- };
768
- whiteWebSdk.listenUpdated(object, listener);
769
- func();
770
- return () => whiteWebSdk.unlistenUpdated(object, listener);
771
- } else {
772
- return whiteWebSdk.reaction(() => object, () => {
773
- func();
774
- }, {
775
- fireImmediately: true
776
- });
777
- }
778
- };
779
- };
780
- const safeListenPropsUpdated = (getProps, callback, onDestroyed) => {
781
- let disposeListenUpdated = null;
782
- const disposeReaction = whiteWebSdk.reaction(getProps, () => {
783
- if (disposeListenUpdated) {
784
- disposeListenUpdated();
785
- disposeListenUpdated = null;
786
- }
787
- const props = getProps();
788
- if (lodash.isObject(props)) {
789
- disposeListenUpdated = () => whiteWebSdk.unlistenUpdated(props, callback);
790
- whiteWebSdk.listenUpdated(props, callback);
791
- } else {
792
- onDestroyed == null ? void 0 : onDestroyed(props);
793
- }
794
- }, { fireImmediately: true });
795
- return () => {
796
- disposeListenUpdated == null ? void 0 : disposeListenUpdated();
797
- disposeReaction();
798
- };
799
- };
800
- const onObjectRemoved = onObjectByEvent(whiteWebSdk.UpdateEventKind.Removed);
801
- onObjectByEvent(whiteWebSdk.UpdateEventKind.Inserted);
802
- const plainObjectKeys = Object.keys;
803
- function isRef(e) {
804
- return Boolean(lodash.has(e, "__isRef"));
805
- }
806
- function makeRef(v) {
807
- return { k: sideEffectManager.genUID(), v, __isRef: true };
808
- }
809
- class StorageEvent {
810
- constructor() {
811
- this.listeners = /* @__PURE__ */ new Set();
812
- }
813
- get length() {
814
- return this.listeners.size;
815
- }
816
- dispatch(message) {
817
- this.listeners.forEach((callback) => callback(message));
818
- }
819
- addListener(listener) {
820
- this.listeners.add(listener);
821
- }
822
- removeListener(listener) {
823
- this.listeners.delete(listener);
824
- }
825
- }
826
- const STORAGE_NS = "_WM-STORAGE_";
827
- class Storage {
828
- constructor(context, id, defaultState) {
829
- this._sideEffect = new sideEffectManager.SideEffectManager();
830
- this._destroyed = false;
831
- this._refMap = /* @__PURE__ */ new WeakMap();
832
- this._lastValue = /* @__PURE__ */ new Map();
833
- this.onStateChanged = new StorageEvent();
834
- if (defaultState && !lodash.isObject(defaultState)) {
835
- throw new Error(`Default state for Storage ${id} is not an object.`);
836
- }
837
- this._context = context;
838
- this.id = id || null;
839
- this._state = {};
840
- const rawState = this._getRawState(this._state);
841
- if (this._context.isWritable) {
842
- if (this.id === null) {
843
- if (context.isAddApp && defaultState) {
844
- this.setState(defaultState);
845
- }
846
- } else {
847
- if (rawState === this._state || !lodash.isObject(rawState)) {
848
- if (!lodash.get(this._context.getAttributes(), [STORAGE_NS])) {
849
- this._context.updateAttributes([STORAGE_NS], {});
850
- }
851
- this._context.updateAttributes([STORAGE_NS, this.id], this._state);
852
- if (defaultState) {
853
- this.setState(defaultState);
854
- }
855
- }
856
- }
857
- }
858
- plainObjectKeys(rawState).forEach((key) => {
859
- if (this.id === null && key === STORAGE_NS) {
860
- return;
861
- }
862
- try {
863
- const rawValue = lodash.isObject(rawState[key]) ? JSON.parse(JSON.stringify(rawState[key])) : rawState[key];
864
- if (isRef(rawValue)) {
865
- this._state[key] = rawValue.v;
866
- if (lodash.isObject(rawValue.v)) {
867
- this._refMap.set(rawValue.v, rawValue);
868
- }
869
- } else {
870
- this._state[key] = rawValue;
871
- }
872
- } catch (e) {
873
- console.error(e);
874
- }
875
- });
876
- this._sideEffect.addDisposer(safeListenPropsUpdated(() => this.id === null ? context.getAttributes() : lodash.get(context.getAttributes(), [STORAGE_NS, this.id]), this._updateProperties.bind(this), this.destroy.bind(this)));
877
- }
878
- get state() {
879
- if (this._destroyed) {
880
- console.warn(`Accessing state on destroyed Storage "${this.id}"`);
881
- }
882
- return this._state;
883
- }
884
- addStateChangedListener(handler) {
885
- this.onStateChanged.addListener(handler);
886
- return () => this.onStateChanged.removeListener(handler);
887
- }
888
- ensureState(state) {
889
- return this.setState(plainObjectKeys(state).reduce((payload, key) => {
890
- if (!lodash.has(this._state, key)) {
891
- payload[key] = state[key];
892
- }
893
- return payload;
894
- }, {}));
895
- }
896
- setState(state) {
897
- if (this._destroyed) {
898
- console.error(new Error(`Cannot call setState on destroyed Storage "${this.id}".`));
899
- return;
900
- }
901
- if (!this._context.isWritable) {
902
- console.error(new Error(`Cannot setState on Storage "${this.id}" without writable access`), state);
903
- return;
904
- }
905
- const keys = plainObjectKeys(state);
906
- if (keys.length > 0) {
907
- keys.forEach((key) => {
908
- const value = state[key];
909
- if (value === this._state[key]) {
910
- return;
911
- }
912
- if (value === void 0) {
913
- this._lastValue.set(key, this._state[key]);
914
- delete this._state[key];
915
- this._setRawState(key, value);
916
- } else {
917
- this._lastValue.set(key, this._state[key]);
918
- this._state[key] = value;
919
- let payload = value;
920
- if (lodash.isObject(value)) {
921
- let refValue = this._refMap.get(value);
922
- if (!refValue) {
923
- refValue = makeRef(value);
924
- this._refMap.set(value, refValue);
925
- }
926
- payload = refValue;
927
- }
928
- this._setRawState(key, payload);
929
- }
930
- });
931
- }
932
- }
933
- emptyStorage() {
934
- if (lodash.size(this._state) <= 0) {
935
- return;
936
- }
937
- if (this._destroyed) {
938
- console.error(new Error(`Cannot empty destroyed Storage "${this.id}".`));
939
- return;
940
- }
941
- if (!this._context.isWritable) {
942
- console.error(new Error(`Cannot empty Storage "${this.id}" without writable access.`));
943
- return;
944
- }
945
- this.setState(lodash.mapValues(this._state, lodash.noop));
946
- }
947
- deleteStorage() {
948
- if (this.id === null) {
949
- throw new Error(`Cannot delete main Storage`);
950
- }
951
- if (!this._context.isWritable) {
952
- console.error(new Error(`Cannot delete Storage "${this.id}" without writable access.`));
953
- return;
954
- }
955
- this.destroy();
956
- this._context.updateAttributes([STORAGE_NS, this.id], void 0);
957
- }
958
- get destroyed() {
959
- return this._destroyed;
960
- }
961
- destroy() {
962
- this._destroyed = true;
963
- this._sideEffect.flushAll();
964
- }
965
- _getRawState(defaultValue) {
966
- var _a;
967
- if (this.id === null) {
968
- return (_a = this._context.getAttributes()) != null ? _a : defaultValue;
969
- } else {
970
- return lodash.get(this._context.getAttributes(), [STORAGE_NS, this.id], defaultValue);
971
- }
972
- }
973
- _setRawState(key, value) {
974
- if (this.id === null) {
975
- if (key === STORAGE_NS) {
976
- throw new Error(`Cannot set attribute internal filed "${STORAGE_NS}"`);
977
- }
978
- return this._context.updateAttributes([key], value);
979
- } else {
980
- return this._context.updateAttributes([STORAGE_NS, this.id, key], value);
981
- }
982
- }
983
- _updateProperties(actions) {
984
- var _a;
985
- if (this._destroyed) {
986
- console.error(new Error(`Cannot call _updateProperties on destroyed Storage "${this.id}".`));
987
- return;
988
- }
989
- if (actions.length > 0) {
990
- const diffs = {};
991
- for (let i = 0; i < actions.length; i++) {
992
- try {
993
- const action = actions[i];
994
- const key = action.key;
995
- if (this.id === null && key === STORAGE_NS) {
996
- continue;
997
- }
998
- const value = lodash.isObject(action.value) ? JSON.parse(JSON.stringify(action.value)) : action.value;
999
- let oldValue;
1000
- if (this._lastValue.has(key)) {
1001
- oldValue = this._lastValue.get(key);
1002
- this._lastValue.delete(key);
1003
- }
1004
- switch (action.kind) {
1005
- case 2: {
1006
- if (lodash.has(this._state, key)) {
1007
- oldValue = this._state[key];
1008
- delete this._state[key];
1009
- }
1010
- diffs[key] = { oldValue };
1011
- break;
1012
- }
1013
- default: {
1014
- let newValue = value;
1015
- if (isRef(value)) {
1016
- const { k: k2, v } = value;
1017
- const curValue = this._state[key];
1018
- if (lodash.isObject(curValue) && ((_a = this._refMap.get(curValue)) == null ? void 0 : _a.k) === k2) {
1019
- newValue = curValue;
1020
- } else {
1021
- newValue = v;
1022
- if (lodash.isObject(v)) {
1023
- this._refMap.set(v, value);
1024
- }
1025
- }
1026
- }
1027
- if (newValue !== this._state[key]) {
1028
- oldValue = this._state[key];
1029
- this._state[key] = newValue;
1030
- }
1031
- diffs[key] = { newValue, oldValue };
1032
- break;
1033
- }
1034
- }
1035
- } catch (e) {
1036
- console.error(e);
1037
- }
1038
- }
1039
- this.onStateChanged.dispatch(diffs);
1040
- }
1041
- }
1042
- }
1043
689
  class WhiteBoardView {
1044
690
  constructor(view, appContext, appProxy, ensureSize) {
1045
691
  this.view = view;
@@ -1068,11 +714,12 @@ var __objRest = (source, exclude) => {
1068
714
  const scenePath = this.appProxy.scenePath;
1069
715
  if (!scenePath)
1070
716
  return;
717
+ const scenes = Array.isArray(scene) ? scene : [scene || {}];
1071
718
  if (after) {
1072
719
  const nextIndex = this.pageState.index + 1;
1073
- putScenes(this.appContext.room, scenePath, [scene || {}], nextIndex);
720
+ putScenes(this.appContext.room, scenePath, scenes, nextIndex);
1074
721
  } else {
1075
- putScenes(this.appContext.room, scenePath, [scene || {}]);
722
+ putScenes(this.appContext.room, scenePath, scenes);
1076
723
  }
1077
724
  };
1078
725
  this.removePage = async (index2) => {
@@ -1272,10 +919,20 @@ var __objRest = (source, exclude) => {
1272
919
  this.getAppOptions = () => {
1273
920
  return typeof this.appOptions === "function" ? this.appOptions() : this.appOptions;
1274
921
  };
1275
- this.createStorage = (storeId, defaultState) => {
1276
- const storage = new Storage(this, storeId, defaultState);
922
+ this.createStorage = (namespace, defaultState) => {
923
+ const isWritable$ = new valueEnhancer.Val(this.isWritable);
924
+ const plugin$ = new valueEnhancer.Val(this.manager.windowManger);
925
+ const storage = new syncedStore.Storage({
926
+ plugin$,
927
+ isWritable$,
928
+ namespace,
929
+ defaultState
930
+ });
931
+ this.emitter.on("writableChange", (writable) => {
932
+ isWritable$.setValue(writable);
933
+ });
1277
934
  this.emitter.on("destroy", () => {
1278
- storage.destroy();
935
+ storage.disconnect();
1279
936
  });
1280
937
  return storage;
1281
938
  };
@@ -1338,7 +995,7 @@ var __objRest = (source, exclude) => {
1338
995
  }
1339
996
  get storage() {
1340
997
  if (!this._storage) {
1341
- this._storage = new Storage(this);
998
+ this._storage = this.createStorage(this.appId, this.getAttributes());
1342
999
  }
1343
1000
  return this._storage;
1344
1001
  }
@@ -1396,6 +1053,77 @@ var __objRest = (source, exclude) => {
1396
1053
  (_a = this.sceneNode) == null ? void 0 : _a.dispose();
1397
1054
  }
1398
1055
  }
1056
+ class CameraSynchronizer {
1057
+ constructor(saveCamera) {
1058
+ this.saveCamera = saveCamera;
1059
+ this.scale = 1;
1060
+ this.setRect = (rect, updateCamera = true) => {
1061
+ this.rect = rect;
1062
+ if (this.remoteCamera && this.remoteSize && updateCamera) {
1063
+ this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
1064
+ }
1065
+ };
1066
+ this.onRemoteUpdate = lodash.throttle((camera, size) => {
1067
+ this.remoteCamera = camera;
1068
+ this.remoteSize = size;
1069
+ if (this.remoteSize && this.rect) {
1070
+ requestAnimationFrame(() => {
1071
+ this.moveCameraToContian(size);
1072
+ this.moveCamera(camera);
1073
+ });
1074
+ }
1075
+ }, 32);
1076
+ }
1077
+ setView(view) {
1078
+ this.view = view;
1079
+ }
1080
+ onRemoteSizeUpdate(size) {
1081
+ var _a;
1082
+ this.remoteSize = size;
1083
+ const needMoveCamera = !lodash.isEqual(lodash.pick(this.rect, ["width", "height"]), lodash.pick(size, ["width", "height"]));
1084
+ if (this.rect && this.remoteCamera && needMoveCamera) {
1085
+ if (!this.view)
1086
+ return;
1087
+ const currentCamera = this.view.camera;
1088
+ (_a = this.view) == null ? void 0 : _a.moveCameraToContain({
1089
+ width: size.width,
1090
+ height: size.height,
1091
+ originX: currentCamera.centerX - size.width / 2,
1092
+ originY: currentCamera.centerY - size.height / 2
1093
+ });
1094
+ }
1095
+ }
1096
+ onLocalCameraUpdate(camera) {
1097
+ this.saveCamera(camera);
1098
+ this.remoteCamera = camera;
1099
+ }
1100
+ moveCameraToContian(size) {
1101
+ if (!lodash.isEmpty(size) && this.view) {
1102
+ this.view.moveCameraToContain({
1103
+ width: size.width,
1104
+ height: size.height,
1105
+ originX: -size.width / 2,
1106
+ originY: -size.height / 2,
1107
+ animationMode: whiteWebSdk.AnimationMode.Immediately
1108
+ });
1109
+ this.scale = this.view.camera.scale;
1110
+ }
1111
+ }
1112
+ moveCamera(camera) {
1113
+ if (!lodash.isEmpty(camera) && this.view && camera.centerX && camera.centerY) {
1114
+ if (lodash.isEqual(camera, this.view.camera))
1115
+ return;
1116
+ const { centerX, centerY, scale: scale2 } = camera;
1117
+ const needScale = scale2 * (this.scale || 1);
1118
+ this.view.moveCamera({
1119
+ centerX,
1120
+ centerY,
1121
+ scale: needScale,
1122
+ animationMode: whiteWebSdk.AnimationMode.Immediately
1123
+ });
1124
+ }
1125
+ }
1126
+ }
1399
1127
  class ViewSync {
1400
1128
  constructor(context) {
1401
1129
  this.context = context;
@@ -1413,8 +1141,9 @@ var __objRest = (source, exclude) => {
1413
1141
  };
1414
1142
  this.subscribeView = () => {
1415
1143
  return this.context.view$.subscribe((view) => {
1144
+ var _a;
1416
1145
  const currentCamera = this.context.camera$.value;
1417
- if (currentCamera && this.context.size$.value) {
1146
+ if (currentCamera && this.context.size$.value && ((_a = this.needRecoverCamera$) == null ? void 0 : _a.value)) {
1418
1147
  view == null ? void 0 : view.moveCamera({
1419
1148
  scale: 1,
1420
1149
  animationMode: whiteWebSdk.AnimationMode.Immediately
@@ -1463,10 +1192,13 @@ var __objRest = (source, exclude) => {
1463
1192
  return;
1464
1193
  if (!this.isBroadcastMode)
1465
1194
  return;
1466
- if (this.context.size$.value && this.context.stageRect$.value) {
1467
- const diffScale = computedMinScale(this.context.size$.value, this.context.stageRect$.value);
1468
- const remoteScale = camera.scale / diffScale;
1469
- this.synchronizer.onLocalCameraUpdate(__spreadProps(__spreadValues({}, camera), { scale: remoteScale, id: this.context.uid }));
1195
+ const { size$, stageRect$, view$ } = this.context;
1196
+ if (size$.value && stageRect$.value && view$.value) {
1197
+ this.synchronizer.onLocalCameraUpdate(__spreadProps(__spreadValues({}, camera), { id: this.context.uid }));
1198
+ const newSize = __spreadProps(__spreadValues({}, view$.value.size), { id: this.context.uid });
1199
+ if (!lodash.isEqual(size$.value, newSize)) {
1200
+ this.context.storeSize(newSize);
1201
+ }
1470
1202
  }
1471
1203
  };
1472
1204
  this.synchronizer = this.createSynchronizer();
@@ -1477,9 +1209,13 @@ var __objRest = (source, exclude) => {
1477
1209
  this.subscribeSize(),
1478
1210
  this.subscribeStageRect()
1479
1211
  ]);
1212
+ if (context.viewMode$) {
1213
+ this.needRecoverCamera$ = valueEnhancer.derive(context.viewMode$, (mode) => mode !== "scroll");
1214
+ }
1480
1215
  const camera$size$ = valueEnhancer.combine([this.context.camera$, this.context.size$]);
1481
1216
  camera$size$.reaction(([camera, size]) => {
1482
- if (camera && size) {
1217
+ var _a;
1218
+ if (camera && size && ((_a = this.needRecoverCamera$) == null ? void 0 : _a.value)) {
1483
1219
  this.synchronizer.onRemoteUpdate(camera, size);
1484
1220
  camera$size$.destroy();
1485
1221
  }
@@ -2560,6 +2296,51 @@ var __objRest = (source, exclude) => {
2560
2296
  this.sideEffectManager.flushAll();
2561
2297
  }
2562
2298
  }
2299
+ const onObjectByEvent = (event) => {
2300
+ return (object, func) => {
2301
+ if (object === void 0)
2302
+ return;
2303
+ if (whiteWebSdk.listenUpdated) {
2304
+ const listener = (events) => {
2305
+ const kinds = events.map((e) => e.kind);
2306
+ if (kinds.includes(event)) {
2307
+ func();
2308
+ }
2309
+ };
2310
+ whiteWebSdk.listenUpdated(object, listener);
2311
+ func();
2312
+ return () => whiteWebSdk.unlistenUpdated(object, listener);
2313
+ } else {
2314
+ return whiteWebSdk.reaction(() => object, () => {
2315
+ func();
2316
+ }, {
2317
+ fireImmediately: true
2318
+ });
2319
+ }
2320
+ };
2321
+ };
2322
+ const safeListenPropsUpdated = (getProps, callback, onDestroyed) => {
2323
+ let disposeListenUpdated = null;
2324
+ const disposeReaction = whiteWebSdk.reaction(getProps, () => {
2325
+ if (disposeListenUpdated) {
2326
+ disposeListenUpdated();
2327
+ disposeListenUpdated = null;
2328
+ }
2329
+ const props = getProps();
2330
+ if (lodash.isObject(props)) {
2331
+ disposeListenUpdated = () => whiteWebSdk.unlistenUpdated(props, callback);
2332
+ whiteWebSdk.listenUpdated(props, callback);
2333
+ } else {
2334
+ onDestroyed == null ? void 0 : onDestroyed(props);
2335
+ }
2336
+ }, { fireImmediately: true });
2337
+ return () => {
2338
+ disposeListenUpdated == null ? void 0 : disposeListenUpdated();
2339
+ disposeReaction();
2340
+ };
2341
+ };
2342
+ const onObjectRemoved = onObjectByEvent(whiteWebSdk.UpdateEventKind.Removed);
2343
+ onObjectByEvent(whiteWebSdk.UpdateEventKind.Inserted);
2563
2344
  class RedoUndo {
2564
2345
  constructor(context) {
2565
2346
  this.context = context;
@@ -2619,24 +2400,181 @@ var __objRest = (source, exclude) => {
2619
2400
  this.disposePrevFocusViewRedoUndoListeners(this.context.focus());
2620
2401
  }
2621
2402
  }
2403
+ const createScrollStorage = (manager) => {
2404
+ return new syncedStore.Storage({
2405
+ plugin$: new valueEnhancer.Val(manager.windowManger),
2406
+ isWritable$: manager.isWritable$,
2407
+ namespace: "scrollStorage",
2408
+ defaultState: { scrollTop: 0 }
2409
+ });
2410
+ };
2411
+ function clamp$2(x2, min, max) {
2412
+ return x2 < min ? min : x2 > max ? max : x2;
2413
+ }
2414
+ class ScrollMode {
2415
+ constructor(manager) {
2416
+ var _a;
2417
+ this.manager = manager;
2418
+ this.sideEffect = new sideEffectManager.SideEffectManager();
2419
+ this.baseWidth = SCROLL_MODE_BASE_WIDTH;
2420
+ this.baseHeight = SCROLL_MODE_BASE_HEIGHT;
2421
+ this.initScroll = () => {
2422
+ const halfWbHeight = this._size$.value.height / 2 / this._scale$.value;
2423
+ const scrollTop = this._scrollTop$.value;
2424
+ this._scrollTop$.setValue(clamp$2(scrollTop, halfWbHeight, this.baseHeight - halfWbHeight) - 0.01);
2425
+ };
2426
+ this.getWhiteboardElement = (root) => {
2427
+ const className = ".netless-window-manager-main-view";
2428
+ return root && root.querySelector(className);
2429
+ };
2430
+ this.onWheel = (ev) => {
2431
+ var _a2;
2432
+ const target = ev.target;
2433
+ if (this.manager.canOperate && ((_a2 = this._whiteboard$.value) == null ? void 0 : _a2.contains(target))) {
2434
+ ev.preventDefault();
2435
+ ev.stopPropagation();
2436
+ const dy = ev.deltaY || 0;
2437
+ const { width } = this._size$.value;
2438
+ if (dy && width > 0) {
2439
+ const halfWbHeight = this._size$.value.height / 2 / this._scale$.value;
2440
+ const scrollTop = this._scrollTop$.value + dy / this._scale$.value;
2441
+ this.scrollStorage.setState({
2442
+ scrollTop: clamp$2(scrollTop, halfWbHeight, this.baseHeight - halfWbHeight)
2443
+ });
2444
+ callbacks.emit("userScroll");
2445
+ }
2446
+ }
2447
+ };
2448
+ this._root$ = new valueEnhancer.Val(null);
2449
+ this._mainView$ = new valueEnhancer.Val(this.manager.mainView);
2450
+ this._mainView$.value.disableCameraTransform = true;
2451
+ if ((_a = manager.scrollBaseSize$) == null ? void 0 : _a.value) {
2452
+ this.baseWidth = manager.scrollBaseSize$.value.width;
2453
+ this.baseHeight = manager.scrollBaseSize$.value.height;
2454
+ }
2455
+ this.scrollStorage = createScrollStorage(manager);
2456
+ const scrollTop$ = new valueEnhancer.Val(this.scrollStorage.state.scrollTop);
2457
+ this._scrollTop$ = scrollTop$;
2458
+ this.sideEffect.push(this.scrollStorage.on("stateChanged", () => {
2459
+ this._scrollTop$.setValue(this.scrollStorage.state.scrollTop);
2460
+ }));
2461
+ const size$ = new valueEnhancer.Val({ width: 0, height: 0 }, { compare: (a, b2) => a.width === b2.width && a.height === b2.height });
2462
+ this._size$ = size$;
2463
+ this.sideEffect.add(() => {
2464
+ const onSizeUpdated = size$.setValue.bind(size$);
2465
+ onSizeUpdated(this._mainView$.value.size);
2466
+ this._mainView$.value.callbacks.on("onSizeUpdated", onSizeUpdated);
2467
+ return () => this._mainView$.value.callbacks.off("onSizeUpdated", onSizeUpdated);
2468
+ });
2469
+ this.sideEffect.add(() => {
2470
+ const onCameraUpdated = (camera) => {
2471
+ const halfWbHeight = size$.value.height / 2 / scale$.value;
2472
+ const scrollTop = camera.centerY;
2473
+ this.scrollStorage.setState({
2474
+ scrollTop: clamp$2(scrollTop, halfWbHeight, this.baseHeight - halfWbHeight)
2475
+ });
2476
+ callbacks.emit("userScroll");
2477
+ };
2478
+ this._mainView$.value.callbacks.on("onCameraUpdatedByDevice", onCameraUpdated);
2479
+ return () => this._mainView$.value.callbacks.off("onCameraUpdatedByDevice", onCameraUpdated);
2480
+ });
2481
+ const scale$ = valueEnhancer.derive(size$, (size) => size.width / this.baseWidth);
2482
+ this._scale$ = scale$;
2483
+ const page$ = new valueEnhancer.Val(0);
2484
+ this.sideEffect.push(valueEnhancer.combine([scrollTop$, size$, scale$]).subscribe(([scrollTop, size, scale2]) => {
2485
+ if (scale2 > 0) {
2486
+ const wbHeight = size.height / scale2;
2487
+ page$.setValue(Math.max(scrollTop / wbHeight - 0.5, 0));
2488
+ }
2489
+ }));
2490
+ this._page$ = page$;
2491
+ this.sideEffect.push(valueEnhancer.combine([scrollTop$, scale$]).subscribe(([scrollTop, scale2]) => {
2492
+ this.updateBound(scrollTop, size$.value, scale2);
2493
+ }));
2494
+ this.sideEffect.push(size$.reaction(() => {
2495
+ this.updateScroll(scrollTop$.value);
2496
+ }));
2497
+ const whiteboard$ = valueEnhancer.derive(this._root$, this.getWhiteboardElement);
2498
+ this._whiteboard$ = whiteboard$;
2499
+ this.sideEffect.push(whiteboard$.reaction((el) => {
2500
+ if (el == null ? void 0 : el.parentElement) {
2501
+ this.sideEffect.addEventListener(el.parentElement, "wheel", this.onWheel, { capture: true, passive: false }, "wheel");
2502
+ }
2503
+ }));
2504
+ this.sideEffect.push(scale$.reaction((scale2) => {
2505
+ if (scale2 > 0) {
2506
+ this.sideEffect.flush("initScroll");
2507
+ this.sideEffect.setTimeout(this.initScroll, 0);
2508
+ }
2509
+ }), "initScroll");
2510
+ const maxScrollPage$ = valueEnhancer.combine([this._size$, this._scale$], ([size, scale2]) => {
2511
+ const halfWbHeight = size.height / 2 / scale2;
2512
+ return (this.baseHeight - halfWbHeight) / halfWbHeight / 2 - 0.51;
2513
+ });
2514
+ this.scrollState$ = valueEnhancer.combine([this._scrollTop$, this._page$, maxScrollPage$], ([scrollTop, page, maxScrollPage]) => {
2515
+ return {
2516
+ scrollTop,
2517
+ page,
2518
+ maxScrollPage
2519
+ };
2520
+ });
2521
+ this.updateScroll(scrollTop$.value);
2522
+ this.sideEffect.push(this.scrollState$.subscribe((state) => callbacks.emit("scrollStateChange", state)));
2523
+ }
2524
+ setRoot(root) {
2525
+ this._root$.setValue(root);
2526
+ }
2527
+ updateScroll(scrollTop) {
2528
+ this._mainView$.value.moveCamera({
2529
+ centerY: scrollTop,
2530
+ animationMode: whiteWebSdk.AnimationMode.Immediately
2531
+ });
2532
+ }
2533
+ updateBound(scrollTop, { height }, scale2) {
2534
+ if (scale2 > 0) {
2535
+ this._mainView$.value.moveCameraToContain({
2536
+ originX: 0,
2537
+ originY: scrollTop - height / scale2 / 2,
2538
+ width: this.baseWidth,
2539
+ height: height / scale2,
2540
+ animationMode: whiteWebSdk.AnimationMode.Immediately
2541
+ });
2542
+ this._mainView$.value.setCameraBound({
2543
+ damping: 1,
2544
+ maxContentMode: () => scale2,
2545
+ minContentMode: () => scale2,
2546
+ centerX: this.baseWidth / 2,
2547
+ centerY: this.baseHeight / 2,
2548
+ width: this.baseWidth,
2549
+ height: this.baseHeight
2550
+ });
2551
+ }
2552
+ }
2553
+ dispose() {
2554
+ this.sideEffect.flushAll();
2555
+ }
2556
+ }
2622
2557
  class AppManager {
2623
2558
  constructor(windowManger) {
2559
+ var _a;
2624
2560
  this.windowManger = windowManger;
2625
2561
  this.appProxies = /* @__PURE__ */ new Map();
2626
2562
  this.appStatus = /* @__PURE__ */ new Map();
2627
2563
  this.store = store;
2628
2564
  this.isReplay = this.windowManger.isReplay;
2629
2565
  this.mainViewScenesLength = 0;
2566
+ this.scrollBaseSize$ = new valueEnhancer.Val(null);
2630
2567
  this.callbacksNode = null;
2631
2568
  this.appCreateQueue = new AppCreateQueue();
2632
2569
  this.sceneIndex$ = new valueEnhancer.Val(void 0);
2633
2570
  this.focused$ = new valueEnhancer.Val(void 0);
2634
2571
  this.members$ = new valueEnhancer.Val([]);
2572
+ this.isWritable$ = new valueEnhancer.Val(Boolean((_a = this.room) == null ? void 0 : _a.isWritable));
2635
2573
  this.sideEffectManager = new sideEffectManager.SideEffectManager();
2636
2574
  this.sceneState = null;
2637
2575
  this.rootDirRemoving = false;
2638
2576
  this.onRemoveScenes = async (params) => {
2639
- var _a, _b;
2577
+ var _a2, _b;
2640
2578
  const { scenePath } = params;
2641
2579
  if (scenePath === ROOT_DIR) {
2642
2580
  await this.onRootDirRemoved();
@@ -2645,7 +2583,7 @@ var __objRest = (source, exclude) => {
2645
2583
  }
2646
2584
  if (isRootDirPage(scenePath)) {
2647
2585
  let nextIndex = this.mainView.focusSceneIndex || 0;
2648
- let sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[nextIndex];
2586
+ let sceneName = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[nextIndex];
2649
2587
  if (!sceneName) {
2650
2588
  nextIndex = 0;
2651
2589
  sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
@@ -2696,11 +2634,11 @@ var __objRest = (source, exclude) => {
2696
2634
  }
2697
2635
  };
2698
2636
  this.removeSceneByIndex = async (index2) => {
2699
- var _a;
2637
+ var _a2;
2700
2638
  const nextIndex = calculateNextIndex(index2, this.windowManger.pageState);
2701
2639
  this.setSceneIndexWithoutSync(nextIndex);
2702
2640
  this.dispatchInternalEvent(Events.SetAppFocusIndex, { type: "main", index: nextIndex });
2703
- const scene = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index2];
2641
+ const scene = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[index2];
2704
2642
  setTimeout(() => {
2705
2643
  if (scene) {
2706
2644
  removeScenes(this.room, `${ROOT_DIR}${scene}`, index2);
@@ -2718,8 +2656,8 @@ var __objRest = (source, exclude) => {
2718
2656
  });
2719
2657
  };
2720
2658
  this.setSceneIndexWithoutSync = (index2) => {
2721
- var _a;
2722
- const sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index2];
2659
+ var _a2;
2660
+ const sceneName = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[index2];
2723
2661
  if (sceneName) {
2724
2662
  this.mainViewProxy.setFocusScenePath(`${ROOT_DIR}${sceneName}`);
2725
2663
  }
@@ -2790,8 +2728,8 @@ var __objRest = (source, exclude) => {
2790
2728
  });
2791
2729
  };
2792
2730
  this.addAppCloseListener = () => {
2793
- var _a;
2794
- (_a = this.refresher) == null ? void 0 : _a.add("appsClose", () => {
2731
+ var _a2;
2732
+ (_a2 = this.refresher) == null ? void 0 : _a2.add("appsClose", () => {
2795
2733
  return onObjectRemoved(this.attributes.apps, () => {
2796
2734
  this.onAppDelete(this.attributes.apps);
2797
2735
  });
@@ -2808,13 +2746,13 @@ var __objRest = (source, exclude) => {
2808
2746
  }
2809
2747
  };
2810
2748
  this.onFocusChange = (focused) => {
2811
- var _a;
2749
+ var _a2;
2812
2750
  if (this.focused$.value !== focused) {
2813
2751
  callbacks.emit("focusedChange", focused);
2814
2752
  emitter.emit("focusedChange", { focused, prev: this.focused$.value });
2815
2753
  this.focused$.setValue(focused);
2816
2754
  if (focused !== void 0) {
2817
- (_a = this.boxManager) == null ? void 0 : _a.focusBox({ appId: focused });
2755
+ (_a2 = this.boxManager) == null ? void 0 : _a2.focusBox({ appId: focused });
2818
2756
  setTimeout(() => {
2819
2757
  const appProxy = this.appProxies.get(focused);
2820
2758
  if (appProxy) {
@@ -2840,14 +2778,14 @@ var __objRest = (source, exclude) => {
2840
2778
  });
2841
2779
  };
2842
2780
  this.onMinimized = (minimized) => {
2843
- var _a, _b;
2844
- if (((_a = this.boxManager) == null ? void 0 : _a.minimized) !== minimized) {
2781
+ var _a2, _b;
2782
+ if (((_a2 = this.boxManager) == null ? void 0 : _a2.minimized) !== minimized) {
2845
2783
  if (minimized === true) {
2846
2784
  (_b = this.boxManager) == null ? void 0 : _b.blurAllBox();
2847
2785
  }
2848
2786
  setTimeout(() => {
2849
- var _a2;
2850
- (_a2 = this.boxManager) == null ? void 0 : _a2.setMinimized(Boolean(minimized));
2787
+ var _a3;
2788
+ (_a3 = this.boxManager) == null ? void 0 : _a3.setMinimized(Boolean(minimized));
2851
2789
  }, 0);
2852
2790
  }
2853
2791
  };
@@ -2887,11 +2825,11 @@ var __objRest = (source, exclude) => {
2887
2825
  }
2888
2826
  };
2889
2827
  this.displayerWritableListener = (isReadonly) => {
2890
- var _a, _b;
2828
+ var _a2, _b;
2891
2829
  const isWritable = !isReadonly;
2892
2830
  const isManualWritable = this.windowManger.readonly === void 0 || !this.windowManger.readonly;
2893
2831
  if (this.windowManger.readonly === void 0) {
2894
- (_a = this.boxManager) == null ? void 0 : _a.setReadonly(isReadonly);
2832
+ (_a2 = this.boxManager) == null ? void 0 : _a2.setReadonly(isReadonly);
2895
2833
  } else {
2896
2834
  (_b = this.boxManager) == null ? void 0 : _b.setReadonly(!(isWritable && isManualWritable));
2897
2835
  }
@@ -2904,6 +2842,7 @@ var __objRest = (source, exclude) => {
2904
2842
  }
2905
2843
  }
2906
2844
  emitter.emit("writableChange", isWritable);
2845
+ this.isWritable$.setValue(isWritable);
2907
2846
  };
2908
2847
  this.updateSceneIndex = () => {
2909
2848
  const scenePath = this.store.getMainViewScenePath();
@@ -2936,10 +2875,10 @@ var __objRest = (source, exclude) => {
2936
2875
  this.refresher.setContext({ emitter });
2937
2876
  this.sideEffectManager.add(() => {
2938
2877
  return () => {
2939
- var _a, _b, _c;
2878
+ var _a2, _b, _c;
2940
2879
  this.appCreateQueue.destroy();
2941
2880
  this.mainViewProxy.destroy();
2942
- (_a = this.refresher) == null ? void 0 : _a.destroy();
2881
+ (_a2 = this.refresher) == null ? void 0 : _a2.destroy();
2943
2882
  this.viewManager.destroy();
2944
2883
  (_b = this.boxManager) == null ? void 0 : _b.destroy();
2945
2884
  (_c = this.callbacksNode) == null ? void 0 : _c.dispose();
@@ -2958,6 +2897,16 @@ var __objRest = (source, exclude) => {
2958
2897
  this.safeUpdateAttributes([Fields.Registered, payload.kind], payload);
2959
2898
  });
2960
2899
  this.members$.setValue(serializeRoomMembers(this.displayer.state.roomMembers));
2900
+ emitter.on("mainViewMounted", () => {
2901
+ this.windowManger.viewMode$.subscribe((viewMode) => {
2902
+ const playground = this.windowManger.playground$.value;
2903
+ if (viewMode === "scroll" && playground) {
2904
+ const scrollMode = new ScrollMode(this);
2905
+ this.scrollMode = scrollMode;
2906
+ scrollMode.setRoot(playground);
2907
+ }
2908
+ });
2909
+ });
2961
2910
  }
2962
2911
  async onRootDirRemoved(needClose = true) {
2963
2912
  await this.setMainViewScenePath(INIT_DIR);
@@ -3129,6 +3078,7 @@ var __objRest = (source, exclude) => {
3129
3078
  bindMainView(divElement, disableCameraTransform) {
3130
3079
  const mainView = this.mainViewProxy.view;
3131
3080
  mainView.disableCameraTransform = disableCameraTransform;
3081
+ console.log("bindMainView", mainView.disableCameraTransform);
3132
3082
  wait(30).then(() => {
3133
3083
  mainView.divElement = divElement;
3134
3084
  emitter.emit("mainViewMounted");
@@ -6895,7 +6845,7 @@ var __objRest = (source, exclude) => {
6895
6845
  this.initCursorInstance = (uid) => {
6896
6846
  let cursorInstance = this.cursorInstances.get(uid);
6897
6847
  if (!cursorInstance) {
6898
- cursorInstance = new Cursor(this.manager, uid, this, WindowManager.playground);
6848
+ cursorInstance = new Cursor(this.manager, uid, this, this.playground$.value);
6899
6849
  this.cursorInstances.set(uid, cursorInstance);
6900
6850
  }
6901
6851
  return cursorInstance;
@@ -6938,7 +6888,7 @@ var __objRest = (source, exclude) => {
6938
6888
  this.hideCursor(this.manager.uid);
6939
6889
  };
6940
6890
  this.roomMembers = (_a = this.manager.room) == null ? void 0 : _a.state.roomMembers;
6941
- const playground = WindowManager.playground;
6891
+ const playground = this.playground$.value;
6942
6892
  if (playground) {
6943
6893
  this.setupWrapper(playground);
6944
6894
  }
@@ -6952,6 +6902,9 @@ var __objRest = (source, exclude) => {
6952
6902
  this.applianceIcons = __spreadValues(__spreadValues({}, ApplianceMap), applianceIcons);
6953
6903
  }
6954
6904
  }
6905
+ get playground$() {
6906
+ return this.manager.windowManger.playground$;
6907
+ }
6955
6908
  canMoveCursor(member) {
6956
6909
  const isLaserPointer = (member == null ? void 0 : member.memberState.currentApplianceName) === whiteWebSdk.ApplianceNames.laserPointer;
6957
6910
  return this.enableCursor || isLaserPointer;
@@ -11689,70 +11642,35 @@ var __objRest = (source, exclude) => {
11689
11642
  const _WindowManager = class extends whiteWebSdk.InvisiblePlugin {
11690
11643
  constructor(context) {
11691
11644
  super(context);
11692
- this.version = "1.0.0-canary.53";
11693
- this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.37", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.2", "side-effect-manager": "^1.1.1", "uuid": "^7.0.3", "value-enhancer": "^1.3.2" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.3.3", "@netless/app-plyr": "0.2.2", "@playwright/test": "^1.23.2", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.49", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.6", "@types/node": "^18.0.3", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.2", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.3", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.1", "vitest": "^0.18.0", "white-web-sdk": "2.16.26" } };
11645
+ this.version = "1.0.0-canary.54";
11646
+ this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/synced-store": "^2.0.7", "@netless/telebox-insider": "1.0.0-alpha.37", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.2", "side-effect-manager": "^1.2.1", "uuid": "^7.0.3", "value-enhancer": "^1.3.2" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.3.3", "@netless/app-plyr": "0.2.2", "@playwright/test": "^1.23.2", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.49", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.6", "@types/node": "^18.0.3", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.2", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.3", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.1", "vitest": "^0.18.0", "white-web-sdk": "^2.16.35" } };
11694
11647
  this.emitter = callbacks;
11695
11648
  this.viewMode = whiteWebSdk.ViewMode.Broadcaster;
11696
11649
  this.viewMode$ = new valueEnhancer.Val(whiteWebSdk.ViewMode.Broadcaster);
11650
+ this.playground$ = new valueEnhancer.Val(void 0);
11697
11651
  this.isReplay = whiteWebSdk.isPlayer(this.displayer);
11698
- this.cameraUpdating = 0;
11699
- this.nextCamera = null;
11700
11652
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
11701
11653
  this.moveCamera = (camera) => {
11702
11654
  var _a;
11655
+ const pureCamera = lodash.omit(camera, ["animationMode"]);
11703
11656
  const mainViewCamera = __spreadValues({}, this.mainView.camera);
11704
- const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
11705
- if (lodash.isEqual(nextCamera, mainViewCamera))
11657
+ if (lodash.isEqual(__spreadValues(__spreadValues({}, mainViewCamera), pureCamera), mainViewCamera))
11706
11658
  return;
11707
- if (!this.appManager)
11708
- return;
11709
- if (camera.animationMode === whiteWebSdk.AnimationMode.Immediately) {
11710
- this.appManager.mainViewProxy.storeCamera(__spreadValues({
11711
- id: this.appManager.uid
11712
- }, nextCamera));
11713
- } else {
11714
- const remoteCamera = this.appManager.mainViewProxy.size$.value;
11715
- const currentSize = (_a = this.boxManager) == null ? void 0 : _a.stageRect;
11716
- let nextScale;
11717
- if (camera.scale && remoteCamera && currentSize) {
11718
- nextScale = camera.scale * computedMinScale(remoteCamera, currentSize);
11719
- }
11720
- if (nextScale) {
11721
- this.mainView.moveCamera(__spreadProps(__spreadValues({}, camera), {
11722
- scale: nextScale
11723
- }));
11724
- } else {
11725
- this.mainView.moveCamera(camera);
11726
- }
11727
- this.appManager.dispatchInternalEvent(Events.MoveCamera, camera);
11728
- this.mainView.callbacks.off("onCameraUpdated", this.onCameraUpdated);
11729
- clearTimeout(this.cameraUpdating);
11730
- this.cameraUpdating = 0;
11731
- this.mainView.callbacks.on("onCameraUpdated", this.onCameraUpdated);
11732
- if (nextScale) {
11733
- this.nextCamera = nextCamera;
11734
- }
11735
- }
11736
- };
11737
- this.onCameraUpdated = () => {
11738
- if (this.cameraUpdating) {
11739
- clearTimeout(this.cameraUpdating);
11740
- this.cameraUpdating = 0;
11741
- }
11742
- this.cameraUpdating = setTimeout(() => {
11743
- this.mainView.callbacks.off("onCameraUpdated", this.onCameraUpdated);
11744
- clearTimeout(this.cameraUpdating);
11745
- this.cameraUpdating = 0;
11746
- if (!this.appManager || !this.nextCamera)
11747
- return;
11748
- this.appManager.mainViewProxy.storeCamera(__spreadValues({
11749
- id: this.appManager.uid
11750
- }, this.nextCamera));
11751
- this.nextCamera = null;
11752
- }, 50);
11659
+ this.debouncedStoreCamera();
11660
+ this.mainView.moveCamera(camera);
11661
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCamera, camera);
11662
+ };
11663
+ this.debouncedStoreCamera = () => {
11664
+ const storeCamera = lodash.debounce(() => {
11665
+ var _a, _b;
11666
+ (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.storeCurrentCamera();
11667
+ (_b = this.appManager) == null ? void 0 : _b.mainViewProxy.storeCurrentSize();
11668
+ this.mainView.callbacks.off("onCameraUpdated", storeCamera);
11669
+ }, 200);
11670
+ this.mainView.callbacks.on("onCameraUpdated", storeCamera);
11753
11671
  };
11754
11672
  _WindowManager.displayer = context.displayer;
11755
- window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.37", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.2", "side-effect-manager": "^1.1.1", "uuid": "^7.0.3", "value-enhancer": "^1.3.2" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.3.3", "@netless/app-plyr": "0.2.2", "@playwright/test": "^1.23.2", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.49", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.6", "@types/node": "^18.0.3", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.2", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.3", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.1", "vitest": "^0.18.0", "white-web-sdk": "2.16.26" } };
11673
+ window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/synced-store": "^2.0.7", "@netless/telebox-insider": "1.0.0-alpha.37", "emittery": "^0.11.0", "lodash": "^4.17.21", "p-retry": "^4.6.2", "side-effect-manager": "^1.2.1", "uuid": "^7.0.3", "value-enhancer": "^1.3.2" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.3.3", "@netless/app-plyr": "0.2.2", "@playwright/test": "^1.23.2", "@rollup/plugin-commonjs": "^20.0.0", "@rollup/plugin-node-resolve": "^13.0.4", "@rollup/plugin-url": "^6.1.0", "@sveltejs/vite-plugin-svelte": "^1.0.0-next.49", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.6", "@types/node": "^18.0.3", "@types/uuid": "^8.3.4", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.2", "cypress": "^8.7.0", "dotenv": "^10.0.0", "eslint": "^7.32.0", "eslint-config-prettier": "^8.3.0", "eslint-plugin-svelte3": "^3.2.0", "jsdom": "^19.0.0", "less": "^4.1.3", "prettier": "^2.3.2", "prettier-plugin-svelte": "^2.4.0", "rollup-plugin-analyzer": "^4.0.0", "rollup-plugin-styles": "^3.14.1", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.5.3", "vite-plugin-dts": "^1.2.1", "vitest": "^0.18.0", "white-web-sdk": "^2.16.35" } };
11756
11674
  }
11757
11675
  static async mount(params) {
11758
11676
  var _a;
@@ -11799,6 +11717,9 @@ var __objRest = (source, exclude) => {
11799
11717
  }
11800
11718
  manager.containerSizeRatio = _WindowManager.containerSizeRatio;
11801
11719
  await manager.ensureAttributes();
11720
+ if (params.viewMode) {
11721
+ manager.viewMode$.setValue(params.viewMode);
11722
+ }
11802
11723
  manager.appManager = new AppManager(manager);
11803
11724
  manager._pageState = new PageStateImpl(manager.appManager);
11804
11725
  manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
@@ -11816,6 +11737,9 @@ var __objRest = (source, exclude) => {
11816
11737
  if (params.container) {
11817
11738
  manager.bindContainer(params.container);
11818
11739
  }
11740
+ if (params.scrollModeWidth && params.scrollModeHeight) {
11741
+ manager.appManager.scrollBaseSize$.setValue({ width: params.scrollModeWidth, height: params.scrollModeHeight });
11742
+ }
11819
11743
  replaceRoomFunction(room, manager);
11820
11744
  emitter.emit("onCreated");
11821
11745
  _WindowManager.isCreated = true;
@@ -11884,6 +11808,7 @@ var __objRest = (source, exclude) => {
11884
11808
  this.bindMainView(mainViewElement, params.disableCameraTransform);
11885
11809
  if (_WindowManager.playground) {
11886
11810
  (_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.playground);
11811
+ this.playground$.setValue(_WindowManager.playground);
11887
11812
  }
11888
11813
  }
11889
11814
  }
@@ -12099,10 +12024,11 @@ var __objRest = (source, exclude) => {
12099
12024
  if (mode === whiteWebSdk.ViewMode.Broadcaster) {
12100
12025
  if (this.canOperate) {
12101
12026
  mainViewProxy == null ? void 0 : mainViewProxy.storeCurrentCamera();
12027
+ mainViewProxy == null ? void 0 : mainViewProxy.storeCurrentSize();
12102
12028
  }
12103
12029
  mainViewProxy == null ? void 0 : mainViewProxy.start();
12104
12030
  }
12105
- if (mode === whiteWebSdk.ViewMode.Freedom) {
12031
+ if (mode === whiteWebSdk.ViewMode.Freedom || mode === "scroll") {
12106
12032
  mainViewProxy == null ? void 0 : mainViewProxy.stop();
12107
12033
  }
12108
12034
  this.viewMode = mode;
@@ -12253,6 +12179,10 @@ var __objRest = (source, exclude) => {
12253
12179
  throw new AppManagerNotInitError();
12254
12180
  }
12255
12181
  }
12182
+ get scrollState() {
12183
+ var _a, _b;
12184
+ return (_b = (_a = this.appManager) == null ? void 0 : _a.scrollMode) == null ? void 0 : _b.scrollState$.value;
12185
+ }
12256
12186
  get teleboxManager() {
12257
12187
  if (!this.boxManager) {
12258
12188
  throw new BoxManagerNotInitializeError();
@@ -12271,6 +12201,12 @@ var __objRest = (source, exclude) => {
12271
12201
  var _a;
12272
12202
  return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
12273
12203
  }
12204
+ moveCameraToContain(rectangle) {
12205
+ var _a;
12206
+ this.debouncedStoreCamera();
12207
+ this.mainView.moveCameraToContain(rectangle);
12208
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
12209
+ }
12274
12210
  convertToPointInWorld(point) {
12275
12211
  return this.mainView.convertToPointInWorld(point);
12276
12212
  }