@netless/window-manager 1.0.13-test.11 → 1.0.13-test.12
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 +4 -0
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +49 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/View/MainView.ts +50 -0
package/package.json
CHANGED
package/src/View/MainView.ts
CHANGED
|
@@ -19,6 +19,7 @@ export class MainViewProxy {
|
|
|
19
19
|
private scale?: number;
|
|
20
20
|
private started = false;
|
|
21
21
|
private mainViewIsAddListener = false;
|
|
22
|
+
private mainViewResizeObserver?: ResizeObserver;
|
|
22
23
|
private mainView: View;
|
|
23
24
|
private store = this.manager.store;
|
|
24
25
|
private viewMode = this.manager.windowManger.viewMode;
|
|
@@ -31,6 +32,7 @@ export class MainViewProxy {
|
|
|
31
32
|
this.mainView = this.createMainView();
|
|
32
33
|
this.moveCameraSizeByAttributes();
|
|
33
34
|
internalEmitter.once("mainViewMounted").then(() => {
|
|
35
|
+
this.observeMainViewDivElement();
|
|
34
36
|
this.addMainViewListener();
|
|
35
37
|
this.start();
|
|
36
38
|
this.ensureCameraAndSize();
|
|
@@ -218,9 +220,11 @@ export class MainViewProxy {
|
|
|
218
220
|
this.mainView.release();
|
|
219
221
|
}
|
|
220
222
|
this.removeMainViewListener();
|
|
223
|
+
this.disconnectMainViewResizeObserver();
|
|
221
224
|
this.mainView = this.createMainView();
|
|
222
225
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
|
223
226
|
this.mainView.divElement = divElement;
|
|
227
|
+
this.observeMainViewDivElement();
|
|
224
228
|
this.addMainViewListener();
|
|
225
229
|
this.start();
|
|
226
230
|
callbacks.emit("onMainViewRebind", this.mainView);
|
|
@@ -277,6 +281,51 @@ export class MainViewProxy {
|
|
|
277
281
|
this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
|
|
278
282
|
}
|
|
279
283
|
|
|
284
|
+
private observeMainViewDivElement() {
|
|
285
|
+
this.disconnectMainViewResizeObserver();
|
|
286
|
+
if (!("ResizeObserver" in window)) return;
|
|
287
|
+
if (!this.mainView.divElement) return;
|
|
288
|
+
this.mainViewResizeObserver = new window.ResizeObserver(this.onResize);
|
|
289
|
+
this.mainViewResizeObserver.observe(this.mainView.divElement);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
private disconnectMainViewResizeObserver() {
|
|
293
|
+
this.mainViewResizeObserver?.disconnect();
|
|
294
|
+
this.mainViewResizeObserver = undefined;
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
private onResize = (entries: ResizeObserverEntry[]) => {
|
|
298
|
+
const entry = entries[0];
|
|
299
|
+
if (!entry) return;
|
|
300
|
+
const target = entry.target as HTMLDivElement;
|
|
301
|
+
const child = target.children[0] as HTMLElement | undefined;
|
|
302
|
+
console.log("[window-manager] mainViewResizeObserver " + JSON.stringify({
|
|
303
|
+
contentRect: {
|
|
304
|
+
width: entry.contentRect.width,
|
|
305
|
+
height: entry.contentRect.height,
|
|
306
|
+
},
|
|
307
|
+
client: {
|
|
308
|
+
width: target.clientWidth,
|
|
309
|
+
height: target.clientHeight,
|
|
310
|
+
},
|
|
311
|
+
offset: {
|
|
312
|
+
width: target.offsetWidth,
|
|
313
|
+
height: target.offsetHeight,
|
|
314
|
+
},
|
|
315
|
+
rect: {
|
|
316
|
+
width: target.getBoundingClientRect().width,
|
|
317
|
+
height: target.getBoundingClientRect().height,
|
|
318
|
+
},
|
|
319
|
+
childRect: child
|
|
320
|
+
? {
|
|
321
|
+
width: child.getBoundingClientRect().width,
|
|
322
|
+
height: child.getBoundingClientRect().height,
|
|
323
|
+
}
|
|
324
|
+
: null,
|
|
325
|
+
viewSize: this.mainView.size,
|
|
326
|
+
}));
|
|
327
|
+
};
|
|
328
|
+
|
|
280
329
|
private _syncMainViewTimer = 0;
|
|
281
330
|
private onCameraOrSizeUpdated = () => {
|
|
282
331
|
console.log("[window-manager] onCameraOrSizeUpdated " + JSON.stringify(this.cameraState));
|
|
@@ -357,6 +406,7 @@ export class MainViewProxy {
|
|
|
357
406
|
|
|
358
407
|
public destroy() {
|
|
359
408
|
this.removeMainViewListener();
|
|
409
|
+
this.disconnectMainViewResizeObserver();
|
|
360
410
|
this.stop();
|
|
361
411
|
this.sideEffectManager.flushAll();
|
|
362
412
|
}
|