@haoxin-web/excalidraw 1.0.21 → 1.0.23
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/dev/{chunk-5LGCONU6.js → chunk-ITD5AOM3.js} +3 -3
- package/dist/dev/{chunk-J55ZSMLS.js → chunk-NHZFLEMT.js} +2 -2
- package/dist/dev/data/{image-4T2DPV7H.js → image-EFEZBK6B.js} +3 -3
- package/dist/dev/index.css.map +2 -2
- package/dist/dev/index.js +927 -303
- package/dist/dev/index.js.map +4 -4
- package/dist/dev/subset-shared.chunk.js +1 -1
- package/dist/dev/subset-worker.chunk.js +1 -1
- package/dist/prod/{chunk-UB3N3ODO.js → chunk-GANJJ4PJ.js} +1 -1
- package/dist/prod/{chunk-MGDE5ZMU.js → chunk-TG36IG4W.js} +2 -2
- package/dist/prod/data/image-ERM7RAOD.js +1 -0
- package/dist/prod/index.js +27 -27
- package/dist/prod/subset-shared.chunk.js +1 -1
- package/dist/prod/subset-worker.chunk.js +1 -1
- package/dist/types/excalidraw/components/ExternalLeftToolbar.d.ts +8 -0
- package/dist/types/excalidraw/components/LayerUI.d.ts +2 -1
- package/dist/types/excalidraw/index.d.ts +5 -0
- package/dist/types/excalidraw/types.d.ts +102 -0
- package/docs/left-toolbar-commands.mdx +380 -0
- package/docs/remote-annotation-integration.mdx +170 -0
- package/package.json +3 -2
- package/dist/prod/data/image-SVXFZHEK.js +0 -1
- /package/dist/dev/{chunk-5LGCONU6.js.map → chunk-ITD5AOM3.js.map} +0 -0
- /package/dist/dev/{chunk-J55ZSMLS.js.map → chunk-NHZFLEMT.js.map} +0 -0
- /package/dist/dev/data/{image-4T2DPV7H.js.map → image-EFEZBK6B.js.map} +0 -0
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d}from"./chunk-LS7FJGPW.js";import"./chunk-
|
|
1
|
+
import{a,b,c,d}from"./chunk-LS7FJGPW.js";import"./chunk-GANJJ4PJ.js";import"./chunk-SRAX5OIU.js";export{a as Commands,b as subsetToBase64,c as subsetToBinary,d as toBase64};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a as r,c as t}from"./chunk-LS7FJGPW.js";import"./chunk-
|
|
1
|
+
import{a as r,c as t}from"./chunk-LS7FJGPW.js";import"./chunk-GANJJ4PJ.js";import"./chunk-SRAX5OIU.js";var s=import.meta.url?new URL(import.meta.url):void 0;typeof window>"u"&&typeof self<"u"&&(self.onmessage=async e=>{switch(e.data.command){case r.Subset:let a=await t(e.data.arrayBuffer,e.data.codePoints);self.postMessage(a,{transfer:[a]});break}});export{s as WorkerUrl};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import type { ExcalidrawImperativeAPI } from "../types";
|
|
3
|
+
export type ExternalLeftToolbarProps = {
|
|
4
|
+
excalidrawAPI: ExcalidrawImperativeAPI | null;
|
|
5
|
+
className?: string;
|
|
6
|
+
style?: React.CSSProperties;
|
|
7
|
+
};
|
|
8
|
+
export declare const ExternalLeftToolbar: ({ excalidrawAPI, className, style, }: ExternalLeftToolbarProps) => import("react/jsx-runtime").JSX.Element;
|
|
@@ -30,6 +30,7 @@ interface LayerUIProps {
|
|
|
30
30
|
showZoomActions?: boolean;
|
|
31
31
|
showPanActions?: boolean;
|
|
32
32
|
showToolBar?: boolean;
|
|
33
|
+
showTopLeftToolbar?: boolean;
|
|
33
34
|
}
|
|
34
|
-
declare const _default: React.MemoExoticComponent<({ actionManager, appState, files, setAppState, elements, canvas, onLockToggle, onHandToolToggle, onPenModeToggle, showExitZenModeBtn, renderTopRightUI, renderCustomStats, UIOptions, onExportImage, renderWelcomeScreen, children, app, isCollaborating, generateLinkForSelection, showZoomActions, showPanActions, showToolBar, }: LayerUIProps) => import("react/jsx-runtime").JSX.Element>;
|
|
35
|
+
declare const _default: React.MemoExoticComponent<({ actionManager, appState, files, setAppState, elements, canvas, onLockToggle, onHandToolToggle, onPenModeToggle, showExitZenModeBtn, renderTopRightUI, renderCustomStats, UIOptions, onExportImage, renderWelcomeScreen, children, app, isCollaborating, generateLinkForSelection, showZoomActions, showPanActions, showToolBar, showTopLeftToolbar, }: LayerUIProps) => import("react/jsx-runtime").JSX.Element>;
|
|
35
36
|
export default _default;
|
|
@@ -3,6 +3,7 @@ import Footer from "./components/footer/FooterCenter";
|
|
|
3
3
|
import LiveCollaborationTrigger from "./components/live-collaboration/LiveCollaborationTrigger";
|
|
4
4
|
import MainMenu from "./components/main-menu/MainMenu";
|
|
5
5
|
import WelcomeScreen from "./components/welcome-screen/WelcomeScreen";
|
|
6
|
+
import { UserList } from "./components/UserList";
|
|
6
7
|
import "./css/app.scss";
|
|
7
8
|
import "./css/styles.scss";
|
|
8
9
|
import "./fonts/fonts.css";
|
|
@@ -32,7 +33,10 @@ export { MainMenu };
|
|
|
32
33
|
export { Ellipsify } from "./components/Ellipsify";
|
|
33
34
|
export { useDevice } from "./components/App";
|
|
34
35
|
export { WelcomeScreen };
|
|
36
|
+
export { UserList };
|
|
35
37
|
export { LiveCollaborationTrigger };
|
|
38
|
+
export { ExternalLeftToolbar } from "./components/ExternalLeftToolbar";
|
|
39
|
+
export type { ExternalLeftToolbarProps } from "./components/ExternalLeftToolbar";
|
|
36
40
|
export { Stats } from "./components/Stats";
|
|
37
41
|
export { DefaultSidebar } from "./components/DefaultSidebar";
|
|
38
42
|
export { TTDDialog } from "./components/TTDDialog/TTDDialog";
|
|
@@ -45,3 +49,4 @@ export { DiagramToCodePlugin } from "./components/DiagramToCodePlugin/DiagramToC
|
|
|
45
49
|
export { getDataURL } from "./data/blob";
|
|
46
50
|
export { isElementLink } from "@excalidraw/element";
|
|
47
51
|
export { setCustomTextMetricsProvider } from "@excalidraw/element";
|
|
52
|
+
export type { LeftToolbarCommand, LeftToolbarFreedrawVariant, LeftToolbarLineVariant, LeftToolbarShapeTool, LeftToolbarStylePatch, } from "./types";
|
|
@@ -481,6 +481,7 @@ export interface ExcalidrawProps {
|
|
|
481
481
|
showZoomActions?: boolean;
|
|
482
482
|
showPanActions?: boolean;
|
|
483
483
|
showToolBar?: boolean;
|
|
484
|
+
showTopLeftToolbar?: boolean;
|
|
484
485
|
}
|
|
485
486
|
export type SceneData = {
|
|
486
487
|
elements?: ImportedDataState["elements"];
|
|
@@ -628,6 +629,52 @@ export type PointerDownState = Readonly<{
|
|
|
628
629
|
};
|
|
629
630
|
}>;
|
|
630
631
|
export type UnsubscribeCallback = () => void;
|
|
632
|
+
export type LeftToolbarShapeTool = Extract<ToolType, "rectangle" | "diamond" | "ellipse" | "triangle" | "pentagon" | "callout" | "hollow_arrow" | "hollow_double_arrow">;
|
|
633
|
+
export type LeftToolbarLineVariant = "line" | "arrow" | "doubleArrow" | "outlineArrow" | "outlineDoubleArrow";
|
|
634
|
+
export type LeftToolbarFreedrawVariant = "pen" | "highlighter";
|
|
635
|
+
export type LeftToolbarStylePatch = Partial<Pick<AppState, "currentItemStrokeColor" | "currentItemBackgroundColor" | "currentItemFillStyle" | "currentItemStrokeWidth" | "currentItemOpacity" | "currentItemStartArrowhead" | "currentItemEndArrowhead" | "currentItemFontSize" | "currentItemTextAlign" | "currentTextBold" | "currentTextItalic" | "currentTextUnderline" | "currentTextStrikethrough">>;
|
|
636
|
+
export type LeftToolbarCommand = {
|
|
637
|
+
type: "selectSelection";
|
|
638
|
+
} | {
|
|
639
|
+
type: "selectFreedraw";
|
|
640
|
+
payload?: {
|
|
641
|
+
variant?: LeftToolbarFreedrawVariant;
|
|
642
|
+
strokeWidth?: number;
|
|
643
|
+
strokeColor?: string;
|
|
644
|
+
};
|
|
645
|
+
} | {
|
|
646
|
+
type: "selectLine";
|
|
647
|
+
payload?: {
|
|
648
|
+
variant?: LeftToolbarLineVariant;
|
|
649
|
+
strokeWidth?: number;
|
|
650
|
+
strokeColor?: string;
|
|
651
|
+
};
|
|
652
|
+
} | {
|
|
653
|
+
type: "selectShape";
|
|
654
|
+
payload?: {
|
|
655
|
+
shape?: LeftToolbarShapeTool;
|
|
656
|
+
strokeWidth?: number;
|
|
657
|
+
strokeColor?: string;
|
|
658
|
+
backgroundColor?: string;
|
|
659
|
+
fillStyle?: AppState["currentItemFillStyle"];
|
|
660
|
+
};
|
|
661
|
+
} | {
|
|
662
|
+
type: "selectText";
|
|
663
|
+
payload?: {
|
|
664
|
+
fontSize?: number;
|
|
665
|
+
textAlign?: AppState["currentItemTextAlign"];
|
|
666
|
+
strokeColor?: string;
|
|
667
|
+
bold?: boolean;
|
|
668
|
+
italic?: boolean;
|
|
669
|
+
underline?: boolean;
|
|
670
|
+
strikethrough?: boolean;
|
|
671
|
+
};
|
|
672
|
+
} | {
|
|
673
|
+
type: "selectEraser";
|
|
674
|
+
} | {
|
|
675
|
+
type: "updateStyle";
|
|
676
|
+
payload: LeftToolbarStylePatch;
|
|
677
|
+
};
|
|
631
678
|
export interface ExcalidrawImperativeAPI {
|
|
632
679
|
updateScene: InstanceType<typeof App>["updateScene"];
|
|
633
680
|
/**
|
|
@@ -658,6 +705,61 @@ export interface ExcalidrawImperativeAPI {
|
|
|
658
705
|
addFiles: (data: BinaryFileData[]) => void;
|
|
659
706
|
id: string;
|
|
660
707
|
setActiveTool: InstanceType<typeof App>["setActiveTool"];
|
|
708
|
+
leftToolbar: {
|
|
709
|
+
/**
|
|
710
|
+
* Left toolbar: selection tool.
|
|
711
|
+
*/
|
|
712
|
+
selectSelection: () => void;
|
|
713
|
+
/**
|
|
714
|
+
* Left toolbar: freedraw tool.
|
|
715
|
+
*/
|
|
716
|
+
selectFreedraw: (opts?: {
|
|
717
|
+
variant?: LeftToolbarFreedrawVariant;
|
|
718
|
+
strokeWidth?: number;
|
|
719
|
+
strokeColor?: string;
|
|
720
|
+
}) => void;
|
|
721
|
+
/**
|
|
722
|
+
* Left toolbar: line/arrow group.
|
|
723
|
+
*/
|
|
724
|
+
selectLine: (opts?: {
|
|
725
|
+
variant?: LeftToolbarLineVariant;
|
|
726
|
+
strokeWidth?: number;
|
|
727
|
+
strokeColor?: string;
|
|
728
|
+
}) => void;
|
|
729
|
+
/**
|
|
730
|
+
* Left toolbar: shapes group.
|
|
731
|
+
*/
|
|
732
|
+
selectShape: (shape?: LeftToolbarShapeTool, opts?: {
|
|
733
|
+
strokeWidth?: number;
|
|
734
|
+
strokeColor?: string;
|
|
735
|
+
backgroundColor?: string;
|
|
736
|
+
fillStyle?: AppState["currentItemFillStyle"];
|
|
737
|
+
}) => void;
|
|
738
|
+
/**
|
|
739
|
+
* Left toolbar: text tool.
|
|
740
|
+
*/
|
|
741
|
+
selectText: (opts?: {
|
|
742
|
+
fontSize?: number;
|
|
743
|
+
textAlign?: AppState["currentItemTextAlign"];
|
|
744
|
+
strokeColor?: string;
|
|
745
|
+
bold?: boolean;
|
|
746
|
+
italic?: boolean;
|
|
747
|
+
underline?: boolean;
|
|
748
|
+
strikethrough?: boolean;
|
|
749
|
+
}) => void;
|
|
750
|
+
/**
|
|
751
|
+
* Left toolbar: eraser tool.
|
|
752
|
+
*/
|
|
753
|
+
selectEraser: () => void;
|
|
754
|
+
/**
|
|
755
|
+
* Generic style update used by external custom toolbar.
|
|
756
|
+
*/
|
|
757
|
+
updateStyle: (patch: LeftToolbarStylePatch) => void;
|
|
758
|
+
/**
|
|
759
|
+
* Executes a serializable command. Designed for cross-end communication.
|
|
760
|
+
*/
|
|
761
|
+
dispatch: (command: LeftToolbarCommand) => void;
|
|
762
|
+
};
|
|
661
763
|
setCursor: InstanceType<typeof App>["setCursor"];
|
|
662
764
|
resetCursor: InstanceType<typeof App>["resetCursor"];
|
|
663
765
|
toggleSidebar: InstanceType<typeof App>["toggleSidebar"];
|
|
@@ -0,0 +1,380 @@
|
|
|
1
|
+
# Left Toolbar Remote Commands
|
|
2
|
+
|
|
3
|
+
本文档说明如何在“工具条端与白板端隔离”的场景下,通过命令控制白板左侧工具能力。
|
|
4
|
+
|
|
5
|
+
## 适用场景
|
|
6
|
+
|
|
7
|
+
- 工具条和白板不在同一个组件中
|
|
8
|
+
- 通过 `WebSocket` / `postMessage` / 其他消息通道传 JSON
|
|
9
|
+
- 白板端收到命令后执行,不直接暴露 UI
|
|
10
|
+
|
|
11
|
+
## 白板端执行入口
|
|
12
|
+
|
|
13
|
+
白板端拿到 `excalidrawAPI` 后,统一调用:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
excalidrawAPI.leftToolbar.dispatch(command);
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
其中 `command` 的类型是 `LeftToolbarCommand`。
|
|
20
|
+
|
|
21
|
+
## Command 总览
|
|
22
|
+
|
|
23
|
+
| `type` | 作用 | `payload` |
|
|
24
|
+
| --- | --- | --- |
|
|
25
|
+
| `selectSelection` | 切换到“选择”工具 | 无 |
|
|
26
|
+
| `selectFreedraw` | 切换到“自由书写”工具 | 可选 |
|
|
27
|
+
| `selectLine` | 切换到“线条/箭头”工具组 | 可选 |
|
|
28
|
+
| `selectShape` | 切换到“形状”工具组 | 可选 |
|
|
29
|
+
| `selectText` | 切换到“文字”工具 | 可选 |
|
|
30
|
+
| `selectEraser` | 切换到“橡皮”工具 | 无 |
|
|
31
|
+
| `updateStyle` | 仅更新样式,不切换工具 | 必填 |
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 1) `selectSelection`
|
|
36
|
+
|
|
37
|
+
切换到选择工具。
|
|
38
|
+
|
|
39
|
+
```json
|
|
40
|
+
{ "type": "selectSelection" }
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
---
|
|
44
|
+
|
|
45
|
+
## 2) `selectFreedraw`
|
|
46
|
+
|
|
47
|
+
切换到自由书写工具(普通画笔/荧光笔)。
|
|
48
|
+
|
|
49
|
+
### payload 字段
|
|
50
|
+
|
|
51
|
+
| 字段 | 类型 | 必填 | 含义 |
|
|
52
|
+
| --- | --- | --- | --- |
|
|
53
|
+
| `variant` | `"pen" \| "highlighter"` | 否 | 画笔类型。`pen` 普通笔,`highlighter` 荧光笔(半透明) |
|
|
54
|
+
| `strokeWidth` | `number` | 否 | 线宽 |
|
|
55
|
+
| `strokeColor` | `string` | 否 | 笔颜色(如 `#1677ff`) |
|
|
56
|
+
|
|
57
|
+
### `variant` 取值对照(freedraw)
|
|
58
|
+
|
|
59
|
+
| 值 | 含义 |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| `pen` | 普通画笔(不透明) |
|
|
62
|
+
| `highlighter` | 荧光笔(半透明,适合标注) |
|
|
63
|
+
|
|
64
|
+
### 示例
|
|
65
|
+
|
|
66
|
+
```json
|
|
67
|
+
{
|
|
68
|
+
"type": "selectFreedraw",
|
|
69
|
+
"payload": {
|
|
70
|
+
"variant": "highlighter",
|
|
71
|
+
"strokeWidth": 6,
|
|
72
|
+
"strokeColor": "#ffcc00"
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
---
|
|
78
|
+
|
|
79
|
+
## 3) `selectLine`
|
|
80
|
+
|
|
81
|
+
切换到线条/箭头工具组,并可指定箭头类型。
|
|
82
|
+
|
|
83
|
+
### payload 字段
|
|
84
|
+
|
|
85
|
+
| 字段 | 类型 | 必填 | 含义 |
|
|
86
|
+
| --- | --- | --- | --- |
|
|
87
|
+
| `variant` | `"line" \| "arrow" \| "doubleArrow" \| "outlineArrow" \| "outlineDoubleArrow"` | 否 | 线条变体:直线、单箭头、双箭头、空心单箭头、空心双箭头 |
|
|
88
|
+
| `strokeWidth` | `number` | 否 | 线宽 |
|
|
89
|
+
| `strokeColor` | `string` | 否 | 线条颜色 |
|
|
90
|
+
|
|
91
|
+
### `variant` 取值对照(line)
|
|
92
|
+
|
|
93
|
+
| 值 | 含义 |
|
|
94
|
+
| --- | --- |
|
|
95
|
+
| `line` | 直线 |
|
|
96
|
+
| `arrow` | 实心单箭头 |
|
|
97
|
+
| `doubleArrow` | 实心双箭头 |
|
|
98
|
+
| `outlineArrow` | 空心单箭头 |
|
|
99
|
+
| `outlineDoubleArrow` | 空心双箭头 |
|
|
100
|
+
|
|
101
|
+
### 示例
|
|
102
|
+
|
|
103
|
+
```json
|
|
104
|
+
{
|
|
105
|
+
"type": "selectLine",
|
|
106
|
+
"payload": {
|
|
107
|
+
"variant": "outlineDoubleArrow",
|
|
108
|
+
"strokeWidth": 2,
|
|
109
|
+
"strokeColor": "#1677ff"
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
```
|
|
113
|
+
|
|
114
|
+
---
|
|
115
|
+
|
|
116
|
+
## 4) `selectShape`
|
|
117
|
+
|
|
118
|
+
切换到形状工具组,并可指定具体形状。
|
|
119
|
+
|
|
120
|
+
### payload 字段
|
|
121
|
+
|
|
122
|
+
| 字段 | 类型 | 必填 | 含义 |
|
|
123
|
+
| --- | --- | --- | --- |
|
|
124
|
+
| `shape` | `"rectangle" \| "diamond" \| "ellipse" \| "triangle" \| "pentagon" \| "callout" \| "hollow_arrow" \| "hollow_double_arrow"` | 否 | 具体形状。不传时默认矩形 |
|
|
125
|
+
| `strokeWidth` | `number` | 否 | 描边宽度 |
|
|
126
|
+
| `strokeColor` | `string` | 否 | 描边颜色 |
|
|
127
|
+
| `backgroundColor` | `string` | 否 | 填充背景色 |
|
|
128
|
+
| `fillStyle` | `AppState["currentItemFillStyle"]` | 否 | 填充样式(如 `solid` / `hachure` / `cross-hatch`) |
|
|
129
|
+
|
|
130
|
+
### `shape` 取值对照
|
|
131
|
+
|
|
132
|
+
| 值 | 对应图形 |
|
|
133
|
+
| --- | --- |
|
|
134
|
+
| `rectangle` | 矩形 |
|
|
135
|
+
| `diamond` | 菱形 |
|
|
136
|
+
| `ellipse` | 椭圆 |
|
|
137
|
+
| `triangle` | 三角形 |
|
|
138
|
+
| `pentagon` | 五边形 |
|
|
139
|
+
| `callout` | 标注框(气泡) |
|
|
140
|
+
| `hollow_arrow` | 空心单箭头形状 |
|
|
141
|
+
| `hollow_double_arrow` | 空心双箭头形状 |
|
|
142
|
+
|
|
143
|
+
### `fillStyle` 常见值对照
|
|
144
|
+
|
|
145
|
+
| 值 | 含义 |
|
|
146
|
+
| --- | --- |
|
|
147
|
+
| `hachure` | 斜线填充 |
|
|
148
|
+
| `cross-hatch` | 交叉线填充 |
|
|
149
|
+
| `solid` | 实心填充 |
|
|
150
|
+
|
|
151
|
+
### 示例
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"type": "selectShape",
|
|
156
|
+
"payload": {
|
|
157
|
+
"shape": "ellipse",
|
|
158
|
+
"strokeWidth": 3,
|
|
159
|
+
"strokeColor": "#1f1f1f",
|
|
160
|
+
"backgroundColor": "#E6F4FF",
|
|
161
|
+
"fillStyle": "solid"
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
```
|
|
165
|
+
|
|
166
|
+
---
|
|
167
|
+
|
|
168
|
+
## 5) `selectText`
|
|
169
|
+
|
|
170
|
+
切换到文字工具,并可设置文字默认样式。
|
|
171
|
+
|
|
172
|
+
### payload 字段
|
|
173
|
+
|
|
174
|
+
| 字段 | 类型 | 必填 | 含义 |
|
|
175
|
+
| --- | --- | --- | --- |
|
|
176
|
+
| `fontSize` | `number` | 否 | 字号 |
|
|
177
|
+
| `textAlign` | `"left" \| "center" \| "right"` | 否 | 对齐方式 |
|
|
178
|
+
| `strokeColor` | `string` | 否 | 文字颜色 |
|
|
179
|
+
| `bold` | `boolean` | 否 | 是否粗体 |
|
|
180
|
+
| `italic` | `boolean` | 否 | 是否斜体 |
|
|
181
|
+
| `underline` | `boolean` | 否 | 是否下划线 |
|
|
182
|
+
| `strikethrough` | `boolean` | 否 | 是否删除线 |
|
|
183
|
+
|
|
184
|
+
### `textAlign` 取值对照
|
|
185
|
+
|
|
186
|
+
| 值 | 含义 |
|
|
187
|
+
| --- | --- |
|
|
188
|
+
| `left` | 左对齐 |
|
|
189
|
+
| `center` | 居中对齐 |
|
|
190
|
+
| `right` | 右对齐 |
|
|
191
|
+
|
|
192
|
+
### 示例
|
|
193
|
+
|
|
194
|
+
```json
|
|
195
|
+
{
|
|
196
|
+
"type": "selectText",
|
|
197
|
+
"payload": {
|
|
198
|
+
"fontSize": 24,
|
|
199
|
+
"textAlign": "center",
|
|
200
|
+
"strokeColor": "#222222",
|
|
201
|
+
"bold": true
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
```
|
|
205
|
+
|
|
206
|
+
---
|
|
207
|
+
|
|
208
|
+
## 6) `selectEraser`
|
|
209
|
+
|
|
210
|
+
切换到橡皮工具。
|
|
211
|
+
|
|
212
|
+
```json
|
|
213
|
+
{ "type": "selectEraser" }
|
|
214
|
+
```
|
|
215
|
+
|
|
216
|
+
---
|
|
217
|
+
|
|
218
|
+
## 7) `updateStyle`
|
|
219
|
+
|
|
220
|
+
只更新样式,不切换当前工具。
|
|
221
|
+
|
|
222
|
+
### payload 字段(可选子集)
|
|
223
|
+
|
|
224
|
+
可以传递以下字段中的任意组合:
|
|
225
|
+
|
|
226
|
+
- `currentItemStrokeColor`
|
|
227
|
+
- `currentItemBackgroundColor`
|
|
228
|
+
- `currentItemFillStyle`
|
|
229
|
+
- `currentItemStrokeWidth`
|
|
230
|
+
- `currentItemOpacity`
|
|
231
|
+
- `currentItemStartArrowhead`
|
|
232
|
+
- `currentItemEndArrowhead`
|
|
233
|
+
- `currentItemFontSize`
|
|
234
|
+
- `currentItemTextAlign`
|
|
235
|
+
- `currentTextBold`
|
|
236
|
+
- `currentTextItalic`
|
|
237
|
+
- `currentTextUnderline`
|
|
238
|
+
- `currentTextStrikethrough`
|
|
239
|
+
|
|
240
|
+
### `updateStyle` 字段含义对照
|
|
241
|
+
|
|
242
|
+
| 字段 | 含义 |
|
|
243
|
+
| --- | --- |
|
|
244
|
+
| `currentItemStrokeColor` | 当前工具的描边颜色 |
|
|
245
|
+
| `currentItemBackgroundColor` | 当前工具的填充背景色 |
|
|
246
|
+
| `currentItemFillStyle` | 当前工具的填充样式 |
|
|
247
|
+
| `currentItemStrokeWidth` | 当前工具线宽 |
|
|
248
|
+
| `currentItemOpacity` | 当前工具透明度(0-100) |
|
|
249
|
+
| `currentItemStartArrowhead` | 箭头起点箭头样式 |
|
|
250
|
+
| `currentItemEndArrowhead` | 箭头终点箭头样式 |
|
|
251
|
+
| `currentItemFontSize` | 文字默认字号 |
|
|
252
|
+
| `currentItemTextAlign` | 文字默认对齐方式 |
|
|
253
|
+
| `currentTextBold` | 文字是否粗体 |
|
|
254
|
+
| `currentTextItalic` | 文字是否斜体 |
|
|
255
|
+
| `currentTextUnderline` | 文字是否下划线 |
|
|
256
|
+
| `currentTextStrikethrough` | 文字是否删除线 |
|
|
257
|
+
|
|
258
|
+
### 示例
|
|
259
|
+
|
|
260
|
+
```json
|
|
261
|
+
{
|
|
262
|
+
"type": "updateStyle",
|
|
263
|
+
"payload": {
|
|
264
|
+
"currentItemStrokeWidth": 4,
|
|
265
|
+
"currentItemStrokeColor": "#ff4d4f"
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
```
|
|
269
|
+
|
|
270
|
+
---
|
|
271
|
+
|
|
272
|
+
## 接入示例(白板端)
|
|
273
|
+
|
|
274
|
+
```ts
|
|
275
|
+
socket.on("toolbar-command", (command) => {
|
|
276
|
+
excalidrawAPI?.leftToolbar.dispatch(command);
|
|
277
|
+
});
|
|
278
|
+
```
|
|
279
|
+
|
|
280
|
+
## 完整命令 JSON 示例集合
|
|
281
|
+
|
|
282
|
+
以下示例可直接用于联调(通过 socket 发送):
|
|
283
|
+
|
|
284
|
+
### 1) 选择工具
|
|
285
|
+
|
|
286
|
+
```json
|
|
287
|
+
{ "type": "selectSelection" }
|
|
288
|
+
```
|
|
289
|
+
|
|
290
|
+
### 2) 自由书写(普通画笔)
|
|
291
|
+
|
|
292
|
+
```json
|
|
293
|
+
{
|
|
294
|
+
"type": "selectFreedraw",
|
|
295
|
+
"payload": {
|
|
296
|
+
"variant": "pen",
|
|
297
|
+
"strokeWidth": 2,
|
|
298
|
+
"strokeColor": "#1677ff"
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 3) 自由书写(荧光笔)
|
|
304
|
+
|
|
305
|
+
```json
|
|
306
|
+
{
|
|
307
|
+
"type": "selectFreedraw",
|
|
308
|
+
"payload": {
|
|
309
|
+
"variant": "highlighter",
|
|
310
|
+
"strokeWidth": 6,
|
|
311
|
+
"strokeColor": "#ffcc00"
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
### 4) 线条(空心双箭头)
|
|
317
|
+
|
|
318
|
+
```json
|
|
319
|
+
{
|
|
320
|
+
"type": "selectLine",
|
|
321
|
+
"payload": {
|
|
322
|
+
"variant": "outlineDoubleArrow",
|
|
323
|
+
"strokeWidth": 2,
|
|
324
|
+
"strokeColor": "#1f1f1f"
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
```
|
|
328
|
+
|
|
329
|
+
### 5) 形状(椭圆 + 实心填充)
|
|
330
|
+
|
|
331
|
+
```json
|
|
332
|
+
{
|
|
333
|
+
"type": "selectShape",
|
|
334
|
+
"payload": {
|
|
335
|
+
"shape": "ellipse",
|
|
336
|
+
"strokeWidth": 3,
|
|
337
|
+
"strokeColor": "#1f1f1f",
|
|
338
|
+
"backgroundColor": "#E6F4FF",
|
|
339
|
+
"fillStyle": "solid"
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
```
|
|
343
|
+
|
|
344
|
+
### 6) 文字(24号,居中,加粗)
|
|
345
|
+
|
|
346
|
+
```json
|
|
347
|
+
{
|
|
348
|
+
"type": "selectText",
|
|
349
|
+
"payload": {
|
|
350
|
+
"fontSize": 24,
|
|
351
|
+
"textAlign": "center",
|
|
352
|
+
"strokeColor": "#222222",
|
|
353
|
+
"bold": true
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
```
|
|
357
|
+
|
|
358
|
+
### 7) 橡皮
|
|
359
|
+
|
|
360
|
+
```json
|
|
361
|
+
{ "type": "selectEraser" }
|
|
362
|
+
```
|
|
363
|
+
|
|
364
|
+
### 8) 仅更新样式(不切工具)
|
|
365
|
+
|
|
366
|
+
```json
|
|
367
|
+
{
|
|
368
|
+
"type": "updateStyle",
|
|
369
|
+
"payload": {
|
|
370
|
+
"currentItemStrokeWidth": 4,
|
|
371
|
+
"currentItemStrokeColor": "#ff4d4f"
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
```
|
|
375
|
+
|
|
376
|
+
## 注意事项
|
|
377
|
+
|
|
378
|
+
- 命令建议使用 JSON 格式,便于跨端传输和记录日志
|
|
379
|
+
- 白板端建议做一次类型校验后再 `dispatch`
|
|
380
|
+
- 建议在“进入注释模式”时再接收命令,退出时解绑监听
|