// One answer on every target. Each style pack, with an app sheet parsed // over it, is built in the light and dark scheme; the digest covers the // rule table and what it resolves to for every widget kind and state. // tests/css_conformance.sh runs it as C, C++, Go, ZX and Android code and // compares each with tests/css_conformance.expected; css_conformance_main // is the C program and writes the browser pages. #import "css_parser" #import "css_export" #import "css_sheet" #import "css_digest" #import "style_pack_classic" #import "style_pack_material" #import "style_pack_lightfield" #import "kryon/style" #import "kryon/style_sheet" conformance_sheet: CssSheet; conformance_rules: StyleRules; conformance_id: s32 = StyleId("conformance"); // Everything the subset has that a browser can show, without attribute // selectors, so the same sheet also goes through the DOM export. conformance_app :: #string CSS @layer base, app; :root { --ink: #1d2733; --paper: #fbfaf7; --brand: rgb(40 90 160); --soft-brand: color-mix(in srgb, 30% rgb(40 90 160 / 80%), #e1ecf9 40%); --pad: 6px; --round: 0.5rem; --leading: 125%; } @media (prefers-color-scheme: dark) { :root { --ink: #e8eef5; --paper: #151a20; } } @layer app { Button { color: var(--ink); background: var(--paper); border-color: var(--ink); padding-inline: var(--pad); padding-block: 2px; border-radius: var(--round); } Button.primary { color: #ffffff; background: var(--brand); } } @layer base { Button.primary { color: #ff0000; font-size: 20px; } Text { color: var(--ink); font-size: 15px; } } Button:disabled { opacity: 50%; } Button:selected { border-color: color-mix(in srgb, transparent, #2877b3 38%); } Button.primary:loading { background: var(--soft-brand); color: color-mix(in srgb, rgb(10.4 30.4 50.4 / .499) 80%, rgb(11.4 31.4 51.4 / .501) 20%); } #conformance { color: #234567; min-block-size: 41px; line-height: var(--leading); font-weight: 650; font-style: italic; letter-spacing: -0.5px; -kryon-font-role: body; -kryon-elevation: floating; -kryon-motion-duration: 123ms; -kryon-motion-multiplier: 1.5; -kryon-motion-easing: linear; -kryon-motion-reduced: reduce; } @media (prefers-reduced-motion) { #conformance { -kryon-motion-duration: 0ms; } } Button#conformance:selected { color: #654321; } .quiet { color: #556677; gap: 3px; } Text.quiet { font-size: 13px; } Row.quiet, Column { gap: 4px 0.75rem; row-gap: 0; } Card, TextField { background: var(--paper); border-color: hwb(.5turn 0% 100% / 25%); padding: 4px 8px; } TextField:disabled { color: var(--dim, color-mix(in srgb, color-mix(in srgb, #223344, #8a9bac), #eeeeee 33%)); } CSS; PackName :: (pack: s32) -> string { if pack == 0 { return "classic" } if pack == 1 { return "material" } return "lightfield" } Pack :: (pack: s32) -> CssCompiledSheet { if pack == 0 { return StylePackClassic() } if pack == 1 { return StylePackMaterial() } return StylePackLightfield() } ThemeEnv :: (theme: s32) -> CssEnvironment { env: CssEnvironment = CssEnvironmentWithNames(CssDefaultEnvironment(), ifx theme == 1 then "dark" else "light", "", "", "", "") env.reduced_motion = theme == 1 return env } conformance_flex_css :: #string CSS Row { display: flex; justify-content: space-around; } Text { flex: initial; flex-grow: .5; flex-shrink: 2; flex-basis: 2rem; } CSS; FlexConforms :: () -> bool { CssSheetReset(*conformance_sheet) if !CssSheetParse(*conformance_sheet, conformance_flex_css, "flex.css", CssNoImports) || !CssSheetBuild(*conformance_sheet, CssDefaultEnvironment(), null, *conformance_rules) { return false } container := conformance_rules.items[0].flex item := conformance_rules.items[1].flex return conformance_rules.count == 2 && container.justify_content == 4 && item.basis == 32.0 && item.grow == 0.5 && item.shrink == 2.0 } // Small numbers signal failure to load, parse, build or resolve flex declarations. #program_export CssConformanceDigest :: (pack: s32, theme: s32) -> u32 { if pack == 0 && theme == 0 && !FlexConforms() { return 4 } CssSheetReset(*conformance_sheet) if !CssSheetLoad(*conformance_sheet, Pack(pack)) { return 1 } if !CssSheetParse(*conformance_sheet, conformance_app, "conformance.css", CssNoImports) { return 2 } if !CssSheetBuild(*conformance_sheet, ThemeEnv(theme), null, *conformance_rules) { return 3 } return CssDigestMix(CssDigestTable(conformance_rules), CssDigestResolved(conformance_rules, conformance_id)) } // All six digests in one number, for hosts that only return an integer. #program_export CssConformanceAll :: () -> s32 { hash: u32 = 2166136261 for pack: cast(s32)0..2 { for theme: cast(s32)0..1 { hash = CssDigestMix(hash, CssConformanceDigest(pack, theme)) } } return cast(s32)(hash & cast(u32)0x7fffffff) }