@@ -3,13 +3,15 @@ let defaultSize = 512
3
3
const generateIconSVG = ( options ) => {
4
4
const {
5
5
text = 'AI' ,
6
- size = defaultSize ,
7
- bgColor = '#131516' ,
8
- radius = 80 ,
9
- fontFamily = 'Arial' ,
10
- fontWeight = 'normal' ,
11
- textColor = '#70e000' ,
12
- verticalOffset = 0
6
+ textLead = - 1 ,
7
+ textLineHeight = 1 ,
8
+ size = defaultSize ,
9
+ bgColor = '#131516' ,
10
+ radius = 80 ,
11
+ fontFamily = 'Arial' ,
12
+ fontWeight = 'normal' ,
13
+ textColor = '#70e000' ,
14
+ verticalOffset = 0
13
15
} = options ;
14
16
15
17
const svgNS = "http://www.w3.org/2000/svg" ;
@@ -33,7 +35,14 @@ const generateIconSVG = (options) => {
33
35
textElement . setAttribute ( "font-family" , fontFamily ) ;
34
36
textElement . setAttribute ( "font-weight" , fontWeight ) ;
35
37
textElement . setAttribute ( "fill" , textColor ) ;
36
- textElement . textContent = text ;
38
+ textElement . innerHTML = text . replace ( / \r \n | \r / g, '\n' ) . split ( '\n' ) [ 0 ] + text
39
+ . replace ( / \r \n | \r / g, '\n' )
40
+ . split ( '\n' )
41
+ . slice ( 1 )
42
+ . map ( ( item ) => {
43
+ return '<tspan dx="' + textLead + 'em" dy="' + textLineHeight + 'em">' + item + '</tspan>'
44
+ } ) . join ( '' )
45
+
37
46
svg . appendChild ( textElement ) ;
38
47
39
48
const adjustTextSizeAndPosition = ( ) => {
@@ -506,6 +515,8 @@ const applyColorScheme = (index) => {
506
515
507
516
const defaultSettings = {
508
517
text : 'AI' ,
518
+ textLead : - 1 ,
519
+ textLineHeight : 1 ,
509
520
size : defaultSize ,
510
521
bgColor : '#131516' ,
511
522
radius : 80 ,
@@ -518,6 +529,8 @@ const defaultSettings = {
518
529
const generateIcon = ( ) => {
519
530
const options = {
520
531
text : document . getElementById ( 'text' ) . value ,
532
+ textLead : parseFloat ( document . getElementById ( 'textLead' ) . value ) ,
533
+ textLineHeight : parseFloat ( document . getElementById ( 'textLineHeight' ) . value ) ,
521
534
size : parseInt ( document . getElementById ( 'size' ) . value ) ,
522
535
bgColor : document . getElementById ( 'bgColor' ) . value ,
523
536
radius : parseInt ( document . getElementById ( 'radius' ) . value ) ,
@@ -641,6 +654,8 @@ const resetToDefault = () => {
641
654
}
642
655
} ) ;
643
656
document . getElementById ( 'verticalOffsetValue' ) . textContent = '0%' ;
657
+ document . getElementById ( 'textLeadValue' ) . textContent = - 1 ;
658
+ document . getElementById ( 'textLineHeightValue' ) . textContent = 1 ;
644
659
645
660
generateIcon ( ) ;
646
661
} ;
@@ -726,6 +741,24 @@ verticalOffsetInput.addEventListener('input', function() {
726
741
generateIcon ( ) ;
727
742
} ) ;
728
743
744
+ const textLeadInput = document . getElementById ( 'textLead' ) ;
745
+ const textLeadValue = document . getElementById ( 'textLeadValue' ) ;
746
+
747
+ textLeadInput . addEventListener ( 'input' , function ( ) {
748
+ console . log ( 'changed' , this . value )
749
+ textLeadValue . textContent = this . value ;
750
+ generateIcon ( ) ;
751
+ } ) ;
752
+
753
+ const textLineHeightInput = document . getElementById ( 'textLineHeight' ) ;
754
+ const textLineHeightValue = document . getElementById ( 'textLineHeightValue' ) ;
755
+
756
+ textLineHeightInput . addEventListener ( 'input' , function ( ) {
757
+ console . log ( 'changed' , this . value )
758
+ textLineHeightValue . textContent = this . value ;
759
+ generateIcon ( ) ;
760
+ } ) ;
761
+
729
762
// Add event listeners to all input elements
730
763
const inputElements = document . querySelectorAll ( 'input, select' ) ;
731
764
inputElements . forEach ( element => {
@@ -1611,6 +1644,8 @@ document.addEventListener('DOMContentLoaded', function() {
1611
1644
1612
1645
function applyConfig ( config ) {
1613
1646
document . getElementById ( 'text' ) . value = config . text ;
1647
+ document . getElementById ( 'textLead' ) . value = config . textLead ;
1648
+ document . getElementById ( 'textLineHeight' ) . value = config . textLineHeight ;
1614
1649
document . getElementById ( 'size' ) . value = config . size === 64 ? config . size * 8 : config . size ;
1615
1650
document . getElementById ( 'bgColor' ) . value = config . bgColor ;
1616
1651
document . getElementById ( 'textColor' ) . value = config . textColor ;
@@ -1663,4 +1698,4 @@ document.addEventListener('DOMContentLoaded', (event) => {
1663
1698
}
1664
1699
} ) ;
1665
1700
} ) ;
1666
- } ) ;
1701
+ } ) ;
0 commit comments