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

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 +375 -444
  2. package/dist/index.es.js +421 -490
  3. package/dist/index.umd.js +375 -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 +18 -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 +219 -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,176 @@ 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
+ const maxScrollPage$ = valueEnhancer.combine([this._size$, this._scale$], ([size, scale2]) => {
2505
+ const halfWbHeight = size.height / 2 / scale2;
2506
+ return (this.baseHeight - halfWbHeight) / halfWbHeight / 2 - 0.51;
2507
+ });
2508
+ this.scrollState$ = valueEnhancer.combine([this._scrollTop$, this._page$, maxScrollPage$], ([scrollTop, page, maxScrollPage]) => {
2509
+ return {
2510
+ scrollTop,
2511
+ page,
2512
+ maxScrollPage
2513
+ };
2514
+ });
2515
+ this.updateScroll(scrollTop$.value);
2516
+ this.sideEffect.push(this.scrollState$.subscribe((state) => callbacks.emit("scrollStateChange", state)));
2517
+ this.initScroll();
2518
+ }
2519
+ setRoot(root) {
2520
+ this._root$.setValue(root);
2521
+ }
2522
+ updateScroll(scrollTop) {
2523
+ this._mainView$.value.moveCamera({
2524
+ centerY: scrollTop,
2525
+ animationMode: whiteWebSdk.AnimationMode.Immediately
2526
+ });
2527
+ }
2528
+ updateBound(scrollTop, { height }, scale2) {
2529
+ if (scale2 > 0) {
2530
+ this._mainView$.value.moveCameraToContain({
2531
+ originX: 0,
2532
+ originY: scrollTop - height / scale2 / 2,
2533
+ width: this.baseWidth,
2534
+ height: height / scale2,
2535
+ animationMode: whiteWebSdk.AnimationMode.Immediately
2536
+ });
2537
+ this._mainView$.value.setCameraBound({
2538
+ damping: 1,
2539
+ maxContentMode: () => scale2,
2540
+ minContentMode: () => scale2,
2541
+ centerX: this.baseWidth / 2,
2542
+ centerY: this.baseHeight / 2,
2543
+ width: this.baseWidth,
2544
+ height: this.baseHeight
2545
+ });
2546
+ }
2547
+ }
2548
+ dispose() {
2549
+ this.sideEffect.flushAll();
2550
+ }
2551
+ }
2622
2552
  class AppManager {
2623
2553
  constructor(windowManger) {
2554
+ var _a;
2624
2555
  this.windowManger = windowManger;
2625
2556
  this.appProxies = /* @__PURE__ */ new Map();
2626
2557
  this.appStatus = /* @__PURE__ */ new Map();
2627
2558
  this.store = store;
2628
2559
  this.isReplay = this.windowManger.isReplay;
2629
2560
  this.mainViewScenesLength = 0;
2561
+ this.scrollBaseSize$ = new valueEnhancer.Val(null);
2630
2562
  this.callbacksNode = null;
2631
2563
  this.appCreateQueue = new AppCreateQueue();
2632
2564
  this.sceneIndex$ = new valueEnhancer.Val(void 0);
2633
2565
  this.focused$ = new valueEnhancer.Val(void 0);
2634
2566
  this.members$ = new valueEnhancer.Val([]);
2567
+ this.isWritable$ = new valueEnhancer.Val(Boolean((_a = this.room) == null ? void 0 : _a.isWritable));
2635
2568
  this.sideEffectManager = new sideEffectManager.SideEffectManager();
2636
2569
  this.sceneState = null;
2637
2570
  this.rootDirRemoving = false;
2638
2571
  this.onRemoveScenes = async (params) => {
2639
- var _a, _b;
2572
+ var _a2, _b;
2640
2573
  const { scenePath } = params;
2641
2574
  if (scenePath === ROOT_DIR) {
2642
2575
  await this.onRootDirRemoved();
@@ -2645,7 +2578,7 @@ var __objRest = (source, exclude) => {
2645
2578
  }
2646
2579
  if (isRootDirPage(scenePath)) {
2647
2580
  let nextIndex = this.mainView.focusSceneIndex || 0;
2648
- let sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[nextIndex];
2581
+ let sceneName = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[nextIndex];
2649
2582
  if (!sceneName) {
2650
2583
  nextIndex = 0;
2651
2584
  sceneName = (_b = this.callbacksNode) == null ? void 0 : _b.scenes[nextIndex];
@@ -2696,11 +2629,11 @@ var __objRest = (source, exclude) => {
2696
2629
  }
2697
2630
  };
2698
2631
  this.removeSceneByIndex = async (index2) => {
2699
- var _a;
2632
+ var _a2;
2700
2633
  const nextIndex = calculateNextIndex(index2, this.windowManger.pageState);
2701
2634
  this.setSceneIndexWithoutSync(nextIndex);
2702
2635
  this.dispatchInternalEvent(Events.SetAppFocusIndex, { type: "main", index: nextIndex });
2703
- const scene = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index2];
2636
+ const scene = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[index2];
2704
2637
  setTimeout(() => {
2705
2638
  if (scene) {
2706
2639
  removeScenes(this.room, `${ROOT_DIR}${scene}`, index2);
@@ -2718,8 +2651,8 @@ var __objRest = (source, exclude) => {
2718
2651
  });
2719
2652
  };
2720
2653
  this.setSceneIndexWithoutSync = (index2) => {
2721
- var _a;
2722
- const sceneName = (_a = this.callbacksNode) == null ? void 0 : _a.scenes[index2];
2654
+ var _a2;
2655
+ const sceneName = (_a2 = this.callbacksNode) == null ? void 0 : _a2.scenes[index2];
2723
2656
  if (sceneName) {
2724
2657
  this.mainViewProxy.setFocusScenePath(`${ROOT_DIR}${sceneName}`);
2725
2658
  }
@@ -2790,8 +2723,8 @@ var __objRest = (source, exclude) => {
2790
2723
  });
2791
2724
  };
2792
2725
  this.addAppCloseListener = () => {
2793
- var _a;
2794
- (_a = this.refresher) == null ? void 0 : _a.add("appsClose", () => {
2726
+ var _a2;
2727
+ (_a2 = this.refresher) == null ? void 0 : _a2.add("appsClose", () => {
2795
2728
  return onObjectRemoved(this.attributes.apps, () => {
2796
2729
  this.onAppDelete(this.attributes.apps);
2797
2730
  });
@@ -2808,13 +2741,13 @@ var __objRest = (source, exclude) => {
2808
2741
  }
2809
2742
  };
2810
2743
  this.onFocusChange = (focused) => {
2811
- var _a;
2744
+ var _a2;
2812
2745
  if (this.focused$.value !== focused) {
2813
2746
  callbacks.emit("focusedChange", focused);
2814
2747
  emitter.emit("focusedChange", { focused, prev: this.focused$.value });
2815
2748
  this.focused$.setValue(focused);
2816
2749
  if (focused !== void 0) {
2817
- (_a = this.boxManager) == null ? void 0 : _a.focusBox({ appId: focused });
2750
+ (_a2 = this.boxManager) == null ? void 0 : _a2.focusBox({ appId: focused });
2818
2751
  setTimeout(() => {
2819
2752
  const appProxy = this.appProxies.get(focused);
2820
2753
  if (appProxy) {
@@ -2840,14 +2773,14 @@ var __objRest = (source, exclude) => {
2840
2773
  });
2841
2774
  };
2842
2775
  this.onMinimized = (minimized) => {
2843
- var _a, _b;
2844
- if (((_a = this.boxManager) == null ? void 0 : _a.minimized) !== minimized) {
2776
+ var _a2, _b;
2777
+ if (((_a2 = this.boxManager) == null ? void 0 : _a2.minimized) !== minimized) {
2845
2778
  if (minimized === true) {
2846
2779
  (_b = this.boxManager) == null ? void 0 : _b.blurAllBox();
2847
2780
  }
2848
2781
  setTimeout(() => {
2849
- var _a2;
2850
- (_a2 = this.boxManager) == null ? void 0 : _a2.setMinimized(Boolean(minimized));
2782
+ var _a3;
2783
+ (_a3 = this.boxManager) == null ? void 0 : _a3.setMinimized(Boolean(minimized));
2851
2784
  }, 0);
2852
2785
  }
2853
2786
  };
@@ -2887,11 +2820,11 @@ var __objRest = (source, exclude) => {
2887
2820
  }
2888
2821
  };
2889
2822
  this.displayerWritableListener = (isReadonly) => {
2890
- var _a, _b;
2823
+ var _a2, _b;
2891
2824
  const isWritable = !isReadonly;
2892
2825
  const isManualWritable = this.windowManger.readonly === void 0 || !this.windowManger.readonly;
2893
2826
  if (this.windowManger.readonly === void 0) {
2894
- (_a = this.boxManager) == null ? void 0 : _a.setReadonly(isReadonly);
2827
+ (_a2 = this.boxManager) == null ? void 0 : _a2.setReadonly(isReadonly);
2895
2828
  } else {
2896
2829
  (_b = this.boxManager) == null ? void 0 : _b.setReadonly(!(isWritable && isManualWritable));
2897
2830
  }
@@ -2904,6 +2837,7 @@ var __objRest = (source, exclude) => {
2904
2837
  }
2905
2838
  }
2906
2839
  emitter.emit("writableChange", isWritable);
2840
+ this.isWritable$.setValue(isWritable);
2907
2841
  };
2908
2842
  this.updateSceneIndex = () => {
2909
2843
  const scenePath = this.store.getMainViewScenePath();
@@ -2936,10 +2870,10 @@ var __objRest = (source, exclude) => {
2936
2870
  this.refresher.setContext({ emitter });
2937
2871
  this.sideEffectManager.add(() => {
2938
2872
  return () => {
2939
- var _a, _b, _c;
2873
+ var _a2, _b, _c;
2940
2874
  this.appCreateQueue.destroy();
2941
2875
  this.mainViewProxy.destroy();
2942
- (_a = this.refresher) == null ? void 0 : _a.destroy();
2876
+ (_a2 = this.refresher) == null ? void 0 : _a2.destroy();
2943
2877
  this.viewManager.destroy();
2944
2878
  (_b = this.boxManager) == null ? void 0 : _b.destroy();
2945
2879
  (_c = this.callbacksNode) == null ? void 0 : _c.dispose();
@@ -2958,6 +2892,16 @@ var __objRest = (source, exclude) => {
2958
2892
  this.safeUpdateAttributes([Fields.Registered, payload.kind], payload);
2959
2893
  });
2960
2894
  this.members$.setValue(serializeRoomMembers(this.displayer.state.roomMembers));
2895
+ emitter.on("mainViewMounted", () => {
2896
+ this.windowManger.viewMode$.subscribe((viewMode) => {
2897
+ const playground = this.windowManger.playground$.value;
2898
+ if (viewMode === "scroll" && playground) {
2899
+ const scrollMode = new ScrollMode(this);
2900
+ this.scrollMode = scrollMode;
2901
+ scrollMode.setRoot(playground);
2902
+ }
2903
+ });
2904
+ });
2961
2905
  }
2962
2906
  async onRootDirRemoved(needClose = true) {
2963
2907
  await this.setMainViewScenePath(INIT_DIR);
@@ -6895,7 +6839,7 @@ var __objRest = (source, exclude) => {
6895
6839
  this.initCursorInstance = (uid) => {
6896
6840
  let cursorInstance = this.cursorInstances.get(uid);
6897
6841
  if (!cursorInstance) {
6898
- cursorInstance = new Cursor(this.manager, uid, this, WindowManager.playground);
6842
+ cursorInstance = new Cursor(this.manager, uid, this, this.playground$.value);
6899
6843
  this.cursorInstances.set(uid, cursorInstance);
6900
6844
  }
6901
6845
  return cursorInstance;
@@ -6938,7 +6882,7 @@ var __objRest = (source, exclude) => {
6938
6882
  this.hideCursor(this.manager.uid);
6939
6883
  };
6940
6884
  this.roomMembers = (_a = this.manager.room) == null ? void 0 : _a.state.roomMembers;
6941
- const playground = WindowManager.playground;
6885
+ const playground = this.playground$.value;
6942
6886
  if (playground) {
6943
6887
  this.setupWrapper(playground);
6944
6888
  }
@@ -6952,6 +6896,9 @@ var __objRest = (source, exclude) => {
6952
6896
  this.applianceIcons = __spreadValues(__spreadValues({}, ApplianceMap), applianceIcons);
6953
6897
  }
6954
6898
  }
6899
+ get playground$() {
6900
+ return this.manager.windowManger.playground$;
6901
+ }
6955
6902
  canMoveCursor(member) {
6956
6903
  const isLaserPointer = (member == null ? void 0 : member.memberState.currentApplianceName) === whiteWebSdk.ApplianceNames.laserPointer;
6957
6904
  return this.enableCursor || isLaserPointer;
@@ -11689,70 +11636,35 @@ var __objRest = (source, exclude) => {
11689
11636
  const _WindowManager = class extends whiteWebSdk.InvisiblePlugin {
11690
11637
  constructor(context) {
11691
11638
  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" } };
11639
+ this.version = "1.0.0-canary.54";
11640
+ 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
11641
  this.emitter = callbacks;
11695
11642
  this.viewMode = whiteWebSdk.ViewMode.Broadcaster;
11696
11643
  this.viewMode$ = new valueEnhancer.Val(whiteWebSdk.ViewMode.Broadcaster);
11644
+ this.playground$ = new valueEnhancer.Val(void 0);
11697
11645
  this.isReplay = whiteWebSdk.isPlayer(this.displayer);
11698
- this.cameraUpdating = 0;
11699
- this.nextCamera = null;
11700
11646
  this.containerSizeRatio = _WindowManager.containerSizeRatio;
11701
11647
  this.moveCamera = (camera) => {
11702
11648
  var _a;
11649
+ const pureCamera = lodash.omit(camera, ["animationMode"]);
11703
11650
  const mainViewCamera = __spreadValues({}, this.mainView.camera);
11704
- const nextCamera = __spreadValues(__spreadValues({}, mainViewCamera), camera);
11705
- if (lodash.isEqual(nextCamera, mainViewCamera))
11651
+ if (lodash.isEqual(__spreadValues(__spreadValues({}, mainViewCamera), pureCamera), mainViewCamera))
11706
11652
  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);
11653
+ this.debouncedStoreCamera();
11654
+ this.mainView.moveCamera(camera);
11655
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCamera, camera);
11656
+ };
11657
+ this.debouncedStoreCamera = () => {
11658
+ const storeCamera = lodash.debounce(() => {
11659
+ var _a, _b;
11660
+ (_a = this.appManager) == null ? void 0 : _a.mainViewProxy.storeCurrentCamera();
11661
+ (_b = this.appManager) == null ? void 0 : _b.mainViewProxy.storeCurrentSize();
11662
+ this.mainView.callbacks.off("onCameraUpdated", storeCamera);
11663
+ }, 200);
11664
+ this.mainView.callbacks.on("onCameraUpdated", storeCamera);
11753
11665
  };
11754
11666
  _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" } };
11667
+ 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
11668
  }
11757
11669
  static async mount(params) {
11758
11670
  var _a;
@@ -11799,6 +11711,9 @@ var __objRest = (source, exclude) => {
11799
11711
  }
11800
11712
  manager.containerSizeRatio = _WindowManager.containerSizeRatio;
11801
11713
  await manager.ensureAttributes();
11714
+ if (params.viewMode) {
11715
+ manager.viewMode$.setValue(params.viewMode);
11716
+ }
11802
11717
  manager.appManager = new AppManager(manager);
11803
11718
  manager._pageState = new PageStateImpl(manager.appManager);
11804
11719
  manager.cursorManager = new CursorManager(manager.appManager, Boolean(cursor), params.applianceIcons);
@@ -11816,6 +11731,9 @@ var __objRest = (source, exclude) => {
11816
11731
  if (params.container) {
11817
11732
  manager.bindContainer(params.container);
11818
11733
  }
11734
+ if (params.scrollModeWidth && params.scrollModeHeight) {
11735
+ manager.appManager.scrollBaseSize$.setValue({ width: params.scrollModeWidth, height: params.scrollModeHeight });
11736
+ }
11819
11737
  replaceRoomFunction(room, manager);
11820
11738
  emitter.emit("onCreated");
11821
11739
  _WindowManager.isCreated = true;
@@ -11884,6 +11802,7 @@ var __objRest = (source, exclude) => {
11884
11802
  this.bindMainView(mainViewElement, params.disableCameraTransform);
11885
11803
  if (_WindowManager.playground) {
11886
11804
  (_b = this.cursorManager) == null ? void 0 : _b.setupWrapper(_WindowManager.playground);
11805
+ this.playground$.setValue(_WindowManager.playground);
11887
11806
  }
11888
11807
  }
11889
11808
  }
@@ -12099,10 +12018,11 @@ var __objRest = (source, exclude) => {
12099
12018
  if (mode === whiteWebSdk.ViewMode.Broadcaster) {
12100
12019
  if (this.canOperate) {
12101
12020
  mainViewProxy == null ? void 0 : mainViewProxy.storeCurrentCamera();
12021
+ mainViewProxy == null ? void 0 : mainViewProxy.storeCurrentSize();
12102
12022
  }
12103
12023
  mainViewProxy == null ? void 0 : mainViewProxy.start();
12104
12024
  }
12105
- if (mode === whiteWebSdk.ViewMode.Freedom) {
12025
+ if (mode === whiteWebSdk.ViewMode.Freedom || mode === "scroll") {
12106
12026
  mainViewProxy == null ? void 0 : mainViewProxy.stop();
12107
12027
  }
12108
12028
  this.viewMode = mode;
@@ -12253,6 +12173,10 @@ var __objRest = (source, exclude) => {
12253
12173
  throw new AppManagerNotInitError();
12254
12174
  }
12255
12175
  }
12176
+ get scrollState() {
12177
+ var _a, _b;
12178
+ return (_b = (_a = this.appManager) == null ? void 0 : _a.scrollMode) == null ? void 0 : _b.scrollState$.value;
12179
+ }
12256
12180
  get teleboxManager() {
12257
12181
  if (!this.boxManager) {
12258
12182
  throw new BoxManagerNotInitializeError();
@@ -12271,6 +12195,12 @@ var __objRest = (source, exclude) => {
12271
12195
  var _a;
12272
12196
  return (_a = this.appManager) == null ? void 0 : _a.closeApp(appId);
12273
12197
  }
12198
+ moveCameraToContain(rectangle) {
12199
+ var _a;
12200
+ this.debouncedStoreCamera();
12201
+ this.mainView.moveCameraToContain(rectangle);
12202
+ (_a = this.appManager) == null ? void 0 : _a.dispatchInternalEvent(Events.MoveCameraToContain, rectangle);
12203
+ }
12274
12204
  convertToPointInWorld(point) {
12275
12205
  return this.mainView.convertToPointInWorld(point);
12276
12206
  }