IT-TOOLS-PRO v1 - 定制版开发者工具站
12个原创工具(批量条码/二维码识别/在线翻译/OCR/面单设计/AI修图/网站收藏/PDF工具/图片工具/文档转换等) + 卡密授权系统(CardAuth对接,30分钟试用,换卡/撤销) + 体验优化(中文默认/收藏/最近使用/菜单展开/宽屏/品牌页脚)
This commit is contained in:
commit
01ff133ac9
528 files changed
+50026
No files matched your search
+52
@@ -0,0 +1,52 @@
|
||||
<script setup lang="ts">
|
||||
import { RouterView, useRoute } from 'vue-router';
|
||||
import { NGlobalStyle, NMessageProvider, NNotificationProvider, darkTheme } from 'naive-ui';
|
||||
import { darkThemeOverrides, lightThemeOverrides } from './themes';
|
||||
import { layouts } from './layouts';
|
||||
import { useStyleStore } from './stores/style.store';
|
||||
|
||||
const route = useRoute();
|
||||
const layout = computed(() => route?.meta?.layout ?? layouts.base);
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
const theme = computed(() => (styleStore.isDarkTheme ? darkTheme : null));
|
||||
const themeOverrides = computed(() => (styleStore.isDarkTheme ? darkThemeOverrides : lightThemeOverrides));
|
||||
|
||||
const { locale } = useI18n();
|
||||
|
||||
syncRef(
|
||||
locale,
|
||||
useStorage('locale', locale),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-config-provider :theme="theme" :theme-overrides="themeOverrides">
|
||||
<NGlobalStyle />
|
||||
<NMessageProvider placement="bottom">
|
||||
<NNotificationProvider placement="bottom-right">
|
||||
<component :is="layout">
|
||||
<RouterView />
|
||||
</component>
|
||||
</NNotificationProvider>
|
||||
</NMessageProvider>
|
||||
</n-config-provider>
|
||||
</template>
|
||||
|
||||
<style>
|
||||
body {
|
||||
min-height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
html {
|
||||
height: 100%;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
}
|
||||
|
||||
* {
|
||||
box-sizing: border-box;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,23 @@
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 300 275">
|
||||
<defs>
|
||||
<linearGradient id="small-hero-gradient-1" x1="13.74" y1="183.7" x2="303.96" y2="45.59" gradientUnits="userSpaceOnUse">
|
||||
<stop offset="0" stop-color="#25636c"/>
|
||||
<stop offset="0.6" stop-color="#3b956f"/>
|
||||
<stop offset="1" stop-color="#14a058"/>
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g>
|
||||
<g>
|
||||
<path fill="#14a058" opacity="0.49" d="M0,187.5v25s0,37.5,50,50S300,225,300,225V187.5Z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#14a058" opacity="0.49" d="M300,237.5S287.5,275,250,275,121.05,237.5,61.4,200s134.21,0,134.21,0Z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="#14a058" opacity="0.38" d="M0,200v12.5a241.47,241.47,0,0,0,112.5,50c73.6,11.69,130.61-14.86,150-25L300,200Z"/>
|
||||
</g>
|
||||
<g>
|
||||
<path fill="url(#small-hero-gradient-1)" d="M0,0V212.5s62.5-12.5,150,25,150,0,150,0V0Z"/>
|
||||
</g>
|
||||
</g>
|
||||
</svg>
|
||||
|
After Width: | Height: | Size: 894 B |
@@ -0,0 +1,165 @@
|
||||
<script setup lang="ts">
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { RouterLink, useRoute } from 'vue-router';
|
||||
import MenuIconItem from './MenuIconItem.vue';
|
||||
import type { Tool, ToolCategory } from '@/tools/tools.types';
|
||||
|
||||
const props = withDefaults(defineProps<{ toolsByCategory?: ToolCategory[] }>(), { toolsByCategory: () => [] });
|
||||
const { toolsByCategory } = toRefs(props);
|
||||
const route = useRoute();
|
||||
|
||||
const makeLabel = (tool: Tool) => () => h(RouterLink, { to: tool.path }, { default: () => tool.name });
|
||||
const makeIcon = (tool: Tool) => () => h(MenuIconItem, { tool });
|
||||
|
||||
const collapsedCategories = useStorage<Record<string, boolean>>(
|
||||
'menu-tool-option:collapsed-categories',
|
||||
{},
|
||||
undefined,
|
||||
{
|
||||
deep: true,
|
||||
serializer: {
|
||||
read: v => (v ? JSON.parse(v) : null),
|
||||
write: v => JSON.stringify(v),
|
||||
},
|
||||
},
|
||||
);
|
||||
|
||||
function toggleCategoryCollapse({ name }: { name: string }) {
|
||||
collapsedCategories.value[name] = !collapsedCategories.value[name];
|
||||
}
|
||||
|
||||
function expandAll() {
|
||||
const m: Record<string, boolean> = {};
|
||||
for (const { name } of toolsByCategory.value) {
|
||||
m[name] = false;
|
||||
}
|
||||
collapsedCategories.value = m;
|
||||
}
|
||||
|
||||
function collapseAll() {
|
||||
const m: Record<string, boolean> = {};
|
||||
for (const { name } of toolsByCategory.value) {
|
||||
m[name] = true;
|
||||
}
|
||||
collapsedCategories.value = m;
|
||||
}
|
||||
|
||||
const menuOptions = computed(() =>
|
||||
toolsByCategory.value.map(({ name, components }) => ({
|
||||
name,
|
||||
isCollapsed: collapsedCategories.value[name],
|
||||
tools: components.map(tool => ({
|
||||
label: makeLabel(tool),
|
||||
icon: makeIcon(tool),
|
||||
key: tool.path,
|
||||
})),
|
||||
})),
|
||||
);
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="menu-actions">
|
||||
<a href="javascript:;" class="menu-action" title="展开所有分类" @click="expandAll">⊕ 展开全部</a>
|
||||
<span class="menu-action-sep" />
|
||||
<a href="javascript:;" class="menu-action" title="收起所有分类" @click="collapseAll">⊖ 收起全部</a>
|
||||
</div>
|
||||
|
||||
<div v-for="{ name, tools, isCollapsed } of menuOptions" :key="name">
|
||||
<div ml-6px mt-12px flex cursor-pointer items-center op-60 @click="toggleCategoryCollapse({ name })">
|
||||
<span :class="{ 'rotate-0': isCollapsed, 'rotate-90': !isCollapsed }" text-16px lh-1 op-50 transition-transform>
|
||||
<icon-mdi-chevron-right />
|
||||
</span>
|
||||
|
||||
<span ml-8px text-13px>
|
||||
{{ name }}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<n-collapse-transition :show="!isCollapsed">
|
||||
<div class="menu-wrapper">
|
||||
<div class="toggle-bar" @click="toggleCategoryCollapse({ name })" />
|
||||
|
||||
<n-menu
|
||||
class="menu"
|
||||
:value="route.path"
|
||||
:collapsed-width="64"
|
||||
:collapsed-icon-size="22"
|
||||
:options="tools"
|
||||
:indent="8"
|
||||
:default-expand-all="true"
|
||||
/>
|
||||
</div>
|
||||
</n-collapse-transition>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.menu-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
padding: 2px 6px 0 6px;
|
||||
|
||||
.menu-action {
|
||||
font-size: 12px;
|
||||
color: inherit;
|
||||
opacity: 0.55;
|
||||
text-decoration: none;
|
||||
padding: 2px 4px;
|
||||
border-radius: 4px;
|
||||
transition: opacity 0.15s, color 0.15s;
|
||||
|
||||
&:hover {
|
||||
opacity: 1;
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-action-sep {
|
||||
width: 1px;
|
||||
height: 11px;
|
||||
background: currentColor;
|
||||
opacity: 0.2;
|
||||
}
|
||||
}
|
||||
|
||||
.menu-wrapper {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
.menu {
|
||||
flex: 1;
|
||||
margin-bottom: 5px;
|
||||
|
||||
::v-deep(.n-menu-item-content::before) {
|
||||
left: 0;
|
||||
right: 13px;
|
||||
}
|
||||
}
|
||||
|
||||
.toggle-bar {
|
||||
width: 24px;
|
||||
opacity: 0.1;
|
||||
transition: opacity ease 0.2s;
|
||||
position: relative;
|
||||
cursor: pointer;
|
||||
|
||||
&::before {
|
||||
width: 2px;
|
||||
height: 100%;
|
||||
content: ' ';
|
||||
background-color: v-bind('themeVars.textColor3');
|
||||
border-radius: 2px;
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 14px;
|
||||
}
|
||||
|
||||
&:hover {
|
||||
opacity: 0.5;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import type { Component } from 'vue';
|
||||
|
||||
const props = defineProps<{ icon: Component; title: string }>();
|
||||
const { icon, title } = toRefs(props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card class="colored-card">
|
||||
<n-icon class="icon" size="40" :component="icon" />
|
||||
<n-h3 class="title">
|
||||
<n-ellipsis>{{ title }}</n-ellipsis>
|
||||
</n-h3>
|
||||
|
||||
<div class="description">
|
||||
<n-ellipsis :line-clamp="2" :tooltip="false">
|
||||
<slot />
|
||||
</n-ellipsis>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.colored-card {
|
||||
background: rgb(37, 99, 108);
|
||||
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 60%, rgba(20, 160, 88, 1) 100%);
|
||||
color: #fff;
|
||||
border: none;
|
||||
|
||||
.icon {
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
.title {
|
||||
color: #fff;
|
||||
|
||||
margin: 5px 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
opacity: 0.8;
|
||||
|
||||
margin: 5px 0;
|
||||
|
||||
::v-deep(a) {
|
||||
color: inherit;
|
||||
text-decoration: underline;
|
||||
font-weight: bold;
|
||||
transition: color ease 0.2s;
|
||||
|
||||
&:hover {
|
||||
color: rgb(20, 20, 20);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,37 @@
|
||||
<script setup lang="ts">
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import type { Tool } from '@/tools/tools.types';
|
||||
|
||||
const props = defineProps<{ tool: Tool }>();
|
||||
|
||||
const toolStore = useToolStore();
|
||||
|
||||
const { tool } = toRefs(props);
|
||||
|
||||
const isFavorite = computed(() => toolStore.isToolFavorite({ tool }));
|
||||
const buttonType = computed(() => (isFavorite.value ? 'primary' : 'default'));
|
||||
|
||||
function toggleFavorite(event: MouseEvent) {
|
||||
event.preventDefault();
|
||||
|
||||
if (toolStore.isToolFavorite({ tool })) {
|
||||
toolStore.removeToolFromFavorites({ tool });
|
||||
return;
|
||||
}
|
||||
|
||||
toolStore.addToolToFavorites({ tool });
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-tooltip :tooltip="isFavorite ? $t('favoriteButton.remove') : $t('favoriteButton.add')">
|
||||
<c-button
|
||||
round
|
||||
:type="buttonType"
|
||||
:style="{ minWidth: '110px' }"
|
||||
@click="toggleFavorite"
|
||||
>
|
||||
<icon-mdi-heart mr-6px /> {{ isFavorite ? $t('favoriteButton.added') : $t('favoriteButton.add') }}
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</template>
|
||||
@@ -0,0 +1,57 @@
|
||||
<script setup lang="ts">
|
||||
import _ from 'lodash';
|
||||
import type { UseValidationRule } from '@/composable/validation';
|
||||
import CInputText from '@/ui/c-input-text/c-input-text.vue';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
transformer?: (v: string) => string
|
||||
inputValidationRules?: UseValidationRule<string>[]
|
||||
inputLabel?: string
|
||||
inputPlaceholder?: string
|
||||
inputDefault?: string
|
||||
outputLabel?: string
|
||||
outputLanguage?: string
|
||||
}>(),
|
||||
{
|
||||
transformer: _.identity,
|
||||
inputValidationRules: () => [],
|
||||
inputLabel: 'Input',
|
||||
inputDefault: '',
|
||||
inputPlaceholder: 'Input...',
|
||||
outputLabel: 'Output',
|
||||
outputLanguage: '',
|
||||
},
|
||||
);
|
||||
|
||||
const { transformer, inputValidationRules, inputLabel, outputLabel, outputLanguage, inputPlaceholder, inputDefault }
|
||||
= toRefs(props);
|
||||
|
||||
const inputElement = ref<typeof CInputText>();
|
||||
|
||||
const input = ref(inputDefault.value);
|
||||
const output = computed(() => transformer.value(input.value));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<CInputText
|
||||
ref="inputElement"
|
||||
v-model:value="input"
|
||||
:placeholder="inputPlaceholder"
|
||||
:label="inputLabel"
|
||||
rows="20"
|
||||
autosize
|
||||
raw-text
|
||||
multiline
|
||||
test-id="input"
|
||||
:validation-rules="inputValidationRules"
|
||||
monospace
|
||||
/>
|
||||
|
||||
<div overflow-auto>
|
||||
<div mb-5px>
|
||||
{{ outputLabel }}
|
||||
</div>
|
||||
<textarea-copyable :value="output" :language="outputLanguage" :follow-height-of="inputElement?.inputWrapperRef" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,23 @@
|
||||
<script setup lang="ts">
|
||||
import { useVModel } from '@vueuse/core';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const props = defineProps<{ value: string }>();
|
||||
const emit = defineEmits(['update:value']);
|
||||
|
||||
const value = useVModel(props, 'value', emit);
|
||||
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
|
||||
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : 'Copy to clipboard');
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-input-text v-model:value="value">
|
||||
<template #suffix>
|
||||
<c-tooltip :tooltip="tooltipText">
|
||||
<c-button circle variant="text" size="small" @click="copy()">
|
||||
<icon-mdi-content-copy />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</template>
|
||||
</c-input-text>
|
||||
</template>
|
||||
@@ -0,0 +1,35 @@
|
||||
<script setup lang="ts">
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import type { Tool } from '@/tools/tools.types';
|
||||
|
||||
const props = defineProps<{ tool: Tool }>();
|
||||
const { tool } = toRefs(props);
|
||||
|
||||
const theme = useThemeVars();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="menu-icon-item">
|
||||
<n-icon :component="tool.icon" />
|
||||
<div v-if="tool.isNew" class="badge" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.menu-icon-item {
|
||||
position: relative;
|
||||
|
||||
.badge {
|
||||
position: absolute;
|
||||
background-color: v-bind('theme.primaryColor');
|
||||
border-radius: 10px;
|
||||
line-height: 1;
|
||||
top: 3px;
|
||||
left: -6px;
|
||||
font-size: 10px;
|
||||
|
||||
height: 6px;
|
||||
width: 6px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,51 @@
|
||||
<script setup lang="ts">
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
const { isMenuCollapsed, isSmallScreen } = toRefs(styleStore);
|
||||
const siderPosition = computed(() => (isSmallScreen.value ? 'absolute' : 'static'));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-layout has-sider>
|
||||
<n-layout-sider
|
||||
bordered
|
||||
collapse-mode="width"
|
||||
:collapsed-width="0"
|
||||
:width="240"
|
||||
:collapsed="isMenuCollapsed"
|
||||
:show-trigger="false"
|
||||
:native-scrollbar="false"
|
||||
:position="siderPosition"
|
||||
>
|
||||
<slot name="sider" />
|
||||
</n-layout-sider>
|
||||
<n-layout class="content">
|
||||
<slot name="content" />
|
||||
<div v-show="isSmallScreen && !isMenuCollapsed" class="overlay" @click="isMenuCollapsed = true" />
|
||||
</n-layout>
|
||||
</n-layout>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.overlay {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
background-color: #00000080;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.content {
|
||||
// background-color: #f1f5f9;
|
||||
::v-deep(.n-layout-scroll-container) {
|
||||
padding: 26px;
|
||||
}
|
||||
}
|
||||
|
||||
.n-layout {
|
||||
height: 100vh;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,55 @@
|
||||
<script setup lang="ts">
|
||||
import { IconBrandGithub, IconBrandX, IconInfoCircle, IconMoon, IconSun } from '@tabler/icons-vue';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
const { isDarkTheme } = toRefs(styleStore);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-tooltip :tooltip="$t('home.nav.github')" position="bottom">
|
||||
<c-button
|
||||
circle
|
||||
variant="text"
|
||||
href="https://github.com/CorentinTh/it-tools"
|
||||
target="_blank"
|
||||
rel="noopener noreferrer"
|
||||
:aria-label="$t('home.nav.githubRepository')"
|
||||
>
|
||||
<n-icon size="25" :component="IconBrandGithub" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<c-tooltip :tooltip="$t('home.nav.twitterX')" position="bottom">
|
||||
<c-button
|
||||
circle
|
||||
variant="text"
|
||||
href="https://x.com/ittoolsdottech"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
:aria-label="$t('home.nav.twitterXAccount')"
|
||||
>
|
||||
<n-icon size="25" :component="IconBrandX" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<c-tooltip :tooltip="$t('home.nav.about')" position="bottom">
|
||||
<c-button circle variant="text" to="/about" :aria-label="$t('home.nav.aboutLabel')">
|
||||
<n-icon size="25" :component="IconInfoCircle" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
<c-tooltip :tooltip="isDarkTheme ? $t('home.nav.lightMode') : $t('home.nav.darkMode')" position="bottom">
|
||||
<c-button circle variant="text" :aria-label="$t('home.nav.mode')" @click="() => styleStore.toggleDark()">
|
||||
<n-icon v-if="isDarkTheme" size="25" :component="IconSun" />
|
||||
<n-icon v-else size="25" :component="IconMoon" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.n-button {
|
||||
&:not(:last-child) {
|
||||
margin-right: 5px;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,17 @@
|
||||
<script setup lang="ts">
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const props = withDefaults(defineProps<{ value?: string }>(), { value: '' });
|
||||
const { value } = toRefs(props);
|
||||
|
||||
const initialText = 'Copy to clipboard';
|
||||
|
||||
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
|
||||
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : initialText);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-tooltip :tooltip="tooltipText">
|
||||
<span cursor-pointer font-mono @click="copy()">{{ value }}</span>
|
||||
</c-tooltip>
|
||||
</template>
|
||||
@@ -0,0 +1,76 @@
|
||||
<script setup lang="ts">
|
||||
import { Copy } from '@vicons/tabler';
|
||||
import { useElementSize } from '@vueuse/core';
|
||||
import hljs from 'highlight.js/lib/core';
|
||||
import jsonHljs from 'highlight.js/lib/languages/json';
|
||||
import sqlHljs from 'highlight.js/lib/languages/sql';
|
||||
import xmlHljs from 'highlight.js/lib/languages/xml';
|
||||
import yamlHljs from 'highlight.js/lib/languages/yaml';
|
||||
import iniHljs from 'highlight.js/lib/languages/ini';
|
||||
import markdownHljs from 'highlight.js/lib/languages/markdown';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const props = withDefaults(
|
||||
defineProps<{
|
||||
value: string
|
||||
followHeightOf?: HTMLElement | null
|
||||
language?: string
|
||||
copyPlacement?: 'top-right' | 'bottom-right' | 'outside' | 'none'
|
||||
copyMessage?: string
|
||||
}>(),
|
||||
{
|
||||
followHeightOf: null,
|
||||
language: 'txt',
|
||||
copyPlacement: 'top-right',
|
||||
copyMessage: 'Copy to clipboard',
|
||||
},
|
||||
);
|
||||
hljs.registerLanguage('sql', sqlHljs);
|
||||
hljs.registerLanguage('json', jsonHljs);
|
||||
hljs.registerLanguage('html', xmlHljs);
|
||||
hljs.registerLanguage('xml', xmlHljs);
|
||||
hljs.registerLanguage('yaml', yamlHljs);
|
||||
hljs.registerLanguage('toml', iniHljs);
|
||||
hljs.registerLanguage('markdown', markdownHljs);
|
||||
|
||||
const { value, language, followHeightOf, copyPlacement, copyMessage } = toRefs(props);
|
||||
const { height } = followHeightOf.value ? useElementSize(followHeightOf) : { height: ref(null) };
|
||||
|
||||
const { copy, isJustCopied } = useCopy({ source: value, createToast: false });
|
||||
const tooltipText = computed(() => isJustCopied.value ? 'Copied!' : copyMessage.value);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="overflow-x: hidden; width: 100%">
|
||||
<c-card relative>
|
||||
<n-scrollbar
|
||||
x-scrollable
|
||||
trigger="none"
|
||||
:style="height ? `min-height: ${height - 40 /* card padding */ + 10 /* negative margin compensation */}px` : ''"
|
||||
>
|
||||
<n-config-provider :hljs="hljs">
|
||||
<n-code :code="value" :language="language" :trim="false" data-test-id="area-content" />
|
||||
</n-config-provider>
|
||||
</n-scrollbar>
|
||||
<div absolute right-10px top-10px>
|
||||
<c-tooltip v-if="value" :tooltip="tooltipText" position="left">
|
||||
<c-button circle important:h-10 important:w-10 @click="copy()">
|
||||
<n-icon size="22" :component="Copy" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</div>
|
||||
</c-card>
|
||||
<div v-if="copyPlacement === 'outside'" mt-4 flex justify-center>
|
||||
<c-button @click="copy()">
|
||||
{{ tooltipText }}
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-scrollbar) {
|
||||
padding-bottom: 10px;
|
||||
margin-bottom: -10px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,41 @@
|
||||
<script setup lang="ts">
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import FavoriteButton from './FavoriteButton.vue';
|
||||
import type { Tool } from '@/tools/tools.types';
|
||||
|
||||
const props = defineProps<{ tool: Tool & { category: string } }>();
|
||||
const { tool } = toRefs(props);
|
||||
const theme = useThemeVars();
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<router-link :to="tool.path" class="decoration-none">
|
||||
<c-card class="h-full transition transition-duration-0.5s !border-2px !hover:border-primary">
|
||||
<div flex items-center justify-between>
|
||||
<n-icon class="text-neutral-400 dark:text-neutral-600" size="40" :component="tool.icon" />
|
||||
|
||||
<div flex items-center gap-8px>
|
||||
<div
|
||||
v-if="tool.isNew"
|
||||
class="rounded-full px-8px py-3px text-xs text-white dark:text-neutral-800"
|
||||
:style="{
|
||||
'background-color': theme.primaryColor,
|
||||
}"
|
||||
>
|
||||
{{ $t('toolCard.new') }}
|
||||
</div>
|
||||
|
||||
<FavoriteButton :tool="tool" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="truncat my-5px text-lg text-black dark:text-white">
|
||||
{{ tool.name }}
|
||||
</div>
|
||||
|
||||
<div class="line-clamp-2 text-neutral-500 dark:text-neutral-400">
|
||||
{{ tool.description }}
|
||||
</div>
|
||||
</c-card>
|
||||
</router-link>
|
||||
</template>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { type Ref, ref, watchEffect } from 'vue';
|
||||
|
||||
export { computedCatch };
|
||||
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue }: { defaultValue: D; defaultErrorMessage?: string }): [Ref<T | D>, Ref<string | undefined>];
|
||||
function computedCatch<T, D>(getter: () => T, { defaultValue, defaultErrorMessage = 'Unknown error' }: { defaultValue?: D; defaultErrorMessage?: string } = {}) {
|
||||
const error = ref<string | undefined>();
|
||||
const value = ref<T | D | undefined>();
|
||||
|
||||
watchEffect(() => {
|
||||
try {
|
||||
error.value = undefined;
|
||||
value.value = getter();
|
||||
}
|
||||
catch (err) {
|
||||
error.value = err instanceof Error ? err.message : err?.toString() ?? defaultErrorMessage;
|
||||
value.value = defaultValue;
|
||||
}
|
||||
});
|
||||
|
||||
return [value, error] as const;
|
||||
}
|
||||
@@ -0,0 +1,47 @@
|
||||
import { computedAsync, watchThrottled } from '@vueuse/core';
|
||||
import { computed, ref, watch } from 'vue';
|
||||
|
||||
export { computedRefreshable, computedRefreshableAsync };
|
||||
|
||||
function computedRefreshable<T>(getter: () => T, { throttle }: { throttle?: number } = {}) {
|
||||
const dirty = ref(true);
|
||||
let value: T;
|
||||
|
||||
const update = () => (dirty.value = true);
|
||||
|
||||
if (throttle) {
|
||||
watchThrottled(getter, update, { throttle });
|
||||
}
|
||||
else {
|
||||
watch(getter, update);
|
||||
}
|
||||
|
||||
const computedValue = computed(() => {
|
||||
if (dirty.value) {
|
||||
value = getter();
|
||||
dirty.value = false;
|
||||
}
|
||||
return value;
|
||||
});
|
||||
|
||||
return [computedValue, update] as const;
|
||||
}
|
||||
|
||||
function computedRefreshableAsync<T>(getter: () => Promise<T>, defaultValue?: T) {
|
||||
const dirty = ref(true);
|
||||
let value: T;
|
||||
|
||||
const update = () => (dirty.value = true);
|
||||
|
||||
watch(getter, update);
|
||||
|
||||
const computedValue = computedAsync(async () => {
|
||||
if (dirty.value) {
|
||||
value = await getter();
|
||||
dirty.value = false;
|
||||
}
|
||||
return value;
|
||||
}, defaultValue);
|
||||
|
||||
return [computedValue, update] as const;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
// eslint-disable-next-line no-restricted-imports
|
||||
import { useClipboard } from '@vueuse/core';
|
||||
import { useMessage } from 'naive-ui';
|
||||
import type { MaybeRefOrGetter } from 'vue';
|
||||
|
||||
export function useCopy({ source, text = 'Copied to the clipboard', createToast = true }: { source?: MaybeRefOrGetter<string>; text?: string; createToast?: boolean } = {}) {
|
||||
const { copy, copied, ...rest } = useClipboard({
|
||||
source,
|
||||
legacy: true,
|
||||
});
|
||||
|
||||
const message = useMessage();
|
||||
|
||||
return {
|
||||
...rest,
|
||||
isJustCopied: copied,
|
||||
async copy(content?: string, { notificationMessage }: { notificationMessage?: string } = {}) {
|
||||
if (source) {
|
||||
await copy();
|
||||
}
|
||||
else {
|
||||
await copy(content);
|
||||
}
|
||||
|
||||
if (createToast) {
|
||||
message.success(notificationMessage ?? text);
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
function useDebouncedRef<T>(initialValue: T, delay: number, immediate: boolean = false) {
|
||||
const state = ref(initialValue);
|
||||
const debouncedRef = customRef((track, trigger) => ({
|
||||
get() {
|
||||
track();
|
||||
return state.value;
|
||||
},
|
||||
set: _.debounce(
|
||||
(value) => {
|
||||
state.value = value;
|
||||
trigger();
|
||||
},
|
||||
delay,
|
||||
{ leading: immediate },
|
||||
),
|
||||
}));
|
||||
return debouncedRef;
|
||||
}
|
||||
export default useDebouncedRef;
|
||||
@@ -0,0 +1,32 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { getMimeTypeFromBase64 } from './downloadBase64';
|
||||
|
||||
describe('downloadBase64', () => {
|
||||
describe('getMimeTypeFromBase64', () => {
|
||||
it('when the base64 string has a data URI, it returns the mime type', () => {
|
||||
expect(getMimeTypeFromBase64({ base64String: 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA' })).to.deep.equal({ mimeType: 'image/png' });
|
||||
expect(getMimeTypeFromBase64({ base64String: 'data:image/jpg;base64,iVBORw0KGgoAAAANSUhEUgAAAAUA' })).to.deep.equal({ mimeType: 'image/jpg' });
|
||||
});
|
||||
|
||||
it('when the base64 string has no data URI, it try to infer the mime type from the signature', () => {
|
||||
// https://en.wikipedia.org/wiki/List_of_file_signatures
|
||||
|
||||
// PNG
|
||||
expect(getMimeTypeFromBase64({ base64String: 'iVBORw0KGgoAAAANSUhEUgAAAAUA' })).to.deep.equal({ mimeType: 'image/png' });
|
||||
|
||||
// GIF
|
||||
expect(getMimeTypeFromBase64({ base64String: 'R0lGODdh' })).to.deep.equal({ mimeType: 'image/gif' });
|
||||
expect(getMimeTypeFromBase64({ base64String: 'R0lGODlh' })).to.deep.equal({ mimeType: 'image/gif' });
|
||||
|
||||
// JPG
|
||||
expect(getMimeTypeFromBase64({ base64String: '/9j/' })).to.deep.equal({ mimeType: 'image/jpg' });
|
||||
|
||||
// PDF
|
||||
expect(getMimeTypeFromBase64({ base64String: 'JVBERi0' })).to.deep.equal({ mimeType: 'application/pdf' });
|
||||
});
|
||||
|
||||
it('when the base64 string has no data URI and no signature, it returns an undefined mimeType', () => {
|
||||
expect(getMimeTypeFromBase64({ base64String: 'JVBERi' })).to.deep.equal({ mimeType: undefined });
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,118 @@
|
||||
import { extension as getExtensionFromMimeType, extension as getMimeTypeFromExtension } from 'mime-types';
|
||||
import type { Ref } from 'vue';
|
||||
import _ from 'lodash';
|
||||
|
||||
export {
|
||||
getMimeTypeFromBase64,
|
||||
getMimeTypeFromExtension, getExtensionFromMimeType,
|
||||
useDownloadFileFromBase64, useDownloadFileFromBase64Refs,
|
||||
previewImageFromBase64,
|
||||
};
|
||||
|
||||
const commonMimeTypesSignatures = {
|
||||
'JVBERi0': 'application/pdf',
|
||||
'R0lGODdh': 'image/gif',
|
||||
'R0lGODlh': 'image/gif',
|
||||
'iVBORw0KGgo': 'image/png',
|
||||
'/9j/': 'image/jpg',
|
||||
};
|
||||
|
||||
function getMimeTypeFromBase64({ base64String }: { base64String: string }) {
|
||||
const [,mimeTypeFromBase64] = base64String.match(/data:(.*?);base64/i) ?? [];
|
||||
|
||||
if (mimeTypeFromBase64) {
|
||||
return { mimeType: mimeTypeFromBase64 };
|
||||
}
|
||||
|
||||
const inferredMimeType = _.find(commonMimeTypesSignatures, (_mimeType, signature) => base64String.startsWith(signature));
|
||||
|
||||
if (inferredMimeType) {
|
||||
return { mimeType: inferredMimeType };
|
||||
}
|
||||
|
||||
return { mimeType: undefined };
|
||||
}
|
||||
|
||||
function getFileExtensionFromMimeType({
|
||||
mimeType,
|
||||
defaultExtension = 'txt',
|
||||
}: {
|
||||
mimeType: string | undefined
|
||||
defaultExtension?: string
|
||||
}) {
|
||||
if (mimeType) {
|
||||
return getExtensionFromMimeType(mimeType) ?? defaultExtension;
|
||||
}
|
||||
|
||||
return defaultExtension;
|
||||
}
|
||||
|
||||
function downloadFromBase64({ sourceValue, filename, extension, fileMimeType }:
|
||||
{ sourceValue: string; filename?: string; extension?: string; fileMimeType?: string }) {
|
||||
if (sourceValue === '') {
|
||||
throw new Error('Base64 string is empty');
|
||||
}
|
||||
|
||||
const defaultExtension = extension ?? 'txt';
|
||||
const { mimeType } = getMimeTypeFromBase64({ base64String: sourceValue });
|
||||
let base64String = sourceValue;
|
||||
if (!mimeType) {
|
||||
const targetMimeType = fileMimeType ?? getMimeTypeFromExtension(defaultExtension);
|
||||
base64String = `data:${targetMimeType};base64,${sourceValue}`;
|
||||
}
|
||||
|
||||
const cleanExtension = extension ?? getFileExtensionFromMimeType(
|
||||
{ mimeType, defaultExtension });
|
||||
let cleanFileName = filename ?? `file.${cleanExtension}`;
|
||||
if (extension && !cleanFileName.endsWith(`.${extension}`)) {
|
||||
cleanFileName = `${cleanFileName}.${cleanExtension}`;
|
||||
}
|
||||
|
||||
const a = document.createElement('a');
|
||||
a.href = base64String;
|
||||
a.download = cleanFileName;
|
||||
a.click();
|
||||
}
|
||||
|
||||
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: Ref<string>; filename?: Ref<string>; extension?: Ref<string> }) {
|
||||
return {
|
||||
download() {
|
||||
downloadFromBase64({ sourceValue: source.value, filename: filename?.value, extension: extension?.value });
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function previewImageFromBase64(base64String: string): HTMLImageElement {
|
||||
if (base64String === '') {
|
||||
throw new Error('Base64 string is empty');
|
||||
}
|
||||
|
||||
const img = document.createElement('img');
|
||||
img.src = base64String;
|
||||
|
||||
const container = document.createElement('div');
|
||||
container.appendChild(img);
|
||||
|
||||
const previewContainer = document.getElementById('previewContainer');
|
||||
if (previewContainer) {
|
||||
previewContainer.innerHTML = '';
|
||||
previewContainer.appendChild(container);
|
||||
}
|
||||
else {
|
||||
throw new Error('Preview container element not found');
|
||||
}
|
||||
|
||||
return img;
|
||||
}
|
||||
@@ -0,0 +1,30 @@
|
||||
import { type MaybeRef, get } from '@vueuse/core';
|
||||
import Fuse from 'fuse.js';
|
||||
import { computed } from 'vue';
|
||||
|
||||
export { useFuzzySearch };
|
||||
|
||||
function useFuzzySearch<Data>({
|
||||
search,
|
||||
data,
|
||||
options = {},
|
||||
}: {
|
||||
search: MaybeRef<string>
|
||||
data: Data[]
|
||||
options?: Fuse.IFuseOptions<Data> & { filterEmpty?: boolean }
|
||||
}) {
|
||||
const fuse = new Fuse(data, options);
|
||||
const filterEmpty = options.filterEmpty ?? true;
|
||||
|
||||
const searchResult = computed<Data[]>(() => {
|
||||
const query = get(search);
|
||||
|
||||
if (!filterEmpty && query === '') {
|
||||
return data;
|
||||
}
|
||||
|
||||
return fuse.search(query).map(({ item }) => item);
|
||||
});
|
||||
|
||||
return { searchResult };
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
import { useRouteQuery } from '@vueuse/router';
|
||||
import { computed } from 'vue';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
|
||||
export { useQueryParam, useQueryParamOrStorage };
|
||||
|
||||
const transformers = {
|
||||
number: {
|
||||
fromQuery: (value: string) => Number(value),
|
||||
toQuery: (value: number) => String(value),
|
||||
},
|
||||
string: {
|
||||
fromQuery: (value: string) => value,
|
||||
toQuery: (value: string) => value,
|
||||
},
|
||||
boolean: {
|
||||
fromQuery: (value: string) => value.toLowerCase() === 'true',
|
||||
toQuery: (value: boolean) => (value ? 'true' : 'false'),
|
||||
},
|
||||
object: {
|
||||
fromQuery: (value: string) => {
|
||||
return JSON.parse(value);
|
||||
},
|
||||
toQuery: (value: object) => JSON.stringify(value),
|
||||
},
|
||||
};
|
||||
|
||||
function useQueryParam<T>({ name, defaultValue }: { name: string; defaultValue: T }) {
|
||||
const type = typeof defaultValue;
|
||||
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
|
||||
|
||||
const proxy = useRouteQuery(name, transformer.toQuery(defaultValue as never));
|
||||
|
||||
return computed<T>({
|
||||
get() {
|
||||
return transformer.fromQuery(proxy.value) as unknown as T;
|
||||
},
|
||||
set(value) {
|
||||
proxy.value = transformer.toQuery(value as never);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function useQueryParamOrStorage<T>({ name, storageName, defaultValue }: { name: string; storageName: string; defaultValue: T }) {
|
||||
const type = typeof defaultValue;
|
||||
const transformer = transformers[type as keyof typeof transformers] ?? transformers.string;
|
||||
|
||||
const storageRef = useStorage(storageName, defaultValue);
|
||||
const proxyDefaultValue = transformer.toQuery(defaultValue as never);
|
||||
const proxy = useRouteQuery(name, proxyDefaultValue);
|
||||
|
||||
const r = ref(defaultValue);
|
||||
|
||||
watch(r,
|
||||
(value) => {
|
||||
proxy.value = transformer.toQuery(value as never);
|
||||
storageRef.value = value as never;
|
||||
},
|
||||
{ deep: true });
|
||||
|
||||
r.value = (proxy.value && proxy.value !== proxyDefaultValue
|
||||
? transformer.fromQuery(proxy.value) as unknown as T
|
||||
: storageRef.value as T) as never;
|
||||
|
||||
return r;
|
||||
}
|
||||
@@ -0,0 +1,43 @@
|
||||
import { ref } from 'vue';
|
||||
|
||||
export interface RecentTool {
|
||||
path: string;
|
||||
name: string;
|
||||
at: number;
|
||||
}
|
||||
|
||||
const LS_KEY = 'it-tools-recent-tools';
|
||||
const MAX = 20;
|
||||
|
||||
const recent = ref<RecentTool[]>(load());
|
||||
|
||||
function load(): RecentTool[] {
|
||||
try {
|
||||
const arr = JSON.parse(localStorage.getItem(LS_KEY) ?? '[]');
|
||||
return Array.isArray(arr) ? arr : [];
|
||||
}
|
||||
catch {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
function save() {
|
||||
try {
|
||||
localStorage.setItem(LS_KEY, JSON.stringify(recent.value.slice(0, MAX)));
|
||||
}
|
||||
catch { /* quota */ }
|
||||
}
|
||||
|
||||
/** record a tool visit (dedupes by path, newest first) */
|
||||
export function recordRecentTool(path: string, name: string) {
|
||||
if (!path || !name || path === '/') {
|
||||
return;
|
||||
}
|
||||
const rest = recent.value.filter(r => r.path !== path);
|
||||
recent.value = [{ path, name, at: Date.now() }, ...rest].slice(0, MAX);
|
||||
save();
|
||||
}
|
||||
|
||||
export function useRecentTools() {
|
||||
return { recentTools: recent };
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { isFalsyOrHasThrown } from './validation';
|
||||
|
||||
describe('useValidation', () => {
|
||||
describe('isFalsyOrHasThrown', () => {
|
||||
it('should return true if the callback return nil, false or throw', () => {
|
||||
expect(isFalsyOrHasThrown(() => false)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => null)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => undefined)).toBe(true);
|
||||
expect(isFalsyOrHasThrown(() => {})).toBe(true);
|
||||
expect(
|
||||
isFalsyOrHasThrown(() => {
|
||||
throw new Error('message');
|
||||
}),
|
||||
).toBe(true);
|
||||
});
|
||||
|
||||
it('should return true for any truthy values and empty string and 0 values', () => {
|
||||
expect(isFalsyOrHasThrown(() => true)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 'string')).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 1)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => 0)).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => '')).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => [])).toBe(false);
|
||||
expect(isFalsyOrHasThrown(() => ({}))).toBe(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,94 @@
|
||||
import { type MaybeRef, get } from '@vueuse/core';
|
||||
import _ from 'lodash';
|
||||
import { type Ref, reactive, watch } from 'vue';
|
||||
|
||||
type ValidatorReturnType = unknown;
|
||||
type GetErrorMessageReturnType = string;
|
||||
|
||||
export interface UseValidationRule<T> {
|
||||
validator: (value: T) => ValidatorReturnType
|
||||
getErrorMessage?: (value: T) => GetErrorMessageReturnType
|
||||
message: string
|
||||
}
|
||||
|
||||
export function isFalsyOrHasThrown(cb: () => ValidatorReturnType): boolean {
|
||||
try {
|
||||
const returnValue = cb();
|
||||
|
||||
if (_.isNil(returnValue)) {
|
||||
return true;
|
||||
}
|
||||
|
||||
return returnValue === false;
|
||||
}
|
||||
catch (_) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export function getErrorMessageOrThrown(cb: () => GetErrorMessageReturnType): string {
|
||||
try {
|
||||
return cb() || '';
|
||||
}
|
||||
catch (e: any) {
|
||||
return e.toString();
|
||||
}
|
||||
}
|
||||
|
||||
export interface ValidationAttrs {
|
||||
feedback: string
|
||||
validationStatus: string | undefined
|
||||
}
|
||||
|
||||
export function useValidation<T>({
|
||||
source,
|
||||
rules,
|
||||
watch: watchRefs = [],
|
||||
}: {
|
||||
source: Ref<T>
|
||||
rules: MaybeRef<UseValidationRule<T>[]>
|
||||
watch?: Ref<unknown>[]
|
||||
}) {
|
||||
const state = reactive<{
|
||||
message: string
|
||||
status: undefined | 'error'
|
||||
isValid: boolean
|
||||
attrs: ValidationAttrs
|
||||
}>({
|
||||
message: '',
|
||||
status: undefined,
|
||||
isValid: false,
|
||||
attrs: {
|
||||
validationStatus: undefined,
|
||||
feedback: '',
|
||||
},
|
||||
});
|
||||
|
||||
watch(
|
||||
[source, ...watchRefs],
|
||||
() => {
|
||||
state.message = '';
|
||||
state.status = undefined;
|
||||
|
||||
for (const rule of get(rules)) {
|
||||
if (isFalsyOrHasThrown(() => rule.validator(source.value))) {
|
||||
if (rule.getErrorMessage) {
|
||||
const getErrorMessage = rule.getErrorMessage;
|
||||
state.message = rule.message.replace('{0}', getErrorMessageOrThrown(() => getErrorMessage(source.value)));
|
||||
}
|
||||
else {
|
||||
state.message = rule.message;
|
||||
}
|
||||
state.status = 'error';
|
||||
}
|
||||
}
|
||||
|
||||
state.isValid = state.status !== 'error';
|
||||
state.attrs.feedback = state.message;
|
||||
state.attrs.validationStatus = state.status;
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
return state;
|
||||
}
|
||||
@@ -0,0 +1,75 @@
|
||||
import { figue } from 'figue';
|
||||
|
||||
export const config = figue({
|
||||
app: {
|
||||
version: {
|
||||
doc: 'Application current version',
|
||||
format: 'string',
|
||||
default: '0.0.0',
|
||||
env: 'PACKAGE_VERSION',
|
||||
},
|
||||
lastCommitSha: {
|
||||
doc: 'Application last commit SHA version',
|
||||
format: 'string',
|
||||
default: '',
|
||||
env: 'VITE_VERCEL_GIT_COMMIT_SHA',
|
||||
},
|
||||
baseUrl: {
|
||||
doc: 'Application base url',
|
||||
format: 'string',
|
||||
default: '/',
|
||||
env: 'BASE_URL',
|
||||
},
|
||||
env: {
|
||||
doc: 'Application current env',
|
||||
format: 'enum',
|
||||
values: ['production', 'development', 'preview', 'test'],
|
||||
default: 'development',
|
||||
env: 'VITE_VERCEL_ENV',
|
||||
},
|
||||
},
|
||||
plausible: {
|
||||
isTrackerEnabled: {
|
||||
doc: 'Is the tracker enabled',
|
||||
format: 'boolean',
|
||||
default: false,
|
||||
env: 'VITE_TRACKER_ENABLED',
|
||||
},
|
||||
domain: {
|
||||
doc: 'Plausible current domain',
|
||||
format: 'string',
|
||||
default: '',
|
||||
env: 'VITE_PLAUSIBLE_DOMAIN',
|
||||
},
|
||||
apiHost: {
|
||||
doc: 'Plausible remote api host',
|
||||
format: 'string',
|
||||
default: '',
|
||||
env: 'VITE_PLAUSIBLE_API_HOST',
|
||||
},
|
||||
trackLocalhost: {
|
||||
doc: 'Enable or disable localhost tracking by plausible',
|
||||
format: 'boolean',
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
showBanner: {
|
||||
doc: 'Show the banner',
|
||||
format: 'boolean',
|
||||
default: false,
|
||||
env: 'VITE_SHOW_BANNER',
|
||||
},
|
||||
showSponsorBanner: {
|
||||
doc: 'Show the sponsor banner',
|
||||
format: 'boolean',
|
||||
default: false,
|
||||
env: 'VITE_SHOW_SPONSOR_BANNER',
|
||||
},
|
||||
})
|
||||
.loadEnv({
|
||||
...import.meta.env,
|
||||
// Because the string 'import.meta.env.PACKAGE_VERSION' is statically replaced during build time (see 'define' in vite.config.ts)
|
||||
PACKAGE_VERSION: import.meta.env.PACKAGE_VERSION,
|
||||
})
|
||||
.validate()
|
||||
.getConfig();
|
||||
@@ -0,0 +1,199 @@
|
||||
<script lang="ts" setup>
|
||||
import { NIcon, useThemeVars } from 'naive-ui';
|
||||
|
||||
import { RouterLink } from 'vue-router';
|
||||
import { Heart, Home2, Key, Menu2 } from '@vicons/tabler';
|
||||
|
||||
import { storeToRefs } from 'pinia';
|
||||
import HeroGradient from '../assets/hero-gradient.svg?component';
|
||||
import MenuLayout from '../components/MenuLayout.vue';
|
||||
import NavbarButtons from '../components/NavbarButtons.vue';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
import { config } from '@/config';
|
||||
import type { ToolCategory } from '@/tools/tools.types';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import { useTracker } from '@/modules/tracker/tracker.services';
|
||||
import CollapsibleToolMenu from '@/components/CollapsibleToolMenu.vue';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
const styleStore = useStyleStore();
|
||||
const version = config.app.version;
|
||||
const commitSha = config.app.lastCommitSha.slice(0, 7);
|
||||
|
||||
const { tracker } = useTracker();
|
||||
const { t } = useI18n();
|
||||
|
||||
const toolStore = useToolStore();
|
||||
const { favoriteTools, toolsByCategory } = storeToRefs(toolStore);
|
||||
|
||||
const tools = computed<ToolCategory[]>(() => [
|
||||
...(favoriteTools.value.length > 0 ? [{ name: t('tools.categories.favorite-tools'), components: favoriteTools.value }] : []),
|
||||
...toolsByCategory.value,
|
||||
]);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<MenuLayout class="menu-layout" :class="{ isSmallScreen: styleStore.isSmallScreen }">
|
||||
<template #sider>
|
||||
<RouterLink to="/" class="hero-wrapper">
|
||||
<HeroGradient class="gradient" />
|
||||
<div class="text-wrapper">
|
||||
<div class="title">
|
||||
IT-TOOLS-PRO
|
||||
</div>
|
||||
<div class="divider" />
|
||||
<div class="subtitle">
|
||||
{{ $t('home.subtitle') }}
|
||||
</div>
|
||||
</div>
|
||||
</RouterLink>
|
||||
|
||||
<div class="sider-content">
|
||||
<div v-if="styleStore.isSmallScreen" flex flex-col items-center>
|
||||
<locale-selector w="90%" />
|
||||
|
||||
<div flex justify-center>
|
||||
<NavbarButtons />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<CollapsibleToolMenu :tools-by-category="tools" />
|
||||
|
||||
<div class="footer">
|
||||
<div>
|
||||
© {{ new Date().getFullYear() }} IT-TOOLS-PRO
|
||||
</div>
|
||||
<div>
|
||||
<c-link target="_blank" rel="noopener" href="https://nav.88531.cn">
|
||||
🚀 更多应用尽在 nav.88531.cn
|
||||
</c-link>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<template #content>
|
||||
<div flex items-center justify-center gap-2>
|
||||
<c-button
|
||||
circle
|
||||
variant="text"
|
||||
:aria-label="$t('home.toggleMenu')"
|
||||
@click="styleStore.isMenuCollapsed = !styleStore.isMenuCollapsed"
|
||||
>
|
||||
<NIcon size="25" :component="Menu2" />
|
||||
</c-button>
|
||||
|
||||
<c-tooltip :tooltip="$t('home.home')" position="bottom">
|
||||
<c-button to="/" circle variant="text" :aria-label="$t('home.home')">
|
||||
<NIcon size="25" :component="Home2" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<c-tooltip :tooltip="$t('home.uiLib')" position="bottom">
|
||||
<c-button v-if="config.app.env === 'development'" to="/c-lib" circle variant="text" :aria-label="$t('home.uiLib')">
|
||||
<icon-mdi:brush-variant text-20px />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
|
||||
<command-palette />
|
||||
|
||||
<locale-selector v-if="!styleStore.isSmallScreen" />
|
||||
|
||||
<div>
|
||||
<NavbarButtons v-if="!styleStore.isSmallScreen" />
|
||||
</div>
|
||||
|
||||
<c-tooltip position="bottom" :tooltip="'查看授权功能与购买'">
|
||||
<RouterLink to="/pricing" class="pricing-link">
|
||||
<c-button
|
||||
round
|
||||
class="support-button"
|
||||
:bordered="false"
|
||||
>
|
||||
授权应用
|
||||
<NIcon v-if="!styleStore.isSmallScreen" :component="Key" ml-2 />
|
||||
</c-button>
|
||||
</RouterLink>
|
||||
</c-tooltip>
|
||||
</div>
|
||||
<slot />
|
||||
</template>
|
||||
</MenuLayout>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
// ::v-deep(.n-layout-scroll-container) {
|
||||
// @percent: 4%;
|
||||
// @position: 25px;
|
||||
// @size: 50px;
|
||||
// @color: #eeeeee25;
|
||||
// background-image: radial-gradient(@color @percent, transparent @percent),
|
||||
// radial-gradient(@color @percent, transparent @percent);
|
||||
// background-position: 0 0, @position @position;
|
||||
// background-size: @size @size;
|
||||
// }
|
||||
|
||||
.support-button {
|
||||
background: rgb(37, 99, 108);
|
||||
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 60%, rgba(20, 160, 88, 1) 100%);
|
||||
color: #fff !important;
|
||||
transition: padding ease 0.2s !important;
|
||||
|
||||
&:hover {
|
||||
color: #fff;
|
||||
padding-left: 30px;
|
||||
padding-right: 30px;
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
text-align: center;
|
||||
color: #838587;
|
||||
margin-top: 20px;
|
||||
padding: 20px 0;
|
||||
}
|
||||
|
||||
.sider-content {
|
||||
padding-top: 160px;
|
||||
padding-bottom: 200px;
|
||||
}
|
||||
|
||||
.hero-wrapper {
|
||||
position: absolute;
|
||||
display: block;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
z-index: 10;
|
||||
overflow: hidden;
|
||||
|
||||
.gradient {
|
||||
margin-top: -65px;
|
||||
}
|
||||
|
||||
.text-wrapper {
|
||||
position: absolute;
|
||||
left: 0;
|
||||
width: 100%;
|
||||
text-align: center;
|
||||
top: 16px;
|
||||
color: #fff;
|
||||
|
||||
.title {
|
||||
font-size: 25px;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
.divider {
|
||||
width: 50px;
|
||||
height: 2px;
|
||||
border-radius: 4px;
|
||||
background-color: v-bind('themeVars.primaryColor');
|
||||
margin: 0 auto 5px;
|
||||
}
|
||||
|
||||
.subtitle {
|
||||
font-size: 16px;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,7 @@
|
||||
import BaseLayout from './base.layout.vue';
|
||||
import ToolLayout from './tool.layout.vue';
|
||||
|
||||
export const layouts = {
|
||||
base: BaseLayout,
|
||||
toolLayout: ToolLayout,
|
||||
};
|
||||
@@ -0,0 +1,156 @@
|
||||
<script lang="ts" setup>
|
||||
import { useRoute } from 'vue-router';
|
||||
import { recordRecentTool } from '@/composable/recent-tools';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import type { HeadObject } from '@vueuse/head';
|
||||
|
||||
import BaseLayout from './base.layout.vue';
|
||||
import FavoriteButton from '@/components/FavoriteButton.vue';
|
||||
import LicenseGate from '@/tools/license/LicenseGate.vue';
|
||||
import type { Tool } from '@/tools/tools.types';
|
||||
|
||||
const route = useRoute();
|
||||
|
||||
// record into "recent tools" (shown on home page)
|
||||
watch(
|
||||
() => route.path,
|
||||
(path) => {
|
||||
const name = String(route.meta.name ?? '');
|
||||
if (path && name) {
|
||||
recordRecentTool(path, name);
|
||||
}
|
||||
},
|
||||
{ immediate: true },
|
||||
);
|
||||
|
||||
const head = computed<HeadObject>(() => ({
|
||||
title: `${route.meta.name} - IT-TOOLS-PRO`,
|
||||
meta: [
|
||||
{
|
||||
name: 'description',
|
||||
content: route.meta?.description as string,
|
||||
},
|
||||
{
|
||||
name: 'keywords',
|
||||
content: ((route.meta.keywords ?? []) as string[]).join(','),
|
||||
},
|
||||
],
|
||||
}));
|
||||
useHead(head);
|
||||
const { t } = useI18n();
|
||||
|
||||
// 宽屏工具:不受 600px 限宽,占满可用宽度(画布/多栏类工具)
|
||||
const WIDE_TOOLS = new Set(['/label-designer', '/json-prettify', '/pdf-tools', '/image-tools', '/doc-convert']);
|
||||
const isWide = computed(() => WIDE_TOOLS.has(route.path));
|
||||
|
||||
const i18nKey = computed<string>(() => route.path.trim().replace('/', ''));
|
||||
const toolTitle = computed<string>(() => t(`tools.${i18nKey.value}.title`, String(route.meta.name)));
|
||||
const toolDescription = computed<string>(() => t(`tools.${i18nKey.value}.description`, String(route.meta.description)));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<BaseLayout>
|
||||
<div class="tool-layout" :class="{ wide: isWide }">
|
||||
<div class="tool-header">
|
||||
<div flex flex-nowrap items-center justify-between>
|
||||
<n-h1>
|
||||
{{ toolTitle }}
|
||||
</n-h1>
|
||||
|
||||
<div>
|
||||
<FavoriteButton :tool="{ name: route.meta.name, path: route.path } as Tool" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="separator" />
|
||||
|
||||
<div class="description">
|
||||
{{ toolDescription }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="tool-content" :class="{ wide: isWide }">
|
||||
<slot />
|
||||
</div>
|
||||
|
||||
<!-- 授权门:受控功能显示试用倒计时,到期锁定 -->
|
||||
<LicenseGate :path="route.path" />
|
||||
</BaseLayout>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.tool-content {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
justify-content: center;
|
||||
align-items: flex-start;
|
||||
flex-wrap: wrap;
|
||||
gap: 16px;
|
||||
|
||||
::v-deep(& > *) {
|
||||
flex: 0 1 600px;
|
||||
}
|
||||
|
||||
&.wide {
|
||||
::v-deep(& > *) {
|
||||
flex: 1 1 100%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tool-layout {
|
||||
max-width: 600px;
|
||||
margin: 0 auto;
|
||||
box-sizing: border-box;
|
||||
|
||||
&.wide {
|
||||
max-width: none;
|
||||
width: 100%;
|
||||
padding: 0 20px;
|
||||
|
||||
.tool-header {
|
||||
max-width: 1280px;
|
||||
margin: 0 auto;
|
||||
padding: 10px 0 6px;
|
||||
|
||||
.n-h1 {
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
.description {
|
||||
font-size: 12.5px;
|
||||
margin-top: 2px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.tool-header {
|
||||
padding: 40px 0;
|
||||
width: 100%;
|
||||
|
||||
.n-h1 {
|
||||
opacity: 0.9;
|
||||
font-size: 40px;
|
||||
font-weight: 400;
|
||||
margin: 0;
|
||||
line-height: 1;
|
||||
}
|
||||
|
||||
.separator {
|
||||
width: 200px;
|
||||
height: 2px;
|
||||
background: rgb(161, 161, 161);
|
||||
opacity: 0.2;
|
||||
|
||||
margin: 10px 0;
|
||||
}
|
||||
|
||||
.description {
|
||||
margin: 0;
|
||||
|
||||
opacity: 0.7;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
+29
@@ -0,0 +1,29 @@
|
||||
import { createApp } from 'vue';
|
||||
import { createPinia } from 'pinia';
|
||||
import { createHead } from '@vueuse/head';
|
||||
|
||||
import { registerSW } from 'virtual:pwa-register';
|
||||
import shadow from 'vue-shadow-dom';
|
||||
import { plausible } from './plugins/plausible.plugin';
|
||||
|
||||
import 'virtual:uno.css';
|
||||
|
||||
import { naive } from './plugins/naive.plugin';
|
||||
|
||||
import App from './App.vue';
|
||||
import router from './router';
|
||||
import { i18nPlugin } from './plugins/i18n.plugin';
|
||||
|
||||
registerSW();
|
||||
|
||||
const app = createApp(App);
|
||||
|
||||
app.use(createPinia());
|
||||
app.use(createHead());
|
||||
app.use(i18nPlugin);
|
||||
app.use(router);
|
||||
app.use(naive);
|
||||
app.use(plausible);
|
||||
app.use(shadow);
|
||||
|
||||
app.mount('#app');
|
||||
@@ -0,0 +1,91 @@
|
||||
import { defineStore } from 'pinia';
|
||||
import _ from 'lodash';
|
||||
import type { PaletteOption } from './command-palette.types';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import { useFuzzySearch } from '@/composable/fuzzySearch';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
import SunIcon from '~icons/mdi/white-balance-sunny';
|
||||
import GithubIcon from '~icons/mdi/github';
|
||||
import BugIcon from '~icons/mdi/bug-outline';
|
||||
import DiceIcon from '~icons/mdi/dice-5';
|
||||
import InfoIcon from '~icons/mdi/information-outline';
|
||||
|
||||
export const useCommandPaletteStore = defineStore('command-palette', () => {
|
||||
const toolStore = useToolStore();
|
||||
const styleStore = useStyleStore();
|
||||
const router = useRouter();
|
||||
const searchPrompt = ref('');
|
||||
|
||||
const toolsOptions = toolStore.tools.map(tool => ({
|
||||
...tool,
|
||||
to: tool.path,
|
||||
toolCategory: tool.category,
|
||||
category: 'Tools',
|
||||
}));
|
||||
|
||||
const searchOptions: PaletteOption[] = [
|
||||
...toolsOptions,
|
||||
{
|
||||
name: 'Random tool',
|
||||
description: 'Get a random tool from the list.',
|
||||
action: () => {
|
||||
const { path } = _.sample(toolStore.tools)!;
|
||||
router.push(path);
|
||||
},
|
||||
icon: DiceIcon,
|
||||
category: 'Tools',
|
||||
keywords: ['random', 'tool', 'pick', 'choose', 'select'],
|
||||
closeOnSelect: true,
|
||||
},
|
||||
{
|
||||
name: 'Toggle dark mode',
|
||||
description: 'Toggle dark mode on or off.',
|
||||
action: () => styleStore.toggleDark(),
|
||||
icon: SunIcon,
|
||||
category: 'Actions',
|
||||
keywords: ['dark', 'theme', 'toggle', 'mode', 'light', 'system'],
|
||||
},
|
||||
{
|
||||
name: 'Github repository',
|
||||
href: 'https://github.com/CorentinTh/it-tools',
|
||||
category: 'External',
|
||||
description: 'View the source code of it-tools on Github.',
|
||||
keywords: ['github', 'repo', 'repository', 'source', 'code'],
|
||||
icon: GithubIcon,
|
||||
},
|
||||
{
|
||||
name: 'Report a bug or an issue',
|
||||
description: 'Report a bug or an issue to help improve it-tools.',
|
||||
href: 'https://github.com/CorentinTh/it-tools/issues/new/choose',
|
||||
category: 'Actions',
|
||||
keywords: ['report', 'issue', 'bug', 'problem', 'error'],
|
||||
icon: BugIcon,
|
||||
},
|
||||
{
|
||||
name: 'About',
|
||||
description: 'Learn more about IT-Tools.',
|
||||
to: '/about',
|
||||
category: 'Pages',
|
||||
keywords: ['about', 'learn', 'more', 'info', 'information'],
|
||||
icon: InfoIcon,
|
||||
},
|
||||
];
|
||||
|
||||
const { searchResult } = useFuzzySearch({
|
||||
search: searchPrompt,
|
||||
data: searchOptions,
|
||||
options: {
|
||||
keys: [{ name: 'name', weight: 2 }, 'description', 'keywords', 'category'],
|
||||
threshold: 0.3,
|
||||
},
|
||||
});
|
||||
|
||||
const filteredSearchResult = computed(() =>
|
||||
_.chain(searchResult.value).groupBy('category').mapValues(categoryOptions => _.take(categoryOptions, 5)).value());
|
||||
|
||||
return {
|
||||
filteredSearchResult,
|
||||
searchPrompt,
|
||||
};
|
||||
});
|
||||
@@ -0,0 +1,14 @@
|
||||
import type { Component } from 'vue';
|
||||
import type { RouteLocationRaw } from 'vue-router';
|
||||
|
||||
export interface PaletteOption {
|
||||
name: string
|
||||
description?: string
|
||||
icon?: Component
|
||||
action?: () => void
|
||||
to?: RouteLocationRaw
|
||||
category: string
|
||||
keywords?: string[]
|
||||
href?: string
|
||||
closeOnSelect?: boolean
|
||||
}
|
||||
@@ -0,0 +1,154 @@
|
||||
<script setup lang="ts">
|
||||
import { storeToRefs } from 'pinia';
|
||||
import _ from 'lodash';
|
||||
import { useCommandPaletteStore } from './command-palette.store';
|
||||
import type { PaletteOption } from './command-palette.types';
|
||||
|
||||
const isModalOpen = ref(false);
|
||||
const inputRef = ref();
|
||||
const router = useRouter();
|
||||
const isMac = computed(() => window.navigator.userAgent.toLowerCase().includes('mac'));
|
||||
|
||||
const commandPaletteStore = useCommandPaletteStore();
|
||||
const { searchPrompt, filteredSearchResult } = storeToRefs(commandPaletteStore);
|
||||
|
||||
const keys = useMagicKeys({
|
||||
passive: false,
|
||||
onEventFired(e) {
|
||||
if (e.ctrlKey && e.key === 'k' && e.type === 'keydown') {
|
||||
e.preventDefault();
|
||||
}
|
||||
|
||||
if (e.metaKey && e.key === 'k' && e.type === 'keydown') {
|
||||
e.preventDefault();
|
||||
}
|
||||
},
|
||||
});
|
||||
|
||||
whenever(isModalOpen, () => inputRef.value?.focus());
|
||||
|
||||
whenever(keys.ctrl_k, open);
|
||||
whenever(keys.meta_k, open);
|
||||
whenever(keys.escape, close);
|
||||
|
||||
function open() {
|
||||
return isModalOpen.value = true;
|
||||
}
|
||||
|
||||
function close() {
|
||||
isModalOpen.value = false;
|
||||
searchPrompt.value = '';
|
||||
}
|
||||
|
||||
const selectedOptionIndex = ref(0);
|
||||
|
||||
function handleKeydown(event: KeyboardEvent) {
|
||||
const { key } = event;
|
||||
const isEnterPressed = key === 'Enter';
|
||||
const isArrowUpOrDown = ['ArrowUp', 'ArrowDown'].includes(key);
|
||||
const isArrowDown = key === 'ArrowDown';
|
||||
|
||||
if (isArrowUpOrDown) {
|
||||
const increment = isArrowDown ? 1 : -1;
|
||||
const maxIndex = Math.max(_.chain(filteredSearchResult.value).values().flatten().size().value() - 1, 0);
|
||||
|
||||
selectedOptionIndex.value = Math.min(Math.max(selectedOptionIndex.value + increment, 0), maxIndex);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (isEnterPressed) {
|
||||
const option = _.chain(filteredSearchResult.value)
|
||||
.values()
|
||||
.flatten()
|
||||
.nth(selectedOptionIndex.value)
|
||||
.value();
|
||||
|
||||
activateOption(option);
|
||||
}
|
||||
}
|
||||
|
||||
function getOptionIndex(option: PaletteOption) {
|
||||
return _.chain(filteredSearchResult.value)
|
||||
.values()
|
||||
.flatten()
|
||||
.findIndex(o => o === option)
|
||||
.value();
|
||||
}
|
||||
|
||||
function activateOption(option: PaletteOption) {
|
||||
const { closeOnSelect } = option;
|
||||
|
||||
if (option.action) {
|
||||
option.action();
|
||||
|
||||
if (closeOnSelect) {
|
||||
close();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
const closeAfterNavigation = closeOnSelect || _.isUndefined(closeOnSelect);
|
||||
|
||||
if (option.to) {
|
||||
router.push(option.to);
|
||||
|
||||
if (closeAfterNavigation) {
|
||||
close();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
if (option.href) {
|
||||
window.open(option.href, '_blank');
|
||||
|
||||
if (closeAfterNavigation) {
|
||||
close();
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div flex-1>
|
||||
<c-button w-full important:justify-start @click="isModalOpen = true">
|
||||
<span flex items-center gap-3 op-40>
|
||||
|
||||
<icon-mdi-search />
|
||||
{{ $t('search.label') }}
|
||||
|
||||
<span hidden flex-1 border border-current border-op-40 rounded border-solid px-5px py-3px sm:inline>
|
||||
{{ isMac ? 'Cmd' : 'Ctrl' }} + K
|
||||
</span>
|
||||
</span>
|
||||
</c-button>
|
||||
|
||||
<c-modal v-model:open="isModalOpen" class="palette-modal" shadow-xl important:max-w-650px important:pa-12px @keydown="handleKeydown">
|
||||
<c-input-text ref="inputRef" v-model:value="searchPrompt" raw-text placeholder="Type to search a tool or a command..." autofocus clearable />
|
||||
|
||||
<div v-for="(options, category) in filteredSearchResult" :key="category">
|
||||
<div ml-3 mt-3 text-sm font-bold text-primary op-60>
|
||||
{{ category }}
|
||||
</div>
|
||||
<command-palette-option v-for="option in options" :key="option.name" :option="option" :selected="selectedOptionIndex === getOptionIndex(option)" @activated="activateOption" />
|
||||
</div>
|
||||
</c-modal>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.c-input-text {
|
||||
font-size: 18px;
|
||||
|
||||
::v-deep(.input-wrapper) {
|
||||
padding: 4px;
|
||||
padding-left: 18px;
|
||||
}
|
||||
}
|
||||
|
||||
.c-modal--overlay {
|
||||
align-items: flex-start !important;
|
||||
padding-top: 80px;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,36 @@
|
||||
<script setup lang="ts">
|
||||
import type { PaletteOption } from '../command-palette.types';
|
||||
|
||||
const props = withDefaults(defineProps<{ option: PaletteOption; selected?: boolean }>(), {
|
||||
selected: false,
|
||||
});
|
||||
const emit = defineEmits(['activated']);
|
||||
const { option } = toRefs(props);
|
||||
|
||||
const { selected } = toRefs(props);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div
|
||||
role="option"
|
||||
:aria-selected="selected"
|
||||
:class="{
|
||||
'text-white': selected,
|
||||
'bg-primary': selected,
|
||||
}"
|
||||
w-full flex cursor-pointer items-center overflow-hidden rounded pa-3 transition hover:bg-primary hover:text-white
|
||||
@click="() => emit('activated', option)"
|
||||
>
|
||||
<component :is="option.icon" v-if="option.icon" mr-3 h-30px w-30px shrink-0 op-50 />
|
||||
|
||||
<div flex-1 overflow-hidden>
|
||||
<div truncate font-bold lh-tight op-90>
|
||||
{{ option.name }}
|
||||
</div>
|
||||
|
||||
<div v-if="option.description" truncate lh-tight op-60>
|
||||
{{ option.description }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,32 @@
|
||||
<script setup lang="ts">
|
||||
const { availableLocales, locale } = useI18n();
|
||||
|
||||
const localesLong: Record<string, string> = {
|
||||
en: 'English',
|
||||
de: 'Deutsch',
|
||||
es: 'Español',
|
||||
fr: 'Français',
|
||||
no: 'Norwegian',
|
||||
pt: 'Português',
|
||||
ru: 'Русский',
|
||||
uk: 'Українська',
|
||||
zh: '中文',
|
||||
vi: 'Tiếng Việt',
|
||||
};
|
||||
|
||||
const localeOptions = computed(() =>
|
||||
availableLocales.map(locale => ({
|
||||
label: localesLong[locale] ?? locale,
|
||||
value: locale,
|
||||
})),
|
||||
);
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-select
|
||||
v-model:value="locale"
|
||||
:options="localeOptions"
|
||||
placeholder="Select a language"
|
||||
w-100px
|
||||
/>
|
||||
</template>
|
||||
@@ -0,0 +1,7 @@
|
||||
import { format } from 'date-fns';
|
||||
|
||||
export { getUrlFriendlyDateTime };
|
||||
|
||||
function getUrlFriendlyDateTime({ date = new Date() }: { date?: Date } = {}) {
|
||||
return format(date, 'yyyy-MM-dd-HH-mm-ss');
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
function clamp({ value, min = 0, max = 100 }: { value: number; min?: number; max?: number }) {
|
||||
return Math.min(Math.max(value, min), max);
|
||||
}
|
||||
|
||||
export { clamp };
|
||||
@@ -0,0 +1,27 @@
|
||||
import _ from 'lodash';
|
||||
import type Plausible from 'plausible-tracker';
|
||||
import { inject } from 'vue';
|
||||
|
||||
export { createTrackerService, useTracker };
|
||||
|
||||
function createTrackerService({ plausible }: { plausible: ReturnType<typeof Plausible> }) {
|
||||
return {
|
||||
trackEvent({ eventName }: { eventName: string }) {
|
||||
plausible.trackEvent(eventName);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
function useTracker() {
|
||||
const plausible: ReturnType<typeof Plausible> | undefined = inject('plausible');
|
||||
|
||||
if (_.isNil(plausible)) {
|
||||
throw new TypeError('Plausible must be instantiated');
|
||||
}
|
||||
|
||||
const tracker = createTrackerService({ plausible });
|
||||
|
||||
return {
|
||||
tracker,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
import type { createTrackerService } from './tracker.services';
|
||||
|
||||
export type TrackerService = ReturnType<typeof createTrackerService>;
|
||||
@@ -0,0 +1,27 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
|
||||
useHead({ title: 'Page not found - IT-TOOLS-PRO' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div mt-20 flex flex-col items-center>
|
||||
<span text-90px lh-1 op-50>
|
||||
<icon-mdi:kettle-steam-outline />
|
||||
</span>
|
||||
|
||||
<h1 m-0 mt-3>
|
||||
{{ $t('404.notFound') }}
|
||||
</h1>
|
||||
<div mt-4 op-60>
|
||||
{{ $t('404.sorry') }}
|
||||
</div>
|
||||
<div mb-8 op-60>
|
||||
{{ $t('404.maybe') }}
|
||||
</div>
|
||||
|
||||
<c-button to="/">
|
||||
{{ $t('404.backHome') }}
|
||||
</c-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,229 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
|
||||
useHead({ title: '新功能介绍 - IT-TOOLS-PRO' });
|
||||
|
||||
interface Item {
|
||||
name: string;
|
||||
icon: string;
|
||||
desc: string;
|
||||
tag: string;
|
||||
}
|
||||
|
||||
const groups: { title: string; items: Item[] }[] = [
|
||||
{
|
||||
title: '原创工具',
|
||||
items: [
|
||||
{ name: '批量条码生成', icon: '条', desc: 'EAN/UPC/Code128/Code39/DataMatrix 等 12 种码制,批量生成、打包下载,尺寸颜色字号可调', tag: '全新' },
|
||||
{ name: '二维码条码识别', icon: '扫', desc: '上传/拖拽/粘贴图片一键识别,支持多码混合批量输出,本地 WASM 解码,图片不上传', tag: '全新' },
|
||||
{ name: '在线翻译', icon: '译', desc: '中英日韩等 16 种语言互译,谷歌主线 + MyMemory 备用双线路,自动识别源语言', tag: '全新' },
|
||||
{ name: '图片OCR / PDF文字识别', icon: '识', desc: '本地 OCR 引擎,截图扫描件文字提取(准确率 99%+);PDF 逐页识别、预览、导出 TXT', tag: '全新' },
|
||||
{ name: '面单设计', icon: '单', desc: '快递面单模板开箱即用,支持上传 PDF 面单二次编辑(遮盖改字),300dpi 高清导出', tag: '全新' },
|
||||
{ name: 'AI修图', icon: 'AI', desc: '去水印/修复(涂抹智能填充)、抠图去背景、4x 超分辨率、人脸修复,本地 AI 模型 10 秒级出图', tag: '全新' },
|
||||
{ name: 'IT网站收藏', icon: '藏', desc: '内置 91 个精选开发站点(社区/文档/工具/AI/设计/视频/媒体平台),数据存用户本地,可自选目录', tag: '全新' },
|
||||
{ name: '文档格式转换', icon: '转', desc: 'Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九格式互转,自建 calibre 引擎,批量打包下载', tag: '全新' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '深度改造',
|
||||
items: [
|
||||
{ name: 'JSON 美化和格式化', icon: 'J', desc: '双栏专业工作台:左侧行号编辑,右侧树视图/语法高亮切换,含 Dict/Get参数/XML/CSV 等 7 种转换', tag: '改造' },
|
||||
{ name: 'PDF工具', icon: 'P', desc: '合并/拆分/旋转/重排/压缩/加密/解密/水印/提取文本/页码/转图片,11 功能全程浏览器本地处理', tag: '全新' },
|
||||
{ name: '图片工具', icon: '图', desc: '压缩/转换/尺寸/裁剪/旋转/滤镜/打码/EXIF/二维码生成识别/水印/拼接,12 功能本地处理', tag: '全新' },
|
||||
],
|
||||
},
|
||||
{
|
||||
title: '授权与体验',
|
||||
items: [
|
||||
{ name: '卡密授权系统', icon: '锁', desc: '对接自建 CardAuth:高级功能 30 分钟免费试用,卡密激活全站通用,支持换卡密/自助撤销', tag: '全新' },
|
||||
{ name: '授权介绍页', icon: '介', desc: '右上角「授权应用」直达:功能清单、购买优势、一键购买与机器码复制', tag: '全新' },
|
||||
{ name: '生成记录', icon: '记', desc: '翻译/OCR/修图/转换等 9 个工具自动留痕,支持复制、删除、清空,数据存本地', tag: '全新' },
|
||||
{ name: '体验优化', icon: '优', desc: '全站中文默认、收藏与最近使用、菜单一键展开/收起、宽屏自适应、品牌页脚等数十项细节', tag: '优化' },
|
||||
],
|
||||
},
|
||||
];
|
||||
|
||||
const repoUrl = 'https://github.com/personal82555/it-tools-pro';
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="about-root">
|
||||
<div class="hero">
|
||||
<div class="hero-title">IT-TOOLS-PRO 新增功能介绍</div>
|
||||
<div class="hero-sub">
|
||||
基于开源项目 IT-Tools 深度定制:新增 12 个原创工具、授权系统与数十项体验优化,全部功能持续更新中。
|
||||
</div>
|
||||
<a class="repo-btn" :href="repoUrl" target="_blank" rel="noopener">
|
||||
⭐ GitHub 源码仓库
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<div v-for="g in groups" :key="g.title" class="group">
|
||||
<h3 class="group-title">
|
||||
{{ g.title }}
|
||||
</h3>
|
||||
<div class="item-grid">
|
||||
<div v-for="it in g.items" :key="it.name" class="item-card">
|
||||
<div class="item-head">
|
||||
<span class="item-icon">{{ it.icon }}</span>
|
||||
<span class="item-name">{{ it.name }}</span>
|
||||
<span class="item-tag" :class="{ hot: it.tag === '全新' }">{{ it.tag }}</span>
|
||||
</div>
|
||||
<div class="item-desc">
|
||||
{{ it.desc }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="bottom-links">
|
||||
<a :href="repoUrl" target="_blank" rel="noopener">GitHub 仓库</a>
|
||||
<span class="sep">·</span>
|
||||
<RouterLink to="/pricing">
|
||||
授权购买
|
||||
</RouterLink>
|
||||
<span class="sep">·</span>
|
||||
<a href="https://nav.88531.cn" target="_blank" rel="noopener">nav.88531.cn 更多应用</a>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.about-root {
|
||||
max-width: 980px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px 80px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
text-align: center;
|
||||
margin-bottom: 34px;
|
||||
|
||||
.hero-title {
|
||||
font-size: 26px;
|
||||
font-weight: 800;
|
||||
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 55%, rgba(20, 160, 88, 1) 100%);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.hero-sub {
|
||||
margin-top: 10px;
|
||||
font-size: 14px;
|
||||
opacity: 0.65;
|
||||
line-height: 1.8;
|
||||
}
|
||||
|
||||
.repo-btn {
|
||||
display: inline-block;
|
||||
margin-top: 16px;
|
||||
background: #24292f;
|
||||
color: #fff;
|
||||
text-decoration: none;
|
||||
font-size: 13.5px;
|
||||
font-weight: 600;
|
||||
border-radius: 999px;
|
||||
padding: 9px 26px;
|
||||
transition: opacity 0.15s;
|
||||
|
||||
&:hover {
|
||||
opacity: 0.85;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.group {
|
||||
margin-bottom: 26px;
|
||||
|
||||
.group-title {
|
||||
font-size: 16.5px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 12px;
|
||||
}
|
||||
}
|
||||
|
||||
.item-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.item-card {
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
border-radius: 10px;
|
||||
padding: 12px 14px;
|
||||
transition: border-color 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(24, 160, 88, 0.55);
|
||||
}
|
||||
|
||||
.item-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
|
||||
.item-icon {
|
||||
width: 26px;
|
||||
height: 26px;
|
||||
border-radius: 7px;
|
||||
background: rgba(24, 160, 88, 0.12);
|
||||
color: #18a058;
|
||||
font-size: 12.5px;
|
||||
font-weight: 700;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.item-name {
|
||||
font-size: 14px;
|
||||
font-weight: 700;
|
||||
}
|
||||
|
||||
.item-tag {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
padding: 1px 8px;
|
||||
border-radius: 999px;
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
color: #777;
|
||||
flex-shrink: 0;
|
||||
|
||||
&.hot {
|
||||
background: rgba(24, 160, 88, 0.12);
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.item-desc {
|
||||
font-size: 12.5px;
|
||||
opacity: 0.7;
|
||||
line-height: 1.75;
|
||||
}
|
||||
}
|
||||
|
||||
.bottom-links {
|
||||
text-align: center;
|
||||
margin-top: 30px;
|
||||
font-size: 13px;
|
||||
|
||||
a {
|
||||
color: #18a058;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.sep {
|
||||
margin: 0 10px;
|
||||
opacity: 0.4;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,151 @@
|
||||
<script setup lang="ts">
|
||||
import { IconDragDrop, IconHeart } from '@tabler/icons-vue';
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { computed } from 'vue';
|
||||
import Draggable from 'vuedraggable';
|
||||
import ColoredCard from '../components/ColoredCard.vue';
|
||||
import ToolCard from '../components/ToolCard.vue';
|
||||
import { useToolStore } from '@/tools/tools.store';
|
||||
import { useRecentTools } from '@/composable/recent-tools';
|
||||
import { config } from '@/config';
|
||||
|
||||
const toolStore = useToolStore();
|
||||
const { recentTools } = useRecentTools();
|
||||
|
||||
// map recent paths to tool objects (newest first, cap 8)
|
||||
const recentToolList = computed(() => {
|
||||
const byPath = new Map(toolStore.tools.map(t => [t.path, t]));
|
||||
const out: any[] = [];
|
||||
for (const r of recentTools.value) {
|
||||
const tool = byPath.get(r.path);
|
||||
if (tool && !out.includes(tool)) {
|
||||
out.push(tool);
|
||||
}
|
||||
if (out.length >= 8) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return out;
|
||||
});
|
||||
|
||||
useHead({ title: 'IT-TOOLS-PRO - Handy online tools for developers' });
|
||||
const { t } = useI18n();
|
||||
|
||||
const favoriteTools = computed(() => toolStore.favoriteTools);
|
||||
|
||||
// Update favorite tools order when drag is finished
|
||||
function onUpdateFavoriteTools() {
|
||||
toolStore.updateFavoriteTools(favoriteTools.value); // Update the store with the new order
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pt-50px">
|
||||
<div class="grid-wrapper">
|
||||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<ColoredCard v-if="config.showBanner" :title="$t('home.follow.title')" :icon="IconHeart">
|
||||
{{ $t('home.follow.p1') }}
|
||||
<a
|
||||
href="https://github.com/CorentinTh/it-tools"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
:aria-label="$t('home.follow.githubRepository')"
|
||||
>GitHub</a>
|
||||
{{ $t('home.follow.p2') }}
|
||||
<a
|
||||
href="https://x.com/ittoolsdottech"
|
||||
rel="noopener"
|
||||
target="_blank"
|
||||
:aria-label="$t('home.follow.twitterXAccount')"
|
||||
>X</a>.
|
||||
{{ $t('home.follow.thankYou') }}
|
||||
<n-icon :component="IconHeart" />
|
||||
</ColoredCard>
|
||||
</div>
|
||||
|
||||
<div v-if="recentToolList.length > 0">
|
||||
<h3 class="mb-5px mt-25px text-neutral-400 font-500">
|
||||
🕘 {{ $t('home.categories.recentTools') }}
|
||||
</h3>
|
||||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<ToolCard v-for="tool in recentToolList" :key="tool.name" :tool="tool" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<transition name="height">
|
||||
<div v-if="toolStore.favoriteTools.length > 0">
|
||||
<h3 class="mb-5px mt-25px text-neutral-400 font-500">
|
||||
{{ $t('home.categories.favoriteTools') }}
|
||||
<c-tooltip :tooltip="$t('home.categories.favoritesDndToolTip')">
|
||||
<n-icon :component="IconDragDrop" size="18" />
|
||||
</c-tooltip>
|
||||
</h3>
|
||||
<Draggable
|
||||
:list="favoriteTools"
|
||||
class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4"
|
||||
ghost-class="ghost-favorites-draggable"
|
||||
item-key="name"
|
||||
@end="onUpdateFavoriteTools"
|
||||
>
|
||||
<template #item="{ element: tool }">
|
||||
<ToolCard :tool="tool" />
|
||||
</template>
|
||||
</Draggable>
|
||||
</div>
|
||||
</transition>
|
||||
|
||||
<div v-if="toolStore.newTools.length > 0">
|
||||
<h3 class="mb-5px mt-25px text-neutral-400 font-500">
|
||||
{{ t('home.categories.newestTools') }}
|
||||
</h3>
|
||||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<ToolCard v-for="tool in toolStore.newTools" :key="tool.name" :tool="tool" />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h3 class="mb-5px mt-25px text-neutral-400 font-500">
|
||||
{{ $t('home.categories.allTools') }}
|
||||
</h3>
|
||||
<div class="grid grid-cols-1 gap-12px lg:grid-cols-3 md:grid-cols-3 sm:grid-cols-2 xl:grid-cols-4">
|
||||
<ToolCard v-for="tool in toolStore.tools" :key="tool.name" :tool="tool" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped lang="less">
|
||||
.height-enter-active,
|
||||
.height-leave-active {
|
||||
transition: all 0.5s ease-in-out;
|
||||
overflow: hidden;
|
||||
max-height: 500px;
|
||||
}
|
||||
|
||||
.height-enter-from,
|
||||
.height-leave-to {
|
||||
max-height: 42px;
|
||||
overflow: hidden;
|
||||
opacity: 0;
|
||||
margin-bottom: 0;
|
||||
}
|
||||
|
||||
.ghost-favorites-draggable {
|
||||
opacity: 0.4;
|
||||
background-color: #ccc;
|
||||
border: 2px dashed #666;
|
||||
box-shadow: 0 0 10px rgba(0, 0, 0, 0.2);
|
||||
transform: scale(1.1);
|
||||
animation: ghost-favorites-draggable-animation 0.2s ease-out;
|
||||
}
|
||||
|
||||
@keyframes ghost-favorites-draggable-animation {
|
||||
0% {
|
||||
opacity: 0;
|
||||
transform: scale(0.9);
|
||||
}
|
||||
100% {
|
||||
opacity: 0.4;
|
||||
transform: scale(1.0);
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,385 @@
|
||||
<script setup lang="ts">
|
||||
import { useHead } from '@vueuse/head';
|
||||
import { BUY_URL, PROTECTED_TOOLS, getMachineId } from '@/tools/license/license';
|
||||
|
||||
useHead({ title: '授权应用 - IT-TOOLS-PRO' });
|
||||
|
||||
interface Feature {
|
||||
path: string;
|
||||
name: string;
|
||||
icon: string;
|
||||
points: string[];
|
||||
}
|
||||
|
||||
const FEATURES: Feature[] = [
|
||||
{
|
||||
path: '/translator',
|
||||
name: '在线翻译',
|
||||
icon: '🌐',
|
||||
points: ['支持中英日韩等 16 种语言互译', '谷歌翻译主线 + MyMemory 备用双线路', '粘贴即译,自动识别源语言'],
|
||||
},
|
||||
{
|
||||
path: '/image-ocr',
|
||||
name: '图片OCR文字识别',
|
||||
icon: '📷',
|
||||
points: ['本地 OCR 引擎,中文识别准确率 99%+', '截图、扫描件、照片文字一键提取', '逐行输出带置信度,支持粘贴图片'],
|
||||
},
|
||||
{
|
||||
path: '/pdf-ocr',
|
||||
name: 'PDF文字识别',
|
||||
icon: '📄',
|
||||
points: ['逐页 OCR 中英文 PDF(最多 50 页)', '每页预览、翻页查看识别结果', '一键复制全部或下载 TXT'],
|
||||
},
|
||||
{
|
||||
path: '/ai-retouch',
|
||||
name: 'AI修图',
|
||||
icon: '🎨',
|
||||
points: ['去水印/修复:涂抹区域智能填充', '抠图去背景、4x 超分辨率、人脸修复', '本地 AI 模型推理,单张 10 秒级出图'],
|
||||
},
|
||||
{
|
||||
path: '/label-designer',
|
||||
name: '面单设计',
|
||||
icon: '🏷️',
|
||||
points: ['快递面单/物流标签常用模板开箱即用', '上传 PDF 面单二次编辑(遮盖改字)', '300dpi 高清导出,打印即用'],
|
||||
},
|
||||
{
|
||||
path: '/doc-convert',
|
||||
name: '文档格式转换',
|
||||
icon: '🔄',
|
||||
points: ['Word/PDF/TXT/RTF/ODT/EPUB/MOBI/AZW3/HTML 九种格式互转', '自建转换引擎,批量转换打包下载', '单文件最快几秒完成'],
|
||||
},
|
||||
];
|
||||
|
||||
// only show tools that are actually in the protected list
|
||||
const paidFeatures = FEATURES.filter(f => f.path in PROTECTED_TOOLS);
|
||||
|
||||
const machineId = getMachineId();
|
||||
const copied = ref(false);
|
||||
|
||||
async function copyMachine() {
|
||||
try {
|
||||
await navigator.clipboard.writeText(machineId);
|
||||
copied.value = true;
|
||||
setTimeout(() => (copied.value = false), 1500);
|
||||
}
|
||||
catch { /* ignore */ }
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div class="pricing-root">
|
||||
<!-- hero -->
|
||||
<div class="hero">
|
||||
<div class="hero-title">🚀 授权解锁全部高级功能</div>
|
||||
<div class="hero-sub">
|
||||
IT-TOOLS-PRO 的 20+ 基础工具永久免费,下面 6 个算力型高级功能需要授权。一次激活,全部通用。
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- feature grid -->
|
||||
<div class="section">
|
||||
<h3 class="section-title">
|
||||
授权可用的高级功能
|
||||
</h3>
|
||||
<div class="feat-grid">
|
||||
<div v-for="f in paidFeatures" :key="f.path" class="feat-card">
|
||||
<div class="feat-head">
|
||||
<span class="feat-icon">{{ f.icon }}</span>
|
||||
<RouterLink class="feat-name" :to="f.path">
|
||||
{{ f.name }}
|
||||
</RouterLink>
|
||||
<span class="feat-tag">授权功能</span>
|
||||
</div>
|
||||
<ul class="feat-points">
|
||||
<li v-for="(p, i) in f.points" :key="i">
|
||||
{{ p }}
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- advantages -->
|
||||
<div class="section">
|
||||
<h3 class="section-title">
|
||||
为什么值得购买
|
||||
</h3>
|
||||
<div class="adv-grid">
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">🔑</div>
|
||||
<div class="adv-title">一次激活,全站通用</div>
|
||||
<div class="adv-desc">输入一次卡密,6 个高级功能全部解锁,无需逐个购买</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">♾️</div>
|
||||
<div class="adv-title">永久套餐</div>
|
||||
<div class="adv-desc">买断制授权,不按次、不按月,长期使用无后顾之忧</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">🎁</div>
|
||||
<div class="adv-title">先用后买</div>
|
||||
<div class="adv-desc">每个高级功能免费试用 30 分钟,觉得好用再付费</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">🔒</div>
|
||||
<div class="adv-title">隐私友好</div>
|
||||
<div class="adv-desc">PDF/图片工具全程浏览器本地处理,文件不上传服务器</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">⚡</div>
|
||||
<div class="adv-title">自建服务稳定</div>
|
||||
<div class="adv-desc">翻译、OCR、AI 修图、格式转换均为自建服务,不依赖第三方接口</div>
|
||||
</div>
|
||||
<div class="adv-card">
|
||||
<div class="adv-icon">🧊</div>
|
||||
<div class="adv-title">免费工具持续更新</div>
|
||||
<div class="adv-desc">条码、JSON、二维码、IT 网站收藏等 20+ 工具永久免费,还会不断增加</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- CTA -->
|
||||
<div class="section">
|
||||
<div class="cta-box">
|
||||
<div class="cta-left">
|
||||
<div class="cta-title">
|
||||
立即购买授权
|
||||
</div>
|
||||
<div class="cta-sub">
|
||||
购买后你会得到一个卡密,在任意高级功能页右上角「卡密」入口输入即可激活本设备。
|
||||
</div>
|
||||
<div class="cta-machine">
|
||||
本设备机器码:<code>{{ machineId }}</code>
|
||||
<a href="javascript:;" class="copy-link" @click="copyMachine">{{ copied ? '已复制 ✓' : '复制' }}</a>
|
||||
<span class="cta-machine-hint">(购买或激活遇到问题时提供给客服)</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="cta-right">
|
||||
<c-button type="primary" class="cta-btn" tag="a" :href="BUY_URL" target="_blank" rel="noopener">
|
||||
💳 前往购买卡密
|
||||
</c-button>
|
||||
<div class="cta-hint">
|
||||
支付后自动发卡,卡密即时可用
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="foot-note">
|
||||
已购买用户切换设备使用?在旧设备的功能页点「撤销」,新设备重新输入卡密即可。
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.pricing-root {
|
||||
max-width: 1100px;
|
||||
margin: 0 auto;
|
||||
padding: 40px 20px 80px;
|
||||
}
|
||||
|
||||
.hero {
|
||||
text-align: center;
|
||||
margin-bottom: 36px;
|
||||
|
||||
.hero-title {
|
||||
font-size: 30px;
|
||||
font-weight: 800;
|
||||
background: linear-gradient(48deg, rgba(37, 99, 108, 1) 0%, rgba(59, 149, 111, 1) 55%, rgba(20, 160, 88, 1) 100%);
|
||||
-webkit-background-clip: text;
|
||||
background-clip: text;
|
||||
color: transparent;
|
||||
}
|
||||
|
||||
.hero-sub {
|
||||
margin-top: 10px;
|
||||
font-size: 14.5px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
.section {
|
||||
margin-bottom: 34px;
|
||||
|
||||
.section-title {
|
||||
font-size: 17px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 14px;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- feature grid ----
|
||||
.feat-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.feat-card {
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
transition: border-color 0.15s, box-shadow 0.15s;
|
||||
|
||||
&:hover {
|
||||
border-color: rgba(24, 160, 88, 0.6);
|
||||
box-shadow: 0 4px 16px rgba(24, 160, 88, 0.08);
|
||||
}
|
||||
|
||||
.feat-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 8px;
|
||||
|
||||
.feat-icon {
|
||||
font-size: 20px;
|
||||
}
|
||||
|
||||
.feat-name {
|
||||
font-size: 15px;
|
||||
font-weight: 700;
|
||||
color: #333;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.feat-tag {
|
||||
margin-left: auto;
|
||||
font-size: 11px;
|
||||
color: #18a058;
|
||||
background: rgba(24, 160, 88, 0.1);
|
||||
border-radius: 999px;
|
||||
padding: 2px 10px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
|
||||
.feat-points {
|
||||
margin: 0;
|
||||
padding-left: 18px;
|
||||
font-size: 12.5px;
|
||||
line-height: 1.9;
|
||||
opacity: 0.75;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- advantages ----
|
||||
.adv-grid {
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.adv-card {
|
||||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 16px;
|
||||
background: rgba(24, 160, 88, 0.03);
|
||||
|
||||
.adv-icon {
|
||||
font-size: 24px;
|
||||
margin-bottom: 6px;
|
||||
}
|
||||
|
||||
.adv-title {
|
||||
font-size: 14.5px;
|
||||
font-weight: 700;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.adv-desc {
|
||||
font-size: 12.5px;
|
||||
opacity: 0.65;
|
||||
line-height: 1.7;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- CTA ----
|
||||
.cta-box {
|
||||
display: flex;
|
||||
gap: 20px;
|
||||
align-items: center;
|
||||
border: 2px solid rgba(24, 160, 88, 0.45);
|
||||
border-radius: 14px;
|
||||
padding: 22px 26px;
|
||||
background: linear-gradient(120deg, rgba(24, 160, 88, 0.06), rgba(24, 160, 88, 0.02));
|
||||
flex-wrap: wrap;
|
||||
|
||||
.cta-left {
|
||||
flex: 1;
|
||||
min-width: 260px;
|
||||
|
||||
.cta-title {
|
||||
font-size: 19px;
|
||||
font-weight: 800;
|
||||
}
|
||||
|
||||
.cta-sub {
|
||||
font-size: 13px;
|
||||
opacity: 0.7;
|
||||
margin-top: 6px;
|
||||
line-height: 1.7;
|
||||
}
|
||||
|
||||
.cta-machine {
|
||||
margin-top: 10px;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.85;
|
||||
|
||||
code {
|
||||
background: rgba(128, 128, 128, 0.1);
|
||||
padding: 2px 8px;
|
||||
border-radius: 5px;
|
||||
font-size: 12px;
|
||||
}
|
||||
|
||||
.copy-link {
|
||||
color: #18a058;
|
||||
margin-left: 8px;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
.cta-machine-hint {
|
||||
opacity: 0.5;
|
||||
font-size: 11.5px;
|
||||
margin-left: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.cta-right {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
|
||||
.cta-btn {
|
||||
background: #18a058 !important;
|
||||
color: #fff !important;
|
||||
font-size: 16px !important;
|
||||
font-weight: 700;
|
||||
padding: 10px 30px !important;
|
||||
text-decoration: none;
|
||||
}
|
||||
|
||||
.cta-hint {
|
||||
font-size: 11.5px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.foot-note {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
opacity: 0.5;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,32 @@
|
||||
import messages from '@intlify/unplugin-vue-i18n/messages';
|
||||
import { get, useStorage } from '@vueuse/core';
|
||||
import type { Plugin } from 'vue';
|
||||
import { createI18n } from 'vue-i18n';
|
||||
|
||||
// persisted language choice, default to Chinese
|
||||
const locale = useStorage('it-tools-locale', 'zh');
|
||||
|
||||
const i18n = createI18n({
|
||||
legacy: false,
|
||||
locale: locale.value,
|
||||
messages,
|
||||
});
|
||||
|
||||
// keep the persisted value in sync when the user switches language
|
||||
watch(locale, (value) => {
|
||||
i18n.global.locale.value = value;
|
||||
});
|
||||
watch(i18n.global.locale, (value) => {
|
||||
locale.value = value;
|
||||
});
|
||||
|
||||
export const i18nPlugin: Plugin = {
|
||||
install: (app) => {
|
||||
app.use(i18n);
|
||||
},
|
||||
};
|
||||
|
||||
export const translate = function (localeKey: string) {
|
||||
const hasKey = i18n.global.te(localeKey, get(i18n.global.locale));
|
||||
return hasKey ? i18n.global.t(localeKey) : localeKey;
|
||||
};
|
||||
@@ -0,0 +1,3 @@
|
||||
import { create } from 'naive-ui';
|
||||
|
||||
export const naive = create();
|
||||
@@ -0,0 +1,38 @@
|
||||
import { noop } from 'lodash';
|
||||
|
||||
import Plausible from 'plausible-tracker';
|
||||
import type { App } from 'vue';
|
||||
import { config } from '@/config';
|
||||
|
||||
function createFakePlausibleInstance(): Pick<ReturnType<typeof Plausible>, 'trackEvent' | 'enableAutoPageviews'> {
|
||||
return {
|
||||
trackEvent: noop,
|
||||
enableAutoPageviews: () => noop,
|
||||
};
|
||||
}
|
||||
|
||||
function createPlausibleInstance({
|
||||
config,
|
||||
}: {
|
||||
config: {
|
||||
isTrackerEnabled: boolean
|
||||
domain: string
|
||||
apiHost: string
|
||||
trackLocalhost: boolean
|
||||
}
|
||||
}) {
|
||||
if (config.isTrackerEnabled) {
|
||||
return Plausible(config);
|
||||
}
|
||||
|
||||
return createFakePlausibleInstance();
|
||||
}
|
||||
|
||||
export const plausible = {
|
||||
install: (app: App) => {
|
||||
const plausible = createPlausibleInstance({ config: config.plausible });
|
||||
plausible.enableAutoPageviews();
|
||||
|
||||
app.provide('plausible', plausible);
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,46 @@
|
||||
import { createRouter, createWebHistory } from 'vue-router';
|
||||
import { layouts } from './layouts/index';
|
||||
import HomePage from './pages/Home.page.vue';
|
||||
import NotFound from './pages/404.page.vue';
|
||||
import { tools } from './tools';
|
||||
import { config } from './config';
|
||||
import { routes as demoRoutes } from './ui/demo/demo.routes';
|
||||
|
||||
const toolsRoutes = tools.map(({ path, name, component, ...config }) => ({
|
||||
path,
|
||||
name,
|
||||
component,
|
||||
meta: { isTool: true, layout: layouts.toolLayout, name, ...config },
|
||||
}));
|
||||
const toolsRedirectRoutes = tools
|
||||
.filter(({ redirectFrom }) => redirectFrom && redirectFrom.length > 0)
|
||||
.flatMap(
|
||||
({ path, redirectFrom }) => redirectFrom?.map(redirectSource => ({ path: redirectSource, redirect: path })) ?? [],
|
||||
);
|
||||
|
||||
const router = createRouter({
|
||||
history: createWebHistory(config.app.baseUrl),
|
||||
routes: [
|
||||
{
|
||||
path: '/',
|
||||
name: 'home',
|
||||
component: HomePage,
|
||||
},
|
||||
{
|
||||
path: '/about',
|
||||
name: 'about',
|
||||
component: () => import('./pages/About.vue'),
|
||||
},
|
||||
{
|
||||
path: '/pricing',
|
||||
name: 'pricing',
|
||||
component: () => import('./pages/Pricing.page.vue'),
|
||||
},
|
||||
...toolsRoutes,
|
||||
...toolsRedirectRoutes,
|
||||
...(config.app.env === 'development' ? demoRoutes : []),
|
||||
{ path: '/:pathMatch(.*)*', name: 'NotFound', component: NotFound },
|
||||
],
|
||||
});
|
||||
|
||||
export default router;
|
||||
Vendored
+41
@@ -0,0 +1,41 @@
|
||||
declare module '*.vue' {
|
||||
import type { ComponentOptions } from 'vue';
|
||||
const Component: ComponentOptions;
|
||||
export default Component;
|
||||
}
|
||||
|
||||
declare module '*.md' {
|
||||
import type { ComponentOptions } from 'vue';
|
||||
const Component: ComponentOptions;
|
||||
export default Component;
|
||||
}
|
||||
|
||||
declare module 'iarna-toml-esm' {
|
||||
export const parse: (toml: string) => any;
|
||||
export const stringify: (obj: any) => string;
|
||||
}
|
||||
|
||||
declare module 'emojilib' {
|
||||
const lib: Record<string, string[]>;
|
||||
export default lib;
|
||||
}
|
||||
|
||||
declare module 'unicode-emoji-json' {
|
||||
const emoji: Record<string, {
|
||||
name: string;
|
||||
slug: string;
|
||||
group: string;
|
||||
emoji_version: string;
|
||||
unicode_version: string;
|
||||
skin_tone_support: boolean;
|
||||
skin_tone_support_unicode_version: string;
|
||||
}>;
|
||||
|
||||
export default emoji;
|
||||
}
|
||||
|
||||
declare module 'pdf-signature-reader' {
|
||||
const verifySignature: (pdf: ArrayBuffer) => ({signatures: SignatureInfo[]});
|
||||
|
||||
export default verifySignature;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { useDark, useMediaQuery, useStorage, useToggle } from '@vueuse/core';
|
||||
import { defineStore } from 'pinia';
|
||||
import { type Ref, watch } from 'vue';
|
||||
|
||||
export const useStyleStore = defineStore('style', {
|
||||
state: () => {
|
||||
const isDarkTheme = useDark();
|
||||
const toggleDark = useToggle(isDarkTheme);
|
||||
const isSmallScreen = useMediaQuery('(max-width: 700px)');
|
||||
const isMenuCollapsed = useStorage('isMenuCollapsed', isSmallScreen.value) as Ref<boolean>;
|
||||
|
||||
watch(isSmallScreen, v => (isMenuCollapsed.value = v));
|
||||
|
||||
return {
|
||||
isDarkTheme,
|
||||
toggleDark,
|
||||
isMenuCollapsed,
|
||||
isSmallScreen,
|
||||
};
|
||||
},
|
||||
});
|
||||
@@ -0,0 +1,54 @@
|
||||
import type { GlobalThemeOverrides } from 'naive-ui';
|
||||
|
||||
export const lightThemeOverrides: GlobalThemeOverrides = {
|
||||
Menu: {
|
||||
itemHeight: '32px',
|
||||
},
|
||||
|
||||
Layout: { color: '#f1f5f9' },
|
||||
|
||||
AutoComplete: {
|
||||
peers: {
|
||||
InternalSelectMenu: { height: '500px' },
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
export const darkThemeOverrides: GlobalThemeOverrides = {
|
||||
common: {
|
||||
primaryColor: '#1ea54cFF',
|
||||
primaryColorHover: '#36AD6AFF',
|
||||
primaryColorPressed: '#0C7A43FF',
|
||||
primaryColorSuppl: '#36AD6AFF',
|
||||
},
|
||||
|
||||
Notification: {
|
||||
color: '#333333',
|
||||
},
|
||||
|
||||
AutoComplete: {
|
||||
peers: {
|
||||
InternalSelectMenu: { height: '500px', color: '#1e1e1e' },
|
||||
},
|
||||
},
|
||||
|
||||
Menu: {
|
||||
itemHeight: '32px',
|
||||
},
|
||||
|
||||
Layout: {
|
||||
color: '#1c1c1c',
|
||||
siderColor: '#232323',
|
||||
siderBorderColor: 'transparent',
|
||||
},
|
||||
|
||||
Card: {
|
||||
color: '#232323',
|
||||
borderColor: '#282828',
|
||||
},
|
||||
|
||||
Table: {
|
||||
tdColor: '#232323',
|
||||
thColor: '#353535',
|
||||
},
|
||||
};
|
||||
@@ -0,0 +1,698 @@
|
||||
<script setup lang="ts">
|
||||
import { licenseHeaders } from '../license/license';
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
|
||||
const genHist = useGenHistory('ai-retouch');
|
||||
|
||||
interface TabDef {
|
||||
key: string;
|
||||
label: string;
|
||||
plugin?: string; // iopaint plugin name; undefined = lama inpaint
|
||||
}
|
||||
|
||||
const tabs: TabDef[] = [
|
||||
{ key: 'inpaint', label: '去水印/修复' },
|
||||
{ key: 'removebg', label: '抠图/去背景', plugin: 'RemoveBG' },
|
||||
{ key: 'esrgan', label: '超分辨率', plugin: 'RealESRGAN' },
|
||||
{ key: 'gfpgan', label: '人脸修复', plugin: 'GFPGAN' },
|
||||
];
|
||||
|
||||
const MAX_MB = 20;
|
||||
const WARN_KEY = 'ai-retouch-warning-acked';
|
||||
|
||||
const activeTab = ref(0);
|
||||
const warningAcked = ref(localStorage.getItem(WARN_KEY) === '1');
|
||||
|
||||
const fileInput = ref<HTMLInputElement>();
|
||||
const canvasWrap = ref<HTMLElement>();
|
||||
const maskCanvas = ref<HTMLCanvasElement>();
|
||||
|
||||
const srcDataUrl = ref('');
|
||||
const imgNatural = ref({ w: 0, h: 0 });
|
||||
const fileName = ref('');
|
||||
const fileSize = ref(0);
|
||||
const dragActive = ref(false);
|
||||
const processing = ref(false);
|
||||
const elapsed = ref(0);
|
||||
const error = ref('');
|
||||
const resultUrl = ref('');
|
||||
const brushSize = ref(40); // px in image natural coords
|
||||
|
||||
let baseImg: HTMLImageElement | null = null;
|
||||
let drawing = false;
|
||||
let hasMask = ref(false);
|
||||
|
||||
const tab = computed(() => tabs[activeTab.value]);
|
||||
const canSubmit = computed(() => !!srcDataUrl.value && !processing.value
|
||||
&& (tab.value.key !== 'inpaint' || hasMask.value));
|
||||
|
||||
function ackWarning() {
|
||||
warningAcked.value = true;
|
||||
localStorage.setItem(WARN_KEY, '1');
|
||||
}
|
||||
|
||||
function pickFile() {
|
||||
fileInput.value?.click();
|
||||
}
|
||||
|
||||
function onInputChange(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
handleFile(input.files?.[0]);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function onDrop(e: DragEvent) {
|
||||
dragActive.value = false;
|
||||
handleFile(e.dataTransfer?.files?.[0]);
|
||||
}
|
||||
|
||||
function handleFile(file?: File | null) {
|
||||
if (!file) return;
|
||||
if (!file.type.startsWith('image/')) {
|
||||
error.value = '请选择图片文件(png/jpg/webp 等)';
|
||||
return;
|
||||
}
|
||||
if (file.size > MAX_MB * 1024 * 1024) {
|
||||
error.value = `文件超过上限 ${MAX_MB} MB`;
|
||||
return;
|
||||
}
|
||||
error.value = '';
|
||||
resultUrl.value = '';
|
||||
fileName.value = file.name;
|
||||
fileSize.value = file.size;
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
srcDataUrl.value = String(reader.result ?? '');
|
||||
const img = new Image();
|
||||
img.onload = () => {
|
||||
baseImg = img;
|
||||
imgNatural.value = { w: img.naturalWidth, h: img.naturalHeight };
|
||||
nextTick(resetMaskCanvas);
|
||||
};
|
||||
img.src = srcDataUrl.value;
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
// ---------- mask painting (inpaint tab) ----------
|
||||
function resetMaskCanvas() {
|
||||
const c = maskCanvas.value;
|
||||
if (!c || !imgNatural.value.w) return;
|
||||
c.width = imgNatural.value.w;
|
||||
c.height = imgNatural.value.h;
|
||||
const ctx = c.getContext('2d')!;
|
||||
ctx.clearRect(0, 0, c.width, c.height);
|
||||
hasMask.value = false;
|
||||
}
|
||||
|
||||
function clearMask() {
|
||||
resetMaskCanvas();
|
||||
}
|
||||
|
||||
function pos(e: MouseEvent) {
|
||||
const c = maskCanvas.value!;
|
||||
const r = c.getBoundingClientRect();
|
||||
return {
|
||||
x: (e.clientX - r.left) * (c.width / r.width),
|
||||
y: (e.clientY - r.top) * (c.height / r.height),
|
||||
};
|
||||
}
|
||||
|
||||
function startDraw(e: MouseEvent) {
|
||||
if (tab.value.key !== 'inpaint') return;
|
||||
drawing = true;
|
||||
const c = maskCanvas.value!;
|
||||
const ctx = c.getContext('2d')!;
|
||||
const p = pos(e);
|
||||
ctx.beginPath();
|
||||
ctx.moveTo(p.x, p.y);
|
||||
ctx.lineCap = 'round';
|
||||
ctx.lineJoin = 'round';
|
||||
ctx.lineWidth = brushSize.value;
|
||||
ctx.strokeStyle = 'rgba(255, 60, 60, 0.55)';
|
||||
ctx.lineTo(p.x, p.y);
|
||||
ctx.stroke();
|
||||
hasMask.value = true;
|
||||
}
|
||||
|
||||
function moveDraw(e: MouseEvent) {
|
||||
if (!drawing) return;
|
||||
const c = maskCanvas.value!;
|
||||
const ctx = c.getContext('2d')!;
|
||||
const p = pos(e);
|
||||
ctx.lineTo(p.x, p.y);
|
||||
ctx.stroke();
|
||||
}
|
||||
|
||||
function endDraw() {
|
||||
drawing = false;
|
||||
}
|
||||
|
||||
function exportMask(): string {
|
||||
const c = maskCanvas.value!;
|
||||
const ctx = c.getContext('2d')!;
|
||||
const src = ctx.getImageData(0, 0, c.width, c.height);
|
||||
const out = document.createElement('canvas');
|
||||
out.width = c.width;
|
||||
out.height = c.height;
|
||||
const octx = out.getContext('2d')!;
|
||||
const imgData = octx.createImageData(c.width, c.height);
|
||||
for (let i = 0; i < src.data.length; i += 4) {
|
||||
const on = src.data[i + 3] > 20; // painted pixels
|
||||
const v = on ? 255 : 0;
|
||||
imgData.data[i] = v;
|
||||
imgData.data[i + 1] = v;
|
||||
imgData.data[i + 2] = v;
|
||||
imgData.data[i + 3] = 255;
|
||||
}
|
||||
octx.putImageData(imgData, 0, 0);
|
||||
return out.toDataURL('image/png');
|
||||
}
|
||||
|
||||
// ---------- submit ----------
|
||||
async function submit() {
|
||||
if (!canSubmit.value) return;
|
||||
processing.value = true;
|
||||
error.value = '';
|
||||
resultUrl.value = '';
|
||||
const start = performance.now();
|
||||
try {
|
||||
let url: string;
|
||||
if (tab.value.key === 'inpaint') {
|
||||
url = '/api/v1/inpaint';
|
||||
} else {
|
||||
url = '/api/v1/run_plugin_gen_image';
|
||||
}
|
||||
const body = tab.value.key === 'inpaint'
|
||||
? { image: srcDataUrl.value, mask: exportMask() }
|
||||
: {
|
||||
name: tab.value.plugin,
|
||||
image: srcDataUrl.value,
|
||||
clicks: [],
|
||||
...(tab.value.key === 'esrgan' ? { scale: 4 } : {}),
|
||||
};
|
||||
|
||||
const res = await fetch(url, {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/json', ...licenseHeaders('ai-retouch') },
|
||||
body: JSON.stringify(body),
|
||||
});
|
||||
if (res.status === 403) {
|
||||
throw new Error('授权校验未通过:免费试用已结束,请购买授权或输入卡密');
|
||||
}
|
||||
if (!res.ok) {
|
||||
throw new Error(`处理失败 HTTP ${res.status}`);
|
||||
}
|
||||
const blob = await res.blob();
|
||||
resultUrl.value = URL.createObjectURL(blob);
|
||||
if (tab.value.key === 'inpaint') clearMask();
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = e?.message ?? String(e);
|
||||
}
|
||||
finally {
|
||||
elapsed.value = Math.round(performance.now() - start);
|
||||
processing.value = false;
|
||||
if (resultUrl.value) {
|
||||
genHist.add({
|
||||
title: tab.value.label,
|
||||
detail: `原图 ${imgNatural.value.w}×${imgNatural.value.h} · 耗时 ${elapsed.value}ms`,
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function downloadResult() {
|
||||
if (!resultUrl.value) return;
|
||||
const a = document.createElement('a');
|
||||
a.href = resultUrl.value;
|
||||
const base = fileName.value.replace(/\.[^.]+$/, '') || 'image';
|
||||
const suffix = { inpaint: '-retouched', removebg: '-nobb', esrgan: '-4x', gfpgan: '-face' }[tab.value.key as string] ?? '';
|
||||
a.download = `${base}${suffix}.png`;
|
||||
a.click();
|
||||
}
|
||||
|
||||
function resetAll() {
|
||||
srcDataUrl.value = '';
|
||||
resultUrl.value = '';
|
||||
error.value = '';
|
||||
fileName.value = '';
|
||||
baseImg = null;
|
||||
imgNatural.value = { w: 0, h: 0 };
|
||||
}
|
||||
|
||||
function onTabChange(i: number) {
|
||||
activeTab.value = i;
|
||||
resultUrl.value = '';
|
||||
error.value = '';
|
||||
if (tabs[i].key === 'inpaint') nextTick(resetMaskCanvas);
|
||||
}
|
||||
|
||||
// fit viewport: no page scroll
|
||||
const rootEl = ref<HTMLElement>();
|
||||
const rootStyle = ref<Record<string, string>>({});
|
||||
|
||||
function fit() {
|
||||
const el = rootEl.value;
|
||||
if (!el) return;
|
||||
const top = el.getBoundingClientRect().top;
|
||||
const height = Math.max(340, window.innerHeight - top - 12);
|
||||
rootStyle.value = { height: `${height}px`, flex: '1 1 100%' };
|
||||
}
|
||||
|
||||
let observer: ResizeObserver | undefined;
|
||||
onMounted(() => {
|
||||
fit();
|
||||
window.addEventListener('resize', fit);
|
||||
observer = new ResizeObserver(() => fit());
|
||||
if (rootEl.value) observer.observe(rootEl.value);
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', fit);
|
||||
observer?.disconnect();
|
||||
if (resultUrl.value) URL.revokeObjectURL(resultUrl.value);
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="rootEl" class="ar-root" :style="rootStyle">
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
style="display:none"
|
||||
@change="onInputChange"
|
||||
>
|
||||
|
||||
<!-- tabs -->
|
||||
<div class="ar-tabs">
|
||||
<button
|
||||
v-for="(t, i) in tabs"
|
||||
:key="t.key"
|
||||
class="ar-tab"
|
||||
:class="{ active: i === activeTab }"
|
||||
@click="onTabChange(i)"
|
||||
>
|
||||
{{ t.label }}
|
||||
</button>
|
||||
<div class="ar-tab-stats">
|
||||
<template v-if="fileName">
|
||||
{{ fileName }} · {{ (fileSize / 1024 / 1024).toFixed(1) }} MB<template v-if="elapsed"> · {{ elapsed }}ms</template>
|
||||
</template>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- copyright warning (inpaint tab) -->
|
||||
<div v-if="activeTab === 0 && !warningAcked" class="ar-warn">
|
||||
<span class="ar-warn-icon">⚠️</span>
|
||||
<span class="ar-warn-text">
|
||||
去水印功能仅限用于您拥有版权或已获授权的图片,请勿用于去除他人水印或违法用途
|
||||
</span>
|
||||
<button class="ar-warn-btn" @click="ackWarning">
|
||||
我已了解
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="ar-body">
|
||||
<!-- left: upload / paint -->
|
||||
<div class="ar-left">
|
||||
<div
|
||||
class="ar-drop"
|
||||
:class="{ active: dragActive, hasImg: !!srcDataUrl }"
|
||||
@click="!srcDataUrl && pickFile()"
|
||||
@dragover.prevent="dragActive = true"
|
||||
@dragleave.prevent="dragActive = false"
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<template v-if="srcDataUrl">
|
||||
<div class="ar-canvas-wrap" ref="canvasWrap">
|
||||
<img :src="srcDataUrl" draggable="false" alt="原图">
|
||||
<canvas
|
||||
ref="maskCanvas"
|
||||
class="ar-mask"
|
||||
:style="{ display: activeTab === 0 ? 'block' : 'none', cursor: activeTab === 0 ? 'crosshair' : 'default' }"
|
||||
@mousedown="startDraw"
|
||||
@mousemove="moveDraw"
|
||||
@mouseup="endDraw"
|
||||
@mouseleave="endDraw"
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="ar-drop-hint">
|
||||
<div class="icon">
|
||||
⬆️
|
||||
</div>
|
||||
<div class="big">
|
||||
原图
|
||||
</div>
|
||||
<div class="sub">
|
||||
点击或拖拽文件到此处
|
||||
</div>
|
||||
<div class="sub">
|
||||
上限 {{ MAX_MB.toFixed(1) }} MB
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div v-if="srcDataUrl" class="ar-actions-left">
|
||||
<template v-if="activeTab === 0">
|
||||
<span class="ar-brush-hint">涂抹水印区域(红色)</span>
|
||||
<span class="ar-brush-label">笔刷 {{ brushSize }}</span>
|
||||
<input v-model.number="brushSize" class="ar-brush" type="range" min="10" max="120" step="5">
|
||||
<c-button size="small" @click="clearMask">
|
||||
清除涂抹
|
||||
</c-button>
|
||||
</template>
|
||||
<c-button size="small" @click="pickFile">
|
||||
换图
|
||||
</c-button>
|
||||
<c-button size="small" @click="resetAll">
|
||||
清空
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- right: result -->
|
||||
<div class="ar-right">
|
||||
<n-spin :show="processing">
|
||||
<div v-if="error" class="ar-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
<div v-else-if="!resultUrl" class="ar-empty">
|
||||
<template v-if="processing">
|
||||
AI 处理中,大图可能需要 10-30 秒…
|
||||
</template>
|
||||
<template v-else>
|
||||
处理结果将显示在这里
|
||||
</template>
|
||||
</div>
|
||||
<div v-else class="ar-result">
|
||||
<figure class="ar-fig">
|
||||
<img :src="srcDataUrl" alt="原图">
|
||||
<figcaption>原图</figcaption>
|
||||
</figure>
|
||||
<figure class="ar-fig">
|
||||
<img :src="resultUrl" alt="结果">
|
||||
<figcaption>{{ tab.label }}结果</figcaption>
|
||||
</figure>
|
||||
</div>
|
||||
</n-spin>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- bottom bar -->
|
||||
<div class="ar-bottom">
|
||||
<span class="ar-tip">
|
||||
{{ activeTab === 0 ? '先涂抹水印区域,再提交修复' : '上传图片后点击提交' }}
|
||||
</span>
|
||||
<c-button
|
||||
type="primary"
|
||||
class="ar-submit"
|
||||
:disabled="!canSubmit"
|
||||
:style="{ backgroundColor: canSubmit ? '#18a058' : undefined }"
|
||||
@click="submit"
|
||||
>
|
||||
{{ processing ? '处理中…' : '提交修复' }}
|
||||
</c-button>
|
||||
<c-button v-if="resultUrl" @click="downloadResult">
|
||||
下载结果
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="ai-retouch" position="right" label="修图记录" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.ar-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
background: #fff;
|
||||
border: 1px solid rgba(128, 128, 128, 0.2);
|
||||
border-radius: 12px;
|
||||
padding: 14px 16px;
|
||||
}
|
||||
|
||||
// ---- tabs ----
|
||||
.ar-tabs {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
flex-shrink: 0;
|
||||
margin-bottom: 10px;
|
||||
flex-wrap: wrap;
|
||||
|
||||
.ar-tab {
|
||||
padding: 7px 16px;
|
||||
border-radius: 999px;
|
||||
border: none;
|
||||
background: rgba(128, 128, 128, 0.12);
|
||||
color: #666;
|
||||
font-size: 13.5px;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
|
||||
&.active {
|
||||
background: #18a058;
|
||||
color: #fff;
|
||||
font-weight: 600;
|
||||
}
|
||||
|
||||
&:not(.active):hover {
|
||||
background: rgba(128, 128, 128, 0.2);
|
||||
}
|
||||
}
|
||||
|
||||
.ar-tab-stats {
|
||||
margin-left: auto;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
}
|
||||
|
||||
// ---- warning ----
|
||||
.ar-warn {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
background: rgba(240, 160, 0, 0.1);
|
||||
border: 1px solid rgba(240, 160, 0, 0.45);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
margin-bottom: 10px;
|
||||
flex-shrink: 0;
|
||||
font-size: 12.5px;
|
||||
|
||||
.ar-warn-text {
|
||||
flex: 1;
|
||||
line-height: 1.6;
|
||||
}
|
||||
|
||||
.ar-warn-btn {
|
||||
flex-shrink: 0;
|
||||
border: 1px solid #e09000;
|
||||
background: transparent;
|
||||
color: #c07800;
|
||||
border-radius: 5px;
|
||||
padding: 3px 12px;
|
||||
font-size: 12.5px;
|
||||
cursor: pointer;
|
||||
|
||||
&:hover { background: rgba(240, 160, 0, 0.15); }
|
||||
}
|
||||
}
|
||||
|
||||
// ---- body ----
|
||||
.ar-body {
|
||||
display: flex;
|
||||
gap: 14px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
@media (max-width: 760px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.ar-left {
|
||||
flex: 1 1 55%;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ar-right {
|
||||
flex: 1 1 45%;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ar-drop {
|
||||
flex: 1;
|
||||
min-height: 180px;
|
||||
border: 2px dashed rgba(128, 128, 128, 0.45);
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
overflow: hidden;
|
||||
cursor: pointer;
|
||||
transition: border-color 0.2s, background-color 0.2s;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:hover,
|
||||
&.active {
|
||||
border-color: #18a058;
|
||||
background: rgba(24, 160, 88, 0.05);
|
||||
}
|
||||
|
||||
&.hasImg {
|
||||
cursor: default;
|
||||
padding: 8px;
|
||||
background: repeating-conic-gradient(#f5f5f5 0% 25%, #fff 0% 50%) 50% / 20px 20px;
|
||||
}
|
||||
|
||||
.ar-drop-hint {
|
||||
text-align: center;
|
||||
opacity: 0.7;
|
||||
|
||||
.icon { font-size: 40px; }
|
||||
.big { font-size: 18px; font-weight: 600; margin-top: 6px; }
|
||||
.sub { font-size: 12.5px; opacity: 0.7; margin-top: 5px; }
|
||||
}
|
||||
}
|
||||
|
||||
.ar-canvas-wrap {
|
||||
position: relative;
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
line-height: 0;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
display: block;
|
||||
}
|
||||
|
||||
.ar-mask {
|
||||
position: absolute;
|
||||
inset: 0;
|
||||
width: 100%;
|
||||
height: 100%;
|
||||
touch-action: none;
|
||||
}
|
||||
}
|
||||
|
||||
.ar-actions-left {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-top: 8px;
|
||||
flex-shrink: 0;
|
||||
flex-wrap: wrap;
|
||||
font-size: 12.5px;
|
||||
|
||||
.ar-brush-hint { opacity: 0.6; }
|
||||
.ar-brush-label { opacity: 0.85; min-width: 66px; }
|
||||
|
||||
.ar-brush {
|
||||
width: 120px;
|
||||
accent-color: #18a058;
|
||||
}
|
||||
}
|
||||
|
||||
.ar-empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
min-height: 160px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 8px;
|
||||
opacity: 0.5;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.ar-error {
|
||||
color: #d03050;
|
||||
font-size: 13px;
|
||||
padding: 12px;
|
||||
border: 1px solid rgba(208, 48, 80, 0.35);
|
||||
border-radius: 8px;
|
||||
}
|
||||
|
||||
.ar-result {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
height: 100%;
|
||||
overflow: auto;
|
||||
|
||||
@media (max-width: 760px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.ar-fig {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
margin: 0;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 8px;
|
||||
padding: 8px;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
background: repeating-conic-gradient(#f7f7f7 0% 25%, #fff 0% 50%) 50% / 16px 16px;
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
}
|
||||
|
||||
figcaption {
|
||||
text-align: center;
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
margin-top: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// ---- bottom ----
|
||||
.ar-bottom {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
margin-top: 10px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.ar-tip {
|
||||
margin-right: auto;
|
||||
font-size: 12.5px;
|
||||
opacity: 0.55;
|
||||
}
|
||||
|
||||
.ar-submit {
|
||||
background: #18a058 !important;
|
||||
color: #fff;
|
||||
min-width: 120px;
|
||||
font-weight: 600;
|
||||
|
||||
&:disabled {
|
||||
opacity: 0.45;
|
||||
cursor: not-allowed;
|
||||
}
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Wand } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.ai-retouch.title'),
|
||||
path: '/ai-retouch',
|
||||
description: translate('tools.ai-retouch.description'),
|
||||
keywords: ['ai', 'retouch', 'watermark', 'remove', 'background', 'upscale', 'face', 'repair', 'inpaint', '抠图', '去水印', '超分', '修复', '去背景', '修图'],
|
||||
component: () => import('./ai-retouch.vue'),
|
||||
icon: Wand,
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
<script setup lang="ts">
|
||||
import figlet from 'figlet';
|
||||
import TextareaCopyable from '@/components/TextareaCopyable.vue';
|
||||
|
||||
const input = ref('Ascii ART');
|
||||
const font = useStorage('ascii-text-drawer:font', 'Standard');
|
||||
const width = useStorage('ascii-text-drawer:width', 80);
|
||||
const output = ref('');
|
||||
const errored = ref(false);
|
||||
const processing = ref(false);
|
||||
|
||||
figlet.defaults({ fontPath: '//unpkg.com/figlet@1.6.0/fonts/' });
|
||||
|
||||
watchEffect(async () => {
|
||||
processing.value = true;
|
||||
try {
|
||||
const options: figlet.Options = {
|
||||
font: font.value as figlet.Fonts,
|
||||
width: width.value,
|
||||
whitespaceBreak: true,
|
||||
};
|
||||
output.value = await (new Promise<string>((resolve, reject) =>
|
||||
figlet.text(input.value, options,
|
||||
(err, text) => {
|
||||
if (err) {
|
||||
reject(err);
|
||||
return;
|
||||
}
|
||||
|
||||
resolve(text ?? '');
|
||||
})));
|
||||
errored.value = false;
|
||||
}
|
||||
catch (e: any) {
|
||||
errored.value = true;
|
||||
}
|
||||
processing.value = false;
|
||||
});
|
||||
|
||||
const fonts = ['1Row', '3-D', '3D Diagonal', '3D-ASCII', '3x5', '4Max', '5 Line Oblique', 'AMC 3 Line', 'AMC 3 Liv1', 'AMC AAA01', 'AMC Neko', 'AMC Razor', 'AMC Razor2', 'AMC Slash', 'AMC Slider', 'AMC Thin', 'AMC Tubes', 'AMC Untitled', 'ANSI Shadow', 'ASCII New Roman', 'Acrobatic', 'Alligator', 'Alligator2', 'Alpha', 'Alphabet', 'Arrows', 'Avatar', 'B1FF', 'B1FF', 'Banner', 'Banner3-D', 'Banner3', 'Banner4', 'Barbwire', 'Basic', 'Bear', 'Bell', 'Benjamin', 'Big Chief', 'Big Money-ne', 'Big Money-nw', 'Big Money-se', 'Big Money-sw', 'Big', 'Bigfig', 'Binary', 'Block', 'Blocks', 'Bloody', 'Bolger', 'Braced', 'Bright', 'Broadway KB', 'Broadway', 'Bubble', 'Bulbhead', 'Caligraphy', 'Caligraphy2', 'Calvin S', 'Cards', 'Catwalk', 'Chiseled', 'Chunky', 'Coinstak', 'Cola', 'Colossal', 'Computer', 'Contessa', 'Contrast', 'Cosmike', 'Crawford', 'Crawford2', 'Crazy', 'Cricket', 'Cursive', 'Cyberlarge', 'Cybermedium', 'Cybersmall', 'Cygnet', 'DANC4', 'DOS Rebel', 'DWhistled', 'Dancing Font', 'Decimal', 'Def Leppard', 'Delta Corps Priest 1', 'Diamond', 'Diet Cola', 'Digital', 'Doh', 'Doom', 'Dot Matrix', 'Double Shorts', 'Double', 'Dr Pepper', 'Efti Chess', 'Efti Font', 'Efti Italic', 'Efti Piti', 'Efti Robot', 'Efti Wall', 'Efti Water', 'Electronic', 'Elite', 'Epic', 'Fender', 'Filter', 'Fire Font-k', 'Fire Font-s', 'Flipped', 'Flower Power', 'Four Tops', 'Fraktur', 'Fun Face', 'Fun Faces', 'Fuzzy', 'Georgi16', 'Georgia11', 'Ghost', 'Ghoulish', 'Glenyn', 'Goofy', 'Gothic', 'Graceful', 'Gradient', 'Graffiti', 'Greek', 'Heart Left', 'Heart Right', 'Henry 3D', 'Hex', 'Hieroglyphs', 'Hollywood', 'Horizontal Left', 'Horizontal Right', 'ICL-1900', 'Impossible', 'Invita', 'Isometric1', 'Isometric2', 'Isometric3', 'Isometric4', 'Italic', 'Ivrit', 'JS Block Letters', 'JS Bracket Letters', 'JS Capital Curves', 'JS Cursive', 'JS Stick Letters', 'Jacky', 'Jazmine', 'Jerusalem', 'Katakana', 'Kban', 'Keyboard', 'Knob', 'Konto Slant', 'Konto', 'LCD', 'Larry 3D 2', 'Larry 3D', 'Lean', 'Letters', 'Lil Devil', 'Line Blocks', 'Linux', 'Lockergnome', 'Madrid', 'Marquee', 'Maxfour', 'Merlin1', 'Merlin2', 'Mike', 'Mini', 'Mirror', 'Mnemonic', 'Modular', 'Morse', 'Morse2', 'Moscow', 'Mshebrew210', 'Muzzle', 'NScript', 'NT Greek', 'NV Script', 'Nancyj-Fancy', 'Nancyj-Improved', 'Nancyj-Underlined', 'Nancyj', 'Nipples', 'O8', 'OS2', 'Octal', 'Ogre', 'Old Banner', 'Patorjk\'s Cheese', 'Patorjk-HeX', 'Pawp', 'Peaks Slant', 'Peaks', 'Pebbles', 'Pepper', 'Poison', 'Puffy', 'Puzzle', 'Pyramid', 'Rammstein', 'Rectangles', 'Red Phoenix', 'Relief', 'Relief2', 'Reverse', 'Roman', 'Rot13', 'Rot13', 'Rotated', 'Rounded', 'Rowan Cap', 'Rozzo', 'Runic', 'Runyc', 'S Blood', 'SL Script', 'Santa Clara', 'Script', 'Serifcap', 'Shadow', 'Shimrod', 'Short', 'Slant Relief', 'Slant', 'Slide', 'Small Caps', 'Small Isometric1', 'Small Keyboard', 'Small Poison', 'Small Script', 'Small Shadow', 'Small Slant', 'Small Tengwar', 'Small', 'Soft', 'Speed', 'Spliff', 'Stacey', 'Stampate', 'Stampatello', 'Standard', 'Star Strips', 'Star Wars', 'Stellar', 'Stforek', 'Stick Letters', 'Stop', 'Straight', 'Stronger Than All', 'Sub-Zero', 'Swamp Land', 'Swan', 'Sweet', 'THIS', 'Tanja', 'Tengwar', 'Term', 'Test1', 'The Edge', 'Thick', 'Thin', 'Thorned', 'Three Point', 'Ticks Slant', 'Ticks', 'Tiles', 'Tinker-Toy', 'Tombstone', 'Train', 'Trek', 'Tsalagi', 'Tubular', 'Twisted', 'Two Point', 'USA Flag', 'Univers', 'Varsity', 'Wavy', 'Weird', 'Wet Letter', 'Whimsy', 'Wow'];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card style="max-width: 600px;">
|
||||
<c-input-text
|
||||
v-model:value="input"
|
||||
label="Your text:"
|
||||
placeholder="Your text to draw"
|
||||
raw-text
|
||||
multiline
|
||||
rows="4"
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<n-grid cols="4" x-gap="12" w-full>
|
||||
<n-gi span="2">
|
||||
<c-select
|
||||
v-model:value="font"
|
||||
label-position="top"
|
||||
label="Font:"
|
||||
:options="fonts"
|
||||
searchable="true"
|
||||
placeholder="Select font to use"
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi span="2">
|
||||
<n-form-item label="Width:" label-placement="top" label-width="100" :show-feedback="false">
|
||||
<n-input-number v-model:value="width" min="0" max="10000" w-full placeholder="Width of the text" />
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div v-if="processing" flex items-center justify-center>
|
||||
<n-spin size="medium" />
|
||||
<span class="ml-2">Loading font...</span>
|
||||
</div>
|
||||
|
||||
<c-alert v-if="errored" mt-1 text-center type="error">
|
||||
Current settings resulted in error.
|
||||
</c-alert>
|
||||
|
||||
<n-form-item v-if="!processing && !errored" label="Ascii Art text:">
|
||||
<TextareaCopyable
|
||||
:value="output"
|
||||
mb-1 mt-1
|
||||
copy-placement="outside"
|
||||
/>
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Artboard } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'ASCII Art Text Generator',
|
||||
path: '/ascii-text-drawer',
|
||||
description: 'Create ASCII art text with many fonts and styles.',
|
||||
keywords: ['ascii', 'asciiart', 'text', 'drawer'],
|
||||
component: () => import('./ascii-text-drawer.vue'),
|
||||
icon: Artboard,
|
||||
createdAt: new Date('2024-03-03'),
|
||||
});
|
||||
@@ -0,0 +1,140 @@
|
||||
<script setup lang="ts">
|
||||
import { useBase64 } from '@vueuse/core';
|
||||
import type { Ref } from 'vue';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { getExtensionFromMimeType, getMimeTypeFromBase64, previewImageFromBase64, useDownloadFileFromBase64Refs } from '@/composable/downloadBase64';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { isValidBase64 } from '@/utils/base64';
|
||||
|
||||
const fileName = ref('file');
|
||||
const fileExtension = ref('');
|
||||
const base64Input = ref('');
|
||||
const { download } = useDownloadFileFromBase64Refs(
|
||||
{
|
||||
source: base64Input,
|
||||
filename: fileName,
|
||||
extension: fileExtension,
|
||||
});
|
||||
const base64InputValidation = useValidation({
|
||||
source: base64Input,
|
||||
rules: [
|
||||
{
|
||||
message: 'Invalid base 64 string',
|
||||
validator: value => isValidBase64(value.trim()),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
watch(
|
||||
base64Input,
|
||||
(newValue, _) => {
|
||||
const { mimeType } = getMimeTypeFromBase64({ base64String: newValue });
|
||||
if (mimeType) {
|
||||
fileExtension.value = getExtensionFromMimeType(mimeType) || fileExtension.value;
|
||||
}
|
||||
},
|
||||
);
|
||||
|
||||
function previewImage() {
|
||||
if (!base64InputValidation.isValid) {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
const image = previewImageFromBase64(base64Input.value);
|
||||
image.style.maxWidth = '100%';
|
||||
image.style.maxHeight = '400px';
|
||||
const previewContainer = document.getElementById('previewContainer');
|
||||
if (previewContainer) {
|
||||
previewContainer.innerHTML = '';
|
||||
previewContainer.appendChild(image);
|
||||
}
|
||||
}
|
||||
catch (_) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
function downloadFile() {
|
||||
if (!base64InputValidation.isValid) {
|
||||
return;
|
||||
}
|
||||
|
||||
try {
|
||||
download();
|
||||
}
|
||||
catch (_) {
|
||||
//
|
||||
}
|
||||
}
|
||||
|
||||
const fileInput = ref() as Ref<File>;
|
||||
const { base64: fileBase64 } = useBase64(fileInput);
|
||||
const { copy: copyFileBase64 } = useCopy({ source: fileBase64, text: 'Base64 string copied to the clipboard' });
|
||||
|
||||
async function onUpload(file: File) {
|
||||
if (file) {
|
||||
fileInput.value = file;
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="Base64 to file">
|
||||
<n-grid cols="3" x-gap="12">
|
||||
<n-gi span="2">
|
||||
<c-input-text
|
||||
v-model:value="fileName"
|
||||
label="File Name"
|
||||
placeholder="Download filename"
|
||||
mb-2
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi>
|
||||
<c-input-text
|
||||
v-model:value="fileExtension"
|
||||
label="Extension"
|
||||
placeholder="Extension"
|
||||
mb-2
|
||||
/>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<c-input-text
|
||||
v-model:value="base64Input"
|
||||
multiline
|
||||
placeholder="Put your base64 file string here..."
|
||||
rows="5"
|
||||
:validation="base64InputValidation"
|
||||
mb-2
|
||||
/>
|
||||
|
||||
<div flex justify-center py-2>
|
||||
<div id="previewContainer" />
|
||||
</div>
|
||||
|
||||
<div flex justify-center gap-3>
|
||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="previewImage()">
|
||||
Preview image
|
||||
</c-button>
|
||||
<c-button :disabled="base64Input === '' || !base64InputValidation.isValid" @click="downloadFile()">
|
||||
Download file
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="File to base64">
|
||||
<c-file-upload title="Drag and drop a file here, or click to select a file" @file-upload="onUpload" />
|
||||
<c-input-text :value="fileBase64" multiline readonly placeholder="File in base64 will be here" rows="5" my-2 />
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyFileBase64()">
|
||||
Copy
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-upload-trigger) {
|
||||
width: 100%;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { FileDigit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.base64-file-converter.title'),
|
||||
path: '/base64-file-converter',
|
||||
description: translate('tools.base64-file-converter.description'),
|
||||
keywords: ['base64', 'converter', 'upload', 'image', 'file', 'conversion', 'web', 'data', 'format'],
|
||||
component: () => import('./base64-file-converter.vue'),
|
||||
icon: FileDigit,
|
||||
});
|
||||
@@ -0,0 +1,90 @@
|
||||
<script setup lang="ts">
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { base64ToText, isValidBase64, textToBase64 } from '@/utils/base64';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const encodeUrlSafe = useStorage('base64-string-converter--encode-url-safe', false);
|
||||
const decodeUrlSafe = useStorage('base64-string-converter--decode-url-safe', false);
|
||||
|
||||
const textInput = ref('');
|
||||
const base64Output = computed(() => textToBase64(textInput.value, { makeUrlSafe: encodeUrlSafe.value }));
|
||||
const { copy: copyTextBase64 } = useCopy({ source: base64Output, text: 'Base64 string copied to the clipboard' });
|
||||
|
||||
const base64Input = ref('');
|
||||
const textOutput = computed(() =>
|
||||
withDefaultOnError(() => base64ToText(base64Input.value.trim(), { makeUrlSafe: decodeUrlSafe.value }), ''),
|
||||
);
|
||||
const { copy: copyText } = useCopy({ source: textOutput, text: 'String copied to the clipboard' });
|
||||
const b64ValidationRules = [
|
||||
{
|
||||
message: 'Invalid base64 string',
|
||||
validator: (value: string) => isValidBase64(value.trim(), { makeUrlSafe: decodeUrlSafe.value }),
|
||||
},
|
||||
];
|
||||
const b64ValidationWatch = [decodeUrlSafe];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="String to base64">
|
||||
<n-form-item label="Encode URL safe" label-placement="left">
|
||||
<n-switch v-model:value="encodeUrlSafe" />
|
||||
</n-form-item>
|
||||
<c-input-text
|
||||
v-model:value="textInput"
|
||||
multiline
|
||||
placeholder="Put your string here..."
|
||||
rows="5"
|
||||
label="String to encode"
|
||||
raw-text
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
label="Base64 of string"
|
||||
:value="base64Output"
|
||||
multiline
|
||||
readonly
|
||||
placeholder="The base64 encoding of your string will be here"
|
||||
rows="5"
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyTextBase64()">
|
||||
Copy base64
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Base64 to string">
|
||||
<n-form-item label="Decode URL safe" label-placement="left">
|
||||
<n-switch v-model:value="decodeUrlSafe" />
|
||||
</n-form-item>
|
||||
<c-input-text
|
||||
v-model:value="base64Input"
|
||||
multiline
|
||||
placeholder="Your base64 string..."
|
||||
rows="5"
|
||||
:validation-rules="b64ValidationRules"
|
||||
:validation-watch="b64ValidationWatch"
|
||||
label="Base64 string to decode"
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<c-input-text
|
||||
v-model:value="textOutput"
|
||||
label="Decoded string"
|
||||
placeholder="The decoded string will be here"
|
||||
multiline
|
||||
rows="5"
|
||||
readonly
|
||||
mb-5
|
||||
/>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button @click="copyText()">
|
||||
Copy decoded string
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { FileDigit } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.base64-string-converter.title'),
|
||||
path: '/base64-string-converter',
|
||||
description: translate('tools.base64-string-converter.description'),
|
||||
keywords: ['base64', 'converter', 'conversion', 'web', 'data', 'format', 'atob', 'btoa'],
|
||||
component: () => import('./base64-string-converter.vue'),
|
||||
icon: FileDigit,
|
||||
redirectFrom: ['/file-to-base64', '/base64-converter'],
|
||||
});
|
||||
@@ -0,0 +1,46 @@
|
||||
<script setup lang="ts">
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { textToBase64 } from '@/utils/base64';
|
||||
|
||||
const username = ref('');
|
||||
const password = ref('');
|
||||
const header = computed(() => `Authorization: Basic ${textToBase64(`${username.value}:${password.value}`)}`);
|
||||
|
||||
const { copy } = useCopy({ source: header, text: 'Header copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-input-text v-model:value="username" label="Username" placeholder="Your username..." clearable raw-text mb-5 />
|
||||
<c-input-text
|
||||
v-model:value="password"
|
||||
label="Password"
|
||||
placeholder="Your password..."
|
||||
clearable
|
||||
raw-text
|
||||
mb-2
|
||||
type="password"
|
||||
/>
|
||||
|
||||
<c-card>
|
||||
<n-statistic label="Authorization header:" class="header">
|
||||
<n-scrollbar x-scrollable style="max-width: 550px; margin-bottom: -10px; padding-bottom: 10px" trigger="none">
|
||||
{{ header }}
|
||||
</n-scrollbar>
|
||||
</n-statistic>
|
||||
</c-card>
|
||||
<div mt-5 flex justify-center>
|
||||
<c-button @click="copy()">
|
||||
Copy header
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(.n-statistic-value__content) {
|
||||
font-family: monospace;
|
||||
font-size: 17px !important;
|
||||
white-space: nowrap;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,22 @@
|
||||
import { PasswordRound } from '@vicons/material';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.basic-auth-generator.title'),
|
||||
path: '/basic-auth-generator',
|
||||
description: translate('tools.basic-auth-generator.description'),
|
||||
keywords: [
|
||||
'basic',
|
||||
'auth',
|
||||
'generator',
|
||||
'username',
|
||||
'password',
|
||||
'base64',
|
||||
'authentication',
|
||||
'header',
|
||||
'authorization',
|
||||
],
|
||||
component: () => import('./basic-auth-generator.vue'),
|
||||
icon: PasswordRound,
|
||||
});
|
||||
@@ -0,0 +1,437 @@
|
||||
<script setup lang="ts">
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
|
||||
const genHist = useGenHistory('barcode-batch');
|
||||
import bwipjs from 'bwip-js';
|
||||
import { zipSync } from 'fflate';
|
||||
|
||||
interface BarcodeType {
|
||||
label: string;
|
||||
value: string;
|
||||
hint?: string;
|
||||
}
|
||||
|
||||
const barcodeTypes: BarcodeType[] = [
|
||||
{ label: 'EAN 8', value: 'ean8', hint: '7-8 位数字' },
|
||||
{ label: 'EAN 13', value: 'ean13', hint: '12-13 位数字' },
|
||||
{ label: 'UPC-A', value: 'upca', hint: '11-12 位数字' },
|
||||
{ label: 'standard 2 of 5 (industrial)', value: 'industrial2of5', hint: '纯数字' },
|
||||
{ label: 'interleaved 2 of 5', value: 'interleaved2of5', hint: '偶数位数字' },
|
||||
{ label: 'CODE11', value: 'code11' },
|
||||
{ label: 'CODE39', value: 'code39' },
|
||||
{ label: 'CODE93', value: 'code93' },
|
||||
{ label: 'CODE128', value: 'code128' },
|
||||
{ label: 'Codabar', value: 'rationalizedCodabar', hint: '如 A123456A' },
|
||||
{ label: 'MSI', value: 'msi', hint: '纯数字' },
|
||||
{ label: 'Data Matrix', value: 'datamatrix' },
|
||||
];
|
||||
|
||||
const MM = 72 / 25.4; // px per mm at 72dpi
|
||||
|
||||
const input = ref('');
|
||||
const barcodeType = ref('code128');
|
||||
const barcodeWidth = ref(2); // module scale
|
||||
const barcodeHeight = ref(80); // bar height in px
|
||||
const fontSize = ref(14); // text height in px
|
||||
const previewWidth = ref(280); // display width in px
|
||||
const foreColor = ref('#000000');
|
||||
const backgroundColor = ref('#ffffff');
|
||||
const showValue = ref(true);
|
||||
const trimBlank = ref(true);
|
||||
const doubleRow = ref(false);
|
||||
|
||||
const results = ref<{ text: string; url?: string; error?: string }[]>([]);
|
||||
const generating = ref(false);
|
||||
|
||||
const lines = computed(() => {
|
||||
const raw = input.value.split('\n');
|
||||
const list = trimBlank.value ? raw.map(l => l.trim()).filter(Boolean) : raw;
|
||||
return list.slice(0, 2000);
|
||||
});
|
||||
|
||||
function generateOne(text: string): { url?: string; error?: string } {
|
||||
try {
|
||||
const canvas = document.createElement('canvas');
|
||||
const scale = barcodeWidth.value;
|
||||
bwipjs.toCanvas(canvas, {
|
||||
bcid: barcodeType.value,
|
||||
text,
|
||||
scaleX: scale,
|
||||
scaleY: scale,
|
||||
height: barcodeHeight.value / (MM * scale),
|
||||
textsize: fontSize.value / scale,
|
||||
includetext: showValue.value,
|
||||
paddingwidth: 10,
|
||||
paddingtop: 4,
|
||||
paddingbottom: 4,
|
||||
barcolor: foreColor.value,
|
||||
background: backgroundColor.value,
|
||||
} as any);
|
||||
return { url: canvas.toDataURL('image/png') };
|
||||
}
|
||||
catch (e: any) {
|
||||
return { error: e?.message ?? String(e) };
|
||||
}
|
||||
}
|
||||
|
||||
function generate() {
|
||||
if (!lines.value.length) {
|
||||
results.value = [];
|
||||
return;
|
||||
}
|
||||
generating.value = true;
|
||||
// defer heavy loop so the UI can paint the loading state first
|
||||
setTimeout(() => {
|
||||
results.value = lines.value.map((text) => {
|
||||
const { url, error } = generateOne(text);
|
||||
return { text, url, error };
|
||||
});
|
||||
generating.value = false;
|
||||
}, 50);
|
||||
}
|
||||
|
||||
function downloadOne(item: { text: string; url?: string }) {
|
||||
if (!item.url) {
|
||||
return;
|
||||
}
|
||||
const a = document.createElement('a');
|
||||
a.href = item.url;
|
||||
a.download = `barcode-${sanitize(item.text)}.png`;
|
||||
a.click();
|
||||
genHist.add({ title: item.text.slice(0, 60), detail: '单个条码下载' });
|
||||
}
|
||||
|
||||
function sanitize(text: string) {
|
||||
return text.replace(/[^\w\u4e00-\u9fa5-]+/g, '_').slice(0, 60) || 'barcode';
|
||||
}
|
||||
|
||||
function downloadAll() {
|
||||
const valid = results.value.filter(r => r.url);
|
||||
if (!valid.length) {
|
||||
return;
|
||||
}
|
||||
const files: Record<string, Uint8Array> = {};
|
||||
valid.forEach((r, i) => {
|
||||
const base64 = r.url!.split(',')[1];
|
||||
const bin = atob(base64);
|
||||
const bytes = new Uint8Array(bin.length);
|
||||
for (let j = 0; j < bin.length; j++) {
|
||||
bytes[j] = bin.charCodeAt(j);
|
||||
}
|
||||
files[`${String(i + 1).padStart(3, '0')}-${sanitize(r.text)}.png`] = bytes;
|
||||
});
|
||||
const zipped = zipSync(files, { level: 6 });
|
||||
const blob = new Blob([zipped], { type: 'application/zip' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'barcodes.zip';
|
||||
a.click();
|
||||
genHist.add({ title: `${valid.length} 个条码打包`, detail: `${valid[0]?.text.slice(0, 40)}…` });
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function loadExample() {
|
||||
barcodeType.value = 'code128';
|
||||
input.value = [
|
||||
'https://it-tools.tech',
|
||||
'IT-TOOLS-2024',
|
||||
'HELLO-WORLD',
|
||||
'BATCH-001',
|
||||
'11112222',
|
||||
].join('\n');
|
||||
generate();
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
input.value = '';
|
||||
results.value = [];
|
||||
}
|
||||
|
||||
// regenerate automatically when options change (debounced)
|
||||
let timer: ReturnType<typeof setTimeout> | undefined;
|
||||
watch([input, barcodeType, barcodeWidth, barcodeHeight, fontSize, foreColor, backgroundColor, showValue, trimBlank], () => {
|
||||
clearTimeout(timer);
|
||||
timer = setTimeout(generate, 400);
|
||||
});
|
||||
|
||||
// fit the page to the viewport: no page scrolling, panes scroll internally
|
||||
const rootEl = ref<HTMLElement>();
|
||||
const rootStyle = ref<Record<string, string>>({});
|
||||
|
||||
function fit() {
|
||||
const el = rootEl.value;
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
const top = el.getBoundingClientRect().top;
|
||||
const height = Math.max(300, window.innerHeight - top - 12);
|
||||
rootStyle.value = { height: `${height}px`, flex: '1 1 100%' };
|
||||
}
|
||||
|
||||
let observer: ResizeObserver | undefined;
|
||||
onMounted(() => {
|
||||
fit();
|
||||
window.addEventListener('resize', fit);
|
||||
observer = new ResizeObserver(() => fit());
|
||||
if (rootEl.value) {
|
||||
observer.observe(rootEl.value);
|
||||
}
|
||||
generate();
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', fit);
|
||||
observer?.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="rootEl" class="batch-bc-root" :style="rootStyle">
|
||||
<!-- toolbar: actions pinned right -->
|
||||
<div class="toolbar">
|
||||
<div class="stats">
|
||||
<template v-if="results.length">
|
||||
共 {{ results.length }} 个条形码<template v-if="results.filter(r => r.error).length">,{{ results.filter(r => r.error).length }} 个失败</template>
|
||||
</template>
|
||||
</div>
|
||||
<c-button type="primary" @click="generate">
|
||||
生成条形码
|
||||
</c-button>
|
||||
<c-button @click="downloadAll">
|
||||
打包下载全部
|
||||
</c-button>
|
||||
<c-button @click="loadExample">
|
||||
举个例子
|
||||
</c-button>
|
||||
<c-button @click="clearAll">
|
||||
清空
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<div class="body">
|
||||
<!-- left: form -->
|
||||
<div class="form-pane">
|
||||
<c-input-text
|
||||
v-model:value="input"
|
||||
label="条形码数值(每行一个)"
|
||||
multiline
|
||||
:rows="3"
|
||||
placeholder="每行一个条形码数值,点「举个例子」看格式"
|
||||
mb-8px
|
||||
/>
|
||||
<div class="form-grid">
|
||||
<n-form-item label="码制" size="small" class="span2">
|
||||
<c-select
|
||||
v-model:value="barcodeType"
|
||||
:options="barcodeTypes.map(t => ({ label: t.label + (t.hint ? ` (${t.hint})` : ''), value: t.value }))"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item label="条码宽度" size="small">
|
||||
<n-input-number v-model:value="barcodeWidth" :min="1" :max="6" style="width:100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="条码高度" size="small">
|
||||
<n-input-number v-model:value="barcodeHeight" :min="30" :max="200" :step="10" style="width:100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="文字大小" size="small">
|
||||
<n-input-number v-model:value="fontSize" :min="8" :max="32" style="width:100%" />
|
||||
</n-form-item>
|
||||
<n-form-item label="预览宽度" size="small">
|
||||
<n-slider v-model:value="previewWidth" :min="120" :max="600" :step="10" />
|
||||
</n-form-item>
|
||||
<n-form-item label="前景色" size="small">
|
||||
<n-color-picker v-model:value="foreColor" :modes="['hex']" :show-alpha="false" />
|
||||
</n-form-item>
|
||||
<n-form-item label="背景色" size="small">
|
||||
<n-color-picker v-model:value="backgroundColor" :modes="['hex']" :show-alpha="false" />
|
||||
</n-form-item>
|
||||
<n-form-item label="显示数值" size="small">
|
||||
<n-switch v-model:value="showValue" size="small" />
|
||||
</n-form-item>
|
||||
<n-form-item label="去空白行" size="small">
|
||||
<n-switch v-model:value="trimBlank" size="small" />
|
||||
</n-form-item>
|
||||
<n-form-item label="一行两个" size="small">
|
||||
<n-switch v-model:value="doubleRow" size="small" />
|
||||
</n-form-item>
|
||||
<div class="span2 hint">
|
||||
条码宽度=模块精细度,条码高度=条纹像素高,改完自动重新生成
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- right: results -->
|
||||
<div class="result-pane">
|
||||
<n-spin :show="generating">
|
||||
<div v-if="!results.length" class="empty">
|
||||
输入数值后自动生成,或点击「举个例子」
|
||||
</div>
|
||||
<div
|
||||
v-else
|
||||
class="result-grid"
|
||||
:style="{ gridTemplateColumns: `repeat(${doubleRow ? 2 : 1}, minmax(0, 1fr))` }"
|
||||
>
|
||||
<div v-for="(item, idx) in results" :key="idx" class="result-item">
|
||||
<template v-if="item.url">
|
||||
<img
|
||||
:src="item.url"
|
||||
:style="{ width: previewWidth + 'px', maxWidth: '100%', height: 'auto' }"
|
||||
:alt="item.text"
|
||||
>
|
||||
<div class="item-actions">
|
||||
<span class="item-text">{{ item.text }}</span>
|
||||
<c-button size="small" @click="downloadOne(item)">
|
||||
下载
|
||||
</c-button>
|
||||
</div>
|
||||
</template>
|
||||
<div v-else class="item-error">
|
||||
{{ item.text }}:{{ item.error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-spin>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="barcode-batch" position="bottom" label="生成记录" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.batch-bc-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
padding-bottom: 12px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.stats {
|
||||
margin-right: auto;
|
||||
font-size: 13px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 16px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
@media (max-width: 760px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.form-pane {
|
||||
flex: 0 0 400px;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
|
||||
@media (max-width: 760px) {
|
||||
flex: 0 0 auto;
|
||||
overflow-y: visible;
|
||||
}
|
||||
}
|
||||
|
||||
.form-grid {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 1fr;
|
||||
gap: 0 12px;
|
||||
|
||||
.span2 {
|
||||
grid-column: span 2;
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
opacity: 0.55;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
// compact form items
|
||||
:deep(.n-form-item) {
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
:deep(.n-form-item-label) {
|
||||
padding-bottom: 4px !important;
|
||||
font-size: 12px;
|
||||
justify-content: flex-start;
|
||||
}
|
||||
}
|
||||
|
||||
.result-pane {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
overflow-y: auto;
|
||||
padding-right: 4px;
|
||||
}
|
||||
|
||||
.empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
min-height: 120px;
|
||||
opacity: 0.55;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.result-grid {
|
||||
display: grid;
|
||||
gap: 14px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
gap: 6px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.25);
|
||||
border-radius: 8px;
|
||||
padding: 12px;
|
||||
box-sizing: border-box;
|
||||
|
||||
img {
|
||||
display: block;
|
||||
object-fit: contain;
|
||||
}
|
||||
}
|
||||
|
||||
.item-actions {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
width: 100%;
|
||||
justify-content: space-between;
|
||||
}
|
||||
|
||||
.item-text {
|
||||
font-size: 12px;
|
||||
opacity: 0.7;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.item-error {
|
||||
font-size: 12px;
|
||||
color: #d03050;
|
||||
word-break: break-all;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Barcode } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.barcode-batch-generator.title'),
|
||||
path: '/barcode-batch-generator',
|
||||
description: translate('tools.barcode-batch-generator.description'),
|
||||
keywords: ['barcode', 'batch', 'code128', 'code39', 'ean', 'upc', 'product', 'label', 'print', 'generator', '条形码', '批量', '条码', '码'],
|
||||
component: () => import('./barcode-batch-generator.vue'),
|
||||
icon: Barcode,
|
||||
});
|
||||
@@ -0,0 +1,68 @@
|
||||
<script setup lang="ts">
|
||||
import { compareSync, hashSync } from 'bcryptjs';
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
|
||||
const input = ref('');
|
||||
const saltCount = ref(10);
|
||||
const hashed = computed(() => hashSync(input.value, saltCount.value));
|
||||
const { copy } = useCopy({ source: hashed, text: 'Hashed string copied to the clipboard' });
|
||||
|
||||
const compareString = ref('');
|
||||
const compareHash = ref('');
|
||||
const compareMatch = computed(() => compareSync(compareString.value, compareHash.value));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card title="Hash">
|
||||
<c-input-text
|
||||
v-model:value="input"
|
||||
placeholder="Your string to bcrypt..."
|
||||
raw-text
|
||||
label="Your string: "
|
||||
label-position="left"
|
||||
label-align="right"
|
||||
label-width="120px"
|
||||
mb-2
|
||||
/>
|
||||
<n-form-item label="Salt count: " label-placement="left" label-width="120">
|
||||
<n-input-number v-model:value="saltCount" placeholder="Salt rounds..." :max="100" :min="0" w-full />
|
||||
</n-form-item>
|
||||
|
||||
<c-input-text :value="hashed" readonly text-center />
|
||||
|
||||
<div mt-5 flex justify-center>
|
||||
<c-button @click="copy()">
|
||||
Copy hash
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card title="Compare string with hash">
|
||||
<n-form label-width="120">
|
||||
<n-form-item label="Your string: " label-placement="left">
|
||||
<c-input-text v-model:value="compareString" placeholder="Your string to compare..." raw-text />
|
||||
</n-form-item>
|
||||
<n-form-item label="Your hash: " label-placement="left">
|
||||
<c-input-text v-model:value="compareHash" placeholder="Your hash to compare..." raw-text />
|
||||
</n-form-item>
|
||||
<n-form-item label="Do they match ? " label-placement="left" :show-feedback="false">
|
||||
<div class="compare-result" :class="{ positive: compareMatch }">
|
||||
{{ compareMatch ? 'Yes' : 'No' }}
|
||||
</div>
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.compare-result {
|
||||
color: v-bind('themeVars.errorColor');
|
||||
|
||||
&.positive {
|
||||
color: v-bind('themeVars.successColor');
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { LockSquare } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.bcrypt.title'),
|
||||
path: '/bcrypt',
|
||||
description: translate('tools.bcrypt.description'),
|
||||
keywords: ['bcrypt', 'hash', 'compare', 'password', 'salt', 'round', 'storage', 'crypto'],
|
||||
component: () => import('./bcrypt.vue'),
|
||||
icon: LockSquare,
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export { computeAverage, computeVariance, arrayToMarkdownTable };
|
||||
|
||||
function computeAverage({ data }: { data: number[] }) {
|
||||
if (data.length === 0) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return _.sum(data) / data.length;
|
||||
}
|
||||
|
||||
function computeVariance({ data }: { data: number[] }) {
|
||||
const mean = computeAverage({ data });
|
||||
|
||||
const squaredDiffs = data.map(value => (value - mean) ** 2);
|
||||
|
||||
return computeAverage({ data: squaredDiffs });
|
||||
}
|
||||
|
||||
function arrayToMarkdownTable({ data, headerMap = {} }: { data: Record<string, unknown>[]; headerMap?: Record<string, string> }) {
|
||||
if (!Array.isArray(data) || data.length === 0) {
|
||||
return '';
|
||||
}
|
||||
|
||||
const headers = Object.keys(data[0]);
|
||||
const rows = data.map(obj => Object.values(obj));
|
||||
|
||||
const headerRow = `| ${headers.map(header => headerMap[header] ?? header).join(' | ')} |`;
|
||||
const separatorRow = `| ${headers.map(() => '---').join(' | ')} |`;
|
||||
const dataRows = rows.map(row => `| ${row.join(' | ')} |`).join('\n');
|
||||
|
||||
return `${headerRow}\n${separatorRow}\n${dataRows}`;
|
||||
}
|
||||
@@ -0,0 +1,146 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus, Trash } from '@vicons/tabler';
|
||||
import { useStorage } from '@vueuse/core';
|
||||
import _ from 'lodash';
|
||||
|
||||
import { arrayToMarkdownTable, computeAverage, computeVariance } from './benchmark-builder.models';
|
||||
import DynamicValues from './dynamic-values.vue';
|
||||
import { useCopy } from '@/composable/copy';
|
||||
|
||||
const suites = useStorage('benchmark-builder:suites', [
|
||||
{ title: 'Suite 1', data: [5, 10] },
|
||||
{ title: 'Suite 2', data: [8, 12] },
|
||||
]);
|
||||
|
||||
const unit = useStorage('benchmark-builder:unit', '');
|
||||
|
||||
const round = (v: number) => Math.round(v * 1000) / 1000;
|
||||
|
||||
const results = computed(() => {
|
||||
return suites.value
|
||||
.map(({ data: dirtyData, title }) => {
|
||||
const data = dirtyData.filter(_.isNumber);
|
||||
|
||||
return {
|
||||
title,
|
||||
size: data.length,
|
||||
mean: computeAverage({ data }),
|
||||
variance: computeVariance({ data }),
|
||||
};
|
||||
})
|
||||
.sort((a, b) => a.mean - b.mean)
|
||||
.map(({ mean, variance, size, title }, index, suites) => {
|
||||
const cleanUnit = unit.value.trim();
|
||||
const bestMean: number = suites[0].mean;
|
||||
const deltaWithBestMean = mean - bestMean;
|
||||
const ratioWithBestMean = bestMean === 0 ? '∞' : round(mean / bestMean);
|
||||
|
||||
const comparisonValues: string
|
||||
= (index !== 0 && bestMean !== mean) ? ` (+${round(deltaWithBestMean)}${cleanUnit} ; x${ratioWithBestMean})` : '';
|
||||
|
||||
return {
|
||||
position: index + 1,
|
||||
title,
|
||||
mean: `${round(mean)}${cleanUnit}${comparisonValues}`,
|
||||
variance: `${round(variance)}${cleanUnit}${cleanUnit ? '²' : ''}`,
|
||||
size,
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
const { copy } = useCopy({ createToast: false });
|
||||
|
||||
const header = {
|
||||
position: 'Position',
|
||||
title: 'Suite',
|
||||
size: 'Samples',
|
||||
mean: 'Mean',
|
||||
variance: 'Variance',
|
||||
};
|
||||
|
||||
function copyAsMarkdown() {
|
||||
copy(arrayToMarkdownTable({ data: results.value, headerMap: header }));
|
||||
}
|
||||
|
||||
function copyAsBulletList() {
|
||||
const bulletList = results.value
|
||||
.flatMap(({ title, ...sections }) => {
|
||||
return [
|
||||
` - ${title}`,
|
||||
...Object.entries(sections).map(
|
||||
([key, value]) => ` - ${header[key as keyof typeof header] ?? key}: ${value}`,
|
||||
),
|
||||
];
|
||||
})
|
||||
.join('\n');
|
||||
|
||||
copy(bulletList);
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<n-scrollbar style="flex: 1" x-scrollable>
|
||||
<div mb-5 flex flex-1 flex-nowrap justify-center gap-12px>
|
||||
<div v-for="(suite, index) of suites" :key="index">
|
||||
<c-card style="width: 294px">
|
||||
<c-input-text
|
||||
v-model:value="suite.title"
|
||||
label-position="left"
|
||||
label="Suite name"
|
||||
placeholder="Suite name..."
|
||||
clearable
|
||||
/>
|
||||
|
||||
<n-divider />
|
||||
<n-form-item label="Suite values" :show-feedback="false">
|
||||
<DynamicValues v-model:values="suite.data" />
|
||||
</n-form-item>
|
||||
</c-card>
|
||||
|
||||
<div flex justify-center>
|
||||
<c-button v-if="suites.length > 1" variant="text" @click="suites.splice(index, 1)">
|
||||
<n-icon :component="Trash" depth="3" mr-2 size="18" />
|
||||
Delete suite
|
||||
</c-button>
|
||||
<c-button
|
||||
variant="text"
|
||||
@click="suites.splice(index + 1, 0, { data: [0], title: `Suite ${suites.length + 1}` })"
|
||||
>
|
||||
<n-icon :component="Plus" depth="3" mr-2 size="18" />
|
||||
Add suite
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-scrollbar>
|
||||
|
||||
<div style="flex: 0 0 100%">
|
||||
<div style="max-width: 600px; margin: 0 auto">
|
||||
<div mx-auto max-w-sm flex justify-center gap-3>
|
||||
<c-input-text v-model:value="unit" placeholder="Unit (eg: ms)" label="Unit" label-position="left" mb-4 />
|
||||
|
||||
<c-button
|
||||
@click="
|
||||
suites = [
|
||||
{ title: 'Suite 1', data: [] },
|
||||
{ title: 'Suite 2', data: [] },
|
||||
]
|
||||
"
|
||||
>
|
||||
Reset suites
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<c-table :data="results" :headers="header" />
|
||||
|
||||
<div mt-5 flex justify-center gap-3>
|
||||
<c-button @click="copyAsMarkdown()">
|
||||
Copy as markdown table
|
||||
</c-button>
|
||||
<c-button @click="copyAsBulletList()">
|
||||
Copy as bullet list
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,54 @@
|
||||
<script setup lang="ts">
|
||||
import { Plus, Trash } from '@vicons/tabler';
|
||||
import { useTemplateRefsList, useVModel } from '@vueuse/core';
|
||||
import { NInputNumber } from 'naive-ui';
|
||||
import { nextTick } from 'vue';
|
||||
|
||||
const props = defineProps<{ values: (number | null)[] }>();
|
||||
|
||||
const emit = defineEmits(['update:values']);
|
||||
|
||||
const refs = useTemplateRefsList<typeof NInputNumber>();
|
||||
|
||||
const values = useVModel(props, 'values', emit);
|
||||
|
||||
async function addValue() {
|
||||
values.value.push(null);
|
||||
await nextTick();
|
||||
refs.value.at(-1)?.focus();
|
||||
}
|
||||
|
||||
function onInputEnter(index: number) {
|
||||
if (index === values.value.length - 1) {
|
||||
addValue();
|
||||
return;
|
||||
}
|
||||
|
||||
refs.value.at(index + 1)?.focus();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div v-for="(value, index) of values" :key="index" mb-2 flex flex-nowrap gap-2>
|
||||
<NInputNumber
|
||||
:ref="refs.set"
|
||||
v-model:value="values[index]"
|
||||
:show-button="false"
|
||||
placeholder="Set your measure..."
|
||||
autofocus
|
||||
@keydown.enter="onInputEnter(index)"
|
||||
/>
|
||||
<c-tooltip tooltip="Delete this value">
|
||||
<c-button circle variant="text" @click="values.splice(index, 1)">
|
||||
<n-icon :component="Trash" depth="3" size="18" />
|
||||
</c-button>
|
||||
</c-tooltip>
|
||||
</div>
|
||||
|
||||
<c-button @click="addValue">
|
||||
<n-icon :component="Plus" depth="3" mr-2 size="18" />
|
||||
Add a measure
|
||||
</c-button>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { SpeedFilled } from '@vicons/material';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.benchmark-builder.title'),
|
||||
path: '/benchmark-builder',
|
||||
description: translate('tools.benchmark-builder.description'),
|
||||
keywords: ['benchmark', 'builder', 'execution', 'duration', 'mean', 'variance'],
|
||||
component: () => import('./benchmark-builder.vue'),
|
||||
icon: SpeedFilled,
|
||||
createdAt: new Date('2023-04-05'),
|
||||
});
|
||||
@@ -0,0 +1,131 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
chineseSimplifiedWordList,
|
||||
chineseTraditionalWordList,
|
||||
czechWordList,
|
||||
englishWordList,
|
||||
entropyToMnemonic,
|
||||
frenchWordList,
|
||||
generateEntropy,
|
||||
italianWordList,
|
||||
japaneseWordList,
|
||||
koreanWordList,
|
||||
mnemonicToEntropy,
|
||||
portugueseWordList,
|
||||
spanishWordList,
|
||||
} from '@it-tools/bip39';
|
||||
import { Copy, Refresh } from '@vicons/tabler';
|
||||
|
||||
import { useCopy } from '@/composable/copy';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
import { isNotThrowing } from '@/utils/boolean';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
|
||||
const languages = {
|
||||
'English': englishWordList,
|
||||
'Chinese simplified': chineseSimplifiedWordList,
|
||||
'Chinese traditional': chineseTraditionalWordList,
|
||||
'Czech': czechWordList,
|
||||
'French': frenchWordList,
|
||||
'Italian': italianWordList,
|
||||
'Japanese': japaneseWordList,
|
||||
'Korean': koreanWordList,
|
||||
'Portuguese': portugueseWordList,
|
||||
'Spanish': spanishWordList,
|
||||
};
|
||||
|
||||
const entropy = ref(generateEntropy());
|
||||
const passphraseInput = ref('');
|
||||
|
||||
const language = ref<keyof typeof languages>('English');
|
||||
const passphrase = computed({
|
||||
get() {
|
||||
return withDefaultOnError(() => entropyToMnemonic(entropy.value, languages[language.value]), passphraseInput.value);
|
||||
},
|
||||
set(value: string) {
|
||||
passphraseInput.value = value;
|
||||
entropy.value = withDefaultOnError(() => mnemonicToEntropy(value, languages[language.value]), '');
|
||||
},
|
||||
});
|
||||
|
||||
const entropyValidation = useValidation({
|
||||
source: entropy,
|
||||
rules: [
|
||||
{
|
||||
validator: value => value === '' || (value.length <= 32 && value.length >= 16 && value.length % 4 === 0),
|
||||
message: 'Entropy length should be >= 16, <= 32 and be a multiple of 4',
|
||||
},
|
||||
{
|
||||
validator: value => /^[a-fA-F0-9]*$/.test(value),
|
||||
message: 'Entropy should be an hexadecimal string',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const mnemonicValidation = useValidation({
|
||||
source: passphrase,
|
||||
rules: [
|
||||
{
|
||||
validator: value => isNotThrowing(() => mnemonicToEntropy(value, languages[language.value])),
|
||||
message: 'Invalid mnemonic',
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function refreshEntropy() {
|
||||
entropy.value = generateEntropy();
|
||||
}
|
||||
|
||||
const { copy: copyEntropy } = useCopy({ source: entropy, text: 'Entropy copied to the clipboard' });
|
||||
const { copy: copyPassphrase } = useCopy({ source: passphrase, text: 'Passphrase copied to the clipboard' });
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-grid cols="3" x-gap="12">
|
||||
<n-gi span="1">
|
||||
<c-select
|
||||
v-model:value="language"
|
||||
searchable
|
||||
label="Language:"
|
||||
:options="Object.keys(languages)"
|
||||
/>
|
||||
</n-gi>
|
||||
<n-gi span="2">
|
||||
<n-form-item
|
||||
label="Entropy (seed):"
|
||||
:feedback="entropyValidation.message"
|
||||
:validation-status="entropyValidation.status"
|
||||
>
|
||||
<n-input-group>
|
||||
<c-input-text v-model:value="entropy" placeholder="Your string..." />
|
||||
|
||||
<c-button @click="refreshEntropy()">
|
||||
<n-icon size="22">
|
||||
<Refresh />
|
||||
</n-icon>
|
||||
</c-button>
|
||||
<c-button @click="copyEntropy()">
|
||||
<n-icon size="22">
|
||||
<Copy />
|
||||
</n-icon>
|
||||
</c-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
<n-form-item
|
||||
label="Passphrase (mnemonic):"
|
||||
:feedback="mnemonicValidation.message"
|
||||
:validation-status="mnemonicValidation.status"
|
||||
>
|
||||
<n-input-group>
|
||||
<c-input-text v-model:value="passphrase" placeholder="Your mnemonic..." raw-text />
|
||||
|
||||
<c-button @click="copyPassphrase()">
|
||||
<n-icon size="22" :component="Copy" />
|
||||
</c-button>
|
||||
</n-input-group>
|
||||
</n-form-item>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { AlignJustified } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.bip39-generator.title'),
|
||||
path: '/bip39-generator',
|
||||
description: translate('tools.bip39-generator.description'),
|
||||
keywords: ['BIP39', 'passphrase', 'generator', 'mnemonic', 'entropy'],
|
||||
component: () => import('./bip39-generator.vue'),
|
||||
icon: AlignJustified,
|
||||
});
|
||||
@@ -0,0 +1,217 @@
|
||||
<script setup lang="ts">
|
||||
import _ from 'lodash';
|
||||
|
||||
import { useMediaRecorder } from './useMediaRecorder';
|
||||
|
||||
interface Media { type: 'image' | 'video'; value: string; createdAt: Date }
|
||||
|
||||
const {
|
||||
videoInputs: cameras,
|
||||
audioInputs: microphones,
|
||||
permissionGranted,
|
||||
isSupported,
|
||||
ensurePermissions,
|
||||
} = useDevicesList({
|
||||
requestPermissions: true,
|
||||
constraints: { video: true, audio: true },
|
||||
onUpdated() {
|
||||
refreshCurrentDevices();
|
||||
},
|
||||
});
|
||||
|
||||
const video = ref<HTMLVideoElement>();
|
||||
const medias = ref<Media[]>([]);
|
||||
const currentCamera = ref(cameras.value[0]?.deviceId);
|
||||
const currentMicrophone = ref(microphones.value[0]?.deviceId);
|
||||
const permissionCannotBePrompted = ref(false);
|
||||
|
||||
const {
|
||||
stream,
|
||||
start,
|
||||
stop,
|
||||
enabled: isMediaStreamAvailable,
|
||||
} = useUserMedia({
|
||||
constraints: computed(() => ({
|
||||
video: { deviceId: currentCamera.value },
|
||||
...(currentMicrophone.value ? { audio: { deviceId: currentMicrophone.value } } : {}),
|
||||
})),
|
||||
autoSwitch: true,
|
||||
});
|
||||
|
||||
const {
|
||||
isRecordingSupported,
|
||||
onRecordAvailable,
|
||||
startRecording,
|
||||
stopRecording,
|
||||
pauseRecording,
|
||||
recordingState,
|
||||
resumeRecording,
|
||||
} = useMediaRecorder({
|
||||
stream,
|
||||
});
|
||||
|
||||
onRecordAvailable((value) => {
|
||||
medias.value.unshift({ type: 'video', value, createdAt: new Date() });
|
||||
});
|
||||
|
||||
function refreshCurrentDevices() {
|
||||
if (_.isNil(currentCamera) || !cameras.value.find(i => i.deviceId === currentCamera.value)) {
|
||||
currentCamera.value = cameras.value[0]?.deviceId;
|
||||
}
|
||||
|
||||
if (_.isNil(microphones) || !microphones.value.find(i => i.deviceId === currentMicrophone.value)) {
|
||||
currentMicrophone.value = microphones.value[0]?.deviceId;
|
||||
}
|
||||
}
|
||||
|
||||
function takeScreenshot() {
|
||||
if (!video.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = video.value.videoWidth;
|
||||
canvas.height = video.value.videoHeight;
|
||||
canvas.getContext('2d')?.drawImage(video.value, 0, 0);
|
||||
const image = canvas.toDataURL('image/png');
|
||||
|
||||
medias.value.unshift({ type: 'image', value: image, createdAt: new Date() });
|
||||
}
|
||||
|
||||
watchEffect(() => {
|
||||
if (video.value && stream.value) {
|
||||
video.value.srcObject = stream.value;
|
||||
}
|
||||
});
|
||||
|
||||
onBeforeUnmount(() => stop());
|
||||
|
||||
async function requestPermissions() {
|
||||
try {
|
||||
await ensurePermissions();
|
||||
}
|
||||
catch (e) {
|
||||
permissionCannotBePrompted.value = true;
|
||||
}
|
||||
}
|
||||
|
||||
function downloadMedia({ type, value, createdAt }: Media) {
|
||||
const link = document.createElement('a');
|
||||
link.href = value;
|
||||
link.download = `${type}-${createdAt.getTime()}.${type === 'image' ? 'png' : 'webm'}`;
|
||||
link.click();
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card v-if="!isSupported">
|
||||
Your browser does not support recording video from camera
|
||||
</c-card>
|
||||
|
||||
<c-card v-else-if="!permissionGranted" text-center>
|
||||
You need to grant permission to use your camera and microphone
|
||||
|
||||
<c-alert v-if="permissionCannotBePrompted" mt-4 text-left>
|
||||
Your browser has blocked permission request or does not support it. You need to grant permission manually in
|
||||
your browser settings (usually the lock icon in the address bar).
|
||||
</c-alert>
|
||||
|
||||
<div v-else mt-4 flex justify-center>
|
||||
<c-button @click="requestPermissions">
|
||||
Grant permission
|
||||
</c-button>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<c-card v-else>
|
||||
<div flex flex-col gap-2>
|
||||
<c-select
|
||||
v-model:value="currentCamera"
|
||||
label-position="left"
|
||||
label-width="60px"
|
||||
label="Video:"
|
||||
:options="cameras.map(({ deviceId, label }) => ({ value: deviceId, label }))"
|
||||
placeholder="Select camera"
|
||||
/>
|
||||
<c-select
|
||||
v-if="currentMicrophone && microphones.length > 0"
|
||||
v-model:value="currentMicrophone"
|
||||
label="Audio:"
|
||||
label-position="left"
|
||||
label-width="60px"
|
||||
:options="microphones.map(({ deviceId, label }) => ({ value: deviceId, label }))"
|
||||
placeholder="Select microphone"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div v-if="!isMediaStreamAvailable" mt-3 flex justify-center>
|
||||
<c-button type="primary" @click="start">
|
||||
Start webcam
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<div v-else>
|
||||
<div my-2>
|
||||
<video ref="video" autoplay controls playsinline max-h-full w-full />
|
||||
</div>
|
||||
|
||||
<div flex items-center justify-between gap-2>
|
||||
<c-button :disabled="!isMediaStreamAvailable" @click="takeScreenshot">
|
||||
<span mr-2> <icon-mdi-camera /></span>
|
||||
Take screenshot
|
||||
</c-button>
|
||||
|
||||
<div v-if="isRecordingSupported" flex justify-center gap-2>
|
||||
<c-button v-if="recordingState === 'stopped'" @click="startRecording">
|
||||
<span mr-2> <icon-mdi-video /></span>
|
||||
Start recording
|
||||
</c-button>
|
||||
|
||||
<c-button v-if="recordingState === 'recording'" @click="pauseRecording">
|
||||
<span mr-2> <icon-mdi-pause /></span>
|
||||
Pause
|
||||
</c-button>
|
||||
|
||||
<c-button v-if="recordingState === 'paused'" @click="resumeRecording">
|
||||
<span mr-2> <icon-mdi-play /></span>
|
||||
Resume
|
||||
</c-button>
|
||||
|
||||
<c-button v-if="recordingState !== 'stopped'" type="error" @click="stopRecording">
|
||||
<span mr-2> <icon-mdi-record /></span>
|
||||
Stop
|
||||
</c-button>
|
||||
</div>
|
||||
<div v-else italic op-60>
|
||||
Video recording is not supported in your browser
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</c-card>
|
||||
|
||||
<div grid grid-cols-2 mt-5 gap-2>
|
||||
<c-card v-for="({ type, value, createdAt }, index) in medias" :key="index">
|
||||
<img v-if="type === 'image'" :src="value" max-h-full w-full alt="screenshot">
|
||||
|
||||
<video v-else :src="value" controls max-h-full w-full />
|
||||
|
||||
<div flex items-center justify-between>
|
||||
<div font-bold>
|
||||
{{ type === 'image' ? 'Screenshot' : 'Video' }}
|
||||
</div>
|
||||
|
||||
<div flex gap-2>
|
||||
<c-button @click="downloadMedia({ type, value, createdAt })">
|
||||
<icon-mdi-download />
|
||||
</c-button>
|
||||
|
||||
<c-button @click="medias = medias.filter((_ignored, i) => i !== index)">
|
||||
<icon-mdi-delete-outline />
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Camera } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.camera-recorder.title'),
|
||||
path: '/camera-recorder',
|
||||
description: translate('tools.camera-recorder.description'),
|
||||
keywords: ['camera', 'recoder'],
|
||||
component: () => import('./camera-recorder.vue'),
|
||||
icon: Camera,
|
||||
createdAt: new Date('2023-05-15'),
|
||||
});
|
||||
@@ -0,0 +1,114 @@
|
||||
import { type Ref, computed, ref } from 'vue';
|
||||
|
||||
export { useMediaRecorder };
|
||||
|
||||
function useMediaRecorder({ stream }: { stream: Ref<MediaStream | undefined> }): {
|
||||
isRecordingSupported: Ref<boolean>
|
||||
recordingState: Ref<'stopped' | 'recording' | 'paused'>
|
||||
startRecording: () => void
|
||||
stopRecording: () => void
|
||||
pauseRecording: () => void
|
||||
resumeRecording: () => void
|
||||
onRecordAvailable: (cb: (url: string) => void) => void
|
||||
} {
|
||||
const isRecordingSupported = computed(() => MediaRecorder.isTypeSupported('video/webm'));
|
||||
const mediaRecorder = ref<MediaRecorder | null>(null);
|
||||
const recordedChunks = ref<Blob[]>([]);
|
||||
const recordAvailable = createEventHook();
|
||||
const recordingState = ref<'stopped' | 'recording' | 'paused'>('stopped');
|
||||
|
||||
const createVideo = () => {
|
||||
const blob = new Blob(recordedChunks.value, { type: 'video/webm' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
recordedChunks.value = [];
|
||||
return url;
|
||||
};
|
||||
|
||||
const startRecording = () => {
|
||||
if (!isRecordingSupported.value) {
|
||||
return;
|
||||
}
|
||||
if (!stream.value) {
|
||||
return;
|
||||
}
|
||||
if (recordingState.value !== 'stopped') {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.value = new MediaRecorder(stream.value, { mimeType: 'video/webm' });
|
||||
|
||||
mediaRecorder.value.ondataavailable = (e) => {
|
||||
if (e.data.size > 0) {
|
||||
recordedChunks.value.push(e.data);
|
||||
}
|
||||
};
|
||||
|
||||
mediaRecorder.value.onstop = () => {
|
||||
recordAvailable.trigger(createVideo());
|
||||
};
|
||||
|
||||
if (mediaRecorder.value.state !== 'inactive') {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.value.start();
|
||||
recordingState.value = 'recording';
|
||||
};
|
||||
|
||||
const stopRecording = () => {
|
||||
if (!isRecordingSupported.value) {
|
||||
return;
|
||||
}
|
||||
if (!mediaRecorder.value) {
|
||||
return;
|
||||
}
|
||||
if (recordingState.value === 'stopped') {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.value.stop();
|
||||
recordingState.value = 'stopped';
|
||||
};
|
||||
|
||||
const pauseRecording = () => {
|
||||
if (!isRecordingSupported.value) {
|
||||
return;
|
||||
}
|
||||
if (!mediaRecorder.value) {
|
||||
return;
|
||||
}
|
||||
if (recordingState.value !== 'recording') {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.value.pause();
|
||||
recordingState.value = 'paused';
|
||||
};
|
||||
|
||||
const resumeRecording = () => {
|
||||
if (!isRecordingSupported.value) {
|
||||
return;
|
||||
}
|
||||
if (!mediaRecorder.value) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (recordingState.value !== 'paused') {
|
||||
return;
|
||||
}
|
||||
|
||||
mediaRecorder.value.resume();
|
||||
recordingState.value = 'recording';
|
||||
};
|
||||
|
||||
return {
|
||||
isRecordingSupported,
|
||||
startRecording,
|
||||
stopRecording,
|
||||
pauseRecording,
|
||||
resumeRecording,
|
||||
recordingState,
|
||||
|
||||
onRecordAvailable: recordAvailable.on,
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,113 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
camelCase,
|
||||
capitalCase,
|
||||
constantCase,
|
||||
dotCase,
|
||||
headerCase,
|
||||
noCase,
|
||||
paramCase,
|
||||
pascalCase,
|
||||
pathCase,
|
||||
sentenceCase,
|
||||
snakeCase,
|
||||
} from 'change-case';
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
|
||||
const baseConfig = {
|
||||
stripRegexp: /[^A-Za-zÀ-ÖØ-öø-ÿ]+/gi,
|
||||
};
|
||||
|
||||
const input = ref('lorem ipsum dolor sit amet');
|
||||
|
||||
const formats = computed(() => [
|
||||
{
|
||||
label: 'Lowercase:',
|
||||
value: input.value.toLocaleLowerCase(),
|
||||
},
|
||||
{
|
||||
label: 'Uppercase:',
|
||||
value: input.value.toLocaleUpperCase(),
|
||||
},
|
||||
{
|
||||
label: 'Camelcase:',
|
||||
value: camelCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Capitalcase:',
|
||||
value: capitalCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Constantcase:',
|
||||
value: constantCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Dotcase:',
|
||||
value: dotCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Headercase:',
|
||||
value: headerCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Nocase:',
|
||||
value: noCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Paramcase:',
|
||||
value: paramCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Pascalcase:',
|
||||
value: pascalCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Pathcase:',
|
||||
value: pathCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Sentencecase:',
|
||||
value: sentenceCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Snakecase:',
|
||||
value: snakeCase(input.value, baseConfig),
|
||||
},
|
||||
{
|
||||
label: 'Mockingcase:',
|
||||
value: input.value
|
||||
.split('')
|
||||
.map((char, index) => (index % 2 === 0 ? char.toUpperCase() : char.toLowerCase()))
|
||||
.join(''),
|
||||
},
|
||||
]);
|
||||
|
||||
const inputLabelAlignmentConfig = {
|
||||
labelPosition: 'left',
|
||||
labelWidth: '120px',
|
||||
labelAlign: 'right',
|
||||
};
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<c-input-text
|
||||
v-model:value="input"
|
||||
label="Your string:"
|
||||
placeholder="Your string..."
|
||||
raw-text
|
||||
v-bind="inputLabelAlignmentConfig"
|
||||
/>
|
||||
|
||||
<div my-16px divider />
|
||||
|
||||
<InputCopyable
|
||||
v-for="format in formats"
|
||||
:key="format.label"
|
||||
:value="format.value"
|
||||
:label="format.label"
|
||||
v-bind="inputLabelAlignmentConfig"
|
||||
mb-1
|
||||
/>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -0,0 +1,26 @@
|
||||
import { LetterCaseToggle } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.case-converter.title'),
|
||||
path: '/case-converter',
|
||||
description: translate('tools.case-converter.description'),
|
||||
keywords: [
|
||||
'case',
|
||||
'converter',
|
||||
'camelCase',
|
||||
'capitalCase',
|
||||
'constantCase',
|
||||
'dotCase',
|
||||
'headerCase',
|
||||
'noCase',
|
||||
'paramCase',
|
||||
'pascalCase',
|
||||
'pathCase',
|
||||
'sentenceCase',
|
||||
'snakeCase',
|
||||
],
|
||||
component: () => import('./case-converter.vue'),
|
||||
icon: LetterCaseToggle,
|
||||
});
|
||||
@@ -0,0 +1,130 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
||||
|
||||
describe('chmod-calculator', () => {
|
||||
describe('computeChmodOctalRepresentation', () => {
|
||||
it('get the octal representation from permissions', () => {
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('777');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('000');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('235');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('421');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('124');
|
||||
|
||||
expect(
|
||||
computeChmodOctalRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('222');
|
||||
});
|
||||
|
||||
it('get the symbolic representation from permissions', () => {
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: true, execute: true },
|
||||
group: { read: true, write: true, execute: true },
|
||||
public: { read: true, write: true, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('rwxrwxrwx');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('---------');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: true },
|
||||
public: { read: true, write: false, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--wxr-x');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: true, write: false, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: false, execute: true },
|
||||
},
|
||||
}),
|
||||
).to.eql('r---w---x');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: false, execute: true },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: true, write: false, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('--x-w-r--');
|
||||
|
||||
expect(
|
||||
computeChmodSymbolicRepresentation({
|
||||
permissions: {
|
||||
owner: { read: false, write: true, execute: false },
|
||||
group: { read: false, write: true, execute: false },
|
||||
public: { read: false, write: true, execute: false },
|
||||
},
|
||||
}),
|
||||
).to.eql('-w--w--w-');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,30 @@
|
||||
import _ from 'lodash';
|
||||
import type { GroupPermissions, Permissions } from './chmod-calculator.types';
|
||||
|
||||
export { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation };
|
||||
|
||||
function computeChmodOctalRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||
const permissionValue = { read: 4, write: 2, execute: 1 };
|
||||
|
||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, 0) : 0), 0);
|
||||
|
||||
return [
|
||||
getGroupPermissionValue(permissions.owner),
|
||||
getGroupPermissionValue(permissions.group),
|
||||
getGroupPermissionValue(permissions.public),
|
||||
].join('');
|
||||
}
|
||||
|
||||
function computeChmodSymbolicRepresentation({ permissions }: { permissions: Permissions }): string {
|
||||
const permissionValue = { read: 'r', write: 'w', execute: 'x' };
|
||||
|
||||
const getGroupPermissionValue = (permission: GroupPermissions) =>
|
||||
_.reduce(permission, (acc, isPermSet, key) => acc + (isPermSet ? _.get(permissionValue, key, '') : '-'), '');
|
||||
|
||||
return [
|
||||
getGroupPermissionValue(permissions.owner),
|
||||
getGroupPermissionValue(permissions.group),
|
||||
getGroupPermissionValue(permissions.public),
|
||||
].join('');
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
export type Scope = 'read' | 'write' | 'execute';
|
||||
export type Group = 'owner' | 'group' | 'public';
|
||||
|
||||
export type GroupPermissions = {
|
||||
[k in Scope]: boolean;
|
||||
};
|
||||
|
||||
export type Permissions = {
|
||||
[k in Group]: GroupPermissions;
|
||||
};
|
||||
@@ -0,0 +1,95 @@
|
||||
<script setup lang="ts">
|
||||
import { useThemeVars } from 'naive-ui';
|
||||
|
||||
import InputCopyable from '../../components/InputCopyable.vue';
|
||||
import { computeChmodOctalRepresentation, computeChmodSymbolicRepresentation } from './chmod-calculator.service';
|
||||
|
||||
import type { Group, Scope } from './chmod-calculator.types';
|
||||
|
||||
const themeVars = useThemeVars();
|
||||
|
||||
const scopes: { scope: Scope; title: string }[] = [
|
||||
{ scope: 'read', title: 'Read (4)' },
|
||||
{ scope: 'write', title: 'Write (2)' },
|
||||
{ scope: 'execute', title: 'Execute (1)' },
|
||||
];
|
||||
const groups: Group[] = ['owner', 'group', 'public'];
|
||||
|
||||
const permissions = ref({
|
||||
owner: { read: false, write: false, execute: false },
|
||||
group: { read: false, write: false, execute: false },
|
||||
public: { read: false, write: false, execute: false },
|
||||
});
|
||||
|
||||
const octal = computed(() => computeChmodOctalRepresentation({ permissions: permissions.value }));
|
||||
const symbolic = computed(() => computeChmodSymbolicRepresentation({ permissions: permissions.value }));
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<n-table :bordered="false" :bottom-bordered="false" single-column class="permission-table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th class="text-center" scope="col" />
|
||||
<th class="text-center" scope="col">
|
||||
Owner (u)
|
||||
</th>
|
||||
<th class="text-center" scope="col">
|
||||
Group (g)
|
||||
</th>
|
||||
<th class="text-center" scope="col">
|
||||
Public (o)
|
||||
</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<tr v-for="{ scope, title } of scopes" :key="scope">
|
||||
<td class="line-header">
|
||||
{{ title }}
|
||||
</td>
|
||||
<td v-for="group of groups" :key="group" class="text-center">
|
||||
<!-- <n-switch v-model:value="permissions[group][scope]" /> -->
|
||||
<n-checkbox v-model:checked="permissions[group][scope]" size="large" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</n-table>
|
||||
|
||||
<div class="octal-result">
|
||||
{{ octal }}
|
||||
</div>
|
||||
<div class="octal-result">
|
||||
{{ symbolic }}
|
||||
</div>
|
||||
|
||||
<InputCopyable :value="`chmod ${octal} path`" readonly />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.octal-result {
|
||||
text-align: center;
|
||||
font-size: 50px;
|
||||
font-family: monospace;
|
||||
color: v-bind('themeVars.primaryColor');
|
||||
margin: 20px 0;
|
||||
}
|
||||
.permission-table {
|
||||
td,
|
||||
th {
|
||||
padding: 15px;
|
||||
|
||||
@media screen and (max-width: 600px) {
|
||||
padding: 5px;
|
||||
}
|
||||
}
|
||||
}
|
||||
.line-header {
|
||||
font-weight: bold;
|
||||
text-align: right;
|
||||
max-width: 80px;
|
||||
}
|
||||
.text-center {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,23 @@
|
||||
import { FileInvoice } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.chmod-calculator.title'),
|
||||
path: '/chmod-calculator',
|
||||
description: translate('tools.chmod-calculator.description'),
|
||||
keywords: [
|
||||
'chmod',
|
||||
'calculator',
|
||||
'file',
|
||||
'permission',
|
||||
'files',
|
||||
'directory',
|
||||
'folder',
|
||||
'recursive',
|
||||
'generator',
|
||||
'octal',
|
||||
],
|
||||
component: () => import('./chmod-calculator.vue'),
|
||||
icon: FileInvoice,
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatMs } from './chronometer.service';
|
||||
|
||||
describe('chronometer', () => {
|
||||
describe('formatChronometerTime', () => {
|
||||
it('format the elapsed time', () => {
|
||||
expect(formatMs(0)).toEqual('00:00.000');
|
||||
expect(formatMs(1)).toEqual('00:00.001');
|
||||
expect(formatMs(123456)).toEqual('02:03.456');
|
||||
expect(formatMs(12345600)).toEqual('03:25:45.600');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,11 @@
|
||||
export function formatMs(msTotal: number) {
|
||||
const ms = msTotal % 1000;
|
||||
const secs = ((msTotal - ms) / 1000) % 60;
|
||||
const mins = (((msTotal - ms) / 1000 - secs) / 60) % 60;
|
||||
const hrs = (((msTotal - ms) / 1000 - secs) / 60 - mins) / 60;
|
||||
const hrsString = hrs > 0 ? `${hrs.toString().padStart(2, '0')}:` : '';
|
||||
|
||||
return `${hrsString}${mins.toString().padStart(2, '0')}:${secs.toString().padStart(2, '0')}.${ms
|
||||
.toString()
|
||||
.padStart(3, '0')}`;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
<script setup lang="ts">
|
||||
import { useRafFn } from '@vueuse/core';
|
||||
|
||||
import { formatMs } from './chronometer.service';
|
||||
|
||||
const isRunning = ref(false);
|
||||
const counter = ref(0);
|
||||
|
||||
let previousRafDate = Date.now();
|
||||
const { pause: pauseRaf, resume: resumeRaf } = useRafFn(
|
||||
() => {
|
||||
const deltaMs = Date.now() - previousRafDate;
|
||||
previousRafDate = Date.now();
|
||||
counter.value += deltaMs;
|
||||
},
|
||||
{ immediate: false },
|
||||
);
|
||||
|
||||
function resume() {
|
||||
previousRafDate = Date.now();
|
||||
resumeRaf();
|
||||
isRunning.value = true;
|
||||
}
|
||||
|
||||
function pause() {
|
||||
pauseRaf();
|
||||
isRunning.value = false;
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<c-card>
|
||||
<div class="duration">
|
||||
{{ formatMs(counter) }}
|
||||
</div>
|
||||
</c-card>
|
||||
<div mt-5 flex justify-center gap-3>
|
||||
<c-button v-if="!isRunning" type="primary" @click="resume">
|
||||
Start
|
||||
</c-button>
|
||||
<c-button v-else type="warning" @click="pause">
|
||||
Stop
|
||||
</c-button>
|
||||
|
||||
<c-button @click="counter = 0">
|
||||
Reset
|
||||
</c-button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.duration {
|
||||
text-align: center;
|
||||
font-size: 40px;
|
||||
font-family: monospace;
|
||||
margin: 20px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { TimerOutlined } from '@vicons/material';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.chronometer.title'),
|
||||
path: '/chronometer',
|
||||
description: translate('tools.chronometer.description'),
|
||||
keywords: ['chronometer', 'time', 'lap', 'duration', 'measure', 'pause', 'resume', 'stopwatch'],
|
||||
component: () => import('./chronometer.vue'),
|
||||
icon: TimerOutlined,
|
||||
});
|
||||
@@ -0,0 +1,472 @@
|
||||
<script setup lang="ts">
|
||||
import GenHistory from '@/tools/gen-history/GenHistory.vue';
|
||||
import { useGenHistory } from '@/tools/gen-history/gen-history';
|
||||
|
||||
const genHist = useGenHistory('code-reader');
|
||||
import { prepareZXingModule, readBarcodes } from 'zxing-wasm/reader';
|
||||
import wasmUrl from 'zxing-wasm/reader/zxing_reader.wasm?url';
|
||||
|
||||
// load wasm from our own bundle instead of jsdelivr CDN (works offline / in CN)
|
||||
prepareZXingModule({
|
||||
overrides: {
|
||||
locateFile: () => wasmUrl,
|
||||
},
|
||||
fireImmediately: true,
|
||||
});
|
||||
|
||||
interface CodeResult {
|
||||
format: string;
|
||||
symbology: string;
|
||||
contentType: string;
|
||||
text: string;
|
||||
}
|
||||
|
||||
const fileInput = ref<HTMLInputElement>();
|
||||
const imageSrc = ref('');
|
||||
const fileName = ref('');
|
||||
const results = ref<CodeResult[]>([]);
|
||||
const loading = ref(false);
|
||||
const error = ref('');
|
||||
const dragActive = ref(false);
|
||||
const elapsed = ref(0);
|
||||
|
||||
function pickFile() {
|
||||
fileInput.value?.click();
|
||||
}
|
||||
|
||||
async function handleFile(file?: File | null) {
|
||||
if (!file) {
|
||||
return;
|
||||
}
|
||||
if (!file.type.startsWith('image/')) {
|
||||
error.value = '请选择图片文件(png/jpg/webp/bmp 等)';
|
||||
return;
|
||||
}
|
||||
error.value = '';
|
||||
const reader = new FileReader();
|
||||
reader.onload = () => {
|
||||
imageSrc.value = String(reader.result ?? '');
|
||||
fileName.value = file.name;
|
||||
recognize(file);
|
||||
};
|
||||
reader.readAsDataURL(file);
|
||||
}
|
||||
|
||||
function onInputChange(e: Event) {
|
||||
const input = e.target as HTMLInputElement;
|
||||
handleFile(input.files?.[0]);
|
||||
input.value = '';
|
||||
}
|
||||
|
||||
function onDrop(e: DragEvent) {
|
||||
dragActive.value = false;
|
||||
handleFile(e.dataTransfer?.files?.[0]);
|
||||
}
|
||||
|
||||
// paste image from clipboard
|
||||
function onPaste(e: ClipboardEvent) {
|
||||
const items = e.clipboardData?.items;
|
||||
if (!items) {
|
||||
return;
|
||||
}
|
||||
for (const item of items) {
|
||||
if (item.type.startsWith('image/')) {
|
||||
handleFile(item.getAsFile());
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// flatten onto a white canvas first: ZXing handles transparent PNGs poorly
|
||||
async function toFlattenedBlob(file: File | Blob): Promise<Blob> {
|
||||
const bitmap = await createImageBitmap(file);
|
||||
const canvas = document.createElement('canvas');
|
||||
canvas.width = bitmap.width;
|
||||
canvas.height = bitmap.height;
|
||||
const ctx = canvas.getContext('2d')!;
|
||||
ctx.fillStyle = '#ffffff';
|
||||
ctx.fillRect(0, 0, canvas.width, canvas.height);
|
||||
ctx.drawImage(bitmap, 0, 0);
|
||||
bitmap.close();
|
||||
return new Promise(resolve => canvas.toBlob(b => resolve(b!), 'image/png'));
|
||||
}
|
||||
|
||||
async function recognize(file: File | Blob) {
|
||||
loading.value = true;
|
||||
error.value = '';
|
||||
results.value = [];
|
||||
const start = performance.now();
|
||||
try {
|
||||
const flattened = await toFlattenedBlob(file);
|
||||
const found = await readBarcodes(flattened, {
|
||||
tryHarder: true,
|
||||
tryRotate: true,
|
||||
tryInvert: true,
|
||||
maxNumberOfSymbols: 0, // no limit
|
||||
});
|
||||
results.value = found.map(r => ({
|
||||
format: r.format,
|
||||
symbology: r.symbology,
|
||||
contentType: r.contentType,
|
||||
text: r.text,
|
||||
}));
|
||||
if (!found.length) {
|
||||
error.value = '未识别到条码/二维码,可尝试更清晰、完整(含留白)的图片';
|
||||
}
|
||||
else {
|
||||
genHist.add({
|
||||
title: found[0].text.slice(0, 60),
|
||||
detail: `${found[0].format}${found.length > 1 ? ` 等 ${found.length} 个` : ''}`,
|
||||
});
|
||||
}
|
||||
}
|
||||
catch (e: any) {
|
||||
error.value = `识别失败:${e?.message ?? e}`;
|
||||
}
|
||||
finally {
|
||||
elapsed.value = Math.round(performance.now() - start);
|
||||
loading.value = false;
|
||||
}
|
||||
}
|
||||
|
||||
function reRecognize() {
|
||||
if (!imageSrc.value) {
|
||||
return;
|
||||
}
|
||||
fetch(imageSrc.value)
|
||||
.then(r => r.blob())
|
||||
.then(blob => recognize(blob));
|
||||
}
|
||||
|
||||
const allText = computed(() => results.value.map(r => r.text).join('\n'));
|
||||
|
||||
async function copyText(text: string) {
|
||||
try {
|
||||
await navigator.clipboard.writeText(text);
|
||||
}
|
||||
catch {
|
||||
const ta = document.createElement('textarea');
|
||||
ta.value = text;
|
||||
document.body.appendChild(ta);
|
||||
ta.select();
|
||||
document.execCommand('copy');
|
||||
ta.remove();
|
||||
}
|
||||
}
|
||||
|
||||
function downloadTxt() {
|
||||
if (!allText.value) {
|
||||
return;
|
||||
}
|
||||
const blob = new Blob([allText.value], { type: 'text/plain;charset=utf-8' });
|
||||
const url = URL.createObjectURL(blob);
|
||||
const a = document.createElement('a');
|
||||
a.href = url;
|
||||
a.download = 'code-results.txt';
|
||||
a.click();
|
||||
URL.revokeObjectURL(url);
|
||||
}
|
||||
|
||||
function clearAll() {
|
||||
imageSrc.value = '';
|
||||
fileName.value = '';
|
||||
results.value = [];
|
||||
error.value = '';
|
||||
}
|
||||
|
||||
// fit viewport: no page scroll
|
||||
const rootEl = ref<HTMLElement>();
|
||||
const rootStyle = ref<Record<string, string>>({});
|
||||
|
||||
function fit() {
|
||||
const el = rootEl.value;
|
||||
if (!el) {
|
||||
return;
|
||||
}
|
||||
const top = el.getBoundingClientRect().top;
|
||||
const height = Math.max(300, window.innerHeight - top - 12);
|
||||
rootStyle.value = { height: `${height}px`, flex: '1 1 100%' };
|
||||
}
|
||||
|
||||
let observer: ResizeObserver | undefined;
|
||||
onMounted(() => {
|
||||
fit();
|
||||
window.addEventListener('resize', fit);
|
||||
window.addEventListener('paste', onPaste);
|
||||
observer = new ResizeObserver(() => fit());
|
||||
if (rootEl.value) {
|
||||
observer.observe(rootEl.value);
|
||||
}
|
||||
});
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('resize', fit);
|
||||
window.removeEventListener('paste', onPaste);
|
||||
observer?.disconnect();
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div ref="rootEl" class="cr-root" :style="rootStyle">
|
||||
<input
|
||||
ref="fileInput"
|
||||
type="file"
|
||||
accept="image/*"
|
||||
style="display:none"
|
||||
@change="onInputChange"
|
||||
>
|
||||
|
||||
<div class="toolbar">
|
||||
<div class="stats">
|
||||
<template v-if="results.length">
|
||||
识别到 {{ results.length }} 个码 · {{ elapsed }}ms
|
||||
</template>
|
||||
</div>
|
||||
<c-button :disabled="!imageSrc || loading" @click="reRecognize">
|
||||
重新识别
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="copyText(allText)">
|
||||
复制全部
|
||||
</c-button>
|
||||
<c-button :disabled="!results.length" @click="downloadTxt">
|
||||
下载TXT
|
||||
</c-button>
|
||||
<c-button @click="clearAll">
|
||||
清空
|
||||
</c-button>
|
||||
</div>
|
||||
|
||||
<div class="body">
|
||||
<!-- left: image -->
|
||||
<div class="pane">
|
||||
<div
|
||||
class="dropzone"
|
||||
:class="{ active: dragActive, hasImage: !!imageSrc }"
|
||||
@click="pickFile"
|
||||
@dragover.prevent="dragActive = true"
|
||||
@dragleave.prevent="dragActive = false"
|
||||
@drop.prevent="onDrop"
|
||||
>
|
||||
<img v-if="imageSrc" :src="imageSrc" alt="待识别图片">
|
||||
<div v-else class="drop-hint">
|
||||
<div class="icon">
|
||||
🔍
|
||||
</div>
|
||||
<div>点击选择图片</div>
|
||||
<div class="sub">或拖拽图片到此处 / Ctrl+V 粘贴截图</div>
|
||||
<div class="sub">支持二维码、条形码混合识别</div>
|
||||
</div>
|
||||
</div>
|
||||
<div v-if="fileName" class="hint">
|
||||
{{ fileName }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- right: results -->
|
||||
<div class="pane">
|
||||
<n-spin :show="loading">
|
||||
<div v-if="error && !results.length" class="cr-error">
|
||||
{{ error }}
|
||||
</div>
|
||||
<div v-else-if="!results.length" class="empty">
|
||||
识别结果将显示在这里
|
||||
</div>
|
||||
<div v-else class="results">
|
||||
<div v-for="(r, i) in results" :key="i" class="result-item">
|
||||
<div class="result-head">
|
||||
<span class="badge">{{ r.format }}</span>
|
||||
<span class="meta">{{ r.contentType }} · {{ r.symbology }}</span>
|
||||
<c-button size="small" @click="copyText(r.text)">
|
||||
复制
|
||||
</c-button>
|
||||
</div>
|
||||
<div class="result-text">
|
||||
{{ r.text }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</n-spin>
|
||||
<div v-if="error && results.length" class="warn">
|
||||
{{ error }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<GenHistory tool="code-reader" position="bottom" label="识别记录" />
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.cr-root {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
width: 100%;
|
||||
min-height: 0;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
|
||||
.toolbar {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
align-items: center;
|
||||
justify-content: flex-end;
|
||||
gap: 10px;
|
||||
padding-bottom: 12px;
|
||||
flex-shrink: 0;
|
||||
|
||||
.stats {
|
||||
margin-right: auto;
|
||||
font-size: 13px;
|
||||
opacity: 0.65;
|
||||
}
|
||||
}
|
||||
|
||||
.body {
|
||||
display: flex;
|
||||
flex-direction: row;
|
||||
gap: 16px;
|
||||
flex: 1;
|
||||
min-height: 0;
|
||||
|
||||
@media (max-width: 760px) {
|
||||
flex-direction: column;
|
||||
}
|
||||
}
|
||||
|
||||
.pane {
|
||||
flex: 1;
|
||||
min-width: 0;
|
||||
min-height: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
}
|
||||
|
||||
.dropzone {
|
||||
flex: 1;
|
||||
min-height: 180px;
|
||||
border: 2px dashed rgba(128, 128, 128, 0.45);
|
||||
border-radius: 10px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
cursor: pointer;
|
||||
overflow: hidden;
|
||||
transition: border-color 0.2s, background-color 0.2s;
|
||||
box-sizing: border-box;
|
||||
|
||||
&:hover,
|
||||
&.active {
|
||||
border-color: #18a058;
|
||||
background-color: rgba(24, 160, 88, 0.06);
|
||||
}
|
||||
|
||||
img {
|
||||
max-width: 100%;
|
||||
max-height: 100%;
|
||||
object-fit: contain;
|
||||
}
|
||||
|
||||
.drop-hint {
|
||||
text-align: center;
|
||||
font-size: 14px;
|
||||
opacity: 0.75;
|
||||
|
||||
.icon {
|
||||
font-size: 40px;
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.sub {
|
||||
font-size: 12px;
|
||||
opacity: 0.6;
|
||||
margin-top: 6px;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.hint {
|
||||
font-size: 12px;
|
||||
opacity: 0.55;
|
||||
margin-top: 6px;
|
||||
flex-shrink: 0;
|
||||
}
|
||||
|
||||
.empty {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
height: 100%;
|
||||
min-height: 150px;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 6px;
|
||||
opacity: 0.5;
|
||||
font-size: 14px;
|
||||
}
|
||||
|
||||
.cr-error {
|
||||
color: #d03050;
|
||||
font-size: 13px;
|
||||
padding: 12px;
|
||||
border: 1px solid rgba(208, 48, 80, 0.35);
|
||||
border-radius: 6px;
|
||||
}
|
||||
|
||||
.warn {
|
||||
font-size: 12px;
|
||||
color: #d03050;
|
||||
margin-top: 8px;
|
||||
opacity: 0.85;
|
||||
}
|
||||
|
||||
.results {
|
||||
height: 100%;
|
||||
overflow-y: auto;
|
||||
border: 1px solid rgba(128, 128, 128, 0.3);
|
||||
border-radius: 6px;
|
||||
padding: 8px;
|
||||
box-sizing: border-box;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.result-item {
|
||||
border: 1px solid rgba(128, 128, 128, 0.22);
|
||||
border-radius: 6px;
|
||||
padding: 8px 10px;
|
||||
user-select: text;
|
||||
|
||||
.result-head {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
margin-bottom: 6px;
|
||||
|
||||
.badge {
|
||||
background: rgba(24, 160, 88, 0.14);
|
||||
color: #18a058;
|
||||
font-size: 12px;
|
||||
font-weight: 600;
|
||||
padding: 1px 8px;
|
||||
border-radius: 10px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.meta {
|
||||
font-size: 11px;
|
||||
opacity: 0.5;
|
||||
flex: 1;
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
|
||||
.result-text {
|
||||
font-size: 13.5px;
|
||||
line-height: 1.6;
|
||||
word-break: break-all;
|
||||
white-space: pre-wrap;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Scan } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.code-reader.title'),
|
||||
path: '/code-reader',
|
||||
description: translate('tools.code-reader.description'),
|
||||
keywords: ['scan', 'reader', 'decode', 'qr', 'barcode', 'zxing', 'camera', 'image', '识别', '扫码', '读取', '解码', '二维码', '条码'],
|
||||
component: () => import('./code-reader.vue'),
|
||||
icon: Scan,
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Tool - Color converter', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/color-converter');
|
||||
});
|
||||
|
||||
test('Has title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('Color converter - IT Tools');
|
||||
});
|
||||
|
||||
test('Color is converted from its name to other formats', async ({ page }) => {
|
||||
await page.getByTestId('input-name').fill('olive');
|
||||
|
||||
expect(await page.getByTestId('input-name').inputValue()).toEqual('olive');
|
||||
expect(await page.getByTestId('input-hex').inputValue()).toEqual('#808000');
|
||||
expect(await page.getByTestId('input-rgb').inputValue()).toEqual('rgb(128, 128, 0)');
|
||||
expect(await page.getByTestId('input-hsl').inputValue()).toEqual('hsl(60, 100%, 25%)');
|
||||
expect(await page.getByTestId('input-hwb').inputValue()).toEqual('hwb(60 0% 50%)');
|
||||
expect(await page.getByTestId('input-cmyk').inputValue()).toEqual('device-cmyk(0% 0% 100% 50%)');
|
||||
expect(await page.getByTestId('input-lch').inputValue()).toEqual('lch(52.15% 56.81 99.57)');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,13 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { removeAlphaChannelWhenOpaque } from './color-converter.models';
|
||||
|
||||
describe('color-converter models', () => {
|
||||
describe('removeAlphaChannelWhenOpaque', () => {
|
||||
it('remove alpha channel of an hex color when it is opaque (alpha = 1)', () => {
|
||||
expect(removeAlphaChannelWhenOpaque('#000000ff')).toBe('#000000');
|
||||
expect(removeAlphaChannelWhenOpaque('#ffffffFF')).toBe('#ffffff');
|
||||
expect(removeAlphaChannelWhenOpaque('#000000FE')).toBe('#000000FE');
|
||||
expect(removeAlphaChannelWhenOpaque('#00000000')).toBe('#00000000');
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,52 @@
|
||||
import { type Colord, colord } from 'colord';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
export { removeAlphaChannelWhenOpaque, buildColorFormat };
|
||||
|
||||
function removeAlphaChannelWhenOpaque(hexColor: string) {
|
||||
return hexColor.replace(/^(#(?:[0-9a-f]{3}){1,2})ff$/i, '$1');
|
||||
}
|
||||
|
||||
function buildColorFormat({
|
||||
label,
|
||||
parse = value => colord(value),
|
||||
format,
|
||||
placeholder,
|
||||
invalidMessage = `Invalid ${label.toLowerCase()} format.`,
|
||||
type = 'text',
|
||||
}: {
|
||||
label: string
|
||||
parse?: (value: string) => Colord
|
||||
format: (value: Colord) => string
|
||||
placeholder?: string
|
||||
invalidMessage?: string
|
||||
type?: 'text' | 'color-picker'
|
||||
}) {
|
||||
const value = ref('');
|
||||
|
||||
return {
|
||||
type,
|
||||
label,
|
||||
parse: (v: string) => withDefaultOnError(() => parse(v), undefined),
|
||||
format,
|
||||
placeholder,
|
||||
value,
|
||||
validation: useValidation({
|
||||
source: value,
|
||||
rules: [
|
||||
{
|
||||
message: invalidMessage,
|
||||
validator: v => withDefaultOnError(() => {
|
||||
if (v === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return parse(v).isValid();
|
||||
}, false),
|
||||
},
|
||||
],
|
||||
}),
|
||||
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
<script setup lang="ts">
|
||||
import type { Colord } from 'colord';
|
||||
import { colord, extend } from 'colord';
|
||||
import _ from 'lodash';
|
||||
import cmykPlugin from 'colord/plugins/cmyk';
|
||||
import hwbPlugin from 'colord/plugins/hwb';
|
||||
import namesPlugin from 'colord/plugins/names';
|
||||
import lchPlugin from 'colord/plugins/lch';
|
||||
import { buildColorFormat } from './color-converter.models';
|
||||
|
||||
extend([cmykPlugin, hwbPlugin, namesPlugin, lchPlugin]);
|
||||
|
||||
const formats = {
|
||||
picker: buildColorFormat({
|
||||
label: 'color picker',
|
||||
format: (v: Colord) => v.toHex(),
|
||||
type: 'color-picker',
|
||||
}),
|
||||
hex: buildColorFormat({
|
||||
label: 'hex',
|
||||
format: (v: Colord) => v.toHex(),
|
||||
placeholder: 'e.g. #ff0000',
|
||||
}),
|
||||
rgb: buildColorFormat({
|
||||
label: 'rgb',
|
||||
format: (v: Colord) => v.toRgbString(),
|
||||
placeholder: 'e.g. rgb(255, 0, 0)',
|
||||
}),
|
||||
hsl: buildColorFormat({
|
||||
label: 'hsl',
|
||||
format: (v: Colord) => v.toHslString(),
|
||||
placeholder: 'e.g. hsl(0, 100%, 50%)',
|
||||
}),
|
||||
hwb: buildColorFormat({
|
||||
label: 'hwb',
|
||||
format: (v: Colord) => v.toHwbString(),
|
||||
placeholder: 'e.g. hwb(0, 0%, 0%)',
|
||||
}),
|
||||
lch: buildColorFormat({
|
||||
label: 'lch',
|
||||
format: (v: Colord) => v.toLchString(),
|
||||
placeholder: 'e.g. lch(53.24, 104.55, 40.85)',
|
||||
}),
|
||||
cmyk: buildColorFormat({
|
||||
label: 'cmyk',
|
||||
format: (v: Colord) => v.toCmykString(),
|
||||
placeholder: 'e.g. cmyk(0, 100%, 100%, 0)',
|
||||
}),
|
||||
name: buildColorFormat({
|
||||
label: 'name',
|
||||
format: (v: Colord) => v.toName({ closest: true }) ?? 'Unknown',
|
||||
placeholder: 'e.g. red',
|
||||
}),
|
||||
};
|
||||
|
||||
updateColorValue(colord('#1ea54c'));
|
||||
|
||||
function updateColorValue(value: Colord | undefined, omitLabel?: string) {
|
||||
if (value === undefined) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!value.isValid()) {
|
||||
return;
|
||||
}
|
||||
|
||||
_.forEach(formats, ({ value: valueRef, format }, key) => {
|
||||
if (key !== omitLabel) {
|
||||
valueRef.value = format(value);
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<template v-for="({ label, parse, placeholder, validation, type }, key) in formats" :key="key">
|
||||
<input-copyable
|
||||
v-if="type === 'text'"
|
||||
v-model:value="formats[key].value.value"
|
||||
:test-id="`input-${key}`"
|
||||
:label="`${label}:`"
|
||||
label-position="left"
|
||||
label-width="100px"
|
||||
label-align="right"
|
||||
:placeholder="placeholder"
|
||||
:validation="validation"
|
||||
raw-text
|
||||
clearable
|
||||
mt-2
|
||||
@update:value="(v:string) => updateColorValue(parse(v), key)"
|
||||
/>
|
||||
|
||||
<n-form-item v-else-if="type === 'color-picker'" :label="`${label}:`" label-width="100" label-placement="left" :show-feedback="false">
|
||||
<n-color-picker
|
||||
v-model:value="formats[key].value.value"
|
||||
placement="bottom-end"
|
||||
@update:value="(v:string) => updateColorValue(parse(v), key)"
|
||||
/>
|
||||
</n-form-item>
|
||||
</template>
|
||||
</c-card>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { Palette } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.color-converter.title'),
|
||||
path: '/color-converter',
|
||||
description: translate('tools.color-converter.description'),
|
||||
keywords: ['color', 'converter'],
|
||||
component: () => import('./color-converter.vue'),
|
||||
icon: Palette,
|
||||
redirectFrom: ['/color-picker-converter'],
|
||||
});
|
||||
@@ -0,0 +1,194 @@
|
||||
<script setup lang="ts">
|
||||
import cronstrue from 'cronstrue';
|
||||
import { isValidCron } from 'cron-validator';
|
||||
import { useStyleStore } from '@/stores/style.store';
|
||||
|
||||
function isCronValid(v: string) {
|
||||
return isValidCron(v, { allowBlankDay: true, alias: true, seconds: true });
|
||||
}
|
||||
|
||||
const styleStore = useStyleStore();
|
||||
|
||||
const cron = ref('40 * * * *');
|
||||
const cronstrueConfig = reactive({
|
||||
verbose: true,
|
||||
dayOfWeekStartIndexZero: true,
|
||||
use24HourTimeFormat: true,
|
||||
throwExceptionOnParseError: true,
|
||||
});
|
||||
|
||||
const helpers = [
|
||||
{
|
||||
symbol: '*',
|
||||
meaning: 'Any value',
|
||||
example: '* * * *',
|
||||
equivalent: 'Every minute',
|
||||
},
|
||||
{
|
||||
symbol: '-',
|
||||
meaning: 'Range of values',
|
||||
example: '1-10 * * *',
|
||||
equivalent: 'Minutes 1 through 10',
|
||||
},
|
||||
{
|
||||
symbol: ',',
|
||||
meaning: 'List of values',
|
||||
example: '1,10 * * *',
|
||||
equivalent: 'At minutes 1 and 10',
|
||||
},
|
||||
{
|
||||
symbol: '/',
|
||||
meaning: 'Step values',
|
||||
example: '*/10 * * *',
|
||||
equivalent: 'Every 10 minutes',
|
||||
},
|
||||
{
|
||||
symbol: '@yearly',
|
||||
meaning: 'Once every year at midnight of 1 January',
|
||||
example: '@yearly',
|
||||
equivalent: '0 0 1 1 *',
|
||||
},
|
||||
{
|
||||
symbol: '@annually',
|
||||
meaning: 'Same as @yearly',
|
||||
example: '@annually',
|
||||
equivalent: '0 0 1 1 *',
|
||||
},
|
||||
{
|
||||
symbol: '@monthly',
|
||||
meaning: 'Once a month at midnight on the first day',
|
||||
example: '@monthly',
|
||||
equivalent: '0 0 1 * *',
|
||||
},
|
||||
{
|
||||
symbol: '@weekly',
|
||||
meaning: 'Once a week at midnight on Sunday morning',
|
||||
example: '@weekly',
|
||||
equivalent: '0 0 * * 0',
|
||||
},
|
||||
{
|
||||
symbol: '@daily',
|
||||
meaning: 'Once a day at midnight',
|
||||
example: '@daily',
|
||||
equivalent: '0 0 * * *',
|
||||
},
|
||||
{
|
||||
symbol: '@midnight',
|
||||
meaning: 'Same as @daily',
|
||||
example: '@midnight',
|
||||
equivalent: '0 0 * * *',
|
||||
},
|
||||
{
|
||||
symbol: '@hourly',
|
||||
meaning: 'Once an hour at the beginning of the hour',
|
||||
example: '@hourly',
|
||||
equivalent: '0 * * * *',
|
||||
},
|
||||
{
|
||||
symbol: '@reboot',
|
||||
meaning: 'Run at startup',
|
||||
example: '',
|
||||
equivalent: '',
|
||||
},
|
||||
];
|
||||
|
||||
const cronString = computed(() => {
|
||||
if (isCronValid(cron.value)) {
|
||||
return cronstrue.toString(cron.value, cronstrueConfig);
|
||||
}
|
||||
return ' ';
|
||||
});
|
||||
|
||||
const cronValidationRules = [
|
||||
{
|
||||
validator: (value: string) => isCronValid(value),
|
||||
message: 'This cron is invalid',
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card>
|
||||
<div mx-auto max-w-sm>
|
||||
<c-input-text
|
||||
v-model:value="cron"
|
||||
size="large"
|
||||
placeholder="* * * * *"
|
||||
:validation-rules="cronValidationRules"
|
||||
mb-3
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div class="cron-string">
|
||||
{{ cronString }}
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<div flex justify-center>
|
||||
<n-form :show-feedback="false" label-width="170" label-placement="left">
|
||||
<n-form-item label="Verbose">
|
||||
<n-switch v-model:value="cronstrueConfig.verbose" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Use 24 hour time format">
|
||||
<n-switch v-model:value="cronstrueConfig.use24HourTimeFormat" />
|
||||
</n-form-item>
|
||||
<n-form-item label="Days start at 0">
|
||||
<n-switch v-model:value="cronstrueConfig.dayOfWeekStartIndexZero" />
|
||||
</n-form-item>
|
||||
</n-form>
|
||||
</div>
|
||||
</c-card>
|
||||
<c-card>
|
||||
<pre>
|
||||
┌──────────── [optional] seconds (0 - 59)
|
||||
| ┌────────── minute (0 - 59)
|
||||
| | ┌──────── hour (0 - 23)
|
||||
| | | ┌────── day of month (1 - 31)
|
||||
| | | | ┌──── month (1 - 12) OR jan,feb,mar,apr ...
|
||||
| | | | | ┌── day of week (0 - 6, sunday=0) OR sun,mon ...
|
||||
| | | | | |
|
||||
* * * * * * command</pre>
|
||||
|
||||
<div v-if="styleStore.isSmallScreen">
|
||||
<c-card v-for="{ symbol, meaning, example, equivalent } in helpers" :key="symbol" mb-3 important:border-none>
|
||||
<div>
|
||||
Symbol: <strong>{{ symbol }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
Meaning: <strong>{{ meaning }}</strong>
|
||||
</div>
|
||||
<div>
|
||||
Example:
|
||||
<strong><code>{{ example }}</code></strong>
|
||||
</div>
|
||||
<div>
|
||||
Equivalent: <strong>{{ equivalent }}</strong>
|
||||
</div>
|
||||
</c-card>
|
||||
</div>
|
||||
|
||||
<c-table v-else :data="helpers" />
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
::v-deep(input) {
|
||||
font-size: 30px;
|
||||
font-family: monospace;
|
||||
padding: 5px;
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.cron-string {
|
||||
text-align: center;
|
||||
font-size: 22px;
|
||||
opacity: 0.8;
|
||||
margin: 5px 0 15px;
|
||||
}
|
||||
|
||||
pre {
|
||||
overflow: auto;
|
||||
padding: 10px 0;
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,26 @@
|
||||
import { Alarm } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.crontab-generator.title'),
|
||||
path: '/crontab-generator',
|
||||
description: translate('tools.crontab-generator.description'),
|
||||
keywords: [
|
||||
'crontab',
|
||||
'generator',
|
||||
'cronjob',
|
||||
'cron',
|
||||
'schedule',
|
||||
'parse',
|
||||
'expression',
|
||||
'year',
|
||||
'month',
|
||||
'week',
|
||||
'day',
|
||||
'minute',
|
||||
'second',
|
||||
],
|
||||
component: () => import('./crontab-generator.vue'),
|
||||
icon: Alarm,
|
||||
});
|
||||
@@ -0,0 +1,34 @@
|
||||
import { expect, test } from '@playwright/test';
|
||||
|
||||
test.describe('Date time converter - json to yaml', () => {
|
||||
test.beforeEach(async ({ page }) => {
|
||||
await page.goto('/date-converter');
|
||||
});
|
||||
|
||||
test('Has correct title', async ({ page }) => {
|
||||
await expect(page).toHaveTitle('Date-time converter - IT Tools');
|
||||
});
|
||||
|
||||
test('Format is auto detected from a date and the date is correctly converted', async ({ page }) => {
|
||||
const initialFormat = await page.getByTestId('date-time-converter-format-select').innerText();
|
||||
expect(initialFormat.trim()).toEqual('Timestamp');
|
||||
|
||||
await page.getByTestId('date-time-converter-input').fill('2023-04-12T23:10:24+02:00');
|
||||
|
||||
const detectedFormat = await page.getByTestId('date-time-converter-format-select').innerText();
|
||||
expect(detectedFormat.trim()).toEqual('ISO 8601');
|
||||
|
||||
expect((await page.getByTestId('JS locale date string').inputValue()).trim()).toEqual(
|
||||
'Wed Apr 12 2023 23:10:24 GMT+0200 (Central European Summer Time)',
|
||||
);
|
||||
expect((await page.getByTestId('ISO 8601').inputValue()).trim()).toEqual('2023-04-12T23:10:24+02:00');
|
||||
expect((await page.getByTestId('ISO 9075').inputValue()).trim()).toEqual('2023-04-12 23:10:24');
|
||||
expect((await page.getByTestId('Unix timestamp').inputValue()).trim()).toEqual('1681333824');
|
||||
expect((await page.getByTestId('RFC 7231').inputValue()).trim()).toEqual('Wed, 12 Apr 2023 21:10:24 GMT');
|
||||
expect((await page.getByTestId('RFC 3339').inputValue()).trim()).toEqual('2023-04-12T23:10:24+02:00');
|
||||
expect((await page.getByTestId('Timestamp').inputValue()).trim()).toEqual('1681333824000');
|
||||
expect((await page.getByTestId('UTC format').inputValue()).trim()).toEqual('Wed, 12 Apr 2023 21:10:24 GMT');
|
||||
expect((await page.getByTestId('Mongo ObjectID').inputValue()).trim()).toEqual('64371e400000000000000000');
|
||||
expect((await page.getByTestId('Excel date/time').inputValue()).trim()).toEqual('45028.88222222222');
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,180 @@
|
||||
import { describe, expect, test } from 'vitest';
|
||||
import {
|
||||
dateToExcelFormat,
|
||||
excelFormatToDate,
|
||||
isExcelFormat,
|
||||
isISO8601DateTimeString,
|
||||
isISO9075DateString,
|
||||
isMongoObjectId,
|
||||
isRFC3339DateString,
|
||||
isRFC7231DateString,
|
||||
isTimestamp,
|
||||
isUTCDateString,
|
||||
isUnixTimestamp,
|
||||
} from './date-time-converter.models';
|
||||
|
||||
describe('date-time-converter models', () => {
|
||||
describe('isISO8601DateTimeString', () => {
|
||||
test('should return true for valid ISO 8601 date strings', () => {
|
||||
expect(isISO8601DateTimeString('2021-01-01T00:00:00.000Z')).toBe(true);
|
||||
expect(isISO8601DateTimeString('2023-04-12T14:56:00+01:00')).toBe(true);
|
||||
expect(isISO8601DateTimeString('20230412T145600+0100')).toBe(true);
|
||||
expect(isISO8601DateTimeString('20230412T145600Z')).toBe(true);
|
||||
expect(isISO8601DateTimeString('2016-02-01')).toBe(true);
|
||||
expect(isISO8601DateTimeString('2016')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid ISO 8601 date strings', () => {
|
||||
expect(isISO8601DateTimeString()).toBe(false);
|
||||
expect(isISO8601DateTimeString('')).toBe(false);
|
||||
expect(isISO8601DateTimeString('qsdqsd')).toBe(false);
|
||||
expect(isISO8601DateTimeString('2016-02-01-')).toBe(false);
|
||||
expect(isISO8601DateTimeString('2021-01-01T00:00:00.')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isISO9075DateString', () => {
|
||||
test('should return true for valid ISO 9075 date strings', () => {
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00Z')).toBe(true);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00.123456Z')).toBe(true);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00+01:00')).toBe(true);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00-05:00')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid ISO 9075 date strings', () => {
|
||||
expect(isISO9075DateString('2022/01/01T12:00:00Z')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00.123456789Z')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00+1:00')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00-05:')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01 12:00:00-05:00:00')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01')).toBe(false);
|
||||
expect(isISO9075DateString('12:00:00Z')).toBe(false);
|
||||
expect(isISO9075DateString('2022-01-01T12:00:00Zfoo')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRFC3339DateString', () => {
|
||||
test('should return true for valid RFC 3339 date strings', () => {
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00Z')).toBe(true);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00.123456789Z')).toBe(true);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00.123456789+01:00')).toBe(true);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00-05:00')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid RFC 3339 date strings', () => {
|
||||
expect(isRFC3339DateString('2022/01/01T12:00:00Z')).toBe(false);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00.123456789+1:00')).toBe(false);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00-05:')).toBe(false);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00-05:00:00')).toBe(false);
|
||||
expect(isRFC3339DateString('2022-01-01')).toBe(false);
|
||||
expect(isRFC3339DateString('12:00:00Z')).toBe(false);
|
||||
expect(isRFC3339DateString('2022-01-01T12:00:00Zfoo')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isRFC7231DateString', () => {
|
||||
test('should return true for valid RFC 7231 date strings', () => {
|
||||
expect(isRFC7231DateString('Sun, 06 Nov 1994 08:49:37 GMT')).toBe(true);
|
||||
expect(isRFC7231DateString('Tue, 22 Apr 2014 07:00:00 GMT')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid RFC 7231 date strings', () => {
|
||||
expect(isRFC7231DateString('06 Nov 1994 08:49:37 GMT')).toBe(false);
|
||||
expect(isRFC7231DateString('Sun, 06 Nov 94 08:49:37 GMT')).toBe(false);
|
||||
expect(isRFC7231DateString('Sun, 06 Nov 1994 8:49:37 GMT')).toBe(false);
|
||||
expect(isRFC7231DateString('Sun, 06 Nov 1994 08:49:37 GMT-0500')).toBe(false);
|
||||
expect(isRFC7231DateString('Sun, 06 November 1994 08:49:37 GMT')).toBe(false);
|
||||
expect(isRFC7231DateString('Sunday, 06 Nov 1994 08:49:37 GMT')).toBe(false);
|
||||
expect(isRFC7231DateString('06 Nov 1994')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isUnixTimestamp', () => {
|
||||
test('should return true for valid Unix timestamps', () => {
|
||||
expect(isUnixTimestamp('1649789394')).toBe(true);
|
||||
expect(isUnixTimestamp('1234567890')).toBe(true);
|
||||
expect(isUnixTimestamp('0')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid Unix timestamps', () => {
|
||||
expect(isUnixTimestamp('foo')).toBe(false);
|
||||
expect(isUnixTimestamp('')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isTimestamp', () => {
|
||||
test('should return true for valid Unix timestamps in milliseconds', () => {
|
||||
expect(isTimestamp('1649792026123')).toBe(true);
|
||||
expect(isTimestamp('1234567890000')).toBe(true);
|
||||
expect(isTimestamp('0')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid Unix timestamps in milliseconds', () => {
|
||||
expect(isTimestamp('foo')).toBe(false);
|
||||
expect(isTimestamp('')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isUTCDateString', () => {
|
||||
test('should return true for valid UTC date strings', () => {
|
||||
expect(isUTCDateString('Sun, 06 Nov 1994 08:49:37 GMT')).toBe(true);
|
||||
expect(isUTCDateString('Tue, 22 Apr 2014 07:00:00 GMT')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid UTC date strings', () => {
|
||||
expect(isUTCDateString('06 Nov 1994 08:49:37 GMT')).toBe(false);
|
||||
expect(isUTCDateString('16497920261')).toBe(false);
|
||||
expect(isUTCDateString('foo')).toBe(false);
|
||||
expect(isUTCDateString('')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isMongoObjectId', () => {
|
||||
test('should return true for valid Mongo ObjectIds', () => {
|
||||
expect(isMongoObjectId('507f1f77bcf86cd799439011')).toBe(true);
|
||||
expect(isMongoObjectId('507f1f77bcf86cd799439012')).toBe(true);
|
||||
});
|
||||
|
||||
test('should return false for invalid Mongo ObjectIds', () => {
|
||||
expect(isMongoObjectId('507f1f77bcf86cd79943901')).toBe(false);
|
||||
expect(isMongoObjectId('507f1f77bcf86cd79943901z')).toBe(false);
|
||||
expect(isMongoObjectId('foo')).toBe(false);
|
||||
expect(isMongoObjectId('')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('isExcelFormat', () => {
|
||||
test('an Excel format string is a floating number that can be negative', () => {
|
||||
expect(isExcelFormat('0')).toBe(true);
|
||||
expect(isExcelFormat('1')).toBe(true);
|
||||
expect(isExcelFormat('1.1')).toBe(true);
|
||||
expect(isExcelFormat('-1.1')).toBe(true);
|
||||
expect(isExcelFormat('-1')).toBe(true);
|
||||
|
||||
expect(isExcelFormat('')).toBe(false);
|
||||
expect(isExcelFormat('foo')).toBe(false);
|
||||
expect(isExcelFormat('1.1.1')).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('dateToExcelFormat', () => {
|
||||
test('a date in Excel format is the number of days since 01/01/1900', () => {
|
||||
expect(dateToExcelFormat(new Date('2016-05-20T00:00:00.000Z'))).toBe('42510');
|
||||
expect(dateToExcelFormat(new Date('2016-05-20T12:00:00.000Z'))).toBe('42510.5');
|
||||
expect(dateToExcelFormat(new Date('2023-10-31T09:26:06.421Z'))).toBe('45230.39312987268');
|
||||
expect(dateToExcelFormat(new Date('1970-01-01T00:00:00.000Z'))).toBe('25569');
|
||||
expect(dateToExcelFormat(new Date('1800-01-01T00:00:00.000Z'))).toBe('-36522');
|
||||
});
|
||||
});
|
||||
|
||||
describe('excelFormatToDate', () => {
|
||||
test('a date in Excel format is the number of days since 01/01/1900', () => {
|
||||
expect(excelFormatToDate('0')).toEqual(new Date('1899-12-30T00:00:00.000Z'));
|
||||
expect(excelFormatToDate('1')).toEqual(new Date('1899-12-31T00:00:00.000Z'));
|
||||
expect(excelFormatToDate('2')).toEqual(new Date('1900-01-01T00:00:00.000Z'));
|
||||
expect(excelFormatToDate('4242.4242')).toEqual(new Date('1911-08-12T10:10:50.880Z'));
|
||||
expect(excelFormatToDate('42738.22626859954')).toEqual(new Date('2017-01-03T05:25:49.607Z'));
|
||||
expect(excelFormatToDate('-1000')).toEqual(new Date('1897-04-04T00:00:00.000Z'));
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,62 @@
|
||||
import _ from 'lodash';
|
||||
|
||||
export {
|
||||
isISO8601DateTimeString,
|
||||
isISO9075DateString,
|
||||
isRFC3339DateString,
|
||||
isRFC7231DateString,
|
||||
isUnixTimestamp,
|
||||
isTimestamp,
|
||||
isUTCDateString,
|
||||
isMongoObjectId,
|
||||
dateToExcelFormat,
|
||||
excelFormatToDate,
|
||||
isExcelFormat,
|
||||
};
|
||||
|
||||
const ISO8601_REGEX
|
||||
= /^([+-]?\d{4}(?!\d{2}\b))((-?)((0[1-9]|1[0-2])(\3([12]\d|0[1-9]|3[01]))?|W([0-4]\d|5[0-2])(-?[1-7])?|(00[1-9]|0[1-9]\d|[12]\d{2}|3([0-5]\d|6[1-6])))([T\s]((([01]\d|2[0-3])((:?)[0-5]\d)?|24:?00)([.,]\d+(?!:))?)?(\17[0-5]\d([.,]\d+)?)?([zZ]|([+-])([01]\d|2[0-3]):?([0-5]\d)?)?)?)?$/;
|
||||
const ISO9075_REGEX
|
||||
= /^([0-9]{4})-([0-9]{2})-([0-9]{2}) ([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,6})?(([+-])([0-9]{2}):([0-9]{2})|Z)?$/;
|
||||
|
||||
const RFC3339_REGEX
|
||||
= /^([0-9]{4})-([0-9]{2})-([0-9]{2})T([0-9]{2}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,9})?(([+-])([0-9]{2}):([0-9]{2})|Z)$/;
|
||||
|
||||
const RFC7231_REGEX = /^[A-Za-z]{3},\s[0-9]{2}\s[A-Za-z]{3}\s[0-9]{4}\s[0-9]{2}:[0-9]{2}:[0-9]{2}\sGMT$/;
|
||||
|
||||
const EXCEL_FORMAT_REGEX = /^-?\d+(\.\d+)?$/;
|
||||
|
||||
function createRegexMatcher(regex: RegExp) {
|
||||
return (date?: string) => !_.isNil(date) && regex.test(date);
|
||||
}
|
||||
|
||||
const isISO8601DateTimeString = createRegexMatcher(ISO8601_REGEX);
|
||||
const isISO9075DateString = createRegexMatcher(ISO9075_REGEX);
|
||||
const isRFC3339DateString = createRegexMatcher(RFC3339_REGEX);
|
||||
const isRFC7231DateString = createRegexMatcher(RFC7231_REGEX);
|
||||
const isUnixTimestamp = createRegexMatcher(/^[0-9]{1,10}$/);
|
||||
const isTimestamp = createRegexMatcher(/^[0-9]{1,13}$/);
|
||||
const isMongoObjectId = createRegexMatcher(/^[0-9a-fA-F]{24}$/);
|
||||
|
||||
const isExcelFormat = createRegexMatcher(EXCEL_FORMAT_REGEX);
|
||||
|
||||
function isUTCDateString(date?: string) {
|
||||
if (_.isNil(date)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return new Date(date).toUTCString() === date;
|
||||
}
|
||||
catch (_ignored) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
function dateToExcelFormat(date: Date) {
|
||||
return String(((date.getTime()) / (1000 * 60 * 60 * 24)) + 25569);
|
||||
}
|
||||
|
||||
function excelFormatToDate(excelFormat: string | number) {
|
||||
return new Date((Number(excelFormat) - 25569) * 86400 * 1000);
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
export type ToDateMapper = (value: string) => Date;
|
||||
|
||||
export interface DateFormat {
|
||||
name: string
|
||||
fromDate: (date: Date) => string
|
||||
toDate: (value: string) => Date
|
||||
formatMatcher: (dateString: string) => boolean
|
||||
}
|
||||
@@ -0,0 +1,189 @@
|
||||
<script setup lang="ts">
|
||||
import {
|
||||
formatISO,
|
||||
formatISO9075,
|
||||
formatRFC3339,
|
||||
formatRFC7231,
|
||||
fromUnixTime,
|
||||
getTime,
|
||||
getUnixTime,
|
||||
isDate,
|
||||
isValid,
|
||||
parseISO,
|
||||
parseJSON,
|
||||
} from 'date-fns';
|
||||
import type { DateFormat, ToDateMapper } from './date-time-converter.types';
|
||||
import {
|
||||
dateToExcelFormat,
|
||||
excelFormatToDate,
|
||||
isExcelFormat,
|
||||
isISO8601DateTimeString,
|
||||
isISO9075DateString,
|
||||
isMongoObjectId,
|
||||
isRFC3339DateString,
|
||||
isRFC7231DateString,
|
||||
isTimestamp,
|
||||
isUTCDateString,
|
||||
isUnixTimestamp,
|
||||
} from './date-time-converter.models';
|
||||
import { withDefaultOnError } from '@/utils/defaults';
|
||||
import { useValidation } from '@/composable/validation';
|
||||
|
||||
const inputDate = ref('');
|
||||
|
||||
const toDate: ToDateMapper = date => new Date(date);
|
||||
|
||||
const formats: DateFormat[] = [
|
||||
{
|
||||
name: 'JS locale date string',
|
||||
fromDate: date => date.toString(),
|
||||
toDate,
|
||||
formatMatcher: () => false,
|
||||
},
|
||||
{
|
||||
name: 'ISO 8601',
|
||||
fromDate: formatISO,
|
||||
toDate: parseISO,
|
||||
formatMatcher: date => isISO8601DateTimeString(date),
|
||||
},
|
||||
{
|
||||
name: 'ISO 9075',
|
||||
fromDate: formatISO9075,
|
||||
toDate: parseISO,
|
||||
formatMatcher: date => isISO9075DateString(date),
|
||||
},
|
||||
{
|
||||
name: 'RFC 3339',
|
||||
fromDate: formatRFC3339,
|
||||
toDate,
|
||||
formatMatcher: date => isRFC3339DateString(date),
|
||||
},
|
||||
{
|
||||
name: 'RFC 7231',
|
||||
fromDate: formatRFC7231,
|
||||
toDate,
|
||||
formatMatcher: date => isRFC7231DateString(date),
|
||||
},
|
||||
{
|
||||
name: 'Unix timestamp',
|
||||
fromDate: date => String(getUnixTime(date)),
|
||||
toDate: sec => fromUnixTime(+sec),
|
||||
formatMatcher: date => isUnixTimestamp(date),
|
||||
},
|
||||
{
|
||||
name: 'Timestamp',
|
||||
fromDate: date => String(getTime(date)),
|
||||
toDate: ms => parseJSON(+ms),
|
||||
formatMatcher: date => isTimestamp(date),
|
||||
},
|
||||
{
|
||||
name: 'UTC format',
|
||||
fromDate: date => date.toUTCString(),
|
||||
toDate,
|
||||
formatMatcher: date => isUTCDateString(date),
|
||||
},
|
||||
{
|
||||
name: 'Mongo ObjectID',
|
||||
fromDate: date => `${Math.floor(date.getTime() / 1000).toString(16)}0000000000000000`,
|
||||
toDate: objectId => new Date(Number.parseInt(objectId.substring(0, 8), 16) * 1000),
|
||||
formatMatcher: date => isMongoObjectId(date),
|
||||
},
|
||||
{
|
||||
name: 'Excel date/time',
|
||||
fromDate: date => dateToExcelFormat(date),
|
||||
toDate: excelFormatToDate,
|
||||
formatMatcher: isExcelFormat,
|
||||
},
|
||||
];
|
||||
|
||||
const formatIndex = ref(6);
|
||||
const now = useNow();
|
||||
|
||||
const normalizedDate = computed(() => {
|
||||
if (!inputDate.value) {
|
||||
return now.value;
|
||||
}
|
||||
|
||||
const { toDate } = formats[formatIndex.value];
|
||||
|
||||
try {
|
||||
return toDate(inputDate.value);
|
||||
}
|
||||
catch (_ignored) {
|
||||
return undefined;
|
||||
}
|
||||
});
|
||||
|
||||
function onDateInputChanged(value: string) {
|
||||
const matchingIndex = formats.findIndex(({ formatMatcher }) => formatMatcher(value));
|
||||
if (matchingIndex !== -1) {
|
||||
formatIndex.value = matchingIndex;
|
||||
}
|
||||
}
|
||||
|
||||
const validation = useValidation({
|
||||
source: inputDate,
|
||||
watch: [formatIndex],
|
||||
rules: [
|
||||
{
|
||||
message: 'This date is invalid for this format',
|
||||
validator: value =>
|
||||
withDefaultOnError(() => {
|
||||
if (value === '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
const maybeDate = formats[formatIndex.value].toDate(value);
|
||||
return isDate(maybeDate) && isValid(maybeDate);
|
||||
}, false),
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
function formatDateUsingFormatter(formatter: (date: Date) => string, date?: Date) {
|
||||
if (!date || !validation.isValid) {
|
||||
return '';
|
||||
}
|
||||
|
||||
return withDefaultOnError(() => formatter(date), '');
|
||||
}
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div>
|
||||
<div flex gap-2>
|
||||
<c-input-text
|
||||
v-model:value="inputDate"
|
||||
autofocus
|
||||
placeholder="Put your date string here..."
|
||||
clearable
|
||||
test-id="date-time-converter-input"
|
||||
:validation="validation"
|
||||
@update:value="onDateInputChanged"
|
||||
/>
|
||||
|
||||
<c-select
|
||||
v-model:value="formatIndex"
|
||||
style="flex: 0 0 170px"
|
||||
:options="formats.map(({ name }, i) => ({ label: name, value: i }))"
|
||||
data-test-id="date-time-converter-format-select"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<input-copyable
|
||||
v-for="{ name, fromDate } in formats"
|
||||
:key="name"
|
||||
:label="name"
|
||||
label-width="150px"
|
||||
label-position="left"
|
||||
label-align="right"
|
||||
:value="formatDateUsingFormatter(fromDate, normalizedDate)"
|
||||
placeholder="Invalid date..."
|
||||
:test-id="name"
|
||||
readonly
|
||||
mt-2
|
||||
/>
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,12 @@
|
||||
import { Calendar } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.date-converter.title'),
|
||||
path: '/date-converter',
|
||||
description: translate('tools.date-converter.description'),
|
||||
keywords: ['date', 'time', 'converter', 'iso', 'utc', 'timezone', 'year', 'month', 'day', 'minute', 'seconde'],
|
||||
component: () => import('./date-time-converter.vue'),
|
||||
icon: Calendar,
|
||||
});
|
||||
@@ -0,0 +1,102 @@
|
||||
<script setup lang="ts">
|
||||
import { useWindowSize } from '@vueuse/core';
|
||||
|
||||
const { width, height } = useWindowSize();
|
||||
|
||||
const sections = [
|
||||
{
|
||||
name: 'Screen',
|
||||
information: [
|
||||
{
|
||||
label: 'Screen size',
|
||||
value: computed(() => `${window.screen.availWidth} x ${window.screen.availHeight}`),
|
||||
},
|
||||
{
|
||||
label: 'Orientation',
|
||||
value: computed(() => window.screen.orientation.type),
|
||||
},
|
||||
{
|
||||
label: 'Orientation angle',
|
||||
value: computed(() => `${window.screen.orientation.angle}°`),
|
||||
},
|
||||
{
|
||||
label: 'Color depth',
|
||||
value: computed(() => `${window.screen.colorDepth} bits`),
|
||||
},
|
||||
{
|
||||
label: 'Pixel ratio',
|
||||
value: computed(() => `${window.devicePixelRatio} dppx`),
|
||||
},
|
||||
{
|
||||
label: 'Window size',
|
||||
value: computed(() => `${width.value} x ${height.value}`),
|
||||
},
|
||||
],
|
||||
},
|
||||
{
|
||||
name: 'Device',
|
||||
information: [
|
||||
{
|
||||
label: 'Browser vendor',
|
||||
value: computed(() => navigator.vendor),
|
||||
},
|
||||
{
|
||||
label: 'Languages',
|
||||
value: computed(() => navigator.languages.join(', ')),
|
||||
},
|
||||
{
|
||||
label: 'Platform',
|
||||
value: computed(() => navigator.platform),
|
||||
},
|
||||
{
|
||||
label: 'User agent',
|
||||
value: computed(() => navigator.userAgent),
|
||||
},
|
||||
],
|
||||
},
|
||||
];
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<c-card v-for="{ name, information } in sections" :key="name" :title="name">
|
||||
<n-grid cols="1 400:2" x-gap="12" y-gap="12">
|
||||
<n-gi v-for="{ label, value: { value } } in information" :key="label" class="information">
|
||||
<div class="label">
|
||||
{{ label }}
|
||||
</div>
|
||||
|
||||
<div class="value">
|
||||
<n-ellipsis v-if="value">
|
||||
{{ value }}
|
||||
</n-ellipsis>
|
||||
<div v-else class="undefined-value">
|
||||
unknown
|
||||
</div>
|
||||
</div>
|
||||
</n-gi>
|
||||
</n-grid>
|
||||
</c-card>
|
||||
</template>
|
||||
|
||||
<style lang="less" scoped>
|
||||
.information {
|
||||
padding: 14px 16px;
|
||||
border-radius: 4px;
|
||||
background-color: #aaaaaa11;
|
||||
|
||||
.label {
|
||||
font-size: 14px;
|
||||
opacity: 0.8;
|
||||
line-height: 1;
|
||||
margin-bottom: 5px;
|
||||
}
|
||||
.value {
|
||||
font-size: 20px;
|
||||
font-weight: 400;
|
||||
}
|
||||
|
||||
.undefined-value {
|
||||
opacity: 0.8;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
@@ -0,0 +1,24 @@
|
||||
import { DeviceDesktop } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
import { translate } from '@/plugins/i18n.plugin';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: translate('tools.device-information.title'),
|
||||
path: '/device-information',
|
||||
description: translate('tools.device-information.description'),
|
||||
keywords: [
|
||||
'device',
|
||||
'information',
|
||||
'screen',
|
||||
'pixel',
|
||||
'ratio',
|
||||
'status',
|
||||
'data',
|
||||
'computer',
|
||||
'size',
|
||||
'user',
|
||||
'agent',
|
||||
],
|
||||
component: () => import('./device-information.vue'),
|
||||
icon: DeviceDesktop,
|
||||
});
|
||||
Loaded 100 of 528 files, more files were not shown because too many files have changed in this diff.
Show more
Reference in new issue
Block a user