chore: remove legacy assets package and CSS enforcement script
This commit is contained in:
1 parent
c9fc3abcad
commit
6be3f90afa
11 files changed
+64
-5387
No files matched your search
@@ -39,9 +39,10 @@ const paletteByName = Object.fromEntries(PRIMARY_COLOR_PALETTE.map((color) => [c
|
||||
string,
|
||||
PaletteColor
|
||||
>
|
||||
const primaryVars = ['--color-primary', '--color-accent', '--color-ring']
|
||||
const foregroundVars = ['--color-primary-fg', '--color-accent-fg']
|
||||
const primaryVars = ['--color-primary', '--color-accent', '--color-ring', '--sc-primary', '--sc-accent', '--sc-ring']
|
||||
const foregroundVars = ['--color-primary-fg', '--color-accent-fg', '--sc-primary-fg', '--sc-accent-fg']
|
||||
const activeUserAttribute = 'data-primary-color-user'
|
||||
const styleElementId = 'sc-primary-color'
|
||||
const activeProjects = new Set<string>()
|
||||
|
||||
function normalizeUserKey(userKey: string): string {
|
||||
@@ -67,19 +68,45 @@ function readStoredColor(projectKey: string): string {
|
||||
}
|
||||
}
|
||||
|
||||
// Moves a #rrggbb color a fraction of the way toward a channel value (0 = black, 255 = white).
|
||||
function mixHex(hex: string, towards: number, weight: number): string {
|
||||
const channels = [1, 3, 5].map((start) => parseInt(hex.slice(start, start + 2), 16))
|
||||
return `#${channels.map((c) => Math.round(c + (towards - c) * weight).toString(16).padStart(2, '0')).join('')}`
|
||||
}
|
||||
|
||||
// The color is written to a stylesheet rather than inline on <html>. Shared and app CSS re-declare these
|
||||
// tokens on every [data-theme] element (the AppShell root, for one), and that declaration hides the value
|
||||
// <html> would pass down, so the choice never reached the app's UI. Targeting [data-theme] elements with
|
||||
// !important makes it win everywhere, and the dark/light split is left to the selectors.
|
||||
function primaryDeclarations(color: PaletteColor, dark: boolean): string {
|
||||
const primary = dark ? color.dark : color.light
|
||||
// Hover is lighter on dark and darker on light, as in the shared theme. It is a hex value, not color-mix(),
|
||||
// because consumers such as the terminal read these tokens as plain colors.
|
||||
const hover = dark ? mixHex(primary, 255, 0.15) : mixHex(primary, 0, 0.15)
|
||||
const foreground = dark ? color.darkFg : '#ffffff'
|
||||
return [
|
||||
...primaryVars.map((name) => `${name}: ${primary} !important;`),
|
||||
`--sc-primary-hover: ${hover} !important;`,
|
||||
...foregroundVars.map((name) => `${name}: ${foreground} !important;`),
|
||||
].join(' ')
|
||||
}
|
||||
|
||||
export function applyPrimaryColor(_projectKey: string, colorName: string): void {
|
||||
if (typeof document === 'undefined') return
|
||||
const color = paletteByName[colorName]
|
||||
const root = document.documentElement.style
|
||||
let style = document.getElementById(styleElementId) as HTMLStyleElement | null
|
||||
if (!color) {
|
||||
for (const name of [...primaryVars, ...foregroundVars]) root.removeProperty(name)
|
||||
style?.remove()
|
||||
return
|
||||
}
|
||||
const dark = document.documentElement.getAttribute('data-theme') === 'dark'
|
||||
const primary = dark ? color.dark : color.light
|
||||
const foreground = dark ? color.darkFg : '#ffffff'
|
||||
for (const name of primaryVars) root.setProperty(name, primary)
|
||||
for (const name of foregroundVars) root.setProperty(name, foreground)
|
||||
if (!style) {
|
||||
style = document.createElement('style')
|
||||
style.id = styleElementId
|
||||
document.head.append(style)
|
||||
}
|
||||
style.textContent = `:root, [data-theme] { ${primaryDeclarations(color, false)} }
|
||||
[data-theme='dark'] { ${primaryDeclarations(color, true)} }
|
||||
`
|
||||
}
|
||||
|
||||
export function setPrimaryColor(projectKey: string, colorName: string): void {
|
||||
@@ -105,11 +132,8 @@ export function initPrimaryColor(projectKey: string, userKey = ''): () => void {
|
||||
if (typeof document === 'undefined') return () => undefined
|
||||
if (userKey) setPrimaryColorUser(userKey)
|
||||
activeProjects.add(projectKey.trim().toLowerCase() || 'application')
|
||||
const stored = readStoredColor(projectKey)
|
||||
applyPrimaryColor(projectKey, stored)
|
||||
const observer = new MutationObserver(() => applyPrimaryColor(projectKey, readStoredColor(projectKey)))
|
||||
observer.observe(document.documentElement, { attributes: true, attributeFilter: ['data-theme'] })
|
||||
return () => observer.disconnect()
|
||||
applyPrimaryColor(projectKey, readStoredColor(projectKey))
|
||||
return () => undefined
|
||||
}
|
||||
|
||||
export function storedPrimaryColor(projectKey: string): string {
|
||||
|
||||
@@ -703,6 +703,27 @@ html[data-wide-layout='true'] .sc-header {
|
||||
box-shadow: 0 0 0 3px color-mix(in srgb, var(--sc-ring) 22%, transparent);
|
||||
}
|
||||
|
||||
/* Checkboxes and radios share one look across apps. The box takes each app's primary color,
|
||||
so it follows that app's light and dark theme. Sizes match the legacy shared sheet. The rule
|
||||
sits in the base layer so Tailwind utilities (size-*, accent-*) still override it per element. */
|
||||
@layer base {
|
||||
input[type='checkbox'],
|
||||
input[type='radio'] {
|
||||
accent-color: var(--sc-primary);
|
||||
width: 1.05rem;
|
||||
height: 1.05rem;
|
||||
flex: 0 0 auto;
|
||||
}
|
||||
|
||||
input[type='checkbox'] {
|
||||
border-radius: 4px;
|
||||
}
|
||||
|
||||
input[type='radio'] {
|
||||
border-radius: 9999px;
|
||||
}
|
||||
}
|
||||
|
||||
.sc-form-actions,
|
||||
.sc-dialog-footer {
|
||||
display: flex;
|
||||
|
||||
Reference in new issue
Block a user