@netless/window-manager 1.0.0-canary.9 → 1.0.0

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.
Files changed (132) hide show
  1. package/LICENSE.txt +21 -0
  2. package/README.md +90 -64
  3. package/README.zh-cn.md +224 -0
  4. package/dist/index.d.ts +1133 -40
  5. package/dist/index.js +62 -0
  6. package/dist/index.js.map +1 -0
  7. package/dist/{index.es.js → index.mjs} +9480 -6984
  8. package/dist/index.mjs.map +1 -0
  9. package/dist/style.css +1 -1
  10. package/docs/advanced.md +55 -55
  11. package/docs/api.md +124 -113
  12. package/docs/app-context.md +248 -209
  13. package/docs/basic.md +25 -26
  14. package/docs/camera.md +19 -20
  15. package/docs/cn/advanced.md +137 -0
  16. package/docs/cn/api.md +309 -0
  17. package/docs/cn/app-context.md +369 -0
  18. package/docs/cn/basic.md +64 -0
  19. package/docs/cn/camera.md +53 -0
  20. package/docs/cn/concept.md +9 -0
  21. package/docs/cn/custom-max-bar.md +31 -0
  22. package/docs/cn/develop-app.md +94 -0
  23. package/docs/cn/export-pdf.md +48 -0
  24. package/docs/cn/migrate.md +60 -0
  25. package/docs/cn/replay.md +40 -0
  26. package/docs/concept.md +6 -5
  27. package/docs/custom-max-bar.md +31 -0
  28. package/docs/develop-app.md +22 -19
  29. package/docs/export-pdf.md +48 -0
  30. package/docs/migrate.md +25 -27
  31. package/docs/quickstart.md +50 -0
  32. package/docs/replay.md +20 -20
  33. package/package.json +32 -22
  34. package/src/App/AppContext.ts +105 -73
  35. package/src/App/AppPageStateImpl.ts +6 -25
  36. package/src/App/AppProxy.ts +41 -166
  37. package/src/App/MagixEvent/index.ts +38 -38
  38. package/src/App/Storage/StorageEvent.ts +13 -13
  39. package/src/App/Storage/index.ts +269 -245
  40. package/src/App/Storage/typings.ts +4 -2
  41. package/src/App/Storage/utils.ts +3 -3
  42. package/src/App/index.ts +0 -1
  43. package/src/AppListener.ts +8 -8
  44. package/src/AppManager.ts +88 -77
  45. package/src/AttributesDelegate.ts +42 -22
  46. package/src/BoxEmitter.ts +12 -6
  47. package/src/BoxManager.ts +128 -108
  48. package/src/ContainerResizeObserver.ts +75 -0
  49. package/src/Cursor/Cursor.svelte +16 -5
  50. package/src/Cursor/Cursor.svelte.d.ts +21 -0
  51. package/src/Cursor/Cursor.ts +77 -13
  52. package/src/Cursor/icons.ts +6 -0
  53. package/src/Cursor/icons2.ts +66 -0
  54. package/src/Cursor/index.ts +127 -26
  55. package/src/Helper.ts +94 -14
  56. package/src/InternalEmitter.ts +2 -7
  57. package/src/Page/index.ts +1 -1
  58. package/src/PageState.ts +6 -5
  59. package/src/ReconnectRefresher.ts +9 -4
  60. package/src/RedoUndo.ts +3 -3
  61. package/src/Register/index.ts +22 -17
  62. package/src/Register/loader.ts +26 -22
  63. package/src/Register/storage.ts +13 -13
  64. package/src/Utils/Common.ts +18 -14
  65. package/src/Utils/Reactive.ts +26 -25
  66. package/src/Utils/RoomHacker.ts +4 -4
  67. package/src/Utils/error.ts +0 -1
  68. package/src/View/IframeBridge.ts +680 -0
  69. package/src/View/MainView.ts +127 -53
  70. package/src/callback.ts +21 -1
  71. package/src/constants.ts +0 -2
  72. package/src/image/pencil-eraser-1.svg +3 -0
  73. package/src/image/pencil-eraser-2.svg +3 -0
  74. package/src/image/pencil-eraser-3.svg +3 -0
  75. package/src/index.ts +220 -83
  76. package/src/style.css +27 -10
  77. package/src/typings.ts +20 -10
  78. package/.prettierignore +0 -7
  79. package/.prettierrc.json +0 -9
  80. package/CHANGELOG.md +0 -196
  81. package/__mocks__/white-web-sdk.ts +0 -50
  82. package/dist/App/AppContext.d.ts +0 -76
  83. package/dist/App/AppPageStateImpl.d.ts +0 -21
  84. package/dist/App/AppProxy.d.ts +0 -86
  85. package/dist/App/AppViewSync.d.ts +0 -11
  86. package/dist/App/MagixEvent/index.d.ts +0 -29
  87. package/dist/App/Storage/StorageEvent.d.ts +0 -8
  88. package/dist/App/Storage/index.d.ts +0 -39
  89. package/dist/App/Storage/typings.d.ts +0 -22
  90. package/dist/App/Storage/utils.d.ts +0 -5
  91. package/dist/App/WhiteboardView.d.ts +0 -22
  92. package/dist/App/index.d.ts +0 -3
  93. package/dist/AppListener.d.ts +0 -21
  94. package/dist/AppManager.d.ts +0 -107
  95. package/dist/AttributesDelegate.d.ts +0 -80
  96. package/dist/BoxEmitter.d.ts +0 -34
  97. package/dist/BoxManager.d.ts +0 -99
  98. package/dist/BuiltinApps.d.ts +0 -5
  99. package/dist/Cursor/Cursor.d.ts +0 -39
  100. package/dist/Cursor/icons.d.ts +0 -3
  101. package/dist/Cursor/index.d.ts +0 -46
  102. package/dist/Helper.d.ts +0 -17
  103. package/dist/InternalEmitter.d.ts +0 -39
  104. package/dist/Page/PageController.d.ts +0 -21
  105. package/dist/Page/index.d.ts +0 -3
  106. package/dist/PageState.d.ts +0 -9
  107. package/dist/ReconnectRefresher.d.ts +0 -24
  108. package/dist/RedoUndo.d.ts +0 -18
  109. package/dist/Register/index.d.ts +0 -28
  110. package/dist/Register/loader.d.ts +0 -4
  111. package/dist/Register/storage.d.ts +0 -8
  112. package/dist/Utils/AppCreateQueue.d.ts +0 -15
  113. package/dist/Utils/Common.d.ts +0 -23
  114. package/dist/Utils/Reactive.d.ts +0 -6
  115. package/dist/Utils/RoomHacker.d.ts +0 -3
  116. package/dist/Utils/error.d.ts +0 -27
  117. package/dist/Utils/log.d.ts +0 -1
  118. package/dist/View/CameraSynchronizer.d.ts +0 -16
  119. package/dist/View/MainView.d.ts +0 -47
  120. package/dist/View/ViewManager.d.ts +0 -13
  121. package/dist/callback.d.ts +0 -24
  122. package/dist/constants.d.ts +0 -49
  123. package/dist/index.cjs.js +0 -46
  124. package/dist/index.umd.js +0 -46
  125. package/dist/typings.d.ts +0 -82
  126. package/jest.config.js +0 -27
  127. package/pnpm-lock.yaml +0 -6302
  128. package/src/App/AppViewSync.ts +0 -68
  129. package/src/App/WhiteboardView.ts +0 -83
  130. package/src/View/CameraSynchronizer.ts +0 -56
  131. package/vite.config.js +0 -51
  132. /package/docs/{qickstart.md → cn/quickstart.md} +0 -0
@@ -1,68 +0,0 @@
1
- import { CameraSynchronizer } from "../View/CameraSynchronizer";
2
- import { SideEffectManager } from "side-effect-manager";
3
- import type { Camera, View } from "white-web-sdk";
4
- import type { AppProxy } from "./AppProxy";
5
- import { isEqual } from "lodash";
6
- import { combine } from "value-enhancer";
7
-
8
- export class AppViewSync {
9
- private sem = new SideEffectManager();
10
- private synchronizer: CameraSynchronizer;
11
-
12
- constructor(private appProxy: AppProxy) {
13
- this.synchronizer = new CameraSynchronizer((camera: Camera) => {
14
- this.appProxy.storeCamera({
15
- id: this.appProxy.uid,
16
- ...camera,
17
- });
18
- });
19
- this.bindView(appProxy.view);
20
- this.sem.add(() => this.appProxy.camera$.subscribe(camera => {
21
- const size = this.appProxy.size$.value;
22
- if (camera && size) {
23
- this.synchronizer.onRemoteUpdate(camera, size);
24
- }
25
- }));
26
- const box = this.appProxy.box;
27
- if (box && box.contentStageRect) {
28
- this.synchronizer.setRect(box.contentStageRect);
29
- this.sem.add(() =>
30
- box._contentStageRect$.subscribe(rect => {
31
- if (rect) {
32
- this.synchronizer.setRect(rect);
33
- }
34
- }),
35
- );
36
- }
37
- this.sem.add(() => combine([this.appProxy.camera$, this.appProxy.size$]).subscribe(([camera, size]) => {
38
- if (camera && size) {
39
- this.synchronizer.onRemoteUpdate(camera, size);
40
- }
41
- }));
42
- }
43
-
44
- public bindView = (view?: View) => {
45
- if (!view) return;
46
- this.synchronizer.setView(view);
47
- this.sem.add(() => {
48
- view.callbacks.on("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
49
- return () =>
50
- view.callbacks.off("onCameraUpdatedByDevice", this.onCameraUpdatedByDevice);
51
- });
52
- };
53
-
54
- private onCameraUpdatedByDevice = (camera: Camera) => {
55
- this.synchronizer.onLocalCameraUpdate(camera);
56
- const stage = this.appProxy.box?.contentStageRect;
57
- if (stage) {
58
- const size = { width: stage.width, height: stage.height, id: this.appProxy.uid };
59
- if (!isEqual(size, this.appProxy.size$.value)) {
60
- this.appProxy.storeSize(size);
61
- }
62
- }
63
- };
64
-
65
- public destroy() {
66
- this.sem.flushAll();
67
- }
68
- }
@@ -1,83 +0,0 @@
1
- import { putScenes } from "../Utils/Common";
2
- import { Val } from "value-enhancer";
3
-
4
- import type { ReadonlyVal } from "value-enhancer";
5
- import type { AddPageParams, PageController, PageState } from "../Page";
6
- import type { AppProxy } from "./AppProxy";
7
- import type { AppContext } from "./AppContext";
8
- import type { Camera, View } from "white-web-sdk";
9
-
10
- export class WhiteBoardView implements PageController {
11
- public readonly pageState$: ReadonlyVal<PageState>;
12
-
13
- constructor(
14
- public view: View,
15
- protected appContext: AppContext,
16
- protected appProxy: AppProxy,
17
- private removeViewWrapper: () => void,
18
- public ensureSize: (size: number) => void
19
- ) {
20
- const pageState$ = new Val<PageState>(appProxy.pageState);
21
- this.pageState$ = pageState$;
22
- appProxy.appEmitter.on("pageStateChange", pageState => {
23
- pageState$.setValue(pageState);
24
- });
25
- }
26
-
27
- public get pageState() {
28
- return this.pageState$.value;
29
- }
30
-
31
- public moveCamera(camera: Camera) {
32
- this.appProxy.moveCamera(camera);
33
- }
34
-
35
- public nextPage = async (): Promise<boolean> => {
36
- const nextIndex = this.pageState.index + 1;
37
- return this.jumpPage(nextIndex);
38
- };
39
-
40
- public prevPage = async (): Promise<boolean> => {
41
- const nextIndex = this.pageState.index - 1;
42
- return this.jumpPage(nextIndex);
43
- };
44
-
45
- public jumpPage = async (index: number): Promise<boolean> => {
46
- if (index < 0 || index >= this.pageState.length) {
47
- console.warn(`[WindowManager]: index ${index} out of range`);
48
- return false;
49
- }
50
- this.appProxy.setSceneIndex(index);
51
- return true;
52
- };
53
-
54
- public addPage = async (params?: AddPageParams) => {
55
- const after = params?.after;
56
- const scene = params?.scene;
57
- const scenePath = this.appProxy.scenePath;
58
- if (!scenePath) return;
59
- if (after) {
60
- const nextIndex = this.pageState.index + 1;
61
- putScenes(this.appContext.room, scenePath, [scene || {}], nextIndex);
62
- } else {
63
- putScenes(this.appContext.room, scenePath, [scene || {}]);
64
- }
65
- };
66
-
67
- public removePage = async (index?: number): Promise<boolean> => {
68
- const needRemoveIndex = index === undefined ? this.pageState.index : index;
69
- if (this.pageState.length === 1) {
70
- console.warn(`[WindowManager]: can not remove the last page`);
71
- return false;
72
- }
73
- if (needRemoveIndex < 0 || needRemoveIndex >= this.pageState.length) {
74
- console.warn(`[WindowManager]: page index ${index} out of range`);
75
- return false;
76
- }
77
- return this.appProxy.removeSceneByIndex(needRemoveIndex);
78
- };
79
-
80
- public destroy() {
81
- this.removeViewWrapper();
82
- }
83
- }
@@ -1,56 +0,0 @@
1
- import { AnimationMode } from "white-web-sdk";
2
- import { delay, throttle } from "lodash";
3
- import type { TeleBoxRect } from "@netless/telebox-insider";
4
- import type { Camera, View } from "white-web-sdk";
5
- import type { ISize } from "../AttributesDelegate";
6
-
7
- export type SaveCamera = (camera: Camera) => void;
8
-
9
- export class CameraSynchronizer {
10
- public remoteCamera?: Camera;
11
- public remoteSize?: ISize;
12
- protected rect?: TeleBoxRect;
13
- protected view?: View;
14
-
15
- constructor(protected saveCamera: SaveCamera) {}
16
-
17
- public setRect(rect: TeleBoxRect) {
18
- this.rect = rect;
19
- if (this.remoteCamera && this.remoteSize) {
20
- this.onRemoteUpdate(this.remoteCamera, this.remoteSize);
21
- }
22
- }
23
-
24
- public setView(view: View) {
25
- this.view = view;
26
- }
27
-
28
- // 远端 Camera 或者 size 更新
29
- public onRemoteUpdate = throttle((camera: Camera, size: ISize) => {
30
- this.remoteCamera = camera;
31
- this.remoteSize = size;
32
- if (this.remoteSize && this.rect) {
33
- let scale: number;
34
- if (size.width < size.height) {
35
- scale = this.rect.width / size.width;
36
- } else {
37
- scale = this.rect.height / size.height;
38
- }
39
- const nextScale = camera.scale * scale;
40
- const moveCamera = () => this.view?.moveCamera({
41
- centerX: camera.centerX,
42
- centerY: camera.centerY,
43
- scale: nextScale,
44
- animationMode: AnimationMode.Immediately,
45
- });
46
- // TODO 直接调用 moveCamera 依然会出现 camera 错误的情况,这里暂时加一个 delay 保证 camera 是对的, 后续需要 SDK 进行修改
47
- delay(moveCamera, 50);
48
- }
49
- }, 50);
50
-
51
-
52
- public onLocalCameraUpdate(camera: Camera) {
53
- this.saveCamera(camera);
54
- this.remoteCamera = camera;
55
- }
56
- }
package/vite.config.js DELETED
@@ -1,51 +0,0 @@
1
- import path from "path";
2
- import { defineConfig } from 'vitest/config'
3
- import { svelte } from "@sveltejs/vite-plugin-svelte";
4
- import { dependencies, peerDependencies, version, devDependencies } from "./package.json"
5
- import { omit } from "lodash";
6
-
7
- export default defineConfig(({ mode }) => {
8
- const isProd = mode === "production";
9
-
10
- return {
11
- test: {
12
- environment: "jsdom",
13
- deps: {
14
- inline: [
15
- "@juggle/resize-observer"
16
- ]
17
- }
18
- },
19
- define: {
20
- __APP_VERSION__: JSON.stringify(version),
21
- __APP_DEPENDENCIES__: JSON.stringify({
22
- dependencies, peerDependencies, devDependencies
23
- }),
24
- },
25
- plugins: [
26
- svelte({
27
- emitCss: false,
28
- experimental: {
29
- useVitePreprocess: true,
30
- },
31
- })
32
- ],
33
- build: {
34
- lib: {
35
- // eslint-disable-next-line no-undef
36
- entry: path.resolve(__dirname, "src/index.ts"),
37
- formats: ["es", "umd", "cjs"],
38
- name: "WindowManager",
39
- fileName: "index"
40
- },
41
- outDir: "dist",
42
- rollupOptions: {
43
- external: Object.keys({
44
- ...omit(dependencies, ["@netless/telebox-insider"]),
45
- ...peerDependencies,
46
- }),
47
- },
48
- minify: isProd,
49
- },
50
- };
51
- });
File without changes