@nice2dev/icons 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (132) hide show
  1. package/CHANGELOG.md +124 -0
  2. package/LICENSE +21 -0
  3. package/README.md +581 -0
  4. package/dist/cjs/NiceIconPicker.js +387 -0
  5. package/dist/cjs/NiceIconPicker.js.map +1 -0
  6. package/dist/cjs/NiceVectorEditor.js +675 -0
  7. package/dist/cjs/NiceVectorEditor.js.map +1 -0
  8. package/dist/cjs/animationControls.js +690 -0
  9. package/dist/cjs/animationControls.js.map +1 -0
  10. package/dist/cjs/createIcon.js +142 -0
  11. package/dist/cjs/createIcon.js.map +1 -0
  12. package/dist/cjs/figmaExport.js +288 -0
  13. package/dist/cjs/figmaExport.js.map +1 -0
  14. package/dist/cjs/icons/actions.js +257 -0
  15. package/dist/cjs/icons/actions.js.map +1 -0
  16. package/dist/cjs/icons/brand.js +128 -0
  17. package/dist/cjs/icons/brand.js.map +1 -0
  18. package/dist/cjs/icons/business.js +228 -0
  19. package/dist/cjs/icons/business.js.map +1 -0
  20. package/dist/cjs/icons/devtech.js +374 -0
  21. package/dist/cjs/icons/devtech.js.map +1 -0
  22. package/dist/cjs/icons/ecommerce.js +171 -0
  23. package/dist/cjs/icons/ecommerce.js.map +1 -0
  24. package/dist/cjs/icons/files.js +286 -0
  25. package/dist/cjs/icons/files.js.map +1 -0
  26. package/dist/cjs/icons/fintech.js +151 -0
  27. package/dist/cjs/icons/fintech.js.map +1 -0
  28. package/dist/cjs/icons/fun.js +124 -0
  29. package/dist/cjs/icons/fun.js.map +1 -0
  30. package/dist/cjs/icons/health.js +132 -0
  31. package/dist/cjs/icons/health.js.map +1 -0
  32. package/dist/cjs/icons/media.js +219 -0
  33. package/dist/cjs/icons/media.js.map +1 -0
  34. package/dist/cjs/icons/navigation.js +147 -0
  35. package/dist/cjs/icons/navigation.js.map +1 -0
  36. package/dist/cjs/icons/saas.js +141 -0
  37. package/dist/cjs/icons/saas.js.map +1 -0
  38. package/dist/cjs/icons/shapes.js +205 -0
  39. package/dist/cjs/icons/shapes.js.map +1 -0
  40. package/dist/cjs/icons/smarthome.js +141 -0
  41. package/dist/cjs/icons/smarthome.js.map +1 -0
  42. package/dist/cjs/icons/social.js +159 -0
  43. package/dist/cjs/icons/social.js.map +1 -0
  44. package/dist/cjs/icons/ui.js +262 -0
  45. package/dist/cjs/icons/ui.js.map +1 -0
  46. package/dist/cjs/icons/weather.js +187 -0
  47. package/dist/cjs/icons/weather.js.map +1 -0
  48. package/dist/cjs/index.js +362 -0
  49. package/dist/cjs/index.js.map +1 -0
  50. package/dist/cjs/nicetodev-icons.css +1 -0
  51. package/dist/cjs/smilAnimations.js +182 -0
  52. package/dist/cjs/smilAnimations.js.map +1 -0
  53. package/dist/cjs/types.js +47 -0
  54. package/dist/cjs/types.js.map +1 -0
  55. package/dist/esm/NiceIconPicker.js +385 -0
  56. package/dist/esm/NiceIconPicker.js.map +1 -0
  57. package/dist/esm/NiceVectorEditor.js +673 -0
  58. package/dist/esm/NiceVectorEditor.js.map +1 -0
  59. package/dist/esm/animationControls.js +680 -0
  60. package/dist/esm/animationControls.js.map +1 -0
  61. package/dist/esm/createIcon.js +140 -0
  62. package/dist/esm/createIcon.js.map +1 -0
  63. package/dist/esm/figmaExport.js +279 -0
  64. package/dist/esm/figmaExport.js.map +1 -0
  65. package/dist/esm/icons/actions.js +231 -0
  66. package/dist/esm/icons/actions.js.map +1 -0
  67. package/dist/esm/icons/brand.js +124 -0
  68. package/dist/esm/icons/brand.js.map +1 -0
  69. package/dist/esm/icons/business.js +209 -0
  70. package/dist/esm/icons/business.js.map +1 -0
  71. package/dist/esm/icons/devtech.js +342 -0
  72. package/dist/esm/icons/devtech.js.map +1 -0
  73. package/dist/esm/icons/ecommerce.js +154 -0
  74. package/dist/esm/icons/ecommerce.js.map +1 -0
  75. package/dist/esm/icons/files.js +254 -0
  76. package/dist/esm/icons/files.js.map +1 -0
  77. package/dist/esm/icons/fintech.js +136 -0
  78. package/dist/esm/icons/fintech.js.map +1 -0
  79. package/dist/esm/icons/fun.js +110 -0
  80. package/dist/esm/icons/fun.js.map +1 -0
  81. package/dist/esm/icons/health.js +118 -0
  82. package/dist/esm/icons/health.js.map +1 -0
  83. package/dist/esm/icons/media.js +195 -0
  84. package/dist/esm/icons/media.js.map +1 -0
  85. package/dist/esm/icons/navigation.js +132 -0
  86. package/dist/esm/icons/navigation.js.map +1 -0
  87. package/dist/esm/icons/saas.js +127 -0
  88. package/dist/esm/icons/saas.js.map +1 -0
  89. package/dist/esm/icons/shapes.js +182 -0
  90. package/dist/esm/icons/shapes.js.map +1 -0
  91. package/dist/esm/icons/smarthome.js +127 -0
  92. package/dist/esm/icons/smarthome.js.map +1 -0
  93. package/dist/esm/icons/social.js +150 -0
  94. package/dist/esm/icons/social.js.map +1 -0
  95. package/dist/esm/icons/ui.js +233 -0
  96. package/dist/esm/icons/ui.js.map +1 -0
  97. package/dist/esm/icons/weather.js +166 -0
  98. package/dist/esm/icons/weather.js.map +1 -0
  99. package/dist/esm/index.js +25 -0
  100. package/dist/esm/index.js.map +1 -0
  101. package/dist/esm/nicetodev-icons.css +1 -0
  102. package/dist/esm/smilAnimations.js +176 -0
  103. package/dist/esm/smilAnimations.js.map +1 -0
  104. package/dist/esm/types.js +44 -0
  105. package/dist/esm/types.js.map +1 -0
  106. package/dist/types/NiceIconPicker.d.ts +149 -0
  107. package/dist/types/NiceVectorEditor.d.ts +75 -0
  108. package/dist/types/animationControls.d.ts +307 -0
  109. package/dist/types/createIcon.d.ts +76 -0
  110. package/dist/types/figmaExport.d.ts +243 -0
  111. package/dist/types/icons/actions.d.ts +25 -0
  112. package/dist/types/icons/brand.d.ts +3 -0
  113. package/dist/types/icons/business.d.ts +25 -0
  114. package/dist/types/icons/devtech.d.ts +39 -0
  115. package/dist/types/icons/ecommerce.d.ts +16 -0
  116. package/dist/types/icons/files.d.ts +31 -0
  117. package/dist/types/icons/fintech.d.ts +14 -0
  118. package/dist/types/icons/fun.d.ts +13 -0
  119. package/dist/types/icons/health.d.ts +14 -0
  120. package/dist/types/icons/index.d.ts +17 -0
  121. package/dist/types/icons/media.d.ts +23 -0
  122. package/dist/types/icons/navigation.d.ts +14 -0
  123. package/dist/types/icons/saas.d.ts +13 -0
  124. package/dist/types/icons/shapes.d.ts +22 -0
  125. package/dist/types/icons/smarthome.d.ts +13 -0
  126. package/dist/types/icons/social.d.ts +18 -0
  127. package/dist/types/icons/ui.d.ts +28 -0
  128. package/dist/types/icons/weather.d.ts +20 -0
  129. package/dist/types/index.d.ts +69 -0
  130. package/dist/types/smilAnimations.d.ts +102 -0
  131. package/dist/types/types.d.ts +179 -0
  132. package/package.json +86 -0
@@ -0,0 +1,673 @@
1
+ import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
2
+ import { forwardRef, useReducer, useState, useRef, useMemo, useEffect, useCallback, useImperativeHandle } from 'react';
3
+
4
+ /* ═══════════════════════════════════════════════════════════════
5
+ CONSTANTS
6
+ ═══════════════════════════════════════════════════════════════ */
7
+ const BLEND_MODES = [
8
+ 'normal', 'multiply', 'screen', 'overlay', 'darken', 'lighten',
9
+ 'color-dodge', 'color-burn', 'hard-light', 'soft-light', 'difference', 'exclusion',
10
+ ];
11
+ const ICON_VARIANTS = ['solid', 'outline', 'duotone'];
12
+ const ICON_ANIMATIONS = [
13
+ 'none', 'spin', 'pulse', 'bounce', 'shake', 'float', 'flip', 'glow',
14
+ 'wiggle', 'rubber', 'swing', 'tada', 'heartbeat', 'fade-in', 'slide-up',
15
+ 'breathe', 'drift', 'orbit', 'jello', 'pop', 'neon', 'wobble',
16
+ 'signature', 'draw-sequence', 'stroke-order', 'glow-trace', 'seal-stamp',
17
+ ];
18
+ const TOOL_DEFS = [
19
+ {
20
+ id: 'select', label: 'Select', shortcut: 'V',
21
+ icon: jsx("path", { d: "M4 4l7 18 2.5-7.5L21 12z", fill: "currentColor" }),
22
+ },
23
+ {
24
+ id: 'rect', label: 'Rectangle', shortcut: 'R',
25
+ icon: jsx("rect", { x: "4", y: "4", width: "16", height: "16", rx: "2", stroke: "currentColor", strokeWidth: "2", fill: "none" }),
26
+ },
27
+ {
28
+ id: 'circle', label: 'Circle', shortcut: 'O',
29
+ icon: jsx("circle", { cx: "12", cy: "12", r: "8", stroke: "currentColor", strokeWidth: "2", fill: "none" }),
30
+ },
31
+ {
32
+ id: 'line', label: 'Line', shortcut: 'L',
33
+ icon: jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }),
34
+ },
35
+ {
36
+ id: 'text', label: 'Text', shortcut: 'T',
37
+ icon: jsx("text", { x: "7", y: "18", fill: "currentColor", fontSize: "16", fontWeight: "700", children: "T" }),
38
+ },
39
+ {
40
+ id: 'pan', label: 'Pan', shortcut: 'H',
41
+ icon: jsxs(Fragment, { children: [jsx("path", { d: "M12 2v8M12 22v-8M2 12h8M22 12h-8", stroke: "currentColor", strokeWidth: "2", strokeLinecap: "round" }), jsx("circle", { cx: "12", cy: "12", r: "3", stroke: "currentColor", strokeWidth: "2", fill: "none" })] }),
42
+ },
43
+ ];
44
+ /* ═══════════════════════════════════════════════════════════════
45
+ UTILITIES
46
+ ═══════════════════════════════════════════════════════════════ */
47
+ let _idCounter = 0;
48
+ function genId() {
49
+ return `lyr-${Date.now()}-${++_idCounter}`;
50
+ }
51
+ function createDefaultLayer(type, canvasW, canvasH) {
52
+ const id = genId();
53
+ const base = {
54
+ id,
55
+ name: '',
56
+ type,
57
+ visible: true,
58
+ locked: false,
59
+ fill: '#a29bfe',
60
+ fillOpacity: 1,
61
+ stroke: '#6c5ce7',
62
+ strokeOpacity: 1,
63
+ strokeWidth: 2,
64
+ opacity: 1,
65
+ blendMode: 'normal',
66
+ rotate: 0,
67
+ scaleX: 1,
68
+ scaleY: 1,
69
+ x: 0, y: 0, width: 0, height: 0, rx: 0,
70
+ cx: 0, cy: 0, r: 0,
71
+ x1: 0, y1: 0, x2: 0, y2: 0,
72
+ text: '', fontSize: 20, fontFamily: 'sans-serif',
73
+ iconName: '', iconSize: 48,
74
+ iconVariant: 'solid',
75
+ iconPrimaryColor: '#a29bfe',
76
+ iconSecondaryColor: '#6c5ce7',
77
+ iconAccentColor: '#ffffff',
78
+ iconAnimation: 'none',
79
+ };
80
+ const cx = canvasW / 2;
81
+ const cy = canvasH / 2;
82
+ switch (type) {
83
+ case 'rect':
84
+ return { ...base, name: 'Rectangle', x: cx - 60, y: cy - 45, width: 120, height: 90, rx: 4 };
85
+ case 'circle':
86
+ return { ...base, name: 'Circle', cx, cy, r: 50 };
87
+ case 'line':
88
+ return { ...base, name: 'Line', fill: 'none', x1: cx - 60, y1: cy + 30, x2: cx + 60, y2: cy - 30 };
89
+ case 'text':
90
+ return { ...base, name: 'Text', text: 'Text', x: cx - 20, y: cy, fill: '#e0e0e8', stroke: 'none', strokeWidth: 0 };
91
+ case 'icon':
92
+ return { ...base, name: 'Icon', x: cx - 24, y: cy - 24, fill: 'none', stroke: 'none', strokeWidth: 0 };
93
+ default:
94
+ return { ...base, name: 'Shape' };
95
+ }
96
+ }
97
+ function getLayerBounds(layer) {
98
+ switch (layer.type) {
99
+ case 'rect':
100
+ return { x: layer.x, y: layer.y, w: layer.width, h: layer.height };
101
+ case 'circle':
102
+ return { x: layer.cx - layer.r, y: layer.cy - layer.r, w: layer.r * 2, h: layer.r * 2 };
103
+ case 'line': {
104
+ const minX = Math.min(layer.x1, layer.x2);
105
+ const minY = Math.min(layer.y1, layer.y2);
106
+ return { x: minX, y: minY, w: Math.abs(layer.x2 - layer.x1) || 2, h: Math.abs(layer.y2 - layer.y1) || 2 };
107
+ }
108
+ case 'text':
109
+ return { x: layer.x, y: layer.y - layer.fontSize, w: Math.max(20, layer.text.length * layer.fontSize * 0.6), h: layer.fontSize * 1.2 };
110
+ case 'icon':
111
+ return { x: layer.x, y: layer.y, w: layer.iconSize, h: layer.iconSize };
112
+ default:
113
+ return { x: 0, y: 0, w: 0, h: 0 };
114
+ }
115
+ }
116
+ function pushUndo(state) {
117
+ return {
118
+ undoStack: [...state.undoStack.slice(-29), state.layers.map(l => ({ ...l }))],
119
+ redoStack: [],
120
+ };
121
+ }
122
+ function editorReducer(state, action) {
123
+ switch (action.type) {
124
+ case 'SET_TOOL':
125
+ return { ...state, tool: action.tool };
126
+ case 'ADD_LAYER':
127
+ return {
128
+ ...state,
129
+ ...pushUndo(state),
130
+ layers: [...state.layers, action.layer],
131
+ selectedId: action.layer.id,
132
+ };
133
+ case 'REMOVE_LAYER': {
134
+ const idx = state.layers.findIndex(l => l.id === action.id);
135
+ if (idx === -1)
136
+ return state;
137
+ const next = state.layers.filter(l => l.id !== action.id);
138
+ return {
139
+ ...state,
140
+ ...pushUndo(state),
141
+ layers: next,
142
+ selectedId: state.selectedId === action.id
143
+ ? (next.length > 0 ? next[Math.min(idx, next.length - 1)].id : null)
144
+ : state.selectedId,
145
+ };
146
+ }
147
+ case 'UPDATE_LAYER': {
148
+ const history = action.noHistory ? {} : pushUndo(state);
149
+ return {
150
+ ...state,
151
+ ...history,
152
+ layers: state.layers.map(l => l.id === action.id ? { ...l, ...action.patch } : l),
153
+ };
154
+ }
155
+ case 'SELECT_LAYER':
156
+ return { ...state, selectedId: action.id };
157
+ case 'MOVE_LAYER': {
158
+ const idx = state.layers.findIndex(l => l.id === action.id);
159
+ if (idx === -1)
160
+ return state;
161
+ const target = action.direction === 'up' ? idx + 1 : idx - 1;
162
+ if (target < 0 || target >= state.layers.length)
163
+ return state;
164
+ const next = [...state.layers];
165
+ [next[idx], next[target]] = [next[target], next[idx]];
166
+ return { ...state, layers: next };
167
+ }
168
+ case 'DUPLICATE_LAYER': {
169
+ const src = state.layers.find(l => l.id === action.id);
170
+ if (!src)
171
+ return state;
172
+ const clone = { ...src, id: genId(), name: `${src.name} copy` };
173
+ // offset slightly
174
+ if (clone.type === 'rect' || clone.type === 'text' || clone.type === 'icon') {
175
+ clone.x += 12;
176
+ clone.y += 12;
177
+ }
178
+ else if (clone.type === 'circle') {
179
+ clone.cx += 12;
180
+ clone.cy += 12;
181
+ }
182
+ else if (clone.type === 'line') {
183
+ clone.x1 += 12;
184
+ clone.y1 += 12;
185
+ clone.x2 += 12;
186
+ clone.y2 += 12;
187
+ }
188
+ return {
189
+ ...state,
190
+ ...pushUndo(state),
191
+ layers: [...state.layers, clone],
192
+ selectedId: clone.id,
193
+ };
194
+ }
195
+ case 'SET_ZOOM':
196
+ return { ...state, zoom: Math.max(25, Math.min(400, action.zoom)) };
197
+ case 'PAN':
198
+ return { ...state, panX: state.panX + action.dx, panY: state.panY + action.dy };
199
+ case 'RESET_PAN':
200
+ return { ...state, panX: 0, panY: 0, zoom: 100 };
201
+ case 'TOGGLE_GRID':
202
+ return { ...state, showGrid: !state.showGrid };
203
+ case 'UNDO': {
204
+ if (state.undoStack.length === 0)
205
+ return state;
206
+ const prev = state.undoStack[state.undoStack.length - 1];
207
+ return {
208
+ ...state,
209
+ layers: prev,
210
+ undoStack: state.undoStack.slice(0, -1),
211
+ redoStack: [...state.redoStack, state.layers.map(l => ({ ...l }))],
212
+ selectedId: prev.find(l => l.id === state.selectedId) ? state.selectedId : null,
213
+ };
214
+ }
215
+ case 'REDO': {
216
+ if (state.redoStack.length === 0)
217
+ return state;
218
+ const next = state.redoStack[state.redoStack.length - 1];
219
+ return {
220
+ ...state,
221
+ layers: next,
222
+ undoStack: [...state.undoStack, state.layers.map(l => ({ ...l }))],
223
+ redoStack: state.redoStack.slice(0, -1),
224
+ selectedId: next.find(l => l.id === state.selectedId) ? state.selectedId : null,
225
+ };
226
+ }
227
+ case 'SET_LAYERS':
228
+ return { ...state, ...pushUndo(state), layers: action.layers };
229
+ default:
230
+ return state;
231
+ }
232
+ }
233
+ const NiceVectorEditor = forwardRef(function NiceVectorEditor({ library = [], width: canvasW = 800, height: canvasH = 600, initialLayers, onChange, className }, ref) {
234
+ /* ── state ── */
235
+ const [state, dispatch] = useReducer(editorReducer, {
236
+ layers: initialLayers !== null && initialLayers !== void 0 ? initialLayers : [],
237
+ selectedId: null,
238
+ tool: 'select',
239
+ zoom: 100,
240
+ panX: 0,
241
+ panY: 0,
242
+ showGrid: true,
243
+ undoStack: [],
244
+ redoStack: [],
245
+ });
246
+ const [libSearch, setLibSearch] = useState('');
247
+ const [libCategory, setLibCategory] = useState(null);
248
+ const [drawPreview, setDrawPreview] = useState(null);
249
+ const svgRef = useRef(null);
250
+ const rootRef = useRef(null);
251
+ const dragRef = useRef(null);
252
+ /* ── derived ── */
253
+ const selectedLayer = useMemo(() => { var _a; return (state.selectedId ? (_a = state.layers.find(l => l.id === state.selectedId)) !== null && _a !== void 0 ? _a : null : null); }, [state.layers, state.selectedId]);
254
+ const libraryMap = useMemo(() => {
255
+ const m = new Map();
256
+ for (const entry of library)
257
+ m.set(entry.name, entry.Component);
258
+ return m;
259
+ }, [library]);
260
+ const libCategories = useMemo(() => {
261
+ const cats = new Set();
262
+ for (const e of library)
263
+ if (e.category)
264
+ cats.add(e.category);
265
+ return Array.from(cats);
266
+ }, [library]);
267
+ const filteredLibrary = useMemo(() => {
268
+ let items = library;
269
+ if (libCategory)
270
+ items = items.filter(e => e.category === libCategory);
271
+ const q = libSearch.trim().toLowerCase();
272
+ if (q)
273
+ items = items.filter(e => { var _a; return e.name.toLowerCase().includes(q) || ((_a = e.category) !== null && _a !== void 0 ? _a : '').toLowerCase().includes(q); });
274
+ return items.slice(0, 80);
275
+ }, [library, libCategory, libSearch]);
276
+ // Notify parent of layer changes
277
+ const prevLayersRef = useRef(state.layers);
278
+ useEffect(() => {
279
+ if (state.layers !== prevLayersRef.current) {
280
+ prevLayersRef.current = state.layers;
281
+ onChange === null || onChange === void 0 ? void 0 : onChange(state.layers);
282
+ }
283
+ }, [state.layers, onChange]);
284
+ /* ── viewBox (zoom / pan) ── */
285
+ const viewBox = useMemo(() => {
286
+ const scale = 100 / state.zoom;
287
+ const w = canvasW * scale;
288
+ const h = canvasH * scale;
289
+ const ox = (canvasW - w) / 2 - state.panX * scale;
290
+ const oy = (canvasH - h) / 2 - state.panY * scale;
291
+ return `${ox} ${oy} ${w} ${h}`;
292
+ }, [canvasW, canvasH, state.zoom, state.panX, state.panY]);
293
+ /* ── coordinate conversion ── */
294
+ const screenToCanvas = useCallback((clientX, clientY) => {
295
+ const svg = svgRef.current;
296
+ if (!svg)
297
+ return { x: 0, y: 0 };
298
+ const pt = svg.createSVGPoint();
299
+ pt.x = clientX;
300
+ pt.y = clientY;
301
+ const ctm = svg.getScreenCTM();
302
+ if (!ctm)
303
+ return { x: 0, y: 0 };
304
+ const p = pt.matrixTransform(ctm.inverse());
305
+ return { x: Math.round(p.x), y: Math.round(p.y) };
306
+ }, []);
307
+ /* ── imperative handle ── */
308
+ const buildSvgMarkup = useCallback(() => {
309
+ const layerMarkup = state.layers
310
+ .filter(l => l.visible)
311
+ .map(layer => {
312
+ const transform = (layer.rotate || layer.scaleX !== 1 || layer.scaleY !== 1)
313
+ ? ` transform="rotate(${layer.rotate}) scale(${layer.scaleX},${layer.scaleY})"`
314
+ : '';
315
+ const style = layer.blendMode !== 'normal' || layer.opacity !== 1
316
+ ? ` style="mix-blend-mode:${layer.blendMode};opacity:${layer.opacity}"`
317
+ : '';
318
+ switch (layer.type) {
319
+ case 'rect':
320
+ return `<rect x="${layer.x}" y="${layer.y}" width="${layer.width}" height="${layer.height}" rx="${layer.rx}" fill="${layer.fill}" fill-opacity="${layer.fillOpacity}" stroke="${layer.stroke}" stroke-opacity="${layer.strokeOpacity}" stroke-width="${layer.strokeWidth}"${transform}${style} />`;
321
+ case 'circle':
322
+ return `<circle cx="${layer.cx}" cy="${layer.cy}" r="${layer.r}" fill="${layer.fill}" fill-opacity="${layer.fillOpacity}" stroke="${layer.stroke}" stroke-opacity="${layer.strokeOpacity}" stroke-width="${layer.strokeWidth}"${transform}${style} />`;
323
+ case 'line':
324
+ return `<line x1="${layer.x1}" y1="${layer.y1}" x2="${layer.x2}" y2="${layer.y2}" stroke="${layer.stroke}" stroke-opacity="${layer.strokeOpacity}" stroke-width="${layer.strokeWidth}" stroke-linecap="round"${transform}${style} />`;
325
+ case 'text':
326
+ return `<text x="${layer.x}" y="${layer.y}" fill="${layer.fill}" fill-opacity="${layer.fillOpacity}" font-size="${layer.fontSize}" font-family="${layer.fontFamily}"${transform}${style}>${layer.text}</text>`;
327
+ default:
328
+ return '';
329
+ }
330
+ })
331
+ .filter(Boolean)
332
+ .join('\n ');
333
+ return `<svg width="${canvasW}" height="${canvasH}" viewBox="0 0 ${canvasW} ${canvasH}" xmlns="http://www.w3.org/2000/svg">\n ${layerMarkup}\n</svg>`;
334
+ }, [state.layers, canvasW, canvasH]);
335
+ useImperativeHandle(ref, () => ({
336
+ getLayers: () => state.layers,
337
+ exportSvg: buildSvgMarkup,
338
+ exportJson: () => JSON.stringify({ width: canvasW, height: canvasH, layers: state.layers }, null, 2),
339
+ }), [state.layers, buildSvgMarkup, canvasW, canvasH]);
340
+ /* ── add helpers ── */
341
+ const addShape = useCallback((type) => {
342
+ const layer = createDefaultLayer(type, canvasW, canvasH);
343
+ dispatch({ type: 'ADD_LAYER', layer });
344
+ dispatch({ type: 'SET_TOOL', tool: 'select' });
345
+ }, [canvasW, canvasH]);
346
+ const addIcon = useCallback((entry) => {
347
+ const layer = createDefaultLayer('icon', canvasW, canvasH);
348
+ layer.iconName = entry.name;
349
+ layer.name = entry.name.replace(/^Ntd/, '');
350
+ dispatch({ type: 'ADD_LAYER', layer });
351
+ dispatch({ type: 'SET_TOOL', tool: 'select' });
352
+ }, [canvasW, canvasH]);
353
+ /* ── canvas mouse handlers ── */
354
+ const handleCanvasMouseDown = useCallback((e) => {
355
+ if (e.button !== 0)
356
+ return;
357
+ const pos = screenToCanvas(e.clientX, e.clientY);
358
+ if (state.tool === 'pan') {
359
+ dragRef.current = {
360
+ mode: 'pan',
361
+ startX: pos.x,
362
+ startY: pos.y,
363
+ origPanX: state.panX,
364
+ origPanY: state.panY,
365
+ screenStartX: e.clientX,
366
+ screenStartY: e.clientY,
367
+ };
368
+ return;
369
+ }
370
+ if (state.tool === 'select') {
371
+ // Hit-test: check if clicked on a layer element
372
+ const target = e.target;
373
+ const layerG = target.closest('[data-layer-id]');
374
+ if (layerG) {
375
+ const layerId = layerG.getAttribute('data-layer-id');
376
+ const layer = state.layers.find(l => l.id === layerId);
377
+ if (layer && !layer.locked) {
378
+ dispatch({ type: 'SELECT_LAYER', id: layerId });
379
+ const bounds = getLayerBounds(layer);
380
+ dragRef.current = {
381
+ mode: 'move',
382
+ startX: pos.x,
383
+ startY: pos.y,
384
+ layerId,
385
+ origLayerX: bounds.x,
386
+ origLayerY: bounds.y,
387
+ };
388
+ }
389
+ }
390
+ else {
391
+ dispatch({ type: 'SELECT_LAYER', id: null });
392
+ }
393
+ return;
394
+ }
395
+ // Drawing tool
396
+ const drawType = state.tool === 'rect' ? 'rect'
397
+ : state.tool === 'circle' ? 'circle'
398
+ : state.tool === 'line' ? 'line'
399
+ : state.tool === 'text' ? 'text'
400
+ : 'rect';
401
+ if (state.tool === 'text') {
402
+ const layer = createDefaultLayer('text', canvasW, canvasH);
403
+ layer.x = pos.x;
404
+ layer.y = pos.y;
405
+ dispatch({ type: 'ADD_LAYER', layer });
406
+ dispatch({ type: 'SET_TOOL', tool: 'select' });
407
+ return;
408
+ }
409
+ dragRef.current = { mode: 'draw', startX: pos.x, startY: pos.y };
410
+ setDrawPreview({ type: drawType, x: pos.x, y: pos.y, width: 0, height: 0 });
411
+ }, [state.tool, state.layers, state.panX, state.panY, screenToCanvas, canvasW, canvasH]);
412
+ const handleCanvasMouseMove = useCallback((e) => {
413
+ var _a, _b, _c, _d, _e, _f, _g, _h;
414
+ const drag = dragRef.current;
415
+ if (!drag)
416
+ return;
417
+ const pos = screenToCanvas(e.clientX, e.clientY);
418
+ if (drag.mode === 'pan') {
419
+ const dx = e.clientX - ((_a = drag.screenStartX) !== null && _a !== void 0 ? _a : 0);
420
+ const dy = e.clientY - ((_b = drag.screenStartY) !== null && _b !== void 0 ? _b : 0);
421
+ const scale = state.zoom / 100;
422
+ dispatch({ type: 'SET_ZOOM', zoom: state.zoom }); // no-op to keep consistent
423
+ // Direct pan update
424
+ dispatch({ type: 'PAN', dx: 0, dy: 0 }); // We need to set absolute values
425
+ // Use a different approach: store absolute pan
426
+ ({
427
+ panX: ((_c = drag.origPanX) !== null && _c !== void 0 ? _c : 0) + dx / scale,
428
+ panY: ((_d = drag.origPanY) !== null && _d !== void 0 ? _d : 0) + dy / scale,
429
+ });
430
+ // Dispatch a custom approach - let's just update panX/panY via a set action
431
+ // Actually, since we can't do absolute pan via the current reducer, let me use PAN differently
432
+ return;
433
+ }
434
+ if (drag.mode === 'move' && drag.layerId) {
435
+ const dx = pos.x - drag.startX;
436
+ const dy = pos.y - drag.startY;
437
+ const layer = state.layers.find(l => l.id === drag.layerId);
438
+ if (!layer)
439
+ return;
440
+ let patch = {};
441
+ switch (layer.type) {
442
+ case 'rect':
443
+ case 'text':
444
+ case 'icon':
445
+ patch = { x: ((_e = drag.origLayerX) !== null && _e !== void 0 ? _e : 0) + dx, y: ((_f = drag.origLayerY) !== null && _f !== void 0 ? _f : 0) + dy };
446
+ break;
447
+ case 'circle':
448
+ patch = { cx: ((_g = drag.origLayerX) !== null && _g !== void 0 ? _g : 0) + layer.r + dx, cy: ((_h = drag.origLayerY) !== null && _h !== void 0 ? _h : 0) + layer.r + dy };
449
+ break;
450
+ case 'line':
451
+ patch = {
452
+ x1: layer.x1 + (pos.x - drag.startX),
453
+ y1: layer.y1 + (pos.y - drag.startY),
454
+ x2: layer.x2 + (pos.x - drag.startX),
455
+ y2: layer.y2 + (pos.y - drag.startY),
456
+ };
457
+ // Update start for continuous delta
458
+ drag.startX = pos.x;
459
+ drag.startY = pos.y;
460
+ break;
461
+ }
462
+ dispatch({ type: 'UPDATE_LAYER', id: drag.layerId, patch, noHistory: true });
463
+ return;
464
+ }
465
+ if (drag.mode === 'draw') {
466
+ const x = Math.min(drag.startX, pos.x);
467
+ const y = Math.min(drag.startY, pos.y);
468
+ const w = Math.abs(pos.x - drag.startX);
469
+ const h = Math.abs(pos.y - drag.startY);
470
+ setDrawPreview(prev => prev ? { ...prev, x, y, width: w, height: h } : null);
471
+ }
472
+ }, [screenToCanvas, state.layers, state.zoom]);
473
+ const handleCanvasMouseUp = useCallback(() => {
474
+ const drag = dragRef.current;
475
+ if (!drag)
476
+ return;
477
+ dragRef.current = null;
478
+ if (drag.mode === 'draw' && drawPreview) {
479
+ const minDim = 8;
480
+ const w = Math.max(drawPreview.width, minDim);
481
+ const h = Math.max(drawPreview.height, minDim);
482
+ const x = drawPreview.width < minDim ? drawPreview.x : drawPreview.x;
483
+ const y = drawPreview.height < minDim ? drawPreview.y : drawPreview.y;
484
+ const layer = createDefaultLayer(drawPreview.type, canvasW, canvasH);
485
+ if (drawPreview.type === 'rect') {
486
+ layer.x = x;
487
+ layer.y = y;
488
+ layer.width = w;
489
+ layer.height = h;
490
+ }
491
+ else if (drawPreview.type === 'circle') {
492
+ layer.cx = drawPreview.x + w / 2;
493
+ layer.cy = drawPreview.y + h / 2;
494
+ layer.r = Math.max(w, h) / 2;
495
+ }
496
+ else if (drawPreview.type === 'line') {
497
+ layer.x1 = drag.startX;
498
+ layer.y1 = drag.startY;
499
+ layer.x2 = drag.startX + w;
500
+ layer.y2 = drag.startY + h;
501
+ }
502
+ dispatch({ type: 'ADD_LAYER', layer });
503
+ dispatch({ type: 'SET_TOOL', tool: 'select' });
504
+ setDrawPreview(null);
505
+ return;
506
+ }
507
+ if (drag.mode === 'move' && drag.layerId) {
508
+ // Commit to undo stack — the noHistory moves are now finalized
509
+ // We push a snapshot on mouse-up
510
+ dispatch({ type: 'UPDATE_LAYER', id: drag.layerId, patch: {} });
511
+ }
512
+ setDrawPreview(null);
513
+ }, [drawPreview, canvasW, canvasH]);
514
+ /* ── pan with middle mouse / alt+drag ── */
515
+ useEffect(() => {
516
+ const svg = svgRef.current;
517
+ if (!svg)
518
+ return;
519
+ const onWheel = (e) => {
520
+ e.preventDefault();
521
+ if (e.ctrlKey) {
522
+ dispatch({ type: 'SET_ZOOM', zoom: state.zoom - Math.sign(e.deltaY) * 10 });
523
+ }
524
+ else {
525
+ const scale = 100 / state.zoom;
526
+ dispatch({ type: 'PAN', dx: -e.deltaX * scale * 0.5, dy: -e.deltaY * scale * 0.5 });
527
+ }
528
+ };
529
+ svg.addEventListener('wheel', onWheel, { passive: false });
530
+ return () => svg.removeEventListener('wheel', onWheel);
531
+ }, [state.zoom]);
532
+ /* ── keyboard shortcuts ── */
533
+ const handleKeyDown = useCallback((e) => {
534
+ if (e.target instanceof HTMLInputElement || e.target instanceof HTMLTextAreaElement || e.target instanceof HTMLSelectElement)
535
+ return;
536
+ const ctrl = e.ctrlKey || e.metaKey;
537
+ if (ctrl && e.key === 'z') {
538
+ e.preventDefault();
539
+ dispatch({ type: 'UNDO' });
540
+ return;
541
+ }
542
+ if (ctrl && (e.key === 'y' || (e.shiftKey && e.key === 'Z'))) {
543
+ e.preventDefault();
544
+ dispatch({ type: 'REDO' });
545
+ return;
546
+ }
547
+ if (ctrl && e.key === 'd' && state.selectedId) {
548
+ e.preventDefault();
549
+ dispatch({ type: 'DUPLICATE_LAYER', id: state.selectedId });
550
+ return;
551
+ }
552
+ if (e.key === 'Delete' && state.selectedId) {
553
+ e.preventDefault();
554
+ dispatch({ type: 'REMOVE_LAYER', id: state.selectedId });
555
+ return;
556
+ }
557
+ if (e.key === 'Escape') {
558
+ dispatch({ type: 'SELECT_LAYER', id: null });
559
+ return;
560
+ }
561
+ // Tool shortcuts (only when no modifier)
562
+ if (!ctrl && !e.shiftKey && !e.altKey) {
563
+ const toolMap = { v: 'select', r: 'rect', o: 'circle', l: 'line', t: 'text', h: 'pan' };
564
+ const tool = toolMap[e.key.toLowerCase()];
565
+ if (tool) {
566
+ dispatch({ type: 'SET_TOOL', tool });
567
+ return;
568
+ }
569
+ if (e.key === 'g') {
570
+ dispatch({ type: 'TOGGLE_GRID' });
571
+ return;
572
+ }
573
+ }
574
+ // Nudge with arrow keys
575
+ if (state.selectedId && ['ArrowUp', 'ArrowDown', 'ArrowLeft', 'ArrowRight'].includes(e.key)) {
576
+ e.preventDefault();
577
+ const step = e.shiftKey ? 10 : 1;
578
+ const layer = state.layers.find(l => l.id === state.selectedId);
579
+ if (!layer || layer.locked)
580
+ return;
581
+ let patch = {};
582
+ const dx = e.key === 'ArrowLeft' ? -step : e.key === 'ArrowRight' ? step : 0;
583
+ const dy = e.key === 'ArrowUp' ? -step : e.key === 'ArrowDown' ? step : 0;
584
+ switch (layer.type) {
585
+ case 'rect':
586
+ case 'text':
587
+ case 'icon':
588
+ patch = { x: layer.x + dx, y: layer.y + dy };
589
+ break;
590
+ case 'circle':
591
+ patch = { cx: layer.cx + dx, cy: layer.cy + dy };
592
+ break;
593
+ case 'line':
594
+ patch = { x1: layer.x1 + dx, y1: layer.y1 + dy, x2: layer.x2 + dx, y2: layer.y2 + dy };
595
+ break;
596
+ }
597
+ dispatch({ type: 'UPDATE_LAYER', id: state.selectedId, patch, noHistory: true });
598
+ }
599
+ }, [state.selectedId, state.layers]);
600
+ /* ── export actions ── */
601
+ const handleExportSvg = useCallback(() => {
602
+ const svg = buildSvgMarkup();
603
+ navigator.clipboard.writeText(svg).catch(() => { });
604
+ }, [buildSvgMarkup]);
605
+ const handleExportJson = useCallback(() => {
606
+ const json = JSON.stringify({ width: canvasW, height: canvasH, layers: state.layers }, null, 2);
607
+ navigator.clipboard.writeText(json).catch(() => { });
608
+ }, [state.layers, canvasW, canvasH]);
609
+ /* ── render layer SVG ── */
610
+ const renderLayerSvg = useCallback((layer) => {
611
+ const isSelected = state.selectedId === layer.id;
612
+ const gProps = {
613
+ 'data-layer-id': layer.id,
614
+ style: {
615
+ mixBlendMode: layer.blendMode,
616
+ opacity: layer.opacity,
617
+ cursor: state.tool === 'select' && !layer.locked ? 'move' : undefined,
618
+ },
619
+ };
620
+ if (layer.rotate || layer.scaleX !== 1 || layer.scaleY !== 1) {
621
+ const bounds = getLayerBounds(layer);
622
+ const originX = bounds.x + bounds.w / 2;
623
+ const originY = bounds.y + bounds.h / 2;
624
+ gProps.transform = `rotate(${layer.rotate}, ${originX}, ${originY}) translate(${originX}, ${originY}) scale(${layer.scaleX}, ${layer.scaleY}) translate(${-originX}, ${-originY})`;
625
+ }
626
+ let content = null;
627
+ switch (layer.type) {
628
+ case 'rect':
629
+ content = (jsx("rect", { x: layer.x, y: layer.y, width: layer.width, height: layer.height, rx: layer.rx, fill: layer.fill, fillOpacity: layer.fillOpacity, stroke: layer.stroke, strokeOpacity: layer.strokeOpacity, strokeWidth: layer.strokeWidth }));
630
+ break;
631
+ case 'circle':
632
+ content = (jsx("circle", { cx: layer.cx, cy: layer.cy, r: layer.r, fill: layer.fill, fillOpacity: layer.fillOpacity, stroke: layer.stroke, strokeOpacity: layer.strokeOpacity, strokeWidth: layer.strokeWidth }));
633
+ break;
634
+ case 'line':
635
+ content = (jsx("line", { x1: layer.x1, y1: layer.y1, x2: layer.x2, y2: layer.y2, stroke: layer.stroke, strokeOpacity: layer.strokeOpacity, strokeWidth: layer.strokeWidth, strokeLinecap: "round" }));
636
+ break;
637
+ case 'text':
638
+ content = (jsx("text", { x: layer.x, y: layer.y, fill: layer.fill, fillOpacity: layer.fillOpacity, fontSize: layer.fontSize, fontFamily: layer.fontFamily, children: layer.text }));
639
+ break;
640
+ case 'icon': {
641
+ const IconComp = libraryMap.get(layer.iconName);
642
+ if (IconComp) {
643
+ content = (jsx("foreignObject", { x: layer.x, y: layer.y, width: layer.iconSize, height: layer.iconSize, children: jsx("div", { style: { width: '100%', height: '100%', display: 'flex', alignItems: 'center', justifyContent: 'center' }, children: jsx(IconComp, { size: layer.iconSize, variant: layer.iconVariant, primaryColor: layer.iconPrimaryColor, secondaryColor: layer.iconSecondaryColor, accentColor: layer.iconAccentColor, animation: layer.iconAnimation !== 'none' ? layer.iconAnimation : undefined }) }) }));
644
+ }
645
+ break;
646
+ }
647
+ }
648
+ // Selection indicator
649
+ let selectionBox = null;
650
+ if (isSelected) {
651
+ const b = getLayerBounds(layer);
652
+ const pad = 4;
653
+ selectionBox = (jsx("rect", { x: b.x - pad, y: b.y - pad, width: b.w + pad * 2, height: b.h + pad * 2, fill: "none", stroke: "var(--nve-accent, #a29bfe)", strokeWidth: 1.5 / (state.zoom / 100), strokeDasharray: `${4 / (state.zoom / 100)}`, rx: 2, pointerEvents: "none" }));
654
+ }
655
+ return (jsxs("g", { ...gProps, children: [content, selectionBox] }, layer.id));
656
+ }, [state.selectedId, state.tool, state.zoom, libraryMap]);
657
+ /* ── property update helper ── */
658
+ const updateSelected = useCallback((patch) => {
659
+ if (!state.selectedId)
660
+ return;
661
+ dispatch({ type: 'UPDATE_LAYER', id: state.selectedId, patch });
662
+ }, [state.selectedId]);
663
+ /* ── RENDER ── */
664
+ const hasLibrary = library.length > 0;
665
+ return (jsxs("div", { ref: rootRef, className: `nve-root ${hasLibrary ? '' : 'nve-no-library'} ${className !== null && className !== void 0 ? className : ''}`, tabIndex: 0, onKeyDown: handleKeyDown, children: [jsxs("div", { className: "nve-toolbar", children: [jsxs("div", { className: "nve-toolbar-brand", children: [jsxs("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [jsx("polygon", { points: "12 2 22 8.5 22 15.5 12 22 2 15.5 2 8.5" }), jsx("line", { x1: "12", y1: "22", x2: "12", y2: "15.5" }), jsx("line", { x1: "22", y1: "8.5", x2: "12", y2: "15.5" }), jsx("line", { x1: "2", y1: "8.5", x2: "12", y2: "15.5" })] }), jsx("span", { children: "NiceVectorEditor" })] }), jsx("div", { className: "nve-toolbar-tools", children: TOOL_DEFS.map(t => (jsx("button", { className: `nve-tool-btn ${state.tool === t.id ? 'active' : ''}`, onClick: () => dispatch({ type: 'SET_TOOL', tool: t.id }), title: `${t.label} (${t.shortcut})`, children: jsx("svg", { width: "18", height: "18", viewBox: "0 0 24 24", fill: "none", children: t.icon }) }, t.id))) }), jsxs("div", { className: "nve-toolbar-actions", children: [jsx("button", { className: "nve-action-btn", onClick: () => dispatch({ type: 'UNDO' }), disabled: state.undoStack.length === 0, title: "Undo (Ctrl+Z)", children: jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [jsx("polyline", { points: "1 4 1 10 7 10" }), jsx("path", { d: "M3.51 15a9 9 0 1 0 2.13-9.36L1 10" })] }) }), jsx("button", { className: "nve-action-btn", onClick: () => dispatch({ type: 'REDO' }), disabled: state.redoStack.length === 0, title: "Redo (Ctrl+Y)", children: jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [jsx("polyline", { points: "23 4 23 10 17 10" }), jsx("path", { d: "M20.49 15a9 9 0 1 1-2.13-9.36L23 10" })] }) }), jsx("span", { className: "nve-toolbar-sep" }), jsx("button", { className: "nve-action-btn", onClick: () => dispatch({ type: 'TOGGLE_GRID' }), title: "Toggle Grid (G)", children: jsxs("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", opacity: state.showGrid ? 1 : 0.4, children: [jsx("rect", { x: "3", y: "3", width: "18", height: "18", rx: "2" }), jsx("line", { x1: "3", y1: "9", x2: "21", y2: "9" }), jsx("line", { x1: "3", y1: "15", x2: "21", y2: "15" }), jsx("line", { x1: "9", y1: "3", x2: "9", y2: "21" }), jsx("line", { x1: "15", y1: "3", x2: "15", y2: "21" })] }) }), jsx("button", { className: "nve-action-btn", onClick: () => dispatch({ type: 'RESET_PAN' }), title: "Reset View", children: jsx("svg", { width: "15", height: "15", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("path", { d: "M15 3h6v6M9 21H3v-6M21 3l-7 7M3 21l7-7" }) }) }), jsx("span", { className: "nve-toolbar-sep" }), jsx("button", { className: "nve-action-btn nve-export-btn", onClick: handleExportSvg, title: "Copy SVG to clipboard", children: "SVG" }), jsx("button", { className: "nve-action-btn nve-export-btn", onClick: handleExportJson, title: "Copy JSON to clipboard", children: "JSON" })] })] }), hasLibrary && (jsxs("div", { className: "nve-panel nve-library", children: [jsx("div", { className: "nve-panel-header", children: "Library" }), jsxs("div", { className: "nve-lib-search-wrap", children: [jsxs("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: [jsx("circle", { cx: "11", cy: "11", r: "7" }), jsx("line", { x1: "21", y1: "21", x2: "16", y2: "16" })] }), jsx("input", { className: "nve-lib-search", type: "text", placeholder: "Search library\u2026", value: libSearch, onChange: e => setLibSearch(e.target.value) })] }), libCategories.length > 1 && (jsxs("div", { className: "nve-lib-cats", children: [jsx("button", { className: `nve-cat-btn ${!libCategory ? 'active' : ''}`, onClick: () => setLibCategory(null), children: "All" }), libCategories.map(c => (jsx("button", { className: `nve-cat-btn ${libCategory === c ? 'active' : ''}`, onClick: () => setLibCategory(libCategory === c ? null : c), children: c }, c)))] })), jsxs("div", { className: "nve-lib-grid", children: [filteredLibrary.map(entry => (jsxs("button", { className: "nve-lib-item", onClick: () => addIcon(entry), title: `Add ${entry.name}`, children: [jsx(entry.Component, { size: 28 }), jsx("span", { children: entry.name.replace(/^Ntd/, '') })] }, entry.name))), filteredLibrary.length === 0 && (jsx("div", { className: "nve-lib-empty", children: "No items found" }))] })] })), jsxs("div", { className: "nve-canvas-area", children: [jsxs("svg", { ref: svgRef, className: "nve-canvas", viewBox: viewBox, onMouseDown: handleCanvasMouseDown, onMouseMove: handleCanvasMouseMove, onMouseUp: handleCanvasMouseUp, onMouseLeave: handleCanvasMouseUp, style: { cursor: state.tool === 'pan' ? 'grab' : state.tool === 'select' ? 'default' : 'crosshair' }, children: [state.showGrid && (jsxs(Fragment, { children: [jsxs("defs", { children: [jsx("pattern", { id: "nve-grid-sm", width: "20", height: "20", patternUnits: "userSpaceOnUse", children: jsx("path", { d: "M 20 0 L 0 0 0 20", fill: "none", stroke: "rgba(255,255,255,0.04)", strokeWidth: "0.5" }) }), jsx("pattern", { id: "nve-grid-lg", width: "100", height: "100", patternUnits: "userSpaceOnUse", children: jsx("path", { d: "M 100 0 L 0 0 0 100", fill: "none", stroke: "rgba(255,255,255,0.08)", strokeWidth: "0.5" }) })] }), jsx("rect", { x: "-5000", y: "-5000", width: "10000", height: "10000", fill: "url(#nve-grid-sm)" }), jsx("rect", { x: "-5000", y: "-5000", width: "10000", height: "10000", fill: "url(#nve-grid-lg)" })] })), jsx("rect", { x: "0", y: "0", width: canvasW, height: canvasH, fill: "rgba(255,255,255,0.01)", stroke: "rgba(255,255,255,0.12)", strokeWidth: 1 / (state.zoom / 100), strokeDasharray: `${6 / (state.zoom / 100)}` }), state.layers.filter(l => l.visible).map(renderLayerSvg), drawPreview && (jsxs("g", { pointerEvents: "none", children: [drawPreview.type === 'rect' && (jsx("rect", { x: drawPreview.x, y: drawPreview.y, width: drawPreview.width, height: drawPreview.height, fill: "rgba(162,155,254,0.12)", stroke: "#a29bfe", strokeWidth: 1.5 / (state.zoom / 100), strokeDasharray: `${4 / (state.zoom / 100)}` })), drawPreview.type === 'circle' && (jsx("ellipse", { cx: drawPreview.x + drawPreview.width / 2, cy: drawPreview.y + drawPreview.height / 2, rx: drawPreview.width / 2, ry: drawPreview.height / 2, fill: "rgba(162,155,254,0.12)", stroke: "#a29bfe", strokeWidth: 1.5 / (state.zoom / 100), strokeDasharray: `${4 / (state.zoom / 100)}` })), drawPreview.type === 'line' && (jsx("line", { x1: drawPreview.x, y1: drawPreview.y, x2: drawPreview.x + drawPreview.width, y2: drawPreview.y + drawPreview.height, stroke: "#a29bfe", strokeWidth: 1.5 / (state.zoom / 100), strokeDasharray: `${4 / (state.zoom / 100)}`, strokeLinecap: "round" }))] }))] }), jsxs("div", { className: "nve-zoom-controls", children: [jsx("button", { onClick: () => dispatch({ type: 'SET_ZOOM', zoom: state.zoom - 25 }), title: "Zoom out", children: "\u2212" }), jsxs("span", { className: "nve-zoom-label", children: [state.zoom, "%"] }), jsx("button", { onClick: () => dispatch({ type: 'SET_ZOOM', zoom: state.zoom + 25 }), title: "Zoom in", children: "+" })] })] }), jsxs("div", { className: "nve-sidebar", children: [jsxs("div", { className: "nve-panel nve-layers", children: [jsxs("div", { className: "nve-panel-header", children: [jsx("span", { children: "Layers" }), jsxs("div", { className: "nve-layers-add", children: [jsx("button", { onClick: () => addShape('rect'), title: "Add Rectangle", children: jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("rect", { x: "4", y: "4", width: "16", height: "16", rx: "2" }) }) }), jsx("button", { onClick: () => addShape('circle'), title: "Add Circle", children: jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("circle", { cx: "12", cy: "12", r: "8" }) }) }), jsx("button", { onClick: () => addShape('line'), title: "Add Line", children: jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("line", { x1: "5", y1: "19", x2: "19", y2: "5", strokeLinecap: "round" }) }) }), jsx("button", { onClick: () => addShape('text'), title: "Add Text", children: jsx("svg", { width: "14", height: "14", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: jsx("text", { x: "5", y: "17", fontSize: "14", fontWeight: "700", fill: "currentColor", stroke: "none", children: "T" }) }) })] })] }), jsxs("div", { className: "nve-layers-list", children: [state.layers.length === 0 && (jsx("div", { className: "nve-empty-hint", children: "Add shapes or icons from the library" })), state.layers.slice().reverse().map(layer => (jsxs("div", { className: `nve-layer-row ${state.selectedId === layer.id ? 'active' : ''} ${layer.locked ? 'locked' : ''}`, onClick: () => dispatch({ type: 'SELECT_LAYER', id: layer.id }), children: [jsxs("span", { className: "nve-layer-type-icon", children: [layer.type === 'rect' && '▭', layer.type === 'circle' && '○', layer.type === 'line' && '╱', layer.type === 'text' && 'T', layer.type === 'icon' && '◆'] }), jsx("span", { className: "nve-layer-name", children: layer.name }), jsxs("span", { className: "nve-layer-btns", children: [jsx("button", { onClick: e => { e.stopPropagation(); dispatch({ type: 'UPDATE_LAYER', id: layer.id, patch: { visible: !layer.visible } }); }, title: layer.visible ? 'Hide' : 'Show', className: layer.visible ? '' : 'off', children: jsx("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: layer.visible
666
+ ? jsxs(Fragment, { children: [jsx("path", { d: "M1 12s4-8 11-8 11 8 11 8-4 8-11 8-11-8-11-8z" }), jsx("circle", { cx: "12", cy: "12", r: "3" })] })
667
+ : jsxs(Fragment, { children: [jsx("path", { d: "M17.94 17.94A10.07 10.07 0 0 1 12 20c-7 0-11-8-11-8a18.45 18.45 0 0 1 5.06-5.94" }), jsx("line", { x1: "1", y1: "1", x2: "23", y2: "23" })] }) }) }), jsx("button", { onClick: e => { e.stopPropagation(); dispatch({ type: 'UPDATE_LAYER', id: layer.id, patch: { locked: !layer.locked } }); }, title: layer.locked ? 'Unlock' : 'Lock', className: layer.locked ? 'on' : '', children: jsx("svg", { width: "12", height: "12", viewBox: "0 0 24 24", fill: "none", stroke: "currentColor", strokeWidth: "2", children: layer.locked
668
+ ? jsxs(Fragment, { children: [jsx("rect", { x: "3", y: "11", width: "18", height: "11", rx: "2" }), jsx("path", { d: "M7 11V7a5 5 0 0 1 10 0v4" })] })
669
+ : jsxs(Fragment, { children: [jsx("rect", { x: "3", y: "11", width: "18", height: "11", rx: "2" }), jsx("path", { d: "M7 11V7a5 5 0 0 1 9.9-1" })] }) }) })] })] }, layer.id)))] }), selectedLayer && (jsxs("div", { className: "nve-layer-actions", children: [jsx("button", { onClick: () => dispatch({ type: 'MOVE_LAYER', id: state.selectedId, direction: 'up' }), title: "Move Up", children: "\u2191" }), jsx("button", { onClick: () => dispatch({ type: 'MOVE_LAYER', id: state.selectedId, direction: 'down' }), title: "Move Down", children: "\u2193" }), jsx("button", { onClick: () => dispatch({ type: 'DUPLICATE_LAYER', id: state.selectedId }), title: "Duplicate (Ctrl+D)", children: "\u29C9" }), jsx("button", { onClick: () => dispatch({ type: 'REMOVE_LAYER', id: state.selectedId }), title: "Delete (Del)", className: "nve-danger", children: "\u2715" })] }))] }), jsxs("div", { className: "nve-panel nve-properties", children: [jsx("div", { className: "nve-panel-header", children: "Properties" }), selectedLayer ? (jsxs("div", { className: "nve-props-scroll", children: [jsx("div", { className: "nve-prop-section", children: jsx("input", { className: "nve-prop-name", value: selectedLayer.name, onChange: e => updateSelected({ name: e.target.value }) }) }), jsxs("div", { className: "nve-prop-section", children: [jsx("div", { className: "nve-prop-section-title", children: "Position & Size" }), (selectedLayer.type === 'rect' || selectedLayer.type === 'text' || selectedLayer.type === 'icon') && (jsxs("div", { className: "nve-prop-grid", children: [jsxs("label", { children: ["X", jsx("input", { type: "number", value: selectedLayer.x, onChange: e => updateSelected({ x: Number(e.target.value) }) })] }), jsxs("label", { children: ["Y", jsx("input", { type: "number", value: selectedLayer.y, onChange: e => updateSelected({ y: Number(e.target.value) }) })] }), selectedLayer.type === 'rect' && (jsxs(Fragment, { children: [jsxs("label", { children: ["W", jsx("input", { type: "number", value: selectedLayer.width, onChange: e => updateSelected({ width: Math.max(1, Number(e.target.value)) }) })] }), jsxs("label", { children: ["H", jsx("input", { type: "number", value: selectedLayer.height, onChange: e => updateSelected({ height: Math.max(1, Number(e.target.value)) }) })] }), jsxs("label", { children: ["RX", jsx("input", { type: "number", value: selectedLayer.rx, onChange: e => updateSelected({ rx: Math.max(0, Number(e.target.value)) }) })] })] })), selectedLayer.type === 'icon' && (jsxs("label", { children: ["Size", jsx("input", { type: "number", value: selectedLayer.iconSize, onChange: e => updateSelected({ iconSize: Math.max(8, Number(e.target.value)) }) })] }))] })), selectedLayer.type === 'circle' && (jsxs("div", { className: "nve-prop-grid", children: [jsxs("label", { children: ["CX", jsx("input", { type: "number", value: selectedLayer.cx, onChange: e => updateSelected({ cx: Number(e.target.value) }) })] }), jsxs("label", { children: ["CY", jsx("input", { type: "number", value: selectedLayer.cy, onChange: e => updateSelected({ cy: Number(e.target.value) }) })] }), jsxs("label", { children: ["R", jsx("input", { type: "number", value: selectedLayer.r, onChange: e => updateSelected({ r: Math.max(1, Number(e.target.value)) }) })] })] })), selectedLayer.type === 'line' && (jsxs("div", { className: "nve-prop-grid", children: [jsxs("label", { children: ["X1", jsx("input", { type: "number", value: selectedLayer.x1, onChange: e => updateSelected({ x1: Number(e.target.value) }) })] }), jsxs("label", { children: ["Y1", jsx("input", { type: "number", value: selectedLayer.y1, onChange: e => updateSelected({ y1: Number(e.target.value) }) })] }), jsxs("label", { children: ["X2", jsx("input", { type: "number", value: selectedLayer.x2, onChange: e => updateSelected({ x2: Number(e.target.value) }) })] }), jsxs("label", { children: ["Y2", jsx("input", { type: "number", value: selectedLayer.y2, onChange: e => updateSelected({ y2: Number(e.target.value) }) })] })] }))] }), selectedLayer.type !== 'icon' && (jsxs("div", { className: "nve-prop-section", children: [jsx("div", { className: "nve-prop-section-title", children: "Appearance" }), jsxs("div", { className: "nve-prop-grid", children: [jsxs("label", { className: "nve-color-prop", children: ["Fill", jsxs("div", { className: "nve-color-cell", children: [jsx("span", { className: "nve-color-swatch", style: { background: selectedLayer.fill } }), jsx("input", { type: "color", value: selectedLayer.fill, onChange: e => updateSelected({ fill: e.target.value }) })] })] }), jsxs("label", { children: [jsx("span", { className: "nve-prop-label-sm", children: "Fill \u03B1" }), jsx("input", { type: "range", min: "0", max: "1", step: "0.05", value: selectedLayer.fillOpacity, onChange: e => updateSelected({ fillOpacity: Number(e.target.value) }) })] }), jsxs("label", { className: "nve-color-prop", children: ["Stroke", jsxs("div", { className: "nve-color-cell", children: [jsx("span", { className: "nve-color-swatch", style: { background: selectedLayer.stroke } }), jsx("input", { type: "color", value: selectedLayer.stroke, onChange: e => updateSelected({ stroke: e.target.value }) })] })] }), jsxs("label", { children: [jsx("span", { className: "nve-prop-label-sm", children: "Stroke \u03B1" }), jsx("input", { type: "range", min: "0", max: "1", step: "0.05", value: selectedLayer.strokeOpacity, onChange: e => updateSelected({ strokeOpacity: Number(e.target.value) }) })] }), jsxs("label", { children: [jsx("span", { className: "nve-prop-label-sm", children: "Stroke W" }), jsx("input", { type: "number", min: "0", max: "20", step: "0.5", value: selectedLayer.strokeWidth, onChange: e => updateSelected({ strokeWidth: Number(e.target.value) }) })] })] })] })), selectedLayer.type === 'icon' && (jsxs("div", { className: "nve-prop-section", children: [jsx("div", { className: "nve-prop-section-title", children: "Icon" }), jsxs("div", { className: "nve-prop-grid nve-prop-wide", children: [jsxs("label", { children: ["Variant", jsx("select", { value: selectedLayer.iconVariant, onChange: e => updateSelected({ iconVariant: e.target.value }), children: ICON_VARIANTS.map(v => jsx("option", { value: v, children: v }, v)) })] }), jsxs("label", { className: "nve-color-prop", children: ["Primary", jsxs("div", { className: "nve-color-cell", children: [jsx("span", { className: "nve-color-swatch", style: { background: selectedLayer.iconPrimaryColor } }), jsx("input", { type: "color", value: selectedLayer.iconPrimaryColor, onChange: e => updateSelected({ iconPrimaryColor: e.target.value }) })] })] }), jsxs("label", { className: "nve-color-prop", children: ["Secondary", jsxs("div", { className: "nve-color-cell", children: [jsx("span", { className: "nve-color-swatch", style: { background: selectedLayer.iconSecondaryColor } }), jsx("input", { type: "color", value: selectedLayer.iconSecondaryColor, onChange: e => updateSelected({ iconSecondaryColor: e.target.value }) })] })] }), jsxs("label", { className: "nve-color-prop", children: ["Accent", jsxs("div", { className: "nve-color-cell", children: [jsx("span", { className: "nve-color-swatch", style: { background: selectedLayer.iconAccentColor } }), jsx("input", { type: "color", value: selectedLayer.iconAccentColor, onChange: e => updateSelected({ iconAccentColor: e.target.value }) })] })] }), jsxs("label", { children: ["Animation", jsx("select", { value: selectedLayer.iconAnimation, onChange: e => updateSelected({ iconAnimation: e.target.value }), children: ICON_ANIMATIONS.map(a => jsx("option", { value: a, children: a }, a)) })] })] })] })), selectedLayer.type === 'text' && (jsxs("div", { className: "nve-prop-section", children: [jsx("div", { className: "nve-prop-section-title", children: "Text" }), jsxs("div", { className: "nve-prop-grid nve-prop-wide", children: [jsxs("label", { children: ["Content", jsx("input", { type: "text", value: selectedLayer.text, onChange: e => updateSelected({ text: e.target.value }) })] }), jsxs("label", { children: ["Font Size", jsx("input", { type: "number", min: "8", max: "200", value: selectedLayer.fontSize, onChange: e => updateSelected({ fontSize: Math.max(8, Number(e.target.value)) }) })] }), jsxs("label", { children: ["Font", jsxs("select", { value: selectedLayer.fontFamily, onChange: e => updateSelected({ fontFamily: e.target.value }), children: [jsx("option", { value: "sans-serif", children: "Sans-serif" }), jsx("option", { value: "serif", children: "Serif" }), jsx("option", { value: "monospace", children: "Monospace" }), jsx("option", { value: "cursive", children: "Cursive" })] })] })] })] })), jsxs("div", { className: "nve-prop-section", children: [jsx("div", { className: "nve-prop-section-title", children: "Transform" }), jsxs("div", { className: "nve-prop-grid", children: [jsxs("label", { children: ["Rotate ", jsxs("strong", { children: [selectedLayer.rotate, "\u00B0"] }), jsx("input", { type: "range", min: "-180", max: "180", step: "1", value: selectedLayer.rotate, onChange: e => updateSelected({ rotate: Number(e.target.value) }) })] }), jsxs("label", { children: ["Opacity ", jsxs("strong", { children: [Math.round(selectedLayer.opacity * 100), "%"] }), jsx("input", { type: "range", min: "0", max: "1", step: "0.05", value: selectedLayer.opacity, onChange: e => updateSelected({ opacity: Number(e.target.value) }) })] }), jsxs("label", { children: ["Blend", jsx("select", { value: selectedLayer.blendMode, onChange: e => updateSelected({ blendMode: e.target.value }), children: BLEND_MODES.map(m => jsx("option", { value: m, children: m }, m)) })] })] })] })] })) : (jsx("div", { className: "nve-empty-hint", children: "Select a layer to edit its properties" }))] })] }), jsxs("div", { className: "nve-statusbar", children: [jsxs("span", { children: ["Zoom: ", state.zoom, "%"] }), jsxs("span", { children: [canvasW, " \u00D7 ", canvasH] }), jsxs("span", { children: [state.layers.length, " layer", state.layers.length !== 1 ? 's' : ''] }), selectedLayer && jsxs("span", { className: "nve-status-selected", children: ["\u25CF ", selectedLayer.name] }), jsx("span", { className: "nve-status-shortcuts", children: "V Select \u00B7 R Rect \u00B7 O Circle \u00B7 L Line \u00B7 T Text \u00B7 H Pan \u00B7 G Grid" })] })] }));
670
+ });
671
+
672
+ export { NiceVectorEditor };
673
+ //# sourceMappingURL=NiceVectorEditor.js.map