Use public Kryon widgets for hosted Auth cards

This commit is contained in:
waozi committed 2026-11-16 03:25:59 -03:00
1 parent 8c8d0584f1
commit 2a575a8828
6 files changed
+175 -86

No files matched your search

+4 -10
View File
@@ -1,12 +1,6 @@
ZIRAN ?= ziran
LOCKED := $(if $(wildcard ziran.local.toml),,--locked)
STD = $(shell $(ZIRAN) pkg path ziran $(LOCKED))/std
CRYPTO = $(shell $(ZIRAN) pkg path crypto $(LOCKED))
KRYON = $(shell $(ZIRAN) pkg path kryon $(LOCKED))
MINGCUTE = $(shell $(ZIRAN) pkg path mingcute $(LOCKED))
PATHS = --module-path src --module-path crypto=$(CRYPTO)/src --module-path $(STD)
UI_PATHS = --module-path kryon=$(KRYON)/src/backend --module-path kryon=$(KRYON)/src/ui \
--module-path $(KRYON)/src/ui --module-path $(MINGCUTE)/src --define KRYON_HOSTED_UI
PROJECT = --project $(LOCKED)
.PHONY: test app
# RFC 6238 codes for SHA-1, SHA-256 and SHA-512, RFC 4648 Base32 and the
@@ -14,14 +8,14 @@ UI_PATHS = --module-path kryon=$(KRYON)/src/backend --module-path kryon=$(KRYON)
test: app
mkdir -p build
for name in totp exports; do \
$(ZIRAN) bundle --root . $(PATHS) --entry $${name}_test:Run -o build/$$name.zx tests/$${name}_test.zi && \
$(ZIRAN) bundle $(PROJECT) --root . --entry $${name}_test:Run -o build/$$name.zx tests/$${name}_test.zi && \
test "$$($(ZIRAN) run build/$$name.zx)" = 0 || exit 1; \
done
$(ZIRAN) bundle --root . $(PATHS) $(UI_PATHS) --module-path tests --module-path $(KRYON)/src/backend --bind button_widget:ButtonHostedHost=card_host:ButtonHostedHost --bind box_widget:BoxHostedHost=card_host:BoxHostedHost --bind text_widget:TextHostedHost=card_host:TextHostedHost --bind app_context:AppNowHost=card_host:AppNowHost --bind app_context:AppDarkHost=card_host:AppDarkHost --bind app_context:ClipboardCopyHost=card_host:ClipboardCopyHost --entry card_test:Run -o build/card.zx tests/card_test.zi
$(ZIRAN) bundle $(PROJECT) --root . --define KRYON_HOSTED_UI --bind-host card_host --entry card_test:Run -o build/card.zx tests/card_test.zi
test "$$($(ZIRAN) run build/card.zx)" = 0
@echo 'Auth: RFC 6238 codes, Base32, links and authenticator exports passed'
# The Auth app as a hosted Kryon bundle, as Werkzeug packs it.
app:
mkdir -p build
$(ZIRAN) bundle --root . $(PATHS) $(UI_PATHS) --entry auth:Main -o build/auth.zx src/auth.zi
$(ZIRAN) bundle $(PROJECT) --root . --define KRYON_HOSTED_UI --entry auth:Main -o build/auth.zx src/auth.zi
+38 -43
View File
@@ -1,30 +1,25 @@
TextField :: #import "kryon/text_field";
Scroll :: #import "kryon/scroll";
Box :: #import "kryon/box";
Text :: #import "kryon/text";
Button :: #import "kryon/button";
// Auth: two-factor sign-in codes. Each account is a synced record holding
// its otpauth link, so it follows the owner's Werkzeug account to their
// other devices; secrets are never shown again after adding.
#import "session"
#import "geometry"
#import "drawing_props"
#import "text_props"
#import "text_align"
#import "text_widget"
#import "text_input_props"
#import "text_field_widget"
#import "button_props"
#import "button_widget"
#import "control_props"
#import "box_props"
#import "box_widget"
#import "scroll_props"
#import "scroll_widget"
#import "tree"
#import "text_buffer"
#import "number_text"
#import "kryon/session"
#import "kryon/geometry"
#import "kryon/drawing_props"
#import "kryon/text_align"
#import "kryon/control_props"
#import "kryon/tree"
#import "std/text_buffer"
#import "std/number_text"
#import "kryon/app_context"
#import "kryon/app_protocol"
#import "totp"
#import "exports"
Icon :: #import "mingcute_regular_shield";
Edit :: #import "mingcute_regular_edit_2";
Icon :: #import "mingcute/mingcute_regular_shield";
Edit :: #import "mingcute/mingcute_regular_edit_2";
ACCOUNT_LIMIT :: 128
LIST_LIMIT :: 65536
@@ -320,21 +315,21 @@ GroupedCode :: (code: string, output: []u8) -> string {
}
Label :: (key: u64, text: string, bounds: Rectangle, font: s32) {
Text(session, TextProps.{.key = key, .bounds = bounds, .text = text, .font = font,
.wrap = TextWrap.TextWrapEllipsis})
Text.Draw(session, Text.Props.{.key = key, .bounds = bounds, .text = text, .size = font,
.wrap = Text.Wrap.TextWrapEllipsis})
}
Action :: (id: s32, label: string, bounds: Rectangle, accent: bool) -> bool {
props := ButtonProps.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
props := Button.Props.{.key = cast(u64)id, .id = id, .bounds = bounds, .label = label,
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
if accent {
props.tone = ButtonTone.ButtonToneAccent
props.emphasis = ButtonEmphasis.ButtonEmphasisFilled
}
return Button(session, props) != 0
return Button.Draw(session, props) != 0
}
ApplyEdit :: (buffer: []u8, edit: TextFieldEdit) {
ApplyEdit :: (buffer: []u8, edit: TextField.Edit) {
if !edit.changed {
return
}
@@ -378,9 +373,9 @@ ApplyEdit :: (buffer: []u8, edit: TextFieldEdit) {
Field :: (id: s32, label: string, placeholder: string, buffer: []u8, bounds: Rectangle, secure: bool) {
state := *fields[id]
edit: TextFieldEdit
edit: TextField.Edit
{
props := TextFieldProps.{.key = cast(u64)(500 + id), .focus_id = 500 + id, .bounds = bounds,
props := TextField.Props.{.key = cast(u64)(500 + id), .focus_id = 500 + id, .bounds = bounds,
.label = label, .placeholder = placeholder, .value = TextUntilNul(buffer),
.cursor = state.cursor, .anchor = state.anchor, .scroll_x = state.scroll_x,
.focused = focused == id, .max_bytes = cast(s32)buffer.count - 1,
@@ -392,7 +387,7 @@ Field :: (id: s32, label: string, placeholder: string, buffer: []u8, bounds: Rec
if focused == id {
props.input = AppFieldInput()
}
result := TextField(session, props)
result := TextField.Draw(session, props)
state.cursor = result.cursor
state.anchor = result.anchor
state.scroll_x = result.scroll_x
@@ -442,9 +437,9 @@ DrawRow :: (index: s32, x: float32, y: float32, inner: float32, row: float32) {
fraction := cast(float32)(remaining / period)
surface := ifx AppDark() then Color.{28, 28, 28, 255} else Color.{242, 240, 245, 255}
progress := ifx fraction > 0.5 then Color.{159, 53, 232, 255} else Color.{238, 145, 48, 255}
Box(session, BoxProps.{.key = cast(u64)(1000 + index), .bounds = Rectangle.{x, y, inner, row - 8.0},
Box.Draw(session, Box.Props.{.key = cast(u64)(1000 + index), .bounds = Rectangle.{x, y, inner, row - 8.0},
.fill = surface, .radius = 4.0})
Box(session, BoxProps.{.key = cast(u64)(7000 + index),
Box.Draw(session, Box.Props.{.key = cast(u64)(7000 + index),
.bounds = Rectangle.{x, y, inner * fraction, 3.0}, .fill = progress})
title := TextUntilNul(account.issuer[:])
subtitle := TextUntilNul(account.name[:])
@@ -454,9 +449,9 @@ DrawRow :: (index: s32, x: float32, y: float32, inner: float32, row: float32) {
}
text_width := inner - 64.0
Label(cast(u64)(2000 + index), title, Rectangle.{x + 20.0, y + 14.0, text_width, 22.0}, 16)
Text(session, TextProps.{.key = cast(u64)(3000 + index), .text = subtitle,
.bounds = Rectangle.{x + 20.0, y + 38.0, text_width, 18.0}, .font = 12,
.disabled = true, .wrap = TextWrap.TextWrapEllipsis})
Text.Draw(session, Text.Props.{.key = cast(u64)(3000 + index), .text = subtitle,
.bounds = Rectangle.{x + 20.0, y + 38.0, text_width, 18.0}, .size = 12,
.disabled = true, .wrap = Text.Wrap.TextWrapEllipsis})
code := Code(index, cast(s64)now)
current_text: [16]u8
next_text: [16]u8
@@ -464,23 +459,23 @@ DrawRow :: (index: s32, x: float32, y: float32, inner: float32, row: float32) {
next := GroupedCode(TextUntilNul(codes[index].next[:]), next_text[:])
code_width := (inner - 40.0) * 0.6
code_bounds := Rectangle.{x + 20.0, y + 70.0, code_width, 38.0}
if Button(session, ButtonProps.{.key = cast(u64)(4000 + index), .id = 4000 + index,
if Button.Draw(session, Button.Props.{.key = cast(u64)(4000 + index), .id = 4000 + index,
.bounds = Rectangle.{x, y, inner, row - 8.0}, .label = "Copy current code", .invisible = true}) != 0 {
unused ClipboardCopy(code, CODE_CLEAR_SECONDS)
}
Label(cast(u64)(8000 + index), current, code_bounds, 24)
preview := Rectangle.{x + 20.0 + code_width, y + 72.0, inner - 40.0 - code_width, 16.0}
Text(session, TextProps.{.key = cast(u64)(5000 + index), .text = "next", .bounds = preview,
.font = 12, .disabled = true, .align = TextAlign.TextAlignEnd})
Text.Draw(session, Text.Props.{.key = cast(u64)(5000 + index), .text = "next", .bounds = preview,
.size = 12, .disabled = true, .align = TextAlign.TextAlignEnd})
preview.y += 18.0
preview.height = 20.0
Text(session, TextProps.{.key = cast(u64)(9000 + index), .text = next, .bounds = preview,
.font = 14, .disabled = true, .align = TextAlign.TextAlignEnd})
edit := ButtonProps.{.key = cast(u64)(6000 + index), .id = 6000 + index, .label = "Edit",
Text.Draw(session, Text.Props.{.key = cast(u64)(9000 + index), .text = next, .bounds = preview,
.size = 14, .disabled = true, .align = TextAlign.TextAlignEnd})
edit := Button.Props.{.key = cast(u64)(6000 + index), .id = 6000 + index, .label = "Edit",
.bounds = Rectangle.{x + inner - 40.0, y + 10.0, 32.0, 32.0},
.icon_shape = Edit.Shape, .icon_only = true,
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisGhost}
if Button(session, edit) != 0 {
if Button.Draw(session, edit) != 0 {
OpenEdit(index)
}
}
@@ -499,7 +494,7 @@ ListView :: (area: Rectangle, left: float32, width: float32) {
Rectangle.{left, top, width, 24.0}, 14)
}
row: float32 = 136.0
scroll := Scroll(session, ScrollProps.{.key = cast(u64)12, .bounds = Rectangle.{left, top, width, height},
scroll := Scroll.Draw(session, Scroll.Props.{.key = cast(u64)12, .bounds = Rectangle.{left, top, width, height},
.content_height = cast(s32)(cast(float32)account_count * row), .scroll_offset = list_scroll,
.scale = 1.0})
list_scroll = scroll.scroll_offset
@@ -605,14 +600,14 @@ EditView :: (area: Rectangle, left: float32, width: float32) {
return
}
y += 64.0
remove := ButtonProps.{.key = cast(u64)43, .id = 43, .bounds = Rectangle.{left, y, width, 40.0},
remove := Button.Props.{.key = cast(u64)43, .id = 43, .bounds = Rectangle.{left, y, width, 40.0},
.label = ifx remove_pending then "Tap again to remove" else "Remove account",
.tone = ButtonTone.ButtonToneNeutral, .emphasis = ButtonEmphasis.ButtonEmphasisSoft}
if remove_pending {
remove.tone = ButtonTone.ButtonToneDanger
remove.emphasis = ButtonEmphasis.ButtonEmphasisFilled
}
if Button(session, remove) == 0 {
if Button.Draw(session, remove) == 0 {
return
}
if !remove_pending {
+11 -11
View File
@@ -1,12 +1,12 @@
Box :: #import "kryon/box";
Text :: #import "kryon/text";
Button :: #import "kryon/button";
// In-memory hosted widgets and clipboard; all values are public fixtures.
#import "session"
#import "geometry"
#import "button_props"
#import "box_props"
#import "text_props"
#import "text_buffer"
#import "c_string"
buttons: [2]ButtonProps;
#import "kryon/session"
#import "kryon/geometry"
#import "std/text_buffer"
#import "std/c_string"
buttons: [2]Button.Props;
button_count: s32;
activated: s32;
now: float64 = 59.0;
@@ -14,14 +14,14 @@ copied: [16]u8;
clear_seconds: s32;
next: [16]u8;
#program_export
ButtonHostedHost :: (session: Session, props: ButtonProps) -> s32 {
ButtonHostedHost :: (session: Session, props: Button.Props) -> s32 {
if button_count < 2 { buttons[button_count] = props; button_count += 1 }
return ifx activated == props.id then 1 else 0
}
#program_export
BoxHostedHost :: (session: Session, props: BoxProps) -> s32 { return 0 }
BoxHostedHost :: (session: Session, props: Box.Props) -> s32 { return 0 }
#program_export
TextHostedHost :: (session: Session, props: TextProps) {
TextHostedHost :: (session: Session, props: Text.Props) {
if props.key == cast(u64)9000 { unused CopyCString(props.text, next[:]) }
}
#program_export
+3 -3
View File
@@ -1,11 +1,11 @@
Button :: #import "kryon/button";
// Public RFC 6238 fixture only. Exercise the actual card's code cache at
// rollover, skipped steps and a backwards clock; display spaces never enter it.
Auth :: #import "auth";
Host :: #import "card_host";
#import "totp"
#import "text_buffer"
#import "button_props"
#import "geometry"
#import "std/text_buffer"
#import "kryon/geometry"
#program_export
Run :: () -> s32 {
+117 -17
View File
@@ -2,39 +2,129 @@
"format": 1,
"packages": [
{
"commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
"commit": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
"dependencies": {},
"id": "p5a77c9c35110e925",
"name": "raylib",
"ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
"id": "p0dd67588478f9a3e",
"name": "libsamplerate",
"ref": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7",
"source": true,
"url": "https://github.com/raysan5/raylib.git"
"url": "https://github.com/libsndfile/libsamplerate.git"
},
{
"commit": "1be70904a388db11ef5fb3938cd2d37ab7dd8eb5",
"dependencies": {"audio": "pd258d453b63edc1f", "avif": "p872d871f84f2284f", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db", "libwebp": "p3b3c785a0e17e605", "raylib": "pcc7aa76725f2fb2f", "sdl3": "p16cd0434af3dff7b", "webp": "pa068bd09450b2a80"},
"dependency_refs": {"audio": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b", "avif": "f84c162594e518cb306bfd0ce41783ad55b6c730", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339", "raylib": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e", "sdl3": "829a65d769d935c4852f8159e964312c0957260a", "webp": "02145a00a1f0df2a111da04a75f3fef260883897"},
"id": "p0ecf74487f49020b",
"name": "kryon",
"ref": "1be70904a388db11ef5fb3938cd2d37ab7dd8eb5",
"url": "https://github.com/kryonlabs/kryon.git"
},
{
"commit": "829a65d769d935c4852f8159e964312c0957260a",
"dependencies": {},
"id": "p16cd0434af3dff7b",
"name": "sdl3",
"ref": "829a65d769d935c4852f8159e964312c0957260a",
"source": true,
"url": "https://github.com/libsdl-org/SDL.git"
},
{
"commit": "1844042d1ca751e62e61df7617dba19c98588339",
"dependencies": {},
"id": "p651a2c7a393977c0",
"id": "p3b3c785a0e17e605",
"name": "libwebp",
"ref": "1844042d1ca751e62e61df7617dba19c98588339",
"source": true,
"url": "https://github.com/webmproject/libwebp.git"
},
{
"commit": "ead3eb7aa63535447a1116ecae7bb4d712d72034",
"dependencies": {"libwebp": "p651a2c7a393977c0", "raylib": "p5a77c9c35110e925"},
"id": "p79167729f20b4a95",
"name": "kryon",
"ref": "ead3eb7aa63535447a1116ecae7bb4d712d72034",
"url": "https://github.com/kryonlabs/kryon.git"
"commit": "1aadfad932c98c069a1204261b1856f81f3bc199",
"dependencies": {},
"id": "p57c0272208aae8db",
"name": "libavif",
"ref": "1aadfad932c98c069a1204261b1856f81f3bc199",
"source": true,
"url": "https://github.com/AOMediaCodec/libavif.git"
},
{
"commit": "d11e915b5ee809b1f76b35850dda71f63ec9e09c",
"commit": "bd278217e2bac754d868b3d6502eac4257658d4b",
"dependencies": {"dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa"},
"dependency_refs": {"dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937"},
"id": "p5d7d12505a42f7b3",
"name": "av1",
"ref": "bd278217e2bac754d868b3d6502eac4257658d4b",
"url": "https://github.com/ziranlang/av1.git"
},
{
"commit": "360553150917f352e49e1beb78917370792ccaef",
"dependencies": {},
"id": "p9f270a7aabc9904e",
"id": "p69c0e968ae5735d9",
"name": "image-codec",
"ref": "360553150917f352e49e1beb78917370792ccaef",
"url": "https://github.com/ziranlang/image-codec.git"
},
{
"commit": "b141d9c45db236335351c8a4b2a14b3ade27c937",
"dependencies": {},
"id": "p74ab3cb6eb3b86fa",
"name": "libaom",
"ref": "b141d9c45db236335351c8a4b2a14b3ade27c937",
"source": true,
"url": "https://aomedia.googlesource.com/aom"
},
{
"commit": "f84c162594e518cb306bfd0ce41783ad55b6c730",
"dependencies": {"av1": "p5d7d12505a42f7b3", "dav1d": "pb24767b9eb34d961", "image_codec": "p69c0e968ae5735d9", "libaom": "p74ab3cb6eb3b86fa", "libavif": "p57c0272208aae8db"},
"dependency_refs": {"av1": "bd278217e2bac754d868b3d6502eac4257658d4b", "dav1d": "54706fc6bc0cdecab7e9593974a4039cc038fca7", "image_codec": "360553150917f352e49e1beb78917370792ccaef", "libaom": "b141d9c45db236335351c8a4b2a14b3ade27c937", "libavif": "1aadfad932c98c069a1204261b1856f81f3bc199"},
"id": "p872d871f84f2284f",
"name": "avif",
"ref": "f84c162594e518cb306bfd0ce41783ad55b6c730",
"url": "https://github.com/ziranlang/avif.git"
},
{
"commit": "02145a00a1f0df2a111da04a75f3fef260883897",
"dependencies": {"image_codec": "p69c0e968ae5735d9", "libwebp": "p3b3c785a0e17e605"},
"dependency_refs": {"image_codec": "360553150917f352e49e1beb78917370792ccaef", "libwebp": "1844042d1ca751e62e61df7617dba19c98588339"},
"id": "pa068bd09450b2a80",
"name": "webp",
"ref": "02145a00a1f0df2a111da04a75f3fef260883897",
"url": "https://github.com/ziranlang/webp.git"
},
{
"commit": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
"dependencies": {},
"id": "pb24767b9eb34d961",
"name": "dav1d",
"ref": "54706fc6bc0cdecab7e9593974a4039cc038fca7",
"source": true,
"url": "https://github.com/videolan/dav1d.git"
},
{
"commit": "944826f70779a6b6cd53f6b06a75b36f4d8a2558",
"dependencies": {},
"id": "pc23fbf455e97614d",
"name": "crypto",
"ref": "master",
"url": "https://github.com/ziranlang/crypto.git"
},
{
"commit": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
"dependencies": {},
"id": "pcc7aa76725f2fb2f",
"name": "raylib",
"ref": "fafa2cea97d0cb379d832086ba45a989fa6f9c8e",
"source": true,
"url": "https://github.com/raysan5/raylib.git"
},
{
"commit": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b",
"dependencies": {"libopus": "pe1fe9bbe80bf1d6d", "libsamplerate": "p0dd67588478f9a3e"},
"dependency_refs": {"libopus": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6", "libsamplerate": "c96f5e3de9c4488f4e6c97f59f5245f22fda22f7"},
"id": "pd258d453b63edc1f",
"name": "audio",
"ref": "f5eed1e6c817997d51508f9c3c7b948a0bb4ad0b",
"url": "https://github.com/ziranlang/audio.git"
},
{
"commit": "9cc6872f75447c3a24c16764f9829d0f58751cb0",
"dependencies": {},
@@ -42,15 +132,25 @@
"name": "mingcute",
"ref": "master",
"url": "https://github.com/kryonlabs/mingcute.git"
},
{
"commit": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
"dependencies": {},
"id": "pe1fe9bbe80bf1d6d",
"name": "libopus",
"ref": "ddbe48383984d56acd9e1ab6a090c54ca6b735a6",
"source": true,
"url": "https://github.com/xiph/opus.git"
}
],
"root": {
"dependencies": {"crypto": "p9f270a7aabc9904e", "kryon": "p79167729f20b4a95", "mingcute": "pe1027b9d16704793"},
"dependencies": {"crypto": "pc23fbf455e97614d", "kryon": "p0ecf74487f49020b", "mingcute": "pe1027b9d16704793"},
"dependency_refs": {"crypto": "master", "kryon": "1be70904a388db11ef5fb3938cd2d37ab7dd8eb5", "mingcute": "master"},
"name": "auth"
},
"toolchain": {
"commit": "3c23e5d084e31ad35c3e3e671cba06c985981461",
"ref": "master",
"commit": "665fbbca60ccf1e3823741d727af9af6c6552958",
"ref": "665fbbca60ccf1e3823741d727af9af6c6552958",
"url": "https://github.com/ziranlang/ziran.git"
}
}
+2 -2
View File
@@ -6,11 +6,11 @@ module_roots = ["src", "tests"]
[toolchain]
git = "https://github.com/ziranlang/ziran.git"
ref = "master"
ref = "665fbbca60ccf1e3823741d727af9af6c6552958"
[dependencies.kryon]
git = "https://github.com/kryonlabs/kryon.git"
ref = "ead3eb7aa63535447a1116ecae7bb4d712d72034"
ref = "1be70904a388db11ef5fb3938cd2d37ab7dd8eb5"
[dependencies.mingcute]
git = "https://github.com/kryonlabs/mingcute.git"