@netless/window-manager 1.0.12 → 1.0.13-bate.1
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 +69 -2
- package/dist/index.js +14 -14
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +549 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +3 -3
- package/src/App/AppProxy.ts +10 -2
- package/src/AppListener.ts +0 -19
- package/src/AppManager.ts +46 -6
- package/src/ContainerResizeObserver.ts +18 -9
- package/src/InternalEmitter.ts +1 -0
- package/src/Utils/Reactive.ts +2 -2
- package/src/Utils/RoomHacker.ts +22 -1
- package/src/Utils/attributesLogStringify.ts +78 -0
- package/src/Utils/log.ts +265 -0
- package/src/View/MainView.ts +151 -7
- package/src/index.ts +71 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/window-manager",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.13-bate.1",
|
|
4
4
|
"description": "Multi-window mode for Netless Whiteboard",
|
|
5
5
|
"author": "l1shen <lishen1635@gmail.com> (https://github.com/l1shen)",
|
|
6
6
|
"license": "MIT",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"jspdf": "2.5.1",
|
|
26
|
-
"white-web-sdk": "^2.16.
|
|
26
|
+
"white-web-sdk": "^2.16.54"
|
|
27
27
|
},
|
|
28
28
|
"peerDependenciesMeta": {
|
|
29
29
|
"jspdf": {
|
|
@@ -72,6 +72,6 @@
|
|
|
72
72
|
"typescript": "^4.5.5",
|
|
73
73
|
"vite": "^2.9.9",
|
|
74
74
|
"vitest": "^0.14.1",
|
|
75
|
-
"white-web-sdk": "^2.16.
|
|
75
|
+
"white-web-sdk": "^2.16.54"
|
|
76
76
|
}
|
|
77
77
|
}
|
package/src/App/AppProxy.ts
CHANGED
|
@@ -120,6 +120,10 @@ export class AppProxy implements PageRemoveService {
|
|
|
120
120
|
return this.store.getAppAttributes(this.id);
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
+
public get Logger() {
|
|
124
|
+
return this.manager.windowManger.Logger;
|
|
125
|
+
}
|
|
126
|
+
|
|
123
127
|
public getFullScenePath(): string | undefined {
|
|
124
128
|
if (this.scenePath) {
|
|
125
129
|
return get(this.appAttributes, [Fields.FullPath]) || this.getFullScenePathFromScenes();
|
|
@@ -145,6 +149,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
145
149
|
): Promise<{ appId: string; app: NetlessApp }> {
|
|
146
150
|
const params = this.params;
|
|
147
151
|
if (!params.kind) {
|
|
152
|
+
this.Logger && this.Logger.error(`[WindowManager]: kind require`);
|
|
148
153
|
throw new Error("[WindowManager]: kind require");
|
|
149
154
|
}
|
|
150
155
|
const appImpl = await appRegister.appClasses.get(params.kind)?.();
|
|
@@ -162,6 +167,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
162
167
|
params.isDragContent
|
|
163
168
|
);
|
|
164
169
|
} else {
|
|
170
|
+
this.Logger && this.Logger.error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
|
|
165
171
|
throw new Error(`[WindowManager]: app load failed ${params.kind} ${params.src}`);
|
|
166
172
|
}
|
|
167
173
|
internalEmitter.emit("updateManagerRect");
|
|
@@ -210,7 +216,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
210
216
|
}
|
|
211
217
|
setTimeout(async () => {
|
|
212
218
|
// 延迟执行 setup, 防止初始化的属性没有更新成功
|
|
213
|
-
|
|
219
|
+
this.Logger && this.Logger.info(`[WindowManager]: setup app ${this.kind}, appId: ${appId}`);
|
|
214
220
|
const result = await app.setup(context);
|
|
215
221
|
this.appResult = result;
|
|
216
222
|
appRegister.notifyApp(this.kind, "created", { appId, result });
|
|
@@ -245,7 +251,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
245
251
|
this.boxManager.focusBox({ appId }, false);
|
|
246
252
|
}
|
|
247
253
|
} catch (error: any) {
|
|
248
|
-
|
|
254
|
+
this.Logger && this.Logger.error(`[WindowManager]: app setup error: ${error.message}`);
|
|
249
255
|
throw new Error(`[WindowManager]: app setup error: ${error.message}`);
|
|
250
256
|
}
|
|
251
257
|
}
|
|
@@ -532,6 +538,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
532
538
|
await appRegister.notifyApp(this.kind, "destroy", { appId: this.id });
|
|
533
539
|
await this.appEmitter.emit("destroy", { error });
|
|
534
540
|
} catch (error) {
|
|
541
|
+
this.Logger && this.Logger.error(`[WindowManager]: notifyApp error: ${error.message}`);
|
|
535
542
|
console.error("[WindowManager]: notifyApp error", error.message, error.stack);
|
|
536
543
|
}
|
|
537
544
|
this.appEmitter.clearListeners();
|
|
@@ -554,6 +561,7 @@ export class AppProxy implements PageRemoveService {
|
|
|
554
561
|
this.manager.refresher.remove(this.stateKey);
|
|
555
562
|
this.manager.refresher.remove(`${this.id}-fullPath`);
|
|
556
563
|
this._prevFullPath = undefined;
|
|
564
|
+
this.Logger && this.Logger.info(`[WindowManager]: destroy app ${this.kind} appId: ${this.id}`);
|
|
557
565
|
}
|
|
558
566
|
|
|
559
567
|
public close(): Promise<void> {
|
package/src/AppListener.ts
CHANGED
|
@@ -50,14 +50,6 @@ export class AppListeners {
|
|
|
50
50
|
this.setMainViewScenePathHandler(data.payload);
|
|
51
51
|
break;
|
|
52
52
|
}
|
|
53
|
-
// case Events.MoveCamera: {
|
|
54
|
-
// this.moveCameraHandler(data.payload);
|
|
55
|
-
// break;
|
|
56
|
-
// }
|
|
57
|
-
// case Events.MoveCameraToContain: {
|
|
58
|
-
// this.moveCameraToContainHandler(data.payload);
|
|
59
|
-
// break;
|
|
60
|
-
// }
|
|
61
53
|
case Events.CursorMove: {
|
|
62
54
|
this.cursorMoveHandler(data.payload);
|
|
63
55
|
break;
|
|
@@ -102,17 +94,6 @@ export class AppListeners {
|
|
|
102
94
|
callbacks.emit("mainViewScenePathChange", nextScenePath);
|
|
103
95
|
};
|
|
104
96
|
|
|
105
|
-
// private moveCameraHandler = (
|
|
106
|
-
// payload: Camera & { animationMode?: AnimationMode | undefined }
|
|
107
|
-
// ) => {
|
|
108
|
-
// if (isEqual(omit(payload, ["animationMode"]), { ...this.manager.mainView.camera })) return;
|
|
109
|
-
// this.manager.mainView.moveCamera(payload);
|
|
110
|
-
// };
|
|
111
|
-
|
|
112
|
-
// private moveCameraToContainHandler = (payload: any) => {
|
|
113
|
-
// this.manager.mainView.moveCameraToContain(payload);
|
|
114
|
-
// };
|
|
115
|
-
|
|
116
97
|
private cursorMoveHandler = (payload: any) => {
|
|
117
98
|
internalEmitter.emit("cursorMove", payload);
|
|
118
99
|
};
|
package/src/AppManager.ts
CHANGED
|
@@ -94,11 +94,6 @@ export class AppManager {
|
|
|
94
94
|
|
|
95
95
|
constructor(public windowManger: WindowManager) {
|
|
96
96
|
this.displayer = windowManger.displayer;
|
|
97
|
-
// this.store.setContext({
|
|
98
|
-
// getAttributes: () => this.attributes,
|
|
99
|
-
// safeSetAttributes: attributes => this.safeSetAttributes(attributes),
|
|
100
|
-
// safeUpdateAttributes: (keys, val) => this.safeUpdateAttributes(keys, val),
|
|
101
|
-
// });
|
|
102
97
|
this.store = createAttributesDelegate(WindowManager.extendClass, {
|
|
103
98
|
getAttributes: () => this.attributes,
|
|
104
99
|
safeSetAttributes: attributes => this.safeSetAttributes(attributes),
|
|
@@ -150,6 +145,7 @@ export class AppManager {
|
|
|
150
145
|
const { scenePath } = params;
|
|
151
146
|
// 如果移除根目录就把 scenePath 设置为初始值
|
|
152
147
|
if (scenePath === ROOT_DIR) {
|
|
148
|
+
console.log("[window-manager] onRemoveScenes ROOT_DIR");
|
|
153
149
|
await this.onRootDirRemoved();
|
|
154
150
|
this.dispatchInternalEvent(Events.RootDirRemoved);
|
|
155
151
|
return;
|
|
@@ -162,6 +158,7 @@ export class AppManager {
|
|
|
162
158
|
sceneName = this.callbacksNode?.scenes[nextIndex];
|
|
163
159
|
}
|
|
164
160
|
if (sceneName) {
|
|
161
|
+
console.log(`[window-manager] onRemoveScenes setMainViewScenePath ${ROOT_DIR}${sceneName}`);
|
|
165
162
|
this.setMainViewScenePath(`${ROOT_DIR}${sceneName}`);
|
|
166
163
|
}
|
|
167
164
|
await this.setMainViewSceneIndex(nextIndex);
|
|
@@ -333,6 +330,10 @@ export class AppManager {
|
|
|
333
330
|
return this.room?.uid || "";
|
|
334
331
|
}
|
|
335
332
|
|
|
333
|
+
public get Logger() {
|
|
334
|
+
return this.windowManger.Logger;
|
|
335
|
+
}
|
|
336
|
+
|
|
336
337
|
public getMainViewSceneDir() {
|
|
337
338
|
const scenePath = this.store.getMainViewScenePath();
|
|
338
339
|
if (scenePath) {
|
|
@@ -603,6 +604,9 @@ export class AppManager {
|
|
|
603
604
|
try {
|
|
604
605
|
const appAttributes = this.attributes[id];
|
|
605
606
|
if (!appAttributes) {
|
|
607
|
+
this.Logger && this.Logger.error(
|
|
608
|
+
`[WindowManager]: appAttributes is undefined, appId: ${id}`
|
|
609
|
+
);
|
|
606
610
|
throw new Error("appAttributes is undefined");
|
|
607
611
|
}
|
|
608
612
|
|
|
@@ -706,6 +710,31 @@ export class AppManager {
|
|
|
706
710
|
}
|
|
707
711
|
internalEmitter.emit("mainViewMounted");
|
|
708
712
|
callbacks.emit("onMainViewMounted", mainView);
|
|
713
|
+
const hasRoot = this.hasRoot(mainView.divElement);
|
|
714
|
+
const rect = this.getRectByDivElement(mainView.divElement);
|
|
715
|
+
let log = `[window-manager] bindMainView hasRoot:${hasRoot}, rect:${JSON.stringify(rect)}, outerHeight:${window.outerHeight}, outerWidth:${window.outerWidth}`;
|
|
716
|
+
const visualViewport = window.visualViewport;
|
|
717
|
+
if (visualViewport) {
|
|
718
|
+
log += `, visualViewportWidth:${visualViewport.width}, visualViewportHeight:${visualViewport.height}, visualViewportOffsetLeft:${visualViewport.offsetLeft}, visualViewportOffsetTop:${visualViewport.offsetTop}`;
|
|
719
|
+
}
|
|
720
|
+
console.log(log);
|
|
721
|
+
}
|
|
722
|
+
|
|
723
|
+
private hasRoot(divElement: HTMLDivElement){
|
|
724
|
+
let current = divElement;
|
|
725
|
+
while (current) {
|
|
726
|
+
if (current.parentElement === document.body) {
|
|
727
|
+
return true;
|
|
728
|
+
}
|
|
729
|
+
current = current.parentElement as HTMLDivElement;
|
|
730
|
+
}
|
|
731
|
+
return false;
|
|
732
|
+
}
|
|
733
|
+
|
|
734
|
+
private getRectByDivElement(divElement: HTMLDivElement){
|
|
735
|
+
// 获取当前divElement的矩形区域
|
|
736
|
+
const rect = divElement.getBoundingClientRect();
|
|
737
|
+
return rect;
|
|
709
738
|
}
|
|
710
739
|
|
|
711
740
|
public setMainViewFocusPath(scenePath?: string) {
|
|
@@ -725,6 +754,9 @@ export class AppManager {
|
|
|
725
754
|
|
|
726
755
|
public async addApp(params: AddAppParams, isDynamicPPT: boolean): Promise<string | undefined> {
|
|
727
756
|
log("addApp", params);
|
|
757
|
+
this.windowManger.Logger?.info(
|
|
758
|
+
`[WindowManager]: addApp ${params.kind}, isDynamicPPT: ${isDynamicPPT}`
|
|
759
|
+
);
|
|
728
760
|
const { appId, needFocus } = await this.beforeAddApp(params, isDynamicPPT);
|
|
729
761
|
const appProxy = await this.baseInsertApp(params, appId, true, needFocus);
|
|
730
762
|
this.afterAddApp(appProxy);
|
|
@@ -773,7 +805,9 @@ export class AppManager {
|
|
|
773
805
|
focus?: boolean
|
|
774
806
|
) {
|
|
775
807
|
if (this.appProxies.has(appId)) {
|
|
776
|
-
|
|
808
|
+
this.windowManger.Logger?.warn(
|
|
809
|
+
`[WindowManager]: app duplicate exists and cannot be created again, appId: ${appId}`
|
|
810
|
+
);
|
|
777
811
|
return;
|
|
778
812
|
}
|
|
779
813
|
const AppProxyClass = getExtendClass(AppProxy, WindowManager.extendClass);
|
|
@@ -784,6 +818,7 @@ export class AppManager {
|
|
|
784
818
|
return appProxy;
|
|
785
819
|
} else {
|
|
786
820
|
this.appStatus.delete(appId);
|
|
821
|
+
this.Logger && this.Logger.error(`[WindowManager]: initialize AppProxy failed, appId: ${appId}`);
|
|
787
822
|
throw new Error("[WindowManger]: initialize AppProxy failed");
|
|
788
823
|
}
|
|
789
824
|
}
|
|
@@ -823,12 +858,15 @@ export class AppManager {
|
|
|
823
858
|
const scenePathType = this.displayer.scenePathType(scenePath);
|
|
824
859
|
const sceneDir = parseSceneDir(scenePath);
|
|
825
860
|
if (sceneDir !== ROOT_DIR) {
|
|
861
|
+
this.Logger && this.Logger.error(`[WindowManager]: main view scenePath must in root dir "/"`);
|
|
826
862
|
throw new Error(`[WindowManager]: main view scenePath must in root dir "/"`);
|
|
827
863
|
}
|
|
828
864
|
if (scenePathType === ScenePathType.None) {
|
|
865
|
+
this.Logger && this.Logger.error(`[WindowManager]: ${scenePath} not valid scene`);
|
|
829
866
|
throw new Error(`[WindowManager]: ${scenePath} not valid scene`);
|
|
830
867
|
} else if (scenePathType === ScenePathType.Page) {
|
|
831
868
|
await this._setMainViewScenePath(scenePath);
|
|
869
|
+
|
|
832
870
|
} else if (scenePathType === ScenePathType.Dir) {
|
|
833
871
|
const validScenePath = makeValidScenePath(this.displayer, scenePath);
|
|
834
872
|
if (validScenePath) {
|
|
@@ -875,6 +913,7 @@ export class AppManager {
|
|
|
875
913
|
this.dispatchSetMainViewScenePath(scenePath);
|
|
876
914
|
}
|
|
877
915
|
} else {
|
|
916
|
+
this.Logger && this.Logger.error(`[WindowManager]: ${index} not valid index`);
|
|
878
917
|
throw new Error(`[WindowManager]: ${index} not valid index`);
|
|
879
918
|
}
|
|
880
919
|
}
|
|
@@ -961,3 +1000,4 @@ export class AppManager {
|
|
|
961
1000
|
this._resolveTimer = undefined;
|
|
962
1001
|
}
|
|
963
1002
|
}
|
|
1003
|
+
|
|
@@ -1,14 +1,16 @@
|
|
|
1
1
|
import { ResizeObserver as ResizeObserverPolyfill } from "@juggle/resize-observer";
|
|
2
|
-
import { isFunction } from "lodash";
|
|
3
2
|
import { WindowManager } from "./index";
|
|
4
3
|
import type { EmitterType } from "./InternalEmitter";
|
|
5
4
|
import type { UnsubscribeFn } from "emittery";
|
|
5
|
+
import { LocalConsole } from "./Utils/log";
|
|
6
6
|
|
|
7
7
|
const ResizeObserver = window.ResizeObserver || ResizeObserverPolyfill;
|
|
8
8
|
|
|
9
9
|
export class ContainerResizeObserver {
|
|
10
10
|
private containerResizeObserver?: ResizeObserver;
|
|
11
11
|
private disposer?: UnsubscribeFn;
|
|
12
|
+
|
|
13
|
+
private updateSizerLocalConsole = new LocalConsole("updateSizer", 100);
|
|
12
14
|
|
|
13
15
|
constructor(private emitter: EmitterType) {}
|
|
14
16
|
|
|
@@ -28,19 +30,19 @@ export class ContainerResizeObserver {
|
|
|
28
30
|
sizer: HTMLElement,
|
|
29
31
|
wrapper: HTMLDivElement
|
|
30
32
|
) {
|
|
31
|
-
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper);
|
|
33
|
+
this.updateSizer(container.getBoundingClientRect(), sizer, wrapper, 'observePlaygroundSize');
|
|
32
34
|
|
|
33
35
|
this.containerResizeObserver = new ResizeObserver(entries => {
|
|
34
36
|
const containerRect = entries[0]?.contentRect;
|
|
35
37
|
if (containerRect) {
|
|
36
|
-
this.updateSizer(containerRect, sizer, wrapper);
|
|
38
|
+
this.updateSizer(containerRect, sizer, wrapper, 'containerResizeObserver');
|
|
37
39
|
this.emitter.emit("playgroundSizeChange", containerRect);
|
|
38
40
|
}
|
|
39
41
|
});
|
|
40
42
|
|
|
41
43
|
this.disposer = this.emitter.on("containerSizeRatioUpdate", () => {
|
|
42
44
|
const containerRect = container.getBoundingClientRect();
|
|
43
|
-
this.updateSizer(containerRect, sizer, wrapper);
|
|
45
|
+
this.updateSizer(containerRect, sizer, wrapper, 'containerSizeRatioUpdate');
|
|
44
46
|
this.emitter.emit("playgroundSizeChange", containerRect);
|
|
45
47
|
});
|
|
46
48
|
|
|
@@ -50,7 +52,8 @@ export class ContainerResizeObserver {
|
|
|
50
52
|
public updateSizer(
|
|
51
53
|
{ width, height }: DOMRectReadOnly,
|
|
52
54
|
sizer: HTMLElement,
|
|
53
|
-
wrapper: HTMLDivElement
|
|
55
|
+
wrapper: HTMLDivElement,
|
|
56
|
+
origin?: string
|
|
54
57
|
) {
|
|
55
58
|
if (width && height) {
|
|
56
59
|
if (height / width > WindowManager.containerSizeRatio) {
|
|
@@ -62,14 +65,20 @@ export class ContainerResizeObserver {
|
|
|
62
65
|
}
|
|
63
66
|
wrapper.style.width = `${width}px`;
|
|
64
67
|
wrapper.style.height = `${height}px`;
|
|
68
|
+
const wrapperRect = wrapper.getBoundingClientRect();
|
|
69
|
+
this.updateSizerLocalConsole.log(`from ${origin}, traget size: ${JSON.stringify({ width, height })}, wrapperRect: ${wrapperRect.width} ${wrapperRect.height}`);
|
|
70
|
+
this.emitter.emit("wrapperRectChange", {
|
|
71
|
+
width: wrapperRect.width,
|
|
72
|
+
height: wrapperRect.height,
|
|
73
|
+
origin,
|
|
74
|
+
});
|
|
65
75
|
}
|
|
66
76
|
}
|
|
67
77
|
|
|
68
78
|
public disconnect() {
|
|
79
|
+
this.updateSizerLocalConsole.destroy();
|
|
69
80
|
this.containerResizeObserver?.disconnect();
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
this.disposer = undefined;
|
|
73
|
-
}
|
|
81
|
+
this.disposer?.();
|
|
82
|
+
this.disposer = undefined;
|
|
74
83
|
}
|
|
75
84
|
}
|
package/src/InternalEmitter.ts
CHANGED
|
@@ -29,6 +29,7 @@ export type EmitterEvent = {
|
|
|
29
29
|
changePageState: undefined;
|
|
30
30
|
writableChange: boolean;
|
|
31
31
|
containerSizeRatioUpdate: number;
|
|
32
|
+
wrapperRectChange: { width: number; height: number; origin?: string };
|
|
32
33
|
boxesStatusChange: Map<string, TeleBoxState>;
|
|
33
34
|
lastNotMinimizedBoxesStatusChange: Map<string, NotMinimizedBoxState>;
|
|
34
35
|
};
|
package/src/Utils/Reactive.ts
CHANGED
|
@@ -30,8 +30,8 @@ export const onObjectByEvent = (event: UpdateEventKind) => {
|
|
|
30
30
|
};
|
|
31
31
|
};
|
|
32
32
|
|
|
33
|
-
export const safeListenPropsUpdated = <T
|
|
34
|
-
getProps: () => T,
|
|
33
|
+
export const safeListenPropsUpdated = <T extends Record<string, unknown>>(
|
|
34
|
+
getProps: () => T | null | undefined,
|
|
35
35
|
callback: AkkoObjectUpdatedListener<T>,
|
|
36
36
|
onDestroyed?: (props: unknown) => void
|
|
37
37
|
) => {
|
package/src/Utils/RoomHacker.ts
CHANGED
|
@@ -33,7 +33,28 @@ export const replaceRoomFunction = (room: Room | Player, manager: WindowManager)
|
|
|
33
33
|
return manager.canRedoSteps;
|
|
34
34
|
},
|
|
35
35
|
});
|
|
36
|
-
|
|
36
|
+
const _scalePptToFit = room.scalePptToFit;
|
|
37
|
+
room.scalePptToFit = (...args) => {
|
|
38
|
+
_scalePptToFit.call(room, ...args);
|
|
39
|
+
if (manager.appManager?.mainViewProxy) {
|
|
40
|
+
manager.appManager.mainViewProxy.setCameraAndSize();
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
const _putScenes = room.putScenes;
|
|
44
|
+
room.putScenes = (...args) => {
|
|
45
|
+
const [path, scenes] = args;
|
|
46
|
+
const currentScenePath = manager.mainView.focusScenePath;
|
|
47
|
+
if (currentScenePath && path && scenes) {
|
|
48
|
+
console.log("[window-manager] putScenes " + JSON.stringify(args));
|
|
49
|
+
for (const scene of scenes) {
|
|
50
|
+
if (`${path}${scene.name}` === currentScenePath) {
|
|
51
|
+
console.error(`[window-manager] putScenes: scene name can not be the same as the current scene path: ${currentScenePath}`);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
return _putScenes.call(room, ...args);
|
|
57
|
+
};
|
|
37
58
|
room.moveCamera = (camera: Camera) => manager.moveCamera(camera);
|
|
38
59
|
room.moveCameraToContain = (...args) => manager.moveCameraToContain(...args);
|
|
39
60
|
room.convertToPointInWorld = (...args) => manager.mainView.convertToPointInWorld(...args);
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/** 合法标识符形式的 key 省略引号,形如 `{aaa:undefined}` */
|
|
2
|
+
function formatAttributesLogObjectKey(key: string): string {
|
|
3
|
+
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(key) ? key : JSON.stringify(key);
|
|
4
|
+
}
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* attributes 调试日志:对象/数组会写成近似 JS 字面量(保留 `undefined`、数组空洞),避免 `[object Object]`;
|
|
8
|
+
* 并处理 BigInt、循环引用等。
|
|
9
|
+
*/
|
|
10
|
+
export function stringifyForAttributesLog(value: unknown, seen?: WeakSet<object>): string {
|
|
11
|
+
if (value === undefined) {
|
|
12
|
+
return "undefined";
|
|
13
|
+
}
|
|
14
|
+
if (value === null) {
|
|
15
|
+
return "null";
|
|
16
|
+
}
|
|
17
|
+
const t = typeof value;
|
|
18
|
+
if (t === "bigint") {
|
|
19
|
+
return `${value}n`;
|
|
20
|
+
}
|
|
21
|
+
if (t === "symbol") {
|
|
22
|
+
return String(value);
|
|
23
|
+
}
|
|
24
|
+
if (t === "function") {
|
|
25
|
+
const fn = value as (...args: unknown[]) => unknown;
|
|
26
|
+
return `[Function ${fn.name || "anonymous"}]`;
|
|
27
|
+
}
|
|
28
|
+
if (t !== "object") {
|
|
29
|
+
return t === "string" ? JSON.stringify(value as string) : String(value);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const obj = value as object;
|
|
33
|
+
if (seen?.has(obj)) {
|
|
34
|
+
return "[Circular]";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
const nextSeen = seen ?? new WeakSet<object>();
|
|
38
|
+
nextSeen.add(obj);
|
|
39
|
+
try {
|
|
40
|
+
if (Array.isArray(value)) {
|
|
41
|
+
return `[${Array.from(value as unknown[], (item) =>
|
|
42
|
+
stringifyForAttributesLog(item, nextSeen),
|
|
43
|
+
).join(",")}]`;
|
|
44
|
+
}
|
|
45
|
+
if (value instanceof Date) {
|
|
46
|
+
return JSON.stringify(value.toISOString());
|
|
47
|
+
}
|
|
48
|
+
if (value instanceof RegExp) {
|
|
49
|
+
return String(value);
|
|
50
|
+
}
|
|
51
|
+
const keys = Object.keys(value as object);
|
|
52
|
+
const pairs = keys.map((k) => {
|
|
53
|
+
let v: unknown;
|
|
54
|
+
try {
|
|
55
|
+
v = (value as Record<string, unknown>)[k];
|
|
56
|
+
} catch {
|
|
57
|
+
return `${formatAttributesLogObjectKey(k)}:[Threw]`;
|
|
58
|
+
}
|
|
59
|
+
return `${formatAttributesLogObjectKey(k)}:${stringifyForAttributesLog(v, nextSeen)}`;
|
|
60
|
+
});
|
|
61
|
+
return `{${pairs.join(",")}}`;
|
|
62
|
+
} catch {
|
|
63
|
+
return "[Unserializable]";
|
|
64
|
+
} finally {
|
|
65
|
+
nextSeen.delete(obj);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
/** 仅一层 key 合并:可作为 attributes 片段的「普通对象」(非数组、Date 等) */
|
|
70
|
+
export function isShallowMergeAttributesRecord(value: unknown): value is Record<string, unknown> {
|
|
71
|
+
return (
|
|
72
|
+
value !== null &&
|
|
73
|
+
typeof value === "object" &&
|
|
74
|
+
!Array.isArray(value) &&
|
|
75
|
+
!(value instanceof Date) &&
|
|
76
|
+
!(value instanceof RegExp)
|
|
77
|
+
);
|
|
78
|
+
}
|