@netless/window-manager 1.0.18 → 1.0.19
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.d.ts +10 -0
- package/dist/index.js +5 -5
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +147 -3
- package/dist/index.mjs.map +1 -1
- package/docs/cn/box-size-change.md +144 -0
- package/package.json +3 -3
- package/src/App/AppBoxSizeSynchronizer.ts +124 -0
- package/src/App/AppContext.ts +2 -0
- package/src/App/AppProxy.ts +23 -0
- package/src/AppManager.ts +9 -0
- package/src/BoxManager.ts +15 -0
- package/src/typings.ts +2 -0
package/dist/index.mjs
CHANGED
|
@@ -1016,9 +1016,11 @@ class AppContext {
|
|
|
1016
1016
|
const view = this.getView();
|
|
1017
1017
|
if (view) {
|
|
1018
1018
|
view.divElement = dom;
|
|
1019
|
+
this.appProxy.scheduleBoxSizeSync();
|
|
1019
1020
|
setTimeout(() => {
|
|
1020
1021
|
var _a;
|
|
1021
1022
|
(_a = this.getRoom()) == null ? void 0 : _a.refreshViewSize();
|
|
1023
|
+
this.appProxy.scheduleBoxSizeSync();
|
|
1022
1024
|
callbacks.emit("onAppViewMounted", { appId: this.appId, view });
|
|
1023
1025
|
}, 1e3);
|
|
1024
1026
|
}
|
|
@@ -5337,6 +5339,10 @@ const createBoxManager = (manager, callbacks2, emitter, boxEmitter2, options) =>
|
|
|
5337
5339
|
var _a;
|
|
5338
5340
|
return (_a = manager.appManager) == null ? void 0 : _a.notifyContainerRectUpdate(rect);
|
|
5339
5341
|
},
|
|
5342
|
+
scheduleAppBoxSizeSync: (appId) => {
|
|
5343
|
+
var _a;
|
|
5344
|
+
return (_a = manager.appManager) == null ? void 0 : _a.scheduleAppBoxSizeSync(appId);
|
|
5345
|
+
},
|
|
5340
5346
|
cleanFocus: () => {
|
|
5341
5347
|
var _a;
|
|
5342
5348
|
return (_a = manager.appManager) == null ? void 0 : _a.store.cleanFocus();
|
|
@@ -5415,6 +5421,9 @@ class BoxManager {
|
|
|
5415
5421
|
});
|
|
5416
5422
|
}, 200)
|
|
5417
5423
|
);
|
|
5424
|
+
this.teleBoxManager.events.on("visual_resize", (box) => {
|
|
5425
|
+
this.context.scheduleAppBoxSizeSync(box.id);
|
|
5426
|
+
});
|
|
5418
5427
|
this.teleBoxManager.events.on("focused", (box) => {
|
|
5419
5428
|
if (box) {
|
|
5420
5429
|
if (this.canOperate) {
|
|
@@ -5437,6 +5446,7 @@ class BoxManager {
|
|
|
5437
5446
|
this.teleBoxManager.events.on(
|
|
5438
5447
|
"box_status",
|
|
5439
5448
|
(box) => {
|
|
5449
|
+
this.context.scheduleAppBoxSizeSync(box.id);
|
|
5440
5450
|
if (this.canOperate) {
|
|
5441
5451
|
this.context.setBoxStatus(box.id, box.boxStatus);
|
|
5442
5452
|
}
|
|
@@ -5523,6 +5533,7 @@ class BoxManager {
|
|
|
5523
5533
|
setBoxesStatus(status) {
|
|
5524
5534
|
const map = new Map(Object.entries(status != null ? status : {}));
|
|
5525
5535
|
this.teleBoxManager.setBoxesStatus(map, true);
|
|
5536
|
+
this.context.scheduleAppBoxSizeSync();
|
|
5526
5537
|
this.context.callbacks.emit("onBoxesStatusChange", map);
|
|
5527
5538
|
this.context.emitter.emit("boxesStatusChange", map);
|
|
5528
5539
|
}
|
|
@@ -5615,6 +5626,7 @@ class BoxManager {
|
|
|
5615
5626
|
if (state.minimized != null) {
|
|
5616
5627
|
this.teleBoxManager.setMinimized(Boolean(state.minimized), true);
|
|
5617
5628
|
}
|
|
5629
|
+
this.context.scheduleAppBoxSizeSync(box.id);
|
|
5618
5630
|
}, 50);
|
|
5619
5631
|
if (!state.boxStatus) {
|
|
5620
5632
|
this.context.callbacks.emit("boxStateChange", this.teleBoxManager.state);
|
|
@@ -5628,6 +5640,7 @@ class BoxManager {
|
|
|
5628
5640
|
const containerRect = { x: 0, y: 0, width: rect.width, height: rect.height };
|
|
5629
5641
|
this.teleBoxManager.setContainerRect(containerRect);
|
|
5630
5642
|
this.context.notifyContainerRectUpdate(this.teleBoxManager.containerRect);
|
|
5643
|
+
this.context.scheduleAppBoxSizeSync();
|
|
5631
5644
|
}
|
|
5632
5645
|
}
|
|
5633
5646
|
moveBox({ appId, x, y }) {
|
|
@@ -5638,6 +5651,7 @@ class BoxManager {
|
|
|
5638
5651
|
}
|
|
5639
5652
|
resizeBox({ appId, width, height, skipUpdate }) {
|
|
5640
5653
|
this.teleBoxManager.update(appId, { width, height }, skipUpdate);
|
|
5654
|
+
this.context.scheduleAppBoxSizeSync(appId);
|
|
5641
5655
|
}
|
|
5642
5656
|
setBoxMinSize(params) {
|
|
5643
5657
|
this.teleBoxManager.update(
|
|
@@ -5648,6 +5662,7 @@ class BoxManager {
|
|
|
5648
5662
|
},
|
|
5649
5663
|
true
|
|
5650
5664
|
);
|
|
5665
|
+
this.context.scheduleAppBoxSizeSync(params.appId);
|
|
5651
5666
|
}
|
|
5652
5667
|
setBoxTitle(params) {
|
|
5653
5668
|
this.teleBoxManager.update(params.appId, { title: params.title }, true);
|
|
@@ -5661,10 +5676,12 @@ class BoxManager {
|
|
|
5661
5676
|
setMaximized(maximized, skipUpdate = true) {
|
|
5662
5677
|
if (maximized !== this.maximized) {
|
|
5663
5678
|
this.teleBoxManager.setMaximized(maximized, skipUpdate);
|
|
5679
|
+
this.context.scheduleAppBoxSizeSync();
|
|
5664
5680
|
}
|
|
5665
5681
|
}
|
|
5666
5682
|
setMinimized(minimized, skipUpdate = true) {
|
|
5667
5683
|
this.teleBoxManager.setMinimized(minimized, skipUpdate);
|
|
5684
|
+
this.context.scheduleAppBoxSizeSync();
|
|
5668
5685
|
}
|
|
5669
5686
|
focusTopBox() {
|
|
5670
5687
|
const boxes = this.teleBoxManager.query();
|
|
@@ -5677,6 +5694,7 @@ class BoxManager {
|
|
|
5677
5694
|
}
|
|
5678
5695
|
updateBox(id, payload, skipUpdate = true) {
|
|
5679
5696
|
this.teleBoxManager.update(id, payload, skipUpdate);
|
|
5697
|
+
this.context.scheduleAppBoxSizeSync(id);
|
|
5680
5698
|
}
|
|
5681
5699
|
setReadonly(readonly) {
|
|
5682
5700
|
this.teleBoxManager.setReadonly(readonly);
|
|
@@ -7493,6 +7511,97 @@ const calculateNextIndex = (index2, pageState) => {
|
|
|
7493
7511
|
return nextIndex;
|
|
7494
7512
|
};
|
|
7495
7513
|
const boxEmitter = new Emittery();
|
|
7514
|
+
const BOX_SIZE_EPSILON = 0.5;
|
|
7515
|
+
const BOX_SIZE_SETTLE_DELAY = 650;
|
|
7516
|
+
const BOX_SIZE_CONFIRM_DELAY = 100;
|
|
7517
|
+
const sizesEqual = (left, right) => Boolean(
|
|
7518
|
+
left && Math.abs(left.width - right.width) <= BOX_SIZE_EPSILON && Math.abs(left.height - right.height) <= BOX_SIZE_EPSILON
|
|
7519
|
+
);
|
|
7520
|
+
class AppBoxSizeSynchronizer {
|
|
7521
|
+
constructor(appId, getView, getElement, notify, onError) {
|
|
7522
|
+
this.appId = appId;
|
|
7523
|
+
this.getView = getView;
|
|
7524
|
+
this.getElement = getElement;
|
|
7525
|
+
this.notify = notify;
|
|
7526
|
+
this.onError = onError;
|
|
7527
|
+
this.destroyed = false;
|
|
7528
|
+
this.schedule = () => {
|
|
7529
|
+
if (this.destroyed)
|
|
7530
|
+
return;
|
|
7531
|
+
if (this.timer != null)
|
|
7532
|
+
clearTimeout(this.timer);
|
|
7533
|
+
if (this.frame != null) {
|
|
7534
|
+
cancelAnimationFrame(this.frame);
|
|
7535
|
+
this.frame = void 0;
|
|
7536
|
+
}
|
|
7537
|
+
this.pendingSize = void 0;
|
|
7538
|
+
this.timer = setTimeout(() => {
|
|
7539
|
+
this.timer = void 0;
|
|
7540
|
+
this.frame = requestAnimationFrame(this.confirmDOMSize);
|
|
7541
|
+
}, BOX_SIZE_SETTLE_DELAY);
|
|
7542
|
+
};
|
|
7543
|
+
this.confirmDOMSize = () => {
|
|
7544
|
+
var _a, _b, _c, _d;
|
|
7545
|
+
this.frame = void 0;
|
|
7546
|
+
if (this.destroyed)
|
|
7547
|
+
return;
|
|
7548
|
+
const element2 = this.getElement();
|
|
7549
|
+
if (!element2)
|
|
7550
|
+
return;
|
|
7551
|
+
const rect = element2.getBoundingClientRect();
|
|
7552
|
+
const size2 = { width: rect.width, height: rect.height };
|
|
7553
|
+
if (!Number.isFinite(size2.width) || !Number.isFinite(size2.height) || size2.width <= 0 || size2.height <= 0) {
|
|
7554
|
+
this.pendingSize = void 0;
|
|
7555
|
+
return;
|
|
7556
|
+
}
|
|
7557
|
+
if (!sizesEqual(this.pendingSize, size2)) {
|
|
7558
|
+
this.pendingSize = size2;
|
|
7559
|
+
this.timer = setTimeout(() => {
|
|
7560
|
+
this.timer = void 0;
|
|
7561
|
+
this.frame = requestAnimationFrame(this.confirmDOMSize);
|
|
7562
|
+
}, BOX_SIZE_CONFIRM_DELAY);
|
|
7563
|
+
return;
|
|
7564
|
+
}
|
|
7565
|
+
this.pendingSize = void 0;
|
|
7566
|
+
const view = this.getView();
|
|
7567
|
+
if (view && !sizesEqual(view.size, size2)) {
|
|
7568
|
+
try {
|
|
7569
|
+
if (typeof view.refreshSize === "function") {
|
|
7570
|
+
view.refreshSize(size2.width, size2.height);
|
|
7571
|
+
} else if (typeof ((_a = view.screen) == null ? void 0 : _a.refreshSize) === "function") {
|
|
7572
|
+
const resizeObserver = view.screen.resizeObserver;
|
|
7573
|
+
(_b = resizeObserver == null ? void 0 : resizeObserver.disconnect) == null ? void 0 : _b.call(resizeObserver);
|
|
7574
|
+
try {
|
|
7575
|
+
view.screen.refreshSize(size2.width, size2.height);
|
|
7576
|
+
} finally {
|
|
7577
|
+
if (view.divElement)
|
|
7578
|
+
(_c = resizeObserver == null ? void 0 : resizeObserver.observe) == null ? void 0 : _c.call(resizeObserver, view.divElement);
|
|
7579
|
+
}
|
|
7580
|
+
}
|
|
7581
|
+
} catch (error) {
|
|
7582
|
+
(_d = this.onError) == null ? void 0 : _d.call(this, error);
|
|
7583
|
+
}
|
|
7584
|
+
}
|
|
7585
|
+
if (!sizesEqual(this.lastNotifiedSize, size2)) {
|
|
7586
|
+
this.lastNotifiedSize = size2;
|
|
7587
|
+
this.notify({ appId: this.appId, ...size2 });
|
|
7588
|
+
}
|
|
7589
|
+
};
|
|
7590
|
+
}
|
|
7591
|
+
destroy() {
|
|
7592
|
+
this.destroyed = true;
|
|
7593
|
+
if (this.timer != null) {
|
|
7594
|
+
clearTimeout(this.timer);
|
|
7595
|
+
this.timer = void 0;
|
|
7596
|
+
}
|
|
7597
|
+
if (this.frame != null) {
|
|
7598
|
+
cancelAnimationFrame(this.frame);
|
|
7599
|
+
this.frame = void 0;
|
|
7600
|
+
}
|
|
7601
|
+
this.pendingSize = void 0;
|
|
7602
|
+
this.lastNotifiedSize = void 0;
|
|
7603
|
+
}
|
|
7604
|
+
}
|
|
7496
7605
|
const _AppProxy = class {
|
|
7497
7606
|
constructor(params, manager, appId, isAddApp) {
|
|
7498
7607
|
var _a;
|
|
@@ -7503,6 +7612,10 @@ const _AppProxy = class {
|
|
|
7503
7612
|
this.viewManager = this.manager.viewManager;
|
|
7504
7613
|
this.store = this.manager.store;
|
|
7505
7614
|
this.status = "normal";
|
|
7615
|
+
this.scheduleBoxSizeSync = () => {
|
|
7616
|
+
if (this.status !== "destroyed")
|
|
7617
|
+
this.boxSizeSynchronizer.schedule();
|
|
7618
|
+
};
|
|
7506
7619
|
this.getAppInitState = (id) => {
|
|
7507
7620
|
var _a2, _b, _c, _d;
|
|
7508
7621
|
const attrs = this.store.getAppState(id);
|
|
@@ -7597,6 +7710,26 @@ const _AppProxy = class {
|
|
|
7597
7710
|
this.stateKey = `${this.id}_state`;
|
|
7598
7711
|
this.appProxies.set(this.id, this);
|
|
7599
7712
|
this.appEmitter = new Emittery();
|
|
7713
|
+
this.boxSizeSynchronizer = new AppBoxSizeSynchronizer(
|
|
7714
|
+
this.id,
|
|
7715
|
+
() => this.view,
|
|
7716
|
+
() => {
|
|
7717
|
+
var _a2, _b;
|
|
7718
|
+
return ((_a2 = this.view) == null ? void 0 : _a2.divElement) || ((_b = this.box) == null ? void 0 : _b.$content);
|
|
7719
|
+
},
|
|
7720
|
+
(payload) => {
|
|
7721
|
+
this.appEmitter.emit("boxSizeChange", payload).catch((error) => {
|
|
7722
|
+
var _a2;
|
|
7723
|
+
(_a2 = this.Logger) == null ? void 0 : _a2.error(
|
|
7724
|
+
`[WindowManager]: failed to notify app box size change: ${error}`
|
|
7725
|
+
);
|
|
7726
|
+
});
|
|
7727
|
+
},
|
|
7728
|
+
(error) => {
|
|
7729
|
+
var _a2;
|
|
7730
|
+
(_a2 = this.Logger) == null ? void 0 : _a2.error(`[WindowManager]: failed to refresh app view size: ${error}`);
|
|
7731
|
+
}
|
|
7732
|
+
);
|
|
7600
7733
|
this.appListener = this.makeAppEventListener(this.id);
|
|
7601
7734
|
this.isAddApp = isAddApp;
|
|
7602
7735
|
this.initScenes();
|
|
@@ -7727,6 +7860,7 @@ const _AppProxy = class {
|
|
|
7727
7860
|
);
|
|
7728
7861
|
const result = await app.setup(context);
|
|
7729
7862
|
this.appResult = result;
|
|
7863
|
+
this.scheduleBoxSizeSync();
|
|
7730
7864
|
appRegister.notifyApp(this.kind, "created", { appId, result });
|
|
7731
7865
|
this.afterSetupApp(boxInitState);
|
|
7732
7866
|
this.fixMobileSize();
|
|
@@ -7934,6 +8068,7 @@ const _AppProxy = class {
|
|
|
7934
8068
|
if (this.status === "destroyed")
|
|
7935
8069
|
return;
|
|
7936
8070
|
this.status = "destroyed";
|
|
8071
|
+
this.boxSizeSynchronizer.destroy();
|
|
7937
8072
|
try {
|
|
7938
8073
|
await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
|
|
7939
8074
|
await this.appEmitter.emit("destroy", { error });
|
|
@@ -8637,6 +8772,15 @@ class AppManager {
|
|
|
8637
8772
|
});
|
|
8638
8773
|
callbacks.emit("onBoxResize", payload);
|
|
8639
8774
|
}
|
|
8775
|
+
this.scheduleAppBoxSizeSync(payload.appId);
|
|
8776
|
+
};
|
|
8777
|
+
this.scheduleAppBoxSizeSync = (appId) => {
|
|
8778
|
+
var _a;
|
|
8779
|
+
if (appId) {
|
|
8780
|
+
(_a = this.appProxies.get(appId)) == null ? void 0 : _a.scheduleBoxSizeSync();
|
|
8781
|
+
} else {
|
|
8782
|
+
this.appProxies.forEach((appProxy) => appProxy.scheduleBoxSizeSync());
|
|
8783
|
+
}
|
|
8640
8784
|
};
|
|
8641
8785
|
this.onBoxFocus = (payload) => {
|
|
8642
8786
|
this.windowManger.safeSetAttributes({ focus: payload.appId });
|
|
@@ -10243,8 +10387,8 @@ const reconnectRefresher = new ReconnectRefresher({ emitter: internalEmitter });
|
|
|
10243
10387
|
const _WindowManager = class extends InvisiblePlugin {
|
|
10244
10388
|
constructor(context) {
|
|
10245
10389
|
super(context);
|
|
10246
|
-
this.version = "1.0.
|
|
10247
|
-
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.
|
|
10390
|
+
this.version = "1.0.19";
|
|
10391
|
+
this.dependencies = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.57" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@netless/app-presentation": "^0.1.10", "@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.30", "@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", "jspdf": "^2.5.1", "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", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.57" } };
|
|
10248
10392
|
this.emitter = callbacks;
|
|
10249
10393
|
this.viewMode = ViewMode.Broadcaster;
|
|
10250
10394
|
this.isReplay = isPlayer(this.displayer);
|
|
@@ -10274,7 +10418,7 @@ const _WindowManager = class extends InvisiblePlugin {
|
|
|
10274
10418
|
);
|
|
10275
10419
|
};
|
|
10276
10420
|
_WindowManager.displayer = context.displayer;
|
|
10277
|
-
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.
|
|
10421
|
+
window.NETLESS_DEPS = { "dependencies": { "@juggle/resize-observer": "^3.3.1", "@netless/telebox-insider": "0.3.0", "emittery": "^0.9.2", "lodash": "^4.17.21", "p-retry": "^4.6.1", "uuid": "^7.0.3", "video.js": ">=7" }, "peerDependencies": { "jspdf": "2.5.1", "white-web-sdk": "^2.16.57" }, "devDependencies": { "@hyrious/dts": "^0.2.2", "@netless/app-docs-viewer": "^0.2.19", "@netless/app-media-player": "0.1.4", "@netless/app-presentation": "^0.1.10", "@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.30", "@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", "jspdf": "^2.5.1", "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", "side-effect-manager": "0.1.5", "svelte": "^3.42.4", "typescript": "^4.5.5", "vite": "^2.9.9", "vitest": "^0.14.1", "white-web-sdk": "^2.16.57" } };
|
|
10278
10422
|
this.emitter.on("mainViewScenePathChange", this.onMainViewScenePathChangeHandler);
|
|
10279
10423
|
}
|
|
10280
10424
|
get Logger() {
|