@netless/fastboard-ui 0.3.2-canary.5 → 0.3.3
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/LICENSE.txt +21 -21
- package/README.md +7 -7
- package/dist/index.d.ts +102 -102
- package/dist/index.js +30 -23
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +30 -23
- package/dist/index.mjs.map +1 -1
- package/dist/index.svelte.mjs +22 -17
- package/dist/index.svelte.mjs.map +1 -1
- package/package.json +4 -5
- package/src/actions/height.ts +43 -43
- package/src/actions/scroll.ts +31 -31
- package/src/actions/tippy.ts +71 -71
- package/src/behaviors/apps.ts +74 -74
- package/src/behaviors/index.ts +1 -1
- package/src/components/Button/Button.svelte +51 -51
- package/src/components/Button/Button.svelte.d.ts +26 -26
- package/src/components/Button/index.ts +2 -2
- package/src/components/Fastboard/Fastboard.scss +61 -61
- package/src/components/Fastboard/Fastboard.svelte +80 -80
- package/src/components/Fastboard/Fastboard.svelte.ts +14 -14
- package/src/components/Fastboard/ReplayFastboard.svelte +43 -43
- package/src/components/Fastboard/ReplayFastboard.svelte.ts +13 -13
- package/src/components/Fastboard/index.ts +5 -5
- package/src/components/Icon/Icon.svelte +11 -11
- package/src/components/Icon/Icon.svelte.d.ts +10 -10
- package/src/components/Icon/index.ts +2 -2
- package/src/components/Icons/Apps.svelte +49 -49
- package/src/components/Icons/Arrow.svelte +16 -16
- package/src/components/Icons/ArrowBolded.svelte +17 -17
- package/src/components/Icons/Balloon.svelte +16 -16
- package/src/components/Icons/BalloonBolded.svelte +16 -16
- package/src/components/Icons/Circle.svelte +20 -20
- package/src/components/Icons/CircleBolded.svelte +20 -20
- package/src/components/Icons/Clean.svelte +14 -14
- package/src/components/Icons/Clear.svelte +16 -16
- package/src/components/Icons/Click.svelte +16 -16
- package/src/components/Icons/ClickFilled.svelte +10 -10
- package/src/components/Icons/Diamond.svelte +16 -16
- package/src/components/Icons/Down.svelte +16 -16
- package/src/components/Icons/Eraser.svelte +16 -16
- package/src/components/Icons/EraserFilled.svelte +16 -16
- package/src/components/Icons/Icons.scss +20 -20
- package/src/components/Icons/Left.svelte +16 -16
- package/src/components/Icons/Line.svelte +16 -16
- package/src/components/Icons/LineBolded.svelte +16 -16
- package/src/components/Icons/Loading.svelte +10 -10
- package/src/components/Icons/Minus.svelte +16 -16
- package/src/components/Icons/Pause.svelte +10 -10
- package/src/components/Icons/Pencil.svelte +29 -29
- package/src/components/Icons/PencilFilled.svelte +16 -16
- package/src/components/Icons/Play.svelte +10 -10
- package/src/components/Icons/Plus.svelte +16 -16
- package/src/components/Icons/Rectangle.svelte +16 -16
- package/src/components/Icons/RectangleBolded.svelte +16 -16
- package/src/components/Icons/Redo.svelte +15 -15
- package/src/components/Icons/Reset.svelte +26 -26
- package/src/components/Icons/Rhombus.svelte +16 -16
- package/src/components/Icons/RhombusBolded.svelte +16 -16
- package/src/components/Icons/Right.svelte +16 -16
- package/src/components/Icons/Selector.svelte +24 -24
- package/src/components/Icons/SelectorFilled.svelte +18 -18
- package/src/components/Icons/SpeechBalloon.svelte +16 -16
- package/src/components/Icons/Star.svelte +16 -16
- package/src/components/Icons/StarBolded.svelte +16 -16
- package/src/components/Icons/Text.svelte +16 -16
- package/src/components/Icons/TextFilled.svelte +17 -17
- package/src/components/Icons/Triangle.svelte +16 -16
- package/src/components/Icons/TriangleBolded.svelte +16 -16
- package/src/components/Icons/Undo.svelte +15 -15
- package/src/components/Icons/Up.svelte +16 -16
- package/src/components/Icons/WhiteboardAdd.svelte +34 -34
- package/src/components/Icons/index.ts +93 -93
- package/src/components/PageControl/PageControl.scss +15 -15
- package/src/components/PageControl/PageControl.svelte +79 -79
- package/src/components/PageControl/PageControl.svelte.d.ts +13 -13
- package/src/components/PageControl/index.ts +2 -2
- package/src/components/PlayerControl/PlayerControl.scss +57 -57
- package/src/components/PlayerControl/PlayerControl.svelte +153 -153
- package/src/components/PlayerControl/PlayerControl.svelte.d.ts +13 -13
- package/src/components/PlayerControl/index.ts +2 -2
- package/src/components/RedoUndo/RedoUndo.scss +11 -11
- package/src/components/RedoUndo/RedoUndo.svelte +60 -60
- package/src/components/RedoUndo/RedoUndo.svelte.d.ts +13 -13
- package/src/components/RedoUndo/index.ts +2 -2
- package/src/components/Toolbar/README.md +57 -57
- package/src/components/Toolbar/Toolbar.scss +78 -78
- package/src/components/Toolbar/Toolbar.svelte +62 -62
- package/src/components/Toolbar/Toolbar.svelte.d.ts +13 -13
- package/src/components/Toolbar/components/Contents.scss +168 -168
- package/src/components/Toolbar/components/Contents.svelte +202 -197
- package/src/components/Toolbar/components/Shapes.svelte +85 -85
- package/src/components/Toolbar/components/Slider.scss +119 -119
- package/src/components/Toolbar/components/Slider.svelte +54 -54
- package/src/components/Toolbar/components/StrokeColor.svelte +39 -39
- package/src/components/Toolbar/components/StrokeWidth.svelte +20 -20
- package/src/components/Toolbar/components/TextColor.svelte +39 -39
- package/src/components/Toolbar/components/constants.ts +80 -80
- package/src/components/Toolbar/components/helper.ts +24 -24
- package/src/components/Toolbar/index.ts +2 -2
- package/src/components/ZoomControl/ZoomControl.scss +15 -15
- package/src/components/ZoomControl/ZoomControl.svelte +99 -99
- package/src/components/ZoomControl/ZoomControl.svelte.d.ts +13 -13
- package/src/components/ZoomControl/index.ts +2 -2
- package/src/components/helpers.ts +3 -3
- package/src/components/theme.scss +92 -92
- package/src/components/variables.scss +69 -69
- package/src/index.ts +13 -13
- package/src/style.scss +36 -36
- package/src/typings.ts +38 -38
|
@@ -1,80 +1,80 @@
|
|
|
1
|
-
import type { Appliance, Color } from "@netless/fastboard-core";
|
|
2
|
-
import type { I18nData } from "../../../typings";
|
|
3
|
-
import Icons from "../../Icons";
|
|
4
|
-
|
|
5
|
-
export const colors: Record<string, Color> = {
|
|
6
|
-
"#E02020": [224, 32, 32],
|
|
7
|
-
"#F7B500": [247, 181, 0],
|
|
8
|
-
"#6DD400": [109, 212, 0],
|
|
9
|
-
"#32C5FF": [50, 197, 255],
|
|
10
|
-
"#0091FF": [0, 145, 255],
|
|
11
|
-
"#6236FF": [98, 54, 255],
|
|
12
|
-
"#B620E0": [182, 32, 224],
|
|
13
|
-
"#6D7278": [109, 114, 120],
|
|
14
|
-
};
|
|
15
|
-
|
|
16
|
-
export const shapes = [
|
|
17
|
-
"rectangle",
|
|
18
|
-
"ellipse",
|
|
19
|
-
"straight",
|
|
20
|
-
"arrow",
|
|
21
|
-
"pentagram",
|
|
22
|
-
"rhombus",
|
|
23
|
-
"triangle",
|
|
24
|
-
"speechBalloon",
|
|
25
|
-
] as const;
|
|
26
|
-
|
|
27
|
-
export type Shape = typeof shapes[number];
|
|
28
|
-
|
|
29
|
-
export const applianceShapes = shapes.slice(0, 4) as Appliance[];
|
|
30
|
-
|
|
31
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
-
export const shapesIcon: Record<Shape, any> = {
|
|
33
|
-
rectangle: Icons.Rectangle,
|
|
34
|
-
ellipse: Icons.Circle,
|
|
35
|
-
straight: Icons.Line,
|
|
36
|
-
arrow: Icons.Arrow,
|
|
37
|
-
pentagram: Icons.Star,
|
|
38
|
-
rhombus: Icons.Rhombus,
|
|
39
|
-
triangle: Icons.Triangle,
|
|
40
|
-
speechBalloon: Icons.Balloon,
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
-
export const shapesIconActive: Record<Shape, any> = {
|
|
45
|
-
rectangle: Icons.RectangleBolded,
|
|
46
|
-
ellipse: Icons.CircleBolded,
|
|
47
|
-
straight: Icons.LineBolded,
|
|
48
|
-
arrow: Icons.ArrowBolded,
|
|
49
|
-
pentagram: Icons.StarBolded,
|
|
50
|
-
rhombus: Icons.RhombusBolded,
|
|
51
|
-
triangle: Icons.TriangleBolded,
|
|
52
|
-
speechBalloon: Icons.BalloonBolded,
|
|
53
|
-
};
|
|
54
|
-
|
|
55
|
-
export const i18n: I18nData<
|
|
56
|
-
"clicker" | "selector" | "pencil" | "text" | "shapes" | "eraser" | "clear" | "apps"
|
|
57
|
-
> = {
|
|
58
|
-
en: {
|
|
59
|
-
clicker: "clicker",
|
|
60
|
-
selector: "selector",
|
|
61
|
-
pencil: "pencil",
|
|
62
|
-
eraser: "eraser",
|
|
63
|
-
text: "text",
|
|
64
|
-
shapes: "shapes",
|
|
65
|
-
clear: "clear",
|
|
66
|
-
apps: "apps",
|
|
67
|
-
},
|
|
68
|
-
"zh-CN": {
|
|
69
|
-
clicker: "点击",
|
|
70
|
-
selector: "选择",
|
|
71
|
-
pencil: "铅笔",
|
|
72
|
-
eraser: "橡皮",
|
|
73
|
-
text: "文字",
|
|
74
|
-
shapes: "形状",
|
|
75
|
-
clear: "清屏",
|
|
76
|
-
apps: "Apps",
|
|
77
|
-
},
|
|
78
|
-
};
|
|
79
|
-
|
|
80
|
-
export const colorKeys = Object.keys(colors);
|
|
1
|
+
import type { Appliance, Color } from "@netless/fastboard-core";
|
|
2
|
+
import type { I18nData } from "../../../typings";
|
|
3
|
+
import Icons from "../../Icons";
|
|
4
|
+
|
|
5
|
+
export const colors: Record<string, Color> = {
|
|
6
|
+
"#E02020": [224, 32, 32],
|
|
7
|
+
"#F7B500": [247, 181, 0],
|
|
8
|
+
"#6DD400": [109, 212, 0],
|
|
9
|
+
"#32C5FF": [50, 197, 255],
|
|
10
|
+
"#0091FF": [0, 145, 255],
|
|
11
|
+
"#6236FF": [98, 54, 255],
|
|
12
|
+
"#B620E0": [182, 32, 224],
|
|
13
|
+
"#6D7278": [109, 114, 120],
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export const shapes = [
|
|
17
|
+
"rectangle",
|
|
18
|
+
"ellipse",
|
|
19
|
+
"straight",
|
|
20
|
+
"arrow",
|
|
21
|
+
"pentagram",
|
|
22
|
+
"rhombus",
|
|
23
|
+
"triangle",
|
|
24
|
+
"speechBalloon",
|
|
25
|
+
] as const;
|
|
26
|
+
|
|
27
|
+
export type Shape = typeof shapes[number];
|
|
28
|
+
|
|
29
|
+
export const applianceShapes = shapes.slice(0, 4) as Appliance[];
|
|
30
|
+
|
|
31
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
32
|
+
export const shapesIcon: Record<Shape, any> = {
|
|
33
|
+
rectangle: Icons.Rectangle,
|
|
34
|
+
ellipse: Icons.Circle,
|
|
35
|
+
straight: Icons.Line,
|
|
36
|
+
arrow: Icons.Arrow,
|
|
37
|
+
pentagram: Icons.Star,
|
|
38
|
+
rhombus: Icons.Rhombus,
|
|
39
|
+
triangle: Icons.Triangle,
|
|
40
|
+
speechBalloon: Icons.Balloon,
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
44
|
+
export const shapesIconActive: Record<Shape, any> = {
|
|
45
|
+
rectangle: Icons.RectangleBolded,
|
|
46
|
+
ellipse: Icons.CircleBolded,
|
|
47
|
+
straight: Icons.LineBolded,
|
|
48
|
+
arrow: Icons.ArrowBolded,
|
|
49
|
+
pentagram: Icons.StarBolded,
|
|
50
|
+
rhombus: Icons.RhombusBolded,
|
|
51
|
+
triangle: Icons.TriangleBolded,
|
|
52
|
+
speechBalloon: Icons.BalloonBolded,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const i18n: I18nData<
|
|
56
|
+
"clicker" | "selector" | "pencil" | "text" | "shapes" | "eraser" | "clear" | "apps"
|
|
57
|
+
> = {
|
|
58
|
+
en: {
|
|
59
|
+
clicker: "clicker",
|
|
60
|
+
selector: "selector",
|
|
61
|
+
pencil: "pencil",
|
|
62
|
+
eraser: "eraser",
|
|
63
|
+
text: "text",
|
|
64
|
+
shapes: "shapes",
|
|
65
|
+
clear: "clear",
|
|
66
|
+
apps: "apps",
|
|
67
|
+
},
|
|
68
|
+
"zh-CN": {
|
|
69
|
+
clicker: "点击",
|
|
70
|
+
selector: "选择",
|
|
71
|
+
pencil: "铅笔",
|
|
72
|
+
eraser: "橡皮",
|
|
73
|
+
text: "文字",
|
|
74
|
+
shapes: "形状",
|
|
75
|
+
clear: "清屏",
|
|
76
|
+
apps: "Apps",
|
|
77
|
+
},
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
export const colorKeys = Object.keys(colors);
|
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import type { HotKey } from "@netless/fastboard-core";
|
|
2
|
-
import { element, attr, append } from "svelte/internal";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* ```svelte
|
|
6
|
-
* <span class="fastboard-toolbar-tooltip">
|
|
7
|
-
* <span>{text}</span>
|
|
8
|
-
* <span class="fastboard-toolbar-hotkey">{hotkey.toUpperCase()}</span>
|
|
9
|
-
* </span>
|
|
10
|
-
* ```
|
|
11
|
-
*/
|
|
12
|
-
export function tooltip(text: string, hotkey?: HotKey) {
|
|
13
|
-
if (!hotkey || typeof hotkey !== "string") return text;
|
|
14
|
-
const outer = element("span");
|
|
15
|
-
const inner = element("span");
|
|
16
|
-
inner.textContent = text;
|
|
17
|
-
const hotkey_span = element("span");
|
|
18
|
-
hotkey_span.textContent = hotkey.toUpperCase();
|
|
19
|
-
attr(outer, "class", "fastboard-toolbar-tooltip");
|
|
20
|
-
attr(hotkey_span, "class", "fastboard-toolbar-hotkey");
|
|
21
|
-
append(outer, inner);
|
|
22
|
-
append(outer, hotkey_span);
|
|
23
|
-
return outer;
|
|
24
|
-
}
|
|
1
|
+
import type { HotKey } from "@netless/fastboard-core";
|
|
2
|
+
import { element, attr, append } from "svelte/internal";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* ```svelte
|
|
6
|
+
* <span class="fastboard-toolbar-tooltip">
|
|
7
|
+
* <span>{text}</span>
|
|
8
|
+
* <span class="fastboard-toolbar-hotkey">{hotkey.toUpperCase()}</span>
|
|
9
|
+
* </span>
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
12
|
+
export function tooltip(text: string, hotkey?: HotKey) {
|
|
13
|
+
if (!hotkey || typeof hotkey !== "string") return text;
|
|
14
|
+
const outer = element("span");
|
|
15
|
+
const inner = element("span");
|
|
16
|
+
inner.textContent = text;
|
|
17
|
+
const hotkey_span = element("span");
|
|
18
|
+
hotkey_span.textContent = hotkey.toUpperCase();
|
|
19
|
+
attr(outer, "class", "fastboard-toolbar-tooltip");
|
|
20
|
+
attr(hotkey_span, "class", "fastboard-toolbar-hotkey");
|
|
21
|
+
append(outer, inner);
|
|
22
|
+
append(outer, hotkey_span);
|
|
23
|
+
return outer;
|
|
24
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./Toolbar.svelte";
|
|
2
|
-
export * from "./Toolbar.svelte";
|
|
1
|
+
export { default } from "./Toolbar.svelte";
|
|
2
|
+
export * from "./Toolbar.svelte";
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
-
@import "../theme.scss";
|
|
2
|
-
|
|
3
|
-
$name: "fastboard-zoom-control";
|
|
4
|
-
|
|
5
|
-
.#{$name} {
|
|
6
|
-
@include container;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
.#{$name}-btn {
|
|
10
|
-
@include btn;
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
.#{$name}-text {
|
|
14
|
-
@include tabular-nums;
|
|
15
|
-
}
|
|
1
|
+
@import "../theme.scss";
|
|
2
|
+
|
|
3
|
+
$name: "fastboard-zoom-control";
|
|
4
|
+
|
|
5
|
+
.#{$name} {
|
|
6
|
+
@include container;
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
.#{$name}-btn {
|
|
10
|
+
@include btn;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
.#{$name}-text {
|
|
14
|
+
@include tabular-nums;
|
|
15
|
+
}
|
|
@@ -1,99 +1,99 @@
|
|
|
1
|
-
<script lang="ts" context="module">
|
|
2
|
-
import type { FastboardApp } from "@netless/fastboard-core";
|
|
3
|
-
import type { GenericIcon, I18nData, IconType, Language, Theme } from "../../typings";
|
|
4
|
-
import { clamp } from "../helpers";
|
|
5
|
-
|
|
6
|
-
const i18n: I18nData<"plus" | "minus" | "reset"> = {
|
|
7
|
-
en: {
|
|
8
|
-
plus: "Zoom In",
|
|
9
|
-
minus: "Zoom Out",
|
|
10
|
-
reset: "Reset",
|
|
11
|
-
},
|
|
12
|
-
"zh-CN": {
|
|
13
|
-
plus: "放大",
|
|
14
|
-
minus: "缩小",
|
|
15
|
-
reset: "重置",
|
|
16
|
-
},
|
|
17
|
-
};
|
|
18
|
-
|
|
19
|
-
const scales: readonly number[] = [
|
|
20
|
-
0.3, 0.4096000000000002, 0.5120000000000001, 0.6400000000000001, 0.8, 1, 1.26, 1.5876000000000001,
|
|
21
|
-
2.000376, 2.5204737600000002, 3,
|
|
22
|
-
];
|
|
23
|
-
|
|
24
|
-
function next_scale(scale: number, delta: 1 | -1) {
|
|
25
|
-
const { length } = scales;
|
|
26
|
-
const last = length - 1;
|
|
27
|
-
if (scale < scales[0]) return scales[0];
|
|
28
|
-
if (scale > scales[last]) return scales[last];
|
|
29
|
-
for (let i = 0; i < length; ++i) {
|
|
30
|
-
const cur = scales[i];
|
|
31
|
-
const prev = i === 0 ? -Infinity : (scales[i - 1] + cur) / 2;
|
|
32
|
-
const next = i === last ? Infinity : (scales[i + 1] + cur) / 2;
|
|
33
|
-
if (prev <= scale && scale <= next) return scales[clamp(i + delta, 0, last)];
|
|
34
|
-
}
|
|
35
|
-
return 1;
|
|
36
|
-
}
|
|
37
|
-
</script>
|
|
38
|
-
|
|
39
|
-
<script lang="ts">
|
|
40
|
-
import Icon from "../Icon";
|
|
41
|
-
import Icons from "../Icons";
|
|
42
|
-
import Button from "../Button";
|
|
43
|
-
|
|
44
|
-
export let app: FastboardApp | null | undefined = null;
|
|
45
|
-
export let theme: Theme = "light";
|
|
46
|
-
export let language: Language = "en";
|
|
47
|
-
export let icons: GenericIcon<"plus" | "minus" | "reset"> | undefined = undefined;
|
|
48
|
-
|
|
49
|
-
const name = "fastboard-zoom-control";
|
|
50
|
-
|
|
51
|
-
$: writable = app?.writable;
|
|
52
|
-
$: disabled = !$writable;
|
|
53
|
-
$: t = i18n[language];
|
|
54
|
-
|
|
55
|
-
let type: IconType;
|
|
56
|
-
$: type = disabled ? "disable" : "normal";
|
|
57
|
-
|
|
58
|
-
$: camera = app?.camera;
|
|
59
|
-
$: scale = $camera?.scale ?? 1;
|
|
60
|
-
$: plus_disabled = disabled || next_scale(scale, 1) === scale;
|
|
61
|
-
$: minus_disabled = disabled || next_scale(scale, -1) === scale;
|
|
62
|
-
|
|
63
|
-
function plus() {
|
|
64
|
-
app?.moveCamera({ scale: next_scale(scale, 1), centerX: 0, centerY: 0 });
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function minus() {
|
|
68
|
-
app?.moveCamera({ scale: next_scale(scale, -1), centerX: 0, centerY: 0 });
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
function reset() {
|
|
72
|
-
app?.moveCamera({ scale: 1, centerX: 0, centerY: 0 });
|
|
73
|
-
}
|
|
74
|
-
</script>
|
|
75
|
-
|
|
76
|
-
<div class="{name} {theme}">
|
|
77
|
-
<Button class="plus" {name} {theme} disabled={plus_disabled} on:click={plus} content={t.plus}>
|
|
78
|
-
<Icon src={icons?.plus[type]} alt="[plus]">
|
|
79
|
-
<Icons.Plus {theme} />
|
|
80
|
-
</Icon>
|
|
81
|
-
</Button>
|
|
82
|
-
<span class="{name}-text {theme}">
|
|
83
|
-
{#if $camera == null}
|
|
84
|
-
…
|
|
85
|
-
{:else}
|
|
86
|
-
{Math.ceil(scale * 100)}%
|
|
87
|
-
{/if}
|
|
88
|
-
</span>
|
|
89
|
-
<Button class="minus" {name} {theme} disabled={minus_disabled} on:click={minus} content={t.minus}>
|
|
90
|
-
<Icon src={icons?.minus[type]} alt="[minus]">
|
|
91
|
-
<Icons.Minus {theme} />
|
|
92
|
-
</Icon>
|
|
93
|
-
</Button>
|
|
94
|
-
<Button class="reset" {name} {theme} {disabled} on:click={reset} content={t.reset}>
|
|
95
|
-
<Icon src={icons?.reset[type]} alt="[reset]">
|
|
96
|
-
<Icons.Reset {theme} />
|
|
97
|
-
</Icon>
|
|
98
|
-
</Button>
|
|
99
|
-
</div>
|
|
1
|
+
<script lang="ts" context="module">
|
|
2
|
+
import type { FastboardApp } from "@netless/fastboard-core";
|
|
3
|
+
import type { GenericIcon, I18nData, IconType, Language, Theme } from "../../typings";
|
|
4
|
+
import { clamp } from "../helpers";
|
|
5
|
+
|
|
6
|
+
const i18n: I18nData<"plus" | "minus" | "reset"> = {
|
|
7
|
+
en: {
|
|
8
|
+
plus: "Zoom In",
|
|
9
|
+
minus: "Zoom Out",
|
|
10
|
+
reset: "Reset",
|
|
11
|
+
},
|
|
12
|
+
"zh-CN": {
|
|
13
|
+
plus: "放大",
|
|
14
|
+
minus: "缩小",
|
|
15
|
+
reset: "重置",
|
|
16
|
+
},
|
|
17
|
+
};
|
|
18
|
+
|
|
19
|
+
const scales: readonly number[] = [
|
|
20
|
+
0.3, 0.4096000000000002, 0.5120000000000001, 0.6400000000000001, 0.8, 1, 1.26, 1.5876000000000001,
|
|
21
|
+
2.000376, 2.5204737600000002, 3,
|
|
22
|
+
];
|
|
23
|
+
|
|
24
|
+
function next_scale(scale: number, delta: 1 | -1) {
|
|
25
|
+
const { length } = scales;
|
|
26
|
+
const last = length - 1;
|
|
27
|
+
if (scale < scales[0]) return scales[0];
|
|
28
|
+
if (scale > scales[last]) return scales[last];
|
|
29
|
+
for (let i = 0; i < length; ++i) {
|
|
30
|
+
const cur = scales[i];
|
|
31
|
+
const prev = i === 0 ? -Infinity : (scales[i - 1] + cur) / 2;
|
|
32
|
+
const next = i === last ? Infinity : (scales[i + 1] + cur) / 2;
|
|
33
|
+
if (prev <= scale && scale <= next) return scales[clamp(i + delta, 0, last)];
|
|
34
|
+
}
|
|
35
|
+
return 1;
|
|
36
|
+
}
|
|
37
|
+
</script>
|
|
38
|
+
|
|
39
|
+
<script lang="ts">
|
|
40
|
+
import Icon from "../Icon";
|
|
41
|
+
import Icons from "../Icons";
|
|
42
|
+
import Button from "../Button";
|
|
43
|
+
|
|
44
|
+
export let app: FastboardApp | null | undefined = null;
|
|
45
|
+
export let theme: Theme = "light";
|
|
46
|
+
export let language: Language = "en";
|
|
47
|
+
export let icons: GenericIcon<"plus" | "minus" | "reset"> | undefined = undefined;
|
|
48
|
+
|
|
49
|
+
const name = "fastboard-zoom-control";
|
|
50
|
+
|
|
51
|
+
$: writable = app?.writable;
|
|
52
|
+
$: disabled = !$writable;
|
|
53
|
+
$: t = i18n[language];
|
|
54
|
+
|
|
55
|
+
let type: IconType;
|
|
56
|
+
$: type = disabled ? "disable" : "normal";
|
|
57
|
+
|
|
58
|
+
$: camera = app?.camera;
|
|
59
|
+
$: scale = $camera?.scale ?? 1;
|
|
60
|
+
$: plus_disabled = disabled || next_scale(scale, 1) === scale;
|
|
61
|
+
$: minus_disabled = disabled || next_scale(scale, -1) === scale;
|
|
62
|
+
|
|
63
|
+
function plus() {
|
|
64
|
+
app?.moveCamera({ scale: next_scale(scale, 1), centerX: 0, centerY: 0 });
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function minus() {
|
|
68
|
+
app?.moveCamera({ scale: next_scale(scale, -1), centerX: 0, centerY: 0 });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
function reset() {
|
|
72
|
+
app?.moveCamera({ scale: 1, centerX: 0, centerY: 0 });
|
|
73
|
+
}
|
|
74
|
+
</script>
|
|
75
|
+
|
|
76
|
+
<div class="{name} {theme}">
|
|
77
|
+
<Button class="plus" {name} {theme} disabled={plus_disabled} on:click={plus} content={t.plus}>
|
|
78
|
+
<Icon src={icons?.plus[type]} alt="[plus]">
|
|
79
|
+
<Icons.Plus {theme} />
|
|
80
|
+
</Icon>
|
|
81
|
+
</Button>
|
|
82
|
+
<span class="{name}-text {theme}">
|
|
83
|
+
{#if $camera == null}
|
|
84
|
+
…
|
|
85
|
+
{:else}
|
|
86
|
+
{Math.ceil(scale * 100)}%
|
|
87
|
+
{/if}
|
|
88
|
+
</span>
|
|
89
|
+
<Button class="minus" {name} {theme} disabled={minus_disabled} on:click={minus} content={t.minus}>
|
|
90
|
+
<Icon src={icons?.minus[type]} alt="[minus]">
|
|
91
|
+
<Icons.Minus {theme} />
|
|
92
|
+
</Icon>
|
|
93
|
+
</Button>
|
|
94
|
+
<Button class="reset" {name} {theme} {disabled} on:click={reset} content={t.reset}>
|
|
95
|
+
<Icon src={icons?.reset[type]} alt="[reset]">
|
|
96
|
+
<Icons.Reset {theme} />
|
|
97
|
+
</Icon>
|
|
98
|
+
</Button>
|
|
99
|
+
</div>
|
|
@@ -1,13 +1,13 @@
|
|
|
1
|
-
import type { FastboardApp } from "@netless/fastboard-core";
|
|
2
|
-
import type { Theme, Language, GenericIcon } from "../../typings";
|
|
3
|
-
import { SvelteComponentTyped } from "svelte";
|
|
4
|
-
|
|
5
|
-
export declare interface ZoomControlProps {
|
|
6
|
-
app?: FastboardApp | null;
|
|
7
|
-
theme?: Theme;
|
|
8
|
-
language?: Language;
|
|
9
|
-
icons?: GenericIcon<"plus" | "minus" | "reset">;
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
declare class ZoomControl extends SvelteComponentTyped<ZoomControlProps> {}
|
|
13
|
-
export default ZoomControl;
|
|
1
|
+
import type { FastboardApp } from "@netless/fastboard-core";
|
|
2
|
+
import type { Theme, Language, GenericIcon } from "../../typings";
|
|
3
|
+
import { SvelteComponentTyped } from "svelte";
|
|
4
|
+
|
|
5
|
+
export declare interface ZoomControlProps {
|
|
6
|
+
app?: FastboardApp | null;
|
|
7
|
+
theme?: Theme;
|
|
8
|
+
language?: Language;
|
|
9
|
+
icons?: GenericIcon<"plus" | "minus" | "reset">;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
declare class ZoomControl extends SvelteComponentTyped<ZoomControlProps> {}
|
|
13
|
+
export default ZoomControl;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { default } from "./ZoomControl.svelte";
|
|
2
|
-
export * from "./ZoomControl.svelte";
|
|
1
|
+
export { default } from "./ZoomControl.svelte";
|
|
2
|
+
export * from "./ZoomControl.svelte";
|
|
@@ -1,3 +1,3 @@
|
|
|
1
|
-
export function clamp(value: number, min: number, max: number) {
|
|
2
|
-
return value < min ? min : value > max ? max : value;
|
|
3
|
-
}
|
|
1
|
+
export function clamp(value: number, min: number, max: number) {
|
|
2
|
+
return value < min ? min : value > max ? max : value;
|
|
3
|
+
}
|
|
@@ -1,92 +1,92 @@
|
|
|
1
|
-
@use "sass:color";
|
|
2
|
-
@import "./variables.scss";
|
|
3
|
-
|
|
4
|
-
$themes: (
|
|
5
|
-
light: (
|
|
6
|
-
color: $grey-6,
|
|
7
|
-
active-color: $blue-6,
|
|
8
|
-
bg-color: color.change(white, $alpha: 0.9),
|
|
9
|
-
hover-bg-color: $blue-1,
|
|
10
|
-
border-color: $grey-1,
|
|
11
|
-
),
|
|
12
|
-
dark: (
|
|
13
|
-
color: $grey-5,
|
|
14
|
-
active-color: $blue-7,
|
|
15
|
-
bg-color: color.change($grey-10, $alpha: 0.9),
|
|
16
|
-
hover-bg-color: $grey-8,
|
|
17
|
-
border-color: $grey-8,
|
|
18
|
-
),
|
|
19
|
-
);
|
|
20
|
-
|
|
21
|
-
@function read($theme, $name) {
|
|
22
|
-
@return var(--fastboard-#{$name}, map-get($theme, $name));
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
@mixin border-box {
|
|
26
|
-
box-sizing: border-box;
|
|
27
|
-
|
|
28
|
-
* {
|
|
29
|
-
box-sizing: inherit;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
@mixin tabular-nums {
|
|
34
|
-
font-variant-numeric: tabular-nums;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
@mixin container {
|
|
38
|
-
@include border-box;
|
|
39
|
-
|
|
40
|
-
display: inline-flex;
|
|
41
|
-
align-items: center;
|
|
42
|
-
gap: 4px;
|
|
43
|
-
padding: 4px;
|
|
44
|
-
border: 1px solid;
|
|
45
|
-
border-radius: 4px;
|
|
46
|
-
font-size: 14px;
|
|
47
|
-
font-family: system-ui;
|
|
48
|
-
pointer-events: auto;
|
|
49
|
-
backdrop-filter: blur(5px);
|
|
50
|
-
-webkit-backdrop-filter: blur(5px);
|
|
51
|
-
|
|
52
|
-
@each $name, $theme in $themes {
|
|
53
|
-
&.#{$name} {
|
|
54
|
-
color: read($theme, "color");
|
|
55
|
-
background-color: read($theme, "bg-color");
|
|
56
|
-
border-color: read($theme, "border-color");
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
@mixin btn($size: 24px, $padding: 0) {
|
|
62
|
-
appearance: none;
|
|
63
|
-
cursor: pointer;
|
|
64
|
-
margin: 0;
|
|
65
|
-
border: 0;
|
|
66
|
-
padding: $padding;
|
|
67
|
-
width: $size;
|
|
68
|
-
height: $size;
|
|
69
|
-
background-color: transparent;
|
|
70
|
-
border-radius: 4px;
|
|
71
|
-
font-size: 0;
|
|
72
|
-
line-height: 1;
|
|
73
|
-
flex-shrink: 0;
|
|
74
|
-
|
|
75
|
-
svg,
|
|
76
|
-
img {
|
|
77
|
-
width: 100%;
|
|
78
|
-
height: 100%;
|
|
79
|
-
pointer-events: none;
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
&:disabled {
|
|
83
|
-
opacity: 0.5;
|
|
84
|
-
cursor: not-allowed;
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@each $name, $theme in $themes {
|
|
88
|
-
&.#{$name}:not(:disabled):hover {
|
|
89
|
-
background-color: read($theme, "hover-bg-color");
|
|
90
|
-
}
|
|
91
|
-
}
|
|
92
|
-
}
|
|
1
|
+
@use "sass:color";
|
|
2
|
+
@import "./variables.scss";
|
|
3
|
+
|
|
4
|
+
$themes: (
|
|
5
|
+
light: (
|
|
6
|
+
color: $grey-6,
|
|
7
|
+
active-color: $blue-6,
|
|
8
|
+
bg-color: color.change(white, $alpha: 0.9),
|
|
9
|
+
hover-bg-color: $blue-1,
|
|
10
|
+
border-color: $grey-1,
|
|
11
|
+
),
|
|
12
|
+
dark: (
|
|
13
|
+
color: $grey-5,
|
|
14
|
+
active-color: $blue-7,
|
|
15
|
+
bg-color: color.change($grey-10, $alpha: 0.9),
|
|
16
|
+
hover-bg-color: $grey-8,
|
|
17
|
+
border-color: $grey-8,
|
|
18
|
+
),
|
|
19
|
+
);
|
|
20
|
+
|
|
21
|
+
@function read($theme, $name) {
|
|
22
|
+
@return var(--fastboard-#{$name}, map-get($theme, $name));
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
@mixin border-box {
|
|
26
|
+
box-sizing: border-box;
|
|
27
|
+
|
|
28
|
+
* {
|
|
29
|
+
box-sizing: inherit;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
@mixin tabular-nums {
|
|
34
|
+
font-variant-numeric: tabular-nums;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
@mixin container {
|
|
38
|
+
@include border-box;
|
|
39
|
+
|
|
40
|
+
display: inline-flex;
|
|
41
|
+
align-items: center;
|
|
42
|
+
gap: 4px;
|
|
43
|
+
padding: 4px;
|
|
44
|
+
border: 1px solid;
|
|
45
|
+
border-radius: 4px;
|
|
46
|
+
font-size: 14px;
|
|
47
|
+
font-family: system-ui;
|
|
48
|
+
pointer-events: auto;
|
|
49
|
+
backdrop-filter: blur(5px);
|
|
50
|
+
-webkit-backdrop-filter: blur(5px);
|
|
51
|
+
|
|
52
|
+
@each $name, $theme in $themes {
|
|
53
|
+
&.#{$name} {
|
|
54
|
+
color: read($theme, "color");
|
|
55
|
+
background-color: read($theme, "bg-color");
|
|
56
|
+
border-color: read($theme, "border-color");
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
@mixin btn($size: 24px, $padding: 0) {
|
|
62
|
+
appearance: none;
|
|
63
|
+
cursor: pointer;
|
|
64
|
+
margin: 0;
|
|
65
|
+
border: 0;
|
|
66
|
+
padding: $padding;
|
|
67
|
+
width: $size;
|
|
68
|
+
height: $size;
|
|
69
|
+
background-color: transparent;
|
|
70
|
+
border-radius: 4px;
|
|
71
|
+
font-size: 0;
|
|
72
|
+
line-height: 1;
|
|
73
|
+
flex-shrink: 0;
|
|
74
|
+
|
|
75
|
+
svg,
|
|
76
|
+
img {
|
|
77
|
+
width: 100%;
|
|
78
|
+
height: 100%;
|
|
79
|
+
pointer-events: none;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
&:disabled {
|
|
83
|
+
opacity: 0.5;
|
|
84
|
+
cursor: not-allowed;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@each $name, $theme in $themes {
|
|
88
|
+
&.#{$name}:not(:disabled):hover {
|
|
89
|
+
background-color: read($theme, "hover-bg-color");
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}
|