@nice2dev/ui-graphics 1.3.15 → 1.3.17

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 (294) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/dist/cjs/animation/AnimatedPerson.js +470 -143
  3. package/dist/cjs/animation/AnimationEditor.js +289 -101
  4. package/dist/cjs/animation/Audience.js +83 -61
  5. package/dist/cjs/animation/BodyRenderer.js +69 -28
  6. package/dist/cjs/animation/animationHelper.js +281 -288
  7. package/dist/cjs/animation/characterTypes.js +200 -203
  8. package/dist/cjs/animation/choreoDSL.js +205 -219
  9. package/dist/cjs/animation/choreography.js +4 -32
  10. package/dist/cjs/animation/karaokeIntegration.js +68 -77
  11. package/dist/cjs/animation/lottieExport.js +108 -114
  12. package/dist/cjs/animation/motionPath.js +225 -248
  13. package/dist/cjs/animation/physics.js +227 -254
  14. package/dist/cjs/animation/rig/RigPlayer.js +53 -56
  15. package/dist/cjs/animation/rig/RiggedBody.js +71 -26
  16. package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
  17. package/dist/cjs/animation/rig/ik.js +13 -18
  18. package/dist/cjs/animation/rig/poseOps.js +34 -41
  19. package/dist/cjs/animation/rig/presets.js +64 -72
  20. package/dist/cjs/animation/rig/rigMath.js +25 -32
  21. package/dist/cjs/animation/rig/rigTypes.js +59 -63
  22. package/dist/cjs/animation/shapes/arms.js +31 -13
  23. package/dist/cjs/animation/shapes/eyes.js +129 -47
  24. package/dist/cjs/animation/shapes/hair.js +72 -45
  25. package/dist/cjs/animation/shapes/heads.js +131 -57
  26. package/dist/cjs/animation/shapes/headwear.js +47 -38
  27. package/dist/cjs/animation/shapes/legs.js +31 -13
  28. package/dist/cjs/animation/shapes/mouths.js +120 -44
  29. package/dist/cjs/animation/shapes/noses.js +80 -25
  30. package/dist/cjs/animation/shapes/outfits.js +101 -39
  31. package/dist/cjs/animation/shapes/torsos.js +15 -11
  32. package/dist/cjs/animation/spineExport.js +103 -121
  33. package/dist/cjs/core/LocalUI.js +108 -43
  34. package/dist/cjs/core/NiceBrushEngine.js +758 -552
  35. package/dist/cjs/core/collaboration.js +249 -251
  36. package/dist/cjs/core/colorBlindness.js +100 -115
  37. package/dist/cjs/core/dragDrop.js +155 -158
  38. package/dist/cjs/core/editorAsk.js +51 -41
  39. package/dist/cjs/core/fixes.js +140 -171
  40. package/dist/cjs/core/gridGuides.js +166 -201
  41. package/dist/cjs/core/historyVisual.js +156 -135
  42. package/dist/cjs/core/i18n.js +13 -14
  43. package/dist/cjs/core/integrations.js +238 -249
  44. package/dist/cjs/core/minimap.js +149 -151
  45. package/dist/cjs/core/plugins.js +98 -113
  46. package/dist/cjs/core/rtl.js +71 -83
  47. package/dist/cjs/core/shortcuts.js +196 -225
  48. package/dist/cjs/core/theme.js +142 -149
  49. package/dist/cjs/core/yjsCollaboration.js +232 -293
  50. package/dist/cjs/design/design-tools.js +12 -22
  51. package/dist/cjs/font/NiceFontEditor.js +877 -316
  52. package/dist/cjs/font/fontFormatUtils.js +388 -448
  53. package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
  54. package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
  55. package/dist/cjs/game/gameAssetTypes.js +7 -16
  56. package/dist/cjs/game/gameAssetUtils.js +390 -413
  57. package/dist/cjs/game/useGameAssetEditor.js +820 -763
  58. package/dist/cjs/index.js +81 -84
  59. package/dist/cjs/nice2dev-ui-graphics.css +1 -1
  60. package/dist/cjs/node_modules/lib0/array.js +8 -70
  61. package/dist/cjs/node_modules/lib0/binary.js +3 -20
  62. package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
  63. package/dist/cjs/node_modules/lib0/buffer.js +15 -82
  64. package/dist/cjs/node_modules/lib0/conditions.js +3 -16
  65. package/dist/cjs/node_modules/lib0/decoding.js +108 -287
  66. package/dist/cjs/node_modules/lib0/dom.js +14 -44
  67. package/dist/cjs/node_modules/lib0/encoding.js +68 -418
  68. package/dist/cjs/node_modules/lib0/environment.js +26 -92
  69. package/dist/cjs/node_modules/lib0/error.js +5 -29
  70. package/dist/cjs/node_modules/lib0/function.js +27 -66
  71. package/dist/cjs/node_modules/lib0/iterator.js +8 -33
  72. package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
  73. package/dist/cjs/node_modules/lib0/logging.js +32 -71
  74. package/dist/cjs/node_modules/lib0/map.js +16 -86
  75. package/dist/cjs/node_modules/lib0/math.js +3 -32
  76. package/dist/cjs/node_modules/lib0/number.js +4 -15
  77. package/dist/cjs/node_modules/lib0/object.js +14 -88
  78. package/dist/cjs/node_modules/lib0/observable.js +38 -78
  79. package/dist/cjs/node_modules/lib0/pair.js +3 -20
  80. package/dist/cjs/node_modules/lib0/prng.js +8 -77
  81. package/dist/cjs/node_modules/lib0/promise.js +6 -30
  82. package/dist/cjs/node_modules/lib0/random.js +8 -23
  83. package/dist/cjs/node_modules/lib0/schema.js +313 -687
  84. package/dist/cjs/node_modules/lib0/set.js +3 -10
  85. package/dist/cjs/node_modules/lib0/storage.js +20 -55
  86. package/dist/cjs/node_modules/lib0/string.js +17 -72
  87. package/dist/cjs/node_modules/lib0/symbol.js +2 -12
  88. package/dist/cjs/node_modules/lib0/time.js +2 -15
  89. package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
  90. package/dist/cjs/node_modules/lib0/url.js +4 -18
  91. package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
  92. package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
  93. package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
  94. package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
  95. package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
  96. package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
  97. package/dist/cjs/photo/FilterThumb.js +37 -25
  98. package/dist/cjs/photo/NiceAITools.js +679 -467
  99. package/dist/cjs/photo/PhotoEditor.js +34 -20
  100. package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
  101. package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
  102. package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
  103. package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
  104. package/dist/cjs/photo/photoEditorActions.js +89 -72
  105. package/dist/cjs/photo/photoEditorTypes.js +29 -32
  106. package/dist/cjs/photo/photoFilters.js +959 -985
  107. package/dist/cjs/photo/photoOverlays.js +899 -945
  108. package/dist/cjs/photo/photoSelection.js +427 -499
  109. package/dist/cjs/photo/usePhotoEditor.js +739 -741
  110. package/dist/cjs/pixel/HSVPicker.js +191 -175
  111. package/dist/cjs/pixel/PixelEditor.js +159 -48
  112. package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
  113. package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
  114. package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
  115. package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
  116. package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
  117. package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
  118. package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
  119. package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
  120. package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
  121. package/dist/cjs/pixel/asepriteFormat.js +511 -560
  122. package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
  123. package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
  124. package/dist/cjs/pixel/pixel-pro.js +52 -63
  125. package/dist/cjs/pixel/pixelEditorExports.js +388 -428
  126. package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
  127. package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
  128. package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
  129. package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
  130. package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
  131. package/dist/cjs/ui/NiceUIDesigner.js +954 -527
  132. package/dist/cjs/vector/NiceSvgToCode.js +586 -446
  133. package/dist/cjs/vector/VectorEditor.js +290 -117
  134. package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
  135. package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
  136. package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
  137. package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
  138. package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
  139. package/dist/cjs/vector/useVectorEditor.js +848 -889
  140. package/dist/cjs/vector/vectorAnimation.js +110 -137
  141. package/dist/cjs/vector/vectorBooleanOps.js +398 -485
  142. package/dist/cjs/vector/vectorEditorExport.js +201 -203
  143. package/dist/cjs/vector/vectorEditorImport.js +173 -189
  144. package/dist/cjs/vector/vectorEditorTypes.js +42 -49
  145. package/dist/cjs/vector/vectorGradients.js +151 -174
  146. package/dist/cjs/vector/vectorIconExport.js +52 -59
  147. package/dist/cjs/vector/vectorIconImport.js +169 -219
  148. package/dist/esm/animation/AnimatedPerson.js +470 -141
  149. package/dist/esm/animation/AnimationEditor.js +290 -100
  150. package/dist/esm/animation/Audience.js +83 -59
  151. package/dist/esm/animation/BodyRenderer.js +71 -25
  152. package/dist/esm/animation/animationHelper.js +284 -287
  153. package/dist/esm/animation/characterTypes.js +204 -202
  154. package/dist/esm/animation/choreoDSL.js +212 -218
  155. package/dist/esm/animation/choreography.js +8 -31
  156. package/dist/esm/animation/karaokeIntegration.js +74 -76
  157. package/dist/esm/animation/lottieExport.js +112 -113
  158. package/dist/esm/animation/motionPath.js +235 -247
  159. package/dist/esm/animation/physics.js +235 -253
  160. package/dist/esm/animation/rig/RigPlayer.js +53 -54
  161. package/dist/esm/animation/rig/RiggedBody.js +71 -24
  162. package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
  163. package/dist/esm/animation/rig/ik.js +14 -17
  164. package/dist/esm/animation/rig/poseOps.js +37 -40
  165. package/dist/esm/animation/rig/presets.js +70 -71
  166. package/dist/esm/animation/rig/rigMath.js +28 -31
  167. package/dist/esm/animation/rig/rigTypes.js +62 -62
  168. package/dist/esm/animation/shapes/arms.js +32 -12
  169. package/dist/esm/animation/shapes/eyes.js +135 -46
  170. package/dist/esm/animation/shapes/hair.js +80 -44
  171. package/dist/esm/animation/shapes/heads.js +140 -56
  172. package/dist/esm/animation/shapes/headwear.js +54 -37
  173. package/dist/esm/animation/shapes/legs.js +32 -12
  174. package/dist/esm/animation/shapes/mouths.js +127 -43
  175. package/dist/esm/animation/shapes/noses.js +87 -24
  176. package/dist/esm/animation/shapes/outfits.js +106 -38
  177. package/dist/esm/animation/shapes/torsos.js +16 -10
  178. package/dist/esm/animation/spineExport.js +106 -120
  179. package/dist/esm/core/LocalUI.js +111 -42
  180. package/dist/esm/core/NiceBrushEngine.js +761 -551
  181. package/dist/esm/core/collaboration.js +255 -250
  182. package/dist/esm/core/colorBlindness.js +106 -114
  183. package/dist/esm/core/dragDrop.js +157 -157
  184. package/dist/esm/core/editorAsk.js +53 -40
  185. package/dist/esm/core/fixes.js +145 -170
  186. package/dist/esm/core/gridGuides.js +178 -200
  187. package/dist/esm/core/historyVisual.js +158 -134
  188. package/dist/esm/core/i18n.js +15 -13
  189. package/dist/esm/core/integrations.js +244 -248
  190. package/dist/esm/core/minimap.js +151 -150
  191. package/dist/esm/core/plugins.js +102 -112
  192. package/dist/esm/core/rtl.js +77 -82
  193. package/dist/esm/core/shortcuts.js +200 -224
  194. package/dist/esm/core/theme.js +150 -148
  195. package/dist/esm/core/yjsCollaboration.js +240 -292
  196. package/dist/esm/design/design-tools.js +13 -21
  197. package/dist/esm/font/NiceFontEditor.js +880 -315
  198. package/dist/esm/font/fontFormatUtils.js +394 -447
  199. package/dist/esm/game/GameAsset2dEditor.js +1202 -391
  200. package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
  201. package/dist/esm/game/gameAssetTypes.js +8 -15
  202. package/dist/esm/game/gameAssetUtils.js +408 -412
  203. package/dist/esm/game/useGameAssetEditor.js +821 -762
  204. package/dist/esm/index.js +332 -69
  205. package/dist/esm/nice2dev-ui-graphics.css +1 -1
  206. package/dist/esm/node_modules/lib0/array.js +15 -69
  207. package/dist/esm/node_modules/lib0/binary.js +14 -19
  208. package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
  209. package/dist/esm/node_modules/lib0/buffer.js +20 -80
  210. package/dist/esm/node_modules/lib0/conditions.js +4 -15
  211. package/dist/esm/node_modules/lib0/decoding.js +128 -286
  212. package/dist/esm/node_modules/lib0/dom.js +20 -43
  213. package/dist/esm/node_modules/lib0/encoding.js +90 -415
  214. package/dist/esm/node_modules/lib0/environment.js +33 -91
  215. package/dist/esm/node_modules/lib0/error.js +8 -28
  216. package/dist/esm/node_modules/lib0/function.js +31 -65
  217. package/dist/esm/node_modules/lib0/iterator.js +11 -32
  218. package/dist/esm/node_modules/lib0/logging.common.js +22 -21
  219. package/dist/esm/node_modules/lib0/logging.js +44 -70
  220. package/dist/esm/node_modules/lib0/map.js +21 -85
  221. package/dist/esm/node_modules/lib0/math.js +9 -31
  222. package/dist/esm/node_modules/lib0/number.js +7 -14
  223. package/dist/esm/node_modules/lib0/object.js +26 -87
  224. package/dist/esm/node_modules/lib0/observable.js +40 -77
  225. package/dist/esm/node_modules/lib0/pair.js +5 -19
  226. package/dist/esm/node_modules/lib0/prng.js +15 -76
  227. package/dist/esm/node_modules/lib0/promise.js +7 -29
  228. package/dist/esm/node_modules/lib0/random.js +10 -22
  229. package/dist/esm/node_modules/lib0/schema.js +367 -686
  230. package/dist/esm/node_modules/lib0/set.js +4 -9
  231. package/dist/esm/node_modules/lib0/storage.js +23 -54
  232. package/dist/esm/node_modules/lib0/string.js +26 -71
  233. package/dist/esm/node_modules/lib0/symbol.js +3 -11
  234. package/dist/esm/node_modules/lib0/time.js +3 -14
  235. package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
  236. package/dist/esm/node_modules/lib0/url.js +5 -17
  237. package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
  238. package/dist/esm/node_modules/y-protocols/auth.js +7 -18
  239. package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
  240. package/dist/esm/node_modules/y-protocols/sync.js +26 -102
  241. package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
  242. package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
  243. package/dist/esm/photo/FilterThumb.js +37 -23
  244. package/dist/esm/photo/NiceAITools.js +685 -466
  245. package/dist/esm/photo/PhotoEditor.js +34 -18
  246. package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
  247. package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
  248. package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
  249. package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
  250. package/dist/esm/photo/photoEditorActions.js +93 -71
  251. package/dist/esm/photo/photoEditorTypes.js +32 -31
  252. package/dist/esm/photo/photoFilters.js +967 -984
  253. package/dist/esm/photo/photoOverlays.js +913 -944
  254. package/dist/esm/photo/photoSelection.js +438 -498
  255. package/dist/esm/photo/usePhotoEditor.js +740 -740
  256. package/dist/esm/pixel/HSVPicker.js +192 -174
  257. package/dist/esm/pixel/PixelEditor.js +160 -47
  258. package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
  259. package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
  260. package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
  261. package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
  262. package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
  263. package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
  264. package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
  265. package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
  266. package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
  267. package/dist/esm/pixel/asepriteFormat.js +517 -559
  268. package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
  269. package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
  270. package/dist/esm/pixel/pixel-pro.js +53 -62
  271. package/dist/esm/pixel/pixelEditorExports.js +397 -427
  272. package/dist/esm/pixel/pixelEditorTypes.js +103 -107
  273. package/dist/esm/pixel/pixelEditorUtils.js +551 -560
  274. package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
  275. package/dist/esm/pixel/usePixelEditor.js +1322 -1342
  276. package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
  277. package/dist/esm/ui/NiceUIDesigner.js +957 -526
  278. package/dist/esm/vector/NiceSvgToCode.js +589 -445
  279. package/dist/esm/vector/VectorEditor.js +291 -116
  280. package/dist/esm/vector/VectorEditor.module.css.js +86 -3
  281. package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
  282. package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
  283. package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
  284. package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
  285. package/dist/esm/vector/useVectorEditor.js +849 -888
  286. package/dist/esm/vector/vectorAnimation.js +115 -136
  287. package/dist/esm/vector/vectorBooleanOps.js +401 -484
  288. package/dist/esm/vector/vectorEditorExport.js +207 -202
  289. package/dist/esm/vector/vectorEditorImport.js +174 -188
  290. package/dist/esm/vector/vectorEditorTypes.js +50 -48
  291. package/dist/esm/vector/vectorGradients.js +158 -173
  292. package/dist/esm/vector/vectorIconExport.js +53 -58
  293. package/dist/esm/vector/vectorIconImport.js +171 -218
  294. package/package.json +9 -15
@@ -1,487 +1,631 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
2
- import { NiceIcon } from '@nice2dev/ui-core';
3
- import React, { useState, useCallback } from 'react';
4
- import { useNiceTranslation } from '../core/i18n.js';
5
-
6
- /* ── Default config ── */
1
+ import { jsxs, jsx } from "react/jsx-runtime";
2
+ import { NiceIcon } from "@nice2dev/ui-core";
3
+ import React, { useState, useCallback } from "react";
4
+ import { useNiceTranslation } from "../core/i18n.js";
7
5
  const DEFAULT_CONFIG = {
8
- framework: 'react',
9
- componentName: 'MyIcon',
10
- extractColors: true,
11
- useClassNames: false,
12
- typescript: true,
13
- optimize: true,
14
- sizeProps: true,
15
- useCurrentColor: false,
16
- memo: true,
17
- defaultExport: true,
18
- ariaLabel: true,
6
+ framework: "react",
7
+ componentName: "MyIcon",
8
+ extractColors: true,
9
+ useClassNames: false,
10
+ typescript: true,
11
+ optimize: true,
12
+ sizeProps: true,
13
+ useCurrentColor: false,
14
+ memo: true,
15
+ defaultExport: true,
16
+ ariaLabel: true
19
17
  };
20
- /* ── SVG Parser (simple regex-based for browser) ── */
21
- const METADATA_TAGS = new Set(['metadata', 'title', 'desc', 'defs', 'comment']);
22
- const REMOVABLE_ATTRS = new Set([
23
- 'xmlns:xlink',
24
- 'xml:space',
25
- 'xmlns:svg',
26
- 'version',
27
- 'xmlns:dc',
28
- 'xmlns:cc',
29
- 'xmlns:rdf',
30
- 'xmlns:sodipodi',
31
- 'xmlns:inkscape',
32
- 'sodipodi:docname',
33
- 'inkscape:version',
34
- 'data-name',
18
+ const METADATA_TAGS = /* @__PURE__ */ new Set(["metadata", "title", "desc", "defs", "comment"]);
19
+ const REMOVABLE_ATTRS = /* @__PURE__ */ new Set([
20
+ "xmlns:xlink",
21
+ "xml:space",
22
+ "xmlns:svg",
23
+ "version",
24
+ "xmlns:dc",
25
+ "xmlns:cc",
26
+ "xmlns:rdf",
27
+ "xmlns:sodipodi",
28
+ "xmlns:inkscape",
29
+ "sodipodi:docname",
30
+ "inkscape:version",
31
+ "data-name"
35
32
  ]);
36
33
  function parseSvgString(svg) {
37
- // Use DOMParser for safe parsing
38
- if (typeof DOMParser === 'undefined') {
39
- return null;
34
+ if (typeof DOMParser === "undefined") {
35
+ return null;
36
+ }
37
+ const parser = new DOMParser();
38
+ const doc = parser.parseFromString(svg, "image/svg+xml");
39
+ const error = doc.querySelector("parsererror");
40
+ if (error) {
41
+ return null;
42
+ }
43
+ function elementToNode(el) {
44
+ const attrs = {};
45
+ for (const attr of Array.from(el.attributes)) {
46
+ attrs[attr.name] = attr.value;
40
47
  }
41
- const parser = new DOMParser();
42
- const doc = parser.parseFromString(svg, 'image/svg+xml');
43
- const error = doc.querySelector('parsererror');
44
- if (error) {
45
- return null;
48
+ const children = [];
49
+ for (const child of Array.from(el.children)) {
50
+ children.push(elementToNode(child));
46
51
  }
47
- function elementToNode(el) {
48
- const attrs = {};
49
- for (const attr of Array.from(el.attributes)) {
50
- attrs[attr.name] = attr.value;
51
- }
52
- const children = [];
53
- for (const child of Array.from(el.children)) {
54
- children.push(elementToNode(child));
55
- }
56
- const text = el.childNodes.length === 1 && el.childNodes[0].nodeType === 3
57
- ? el.childNodes[0].textContent || undefined
58
- : undefined;
59
- return { tag: el.tagName.toLowerCase(), attrs, children, text };
60
- }
61
- const svgEl = doc.querySelector('svg');
62
- if (!svgEl) {
63
- return null;
64
- }
65
- return elementToNode(svgEl);
52
+ const text = el.childNodes.length === 1 && el.childNodes[0].nodeType === 3 ? el.childNodes[0].textContent || void 0 : void 0;
53
+ return { tag: el.tagName.toLowerCase(), attrs, children, text };
54
+ }
55
+ const svgEl = doc.querySelector("svg");
56
+ if (!svgEl) {
57
+ return null;
58
+ }
59
+ return elementToNode(svgEl);
66
60
  }
67
61
  function optimizeSvgNode(node) {
68
- // Remove metadata tags
69
- const filteredChildren = node.children
70
- .filter((c) => !METADATA_TAGS.has(c.tag))
71
- .map(optimizeSvgNode);
72
- // Remove removable attrs
73
- const cleanAttrs = {};
74
- for (const [key, val] of Object.entries(node.attrs)) {
75
- if (!REMOVABLE_ATTRS.has(key) && !key.startsWith('inkscape:') && !key.startsWith('sodipodi:')) {
76
- cleanAttrs[key] = val;
77
- }
62
+ const filteredChildren = node.children.filter((c) => !METADATA_TAGS.has(c.tag)).map(optimizeSvgNode);
63
+ const cleanAttrs = {};
64
+ for (const [key, val] of Object.entries(node.attrs)) {
65
+ if (!REMOVABLE_ATTRS.has(key) && !key.startsWith("inkscape:") && !key.startsWith("sodipodi:")) {
66
+ cleanAttrs[key] = val;
78
67
  }
79
- return { tag: node.tag, attrs: cleanAttrs, children: filteredChildren, text: node.text };
68
+ }
69
+ return { tag: node.tag, attrs: cleanAttrs, children: filteredChildren, text: node.text };
80
70
  }
81
71
  function extractColorsFromNode(node, colors) {
82
- for (const val of Object.values(node.attrs)) {
83
- if (/^#[0-9a-fA-F]{3,8}$/.test(val)) {
84
- colors.add(val.toLowerCase());
85
- }
86
- if (/^rgb\(/.test(val)) {
87
- colors.add(val);
88
- }
72
+ for (const val of Object.values(node.attrs)) {
73
+ if (/^#[0-9a-fA-F]{3,8}$/.test(val)) {
74
+ colors.add(val.toLowerCase());
89
75
  }
90
- for (const style of (node.attrs.style || '').split(';')) {
91
- const match = style.match(/(fill|stroke|color)\s*:\s*(#[0-9a-fA-F]{3,8}|rgb\([^)]+\))/i);
92
- if (match) {
93
- colors.add(match[2].toLowerCase());
94
- }
76
+ if (/^rgb\(/.test(val)) {
77
+ colors.add(val);
95
78
  }
96
- for (const child of node.children) {
97
- extractColorsFromNode(child, colors);
79
+ }
80
+ for (const style of (node.attrs.style || "").split(";")) {
81
+ const match = style.match(/(fill|stroke|color)\s*:\s*(#[0-9a-fA-F]{3,8}|rgb\([^)]+\))/i);
82
+ if (match) {
83
+ colors.add(match[2].toLowerCase());
98
84
  }
85
+ }
86
+ for (const child of node.children) {
87
+ extractColorsFromNode(child, colors);
88
+ }
99
89
  }
100
90
  function replaceColorsInNode(node, replacement) {
101
- const newAttrs = {};
102
- for (const [key, val] of Object.entries(node.attrs)) {
103
- if (/^#[0-9a-fA-F]{3,8}$/.test(val) && (key === 'fill' || key === 'stroke')) {
104
- newAttrs[key] = replacement;
105
- }
106
- else {
107
- newAttrs[key] = val;
108
- }
91
+ const newAttrs = {};
92
+ for (const [key, val] of Object.entries(node.attrs)) {
93
+ if (/^#[0-9a-fA-F]{3,8}$/.test(val) && (key === "fill" || key === "stroke")) {
94
+ newAttrs[key] = replacement;
95
+ } else {
96
+ newAttrs[key] = val;
109
97
  }
110
- return {
111
- tag: node.tag,
112
- attrs: newAttrs,
113
- children: node.children.map((c) => replaceColorsInNode(c, replacement)),
114
- text: node.text,
115
- };
98
+ }
99
+ return {
100
+ tag: node.tag,
101
+ attrs: newAttrs,
102
+ children: node.children.map((c) => replaceColorsInNode(c, replacement)),
103
+ text: node.text
104
+ };
116
105
  }
117
- /* ── SVG attribute → JSX attribute mapping ── */
118
106
  const SVG_TO_JSX = {
119
- class: 'className',
120
- 'clip-path': 'clipPath',
121
- 'clip-rule': 'clipRule',
122
- 'fill-opacity': 'fillOpacity',
123
- 'fill-rule': 'fillRule',
124
- 'font-family': 'fontFamily',
125
- 'font-size': 'fontSize',
126
- 'font-weight': 'fontWeight',
127
- 'letter-spacing': 'letterSpacing',
128
- 'marker-end': 'markerEnd',
129
- 'marker-mid': 'markerMid',
130
- 'marker-start': 'markerStart',
131
- 'stop-color': 'stopColor',
132
- 'stop-opacity': 'stopOpacity',
133
- 'stroke-dasharray': 'strokeDasharray',
134
- 'stroke-dashoffset': 'strokeDashoffset',
135
- 'stroke-linecap': 'strokeLinecap',
136
- 'stroke-linejoin': 'strokeLinejoin',
137
- 'stroke-miterlimit': 'strokeMiterlimit',
138
- 'stroke-opacity': 'strokeOpacity',
139
- 'stroke-width': 'strokeWidth',
140
- 'text-anchor': 'textAnchor',
141
- 'text-decoration': 'textDecoration',
142
- 'transform-origin': 'transformOrigin',
143
- 'xlink:href': 'xlinkHref',
144
- 'xml:lang': 'xmlLang',
145
- 'xml:space': 'xmlSpace',
146
- 'xmlns:xlink': '',
147
- xmlns: '',
107
+ class: "className",
108
+ "clip-path": "clipPath",
109
+ "clip-rule": "clipRule",
110
+ "fill-opacity": "fillOpacity",
111
+ "fill-rule": "fillRule",
112
+ "font-family": "fontFamily",
113
+ "font-size": "fontSize",
114
+ "font-weight": "fontWeight",
115
+ "letter-spacing": "letterSpacing",
116
+ "marker-end": "markerEnd",
117
+ "marker-mid": "markerMid",
118
+ "marker-start": "markerStart",
119
+ "stop-color": "stopColor",
120
+ "stop-opacity": "stopOpacity",
121
+ "stroke-dasharray": "strokeDasharray",
122
+ "stroke-dashoffset": "strokeDashoffset",
123
+ "stroke-linecap": "strokeLinecap",
124
+ "stroke-linejoin": "strokeLinejoin",
125
+ "stroke-miterlimit": "strokeMiterlimit",
126
+ "stroke-opacity": "strokeOpacity",
127
+ "stroke-width": "strokeWidth",
128
+ "text-anchor": "textAnchor",
129
+ "text-decoration": "textDecoration",
130
+ "transform-origin": "transformOrigin",
131
+ "xlink:href": "xlinkHref",
132
+ "xml:lang": "xmlLang",
133
+ "xml:space": "xmlSpace",
134
+ "xmlns:xlink": "",
135
+ xmlns: ""
148
136
  };
149
137
  function attrToJsx(name) {
150
- if (name in SVG_TO_JSX) {
151
- return SVG_TO_JSX[name];
152
- }
153
- // camelCase any remaining kebab-case
154
- return name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
138
+ if (name in SVG_TO_JSX) {
139
+ return SVG_TO_JSX[name];
140
+ }
141
+ return name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
155
142
  }
156
- /* ── Code Generators ── */
157
143
  function nodeToJsx(node, indent = 2) {
158
- const pad = ' '.repeat(indent);
159
- const attrs = Object.entries(node.attrs)
160
- .map(([k, v]) => {
161
- const jsxKey = attrToJsx(k);
162
- if (!jsxKey) {
163
- return '';
164
- }
165
- return `${jsxKey}="${v}"`;
166
- })
167
- .filter(Boolean)
168
- .join(' ');
169
- if (node.children.length === 0 && !node.text) {
170
- return `${pad}<${node.tag}${attrs ? ' ' + attrs : ''} />`;
144
+ const pad = " ".repeat(indent);
145
+ const attrs = Object.entries(node.attrs).map(([k, v]) => {
146
+ const jsxKey = attrToJsx(k);
147
+ if (!jsxKey) {
148
+ return "";
171
149
  }
172
- const inner = node.text
173
- ? node.text
174
- : '\n' + node.children.map((c) => nodeToJsx(c, indent + 2)).join('\n') + '\n' + pad;
175
- return `${pad}<${node.tag}${attrs ? ' ' + attrs : ''}>${inner}</${node.tag}>`;
150
+ return `${jsxKey}="${v}"`;
151
+ }).filter(Boolean).join(" ");
152
+ if (node.children.length === 0 && !node.text) {
153
+ return `${pad}<${node.tag}${attrs ? " " + attrs : ""} />`;
154
+ }
155
+ const inner = node.text ? node.text : "\n" + node.children.map((c) => nodeToJsx(c, indent + 2)).join("\n") + "\n" + pad;
156
+ return `${pad}<${node.tag}${attrs ? " " + attrs : ""}>${inner}</${node.tag}>`;
176
157
  }
177
158
  function nodeToHtml(node, indent = 2) {
178
- const pad = ' '.repeat(indent);
179
- const attrs = Object.entries(node.attrs)
180
- .map(([k, v]) => `${k}="${v}"`)
181
- .filter(Boolean)
182
- .join(' ');
183
- if (node.children.length === 0 && !node.text) {
184
- return `${pad}<${node.tag}${attrs ? ' ' + attrs : ''} />`;
185
- }
186
- const inner = node.text
187
- ? node.text
188
- : '\n' + node.children.map((c) => nodeToHtml(c, indent + 2)).join('\n') + '\n' + pad;
189
- return `${pad}<${node.tag}${attrs ? ' ' + attrs : ''}>${inner}</${node.tag}>`;
159
+ const pad = " ".repeat(indent);
160
+ const attrs = Object.entries(node.attrs).map(([k, v]) => `${k}="${v}"`).filter(Boolean).join(" ");
161
+ if (node.children.length === 0 && !node.text) {
162
+ return `${pad}<${node.tag}${attrs ? " " + attrs : ""} />`;
163
+ }
164
+ const inner = node.text ? node.text : "\n" + node.children.map((c) => nodeToHtml(c, indent + 2)).join("\n") + "\n" + pad;
165
+ return `${pad}<${node.tag}${attrs ? " " + attrs : ""}>${inner}</${node.tag}>`;
190
166
  }
191
167
  function generateReact(node, config) {
192
- const { componentName, typescript, sizeProps, memo, defaultExport, ariaLabel } = config;
193
- // Build props interface
194
- const propsLines = [];
195
- if (sizeProps) {
196
- propsLines.push(' width?: number | string;');
197
- propsLines.push(' height?: number | string;');
198
- }
199
- if (ariaLabel) {
200
- propsLines.push(" 'aria-label'?: string;");
201
- }
202
- propsLines.push(' className?: string;');
203
- propsLines.push(' style?: React.CSSProperties;');
204
- // Modify SVG node for props
205
- const svgNode = { ...node, attrs: { ...node.attrs } };
206
- if (sizeProps) {
207
- svgNode.attrs.width = '{width}';
208
- svgNode.attrs.height = '{height}';
209
- }
210
- const jsxBody = nodeToJsx({ ...svgNode, tag: 'svg' }, 4);
211
- const lines = [];
212
- lines.push("import React from 'react';");
213
- lines.push('');
214
- if (typescript) {
215
- lines.push(`interface ${componentName}Props {`);
216
- lines.push(...propsLines);
217
- lines.push('}');
218
- lines.push('');
219
- }
220
- const propsType = typescript ? `${componentName}Props` : 'any';
221
- const propsDestructure = [
222
- sizeProps ? `width = ${JSON.stringify(node.attrs.width || '24')}` : '',
223
- sizeProps ? `height = ${JSON.stringify(node.attrs.height || '24')}` : '',
224
- ariaLabel ? "'aria-label': ariaLabel" : '',
225
- 'className',
226
- 'style',
227
- ]
228
- .filter(Boolean)
229
- .join(', ');
230
- if (memo) {
231
- lines.push(`const ${componentName} = React.memo<${propsType}>(({ ${propsDestructure} }) => (`);
232
- }
233
- else {
234
- lines.push(`const ${componentName}: React.FC<${propsType}> = ({ ${propsDestructure} }) => (`);
235
- }
236
- lines.push(jsxBody);
237
- if (memo) {
238
- lines.push('));');
239
- }
240
- else {
241
- lines.push(');');
242
- }
243
- lines.push('');
244
- lines.push(`${componentName}.displayName = '${componentName}';`);
245
- lines.push('');
246
- if (defaultExport) {
247
- lines.push(`export default ${componentName};`);
248
- }
249
- else {
250
- lines.push(`export { ${componentName} };`);
251
- }
252
- return lines.join('\n');
168
+ const { componentName, typescript, sizeProps, memo, defaultExport, ariaLabel } = config;
169
+ const propsLines = [];
170
+ if (sizeProps) {
171
+ propsLines.push(" width?: number | string;");
172
+ propsLines.push(" height?: number | string;");
173
+ }
174
+ if (ariaLabel) {
175
+ propsLines.push(" 'aria-label'?: string;");
176
+ }
177
+ propsLines.push(" className?: string;");
178
+ propsLines.push(" style?: React.CSSProperties;");
179
+ const svgNode = { ...node, attrs: { ...node.attrs } };
180
+ if (sizeProps) {
181
+ svgNode.attrs.width = "{width}";
182
+ svgNode.attrs.height = "{height}";
183
+ }
184
+ const jsxBody = nodeToJsx({ ...svgNode, tag: "svg" }, 4);
185
+ const lines = [];
186
+ lines.push("import React from 'react';");
187
+ lines.push("");
188
+ if (typescript) {
189
+ lines.push(`interface ${componentName}Props {`);
190
+ lines.push(...propsLines);
191
+ lines.push("}");
192
+ lines.push("");
193
+ }
194
+ const propsType = typescript ? `${componentName}Props` : "any";
195
+ const propsDestructure = [
196
+ sizeProps ? `width = ${JSON.stringify(node.attrs.width || "24")}` : "",
197
+ sizeProps ? `height = ${JSON.stringify(node.attrs.height || "24")}` : "",
198
+ ariaLabel ? "'aria-label': ariaLabel" : "",
199
+ "className",
200
+ "style"
201
+ ].filter(Boolean).join(", ");
202
+ if (memo) {
203
+ lines.push(`const ${componentName} = React.memo<${propsType}>(({ ${propsDestructure} }) => (`);
204
+ } else {
205
+ lines.push(`const ${componentName}: React.FC<${propsType}> = ({ ${propsDestructure} }) => (`);
206
+ }
207
+ lines.push(jsxBody);
208
+ if (memo) {
209
+ lines.push("));");
210
+ } else {
211
+ lines.push(");");
212
+ }
213
+ lines.push("");
214
+ lines.push(`${componentName}.displayName = '${componentName}';`);
215
+ lines.push("");
216
+ if (defaultExport) {
217
+ lines.push(`export default ${componentName};`);
218
+ } else {
219
+ lines.push(`export { ${componentName} };`);
220
+ }
221
+ return lines.join("\n");
253
222
  }
254
223
  function generateVue(node, config) {
255
- const { componentName, sizeProps, typescript } = config;
256
- const svgHtml = nodeToHtml(node, 2);
257
- const lines = [];
258
- lines.push('<template>');
259
- lines.push(svgHtml);
260
- lines.push('</template>');
261
- lines.push('');
262
- lines.push(`<script${typescript ? ' lang="ts"' : ''} setup>`);
263
- if (sizeProps) {
264
- if (typescript) {
265
- lines.push('interface Props {');
266
- lines.push(' width?: string | number;');
267
- lines.push(' height?: string | number;');
268
- lines.push('}');
269
- lines.push('');
270
- lines.push('const props = withDefaults(defineProps<Props>(), {');
271
- lines.push(` width: '${node.attrs.width || '24'}',`);
272
- lines.push(` height: '${node.attrs.height || '24'}',`);
273
- lines.push('});');
274
- }
275
- else {
276
- lines.push('const props = defineProps({');
277
- lines.push(" width: { type: [String, Number], default: '24' },");
278
- lines.push(" height: { type: [String, Number], default: '24' },");
279
- lines.push('});');
280
- }
224
+ const { componentName, sizeProps, typescript } = config;
225
+ const svgHtml = nodeToHtml(node, 2);
226
+ const lines = [];
227
+ lines.push("<template>");
228
+ lines.push(svgHtml);
229
+ lines.push("</template>");
230
+ lines.push("");
231
+ lines.push(`<script${typescript ? ' lang="ts"' : ""} setup>`);
232
+ if (sizeProps) {
233
+ if (typescript) {
234
+ lines.push("interface Props {");
235
+ lines.push(" width?: string | number;");
236
+ lines.push(" height?: string | number;");
237
+ lines.push("}");
238
+ lines.push("");
239
+ lines.push("const props = withDefaults(defineProps<Props>(), {");
240
+ lines.push(` width: '${node.attrs.width || "24"}',`);
241
+ lines.push(` height: '${node.attrs.height || "24"}',`);
242
+ lines.push("});");
243
+ } else {
244
+ lines.push("const props = defineProps({");
245
+ lines.push(" width: { type: [String, Number], default: '24' },");
246
+ lines.push(" height: { type: [String, Number], default: '24' },");
247
+ lines.push("});");
281
248
  }
282
- lines.push('</script>');
283
- lines.push('');
284
- lines.push(`<!-- ${componentName}.vue -->`);
285
- return lines.join('\n');
249
+ }
250
+ lines.push("<\/script>");
251
+ lines.push("");
252
+ lines.push(`<!-- ${componentName}.vue -->`);
253
+ return lines.join("\n");
286
254
  }
287
255
  function generateWebComponent(node, config) {
288
- const { componentName, sizeProps } = config;
289
- const tagName = componentName
290
- .replace(/([A-Z])/g, '-$1')
291
- .toLowerCase()
292
- .replace(/^-/, '');
293
- const svgHtml = nodeToHtml(node, 6);
294
- const lines = [];
295
- lines.push(`class ${componentName} extends HTMLElement {`);
296
- lines.push(' constructor() {');
297
- lines.push(' super();');
298
- lines.push(" this.attachShadow({ mode: 'open' });");
299
- lines.push(' }');
300
- lines.push('');
301
- lines.push(' connectedCallback() {');
302
- lines.push(' this.render();');
303
- lines.push(' }');
304
- lines.push('');
305
- if (sizeProps) {
306
- lines.push(" static get observedAttributes() { return ['width', 'height']; }");
307
- lines.push('');
308
- lines.push(' attributeChangedCallback() { this.render(); }');
309
- lines.push('');
310
- }
311
- lines.push(' render() {');
312
- if (sizeProps) {
313
- lines.push(` const width = this.getAttribute('width') || '${node.attrs.width || '24'}';`);
314
- lines.push(` const height = this.getAttribute('height') || '${node.attrs.height || '24'}';`);
315
- }
316
- lines.push(' if (this.shadowRoot) {');
317
- lines.push(' this.shadowRoot.innerHTML = `');
318
- lines.push(svgHtml);
319
- lines.push(' `;');
320
- lines.push(' }');
321
- lines.push(' }');
322
- lines.push('}');
323
- lines.push('');
324
- lines.push(`customElements.define('${tagName}', ${componentName});`);
325
- lines.push('');
326
- lines.push(`export { ${componentName} };`);
327
- return lines.join('\n');
256
+ const { componentName, sizeProps } = config;
257
+ const tagName = componentName.replace(/([A-Z])/g, "-$1").toLowerCase().replace(/^-/, "");
258
+ const svgHtml = nodeToHtml(node, 6);
259
+ const lines = [];
260
+ lines.push(`class ${componentName} extends HTMLElement {`);
261
+ lines.push(" constructor() {");
262
+ lines.push(" super();");
263
+ lines.push(" this.attachShadow({ mode: 'open' });");
264
+ lines.push(" }");
265
+ lines.push("");
266
+ lines.push(" connectedCallback() {");
267
+ lines.push(" this.render();");
268
+ lines.push(" }");
269
+ lines.push("");
270
+ if (sizeProps) {
271
+ lines.push(" static get observedAttributes() { return ['width', 'height']; }");
272
+ lines.push("");
273
+ lines.push(" attributeChangedCallback() { this.render(); }");
274
+ lines.push("");
275
+ }
276
+ lines.push(" render() {");
277
+ if (sizeProps) {
278
+ lines.push(` const width = this.getAttribute('width') || '${node.attrs.width || "24"}';`);
279
+ lines.push(` const height = this.getAttribute('height') || '${node.attrs.height || "24"}';`);
280
+ }
281
+ lines.push(" if (this.shadowRoot) {");
282
+ lines.push(" this.shadowRoot.innerHTML = `");
283
+ lines.push(svgHtml);
284
+ lines.push(" `;");
285
+ lines.push(" }");
286
+ lines.push(" }");
287
+ lines.push("}");
288
+ lines.push("");
289
+ lines.push(`customElements.define('${tagName}', ${componentName});`);
290
+ lines.push("");
291
+ lines.push(`export { ${componentName} };`);
292
+ return lines.join("\n");
328
293
  }
329
294
  function generateTypeScript(node, config) {
330
- const { componentName, sizeProps } = config;
331
- const svgHtml = nodeToHtml(node, 2);
332
- const lines = [];
333
- lines.push(`export interface ${componentName}Options {`);
334
- if (sizeProps) {
335
- lines.push(' width?: string | number;');
336
- lines.push(' height?: string | number;');
337
- }
338
- lines.push(' className?: string;');
339
- lines.push('}');
340
- lines.push('');
341
- lines.push(`export function render${componentName}(container: HTMLElement, options: ${componentName}Options = {}): void {`);
342
- if (sizeProps) {
343
- lines.push(` const width = options.width ?? '${node.attrs.width || '24'}';`);
344
- lines.push(` const height = options.height ?? '${node.attrs.height || '24'}';`);
345
- }
346
- lines.push(' container.innerHTML = `');
347
- lines.push(svgHtml);
348
- lines.push(' `;');
349
- lines.push('}');
350
- lines.push('');
351
- lines.push(`export const ${componentName}SVG = \``);
352
- lines.push(svgHtml);
353
- lines.push('`;');
354
- return lines.join('\n');
295
+ const { componentName, sizeProps } = config;
296
+ const svgHtml = nodeToHtml(node, 2);
297
+ const lines = [];
298
+ lines.push(`export interface ${componentName}Options {`);
299
+ if (sizeProps) {
300
+ lines.push(" width?: string | number;");
301
+ lines.push(" height?: string | number;");
302
+ }
303
+ lines.push(" className?: string;");
304
+ lines.push("}");
305
+ lines.push("");
306
+ lines.push(
307
+ `export function render${componentName}(container: HTMLElement, options: ${componentName}Options = {}): void {`
308
+ );
309
+ if (sizeProps) {
310
+ lines.push(` const width = options.width ?? '${node.attrs.width || "24"}';`);
311
+ lines.push(` const height = options.height ?? '${node.attrs.height || "24"}';`);
312
+ }
313
+ lines.push(" container.innerHTML = `");
314
+ lines.push(svgHtml);
315
+ lines.push(" `;");
316
+ lines.push("}");
317
+ lines.push("");
318
+ lines.push(`export const ${componentName}SVG = \``);
319
+ lines.push(svgHtml);
320
+ lines.push("`;");
321
+ return lines.join("\n");
355
322
  }
356
- /* ── Main conversion function ── */
357
323
  function convertSvgToCode(svgString, config) {
358
- let node = parseSvgString(svgString);
359
- if (!node) {
360
- return null;
324
+ let node = parseSvgString(svgString);
325
+ if (!node) {
326
+ return null;
327
+ }
328
+ if (config.optimize) {
329
+ node = optimizeSvgNode(node);
330
+ }
331
+ const colors = /* @__PURE__ */ new Set();
332
+ extractColorsFromNode(node, colors);
333
+ if (config.useCurrentColor) {
334
+ node = replaceColorsInNode(node, "currentColor");
335
+ }
336
+ let code;
337
+ let ext;
338
+ switch (config.framework) {
339
+ case "react":
340
+ code = generateReact(node, config);
341
+ ext = config.typescript ? "tsx" : "jsx";
342
+ break;
343
+ case "vue":
344
+ code = generateVue(node, config);
345
+ ext = "vue";
346
+ break;
347
+ case "web-component":
348
+ code = generateWebComponent(node, config);
349
+ ext = config.typescript ? "ts" : "js";
350
+ break;
351
+ case "typescript":
352
+ code = generateTypeScript(node, config);
353
+ ext = "ts";
354
+ break;
355
+ default:
356
+ return null;
357
+ }
358
+ return {
359
+ code,
360
+ framework: config.framework,
361
+ componentName: config.componentName,
362
+ fileName: `${config.componentName}.${ext}`,
363
+ extractedColors: [...colors]
364
+ };
365
+ }
366
+ function useSvgToCode() {
367
+ const [svgInput, setSvgInput] = useState("");
368
+ const [config, setConfig] = useState({ ...DEFAULT_CONFIG });
369
+ const [result, setResult] = useState(null);
370
+ const convert = useCallback(() => {
371
+ if (!svgInput.trim()) {
372
+ setResult(null);
373
+ return;
361
374
  }
362
- if (config.optimize) {
363
- node = optimizeSvgNode(node);
375
+ const r = convertSvgToCode(svgInput, config);
376
+ setResult(r);
377
+ }, [svgInput, config]);
378
+ const updateConfig = useCallback((partial) => {
379
+ setConfig((prev) => ({ ...prev, ...partial }));
380
+ }, []);
381
+ return { svgInput, setSvgInput, config, updateConfig, convert, result };
382
+ }
383
+ const NiceSvgToCode = ({
384
+ initialSvg = "",
385
+ onConvert,
386
+ className = ""
387
+ }) => {
388
+ const { t } = useNiceTranslation();
389
+ const { svgInput, setSvgInput, config, updateConfig, convert, result } = useSvgToCode();
390
+ React.useEffect(() => {
391
+ if (initialSvg) {
392
+ setSvgInput(initialSvg);
364
393
  }
365
- // Extract colors
366
- const colors = new Set();
367
- extractColorsFromNode(node, colors);
368
- if (config.useCurrentColor) {
369
- node = replaceColorsInNode(node, 'currentColor');
394
+ }, [initialSvg, setSvgInput]);
395
+ const handleConvert = () => {
396
+ convert();
397
+ if (result && onConvert) {
398
+ onConvert(result);
370
399
  }
371
- let code;
372
- let ext;
373
- switch (config.framework) {
374
- case 'react':
375
- code = generateReact(node, config);
376
- ext = config.typescript ? 'tsx' : 'jsx';
377
- break;
378
- case 'vue':
379
- code = generateVue(node, config);
380
- ext = 'vue';
381
- break;
382
- case 'web-component':
383
- code = generateWebComponent(node, config);
384
- ext = config.typescript ? 'ts' : 'js';
385
- break;
386
- case 'typescript':
387
- code = generateTypeScript(node, config);
388
- ext = 'ts';
389
- break;
390
- default:
391
- return null;
400
+ };
401
+ const handleCopy = () => {
402
+ if (result) {
403
+ navigator.clipboard.writeText(result.code);
392
404
  }
393
- return {
394
- code,
395
- framework: config.framework,
396
- componentName: config.componentName,
397
- fileName: `${config.componentName}.${ext}`,
398
- extractedColors: [...colors],
399
- };
400
- }
401
- /* ── Hook ── */
402
- function useSvgToCode() {
403
- const [svgInput, setSvgInput] = useState('');
404
- const [config, setConfig] = useState({ ...DEFAULT_CONFIG });
405
- const [result, setResult] = useState(null);
406
- const convert = useCallback(() => {
407
- if (!svgInput.trim()) {
408
- setResult(null);
409
- return;
410
- }
411
- const r = convertSvgToCode(svgInput, config);
412
- setResult(r);
413
- }, [svgInput, config]);
414
- const updateConfig = useCallback((partial) => {
415
- setConfig((prev) => ({ ...prev, ...partial }));
416
- }, []);
417
- return { svgInput, setSvgInput, config, updateConfig, convert, result };
418
- }
419
- /* ── Component ── */
420
- const NiceSvgToCode = ({ initialSvg = '', onConvert, className = '', }) => {
421
- const { t } = useNiceTranslation();
422
- const { svgInput, setSvgInput, config, updateConfig, convert, result } = useSvgToCode();
423
- // Initialize with provided SVG
424
- React.useEffect(() => {
425
- if (initialSvg) {
426
- setSvgInput(initialSvg);
427
- }
428
- }, [initialSvg, setSvgInput]);
429
- const handleConvert = () => {
430
- convert();
431
- if (result && onConvert) {
432
- onConvert(result);
433
- }
434
- };
435
- const handleCopy = () => {
436
- if (result) {
437
- navigator.clipboard.writeText(result.code);
438
- }
439
- };
440
- return (jsxs("div", { className: `nice-svg-to-code ${className}`, style: { display: 'grid', gap: 8, fontSize: 13 }, children: [jsxs("strong", { children: [jsx(NiceIcon, { name: "refresh", size: 14 }), " ", t('svgToCode.svgCode', 'SVG → Code')] }), jsx("textarea", { value: svgInput, onChange: (e) => setSvgInput(e.target.value), placeholder: t('svgToCode.pasteSvgMarkupHere', 'Paste SVG markup here…'), rows: 6, style: {
441
- width: '100%',
442
- fontFamily: 'monospace',
443
- fontSize: 11,
444
- padding: 6,
445
- borderRadius: 4,
446
- border: '1px solid var(--nice-border, #e2e8f0)',
447
- } }), jsxs("div", { style: { display: 'grid', gap: 4 }, children: [jsxs("label", { children: [t('svgToCode.framework', 'Framework:'), jsxs("select", { value: config.framework, onChange: (e) => updateConfig({ framework: e.target.value }), style: { width: '100%' }, children: [jsx("option", { value: "react", children: "React (JSX/TSX)" }), jsx("option", { value: "vue", children: "Vue (SFC)" }), jsx("option", { value: "web-component", children: t('svgToCode.webComponent', 'Web Component') }), jsx("option", { value: "typescript", children: t('svgToCode.typescriptUtility', 'TypeScript (utility)') })] })] }), jsxs("label", { children: [t('svgToCode.componentName', 'Component name:'), jsx("input", { type: "text", value: config.componentName, onChange: (e) => updateConfig({ componentName: e.target.value.replace(/[^a-zA-Z0-9]/g, '') }), style: { width: '100%', padding: '3px 6px' } })] }), jsxs("div", { style: { display: 'flex', gap: 8, flexWrap: 'wrap', fontSize: 11 }, children: [jsxs("label", { children: [jsx("input", { type: "checkbox", checked: config.typescript, onChange: (e) => updateConfig({ typescript: e.target.checked }) }), ' ', t('svgToCode.typescript', 'TypeScript')] }), jsxs("label", { children: [jsx("input", { type: "checkbox", checked: config.optimize, onChange: (e) => updateConfig({ optimize: e.target.checked }) }), ' ', t('svgToCode.optimize', 'Optimize')] }), jsxs("label", { children: [jsx("input", { type: "checkbox", checked: config.sizeProps, onChange: (e) => updateConfig({ sizeProps: e.target.checked }) }), ' ', t('svgToCode.sizeProps', 'Size props')] }), jsxs("label", { children: [jsx("input", { type: "checkbox", checked: config.useCurrentColor, onChange: (e) => updateConfig({ useCurrentColor: e.target.checked }) }), ' ', "currentColor"] }), jsxs("label", { children: [jsx("input", { type: "checkbox", checked: config.memo, onChange: (e) => updateConfig({ memo: e.target.checked }) }), ' ', "memo"] })] })] }), jsxs("button", { type: "button", onClick: handleConvert, disabled: !svgInput.trim(), style: {
448
- background: 'var(--nice-color-accent, #6366f1)',
449
- color: 'var(--nice-text-on-primary, #fff)',
450
- border: 'none',
451
- borderRadius: 4,
452
- padding: '8px 12px',
453
- cursor: 'pointer',
454
- }, children: [jsx(NiceIcon, { name: "refresh", size: 14 }), ' ', t('svgToCode.convertTo', 'Convert to {framework}').replace('{framework}', config.framework.charAt(0).toUpperCase() + config.framework.slice(1))] }), result && (jsxs("div", { children: [jsxs("div", { style: {
455
- display: 'flex',
456
- justifyContent: 'space-between',
457
- alignItems: 'center',
458
- marginBottom: 4,
459
- }, children: [jsx("span", { style: { fontSize: 11, color: 'var(--nice-text-muted, #64748b)' }, children: result.fileName }), jsxs("button", { type: "button", onClick: handleCopy, style: {
460
- fontSize: 10,
461
- padding: '2px 8px',
462
- cursor: 'pointer',
463
- borderRadius: 3,
464
- border: '1px solid var(--nice-border, #e2e8f0)',
465
- background: 'transparent',
466
- }, children: [jsx(NiceIcon, { name: "clipboard", size: 12 }), " ", t('svgToCode.copy', 'Copy')] })] }), jsx("pre", { style: {
467
- background: 'var(--nice-code-bg, #1e293b)',
468
- color: 'var(--nice-code-color, #e2e8f0)',
469
- padding: 8,
470
- borderRadius: 4,
471
- fontSize: 11,
472
- overflow: 'auto',
473
- maxHeight: 300,
474
- whiteSpace: 'pre-wrap',
475
- }, children: result.code }), result.extractedColors.length > 0 && (jsxs("div", { style: { fontSize: 11, marginTop: 4 }, children: [t('svgToCode.colors', 'Colors:'), ' ', result.extractedColors.map((c) => (jsx("span", { style: {
476
- display: 'inline-block',
477
- width: 12,
478
- height: 12,
479
- background: c,
480
- border: '1px solid var(--nice-border, #ccc)',
481
- borderRadius: 2,
482
- marginRight: 4,
483
- verticalAlign: 'middle',
484
- } }, c)))] }))] }))] }));
405
+ };
406
+ return /* @__PURE__ */ jsxs(
407
+ "div",
408
+ {
409
+ className: `nice-svg-to-code ${className}`,
410
+ style: { display: "grid", gap: 8, fontSize: 13 },
411
+ children: [
412
+ /* @__PURE__ */ jsxs("strong", { children: [
413
+ /* @__PURE__ */ jsx(NiceIcon, { name: "refresh", size: 14 }),
414
+ " ",
415
+ t("svgToCode.svgCode", "SVG → Code")
416
+ ] }),
417
+ /* @__PURE__ */ jsx(
418
+ "textarea",
419
+ {
420
+ value: svgInput,
421
+ onChange: (e) => setSvgInput(e.target.value),
422
+ placeholder: t("svgToCode.pasteSvgMarkupHere", "Paste SVG markup here…"),
423
+ rows: 6,
424
+ style: {
425
+ width: "100%",
426
+ fontFamily: "monospace",
427
+ fontSize: 11,
428
+ padding: 6,
429
+ borderRadius: 4,
430
+ border: "1px solid var(--nice-border, #e2e8f0)"
431
+ }
432
+ }
433
+ ),
434
+ /* @__PURE__ */ jsxs("div", { style: { display: "grid", gap: 4 }, children: [
435
+ /* @__PURE__ */ jsxs("label", { children: [
436
+ t("svgToCode.framework", "Framework:"),
437
+ /* @__PURE__ */ jsxs(
438
+ "select",
439
+ {
440
+ value: config.framework,
441
+ onChange: (e) => updateConfig({ framework: e.target.value }),
442
+ style: { width: "100%" },
443
+ children: [
444
+ /* @__PURE__ */ jsx("option", { value: "react", children: "React (JSX/TSX)" }),
445
+ /* @__PURE__ */ jsx("option", { value: "vue", children: "Vue (SFC)" }),
446
+ /* @__PURE__ */ jsx("option", { value: "web-component", children: t("svgToCode.webComponent", "Web Component") }),
447
+ /* @__PURE__ */ jsx("option", { value: "typescript", children: t("svgToCode.typescriptUtility", "TypeScript (utility)") })
448
+ ]
449
+ }
450
+ )
451
+ ] }),
452
+ /* @__PURE__ */ jsxs("label", { children: [
453
+ t("svgToCode.componentName", "Component name:"),
454
+ /* @__PURE__ */ jsx(
455
+ "input",
456
+ {
457
+ type: "text",
458
+ value: config.componentName,
459
+ onChange: (e) => updateConfig({ componentName: e.target.value.replace(/[^a-zA-Z0-9]/g, "") }),
460
+ style: { width: "100%", padding: "3px 6px" }
461
+ }
462
+ )
463
+ ] }),
464
+ /* @__PURE__ */ jsxs("div", { style: { display: "flex", gap: 8, flexWrap: "wrap", fontSize: 11 }, children: [
465
+ /* @__PURE__ */ jsxs("label", { children: [
466
+ /* @__PURE__ */ jsx(
467
+ "input",
468
+ {
469
+ type: "checkbox",
470
+ checked: config.typescript,
471
+ onChange: (e) => updateConfig({ typescript: e.target.checked })
472
+ }
473
+ ),
474
+ " ",
475
+ t("svgToCode.typescript", "TypeScript")
476
+ ] }),
477
+ /* @__PURE__ */ jsxs("label", { children: [
478
+ /* @__PURE__ */ jsx(
479
+ "input",
480
+ {
481
+ type: "checkbox",
482
+ checked: config.optimize,
483
+ onChange: (e) => updateConfig({ optimize: e.target.checked })
484
+ }
485
+ ),
486
+ " ",
487
+ t("svgToCode.optimize", "Optimize")
488
+ ] }),
489
+ /* @__PURE__ */ jsxs("label", { children: [
490
+ /* @__PURE__ */ jsx(
491
+ "input",
492
+ {
493
+ type: "checkbox",
494
+ checked: config.sizeProps,
495
+ onChange: (e) => updateConfig({ sizeProps: e.target.checked })
496
+ }
497
+ ),
498
+ " ",
499
+ t("svgToCode.sizeProps", "Size props")
500
+ ] }),
501
+ /* @__PURE__ */ jsxs("label", { children: [
502
+ /* @__PURE__ */ jsx(
503
+ "input",
504
+ {
505
+ type: "checkbox",
506
+ checked: config.useCurrentColor,
507
+ onChange: (e) => updateConfig({ useCurrentColor: e.target.checked })
508
+ }
509
+ ),
510
+ " ",
511
+ "currentColor"
512
+ ] }),
513
+ /* @__PURE__ */ jsxs("label", { children: [
514
+ /* @__PURE__ */ jsx(
515
+ "input",
516
+ {
517
+ type: "checkbox",
518
+ checked: config.memo,
519
+ onChange: (e) => updateConfig({ memo: e.target.checked })
520
+ }
521
+ ),
522
+ " ",
523
+ "memo"
524
+ ] })
525
+ ] })
526
+ ] }),
527
+ /* @__PURE__ */ jsxs(
528
+ "button",
529
+ {
530
+ type: "button",
531
+ onClick: handleConvert,
532
+ disabled: !svgInput.trim(),
533
+ style: {
534
+ background: "var(--nice-color-accent, #6366f1)",
535
+ color: "var(--nice-text-on-primary, #fff)",
536
+ border: "none",
537
+ borderRadius: 4,
538
+ padding: "8px 12px",
539
+ cursor: "pointer"
540
+ },
541
+ children: [
542
+ /* @__PURE__ */ jsx(NiceIcon, { name: "refresh", size: 14 }),
543
+ " ",
544
+ t("svgToCode.convertTo", "Convert to {framework}").replace(
545
+ "{framework}",
546
+ config.framework.charAt(0).toUpperCase() + config.framework.slice(1)
547
+ )
548
+ ]
549
+ }
550
+ ),
551
+ result && /* @__PURE__ */ jsxs("div", { children: [
552
+ /* @__PURE__ */ jsxs(
553
+ "div",
554
+ {
555
+ style: {
556
+ display: "flex",
557
+ justifyContent: "space-between",
558
+ alignItems: "center",
559
+ marginBottom: 4
560
+ },
561
+ children: [
562
+ /* @__PURE__ */ jsx("span", { style: { fontSize: 11, color: "var(--nice-text-muted, #64748b)" }, children: result.fileName }),
563
+ /* @__PURE__ */ jsxs(
564
+ "button",
565
+ {
566
+ type: "button",
567
+ onClick: handleCopy,
568
+ style: {
569
+ fontSize: 10,
570
+ padding: "2px 8px",
571
+ cursor: "pointer",
572
+ borderRadius: 3,
573
+ border: "1px solid var(--nice-border, #e2e8f0)",
574
+ background: "transparent"
575
+ },
576
+ children: [
577
+ /* @__PURE__ */ jsx(NiceIcon, { name: "clipboard", size: 12 }),
578
+ " ",
579
+ t("svgToCode.copy", "Copy")
580
+ ]
581
+ }
582
+ )
583
+ ]
584
+ }
585
+ ),
586
+ /* @__PURE__ */ jsx(
587
+ "pre",
588
+ {
589
+ style: {
590
+ background: "var(--nice-code-bg, #1e293b)",
591
+ color: "var(--nice-code-color, #e2e8f0)",
592
+ padding: 8,
593
+ borderRadius: 4,
594
+ fontSize: 11,
595
+ overflow: "auto",
596
+ maxHeight: 300,
597
+ whiteSpace: "pre-wrap"
598
+ },
599
+ children: result.code
600
+ }
601
+ ),
602
+ result.extractedColors.length > 0 && /* @__PURE__ */ jsxs("div", { style: { fontSize: 11, marginTop: 4 }, children: [
603
+ t("svgToCode.colors", "Colors:"),
604
+ " ",
605
+ result.extractedColors.map((c) => /* @__PURE__ */ jsx(
606
+ "span",
607
+ {
608
+ style: {
609
+ display: "inline-block",
610
+ width: 12,
611
+ height: 12,
612
+ background: c,
613
+ border: "1px solid var(--nice-border, #ccc)",
614
+ borderRadius: 2,
615
+ marginRight: 4,
616
+ verticalAlign: "middle"
617
+ }
618
+ },
619
+ c
620
+ ))
621
+ ] })
622
+ ] })
623
+ ]
624
+ }
625
+ );
626
+ };
627
+ export {
628
+ NiceSvgToCode,
629
+ convertSvgToCode,
630
+ useSvgToCode
485
631
  };
486
-
487
- export { NiceSvgToCode, convertSvgToCode, useSvgToCode };