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

color-scheme adaptive fade-in/out-bloom #268

Merged
merged 2 commits into from
Aug 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions build/to-stylesheet.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ export const buildPropsStylesheet = ({filename,props}, {selector,prefix}) => {

let appendedMeta = ''

if (filename.includes('shadows')) {
if (filename.includes('shadows') || filename.includes('animations')) {
file.write(`@import 'props.media.css';\n\n`)
}

if (filename.includes('shadows')) {
let dark_propsMeta = ``
let dark_props = Object.entries(props)
.filter(([prop, val]) =>
Expand All @@ -18,7 +21,7 @@ export const buildPropsStylesheet = ({filename,props}, {selector,prefix}) => {
let p = prefix && prefix !== "''"
? `--${prefix}-` + extract
: `--${extract}`

dark_propsMeta += ` ${p}: ${val};${index !== dark_props.length-1 ? '\n' : ''}`
})
appendedMeta += `
Expand Down Expand Up @@ -49,6 +52,22 @@ ${dark_propsMeta}
file.write(` ${prop}: ${val};\n`)
})

if (filename.includes('animations')) {
let dark_props = Object.entries(props)
.filter(([prop, val]) =>
prop.includes('-@media:dark'))

dark_props.forEach(([prop, val], index) => {
let hasDarkKeyframe = prop.endsWith('-@media:dark') && val.trim().startsWith('@keyframe')
if (hasDarkKeyframe) {
appendedMeta += `
@media (--OSdark) {
${val.trim().replace(/\n/g, '\n ')};
}`
}
})
}

file.write('}\n')
file.end(appendedMeta)
}
16 changes: 16 additions & 0 deletions src/props.animations.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
@import 'props.media.css';

:where(html) {
--animation-fade-in: fade-in .5s var(--ease-3);
--animation-fade-in-bloom: fade-in-bloom 2s var(--ease-3);
Expand Down Expand Up @@ -110,4 +112,18 @@
}
@keyframes pulse {
50% { transform: scale(.9,.9) }
}
@media (--OSdark) {
@keyframes fade-in-bloom {
0% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(0.5) blur(10px) }
100% { opacity: 1; filter: brightness(1) blur(0) }
};
}
@media (--OSdark) {
@keyframes fade-out-bloom {
100% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(0.5) blur(10px) }
0% { opacity: 1; filter: brightness(1) blur(0) }
};
}
12 changes: 12 additions & 0 deletions src/props.animations.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ export default {
0% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(2) blur(10px) }
100% { opacity: 1; filter: brightness(1) blur(0) }
}`,
"--animation-fade-in-bloom-@media:dark": `
@keyframes fade-in-bloom {
0% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(0.5) blur(10px) }
100% { opacity: 1; filter: brightness(1) blur(0) }
}`,
"--animation-fade-out": "fade-out .5s var(--ease-3)",
"--animation-fade-out-@": `
Expand All @@ -22,6 +28,12 @@ export default {
100% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(2) blur(10px) }
0% { opacity: 1; filter: brightness(1) blur(0) }
}`,
"--animation-fade-out-bloom-@media:dark": `
@keyframes fade-out-bloom {
100% { opacity: 0; filter: brightness(1) blur(20px) }
10% { opacity: 1; filter: brightness(0.5) blur(10px) }
0% { opacity: 1; filter: brightness(1) blur(0) }
}`,
"--animation-scale-up": "scale-up .5s var(--ease-3)",
"--animation-scale-up-@": `
Expand Down
2 changes: 1 addition & 1 deletion test/basic.test.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const OpenProps = require('../dist/open-props.cjs')
const OPtokens = require('../open-props.tokens.json')

test('Should have an all included import', t => {
t.is(Object.keys(OpenProps).length, 1094)
t.is(Object.keys(OpenProps).length, 1098)
})

test('Import should have animations', async t => {
Expand Down