foliko 1.1.7 → 1.1.9

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.
Files changed (113) hide show
  1. package/.agent/agents/poster-expert.md +228 -0
  2. package/.agent/data/default.json +10 -0
  3. package/.agent/data/plugins-state.json +1 -1
  4. package/.agent/mcp_config.json +0 -6
  5. package/.agent/plugins/test-plugin.py +15 -0
  6. package/.agent/plugins/test_nested_plugin.py +85 -0
  7. package/.agent/sessions/cli_default.json +83 -803
  8. package/.agent/sessions/weixin_o9cq80zgZqKPA2-s59PN43GdDy1w@im.wechat.json +189 -0
  9. package/.claude/settings.local.json +8 -1
  10. package/cli/src/ui/chat-ui.js +32 -21
  11. package/foliko_poster.png +0 -0
  12. package/output/business_poster_final.png +0 -0
  13. package/output/emoji_test_v2.png +0 -0
  14. package/output/foliko-ai-launch-poster.png +0 -0
  15. package/output/foliko-poster.png +0 -0
  16. package/output/muji_style_poster.png +0 -0
  17. package/output/new_product_launch.png +0 -0
  18. package/output/news_poster_625yi_subsidy.png +0 -0
  19. package/output/tech_future_2026.png +0 -0
  20. package/output/tech_future_poster.png +0 -0
  21. package/package.json +2 -2
  22. package/plugins/default-plugins.js +60 -7
  23. package/plugins/extension-executor-plugin.js +32 -22
  24. package/plugins/feishu-plugin.js +2 -2
  25. package/plugins/python-plugin-loader.js +461 -40
  26. package/plugins/python-plugin-loader.js.bak +856 -0
  27. package/plugins/subagent-plugin.js +0 -121
  28. package/plugins/telegram-plugin.js +2 -2
  29. package/plugins/weixin-plugin.js +40 -31
  30. package/poster.png +0 -0
  31. package/skills/foliko-dev/SKILL.md +6 -0
  32. package/skills/python-plugin-dev/SKILL.md +124 -2
  33. package/src/core/agent-chat.js +220 -281
  34. package/src/core/agent.js +127 -29
  35. package/src/executors/mcp-executor.js +282 -26
  36. package/src/utils/plugin-helpers.js +22 -4
  37. package/system.md +362 -109
  38. package/test-scan.js +18 -0
  39. package/.agent/memory/feedback/mnt7jrlt-d67qs7.md +0 -15
  40. package/.agent/memory/feedback/mnt88ja3-al4fuy.md +0 -9
  41. package/.agent/plugins/poster-plugin/README.md +0 -304
  42. package/.agent/plugins/poster-plugin/emojis/rocket.png +0 -1
  43. package/.agent/plugins/poster-plugin/fonts/PatuaOne-Regular.ttf +0 -0
  44. package/.agent/plugins/poster-plugin/fonts/SegoeUI Emoji.ttf +0 -0
  45. package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221.ttf +0 -0
  46. package/.agent/plugins/poster-plugin/fonts//345/276/256/350/275/257/351/233/205/351/273/221/347/262/227/344/275/223.ttf +0 -0
  47. package/.agent/plugins/poster-plugin/index.js +0 -13
  48. package/.agent/plugins/poster-plugin/package.json +0 -29
  49. package/.agent/plugins/poster-plugin/src/canvas.js +0 -224
  50. package/.agent/plugins/poster-plugin/src/components/arrow.js +0 -84
  51. package/.agent/plugins/poster-plugin/src/components/avatar.js +0 -71
  52. package/.agent/plugins/poster-plugin/src/components/badge.js +0 -85
  53. package/.agent/plugins/poster-plugin/src/components/barcode.js +0 -120
  54. package/.agent/plugins/poster-plugin/src/components/bubble.js +0 -153
  55. package/.agent/plugins/poster-plugin/src/components/button.js +0 -124
  56. package/.agent/plugins/poster-plugin/src/components/card.js +0 -88
  57. package/.agent/plugins/poster-plugin/src/components/chart.js +0 -127
  58. package/.agent/plugins/poster-plugin/src/components/chip.js +0 -88
  59. package/.agent/plugins/poster-plugin/src/components/columns.js +0 -107
  60. package/.agent/plugins/poster-plugin/src/components/cta.js +0 -87
  61. package/.agent/plugins/poster-plugin/src/components/divider.js +0 -55
  62. package/.agent/plugins/poster-plugin/src/components/feature.js +0 -85
  63. package/.agent/plugins/poster-plugin/src/components/featureGrid.js +0 -117
  64. package/.agent/plugins/poster-plugin/src/components/frame.js +0 -230
  65. package/.agent/plugins/poster-plugin/src/components/grid.js +0 -118
  66. package/.agent/plugins/poster-plugin/src/components/highlightText.js +0 -144
  67. package/.agent/plugins/poster-plugin/src/components/icon.js +0 -94
  68. package/.agent/plugins/poster-plugin/src/components/imageFrame.js +0 -155
  69. package/.agent/plugins/poster-plugin/src/components/index.js +0 -81
  70. package/.agent/plugins/poster-plugin/src/components/listItem.js +0 -147
  71. package/.agent/plugins/poster-plugin/src/components/notification.js +0 -123
  72. package/.agent/plugins/poster-plugin/src/components/progress.js +0 -79
  73. package/.agent/plugins/poster-plugin/src/components/progressCircle.js +0 -117
  74. package/.agent/plugins/poster-plugin/src/components/qrcode.js +0 -74
  75. package/.agent/plugins/poster-plugin/src/components/quote.js +0 -97
  76. package/.agent/plugins/poster-plugin/src/components/rating.js +0 -85
  77. package/.agent/plugins/poster-plugin/src/components/ribbon.js +0 -193
  78. package/.agent/plugins/poster-plugin/src/components/seal.js +0 -146
  79. package/.agent/plugins/poster-plugin/src/components/star.js +0 -70
  80. package/.agent/plugins/poster-plugin/src/components/statCard.js +0 -105
  81. package/.agent/plugins/poster-plugin/src/components/stepper.js +0 -118
  82. package/.agent/plugins/poster-plugin/src/components/table.js +0 -167
  83. package/.agent/plugins/poster-plugin/src/components/tagCloud.js +0 -85
  84. package/.agent/plugins/poster-plugin/src/components/timeline.js +0 -117
  85. package/.agent/plugins/poster-plugin/src/components/watermark.js +0 -52
  86. package/.agent/plugins/poster-plugin/src/composer.js +0 -2146
  87. package/.agent/plugins/poster-plugin/src/elements/artText.js +0 -60
  88. package/.agent/plugins/poster-plugin/src/elements/background.js +0 -84
  89. package/.agent/plugins/poster-plugin/src/elements/circle.js +0 -31
  90. package/.agent/plugins/poster-plugin/src/elements/image.js +0 -28
  91. package/.agent/plugins/poster-plugin/src/elements/index.js +0 -28
  92. package/.agent/plugins/poster-plugin/src/elements/line.js +0 -23
  93. package/.agent/plugins/poster-plugin/src/elements/polygon.js +0 -63
  94. package/.agent/plugins/poster-plugin/src/elements/rectangle.js +0 -32
  95. package/.agent/plugins/poster-plugin/src/elements/richText.js +0 -230
  96. package/.agent/plugins/poster-plugin/src/elements/svg.js +0 -108
  97. package/.agent/plugins/poster-plugin/src/elements/text.js +0 -109
  98. package/.agent/plugins/poster-plugin/src/fonts.js +0 -243
  99. package/.agent/plugins/poster-plugin/src/index.js +0 -2081
  100. package/.agent/plugins/poster-plugin/src/presets.js +0 -36
  101. package/.agent/plugins/poster-plugin/src/templates/business.js +0 -60
  102. package/.agent/plugins/poster-plugin/src/templates/gradient.js +0 -64
  103. package/.agent/plugins/poster-plugin/src/templates/index.js +0 -43
  104. package/.agent/plugins/poster-plugin/src/templates/modern.js +0 -69
  105. package/.agent/plugins/poster-plugin/src/templates/simple.js +0 -58
  106. package/.agent/plugins/poster-plugin/src/templates/social.js +0 -62
  107. package/.agent/plugins/poster-plugin/src/templates/tech.js +0 -84
  108. package/.agent/plugins/poster-plugin/src/utils/imageLoader.js +0 -84
  109. package/.agent/plugins/poster-plugin/test-background.svg +0 -1
  110. package/.agent/plugins/poster-plugin/test-full-poster.svg +0 -2
  111. package/.agent/plugins/poster-plugin/test-image.png +0 -0
  112. package/.agent/plugins/poster-plugin/yarn.lock +0 -1007
  113. package/output/zen_silence.png +0 -0
@@ -1,2081 +0,0 @@
1
- /**
2
- * Poster Plugin - 海报制作插件 (重构版)
3
- *
4
- * 模块化架构,支持组件化海报生成
5
- */
6
-
7
- const { z } = require('zod')
8
- const path = require('path')
9
- const fs = require('fs')
10
-
11
- // 导入模块
12
- const PRESETS = require('./presets')
13
- const CanvasManager = require('./canvas')
14
- const { createFromConfig, COMPONENT_TYPES } = require('./composer')
15
- const { applyTemplate, getAvailableTemplates } = require('./templates')
16
- const {
17
- addRectangle,
18
- addCircle,
19
- addLine,
20
- addPolygon,
21
- addImage,
22
- addText,
23
- addArtText,
24
- addRichText,
25
- addBackground,
26
- addSVG,
27
- } = require('./elements')
28
- const {
29
- createCard,
30
- createBadge,
31
- createCTA,
32
- createFeature,
33
- createFeatureGrid,
34
- createDivider,
35
- createAvatar,
36
- createProgress,
37
- createRating,
38
- createQuote,
39
- createStatCard,
40
- createTagCloud,
41
- createStepper,
42
- createTimeline,
43
- createListItem,
44
- createNotification,
45
- createImageFrame,
46
- createColumns,
47
- createGrid,
48
- createStar,
49
- createArrow,
50
- createProgressCircle,
51
- createChip,
52
- createChart,
53
- createWatermark,
54
- createTable,
55
- createButton,
56
- createIcon,
57
- createQRCode,
58
- createFrame,
59
- createBubble,
60
- createRibbon,
61
- createSeal,
62
- createHighlightText,
63
- createBarcode,
64
- } = require('./components')
65
-
66
- module.exports = function (Plugin) {
67
- return class PosterPlugin extends Plugin {
68
- constructor(config = {}) {
69
- super()
70
- this.name = 'poster'
71
- this.version = '1.1.0'
72
- this.description = '海报制作插件 - 支持组件化海报生成'
73
- this.priority = 15
74
-
75
- this._framework = null
76
- this._canvasManager = new CanvasManager()
77
- }
78
-
79
-
80
-
81
- // ==================== 工具定义 ====================
82
-
83
- tools = {
84
- // ==================== 画布管理 ====================
85
-
86
- /**
87
- * 列出预设尺寸
88
- */
89
- list_poster_presets: {
90
- description: '列出所有可用的海报/Banner预设尺寸',
91
- inputSchema: z.object({}),
92
- execute: async () => ({
93
- success: true,
94
- presets: Object.entries(PRESETS).map(([key, value]) => ({ key, ...value })),
95
- }),
96
- },
97
-
98
- /**
99
- * 创建画布
100
- */
101
- create_poster_canvas: {
102
- description: '创建新画布,支持预设尺寸或自定义尺寸',
103
- inputSchema: z.object({
104
- preset: z.string().optional().describe('预设尺寸key'),
105
- width: z.number().optional().describe('自定义宽度'),
106
- height: z.number().optional().describe('自定义高度'),
107
- background: z.union([z.string(), z.object({
108
- image: z.string()
109
- })]).optional().describe('背景颜色或图片路径'),
110
- }),
111
- execute: async (args) => {
112
- try {
113
- const result = await this._canvasManager.create(args)
114
- return { success: true, ...result }
115
- } catch (err) {
116
- return { success: false, error: err.message }
117
- }
118
- },
119
- },
120
-
121
- /**
122
- * 获取画布信息
123
- */
124
- get_poster_canvas_info: {
125
- description: '获取当前画布信息',
126
- inputSchema: z.object({}),
127
- execute: async () => {
128
- if (!this._canvasManager.isCreated()) {
129
- return { success: false, error: 'No canvas created' }
130
- }
131
- const size = this._canvasManager.getSize()
132
- return {
133
- success: true,
134
- ...size,
135
- elementCount: this._canvasManager.getElementCount(),
136
- }
137
- },
138
- },
139
-
140
- /**
141
- * 清除画布
142
- */
143
- clear_poster_canvas: {
144
- description: '清除画布上的所有元素',
145
- inputSchema: z.object({}),
146
- execute: async () => {
147
- if (!this._canvasManager.isCreated()) {
148
- return { success: false, error: 'No canvas created' }
149
- }
150
- this._canvasManager.clear()
151
- return { success: true, message: 'Canvas cleared' }
152
- },
153
- },
154
-
155
- // ==================== 基础元素 ====================
156
-
157
- /**
158
- * 添加背景
159
- */
160
- add_poster_background: {
161
- description: '为画布添加纯色、渐变或图片背景',
162
- inputSchema: z.object({
163
- color: z.string().optional().describe('纯色背景'),
164
- gradient: z.object({
165
- type: z.enum(['linear', 'radial']).describe('渐变类型'),
166
- colors: z.array(z.string()).describe('颜色数组'),
167
- direction: z.number().optional().describe('方向角度,默认45'),
168
- }).optional(),
169
- image: z.string().optional().describe('背景图片路径(本地路径或URL)'),
170
- }),
171
- execute: async (args) => {
172
- try {
173
- if (!this._canvasManager.isCreated()) {
174
- return { success: false, error: 'No canvas created' }
175
- }
176
- return await addBackground(
177
- this._canvasManager.getProject(),
178
- this._canvasManager.getCanvas(),
179
- args
180
- )
181
- } catch (err) {
182
- return { success: false, error: err.message }
183
- }
184
- },
185
- },
186
-
187
- /**
188
- * 添加矩形
189
- */
190
- add_poster_rectangle: {
191
- description: '在画布上添加矩形',
192
- inputSchema: z.object({
193
- x: z.number().describe('X坐标'),
194
- y: z.number().describe('Y坐标'),
195
- width: z.number().describe('宽度'),
196
- height: z.number().describe('高度'),
197
- fill: z.string().optional().describe('填充颜色'),
198
- stroke: z.string().optional().describe('边框颜色'),
199
- strokeWidth: z.number().optional().describe('边框宽度'),
200
- radius: z.number().optional().describe('圆角半径'),
201
- opacity: z.number().optional().describe('透明度 0-1'),
202
- }),
203
- execute: async (args) => {
204
- try {
205
- if (!this._canvasManager.isCreated()) {
206
- return { success: false, error: 'No canvas created' }
207
- }
208
- return addRectangle(this._canvasManager.getProject(), args)
209
- } catch (err) {
210
- return { success: false, error: err.message }
211
- }
212
- },
213
- },
214
-
215
- /**
216
- * 添加圆形
217
- */
218
- add_poster_circle: {
219
- description: '在画布上添加圆形或椭圆',
220
- inputSchema: z.object({
221
- cx: z.number().describe('圆心X坐标'),
222
- cy: z.number().describe('圆心Y坐标'),
223
- rx: z.number().describe('X轴半径'),
224
- ry: z.number().optional().describe('Y轴半径'),
225
- fill: z.string().optional().describe('填充颜色'),
226
- stroke: z.string().optional().describe('边框颜色'),
227
- strokeWidth: z.number().optional().describe('边框宽度'),
228
- opacity: z.number().optional().describe('透明度 0-1'),
229
- }),
230
- execute: async (args) => {
231
- try {
232
- if (!this._canvasManager.isCreated()) {
233
- return { success: false, error: 'No canvas created' }
234
- }
235
- return addCircle(this._canvasManager.getProject(), args)
236
- } catch (err) {
237
- return { success: false, error: err.message }
238
- }
239
- },
240
- },
241
-
242
- /**
243
- * 添加线条
244
- */
245
- add_poster_line: {
246
- description: '在画布上添加线条',
247
- inputSchema: z.object({
248
- x1: z.number().describe('起点X'),
249
- y1: z.number().describe('起点Y'),
250
- x2: z.number().describe('终点X'),
251
- y2: z.number().describe('终点Y'),
252
- stroke: z.string().optional().describe('线条颜色'),
253
- strokeWidth: z.number().optional().describe('线条宽度'),
254
- }),
255
- execute: async (args) => {
256
- try {
257
- if (!this._canvasManager.isCreated()) {
258
- return { success: false, error: 'No canvas created' }
259
- }
260
- return addLine(this._canvasManager.getProject(), args)
261
- } catch (err) {
262
- return { success: false, error: err.message }
263
- }
264
- },
265
- },
266
-
267
- /**
268
- * 添加多边形
269
- */
270
- add_poster_polygon: {
271
- description: '在画布上添加多边形',
272
- inputSchema: z.object({
273
- cx: z.number().describe('中心X坐标'),
274
- cy: z.number().describe('中心Y坐标'),
275
- radius: z.number().describe('外接圆半径'),
276
- sides: z.number().describe('边数'),
277
- fill: z.string().optional().describe('填充颜色'),
278
- stroke: z.string().optional().describe('边框颜色'),
279
- strokeWidth: z.number().optional().describe('边框宽度'),
280
- opacity: z.number().optional().describe('透明度 0-1'),
281
- }),
282
- execute: async (args) => {
283
- try {
284
- if (!this._canvasManager.isCreated()) {
285
- return { success: false, error: 'No canvas created' }
286
- }
287
- return addPolygon(this._canvasManager.getProject(), args)
288
- } catch (err) {
289
- return { success: false, error: err.message }
290
- }
291
- },
292
- },
293
-
294
- /**
295
- * 添加文字
296
- */
297
- add_poster_text: {
298
- description: '在画布上添加文字',
299
- inputSchema: z.object({
300
- text: z.string().describe('文字内容'),
301
- x: z.number().describe('X坐标'),
302
- y: z.number().describe('Y坐标'),
303
- fontSize: z.number().optional().describe('字体大小,默认48'),
304
- fontFamily: z.string().optional().describe('字体名称'),
305
- color: z.string().optional().describe('文字颜色'),
306
- align: z.enum(['left', 'center', 'right']).optional().describe('对齐方式'),
307
- shadow: z.object({
308
- color: z.string().describe('阴影颜色'),
309
- blur: z.number().optional(),
310
- offsetX: z.number().optional(),
311
- offsetY: z.number().optional(),
312
- }).optional(),
313
- }),
314
- execute: async (args) => {
315
- try {
316
- if (!this._canvasManager.isCreated()) {
317
- return { success: false, error: 'No canvas created' }
318
- }
319
- return addText(this._canvasManager.getProject(), args)
320
- } catch (err) {
321
- return { success: false, error: err.message }
322
- }
323
- },
324
- },
325
-
326
- /**
327
- * 添加艺术文字
328
- */
329
- add_poster_art_text: {
330
- description: '添加艺术文字,支持渐变填充和描边',
331
- inputSchema: z.object({
332
- text: z.string().describe('文字内容'),
333
- x: z.number().describe('X坐标'),
334
- y: z.number().describe('Y坐标'),
335
- fontSize: z.number().optional().describe('字体大小,默认120'),
336
- fontFamily: z.string().optional().describe('字体名称'),
337
- gradient: z.object({
338
- colors: z.array(z.string()).describe('渐变颜色数组'),
339
- direction: z.number().optional().describe('方向角度'),
340
- }).optional(),
341
- strokeColor: z.string().optional().describe('描边颜色'),
342
- strokeWidth: z.number().optional().describe('描边宽度'),
343
- shadow: z.object({
344
- color: z.string().describe('阴影颜色'),
345
- blur: z.number().optional(),
346
- offsetX: z.number().optional(),
347
- offsetY: z.number().optional(),
348
- }).optional(),
349
- }),
350
- execute: async (args) => {
351
- try {
352
- if (!this._canvasManager.isCreated()) {
353
- return { success: false, error: 'No canvas created' }
354
- }
355
- return addArtText(this._canvasManager.getProject(), args)
356
- } catch (err) {
357
- return { success: false, error: err.message }
358
- }
359
- },
360
- },
361
-
362
- /**
363
- * 添加富文本(支持旋转和多种样式)
364
- */
365
- add_poster_rich_text: {
366
- description: '添加富文本,支持旋转、描边、渐变、阴影等多种样式',
367
- inputSchema: z.object({
368
- // 位置和尺寸
369
- x: z.number().describe('X坐标'),
370
- y: z.number().describe('Y坐标'),
371
- width: z.number().optional().describe('文本区域宽度(用于自动换行)'),
372
-
373
- // 文本内容
374
- text: z.string().describe('文字内容'),
375
-
376
- // 字体样式
377
- fontSize: z.number().optional().describe('字体大小,默认48'),
378
- fontFamily: z.string().optional().describe('字体名称'),
379
- fontWeight: z.union([z.string(), z.number()]).optional().describe('字重 normal/bold 或 100-900'),
380
- fontStyle: z.enum(['normal', 'italic', 'oblique']).optional().describe('字体风格'),
381
- bold: z.boolean().optional().describe('粗体'),
382
- italic: z.boolean().optional().describe('斜体'),
383
-
384
- // 文字装饰
385
- underline: z.boolean().optional().describe('下划线'),
386
- strikethrough: z.boolean().optional().describe('删除线'),
387
-
388
- // 颜色
389
- color: z.string().optional().describe('文字颜色,默认#ffffff'),
390
- backgroundColor: z.string().optional().describe('文字背景色'),
391
- gradient: z.object({
392
- colors: z.array(z.string()).describe('渐变颜色数组'),
393
- direction: z.number().optional().describe('方向角度'),
394
- }).optional().describe('渐变填充'),
395
-
396
- // 描边
397
- strokeColor: z.string().optional().describe('描边颜色'),
398
- strokeWidth: z.number().optional().describe('描边宽度'),
399
-
400
- // 阴影
401
- shadow: z.object({
402
- color: z.string().optional().describe('阴影颜色'),
403
- blur: z.number().optional().describe('模糊度'),
404
- offsetX: z.number().optional().describe('X偏移'),
405
- offsetY: z.number().optional().describe('Y偏移'),
406
- }).optional(),
407
-
408
- // 间距
409
- letterSpacing: z.number().optional().describe('字间距'),
410
- lineSpacing: z.number().optional().describe('行间距增量'),
411
- lineHeight: z.number().optional().describe('行高'),
412
-
413
- // 对齐
414
- align: z.enum(['left', 'center', 'right', 'justify']).optional().describe('对齐方式'),
415
-
416
- // 变换
417
- rotation: z.number().optional().describe('旋转角度(度)'),
418
- scale: z.union([z.number(), z.object({
419
- x: z.number().optional(),
420
- y: z.number().optional()
421
- })]).optional().describe('缩放'),
422
-
423
- // 透明度
424
- opacity: z.number().optional().describe('透明度 0-1,默认1'),
425
- }),
426
- execute: async (args) => {
427
- try {
428
- if (!this._canvasManager.isCreated()) {
429
- return { success: false, error: 'No canvas created' }
430
- }
431
- return addRichText(this._canvasManager.getProject(), args)
432
- } catch (err) {
433
- return { success: false, error: err.message }
434
- }
435
- },
436
- },
437
-
438
- /**
439
- * 添加图片
440
- */
441
- add_poster_image: {
442
- description: '在画布上添加图片',
443
- inputSchema: z.object({
444
- src: z.string().describe('图片路径或URL'),
445
- x: z.number().describe('X坐标'),
446
- y: z.number().describe('Y坐标'),
447
- width: z.number().optional().describe('图片宽度'),
448
- height: z.number().optional().describe('图片高度'),
449
- opacity: z.number().optional().describe('透明度 0-1'),
450
- }),
451
- execute: async (args) => {
452
- try {
453
- if (!this._canvasManager.isCreated()) {
454
- return { success: false, error: 'No canvas created' }
455
- }
456
- return await addImage(this._canvasManager.getProject(), args)
457
- } catch (err) {
458
- return { success: false, error: err.message }
459
- }
460
- },
461
- },
462
-
463
- // ==================== SVG 支持 ====================
464
-
465
- /**
466
- * 导入 SVG 文件或内容
467
- */
468
- add_poster_svg: {
469
- description: '在画布上添加 SVG(支持文件路径或 SVG 字符串)',
470
- inputSchema: z.object({
471
- src: z.string().describe('SVG 文件路径或 SVG 字符串'),
472
- x: z.number().describe('X坐标'),
473
- y: z.number().describe('Y坐标'),
474
- width: z.number().optional().describe('宽度'),
475
- height: z.number().optional().describe('高度'),
476
- opacity: z.number().optional().describe('透明度 0-1'),
477
- }),
478
- execute: async (args) => {
479
- try {
480
- if (!this._canvasManager.isCreated()) {
481
- return { success: false, error: 'No canvas created' }
482
- }
483
- return addSVG(this._canvasManager.getProject(), args)
484
- } catch (err) {
485
- return { success: false, error: err.message }
486
- }
487
- },
488
- },
489
-
490
- /**
491
- * 导出为 SVG 格式
492
- */
493
- export_poster_svg: {
494
- description: '导出画布为 SVG 格式',
495
- inputSchema: z.object({
496
- filename: z.string().describe('文件名(不含扩展名)'),
497
- outputDir: z.string().optional().describe('输出目录'),
498
- }),
499
- execute: async (args) => {
500
- try {
501
- if (!this._canvasManager.isCreated()) {
502
- return { success: false, error: 'No canvas created' }
503
- }
504
-
505
- const outputDir = args.outputDir || '.'
506
- const filename = `${args.filename}.svg`
507
- await fs.promises.mkdir(outputDir, { recursive: true })
508
- const filepath = path.join(outputDir, filename)
509
-
510
- const svg = this._canvasManager.getProject().exportSVG({
511
- asString: true,
512
- bounds: 'content',
513
- })
514
-
515
- await fs.promises.writeFile(filepath, svg)
516
-
517
- return {
518
- success: true,
519
- filepath,
520
- filename,
521
- format: 'svg',
522
- size: Buffer.byteLength(svg),
523
- }
524
- } catch (err) {
525
- return { success: false, error: err.message }
526
- }
527
- },
528
- },
529
-
530
- /**
531
- * 导出为 SVG Base64
532
- */
533
- export_poster_svg_base64: {
534
- description: '导出画布为 SVG Base64 编码',
535
- inputSchema: z.object({}),
536
- execute: async () => {
537
- try {
538
- if (!this._canvasManager.isCreated()) {
539
- return { success: false, error: 'No canvas created' }
540
- }
541
-
542
- const svg = this._canvasManager.getProject().exportSVG({
543
- asString: true,
544
- bounds: 'content',
545
- })
546
-
547
- const base64 = Buffer.from(svg).toString('base64')
548
-
549
- return {
550
- success: true,
551
- base64,
552
- svg,
553
- mimeType: 'image/svg+xml',
554
- }
555
- } catch (err) {
556
- return { success: false, error: err.message }
557
- }
558
- },
559
- },
560
-
561
- // ==================== 高级组件 ====================
562
-
563
- /**
564
- * 添加卡片组件
565
- */
566
- add_poster_card: {
567
- description: '添加卡片组件(带背景、标题、副标题)',
568
- inputSchema: z.object({
569
- x: z.number().describe('X坐标'),
570
- y: z.number().describe('Y坐标'),
571
- width: z.number().describe('卡片宽度'),
572
- height: z.number().describe('卡片高度'),
573
- background: z.string().optional().describe('背景色'),
574
- border: z.string().optional().describe('边框颜色'),
575
- borderWidth: z.number().optional().describe('边框宽度'),
576
- radius: z.number().optional().describe('圆角半径'),
577
- title: z.string().optional().describe('标题文字'),
578
- titleSize: z.number().optional().describe('标题字体大小'),
579
- titleColor: z.string().optional().describe('标题颜色'),
580
- subtitle: z.string().optional().describe('副标题'),
581
- subtitleSize: z.number().optional().describe('副标题字体大小'),
582
- subtitleColor: z.string().optional().describe('副标题颜色'),
583
- padding: z.number().optional().describe('内边距'),
584
- }),
585
- execute: async (args) => {
586
- try {
587
- if (!this._canvasManager.isCreated()) {
588
- return { success: false, error: 'No canvas created' }
589
- }
590
- return createCard(
591
- this._canvasManager.getProject(),
592
- this._canvasManager.getCanvas(),
593
- args
594
- )
595
- } catch (err) {
596
- return { success: false, error: err.message }
597
- }
598
- },
599
- },
600
-
601
- /**
602
- * 添加徽章组件
603
- */
604
- add_poster_badge: {
605
- description: '添加徽章/标签组件',
606
- inputSchema: z.object({
607
- x: z.number().describe('X坐标(居中)'),
608
- y: z.number().describe('Y坐标'),
609
- text: z.string().describe('徽章文字'),
610
- background: z.string().optional().describe('背景色'),
611
- color: z.string().optional().describe('文字颜色'),
612
- border: z.string().optional().describe('边框颜色'),
613
- fontSize: z.number().optional().describe('字体大小'),
614
- padding: z.number().optional().describe('内边距'),
615
- radius: z.number().optional().describe('圆角半径'),
616
- }),
617
- execute: async (args) => {
618
- try {
619
- if (!this._canvasManager.isCreated()) {
620
- return { success: false, error: 'No canvas created' }
621
- }
622
- return createBadge(
623
- this._canvasManager.getProject(),
624
- this._canvasManager.getCanvas(),
625
- args
626
- )
627
- } catch (err) {
628
- return { success: false, error: err.message }
629
- }
630
- },
631
- },
632
-
633
- /**
634
- * 添加 CTA 按钮
635
- */
636
- add_poster_cta: {
637
- description: '添加行动号召按钮',
638
- inputSchema: z.object({
639
- x: z.number().describe('X坐标(居中)'),
640
- y: z.number().describe('Y坐标'),
641
- text: z.string().describe('按钮文字'),
642
- background: z.string().optional().describe('背景色'),
643
- color: z.string().optional().describe('文字颜色'),
644
- border: z.string().optional().describe('边框颜色'),
645
- fontSize: z.number().optional().describe('字体大小'),
646
- padding: z.number().optional().describe('内边距'),
647
- radius: z.number().optional().describe('圆角半径'),
648
- shadow: z.object({
649
- color: z.string().optional(),
650
- blur: z.number().optional(),
651
- offsetX: z.number().optional(),
652
- offsetY: z.number().optional(),
653
- }).optional(),
654
- }),
655
- execute: async (args) => {
656
- try {
657
- if (!this._canvasManager.isCreated()) {
658
- return { success: false, error: 'No canvas created' }
659
- }
660
- return createCTA(
661
- this._canvasManager.getProject(),
662
- this._canvasManager.getCanvas(),
663
- args
664
- )
665
- } catch (err) {
666
- return { success: false, error: err.message }
667
- }
668
- },
669
- },
670
-
671
- /**
672
- * 添加特性展示
673
- */
674
- add_poster_feature: {
675
- description: '添加特性展示块',
676
- inputSchema: z.object({
677
- x: z.number().describe('X坐标'),
678
- y: z.number().describe('Y坐标'),
679
- width: z.number().describe('宽度'),
680
- icon: z.string().optional().describe('图标 emoji'),
681
- title: z.string().optional().describe('标题'),
682
- description: z.string().optional().describe('描述'),
683
- iconColor: z.string().optional().describe('图标颜色'),
684
- titleColor: z.string().optional().describe('标题颜色'),
685
- descColor: z.string().optional().describe('描述颜色'),
686
- iconSize: z.number().optional().describe('图标大小'),
687
- titleSize: z.number().optional().describe('标题大小'),
688
- descSize: z.number().optional().describe('描述大小'),
689
- }),
690
- execute: async (args) => {
691
- try {
692
- if (!this._canvasManager.isCreated()) {
693
- return { success: false, error: 'No canvas created' }
694
- }
695
- return createFeature(
696
- this._canvasManager.getProject(),
697
- this._canvasManager.getCanvas(),
698
- args
699
- )
700
- } catch (err) {
701
- return { success: false, error: err.message }
702
- }
703
- },
704
- },
705
-
706
- /**
707
- * 添加特性网格
708
- */
709
- add_poster_feature_grid: {
710
- description: '添加特性网格布局',
711
- inputSchema: z.object({
712
- x: z.number().describe('X坐标'),
713
- y: z.number().describe('Y坐标'),
714
- columns: z.number().optional().describe('列数,默认3'),
715
- itemWidth: z.number().optional().describe('每个特性宽度,默认200'),
716
- itemHeight: z.number().optional().describe('每个特性高度,默认120'),
717
- gap: z.number().optional().describe('间距,默认20'),
718
- items: z.array(z.object({
719
- icon: z.string().optional(),
720
- title: z.string().optional(),
721
- description: z.string().optional(),
722
- iconColor: z.string().optional(),
723
- titleColor: z.string().optional(),
724
- descColor: z.string().optional(),
725
- })).describe('特性数组'),
726
- background: z.string().optional().describe('背景色'),
727
- borderColor: z.string().optional().describe('边框颜色'),
728
- radius: z.number().optional().describe('圆角半径'),
729
- }),
730
- execute: async (args) => {
731
- try {
732
- if (!this._canvasManager.isCreated()) {
733
- return { success: false, error: 'No canvas created' }
734
- }
735
- return createFeatureGrid(
736
- this._canvasManager.getProject(),
737
- this._canvasManager.getCanvas(),
738
- args
739
- )
740
- } catch (err) {
741
- return { success: false, error: err.message }
742
- }
743
- },
744
- },
745
-
746
- /**
747
- * 添加分隔线
748
- */
749
- add_poster_divider: {
750
- description: '添加分隔线',
751
- inputSchema: z.object({
752
- x: z.number().describe('X坐标'),
753
- y: z.number().describe('Y坐标'),
754
- width: z.number().describe('宽度'),
755
- color: z.string().optional().describe('颜色'),
756
- thickness: z.number().optional().describe('厚度'),
757
- style: z.enum(['solid', 'dashed']).optional().describe('样式'),
758
- align: z.enum(['left', 'center', 'right']).optional().describe('对齐'),
759
- }),
760
- execute: async (args) => {
761
- try {
762
- if (!this._canvasManager.isCreated()) {
763
- return { success: false, error: 'No canvas created' }
764
- }
765
- return createDivider(
766
- this._canvasManager.getProject(),
767
- this._canvasManager.getCanvas(),
768
- args
769
- )
770
- } catch (err) {
771
- return { success: false, error: err.message }
772
- }
773
- },
774
- },
775
-
776
- /**
777
- * 添加头像
778
- */
779
- add_poster_avatar: {
780
- description: '添加头像组件',
781
- inputSchema: z.object({
782
- x: z.number().describe('圆心X坐标'),
783
- y: z.number().describe('圆心Y坐标'),
784
- size: z.number().optional().describe('头像大小'),
785
- initials: z.string().optional().describe('首字母'),
786
- background: z.string().optional().describe('背景色'),
787
- border: z.string().optional().describe('边框颜色'),
788
- borderWidth: z.number().optional().describe('边框宽度'),
789
- color: z.string().optional().describe('文字颜色'),
790
- }),
791
- execute: async (args) => {
792
- try {
793
- if (!this._canvasManager.isCreated()) {
794
- return { success: false, error: 'No canvas created' }
795
- }
796
- return createAvatar(
797
- this._canvasManager.getProject(),
798
- this._canvasManager.getCanvas(),
799
- args
800
- )
801
- } catch (err) {
802
- return { success: false, error: err.message }
803
- }
804
- },
805
- },
806
-
807
- /**
808
- * 添加进度条
809
- */
810
- add_poster_progress: {
811
- description: '添加进度条组件',
812
- inputSchema: z.object({
813
- x: z.number().describe('X坐标'),
814
- y: z.number().describe('Y坐标'),
815
- width: z.number().optional().describe('进度条宽度'),
816
- height: z.number().optional().describe('进度条高度'),
817
- value: z.number().optional().describe('进度值 0-100'),
818
- trackColor: z.string().optional().describe('轨道颜色'),
819
- fillColor: z.string().optional().describe('填充颜色'),
820
- radius: z.number().optional().describe('圆角半径'),
821
- showLabel: z.boolean().optional().describe('是否显示标签'),
822
- label: z.string().optional().describe('标签文字'),
823
- }),
824
- execute: async (args) => {
825
- try {
826
- if (!this._canvasManager.isCreated()) {
827
- return { success: false, error: 'No canvas created' }
828
- }
829
- return createProgress(
830
- this._canvasManager.getProject(),
831
- this._canvasManager.getCanvas(),
832
- args
833
- )
834
- } catch (err) {
835
- return { success: false, error: err.message }
836
- }
837
- },
838
- },
839
-
840
- /**
841
- * 添加星级评分
842
- */
843
- add_poster_rating: {
844
- description: '添加星级评分组件',
845
- inputSchema: z.object({
846
- x: z.number().describe('X坐标'),
847
- y: z.number().describe('Y坐标'),
848
- value: z.number().optional().describe('评分值 0-5'),
849
- max: z.number().optional().describe('最大值'),
850
- size: z.number().optional().describe('星星大小'),
851
- filledColor: z.string().optional().describe('填充颜色'),
852
- emptyColor: z.string().optional().describe('空心颜色'),
853
- gap: z.number().optional().describe('星星间距'),
854
- }),
855
- execute: async (args) => {
856
- try {
857
- if (!this._canvasManager.isCreated()) {
858
- return { success: false, error: 'No canvas created' }
859
- }
860
- return createRating(
861
- this._canvasManager.getProject(),
862
- this._canvasManager.getCanvas(),
863
- args
864
- )
865
- } catch (err) {
866
- return { success: false, error: err.message }
867
- }
868
- },
869
- },
870
-
871
- /**
872
- * 添加引用块
873
- */
874
- add_poster_quote: {
875
- description: '添加引用块组件',
876
- inputSchema: z.object({
877
- x: z.number().describe('X坐标'),
878
- y: z.number().describe('Y坐标'),
879
- width: z.number().optional().describe('宽度'),
880
- text: z.string().describe('引用文字'),
881
- author: z.string().optional().describe('作者'),
882
- background: z.string().optional().describe('背景色'),
883
- borderColor: z.string().optional().describe('左边框颜色'),
884
- padding: z.number().optional().describe('内边距'),
885
- radius: z.number().optional().describe('圆角半径'),
886
- textColor: z.string().optional().describe('文字颜色'),
887
- authorColor: z.string().optional().describe('作者颜色'),
888
- fontSize: z.number().optional().describe('字体大小'),
889
- }),
890
- execute: async (args) => {
891
- try {
892
- if (!this._canvasManager.isCreated()) {
893
- return { success: false, error: 'No canvas created' }
894
- }
895
- return createQuote(
896
- this._canvasManager.getProject(),
897
- this._canvasManager.getCanvas(),
898
- args
899
- )
900
- } catch (err) {
901
- return { success: false, error: err.message }
902
- }
903
- },
904
- },
905
-
906
- /**
907
- * 添加统计卡片
908
- */
909
- add_poster_stat_card: {
910
- description: '添加统计卡片组件',
911
- inputSchema: z.object({
912
- x: z.number().describe('X坐标'),
913
- y: z.number().describe('Y坐标'),
914
- width: z.number().optional().describe('宽度'),
915
- height: z.number().optional().describe('高度'),
916
- label: z.string().optional().describe('标签'),
917
- value: z.string().optional().describe('数值'),
918
- change: z.string().optional().describe('变化值'),
919
- positive: z.boolean().optional().describe('变化是否为正'),
920
- icon: z.string().optional().describe('图标'),
921
- iconColor: z.string().optional().describe('图标颜色'),
922
- background: z.string().optional().describe('背景色'),
923
- border: z.string().optional().describe('边框颜色'),
924
- radius: z.number().optional().describe('圆角半径'),
925
- }),
926
- execute: async (args) => {
927
- try {
928
- if (!this._canvasManager.isCreated()) {
929
- return { success: false, error: 'No canvas created' }
930
- }
931
- return createStatCard(
932
- this._canvasManager.getProject(),
933
- this._canvasManager.getCanvas(),
934
- args
935
- )
936
- } catch (err) {
937
- return { success: false, error: err.message }
938
- }
939
- },
940
- },
941
-
942
- /**
943
- * 添加标签云
944
- */
945
- add_poster_tag_cloud: {
946
- description: '添加标签云组件',
947
- inputSchema: z.object({
948
- x: z.number().describe('X坐标'),
949
- y: z.number().describe('Y坐标'),
950
- tags: z.array(z.object({
951
- text: z.string(),
952
- color: z.string().optional(),
953
- bgColor: z.string().optional(),
954
- })).describe('标签数组'),
955
- fontSize: z.number().optional().describe('字体大小'),
956
- padding: z.number().optional().describe('标签内边距'),
957
- gap: z.number().optional().describe('标签间距'),
958
- maxWidth: z.number().optional().describe('最大宽度'),
959
- }),
960
- execute: async (args) => {
961
- try {
962
- if (!this._canvasManager.isCreated()) {
963
- return { success: false, error: 'No canvas created' }
964
- }
965
- return createTagCloud(
966
- this._canvasManager.getProject(),
967
- this._canvasManager.getCanvas(),
968
- args
969
- )
970
- } catch (err) {
971
- return { success: false, error: err.message }
972
- }
973
- },
974
- },
975
-
976
- /**
977
- * 添加步骤指示器
978
- */
979
- add_poster_stepper: {
980
- description: '添加步骤指示器组件',
981
- inputSchema: z.object({
982
- x: z.number().describe('X坐标'),
983
- y: z.number().describe('Y坐标'),
984
- width: z.number().optional().describe('总宽度'),
985
- steps: z.array(z.object({
986
- title: z.string(),
987
- description: z.string().optional(),
988
- })).describe('步骤数组'),
989
- currentStep: z.number().optional().describe('当前步骤'),
990
- activeColor: z.string().optional().describe('激活颜色'),
991
- inactiveColor: z.string().optional().describe('未激活颜色'),
992
- completedColor: z.string().optional().describe('已完成颜色'),
993
- circleSize: z.number().optional().describe('圆圈大小'),
994
- }),
995
- execute: async (args) => {
996
- try {
997
- if (!this._canvasManager.isCreated()) {
998
- return { success: false, error: 'No canvas created' }
999
- }
1000
- return createStepper(
1001
- this._canvasManager.getProject(),
1002
- this._canvasManager.getCanvas(),
1003
- args
1004
- )
1005
- } catch (err) {
1006
- return { success: false, error: err.message }
1007
- }
1008
- },
1009
- },
1010
-
1011
- /**
1012
- * 添加时间线
1013
- */
1014
- add_poster_timeline: {
1015
- description: '添加时间线组件',
1016
- inputSchema: z.object({
1017
- x: z.number().describe('X坐标'),
1018
- y: z.number().describe('Y坐标'),
1019
- width: z.number().optional().describe('总宽度'),
1020
- items: z.array(z.object({
1021
- date: z.string().optional(),
1022
- title: z.string(),
1023
- description: z.string().optional(),
1024
- active: z.boolean().optional(),
1025
- })).describe('时间线项目数组'),
1026
- lineColor: z.string().optional().describe('线条颜色'),
1027
- dotColor: z.string().optional().describe('点颜色'),
1028
- dotSize: z.number().optional().describe('点大小'),
1029
- gap: z.number().optional().describe('项目间距'),
1030
- }),
1031
- execute: async (args) => {
1032
- try {
1033
- if (!this._canvasManager.isCreated()) {
1034
- return { success: false, error: 'No canvas created' }
1035
- }
1036
- return createTimeline(
1037
- this._canvasManager.getProject(),
1038
- this._canvasManager.getCanvas(),
1039
- args
1040
- )
1041
- } catch (err) {
1042
- return { success: false, error: err.message }
1043
- }
1044
- },
1045
- },
1046
-
1047
- /**
1048
- * 添加列表项
1049
- */
1050
- add_poster_list_item: {
1051
- description: '添加列表项组件',
1052
- inputSchema: z.object({
1053
- x: z.number().describe('X坐标'),
1054
- y: z.number().describe('Y坐标'),
1055
- width: z.number().optional().describe('宽度'),
1056
- icon: z.string().optional().describe('图标'),
1057
- title: z.string().optional().describe('标题'),
1058
- description: z.string().optional().describe('描述'),
1059
- badge: z.string().optional().describe('徽章文字'),
1060
- badgeColor: z.string().optional().describe('徽章颜色'),
1061
- iconColor: z.string().optional().describe('图标颜色'),
1062
- background: z.string().optional().describe('背景色'),
1063
- borderColor: z.string().optional().describe('边框颜色'),
1064
- height: z.number().optional().describe('高度'),
1065
- radius: z.number().optional().describe('圆角半径'),
1066
- }),
1067
- execute: async (args) => {
1068
- try {
1069
- if (!this._canvasManager.isCreated()) {
1070
- return { success: false, error: 'No canvas created' }
1071
- }
1072
- return createListItem(
1073
- this._canvasManager.getProject(),
1074
- this._canvasManager.getCanvas(),
1075
- args
1076
- )
1077
- } catch (err) {
1078
- return { success: false, error: err.message }
1079
- }
1080
- },
1081
- },
1082
-
1083
- /**
1084
- * 添加通知提示
1085
- */
1086
- add_poster_notification: {
1087
- description: '添加通知提示组件',
1088
- inputSchema: z.object({
1089
- x: z.number().describe('X坐标'),
1090
- y: z.number().describe('Y坐标'),
1091
- width: z.number().optional().describe('宽度'),
1092
- type: z.enum(['success', 'warning', 'error', 'info']).optional().describe('类型'),
1093
- title: z.string().optional().describe('标题'),
1094
- message: z.string().optional().describe('消息内容'),
1095
- showIcon: z.boolean().optional().describe('是否显示图标'),
1096
- radius: z.number().optional().describe('圆角半径'),
1097
- }),
1098
- execute: async (args) => {
1099
- try {
1100
- if (!this._canvasManager.isCreated()) {
1101
- return { success: false, error: 'No canvas created' }
1102
- }
1103
- return createNotification(
1104
- this._canvasManager.getProject(),
1105
- this._canvasManager.getCanvas(),
1106
- args
1107
- )
1108
- } catch (err) {
1109
- return { success: false, error: err.message }
1110
- }
1111
- },
1112
- },
1113
-
1114
- /**
1115
- * 添加图片框组件
1116
- */
1117
- add_poster_image_frame: {
1118
- description: '添加带装饰边框的图片框组件',
1119
- inputSchema: z.object({
1120
- src: z.string().describe('图片路径或URL'),
1121
- x: z.number().describe('X坐标'),
1122
- y: z.number().describe('Y坐标'),
1123
- width: z.number().describe('图片宽度'),
1124
- height: z.number().describe('图片高度'),
1125
- borderColor: z.string().optional().describe('边框颜色'),
1126
- borderWidth: z.number().optional().describe('边框宽度'),
1127
- outerColor: z.string().optional().describe('外边框颜色'),
1128
- outerWidth: z.number().optional().describe('外边框宽度'),
1129
- shadowBlur: z.number().optional().describe('阴影模糊'),
1130
- shadowOffsetX: z.number().optional().describe('阴影X偏移'),
1131
- shadowOffsetY: z.number().optional().describe('阴影Y偏移'),
1132
- shadowColor: z.string().optional().describe('阴影颜色'),
1133
- radius: z.number().optional().describe('圆角半径'),
1134
- overlayColor: z.string().optional().describe('叠加颜色'),
1135
- overlayOpacity: z.number().optional().describe('叠加透明度'),
1136
- fit: z.enum(['cover', 'contain', 'fill']).optional().describe('图片填充方式'),
1137
- }),
1138
- execute: async (args) => {
1139
- try {
1140
- if (!this._canvasManager.isCreated()) {
1141
- return { success: false, error: 'No canvas created' }
1142
- }
1143
- return createImageFrame(
1144
- this._canvasManager.getProject(),
1145
- this._canvasManager.getCanvas(),
1146
- args
1147
- )
1148
- } catch (err) {
1149
- return { success: false, error: err.message }
1150
- }
1151
- },
1152
- },
1153
-
1154
- /**
1155
- * 添加分栏布局组件
1156
- */
1157
- add_poster_columns: {
1158
- description: '添加分栏布局组件(左右分栏、三栏等)',
1159
- inputSchema: z.object({
1160
- x: z.number().describe('起始X坐标'),
1161
- y: z.number().describe('起始Y坐标'),
1162
- width: z.number().describe('总宽度'),
1163
- height: z.number().describe('总高度'),
1164
- columns: z.number().optional().describe('列数,默认2'),
1165
- gap: z.number().optional().describe('列间距,默认20'),
1166
- background: z.string().optional().describe('背景色'),
1167
- borderColor: z.string().optional().describe('边框颜色'),
1168
- borderWidth: z.number().optional().describe('边框宽度'),
1169
- radius: z.number().optional().describe('圆角半径'),
1170
- direction: z.enum(['horizontal', 'vertical']).optional().describe('排列方向'),
1171
- align: z.enum(['top', 'center', 'bottom']).optional().describe('垂直对齐'),
1172
- }),
1173
- execute: async (args) => {
1174
- try {
1175
- if (!this._canvasManager.isCreated()) {
1176
- return { success: false, error: 'No canvas created' }
1177
- }
1178
- return createColumns(
1179
- this._canvasManager.getProject(),
1180
- this._canvasManager.getCanvas(),
1181
- args
1182
- )
1183
- } catch (err) {
1184
- return { success: false, error: err.message }
1185
- }
1186
- },
1187
- },
1188
-
1189
- /**
1190
- * 添加网格布局组件
1191
- */
1192
- add_poster_grid: {
1193
- description: '添加网格布局组件(任意行列)',
1194
- inputSchema: z.object({
1195
- x: z.number().describe('起始X坐标'),
1196
- y: z.number().describe('起始Y坐标'),
1197
- width: z.number().describe('总宽度'),
1198
- height: z.number().describe('总高度'),
1199
- columns: z.number().optional().describe('列数,默认3'),
1200
- rows: z.number().optional().describe('行数,默认2'),
1201
- gapX: z.number().optional().describe('水平间距,默认20'),
1202
- gapY: z.number().optional().describe('垂直间距,默认20'),
1203
- background: z.string().optional().describe('背景色'),
1204
- borderColor: z.string().optional().describe('边框颜色'),
1205
- borderWidth: z.number().optional().describe('边框宽度'),
1206
- radius: z.number().optional().describe('圆角半径'),
1207
- direction: z.enum(['row', 'column']).optional().describe('排列方向'),
1208
- }),
1209
- execute: async (args) => {
1210
- try {
1211
- if (!this._canvasManager.isCreated()) {
1212
- return { success: false, error: 'No canvas created' }
1213
- }
1214
- return createGrid(
1215
- this._canvasManager.getProject(),
1216
- this._canvasManager.getCanvas(),
1217
- args
1218
- )
1219
- } catch (err) {
1220
- return { success: false, error: err.message }
1221
- }
1222
- },
1223
- },
1224
-
1225
- /**
1226
- * 添加星形组件
1227
- */
1228
- add_poster_star: {
1229
- description: '添加星形/多角形装饰',
1230
- inputSchema: z.object({
1231
- cx: z.number().describe('中心X坐标'),
1232
- cy: z.number().describe('中心Y坐标'),
1233
- points: z.number().optional().describe('星形点数,默认5'),
1234
- innerRadius: z.number().optional().describe('内半径'),
1235
- outerRadius: z.number().describe('外半径'),
1236
- fill: z.string().optional().describe('填充颜色'),
1237
- stroke: z.string().optional().describe('边框颜色'),
1238
- strokeWidth: z.number().optional().describe('边框宽度'),
1239
- opacity: z.number().optional().describe('透明度 0-1'),
1240
- rotation: z.number().optional().describe('旋转角度'),
1241
- }),
1242
- execute: async (args) => {
1243
- try {
1244
- if (!this._canvasManager.isCreated()) {
1245
- return { success: false, error: 'No canvas created' }
1246
- }
1247
- const project = this._canvasManager.getProject()
1248
- const result = createStar(project, this._canvasManager.getCanvas(), args)
1249
- // 强制将所有子元素添加到活动层
1250
- if (result && result.elements && project) {
1251
- // 收集所有新创建的 item
1252
- const allItems = project.getItems({})
1253
- const existingIds = new Set(allItems.map(i => i.id))
1254
-
1255
- // 从项目的所有层中获取新添加的 item
1256
- project.layers.forEach(layer => {
1257
- layer.children.forEach(item => {
1258
- if (item.id && !existingIds.has(item.id) || item.parent === layer) {
1259
- if (item.parent !== project.activeLayer) {
1260
- project.activeLayer.addChild(item)
1261
- }
1262
- }
1263
- })
1264
- })
1265
- }
1266
- return result
1267
- } catch (err) {
1268
- return { success: false, error: err.message }
1269
- }
1270
- },
1271
- },
1272
-
1273
- /**
1274
- * 添加箭头组件
1275
- */
1276
- add_poster_arrow: {
1277
- description: '添加箭头指示',
1278
- inputSchema: z.object({
1279
- x1: z.number().describe('起点X'),
1280
- y1: z.number().describe('起点Y'),
1281
- x2: z.number().describe('终点X'),
1282
- y2: z.number().describe('终点Y'),
1283
- color: z.string().optional().describe('箭头颜色'),
1284
- strokeWidth: z.number().optional().describe('线宽'),
1285
- headSize: z.number().optional().describe('箭头头部大小'),
1286
- style: z.enum(['solid', 'dashed']).optional().describe('样式'),
1287
- direction: z.enum(['end', 'start', 'both']).optional().describe('箭头方向'),
1288
- }),
1289
- execute: async (args) => {
1290
- try {
1291
- if (!this._canvasManager.isCreated()) {
1292
- return { success: false, error: 'No canvas created' }
1293
- }
1294
- const result = createArrow(
1295
- this._canvasManager.getProject(),
1296
- this._canvasManager.getCanvas(),
1297
- args
1298
- )
1299
- if (result && result.elements && this._canvasManager.getProject()) {
1300
- const project = this._canvasManager.getProject()
1301
- result.elements.forEach(el => {
1302
- if (el.id) {
1303
- const item = project.getItem({ id: el.id })
1304
- if (item) project.activeLayer.addChild(item)
1305
- }
1306
- })
1307
- }
1308
- return result
1309
- } catch (err) {
1310
- return { success: false, error: err.message }
1311
- }
1312
- },
1313
- },
1314
-
1315
- /**
1316
- * 添加环形进度条
1317
- */
1318
- add_poster_progress_circle: {
1319
- description: '添加环形进度条组件',
1320
- inputSchema: z.object({
1321
- cx: z.number().describe('圆心X坐标'),
1322
- cy: z.number().describe('圆心Y坐标'),
1323
- radius: z.number().describe('圆环半径'),
1324
- value: z.number().describe('进度值 0-100'),
1325
- strokeWidth: z.number().optional().describe('环宽度'),
1326
- trackColor: z.string().optional().describe('轨道颜色'),
1327
- fillColor: z.string().optional().describe('进度颜色'),
1328
- backgroundColor: z.string().optional().describe('背景填充色'),
1329
- showLabel: z.boolean().optional().describe('是否显示百分比标签'),
1330
- labelColor: z.string().optional().describe('标签颜色'),
1331
- }),
1332
- execute: async (args) => {
1333
- try {
1334
- if (!this._canvasManager.isCreated()) {
1335
- return { success: false, error: 'No canvas created' }
1336
- }
1337
- const result = createProgressCircle(
1338
- this._canvasManager.getProject(),
1339
- this._canvasManager.getCanvas(),
1340
- args
1341
- )
1342
- if (result && result.elements && this._canvasManager.getProject()) {
1343
- const project = this._canvasManager.getProject()
1344
- result.elements.forEach(el => {
1345
- if (el.id) {
1346
- const item = project.getItem({ id: el.id })
1347
- if (item) project.activeLayer.addChild(item)
1348
- }
1349
- })
1350
- }
1351
- return result
1352
- } catch (err) {
1353
- return { success: false, error: err.message }
1354
- }
1355
- },
1356
- },
1357
-
1358
- /**
1359
- * 添加 Chip 标签
1360
- */
1361
- add_poster_chip: {
1362
- description: '添加小型信息标签组件',
1363
- inputSchema: z.object({
1364
- x: z.number().describe('X坐标(居中)'),
1365
- y: z.number().describe('Y坐标'),
1366
- text: z.string().describe('标签文字'),
1367
- background: z.string().optional().describe('背景色'),
1368
- color: z.string().optional().describe('文字颜色'),
1369
- borderColor: z.string().optional().describe('边框颜色'),
1370
- fontSize: z.number().optional().describe('字体大小'),
1371
- padding: z.number().optional().describe('内边距'),
1372
- radius: z.number().optional().describe('圆角'),
1373
- icon: z.string().optional().describe('前置图标 emoji'),
1374
- }),
1375
- execute: async (args) => {
1376
- try {
1377
- if (!this._canvasManager.isCreated()) {
1378
- return { success: false, error: 'No canvas created' }
1379
- }
1380
- const result = createChip(
1381
- this._canvasManager.getProject(),
1382
- this._canvasManager.getCanvas(),
1383
- args
1384
- )
1385
- if (result && result.elements && this._canvasManager.getProject()) {
1386
- const project = this._canvasManager.getProject()
1387
- result.elements.forEach(el => {
1388
- if (el.id) {
1389
- const item = project.getItem({ id: el.id })
1390
- if (item) project.activeLayer.addChild(item)
1391
- }
1392
- })
1393
- }
1394
- return result
1395
- } catch (err) {
1396
- return { success: false, error: err.message }
1397
- }
1398
- },
1399
- },
1400
-
1401
- /**
1402
- * 添加图表组件
1403
- */
1404
- add_poster_chart: {
1405
- description: '添加图表组件(柱状图/饼图)',
1406
- inputSchema: z.object({
1407
- type: z.enum(['bar', 'pie']).describe('图表类型'),
1408
- x: z.number().describe('X坐标'),
1409
- y: z.number().describe('Y坐标'),
1410
- width: z.number().describe('宽度'),
1411
- height: z.number().describe('高度'),
1412
- data: z.array(z.object({
1413
- label: z.string().describe('标签'),
1414
- value: z.number().describe('数值'),
1415
- color: z.string().optional().describe('颜色'),
1416
- })).describe('数据'),
1417
- barColor: z.string().optional().describe('默认柱状颜色'),
1418
- showLabels: z.boolean().optional().describe('显示标签'),
1419
- showValues: z.boolean().optional().describe('显示数值'),
1420
- }),
1421
- execute: async (args) => {
1422
- try {
1423
- if (!this._canvasManager.isCreated()) {
1424
- return { success: false, error: 'No canvas created' }
1425
- }
1426
- const result = createChart(
1427
- this._canvasManager.getProject(),
1428
- this._canvasManager.getCanvas(),
1429
- args
1430
- )
1431
- if (result && result.elements && this._canvasManager.getProject()) {
1432
- const project = this._canvasManager.getProject()
1433
- result.elements.forEach(el => {
1434
- if (el.id) {
1435
- const item = project.getItem({ id: el.id })
1436
- if (item) project.activeLayer.addChild(item)
1437
- }
1438
- })
1439
- }
1440
- return result
1441
- } catch (err) {
1442
- return { success: false, error: err.message }
1443
- }
1444
- },
1445
- },
1446
-
1447
- /**
1448
- * 添加水印
1449
- */
1450
- add_poster_watermark: {
1451
- description: '添加水印文字',
1452
- inputSchema: z.object({
1453
- text: z.string().describe('水印文字'),
1454
- cx: z.number().describe('中心X坐标'),
1455
- cy: z.number().describe('中心Y坐标'),
1456
- color: z.string().optional().describe('水印颜色'),
1457
- fontSize: z.number().optional().describe('字体大小'),
1458
- fontFamily: z.string().optional().describe('字体'),
1459
- opacity: z.number().optional().describe('透明度'),
1460
- rotation: z.number().optional().describe('旋转角度'),
1461
- align: z.enum(['left', 'center', 'right']).optional().describe('对齐方式'),
1462
- }),
1463
- execute: async (args) => {
1464
- try {
1465
- if (!this._canvasManager.isCreated()) {
1466
- return { success: false, error: 'No canvas created' }
1467
- }
1468
- const result = createWatermark(
1469
- this._canvasManager.getProject(),
1470
- this._canvasManager.getCanvas(),
1471
- args
1472
- )
1473
- if (result && result.elements && this._canvasManager.getProject()) {
1474
- const project = this._canvasManager.getProject()
1475
- result.elements.forEach(el => {
1476
- if (el.id) {
1477
- const item = project.getItem({ id: el.id })
1478
- if (item) project.activeLayer.addChild(item)
1479
- }
1480
- })
1481
- }
1482
- return result
1483
- } catch (err) {
1484
- return { success: false, error: err.message }
1485
- }
1486
- },
1487
- },
1488
-
1489
- /**
1490
- * 添加表格组件
1491
- */
1492
- add_poster_table: {
1493
- description: '添加表格组件',
1494
- inputSchema: z.object({
1495
- x: z.number().describe('X坐标'),
1496
- y: z.number().describe('Y坐标'),
1497
- width: z.number().describe('表格宽度'),
1498
- columns: z.array(z.object({
1499
- title: z.string().describe('列标题'),
1500
- width: z.number().optional().describe('列宽'),
1501
- align: z.enum(['left', 'center', 'right']).optional().describe('对齐'),
1502
- })).describe('列配置'),
1503
- rows: z.array(z.array(z.string())).describe('行数据'),
1504
- rowHeight: z.number().optional().describe('行高'),
1505
- headerBg: z.string().optional().describe('表头背景色'),
1506
- headerColor: z.string().optional().describe('表头文字色'),
1507
- borderColor: z.string().optional().describe('边框颜色'),
1508
- fontSize: z.number().optional().describe('字体大小'),
1509
- striped: z.boolean().optional().describe('斑马纹'),
1510
- }),
1511
- execute: async (args) => {
1512
- try {
1513
- if (!this._canvasManager.isCreated()) {
1514
- return { success: false, error: 'No canvas created' }
1515
- }
1516
- const result = createTable(
1517
- this._canvasManager.getProject(),
1518
- this._canvasManager.getCanvas(),
1519
- args
1520
- )
1521
- if (result && result.elements && this._canvasManager.getProject()) {
1522
- const project = this._canvasManager.getProject()
1523
- result.elements.forEach(el => {
1524
- if (el.id) {
1525
- const item = project.getItem({ id: el.id })
1526
- if (item) project.activeLayer.addChild(item)
1527
- }
1528
- })
1529
- }
1530
- return result
1531
- } catch (err) {
1532
- return { success: false, error: err.message }
1533
- }
1534
- },
1535
- },
1536
-
1537
- /**
1538
- * 添加按钮
1539
- */
1540
- add_poster_button: {
1541
- description: '添加按钮组件',
1542
- inputSchema: z.object({
1543
- x: z.number().describe('X坐标'),
1544
- y: z.number().describe('Y坐标'),
1545
- width: z.number().optional().describe('宽度,默认200'),
1546
- height: z.number().optional().describe('高度,默认60'),
1547
- text: z.string().optional().describe('按钮文字'),
1548
- fontSize: z.number().optional().describe('字体大小'),
1549
- color: z.string().optional().describe('文字颜色'),
1550
- backgroundColor: z.string().optional().describe('背景色'),
1551
- borderColor: z.string().optional().describe('边框颜色'),
1552
- borderWidth: z.number().optional().describe('边框宽度'),
1553
- radius: z.number().optional().describe('圆角'),
1554
- shadow: z.object({
1555
- color: z.string().optional(),
1556
- blur: z.number().optional(),
1557
- offsetX: z.number().optional(),
1558
- offsetY: z.number().optional(),
1559
- }).optional(),
1560
- gradient: z.object({
1561
- colors: z.array(z.string()).describe('渐变颜色数组'),
1562
- }).optional(),
1563
- opacity: z.number().optional().describe('透明度'),
1564
- }),
1565
- execute: async (args) => {
1566
- try {
1567
- if (!this._canvasManager.isCreated()) {
1568
- return { success: false, error: 'No canvas created' }
1569
- }
1570
- return await createButton(
1571
- this._canvasManager.getProject(),
1572
- this._canvasManager.getCanvas(),
1573
- args
1574
- )
1575
- } catch (err) {
1576
- return { success: false, error: err.message }
1577
- }
1578
- },
1579
- },
1580
-
1581
- /**
1582
- * 添加图标
1583
- */
1584
- add_poster_icon: {
1585
- description: '添加图标(emoji或图片)',
1586
- inputSchema: z.object({
1587
- x: z.number().describe('X坐标'),
1588
- y: z.number().describe('Y坐标'),
1589
- size: z.number().optional().describe('图标大小,默认64'),
1590
- icon: z.string().describe('图标内容(emoji或图片URL)'),
1591
- color: z.string().optional().describe('颜色'),
1592
- backgroundColor: z.string().optional().describe('背景色'),
1593
- borderColor: z.string().optional().describe('边框颜色'),
1594
- borderWidth: z.number().optional().describe('边框宽度'),
1595
- radius: z.number().optional().describe('圆角'),
1596
- shadow: z.object({
1597
- color: z.string().optional(),
1598
- blur: z.number().optional(),
1599
- offsetX: z.number().optional(),
1600
- offsetY: z.number().optional(),
1601
- }).optional(),
1602
- opacity: z.number().optional().describe('透明度'),
1603
- }),
1604
- execute: async (args) => {
1605
- try {
1606
- if (!this._canvasManager.isCreated()) {
1607
- return { success: false, error: 'No canvas created' }
1608
- }
1609
- return await createIcon(
1610
- this._canvasManager.getProject(),
1611
- args
1612
- )
1613
- } catch (err) {
1614
- return { success: false, error: err.message }
1615
- }
1616
- },
1617
- },
1618
-
1619
- /**
1620
- * 添加二维码
1621
- */
1622
- // add_poster_qrcode: {
1623
- // description: '添加二维码',
1624
- // inputSchema: z.object({
1625
- // x: z.number().describe('X坐标'),
1626
- // y: z.number().describe('Y坐标'),
1627
- // size: z.number().optional().describe('二维码大小,默认200'),
1628
- // content: z.string().describe('二维码内容'),
1629
- // color: z.string().optional().describe('前景色'),
1630
- // backgroundColor: z.string().optional().describe('背景色'),
1631
- // logo: z.string().optional().describe('中间logo图片路径'),
1632
- // logoSize: z.number().optional().describe('logo大小'),
1633
- // opacity: z.number().optional().describe('透明度'),
1634
- // }),
1635
- // execute: async (args) => {
1636
- // try {
1637
- // if (!this._canvasManager.isCreated()) {
1638
- // return { success: false, error: 'No canvas created' }
1639
- // }
1640
- // return await createQRCode(
1641
- // this._canvasManager.getProject(),
1642
- // this._canvasManager.getCanvas(),
1643
- // args
1644
- // )
1645
- // } catch (err) {
1646
- // return { success: false, error: err.message }
1647
- // }
1648
- // },
1649
- // },
1650
-
1651
- /**
1652
- * 添加装饰边框
1653
- */
1654
- add_poster_frame: {
1655
- description: '添加装饰边框',
1656
- inputSchema: z.object({
1657
- x: z.number().describe('X坐标'),
1658
- y: z.number().describe('Y坐标'),
1659
- width: z.number().describe('宽度'),
1660
- height: z.number().describe('高度'),
1661
- style: z.enum(['simple', 'double', 'dashed', 'dotted', 'corner', 'vintage', 'modern', 'floral']).optional().describe('边框样式'),
1662
- color: z.string().optional().describe('边框颜色'),
1663
- borderWidth: z.number().optional().describe('边框宽度'),
1664
- radius: z.number().optional().describe('圆角'),
1665
- padding: z.number().optional().describe('内边距'),
1666
- opacity: z.number().optional().describe('透明度'),
1667
- }),
1668
- execute: async (args) => {
1669
- try {
1670
- if (!this._canvasManager.isCreated()) {
1671
- return { success: false, error: 'No canvas created' }
1672
- }
1673
- return await createFrame(
1674
- this._canvasManager.getProject(),
1675
- this._canvasManager.getCanvas(),
1676
- args
1677
- )
1678
- } catch (err) {
1679
- return { success: false, error: err.message }
1680
- }
1681
- },
1682
- },
1683
-
1684
- /**
1685
- * 添加对话气泡
1686
- */
1687
- add_poster_bubble: {
1688
- description: '添加对话气泡',
1689
- inputSchema: z.object({
1690
- x: z.number().describe('X坐标'),
1691
- y: z.number().describe('Y坐标'),
1692
- width: z.number().optional().describe('宽度,默认300'),
1693
- height: z.number().optional().describe('高度,默认100'),
1694
- text: z.string().describe('气泡文字'),
1695
- fontSize: z.number().optional().describe('字体大小'),
1696
- color: z.string().optional().describe('文字颜色'),
1697
- backgroundColor: z.string().optional().describe('背景色'),
1698
- borderColor: z.string().optional().describe('边框颜色'),
1699
- borderWidth: z.number().optional().describe('边框宽度'),
1700
- radius: z.number().optional().describe('圆角'),
1701
- tailDirection: z.enum(['bottom', 'top', 'left', 'right']).optional().describe('尾巴方向'),
1702
- tailPosition: z.enum(['left', 'center', 'right']).optional().describe('尾巴位置'),
1703
- shadow: z.object({
1704
- color: z.string().optional(),
1705
- blur: z.number().optional(),
1706
- offsetX: z.number().optional(),
1707
- offsetY: z.number().optional(),
1708
- }).optional(),
1709
- opacity: z.number().optional().describe('透明度'),
1710
- }),
1711
- execute: async (args) => {
1712
- try {
1713
- if (!this._canvasManager.isCreated()) {
1714
- return { success: false, error: 'No canvas created' }
1715
- }
1716
- return await createBubble(
1717
- this._canvasManager.getProject(),
1718
- this._canvasManager.getCanvas(),
1719
- args
1720
- )
1721
- } catch (err) {
1722
- return { success: false, error: err.message }
1723
- }
1724
- },
1725
- },
1726
-
1727
- /**
1728
- * 添加丝带
1729
- */
1730
- add_poster_ribbon: {
1731
- description: '添加丝带飘带',
1732
- inputSchema: z.object({
1733
- x: z.number().describe('X坐标'),
1734
- y: z.number().describe('Y坐标'),
1735
- width: z.number().optional().describe('宽度,默认300'),
1736
- text: z.string().optional().describe('丝带文字'),
1737
- fontSize: z.number().optional().describe('字体大小'),
1738
- color: z.string().optional().describe('文字颜色'),
1739
- backgroundColor: z.string().optional().describe('背景色'),
1740
- borderColor: z.string().optional().describe('边框颜色'),
1741
- borderWidth: z.number().optional().describe('边框宽度'),
1742
- style: z.enum(['fold', 'diagonal', 'corner']).optional().describe('丝带样式'),
1743
- shadow: z.object({
1744
- color: z.string().optional(),
1745
- blur: z.number().optional(),
1746
- offsetX: z.number().optional(),
1747
- offsetY: z.number().optional(),
1748
- }).optional(),
1749
- opacity: z.number().optional().describe('透明度'),
1750
- }),
1751
- execute: async (args) => {
1752
- try {
1753
- if (!this._canvasManager.isCreated()) {
1754
- return { success: false, error: 'No canvas created' }
1755
- }
1756
- return await createRibbon(
1757
- this._canvasManager.getProject(),
1758
- this._canvasManager.getCanvas(),
1759
- args
1760
- )
1761
- } catch (err) {
1762
- return { success: false, error: err.message }
1763
- }
1764
- },
1765
- },
1766
-
1767
- /**
1768
- * 添加印章
1769
- */
1770
- add_poster_seal: {
1771
- description: '添加印章效果',
1772
- inputSchema: z.object({
1773
- x: z.number().describe('X坐标'),
1774
- y: z.number().describe('Y坐标'),
1775
- size: z.number().optional().describe('印章大小,默认100'),
1776
- text: z.string().optional().describe('印章文字'),
1777
- fontSize: z.number().optional().describe('字体大小'),
1778
- color: z.string().optional().describe('印章颜色'),
1779
- style: z.enum(['circle', 'square', 'star', 'hexagon']).optional().describe('印章形状'),
1780
- borderWidth: z.number().optional().describe('边框宽度'),
1781
- opacity: z.number().optional().describe('透明度'),
1782
- }),
1783
- execute: async (args) => {
1784
- try {
1785
- if (!this._canvasManager.isCreated()) {
1786
- return { success: false, error: 'No canvas created' }
1787
- }
1788
- return await createSeal(
1789
- this._canvasManager.getProject(),
1790
- this._canvasManager.getCanvas(),
1791
- args
1792
- )
1793
- } catch (err) {
1794
- return { success: false, error: err.message }
1795
- }
1796
- },
1797
- },
1798
-
1799
- /**
1800
- * 添加高亮文字
1801
- */
1802
- add_poster_highlight_text: {
1803
- description: '添加高亮文字(荧光笔效果)',
1804
- inputSchema: z.object({
1805
- x: z.number().describe('X坐标'),
1806
- y: z.number().describe('Y坐标'),
1807
- text: z.string().describe('文字内容'),
1808
- fontSize: z.number().optional().describe('字体大小'),
1809
- color: z.string().optional().describe('文字颜色'),
1810
- highlightColor: z.string().optional().describe('高亮颜色'),
1811
- highlightStyle: z.enum(['marker', 'underline', 'background', 'stroke', 'neon']).optional().describe('高亮样式'),
1812
- strokeWidth: z.number().optional().describe('描边宽度'),
1813
- shadow: z.object({
1814
- color: z.string().optional(),
1815
- blur: z.number().optional(),
1816
- offsetX: z.number().optional(),
1817
- offsetY: z.number().optional(),
1818
- }).optional(),
1819
- opacity: z.number().optional().describe('透明度'),
1820
- }),
1821
- execute: async (args) => {
1822
- try {
1823
- if (!this._canvasManager.isCreated()) {
1824
- return { success: false, error: 'No canvas created' }
1825
- }
1826
- return await createHighlightText(
1827
- this._canvasManager.getProject(),
1828
- this._canvasManager.getCanvas(),
1829
- args
1830
- )
1831
- } catch (err) {
1832
- return { success: false, error: err.message }
1833
- }
1834
- },
1835
- },
1836
-
1837
- /**
1838
- * 添加条形码
1839
- */
1840
- // add_poster_barcode: {
1841
- // description: '添加条形码',
1842
- // inputSchema: z.object({
1843
- // x: z.number().describe('X坐标'),
1844
- // y: z.number().describe('Y坐标'),
1845
- // width: z.number().optional().describe('宽度,默认300'),
1846
- // height: z.number().optional().describe('高度,默认100'),
1847
- // content: z.string().describe('条形码内容'),
1848
- // color: z.string().optional().describe('条形码颜色'),
1849
- // showText: z.boolean().optional().describe('是否显示文字'),
1850
- // textColor: z.string().optional().describe('文字颜色'),
1851
- // fontSize: z.number().optional().describe('字体大小'),
1852
- // opacity: z.number().optional().describe('透明度'),
1853
- // }),
1854
- // execute: async (args) => {
1855
- // try {
1856
- // if (!this._canvasManager.isCreated()) {
1857
- // return { success: false, error: 'No canvas created' }
1858
- // }
1859
- // return await createBarcode(
1860
- // this._canvasManager.getProject(),
1861
- // this._canvasManager.getCanvas(),
1862
- // args
1863
- // )
1864
- // } catch (err) {
1865
- // return { success: false, error: err.message }
1866
- // }
1867
- // },
1868
- // },
1869
-
1870
- // ==================== 组件化海报生成 ====================
1871
-
1872
- /**
1873
- * 组件化生成海报
1874
- */
1875
- compose_poster: {
1876
- description: '使用组件配置一次性生成海报',
1877
- inputSchema: z.object({
1878
- components: z.array(z.object({
1879
- type: z.enum([
1880
- 'background', 'rectangle', 'circle', 'line', 'polygon',
1881
- 'text', 'artText', 'richText', 'image', 'svg', 'imageFrame',
1882
- 'columns', 'grid', 'star', 'arrow', 'progressCircle', 'chip', 'chart', 'watermark', 'table',
1883
- 'card', 'badge', 'cta', 'feature', 'featureGrid', 'divider',
1884
- 'avatar', 'progress', 'rating', 'quote', 'statCard',
1885
- 'tagCloud', 'stepper', 'timeline', 'listItem', 'notification',
1886
- 'button', 'icon', 'qrcode', 'frame', 'bubble', 'ribbon', 'seal', 'highlightText', 'barcode',
1887
- ]).describe('组件类型'),
1888
- })).describe('组件配置数组'),
1889
- }),
1890
- execute: async (args) => {
1891
- try {
1892
- if (!this._canvasManager.isCreated()) {
1893
- return { success: false, error: 'No canvas created' }
1894
- }
1895
- return createFromConfig(
1896
- this._canvasManager.getProject(),
1897
- this._canvasManager.getCanvas(),
1898
- args
1899
- )
1900
- } catch (err) {
1901
- return { success: false, error: err.message }
1902
- }
1903
- },
1904
- },
1905
-
1906
- /**
1907
- * 获取可用组件类型
1908
- */
1909
- list_poster_components: {
1910
- description: '列出所有可用的组件类型',
1911
- inputSchema: z.object({}),
1912
- execute: async () => ({
1913
- success: true,
1914
- components: Object.keys(COMPONENT_TYPES),
1915
- }),
1916
- },
1917
-
1918
- // ==================== 模板 ====================
1919
-
1920
- /**
1921
- * 一键生成海报
1922
- */
1923
- generate_poster: {
1924
- description: '使用预设模板一键生成海报',
1925
- inputSchema: z.object({
1926
- template: z.enum(['modern', 'business', 'social', 'simple', 'tech', 'gradient']).describe('模板类型'),
1927
- title: z.string().describe('主标题'),
1928
- subtitle: z.string().optional().describe('副标题'),
1929
- background: z.string().optional().describe('背景色'),
1930
- accentColor: z.string().optional().describe('强调色'),
1931
- output: z.string().describe('输出文件名'),
1932
- outputDir: z.string().optional().describe('输出目录'),
1933
- }),
1934
- execute: async (args) => {
1935
- try {
1936
- if (!this._canvasManager.isCreated()) {
1937
- return { success: false, error: 'No canvas created' }
1938
- }
1939
-
1940
- // 应用模板
1941
- applyTemplate(
1942
- this._canvasManager.getProject(),
1943
- this._canvasManager.getCanvas(),
1944
- args.template,
1945
- args
1946
- )
1947
-
1948
- // 导出
1949
- const format = 'png'
1950
- const outputDir = args.outputDir || '.'
1951
- const filename = `${args.output}.${format}`
1952
- await fs.promises.mkdir(outputDir, { recursive: true })
1953
- const filepath = path.join(outputDir, filename)
1954
- const buffer = this._canvasManager.toBuffer(format)
1955
- await fs.promises.writeFile(filepath, buffer)
1956
-
1957
- return {
1958
- success: true,
1959
- filepath,
1960
- template: args.template,
1961
- size: buffer.length,
1962
- }
1963
- } catch (err) {
1964
- return { success: false, error: err.message }
1965
- }
1966
- },
1967
- },
1968
-
1969
- /**
1970
- * 列出可用模板
1971
- */
1972
- list_poster_templates: {
1973
- description: '列出所有可用的海报模板',
1974
- inputSchema: z.object({}),
1975
- execute: async () => ({
1976
- success: true,
1977
- templates: getAvailableTemplates(),
1978
- }),
1979
- },
1980
-
1981
- // ==================== 导出 ====================
1982
-
1983
- /**
1984
- * 导出为文件
1985
- */
1986
- export_poster_canvas: {
1987
- description: '导出画布为图片文件',
1988
- inputSchema: z.object({
1989
- filename: z.string().describe('文件名(不含扩展名)'),
1990
- format: z.enum(['png', 'jpg']).optional().describe('格式,默认png'),
1991
- quality: z.number().optional().describe('JPEG质量'),
1992
- outputDir: z.string().optional().describe('输出目录'),
1993
- }),
1994
- execute: async (args) => {
1995
- try {
1996
- if (!this._canvasManager.isCreated()) {
1997
- return { success: false, error: 'No canvas created' }
1998
- }
1999
-
2000
- const format = args.format || 'png'
2001
- const outputDir = args.outputDir || '.'
2002
- const filename = `${args.filename}.${format}`
2003
- await fs.promises.mkdir(outputDir, { recursive: true })
2004
- const filepath = path.join(outputDir, filename)
2005
- const buffer = this._canvasManager.toBuffer(format, args.quality)
2006
- await fs.promises.writeFile(filepath, buffer)
2007
-
2008
- return {
2009
- success: true,
2010
- filepath,
2011
- filename,
2012
- format,
2013
- size: buffer.length,
2014
- }
2015
- } catch (err) {
2016
- return { success: false, error: err.message }
2017
- }
2018
- },
2019
- },
2020
-
2021
- /**
2022
- * 导出为 Base64
2023
- */
2024
- export_poster_base64: {
2025
- description: '导出画布为 Base64 编码',
2026
- inputSchema: z.object({
2027
- format: z.enum(['png', 'jpg']).optional().describe('格式'),
2028
- quality: z.number().optional().describe('JPEG质量'),
2029
- }),
2030
- execute: async (args) => {
2031
- try {
2032
- if (!this._canvasManager.isCreated()) {
2033
- return { success: false, error: 'No canvas created' }
2034
- }
2035
-
2036
- const format = args.format || 'png'
2037
- const base64 = this._canvasManager.toBase64(format, args.quality)
2038
- const mimeType = format === 'jpg' ? 'image/jpeg' : 'image/png'
2039
-
2040
- return {
2041
- success: true,
2042
- base64,
2043
- format,
2044
- mimeType,
2045
- }
2046
- } catch (err) {
2047
- return { success: false, error: err.message }
2048
- }
2049
- },
2050
- },
2051
- }
2052
-
2053
-
2054
- async install(framework) {
2055
- this._framework = framework
2056
- console.log('[poster] Poster plugin installed (v1.1.0)')
2057
- console.log('[poster] Components:', Object.keys(COMPONENT_TYPES).join(', '))
2058
-
2059
- return this
2060
- }
2061
-
2062
- start(framework) {
2063
- // Object.keys(this.all_tools).map(key=>{
2064
- // this._framework.registerTool({...this.all_tools[key],name:key})
2065
- // })
2066
- console.log('[poster] Poster plugin started')
2067
- }
2068
-
2069
-
2070
- reload(framework) {
2071
- console.log('[poster] Reloading poster plugin')
2072
- this._framework = framework
2073
- }
2074
-
2075
- uninstall(framework) {
2076
- this._canvasManager.reset()
2077
- this._framework = null
2078
- console.log('[poster] Poster plugin uninstalled')
2079
- }
2080
- }
2081
- }