@netless/fastboard-ui 0.3.21 → 0.3.22-beta.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/full.d.ts +178 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +668 -464
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +668 -464
- package/dist/index.mjs.map +1 -1
- package/dist/index.svelte.mjs +669 -461
- package/dist/index.svelte.mjs.map +1 -1
- package/dist/lite.d.ts +3 -1
- package/package.json +3 -3
- package/src/components/Fastboard/Fastboard.svelte +23 -1
- package/src/components/Toolbar/Toolbar.svelte +3 -1
- package/src/components/Toolbar/components/Contents.svelte +5 -4
- package/src/components/Toolbar/components/StrokeColor.svelte +12 -7
- package/src/components/Toolbar/components/TextColor.svelte +12 -7
- package/src/components/Toolbar/components/constants.ts +4 -2
- package/src/components/Toolbar/components/helper.ts +23 -1
- package/src/helpers/index.ts +33 -1
- package/src/typings.ts +4 -0
package/dist/lite.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { FastboardApp, FastboardPlayer } from '@netless/fastboard-core/lite';
|
|
1
|
+
import { Color, FastboardApp, FastboardPlayer } from '@netless/fastboard-core/lite';
|
|
2
2
|
import { SvelteComponentTyped } from 'svelte/internal';
|
|
3
3
|
export { SvelteComponentTyped } from 'svelte/internal';
|
|
4
4
|
|
|
@@ -33,6 +33,8 @@ interface ToolbarConfig {
|
|
|
33
33
|
apps?: {
|
|
34
34
|
enable?: boolean;
|
|
35
35
|
};
|
|
36
|
+
/** 颜色 */
|
|
37
|
+
colors?: Color[];
|
|
36
38
|
}
|
|
37
39
|
interface FastboardUIConfig {
|
|
38
40
|
toolbar?: {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netless/fastboard-ui",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.22-beta.1",
|
|
4
4
|
"description": "The front-end of @netless/fastboard-core.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"svelte": "dist/index.svelte.mjs",
|
|
@@ -11,14 +11,14 @@
|
|
|
11
11
|
],
|
|
12
12
|
"repository": "netless-io/fastboard",
|
|
13
13
|
"peerDependencies": {
|
|
14
|
-
"@netless/fastboard-core": "0.3.
|
|
14
|
+
"@netless/fastboard-core": "0.3.22-beta.1"
|
|
15
15
|
},
|
|
16
16
|
"dependencies": {
|
|
17
17
|
"tippy.js": "^6.3.7"
|
|
18
18
|
},
|
|
19
19
|
"devDependencies": {
|
|
20
20
|
"@netless/buildtool": "0.1.0",
|
|
21
|
-
"@netless/fastboard-core": "0.3.
|
|
21
|
+
"@netless/fastboard-core": "0.3.22-beta.1",
|
|
22
22
|
"@netless/esbuild-plugin-inline-sass": "0.1.0"
|
|
23
23
|
},
|
|
24
24
|
"scripts": {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
<svelte:options immutable />
|
|
2
2
|
|
|
3
3
|
<script lang="ts">
|
|
4
|
-
import type { FastboardApp } from "@netless/fastboard-core";
|
|
4
|
+
import type { Color, FastboardApp } from "@netless/fastboard-core";
|
|
5
5
|
import type { Language, Theme, FastboardUIConfig } from "../../typings";
|
|
6
6
|
import { onMount } from "svelte";
|
|
7
7
|
import { tippy_hide_all } from "../../actions/tippy";
|
|
@@ -15,6 +15,7 @@
|
|
|
15
15
|
export let language: Language = "en";
|
|
16
16
|
export let containerRef: ((element: HTMLDivElement | null) => void) | undefined = undefined;
|
|
17
17
|
export let config: FastboardUIConfig = {};
|
|
18
|
+
export let colors: Color[] | undefined = undefined;
|
|
18
19
|
|
|
19
20
|
const name = "fastboard";
|
|
20
21
|
const AppsShowToolbar = ["DocsViewer", "Slide"];
|
|
@@ -23,6 +24,27 @@
|
|
|
23
24
|
let layout: "hidden" | "toolbar-only" | "visible" = "hidden";
|
|
24
25
|
let mounted = false;
|
|
25
26
|
|
|
27
|
+
$: manager = app?.manager;
|
|
28
|
+
$: room = app?.manager.room;
|
|
29
|
+
$: if (manager && room) {
|
|
30
|
+
const floatBarOptions = (room as any).floatBarOptions as { colors?: Color[] };
|
|
31
|
+
if (floatBarOptions.colors) {
|
|
32
|
+
colors = floatBarOptions.colors as Color[];
|
|
33
|
+
}
|
|
34
|
+
if (config?.toolbar) {
|
|
35
|
+
const _colors = config.toolbar.colors;
|
|
36
|
+
if (!_colors && colors) {
|
|
37
|
+
config = {
|
|
38
|
+
...config,
|
|
39
|
+
toolbar: {
|
|
40
|
+
...config.toolbar,
|
|
41
|
+
colors,
|
|
42
|
+
},
|
|
43
|
+
};
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
|
|
26
48
|
$: writable = app?.writable;
|
|
27
49
|
$: boxState = app?.boxState;
|
|
28
50
|
$: focusedApp = app?.focusedApp;
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
import { writable as svelte_writable } from "svelte/store";
|
|
5
5
|
import { height } from "../../actions/height";
|
|
6
6
|
import { clamp } from "../helpers";
|
|
7
|
-
import { default_items } from "./components/constants";
|
|
7
|
+
import { default_items, default_colors } from "./components/constants";
|
|
8
8
|
import Contents from "./components/Contents.svelte";
|
|
9
9
|
|
|
10
10
|
export let app: FastboardApp | null | undefined = null;
|
|
@@ -29,6 +29,7 @@
|
|
|
29
29
|
$: placement = config.placement || "left";
|
|
30
30
|
$: items = config.items || default_items;
|
|
31
31
|
$: hide_apps = config.apps?.enable === false;
|
|
32
|
+
$: colors = (config?.colors && config.colors.length && config.colors) || default_colors;
|
|
32
33
|
</script>
|
|
33
34
|
|
|
34
35
|
<div class="{name} {theme}" class:collapsed use:height={container_height}>
|
|
@@ -44,6 +45,7 @@
|
|
|
44
45
|
{placement}
|
|
45
46
|
{items}
|
|
46
47
|
{hide_apps}
|
|
48
|
+
{colors}
|
|
47
49
|
/>
|
|
48
50
|
</div>
|
|
49
51
|
<label class="{name}-handler {theme}">
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
import { scrollTop } from "../../../actions/scroll";
|
|
8
8
|
import { tippy_hide_all } from "../../../actions/tippy";
|
|
9
9
|
import { clamp } from "../../helpers";
|
|
10
|
-
import { default_items, i18n } from "./constants";
|
|
10
|
+
import { default_colors, default_items, i18n } from "./constants";
|
|
11
11
|
import { apps } from "../../../behaviors";
|
|
12
12
|
import { tooltip } from "./helper";
|
|
13
13
|
import Icons from "../../Icons";
|
|
@@ -38,6 +38,7 @@
|
|
|
38
38
|
export let placement: "left" | "right" = "left";
|
|
39
39
|
export let items: ToolbarItem[] = default_items;
|
|
40
40
|
export let hide_apps = false;
|
|
41
|
+
export let colors = default_colors;
|
|
41
42
|
|
|
42
43
|
const name = "fastboard-toolbar";
|
|
43
44
|
|
|
@@ -157,17 +158,17 @@
|
|
|
157
158
|
<div class="{name}-panel pencil" bind:this={pencil_panel}>
|
|
158
159
|
<StrokeWidth {app} {theme} {disabled} />
|
|
159
160
|
<div class="{name}-panel-divider" />
|
|
160
|
-
<StrokeColor {app} {theme} {disabled} />
|
|
161
|
+
<StrokeColor {app} {theme} {disabled} {colors} />
|
|
161
162
|
</div>
|
|
162
163
|
<div class="{name}-panel text" bind:this={text_panel}>
|
|
163
|
-
<TextColor {app} {theme} {disabled} />
|
|
164
|
+
<TextColor {app} {theme} {disabled} {colors} />
|
|
164
165
|
</div>
|
|
165
166
|
<div class="{name}-panel shapes" bind:this={shapes_panel}>
|
|
166
167
|
<SelectShapes {app} {theme} {language} {disabled} />
|
|
167
168
|
<div class="{name}-panel-divider" />
|
|
168
169
|
<StrokeWidth {app} {theme} {disabled} />
|
|
169
170
|
<div class="{name}-panel-divider" />
|
|
170
|
-
<StrokeColor {app} {theme} {disabled} />
|
|
171
|
+
<StrokeColor {app} {theme} {disabled} {colors} />
|
|
171
172
|
</div>
|
|
172
173
|
<div class="{name}-panel apps" style="--n:{$apps.length}" bind:this={apps_panel}>
|
|
173
174
|
{#each $apps as netless_app}
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Color, FastboardApp } from "@netless/fastboard-core";
|
|
3
3
|
import type { Theme } from "../../../typings";
|
|
4
|
-
import {
|
|
4
|
+
import { default_colors } from "./constants";
|
|
5
|
+
import { hexToRgb, rgbToHex } from "./helper";
|
|
5
6
|
|
|
6
7
|
export let app: FastboardApp | null | undefined = null;
|
|
7
8
|
export let theme: Theme = "light";
|
|
8
9
|
export let disabled = false;
|
|
10
|
+
export let colors: Color[] = default_colors;
|
|
9
11
|
|
|
10
12
|
$: memberState = app?.memberState;
|
|
11
13
|
$: strokeColor = $memberState?.strokeColor;
|
|
@@ -17,9 +19,9 @@
|
|
|
17
19
|
function set_stroke_color(ev: MouseEvent) {
|
|
18
20
|
let button = ev.target as HTMLButtonElement | null;
|
|
19
21
|
if (button && button.dataset.colorKey) {
|
|
20
|
-
let color =
|
|
22
|
+
let color = button.dataset.colorKey;
|
|
21
23
|
if (color && app) {
|
|
22
|
-
app.setStrokeColor(color);
|
|
24
|
+
app.setStrokeColor(hexToRgb(color));
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -27,14 +29,17 @@
|
|
|
27
29
|
|
|
28
30
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
29
31
|
<div class="fastboard-toolbar-colors {theme}" on:click={set_stroke_color}>
|
|
30
|
-
{#each
|
|
32
|
+
{#each colors as color}
|
|
31
33
|
<button
|
|
32
34
|
class="fastboard-toolbar-btn fastboard-toolbar-color-btn {theme}"
|
|
33
|
-
class:is-active={is_equal_color(strokeColor,
|
|
34
|
-
data-color-key={
|
|
35
|
+
class:is-active={is_equal_color(strokeColor, color)}
|
|
36
|
+
data-color-key={rgbToHex(color[0], color[1], color[2])}
|
|
35
37
|
{disabled}
|
|
36
38
|
>
|
|
37
|
-
<span
|
|
39
|
+
<span
|
|
40
|
+
class="fastboard-toolbar-color-item"
|
|
41
|
+
style:background-color={rgbToHex(color[0], color[1], color[2])}
|
|
42
|
+
/>
|
|
38
43
|
</button>
|
|
39
44
|
{/each}
|
|
40
45
|
</div>
|
|
@@ -1,11 +1,13 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
2
|
import type { Color, FastboardApp } from "@netless/fastboard-core";
|
|
3
3
|
import type { Theme } from "../../../typings";
|
|
4
|
-
import {
|
|
4
|
+
import { default_colors } from "./constants";
|
|
5
|
+
import { hexToRgb, rgbToHex } from "./helper";
|
|
5
6
|
|
|
6
7
|
export let app: FastboardApp | null | undefined = null;
|
|
7
8
|
export let theme: Theme = "light";
|
|
8
9
|
export let disabled = false;
|
|
10
|
+
export let colors: Color[] = default_colors;
|
|
9
11
|
|
|
10
12
|
$: memberState = app?.memberState;
|
|
11
13
|
$: textColor = $memberState?.textColor;
|
|
@@ -17,9 +19,9 @@
|
|
|
17
19
|
function set_stroke_color(ev: MouseEvent) {
|
|
18
20
|
let button = ev.target as HTMLButtonElement | null;
|
|
19
21
|
if (button && button.dataset.colorKey) {
|
|
20
|
-
let color =
|
|
22
|
+
let color = button.dataset.colorKey;
|
|
21
23
|
if (color && app) {
|
|
22
|
-
app.setTextColor(color);
|
|
24
|
+
app.setTextColor(hexToRgb(color));
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
27
|
}
|
|
@@ -27,14 +29,17 @@
|
|
|
27
29
|
|
|
28
30
|
<!-- svelte-ignore a11y-click-events-have-key-events -->
|
|
29
31
|
<div class="fastboard-toolbar-colors {theme}" on:click={set_stroke_color}>
|
|
30
|
-
{#each
|
|
32
|
+
{#each colors as color}
|
|
31
33
|
<button
|
|
32
34
|
class="fastboard-toolbar-btn fastboard-toolbar-color-btn {theme}"
|
|
33
|
-
class:is-active={is_equal_color(textColor,
|
|
34
|
-
data-color-key={
|
|
35
|
+
class:is-active={is_equal_color(textColor, color)}
|
|
36
|
+
data-color-key={rgbToHex(color[0], color[1], color[2])}
|
|
35
37
|
{disabled}
|
|
36
38
|
>
|
|
37
|
-
<span
|
|
39
|
+
<span
|
|
40
|
+
class="fastboard-toolbar-color-item"
|
|
41
|
+
style:background-color={rgbToHex(color[0], color[1], color[2])}
|
|
42
|
+
/>
|
|
38
43
|
</button>
|
|
39
44
|
{/each}
|
|
40
45
|
</div>
|
|
@@ -23,6 +23,10 @@ export const colors: Record<string, Color> = {
|
|
|
23
23
|
"#6D7278": [109, 114, 120],
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
export const colorKeys = Object.keys(colors);
|
|
27
|
+
|
|
28
|
+
export const default_colors: Color[] = Object.values(colors);
|
|
29
|
+
|
|
26
30
|
export const shapes = [
|
|
27
31
|
"rectangle",
|
|
28
32
|
"ellipse",
|
|
@@ -88,5 +92,3 @@ export const i18n: I18nData<ToolbarItem | "apps"> = {
|
|
|
88
92
|
laserPointer: "激光笔",
|
|
89
93
|
},
|
|
90
94
|
};
|
|
91
|
-
|
|
92
|
-
export const colorKeys = Object.keys(colors);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { HotKey } from "@netless/fastboard-core";
|
|
1
|
+
import type { Color, HotKey } from "@netless/fastboard-core";
|
|
2
2
|
import { element, attr, append } from "svelte/internal";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -22,3 +22,25 @@ export function tooltip(text: string, hotkey?: HotKey) {
|
|
|
22
22
|
append(outer, hotkey_span);
|
|
23
23
|
return outer;
|
|
24
24
|
}
|
|
25
|
+
|
|
26
|
+
export function rgbToHex(r: number, g: number, b: number) {
|
|
27
|
+
const hex = ((r << 16) + (g << 8) + b).toString(16).padStart(6, "0");
|
|
28
|
+
return "#" + hex;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export function hexToRgb(hex: string): Color {
|
|
32
|
+
// 移除可能存在的 # 符号
|
|
33
|
+
hex = hex.replace(/^#/, "");
|
|
34
|
+
|
|
35
|
+
// 确保 hex 是 6 位
|
|
36
|
+
if (hex.length !== 6) {
|
|
37
|
+
throw new Error("Invalid hex color");
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// 解析每两个字符为一个十进制数
|
|
41
|
+
const r = parseInt(hex.slice(0, 2), 16);
|
|
42
|
+
const g = parseInt(hex.slice(2, 4), 16);
|
|
43
|
+
const b = parseInt(hex.slice(4, 6), 16);
|
|
44
|
+
|
|
45
|
+
return [r, g, b];
|
|
46
|
+
}
|
package/src/helpers/index.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { FastboardApp, FastboardPlayer } from "@netless/fastboard-core";
|
|
1
|
+
import type { Color, FastboardApp, FastboardPlayer } from "@netless/fastboard-core";
|
|
2
2
|
import type { FastboardProps, ReplayFastboardProps } from "../components/Fastboard";
|
|
3
3
|
|
|
4
4
|
import { Fastboard, ReplayFastboard } from "../components/Fastboard";
|
|
@@ -19,17 +19,49 @@ export interface UI {
|
|
|
19
19
|
*/
|
|
20
20
|
export function createUI(app?: FastboardApp | null, div?: Element): UI {
|
|
21
21
|
let fastboard: Fastboard | undefined;
|
|
22
|
+
let colors: Color[] | undefined;
|
|
23
|
+
|
|
24
|
+
if (app?.manager && app.manager.room) {
|
|
25
|
+
const floatBarOptions = (app.manager.room as any).floatBarOptions as { colors?: Color[] };
|
|
26
|
+
if (floatBarOptions.colors) {
|
|
27
|
+
colors = floatBarOptions.colors as Color[];
|
|
28
|
+
}
|
|
29
|
+
}
|
|
22
30
|
|
|
23
31
|
const ui: UI = {
|
|
24
32
|
mount(div: Element, props?: FastboardProps) {
|
|
25
33
|
if (fastboard) {
|
|
26
34
|
fastboard.$destroy();
|
|
27
35
|
}
|
|
36
|
+
if (props?.config?.toolbar) {
|
|
37
|
+
const _colors = props.config.toolbar.colors;
|
|
38
|
+
if (!_colors && colors) {
|
|
39
|
+
props.config = {
|
|
40
|
+
...props.config,
|
|
41
|
+
toolbar: {
|
|
42
|
+
...props.config.toolbar,
|
|
43
|
+
colors,
|
|
44
|
+
},
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
28
48
|
fastboard = new Fastboard({ target: div, props: { app, ...props } });
|
|
29
49
|
return ui;
|
|
30
50
|
},
|
|
31
51
|
update(props?: FastboardProps) {
|
|
32
52
|
if (fastboard && props) {
|
|
53
|
+
if (props?.config?.toolbar) {
|
|
54
|
+
const _colors = props.config.toolbar.colors;
|
|
55
|
+
if (!_colors && colors) {
|
|
56
|
+
props.config = {
|
|
57
|
+
...props.config,
|
|
58
|
+
toolbar: {
|
|
59
|
+
...props.config.toolbar,
|
|
60
|
+
colors,
|
|
61
|
+
},
|
|
62
|
+
};
|
|
63
|
+
}
|
|
64
|
+
}
|
|
33
65
|
fastboard.$set(props);
|
|
34
66
|
}
|
|
35
67
|
},
|
package/src/typings.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
/// <reference types="svelte/types/runtime/ambient.d.ts" />
|
|
2
2
|
|
|
3
|
+
import type { Color } from "@netless/fastboard-core";
|
|
4
|
+
|
|
3
5
|
export { SvelteComponentTyped } from "svelte/internal";
|
|
4
6
|
|
|
5
7
|
export interface SvelteAction<T = void> {
|
|
@@ -47,6 +49,8 @@ export interface ToolbarConfig {
|
|
|
47
49
|
collapsed?: boolean;
|
|
48
50
|
/** Control the last button which opens apps stock on toolbar. */
|
|
49
51
|
apps?: { enable?: boolean };
|
|
52
|
+
/** 颜色 */
|
|
53
|
+
colors?: Color[];
|
|
50
54
|
}
|
|
51
55
|
|
|
52
56
|
export interface FastboardUIConfig {
|