Shoot any app entry as a PNG at any size
kryon run [PROFILE] --png FILE.png [--width PX] [--height PX] [--theme light|dark] renders the project's own entry offscreen through the desktop renderer, with its widget tree beside the PNG, for desktop and pixmap C99 profiles and without a preview fixture. Previews and shots share one flag parser and capture path; shots build under build/shot/PROFILE. The dashboard example's stylesheet put var() in border shorthands, which the CSS package rejects, so the example drew without its sheet. It now sets border-color separately and reports a rejected sheet once. shot_test shoots it at 1280x720 and 390x844, light and dark, and checks that a stylesheet edit changes the picture.
This commit is contained in:
1 parent
3c7ff4b5fb
commit
cdf23986a0
9 files changed
+565
-76
No files matched your search
@@ -2,6 +2,8 @@
|
||||
|
||||
## Unreleased
|
||||
|
||||
- `kryon run [PROFILE] --png FILE.png [--width PX] [--height PX] [--theme light|dark]` renders any app entry offscreen at any size up to 4096 pixels, with its widget tree beside the PNG and no preview fixture. The dashboard example's stylesheet parses again and reports a rejected sheet once.
|
||||
|
||||
- `kryon new` and `kryon init` take templates from the Gitea origin, and every starter pins exact Gitea Ziran and Kryon revisions, so a new app locks and builds with checked packages. `kryon init` explains a kept floating toolchain when the lock refuses it.
|
||||
|
||||
- The kryon project tool reads its command line from argv directly, so restricted sandboxes without procfs can run Kryon builds.
|
||||
|
||||
@@ -391,6 +391,15 @@ templates-test: build/bin/kryon
|
||||
@env -u DISPLAY -u WAYLAND_DISPLAY ZIRAN_ROOT=$(abspath $(ZIRAN_DIR)) \
|
||||
python3 tests/templates_test.py
|
||||
|
||||
# `kryon run shot --png` renders a whole app offscreen at any size: the
|
||||
# dashboard example at two sizes, then restyled.
|
||||
.PHONY: shot-test
|
||||
shot-test:
|
||||
@rm -rf build/test/shot
|
||||
@env -u DISPLAY -u WAYLAND_DISPLAY -u XAUTHORITY -u DBUS_SESSION_BUS_ADDRESS ZIRAN_BIN="$(ZIRAN_BIN)" \
|
||||
"$(ZIRAN_BIN)" run --target=c --root tests tests/shot_test.zi
|
||||
test: shot-test
|
||||
|
||||
# Every supported target -- C, Go, and the portable runner --
|
||||
# renders each template and example on the headless pixmap host, and every
|
||||
# image must equal C's byte for byte. It needs go and python3, and
|
||||
|
||||
@@ -2,6 +2,10 @@
|
||||
|
||||
## Native fixture preview
|
||||
|
||||
To capture the whole app instead, without a fixture, run
|
||||
`kryon run shot --png FILE.png --width PX --height PX --theme light|dark`
|
||||
([Projects](PROJECTS.md)); it writes the same PNG and JSON.
|
||||
|
||||
From a Linux project with a desktop C99 profile, run:
|
||||
|
||||
```sh
|
||||
|
||||
+12
-1
@@ -105,8 +105,19 @@ kryon check
|
||||
kryon build
|
||||
kryon run desktop # or: kryon run --profile desktop, ziran run desktop
|
||||
kryon profiles # the profiles, their hosts, and the default
|
||||
kryon run shot --png build/shot.png --width 390 --height 844 --theme dark
|
||||
```
|
||||
|
||||
`kryon run [PROFILE] --png FILE.png` renders the app's own entry offscreen,
|
||||
with no display and no preview fixture, and writes `FILE.png` and its widget
|
||||
tree `FILE.json` (the [preview JSON](FRAME_REPLAY.md#native-fixture-preview)).
|
||||
`--width` and `--height` take 1–4096 pixels (960 × 600 by default); a comma
|
||||
list of widths writes `FILE-PX.png` per width. `--theme light|dark` picks the
|
||||
palette (light by default). The named profile must be a desktop or pixmap C99
|
||||
profile, and the entry must export `Frame`; the desktop renderer draws the
|
||||
picture in either case, so it matches the window. The capture build lives in
|
||||
`build/shot/PROFILE`.
|
||||
|
||||
Commit `ziran.lock` to pin exact package and toolchain revisions. `ziran
|
||||
fetch` fills the shared cache. For local development, `ziran.local.toml` can
|
||||
override the Kryon and Ziran roots; it is not the published dependency
|
||||
@@ -163,7 +174,7 @@ terminal; otherwise it uses the default.
|
||||
| `terminal` | 80 × 24 terminal cells | TTY for interactive input; redirected output renders once |
|
||||
| `desktop` | SDL2 window with Cairo raster | SDL2, Cairo, and FreeType development libraries |
|
||||
| `canvas` | Canvas2D browser page | Emscripten with Asyncify; see [Canvas host](canvas.md) |
|
||||
| `pixmap` | headless 960 × 600 frame printed as a PPM image | nothing; `kryon run shot > frame.ppm` |
|
||||
| `pixmap` | headless 960 × 600 frame printed as a PPM image; `--png` draws any size instead | nothing; `kryon run shot > frame.ppm` |
|
||||
| `android` | installable APK through a generated `droid/` Gradle project and direct NativeActivity host | a JDK, the Android SDK with NDK `28.2.13676358` and CMake `3.22.1`, the locked codec source packages, and `[tool.kryon.android] package`; see [Android host](BACKENDS.md#android-host) |
|
||||
|
||||
The SDL desktop host presents its already rasterized pixels through the
|
||||
|
||||
@@ -6,6 +6,7 @@ sheet: CSS.CssSheet;
|
||||
sheet_parsed: bool;
|
||||
applied_dark: s32 = -1;
|
||||
applied_compact: s32 = -1;
|
||||
css_reported: bool;
|
||||
|
||||
dashboard_css :: #string CSS
|
||||
:root {
|
||||
@@ -52,20 +53,23 @@ dashboard_css :: #string CSS
|
||||
Card {
|
||||
background: var(--surface-card);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 10px;
|
||||
-kryon-elevation: rest;
|
||||
}
|
||||
|
||||
Card.kpi-card {
|
||||
background: var(--surface-card);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
Card.inspector-card {
|
||||
background: var(--surface-card);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 10px;
|
||||
}
|
||||
|
||||
@@ -94,7 +98,8 @@ Button.nav-item:selected {
|
||||
Button.chip {
|
||||
background: var(--surface-sunken);
|
||||
color: var(--text-muted);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 8px;
|
||||
min-height: 30px;
|
||||
padding: 4px 10px;
|
||||
@@ -115,7 +120,8 @@ Button.chip:selected {
|
||||
Button.result-row {
|
||||
background: var(--surface-card);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 8px;
|
||||
padding: 8px 12px;
|
||||
outline-color: var(--focus-ring);
|
||||
@@ -142,7 +148,8 @@ Button.primary-btn {
|
||||
TextField.search-field {
|
||||
background: var(--surface-sunken);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-strong);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-strong);
|
||||
border-radius: 8px;
|
||||
padding: 0px 12px;
|
||||
outline-color: var(--focus-ring);
|
||||
@@ -155,7 +162,8 @@ TextField.search-field:focus {
|
||||
Modal {
|
||||
background: var(--surface-card);
|
||||
color: var(--text-primary);
|
||||
border: 1px solid var(--border-subtle);
|
||||
border: 1px solid;
|
||||
border-color: var(--border-subtle);
|
||||
border-radius: 12px;
|
||||
-kryon-elevation: floating;
|
||||
}
|
||||
@@ -169,6 +177,16 @@ ElementId :: (name: string) -> s32 {
|
||||
return CSS.StyleId(name)
|
||||
}
|
||||
|
||||
// A rejected stylesheet leaves the default theme; say why, once.
|
||||
ReportCss :: () -> bool {
|
||||
if !css_reported {
|
||||
diagnostic: [512]u8
|
||||
print("dashboard.css: %\n", CSS.CssSheetDiagnostic(*sheet, diagnostic[:]))
|
||||
css_reported = true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
EnsureDashboardTheme :: (dark: bool, compact: bool, reduced_motion: bool) -> bool {
|
||||
want_dark: s32 = ifx dark then 1 else 0
|
||||
want_compact: s32 = ifx compact then 1 else 0
|
||||
@@ -179,7 +197,7 @@ EnsureDashboardTheme :: (dark: bool, compact: bool, reduced_motion: bool) -> boo
|
||||
if !sheet_parsed {
|
||||
CSS.CssSheetReset(*sheet)
|
||||
if !CSS.CssSheetParse(*sheet, dashboard_css, "dashboard.css", CSS.CssNoImports) {
|
||||
return false
|
||||
return ReportCss()
|
||||
}
|
||||
sheet_parsed = true
|
||||
}
|
||||
@@ -191,7 +209,7 @@ EnsureDashboardTheme :: (dark: bool, compact: bool, reduced_motion: bool) -> boo
|
||||
"mouse",
|
||||
"desktop")
|
||||
if !CSS.CssSheetInstall(*sheet, env, null) {
|
||||
return false
|
||||
return ReportCss()
|
||||
}
|
||||
applied_dark = want_dark
|
||||
applied_compact = want_compact
|
||||
|
||||
@@ -0,0 +1,255 @@
|
||||
# LLM-authoring audit: Kryon UI and the CSS package (2026-11-22)
|
||||
|
||||
Read-only audit of how hard it is for an LLM to build a good-looking Kryon app
|
||||
fast. Paths are relative to /mnt/storage/Projects/kryonlabs. Status legend:
|
||||
`supported` = styles native widgets; `web-only` = parsed but ignored by native
|
||||
hosts (kept for the DOM export); `unsupported-count` = parsed but flagged in
|
||||
`sheet.motion_unsupported`; `missing` = hard parse error, whole sheet refused.
|
||||
A second helper covers the Ziran language; not covered here.
|
||||
|
||||
## 1. CSS coverage
|
||||
|
||||
| Group | Item | Status | Proof |
|
||||
| --- | --- | --- | --- |
|
||||
| selectors | type (`Button`,`Row`,`Grid`,`App`,`*`), one `.class`, one `#id` (`props.id = StyleId(...)`) | supported | packages/css/src/parser/selectors.zi:81-92,101-109,146-155; packages/css/README.md:53 |
|
||||
| selectors | descendant, `>` child, `+`/`~` sibling combinators | missing (error) | packages/css/src/parser/selectors.zi:183-186 |
|
||||
| selectors | attribute `[x=y]` for tone/emphasis/size/role/state only, `=` only | supported | packages/css/src/parser/selectors.zi:46-85 |
|
||||
| selectors | any other attribute or `~=`/`*=` operator | missing (error) | packages/css/src/parser/selectors.zi:56-58,79-82 |
|
||||
| selectors | `:hover :active :focus :focus-visible :disabled :checked` (+ `:selected` `:loading`) | supported | packages/css/src/parser/selectors.zi:12-24 |
|
||||
| selectors | `:first-child :last-child :nth-child() :not() :is() :where() :has()` | missing (error) | packages/css/src/parser/selectors.zi:137-139,161-165 |
|
||||
| selectors | `::before ::after ::placeholder` (any pseudo-element) | missing (error) | packages/css/src/parser/selectors.zi:131-133 |
|
||||
| selectors | specificity (layer, then type 1 / attr 10 / class 20 / id 200, order; states add nothing); cascade last-wins; comma lists max 8 | supported (custom model) | packages/css/README.md:174-178,108-110; packages/css/src/parser/selectors.zi:199-201 |
|
||||
| selectors | `!important` | missing (error) | packages/css/README.md:150; packages/css/src/parser/properties.zi:728-730 |
|
||||
| selectors | inheritance: none; `em`/`%` rejected (no inherited font size) | documented limit | packages/css/README.md:119-120 |
|
||||
| at-rules | `@media`: prefers-color-scheme, prefers-contrast, pointer, any-pointer, hover, prefers-reduced-motion, `-kryon-theme/-density/-pointer/-platform` | supported | packages/css/src/parser/media.zi:2-4,67-93; packages/css/README.md:145-149 |
|
||||
| at-rules | `@media` width/min-width/max-width native subset (px, rem, unitless zero) | supported | packages/css/README.md:147,159-164; docs/ui-map.json:43 |
|
||||
| at-rules | `@media` height/min-height/max-height | web-only | packages/css/src/parser/media.zi:31 |
|
||||
| at-rules | `@keyframes` (from/to/percent, comma offsets) | supported | packages/css/src/parser/statements.zi:216-246; packages/css/README.md:232-234 |
|
||||
| at-rules | `@import` (resolver callback, must precede rules) and `@layer` (max 12, flat) | supported | packages/css/src/parser/statements.zi:130-131,41-66,89; packages/css/README.md:46-47,145 |
|
||||
| at-rules | `@container` `@font-face` `@supports` | missing (error) | packages/css/src/parser/statements.zi:249 |
|
||||
| at-rules | nesting (`&`) | missing (error) | packages/css/README.md:57-58 |
|
||||
| values | `var(--name)` / `var(--name, fallback)`; `:root` custom properties only | supported | packages/css/src/parser/values.zi:61-86; packages/css/src/parser/properties.zi:715-718 |
|
||||
| values | nested `var()` in fallbacks | missing (error) | packages/css/src/parser/values.zi:482-483,551-552 |
|
||||
| values | `calc()` `min()` `max()` `clamp()` as value functions | missing (error); sole exception `min(LENGTH,100%)` in native grid `minmax` | packages/css/src/parser/properties.zi:443-455; packages/css/README.md:95 |
|
||||
| values | units px, rem (16px), s, ms; `%` for opacity/channels/line-height/keyframe offsets | supported | packages/css/README.md:115,63,112; packages/css/src/parser/motion.zi:340 |
|
||||
| values | `em`, `%` lengths, `vw`, `vh`, `ch` | missing (error for em/%; others unknown property/value) | packages/css/README.md:119-120 |
|
||||
| values | colors: hex, named (147), `rgb()/rgba()/hsl()/hsla()/hwb()`, `color-mix(in srgb, literals)`, `transparent` | supported | packages/css/src/parser/values.zi:178,184; packages/css/README.md:114,123-129 |
|
||||
| values | `oklch()`, `currentColor`, custom-property color stops | missing | packages/css/README.md:132-133 |
|
||||
| layout | `display: flex/grid/block/inline/inline-flex/none` | web-only | packages/css/src/parser/properties.zi:503; packages/css/README.md:74-76 |
|
||||
| layout | flex-direction, flex-wrap, `flex`, justify-content, align-items, align-self | web-only | packages/css/src/parser/properties.zi:503-504 |
|
||||
| layout | align-content, `order`, flex-grow/shrink/basis | missing (error) | absent from properties.zi:498-505; error path properties.zi:721 |
|
||||
| layout | native flex layout | widget code only: `BeginFlexCursor`/`FlexStep` + JustifyContent/AlignItems enums | docs/HTML_TO_KRYON.md:112-115 |
|
||||
| layout | gap / row-gap / column-gap (px, rem, `normal`) | supported | packages/css/README.md:79-83 |
|
||||
| layout | grid-template-columns: `1fr`, `minmax(0,1fr)`, `repeat(N,...)`, `repeat(auto-fit,minmax(...))` | supported | packages/css/src/parser/properties.zi:437-490; packages/css/README.md:92-97 |
|
||||
| layout | grid-template-rows, grid-column, grid-row | web-only; native spans via `GridItem.column_span` | packages/css/src/parser/properties.zi:504-505; docs/ui-map.json:44; docs/HTML_TO_KRYON.md:118 |
|
||||
| layout | grid-area, place-items | missing (error) | absent from properties.zi:498-505; error path properties.zi:721 |
|
||||
| layout | position relative/absolute/fixed/sticky; top/right/bottom/left/inset | missing (error) | absent from properties.zi:498-505; error path properties.zi:721 |
|
||||
| layout | z-index | web-only | packages/css/src/parser/properties.zi:505 |
|
||||
| layout | width/height (px, rem, `auto`, outer size incl. padding) | supported | packages/css/README.md:84-91; packages/css/src/parser/properties.zi:400-417 |
|
||||
| layout | width/height %, var(), calc(), intrinsic keywords | web-only (native skips) | packages/css/README.md:89-91 |
|
||||
| layout | min-height / min-block-size | supported | packages/css/README.md:108-112 |
|
||||
| layout | min-width, max-width, max-height | web-only | packages/css/src/parser/properties.zi:499 |
|
||||
| layout | aspect-ratio; box-sizing | missing (error) | absent from properties.zi:498-505 |
|
||||
| layout | overflow hidden/scroll/auto | web-only; per-axis overflow-x/y missing; native scroll is the `Scroll` widget | packages/css/src/parser/properties.zi:505; docs/ui-map.json:41 |
|
||||
| layout | margin (incl. `auto`, negative) | web-only; native margins via layout APIs | packages/css/src/parser/properties.zi:500-501; docs/HTML_TO_KRYON.md:295 |
|
||||
| layout | padding + padding-inline/block + per-side names (opposite sides must match) | supported | packages/css/README.md:63-64; packages/css/src/parser/properties.zi:588-592 |
|
||||
| visual | background-color; `background` color | supported | packages/css/src/parser/properties.zi:539-546 |
|
||||
| visual | `background: linear-gradient(...)` two stops, vertical only | supported | packages/css/src/parser/properties.zi:295-302; packages/css/README.md:60 |
|
||||
| visual | `url()` background-image, radial-gradient, conic-gradient, background-size/position/repeat | missing (error) | packages/css/src/parser/properties.zi:345-347; absent from properties.zi:295-302,498-505 |
|
||||
| visual | border width/style/color; `solid` or `none` only; no per-side border-top-* | supported (shorthand only) | packages/css/README.md:61-62 |
|
||||
| visual | border-radius (1-4 values, opposite corners must match; single radius field) | supported | packages/css/src/parser/properties.zi:572-574; packages/css/README.md:63-64 |
|
||||
| visual | box-shadow (multiple, inset, spread) | web-only; native elevation via `-kryon-elevation: none/rest/raised/floating` | packages/css/src/parser/properties.zi:502; packages/css/README.md:71; kryon/src/ui/theme.zi:303-316 |
|
||||
| visual | outline | only outline-color; outline-width/style missing | packages/css/src/parser/properties.zi:551-554; packages/css/README.md:68 |
|
||||
| visual | opacity (number or %, clamped 0-1) | supported | packages/css/README.md:63,112 |
|
||||
| visual | filter (blur/brightness/drop-shadow), backdrop-filter, mix-blend-mode, clip-path, object-fit | missing (error) | absent from properties.zi:498-505; error path properties.zi:721 |
|
||||
| typography | font-family (fallback list: first family wins, rest silently dropped) | supported (partial) | packages/css/src/parser/properties.zi:372-395 |
|
||||
| typography | font-size; font-weight 1-1000; font-style (no angle); line-height `normal`/factor/%/length; letter-spacing px/rem | supported | packages/css/README.md:67,100-106,103 |
|
||||
| typography | text-align, text-decoration, text-transform, white-space | web-only; native via `Text.Props.align` / `.strong` | packages/css/src/parser/properties.zi:501-502; docs/HTML_TO_KRYON.md:43 |
|
||||
| typography | text-overflow ellipsis, word-break | CSS missing; native via `.wrap = TextWrapEllipsis/TextWrapAnywhere` | docs/HTML_TO_KRYON.md:43 |
|
||||
| typography | line-clamp, text-shadow, font-variant-numeric | missing (error) | absent from properties.zi:498-505; error path properties.zi:721 |
|
||||
| motion | transition: property list, duration, delay, `linear/ease*/cubic-bezier()` | supported, one duration/delay/easing per selector, comma list must share timing | packages/css/README.md:222-228 |
|
||||
| motion | unequal transition timings, `steps()` | unsupported-count (`motion_unsupported`) | packages/css/src/parser/motion.zi:280,287; packages/css/README.md:237-240 |
|
||||
| motion | animation + `@keyframes` (one named track per selector; repeats, direction, fill modes) | supported | packages/css/README.md:223-228; packages/css/src/parser/statements.zi:216-246 |
|
||||
| motion | `transform` in a normal rule (and transform-origin, scale, rotate, skew) | missing (error); only `translate: x y` supported | packages/css/src/parser/properties.zi:721; packages/css/README.md:231,239 |
|
||||
| motion | `transform` inside `@keyframes` | unsupported-count (kept raw for browser export) | packages/css/src/parser/motion.zi:311-312; packages/css/tests/css_motion_behavior.zi:142 |
|
||||
| interaction | cursor | web-only; native cursor is a host contract | packages/css/src/parser/properties.zi:502; kryon/README.md:71-72 |
|
||||
| interaction | pointer-events, user-select | missing (error) | absent from properties.zi:498-505 |
|
||||
| interaction | scroll-behavior, scroll-snap | missing (error); scrolling is the `Scroll` widget | docs/ui-map.json:41 |
|
||||
| interaction | shipped look presets: classic, lightfield, material packs | supported (opt-in, compiled) | packages/css/README.md:5-7,297-305; packages/css/styles/ |
|
||||
|
||||
## 2. Unsupported CSS behavior
|
||||
|
||||
Anything unknown fails the whole sheet with one diagnostic: unknown property ->
|
||||
`CssFailName(p, "unknown property", ...)` (packages/css/src/parser/properties.zi:719-722);
|
||||
`CssSheetParse` returns false and the app keeps its previous styles
|
||||
(packages/css/src/css_sheet.zi:394-422; packages/css/README.md:36-44). The same
|
||||
hard failure applies to unknown widget type (selectors.zi:87), pseudo-elements
|
||||
and selector functions (selectors.zi:131-139), unknown pseudo-class
|
||||
(selectors.zi:161-165), unknown at-rule (statements.zi:249), unknown
|
||||
attribute/value (selectors.zi:79-84), and unknown values for known properties
|
||||
(e.g. em/% lengths, README.md:119-120).
|
||||
Ignored declarations are only counted, never listed: `sheet.web_declarations`
|
||||
increments per web-only declaration (properties.zi:492-496; css_sheet.zi:99) and
|
||||
`sheet.motion_unsupported` counts rules/keyframes containing browser-only motion
|
||||
(css_sheet.zi:98,338,371; README.md:237-240). No API returns WHICH declarations
|
||||
were ignored; the only tool surface is `css_tool export | check | format |
|
||||
format-check | pack | pack-file | pack-check` (packages/css/tools/css_tool.zi:494)
|
||||
- there is no lint or ignored-declaration report. `CssSheetDiagnostic` returns
|
||||
the single failure string (css_sheet.zi:187).
|
||||
|
||||
## 3. How an app uses CSS with Kryon today
|
||||
|
||||
Smallest path, all runtime (dashboard starter, examples/dashboard/src/styles.zi):
|
||||
pin and add the package with `ziran add https://git.waozi.xyz/kryonlabs/css.git`
|
||||
(packages/css/README.md:13-20); embed the sheet in the binary via
|
||||
`dashboard_css :: #string CSS` (styles.zi:10-162); at startup call
|
||||
`InstallDefaultTheme(dark)`, `CssSheetParse(*sheet, css, name, CssNoImports)`,
|
||||
then `CssSheetInstall(*sheet, env, null)` with an environment built from
|
||||
dark/density/pointer/platform names (styles.zi:172-198; README.md:28-33); each
|
||||
widget opts in with `.class_name = CSS.StyleClass("kpi-card")` (styles.zi:164-166;
|
||||
dashboard.zi:210) and `.id = StyleId(...)`; reinstall on dark/density changes and
|
||||
feed viewport width via `CssEnvironmentWithViewportWidth` + `CssSheetSameMedia`
|
||||
(packages/css/README.md:159-172).
|
||||
Compile-time alternative: `css_tool pack-file NAME IN.css OUT.zi` compiles a pack
|
||||
apps load with `CssSheetLoad` without parsing (README.md:242-243,297-305).
|
||||
Shipped users: only the dashboard example calls `CssSheetParse`/`CssSheetLoad`
|
||||
in kryonlabs/kryon (rg: examples/dashboard/src/styles.zi:181,
|
||||
examples/dashboard/previews/responsive.zi, docs/HTML_TO_KRYON.md); the gallery,
|
||||
`kryon new` templates and every other example use typed styles with no
|
||||
stylesheet (templates/app/src/app.zi:1-40); kryonlabs/showcase is metadata JSON
|
||||
linking external repos (showcase/projects/inner-breeze/project.json:9-15).
|
||||
|
||||
## 4. Widget API ergonomics without CSS
|
||||
|
||||
Screen A - dashboard starter: src 853 lines + styles.zi 199 lines
|
||||
(examples/dashboard/src/dashboard.zi, styles.zi). Color/radius/elevation/state
|
||||
live in the embedded CSS (styles.zi:52-70,83-113,155-161); spacing and layout
|
||||
are hand-computed `Rectangle` arithmetic (dashboard.zi:217,224,231,301-306).
|
||||
Screen B - gallery scenes: 573 lines, 41 widget imports
|
||||
(examples/gallery/src/scenes.zi:2-42); spacing via theme tokens
|
||||
`Layout.Gap(.ThemeMetricSpace3)` (scenes.zi:169,366); containers measure
|
||||
children then compute bounds (scenes.zi:168-186); wrapping via `Flow.Draw`
|
||||
(scenes.zi:453). Most verbose / surprising constructs:
|
||||
1. Absolute geometry for every widget (dashboard.zi:301-302):
|
||||
```zi
|
||||
Text.Draw(session, Text.Props.{.key = 607, .bounds = Rectangle.{c.x, stat_y + 18.0, col_w, 20.0}, .text = lat_str, .size = 14})
|
||||
Text.Draw(session, Text.Props.{.key = 608, .bounds = Rectangle.{c.x + col_w + 8.0, stat_y, col_w, 16.0}, .text = "Uptime", .size = 11})
|
||||
```
|
||||
2. Per-widget style wiring plus synthetic keys (dashboard.zi:208-216):
|
||||
```zi
|
||||
card := Card.Draw(session, Card.Props.{
|
||||
.key = key, .class_name = ClassId("kpi-card"),
|
||||
.bounds = bounds, .variant = .CardOutlined })
|
||||
Text.Draw(session, Text.Props.{.key = key * 10 + 1, ...})
|
||||
```
|
||||
3. Grid items need up-front heights and spans (previews/responsive.zi:97-99):
|
||||
```zi
|
||||
items: [3]Grid.GridItem = .[.{.height = 106, .column_span = -1}, .{.height = 86}, .{.height = 86}]
|
||||
grid := Layout.Grid(session, Grid.GridProps.{.key = 30, .class_name = CSS.StyleClass("charts")}, items[:])
|
||||
```
|
||||
4. Measure-then-compose container dance (scenes.zi:169-175):
|
||||
```zi
|
||||
gap := Layout.Gap(.ThemeMetricSpace2)
|
||||
button_size := Button.ButtonMeasure(button)
|
||||
sizes: [2]Rectangle = .{button_size, button_size}
|
||||
form := Layout.Draw(session, Layout.Props.{.key = 1, .gap = gap,
|
||||
.bounds = Layout.LayoutContentBounds(b, .FlexColumn, sizes[:], gap)})
|
||||
```
|
||||
5. Scoped containers: draw children then `End(session)` only when `opened`
|
||||
(docs/HTML_TO_KRYON.md:18,91-94), plus `gap_override`/`padding_override` flags
|
||||
to force zero against theme defaults (docs/HTML_TO_KRYON.md:108).
|
||||
Default app, zero styling: the `kryon new` app template imports no CSS and no
|
||||
Theme; the desktop host applies the system palette (templates/app/src/app.zi:1-40;
|
||||
docs/THEMING.md:3-7) and `InstallDefaultTheme(dark)` installs palette, metrics,
|
||||
fonts, shadows and motion (docs/THEMING.md:9-11). Default tokens: radii
|
||||
6/8/10/14/18/999 (kryon/src/ui/theme.zi:285-287); spacing 4/8/12/16/20/24
|
||||
(theme.zi:288-289); elevation shadows rest/raised/floating (theme.zi:303-316);
|
||||
type scale 11/12/13/15 + headings 36/28/22/17 (theme.zi:293-297); fonts
|
||||
Inter/Geist/Lucide (theme.zi:273-279); accent #00864b light, #53dca6 dark
|
||||
(theme.zi:178,203); dark mode via `InstallDefaultTheme`/`SetThemeMode`/
|
||||
`ThemePolicy.ResolveDark` (docs/THEMING.md:9-17) and `prefers-color-scheme`
|
||||
(packages/css/README.md:146); extra named palettes need `-kryon-theme` media
|
||||
(kryon/themes/catalog_light.css:12-23). Verdict: tokenized and consistent, but
|
||||
flat - no cards, shadows or accent usage until code or CSS adds them.
|
||||
Ready-made: card, box, avatar, badge, tabs/TabBar with top/bottom/left/right
|
||||
placements (docs/HTML_TO_KRYON.md:41), NavigationBar bottom nav
|
||||
(docs/ui-map.json:10), Toolbar/TitleBar app bar (docs/HTML_TO_KRYON.md:39),
|
||||
Modal/Dialog (docs/HTML_TO_KRYON.md:58), Sheet (src/ui/sheet;
|
||||
docs/COMPONENTS.md:92-98), Toast (docs/API.md:59-71), Loading/LoadingScreen
|
||||
(docs/HTML_TO_KRYON.md:63), Toggle switch (docs/ui-map.json:22), Slider
|
||||
(docs/ui-map.json:26), SvgIcon (docs/HTML_TO_KRYON.md:61), plus command palette,
|
||||
tooltip, hovercard, carousel, checklist, fieldset, progress, segmented control,
|
||||
collapsible, breadcrumb. Missing: a first-class chip (dashboard fakes it with a
|
||||
styled Button, styles.zi:94-113), a rich list-item composite (docs recommend
|
||||
Scroll+Button rows, docs/HTML_TO_KRYON.md:55), a skeleton placeholder distinct
|
||||
from the spinner. docs/COMPONENTS.md is ZX component hosting, not a widget
|
||||
catalog (docs/COMPONENTS.md:3-7); docs/WIDGET_CONFORMANCE.md is test policy
|
||||
(docs/WIDGET_CONFORMANCE.md:3-11); no widget catalog document exists.
|
||||
|
||||
## 5. LLM-facing documentation
|
||||
|
||||
docs/API.md is a 2923-line feature log with no compact index (docs/API.md:1-46);
|
||||
docs/COMPONENTS.md 105 lines is ZX component hosting (docs/COMPONENTS.md:3-7);
|
||||
docs/HTML_TO_KRYON.md 436 lines is the real porting guide with `ziran api`
|
||||
discovery (docs/HTML_TO_KRYON.md:23-31,417-436); docs/ui-map.json 46 lines is
|
||||
the machine-readable mapping (docs/ui-map.json:4-46); README.md 136 lines
|
||||
(kryon/README.md:50-52); the CSS truth lives in packages/css/README.md:49-178
|
||||
(353 lines total).
|
||||
No compact cheat sheet exists; a gallery with screenshots and live editable
|
||||
previews requires `make site` (Emscripten) (kryon/README.md:87-103); starter
|
||||
templates plus `kryon new DIR --template app|tui|pages|web` exist
|
||||
(src/project/cli_linux.zi:322,329,604; templates/app/) but ship no stylesheet.
|
||||
kryon-start pitfalls (skills/kryon-start/SKILL.md:174-188) and classification:
|
||||
| Pitfall | Class |
|
||||
| --- | --- |
|
||||
| No `ziran.lock`, no build (SKILL.md:175) | fixable in Kryon: templates ship a lockfile or `new` runs lock |
|
||||
| Never start Xvfb yourself; OpenPrivateDisplay/StartOnDisplay (SKILL.md:176-177) | fixable by a clear diagnostic |
|
||||
| App built without `KRYON_TEST_DRIVER` exits under the driver (SKILL.md:178) | fixable by a clear diagnostic |
|
||||
| Frame replay fails without `RecordFrameFailure` capability binding (SKILL.md:179) | fixable by a clear diagnostic |
|
||||
| Typed text lives in `TextField.State` bytes; stale-state gotchas (SKILL.md:180-182) | inherent; cheat-sheet docs |
|
||||
| Focus moves after press; re-select role before next `DriverType` (SKILL.md:183-184) | inherent; docs |
|
||||
| Return views must borrow caller-owned storage (SKILL.md:185-187) | inherent (language rule); compiler diagnostic |
|
||||
| Text field package is `kryon/text_field` (SKILL.md:188) | fixable by cheat sheet / ui-map |
|
||||
|
||||
## 6. Feedback loop for an agent
|
||||
|
||||
| Route | Commands | Result | Proof |
|
||||
| --- | --- | --- | --- |
|
||||
| `kryon preview` fixture | 1, after registering a `previews/` module in `module_roots` | offscreen Cairo PNG + node JSON, fixed palette, deterministic | docs/FRAME_REPLAY.md:5-15,17-21,37-42 |
|
||||
| `kryon run shot` (pixmap profile) | 1 | headless fixed 960x600 PPM, byte-identical across C/Go/ZX; with `--png FILE --width W --height H --theme T` any app entry at any size as PNG + node JSON | docs/PROJECTS.md |
|
||||
| Frame replay + inspect | 3 (capture build, `tools/frame-replay.sh`, `tools/frame-inspect.sh --diff`) | JSON tree/paint commands, no raster pixels | docs/FRAME_REPLAY.md:62-75,104-105 |
|
||||
| Test driver + private Xvfb | 2-3 (`ziran lock`, `KRYON_TEST_DRIVER=1 ziran build`, run test) | real window driven by label/role | skills/kryon-start/SKILL.md:49-56,123-155 |
|
||||
| Browser gallery | `make site` (Emscripten) | editable examples with live preview | kryon/README.md:87-103 |
|
||||
|
||||
An edit reaches pixels in 1 command once a preview fixture exists, but the
|
||||
fixture must be a separate `previews/<name>.zi` module (docs/FRAME_REPLAY.md:17-21);
|
||||
a whole-app screenshot without a fixture is the fixed-size pixmap profile
|
||||
(docs/PROJECTS.md:166). There is no hot reload or live preview outside the
|
||||
browser gallery (only a historical Krait IDE note, kryon/CHANGELOG.md:515-518).
|
||||
No timing numbers are recorded in these docs to cite.
|
||||
|
||||
## 7. Open work already planned
|
||||
|
||||
- plans/2026-11-18-web-apps.md:11-17: five shipped apps lack web builds, each
|
||||
blocked in app code (PTY shell, curl HTTP, gh CLI, XDND, X11 imports).
|
||||
- plans/2026-11-21-style-codec-size.md:33-40: StyleData hosted codec grown to 34
|
||||
fields carrying width/height (done locally, codec + push-check suites passed).
|
||||
- plans/2026-11-21-style-codec-size.md:41-43: open - publish those hunks to
|
||||
master, then update the CSS package and Harmony to the same Kryon identity
|
||||
before publishing the native stylesheet milestone.
|
||||
- kryon/TODO.md:1 and packages/css/TODO.md:1 are bare `# TODO` headers: no
|
||||
tracked styling, appearance or ease-of-use items anywhere.
|
||||
|
||||
## Top gaps
|
||||
|
||||
1. No flex/grid in CSS: `display/flex/justify-*` parsed but ignored, so layout can never be CSS - evidence properties.zi:498-505 + ui-map.json:38-41 - fix: resolve CSS layout declarations onto Layout.Row/Column/Grid at install, or loudly diagnose them - files: packages/css/src/parser/properties.zi, packages/css/src/css_sheet.zi, kryon/src/ui/style.zi - test: a sheet with `Row{gap:12}` + `display:flex` changes the dashboard grid digest and driver node bounds.
|
||||
2. Ignored declarations are invisible: two counters but no listing - evidence properties.zi:492-505, css_sheet.zi:98-99, css_tool.zi:494 - fix: `css_tool check` prints every web-only/ignored declaration with line:col - files: packages/css/src/css_sheet.zi, tools/css_tool.zi - test: check on a margin+box-shadow sheet lists both names.
|
||||
3. One unknown property kills the whole sheet - evidence properties.zi:719-722, README.md:36-37 - fix: collect up to N diagnostics and add a lenient parse mode - files: packages/css/src/parser/properties.zi, src/css_sheet.zi - test: a sheet with two typos returns both diagnostics; lenient mode installs the rest.
|
||||
4. Combinators and nesting rejected, so every web-derived stylesheet needs manual flattening - evidence selectors.zi:183-186, README.md:57-58 - fix: accept and flatten descendant/child combinators into the existing flat rule model - files: packages/css/src/parser/selectors.zi, src/css_sheet.zi - test: `.card .title { color }` matches a Text.title inside a Card class in css_parse_behavior.
|
||||
5. No calc()/min()/clamp() and no % lengths natively - evidence README.md:89-95,119-120 - fix: evaluate these functions over px/rem at install time - files: packages/css/src/parser/values.zi, src/css_sheet.zi - test: `padding: min(16px, 4rem)` and `width: calc(100% - 32px)` parse and install.
|
||||
6. Hand-computed Rectangle math dominates app code (853-line dashboard) - evidence dashboard.zi:206-244,301-306 - fix: make measured auto-stacking Layout the documented default and port examples to it - files: kryon/src/ui/layout*, docs/HTML_TO_KRYON.md - test: rewrite DrawKpiCard with Layout.Draw; frame-inspect node bounds unchanged.
|
||||
7. Grid items require up-front heights/spans - evidence docs/HTML_TO_KRYON.md:117-118,148, responsive.zi:97 - fix: auto row heights from measured items when `.height` is unset - files: kryon/src/ui/layout (grid), examples/dashboard/previews - test: a responsive.zi variant with heightless items renders equal bounds.
|
||||
8. No one-page styling cheat sheet; docs are a 2923-line feature log - evidence docs/API.md:1-46, packages/css/README.md:49-178 - fix: add docs/STYLING.md with a supported-property matrix and a copy-paste app shell, linked from README.md:50 - files: kryon/docs/STYLING.md, kryon/README.md, packages/css/README.md - test: cross-links resolve; matrix matches the parser property list.
|
||||
9. Theme tokens and CSS do not share a vocabulary - evidence theme.zi:285-298 vs the properties.zi list, themes/catalog_light.css:12-23 - fix: expose `--space-2`, `--radius-medium`, `--accent` etc. as CSS custom properties at install - files: packages/css/src/css_sheet.zi, kryon/src/ui/theme.zi - test: dashboard styles.zi uses var(--space-3); conformance digest unchanged.
|
||||
11. No hot reload / live native preview - evidence README.md:95-103 (browser only), no watch in docs - fix: `kryon run --watch` rebuild+relaunch on source change - files: kryon/src/project/cli_linux.zi, ziran run - test: edit a label with the window open; text updates within one rebuild.
|
||||
12. font-family fallback lists silently truncate to the first family - evidence properties.zi:372-395 - fix: keep the list, resolve the first installed family, warn when none match - files: packages/css/src/parser/properties.zi, kryon/src/ui/text_typeface.zi - test: a sheet with `"Geist", Inter` uses Inter when Geist is absent and reports the unresolved family.
|
||||
+114
-59
@@ -322,6 +322,7 @@ Usage :: () -> s32 {
|
||||
PrintFd(1, "usage: kryon new DIR [--template NAME|SOURCE[:NAME]] [--name NAME] [--overrides FILE]\n")
|
||||
PrintFd(1, " kryon init [--template NAME|SOURCE[:NAME]] [--overrides FILE]\n")
|
||||
PrintFd(1, " kryon run|build|check [PROFILE | --profile NAME]\n")
|
||||
PrintFd(1, " kryon run [PROFILE] --png FILE.png [--width PX] [--height PX] [--theme light|dark]\n")
|
||||
PrintFd(1, " kryon run FILE.zx\n")
|
||||
PrintFd(1, " kryon install [--prefix DIR]\n")
|
||||
PrintFd(1, " kryon profiles\n")
|
||||
@@ -379,6 +380,41 @@ PreviewWidthError :: (widths: string) -> string {
|
||||
return ""
|
||||
}
|
||||
|
||||
// Reads FLAG VALUE pairs from argument FIRST on: --theme, --width,
|
||||
// --height, OUTPUT_FLAG and, for previews, --profile; each at most once.
|
||||
ParseCaptureFlags :: (command_line: string, first: s32, output_flag: string, options: *PreviewOptions) -> bool {
|
||||
count := ArgumentCount(command_line)
|
||||
index := first
|
||||
while index < count {
|
||||
flag := ArgumentAt(command_line, index)
|
||||
value := ArgumentAt(command_line, index + 1)
|
||||
if value == "" || ProjectStarts(value, "--") { return false }
|
||||
if flag == "--theme" && options.theme == "" { options.theme = value }
|
||||
else if flag == "--width" && options.width == "" { options.width = value }
|
||||
else if flag == "--height" && options.height == "" { options.height = value }
|
||||
else if flag == output_flag && options.output == "" { options.output = value }
|
||||
else if flag == "--profile" && output_flag == "--output" && options.profile == "" { options.profile = value }
|
||||
else { return false }
|
||||
index += 2
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Theme, height and width errors shared by previews and shots, or "".
|
||||
CaptureSizeError :: (options: PreviewOptions, verb: string) -> string {
|
||||
if options.theme != "light" && options.theme != "dark" {
|
||||
return ifx verb == "preview" then "preview --theme must be light or dark" else "run --theme must be light or dark"
|
||||
}
|
||||
if PreviewDimension(options.height) == 0 {
|
||||
return ifx verb == "preview" then "preview --height must be an integer from 1 through 4096" else "run --height must be an integer from 1 through 4096"
|
||||
}
|
||||
width_error := PreviewWidthError(options.width)
|
||||
if width_error != "" && verb != "preview" {
|
||||
return "run --width must list integers from 1 through 4096 separated by commas"
|
||||
}
|
||||
return width_error
|
||||
}
|
||||
|
||||
ParsePreview :: (command_line: string) -> PreviewOptions {
|
||||
options: PreviewOptions
|
||||
options.fixture = ArgumentAt(command_line, 2)
|
||||
@@ -386,40 +422,39 @@ ParsePreview :: (command_line: string) -> PreviewOptions {
|
||||
options.error = "preview requires a fixture name (letters, digits, _ or -); see kryon preview --help"
|
||||
return options
|
||||
}
|
||||
count := ArgumentCount(command_line)
|
||||
index: s32 = 3
|
||||
while index < count {
|
||||
flag := ArgumentAt(command_line, index)
|
||||
value := ArgumentAt(command_line, index + 1)
|
||||
if value == "" || ProjectStarts(value, "--") {
|
||||
options.error = "preview options need values; see kryon preview --help"
|
||||
return options
|
||||
}
|
||||
if flag == "--theme" && options.theme == "" { options.theme = value }
|
||||
else if flag == "--width" && options.width == "" { options.width = value }
|
||||
else if flag == "--height" && options.height == "" { options.height = value }
|
||||
else if flag == "--output" && options.output == "" { options.output = value }
|
||||
else if flag == "--profile" && options.profile == "" { options.profile = value }
|
||||
else {
|
||||
options.error = "unknown or repeated preview option; see kryon preview --help"
|
||||
return options
|
||||
}
|
||||
index += 2
|
||||
}
|
||||
if options.theme != "light" && options.theme != "dark" {
|
||||
options.error = "preview --theme must be light or dark"
|
||||
} else if PreviewDimension(options.height) == 0 {
|
||||
options.error = "preview --height must be an integer from 1 through 4096"
|
||||
if !ParseCaptureFlags(command_line, 3, "--output", *options) {
|
||||
options.error = "unknown, repeated or empty preview option; see kryon preview --help"
|
||||
} else if options.output == "" {
|
||||
options.error = "preview needs --output FILE.png or PREFIX"
|
||||
options.error = CaptureSizeError(options, "preview")
|
||||
if options.error == "" { options.error = "preview needs --output FILE.png or PREFIX" }
|
||||
} else if options.profile != "" && !ProjectNameValid(options.profile) {
|
||||
options.error = "invalid preview profile name; use kryon profiles to list profiles"
|
||||
} else {
|
||||
options.error = PreviewWidthError(options.width)
|
||||
options.error = CaptureSizeError(options, "preview")
|
||||
}
|
||||
return options
|
||||
}
|
||||
|
||||
// kryon run [PROFILE] --png FILE.png [--width PX] [--height PX] [--theme
|
||||
// light|dark]: the app's own entry, rendered offscreen. 960x600 light by
|
||||
// default.
|
||||
ParseShot :: (command_line: string, first: s32) -> PreviewOptions {
|
||||
options: PreviewOptions
|
||||
if !ParseCaptureFlags(command_line, first, "--png", *options) {
|
||||
options.error = "unknown, repeated or empty run option; use kryon run [PROFILE] --png FILE.png [--width PX] [--height PX] [--theme light|dark]"
|
||||
return options
|
||||
}
|
||||
if options.output == "" {
|
||||
options.error = "kryon run --width, --height and --theme need --png FILE.png"
|
||||
return options
|
||||
}
|
||||
if options.width == "" { options.width = "960" }
|
||||
if options.height == "" { options.height = "600" }
|
||||
if options.theme == "" { options.theme = "light" }
|
||||
options.error = CaptureSizeError(options, "run")
|
||||
return options
|
||||
}
|
||||
|
||||
PreviewPngSizeMatches :: (path: *u8, width: s32, height: s32) -> bool {
|
||||
header: [24]u8
|
||||
fd := RawOpen(path, 0)
|
||||
@@ -447,7 +482,8 @@ PreviewLockDirectory :: (path: *u8) -> *void {
|
||||
return directory
|
||||
}
|
||||
|
||||
PreviewCapture :: (prefix: string, width: string, height: string, args: []string) -> s32 {
|
||||
// FAILURE reports a failed build or render.
|
||||
PreviewCapture :: (prefix: string, width: string, height: string, args: []string, failure: string) -> s32 {
|
||||
png_bytes: [4096]u8
|
||||
tree_bytes: [4096]u8
|
||||
parent_bytes: [4096]u8
|
||||
@@ -491,17 +527,13 @@ PreviewCapture :: (prefix: string, width: string, height: string, args: []string
|
||||
}
|
||||
// Build under the preview lock on the first capture only.
|
||||
if args[5] == "build" {
|
||||
if RunChild(args) != 0 {
|
||||
return Error("preview build or render failed; see diagnostics above, add previews to [package] module_roots and export Frame from the fixture")
|
||||
}
|
||||
if RunChild(args) != 0 { return Error(failure) }
|
||||
args[5] = "run-built"
|
||||
}
|
||||
if RunChild(args) != 0 {
|
||||
return Error("preview build or render failed; see diagnostics above, add previews to [package] module_roots and export Frame from the fixture")
|
||||
}
|
||||
if RunChild(args) != 0 { return Error(failure) }
|
||||
if !Exists(staged_tree) || !PreviewPngSizeMatches(*staged_png_bytes[0],
|
||||
PreviewDimension(width), PreviewDimension(height)) {
|
||||
return Error("preview did not produce a widget tree and PNG of the requested size; export Frame from the fixture")
|
||||
return Error("no widget tree and PNG of the requested size were drawn; export Frame from the entry")
|
||||
}
|
||||
if !CString(parent, parent_bytes[:]) { return Error("preview output directory is too long") }
|
||||
publish_lock := PreviewLockDirectory(*parent_bytes[0])
|
||||
@@ -518,32 +550,42 @@ PreviewCapture :: (prefix: string, width: string, height: string, args: []string
|
||||
return 0
|
||||
}
|
||||
|
||||
// A preview builds previews/FIXTURE.zi into build/preview/PROFILE/FIXTURE;
|
||||
// a shot (no fixture) builds the entry into build/shot/PROFILE.
|
||||
PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string) -> s32 {
|
||||
prefix := options.output
|
||||
if prefix.count >= 4 && prefix[prefix.count - 4:prefix.count] == ".png" {
|
||||
prefix = prefix[0:prefix.count - 4]
|
||||
}
|
||||
if prefix == "" || prefix[prefix.count - 1] == #char "/" {
|
||||
return Error("preview --output must name a file or prefix")
|
||||
return Error("the capture output must name a file or prefix")
|
||||
}
|
||||
area := ifx options.fixture == "" then "build/shot" else "build/preview"
|
||||
failure := "preview build or render failed; see diagnostics above, add previews to [package] module_roots and export Frame from the fixture"
|
||||
if options.fixture == "" {
|
||||
failure = "run --png build or render failed; see diagnostics above and export Frame from the project entry"
|
||||
}
|
||||
|
||||
build_root_bytes: [4096]u8
|
||||
build_path_bytes: [4096]u8
|
||||
build_option_bytes: [4096]u8
|
||||
build_root := Join("build/preview/", profile.name, build_root_bytes[:])
|
||||
build_path := Join(build_root, "/", build_path_bytes[:])
|
||||
if build_root == "" || build_path == "" { return Error("preview build directory is too long") }
|
||||
build_root = Join(build_path, options.fixture, build_root_bytes[:])
|
||||
if build_root == "" { return Error("preview build directory is too long") }
|
||||
build_root := Join(Join(area, "/", build_path_bytes[:]), profile.name, build_root_bytes[:])
|
||||
if build_root == "" { return Error("capture build directory is too long") }
|
||||
if options.fixture != "" {
|
||||
build_path := Join(build_root, "/", build_path_bytes[:])
|
||||
if build_path == "" { return Error("capture build directory is too long") }
|
||||
build_root = Join(build_path, options.fixture, build_root_bytes[:])
|
||||
if build_root == "" { return Error("capture build directory is too long") }
|
||||
}
|
||||
args[5] = "build"
|
||||
args[22] = Join("PROJECT_BUILD_DIR=", build_root, build_option_bytes[:])
|
||||
args[23] = "PROJECT_PROGRAM=" // Bind Frame even if the fixture declares a main.
|
||||
if args[22] == "" { return Error("preview build directory is too long") }
|
||||
if args[22] == "" { return Error("capture build directory is too long") }
|
||||
mkdir: [4]string = .["mkdir", "-p", "--", build_root]
|
||||
if RunChild(mkdir[:]) != 0 { return Error("cannot create the preview build directory") }
|
||||
unused CString("build/preview", build_path_bytes[:])
|
||||
if RunChild(mkdir[:]) != 0 { return Error("cannot create the capture build directory") }
|
||||
unused CString(area, build_path_bytes[:])
|
||||
lock := PreviewLockDirectory(*build_path_bytes[0])
|
||||
if lock == null { return Error("cannot lock the preview build directory") }
|
||||
if lock == null { return Error("cannot lock the capture build directory") }
|
||||
defer { RawCloseDirectory(lock) }
|
||||
|
||||
display_env: [11]string = .["DISPLAY", "WAYLAND_DISPLAY", "XAUTHORITY", "GDK_DISPLAY",
|
||||
@@ -552,7 +594,7 @@ PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string)
|
||||
for name: display_env {
|
||||
key: [64]u8
|
||||
if !CString(name, key[:]) || RawUnsetenv(*key[0]) != 0 {
|
||||
return Error("cannot isolate preview from the desktop session")
|
||||
return Error("cannot isolate the capture from the desktop session")
|
||||
}
|
||||
}
|
||||
if !SetEnvironment("HARMONY_DESKTOP_RECOVERY", "0") ||
|
||||
@@ -565,7 +607,7 @@ PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string)
|
||||
}
|
||||
position: s32 = 0
|
||||
width := NextPreviewWidth(options.width, *position)
|
||||
if position > options.width.count { return PreviewCapture(prefix, width, options.height, args) }
|
||||
if position > options.width.count { return PreviewCapture(prefix, width, options.height, args, failure) }
|
||||
stem_bytes: [4096]u8
|
||||
stem := Join(prefix, "-", stem_bytes[:])
|
||||
if stem == "" { return Error("preview output path is too long") }
|
||||
@@ -573,7 +615,7 @@ PreviewRun :: (options: PreviewOptions, profile: ProjectProfile, args: []string)
|
||||
sized_bytes: [4096]u8
|
||||
sized_prefix := Join(stem, width, sized_bytes[:])
|
||||
if sized_prefix == "" { return Error("preview output path is too long") }
|
||||
status := PreviewCapture(sized_prefix, width, options.height, args)
|
||||
status := PreviewCapture(sized_prefix, width, options.height, args, failure)
|
||||
if status != 0 { return status }
|
||||
if position > options.width.count { break }
|
||||
width = NextPreviewWidth(options.width, *position)
|
||||
@@ -733,26 +775,30 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
}
|
||||
profile_name: string = ""
|
||||
option: string = ArgumentAt(command_line, 2)
|
||||
// The first argument after the profile; only run takes more (--png ...).
|
||||
rest: s32 = 2
|
||||
if verb == "preview" {
|
||||
profile_name = preview.profile
|
||||
rest = ArgumentCount(command_line)
|
||||
} else if option == "--profile" {
|
||||
profile_name = ArgumentAt(command_line, 3)
|
||||
if profile_name == "" || ArgumentAt(command_line, 4) != "" {
|
||||
return Error("expected exactly one profile name")
|
||||
}
|
||||
if profile_name == "" { return Error("expected exactly one profile name") }
|
||||
rest = 4
|
||||
} else if ProjectStarts(option, "--profile=") {
|
||||
profile_name = option[10:cast(s32)option.count]
|
||||
if profile_name == "" || ArgumentAt(command_line, 3) != "" {
|
||||
return Error("expected exactly one profile name")
|
||||
}
|
||||
if profile_name == "" { return Error("expected exactly one profile name") }
|
||||
rest = 3
|
||||
} else if option != "" && option[0] != cast(u8)45 && verb != "profiles" {
|
||||
// kryon run desktop
|
||||
profile_name = option
|
||||
if ArgumentAt(command_line, 3) != "" {
|
||||
return Error("expected exactly one profile name")
|
||||
}
|
||||
} else if option != "" {
|
||||
return Error("unknown option")
|
||||
rest = 3
|
||||
}
|
||||
shot: PreviewOptions
|
||||
if verb == "run" && ArgumentAt(command_line, rest) != "" {
|
||||
shot = ParseShot(command_line, rest)
|
||||
if shot.error != "" { return Error(shot.error) }
|
||||
} else if ArgumentAt(command_line, rest) != "" {
|
||||
return Error(ifx rest == 2 then "unknown option" else "expected exactly one profile name")
|
||||
}
|
||||
|
||||
name_env_bytes: [128]u8
|
||||
@@ -778,7 +824,7 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
profile_name = config.install.profile
|
||||
}
|
||||
if profile_name == "" {
|
||||
if verb == "run" && config.profile_count > 1 && RawIsTty(0) != 0 {
|
||||
if verb == "run" && shot.output == "" && config.profile_count > 1 && RawIsTty(0) != 0 {
|
||||
chosen_profile: s32 = ChooseProfile(config)
|
||||
if chosen_profile < 0 { return Error("invalid profile selection") }
|
||||
profile_name = config.profiles[chosen_profile].name
|
||||
@@ -830,6 +876,14 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
// A preview uses the standard frame host even if the app owns its window.
|
||||
profile.host = ""
|
||||
}
|
||||
if shot.output != "" {
|
||||
// The desktop renderer draws the PNG offscreen, for pixmap profiles too.
|
||||
if profile.codegen != "c99" || (profile.backend != "desktop" && profile.backend != "pixmap") {
|
||||
return Error("run --png needs a desktop or pixmap C99 profile; name one, as in kryon run shot --png FILE.png")
|
||||
}
|
||||
profile.backend = "desktop"
|
||||
profile.host = ""
|
||||
}
|
||||
if profile.backend == "android" {
|
||||
if verb == "install" {
|
||||
return Error("android profiles ship as packages; use kryon build --profile android")
|
||||
@@ -917,6 +971,7 @@ main :: (argc: s32, argv: **u8) -> s32 {
|
||||
at += 1
|
||||
}
|
||||
if verb == "preview" { return PreviewRun(preview, profile, args[:]) }
|
||||
if shot.output != "" { return PreviewRun(shot, profile, args[:]) }
|
||||
return Execute(args[0:22])
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ def run(arguments, project, expected=0):
|
||||
|
||||
def check_ui_map(project):
|
||||
catalog = json.loads((ROOT / 'docs/ui-map.json').read_text())
|
||||
assert (catalog['version'], catalog['backend']) == (1, 'native')
|
||||
assert (catalog['version'], catalog['backend']) == (2, 'native')
|
||||
selectors = [selector for entry in catalog['elements'] for selector in entry['html']]
|
||||
assert len(selectors) == len(set(selectors)), 'duplicate HTML selector in UI map'
|
||||
exports = tomllib.loads((ROOT / 'ziran.toml').read_text())['exports']
|
||||
@@ -185,8 +185,12 @@ def main():
|
||||
scratch.mkdir(parents=True, exist_ok=True)
|
||||
with tempfile.TemporaryDirectory(prefix='project-entry-', dir=scratch) as temporary:
|
||||
project = Path(temporary)
|
||||
(project / 'ziran.local.toml').write_text(
|
||||
f'[overrides]\nkryon = "{ROOT}"\nziran = "{ZIRAN_ROOT}"\n')
|
||||
# Checked packages lock only against the exact toolchain Kryon pins;
|
||||
# this checkout still supplies the Kryon source under test.
|
||||
(project / 'ziran.local.toml').write_text(f'[overrides]\nkryon = "{ROOT}"\n')
|
||||
toolchain = tomllib.loads((ROOT / 'ziran.toml').read_text())['toolchain']
|
||||
revision = subprocess.check_output(['git', 'rev-parse', '--verify', 'HEAD'],
|
||||
cwd=ROOT, text=True).strip()
|
||||
for entry, package_entry in [('app.zi', 'app.zi'), ('button.zi', 'button.zi'),
|
||||
('button.zi', 'main.zi')]:
|
||||
manifest = f'''[package]
|
||||
@@ -195,11 +199,11 @@ entry = "{package_entry}"
|
||||
module_roots = ["."]
|
||||
tool = "kryon"
|
||||
[toolchain]
|
||||
git = "https://github.com/ziranlang/ziran.git"
|
||||
ref = "master"
|
||||
git = "{toolchain['git']}"
|
||||
ref = "{toolchain['ref']}"
|
||||
[dependencies.kryon]
|
||||
git = "https://github.com/kryonlabs/kryon.git"
|
||||
ref = "master"
|
||||
git = "https://git.waozi.xyz/kryonlabs/kryon.git"
|
||||
ref = "{revision}"
|
||||
[tool.kryon]
|
||||
entry = "{entry}"
|
||||
default_profile = "native"
|
||||
|
||||
@@ -0,0 +1,131 @@
|
||||
// `kryon run shot --png`: a whole app rendered offscreen at any size, with
|
||||
// no preview fixture and no display. The test shoots a scratch copy of
|
||||
// examples/dashboard at two sizes and checks each PNG's dimensions, then
|
||||
// edits the copy's stylesheet and checks that the picture changes.
|
||||
//
|
||||
// Run from the Kryon root: make shot-test (ZIRAN_BIN names the ziran
|
||||
// command; default ziran).
|
||||
#import "std/process_run_linux"
|
||||
#import "std/file_tree_linux"
|
||||
#import "std/file"
|
||||
#import "std/text_tools"
|
||||
#import "std/environment_linux"
|
||||
using Vectors :: #import "vec";
|
||||
|
||||
failures: s32;
|
||||
|
||||
Expect :: (ok: bool, what: string) {
|
||||
if ok { return }
|
||||
failures += 1
|
||||
print("shot: FAIL %\n", what)
|
||||
}
|
||||
|
||||
// Runs ARGUMENTS in DIRECTORY with their output in LOG.
|
||||
Run :: (arguments: []string, directory: string, log: string) -> bool {
|
||||
options: ProcessOptions = .{.arguments = arguments, .directory = directory,
|
||||
.output_path = log, .merge_error = true}
|
||||
run: ProcessRun
|
||||
return RunProcess(options, *run) && run.code == 0
|
||||
}
|
||||
|
||||
// The example's own lock pins a published Kryon; the copy's
|
||||
// ziran.local.toml points kryon at this checkout (and ziran at the running
|
||||
// toolchain) instead.
|
||||
PrepareCopy :: (ziran: string, source: string, copy: string) -> bool {
|
||||
if !CreateDirectories(copy) { return false }
|
||||
entries: Vec(string)
|
||||
if !ListDirectory(source, *entries) { return false }
|
||||
copied := true
|
||||
for entry: entries {
|
||||
if entry == "build" || entry == "ziran.local.toml" { continue }
|
||||
from := JoinPath(source, entry)
|
||||
to := JoinPath(copy, entry)
|
||||
copied = copied && (ifx IsDirectory(from) then CopyTree(from, to) else CopyFile(from, to))
|
||||
}
|
||||
FreeDirectoryNames(*entries)
|
||||
overrides: Vec(u8)
|
||||
BuilderPrint(*overrides, "[overrides]\nkryon = \"%\"\n", WorkingDirectory())
|
||||
tool_suffix := "/build/bin/ziran"
|
||||
if TextHasSuffix(ziran, tool_suffix) {
|
||||
BuilderPrint(*overrides, "ziran = \"%\"\n", ziran[:ziran.count - tool_suffix.count])
|
||||
}
|
||||
return copied && WriteEntireFile(JoinPath(copy, "ziran.local.toml"), BuilderFinish(overrides))
|
||||
}
|
||||
|
||||
// One `kryon run shot --png` of the app in DIRECTORY, through the same
|
||||
// `ziran tool kryon` the kryon front door runs.
|
||||
Shoot :: (ziran: string, directory: string, png: string, width: string, height: string,
|
||||
theme: string, log: string) -> bool {
|
||||
arguments: [13]string = .[ziran, "tool", "kryon", "run", "shot", "--png", png,
|
||||
"--width", width, "--height", height, "--theme", theme]
|
||||
return Run(arguments[:], directory, log)
|
||||
}
|
||||
|
||||
// A `kryon run` that must fail and name its fix: its log holds EXPECTED.
|
||||
Refused :: (ziran: string, directory: string, arguments: []string, log: string, expected: string) -> bool {
|
||||
command: [8]string = .[ziran, "tool", "kryon", "", "", "", "", ""]
|
||||
if arguments.count > 5 { return false }
|
||||
for i: 0..arguments.count - 1 { command[3 + i] = arguments[i] }
|
||||
if Run(command[0:3 + arguments.count], directory, log) { return false }
|
||||
text, ok := ReadEntireFile(log)
|
||||
return ok && TextFind(text, expected) >= 0
|
||||
}
|
||||
|
||||
// The width and height a PNG's header declares, or 0, 0.
|
||||
PngSize :: (path: string) -> (width: u32, height: u32) {
|
||||
bytes, ok := ReadEntireFile(path)
|
||||
signature: [8]u8 = .[137, 80, 78, 71, 13, 10, 26, 10]
|
||||
if !ok || bytes.count < 24 || bytes[12:16] != "IHDR" { return 0, 0 }
|
||||
for i: 0..7 { if bytes[i] != signature[i] { return 0, 0 } }
|
||||
width: u32 = 0
|
||||
height: u32 = 0
|
||||
for i: 0..3 {
|
||||
width = (width << 8) | cast(u32)bytes[16 + i]
|
||||
height = (height << 8) | cast(u32)bytes[20 + i]
|
||||
}
|
||||
return width, height
|
||||
}
|
||||
|
||||
main :: () -> s32 {
|
||||
ziran := EnvironmentText("ZIRAN_BIN")
|
||||
if ziran == "" { ziran = "ziran" }
|
||||
root := JoinPath(WorkingDirectory(), "build/test/shot")
|
||||
copy := JoinPath(root, "dashboard")
|
||||
log := JoinPath(root, "shot.log")
|
||||
if !PrepareCopy(ziran, "examples/dashboard", copy) {
|
||||
print("shot: FAIL cannot copy examples/dashboard into %\n", copy)
|
||||
return 1
|
||||
}
|
||||
|
||||
wide := JoinPath(root, "wide.png")
|
||||
narrow := JoinPath(root, "narrow.png")
|
||||
Expect(Shoot(ziran, copy, wide, "1280", "720", "light", log), "shoot 1280x720; see build/test/shot/shot.log")
|
||||
wide_width, wide_height := PngSize(wide)
|
||||
Expect(wide_width == 1280 && wide_height == 720, "the wide shot is 1280x720")
|
||||
Expect(IsFile(JoinPath(root, "wide.json")), "the wide shot writes its widget tree beside the PNG")
|
||||
Expect(Shoot(ziran, copy, narrow, "390", "844", "dark", log), "shoot 390x844 dark; see build/test/shot/shot.log")
|
||||
narrow_width, narrow_height := PngSize(narrow)
|
||||
Expect(narrow_width == 390 && narrow_height == 844, "the narrow shot is 390x844")
|
||||
|
||||
no_png: [4]string = .["run", "shot", "--width", "800"]
|
||||
Expect(Refused(ziran, copy, no_png[:], log, "need --png FILE.png"), "sizes without --png are refused")
|
||||
web: [4]string = .["run", "web", "--png", "web.png"]
|
||||
Expect(Refused(ziran, copy, web[:], log, "needs a desktop or pixmap C99 profile"), "a canvas profile is refused")
|
||||
|
||||
styles := JoinPath(copy, "src/styles.zi")
|
||||
text, read := ReadEntireFile(styles)
|
||||
card := "--surface-card: #ffffff;"
|
||||
Expect(read && TextFind(text, card) >= 0, "the dashboard stylesheet sets --surface-card")
|
||||
edited := TextReplace(text, card, "--surface-card: #ffd8d0;")
|
||||
Expect(WriteEntireFile(styles, edited), "edit the copy's stylesheet")
|
||||
restyled := JoinPath(root, "restyled.png")
|
||||
Expect(Shoot(ziran, copy, restyled, "1280", "720", "light", log), "shoot after the style edit")
|
||||
before, before_ok := ReadEntireFile(wide)
|
||||
after, after_ok := ReadEntireFile(restyled)
|
||||
Expect(before_ok && after_ok && before.count > 0 && after.count > 0, "both shots were written")
|
||||
Expect(before != after, "the style edit changes the shot")
|
||||
|
||||
if failures > 0 { return 1 }
|
||||
print("shot: dashboard at 1280x720 and 390x844, light and dark, restyled; all checks passed\n")
|
||||
return 0
|
||||
}
|
||||
Reference in new issue
Block a user