canvas-drawing-editor 2.5.0 → 2.6.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/README.md CHANGED
@@ -40,6 +40,7 @@
40
40
  - 🖋️ **富文本** - 支持部分加粗、部分改色、部分斜体
41
41
  - 🎬 **Tween 动画** - 对象属性过渡动画(位置、大小、透明度等)
42
42
  - 📱 **移动端支持** - 单指拖拽、双指缩放/旋转、长按选择、响应式布局
43
+ - 📐 **形状库** - 注册自定义形状,支持带文字的组合形状,可搜索选择
43
44
 
44
45
  ### 📦 安装
45
46
 
@@ -196,6 +197,7 @@ export class AppModule { }
196
197
  | `layers` | boolean | true | 图层管理 |
197
198
  | `group` | boolean | true | 组合/解组 |
198
199
  | `align` | boolean | true | 对齐/分布 |
200
+ | `shapePanel` | boolean | true | 形状库面板 |
199
201
 
200
202
  #### 旧版属性(向后兼容)
201
203
 
@@ -455,6 +457,94 @@ document.addEventListener('animation-update', (e) => {
455
457
  }
456
458
  ```
457
459
 
460
+ ### 📐 形状库 API
461
+
462
+ 形状库功能允许你注册自定义形状,用户可以从形状面板中选择并添加到画布。
463
+
464
+ #### 注册形状
465
+
466
+ ```javascript
467
+ const editor = document.querySelector('canvas-drawing-editor');
468
+
469
+ // 注册单个或多个形状
470
+ editor.registerShapes([
471
+ {
472
+ id: 'btn-confirm',
473
+ name: '确认按钮',
474
+ type: 'roundedRect',
475
+ category: '按钮',
476
+ fillColor: '#22c55e',
477
+ fillMode: 'fill',
478
+ cornerRadius: 8,
479
+ width: 100,
480
+ height: 40,
481
+ text: '确认',
482
+ textColor: '#ffffff',
483
+ fontSize: 14,
484
+ fontWeight: 'bold'
485
+ },
486
+ {
487
+ id: 'flow-start',
488
+ name: '开始节点',
489
+ type: 'ellipse',
490
+ category: '流程图',
491
+ fillColor: '#dbeafe',
492
+ fillMode: 'both',
493
+ strokeColor: '#3b82f6',
494
+ strokeWidth: 2,
495
+ width: 100,
496
+ height: 60,
497
+ text: '开始',
498
+ textColor: '#1e40af'
499
+ }
500
+ ]);
501
+ ```
502
+
503
+ #### 形状配置属性
504
+
505
+ | 属性 | 类型 | 说明 |
506
+ |------|------|------|
507
+ | `id` | string | 形状唯一标识 |
508
+ | `name` | string | 形状名称(显示用) |
509
+ | `type` | string | 形状类型:`rectangle`, `circle`, `triangle`, `star`, `heart`, `diamond`, `polygon`, `ellipse`, `roundedRect`, `parallelogram`, `trapezoid`, `hexagon` |
510
+ | `category` | string | 分类名称(可选) |
511
+ | `fillColor` | string | 填充颜色 |
512
+ | `fillMode` | string | 填充模式:`stroke`, `fill`, `both` |
513
+ | `strokeColor` | string | 边框颜色 |
514
+ | `strokeWidth` | number | 边框宽度 |
515
+ | `width` | number | 默认宽度 |
516
+ | `height` | number | 默认高度 |
517
+ | `cornerRadius` | number | 圆角半径(圆角矩形) |
518
+ | `text` | string | 形状中心文字 |
519
+ | `textColor` | string | 文字颜色 |
520
+ | `fontSize` | number | 文字大小 |
521
+ | `fontWeight` | string | 文字粗细:`normal`, `bold` |
522
+ | `icon` | string | 自定义 SVG 图标(面板显示用) |
523
+
524
+ #### 监听形状添加事件
525
+
526
+ ```javascript
527
+ editor.addEventListener('shape-added', (e) => {
528
+ console.log('形状已添加:', e.detail.shape.name);
529
+ console.log('创建的对象:', e.detail.object);
530
+ });
531
+ ```
532
+
533
+ #### 工具配置
534
+
535
+ 通过 `tool-config` 或 `show-shape-panel` 属性控制形状库按钮显示:
536
+
537
+ ```html
538
+ <canvas-drawing-editor
539
+ tool-config='{"shapePanel": true}'
540
+ ></canvas-drawing-editor>
541
+
542
+ <!-- 或使用单独属性 -->
543
+ <canvas-drawing-editor
544
+ show-shape-panel="true"
545
+ ></canvas-drawing-editor>
546
+ ```
547
+
458
548
  ### 🎬 Tween 动画 API
459
549
 
460
550
  通过 `tweenAnimate()` 方法可以为对象创建平滑的属性过渡动画:
@@ -528,6 +618,7 @@ A powerful canvas-based drawing editor Web Component with **zero dependencies**.
528
618
  - 🖋️ **Rich Text** - Support partial bold, partial color, partial italic
529
619
  - 🎬 **Tween Animation** - Object property transition animations (position, size, opacity, etc.)
530
620
  - 📱 **Mobile Support** - Single finger drag, two-finger zoom/rotate, long press selection, responsive layout
621
+ - 📐 **Shape Library** - Register custom shapes with text, searchable panel for quick selection
531
622
 
532
623
  ### 📦 Installation
533
624
 
@@ -684,6 +775,7 @@ Recommended: Use `tool-config` attribute for unified tool configuration:
684
775
  | `layers` | boolean | true | Layer management |
685
776
  | `group` | boolean | true | Group/Ungroup |
686
777
  | `align` | boolean | true | Align/Distribute |
778
+ | `shapePanel` | boolean | true | Shape library panel |
687
779
 
688
780
  #### Legacy Attributes (Backward Compatible)
689
781
 
@@ -916,6 +1008,94 @@ Steps:
916
1008
  }
917
1009
  ```
918
1010
 
1011
+ ### 📐 Shape Library API
1012
+
1013
+ The Shape Library feature allows you to register custom shapes that users can select from a panel and add to the canvas.
1014
+
1015
+ #### Register Shapes
1016
+
1017
+ ```javascript
1018
+ const editor = document.querySelector('canvas-drawing-editor');
1019
+
1020
+ // Register one or more shapes
1021
+ editor.registerShapes([
1022
+ {
1023
+ id: 'btn-confirm',
1024
+ name: 'Confirm Button',
1025
+ type: 'roundedRect',
1026
+ category: 'Buttons',
1027
+ fillColor: '#22c55e',
1028
+ fillMode: 'fill',
1029
+ cornerRadius: 8,
1030
+ width: 100,
1031
+ height: 40,
1032
+ text: 'Confirm',
1033
+ textColor: '#ffffff',
1034
+ fontSize: 14,
1035
+ fontWeight: 'bold'
1036
+ },
1037
+ {
1038
+ id: 'flow-start',
1039
+ name: 'Start Node',
1040
+ type: 'ellipse',
1041
+ category: 'Flowchart',
1042
+ fillColor: '#dbeafe',
1043
+ fillMode: 'both',
1044
+ strokeColor: '#3b82f6',
1045
+ strokeWidth: 2,
1046
+ width: 100,
1047
+ height: 60,
1048
+ text: 'Start',
1049
+ textColor: '#1e40af'
1050
+ }
1051
+ ]);
1052
+ ```
1053
+
1054
+ #### Shape Configuration Properties
1055
+
1056
+ | Property | Type | Description |
1057
+ |----------|------|-------------|
1058
+ | `id` | string | Unique shape identifier |
1059
+ | `name` | string | Shape name (for display) |
1060
+ | `type` | string | Shape type: `rectangle`, `circle`, `triangle`, `star`, `heart`, `diamond`, `polygon`, `ellipse`, `roundedRect`, `parallelogram`, `trapezoid`, `hexagon` |
1061
+ | `category` | string | Category name (optional) |
1062
+ | `fillColor` | string | Fill color |
1063
+ | `fillMode` | string | Fill mode: `stroke`, `fill`, `both` |
1064
+ | `strokeColor` | string | Stroke color |
1065
+ | `strokeWidth` | number | Stroke width |
1066
+ | `width` | number | Default width |
1067
+ | `height` | number | Default height |
1068
+ | `cornerRadius` | number | Corner radius (for rounded rectangles) |
1069
+ | `text` | string | Center text content |
1070
+ | `textColor` | string | Text color |
1071
+ | `fontSize` | number | Font size |
1072
+ | `fontWeight` | string | Font weight: `normal`, `bold` |
1073
+ | `icon` | string | Custom SVG icon (for panel display) |
1074
+
1075
+ #### Listen for Shape Added Event
1076
+
1077
+ ```javascript
1078
+ editor.addEventListener('shape-added', (e) => {
1079
+ console.log('Shape added:', e.detail.shape.name);
1080
+ console.log('Created object:', e.detail.object);
1081
+ });
1082
+ ```
1083
+
1084
+ #### Tool Configuration
1085
+
1086
+ Control shape library button visibility via `tool-config` or `show-shape-panel` attribute:
1087
+
1088
+ ```html
1089
+ <canvas-drawing-editor
1090
+ tool-config='{"shapePanel": true}'
1091
+ ></canvas-drawing-editor>
1092
+
1093
+ <!-- Or use individual attribute -->
1094
+ <canvas-drawing-editor
1095
+ show-shape-panel="true"
1096
+ ></canvas-drawing-editor>
1097
+ ```
1098
+
919
1099
  ### 🎬 Tween Animation API
920
1100
 
921
1101
  Use `tweenAnimate()` method to create smooth property transition animations: