1
- import domtoimage from ' dom-to-image' ;
2
- import copy from ' copy-to-clipboard' ;
1
+ import domtoimage from " dom-to-image" ;
2
+ import copy from " copy-to-clipboard" ;
3
3
4
4
/**
5
5
* @function copyCodeToClipboard
@@ -9,22 +9,22 @@ import copy from 'copy-to-clipboard';
9
9
* @return {void } Nothing
10
10
*/
11
11
export function copyCodeToClipboard (
12
- attribute : string ,
13
- outputElement : HTMLElement ,
12
+ attribute : string ,
13
+ outputElement : HTMLElement
14
14
) : void {
15
- const copyCodeButton = < HTMLElement > (
16
- document . querySelector ( `[data-download=${ attribute } -code]` )
17
- ) ;
18
- copyCodeButton . addEventListener ( ' click' , ( ) : void => {
19
- actOnGenerator ( ) ;
20
- } ) ;
21
-
22
- function actOnGenerator ( ) {
23
- let codeToCopy : string = '' ;
24
- let element ;
25
- switch ( attribute ) {
26
- case ' pic-text' :
27
- codeToCopy = `
15
+ const copyCodeButton = < HTMLElement > (
16
+ document . querySelector ( `[data-download=${ attribute } -code]` )
17
+ ) ;
18
+ copyCodeButton . addEventListener ( " click" , ( ) : void => {
19
+ actOnGenerator ( ) ;
20
+ } ) ;
21
+
22
+ function actOnGenerator ( ) {
23
+ let codeToCopy : string = "" ;
24
+ let element ;
25
+ switch ( attribute ) {
26
+ case " pic-text" :
27
+ codeToCopy = `
28
28
div {
29
29
background-position: ${ outputElement . style . backgroundPosition } ;
30
30
background-size: ${ outputElement . style . backgroundSize } ;
@@ -34,38 +34,47 @@ export function copyCodeToClipboard(
34
34
-webkit-text-fill-color: ${ outputElement . style . webkitTextFillColor } ;
35
35
}
36
36
` ;
37
- break ;
38
- case 'gradient-text' :
39
- codeToCopy = `
40
- p{
41
- ${ outputElement . children [ 0 ] . attributes [ 0 ] . value }
37
+ break ;
38
+ case "gradient-text" :
39
+ codeToCopy = `
40
+ p{
41
+ font-size: ${
42
+ ( outputElement . children [ 0 ] as HTMLElement ) . style . fontSize
43
+ } ;
44
+ background: ${
45
+ ( outputElement . children [ 0 ] as HTMLElement ) . style . backgroundImage
46
+ } ;
47
+ background-clip: 'text';
48
+ -webkit-background-clip: 'text';
49
+ -webkit-text-fill-color: 'transparent';
42
50
}
43
51
` ;
44
52
45
- break ;
46
- case ' gradient-border' :
47
- element = outputElement . style ;
48
- codeToCopy = `
53
+ break ;
54
+ case " gradient-border" :
55
+ element = outputElement . style ;
56
+ codeToCopy = `
49
57
div {
50
58
border: ${ element . border } ,
51
59
border-width: ${ element . borderWidth } ,
52
60
border-image-slice: ${ element . borderImageSlice } ,
53
61
border-image-source: ${ element . borderImageSource } ,
54
62
}
55
63
` ;
56
- break ;
57
- case ' gradient-background' :
58
- element = outputElement . style ;
59
- codeToCopy = `
64
+ break ;
65
+ case " gradient-background" :
66
+ element = outputElement . style ;
67
+ codeToCopy = `
60
68
div {
61
69
height: 100px;
62
70
width: 100px;
63
71
background: ${ element . backgroundImage } ;
64
72
}
65
73
` ;
66
- }
67
- copy ( codeToCopy ) ;
68
- }
74
+ }
75
+
76
+ copy ( codeToCopy ) ;
77
+ }
69
78
}
70
79
71
80
/**
@@ -75,10 +84,10 @@ export function copyCodeToClipboard(
75
84
* @return {void } Nothing
76
85
*/
77
86
export function countForText ( inputElement : HTMLInputElement ) : void {
78
- const countElement = < HTMLElement > document . querySelector ( ' .count > span' ) ;
79
- inputElement . addEventListener ( ' keydown' , ( ) : void => {
80
- countElement . innerText = `${ inputElement . value . length + 1 } ` ;
81
- } ) ;
87
+ const countElement = < HTMLElement > document . querySelector ( " .count > span" ) ;
88
+ inputElement . addEventListener ( " keydown" , ( ) : void => {
89
+ countElement . innerText = `${ inputElement . value . length + 1 } ` ;
90
+ } ) ;
82
91
}
83
92
84
93
/**
@@ -88,10 +97,10 @@ export function countForText(inputElement: HTMLInputElement): void {
88
97
* @return {void } Nothing
89
98
*/
90
99
export function downloadPNG ( attribute : string , outputImage : HTMLElement ) : void {
91
- domtoimage . toPng ( outputImage , { quality : 0.95 } ) . then ( ( dataUrl ) => {
92
- const link = createDownloadLink ( `${ attribute } .png` , dataUrl ) ;
93
- link . click ( ) ;
94
- } ) ;
100
+ domtoimage . toPng ( outputImage , { quality : 0.95 } ) . then ( ( dataUrl ) => {
101
+ const link = createDownloadLink ( `${ attribute } .png` , dataUrl ) ;
102
+ link . click ( ) ;
103
+ } ) ;
95
104
}
96
105
97
106
/**
@@ -101,26 +110,26 @@ export function downloadPNG(attribute: string, outputImage: HTMLElement): void {
101
110
* @return {void } Nothing
102
111
*/
103
112
export function downloadSVG ( attribute : string , outputImage : HTMLElement ) : void {
104
- domtoimage . toSvg ( outputImage ) . then ( ( dataUrl ) => {
105
- const link = createDownloadLink ( `${ attribute } .svg` , dataUrl ) ;
106
- link . click ( ) ;
107
- } ) ;
113
+ domtoimage . toSvg ( outputImage ) . then ( ( dataUrl ) => {
114
+ const link = createDownloadLink ( `${ attribute } .svg` , dataUrl ) ;
115
+ link . click ( ) ;
116
+ } ) ;
108
117
}
109
118
110
119
export function triggerEmptyAnimation ( inputElement : HTMLInputElement ) : void {
111
- inputElement . style . borderColor = ' red' ;
112
- inputElement . animate (
113
- [
114
- { transform : ' translate(10px, 0)' } ,
115
- { transform : ' translate(-10px, 0)' } ,
116
- { transform : ' translate(0, 0)' } ,
117
- ] ,
118
- { duration : 300 } ,
119
- ) ;
120
-
121
- setTimeout ( ( ) => {
122
- inputElement . style . borderColor = ' white' ;
123
- } , 1000 ) ;
120
+ inputElement . style . borderColor = " red" ;
121
+ inputElement . animate (
122
+ [
123
+ { transform : " translate(10px, 0)" } ,
124
+ { transform : " translate(-10px, 0)" } ,
125
+ { transform : " translate(0, 0)" } ,
126
+ ] ,
127
+ { duration : 300 }
128
+ ) ;
129
+
130
+ setTimeout ( ( ) => {
131
+ inputElement . style . borderColor = " white" ;
132
+ } , 1000 ) ;
124
133
}
125
134
126
135
/**
@@ -130,7 +139,7 @@ export function triggerEmptyAnimation(inputElement: HTMLInputElement): void {
130
139
* @return {HTMLElement } The type of the button Element
131
140
*/
132
141
export const getCopyCodeButton = ( attribute : string ) : HTMLElement =>
133
- < HTMLElement > document . querySelector ( `[data-download = ${ attribute } -code]` ) ;
142
+ < HTMLElement > document . querySelector ( `[data-download = ${ attribute } -code]` ) ;
134
143
135
144
/**
136
145
* @function getPNGButton
@@ -139,7 +148,7 @@ export const getCopyCodeButton = (attribute: string): HTMLElement =>
139
148
* @return {HTMLElement } The type of the button Element
140
149
*/
141
150
export const getPNGButton = ( attribute : string ) : HTMLElement =>
142
- < HTMLElement > document . querySelector ( `[data-download=${ attribute } -PNG]` ) ;
151
+ < HTMLElement > document . querySelector ( `[data-download=${ attribute } -PNG]` ) ;
143
152
144
153
/**
145
154
* @function getSVGButton
@@ -148,29 +157,29 @@ export const getPNGButton = (attribute: string): HTMLElement =>
148
157
* @return {HTMLElement } The type of the button Element
149
158
*/
150
159
export const getSVGButton = ( attribute : string ) : HTMLElement =>
151
- < HTMLElement > document . querySelector ( `[data-download=${ attribute } -svg]` ) ;
160
+ < HTMLElement > document . querySelector ( `[data-download=${ attribute } -svg]` ) ;
152
161
153
162
export const getResultButton = ( attribute : string ) : HTMLElement =>
154
- < HTMLElement > document . querySelector ( `[data-button = ${ attribute } ]` ) ;
163
+ < HTMLElement > document . querySelector ( `[data-button = ${ attribute } ]` ) ;
155
164
156
165
export const getColorInput1 = ( attribute : string ) : HTMLInputElement =>
157
- < HTMLInputElement > document . getElementById ( `${ attribute } -color1` ) ;
166
+ < HTMLInputElement > document . getElementById ( `${ attribute } -color1` ) ;
158
167
159
168
export const getColorInput2 = ( attribute : string ) : HTMLInputElement =>
160
- < HTMLInputElement > document . getElementById ( `${ attribute } -color2` ) ;
169
+ < HTMLInputElement > document . getElementById ( `${ attribute } -color2` ) ;
161
170
162
171
export const getOutput = ( attribute : string ) : HTMLElement =>
163
- < HTMLElement > document . querySelector ( `[data-modal = ${ attribute } ] .output` ) ;
172
+ < HTMLElement > document . querySelector ( `[data-modal = ${ attribute } ] .output` ) ;
164
173
165
174
export const getRange = ( attribute : string ) : HTMLInputElement =>
166
- < HTMLInputElement > document . getElementById ( `${ attribute } -degree` ) ;
175
+ < HTMLInputElement > document . getElementById ( `${ attribute } -degree` ) ;
167
176
168
177
export const getInputText = ( attribute : string ) =>
169
- < HTMLInputElement > document . getElementById ( `${ attribute } -text` ) ;
178
+ < HTMLInputElement > document . getElementById ( `${ attribute } -text` ) ;
170
179
171
180
function createDownloadLink ( fileName : string , url : string ) {
172
- const link = document . createElement ( 'a' ) ;
173
- link . download = fileName ;
174
- link . href = url ;
175
- return link ;
181
+ const link = document . createElement ( "a" ) ;
182
+ link . download = fileName ;
183
+ link . href = url ;
184
+ return link ;
176
185
}
0 commit comments