drawui-core 0.1.0 → 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.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 drawui contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,56 @@
1
+ # drawui-core
2
+
3
+ 框架无关的核心画布绘图引擎(原生 TypeScript,无 UI 框架依赖)。
4
+
5
+ 配套 React 封装见 [`drawui-react`](../react)。
6
+
7
+ ## 安装
8
+
9
+ ```bash
10
+ npm install drawui-core
11
+ ```
12
+
13
+ ## 用法
14
+
15
+ ```ts
16
+ import { Editor } from 'drawui-core'
17
+
18
+ const canvas = document.getElementById('board') as HTMLCanvasElement
19
+ const editor = new Editor(canvas, { language: 'zh-CN' })
20
+
21
+ editor.subscribe(() => console.log('changed'))
22
+ editor.setShapes([
23
+ {
24
+ id: 'r1',
25
+ type: 'rectangle',
26
+ x: 80, y: 80, width: 160, height: 90, rotation: 0,
27
+ text: 'Hello',
28
+ style: { strokeColor: '#3b82f6', fillColor: '#eff6ff', strokeWidth: 2, strokeDash: null },
29
+ },
30
+ ])
31
+ ```
32
+
33
+ ## 主要导出
34
+
35
+ - `Editor`(`new Editor(canvas, options?)`)、`EditorOptions`、`UiEvent`
36
+ - 工具类:`SelectTool`、`HandTool`、`ShapeTool`、`LineTool`、`FreehandTool`、`ArrowTool`
37
+ - 几何:`Vec`、`Mat2d`、`Camera`、`Renderer`
38
+ - 主题:`THEME`、`getTheme`、`setTheme`、`subscribeTheme`、`hexToRgba`、`shadeColor`
39
+ - 国际化:`setLanguage`、`getLanguage`、`subscribeLanguage`、`t`
40
+ - 思维导图:`layoutMindMap`、`mindMapNodeColor`、`mindMapNodeSize` 等
41
+ - 类型:`Shape`、`ShapeType`、`EditorData`、`ToolType`、`MindMapNode` 等
42
+
43
+ ## 构造选项
44
+
45
+ ```ts
46
+ interface EditorOptions {
47
+ theme?: Partial<DrawuiTheme>
48
+ language?: 'zh-CN' | 'en-US'
49
+ shapes?: Shape[]
50
+ persist?: boolean // 是否写入 localStorage,默认 true(提供 shapes 时自动关闭)
51
+ }
52
+ ```
53
+
54
+ ## License
55
+
56
+ MIT