@nice2dev/ui-graphics 1.3.15 → 1.3.16

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