@netless/window-manager 1.0.0-canary.20 → 1.0.0-canary.21

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.es.js CHANGED
@@ -19,7 +19,7 @@ var __spreadValues = (a2, b2) => {
19
19
  var __spreadProps = (a2, b2) => __defProps(a2, __getOwnPropDescs(b2));
20
20
  import pRetry from "p-retry";
21
21
  import Emittery from "emittery";
22
- import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isNumber, throttle, delay, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
22
+ import { debounce, isEqual, omit, isObject, has, get, size as size$1, mapValues, noop as noop$1, pick, isNumber, throttle, delay, omitBy, isUndefined, isInteger, orderBy, isEmpty, isFunction, isNull } from "lodash";
23
23
  import { ScenePathType, UpdateEventKind, listenUpdated, unlistenUpdated, reaction, WhiteVersion, autorun, toJS, listenDisposed, unlistenDisposed, AnimationMode, ViewMode, isPlayer, isRoom, ApplianceNames, RoomPhase, InvisiblePlugin } from "white-web-sdk";
24
24
  import { v4 } from "uuid";
25
25
  import { genUID, SideEffectManager } from "side-effect-manager";
@@ -33,7 +33,6 @@ var Events = /* @__PURE__ */ ((Events2) => {
33
33
  Events2["AppBoxStateChange"] = "AppBoxStateChange";
34
34
  Events2["GetAttributes"] = "GetAttributes";
35
35
  Events2["UpdateWindowManagerWrapper"] = "UpdateWindowManagerWrapper";
36
- Events2["InitReplay"] = "InitReplay";
37
36
  Events2["WindowCreated"] = "WindowCreated";
38
37
  Events2["SetMainViewScenePath"] = "SetMainViewScenePath";
39
38
  Events2["SetMainViewSceneIndex"] = "SetMainViewSceneIndex";
@@ -661,16 +660,6 @@ const safeListenPropsUpdated = (getProps, callback, onDestroyed) => {
661
660
  };
662
661
  const onObjectRemoved = onObjectByEvent(UpdateEventKind.Removed);
663
662
  onObjectByEvent(UpdateEventKind.Inserted);
664
- const createValSync = (expr, Val2, isAddApp) => {
665
- let skipUpdate = false;
666
- return reaction(expr, (val) => {
667
- if (isAddApp && !skipUpdate) {
668
- skipUpdate = true;
669
- } else {
670
- Val2.setValue(val);
671
- }
672
- }, { fireImmediately: true });
673
- };
674
663
  const plainObjectKeys = Object.keys;
675
664
  function isRef(e2) {
676
665
  return Boolean(has(e2, "__isRef"));
@@ -1300,9 +1289,7 @@ class ViewSync {
1300
1289
  }, "view");
1301
1290
  };
1302
1291
  this.onCameraUpdatedByDevice = (camera) => {
1303
- if (!camera)
1304
- return;
1305
- this.synchronizer.onLocalCameraUpdate(Object.assign(camera, { id: this.context.uid }));
1292
+ this.synchronizer.onLocalCameraUpdate(Object.assign(toJS(camera), { id: this.context.uid }));
1306
1293
  const stage = this.context.stageRect$.value;
1307
1294
  if (stage) {
1308
1295
  const size2 = { width: stage.width, height: stage.height, id: this.context.uid };
@@ -1321,33 +1308,35 @@ class ViewSync {
1321
1308
  }
1322
1309
  });
1323
1310
  this.bindView(this.context.view$.value);
1324
- this.sem.add(() => this.context.view$.subscribe((view) => {
1325
- const currentCamera = this.context.camera$.value;
1326
- if (currentCamera && this.context.size$.value) {
1327
- view == null ? void 0 : view.moveCamera({
1328
- scale: 1,
1329
- animationMode: AnimationMode.Immediately
1330
- });
1331
- this.synchronizer.onRemoteUpdate(currentCamera, this.context.size$.value);
1332
- }
1333
- this.bindView(view);
1334
- }));
1335
- this.sem.add(() => this.context.camera$.subscribe((camera, skipUpdate) => {
1336
- const size2 = this.context.size$.value;
1337
- if (camera && size2 && !skipUpdate) {
1338
- this.synchronizer.onRemoteUpdate(camera, size2);
1339
- }
1340
- }));
1341
- this.sem.add(() => this.context.size$.subscribe((size2) => {
1342
- if (size2) {
1343
- this.synchronizer.onRemoteSizeUpdate(size2);
1344
- }
1345
- }));
1346
- this.sem.add(() => this.context.stageRect$.reaction((rect) => {
1347
- if (rect) {
1348
- this.synchronizer.setRect(rect);
1349
- }
1350
- }));
1311
+ this.sem.add(() => [
1312
+ this.context.view$.subscribe((view) => {
1313
+ const currentCamera = this.context.camera$.value;
1314
+ if (currentCamera && this.context.size$.value) {
1315
+ view == null ? void 0 : view.moveCamera({
1316
+ scale: 1,
1317
+ animationMode: AnimationMode.Immediately
1318
+ });
1319
+ this.synchronizer.onRemoteUpdate(currentCamera, this.context.size$.value);
1320
+ }
1321
+ this.bindView(view);
1322
+ }),
1323
+ this.context.camera$.subscribe((camera, skipUpdate) => {
1324
+ const size2 = this.context.size$.value;
1325
+ if (camera && size2 && !skipUpdate) {
1326
+ this.synchronizer.onRemoteUpdate(camera, size2);
1327
+ }
1328
+ }),
1329
+ this.context.size$.subscribe((size2) => {
1330
+ if (size2) {
1331
+ this.synchronizer.onRemoteSizeUpdate(size2);
1332
+ }
1333
+ }),
1334
+ this.context.stageRect$.reaction((rect) => {
1335
+ if (rect) {
1336
+ this.synchronizer.setRect(rect);
1337
+ }
1338
+ })
1339
+ ]);
1351
1340
  const camera$size$ = combine([this.context.camera$, this.context.size$]);
1352
1341
  camera$size$.reaction(([camera, size2]) => {
1353
1342
  if (camera && size2) {
@@ -1613,27 +1602,15 @@ class AppProxy {
1613
1602
  const attrs = this.store.getAppState(id2);
1614
1603
  if (!attrs)
1615
1604
  return;
1616
- const position = attrs == null ? void 0 : attrs[AppAttributes.Position];
1617
1605
  const focus = this.store.focus;
1618
- const size2 = attrs == null ? void 0 : attrs[AppAttributes.Size];
1619
- const sceneIndex = attrs == null ? void 0 : attrs[AppAttributes.SceneIndex];
1620
1606
  const maximized = (_a2 = this.attributes) == null ? void 0 : _a2["maximized"];
1621
1607
  const minimized = (_b = this.attributes) == null ? void 0 : _b["minimized"];
1622
- const zIndex = attrs == null ? void 0 : attrs.zIndex;
1623
- let payload = { maximized, minimized, zIndex };
1624
- if (position) {
1625
- payload = __spreadProps(__spreadValues({}, payload), { id: id2, x: position.x, y: position.y });
1626
- }
1608
+ let payload = { maximized, minimized, id: id2 };
1609
+ const state = omitBy(attrs, isUndefined);
1627
1610
  if (focus === id2) {
1628
1611
  payload = __spreadProps(__spreadValues({}, payload), { focus: true });
1629
1612
  }
1630
- if (size2) {
1631
- payload = __spreadProps(__spreadValues({}, payload), { width: size2.width, height: size2.height });
1632
- }
1633
- if (sceneIndex) {
1634
- payload = __spreadProps(__spreadValues({}, payload), { sceneIndex });
1635
- }
1636
- return payload;
1613
+ return Object.assign(payload, state);
1637
1614
  };
1638
1615
  this.appAttributesUpdateListener = (appId2) => {
1639
1616
  this.manager.refresher.add(appId2, () => {
@@ -1802,37 +1779,52 @@ class AppProxy {
1802
1779
  createValSync(() => {
1803
1780
  var _a2;
1804
1781
  return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.visible;
1805
- }, box._visible$, this.isAddApp),
1782
+ }, box._visible$),
1806
1783
  createValSync(() => {
1807
1784
  var _a2;
1808
1785
  return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.ratio;
1809
- }, box._ratio$, this.isAddApp),
1786
+ }, box._ratio$),
1810
1787
  createValSync(() => {
1811
1788
  var _a2;
1812
1789
  return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.stageRatio;
1813
- }, box._stageRatio$, this.isAddApp),
1790
+ }, box._stageRatio$),
1814
1791
  createValSync(() => {
1815
1792
  var _a2;
1816
1793
  return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.draggable;
1817
- }, box._draggable$, this.isAddApp),
1794
+ }, box._draggable$),
1818
1795
  createValSync(() => {
1819
1796
  var _a2;
1820
1797
  return (_a2 = this.appAttributes) == null ? void 0 : _a2.state.resizable;
1821
- }, box._resizable$, this.isAddApp),
1822
- box._visible$.subscribe((visible) => {
1798
+ }, box._resizable$),
1799
+ box._visible$.reaction((visible, skipUpdate) => {
1800
+ if (skipUpdate) {
1801
+ return;
1802
+ }
1823
1803
  this.store.updateAppState(this.id, AppAttributes.Visible, visible);
1824
1804
  }),
1825
- box._ratio$.subscribe((ratio) => {
1805
+ box._ratio$.reaction((ratio, skipUpdate) => {
1806
+ console.log("ratio change", ratio, skipUpdate);
1807
+ if (skipUpdate) {
1808
+ return;
1809
+ }
1826
1810
  this.store.updateAppState(this.id, AppAttributes.Ratio, ratio);
1827
1811
  }),
1828
- box._stageRatio$.subscribe((stageRatio) => {
1812
+ box._stageRatio$.reaction((stageRatio, skipUpdate) => {
1813
+ if (skipUpdate) {
1814
+ return;
1815
+ }
1829
1816
  this.store.updateAppState(this.id, AppAttributes.StageRatio, stageRatio);
1830
1817
  }),
1831
- box._draggable$.subscribe((draggable) => {
1818
+ box._draggable$.reaction((draggable, skipUpdate) => {
1819
+ if (skipUpdate) {
1820
+ return;
1821
+ }
1832
1822
  this.store.updateAppState(this.id, AppAttributes.Draggable, draggable);
1833
1823
  }),
1834
- box._resizable$.subscribe((resizable) => {
1835
- console.log("resizable change", resizable);
1824
+ box._resizable$.reaction((resizable, skipUpdate) => {
1825
+ if (skipUpdate) {
1826
+ return;
1827
+ }
1836
1828
  this.store.updateAppState(this.id, AppAttributes.Resizable, resizable);
1837
1829
  })
1838
1830
  ]);
@@ -1954,6 +1946,11 @@ class AppProxy {
1954
1946
  this.box$.setValue(box);
1955
1947
  if (this.isAddApp && this.box) {
1956
1948
  this.store.updateAppState(appId, AppAttributes.ZIndex, this.box.zIndex);
1949
+ this.store.updateAppState(appId, AppAttributes.Visible, this.box.visible);
1950
+ this.store.updateAppState(appId, AppAttributes.Ratio, this.box.ratio);
1951
+ this.store.updateAppState(appId, AppAttributes.StageRatio, this.box.stageRatio);
1952
+ this.store.updateAppState(appId, AppAttributes.Draggable, this.box.draggable);
1953
+ this.store.updateAppState(appId, AppAttributes.Resizable, this.box.resizable);
1957
1954
  this.boxManager.focusBox({ appId }, false);
1958
1955
  }
1959
1956
  } catch (error) {
@@ -2159,6 +2156,13 @@ class AppProxy {
2159
2156
  return this.destroy(true, true, false);
2160
2157
  }
2161
2158
  }
2159
+ const createValSync = (expr, Val2) => {
2160
+ return reaction(expr, (val) => {
2161
+ if (Val2.value !== val && val !== void 0) {
2162
+ Val2.setValue(val, true);
2163
+ }
2164
+ }, { fireImmediately: true });
2165
+ };
2162
2166
  class ViewManager {
2163
2167
  constructor(displayer) {
2164
2168
  this.displayer = displayer;
@@ -2997,7 +3001,9 @@ class AppManager {
2997
3001
  bindMainView(divElement, disableCameraTransform) {
2998
3002
  const mainView = this.mainViewProxy.view;
2999
3003
  mainView.disableCameraTransform = disableCameraTransform;
3000
- mainView.divElement = divElement;
3004
+ wait(30).then(() => {
3005
+ mainView.divElement = divElement;
3006
+ });
3001
3007
  if (!mainView.focusScenePath) {
3002
3008
  this.setMainViewFocusPath();
3003
3009
  }
@@ -4970,15 +4976,16 @@ class BoxManager {
4970
4976
  return this.teleBoxManager.topBox;
4971
4977
  }
4972
4978
  updateBoxState(state) {
4979
+ var _a, _b, _c, _d;
4973
4980
  if (!state)
4974
4981
  return;
4975
4982
  const box = this.getBox(state.id);
4976
4983
  if (box) {
4977
4984
  this.teleBoxManager.update(box.id, {
4978
- x: state.x,
4979
- y: state.y,
4980
- width: state.width || 0.5,
4981
- height: state.height || 0.5,
4985
+ x: (_a = state.position) == null ? void 0 : _a.x,
4986
+ y: (_b = state.position) == null ? void 0 : _b.y,
4987
+ width: ((_c = state.size) == null ? void 0 : _c.width) || 0.5,
4988
+ height: ((_d = state.size) == null ? void 0 : _d.height) || 0.5,
4982
4989
  zIndex: state.zIndex
4983
4990
  }, true);
4984
4991
  setTimeout(() => {
@@ -5936,9 +5943,8 @@ class CursorManager {
5936
5943
  }
5937
5944
  }
5938
5945
  updateContainerRect() {
5939
- var _a, _b;
5940
- this.containerRect = (_a = WindowManager.container) == null ? void 0 : _a.getBoundingClientRect();
5941
- this.wrapperRect = (_b = WindowManager.playground) == null ? void 0 : _b.getBoundingClientRect();
5946
+ var _a;
5947
+ this.wrapperRect = (_a = WindowManager.playground) == null ? void 0 : _a.getBoundingClientRect();
5942
5948
  }
5943
5949
  deleteCursor(uid) {
5944
5950
  this.store.cleanCursor(uid);
@@ -15680,7 +15686,7 @@ const reconnectRefresher = new ReconnectRefresher({ emitter });
15680
15686
  const _WindowManager = class extends InvisiblePlugin {
15681
15687
  constructor(context) {
15682
15688
  super(context);
15683
- this.version = "1.0.0-canary.20";
15689
+ this.version = "1.0.0-canary.21";
15684
15690
  this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "1.0.0-alpha.18", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "side-effect-manager": "^1.1.0", "uuid": "^7.0.3", "value-enhancer": "^1.3.0", "video.js": ">=7" }, "peerDependencies": { "white-web-sdk": "^2.16.0" }, "devDependencies": { "@netless/app-docs-viewer": "^0.2.9", "@netless/app-media-player": "0.1.0-beta.5", "@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.22", "@tsconfig/svelte": "^2.0.1", "@types/debug": "^4.1.7", "@types/lodash": "^4.14.182", "@types/lodash-es": "^4.17.4", "@types/uuid": "^8.3.1", "@typescript-eslint/eslint-plugin": "^4.30.0", "@typescript-eslint/parser": "^4.30.0", "@vitest/ui": "^0.14.1", "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.1", "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", "vitest": "^0.14.1", "white-web-sdk": "2.16.10" } };
15685
15691
  this.emitter = callbacks$1;
15686
15692
  this.viewMode = ViewMode.Broadcaster;