@netless/window-manager 1.0.13-test.10 → 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 +5 -0
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +76 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/View/MainView.ts +77 -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,12 +32,14 @@ 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();
|
|
37
39
|
this.startListenWritableChange();
|
|
38
40
|
});
|
|
39
41
|
const playgroundSizeChangeListener = () => {
|
|
42
|
+
this.refreshScreenSizeIfStale();
|
|
40
43
|
this.playgroundSizeChangeListenerLocalConsole.log(
|
|
41
44
|
JSON.stringify(this.mainView.camera),
|
|
42
45
|
JSON.stringify(this.mainView.size),
|
|
@@ -109,6 +112,24 @@ export class MainViewProxy {
|
|
|
109
112
|
this.moveCamera(this.mainViewCamera);
|
|
110
113
|
}
|
|
111
114
|
|
|
115
|
+
private refreshScreenSizeIfStale() {
|
|
116
|
+
const element = this.mainView.divElement;
|
|
117
|
+
if (!element) return;
|
|
118
|
+
|
|
119
|
+
const { width, height } = element.getBoundingClientRect();
|
|
120
|
+
if (width <= 0 || height <= 0) return;
|
|
121
|
+
|
|
122
|
+
const { width: viewWidth, height: viewHeight } = this.mainView.size;
|
|
123
|
+
if (Math.abs(viewWidth - width) > 0.5 || Math.abs(viewHeight - height) > 0.5) {
|
|
124
|
+
const resizableView = this.mainView as View & { resizeScreen?: () => void };
|
|
125
|
+
console.log("[window-manager] forceResizeScreen stale size" + JSON.stringify({
|
|
126
|
+
viewSize: this.mainView.size,
|
|
127
|
+
domSize: { width, height },
|
|
128
|
+
}));
|
|
129
|
+
resizableView.resizeScreen?.();
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
112
133
|
public start() {
|
|
113
134
|
console.log("[window-manager] start " + JSON.stringify(this.mainViewSize));
|
|
114
135
|
this.sizeChangeHandler(this.mainViewSize);
|
|
@@ -199,9 +220,11 @@ export class MainViewProxy {
|
|
|
199
220
|
this.mainView.release();
|
|
200
221
|
}
|
|
201
222
|
this.removeMainViewListener();
|
|
223
|
+
this.disconnectMainViewResizeObserver();
|
|
202
224
|
this.mainView = this.createMainView();
|
|
203
225
|
this.mainView.disableCameraTransform = disableCameraTransform;
|
|
204
226
|
this.mainView.divElement = divElement;
|
|
227
|
+
this.observeMainViewDivElement();
|
|
205
228
|
this.addMainViewListener();
|
|
206
229
|
this.start();
|
|
207
230
|
callbacks.emit("onMainViewRebind", this.mainView);
|
|
@@ -258,9 +281,62 @@ export class MainViewProxy {
|
|
|
258
281
|
this.view.callbacks.off("onSizeUpdated", this.onCameraOrSizeUpdated);
|
|
259
282
|
}
|
|
260
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
|
+
|
|
261
329
|
private _syncMainViewTimer = 0;
|
|
262
330
|
private onCameraOrSizeUpdated = () => {
|
|
263
331
|
console.log("[window-manager] onCameraOrSizeUpdated " + JSON.stringify(this.cameraState));
|
|
332
|
+
if(this.mainView.divElement){
|
|
333
|
+
const children = this.mainView.divElement.children;
|
|
334
|
+
console.log("[window-manager] onCameraOrSizeUpdated " + this.mainView.divElement.getBoundingClientRect());
|
|
335
|
+
const child = children[0];
|
|
336
|
+
if (child) {
|
|
337
|
+
console.log("[window-manager] child" + JSON.stringify(child.getBoundingClientRect()));
|
|
338
|
+
}
|
|
339
|
+
}
|
|
264
340
|
callbacks.emit("cameraStateChange", this.cameraState);
|
|
265
341
|
// sdk >= 2.16.43 的 syncMainView() 可以写入当前 main view 的 camera, 以修复复制粘贴元素的位置
|
|
266
342
|
// 注意到这个操作会发送信令,应当避免频繁调用
|
|
@@ -330,6 +406,7 @@ export class MainViewProxy {
|
|
|
330
406
|
|
|
331
407
|
public destroy() {
|
|
332
408
|
this.removeMainViewListener();
|
|
409
|
+
this.disconnectMainViewResizeObserver();
|
|
333
410
|
this.stop();
|
|
334
411
|
this.sideEffectManager.flushAll();
|
|
335
412
|
}
|