mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-27 16:09:01 +03:00
feat(Color Contrast Checker): enhanced UI
Fix https://github.com/sharevb/it-tools/issues/48#issuecomment-2786796909
This commit is contained in:
1 parent
a768896d43
commit
ad213e082d
4 files changed
+96
-18
No files matched your search
Vendored
+4
@@ -270,6 +270,7 @@ declare module '@vue/runtime-core' {
|
|||||||
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
NavbarButtons: typeof import('./src/components/NavbarButtons.vue')['default']
|
||||||
NCode: typeof import('naive-ui')['NCode']
|
NCode: typeof import('naive-ui')['NCode']
|
||||||
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
NCollapseTransition: typeof import('naive-ui')['NCollapseTransition']
|
||||||
|
NColorPicker: typeof import('naive-ui')['NColorPicker']
|
||||||
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
NConfigProvider: typeof import('naive-ui')['NConfigProvider']
|
||||||
NDivider: typeof import('naive-ui')['NDivider']
|
NDivider: typeof import('naive-ui')['NDivider']
|
||||||
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
NEllipsis: typeof import('naive-ui')['NEllipsis']
|
||||||
@@ -285,7 +286,10 @@ declare module '@vue/runtime-core' {
|
|||||||
NLayout: typeof import('naive-ui')['NLayout']
|
NLayout: typeof import('naive-ui')['NLayout']
|
||||||
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
NLayoutSider: typeof import('naive-ui')['NLayoutSider']
|
||||||
NMenu: typeof import('naive-ui')['NMenu']
|
NMenu: typeof import('naive-ui')['NMenu']
|
||||||
|
NP: typeof import('naive-ui')['NP']
|
||||||
|
NRate: typeof import('naive-ui')['NRate']
|
||||||
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
NScrollbar: typeof import('naive-ui')['NScrollbar']
|
||||||
|
NTag: typeof import('naive-ui')['NTag']
|
||||||
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
NumberInput: typeof import('./src/tools/pomodoro-timer/app/components/NumberInput.vue')['default']
|
||||||
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
NumeronymGenerator: typeof import('./src/tools/numeronym-generator/numeronym-generator.vue')['default']
|
||||||
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
OcrImage: typeof import('./src/tools/ocr-image/ocr-image.vue')['default']
|
||||||
|
|||||||
+1
-1
@@ -78,6 +78,7 @@
|
|||||||
"@xmldom/xmldom": "^0.8.10",
|
"@xmldom/xmldom": "^0.8.10",
|
||||||
"@younestouati/playing-cards-standard-deck": "^6.0.1",
|
"@younestouati/playing-cards-standard-deck": "^6.0.1",
|
||||||
"@zxing/library": "^0.21.3",
|
"@zxing/library": "^0.21.3",
|
||||||
|
"a11y-color-contrast": "^0.2.0",
|
||||||
"aircodes": "^1.3.16",
|
"aircodes": "^1.3.16",
|
||||||
"ansible-vault": "^1.3.0",
|
"ansible-vault": "^1.3.0",
|
||||||
"apache-md5": "^1.1.8",
|
"apache-md5": "^1.1.8",
|
||||||
@@ -269,7 +270,6 @@
|
|||||||
"vuedraggable": "^4.1.0",
|
"vuedraggable": "^4.1.0",
|
||||||
"vuex": "^4.1.0",
|
"vuex": "^4.1.0",
|
||||||
"w-websocket-client": "^1.0.29",
|
"w-websocket-client": "^1.0.29",
|
||||||
"wcag-contrast-utils": "^1.0.1",
|
|
||||||
"webcrack": "^2.15.0",
|
"webcrack": "^2.15.0",
|
||||||
"webp-converter-browser": "^1.0.4",
|
"webp-converter-browser": "^1.0.4",
|
||||||
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
|
"xlsx": "https://cdn.sheetjs.com/xlsx-0.20.2/xlsx-0.20.2.tgz",
|
||||||
|
|||||||
Generated
+8
-8
@@ -131,6 +131,9 @@ dependencies:
|
|||||||
'@zxing/library':
|
'@zxing/library':
|
||||||
specifier: ^0.21.3
|
specifier: ^0.21.3
|
||||||
version: 0.21.3
|
version: 0.21.3
|
||||||
|
a11y-color-contrast:
|
||||||
|
specifier: ^0.2.0
|
||||||
|
version: 0.2.0
|
||||||
aircodes:
|
aircodes:
|
||||||
specifier: ^1.3.16
|
specifier: ^1.3.16
|
||||||
version: 1.3.16
|
version: 1.3.16
|
||||||
@@ -704,9 +707,6 @@ dependencies:
|
|||||||
w-websocket-client:
|
w-websocket-client:
|
||||||
specifier: ^1.0.29
|
specifier: ^1.0.29
|
||||||
version: 1.0.29
|
version: 1.0.29
|
||||||
wcag-contrast-utils:
|
|
||||||
specifier: ^1.0.1
|
|
||||||
version: 1.0.1
|
|
||||||
webcrack:
|
webcrack:
|
||||||
specifier: ^2.15.0
|
specifier: ^2.15.0
|
||||||
version: 2.15.0
|
version: 2.15.0
|
||||||
@@ -7469,6 +7469,11 @@ packages:
|
|||||||
resolution: {integrity: sha512-ZJ6wx9xaKJ3yFUhq5/sk82PJMuUyLk277I8mQeyDgCTjGdjWJIvPfaU5LIXaMuaN2UO1X3kZH4+lgphublZUHw==}
|
resolution: {integrity: sha512-ZJ6wx9xaKJ3yFUhq5/sk82PJMuUyLk277I8mQeyDgCTjGdjWJIvPfaU5LIXaMuaN2UO1X3kZH4+lgphublZUHw==}
|
||||||
dev: false
|
dev: false
|
||||||
|
|
||||||
|
/a11y-color-contrast@0.2.0:
|
||||||
|
resolution: {integrity: sha512-INSv5cMPGvJ/jMLvIxRTT9CDQqxODOhoedaQ2+yWIwbxhKyOns9m/7aJjXVQjxp1rntkbiL4lBUtikuH5YK6Cg==}
|
||||||
|
engines: {node: '>=16.6.0'}
|
||||||
|
dev: false
|
||||||
|
|
||||||
/abab@2.0.6:
|
/abab@2.0.6:
|
||||||
resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==}
|
resolution: {integrity: sha512-j2afSsaIENvHZN2B8GOpF566vZ5WVk5opAiMTvWgaQT8DkbOqsTfvNAvHoRGU2zzP8cPoqys+xHTRDWW8L+/BA==}
|
||||||
deprecated: Use your platform's native atob() and btoa() methods instead
|
deprecated: Use your platform's native atob() and btoa() methods instead
|
||||||
@@ -18180,11 +18185,6 @@ packages:
|
|||||||
resolution: {integrity: sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==}
|
resolution: {integrity: sha512-zksaLKM2fVlnB5jQQDqKXXwYHLQUVH9es+5TOOHwGOVJOCeRBCiPjwSg+3tN2AdTCzjgli4jijCH290kXb/zWQ==}
|
||||||
dev: false
|
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:
|
/wcwidth@1.0.1:
|
||||||
resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}
|
resolution: {integrity: sha512-XHPEwS0q6TaxcvG85+8EYkbiCux2XtWG2mkc47Ng2A77BQu9+DqIOJldST4HgPkuea7dvKSj5VgX3P1d4rW8Tg==}
|
||||||
dependencies:
|
dependencies:
|
||||||
|
|||||||
@@ -1,25 +1,49 @@
|
|||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { contrastRatio, passesWCAG } from 'wcag-contrast-utils';
|
import { apcaContrastValue, hex, wcag, wcagContrastValue } from 'a11y-color-contrast';
|
||||||
import { useQueryParam } from '@/composable/queryParams';
|
import { useQueryParam } from '@/composable/queryParams';
|
||||||
|
|
||||||
const forecolor = useQueryParam({ name: 'fg', defaultValue: '#000' });
|
const forecolor = useQueryParam({ name: 'fg', defaultValue: '#000' });
|
||||||
const backcolor = useQueryParam({ name: 'bg', defaultValue: '#fff' });
|
const backcolor = useQueryParam({ name: 'bg', defaultValue: '#fff' });
|
||||||
|
|
||||||
|
const levels = [
|
||||||
|
{ score: 3, text: 'Very poor', bg: '#fbd0da', fg: '#5f071c', stars: 1 },
|
||||||
|
{ score: 4.5, text: 'Poor', bg: '#fbd0da', fg: '#5f071c', stars: 2 },
|
||||||
|
{ score: 7, text: 'Good', bg: '#fbf5d0', fg: '#5f5207', stars: 3 },
|
||||||
|
{ score: 12, text: 'Very good', bg: '#d2fbd0', fg: '#0d5f07', stars: 4 },
|
||||||
|
{ score: 9999, text: 'Super', bg: '#d2fbd0', fg: '#0d5f07', stars: 5 },
|
||||||
|
];
|
||||||
|
const smallLevels = [
|
||||||
|
{ score: 4.5, bg: '#fbd0da', fg: '#5f071c', stars: 1 },
|
||||||
|
{ score: 7, bg: '#fbf5d0', fg: '#5f5207', stars: 2 },
|
||||||
|
{ score: 9999, bg: '#d2fbd0', fg: '#0d5f07', stars: 3 },
|
||||||
|
];
|
||||||
|
const largeLevels = [
|
||||||
|
{ score: 3, bg: '#fbd0da', fg: '#5f071c', stars: 1 },
|
||||||
|
{ score: 4.5, bg: '#fbf5d0', fg: '#5f5207', stars: 2 },
|
||||||
|
{ score: 9999, bg: '#d2fbd0', fg: '#0d5f07', stars: 3 },
|
||||||
|
];
|
||||||
|
|
||||||
const result = computed(() => {
|
const result = computed(() => {
|
||||||
try {
|
try {
|
||||||
const constrastValue = contrastRatio(forecolor.value, backcolor.value);
|
const fgHex = hex(forecolor.value);
|
||||||
const wcagLevel = passesWCAG(constrastValue);
|
const bgHex = hex(backcolor.value);
|
||||||
|
|
||||||
|
const wcagLevel = wcagContrastValue(bgHex, fgHex);
|
||||||
return {
|
return {
|
||||||
constrastValue,
|
wcag21ConstrastValue: wcagLevel,
|
||||||
wcagLevel,
|
aaNormal: wcag(bgHex, fgHex, { level: 'AA', size: 'normal' }),
|
||||||
|
aaaNormal: wcag(bgHex, fgHex, { level: 'AAA', size: 'normal' }),
|
||||||
|
aaLarge: wcag(bgHex, fgHex, { level: 'AA', size: 'large' }),
|
||||||
|
aaaLarge: wcag(bgHex, fgHex, { level: 'AAA', size: 'large' }),
|
||||||
|
level: levels.find(l => wcagLevel < l.score),
|
||||||
|
largeLevel: largeLevels.find(l => wcagLevel < l.score),
|
||||||
|
smallLevel: smallLevels.find(l => wcagLevel < l.score),
|
||||||
|
apcaContrastValue: apcaContrastValue(bgHex, fgHex),
|
||||||
error: '',
|
error: '',
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
catch (e: any) {
|
catch (e: any) {
|
||||||
return {
|
return {
|
||||||
constrastValue: -1,
|
|
||||||
wcagLevel: '',
|
|
||||||
error: e.toString(),
|
error: e.toString(),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@@ -57,7 +81,57 @@ const result = computed(() => {
|
|||||||
{{ result.error }}
|
{{ result.error }}
|
||||||
</c-alert>
|
</c-alert>
|
||||||
|
|
||||||
<input-copyable v-if="!result.error" readonly label="Constrast:" label-width="100px" label-position="left" :value="result.constrastValue" mb-2 />
|
<c-card v-if="!result.error" title="WCAG 2.1">
|
||||||
<input-copyable v-if="!result.error" readonly label="Level:" label-width="100px" label-position="left" :value="result.wcagLevel" />
|
<input-copyable readonly label="WCAG Constrast:" label-width="130px" label-position="left" :value="result.wcag21ConstrastValue" mb-3 />
|
||||||
|
|
||||||
|
<n-form-item v-if="result.level" label="Contrast quality:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :max="5" :color="{ color: result.level.bg, textColor: result.level.fg, borderColor: result.level.fg }" mr-2>
|
||||||
|
<span>{{ result.wcag21ConstrastValue.toFixed(2) }} - {{ result.level.text }}</span>
|
||||||
|
</n-tag>
|
||||||
|
<n-tag :max="5" :color="{ color: result.level.bg, textColor: result.level.fg, borderColor: result.level.fg }">
|
||||||
|
<n-rate :count="5" readonly :default-value="result.level.stars" :color="result.level.fg" />
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item v-if="result.smallLevel" label="Small texts:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :color="{ color: result.smallLevel.bg, textColor: result.smallLevel.fg, borderColor: result.smallLevel.fg }">
|
||||||
|
<n-rate :count="3" readonly :default-value="result.smallLevel.stars" :color="result.smallLevel.fg" />
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item v-if="result.largeLevel" label="Large texts:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :color="{ color: result.largeLevel.bg, textColor: result.largeLevel.fg, borderColor: result.largeLevel.fg }">
|
||||||
|
<n-rate :count="3" readonly :default-value="result.largeLevel.stars" :color="result.largeLevel.fg" />
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
|
||||||
|
<c-card title="Normal text">
|
||||||
|
<n-form-item label="WCAG 2.1 AA:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :bordered="false" :type="result.aaNormal ? 'success' : 'error'">
|
||||||
|
{{ result.aaNormal ? 'Pass' : 'Fail' }}
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="WCAG 2.1 AAA:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :bordered="false" :type="result.aaaNormal ? 'success' : 'error'">
|
||||||
|
{{ result.aaaNormal ? 'Pass' : 'Fail' }}
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
</c-card>
|
||||||
|
<c-card title="Large text">
|
||||||
|
<n-p><i>Text that is 14pt (18.67px) and bold or any text bigger than 18pt (24px) is defined as large scale text.</i></n-p>
|
||||||
|
<n-form-item label="WCAG 2.1 AA:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :bordered="false" :type="result.aaLarge ? 'success' : 'error'">
|
||||||
|
{{ result.aaLarge ? 'Pass' : 'Fail' }}
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
<n-form-item label="WCAG 2.1 AAA:" label-width="130px" label-placement="left">
|
||||||
|
<n-tag :bordered="false" :type="result.aaaLarge ? 'success' : 'error'">
|
||||||
|
{{ result.aaaLarge ? 'Pass' : 'Fail' }}
|
||||||
|
</n-tag>
|
||||||
|
</n-form-item>
|
||||||
|
</c-card>
|
||||||
|
</c-card>
|
||||||
|
|
||||||
|
<c-card v-if="!result.error" title="APCA">
|
||||||
|
<input-copyable readonly label="APCA Constrast:" label-width="130px" label-position="left" :value="result.apcaContrastValue" mb-2 />
|
||||||
|
</c-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
Reference in new issue
Block a user