mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-25 23:24:09 +03:00
Merge branch 'feat/color-contrast' into chore/all-my-stuffs
This commit is contained in:
commit
7ee8ed3557
5 files changed
+87
No files matched your search
@@ -0,0 +1,63 @@
|
||||
<script setup lang="ts">
|
||||
import { contrastRatio, passesWCAG } from 'wcag-contrast-utils';
|
||||
import { useQueryParam } from '@/composable/queryParams';
|
||||
|
||||
const forecolor = useQueryParam({ name: 'fg', defaultValue: '#000' });
|
||||
const backcolor = useQueryParam({ name: 'bg', defaultValue: '#fff' });
|
||||
|
||||
const result = computed(() => {
|
||||
try {
|
||||
const constrastValue = contrastRatio(forecolor.value, backcolor.value);
|
||||
const wcagLevel = passesWCAG(constrastValue);
|
||||
|
||||
return {
|
||||
constrastValue,
|
||||
wcagLevel,
|
||||
error: '',
|
||||
};
|
||||
}
|
||||
catch (e: any) {
|
||||
return {
|
||||
constrastValue: -1,
|
||||
wcagLevel: '',
|
||||
error: e.toString(),
|
||||
};
|
||||
}
|
||||
});
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div max-w-600px>
|
||||
<n-form-item
|
||||
label="Forecolor:"
|
||||
label-placement="left"
|
||||
mb-1
|
||||
>
|
||||
<n-color-picker
|
||||
v-model:value="forecolor"
|
||||
:modes="['hex']"
|
||||
:show-alpha="false"
|
||||
/>
|
||||
</n-form-item>
|
||||
<n-form-item
|
||||
label="Backcolor:"
|
||||
label-placement="left"
|
||||
mb-1
|
||||
>
|
||||
<n-color-picker
|
||||
v-model:value="backcolor"
|
||||
:modes="['hex']"
|
||||
:show-alpha="false"
|
||||
/>
|
||||
</n-form-item>
|
||||
|
||||
<n-divider />
|
||||
|
||||
<c-alert v-if="result.error">
|
||||
{{ result.error }}
|
||||
</c-alert>
|
||||
|
||||
<input-copyable v-if="!result.error" readonly label="Constrast:" label-width="100px" label-position="left" :value="result.constrastValue" mb-2 />
|
||||
<input-copyable v-if="!result.error" readonly label="Level:" label-width="100px" label-position="left" :value="result.wcagLevel" />
|
||||
</div>
|
||||
</template>
|
||||
@@ -0,0 +1,13 @@
|
||||
import { ColorSwatch } from '@vicons/tabler';
|
||||
import { defineTool } from '../tool';
|
||||
|
||||
export const tool = defineTool({
|
||||
name: 'Color Contrast Checker',
|
||||
path: '/color-contrast-checker',
|
||||
description: 'Check the WCAG constrast level between two colors',
|
||||
keywords: ['color', 'contrast', 'checker', 'wcag'],
|
||||
component: () => import('./color-contrast-checker.vue'),
|
||||
icon: ColorSwatch,
|
||||
createdAt: new Date('2025-03-09'),
|
||||
category: 'Web',
|
||||
});
|
||||
Reference in new issue
Block a user