-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into color-issues
* main: update upload/download actions together remove unused grid Bump actions/upload-artifact from 3 to 4 Add flex container to section headers and errors use logical properties capitalize P3 capitalization from source since sRGB should have lowercase "s" Update styles for grouped formats remove unused move headings up a level as they are independent of the result ratio Add explicit name, gamut name, and gamut testing format for Format Groups test fix target spaces review Tests for FormatGroup Lint Fix test Group formats
- Loading branch information
Showing
13 changed files
with
169 additions
and
61 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
<script lang="ts"> | ||
import { inGamut } from 'colorjs.io/fn'; | ||
import type { PlainColorObject } from 'colorjs.io/types/src/color'; | ||
import Output from '$lib/components/colors/Output.svelte'; | ||
import type { FormatGroup } from '$lib/constants'; | ||
import { ColorSpace } from '$lib/stores'; | ||
import { getSpaceFromFormatId } from '$lib/utils'; | ||
import ExternalLink from '../util/ExternalLink.svelte'; | ||
export let type: 'bg' | 'fg'; | ||
export let color: PlainColorObject; | ||
export let formatGroup: FormatGroup; | ||
function inGamutForSpace(color: PlainColorObject) { | ||
if (!formatGroup.gamutFormat) return true; | ||
const gamutSpace = ColorSpace.get( | ||
getSpaceFromFormatId(formatGroup.gamutFormat), | ||
); | ||
return inGamut(color, gamutSpace); | ||
} | ||
$: isInGamut = inGamutForSpace(color); | ||
</script> | ||
|
||
<div data-content="format-group"> | ||
<div class="format-group-heading"> | ||
<h2 class="label section-heading">{formatGroup.name}</h2> | ||
{#if !isInGamut} | ||
<span data-color-info="warning" | ||
>Selected color is <ExternalLink | ||
href="https://www.w3.org/TR/css-color-4/#out-of-gamut" | ||
>outside the {formatGroup.gamutName} gamut.</ExternalLink | ||
></span | ||
> | ||
{/if} | ||
</div> | ||
{#each formatGroup.formats as format (format)} | ||
<Output {type} {color} {format} /> | ||
{/each} | ||
</div> | ||
|
||
<style lang="scss"> | ||
[data-content~='format-group'] { | ||
--heading-transform: none; | ||
margin-block-end: var(--double-gutter); | ||
} | ||
.format-group-heading { | ||
align-items: baseline; | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: var(--shim); | ||
margin-block-end: var(--gutter); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,47 @@ | ||
<script lang="ts"> | ||
import type { PlainColorObject } from 'colorjs.io/types/src/color'; | ||
import Output from '$lib/components/colors/Output.svelte'; | ||
import type { ColorFormatId } from '$lib/constants'; | ||
import { FORMATS } from '$lib/constants'; | ||
import FormatGroup from '$lib/components/colors/FormatGroup.svelte'; | ||
import type { | ||
ColorFormatId, | ||
FormatGroup as FormatGroupType, | ||
} from '$lib/constants'; | ||
import { FORMAT_GROUPS } from '$lib/constants'; | ||
export let type: 'bg' | 'fg'; | ||
export let color: PlainColorObject; | ||
export let format: ColorFormatId; | ||
function otherFormatGroups( | ||
selectedFormat: ColorFormatId, | ||
): typeof FORMAT_GROUPS { | ||
const otherFormats: FormatGroupType[] = []; | ||
FORMAT_GROUPS.forEach((group) => { | ||
const groupFormats = group.formats.filter((s) => s !== selectedFormat); | ||
if (groupFormats.length) { | ||
otherFormats.push({ ...group, formats: groupFormats }); | ||
} | ||
}); | ||
return otherFormats; | ||
} | ||
$: displayType = type === 'bg' ? 'Background' : 'Foreground'; | ||
$: otherFormats = FORMATS.filter((s) => s !== format); | ||
$: otherFormats = otherFormatGroups(format); | ||
</script> | ||
|
||
<div data-content="formats" data-column="tool"> | ||
<h4 class="small-only label">{displayType} Color</h4> | ||
{#each otherFormats as format (format)} | ||
<Output {type} {color} {format} /> | ||
<h2 class="small-only label">{displayType} Color</h2> | ||
{#each otherFormats as formatGroup} | ||
<FormatGroup {type} {color} {formatGroup} /> | ||
{/each} | ||
</div> | ||
|
||
<style lang="scss"> | ||
[data-content~='formats'] { | ||
margin-bottom: var(--double-gutter); | ||
margin-block-end: var(--double-gutter); | ||
} | ||
.label { | ||
--label-margin-bottom: var(--gutter); | ||
.small-only { | ||
--label-margin-block-end: var(--gutter); | ||
} | ||
</style> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { render } from '@testing-library/svelte'; | ||
|
||
import FormatGroup from '$lib/components/colors/FormatGroup.svelte'; | ||
import { FORMAT_GROUPS } from '$src/lib/constants'; | ||
import { HSL_WHITE, OUT_OF_BOUNDED_GAMUTS } from '$test/fixtures'; | ||
|
||
describe('FormatGroup', () => { | ||
it('renders selected group', () => { | ||
const FORMAT_GROUP = FORMAT_GROUPS[0]!; | ||
const { getByTestId, getByText } = render(FormatGroup, { | ||
type: 'bg', | ||
color: HSL_WHITE, | ||
formatGroup: FORMAT_GROUP, | ||
}); | ||
|
||
expect(getByText(FORMAT_GROUP.name)).toBeVisible(); | ||
FORMAT_GROUP.formats.forEach((format) => { | ||
expect(getByTestId(`format-${format}`)).toBeVisible(); | ||
}); | ||
}); | ||
|
||
it('renders warning if out of gamut', () => { | ||
const FORMAT_GROUP = FORMAT_GROUPS[0]!; | ||
const { getByTestId, getByText } = render(FormatGroup, { | ||
type: 'bg', | ||
color: OUT_OF_BOUNDED_GAMUTS, | ||
formatGroup: FORMAT_GROUP, | ||
}); | ||
|
||
expect(getByText(FORMAT_GROUP.name)).toBeVisible(); | ||
FORMAT_GROUP.formats.forEach((format) => { | ||
expect(getByTestId(`format-${format}`)).toBeVisible(); | ||
}); | ||
expect(getByText('outside the sRGB gamut.')).toBeVisible(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters