@genfeedai/workflow-ui 0.1.2 → 0.1.4

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 (84) hide show
  1. package/dist/canvas.d.mts +16 -2
  2. package/dist/canvas.mjs +10 -8
  3. package/dist/chunk-6PSJTBNV.mjs +638 -0
  4. package/dist/chunk-7H3WJJYS.mjs +52 -0
  5. package/dist/{chunk-HCXI63ME.mjs → chunk-AUQGOJOQ.mjs} +27 -4
  6. package/dist/{chunk-AOTUCJMA.mjs → chunk-GWBGK3KL.mjs} +2 -2
  7. package/dist/chunk-JTPADIUO.mjs +130 -0
  8. package/dist/{chunk-SQK4JDYY.mjs → chunk-LT3ZJJL6.mjs} +9 -2
  9. package/dist/{chunk-7P2JWDC7.mjs → chunk-O5II6BOJ.mjs} +1198 -254
  10. package/dist/{chunk-AUZR6REQ.mjs → chunk-OQREHJXK.mjs} +1 -1
  11. package/dist/chunk-OY7BRSGG.mjs +60 -0
  12. package/dist/{chunk-E3YBVMYZ.mjs → chunk-PANZDSP6.mjs} +274 -305
  13. package/dist/chunk-PCIWWD37.mjs +90 -0
  14. package/dist/{chunk-RIGVIEYB.mjs → chunk-R727OFBR.mjs} +11 -1
  15. package/dist/chunk-ZD2BADZO.mjs +1294 -0
  16. package/dist/contextMenuStore-DMg0hJQ1.d.mts +22 -0
  17. package/dist/hooks.d.mts +53 -244
  18. package/dist/hooks.mjs +6 -6
  19. package/dist/index.d.mts +11 -7
  20. package/dist/index.mjs +13 -11
  21. package/dist/lib.d.mts +250 -4
  22. package/dist/lib.mjs +562 -2
  23. package/dist/nodes.d.mts +3 -1
  24. package/dist/nodes.mjs +6 -6
  25. package/dist/panels.mjs +3 -4
  26. package/dist/{promptLibraryStore-zqb59nsu.d.mts → promptLibraryStore-Bgw5LzvD.d.mts} +33 -5
  27. package/dist/provider.d.mts +2 -2
  28. package/dist/provider.mjs +0 -1
  29. package/dist/stores.d.mts +4 -3
  30. package/dist/stores.mjs +3 -40
  31. package/dist/toolbar.d.mts +3 -1
  32. package/dist/toolbar.mjs +5 -4
  33. package/dist/{types-ipAnBzAJ.d.mts → types-CF6DPx0P.d.mts} +8 -3
  34. package/dist/ui.d.mts +1 -1
  35. package/dist/ui.mjs +0 -1
  36. package/dist/{hooks.d.ts → useCommentNavigation-NzJjkaj2.d.mts} +15 -2
  37. package/dist/workflowStore-UAAKOOIK.mjs +2 -0
  38. package/package.json +32 -26
  39. package/dist/canvas.d.ts +0 -27
  40. package/dist/canvas.js +0 -45
  41. package/dist/chunk-3SPPKCWR.js +0 -458
  42. package/dist/chunk-3TMV3K34.js +0 -534
  43. package/dist/chunk-3YFFDHC5.js +0 -300
  44. package/dist/chunk-4MZ62VMF.js +0 -37
  45. package/dist/chunk-5HJFQVUR.js +0 -61
  46. package/dist/chunk-5LQ4QBR5.js +0 -2
  47. package/dist/chunk-6DOEUDD5.js +0 -254
  48. package/dist/chunk-AXFOCPPP.js +0 -998
  49. package/dist/chunk-BMFRA6GK.js +0 -1546
  50. package/dist/chunk-E323WAZG.mjs +0 -272
  51. package/dist/chunk-ECD5J2BA.js +0 -6022
  52. package/dist/chunk-EMGXUNBL.js +0 -120
  53. package/dist/chunk-EMUMKW5C.js +0 -107
  54. package/dist/chunk-FOMOOERN.js +0 -2
  55. package/dist/chunk-IASLG6IA.mjs +0 -118
  56. package/dist/chunk-IHF35QZD.js +0 -1095
  57. package/dist/chunk-JLWKW3G5.js +0 -2
  58. package/dist/chunk-KDIWRSYV.js +0 -375
  59. package/dist/chunk-L5TF4EHW.mjs +0 -1
  60. package/dist/chunk-RJ262NXS.js +0 -24
  61. package/dist/chunk-RXNEDWK2.js +0 -141
  62. package/dist/chunk-SEV2DWKF.js +0 -744
  63. package/dist/chunk-ZJWP5KGZ.mjs +0 -33
  64. package/dist/hooks.js +0 -56
  65. package/dist/index.d.ts +0 -29
  66. package/dist/index.js +0 -180
  67. package/dist/lib.d.ts +0 -164
  68. package/dist/lib.js +0 -144
  69. package/dist/nodes.d.ts +0 -128
  70. package/dist/nodes.js +0 -151
  71. package/dist/panels.d.ts +0 -22
  72. package/dist/panels.js +0 -21
  73. package/dist/promptLibraryStore-BZnfmEkc.d.ts +0 -464
  74. package/dist/provider.d.ts +0 -29
  75. package/dist/provider.js +0 -17
  76. package/dist/stores.d.ts +0 -96
  77. package/dist/stores.js +0 -113
  78. package/dist/toolbar.d.ts +0 -73
  79. package/dist/toolbar.js +0 -34
  80. package/dist/types-ipAnBzAJ.d.ts +0 -46
  81. package/dist/ui.d.ts +0 -67
  82. package/dist/ui.js +0 -84
  83. package/dist/workflowStore-7SDJC4UR.mjs +0 -3
  84. package/dist/workflowStore-LNJQ5RZG.js +0 -12
@@ -1,300 +0,0 @@
1
- 'use strict';
2
-
3
- // src/lib/mediaExtraction.ts
4
- function getMediaFromNode(nodeType, data) {
5
- switch (nodeType) {
6
- case "imageGen": {
7
- const imgData = data;
8
- const urls = imgData.outputImages?.length ? imgData.outputImages : [];
9
- return {
10
- url: imgData.outputImage,
11
- urls,
12
- type: imgData.outputImage || urls.length ? "image" : null
13
- };
14
- }
15
- case "videoGen": {
16
- const vidData = data;
17
- return { url: vidData.outputVideo, type: vidData.outputVideo ? "video" : null };
18
- }
19
- case "imageInput": {
20
- const inputData = data;
21
- return { url: inputData.image, type: inputData.image ? "image" : null };
22
- }
23
- case "videoInput": {
24
- const vidInputData = data;
25
- return { url: vidInputData.video, type: vidInputData.video ? "video" : null };
26
- }
27
- case "motionControl": {
28
- const mcData = data;
29
- return { url: mcData.outputVideo, type: mcData.outputVideo ? "video" : null };
30
- }
31
- case "download": {
32
- const outData = data;
33
- if (outData.inputVideo) {
34
- return { url: outData.inputVideo, type: "video" };
35
- }
36
- if (outData.inputImage) {
37
- return { url: outData.inputImage, type: "image" };
38
- }
39
- return { url: null, type: null };
40
- }
41
- default:
42
- return { url: null, type: null };
43
- }
44
- }
45
-
46
- // src/lib/schemaHandles.ts
47
- var HANDLE_FIELDS = /* @__PURE__ */ new Set([
48
- // Text inputs
49
- "prompt",
50
- "negative_prompt",
51
- "subject_reference",
52
- // Image inputs (single)
53
- "image",
54
- "image_input",
55
- "start_image",
56
- "first_frame_image",
57
- "end_image",
58
- "last_frame",
59
- "mask",
60
- "mask_image",
61
- "control_image",
62
- "init_image",
63
- "subject_image",
64
- "face_image",
65
- "style_image",
66
- "pose_image",
67
- "image_url",
68
- "tail_image_url",
69
- // Image inputs (array)
70
- "reference_images",
71
- // Video inputs
72
- "video",
73
- "video_url",
74
- // Audio inputs
75
- "audio",
76
- "audio_url"
77
- ]);
78
- var FIELD_TO_HANDLE_TYPE = {
79
- // Text fields
80
- prompt: "text",
81
- negative_prompt: "text",
82
- subject_reference: "text",
83
- // Image fields (single)
84
- image: "image",
85
- image_input: "image",
86
- start_image: "image",
87
- first_frame_image: "image",
88
- end_image: "image",
89
- last_frame: "image",
90
- mask: "image",
91
- mask_image: "image",
92
- control_image: "image",
93
- init_image: "image",
94
- subject_image: "image",
95
- face_image: "image",
96
- style_image: "image",
97
- pose_image: "image",
98
- image_url: "image",
99
- tail_image_url: "image",
100
- // Image fields (array)
101
- reference_images: "image",
102
- // Video fields
103
- video: "video",
104
- video_url: "video",
105
- // Audio fields
106
- audio: "audio",
107
- audio_url: "audio"
108
- };
109
- function generateHandlesFromSchema(inputSchema, staticHandles) {
110
- if (!inputSchema) return staticHandles;
111
- const schema = inputSchema;
112
- if (!schema.properties) return staticHandles;
113
- const staticIds = new Set(staticHandles.map((h) => h.id));
114
- const dynamicHandles = [];
115
- for (const [fieldName, prop] of Object.entries(schema.properties)) {
116
- if (!HANDLE_FIELDS.has(fieldName) || staticIds.has(fieldName)) continue;
117
- const handleType = FIELD_TO_HANDLE_TYPE[fieldName];
118
- if (!handleType) continue;
119
- const label = prop.title || fieldName.replace(/_/g, " ").replace(/\b\w/g, (c) => c.toUpperCase());
120
- dynamicHandles.push({
121
- id: fieldName,
122
- type: handleType,
123
- label,
124
- multiple: prop.type === "array",
125
- required: schema.required?.includes(fieldName),
126
- fromSchema: true
127
- });
128
- }
129
- return [...staticHandles, ...dynamicHandles];
130
- }
131
- function isSchemaHandle(handle) {
132
- return handle.fromSchema === true;
133
- }
134
-
135
- // src/lib/models/registry.ts
136
- var IMAGE_MODELS = [
137
- { value: "nano-banana", label: "Nano Banana", apiId: "google/nano-banana" },
138
- { value: "nano-banana-pro", label: "Nano Banana Pro", apiId: "google/nano-banana-pro" }
139
- ];
140
- var IMAGE_MODEL_MAP = Object.fromEntries(
141
- IMAGE_MODELS.map((m) => [m.apiId, m.value])
142
- );
143
- var IMAGE_MODEL_ID_MAP = Object.fromEntries(
144
- IMAGE_MODELS.map((m) => [m.value, m.apiId])
145
- );
146
- var DEFAULT_IMAGE_MODEL = "nano-banana-pro";
147
- var VIDEO_MODELS = [
148
- {
149
- value: "veo-3.1-fast",
150
- label: "Veo 3.1 Fast",
151
- description: "Fast",
152
- apiId: "google/veo-3.1-fast"
153
- },
154
- { value: "veo-3.1", label: "Veo 3.1", description: "High quality", apiId: "google/veo-3.1" }
155
- ];
156
- var VIDEO_MODEL_MAP = Object.fromEntries(
157
- VIDEO_MODELS.map((m) => [m.apiId, m.value])
158
- );
159
- var VIDEO_MODEL_ID_MAP = Object.fromEntries(
160
- VIDEO_MODELS.map((m) => [m.value, m.apiId])
161
- );
162
- var DEFAULT_VIDEO_MODEL = "veo-3.1-fast";
163
- var LIPSYNC_MODELS = [
164
- { value: "bytedance/omni-human", label: "OmniHuman (Image)", supportsImage: true },
165
- { value: "veed/fabric-1.0", label: "VEED Fabric (Image)", supportsImage: true },
166
- { value: "sync/lipsync-2-pro", label: "Sync Labs Pro (Video)", supportsImage: false },
167
- { value: "sync/lipsync-2", label: "Sync Labs (Video)", supportsImage: false },
168
- { value: "pixverse/lipsync", label: "Pixverse", supportsImage: true }
169
- ];
170
- var LIPSYNC_SYNC_MODES = [
171
- { value: "loop", label: "Loop" },
172
- { value: "bounce", label: "Bounce" },
173
- { value: "cut_off", label: "Cut Off" },
174
- { value: "silence", label: "Silence" },
175
- { value: "remap", label: "Remap" }
176
- ];
177
- var DEFAULT_LIPSYNC_MODEL = "bytedance/omni-human";
178
- var LLM_MODELS = [
179
- {
180
- value: "meta-llama-3.1-405b-instruct",
181
- label: "Llama 3.1 405B",
182
- apiId: "meta/meta-llama-3.1-405b-instruct"
183
- },
184
- {
185
- value: "claude-4.5-sonnet",
186
- label: "Claude 4.5 Sonnet",
187
- apiId: "anthropic/claude-4.5-sonnet"
188
- }
189
- ];
190
- var LLM_MODEL_MAP = Object.fromEntries(
191
- LLM_MODELS.map((m) => [m.apiId, m.value])
192
- );
193
- var LLM_MODEL_ID_MAP = Object.fromEntries(
194
- LLM_MODELS.map((m) => [m.value, m.apiId])
195
- );
196
- var DEFAULT_LLM_MODEL = "meta-llama-3.1-405b-instruct";
197
- function getImageModelLabel(model) {
198
- return IMAGE_MODELS.find((m) => m.value === model)?.label ?? model;
199
- }
200
- function getVideoModelLabel(model) {
201
- return VIDEO_MODELS.find((m) => m.value === model)?.label ?? model;
202
- }
203
- function getLipSyncModelLabel(model) {
204
- return LIPSYNC_MODELS.find((m) => m.value === model)?.label ?? model;
205
- }
206
- function getLLMModelLabel(model) {
207
- return LLM_MODELS.find((m) => m.value === model)?.label ?? model;
208
- }
209
- function lipSyncModelSupportsImage(model) {
210
- return LIPSYNC_MODELS.find((m) => m.value === model)?.supportsImage ?? false;
211
- }
212
-
213
- // src/lib/easing.ts
214
- var EASING_PRESETS = {
215
- // Linear - no easing
216
- linear: [0, 0, 1, 1],
217
- // Standard easing functions
218
- easeIn: [0.42, 0, 1, 1],
219
- easeOut: [0, 0, 0.58, 1],
220
- easeInOut: [0.42, 0, 0.58, 1],
221
- // Quadratic easing
222
- easeInQuad: [0.55, 0.085, 0.68, 0.53],
223
- easeOutQuad: [0.25, 0.46, 0.45, 0.94],
224
- easeInOutQuad: [0.455, 0.03, 0.515, 0.955],
225
- // Cubic easing
226
- easeInCubic: [0.55, 0.055, 0.675, 0.19],
227
- easeOutCubic: [0.215, 0.61, 0.355, 1],
228
- easeInOutCubic: [0.645, 0.045, 0.355, 1],
229
- // Exponential easing
230
- easeInExpo: [0.95, 0.05, 0.795, 0.035],
231
- easeOutExpo: [0.19, 1, 0.22, 1],
232
- easeInOutExpo: [1, 0, 0, 1]
233
- };
234
- function evaluateBezier(t, curve) {
235
- const [x1, y1, x2, y2] = curve;
236
- const epsilon = 1e-6;
237
- let guess = t;
238
- for (let i = 0; i < 8; i++) {
239
- const x = 3 * (1 - guess) * (1 - guess) * guess * x1 + 3 * (1 - guess) * guess * guess * x2 + guess * guess * guess - t;
240
- if (Math.abs(x) < epsilon) break;
241
- const dx = 3 * (1 - guess) * (1 - guess) * x1 + 6 * (1 - guess) * guess * (x2 - x1) + 3 * guess * guess * (1 - x2);
242
- guess -= x / dx;
243
- }
244
- return 3 * (1 - guess) * (1 - guess) * guess * y1 + 3 * (1 - guess) * guess * guess * y2 + guess * guess * guess;
245
- }
246
- function applySpeedCurve(duration, curve, sampleRate = 60) {
247
- const timestamps = [];
248
- for (let i = 0; i <= sampleRate; i++) {
249
- const t = i / sampleRate;
250
- const easedT = evaluateBezier(t, curve);
251
- timestamps.push(easedT * duration);
252
- }
253
- return timestamps;
254
- }
255
- function getEasingDisplayName(preset) {
256
- const names = {
257
- linear: "Linear",
258
- easeIn: "Ease In",
259
- easeOut: "Ease Out",
260
- easeInOut: "Ease In Out",
261
- easeInQuad: "Ease In Quadratic",
262
- easeOutQuad: "Ease Out Quadratic",
263
- easeInOutQuad: "Ease In Out Quadratic",
264
- easeInCubic: "Ease In Cubic",
265
- easeOutCubic: "Ease Out Cubic",
266
- easeInOutCubic: "Ease In Out Cubic",
267
- easeInExpo: "Ease In Exponential",
268
- easeOutExpo: "Ease Out Exponential",
269
- easeInOutExpo: "Ease In Out Exponential"
270
- };
271
- return names[preset] || preset;
272
- }
273
-
274
- exports.DEFAULT_IMAGE_MODEL = DEFAULT_IMAGE_MODEL;
275
- exports.DEFAULT_LIPSYNC_MODEL = DEFAULT_LIPSYNC_MODEL;
276
- exports.DEFAULT_LLM_MODEL = DEFAULT_LLM_MODEL;
277
- exports.DEFAULT_VIDEO_MODEL = DEFAULT_VIDEO_MODEL;
278
- exports.EASING_PRESETS = EASING_PRESETS;
279
- exports.IMAGE_MODELS = IMAGE_MODELS;
280
- exports.IMAGE_MODEL_ID_MAP = IMAGE_MODEL_ID_MAP;
281
- exports.IMAGE_MODEL_MAP = IMAGE_MODEL_MAP;
282
- exports.LIPSYNC_MODELS = LIPSYNC_MODELS;
283
- exports.LIPSYNC_SYNC_MODES = LIPSYNC_SYNC_MODES;
284
- exports.LLM_MODELS = LLM_MODELS;
285
- exports.LLM_MODEL_ID_MAP = LLM_MODEL_ID_MAP;
286
- exports.LLM_MODEL_MAP = LLM_MODEL_MAP;
287
- exports.VIDEO_MODELS = VIDEO_MODELS;
288
- exports.VIDEO_MODEL_ID_MAP = VIDEO_MODEL_ID_MAP;
289
- exports.VIDEO_MODEL_MAP = VIDEO_MODEL_MAP;
290
- exports.applySpeedCurve = applySpeedCurve;
291
- exports.evaluateBezier = evaluateBezier;
292
- exports.generateHandlesFromSchema = generateHandlesFromSchema;
293
- exports.getEasingDisplayName = getEasingDisplayName;
294
- exports.getImageModelLabel = getImageModelLabel;
295
- exports.getLLMModelLabel = getLLMModelLabel;
296
- exports.getLipSyncModelLabel = getLipSyncModelLabel;
297
- exports.getMediaFromNode = getMediaFromNode;
298
- exports.getVideoModelLabel = getVideoModelLabel;
299
- exports.isSchemaHandle = isSchemaHandle;
300
- exports.lipSyncModelSupportsImage = lipSyncModelSupportsImage;
@@ -1,37 +0,0 @@
1
- 'use strict';
2
-
3
- var __create = Object.create;
4
- var __defProp = Object.defineProperty;
5
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
- var __getOwnPropNames = Object.getOwnPropertyNames;
7
- var __getProtoOf = Object.getPrototypeOf;
8
- var __hasOwnProp = Object.prototype.hasOwnProperty;
9
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
10
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
11
- }) : x)(function(x) {
12
- if (typeof require !== "undefined") return require.apply(this, arguments);
13
- throw Error('Dynamic require of "' + x + '" is not supported');
14
- });
15
- var __commonJS = (cb, mod) => function __require2() {
16
- return mod || (0, cb[__getOwnPropNames(cb)[0]])((mod = { exports: {} }).exports, mod), mod.exports;
17
- };
18
- var __copyProps = (to, from, except, desc) => {
19
- if (from && typeof from === "object" || typeof from === "function") {
20
- for (let key of __getOwnPropNames(from))
21
- if (!__hasOwnProp.call(to, key) && key !== except)
22
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
23
- }
24
- return to;
25
- };
26
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
27
- // If the importer is in node compatibility mode or this is not an ESM
28
- // file that has been converted to a CommonJS file using a Babel-
29
- // compatible transform (i.e. "__esModule" has not been set), then set
30
- // "default" to the CommonJS "module.exports" for node compatibility.
31
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
32
- mod
33
- ));
34
-
35
- exports.__commonJS = __commonJS;
36
- exports.__require = __require;
37
- exports.__toESM = __toESM;
@@ -1,61 +0,0 @@
1
- 'use strict';
2
-
3
- var clsx = require('clsx');
4
- var tailwindMerge = require('tailwind-merge');
5
- var reactSlot = require('@radix-ui/react-slot');
6
- var classVarianceAuthority = require('class-variance-authority');
7
- var jsxRuntime = require('react/jsx-runtime');
8
-
9
- function cn(...inputs) {
10
- return tailwindMerge.twMerge(clsx.clsx(inputs));
11
- }
12
- var buttonVariants = classVarianceAuthority.cva(
13
- "inline-flex items-center justify-center gap-2 whitespace-nowrap rounded-md text-sm font-medium transition-all cursor-pointer disabled:pointer-events-none disabled:opacity-50 disabled:cursor-not-allowed [&_svg]:pointer-events-none [&_svg:not([class*='size-'])]:size-4 shrink-0 [&_svg]:shrink-0 outline-none focus-visible:border-ring focus-visible:ring-ring/50 focus-visible:ring-[3px] aria-invalid:ring-destructive/20 dark:aria-invalid:ring-destructive/40 aria-invalid:border-destructive",
14
- {
15
- variants: {
16
- variant: {
17
- default: "bg-white text-black hover:bg-white/90",
18
- destructive: "bg-destructive text-white hover:bg-destructive/90 focus-visible:ring-destructive/20 dark:focus-visible:ring-destructive/40 dark:bg-destructive/60",
19
- outline: "border bg-background shadow-xs hover:bg-accent hover:text-accent-foreground dark:bg-input/30 dark:border-input dark:hover:bg-input/50",
20
- secondary: "bg-secondary text-secondary-foreground hover:bg-secondary/80",
21
- ghost: "hover:bg-accent hover:text-accent-foreground dark:hover:bg-accent/50",
22
- link: "text-primary underline-offset-4 hover:underline"
23
- },
24
- size: {
25
- default: "h-9 px-4 py-2 has-[>svg]:px-3",
26
- sm: "h-8 rounded-md gap-1.5 px-3 has-[>svg]:px-2.5",
27
- lg: "h-10 rounded-md px-6 has-[>svg]:px-4",
28
- icon: "size-9",
29
- "icon-sm": "size-8",
30
- "icon-lg": "size-10"
31
- }
32
- },
33
- defaultVariants: {
34
- variant: "default",
35
- size: "default"
36
- }
37
- }
38
- );
39
- function Button({
40
- className,
41
- variant = "default",
42
- size = "default",
43
- asChild = false,
44
- ...props
45
- }) {
46
- const Comp = asChild ? reactSlot.Slot : "button";
47
- return /* @__PURE__ */ jsxRuntime.jsx(
48
- Comp,
49
- {
50
- "data-slot": "button",
51
- "data-variant": variant,
52
- "data-size": size,
53
- className: cn(buttonVariants({ variant, size, className })),
54
- ...props
55
- }
56
- );
57
- }
58
-
59
- exports.Button = Button;
60
- exports.buttonVariants = buttonVariants;
61
- exports.cn = cn;
@@ -1,2 +0,0 @@
1
- 'use strict';
2
-
@@ -1,254 +0,0 @@
1
- 'use strict';
2
-
3
- var zustand = require('zustand');
4
-
5
- var usePromptEditorStore = zustand.create((set, get) => ({
6
- isOpen: false,
7
- nodeId: null,
8
- prompt: "",
9
- fontSize: 14,
10
- openEditor: (nodeId, prompt) => {
11
- set({
12
- isOpen: true,
13
- nodeId,
14
- prompt
15
- });
16
- },
17
- closeEditor: () => {
18
- set({
19
- isOpen: false,
20
- nodeId: null,
21
- prompt: ""
22
- });
23
- },
24
- setPrompt: (prompt) => {
25
- set({ prompt });
26
- },
27
- setFontSize: (fontSize) => {
28
- set({ fontSize });
29
- },
30
- saveAndClose: () => {
31
- const { nodeId, prompt } = get();
32
- if (!nodeId) return null;
33
- const result = { nodeId, prompt };
34
- set({
35
- isOpen: false,
36
- nodeId: null,
37
- prompt: ""
38
- });
39
- return result;
40
- }
41
- }));
42
- var DEFAULT_TOOL_OPTIONS = {
43
- strokeColor: "#ef4444",
44
- // Red
45
- strokeWidth: 3,
46
- fillColor: null,
47
- fontSize: 16
48
- };
49
- var shapeIdCounter = 0;
50
- function generateShapeId() {
51
- return `shape-${Date.now()}-${++shapeIdCounter}`;
52
- }
53
- var useAnnotationStore = zustand.create((set, get) => ({
54
- isOpen: false,
55
- nodeId: null,
56
- sourceImage: null,
57
- shapes: [],
58
- selectedShapeId: null,
59
- currentTool: "rectangle",
60
- toolOptions: DEFAULT_TOOL_OPTIONS,
61
- history: [],
62
- historyIndex: -1,
63
- isDrawing: false,
64
- drawingShape: null,
65
- openAnnotation: (nodeId, image, existingShapes = []) => {
66
- set({
67
- isOpen: true,
68
- nodeId,
69
- sourceImage: image,
70
- shapes: existingShapes,
71
- selectedShapeId: null,
72
- currentTool: "rectangle",
73
- toolOptions: DEFAULT_TOOL_OPTIONS,
74
- history: [existingShapes],
75
- historyIndex: 0,
76
- isDrawing: false,
77
- drawingShape: null
78
- });
79
- },
80
- closeAnnotation: () => {
81
- set({
82
- isOpen: false,
83
- nodeId: null,
84
- sourceImage: null,
85
- shapes: [],
86
- selectedShapeId: null,
87
- history: [],
88
- historyIndex: -1,
89
- isDrawing: false,
90
- drawingShape: null
91
- });
92
- },
93
- saveAndClose: () => {
94
- const { nodeId, shapes } = get();
95
- if (!nodeId) return null;
96
- const result = { nodeId, shapes: [...shapes] };
97
- set({
98
- isOpen: false,
99
- nodeId: null,
100
- sourceImage: null,
101
- shapes: [],
102
- selectedShapeId: null,
103
- history: [],
104
- historyIndex: -1,
105
- isDrawing: false,
106
- drawingShape: null
107
- });
108
- return result;
109
- },
110
- addShape: (shape) => {
111
- set((state) => {
112
- const newShapes = [...state.shapes, shape];
113
- const newHistory = [...state.history.slice(0, state.historyIndex + 1), newShapes].slice(
114
- -50
115
- );
116
- return {
117
- shapes: newShapes,
118
- history: newHistory,
119
- historyIndex: newHistory.length - 1
120
- };
121
- });
122
- },
123
- updateShape: (id, updates) => {
124
- set((state) => {
125
- const newShapes = state.shapes.map(
126
- (s) => s.id === id ? { ...s, ...updates } : s
127
- );
128
- const newHistory = [...state.history.slice(0, state.historyIndex + 1), newShapes].slice(
129
- -50
130
- );
131
- return {
132
- shapes: newShapes,
133
- history: newHistory,
134
- historyIndex: newHistory.length - 1
135
- };
136
- });
137
- },
138
- deleteShape: (id) => {
139
- set((state) => {
140
- const newShapes = state.shapes.filter((s) => s.id !== id);
141
- const newHistory = [...state.history.slice(0, state.historyIndex + 1), newShapes].slice(
142
- -50
143
- );
144
- return {
145
- shapes: newShapes,
146
- selectedShapeId: state.selectedShapeId === id ? null : state.selectedShapeId,
147
- history: newHistory,
148
- historyIndex: newHistory.length - 1
149
- };
150
- });
151
- },
152
- selectShape: (id) => {
153
- set({ selectedShapeId: id });
154
- },
155
- clearShapes: () => {
156
- set((state) => {
157
- const newHistory = [...state.history.slice(0, state.historyIndex + 1), []].slice(
158
- -50
159
- );
160
- return {
161
- shapes: [],
162
- selectedShapeId: null,
163
- history: newHistory,
164
- historyIndex: newHistory.length - 1
165
- };
166
- });
167
- },
168
- setTool: (tool) => {
169
- set({ currentTool: tool, selectedShapeId: null });
170
- },
171
- setToolOptions: (options) => {
172
- set((state) => ({
173
- toolOptions: { ...state.toolOptions, ...options }
174
- }));
175
- },
176
- startDrawing: (shape) => {
177
- set({
178
- isDrawing: true,
179
- drawingShape: {
180
- id: generateShapeId(),
181
- ...shape
182
- }
183
- });
184
- },
185
- updateDrawing: (updates) => {
186
- set((state) => ({
187
- drawingShape: state.drawingShape ? { ...state.drawingShape, ...updates } : null
188
- }));
189
- },
190
- finishDrawing: () => {
191
- const { drawingShape, addShape } = get();
192
- if (drawingShape && isValidShape(drawingShape)) {
193
- addShape(drawingShape);
194
- }
195
- set({ isDrawing: false, drawingShape: null });
196
- },
197
- cancelDrawing: () => {
198
- set({ isDrawing: false, drawingShape: null });
199
- },
200
- undo: () => {
201
- set((state) => {
202
- if (state.historyIndex > 0) {
203
- const newIndex = state.historyIndex - 1;
204
- return {
205
- shapes: state.history[newIndex],
206
- historyIndex: newIndex,
207
- selectedShapeId: null
208
- };
209
- }
210
- return state;
211
- });
212
- },
213
- redo: () => {
214
- set((state) => {
215
- if (state.historyIndex < state.history.length - 1) {
216
- const newIndex = state.historyIndex + 1;
217
- return {
218
- shapes: state.history[newIndex],
219
- historyIndex: newIndex,
220
- selectedShapeId: null
221
- };
222
- }
223
- return state;
224
- });
225
- },
226
- canUndo: () => {
227
- const { historyIndex } = get();
228
- return historyIndex > 0;
229
- },
230
- canRedo: () => {
231
- const { historyIndex, history } = get();
232
- return historyIndex < history.length - 1;
233
- }
234
- }));
235
- function isValidShape(shape) {
236
- if (!shape.id || !shape.type) return false;
237
- switch (shape.type) {
238
- case "rectangle":
239
- return typeof shape.x === "number" && typeof shape.y === "number" && typeof shape.width === "number" && typeof shape.height === "number" && Math.abs(shape.width) > 5 && Math.abs(shape.height) > 5;
240
- case "circle":
241
- return typeof shape.x === "number" && typeof shape.y === "number" && typeof shape.radius === "number" && shape.radius > 5;
242
- case "arrow":
243
- return Array.isArray(shape.points) && shape.points.length >= 4 && Math.hypot(shape.points[2] - shape.points[0], shape.points[3] - shape.points[1]) > 10;
244
- case "freehand":
245
- return Array.isArray(shape.points) && shape.points.length >= 4;
246
- case "text":
247
- return typeof shape.x === "number" && typeof shape.y === "number" && typeof shape.text === "string" && shape.text.length > 0;
248
- default:
249
- return false;
250
- }
251
- }
252
-
253
- exports.useAnnotationStore = useAnnotationStore;
254
- exports.usePromptEditorStore = usePromptEditorStore;