-
Notifications
You must be signed in to change notification settings - Fork 49
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
Themed Posts: Adjust identical background/foreground colors. #1735
base: master
Are you sure you want to change the base?
Themed Posts: Adjust identical background/foreground colors. #1735
Conversation
0a78336
to
4daae09
Compare
const hexToRGBAdjusted = color => {
const cssSign = val => `clamp(-1, ${val} * 100000, 1)`;
const isDarkThreshold = 0.4;
const direction = cssSign(`(${isDarkThreshold} - l)`);
const adjustmentAmount = 0.18;
const newColor = `oklch(from ${color} calc(l + ${adjustmentAmount} * ${direction}) c h)`;
const adjusted = `from ${newColor} r g b`;
return adjusted;
};
const backgroundColorRGB = hexToRGB(backgroundColor);
const titleColorRGB = hexToRGB(titleColor);
const linkColorRGB = hexToRGB(linkColor);
styleElement.textContent += `
[data-xkit-themed="${name}"] {
--background-color: ${backgroundColor};
--white: from var(--background-color) r g b;
--black: ${hexToRGBAdjusted('rgb(var(--white))')};
--deprecated-accent: ${linkColorRGB};
--color-primary-link: rgb(var(--deprecated-accent));
}
`; Also, mdn seems to imply that Edit: Huh. Well now. const el = dom('div', { style: 'color: rgb(from oklch(from #eb1ff4 l calc(c + 0.03) h) r g b)' });
console.log(el.style.color);
console.log(
el.style.color
.replace('color(srgb ', '')
.replace(')', '')
.split(' ')
.map(Number)
.map(value => value * 256)
.join(', ')
);
// color(srgb 0.949722 -0.15044 0.991859)
// 243.128832, -38.51264, 253.915904 |
Hey look, a wild undocumented browser bug: mdn/browser-compat-data#26041. Whee! |
it didn't work on dark colors. consistently producing anything that resembles tumblr's algorithm has so far been fruitless
b345a49
to
cf35b2f
Compare
Description
I am immeasurably pissed that this doesn't actually work. You should have heard me when I figured out that you could do it. I was, like, screaming. (I wasn't actually screaming. "You cannot be serious" was said more than a few times, though.)Edit: Ha, victory.On supporting browser versions, this makes the text/accent colors used by Themed Posts
10%a bit lighter or darker if they exactly match the background depending on whether they're light or dark,with the "is it light or dark; go the opposite way" logic implemented in pure CSS. Without sign().This doesn't work because Tumblr uses the legacyrgba(var(--someVariable), 0.5)
syntax instead ofrgba(var(--someVariable) / 0.5)
, and since you can't mix and match modern and legacy syntax the resultingrgba(from /* etc */ r g b, 0.5)
used value is invalid.Resolves #1636.
Testing steps