Skip to content

Commit 0621c37

Browse files
committed
fix: code generated by gradient-text
code generated by gradient text is fixed fix #82
1 parent c2cc149 commit 0621c37

File tree

2 files changed

+153
-143
lines changed

2 files changed

+153
-143
lines changed

src/general.ts

Lines changed: 80 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
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";
33

44
/**
55
* @function copyCodeToClipboard
@@ -9,22 +9,22 @@ import copy from 'copy-to-clipboard';
99
* @return {void} Nothing
1010
*/
1111
export function copyCodeToClipboard(
12-
attribute: string,
13-
outputElement: HTMLElement,
12+
attribute: string,
13+
outputElement: HTMLElement
1414
): 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 = `
2828
div {
2929
background-position: ${outputElement.style.backgroundPosition};
3030
background-size: ${outputElement.style.backgroundSize};
@@ -34,38 +34,47 @@ export function copyCodeToClipboard(
3434
-webkit-text-fill-color: ${outputElement.style.webkitTextFillColor};
3535
}
3636
`;
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';
4250
}
4351
`;
4452

45-
break;
46-
case 'gradient-border':
47-
element = outputElement.style;
48-
codeToCopy = `
53+
break;
54+
case "gradient-border":
55+
element = outputElement.style;
56+
codeToCopy = `
4957
div {
5058
border: ${element.border},
5159
border-width: ${element.borderWidth},
5260
border-image-slice: ${element.borderImageSlice},
5361
border-image-source: ${element.borderImageSource},
5462
}
5563
`;
56-
break;
57-
case 'gradient-background':
58-
element = outputElement.style;
59-
codeToCopy = `
64+
break;
65+
case "gradient-background":
66+
element = outputElement.style;
67+
codeToCopy = `
6068
div {
6169
height: 100px;
6270
width: 100px;
6371
background: ${element.backgroundImage};
6472
}
6573
`;
66-
}
67-
copy(codeToCopy);
68-
}
74+
}
75+
76+
copy(codeToCopy);
77+
}
6978
}
7079

7180
/**
@@ -75,10 +84,10 @@ export function copyCodeToClipboard(
7584
* @return {void} Nothing
7685
*/
7786
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+
});
8291
}
8392

8493
/**
@@ -88,10 +97,10 @@ export function countForText(inputElement: HTMLInputElement): void {
8897
* @return {void} Nothing
8998
*/
9099
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+
});
95104
}
96105

97106
/**
@@ -101,26 +110,26 @@ export function downloadPNG(attribute: string, outputImage: HTMLElement): void {
101110
* @return {void} Nothing
102111
*/
103112
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+
});
108117
}
109118

110119
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);
124133
}
125134

126135
/**
@@ -130,7 +139,7 @@ export function triggerEmptyAnimation(inputElement: HTMLInputElement): void {
130139
* @return {HTMLElement} The type of the button Element
131140
*/
132141
export const getCopyCodeButton = (attribute: string): HTMLElement =>
133-
<HTMLElement>document.querySelector(`[data-download = ${attribute}-code]`);
142+
<HTMLElement>document.querySelector(`[data-download = ${attribute}-code]`);
134143

135144
/**
136145
* @function getPNGButton
@@ -139,7 +148,7 @@ export const getCopyCodeButton = (attribute: string): HTMLElement =>
139148
* @return {HTMLElement} The type of the button Element
140149
*/
141150
export const getPNGButton = (attribute: string): HTMLElement =>
142-
<HTMLElement>document.querySelector(`[data-download=${attribute}-PNG]`);
151+
<HTMLElement>document.querySelector(`[data-download=${attribute}-PNG]`);
143152

144153
/**
145154
* @function getSVGButton
@@ -148,29 +157,29 @@ export const getPNGButton = (attribute: string): HTMLElement =>
148157
* @return {HTMLElement} The type of the button Element
149158
*/
150159
export const getSVGButton = (attribute: string): HTMLElement =>
151-
<HTMLElement>document.querySelector(`[data-download=${attribute}-svg]`);
160+
<HTMLElement>document.querySelector(`[data-download=${attribute}-svg]`);
152161

153162
export const getResultButton = (attribute: string): HTMLElement =>
154-
<HTMLElement>document.querySelector(`[data-button = ${attribute}]`);
163+
<HTMLElement>document.querySelector(`[data-button = ${attribute}]`);
155164

156165
export const getColorInput1 = (attribute: string): HTMLInputElement =>
157-
<HTMLInputElement>document.getElementById(`${attribute}-color1`);
166+
<HTMLInputElement>document.getElementById(`${attribute}-color1`);
158167

159168
export const getColorInput2 = (attribute: string): HTMLInputElement =>
160-
<HTMLInputElement>document.getElementById(`${attribute}-color2`);
169+
<HTMLInputElement>document.getElementById(`${attribute}-color2`);
161170

162171
export const getOutput = (attribute: string): HTMLElement =>
163-
<HTMLElement>document.querySelector(`[data-modal = ${attribute}] .output`);
172+
<HTMLElement>document.querySelector(`[data-modal = ${attribute}] .output`);
164173

165174
export const getRange = (attribute: string): HTMLInputElement =>
166-
<HTMLInputElement>document.getElementById(`${attribute}-degree`);
175+
<HTMLInputElement>document.getElementById(`${attribute}-degree`);
167176

168177
export const getInputText = (attribute: string) =>
169-
<HTMLInputElement>document.getElementById(`${attribute}-text`);
178+
<HTMLInputElement>document.getElementById(`${attribute}-text`);
170179

171180
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;
176185
}

0 commit comments

Comments
 (0)