From 105fee637056f3a7051356c87a8db170d6ea4a76 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Girault?= Date: Mon, 2 May 2022 00:28:48 +0200 Subject: [PATCH] WIP --- .../combinations/CombinationGrid.svelte | 161 ++++++++++++++++++ src/lib/stores/combinations.ts | 27 ++- src/routes/index.svelte | 3 +- 3 files changed, 189 insertions(+), 2 deletions(-) create mode 100644 src/lib/components/combinations/CombinationGrid.svelte diff --git a/src/lib/components/combinations/CombinationGrid.svelte b/src/lib/components/combinations/CombinationGrid.svelte new file mode 100644 index 0000000..4381105 --- /dev/null +++ b/src/lib/components/combinations/CombinationGrid.svelte @@ -0,0 +1,161 @@ + + +
+
+ {#if colorCount > 1} +
+ + +
+ {/if} +
+ +
+ + {#if $cross.length} + + + + + + + {/each} + + + + + {#each $cross as { id, name, rgb, bgs }, j (id)} + + + {#each bgs as { grade }, i ($cross[i].id)} + + {/each} + + {/each} + +
Test
+ {#each $cross as { id, name, rgb } (id)} + + + Tt + +
+ + + {#if i !== j} + { + $selectedCombinations[ + $cross[i].id + ][id] = e.target.checked; + }} + /> + + {/if} +
+ {:else if colorCount > 1} +

+ There is no color combination matching the selected + filters. +
+ Try adding more colors to your palette or changing filters. +

+ {:else} +

+ Add colors to your palette to try color combinations. +

+ {/if} +
+
+ + diff --git a/src/lib/stores/combinations.ts b/src/lib/stores/combinations.ts index 35d0ad0..e677549 100644 --- a/src/lib/stores/combinations.ts +++ b/src/lib/stores/combinations.ts @@ -1,5 +1,5 @@ import type {Rgb} from 'culori/fn'; -import type {Readable} from 'svelte/store'; +import {readable, type Readable} from 'svelte/store'; import {derived, get, writable} from 'svelte/store'; import type {ContrastType} from '$lib/color/contrast'; import { @@ -124,6 +124,31 @@ const colorPairs = derived(filteredColors, ($colors) => { ); }); +export const cross = derived( + [filteredColors, contrastType], + ([$colors, $type]) => { + const levelFn = + $type === 'wcag2' ? wcag2Contrast : wcag3Contrast; + const gradeFn = + $type === 'wcag2' ? wcag2Grade : wcag3Grade; + + return $colors.map((fg) => ({ + id: fg.id, + name: fg.name, + rgb: fg.rgbColor, + bgs: $colors.map((bg) => { + const level = levelFn(bg.rgbColor, fg.rgbColor); + return { + level, + grade: gradeFn(level) + }; + }) + })); + } +); + +export const selectedCombinations = writable({}); + export const combinations = derived( [colorPairs, contrastType, blindnessTypes], ([$pairs, $type, $blindnessTypes]) => { diff --git a/src/routes/index.svelte b/src/routes/index.svelte index a6ff9c6..6b0c868 100644 --- a/src/routes/index.svelte +++ b/src/routes/index.svelte @@ -2,6 +2,7 @@ import Layout from '$lib/components/Layout.svelte'; import Modal from '$lib/components/Modal.svelte'; import Palette from '$lib/components/Palette.svelte'; + import CombinationGrid from '$lib/components/combinations/CombinationGrid.svelte'; import Combinations from '$lib/components/combinations/Combinations.svelte'; import Export from '$lib/components/export/Export.svelte'; import {pack} from '$lib/packing'; @@ -63,7 +64,7 @@ - +