mirror of
https://github.com/CorentinTh/it-tools.git
synced 2025-05-04 21:37:11 -04:00
fix: last modif
This commit is contained in:
parent
42d1bf7d35
commit
45998fd1f3
5 changed files with 174 additions and 42 deletions
|
@ -2,7 +2,17 @@ import { stringToUrl } from 'svg-to-url';
|
|||
|
||||
export type CSSType = 'Background' | 'Border' | 'ListItemBullet' | 'Url';
|
||||
|
||||
function fileToDataUrl(file: File) {
|
||||
async function fileToDataUrl(file: File) {
|
||||
if (file.type === 'image/svg+xml'){
|
||||
const svgContent = (await (new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsText(file);
|
||||
reader.onload = () => resolve(reader.result?.toString() ?? '');
|
||||
reader.onerror = error => reject(error);
|
||||
})));
|
||||
return svgToDataUrl(svgContent);
|
||||
}
|
||||
|
||||
return new Promise<string>((resolve, reject) => {
|
||||
const reader = new FileReader();
|
||||
reader.readAsDataURL(file);
|
||||
|
@ -20,6 +30,9 @@ export async function imageToCSS(
|
|||
image: File | string,
|
||||
type: CSSType,
|
||||
) {
|
||||
if (image === '' || !image) {
|
||||
return '';
|
||||
}
|
||||
const dataURI = image instanceof File ? await fileToDataUrl(image) : svgToDataUrl(image);
|
||||
switch (type) {
|
||||
case 'Background':
|
||||
|
|
|
@ -61,13 +61,13 @@ watch(svgContent, (_, newValue) => {
|
|||
placeholder="Select CSS Type"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
<div v-if="cssCode !== ''">
|
||||
<n-divider />
|
||||
|
||||
<div>
|
||||
<h3>CSS Code</h3>
|
||||
<TextareaCopyable
|
||||
:value="cssCode"
|
||||
:word-wrap="true"
|
||||
word-wrap
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue