@netless/fastboard-react 0.2.13-canary.0 → 0.3.0-canary.2

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 (105) hide show
  1. package/README.md +49 -0
  2. package/dist/index.d.ts +11 -140
  3. package/dist/index.js +73 -2130
  4. package/dist/index.js.map +1 -1
  5. package/dist/index.mjs +71 -2129
  6. package/dist/index.mjs.map +1 -1
  7. package/package.json +16 -23
  8. package/src/Fastboard.tsx +12 -0
  9. package/src/PageControl.tsx +11 -0
  10. package/src/RedoUndo.tsx +8 -0
  11. package/src/Toolbar.tsx +8 -0
  12. package/src/ZoomControl.tsx +11 -0
  13. package/src/hooks.tsx +53 -0
  14. package/src/index.tsx +19 -0
  15. package/src/style.scss +3 -26
  16. package/src/behaviors/style.ts +0 -4
  17. package/src/components/Fastboard.scss +0 -46
  18. package/src/components/Fastboard.tsx +0 -108
  19. package/src/components/PageControl/PageControl.scss +0 -84
  20. package/src/components/PageControl/PageControl.tsx +0 -101
  21. package/src/components/PageControl/hooks.ts +0 -24
  22. package/src/components/PageControl/index.ts +0 -2
  23. package/src/components/PlayerControl/PlayerControl.scss +0 -146
  24. package/src/components/PlayerControl/PlayerControl.tsx +0 -131
  25. package/src/components/PlayerControl/components/Button.tsx +0 -44
  26. package/src/components/PlayerControl/hooks.ts +0 -88
  27. package/src/components/PlayerControl/icons/Loading.tsx +0 -13
  28. package/src/components/PlayerControl/icons/Pause.tsx +0 -13
  29. package/src/components/PlayerControl/icons/Play.tsx +0 -13
  30. package/src/components/PlayerControl/icons/index.ts +0 -10
  31. package/src/components/PlayerControl/index.ts +0 -2
  32. package/src/components/RedoUndo/RedoUndo.scss +0 -56
  33. package/src/components/RedoUndo/RedoUndo.tsx +0 -76
  34. package/src/components/RedoUndo/hooks.ts +0 -18
  35. package/src/components/RedoUndo/index.ts +0 -2
  36. package/src/components/ReplayFastboard.tsx +0 -36
  37. package/src/components/Toolbar/Content.tsx +0 -89
  38. package/src/components/Toolbar/Toolbar.scss +0 -343
  39. package/src/components/Toolbar/Toolbar.tsx +0 -84
  40. package/src/components/Toolbar/components/ApplianceButtons.tsx +0 -108
  41. package/src/components/Toolbar/components/AppsButton.tsx +0 -134
  42. package/src/components/Toolbar/components/Button.tsx +0 -45
  43. package/src/components/Toolbar/components/ColorBox.tsx +0 -55
  44. package/src/components/Toolbar/components/CutLine.tsx +0 -8
  45. package/src/components/Toolbar/components/PencilButton.tsx +0 -66
  46. package/src/components/Toolbar/components/ShapesButton.tsx +0 -135
  47. package/src/components/Toolbar/components/Slider.tsx +0 -26
  48. package/src/components/Toolbar/components/TextButton.tsx +0 -62
  49. package/src/components/Toolbar/components/UpDownButtons.tsx +0 -49
  50. package/src/components/Toolbar/components/assets/cocos.png +0 -0
  51. package/src/components/Toolbar/components/assets/collapsed.png +0 -0
  52. package/src/components/Toolbar/components/assets/countdown.png +0 -0
  53. package/src/components/Toolbar/components/assets/expanded.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 -89
  58. package/src/components/Toolbar/icons/Apps.tsx +0 -16
  59. package/src/components/Toolbar/icons/Arrow.tsx +0 -13
  60. package/src/components/Toolbar/icons/Circle.tsx +0 -13
  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 -13
  64. package/src/components/Toolbar/icons/Diamond.tsx +0 -13
  65. package/src/components/Toolbar/icons/Down.tsx +0 -13
  66. package/src/components/Toolbar/icons/Eraser.tsx +0 -16
  67. package/src/components/Toolbar/icons/Expand.tsx +0 -13
  68. package/src/components/Toolbar/icons/Laser.tsx +0 -21
  69. package/src/components/Toolbar/icons/Line.tsx +0 -13
  70. package/src/components/Toolbar/icons/Loading.tsx +0 -13
  71. package/src/components/Toolbar/icons/Pencil.tsx +0 -16
  72. package/src/components/Toolbar/icons/Rectangle.tsx +0 -13
  73. package/src/components/Toolbar/icons/Selector.tsx +0 -13
  74. package/src/components/Toolbar/icons/SpeechBalloon.tsx +0 -17
  75. package/src/components/Toolbar/icons/Star.tsx +0 -17
  76. package/src/components/Toolbar/icons/Text.tsx +0 -13
  77. package/src/components/Toolbar/icons/Triangle.tsx +0 -13
  78. package/src/components/Toolbar/icons/Up.tsx +0 -13
  79. package/src/components/Toolbar/icons/index.ts +0 -42
  80. package/src/components/Toolbar/index.ts +0 -2
  81. package/src/components/ZoomControl/ZoomControl.scss +0 -84
  82. package/src/components/ZoomControl/ZoomControl.tsx +0 -96
  83. package/src/components/ZoomControl/hooks.ts +0 -50
  84. package/src/components/ZoomControl/index.ts +0 -2
  85. package/src/components/hooks.ts +0 -66
  86. package/src/components/tippy-util.ts +0 -8
  87. package/src/i18n/en.json +0 -31
  88. package/src/i18n/index.ts +0 -29
  89. package/src/i18n/zh-CN.json +0 -32
  90. package/src/icons/Left.tsx +0 -15
  91. package/src/icons/Minus.tsx +0 -15
  92. package/src/icons/Plus.tsx +0 -15
  93. package/src/icons/Redo.tsx +0 -19
  94. package/src/icons/Reset.tsx +0 -17
  95. package/src/icons/Right.tsx +0 -15
  96. package/src/icons/Undo.tsx +0 -19
  97. package/src/icons/WhiteboardAdd.tsx +0 -26
  98. package/src/icons/index.tsx +0 -11
  99. package/src/index.ts +0 -12
  100. package/src/internal/helpers.ts +0 -31
  101. package/src/internal/hooks.ts +0 -23
  102. package/src/internal/index.ts +0 -2
  103. package/src/theme.ts +0 -36
  104. package/src/typings.ts +0 -15
  105. package/src/vanilla/index.tsx +0 -28
@@ -1,15 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Left({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path d="m14 8-2 2-2 2 2 2 2 2" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
13
- </svg>
14
- );
15
- }
@@ -1,15 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Minus({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path d="M5 12h14" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
13
- </svg>
14
- );
15
- }
@@ -1,15 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Plus({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path d="M5 12h14m-7-7v14" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
13
- </svg>
14
- );
15
- }
@@ -1,19 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Redo({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path
13
- d="M19 9.625H9v-1.25h10v1.25ZM5.625 13v6h-1.25v-6h1.25ZM9 9.625A3.375 3.375 0 0 0 5.625 13h-1.25A4.625 4.625 0 0 1 9 8.375v1.25Z"
14
- fill={stroke}
15
- />
16
- <path d="m15 5 4 4-4 4" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
17
- </svg>
18
- );
19
- }
@@ -1,17 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Reset({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <circle cx="12" cy="12" fill={stroke} r="2" />
13
- <path d="M12 3v4m0 10v4m9-9h-4M7 12H3" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
14
- <circle cx="12" cy="12" r="7" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
15
- </svg>
16
- );
17
- }
@@ -1,15 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Right({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path d="m10 8 2 2 2 2-2 2-2 2" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
13
- </svg>
14
- );
15
- }
@@ -1,19 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function Undo({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path
13
- d="M5 9.625h10v-1.25H5v1.25ZM18.375 13v6h1.25v-6h-1.25ZM15 9.625A3.375 3.375 0 0 1 18.375 13h1.25A4.625 4.625 0 0 0 15 8.375v1.25Z"
14
- fill={stroke}
15
- />
16
- <path d="M9 5 5 9l4 4" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
17
- </svg>
18
- );
19
- }
@@ -1,26 +0,0 @@
1
- import type { IconProps } from "../typings";
2
-
3
- import React from "react";
4
- import { themes } from "../theme";
5
-
6
- export function WhiteboardAdd({ theme = "light", active }: IconProps) {
7
- const config = themes[theme];
8
- const stroke = active ? config.activeColor : config.color;
9
-
10
- return (
11
- <svg viewBox="0 0 24 24" fill="none">
12
- <path d="M4 20h16M4 6h16" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
13
- <rect
14
- height="10"
15
- rx="1"
16
- stroke={stroke}
17
- strokeLinejoin="round"
18
- strokeWidth="1.25"
19
- width="14"
20
- x="5"
21
- y="8"
22
- />
23
- <path d="M12 4v2m-3 7h6m-3-3v6" stroke={stroke} strokeLinejoin="round" strokeWidth="1.25" />
24
- </svg>
25
- );
26
- }
@@ -1,11 +0,0 @@
1
- import React from "react";
2
-
3
- export interface IconPropsWithFallback {
4
- fallback: React.ReactElement;
5
- src?: string;
6
- alt?: string;
7
- }
8
-
9
- export function Icon({ fallback, src, alt = "[icon]" }: IconPropsWithFallback) {
10
- return src ? <img src={src} alt={alt} title={alt} /> : fallback;
11
- }
package/src/index.ts DELETED
@@ -1,12 +0,0 @@
1
- import "./behaviors/style";
2
-
3
- export * from "./typings";
4
- export * from "./components/hooks";
5
- export * from "./components/RedoUndo";
6
- export * from "./components/ZoomControl";
7
- export * from "./components/PageControl";
8
- export * from "./components/Toolbar";
9
- export * from "./components/PlayerControl";
10
- export * from "./components/Fastboard";
11
- export * from "./components/ReplayFastboard";
12
- export * from "./vanilla";
@@ -1,31 +0,0 @@
1
- export function noop() {
2
- return;
3
- }
4
-
5
- export function applyStyles(css: string) {
6
- const el = document.createElement("style");
7
- el.appendChild(document.createTextNode(css));
8
- document.head.appendChild(el);
9
- return el;
10
- }
11
-
12
- export function clamp(value: number, min: number, max: number) {
13
- return value < min ? min : value > max ? max : value;
14
- }
15
-
16
- export function isEqualArray<T>(a: T[], b: T[]) {
17
- return a.length === b.length && a.every((e, i) => e === b[i]);
18
- }
19
-
20
- export const defaultHotKeys = {
21
- changeToSelector: "s",
22
- changeToLaserPointer: "z",
23
- changeToPencil: "p",
24
- changeToRectangle: "r",
25
- changeToEllipse: "c",
26
- changeToEraser: "e",
27
- changeToText: "t",
28
- changeToStraight: "l",
29
- changeToArrow: "a",
30
- changeToHand: "h",
31
- };
@@ -1,23 +0,0 @@
1
- import { useCallback, useEffect, useRef, useState } from "react";
2
-
3
- export function useLastValue<T>(value: T) {
4
- const ref = useRef<T>(value);
5
- useEffect(() => {
6
- ref.current = value;
7
- }, [value]);
8
- return ref.current;
9
- }
10
-
11
- export function useAsyncValue<T>(fn: () => Promise<T>) {
12
- const [value, setValue] = useState<T | null>(null);
13
- useEffect(() => {
14
- fn().then(setValue);
15
- // eslint-disable-next-line react-hooks/exhaustive-deps
16
- }, []);
17
- return value;
18
- }
19
-
20
- export function useForceUpdate() {
21
- const [, forceUpdate] = useState({});
22
- return useCallback(() => forceUpdate({}), []);
23
- }
@@ -1,2 +0,0 @@
1
- export * from "./helpers";
2
- export * from "./hooks";
package/src/theme.ts DELETED
@@ -1,36 +0,0 @@
1
- import type { IconProps } from "./typings";
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];
package/src/typings.ts DELETED
@@ -1,15 +0,0 @@
1
- export type Theme = "light" | "dark";
2
- export type Language = "en" | "zh-CN";
3
-
4
- export interface IconProps {
5
- theme?: Theme;
6
- active?: boolean;
7
- }
8
-
9
- export interface CommonProps {
10
- theme?: Theme;
11
- }
12
-
13
- export type GenericIcon<K extends string, E extends string = "disable"> = Partial<
14
- Record<`${K}Icon${Capitalize<E | "">}`, string>
15
- >;
@@ -1,28 +0,0 @@
1
- import type { FastboardApp } from "@netless/fastboard-core";
2
- import type { DivProps, FastboardProps } from "../components/Fastboard";
3
-
4
- import React from "react";
5
- import ReactDOM from "react-dom";
6
- import { Fastboard } from "../components/Fastboard";
7
-
8
- export type MountProps = Omit<FastboardProps & DivProps, "ref">;
9
-
10
- /**
11
- * Mount fastboard app to some dom, returns the updater and disposer.
12
- * @example
13
- * let app = await createFastboard({ ...config })
14
- * const { update, destroy } = mount(app, document.getElementById("whiteboard"))
15
- * update({ theme: 'dark' })
16
- * destroy()
17
- */
18
- export function mount(app: FastboardApp, dom: HTMLElement, props: MountProps = {}) {
19
- ReactDOM.render(<Fastboard app={app} {...props} />, dom);
20
- return {
21
- update(props: MountProps = {}) {
22
- ReactDOM.render(<Fastboard app={app} {...props} />, dom);
23
- },
24
- destroy() {
25
- ReactDOM.unmountComponentAtNode(dom);
26
- },
27
- };
28
- }