-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
Adjust ratio for opacity #222
Open
jamesnw
wants to merge
5
commits into
main
Choose a base branch
from
alpha
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 |
---|---|---|
@@ -1,15 +1,30 @@ | ||
<script lang="ts"> | ||
import { contrast } from 'colorjs.io/fn'; | ||
import { contrast, mix } from 'colorjs.io/fn'; | ||
|
||
import ColorIssues from '$lib/components/ratio/ColorIssues.svelte'; | ||
import Result from '$lib/components/ratio/Result.svelte'; | ||
import ExternalLink from '$lib/components/util/ExternalLink.svelte'; | ||
import Icon from '$lib/components/util/Icon.svelte'; | ||
import { RATIOS } from '$lib/constants'; | ||
import { bg, fg } from '$lib/stores'; | ||
|
||
let ratio = $derived(contrast($bg, $fg, 'WCAG21')); | ||
let fgPremultiplied = $derived.by(() => { | ||
if ($fg.alpha === 1 || $bg.alpha !== 1) return $fg; | ||
return mix($bg, $fg, $fg.alpha, { | ||
space: 'srgb', | ||
premultiplied: false, | ||
}); | ||
}); | ||
let ratio = $derived(contrast($bg, fgPremultiplied, 'WCAG21')); | ||
let displayRatio = $derived(Math.round((ratio + Number.EPSILON) * 100) / 100); | ||
let pass = $derived(ratio >= RATIOS.AA.Normal); | ||
let alphaWarning = $derived.by(() => { | ||
if ($bg.alpha !== 1) | ||
return 'Alpha is not considered when the background is not opaque.'; | ||
if ($fg.alpha !== 1) | ||
return 'This ratio is our best estimate with transparency.'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. "with transparency" seems a bit vague to me if users haven't read the full description. Maybe "given the specified foreground alpha value" or something? |
||
return null; | ||
}); | ||
</script> | ||
|
||
<aside data-layout="results"> | ||
|
@@ -20,6 +35,9 @@ | |
<span class="sr-only">The contrast ratio is</span> | ||
<span class="result-ratio-number">{displayRatio}:1</span> | ||
</h3> | ||
{#if alphaWarning} | ||
<p><Icon name="warning" />{alphaWarning}</p> | ||
{/if} | ||
|
||
<p class="result-intro"> | ||
In WCAG 2, contrast is a measure of the difference in perceived brightness | ||
|
@@ -73,7 +91,9 @@ | |
@use 'config'; | ||
|
||
[data-layout='results'] { | ||
background-color: var(--bgcolor); | ||
background: linear-gradient(90deg, var(--bgcolor), var(--bgcolor)), | ||
url('data:image/svg+xml;utf8,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 60 60"><rect fill="%23e8e8e8" width="30" height="30"/><rect x="30" y="30" width="30" height="30" fill="%23e8e8e8"/></svg>'); | ||
background-size: 30px 30px; | ||
color: var(--fgcolor); | ||
display: grid; | ||
gap: var(--result-layout-gap, var(--shim)); | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we link these two notes directly to the fuller description (expanding if necessary)?
If not that, we could consider adding the fuller explanation in a tooltip/dialog here instead of in the expandable "issues" section.