Merge 84de3c4b62 into 63fbd3b45c
				
					
				
			This commit is contained in:
		
						commit
						d952b1a37e
					
				
							
								
								
									
										7
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										7
									
								
								components.d.ts
									
									
									
									
										vendored
									
									
								
							| @ -89,6 +89,7 @@ declare module '@vue/runtime-core' { | |||||||
|     HtmlWysiwygEditor: typeof import('./src/tools/html-wysiwyg-editor/html-wysiwyg-editor.vue')['default'] |     HtmlWysiwygEditor: typeof import('./src/tools/html-wysiwyg-editor/html-wysiwyg-editor.vue')['default'] | ||||||
|     HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default'] |     HttpStatusCodes: typeof import('./src/tools/http-status-codes/http-status-codes.vue')['default'] | ||||||
|     IbanValidatorAndParser: typeof import('./src/tools/iban-validator-and-parser/iban-validator-and-parser.vue')['default'] |     IbanValidatorAndParser: typeof import('./src/tools/iban-validator-and-parser/iban-validator-and-parser.vue')['default'] | ||||||
|  |     IcoConverter: typeof import('./src/tools/ico-converter/ico-converter.vue')['default'] | ||||||
|     'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] |     'IconMdi:brushVariant': typeof import('~icons/mdi/brush-variant')['default'] | ||||||
|     'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default'] |     'IconMdi:kettleSteamOutline': typeof import('~icons/mdi/kettle-steam-outline')['default'] | ||||||
|     IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] |     IconMdiChevronDown: typeof import('~icons/mdi/chevron-down')['default'] | ||||||
| @ -135,14 +136,16 @@ declare module '@vue/runtime-core' { | |||||||
|     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] |     NConfigProvider: typeof import('naive-ui')['NConfigProvider'] | ||||||
|     NDivider: typeof import('naive-ui')['NDivider'] |     NDivider: typeof import('naive-ui')['NDivider'] | ||||||
|     NEllipsis: typeof import('naive-ui')['NEllipsis'] |     NEllipsis: typeof import('naive-ui')['NEllipsis'] | ||||||
|  |     NGi: typeof import('naive-ui')['NGi'] | ||||||
|  |     NGrid: typeof import('naive-ui')['NGrid'] | ||||||
|     NH1: typeof import('naive-ui')['NH1'] |     NH1: typeof import('naive-ui')['NH1'] | ||||||
|     NH3: typeof import('naive-ui')['NH3'] |     NH3: typeof import('naive-ui')['NH3'] | ||||||
|     NIcon: typeof import('naive-ui')['NIcon'] |     NIcon: typeof import('naive-ui')['NIcon'] | ||||||
|     NLayout: typeof import('naive-ui')['NLayout'] |     NLayout: typeof import('naive-ui')['NLayout'] | ||||||
|     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] |     NLayoutSider: typeof import('naive-ui')['NLayoutSider'] | ||||||
|     NMenu: typeof import('naive-ui')['NMenu'] |     NMenu: typeof import('naive-ui')['NMenu'] | ||||||
|     NSpace: typeof import('naive-ui')['NSpace'] |     NSpin: typeof import('naive-ui')['NSpin'] | ||||||
|     NTable: typeof import('naive-ui')['NTable'] |     NTag: typeof import('naive-ui')['NTag'] | ||||||
|     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] |     NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default'] | ||||||
|     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] |     OtpCodeGeneratorAndValidator: typeof import('./src/tools/otp-code-generator-and-validator/otp-code-generator-and-validator.vue')['default'] | ||||||
|     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] |     PasswordStrengthAnalyser: typeof import('./src/tools/password-strength-analyser/password-strength-analyser.vue')['default'] | ||||||
|  | |||||||
| @ -70,6 +70,8 @@ | |||||||
|     "iarna-toml-esm": "^3.0.5", |     "iarna-toml-esm": "^3.0.5", | ||||||
|     "ibantools": "^4.3.3", |     "ibantools": "^4.3.3", | ||||||
|     "js-base64": "^3.7.6", |     "js-base64": "^3.7.6", | ||||||
|  |     "image-in-browser": "^3.1.0", | ||||||
|  |     "js-base64": "^3.7.7", | ||||||
|     "json5": "^2.2.3", |     "json5": "^2.2.3", | ||||||
|     "jwt-decode": "^3.1.2", |     "jwt-decode": "^3.1.2", | ||||||
|     "libphonenumber-js": "^1.10.28", |     "libphonenumber-js": "^1.10.28", | ||||||
|  | |||||||
							
								
								
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										9
									
								
								pnpm-lock.yaml
									
									
									
										generated
									
									
									
								
							| @ -104,8 +104,11 @@ dependencies: | |||||||
|   ibantools: |   ibantools: | ||||||
|     specifier: ^4.3.3 |     specifier: ^4.3.3 | ||||||
|     version: 4.3.3 |     version: 4.3.3 | ||||||
|  |   image-in-browser: | ||||||
|  |     specifier: ^3.1.0 | ||||||
|  |     version: 3.1.0 | ||||||
|   js-base64: |   js-base64: | ||||||
|     specifier: ^3.7.6 |     specifier: ^3.7.7 | ||||||
|     version: 3.7.7 |     version: 3.7.7 | ||||||
|   json5: |   json5: | ||||||
|     specifier: ^2.2.3 |     specifier: ^2.2.3 | ||||||
| @ -6188,6 +6191,10 @@ packages: | |||||||
|     engines: {node: '>= 4'} |     engines: {node: '>= 4'} | ||||||
|     dev: true |     dev: true | ||||||
| 
 | 
 | ||||||
|  |   /image-in-browser@3.1.0: | ||||||
|  |     resolution: {integrity: sha512-8VYDQU/AzN6cLrPEjF1W3QFLZS9clmEbztXE6WMBoxBJxOzjzSvC1kIusEQEc+IBFxsCbMKREFw/Cn3xVE8VMA==} | ||||||
|  |     dev: false | ||||||
|  | 
 | ||||||
|   /image-size@0.5.5: |   /image-size@0.5.5: | ||||||
|     resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==} |     resolution: {integrity: sha512-6TDAlDPZxUFCv+fuOkIoXT/V/f3Qbq8e37p+YOiYrUv3v9cc3/6x78VdfPgFVaB9dZYeLUfKgHRebpkm/oP2VQ==} | ||||||
|     engines: {node: '>=0.10.0'} |     engines: {node: '>=0.10.0'} | ||||||
|  | |||||||
| @ -1,6 +1,7 @@ | |||||||
| import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types'; | import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types'; | ||||||
| import type { Ref } from 'vue'; | import type { MaybeRef, Ref } from 'vue'; | ||||||
| import _ from 'lodash'; | import _ from 'lodash'; | ||||||
|  | import { get } from '@vueuse/core'; | ||||||
| 
 | 
 | ||||||
| export { | export { | ||||||
|   getMimeTypeFromBase64, |   getMimeTypeFromBase64, | ||||||
| @ -75,21 +76,11 @@ function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }: | |||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function useDownloadFileFromBase64( | function useDownloadFileFromBase64( | ||||||
|   { source, filename, extension, fileMimeType }: |  | ||||||
|   { source: Ref<string>; filename?: string; extension?: string; fileMimeType?: string }) { |  | ||||||
|   return { |  | ||||||
|     download() { |  | ||||||
|       downloadFromBase64({ sourceValue: source.value, filename, extension, fileMimeType }); |  | ||||||
|     }, |  | ||||||
|   }; |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| function useDownloadFileFromBase64Refs( |  | ||||||
|   { source, filename, extension }: |   { source, filename, extension }: | ||||||
|   { source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) { |   { source: MaybeRef<string>; filename?: MaybeRef<string>; extension?: MaybeRef<string> }) { | ||||||
|   return { |   return { | ||||||
|     download() { |     download() { | ||||||
|       downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value }); |       downloadFromBase64({ sourceValue: get(source), filename: get(filename), extension: get(extension) }); | ||||||
|     }, |     }, | ||||||
|   }; |   }; | ||||||
| } | } | ||||||
| @ -116,3 +107,13 @@ function previewImageFromBase64(base64String: string): HTMLImageElement { | |||||||
| 
 | 
 | ||||||
|   return img; |   return img; | ||||||
| } | } | ||||||
|  | 
 | ||||||
|  | function useDownloadFileFromBase64Refs( | ||||||
|  |   { source, filename, extension }: | ||||||
|  |   { source: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) { | ||||||
|  |   return { | ||||||
|  |     download() { | ||||||
|  |       downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value }); | ||||||
|  |     }, | ||||||
|  |   }; | ||||||
|  | } | ||||||
|  | |||||||
							
								
								
									
										92
									
								
								src/tools/ico-converter/ico-converter.vue
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										92
									
								
								src/tools/ico-converter/ico-converter.vue
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,92 @@ | |||||||
|  | <script setup lang="ts"> | ||||||
|  | import { Base64 } from 'js-base64'; | ||||||
|  | import { Transform, decodeIco, decodeImage, encodeIcoImages, encodePng } from 'image-in-browser'; | ||||||
|  | import { useDownloadFileFromBase64 } from '@/composable/downloadBase64'; | ||||||
|  | 
 | ||||||
|  | const status = ref<'idle' | 'done' | 'error' | 'processing'>('idle'); | ||||||
|  | const file = ref<File | null>(null); | ||||||
|  | 
 | ||||||
|  | const base64OutputFile = ref(''); | ||||||
|  | const fileName = ref(''); | ||||||
|  | const fileExtension = ref(''); | ||||||
|  | const { download } = useDownloadFileFromBase64( | ||||||
|  |   { | ||||||
|  |     source: base64OutputFile, | ||||||
|  |     filename: fileName, | ||||||
|  |     extension: fileExtension, | ||||||
|  |   }); | ||||||
|  | 
 | ||||||
|  | async function onFileUploaded(uploadedFile: File) { | ||||||
|  |   file.value = uploadedFile; | ||||||
|  |   const fileBuffer = new Uint8Array(await uploadedFile.arrayBuffer()); | ||||||
|  | 
 | ||||||
|  |   fileName.value = `${uploadedFile.name}`; | ||||||
|  |   status.value = 'processing'; | ||||||
|  |   try { | ||||||
|  |     if (uploadedFile.type.includes('icon')) { | ||||||
|  |       const decodedIco = decodeIco({ | ||||||
|  |         data: fileBuffer, | ||||||
|  |         largest: true, | ||||||
|  |       }); | ||||||
|  |       if (decodedIco == null) { | ||||||
|  |         throw new Error('Invalid ICO file!'); | ||||||
|  |       } | ||||||
|  |       const encodedPng = encodePng({ | ||||||
|  |         image: decodedIco, | ||||||
|  |       }); | ||||||
|  |       fileExtension.value = 'png'; | ||||||
|  |       base64OutputFile.value = `data:image/png;base64,${Base64.fromUint8Array(encodedPng)}`; | ||||||
|  |     } | ||||||
|  |     else { | ||||||
|  |       const decodedImage = decodeImage({ | ||||||
|  |         data: fileBuffer, | ||||||
|  |       }); | ||||||
|  | 
 | ||||||
|  |       if (decodedImage == null) { | ||||||
|  |         throw new Error('Invalid PNG file!'); | ||||||
|  |       }; | ||||||
|  | 
 | ||||||
|  |       const encodedICO = encodeIcoImages({ | ||||||
|  |         images: [16, 32, 64, 128, 256].map(size => Transform.copyResize({ | ||||||
|  |           image: decodedImage, | ||||||
|  |           width: size, | ||||||
|  |           maintainAspect: true, | ||||||
|  |         })), | ||||||
|  |       }); | ||||||
|  |       fileExtension.value = 'ico'; | ||||||
|  |       base64OutputFile.value = `data:image/x-icon;base64,${Base64.fromUint8Array(encodedICO)}`; | ||||||
|  |     } | ||||||
|  |     status.value = 'done'; | ||||||
|  | 
 | ||||||
|  |     download(); | ||||||
|  |   } | ||||||
|  |   catch (e) { | ||||||
|  |     status.value = 'error'; | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | </script> | ||||||
|  | 
 | ||||||
|  | <template> | ||||||
|  |   <div> | ||||||
|  |     <div style="flex: 0 0 100%"> | ||||||
|  |       <div mx-auto max-w-600px> | ||||||
|  |         <c-file-upload | ||||||
|  |           title="Drag and drop an ICO or PNG/JPEG file here, or click to select a file" | ||||||
|  |           accept=".ico,.png,.jpg" | ||||||
|  |           paste-image | ||||||
|  |           @file-upload="onFileUploaded" | ||||||
|  |         /> | ||||||
|  |       </div> | ||||||
|  |     </div> | ||||||
|  | 
 | ||||||
|  |     <div mt-3 flex justify-center> | ||||||
|  |       <c-alert v-if="status === 'error'" type="error"> | ||||||
|  |         An error occured processing {{ fileName }} | ||||||
|  |       </c-alert> | ||||||
|  |       <n-spin | ||||||
|  |         v-if="status === 'processing'" | ||||||
|  |         size="small" | ||||||
|  |       /> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | </template> | ||||||
							
								
								
									
										12
									
								
								src/tools/ico-converter/index.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								src/tools/ico-converter/index.ts
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,12 @@ | |||||||
|  | import { PictureInPicture } from '@vicons/tabler'; | ||||||
|  | import { defineTool } from '../tool'; | ||||||
|  | 
 | ||||||
|  | export const tool = defineTool({ | ||||||
|  |   name: 'ICO/PNG converter', | ||||||
|  |   path: '/ico-converter', | ||||||
|  |   description: 'Convert from PNG/JPEG to/from ICO', | ||||||
|  |   keywords: ['ico', 'png', 'jpeg', 'icon', 'converter'], | ||||||
|  |   component: () => import('./ico-converter.vue'), | ||||||
|  |   icon: PictureInPicture, | ||||||
|  |   createdAt: new Date('2024-08-15'), | ||||||
|  | }); | ||||||
| @ -1,6 +1,7 @@ | |||||||
| import { tool as base64FileConverter } from './base64-file-converter'; | import { tool as base64FileConverter } from './base64-file-converter'; | ||||||
| import { tool as base64StringConverter } from './base64-string-converter'; | import { tool as base64StringConverter } from './base64-string-converter'; | ||||||
| import { tool as basicAuthGenerator } from './basic-auth-generator'; | import { tool as basicAuthGenerator } from './basic-auth-generator'; | ||||||
|  | import { tool as icoConverter } from './ico-converter'; | ||||||
| import { tool as emailNormalizer } from './email-normalizer'; | import { tool as emailNormalizer } from './email-normalizer'; | ||||||
| 
 | 
 | ||||||
| import { tool as asciiTextDrawer } from './ascii-text-drawer'; | import { tool as asciiTextDrawer } from './ascii-text-drawer'; | ||||||
| @ -141,7 +142,13 @@ export const toolsByCategory: ToolCategory[] = [ | |||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     name: 'Images and videos', |     name: 'Images and videos', | ||||||
|     components: [qrCodeGenerator, wifiQrCodeGenerator, svgPlaceholderGenerator, cameraRecorder], |     components: [ | ||||||
|  |       qrCodeGenerator, | ||||||
|  |       wifiQrCodeGenerator, | ||||||
|  |       svgPlaceholderGenerator, | ||||||
|  |       cameraRecorder, | ||||||
|  |       icoConverter, | ||||||
|  |     ], | ||||||
|   }, |   }, | ||||||
|   { |   { | ||||||
|     name: 'Development', |     name: 'Development', | ||||||
|  | |||||||
| @ -5,10 +5,12 @@ const props = withDefaults(defineProps<{ | |||||||
|   multiple?: boolean |   multiple?: boolean | ||||||
|   accept?: string |   accept?: string | ||||||
|   title?: string |   title?: string | ||||||
|  |   pasteImage?: boolean | ||||||
| }>(), { | }>(), { | ||||||
|   multiple: false, |   multiple: false, | ||||||
|   accept: undefined, |   accept: undefined, | ||||||
|   title: 'Drag and drop files here, or click to select files', |   title: 'Drag and drop files here, or click to select files', | ||||||
|  |   pasteImage: false, | ||||||
| }); | }); | ||||||
| 
 | 
 | ||||||
| const emit = defineEmits<{ | const emit = defineEmits<{ | ||||||
| @ -16,11 +18,31 @@ const emit = defineEmits<{ | |||||||
|   (event: 'fileUpload', file: File): void |   (event: 'fileUpload', file: File): void | ||||||
| }>(); | }>(); | ||||||
| 
 | 
 | ||||||
| const { multiple } = toRefs(props); | const { multiple, pasteImage } = toRefs(props); | ||||||
| 
 | 
 | ||||||
| const isOverDropZone = ref(false); | const isOverDropZone = ref(false); | ||||||
| 
 | 
 | ||||||
|  | function toBase64(file: File) { | ||||||
|  |   return new Promise<string>((resolve, reject) => { | ||||||
|  |     const reader = new FileReader(); | ||||||
|  |     reader.readAsDataURL(file); | ||||||
|  |     reader.onload = () => resolve(reader.result?.toString() ?? ''); | ||||||
|  |     reader.onerror = error => reject(error); | ||||||
|  |   }); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| const fileInput = ref<HTMLInputElement | null>(null); | const fileInput = ref<HTMLInputElement | null>(null); | ||||||
|  | const imgPreview = ref<HTMLImageElement | null>(null); | ||||||
|  | async function handlePreview(image: File) { | ||||||
|  |   if (imgPreview.value) { | ||||||
|  |     imgPreview.value.src = await toBase64(image); | ||||||
|  |   } | ||||||
|  | } | ||||||
|  | function clearPreview() { | ||||||
|  |   if (imgPreview.value) { | ||||||
|  |     imgPreview.value.src = ''; | ||||||
|  |   } | ||||||
|  | } | ||||||
| 
 | 
 | ||||||
| function triggerFileInput() { | function triggerFileInput() { | ||||||
|   fileInput.value?.click(); |   fileInput.value?.click(); | ||||||
| @ -39,7 +61,30 @@ function handleDrop(event: DragEvent) { | |||||||
|   handleUpload(files); |   handleUpload(files); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| function handleUpload(files: FileList | null | undefined) { | async function onPasteImage(evt: ClipboardEvent) { | ||||||
|  |   if (!pasteImage.value) { | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  | 
 | ||||||
|  |   const items = evt.clipboardData?.items; | ||||||
|  |   if (!items) { | ||||||
|  |     return false; | ||||||
|  |   } | ||||||
|  |   for (let i = 0; i < items.length; i++) { | ||||||
|  |     if (items[i].type.includes('image')) { | ||||||
|  |       const imageFile = items[i].getAsFile(); | ||||||
|  |       if (imageFile) { | ||||||
|  |         await handlePreview(imageFile); | ||||||
|  |         emit('fileUpload', imageFile); | ||||||
|  |       } | ||||||
|  |     } | ||||||
|  |   } | ||||||
|  |   return true; | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | async function handleUpload(files: FileList | null | undefined) { | ||||||
|  |   clearPreview(); | ||||||
|  | 
 | ||||||
|   if (_.isNil(files) || _.isEmpty(files)) { |   if (_.isNil(files) || _.isEmpty(files)) { | ||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| @ -49,6 +94,7 @@ function handleUpload(files: FileList | null | undefined) { | |||||||
|     return; |     return; | ||||||
|   } |   } | ||||||
| 
 | 
 | ||||||
|  |   await handlePreview(files[0]); | ||||||
|   emit('fileUpload', files[0]); |   emit('fileUpload', files[0]); | ||||||
| } | } | ||||||
| </script> | </script> | ||||||
| @ -60,6 +106,7 @@ function handleUpload(files: FileList | null | undefined) { | |||||||
|       'border-primary border-opacity-100': isOverDropZone, |       'border-primary border-opacity-100': isOverDropZone, | ||||||
|     }" |     }" | ||||||
|     @click="triggerFileInput" |     @click="triggerFileInput" | ||||||
|  |     @paste.prevent="onPasteImage" | ||||||
|     @drop.prevent="handleDrop" |     @drop.prevent="handleDrop" | ||||||
|     @dragover.prevent |     @dragover.prevent | ||||||
|     @dragenter="isOverDropZone = true" |     @dragenter="isOverDropZone = true" | ||||||
| @ -73,6 +120,7 @@ function handleUpload(files: FileList | null | undefined) { | |||||||
|       :accept="accept" |       :accept="accept" | ||||||
|       @change="handleFileInput" |       @change="handleFileInput" | ||||||
|     > |     > | ||||||
|  | 
 | ||||||
|     <slot> |     <slot> | ||||||
|       <span op-70> |       <span op-70> | ||||||
|         {{ title }} |         {{ title }} | ||||||
| @ -90,6 +138,22 @@ function handleUpload(files: FileList | null | undefined) { | |||||||
|       <c-button> |       <c-button> | ||||||
|         Browse files |         Browse files | ||||||
|       </c-button> |       </c-button> | ||||||
|  | 
 | ||||||
|  |       <div v-if="pasteImage"> | ||||||
|  |         <!-- separator --> | ||||||
|  |         <div my-4 w-full flex items-center justify-center op-70> | ||||||
|  |           <div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" /> | ||||||
|  |           <div class="mx-2 text-gray-400"> | ||||||
|  |             or | ||||||
|  |           </div> | ||||||
|  |           <div class="h-1px max-w-100px flex-1 bg-gray-300 op-50" /> | ||||||
|  |         </div> | ||||||
|  | 
 | ||||||
|  |         <p>Paste an image from clipboard</p> | ||||||
|  |       </div> | ||||||
|     </slot> |     </slot> | ||||||
|  |     <div mt-2> | ||||||
|  |       <img ref="imgPreview" width="150"> | ||||||
|  |     </div> | ||||||
|   </div> |   </div> | ||||||
| </template> | </template> | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user