code wiki / _hdl_build / nx_brand_packs.nx
nx_brand_packs.nx source
↩ module page · 62 lines · 4170 B
1// nx_brand_packs.nx -- R3 multi-brand THEME PACKS + teaching the universal builder. Several complete brands as
2// portable DATA; each TAUGHT to the Nishi Builder catalog (nb_register, domain=brand, kind=pack) so growing the
3// brands grows the catalog/UI with no code change -- the universal-builder doctrine ("every capability calls
4// nb_register"). Swap a whole brand in one move (bp_load -> wb_doc_open_branded). REUSE: nx_nishi_builder (catalog),
5// nx_brand_tokens (the .brand format). Templates are ~-encoded (token rows joined by '~') because the catalog's
6// TSV row terminator is '\n'; bp_decode restores '\n' on load. SOVEREIGNTY: bp_teach_one refuses any template that
7// fails nb_template_safe (no <script/src=). Library. 100% sovereign. license_tier: ORIGINAL
8import "nx_syscalls.nx"
9import "nx_nishi_builder.nx"
10
11// ~-encoded packs (token rows joined by '~'; decoded to '\n' on load). All are AA-safe by design (verified in gate).
12func bp_pack(id: *u8) -> *u8 {
13 if nb_streq(id, "nishi" as *u8) == 1 {
14 return "token|color|primary|#0b2545~token|color|accent|#e8a534~token|color|accent-ink|#0b2545~token|color|hero|#13315c~token|color|ink|#16202e~token|color|bg|#ffffff~token|color|muted|#eef3f8~token|color|line|#cdd7e3~token|font|sans|system-ui, -apple-system, Segoe UI, sans-serif~token|font|size-base|16px~token|font|leading|1.6~token|font|h1|2rem~token|font|h2|1.4rem~token|space|1|8px~token|space|2|16px~token|space|3|24px~token|space|4|40px~token|radius|md|8px~token|radius|sm|6px" as *u8
15 }
16 if nb_streq(id, "ocean" as *u8) == 1 {
17 return "token|color|primary|#0a3d62~token|color|accent|#f4a259~token|color|accent-ink|#07263d~token|color|hero|#1b6a8c~token|color|ink|#0b1f2a~token|color|bg|#ffffff~token|color|muted|#e8f1f5~token|color|line|#b8d4e0~token|font|sans|system-ui, -apple-system, Segoe UI, sans-serif~token|font|size-base|16px~token|font|leading|1.6~token|font|h1|2rem~token|font|h2|1.4rem~token|space|1|8px~token|space|2|16px~token|space|3|24px~token|space|4|40px~token|radius|md|10px~token|radius|sm|6px" as *u8
18 }
19 if nb_streq(id, "forest" as *u8) == 1 {
20 return "token|color|primary|#1b4332~token|color|accent|#e9c46a~token|color|accent-ink|#14241b~token|color|hero|#2d6a4f~token|color|ink|#16241d~token|color|bg|#ffffff~token|color|muted|#e8f0eb~token|color|line|#bcd0c4~token|font|sans|Georgia, Cambria, Times New Roman, serif~token|font|size-base|16px~token|font|leading|1.65~token|font|h1|2.1rem~token|font|h2|1.5rem~token|space|1|8px~token|space|2|16px~token|space|3|24px~token|space|4|40px~token|radius|md|6px~token|radius|sm|4px" as *u8
21 }
22 return 0 as *u8
23}
24
25// decode a ~-encoded pack template into a real .brand blob (replace '~' with '\n'); return length.
26func bp_decode(src: *u8, out: *u8, cap: i64) -> i64 {
27 var i: i64 = 0
28 while src[i] != (0 as u8) {
29 if i < cap - 1 {
30 if src[i] == (126 as u8) { out[i] = 10 as u8 } else { out[i] = src[i] }
31 }
32 i = i + 1
33 }
34 var tp: i64 = i
35 if tp > cap - 1 { tp = cap - 1 }
36 out[tp] = 0 as u8
37 return i
38}
39
40// TEACH one pack to the catalog (sovereignty-checked). returns nb_register's result (1 new / 0 known / -1 fail / 0 unsafe).
41func bp_teach_one(path: *u8, id: *u8, label: *u8) -> i64 {
42 let t: *u8 = bp_pack(id)
43 if (t as i64) == 0 { return 0 }
44 if nb_template_safe(t) == 0 { return 0 }
45 return nb_register(path, "brand" as *u8, "pack" as *u8, id, label, t)
46}
47
48// teach ALL packs; returns count newly taught (idempotent: re-run returns 0).
49func bp_register_all(path: *u8) -> i64 {
50 var c: i64 = 0
51 c = c + bp_teach_one(path, "nishi" as *u8, "Nishi (navy/amber)" as *u8)
52 c = c + bp_teach_one(path, "ocean" as *u8, "Ocean (teal/sand)" as *u8)
53 c = c + bp_teach_one(path, "forest" as *u8, "Forest (green/gold)" as *u8)
54 return c
55}
56
57// load a pack from the catalog -> a real .brand blob into out. returns length, or -1 if not found.
58func bp_load(path: *u8, id: *u8, out: *u8, cap: i64) -> i64 {
59 let tmp: *u8 = sys_mmap(NB_MAXTPL)
60 if nb_lookup(path, "brand" as *u8, "pack" as *u8, id, tmp) == 0 { return 0 - 1 }
61 return bp_decode(tmp, out, cap)
62}