@native-sdk/cli 0.4.4 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (94) hide show
  1. package/build/app.zig +371 -5
  2. package/build/ts_run.mjs +102 -0
  3. package/build.zig +255 -1
  4. package/build.zig.zon +1 -0
  5. package/package.json +19 -10
  6. package/packages/core/package-lock.json +44 -0
  7. package/packages/core/package.json +38 -0
  8. package/packages/core/rt/rt.zig +1579 -0
  9. package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
  10. package/packages/core/sdk/core.ts +694 -0
  11. package/packages/core/sdk/events.ts +137 -0
  12. package/packages/core/sdk/text.ts +519 -0
  13. package/packages/core/src/checker.ts +1869 -0
  14. package/packages/core/src/cli.ts +68 -0
  15. package/packages/core/src/devhost.ts +291 -0
  16. package/packages/core/src/devhost_resolver.mjs +22 -0
  17. package/packages/core/src/diagnostics.ts +417 -0
  18. package/packages/core/src/emitter.ts +8815 -0
  19. package/packages/core/src/infer.ts +1515 -0
  20. package/packages/core/src/modules.ts +173 -0
  21. package/packages/core/src/ownership.ts +740 -0
  22. package/packages/core/src/text_polyfill.ts +337 -0
  23. package/packages/core/src/text_tables.ts +408 -0
  24. package/packages/core/src/transpile.ts +146 -0
  25. package/packages/core/src/typed_ast.ts +546 -0
  26. package/packages/core/src/types.ts +815 -0
  27. package/skill-data/native-ui/SKILL.md +14 -0
  28. package/skill-data/ts-core/SKILL.md +493 -0
  29. package/skill-data/zig/SKILL.md +10 -0
  30. package/src/app_runner/root.zig +24 -0
  31. package/src/app_runner/ts_core_main.zig +231 -0
  32. package/src/platform/windows/webview2_host.cpp +24 -0
  33. package/src/primitives/app_manifest/comptime_scene.zig +341 -0
  34. package/src/primitives/app_manifest/root.zig +5 -0
  35. package/src/primitives/canvas/commands.zig +14 -7
  36. package/src/primitives/canvas/layout_audit.zig +5 -5
  37. package/src/primitives/canvas/lazy_tls.zig +73 -0
  38. package/src/primitives/canvas/render_generic_resources.zig +22 -15
  39. package/src/primitives/canvas/root.zig +11 -0
  40. package/src/primitives/canvas/tests.zig +1 -0
  41. package/src/primitives/canvas/text_atlas.zig +40 -32
  42. package/src/primitives/canvas/text_layout_cache.zig +29 -22
  43. package/src/primitives/canvas/text_measure_cache.zig +56 -41
  44. package/src/primitives/canvas/text_spans.zig +39 -26
  45. package/src/primitives/canvas/tokens.zig +69 -0
  46. package/src/primitives/canvas/ui.zig +125 -0
  47. package/src/primitives/canvas/ui_markup.zig +22 -3
  48. package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
  49. package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
  50. package/src/primitives/canvas/ui_markup_contract.zig +68 -14
  51. package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
  52. package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
  53. package/src/primitives/canvas/ui_markup_view.zig +105 -1
  54. package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
  55. package/src/primitives/canvas/ui_schema.zig +8 -0
  56. package/src/primitives/canvas/ui_schema_tests.zig +5 -4
  57. package/src/primitives/canvas/widget_builtin_tests.zig +309 -5
  58. package/src/primitives/canvas/widget_invalidation.zig +14 -7
  59. package/src/primitives/canvas/widget_layout.zig +138 -2
  60. package/src/primitives/canvas/widget_metrics.zig +16 -8
  61. package/src/primitives/canvas/widget_render.zig +25 -15
  62. package/src/primitives/canvas/widget_render_controls.zig +15 -9
  63. package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
  64. package/src/root.zig +7 -0
  65. package/src/runtime/canvas_frame.zig +57 -36
  66. package/src/runtime/canvas_images.zig +9 -3
  67. package/src/runtime/canvas_widget_control_tests.zig +5 -6
  68. package/src/runtime/canvas_widget_runtime.zig +7 -4
  69. package/src/runtime/core.zig +16 -0
  70. package/src/runtime/effects.zig +1525 -133
  71. package/src/runtime/effects_fetch_tests.zig +42 -0
  72. package/src/runtime/effects_file_tests.zig +220 -0
  73. package/src/runtime/effects_host_tests.zig +594 -0
  74. package/src/runtime/effects_tests.zig +287 -0
  75. package/src/runtime/root.zig +18 -0
  76. package/src/runtime/session_replay.zig +7 -1
  77. package/src/runtime/tests.zig +2 -0
  78. package/src/runtime/ts_core_host.zig +1505 -0
  79. package/src/runtime/ts_core_host_tests.zig +1408 -0
  80. package/src/runtime/ts_ui_app.zig +469 -0
  81. package/src/runtime/ui_app.zig +189 -38
  82. package/src/runtime/ui_app_tests.zig +221 -0
  83. package/src/runtime/ui_app_window_tests.zig +182 -0
  84. package/src/runtime/view_canvas.zig +24 -17
  85. package/src/runtime/view_widget_tree.zig +2 -2
  86. package/src/tooling/codesign.zig +212 -105
  87. package/src/tooling/doctor.zig +78 -0
  88. package/src/tooling/manifest.zig +47 -0
  89. package/src/tooling/package.zig +435 -20
  90. package/src/tooling/raw_manifest.zig +15 -0
  91. package/src/tooling/root.zig +1 -0
  92. package/src/tooling/templates.zig +777 -34
  93. package/src/tooling/ts_core.zig +1099 -0
  94. package/src/tooling/verbs.zig +105 -2
@@ -123,24 +123,36 @@ const AdvanceEntry = struct {
123
123
  last_used: u64 = 0,
124
124
  };
125
125
 
126
- threadlocal var advance_entries: [advance_cache_capacity]AdvanceEntry = @splat(.{});
127
- threadlocal var advance_storage: [advance_cache_capacity][max_cached_advance_run_bytes]f32 = undefined;
128
- threadlocal var oversize_key: AdvanceKey = .{};
129
- threadlocal var oversize_storage: [max_batched_advance_run_bytes]f32 = undefined;
130
- /// Monotonic use tick driving least-recently-used eviction.
131
- threadlocal var advance_use_tick: u64 = 0;
132
- /// Fetch statistics for tests and the render benchmark: how many
133
- /// batched provider calls actually happened vs how many lookups were
134
- /// answered from retained entries.
135
- threadlocal var advance_fetch_count: u64 = 0;
136
- threadlocal var advance_hit_count: u64 = 0;
126
+ /// The whole per-thread cache behind one lazily heap-allocated pointer:
127
+ /// at ~2.25 MiB this was the single largest block in the static TLS
128
+ /// template every OS thread's loader had to clone. Init happens on the
129
+ /// first `textRunAdvances`/`cachedTextRunAdvances` call of a thread —
130
+ /// the measuring thread by construction — so threads that never measure
131
+ /// text never allocate it. The storage arrays carry no default and stay
132
+ /// uninitialized, exactly like the `= undefined` statics they replace.
133
+ const AdvanceCache = struct {
134
+ entries: [advance_cache_capacity]AdvanceEntry = @splat(.{}),
135
+ storage: [advance_cache_capacity][max_cached_advance_run_bytes]f32,
136
+ oversize_key: AdvanceKey = .{},
137
+ oversize_storage: [max_batched_advance_run_bytes]f32,
138
+ /// Monotonic use tick driving least-recently-used eviction.
139
+ use_tick: u64 = 0,
140
+ /// Fetch statistics for tests and the render benchmark: how many
141
+ /// batched provider calls actually happened vs how many lookups were
142
+ /// answered from retained entries.
143
+ fetch_count: u64 = 0,
144
+ hit_count: u64 = 0,
145
+ };
146
+ const advance_cache = @import("lazy_tls.zig").LazyTls(AdvanceCache);
137
147
 
138
148
  pub fn textAdvanceFetchCount() u64 {
139
- return advance_fetch_count;
149
+ const cache = advance_cache.peek() orelse return 0;
150
+ return cache.fetch_count;
140
151
  }
141
152
 
142
153
  pub fn textAdvanceHitCount() u64 {
143
- return advance_hit_count;
154
+ const cache = advance_cache.peek() orelse return 0;
155
+ return cache.hit_count;
144
156
  }
145
157
 
146
158
  fn advanceKeyFor(provider: *const TextMeasureProvider, font_id: FontId, size: f32, text: []const u8) AdvanceKey {
@@ -192,32 +204,33 @@ pub fn textRunAdvances(provider: *const TextMeasureProvider, font_id: FontId, si
192
204
  if (text.len == 0) return &.{};
193
205
  if (text.len > max_batched_advance_run_bytes) return null;
194
206
 
207
+ const cache = advance_cache.get();
195
208
  const key = advanceKeyFor(provider, font_id, size, text);
196
- advance_use_tick += 1;
209
+ cache.use_tick += 1;
197
210
 
198
211
  if (text.len > max_cached_advance_run_bytes) {
199
212
  // Oversize runs: one uncached scratch slot, memoized against
200
213
  // itself so repeated fetches of the same long run (the line
201
214
  // breaker, then elision, then bounds) still pay one call.
202
- if (advanceKeysEqual(oversize_key, key)) {
203
- advance_hit_count += 1;
204
- return oversize_storage[0..text.len];
215
+ if (advanceKeysEqual(cache.oversize_key, key)) {
216
+ cache.hit_count += 1;
217
+ return cache.oversize_storage[0..text.len];
205
218
  }
206
- oversize_key = .{};
207
- advance_fetch_count += 1;
208
- if (!provider.measureAdvances(font_id, size, text, oversize_storage[0..text.len])) return null;
209
- if (!advancesValid(oversize_storage[0..text.len])) return null;
210
- oversize_key = key;
211
- return oversize_storage[0..text.len];
219
+ cache.oversize_key = .{};
220
+ cache.fetch_count += 1;
221
+ if (!provider.measureAdvances(font_id, size, text, cache.oversize_storage[0..text.len])) return null;
222
+ if (!advancesValid(cache.oversize_storage[0..text.len])) return null;
223
+ cache.oversize_key = key;
224
+ return cache.oversize_storage[0..text.len];
212
225
  }
213
226
 
214
227
  var victim: usize = 0;
215
228
  var victim_tick: u64 = std.math.maxInt(u64);
216
- for (&advance_entries, 0..) |*entry, index| {
229
+ for (&cache.entries, 0..) |*entry, index| {
217
230
  if (advanceKeysEqual(entry.key, key)) {
218
- entry.last_used = advance_use_tick;
219
- advance_hit_count += 1;
220
- return advance_storage[index][0..text.len];
231
+ entry.last_used = cache.use_tick;
232
+ cache.hit_count += 1;
233
+ return cache.storage[index][0..text.len];
221
234
  }
222
235
  // Unused slots evict first (tick 0), then the least recently
223
236
  // used entry — honest bounded retention, no clock heuristics.
@@ -228,12 +241,12 @@ pub fn textRunAdvances(provider: *const TextMeasureProvider, font_id: FontId, si
228
241
  }
229
242
  }
230
243
 
231
- advance_entries[victim].key = .{};
232
- advance_fetch_count += 1;
233
- if (!provider.measureAdvances(font_id, size, text, advance_storage[victim][0..text.len])) return null;
234
- if (!advancesValid(advance_storage[victim][0..text.len])) return null;
235
- advance_entries[victim] = .{ .key = key, .last_used = advance_use_tick };
236
- return advance_storage[victim][0..text.len];
244
+ cache.entries[victim].key = .{};
245
+ cache.fetch_count += 1;
246
+ if (!provider.measureAdvances(font_id, size, text, cache.storage[victim][0..text.len])) return null;
247
+ if (!advancesValid(cache.storage[victim][0..text.len])) return null;
248
+ cache.entries[victim] = .{ .key = key, .last_used = cache.use_tick };
249
+ return cache.storage[victim][0..text.len];
237
250
  }
238
251
 
239
252
  /// Peek: the run's advances IF already retained (or sitting in the
@@ -248,20 +261,22 @@ pub fn cachedTextRunAdvances(provider: *const TextMeasureProvider, font_id: Font
248
261
  if (provider.measure_advances_fn == null) return null;
249
262
  if (text.len == 0) return &.{};
250
263
  if (text.len > max_batched_advance_run_bytes) return null;
264
+ // Peek must not allocate a cache that nothing has fetched into yet.
265
+ const cache = advance_cache.peek() orelse return null;
251
266
  const key = advanceKeyFor(provider, font_id, size, text);
252
267
  if (text.len > max_cached_advance_run_bytes) {
253
- if (advanceKeysEqual(oversize_key, key)) {
254
- advance_hit_count += 1;
255
- return oversize_storage[0..text.len];
268
+ if (advanceKeysEqual(cache.oversize_key, key)) {
269
+ cache.hit_count += 1;
270
+ return cache.oversize_storage[0..text.len];
256
271
  }
257
272
  return null;
258
273
  }
259
- for (&advance_entries, 0..) |*entry, index| {
274
+ for (&cache.entries, 0..) |*entry, index| {
260
275
  if (advanceKeysEqual(entry.key, key)) {
261
- advance_use_tick += 1;
262
- entry.last_used = advance_use_tick;
263
- advance_hit_count += 1;
264
- return advance_storage[index][0..text.len];
276
+ cache.use_tick += 1;
277
+ entry.last_used = cache.use_tick;
278
+ cache.hit_count += 1;
279
+ return cache.storage[index][0..text.len];
265
280
  }
266
281
  }
267
282
  return null;
@@ -354,12 +354,13 @@ const LayoutState = struct {
354
354
  /// to the pre-cache behavior (goldens, signatures, reference renders).
355
355
  pub fn layoutTextSpans(spans: []const TextSpan, options: TextSpanLayoutOptions, runs_storage: []TextSpanRun) TextSpanLayout {
356
356
  if (options.measure != null and runs_storage.len >= max_text_span_runs_per_paragraph) {
357
+ const cache = span_wrap_cache.get();
357
358
  const key = spanWrapKey(spans, options);
358
- if (findSpanWrapEntry(key)) |entry_index| {
359
- if (rebaseSpanWrapEntry(entry_index, spans, options, runs_storage)) |layout| return layout;
359
+ if (findSpanWrapEntry(cache, key)) |entry_index| {
360
+ if (rebaseSpanWrapEntry(cache, entry_index, spans, options, runs_storage)) |layout| return layout;
360
361
  }
361
362
  const layout = layoutTextSpansUncached(spans, options, runs_storage);
362
- storeSpanWrapEntry(key, spans, layout);
363
+ storeSpanWrapEntry(cache, key, spans, layout);
363
364
  return layout;
364
365
  }
365
366
  return layoutTextSpansUncached(spans, options, runs_storage);
@@ -502,19 +503,31 @@ const SpanWrapEntry = struct {
502
503
  last_used: u64 = 0,
503
504
  };
504
505
 
505
- threadlocal var span_wrap_entries: [span_wrap_cache_capacity]SpanWrapEntry = @splat(.{});
506
- threadlocal var span_wrap_runs: [span_wrap_cache_capacity][max_text_span_runs_per_paragraph]SpanWrapRun = undefined;
507
- threadlocal var span_wrap_use_tick: u64 = 0;
508
- threadlocal var span_wrap_hit_count: u64 = 0;
509
- threadlocal var span_wrap_miss_count: u64 = 0;
506
+ /// The whole per-thread wrap cache behind one lazily heap-allocated
507
+ /// pointer (~1 MiB that would otherwise sit in the static TLS template
508
+ /// every OS thread's loader clones). Init happens on the first cached
509
+ /// `layoutTextSpans` call of a thread — the layout thread by
510
+ /// construction — so threads that never wrap spans never allocate it.
511
+ /// `runs` carries no default and stays uninitialized, exactly like the
512
+ /// `= undefined` static it replaces.
513
+ const SpanWrapCache = struct {
514
+ entries: [span_wrap_cache_capacity]SpanWrapEntry = @splat(.{}),
515
+ runs: [span_wrap_cache_capacity][max_text_span_runs_per_paragraph]SpanWrapRun,
516
+ use_tick: u64 = 0,
517
+ hit_count: u64 = 0,
518
+ miss_count: u64 = 0,
519
+ };
520
+ const span_wrap_cache = @import("lazy_tls.zig").LazyTls(SpanWrapCache);
510
521
 
511
522
  /// Cache observability for tests and benchmarks.
512
523
  pub fn textSpanWrapCacheHitCount() u64 {
513
- return span_wrap_hit_count;
524
+ const cache = span_wrap_cache.peek() orelse return 0;
525
+ return cache.hit_count;
514
526
  }
515
527
 
516
528
  pub fn textSpanWrapCacheMissCount() u64 {
517
- return span_wrap_miss_count;
529
+ const cache = span_wrap_cache.peek() orelse return 0;
530
+ return cache.miss_count;
518
531
  }
519
532
 
520
533
  fn spanWrapKey(spans: []const TextSpan, options: TextSpanLayoutOptions) SpanWrapKey {
@@ -567,20 +580,20 @@ fn spanWrapKeysEqual(a: SpanWrapKey, b: SpanWrapKey) bool {
567
580
  a.generation == b.generation;
568
581
  }
569
582
 
570
- fn findSpanWrapEntry(key: SpanWrapKey) ?usize {
571
- for (&span_wrap_entries, 0..) |*entry, index| {
583
+ fn findSpanWrapEntry(cache: *SpanWrapCache, key: SpanWrapKey) ?usize {
584
+ for (&cache.entries, 0..) |*entry, index| {
572
585
  if (spanWrapKeysEqual(entry.key, key)) {
573
- span_wrap_use_tick += 1;
574
- entry.last_used = span_wrap_use_tick;
575
- span_wrap_hit_count += 1;
586
+ cache.use_tick += 1;
587
+ entry.last_used = cache.use_tick;
588
+ cache.hit_count += 1;
576
589
  return index;
577
590
  }
578
591
  }
579
- span_wrap_miss_count += 1;
592
+ cache.miss_count += 1;
580
593
  return null;
581
594
  }
582
595
 
583
- fn storeSpanWrapEntry(key: SpanWrapKey, spans: []const TextSpan, layout: TextSpanLayout) void {
596
+ fn storeSpanWrapEntry(cache: *SpanWrapCache, key: SpanWrapKey, spans: []const TextSpan, layout: TextSpanLayout) void {
584
597
  if (layout.runs.len > max_text_span_runs_per_paragraph) return;
585
598
  // Offsets require every run to alias its span's bytes; the breaker
586
599
  // only ever emits subslices of span.text, so a failure here would be
@@ -591,17 +604,17 @@ fn storeSpanWrapEntry(key: SpanWrapKey, spans: []const TextSpan, layout: TextSpa
591
604
 
592
605
  var victim: usize = 0;
593
606
  var victim_tick: u64 = std.math.maxInt(u64);
594
- for (&span_wrap_entries, 0..) |*entry, index| {
607
+ for (&cache.entries, 0..) |*entry, index| {
595
608
  const tick = if (entry.key.used) entry.last_used else 0;
596
609
  if (tick < victim_tick) {
597
610
  victim_tick = tick;
598
611
  victim = index;
599
612
  }
600
613
  }
601
- span_wrap_use_tick += 1;
614
+ cache.use_tick += 1;
602
615
  for (layout.runs, 0..) |run, run_index| {
603
616
  const offset = spanRunOffset(spans, run).?;
604
- span_wrap_runs[victim][run_index] = .{
617
+ cache.runs[victim][run_index] = .{
605
618
  .span_index = @intCast(run.span_index),
606
619
  .text_start = @intCast(offset),
607
620
  .text_len = @intCast(run.text.len),
@@ -611,14 +624,14 @@ fn storeSpanWrapEntry(key: SpanWrapKey, spans: []const TextSpan, layout: TextSpa
611
624
  .baseline = run.baseline,
612
625
  };
613
626
  }
614
- span_wrap_entries[victim] = .{
627
+ cache.entries[victim] = .{
615
628
  .key = key,
616
629
  .run_len = layout.runs.len,
617
630
  .line_count = layout.line_count,
618
631
  .line_height = layout.line_height,
619
632
  .size = layout.size,
620
633
  .truncated = layout.truncated,
621
- .last_used = span_wrap_use_tick,
634
+ .last_used = cache.use_tick,
622
635
  };
623
636
  }
624
637
 
@@ -639,13 +652,13 @@ fn spanRunOffset(spans: []const TextSpan, run: TextSpanRun) ?usize {
639
652
  /// offset does not fit the current spans — only reachable through a
640
653
  /// content-hash collision, and answered by re-laying-out instead of
641
654
  /// serving mismatched geometry.
642
- fn rebaseSpanWrapEntry(entry_index: usize, spans: []const TextSpan, options: TextSpanLayoutOptions, runs_storage: []TextSpanRun) ?TextSpanLayout {
643
- const entry = &span_wrap_entries[entry_index];
644
- for (span_wrap_runs[entry_index][0..entry.run_len]) |cached| {
655
+ fn rebaseSpanWrapEntry(cache: *SpanWrapCache, entry_index: usize, spans: []const TextSpan, options: TextSpanLayoutOptions, runs_storage: []TextSpanRun) ?TextSpanLayout {
656
+ const entry = &cache.entries[entry_index];
657
+ for (cache.runs[entry_index][0..entry.run_len]) |cached| {
645
658
  if (cached.span_index >= spans.len) return null;
646
659
  if (cached.text_start + cached.text_len > spans[cached.span_index].text.len) return null;
647
660
  }
648
- for (span_wrap_runs[entry_index][0..entry.run_len], 0..) |cached, run_index| {
661
+ for (cache.runs[entry_index][0..entry.run_len], 0..) |cached, run_index| {
649
662
  const span = spans[cached.span_index];
650
663
  runs_storage[run_index] = .{
651
664
  .span_index = cached.span_index,
@@ -1,4 +1,5 @@
1
1
  const std = @import("std");
2
+ const geometry = @import("geometry");
2
3
  const canvas = @import("root.zig");
3
4
  const text_metrics = @import("text_metrics.zig");
4
5
  const geist_theme = @import("themes/geist.zig");
@@ -1423,6 +1424,60 @@ pub const ControlTokenOverrides = struct {
1423
1424
  }
1424
1425
  };
1425
1426
 
1427
+ /// The ONE-accent brand statement as a token override bundle: the
1428
+ /// manifest theme surface (`app.zon`'s `.theme_accent`) resolves through
1429
+ /// this, and Zig apps can layer the same bundle over any pack. Three
1430
+ /// slots carry an accent identity, plus the slider's own table:
1431
+ ///
1432
+ /// - `colors.accent`/`accent_text`: the filled-primary pair — selected
1433
+ /// fills, "Playing"-style primary badges, filled primary buttons, and
1434
+ /// every control fill deriving from the accent channel. The knockout
1435
+ /// ink derives from the accent's relative luminance (white over dark
1436
+ /// accents, near-black over light ones) so the pair stays readable in
1437
+ /// both schemes without a second manifest knob.
1438
+ /// - `colors.focus_ring`: packs spend their identity hue on focus; with
1439
+ /// the identity moved, the ring follows so focus and accent chrome
1440
+ /// read as one system.
1441
+ /// - `controls.slider.active_background`: the slider table states its
1442
+ /// own hue for the filled range rather than deriving from the accent
1443
+ /// channel, so the same move is stated once more or a seek scrubber
1444
+ /// would keep the pack's stock hue.
1445
+ ///
1446
+ /// High-contrast composition is the CALLER's rule (accessibility beats
1447
+ /// brand): the runtime skips this bundle when the system asks for high
1448
+ /// contrast, taking the pack's own loud register untouched.
1449
+ pub fn accentOverrides(accent: Color) DesignTokenOverrides {
1450
+ return .{
1451
+ .colors = .{
1452
+ .accent = accent,
1453
+ .accent_text = accentKnockoutInk(accent),
1454
+ .focus_ring = accent,
1455
+ },
1456
+ .controls = .{
1457
+ .slider = .{ .active_background = accent },
1458
+ },
1459
+ };
1460
+ }
1461
+
1462
+ /// The readable knockout ink over one accent fill: WHITE whenever it
1463
+ /// clears the 4.5:1 text bar over the accent (the ink packs pair with
1464
+ /// every solid identity fill — the convention brands expect), and the
1465
+ /// near-black text ink only when the accent is light enough that white
1466
+ /// honestly cannot (1.05 / (L + 0.05) < 4.5).
1467
+ fn accentKnockoutInk(accent: Color) Color {
1468
+ const luminance = 0.2126 * srgbToLinear(accent.r) +
1469
+ 0.7152 * srgbToLinear(accent.g) +
1470
+ 0.0722 * srgbToLinear(accent.b);
1471
+ // White clears 4.5:1 up to L = 1.05/4.5 - 0.05 ≈ 0.18333.
1472
+ if (luminance <= 0.18333) return Color.rgb8(255, 255, 255);
1473
+ return Color.rgb8(10, 10, 10);
1474
+ }
1475
+
1476
+ fn srgbToLinear(channel: f32) f32 {
1477
+ if (channel <= 0.04045) return channel / 12.92;
1478
+ return std.math.pow(f32, (channel + 0.055) / 1.055, 2.4);
1479
+ }
1480
+
1426
1481
  pub const DesignTokenOverrides = struct {
1427
1482
  colors: ColorTokenOverrides = .{},
1428
1483
  typography: TypographyTokenOverrides = .{},
@@ -1467,6 +1522,20 @@ pub const DesignTokens = struct {
1467
1522
  /// actually draws. Not themed and not part of overrides: the runtime
1468
1523
  /// stamps it after theme resolution.
1469
1524
  text_measure: ?*const text_metrics.TextMeasureProvider = null,
1525
+ /// The OS window-control cluster's frame in the canvas's local
1526
+ /// coordinates (Windows: the DWM min/max/close buttons on the
1527
+ /// trailing edge; macOS: the traffic lights on the leading edge),
1528
+ /// for hidden-titlebar windows whose content extends under the
1529
+ /// band. Null (the default) lays out exactly as before. The runtime
1530
+ /// stamps it — like `text_measure`, never themed and not part of
1531
+ /// overrides — and only after a build proved the app's own drag
1532
+ /// header left content UNDER the cluster (an app that already pads
1533
+ /// via the chrome channel's insets keeps its byte-identical
1534
+ /// layout). `window_drag` widgets then lay their content out clear
1535
+ /// of the cluster (`widget_layout.windowControlsClearedContent`),
1536
+ /// so a header that never consumed the chrome insets still keeps
1537
+ /// its trailing status text out from under the caption buttons.
1538
+ window_controls: ?geometry.RectF = null,
1470
1539
 
1471
1540
  pub fn theme(options: ThemeOptions) DesignTokens {
1472
1541
  // The pack resolves the register (palette, control tables, and
@@ -23,6 +23,7 @@ const builtin = @import("builtin");
23
23
  const font_coverage = @import("font_coverage.zig");
24
24
  const geometry = @import("geometry");
25
25
  const canvas = @import("root.zig");
26
+ const reflect = @import("ui_markup_reflect.zig");
26
27
  const ui_provenance = @import("ui_provenance.zig");
27
28
 
28
29
  const ObjectId = canvas.ObjectId;
@@ -786,6 +787,79 @@ pub fn Ui(comptime Msg: type) type {
786
787
  }.make;
787
788
  }
788
789
 
790
+ /// Comptime message constructor for `on_input` over a DECLARED
791
+ /// text-input event union (`ui_markup_reflect.declaredTextInputUnion`
792
+ /// — the transpiled-core shape, where the emitted module declares
793
+ /// its own mirror of `canvas.TextInputEvent` and type identity
794
+ /// cannot cross the emission boundary). The built message carries
795
+ /// the arm's own union value, translated field-for-field from the
796
+ /// runtime event at dispatch: tags map by name, numeric fields widen
797
+ /// the way the payload declares them (i64 or f64), and the event's
798
+ /// text slices ride through unchanged (host-event lifetime — one
799
+ /// dispatch, exactly what `update` gets everywhere else).
800
+ pub fn translatedInputMsg(comptime tag: std.meta.Tag(Msg), comptime Payload: type) InputMsgFn {
801
+ return struct {
802
+ fn caret(comptime D: type, direction: canvas.TextCaretDirection) D {
803
+ return switch (direction) {
804
+ inline else => |d| @field(D, @tagName(d)),
805
+ };
806
+ }
807
+
808
+ fn num(comptime N: type, value: usize) N {
809
+ // Saturating, not @intCast: selection offsets carry a
810
+ // defined "to the end, whatever the length" sentinel —
811
+ // select-all synthesizes `set_selection` with
812
+ // `focus = maxInt(usize)` (events.zig), which every
813
+ // consumer snaps to its text length (the runtime editor
814
+ // via snapTextSelection, an elm-mirror core via its own
815
+ // snap). maxInt(usize) does not fit the declared i64
816
+ // field class, and panicking on translation killed the
817
+ // app on the first cmd/ctrl+A (or automation set_text)
818
+ // in ANY transpiled-core text field. Saturating keeps
819
+ // the sentinel's meaning — still past any real length,
820
+ // the core's snap resolves it exactly like the Zig
821
+ // TextEditState does — and leaves real offsets exact.
822
+ return if (@typeInfo(N) == .float) @floatFromInt(value) else std.math.lossyCast(N, value);
823
+ }
824
+
825
+ fn make(edit: canvas.TextInputEvent) Msg {
826
+ const payload: Payload = switch (edit) {
827
+ .insert_text => |inserted| @unionInit(Payload, "insert_text", inserted),
828
+ .delete_backward => @unionInit(Payload, "delete_backward", {}),
829
+ .delete_forward => @unionInit(Payload, "delete_forward", {}),
830
+ .delete_word_backward => @unionInit(Payload, "delete_word_backward", {}),
831
+ .delete_word_forward => @unionInit(Payload, "delete_word_forward", {}),
832
+ .clear => @unionInit(Payload, "clear", {}),
833
+ .move_caret => |move| blk: {
834
+ const Move = @FieldType(Payload, "move_caret");
835
+ break :blk @unionInit(Payload, "move_caret", .{
836
+ .direction = caret(@FieldType(Move, "direction"), move.direction),
837
+ .extend = move.extend,
838
+ });
839
+ },
840
+ .set_selection => |selection| blk: {
841
+ const Selection = @FieldType(Payload, "set_selection");
842
+ break :blk @unionInit(Payload, "set_selection", .{
843
+ .anchor = num(@FieldType(Selection, "anchor"), selection.anchor),
844
+ .focus = num(@FieldType(Selection, "focus"), selection.focus),
845
+ });
846
+ },
847
+ .set_composition => |composition| blk: {
848
+ const Composition = @FieldType(Payload, "set_composition");
849
+ const Cursor = @typeInfo(@FieldType(Composition, "cursor")).optional.child;
850
+ break :blk @unionInit(Payload, "set_composition", .{
851
+ .text = composition.text,
852
+ .cursor = if (composition.cursor) |cursor| num(Cursor, cursor) else null,
853
+ });
854
+ },
855
+ .commit_composition => @unionInit(Payload, "commit_composition", {}),
856
+ .cancel_composition => @unionInit(Payload, "cancel_composition", {}),
857
+ };
858
+ return @unionInit(Msg, @tagName(tag), payload);
859
+ }
860
+ }.make;
861
+ }
862
+
789
863
  /// Comptime message constructor for `on_value`: `valueMsg(.confidence)`
790
864
  /// yields a function building `Msg{ .confidence = value }`.
791
865
  pub fn valueMsg(comptime tag: std.meta.Tag(Msg)) ValueMsgFn {
@@ -796,6 +870,20 @@ pub fn Ui(comptime Msg: type) type {
796
870
  }.make;
797
871
  }
798
872
 
873
+ /// Comptime message constructor for `on_value`/`on_resize` over a
874
+ /// DECLARED one-number float arm (`ui_markup_reflect.valueArmClass`
875
+ /// — the transpiled-core shape, where the arm's payload is the
876
+ /// emitted `f64` rather than `f32` by identity). The runtime's
877
+ /// applied 0..1 fraction widens exactly at dispatch.
878
+ pub fn translatedValueMsg(comptime tag: std.meta.Tag(Msg), comptime Payload: type) ValueMsgFn {
879
+ return struct {
880
+ fn make(value: f32) Msg {
881
+ const payload: Payload = @floatCast(value);
882
+ return @unionInit(Msg, @tagName(tag), payload);
883
+ }
884
+ }.make;
885
+ }
886
+
799
887
  /// Comptime message constructor for `on_scroll`:
800
888
  /// `scrollMsg(.activity_scrolled)` yields a function building
801
889
  /// `Msg{ .activity_scrolled = scroll }` from the post-scroll
@@ -808,6 +896,43 @@ pub fn Ui(comptime Msg: type) type {
808
896
  }.make;
809
897
  }
810
898
 
899
+ /// Comptime message constructor for `on_scroll` over a DECLARED
900
+ /// scroll-state record (`ui_markup_reflect.declaredScrollStateRecord`
901
+ /// — the transpiled-core shape, where the emitted module declares
902
+ /// its own mirror of `canvas.ScrollState` and type identity cannot
903
+ /// cross the emission boundary). The built message carries the
904
+ /// arm's own record value, translated field-for-field from the
905
+ /// runtime state at dispatch: fields map by name, and each numeric
906
+ /// field widens the way the payload declares it (exactly into
907
+ /// floats, rounded to the nearest whole number into integers).
908
+ pub fn translatedScrollMsg(comptime tag: std.meta.Tag(Msg), comptime Payload: type) ScrollMsgFn {
909
+ return struct {
910
+ fn num(comptime N: type, value: f32) N {
911
+ return if (@typeInfo(N) == .float) @floatCast(value) else @intFromFloat(@round(value));
912
+ }
913
+
914
+ /// The `canvas.ScrollState` field behind a payload field
915
+ /// name: identical for the canvas spelling, mapped for the
916
+ /// TS SDK spelling (`viewportExtent` — transpiled fields
917
+ /// keep their TS names).
918
+ fn sourceName(comptime name: []const u8) []const u8 {
919
+ if (@hasField(canvas.ScrollState, name)) return name;
920
+ inline for (reflect.scroll_state_field_names_ts, 0..) |ts_name, index| {
921
+ if (comptime std.mem.eql(u8, name, ts_name)) return reflect.scroll_state_field_names[index];
922
+ }
923
+ unreachable; // declaredScrollStateRecord admits no other name
924
+ }
925
+
926
+ fn make(scroll_state: canvas.ScrollState) Msg {
927
+ var payload: Payload = undefined;
928
+ inline for (@typeInfo(Payload).@"struct".fields) |field| {
929
+ @field(payload, field.name) = num(field.type, @field(scroll_state, sourceName(field.name)));
930
+ }
931
+ return @unionInit(Msg, @tagName(tag), payload);
932
+ }
933
+ }.make;
934
+ }
935
+
811
936
  /// Comptime message constructor for `on_link`: `linkMsg(.open_url)`
812
937
  /// yields a function building `Msg{ .open_url = link }`. The link
813
938
  /// slice lives in the view arena (or the caller's markdown source),
@@ -1118,10 +1118,10 @@ pub const known_events = schema.event_names;
1118
1118
 
1119
1119
  pub const on_scroll_element_message = "on-scroll is only supported on scroll - the runtime emits scroll offsets for scroll containers, so the handler belongs on the scroll element itself";
1120
1120
  pub const on_reach_end_element_message = "on-reach-end is only supported on scroll - the runtime emits the approach-end signal for scroll containers, so the handler belongs on the scroll element itself";
1121
- pub const on_scroll_payload_message = "on-scroll takes a bare Msg tag whose payload is the post-scroll state (a canvas.ScrollState variant, like activity_scrolled: canvas.ScrollState)";
1121
+ pub const on_scroll_payload_message = "on-scroll takes a bare Msg tag whose payload is the post-scroll state (a canvas.ScrollState variant, like activity_scrolled: canvas.ScrollState, or a declared record of its offset/velocity/viewport_extent/content_extent fields for transpiled cores)";
1122
1122
 
1123
1123
  pub const on_resize_element_message = "on-resize is only supported on split - the runtime emits fraction changes for split dividers, so the handler belongs on the split element itself";
1124
- pub const on_resize_payload_message = "on-resize takes a bare Msg tag whose payload is the new first-pane fraction (an f32 variant, like sidebar_resized: f32)";
1124
+ pub const on_resize_payload_message = "on-resize takes a bare Msg tag whose payload is the new first-pane fraction (an f32 variant, like sidebar_resized: f32; transpiled cores declare a one-number float arm)";
1125
1125
  pub const split_children_message = "split takes exactly two element children (the panes) - put conditional or repeated content inside a pane container, and nest splits for more panes";
1126
1126
 
1127
1127
  /// Elements the runtime's dismissal machinery closes (Escape, click
@@ -1213,6 +1213,8 @@ pub const grid_columns_element_message = "columns is only supported on grid - it
1213
1213
 
1214
1214
  pub const overscroll_element_message = "overscroll is only supported on scroll - it names a scroll region's edge behavior (none pins at the content edges, rubber_band lets the region bounce past them, default follows the ScrollPhysics.overscroll token); anywhere else it would be silently inert";
1215
1215
 
1216
+ pub const quiet_hover_element_message = "quiet-hover is only supported on pressable elements (hit targets like list-item, button, panel) - it opts an image-forward content tile out of the HOVER wash while press feedback, the focus ring, cursor intent, and hit testing keep their own channels; on a non-interactive element it would be silently inert";
1217
+
1216
1218
  /// The `overscroll` attribute's closed value vocabulary: the member names
1217
1219
  /// of `canvas.WidgetOverscroll`, mirrored as data here (this layer stays
1218
1220
  /// std-only) with a lockstep test in ui_markup_view_tests.zig holding the
@@ -1350,6 +1352,15 @@ pub fn anchorElement(name: []const u8) bool {
1350
1352
  return nameInList(name, &known_anchor_element_names);
1351
1353
  }
1352
1354
 
1355
+ /// Whether the engine hit-tests this element's widget kind — the surface
1356
+ /// the hover/press wash ladder exists on, and so the scope of the
1357
+ /// `quiet-hover` knob (registry `hit_target`; composites resolve through
1358
+ /// their library views and are out of scope).
1359
+ pub fn hitTargetElement(name: []const u8) bool {
1360
+ const entry = schema.elementByName(name) orelse return false;
1361
+ return entry.rule_hook == null and entry.hit_target;
1362
+ }
1363
+
1353
1364
  pub fn dismissEventElement(name: []const u8) bool {
1354
1365
  return nameInList(name, &known_dismiss_element_names);
1355
1366
  }
@@ -1832,7 +1843,7 @@ pub const chart_display_only_message = "chart is display-only - presses fall thr
1832
1843
  pub const series_parent_message = "series is only allowed inside a chart";
1833
1844
  pub const series_attr_message = "unknown attribute for series - it takes kind, values, color, and label";
1834
1845
  pub const series_kind_message = "series kind takes a literal: line, area, or bar (area is a line filled to the baseline; band envelopes need a paired lower-edge slice per point and stay with the Zig builder, ui.chart)";
1835
- pub const series_values_message = "series requires a values attribute with one {binding} naming a []const f32 iterable (a model field, pub decl, or fn - the same sources for each accepts); pad the window's leading gap with NaN samples, which draw nothing";
1846
+ pub const series_values_message = "series requires a values attribute with one {binding} naming a []const f32 or []const f64 iterable (a model field, pub decl, or fn - the same sources for each accepts; transpiled TS number arrays are f64); pad the window's leading gap with NaN samples, which draw nothing";
1836
1847
  pub const series_color_message = "series color takes a literal color token name (a canvas ColorTokens field, e.g. accent, info, success, text_muted)";
1837
1848
  pub const series_label_message = "series label expects text (a literal or one {binding}) - it names the series in the chart's semantics summary";
1838
1849
  pub const series_children_message = "series is a leaf - it takes no children; the values binding carries its data";
@@ -3132,6 +3143,14 @@ fn validateNode(document: MarkupDocument, node: MarkupNode, parent_element: ?[]c
3132
3143
  }
3133
3144
  }
3134
3145
  }
3146
+ if (std.mem.eql(u8, attribute.name, "quiet-hover")) {
3147
+ // The hover wash exists only on hit-tested elements:
3148
+ // anywhere else the knob is silently inert (same
3149
+ // policy as overscroll off scroll).
3150
+ if (!hitTargetElement(node.name)) {
3151
+ return attrError(node, attribute, quiet_hover_element_message);
3152
+ }
3153
+ }
3135
3154
  if (std.mem.eql(u8, attribute.name, "resize-duration")) {
3136
3155
  // The layout tween exists only where a fraction can
3137
3156
  // move: anywhere but a split the option is silently