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