@netless/fastboard 0.0.10 → 0.2.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 (103) hide show
  1. package/LICENSE.txt +1 -1
  2. package/dist/index.js +32 -0
  3. package/dist/index.js.map +1 -0
  4. package/dist/index.mjs +7 -0
  5. package/dist/index.mjs.map +1 -0
  6. package/package.json +26 -79
  7. package/src/index.ts +2 -34
  8. package/README.md +0 -126
  9. package/dist/index.cjs.js +0 -14
  10. package/dist/index.cjs.js.map +0 -1
  11. package/dist/index.es.js +0 -2642
  12. package/dist/index.es.js.map +0 -1
  13. package/dist/svelte.cjs.js +0 -2
  14. package/dist/svelte.cjs.js.map +0 -1
  15. package/dist/svelte.es.js +0 -31
  16. package/dist/svelte.es.js.map +0 -1
  17. package/dist/vue.cjs.js +0 -2
  18. package/dist/vue.cjs.js.map +0 -1
  19. package/dist/vue.es.js +0 -42
  20. package/dist/vue.es.js.map +0 -1
  21. package/src/WhiteboardApp.ts +0 -146
  22. package/src/behaviors/register-apps.ts +0 -39
  23. package/src/behaviors/style.ts +0 -17
  24. package/src/components/PageControl.scss +0 -80
  25. package/src/components/PageControl.tsx +0 -181
  26. package/src/components/PlayerControl/PlayerControl.scss +0 -145
  27. package/src/components/PlayerControl/PlayerControl.tsx +0 -158
  28. package/src/components/PlayerControl/components/Button.tsx +0 -55
  29. package/src/components/PlayerControl/hooks.ts +0 -88
  30. package/src/components/PlayerControl/icons/Loading.tsx +0 -13
  31. package/src/components/PlayerControl/icons/Pause.tsx +0 -13
  32. package/src/components/PlayerControl/icons/Play.tsx +0 -13
  33. package/src/components/PlayerControl/icons/index.ts +0 -10
  34. package/src/components/PlayerControl/index.ts +0 -1
  35. package/src/components/RedoUndo.scss +0 -56
  36. package/src/components/RedoUndo.tsx +0 -95
  37. package/src/components/Root.scss +0 -55
  38. package/src/components/Root.tsx +0 -61
  39. package/src/components/Toolbar/Content.tsx +0 -93
  40. package/src/components/Toolbar/Toolbar.scss +0 -247
  41. package/src/components/Toolbar/Toolbar.tsx +0 -82
  42. package/src/components/Toolbar/components/ApplianceButtons.tsx +0 -132
  43. package/src/components/Toolbar/components/AppsButton.tsx +0 -106
  44. package/src/components/Toolbar/components/Button.tsx +0 -54
  45. package/src/components/Toolbar/components/ColorBox.tsx +0 -56
  46. package/src/components/Toolbar/components/CutLine.tsx +0 -8
  47. package/src/components/Toolbar/components/PencilButton.tsx +0 -70
  48. package/src/components/Toolbar/components/ShapesButton.tsx +0 -143
  49. package/src/components/Toolbar/components/Slider.tsx +0 -27
  50. package/src/components/Toolbar/components/TextButton.tsx +0 -66
  51. package/src/components/Toolbar/components/UpDownButtons.tsx +0 -49
  52. package/src/components/Toolbar/components/assets/cocos.png +0 -0
  53. package/src/components/Toolbar/components/assets/countdown.png +0 -0
  54. package/src/components/Toolbar/components/assets/geogebra.png +0 -0
  55. package/src/components/Toolbar/components/assets/vscode.png +0 -0
  56. package/src/components/Toolbar/const.ts +0 -32
  57. package/src/components/Toolbar/hooks.ts +0 -113
  58. package/src/components/Toolbar/icons/Apps.tsx +0 -16
  59. package/src/components/Toolbar/icons/Arrow.tsx +0 -16
  60. package/src/components/Toolbar/icons/Circle.tsx +0 -21
  61. package/src/components/Toolbar/icons/Clean.tsx +0 -16
  62. package/src/components/Toolbar/icons/Clicker.tsx +0 -19
  63. package/src/components/Toolbar/icons/Collapse.tsx +0 -17
  64. package/src/components/Toolbar/icons/Diamond.tsx +0 -17
  65. package/src/components/Toolbar/icons/Down.tsx +0 -17
  66. package/src/components/Toolbar/icons/Eraser.tsx +0 -16
  67. package/src/components/Toolbar/icons/Expand.tsx +0 -17
  68. package/src/components/Toolbar/icons/Line.tsx +0 -13
  69. package/src/components/Toolbar/icons/Pencil.tsx +0 -16
  70. package/src/components/Toolbar/icons/Rectangle.tsx +0 -13
  71. package/src/components/Toolbar/icons/Selector.tsx +0 -16
  72. package/src/components/Toolbar/icons/SpeechBalloon.tsx +0 -17
  73. package/src/components/Toolbar/icons/Star.tsx +0 -17
  74. package/src/components/Toolbar/icons/Text.tsx +0 -16
  75. package/src/components/Toolbar/icons/Triangle.tsx +0 -17
  76. package/src/components/Toolbar/icons/Up.tsx +0 -17
  77. package/src/components/Toolbar/icons/index.ts +0 -42
  78. package/src/components/Toolbar/index.ts +0 -1
  79. package/src/components/ZoomControl.scss +0 -80
  80. package/src/components/ZoomControl.tsx +0 -221
  81. package/src/i18n/en.json +0 -31
  82. package/src/i18n/index.ts +0 -22
  83. package/src/i18n/zh-CN.json +0 -32
  84. package/src/icons/ChevronLeft.tsx +0 -21
  85. package/src/icons/ChevronRight.tsx +0 -21
  86. package/src/icons/FilePlus.tsx +0 -18
  87. package/src/icons/Minus.tsx +0 -21
  88. package/src/icons/Plus.tsx +0 -21
  89. package/src/icons/Redo.tsx +0 -24
  90. package/src/icons/Reset.tsx +0 -23
  91. package/src/icons/Undo.tsx +0 -24
  92. package/src/icons/index.tsx +0 -11
  93. package/src/internal/Instance.tsx +0 -275
  94. package/src/internal/helpers.ts +0 -86
  95. package/src/internal/hooks.ts +0 -9
  96. package/src/internal/index.ts +0 -3
  97. package/src/internal/mount-whiteboard.ts +0 -90
  98. package/src/react.tsx +0 -52
  99. package/src/style.scss +0 -35
  100. package/src/svelte.ts +0 -45
  101. package/src/theme/index.ts +0 -36
  102. package/src/types/index.ts +0 -22
  103. package/src/vue.ts +0 -74
package/src/react.tsx DELETED
@@ -1,52 +0,0 @@
1
- import type { WhiteboardApp } from "./index";
2
-
3
- import React, { forwardRef, useEffect, useRef } from "react";
4
- import { useLastValue } from "./internal/hooks";
5
-
6
- // https://itnext.io/reusing-the-ref-from-forwardref-with-react-hooks-4ce9df693dd
7
- function useCombinedRefs<T>(...refs: React.Ref<T>[]) {
8
- const targetRef = useRef<T | null>(null);
9
-
10
- useEffect(() => {
11
- for (const ref of refs) {
12
- if (!ref) continue;
13
-
14
- if (typeof ref === "function") {
15
- ref(targetRef.current);
16
- } else {
17
- (ref as typeof targetRef).current = targetRef.current;
18
- }
19
- }
20
- }, [refs]);
21
-
22
- return targetRef;
23
- }
24
-
25
- /**
26
- * @example
27
- * let app = await createWhiteboardApp(config)
28
- * <Fastboard app={app} />
29
- * await app.dispose()
30
- */
31
- export const Fastboard = forwardRef<
32
- HTMLDivElement,
33
- { app?: WhiteboardApp | null } & React.DetailedHTMLProps<
34
- React.HTMLAttributes<HTMLDivElement>,
35
- HTMLDivElement
36
- >
37
- >(({ app, ...restProps }, outerRef) => {
38
- const innerRef = useRef<HTMLDivElement>(null);
39
- const ref = useCombinedRefs(outerRef, innerRef);
40
- const previous = useLastValue(app);
41
-
42
- useEffect(() => {
43
- if (previous && previous !== app) {
44
- previous.bindElement(null);
45
- }
46
- if (app) {
47
- app.bindElement(ref.current);
48
- }
49
- }, [app, previous, ref]);
50
-
51
- return <div className="fastboard" {...restProps} ref={ref} />;
52
- });
package/src/style.scss DELETED
@@ -1,35 +0,0 @@
1
- @import "@netless/window-manager/dist/style.css";
2
- @import "tippy.js/dist/tippy.css";
3
- @import "tippy.js/themes/light.css";
4
- @import "rc-slider/assets/index.css";
5
- @import "./components/Root.scss";
6
- @import "./components/RedoUndo.scss";
7
- @import "./components/PageControl.scss";
8
- @import "./components/ZoomControl.scss";
9
- @import "./components/Toolbar/Toolbar.scss";
10
- @import "./components/PlayerControl/PlayerControl.scss";
11
-
12
- .fastboard {
13
- width: 100%;
14
- height: 100%;
15
- position: relative;
16
- }
17
-
18
- .tippy-box.fastboard-tip {
19
- color: #eee;
20
- background-color: rgba($color: #000000, $alpha: 0.95);
21
- backdrop-filter: blur(2px);
22
- -webkit-backdrop-filter: blur(2px);
23
- }
24
-
25
- .tippy-box.fastboard-tip[data-placement^="right"] > .tippy-arrow::before {
26
- top: 4px;
27
- border-width: 4px;
28
- border-right-color: #000;
29
- }
30
-
31
- .tippy-box.fastboard-tip[data-placement^="top"] > .tippy-arrow::before {
32
- left: 4px;
33
- border-width: 4px;
34
- border-top-color: #000;
35
- }
package/src/svelte.ts DELETED
@@ -1,45 +0,0 @@
1
- import { readable, type Readable } from "svelte/store";
2
- import { createWhiteboardApp } from "./index";
3
-
4
- import type { WhiteboardApp, WhiteboardAppConfig } from "./WhiteboardApp";
5
-
6
- export type FastBoardConfig = WhiteboardAppConfig;
7
-
8
- /**
9
- * @example
10
- * ```svelte
11
- * <script>
12
- * let ref = writable(null)
13
- * let app = useFastboard(ref, { sdkConfig, joinRoom })
14
- * if (app) {
15
- * app.insertDocs({...})
16
- * }
17
- * </script>
18
- * <div style="width: 100%; height: 100%" bind:this={$ref} />
19
- * ```
20
- */
21
- export function useFastboard(
22
- ref: Readable<HTMLElement | null>,
23
- config: FastBoardConfig
24
- ): Readable<WhiteboardApp | null> {
25
- return readable<WhiteboardApp | null>(null, set => {
26
- let app_: WhiteboardApp | null = null;
27
-
28
- createWhiteboardApp(config).then(app => {
29
- set((app_ = app));
30
- });
31
-
32
- const dispose = ref.subscribe(div => {
33
- if (div && app_) {
34
- app_.bindElement(div);
35
- }
36
- });
37
-
38
- return () => {
39
- dispose();
40
- if (app_) {
41
- app_.dispose();
42
- }
43
- };
44
- });
45
- }
@@ -1,36 +0,0 @@
1
- import type { IconProps } from "../types";
2
-
3
- export interface ThemeConfig {
4
- color: string;
5
- activeColor: string;
6
- backgroundColor: string;
7
- hoverBackgroundColor: string;
8
- }
9
-
10
- export const light: ThemeConfig = {
11
- color: "#5D5D5D",
12
- activeColor: "#3381FF",
13
- backgroundColor: "#fff",
14
- hoverBackgroundColor: "rgba(51, 129, 255, 0.1)",
15
- };
16
-
17
- export const dark: ThemeConfig = {
18
- ...light,
19
- color: "#eee",
20
- backgroundColor: "#111",
21
- };
22
-
23
- export const themes = { light, dark };
24
-
25
- export const getStroke = (props: IconProps) => {
26
- let config;
27
- if (props.theme) {
28
- config = themes[props.theme];
29
- } else {
30
- config = themes.light;
31
- }
32
- return props.active ? config.activeColor : config.color;
33
- };
34
-
35
- export const TopOffset = [0, 11] as [number, number];
36
- export const RightOffset = [0, 11] as [number, number];
@@ -1,22 +0,0 @@
1
- import type { Room } from "white-web-sdk";
2
- import type { WindowManager } from "@netless/window-manager";
3
- import type { i18n } from "i18next";
4
-
5
- export type Theme = "light" | "dark";
6
-
7
- export interface IconProps {
8
- theme?: Theme;
9
- active?: boolean;
10
- }
11
-
12
- export interface CommonProps {
13
- room?: Room | null;
14
- manager?: WindowManager | null;
15
- theme?: Theme;
16
- i18n?: i18n | null;
17
- }
18
-
19
- export type GenericIcon<
20
- K extends string,
21
- E extends string = "disable"
22
- > = Partial<Record<`${K}Icon${Capitalize<E | "">}`, string>>;
package/src/vue.ts DELETED
@@ -1,74 +0,0 @@
1
- import type { ComponentPublicInstance, Ref } from "vue-demi";
2
- import {
3
- computed,
4
- getCurrentScope,
5
- onScopeDispose,
6
- shallowRef,
7
- unref,
8
- watchEffect,
9
- } from "vue-demi";
10
- import { createWhiteboardApp } from "./index";
11
-
12
- import type { WhiteboardApp, WhiteboardAppConfig } from "./WhiteboardApp";
13
-
14
- export type FastBoardConfig = WhiteboardAppConfig;
15
-
16
- export type MaybeRef<T> = T | Ref<T>;
17
- export type VueInstance = ComponentPublicInstance;
18
- export type MaybeElementRef = MaybeRef<
19
- HTMLElement | SVGElement | VueInstance | undefined | null
20
- >;
21
-
22
- /**
23
- * Get the dom element of a ref of element or Vue component instance
24
- */
25
- export function unrefElement(elRef: MaybeElementRef) {
26
- const plain = unref(elRef);
27
- return (plain as VueInstance)?.$el ?? plain;
28
- }
29
-
30
- function tryOnScopeDispose(fn: () => void) {
31
- if (getCurrentScope()) {
32
- onScopeDispose(fn);
33
- return true;
34
- }
35
- return false;
36
- }
37
-
38
- /**
39
- * @example
40
- * ```vue
41
- * <script setup>
42
- * const el = ref(null)
43
- * const app = useFastboard(el, { sdkConfig, joinRoom })
44
- * if (app.value) {
45
- * app.value.insertDocs({...})
46
- * }
47
- * </script>
48
- * <template>
49
- * <div style="width: 100%; height: 100%" ref="el"></div>
50
- * </template>
51
- * ```
52
- */
53
- export function useFastboard(el: MaybeElementRef, config: FastBoardConfig) {
54
- const app = shallowRef<WhiteboardApp | null>(null);
55
- const target = computed(() => unrefElement(el));
56
-
57
- createWhiteboardApp(config).then(app_ => {
58
- app.value = app_;
59
- });
60
-
61
- watchEffect(() => {
62
- if (target.value && app.value) {
63
- app.value.bindElement(target.value);
64
- }
65
- });
66
-
67
- tryOnScopeDispose(() => {
68
- if (app.value) {
69
- app.value.dispose();
70
- }
71
- });
72
-
73
- return app;
74
- }