Cloudflare Pages / Build and verify the site (push) Successful in 3m29s
Use the verified dependency lock across native hosts and bundled apps. Preserve saved styles, local app reactivation, and offline packages while integrating the latest practice, Habits, Lumi, and figure preview updates.
294 lines
11 KiB
Ziran
294 lines
11 KiB
Ziran
#import, file "../src/app/app_style.zi";
|
|
#import, file "../src/app/app_types.zi";
|
|
#import, file "../src/app/metrics.zi";
|
|
#import, file "../src/app/theme_catalog.zi";
|
|
#import, file "../src/app/appearance_actions.zi";
|
|
#import, file "../src/app/style_customization.zi";
|
|
#import, file "../src/app/text_buffers.zi";
|
|
#import, file "../src/apps/package_files.zi";
|
|
#import, file "../src/core/types.zi";
|
|
#import, file "../apps/habits/coin_color.zi";
|
|
#import "vec"
|
|
#import "control_props"
|
|
#import "drawing_props"
|
|
#import "style_sheet"
|
|
#import "theme"
|
|
#import "style"
|
|
using ButtonState;
|
|
|
|
// App state outgrew the native main stack; the product also owns it globally.
|
|
style_test_app: InnerBreeze;
|
|
|
|
#program_export
|
|
StartupStyleCheck :: () -> s32 {
|
|
highlights: [ThemeCount * 2]u32
|
|
for theme: 0..ThemeCount - 1 {
|
|
if !StyleInstall(cast(s32)theme, false) {
|
|
return 100 + cast(s32)theme * 2
|
|
}
|
|
if !HighlightFollows(cast(s32)theme, false) {
|
|
return 300 + cast(s32)theme * 2
|
|
}
|
|
highlights[theme * 2] = ThemeCatalogLoad(cast(s32)theme, false).circle
|
|
if !StyleInstall(cast(s32)theme, true) {
|
|
return 101 + cast(s32)theme * 2
|
|
}
|
|
if !HighlightFollows(cast(s32)theme, true) {
|
|
return 301 + cast(s32)theme * 2
|
|
}
|
|
highlights[theme * 2 + 1] = ThemeCatalogLoad(cast(s32)theme, true).circle
|
|
}
|
|
// The highlight changes with the theme instead of staying one color.
|
|
distinct: s32 = 0
|
|
for index: 0..ThemeCount * 2 - 1 {
|
|
seen := false
|
|
for before: 0..index - 1 {
|
|
if highlights[before] == highlights[index] { seen = true }
|
|
}
|
|
if !seen { distinct += 1 }
|
|
}
|
|
if distinct < ThemeCount { return 299 }
|
|
// A host older than the highlight sends none: coins take the text color.
|
|
text := StyleTokenColor("text")
|
|
if !SameColor(HabitsCoinColor(Color.{}, text), text) { return 298 }
|
|
return 42
|
|
}
|
|
|
|
// Coins and other important numbers were one warm gold in every theme.
|
|
OLD_COIN_GOLD :: Color.{226, 168, 48, 255}
|
|
|
|
SameColor :: (a: Color, b: Color) -> bool {
|
|
return a.r == b.r && a.g == b.g && a.b == b.b && a.a == b.a
|
|
}
|
|
|
|
// After a theme is installed, coins and other important numbers take its
|
|
// highlight, the theme's circle color, and text on it takes that color's
|
|
// own ink.
|
|
HighlightFollows :: (theme: s32, dark: bool) -> bool {
|
|
circle := ColorFromPacked(ThemeCatalogLoad(theme, dark).circle)
|
|
highlight := StyleTokenColor("highlight")
|
|
ink := StyleTokenColor("highlight-ink")
|
|
coin := HabitsCoinColor(highlight, StyleTokenColor("text"))
|
|
return SameColor(highlight, circle) &&
|
|
SameColor(ink, ColorFromPacked(OnColor(ThemeCatalogLoad(theme, dark).circle))) &&
|
|
SameColor(coin, highlight) && !SameColor(coin, OLD_COIN_GOLD)
|
|
}
|
|
|
|
CustomButtonRadius :: () -> float32 {
|
|
base: StyleData
|
|
facts := AppearanceFacts("Button", "", cast(s32)ButtonStateNormal)
|
|
return ResolveInstalledStyleRules(base, facts, cast(s32)ButtonStateNormal).radius
|
|
}
|
|
|
|
#program_export
|
|
AccountStylesCheck :: (all_source: string, lumi_source: string) -> s32 {
|
|
StyleCustomizationLoad()
|
|
if StyleSavedSource(0) != all_source || StyleDraftSource(0) != all_source ||
|
|
StyleSavedSource(5) != lumi_source || StyleDraftSource(5) != lumi_source ||
|
|
style_undo_count != 0 || style_editor_open || style_error[0] != cast(u8)0 {
|
|
return 1
|
|
}
|
|
for scope: cast(s32)1..cast(s32)4 {
|
|
if StyleDraftSource(scope).count != 0 {
|
|
return 2
|
|
}
|
|
}
|
|
return 42
|
|
}
|
|
|
|
TextHas :: (text: string, part: string) -> bool {
|
|
if part.count > text.count { return false }
|
|
for index: cast(s32)0..cast(s32)(text.count - part.count) {
|
|
if text[index:index + cast(s32)part.count] == part { return true }
|
|
}
|
|
return false
|
|
}
|
|
|
|
// The KSS settings the C side lists: all apps converts and applies; lists
|
|
// has no CSS form and opens as its unapplied draft with the error.
|
|
#program_export
|
|
LegacyStylesCheck :: (failing: string) -> s32 {
|
|
StyleCustomizationLoad()
|
|
saved := StyleSavedSource(0)
|
|
if StyleDraftSource(0) != saved || StyleAppliedSource(0) != saved { return 1 }
|
|
if !TextHas(saved, "border-radius: 24px") || TextHas(saved, "radius: 24;") { return 2 }
|
|
if StyleSavedSource(1).count != 0 || StyleAppliedSource(1).count != 0 { return 3 }
|
|
if StyleDraftSource(1) != failing { return 4 }
|
|
if !TextHas(AppTextFromCString(*style_error[0], 256), "@variant") { return 5 }
|
|
app := *style_test_app
|
|
app.theme_id = 0
|
|
app.dark_mode = 0
|
|
app.breathing.screen = ScreenStart
|
|
if !app_apply_style(app) || CustomButtonRadius() != 24.0 { return 6 }
|
|
return 42
|
|
}
|
|
|
|
#program_export
|
|
CustomizationCheck :: () -> s32 {
|
|
StyleCustomizationLoad()
|
|
app := *style_test_app
|
|
app.theme_id = 0
|
|
app.dark_mode = 0
|
|
app.breathing.screen = ScreenStart
|
|
if !AppearanceEdit(app, 0, "Button { border-radius: 24px; }") || CustomButtonRadius() != 24.0 {
|
|
return 1
|
|
}
|
|
if StyleSavedSource(0).count != 0 {
|
|
return 2
|
|
}
|
|
color := StyleTokenColor("canvas")
|
|
if AppearanceEdit(app, 0, "Button { border-radius: unknown; }") || CustomButtonRadius() != 24.0 ||
|
|
StyleTokenColor("canvas").r != color.r || AppearanceSave(app, 0) {
|
|
return 3
|
|
}
|
|
if !AppearanceUndo(app, 0) || CustomButtonRadius() != 24.0 {
|
|
return 4
|
|
}
|
|
if !AppearanceSave(app, 0) || StyleSavedSource(0) != "Button { border-radius: 24px; }" {
|
|
return 5
|
|
}
|
|
StyleCustomizationLoad()
|
|
if StyleDraftSource(0) != "Button { border-radius: 24px; }" || !app_apply_style(app) {
|
|
return 6
|
|
}
|
|
if !AppearanceEdit(app, 5, "Button { border-radius: 7px; }") {
|
|
return 7
|
|
}
|
|
app.breathing.screen = ScreenLumi
|
|
if !app_apply_style(app) || CustomButtonRadius() != 7.0 {
|
|
return 8
|
|
}
|
|
app.breathing.screen = ScreenHabits
|
|
if !app_apply_style(app) || CustomButtonRadius() != 24.0 {
|
|
return 9
|
|
}
|
|
// Returning from an app that shares the rules restores Lumi's own sheet.
|
|
app.breathing.screen = ScreenLumi
|
|
if !app_apply_style(app) || CustomButtonRadius() != 7.0 {
|
|
return 23
|
|
}
|
|
app.breathing.screen = ScreenHabits
|
|
if !app_apply_style(app) || CustomButtonRadius() != 24.0 {
|
|
return 9
|
|
}
|
|
if !AppearanceReset(app, 5) || StyleSavedSource(5).count != 0 || CustomButtonRadius() != 24.0 {
|
|
return 10
|
|
}
|
|
if !AppearanceEdit(app, 0,
|
|
":root { --radius: 22px; --canvas: #102030; }") {
|
|
return 11
|
|
}
|
|
color = StyleTokenColor("canvas")
|
|
if color.r != 16 || color.g != 32 || color.b != 48 {
|
|
return 12
|
|
}
|
|
base: StyleData
|
|
app_face := ResolveInstalledStyleRules(base, StyleDefaultFacts(StyleKindApp()), 1)
|
|
if app_face.background != cast(u32)0x102030ff {
|
|
return 13
|
|
}
|
|
if !AppearanceDiscard(app, 0) || CustomButtonRadius() != 24.0 {
|
|
return 14
|
|
}
|
|
if AppearanceEdit(app, 0, "@import \"outside.css\";") || CustomButtonRadius() != 24.0 {
|
|
return 15
|
|
}
|
|
if !AppearanceDiscard(app, 0) || !AppearanceFormat(app, 0) || CustomButtonRadius() != 24.0 {
|
|
return 16
|
|
}
|
|
current_revision := style_revision
|
|
args: Vec(u8)
|
|
BuilderPrint(*args, "{\"scope\":\"all\",\"revision\":%}", current_revision - 1)
|
|
arguments := BuilderFinish(args)
|
|
result := AppearanceTool(app, "reset_style", arguments)
|
|
if result == "" || StyleDraftSource(0).count == 0 || style_revision != current_revision {
|
|
return 17
|
|
}
|
|
PackageFree(result)
|
|
PackageFree(arguments)
|
|
result = AppearanceTool(app, "inspect_style", "{\"scope\":\"all\",\"widget\":\"Button\",\"state\":\"normal\"}")
|
|
if result.count < 80 {
|
|
return 18
|
|
}
|
|
PackageFree(result)
|
|
result = AppearanceTool(app, "read_style", "{\"scope\":\"all\"}")
|
|
if result.count < 1000 {
|
|
return 19
|
|
}
|
|
PackageFree(result)
|
|
overflow: Vec(u8)
|
|
for index: cast(s32)0..cast(s32)StyleRuleCapacity {
|
|
unused BuilderAppend(overflow, "Button{border-radius:1px;}")
|
|
}
|
|
source := BuilderFinish(overflow)
|
|
if AppearanceEdit(app, 0, source) || CustomButtonRadius() != 24.0 {
|
|
return 20
|
|
}
|
|
PackageFree(source)
|
|
if !AppearanceReset(app, 0) || StyleSavedSource(0).count != 0 ||
|
|
StyleDraftSource(0).count != 0 || CustomButtonRadius() == 24.0 {
|
|
return 21
|
|
}
|
|
StyleCustomizationLoad()
|
|
if StyleDraftSource(0).count != 0 || StyleDraftSource(5).count != 0 {
|
|
return 22
|
|
}
|
|
return 42
|
|
}
|
|
|
|
#program_export
|
|
Answer :: () -> s32 {
|
|
app := *style_test_app
|
|
app.theme_id = 0
|
|
app.dark_mode = 0
|
|
app.breathing.screen = ScreenStart
|
|
if !app_apply_style(app) { return 1 }
|
|
// Body text takes the theme's Text size.
|
|
if AppFontSize() != 18 || AppSmallFontSize() != 16 { return 13 }
|
|
rules := ActiveStyleRules()
|
|
if rules.count < 20 { return 2 }
|
|
base: StyleData
|
|
facts: StyleFacts = StyleDefaultFacts(StyleKindApp())
|
|
face: StyleData = ResolveStyleRules(rules, base, facts, 1)
|
|
if face.background != cast(u32)0xE2EEFCFF { return 3 }
|
|
canvas := StyleTokenColor("canvas")
|
|
if canvas.r != 0xE2 || canvas.g != 0xEE ||
|
|
canvas.b != 0xFC || canvas.a != 0xFF { return 8 }
|
|
image_face := ResolveStyleRules(rules, base,
|
|
StyleDefaultFacts(StyleKindImage()), 1)
|
|
if image_face.background != cast(u32)0 { return 7 }
|
|
|
|
app.dark_mode = 1
|
|
if !app_apply_style(app) { return 4 }
|
|
rules = ActiveStyleRules()
|
|
face = ResolveStyleRules(rules, base, facts, 1)
|
|
if face.background != cast(u32)0x182838FF { return 5 }
|
|
canvas = StyleTokenColor("canvas")
|
|
if canvas.r != 0x18 || canvas.g != 0x28 ||
|
|
canvas.b != 0x38 || canvas.a != 0xFF { return 9 }
|
|
|
|
app.dark_mode = 0
|
|
if !app_apply_style(app) { return 6 }
|
|
|
|
// Unchanged inputs keep the installed style; changed ones replace it.
|
|
if !app_apply_style(app) || !app_apply_style(app) { return 10 }
|
|
canvas = StyleTokenColor("canvas")
|
|
if canvas.r != 0xE2 || canvas.g != 0xEE ||
|
|
canvas.b != 0xFC || canvas.a != 0xFF { return 11 }
|
|
if ActiveStyleRules().count < 20 { return 12 }
|
|
|
|
// Apps without their own sheet keep the installed rules when they open.
|
|
generation := style_generation
|
|
app.breathing.screen = ScreenEList
|
|
if !app_apply_style(app) || style_generation != generation { return 14 }
|
|
app.breathing.screen = ScreenHabits
|
|
if !app_apply_style(app) || style_generation != generation { return 15 }
|
|
app.breathing.screen = ScreenDiary
|
|
if !app_apply_style(app) || style_generation != generation { return 16 }
|
|
app.breathing.screen = ScreenLumi
|
|
if !app_apply_style(app) || style_generation != generation { return 17 }
|
|
app.breathing.screen = ScreenStart
|
|
if !app_apply_style(app) || style_generation != generation { return 18 }
|
|
return 42
|
|
}
|