diff --git a/.eslintrc-auto-import.json b/.eslintrc-auto-import.json index 4084d922..d4fd5aac 100644 --- a/.eslintrc-auto-import.json +++ b/.eslintrc-auto-import.json @@ -286,6 +286,9 @@ "watchTriggerable": true, "watchWithFilter": true, "whenever": true, - "toValue": true + "toValue": true, + "injectLocal": true, + "provideLocal": true, + "useClipboardItems": true } } diff --git a/auto-imports.d.ts b/auto-imports.d.ts index 186963f1..35bda113 100644 --- a/auto-imports.d.ts +++ b/auto-imports.d.ts @@ -36,6 +36,7 @@ declare global { const h: typeof import('vue')['h'] const ignorableWatch: typeof import('@vueuse/core')['ignorableWatch'] const inject: typeof import('vue')['inject'] + const injectLocal: typeof import('@vueuse/core')['injectLocal'] const isDefined: typeof import('@vueuse/core')['isDefined'] const isProxy: typeof import('vue')['isProxy'] const isReactive: typeof import('vue')['isReactive'] @@ -65,6 +66,7 @@ declare global { const onUpdated: typeof import('vue')['onUpdated'] const pausableWatch: typeof import('@vueuse/core')['pausableWatch'] const provide: typeof import('vue')['provide'] + const provideLocal: typeof import('@vueuse/core')['provideLocal'] const reactify: typeof import('@vueuse/core')['reactify'] const reactifyObject: typeof import('@vueuse/core')['reactifyObject'] const reactive: typeof import('vue')['reactive'] @@ -128,6 +130,7 @@ declare global { const useBrowserLocation: typeof import('@vueuse/core')['useBrowserLocation'] const useCached: typeof import('@vueuse/core')['useCached'] const useClipboard: typeof import('@vueuse/core')['useClipboard'] + const useClipboardItems: typeof import('@vueuse/core')['useClipboardItems'] const useCloned: typeof import('@vueuse/core')['useCloned'] const useColorMode: typeof import('@vueuse/core')['useColorMode'] const useConfirmDialog: typeof import('@vueuse/core')['useConfirmDialog'] @@ -326,6 +329,7 @@ declare module 'vue' { readonly h: UnwrapRef readonly ignorableWatch: UnwrapRef readonly inject: UnwrapRef + readonly injectLocal: UnwrapRef readonly isDefined: UnwrapRef readonly isProxy: UnwrapRef readonly isReactive: UnwrapRef @@ -355,6 +359,7 @@ declare module 'vue' { readonly onUpdated: UnwrapRef readonly pausableWatch: UnwrapRef readonly provide: UnwrapRef + readonly provideLocal: UnwrapRef readonly reactify: UnwrapRef readonly reactifyObject: UnwrapRef readonly reactive: UnwrapRef @@ -418,6 +423,7 @@ declare module 'vue' { readonly useBrowserLocation: UnwrapRef readonly useCached: UnwrapRef readonly useClipboard: UnwrapRef + readonly useClipboardItems: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef @@ -610,6 +616,7 @@ declare module '@vue/runtime-core' { readonly h: UnwrapRef readonly ignorableWatch: UnwrapRef readonly inject: UnwrapRef + readonly injectLocal: UnwrapRef readonly isDefined: UnwrapRef readonly isProxy: UnwrapRef readonly isReactive: UnwrapRef @@ -639,6 +646,7 @@ declare module '@vue/runtime-core' { readonly onUpdated: UnwrapRef readonly pausableWatch: UnwrapRef readonly provide: UnwrapRef + readonly provideLocal: UnwrapRef readonly reactify: UnwrapRef readonly reactifyObject: UnwrapRef readonly reactive: UnwrapRef @@ -702,6 +710,7 @@ declare module '@vue/runtime-core' { readonly useBrowserLocation: UnwrapRef readonly useCached: UnwrapRef readonly useClipboard: UnwrapRef + readonly useClipboardItems: UnwrapRef readonly useCloned: UnwrapRef readonly useColorMode: UnwrapRef readonly useConfirmDialog: UnwrapRef diff --git a/package.json b/package.json index 53e56a7e..54754c64 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ "@types/markdown-it": "^13.0.7", "@vicons/material": "^0.12.0", "@vicons/tabler": "^0.12.0", - "@vueuse/core": "^10.3.0", + "@vueuse/core": "^10.11.1", "@vueuse/head": "^1.0.0", "@vueuse/router": "^10.0.0", "@zxing/library": "^0.21.0", @@ -75,7 +75,7 @@ "iarna-toml-esm": "^3.0.5", "ibantools": "^4.3.3", "js-base64": "^3.7.7", - "jsbarcode": "^3.11.7", + "jsbarcode": "^3.11.6", "json5": "^2.2.3", "jwt-decode": "^3.1.2", "libphonenumber-js": "^1.10.28", @@ -95,6 +95,8 @@ "plausible-tracker": "^0.3.8", "qrcode": "^1.5.1", "randexp": "^0.5.3", + "regex": "^4.3.3", + "shiki": "^1.22.0", "sql-formatter": "^13.0.0", "sshpk": "^1.18.0", "ua-parser-js": "^1.0.35", diff --git a/src/composable/copy.ts b/src/composable/copy.ts index 5f853bac..265977e5 100644 --- a/src/composable/copy.ts +++ b/src/composable/copy.ts @@ -1,5 +1,5 @@ // eslint-disable-next-line no-restricted-imports -import { useClipboard } from '@vueuse/core'; +import { useClipboard, useClipboardItems } from '@vueuse/core'; import { useMessage } from 'naive-ui'; import type { MaybeRefOrGetter } from 'vue'; @@ -28,3 +28,34 @@ export function useCopy({ source, text = 'Copied to the clipboard', createToast }, }; } + +export function useCopyClipboardItems({ source, text = 'Copied to the clipboard', createToast = true }: { source?: MaybeRefOrGetter>; text?: string; createToast?: boolean } = {}) { + function toClipboardItem(item: { mime: string; content: string }) { + return new ClipboardItem({ + [item.mime]: new Blob([item.content], { type: item.mime }), + }); + } + const sourceClipboardItems = computed(() => (toValue(source) || []).map(toClipboardItem)); + const { copy, copied, ...rest } = useClipboardItems({ + source: sourceClipboardItems, + }); + + const message = useMessage(); + + return { + ...rest, + isJustCopied: copied, + async copy(content?: { mime: string; content: string }[], { notificationMessage }: { notificationMessage?: string } = {}) { + if (source) { + await copy(); + } + else { + await copy((content || []).map(toClipboardItem)); + } + + if (createToast) { + message.success(notificationMessage ?? text); + } + }, + }; +} diff --git a/src/tools/code-highlighter/code-highlighter.vue b/src/tools/code-highlighter/code-highlighter.vue new file mode 100644 index 00000000..02c33de8 --- /dev/null +++ b/src/tools/code-highlighter/code-highlighter.vue @@ -0,0 +1,133 @@ + + + + + diff --git a/src/tools/code-highlighter/index.ts b/src/tools/code-highlighter/index.ts new file mode 100644 index 00000000..60b45798 --- /dev/null +++ b/src/tools/code-highlighter/index.ts @@ -0,0 +1,12 @@ +import { Code } from '@vicons/tabler'; +import { defineTool } from '../tool'; + +export const tool = defineTool({ + name: 'Code/Scripts Highlighter', + path: '/code-highlighter', + description: 'Highlight programming code fragments', + keywords: ['code', 'highlighter'], + component: () => import('./code-highlighter.vue'), + icon: Code, + createdAt: new Date('2024-08-15'), +}); diff --git a/src/tools/index.ts b/src/tools/index.ts index 302cc055..56a46eec 100644 --- a/src/tools/index.ts +++ b/src/tools/index.ts @@ -3,6 +3,7 @@ import { tool as base64StringConverter } from './base64-string-converter'; import { tool as basicAuthGenerator } from './basic-auth-generator'; import { tool as emailNormalizer } from './email-normalizer'; import { tool as bounceParser } from './bounce-parser'; +import { tool as codeHighlighter } from './code-highlighter'; import { tool as asciiTextDrawer } from './ascii-text-drawer'; @@ -187,6 +188,7 @@ export const toolsByCategory: ToolCategory[] = [ xmlFormatter, yamlViewer, emailNormalizer, + codeHighlighter, regexTester, regexMemo, ], diff --git a/vite.config.ts b/vite.config.ts index 130e85ce..23bc1e10 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -114,6 +114,9 @@ export default defineConfig({ }, build: { target: 'esnext', + rollupOptions: { + external: ['regex'], + }, }, optimizeDeps: { include: ['re2-wasm-embedded'], // optionally specify dependency name