@pinepaper.studio/mcp-server 1.3.0 → 1.3.2

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 (48) hide show
  1. package/dist/taxonomy/classifier.d.ts +74 -0
  2. package/dist/taxonomy/classifier.d.ts.map +1 -0
  3. package/dist/taxonomy/classifier.js +448 -0
  4. package/dist/taxonomy/classifier.js.map +1 -0
  5. package/dist/taxonomy/error-recovery.d.ts +55 -0
  6. package/dist/taxonomy/error-recovery.d.ts.map +1 -0
  7. package/dist/taxonomy/error-recovery.js +205 -0
  8. package/dist/taxonomy/error-recovery.js.map +1 -0
  9. package/dist/taxonomy/index.d.ts +24 -0
  10. package/dist/taxonomy/index.d.ts.map +1 -0
  11. package/dist/taxonomy/index.js +25 -0
  12. package/dist/taxonomy/index.js.map +1 -0
  13. package/dist/taxonomy/matcher.d.ts +104 -0
  14. package/dist/taxonomy/matcher.d.ts.map +1 -0
  15. package/dist/taxonomy/matcher.js +473 -0
  16. package/dist/taxonomy/matcher.js.map +1 -0
  17. package/dist/taxonomy/registry.d.ts +56 -0
  18. package/dist/taxonomy/registry.d.ts.map +1 -0
  19. package/dist/taxonomy/registry.js +950 -0
  20. package/dist/taxonomy/registry.js.map +1 -0
  21. package/dist/taxonomy/types.d.ts +207 -0
  22. package/dist/taxonomy/types.d.ts.map +1 -0
  23. package/dist/taxonomy/types.js +29 -0
  24. package/dist/taxonomy/types.js.map +1 -0
  25. package/dist/tools/definitions.d.ts.map +1 -1
  26. package/dist/tools/definitions.js +266 -0
  27. package/dist/tools/definitions.js.map +1 -1
  28. package/dist/tools/handlers.d.ts.map +1 -1
  29. package/dist/tools/handlers.js +19 -1
  30. package/dist/tools/handlers.js.map +1 -1
  31. package/dist/tools/p5-compat/index.d.ts +8 -0
  32. package/dist/tools/p5-compat/index.d.ts.map +1 -0
  33. package/dist/tools/p5-compat/index.js +8 -0
  34. package/dist/tools/p5-compat/index.js.map +1 -0
  35. package/dist/tools/p5-compat/p5-helpers.d.ts +25 -0
  36. package/dist/tools/p5-compat/p5-helpers.d.ts.map +1 -0
  37. package/dist/tools/p5-compat/p5-helpers.js +399 -0
  38. package/dist/tools/p5-compat/p5-helpers.js.map +1 -0
  39. package/dist/types/code-generator.d.ts +9 -1
  40. package/dist/types/code-generator.d.ts.map +1 -1
  41. package/dist/types/code-generator.js +176 -1
  42. package/dist/types/code-generator.js.map +1 -1
  43. package/dist/types/schemas.d.ts +227 -0
  44. package/dist/types/schemas.d.ts.map +1 -1
  45. package/dist/types/schemas.js +57 -0
  46. package/dist/types/schemas.js.map +1 -1
  47. package/manifest.json +9 -1
  48. package/package.json +1 -1
@@ -0,0 +1,399 @@
1
+ /**
2
+ * p5.js Compatibility Helpers for PinePaper
3
+ *
4
+ * This module provides p5.js-style drawing functions that wrap Paper.js.
5
+ * These helpers are injected into the browser context to allow Claude
6
+ * to use familiar p5.js syntax when drawing on the PinePaper canvas.
7
+ *
8
+ * SUPPORTED FUNCTIONS (v1.3.1):
9
+ * - Shapes: circle, ellipse, rect, line, triangle, quad, arc, point
10
+ * - Style: fill, noFill, stroke, noStroke, strokeWeight, background
11
+ * - Math: random, map, constrain, dist, lerp, radians, degrees
12
+ * - Canvas: width, height
13
+ * - Mode: rectMode, ellipseMode
14
+ * - Constants: PI, TWO_PI, HALF_PI, QUARTER_PI, CENTER, CORNER
15
+ */
16
+ /**
17
+ * Browser-side p5.js compatibility helpers.
18
+ * This code is injected into the PinePaper page context and executed via eval().
19
+ */
20
+ export const P5_HELPERS = `
21
+ (function() {
22
+ // Prevent double-initialization
23
+ if (window._p5Initialized) {
24
+ console.log('[p5-compat] Already initialized');
25
+ return;
26
+ }
27
+
28
+ // ==========================================================================
29
+ // STATE MANAGEMENT
30
+ // ==========================================================================
31
+
32
+ window._p5State = {
33
+ fillColor: '#ffffff',
34
+ strokeColor: '#000000',
35
+ strokeWidth: 1,
36
+ rectMode: 'corner',
37
+ ellipseMode: 'center'
38
+ };
39
+
40
+ // ==========================================================================
41
+ // CONSTANTS
42
+ // ==========================================================================
43
+
44
+ window.PI = Math.PI;
45
+ window.TWO_PI = Math.PI * 2;
46
+ window.HALF_PI = Math.PI / 2;
47
+ window.QUARTER_PI = Math.PI / 4;
48
+
49
+ window.CENTER = 'center';
50
+ window.CORNER = 'corner';
51
+
52
+ // ==========================================================================
53
+ // CANVAS PROPERTIES
54
+ // ==========================================================================
55
+
56
+ Object.defineProperty(window, 'width', {
57
+ get: function() {
58
+ return paper.view ? paper.view.size.width : 800;
59
+ },
60
+ configurable: true
61
+ });
62
+
63
+ Object.defineProperty(window, 'height', {
64
+ get: function() {
65
+ return paper.view ? paper.view.size.height : 600;
66
+ },
67
+ configurable: true
68
+ });
69
+
70
+ // ==========================================================================
71
+ // MATH UTILITIES
72
+ // ==========================================================================
73
+
74
+ window.random = function(min, max) {
75
+ if (arguments.length === 0) {
76
+ return Math.random();
77
+ } else if (arguments.length === 1) {
78
+ if (Array.isArray(min)) {
79
+ // random(array) - return random element
80
+ return min[Math.floor(Math.random() * min.length)];
81
+ }
82
+ // random(max) - return 0 to max
83
+ return Math.random() * min;
84
+ } else {
85
+ // random(min, max)
86
+ return Math.random() * (max - min) + min;
87
+ }
88
+ };
89
+
90
+ window.map = function(value, start1, stop1, start2, stop2) {
91
+ return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1));
92
+ };
93
+
94
+ window.constrain = function(value, min, max) {
95
+ return Math.min(Math.max(value, min), max);
96
+ };
97
+
98
+ window.dist = function(x1, y1, x2, y2) {
99
+ return Math.sqrt((x2 - x1) * (x2 - x1) + (y2 - y1) * (y2 - y1));
100
+ };
101
+
102
+ window.lerp = function(start, stop, amount) {
103
+ return start + (stop - start) * amount;
104
+ };
105
+
106
+ window.radians = function(degrees) {
107
+ return degrees * Math.PI / 180;
108
+ };
109
+
110
+ window.degrees = function(radians) {
111
+ return radians * 180 / Math.PI;
112
+ };
113
+
114
+ // ==========================================================================
115
+ // STYLE FUNCTIONS
116
+ // ==========================================================================
117
+
118
+ /**
119
+ * Parse color arguments into a valid color string.
120
+ * Supports: fill(gray), fill(r,g,b), fill(r,g,b,a), fill('#hex')
121
+ */
122
+ function parseColor(args) {
123
+ if (args.length === 0) return null;
124
+
125
+ if (args.length === 1) {
126
+ var val = args[0];
127
+ if (typeof val === 'string') {
128
+ return val;
129
+ } else if (typeof val === 'number') {
130
+ // Grayscale
131
+ return 'rgb(' + val + ', ' + val + ', ' + val + ')';
132
+ }
133
+ } else if (args.length === 3) {
134
+ // RGB
135
+ return 'rgb(' + args[0] + ', ' + args[1] + ', ' + args[2] + ')';
136
+ } else if (args.length === 4) {
137
+ // RGBA (p5 uses 0-255 for alpha, CSS uses 0-1)
138
+ return 'rgba(' + args[0] + ', ' + args[1] + ', ' + args[2] + ', ' + (args[3] / 255) + ')';
139
+ }
140
+
141
+ return null;
142
+ }
143
+
144
+ window.fill = function() {
145
+ var color = parseColor(Array.prototype.slice.call(arguments));
146
+ window._p5State.fillColor = color;
147
+ };
148
+
149
+ window.noFill = function() {
150
+ window._p5State.fillColor = null;
151
+ };
152
+
153
+ window.stroke = function() {
154
+ var color = parseColor(Array.prototype.slice.call(arguments));
155
+ window._p5State.strokeColor = color;
156
+ };
157
+
158
+ window.noStroke = function() {
159
+ window._p5State.strokeColor = null;
160
+ };
161
+
162
+ window.strokeWeight = function(weight) {
163
+ window._p5State.strokeWidth = weight;
164
+ };
165
+
166
+ window.background = function() {
167
+ var color = parseColor(Array.prototype.slice.call(arguments));
168
+ if (color && typeof app !== 'undefined' && app.setBackgroundColor) {
169
+ app.setBackgroundColor(color);
170
+ }
171
+ };
172
+
173
+ // ==========================================================================
174
+ // MODE FUNCTIONS
175
+ // ==========================================================================
176
+
177
+ window.rectMode = function(mode) {
178
+ window._p5State.rectMode = mode.toLowerCase();
179
+ };
180
+
181
+ window.ellipseMode = function(mode) {
182
+ window._p5State.ellipseMode = mode.toLowerCase();
183
+ };
184
+
185
+ // ==========================================================================
186
+ // SHAPE FUNCTIONS
187
+ // ==========================================================================
188
+
189
+ /**
190
+ * Apply current style state to an item
191
+ */
192
+ function applyStyle(item) {
193
+ if (window._p5State.fillColor) {
194
+ item.fillColor = window._p5State.fillColor;
195
+ }
196
+ if (window._p5State.strokeColor) {
197
+ item.strokeColor = window._p5State.strokeColor;
198
+ item.strokeWidth = window._p5State.strokeWidth;
199
+ }
200
+ }
201
+
202
+ /**
203
+ * Register item with PinePaper's ItemRegistry
204
+ */
205
+ function registerItem(item, type) {
206
+ if (typeof app !== 'undefined' && app.registerItem) {
207
+ app.registerItem(item, type, { source: 'p5' });
208
+ }
209
+ return item;
210
+ }
211
+
212
+ /**
213
+ * Draw a circle
214
+ * circle(x, y, diameter)
215
+ */
216
+ window.circle = function(x, y, d) {
217
+ var item = new paper.Path.Circle({
218
+ center: [x, y],
219
+ radius: d / 2
220
+ });
221
+ applyStyle(item);
222
+ return registerItem(item, 'circle');
223
+ };
224
+
225
+ /**
226
+ * Draw an ellipse
227
+ * ellipse(x, y, width, [height])
228
+ */
229
+ window.ellipse = function(x, y, w, h) {
230
+ h = h !== undefined ? h : w;
231
+ var mode = window._p5State.ellipseMode;
232
+ var center = mode === 'center' ? [x, y] : [x + w / 2, y + h / 2];
233
+
234
+ var item = new paper.Path.Ellipse({
235
+ center: center,
236
+ size: [w, h]
237
+ });
238
+ applyStyle(item);
239
+ return registerItem(item, 'ellipse');
240
+ };
241
+
242
+ /**
243
+ * Draw a rectangle
244
+ * rect(x, y, width, height, [cornerRadius])
245
+ */
246
+ window.rect = function(x, y, w, h, r) {
247
+ var mode = window._p5State.rectMode;
248
+ var point = mode === 'center' ? [x - w / 2, y - h / 2] : [x, y];
249
+
250
+ var options = {
251
+ point: point,
252
+ size: [w, h]
253
+ };
254
+
255
+ if (r !== undefined && r > 0) {
256
+ options.radius = r;
257
+ }
258
+
259
+ var item = new paper.Path.Rectangle(options);
260
+ applyStyle(item);
261
+ return registerItem(item, 'rectangle');
262
+ };
263
+
264
+ /**
265
+ * Draw a line
266
+ * line(x1, y1, x2, y2)
267
+ */
268
+ window.line = function(x1, y1, x2, y2) {
269
+ var item = new paper.Path.Line({
270
+ from: [x1, y1],
271
+ to: [x2, y2]
272
+ });
273
+ // Lines typically don't have fill
274
+ if (window._p5State.strokeColor) {
275
+ item.strokeColor = window._p5State.strokeColor;
276
+ item.strokeWidth = window._p5State.strokeWidth;
277
+ }
278
+ return registerItem(item, 'line');
279
+ };
280
+
281
+ /**
282
+ * Draw a triangle
283
+ * triangle(x1, y1, x2, y2, x3, y3)
284
+ */
285
+ window.triangle = function(x1, y1, x2, y2, x3, y3) {
286
+ var item = new paper.Path({
287
+ segments: [[x1, y1], [x2, y2], [x3, y3]],
288
+ closed: true
289
+ });
290
+ applyStyle(item);
291
+ return registerItem(item, 'triangle');
292
+ };
293
+
294
+ /**
295
+ * Draw a quadrilateral
296
+ * quad(x1, y1, x2, y2, x3, y3, x4, y4)
297
+ */
298
+ window.quad = function(x1, y1, x2, y2, x3, y3, x4, y4) {
299
+ var item = new paper.Path({
300
+ segments: [[x1, y1], [x2, y2], [x3, y3], [x4, y4]],
301
+ closed: true
302
+ });
303
+ applyStyle(item);
304
+ return registerItem(item, 'quad');
305
+ };
306
+
307
+ /**
308
+ * Draw an arc
309
+ * arc(x, y, width, height, startAngle, stopAngle)
310
+ * Note: p5.js uses radians by default
311
+ */
312
+ window.arc = function(x, y, w, h, start, stop) {
313
+ // Calculate the arc using Paper.js
314
+ var cx = x;
315
+ var cy = y;
316
+ var rx = w / 2;
317
+ var ry = h / 2;
318
+
319
+ // Convert from p5's angle system to Paper.js
320
+ // p5 uses radians where 0 is right, PI/2 is down
321
+ var startDeg = start * 180 / Math.PI;
322
+ var stopDeg = stop * 180 / Math.PI;
323
+
324
+ // Create arc using path segments
325
+ var item = new paper.Path.Arc({
326
+ from: [
327
+ cx + rx * Math.cos(start),
328
+ cy + ry * Math.sin(start)
329
+ ],
330
+ through: [
331
+ cx + rx * Math.cos((start + stop) / 2),
332
+ cy + ry * Math.sin((start + stop) / 2)
333
+ ],
334
+ to: [
335
+ cx + rx * Math.cos(stop),
336
+ cy + ry * Math.sin(stop)
337
+ ]
338
+ });
339
+
340
+ applyStyle(item);
341
+ return registerItem(item, 'arc');
342
+ };
343
+
344
+ /**
345
+ * Draw a point (tiny circle)
346
+ * point(x, y)
347
+ */
348
+ window.point = function(x, y) {
349
+ var size = window._p5State.strokeWidth || 1;
350
+ var item = new paper.Path.Circle({
351
+ center: [x, y],
352
+ radius: size / 2
353
+ });
354
+ // Points use stroke color as fill
355
+ if (window._p5State.strokeColor) {
356
+ item.fillColor = window._p5State.strokeColor;
357
+ }
358
+ return registerItem(item, 'point');
359
+ };
360
+
361
+ // ==========================================================================
362
+ // INITIALIZATION COMPLETE
363
+ // ==========================================================================
364
+
365
+ window._p5Initialized = true;
366
+ console.log('[p5-compat] p5.js compatibility layer loaded (v1.3.1)');
367
+ console.log('[p5-compat] Available: circle, ellipse, rect, line, triangle, quad, arc, point');
368
+ console.log('[p5-compat] Style: fill, noFill, stroke, noStroke, strokeWeight, background');
369
+ console.log('[p5-compat] Math: random, map, constrain, dist, lerp, radians, degrees');
370
+ })();
371
+ `;
372
+ /**
373
+ * Generate code that initializes p5 helpers and executes user code
374
+ */
375
+ export function generateP5DrawCode(userCode) {
376
+ return `
377
+ // Initialize p5.js compatibility layer if not already loaded
378
+ if (!window._p5Initialized) {
379
+ ${P5_HELPERS}
380
+ }
381
+
382
+ // Execute user's p5.js-style code
383
+ (function() {
384
+ try {
385
+ ${userCode}
386
+
387
+ // Save history state after drawing
388
+ if (typeof app !== 'undefined' && app.historyManager) {
389
+ app.historyManager.saveState();
390
+ }
391
+
392
+ return { success: true, message: 'p5.js code executed successfully' };
393
+ } catch (error) {
394
+ return { success: false, error: error.message };
395
+ }
396
+ })();
397
+ `;
398
+ }
399
+ //# sourceMappingURL=p5-helpers.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"p5-helpers.js","sourceRoot":"","sources":["../../../src/tools/p5-compat/p5-helpers.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AAEH;;;GAGG;AACH,MAAM,CAAC,MAAM,UAAU,GAAG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA+VzB,CAAC;AAEF;;GAEG;AACH,MAAM,UAAU,kBAAkB,CAAC,QAAgB;IACjD,OAAO;;;IAGL,UAAU;;;;;;MAMR,QAAQ;;;;;;;;;;;;CAYb,CAAC;AACF,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * Converts MCP tool inputs to executable PinePaper JavaScript code.
5
5
  * This code is designed to run in the browser context where window.PinePaper is available.
6
6
  */
7
- import { ItemType, RelationType, CreateItemInputSchema, ModifyItemInputSchema, AddRelationInputSchema, AnimateItemInputSchema, KeyframeAnimateInputSchema, ExecuteGeneratorInputSchema, ApplyEffectInputSchema, SetBackgroundColorInputSchema, SetCanvasSizeInputSchema, CreateGlossySphereInputSchema, CreateDiagonalStripesInputSchema, BatchCreateInputSchema, BatchModifyInputSchema, CreateGridInputSchema } from './schemas.js';
7
+ import { ItemType, RelationType, CreateItemInputSchema, ModifyItemInputSchema, AddRelationInputSchema, AnimateItemInputSchema, KeyframeAnimateInputSchema, ExecuteGeneratorInputSchema, ApplyEffectInputSchema, SetBackgroundColorInputSchema, SetCanvasSizeInputSchema, CreateGlossySphereInputSchema, CreateDiagonalStripesInputSchema, BatchCreateInputSchema, BatchModifyInputSchema, CreateGridInputSchema, CreateSceneInput } from './schemas.js';
8
8
  import { z } from 'zod';
9
9
  export declare class PinePaperCodeGenerator {
10
10
  /**
@@ -123,6 +123,14 @@ export declare class PinePaperCodeGenerator {
123
123
  * Generate code for creating a grid
124
124
  */
125
125
  generateCreateGrid(input: z.infer<typeof CreateGridInputSchema>): string;
126
+ /**
127
+ * Generate code for executing p5.js-style drawing code
128
+ */
129
+ generateP5Draw(code: string): string;
130
+ /**
131
+ * Generate code for creating a complete scene with items, relations, and animations
132
+ */
133
+ generateCreateScene(input: CreateSceneInput): string;
126
134
  }
127
135
  export declare const codeGenerator: PinePaperCodeGenerator;
128
136
  //# sourceMappingURL=code-generator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"code-generator.d.ts","sourceRoot":"","sources":["../../src/types/code-generator.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EACL,QAAQ,EAER,YAAY,EAEZ,qBAAqB,EACrB,qBAAqB,EACrB,sBAAsB,EACtB,sBAAsB,EACtB,0BAA0B,EAC1B,2BAA2B,EAC3B,sBAAsB,EACtB,6BAA6B,EAC7B,wBAAwB,EAExB,6BAA6B,EAC7B,gCAAgC,EAGhC,sBAAsB,EACtB,sBAAsB,EACtB,qBAAqB,EAGtB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAirBxB,qBAAa,sBAAsB;IACjC;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAAG,MAAM;IASxE;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAAG,MAAM;IAQxE;;OAEG;IACH,kBAAkB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;IAI1C;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE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GAAG,CAAC,EAAE,MAAM,EACZ,QAAQ,GAAE;QAAE,CAAC,EAAE,MAAM,CAAC;QAAC,CAAC,EAAE,MAAM,CAAA;KAAuB,EACvD,KAAK,GAAE,MAAY,GAClB,MAAM;IA4CT;;OAEG;IACH,iBAAiB,CACf,UAAU,EAAE,MAAM,EAClB,MAAM,GAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAM,GACnC,MAAM;IAQT;;OAEG;IACH,0BAA0B,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,6BAA6B,CAAC,GAAG,MAAM;IA0FxF;;OAEG;IACH,6BAA6B,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,gCAAgC,CAAC,GAAG,MAAM;IAyD9F;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,GAAG,MAAM;IAK1E;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,sBAAsB,CAAC,GAAG,MAAM;IAK1E;;OAEG;IACH,kBAAkB,CAAC,KAAK,EAAE,CAAC,CAAC,KAAK,CAAC,OAAO,qBAAqB,CAAC,GAAG,MAAM;IAaxE;;OAEG;IACH,cAAc,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM;IAMpC;;OAEG;IACH,mBAAmB,CAAC,KAAK,EAAE,gBAAgB,GAAG,MAAM;CA0LrD;AAGD,eAAO,MAAM,aAAa,wBAA+B,CAAC"}
@@ -4,7 +4,7 @@
4
4
  * Converts MCP tool inputs to executable PinePaper JavaScript code.
5
5
  * This code is designed to run in the browser context where window.PinePaper is available.
6
6
  */
7
- import { CreateItemInputSchema, ModifyItemInputSchema, AddRelationInputSchema, AnimateItemInputSchema, KeyframeAnimateInputSchema, ExecuteGeneratorInputSchema, ApplyEffectInputSchema, SetBackgroundColorInputSchema, SetCanvasSizeInputSchema, CreateGlossySphereInputSchema, CreateDiagonalStripesInputSchema, BatchCreateInputSchema, BatchModifyInputSchema, CreateGridInputSchema, } from './schemas.js';
7
+ import { CreateItemInputSchema, ModifyItemInputSchema, AddRelationInputSchema, AnimateItemInputSchema, KeyframeAnimateInputSchema, ExecuteGeneratorInputSchema, ApplyEffectInputSchema, SetBackgroundColorInputSchema, SetCanvasSizeInputSchema, CreateGlossySphereInputSchema, CreateDiagonalStripesInputSchema, BatchCreateInputSchema, BatchModifyInputSchema, CreateGridInputSchema, CreateSceneInputSchema, } from './schemas.js';
8
8
  // =============================================================================
9
9
  // HELPER FUNCTIONS
10
10
  // =============================================================================
@@ -909,6 +909,181 @@ app.historyManager.saveState();
909
909
  const validated = CreateGridInputSchema.parse(input);
910
910
  return generateCreateGridCode(validated.cols, validated.rows, validated.strokeColor, validated.strokeWidth, validated.animated, validated.waveSpeed, validated.waveAmplitude);
911
911
  }
912
+ /**
913
+ * Generate code for executing p5.js-style drawing code
914
+ */
915
+ generateP5Draw(code) {
916
+ // Import the p5 helpers generator
917
+ const { generateP5DrawCode } = require('../tools/p5-compat/p5-helpers.js');
918
+ return generateP5DrawCode(code);
919
+ }
920
+ /**
921
+ * Generate code for creating a complete scene with items, relations, and animations
922
+ */
923
+ generateCreateScene(input) {
924
+ const validated = CreateSceneInputSchema.parse(input);
925
+ const { items, relations = [], animations = [], backgroundColor, backgroundGenerator, clearFirst = true, } = validated;
926
+ const codeParts = [];
927
+ // Start with a comment
928
+ codeParts.push('// Create complete scene');
929
+ codeParts.push('const nameToId = {};');
930
+ codeParts.push('const results = { items: [], relations: [], animations: [] };');
931
+ // Clear canvas if requested
932
+ if (clearFirst) {
933
+ codeParts.push(`
934
+ // Clear canvas
935
+ (function() {
936
+ const items = app.itemRegistry.getAll();
937
+ items.forEach(item => {
938
+ try { item.remove(); } catch(e) {}
939
+ });
940
+ app.itemRegistry.clear();
941
+ })();
942
+ `);
943
+ }
944
+ // Set background color if provided
945
+ if (backgroundColor) {
946
+ codeParts.push(`
947
+ // Set background color
948
+ paper.project.activeLayer.children.forEach(c => {
949
+ if (c.name === 'background') c.remove();
950
+ });
951
+ const bg = new paper.Path.Rectangle({
952
+ point: [0, 0],
953
+ size: [paper.view.size.width, paper.view.size.height],
954
+ fillColor: '${backgroundColor}',
955
+ name: 'background'
956
+ });
957
+ bg.sendToBack();
958
+ `);
959
+ }
960
+ // Execute background generator if provided
961
+ if (backgroundGenerator) {
962
+ codeParts.push(`
963
+ // Execute background generator
964
+ if (typeof app.generators !== 'undefined' && app.generators['${backgroundGenerator}']) {
965
+ app.generators['${backgroundGenerator}']();
966
+ }
967
+ `);
968
+ }
969
+ // Create all items
970
+ for (const item of items) {
971
+ const { name, itemType, position = { x: 400, y: 300 }, properties = {} } = item;
972
+ // Build properties string
973
+ const propsEntries = Object.entries(properties)
974
+ .map(([key, value]) => `${key}: ${JSON.stringify(value)}`)
975
+ .join(', ');
976
+ const propsStr = propsEntries ? `, ${propsEntries}` : '';
977
+ codeParts.push(`
978
+ // Create item: ${name}
979
+ (function() {
980
+ const itemParams = {
981
+ type: '${itemType}',
982
+ position: { x: ${position.x}, y: ${position.y} }${propsStr}
983
+ };
984
+
985
+ let item;
986
+ switch ('${itemType}') {
987
+ case 'circle':
988
+ item = new paper.Path.Circle({
989
+ center: [${position.x}, ${position.y}],
990
+ radius: ${properties.radius || 50},
991
+ fillColor: '${properties.color || properties.fillColor || '#3b82f6'}',
992
+ parent: app.textItemGroup
993
+ });
994
+ break;
995
+ case 'rectangle':
996
+ item = new paper.Path.Rectangle({
997
+ point: [${position.x - (properties.width || 100) / 2}, ${position.y - (properties.height || 60) / 2}],
998
+ size: [${properties.width || 100}, ${properties.height || 60}],
999
+ fillColor: '${properties.color || properties.fillColor || '#3b82f6'}',
1000
+ parent: app.textItemGroup
1001
+ });
1002
+ break;
1003
+ case 'star':
1004
+ item = new paper.Path.Star({
1005
+ center: [${position.x}, ${position.y}],
1006
+ points: ${properties.points || 5},
1007
+ radius1: ${properties.radius1 || 40},
1008
+ radius2: ${properties.radius2 || 20},
1009
+ fillColor: '${properties.color || properties.fillColor || '#fbbf24'}',
1010
+ parent: app.textItemGroup
1011
+ });
1012
+ break;
1013
+ case 'text':
1014
+ item = new paper.PointText({
1015
+ point: [${position.x}, ${position.y}],
1016
+ content: '${properties.content || 'Text'}',
1017
+ fontSize: ${properties.fontSize || 24},
1018
+ fillColor: '${properties.color || properties.fillColor || '#ffffff'}',
1019
+ fontFamily: '${properties.fontFamily || 'Inter'}',
1020
+ justification: 'center',
1021
+ parent: app.textItemGroup
1022
+ });
1023
+ break;
1024
+ default:
1025
+ item = new paper.Path.Circle({
1026
+ center: [${position.x}, ${position.y}],
1027
+ radius: 30,
1028
+ fillColor: '${properties.color || properties.fillColor || '#3b82f6'}',
1029
+ parent: app.textItemGroup
1030
+ });
1031
+ }
1032
+
1033
+ const itemId = app.registerItem(item, '${name}', { source: 'mcp-scene' });
1034
+ nameToId['${name}'] = itemId;
1035
+ results.items.push({ name: '${name}', itemId, type: '${itemType}' });
1036
+ })();
1037
+ `);
1038
+ }
1039
+ // Establish relations
1040
+ for (const relation of relations) {
1041
+ const { source, target, type, params = {} } = relation;
1042
+ const paramsStr = JSON.stringify(params);
1043
+ codeParts.push(`
1044
+ // Add relation: ${source} ${type} ${target}
1045
+ (function() {
1046
+ const sourceId = nameToId['${source}'];
1047
+ const targetId = nameToId['${target}'];
1048
+ if (sourceId && targetId) {
1049
+ const sourceItem = app.itemRegistry.get(sourceId);
1050
+ const targetItem = app.itemRegistry.get(targetId);
1051
+ if (sourceItem && targetItem) {
1052
+ const params = ${paramsStr};
1053
+ app.relationManager.addRelation(sourceItem, targetItem, '${type}', params);
1054
+ results.relations.push({ source: '${source}', target: '${target}', type: '${type}' });
1055
+ }
1056
+ }
1057
+ })();
1058
+ `);
1059
+ }
1060
+ // Apply animations
1061
+ for (const animation of animations) {
1062
+ const { target, type, speed = 1.0, params = {} } = animation;
1063
+ const paramsStr = JSON.stringify({ ...params, speed });
1064
+ codeParts.push(`
1065
+ // Apply animation: ${type} to ${target}
1066
+ (function() {
1067
+ const targetId = nameToId['${target}'];
1068
+ if (targetId) {
1069
+ const targetItem = app.itemRegistry.get(targetId);
1070
+ if (targetItem) {
1071
+ const params = ${paramsStr};
1072
+ app.animationManager.addAnimation(targetItem, '${type}', params);
1073
+ results.animations.push({ target: '${target}', type: '${type}' });
1074
+ }
1075
+ }
1076
+ })();
1077
+ `);
1078
+ }
1079
+ // Save history and return results
1080
+ codeParts.push(`
1081
+ // Save history and return results
1082
+ app.historyManager.saveState();
1083
+ results;
1084
+ `);
1085
+ return codeParts.join('\n');
1086
+ }
912
1087
  }
913
1088
  // Export singleton instance
914
1089
  export const codeGenerator = new PinePaperCodeGenerator();