@nice2dev/ui-graphics 1.3.14 → 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.
- package/CHANGELOG.md +13 -0
- package/dist/cjs/animation/AnimatedPerson.js +470 -143
- package/dist/cjs/animation/AnimationEditor.js +289 -101
- package/dist/cjs/animation/Audience.js +83 -61
- package/dist/cjs/animation/BodyRenderer.js +69 -28
- package/dist/cjs/animation/animationHelper.js +281 -288
- package/dist/cjs/animation/characterTypes.js +200 -203
- package/dist/cjs/animation/choreoDSL.js +205 -219
- package/dist/cjs/animation/choreography.js +4 -32
- package/dist/cjs/animation/karaokeIntegration.js +68 -77
- package/dist/cjs/animation/lottieExport.js +108 -114
- package/dist/cjs/animation/motionPath.js +225 -248
- package/dist/cjs/animation/physics.js +227 -254
- package/dist/cjs/animation/rig/RigPlayer.js +53 -56
- package/dist/cjs/animation/rig/RiggedBody.js +71 -26
- package/dist/cjs/animation/rig/choreoRigBridge.js +72 -77
- package/dist/cjs/animation/rig/ik.js +13 -18
- package/dist/cjs/animation/rig/poseOps.js +34 -41
- package/dist/cjs/animation/rig/presets.js +64 -72
- package/dist/cjs/animation/rig/rigMath.js +25 -32
- package/dist/cjs/animation/rig/rigTypes.js +59 -63
- package/dist/cjs/animation/shapes/arms.js +31 -13
- package/dist/cjs/animation/shapes/eyes.js +129 -47
- package/dist/cjs/animation/shapes/hair.js +72 -45
- package/dist/cjs/animation/shapes/heads.js +131 -57
- package/dist/cjs/animation/shapes/headwear.js +47 -38
- package/dist/cjs/animation/shapes/legs.js +31 -13
- package/dist/cjs/animation/shapes/mouths.js +120 -44
- package/dist/cjs/animation/shapes/noses.js +80 -25
- package/dist/cjs/animation/shapes/outfits.js +101 -39
- package/dist/cjs/animation/shapes/torsos.js +15 -11
- package/dist/cjs/animation/spineExport.js +103 -121
- package/dist/cjs/core/LocalUI.js +108 -43
- package/dist/cjs/core/NiceBrushEngine.js +758 -552
- package/dist/cjs/core/collaboration.js +249 -251
- package/dist/cjs/core/colorBlindness.js +100 -115
- package/dist/cjs/core/dragDrop.js +155 -158
- package/dist/cjs/core/editorAsk.js +51 -41
- package/dist/cjs/core/fixes.js +140 -171
- package/dist/cjs/core/gridGuides.js +166 -201
- package/dist/cjs/core/historyVisual.js +156 -135
- package/dist/cjs/core/i18n.js +13 -14
- package/dist/cjs/core/integrations.js +238 -249
- package/dist/cjs/core/minimap.js +149 -151
- package/dist/cjs/core/plugins.js +98 -113
- package/dist/cjs/core/rtl.js +71 -83
- package/dist/cjs/core/shortcuts.js +196 -225
- package/dist/cjs/core/theme.js +142 -149
- package/dist/cjs/core/yjsCollaboration.js +232 -293
- package/dist/cjs/design/design-tools.js +12 -22
- package/dist/cjs/font/NiceFontEditor.js +877 -316
- package/dist/cjs/font/fontFormatUtils.js +388 -448
- package/dist/cjs/game/GameAsset2dEditor.js +1201 -392
- package/dist/cjs/game/GameAsset2dEditor.module.css.js +146 -5
- package/dist/cjs/game/gameAssetTypes.js +7 -16
- package/dist/cjs/game/gameAssetUtils.js +390 -413
- package/dist/cjs/game/useGameAssetEditor.js +820 -763
- package/dist/cjs/index.js +81 -84
- package/dist/cjs/nice2dev-ui-graphics.css +1 -1
- package/dist/cjs/node_modules/lib0/array.js +8 -70
- package/dist/cjs/node_modules/lib0/binary.js +3 -20
- package/dist/cjs/node_modules/lib0/broadcastchannel.js +24 -86
- package/dist/cjs/node_modules/lib0/buffer.js +15 -82
- package/dist/cjs/node_modules/lib0/conditions.js +3 -16
- package/dist/cjs/node_modules/lib0/decoding.js +108 -287
- package/dist/cjs/node_modules/lib0/dom.js +14 -44
- package/dist/cjs/node_modules/lib0/encoding.js +68 -418
- package/dist/cjs/node_modules/lib0/environment.js +26 -92
- package/dist/cjs/node_modules/lib0/error.js +5 -29
- package/dist/cjs/node_modules/lib0/function.js +27 -66
- package/dist/cjs/node_modules/lib0/iterator.js +8 -33
- package/dist/cjs/node_modules/lib0/logging.common.js +12 -22
- package/dist/cjs/node_modules/lib0/logging.js +32 -71
- package/dist/cjs/node_modules/lib0/map.js +16 -86
- package/dist/cjs/node_modules/lib0/math.js +3 -32
- package/dist/cjs/node_modules/lib0/number.js +4 -15
- package/dist/cjs/node_modules/lib0/object.js +14 -88
- package/dist/cjs/node_modules/lib0/observable.js +38 -78
- package/dist/cjs/node_modules/lib0/pair.js +3 -20
- package/dist/cjs/node_modules/lib0/prng.js +8 -77
- package/dist/cjs/node_modules/lib0/promise.js +6 -30
- package/dist/cjs/node_modules/lib0/random.js +8 -23
- package/dist/cjs/node_modules/lib0/schema.js +313 -687
- package/dist/cjs/node_modules/lib0/set.js +3 -10
- package/dist/cjs/node_modules/lib0/storage.js +20 -55
- package/dist/cjs/node_modules/lib0/string.js +17 -72
- package/dist/cjs/node_modules/lib0/symbol.js +2 -12
- package/dist/cjs/node_modules/lib0/time.js +2 -15
- package/dist/cjs/node_modules/lib0/trait/equality.js +3 -28
- package/dist/cjs/node_modules/lib0/url.js +4 -18
- package/dist/cjs/node_modules/lib0/webcrypto.js +2 -5
- package/dist/cjs/node_modules/y-protocols/auth.js +5 -19
- package/dist/cjs/node_modules/y-protocols/awareness.js +53 -116
- package/dist/cjs/node_modules/y-protocols/sync.js +16 -103
- package/dist/cjs/node_modules/y-websocket/src/y-websocket.js +77 -219
- package/dist/cjs/node_modules/yjs/dist/yjs.js +2128 -4868
- package/dist/cjs/photo/FilterThumb.js +37 -25
- package/dist/cjs/photo/NiceAITools.js +679 -467
- package/dist/cjs/photo/PhotoEditor.js +34 -20
- package/dist/cjs/photo/PhotoEditor.module.css.js +296 -5
- package/dist/cjs/photo/PhotoEditorCanvas.js +250 -91
- package/dist/cjs/photo/PhotoEditorLeftPanel.js +1086 -224
- package/dist/cjs/photo/PhotoEditorToolbar.js +135 -19
- package/dist/cjs/photo/photoEditorActions.js +89 -72
- package/dist/cjs/photo/photoEditorTypes.js +29 -32
- package/dist/cjs/photo/photoFilters.js +959 -985
- package/dist/cjs/photo/photoOverlays.js +899 -945
- package/dist/cjs/photo/photoSelection.js +427 -499
- package/dist/cjs/photo/usePhotoEditor.js +739 -741
- package/dist/cjs/pixel/HSVPicker.js +191 -175
- package/dist/cjs/pixel/PixelEditor.js +159 -48
- package/dist/cjs/pixel/PixelEditor.module.css.js +209 -5
- package/dist/cjs/pixel/PixelEditorCanvas.js +29 -16
- package/dist/cjs/pixel/PixelEditorMenuBar.js +160 -162
- package/dist/cjs/pixel/PixelEditorRightPanel.js +377 -45
- package/dist/cjs/pixel/PixelEditorStatusBar.js +47 -20
- package/dist/cjs/pixel/PixelEditorTimeline.js +106 -23
- package/dist/cjs/pixel/PixelEditorToolbar.js +99 -21
- package/dist/cjs/pixel/SpriteGeneratorPanel.js +483 -303
- package/dist/cjs/pixel/animalGeneratorPresets.js +776 -601
- package/dist/cjs/pixel/asepriteFormat.js +511 -560
- package/dist/cjs/pixel/buildingGeneratorPresets.js +693 -520
- package/dist/cjs/pixel/characterGeneratorPresets.js +644 -544
- package/dist/cjs/pixel/pixel-pro.js +52 -63
- package/dist/cjs/pixel/pixelEditorExports.js +388 -428
- package/dist/cjs/pixel/pixelEditorTypes.js +91 -108
- package/dist/cjs/pixel/pixelEditorUtils.js +519 -561
- package/dist/cjs/pixel/spriteGeneratorCore.js +206 -257
- package/dist/cjs/pixel/usePixelEditor.js +1321 -1343
- package/dist/cjs/texture/Nice3DTexturePainter.js +707 -440
- package/dist/cjs/ui/NiceUIDesigner.js +954 -527
- package/dist/cjs/vector/NiceSvgToCode.js +586 -446
- package/dist/cjs/vector/VectorEditor.js +290 -117
- package/dist/cjs/vector/VectorEditor.module.css.js +86 -5
- package/dist/cjs/vector/VectorEditorMenuBar.js +333 -275
- package/dist/cjs/vector/VectorEditorRightPanel.js +1094 -371
- package/dist/cjs/vector/VectorEditorShapeRenderer.js +198 -60
- package/dist/cjs/vector/VectorEditorStatusBar.js +39 -13
- package/dist/cjs/vector/useVectorEditor.js +848 -889
- package/dist/cjs/vector/vectorAnimation.js +110 -137
- package/dist/cjs/vector/vectorBooleanOps.js +398 -485
- package/dist/cjs/vector/vectorEditorExport.js +201 -203
- package/dist/cjs/vector/vectorEditorImport.js +173 -189
- package/dist/cjs/vector/vectorEditorTypes.js +42 -49
- package/dist/cjs/vector/vectorGradients.js +151 -174
- package/dist/cjs/vector/vectorIconExport.js +52 -59
- package/dist/cjs/vector/vectorIconImport.js +169 -219
- package/dist/esm/animation/AnimatedPerson.js +470 -141
- package/dist/esm/animation/AnimationEditor.js +290 -100
- package/dist/esm/animation/Audience.js +83 -59
- package/dist/esm/animation/BodyRenderer.js +71 -25
- package/dist/esm/animation/animationHelper.js +284 -287
- package/dist/esm/animation/characterTypes.js +204 -202
- package/dist/esm/animation/choreoDSL.js +212 -218
- package/dist/esm/animation/choreography.js +8 -31
- package/dist/esm/animation/karaokeIntegration.js +74 -76
- package/dist/esm/animation/lottieExport.js +112 -113
- package/dist/esm/animation/motionPath.js +235 -247
- package/dist/esm/animation/physics.js +235 -253
- package/dist/esm/animation/rig/RigPlayer.js +53 -54
- package/dist/esm/animation/rig/RiggedBody.js +71 -24
- package/dist/esm/animation/rig/choreoRigBridge.js +74 -76
- package/dist/esm/animation/rig/ik.js +14 -17
- package/dist/esm/animation/rig/poseOps.js +37 -40
- package/dist/esm/animation/rig/presets.js +70 -71
- package/dist/esm/animation/rig/rigMath.js +28 -31
- package/dist/esm/animation/rig/rigTypes.js +62 -62
- package/dist/esm/animation/shapes/arms.js +32 -12
- package/dist/esm/animation/shapes/eyes.js +135 -46
- package/dist/esm/animation/shapes/hair.js +80 -44
- package/dist/esm/animation/shapes/heads.js +140 -56
- package/dist/esm/animation/shapes/headwear.js +54 -37
- package/dist/esm/animation/shapes/legs.js +32 -12
- package/dist/esm/animation/shapes/mouths.js +127 -43
- package/dist/esm/animation/shapes/noses.js +87 -24
- package/dist/esm/animation/shapes/outfits.js +106 -38
- package/dist/esm/animation/shapes/torsos.js +16 -10
- package/dist/esm/animation/spineExport.js +106 -120
- package/dist/esm/core/LocalUI.js +111 -42
- package/dist/esm/core/NiceBrushEngine.js +761 -551
- package/dist/esm/core/collaboration.js +255 -250
- package/dist/esm/core/colorBlindness.js +106 -114
- package/dist/esm/core/dragDrop.js +157 -157
- package/dist/esm/core/editorAsk.js +53 -40
- package/dist/esm/core/fixes.js +145 -170
- package/dist/esm/core/gridGuides.js +178 -200
- package/dist/esm/core/historyVisual.js +158 -134
- package/dist/esm/core/i18n.js +15 -13
- package/dist/esm/core/integrations.js +244 -248
- package/dist/esm/core/minimap.js +151 -150
- package/dist/esm/core/plugins.js +102 -112
- package/dist/esm/core/rtl.js +77 -82
- package/dist/esm/core/shortcuts.js +200 -224
- package/dist/esm/core/theme.js +150 -148
- package/dist/esm/core/yjsCollaboration.js +240 -292
- package/dist/esm/design/design-tools.js +13 -21
- package/dist/esm/font/NiceFontEditor.js +880 -315
- package/dist/esm/font/fontFormatUtils.js +394 -447
- package/dist/esm/game/GameAsset2dEditor.js +1202 -391
- package/dist/esm/game/GameAsset2dEditor.module.css.js +146 -3
- package/dist/esm/game/gameAssetTypes.js +8 -15
- package/dist/esm/game/gameAssetUtils.js +408 -412
- package/dist/esm/game/useGameAssetEditor.js +821 -762
- package/dist/esm/index.js +332 -69
- package/dist/esm/nice2dev-ui-graphics.css +1 -1
- package/dist/esm/node_modules/lib0/array.js +15 -69
- package/dist/esm/node_modules/lib0/binary.js +14 -19
- package/dist/esm/node_modules/lib0/broadcastchannel.js +27 -85
- package/dist/esm/node_modules/lib0/buffer.js +20 -80
- package/dist/esm/node_modules/lib0/conditions.js +4 -15
- package/dist/esm/node_modules/lib0/decoding.js +128 -286
- package/dist/esm/node_modules/lib0/dom.js +20 -43
- package/dist/esm/node_modules/lib0/encoding.js +90 -415
- package/dist/esm/node_modules/lib0/environment.js +33 -91
- package/dist/esm/node_modules/lib0/error.js +8 -28
- package/dist/esm/node_modules/lib0/function.js +31 -65
- package/dist/esm/node_modules/lib0/iterator.js +11 -32
- package/dist/esm/node_modules/lib0/logging.common.js +22 -21
- package/dist/esm/node_modules/lib0/logging.js +44 -70
- package/dist/esm/node_modules/lib0/map.js +21 -85
- package/dist/esm/node_modules/lib0/math.js +9 -31
- package/dist/esm/node_modules/lib0/number.js +7 -14
- package/dist/esm/node_modules/lib0/object.js +26 -87
- package/dist/esm/node_modules/lib0/observable.js +40 -77
- package/dist/esm/node_modules/lib0/pair.js +5 -19
- package/dist/esm/node_modules/lib0/prng.js +15 -76
- package/dist/esm/node_modules/lib0/promise.js +7 -29
- package/dist/esm/node_modules/lib0/random.js +10 -22
- package/dist/esm/node_modules/lib0/schema.js +367 -686
- package/dist/esm/node_modules/lib0/set.js +4 -9
- package/dist/esm/node_modules/lib0/storage.js +23 -54
- package/dist/esm/node_modules/lib0/string.js +26 -71
- package/dist/esm/node_modules/lib0/symbol.js +3 -11
- package/dist/esm/node_modules/lib0/time.js +3 -14
- package/dist/esm/node_modules/lib0/trait/equality.js +5 -27
- package/dist/esm/node_modules/lib0/url.js +5 -17
- package/dist/esm/node_modules/lib0/webcrypto.js +3 -4
- package/dist/esm/node_modules/y-protocols/auth.js +7 -18
- package/dist/esm/node_modules/y-protocols/awareness.js +58 -115
- package/dist/esm/node_modules/y-protocols/sync.js +26 -102
- package/dist/esm/node_modules/y-websocket/src/y-websocket.js +82 -218
- package/dist/esm/node_modules/yjs/dist/yjs.js +2263 -4899
- package/dist/esm/photo/FilterThumb.js +37 -23
- package/dist/esm/photo/NiceAITools.js +685 -466
- package/dist/esm/photo/PhotoEditor.js +34 -18
- package/dist/esm/photo/PhotoEditor.module.css.js +296 -3
- package/dist/esm/photo/PhotoEditorCanvas.js +250 -89
- package/dist/esm/photo/PhotoEditorLeftPanel.js +1086 -222
- package/dist/esm/photo/PhotoEditorToolbar.js +135 -17
- package/dist/esm/photo/photoEditorActions.js +93 -71
- package/dist/esm/photo/photoEditorTypes.js +32 -31
- package/dist/esm/photo/photoFilters.js +967 -984
- package/dist/esm/photo/photoOverlays.js +913 -944
- package/dist/esm/photo/photoSelection.js +438 -498
- package/dist/esm/photo/usePhotoEditor.js +740 -740
- package/dist/esm/pixel/HSVPicker.js +192 -174
- package/dist/esm/pixel/PixelEditor.js +160 -47
- package/dist/esm/pixel/PixelEditor.module.css.js +209 -3
- package/dist/esm/pixel/PixelEditorCanvas.js +29 -14
- package/dist/esm/pixel/PixelEditorMenuBar.js +160 -160
- package/dist/esm/pixel/PixelEditorRightPanel.js +377 -43
- package/dist/esm/pixel/PixelEditorStatusBar.js +47 -18
- package/dist/esm/pixel/PixelEditorTimeline.js +106 -21
- package/dist/esm/pixel/PixelEditorToolbar.js +99 -19
- package/dist/esm/pixel/SpriteGeneratorPanel.js +483 -301
- package/dist/esm/pixel/animalGeneratorPresets.js +782 -600
- package/dist/esm/pixel/asepriteFormat.js +517 -559
- package/dist/esm/pixel/buildingGeneratorPresets.js +699 -519
- package/dist/esm/pixel/characterGeneratorPresets.js +650 -543
- package/dist/esm/pixel/pixel-pro.js +53 -62
- package/dist/esm/pixel/pixelEditorExports.js +397 -427
- package/dist/esm/pixel/pixelEditorTypes.js +103 -107
- package/dist/esm/pixel/pixelEditorUtils.js +551 -560
- package/dist/esm/pixel/spriteGeneratorCore.js +223 -256
- package/dist/esm/pixel/usePixelEditor.js +1322 -1342
- package/dist/esm/texture/Nice3DTexturePainter.js +709 -439
- package/dist/esm/ui/NiceUIDesigner.js +957 -526
- package/dist/esm/vector/NiceSvgToCode.js +589 -445
- package/dist/esm/vector/VectorEditor.js +291 -116
- package/dist/esm/vector/VectorEditor.module.css.js +86 -3
- package/dist/esm/vector/VectorEditorMenuBar.js +333 -273
- package/dist/esm/vector/VectorEditorRightPanel.js +1094 -369
- package/dist/esm/vector/VectorEditorShapeRenderer.js +199 -59
- package/dist/esm/vector/VectorEditorStatusBar.js +39 -11
- package/dist/esm/vector/useVectorEditor.js +849 -888
- package/dist/esm/vector/vectorAnimation.js +115 -136
- package/dist/esm/vector/vectorBooleanOps.js +401 -484
- package/dist/esm/vector/vectorEditorExport.js +207 -202
- package/dist/esm/vector/vectorEditorImport.js +174 -188
- package/dist/esm/vector/vectorEditorTypes.js +50 -48
- package/dist/esm/vector/vectorGradients.js +158 -173
- package/dist/esm/vector/vectorIconExport.js +53 -58
- package/dist/esm/vector/vectorIconImport.js +171 -218
- package/package.json +9 -15
|
@@ -1,491 +1,631 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
/*
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
40
|
-
|
|
41
|
-
|
|
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
|
|
44
|
-
const
|
|
45
|
-
|
|
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
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
70
|
+
}
|
|
71
|
+
return { tag: node.tag, attrs: cleanAttrs, children: filteredChildren, text: node.text };
|
|
82
72
|
}
|
|
83
73
|
function extractColorsFromNode(node, colors) {
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
if (match) {
|
|
95
|
-
colors.add(match[2].toLowerCase());
|
|
96
|
-
}
|
|
78
|
+
if (/^rgb\(/.test(val)) {
|
|
79
|
+
colors.add(val);
|
|
97
80
|
}
|
|
98
|
-
|
|
99
|
-
|
|
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
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
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
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
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
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
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
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
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
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
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
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
return `${pad}<${node.tag}${attrs ?
|
|
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
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
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
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
lines.push(
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
lines.push(
|
|
246
|
-
|
|
247
|
-
|
|
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
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
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
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
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
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
lines.push('
|
|
306
|
-
lines.push(
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
}
|
|
313
|
-
lines.push('
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
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
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
348
|
-
lines.push(
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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
|
-
|
|
361
|
-
|
|
362
|
-
|
|
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
|
-
|
|
365
|
-
|
|
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
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
if (
|
|
371
|
-
|
|
396
|
+
}, [initialSvg, setSvgInput]);
|
|
397
|
+
const handleConvert = () => {
|
|
398
|
+
convert();
|
|
399
|
+
if (result && onConvert) {
|
|
400
|
+
onConvert(result);
|
|
372
401
|
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
/*
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
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;
|