Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add implementation warning for browsers #145

Merged
merged 12 commits into from
Dec 19, 2023
27 changes: 27 additions & 0 deletions src/lib/components/colors/ImplementationWarning.svelte
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<script lang="ts">
import ExternalLink from '$lib/components/util/ExternalLink.svelte';
import Icon from '$lib/components/util/Icon.svelte';
import type { ColorFormatId } from '$lib/constants';
import { ColorSpace } from '$lib/stores';
import { getSpaceFromFormatId } from '$lib/utils';

export let format: ColorFormatId;

$: targetSpace = getSpaceFromFormatId(format);
$: spaceObject = ColorSpace.get(targetSpace);
// TODO: Can be replaced with spaceObject.isUnbounded in next version of

Check warning on line 12 in src/lib/components/colors/ImplementationWarning.svelte

View workflow job for this annotation

GitHub Actions / Lint

Unexpected 'todo' comment: 'TODO: Can be replaced with...'
// Color.js.
$: isUnbounded = Object.values(spaceObject.coords).every(
(coord) => !('range' in coord),
);
</script>

{#if isUnbounded}
<span data-color-info="warning"
><Icon name="warning" /> Browser rendering for colors outside of the display
gamut is incorrect
<ExternalLink href="https://github.com/w3c/csswg-drafts/issues/9449">
according to the CSS specification.</ExternalLink
>
</span>
{/if}
2 changes: 2 additions & 0 deletions src/lib/components/colors/index.svelte
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<script lang="ts">
import Formats from '$lib/components/colors/Formats.svelte';
import Header from '$lib/components/colors/Header.svelte';
import ImplementationWarning from '$lib/components/colors/ImplementationWarning.svelte';
import Sliders from '$lib/components/colors/Sliders.svelte';
import SupportWarning from '$lib/components/colors/SupportWarning.svelte';
import { bg, fg, format } from '$lib/stores';
Expand All @@ -9,6 +10,7 @@
<h2 class="sr-only">Check the contrast ratio between two colors</h2>

<SupportWarning format={$format} />
<ImplementationWarning format={$format} />
jgerigmeyer marked this conversation as resolved.
Show resolved Hide resolved

<form data-form="contrast-checker" data-layout="color-form">
<Header type="bg" color={bg} format={$format} />
Expand Down
6 changes: 3 additions & 3 deletions src/lib/stores.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ ColorSpace.register(REC_2020);
export { ColorSpace };

export const INITIAL_VALUES = {
format: 'oklch' as ColorFormatId,
bg_coord: [0.3259, 0.1333, 265.49] as [number, number, number],
fg_coord: [0.8241, 0.1061, 0.8587] as [number, number, number],
format: 'p3' as ColorFormatId,
bg_coord: [0.0967, 0.167, 0.4494] as [number, number, number],
fg_coord: [0.951, 0.675, 0.7569] as [number, number, number],
jgerigmeyer marked this conversation as resolved.
Show resolved Hide resolved
alpha: 1,
};

Expand Down
6 changes: 3 additions & 3 deletions test/js/lib/components/SpaceSelect.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { fireEvent, render } from '@testing-library/svelte';
import { get } from 'svelte/store';

import Space from '$lib/components/SpaceSelect.svelte';
import { bg, fg, reset } from '$lib/stores';
import { bg, fg, INITIAL_VALUES, reset } from '$lib/stores';

describe('Space', () => {
afterEach(() => {
Expand All @@ -12,8 +12,8 @@ describe('Space', () => {
it('renders editable space select', async () => {
const { getByLabelText } = render(Space);

expect(get(bg).space.id).toBe('oklch');
expect(get(fg).space.id).toBe('oklch');
expect(get(bg).space.id).toBe(INITIAL_VALUES.format);
expect(get(fg).space.id).toBe(INITIAL_VALUES.format);

const select = getByLabelText('Color Format');
await fireEvent.change(select, { target: { value: 'hsl' } });
Expand Down