feat(new tool): Color Constract Checker

Fix #48
This commit is contained in:
ShareVB committed 2025-04-06 22:23:25 +02:00
1 parent d9ef06dca5
commit 1858324d60
5 files changed
+93 -6

No files matched your search

+2
View File
@@ -66,6 +66,7 @@ declare module '@vue/runtime-core' {
CodeHighlighter: typeof import('./src/tools/code-highlighter/code-highlighter.vue')['default']
CoinFlipper: typeof import('./src/tools/coin-flipper/coin-flipper.vue')['default']
CollapsibleToolMenu: typeof import('./src/components/CollapsibleToolMenu.vue')['default']
ColorContrastChecker: typeof import('./src/tools/color-contrast-checker/color-contrast-checker.vue')['default']
ColorConverter: typeof import('./src/tools/color-converter/color-converter.vue')['default']
ColoredCard: typeof import('./src/components/ColoredCard.vue')['default']
ColorWheel: typeof import('./src/tools/color-wheel/color-wheel.vue')['default']
@@ -261,6 +262,7 @@ declare module '@vue/runtime-core' {
NCheckbox: typeof import('naive-ui')['NCheckbox']
NCode: typeof import('naive-ui')['NCode']
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
NColorPicker: typeof import('naive-ui')['NColorPicker']
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
NDatePicker: typeof import('naive-ui')['NDatePicker']
NDivider: typeof import('naive-ui')['NDivider']
+1
View File
@@ -261,6 +261,7 @@
"vue3-fortune-wheel": "^2.0.5",
"vuedraggable": "^4.1.0",
"w-websocket-client": "^1.0.29",
"wcag-contrast-utils": "^1.0.1",
"webcrack": "^2.15.0",
"webp-converter-browser": "^1.0.4",
"xml-formatter": "^3.6.4",
+14 -6
View File
@@ -677,6 +677,9 @@ dependencies:
w-websocket-client:
specifier: ^1.0.29
version: 1.0.29
wcag-contrast-utils:
specifier: ^1.0.1
version: 1.0.1
webcrack:
specifier: ^2.15.0
version: 2.15.0
@@ -2639,7 +2642,7 @@ packages:
'@babel/helper-split-export-declaration': 7.22.6
'@babel/parser': 7.22.10
'@babel/types': 7.22.10
debug: 4.3.4
debug: 4.4.0
globals: 11.12.0
transitivePeerDependencies:
- supports-color
@@ -6465,7 +6468,7 @@ packages:
dependencies:
'@typescript-eslint/typescript-estree': 6.4.1(typescript@5.2.2)
'@typescript-eslint/utils': 6.4.1(eslint@8.47.0)(typescript@5.2.2)
debug: 4.3.4
debug: 4.4.0
eslint: 8.47.0
ts-api-utils: 1.0.1(typescript@5.2.2)
typescript: 5.2.2
@@ -6520,7 +6523,7 @@ packages:
dependencies:
'@typescript-eslint/types': 6.4.1
'@typescript-eslint/visitor-keys': 6.4.1
debug: 4.3.4
debug: 4.4.0
globby: 11.1.0
is-glob: 4.0.3
semver: 7.7.1
@@ -6584,7 +6587,7 @@ packages:
'@typescript-eslint/types': 6.4.1
'@typescript-eslint/typescript-estree': 6.4.1(typescript@5.2.2)
eslint: 8.47.0
semver: 7.5.4
semver: 7.7.1
transitivePeerDependencies:
- supports-color
- typescript
@@ -8014,7 +8017,7 @@ packages:
/builtins@5.0.1:
resolution: {integrity: sha512-qwVpFEHNfhYJIzNRBvd2C1kyo6jz3ZSMPyyuR47OPdiKWlbYnZNyDWuyR175qDnAJLiCo5fBBqPb3RiXgWlkOQ==}
dependencies:
semver: 7.5.4
semver: 7.7.1
dev: true
/bwip-js@4.5.1:
@@ -17838,7 +17841,7 @@ packages:
espree: 9.6.1
esquery: 1.5.0
lodash: 4.17.21
semver: 7.5.4
semver: 7.7.1
transitivePeerDependencies:
- supports-color
dev: true
@@ -17983,6 +17986,11 @@ packages:
resolution: {integrity: sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==}
dev: false
/wcag-contrast-utils@1.0.1:
resolution: {integrity: sha512-XDO0ZoIzJmZa/+dDA3hsZTRb/enObfSpo5khBHiW++s+u7ydrFZv4l/0KkomjAlsHZHSI4QCr0n6DJmqwIJOHw==}
engines: {node: '>=10'}
dev: false
/wcwidth@1.0.1:
resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}
dependencies:
@@ -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>
+13
View File
@@ -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',
});