diff --git a/CHANGELOG.md b/CHANGELOG.md index 675eaa6..d734537 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,8 @@ ## Unreleased +- `transform`, `transform-origin`, `scale` and `rotate` are known browser-only declarations: a shared sheet keeps them for the DOM export and a plain native parse refuses them with the reason, instead of failing on an unknown property. + - `linear-gradient()` takes any angle (`deg`, `turn`, `rad`, `grad`) or `to` a side or corner, and two to six color stops with `%` positions, in `background` and `background-image`; Row, Column and Grid paint them, other widgets a top-to-bottom gradient of the first and last colors (`css_tool check` says so). Radial, conic and repeating gradients are refused natively with the reason. The pack format is 101 words a rule. Pins Kryon d0711324. - Selectors take tree context natively: one ancestor by class or id (`.card Text`), the parent (`.card > Text`), `:first-child`, and `:not(.class)` or `:not(:state)`, also in nested `&` rules, and the DOM export writes them as browser selectors. `:last-child`, `:nth-child()`, typed or second ancestors and sibling combinators fail with the native idiom. The pack format is 87 words a rule. Pins Kryon 56777c65. diff --git a/src/parser/properties.zi b/src/parser/properties.zi index 6eef2b2..9b073ba 100644 --- a/src/parser/properties.zi +++ b/src/parser/properties.zi @@ -544,6 +544,11 @@ css_web_properties: [9]string = .[ "text-decoration", "text-transform", "white-space", "cursor", "grid-template-rows", "grid-column", "grid-row", "z-index", "visibility"]; +CssTransformProperty :: (name: CssName) -> bool { + return CssNameEquals(name, "transform") || CssNameEquals(name, "transform-origin") || + CssNameEquals(name, "scale") || CssNameEquals(name, "rotate") +} + // Properties the web document host applies and native hosts skip: browser // layout and text features Kryon lays out in code. CssWebProperty :: (name: CssName) -> bool { @@ -805,6 +810,16 @@ CssApplyProperty :: (p: *CssParser, name: CssName, end: s32) -> s32 { return CssApplyBoxProperty(p, name, end) } else if CssBorderSideOf(name) >= 0 { return CssApplyBorderSide(p, name, end) + } else if CssTransformProperty(name) { + // A transform moves a whole widget and its children where they + // paint. Kryon's paint queue has no such offset yet, and the + // `translate` property already shifts a widget's content. + if p.native_only { + p.cursor = p.pending_name_cursor + CssFail(p, "transform, scale and rotate are browser-only: Kryon paints widgets where layout puts them; move a box with margins") + return -1 + } + return CssPassWebDeclaration(p) } else if CssWebProperty(name) { return CssPassWebDeclaration(p) } else if name.length >= 2 && name.bytes[0] == #char "-" && name.bytes[1] == #char "-" { diff --git a/tests/css_parse_behavior.zi b/tests/css_parse_behavior.zi index 035e434..63cd7fd 100644 --- a/tests/css_parse_behavior.zi +++ b/tests/css_parse_behavior.zi @@ -75,6 +75,8 @@ Values :: () { // sheet is read with CssSheetParseWithDiagnostics, which reports it. ParseFails("Button { width: 50vw; color: red; }", "applied only by the browser", "browser-only size refused natively") ParseFails("Button { text-transform: uppercase; }", "applied only by the browser", "browser-only property refused natively") + ParseFails("Column:hover { transform: translateY(-2px); }", "transform, scale and rotate are browser-only", "transform") + ParseFails("Button { rotate: 45deg; }", "transform, scale and rotate are browser-only", "rotate") if Builds("Button { padding: 4px 8px; }", "padding pair") { Check(Rule(0).style.padding_y == 4.0 && Rule(0).style.padding_x == 8.0, "padding block inline") }