A plain CssSheetParse no longer skips a browser-only declaration silently: it fails with a message that points shared sheets to CssSheetParseWithDiagnostics, which keeps native rules and reports the declaration. The web declaration counters on the parser and sheet are gone; packs refuse such declarations through the same parse, and the formatter counts them from the recorded declarations. The README property table is generated by css_tool properties from the parser's catalog, make check fails when it is stale, and the parse tests read every catalog row natively on its target.
153 lines
5.0 KiB
Ziran
153 lines
5.0 KiB
Ziran
Button :: #import "kryon/button";
|
|
CSS :: #import "css/Css";
|
|
Dom :: #import "kryon/dom";
|
|
Page :: #import "kryon/page";
|
|
Text :: #import "kryon/text";
|
|
Theme :: #import "kryon/theme";
|
|
Tree :: #import "kryon/tree";
|
|
using Geometry :: #import "kryon/geometry";
|
|
using Semantic :: #import "kryon/semantic";
|
|
using SessionModule :: #import "kryon/session";
|
|
#import "kryon/control_props"
|
|
#import "std/web"
|
|
|
|
using ButtonState;
|
|
|
|
started: bool;
|
|
updated: bool;
|
|
sheet: CSS.CssSheet;
|
|
|
|
css_source :: #string CSS
|
|
:root {
|
|
--save-ink: color-mix(in srgb, #e0d0c0, #f0e0d0);
|
|
--save-motion: 123ms;
|
|
}
|
|
|
|
Button.primary {
|
|
background: #111111;
|
|
color: #ffffff;
|
|
min-height: 32px;
|
|
width: 180px;
|
|
display: block;
|
|
margin-bottom: 8px;
|
|
}
|
|
|
|
Button#save {
|
|
background: #102030;
|
|
color: var(--save-ink);
|
|
min-height: 64px;
|
|
line-height: 1.4;
|
|
font-family: "Kryon Css Test";
|
|
font-size: 17px;
|
|
font-weight: 650;
|
|
font-style: italic;
|
|
letter-spacing: -0.5px;
|
|
transition: opacity 123ms linear;
|
|
-kryon-font-role: body;
|
|
-kryon-motion-duration: var(--save-motion);
|
|
-kryon-motion-multiplier: 1.25;
|
|
-kryon-motion-easing: standard;
|
|
-kryon-motion-reduced: no-preference;
|
|
}
|
|
|
|
Button#other {
|
|
background: #302010;
|
|
}
|
|
|
|
Button#state {
|
|
background: #203040;
|
|
}
|
|
|
|
Button#state:selected {
|
|
background: #405060;
|
|
}
|
|
|
|
@media (prefers-reduced-motion) {
|
|
Button#save {
|
|
transition: opacity 0ms linear;
|
|
-kryon-motion-duration: 0ms;
|
|
}
|
|
}
|
|
CSS;
|
|
|
|
ButtonFor :: (key: u64, id: s32, label: string, selected: bool) -> Button.Props {
|
|
props: Button.Props
|
|
props.key = key
|
|
props.id = id
|
|
props.class_name = CSS.StyleClass("primary")
|
|
props.label = label
|
|
props.bounds = Rectangle.{12.0, 12.0, 180.0, 32.0}
|
|
props.selected = selected
|
|
return props
|
|
}
|
|
|
|
Start :: () -> bool {
|
|
if !Theme.InstallDefaultTheme(false) { return false }
|
|
CSS.CssSheetReset(*sheet)
|
|
// The sheet is shared with the browser export, so it is read with the
|
|
// diagnostics parse, which keeps browser-only declarations for the DOM.
|
|
if !CSS.CssSheetParseWithDiagnostics(*sheet, css_source, "css-dom.css", CSS.CssNoImports,
|
|
CSS.CssDiagnostics.{}) { return false }
|
|
if !CSS.CssSheetInstall(*sheet, CSS.CssDefaultEnvironment(), null) { return false }
|
|
|
|
exported: [16384]u8
|
|
result: CSS.CSSExport = CSS.ExportCSS(
|
|
css_source, "css-dom.css", CSS.CssDefaultEnvironment(), exported[:])
|
|
if !result.ok || !Dom.SetStyleSheet(TextView(exported[:result.count])) { return false }
|
|
|
|
save: Button.Props = ButtonFor(101, CSS.StyleId("save"), "Save", false)
|
|
face := Button.ButtonInstalledFaceFor(save, cast(s32)ButtonStateNormal)
|
|
scope: s32 = WebScope()
|
|
WebSet(WebGlobal, WebName("__cssDomInk"), WebNumber(cast(float64)face.foreground))
|
|
WebSet(WebGlobal, WebName("__cssDomMinHeight"), WebNumber(cast(float64)face.min_height))
|
|
WebSet(WebGlobal, WebName("__cssDomLineHeight"), WebNumber(cast(float64)face.line_height))
|
|
WebSet(WebGlobal, WebName("__cssDomLineUnit"), WebNumber(cast(float64)cast(s32)face.line_height_unit))
|
|
WebSet(WebGlobal, WebName("__cssDomWeight"), WebNumber(cast(float64)face.font_weight))
|
|
WebSet(WebGlobal, WebName("__cssDomFontStyle"), WebNumber(cast(float64)cast(s32)face.font_style))
|
|
WebSet(WebGlobal, WebName("__cssDomTracking"), WebNumber(cast(float64)face.letter_spacing))
|
|
WebSet(WebGlobal, WebName("__cssDomTypeface"), WebText(face.typeface))
|
|
WebSet(WebGlobal, WebName("__cssDomMotionDuration"), WebNumber(cast(float64)face.motion_duration))
|
|
WebSet(WebGlobal, WebName("__cssDomMotionMultiplier"), WebNumber(cast(float64)face.motion_multiplier))
|
|
WebEnd(scope)
|
|
return true
|
|
}
|
|
|
|
#program_export
|
|
Frame :: (session: Session, viewport: Rectangle) -> s32 {
|
|
scope: s32 = WebScope()
|
|
defer WebEnd(scope)
|
|
if !started {
|
|
if !Start() { return 1 }
|
|
started = true
|
|
}
|
|
if !updated && WebAsBool(WebGet(WebGlobal, WebName("__cssDomUpdate"))) { updated = true }
|
|
|
|
opened := Page.Draw(session, .{key = 1, bounds = viewport, title = "CSS DOM"})
|
|
if !opened.opened { return 1 }
|
|
|
|
heading: Text.Props
|
|
heading.key = 2; heading.bounds = Rectangle.{12.0, 12.0, 240.0, 28.0}
|
|
heading.text = ifx updated then "CSS DOM updated" else "CSS DOM ready"
|
|
heading.semantic_kind = SemanticKind.SemanticHeading; heading.heading_level = 1
|
|
Text.Draw(session, heading)
|
|
|
|
save: Button.Props = ButtonFor(101, CSS.StyleId("save"),
|
|
ifx updated then "Save updated" else "Save", false)
|
|
other: Button.Props = ButtonFor(102, CSS.StyleId("other"), "Other", true)
|
|
state: Button.Props = ButtonFor(103, CSS.StyleId("state"), "State", true)
|
|
plain: Button.Props = ButtonFor(104, 0, "Plain", false)
|
|
if updated {
|
|
unused Button.Draw(session, other)
|
|
unused Button.Draw(session, save)
|
|
} else {
|
|
unused Button.Draw(session, save)
|
|
unused Button.Draw(session, other)
|
|
}
|
|
unused Button.Draw(session, state)
|
|
unused Button.Draw(session, plain)
|
|
|
|
if !Tree.End(session) { return 1 }
|
|
if WebAsBool(WebGet(WebGlobal, WebName("__cssDomDone"))) { Dom.RequestClose() }
|
|
return 0
|
|
}
|