@netless/window-manager 1.0.13-test.16 → 1.0.13-test.18

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.
@@ -19,7 +19,6 @@ export class MainViewProxy {
19
19
  private scale?: number;
20
20
  private started = false;
21
21
  private mainViewIsAddListener = false;
22
- private mainViewResizeObserver?: ResizeObserver;
23
22
  private isForcingMainViewDivElement = false;
24
23
  private wrapperRectWorkaroundFrame = 0;
25
24
  private pendingWrapperRectChange?: { width: number; height: number; origin?: string };
@@ -30,19 +29,19 @@ export class MainViewProxy {
30
29
  private sideEffectManager = new SideEffectManager();
31
30
 
32
31
  private playgroundSizeChangeListenerLocalConsole = new LocalConsole("playgroundSizeChangeListener", 30);
32
+ private sizeUpdatedLocalConsole = new LocalConsole("sizeUpdated", 30);
33
+ private cameraUpdatedLocalConsole = new LocalConsole("cameraUpdated", 30);
33
34
 
34
35
  constructor(private manager: AppManager) {
35
36
  this.mainView = this.createMainView();
36
37
  this.moveCameraSizeByAttributes();
37
38
  internalEmitter.once("mainViewMounted").then(() => {
38
- this.observeMainViewDivElement();
39
39
  this.addMainViewListener();
40
40
  this.start();
41
41
  this.ensureCameraAndSize();
42
42
  this.startListenWritableChange();
43
43
  });
44
44
  const playgroundSizeChangeListener = () => {
45
- // this.refreshScreenSizeIfStale();
46
45
  this.playgroundSizeChangeListenerLocalConsole.log(
47
46
  JSON.stringify(this.mainView.camera),
48
47
  JSON.stringify(this.mainView.size),
@@ -118,21 +117,8 @@ export class MainViewProxy {
118
117
  this.moveCamera(this.mainViewCamera);
119
118
  }
120
119
 
121
- private refreshScreenSizeIfStale() {
122
- const element = this.mainView.divElement;
123
- if (!element) return;
124
-
125
- const { width, height } = element.getBoundingClientRect();
126
- if (width <= 0 || height <= 0) return;
127
- this.forceSyncMainViewDivElement("playgroundSizeChange", { width, height }, element);
128
- }
129
-
130
120
  private onWrapperRectChange = (payload: { width: number; height: number; origin?: string }) => {
131
121
  this.pendingWrapperRectChange = payload;
132
- console.log("[window-manager] onWrapperRectChange " + JSON.stringify({
133
- ...payload,
134
- viewSize: this.mainView.size,
135
- }));
136
122
  if (this.wrapperRectWorkaroundFrame) {
137
123
  cancelAnimationFrame(this.wrapperRectWorkaroundFrame);
138
124
  }
@@ -155,15 +141,6 @@ export class MainViewProxy {
155
141
  Math.abs(this.mainView.size.width - observedSize.width) > 0.5 ||
156
142
  Math.abs(this.mainView.size.height - observedSize.height) > 0.5;
157
143
 
158
- console.log("[window-manager] runWrapperRectWorkaround " + JSON.stringify({
159
- origin: payload.origin,
160
- wrapperRect: payload,
161
- domRect: observedSize,
162
- viewSize: this.mainView.size,
163
- wrapperMatchesDom,
164
- viewIsStale,
165
- }));
166
-
167
144
  if (wrapperMatchesDom && viewIsStale) {
168
145
  this.forceSyncMainViewDivElement(
169
146
  `wrapperRectChange:${payload.origin || "unknown"}`,
@@ -215,14 +192,17 @@ export class MainViewProxy {
215
192
  }
216
193
 
217
194
  public start() {
218
- console.log("[window-manager] start " + JSON.stringify(this.mainViewSize));
195
+ console.log("[window-manager] start attributes size:" + JSON.stringify(this.mainViewSize));
219
196
  this.sizeChangeHandler(this.mainViewSize);
220
197
  if (this.started) return;
221
198
  this.addCameraListener();
222
199
  this.addCameraReaction();
223
200
  if (this.manager.room) this.syncMainView(this.manager.room);
224
201
  this.started = true;
225
- console.log("[window-manager] start end " + JSON.stringify(this.mainViewSize), JSON.stringify(this.mainView.size));
202
+ if(this.mainView.focusScenePath) {
203
+ this.manager.windowManger.onMainViewScenePathChangeHandler(this.mainView.focusScenePath);
204
+ }
205
+ console.log("[window-manager] start end mainView size:" + JSON.stringify(this.mainView.size));
226
206
  }
227
207
 
228
208
  public addCameraReaction = () => {
@@ -253,7 +233,7 @@ export class MainViewProxy {
253
233
  if (size) {
254
234
  this.moveCameraToContian(size);
255
235
  this.moveCamera(this.mainViewCamera);
256
- console.log("[window-manager] sizeChangeHandler current size and camera" + JSON.stringify(size) + JSON.stringify(this.mainViewCamera) +
236
+ console.log("[window-manager] sizeChangeHandler current size and camera" + JSON.stringify(size) + JSON.stringify(this.mainViewCamera) +
257
237
  JSON.stringify(this.mainView.camera) + JSON.stringify(this.mainView.size));
258
238
  }
259
239
  this.ensureMainViewSize();
@@ -305,11 +285,9 @@ export class MainViewProxy {
305
285
  this.mainView.release();
306
286
  }
307
287
  this.removeMainViewListener();
308
- this.disconnectMainViewResizeObserver();
309
288
  this.mainView = this.createMainView();
310
289
  this.mainView.disableCameraTransform = disableCameraTransform;
311
290
  this.mainView.divElement = divElement;
312
- this.observeMainViewDivElement();
313
291
  this.addMainViewListener();
314
292
  this.start();
315
293
  callbacks.emit("onMainViewRebind", this.mainView);
@@ -366,76 +344,8 @@ export class MainViewProxy {
366
344
  this.view.callbacks.off("onSizeUpdated", this.onSizeUpdated);
367
345
  }
368
346
 
369
- private observeMainViewDivElement() {
370
- this.disconnectMainViewResizeObserver();
371
- if (!("ResizeObserver" in window)) return;
372
- if (!this.mainView.divElement) return;
373
- console.log("[window-manager] observeMainViewDivElement " + JSON.stringify({
374
- rect: this.mainView.divElement.getBoundingClientRect(),
375
- viewSize: this.mainView.size,
376
- }));
377
- this.mainViewResizeObserver = new window.ResizeObserver(this.onResize);
378
- this.mainViewResizeObserver.observe(this.mainView.divElement);
379
- }
380
-
381
- private disconnectMainViewResizeObserver() {
382
- this.mainViewResizeObserver?.disconnect();
383
- this.mainViewResizeObserver = undefined;
384
- }
385
-
386
- private onResize = (entries: ResizeObserverEntry[]) => {
387
- const entry = entries[0];
388
- if (!entry) return;
389
- const target = entry.target as HTMLDivElement;
390
- const child = target.children[0] as HTMLElement | undefined;
391
- const observedSize = {
392
- width: entry.contentRect.width,
393
- height: entry.contentRect.height,
394
- };
395
- console.log("[window-manager] mainViewResizeObserver " + JSON.stringify({
396
- sameTarget: target === this.mainView.divElement,
397
- contentRect: {
398
- width: observedSize.width,
399
- height: observedSize.height,
400
- },
401
- client: {
402
- width: target.clientWidth,
403
- height: target.clientHeight,
404
- },
405
- offset: {
406
- width: target.offsetWidth,
407
- height: target.offsetHeight,
408
- },
409
- rect: {
410
- width: target.getBoundingClientRect().width,
411
- height: target.getBoundingClientRect().height,
412
- },
413
- childRect: child
414
- ? {
415
- width: child.getBoundingClientRect().width,
416
- height: child.getBoundingClientRect().height,
417
- }
418
- : null,
419
- viewSize: this.mainView.size,
420
- }));
421
- // this.forceSyncMainViewDivElement("mainViewResizeObserver", observedSize, target);
422
- };
423
-
424
347
  private _syncMainViewTimer = 0;
425
- private handleCameraOrSizeUpdated = (
426
- source: "onCameraUpdated" | "onSizeUpdated",
427
- payload: Camera | Size
428
- ) => {
429
- console.log("[window-manager] " + source + " payload " + JSON.stringify(payload));
430
- console.log("[window-manager] " + source + " state " + JSON.stringify(this.cameraState));
431
- if(this.mainView.divElement){
432
- const children = this.mainView.divElement.children;
433
- console.log("[window-manager] " + source + " rect " + JSON.stringify(this.mainView.divElement.getBoundingClientRect()));
434
- const child = children[0];
435
- if (child) {
436
- console.log("[window-manager] " + source + " child" + JSON.stringify(child.getBoundingClientRect()));
437
- }
438
- }
348
+ private handleCameraOrSizeUpdated = () => {
439
349
  callbacks.emit("cameraStateChange", this.cameraState);
440
350
  // sdk >= 2.16.43 的 syncMainView() 可以写入当前 main view 的 camera, 以修复复制粘贴元素的位置
441
351
  // 注意到这个操作会发送信令,应当避免频繁调用
@@ -447,11 +357,13 @@ export class MainViewProxy {
447
357
  };
448
358
 
449
359
  private onCameraUpdated = (camera: Camera) => {
450
- this.handleCameraOrSizeUpdated("onCameraUpdated", camera);
360
+ this.cameraUpdatedLocalConsole.log(JSON.stringify(camera));
361
+ this.handleCameraOrSizeUpdated();
451
362
  };
452
363
 
453
364
  private onSizeUpdated = (size: Size) => {
454
- this.handleCameraOrSizeUpdated("onSizeUpdated", size);
365
+ this.sizeUpdatedLocalConsole.log(JSON.stringify(size));
366
+ this.handleCameraOrSizeUpdated();
455
367
  };
456
368
 
457
369
  private ensureMainViewSize() {
@@ -518,7 +430,6 @@ export class MainViewProxy {
518
430
  this.wrapperRectWorkaroundFrame = 0;
519
431
  }
520
432
  this.removeMainViewListener();
521
- this.disconnectMainViewResizeObserver();
522
433
  this.stop();
523
434
  this.sideEffectManager.flushAll();
524
435
  }
package/src/index.ts CHANGED
@@ -403,16 +403,17 @@ export class WindowManager
403
403
  if (mainViewElement) {
404
404
  const backgroundImage = mainViewElement.querySelector('.background img');
405
405
  if (backgroundImage) {
406
- // todo 获取到 back ground image 的 rect情况以及css情况是否可见
407
406
  const backgroundImageRect = backgroundImage?.getBoundingClientRect();
408
407
  const backgroundImageCSS = window.getComputedStyle(backgroundImage);
409
408
  const backgroundImageVisible = backgroundImageRect?.width > 0 && backgroundImageRect?.height > 0 && backgroundImageCSS.display !== 'none';
410
- console.log("[window-manager] backgroundImageVisible" + backgroundImageVisible);
409
+ const camera = this.mainView.camera;
410
+ console.log("[window-manager] backgroundImageVisible:" + backgroundImageVisible + " camera:" + JSON.stringify(camera));
411
411
  return;
412
412
  }
413
- console.log("[window-manager] onMainViewScenePathChange" + scenePath + 'backgroundImageVisible is not found');
413
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' backgroundImageVisible is not found');
414
+ return;
414
415
  }
415
- console.log("[window-manager] onMainViewScenePathChange" + scenePath + 'mainViewElement is not found');
416
+ console.log("[window-manager] onMainViewScenePathChange scenePath:" + scenePath + ' mainViewElement is not found');
416
417
  }
417
418
 
418
419
  private static initManager(room: Room): Promise<WindowManager | undefined> {
@@ -1047,7 +1048,6 @@ export class WindowManager
1047
1048
  animationMode?: AnimationMode;
1048
1049
  }>
1049
1050
  ): void {
1050
- console.log("[window-manager] moveCameraToContain" + JSON.stringify(rectangle));
1051
1051
  this.mainView.moveCameraToContain(rectangle);
1052
1052
  setTimeout(() => {
1053
1053
  this.appManager?.mainViewProxy.setCameraAndSize();
package/src/style.css CHANGED
@@ -51,8 +51,6 @@
51
51
  .netless-window-manager-main-view {
52
52
  width: 100%;
53
53
  height: 100%;
54
- box-sizing: border-box;
55
- border: 0.1px solid transparent
56
54
  }
57
55
 
58
56
  .netless-window-manager-cursor-pencil-image {