@native-sdk/cli 0.7.1 → 0.8.0
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.
- package/build/app.zig +273 -65
- package/build/ts_run.mjs +6 -8
- package/build.zig +341 -361
- package/native-sdk.d.ts +6 -3
- package/package.json +13 -11
- package/packages/core/compile-surface/core.ts +559 -0
- package/packages/core/package-lock.json +375 -12
- package/packages/core/package.json +9 -6
- package/packages/core/scripts/compiler_typecheck.mjs +58 -0
- package/packages/core/scripts/gen_case_tables.mjs +130 -0
- package/packages/core/scripts/gen_declarations.mjs +97 -0
- package/packages/core/scripts/run_external_core_compiler.mjs +108 -0
- package/packages/core/scripts/stage_external_core.mjs +148 -0
- package/packages/core/sdk/core.d.ts +363 -0
- package/packages/core/sdk/events.d.ts +65 -0
- package/packages/core/sdk/text.d.ts +51 -0
- package/packages/core/src/checker.ts +3 -3
- package/packages/core/src/cli.ts +40 -38
- package/packages/core/src/contract.ts +749 -0
- package/packages/core/src/devhost.ts +4 -3
- package/packages/core/src/diagnostics.ts +5 -7
- package/packages/core/src/{transpile.ts → frontend.ts} +38 -50
- package/packages/core/src/infer.ts +1 -1
- package/packages/core/src/typed_ast.ts +16 -15
- package/packages/core/src/wyhash.ts +79 -0
- package/skill-data/native-ui/SKILL.md +4 -2
- package/skill-data/ts-core/SKILL.md +29 -29
- package/src/platform/macos/appkit_host.m +51 -3
- package/src/platform/types.zig +4 -0
- package/src/platform/windows/gpu_surface_renderer.cpp +2280 -0
- package/src/platform/windows/gpu_surface_renderer.h +86 -0
- package/src/platform/windows/root.zig +298 -20
- package/src/platform/windows/webview2_host.cpp +343 -33
- package/src/primitives/canvas/code.zig +50 -0
- package/src/primitives/canvas/code_tests.zig +174 -1
- package/src/primitives/canvas/frame.zig +45 -1
- package/src/primitives/canvas/gpu.zig +6 -0
- package/src/primitives/canvas/render_tests.zig +93 -0
- package/src/primitives/canvas/root.zig +2 -0
- package/src/primitives/canvas/serialization.zig +150 -21
- package/src/primitives/canvas/themes/geist.zig +51 -5
- package/src/primitives/canvas/tokens.zig +33 -4
- package/src/primitives/canvas/ui.zig +52 -7
- package/src/primitives/canvas/ui_markup.zig +38 -1
- package/src/primitives/canvas/ui_markup_compiled.zig +28 -0
- package/src/primitives/canvas/ui_markup_contract.zig +9 -0
- package/src/primitives/canvas/ui_markup_view.zig +28 -0
- package/src/primitives/canvas/ui_markup_view_tests.zig +10 -2
- package/src/primitives/canvas/ui_schema.zig +5 -0
- package/src/primitives/canvas/ui_schema_tests.zig +4 -3
- package/src/primitives/canvas/ui_tests.zig +14 -0
- package/src/primitives/canvas/widget_builtin_tests.zig +513 -13
- package/src/primitives/canvas/widget_invalidation.zig +11 -1
- package/src/primitives/canvas/widget_layout.zig +260 -21
- package/src/primitives/canvas/widget_metrics.zig +45 -9
- package/src/primitives/canvas/widget_render.zig +220 -70
- package/src/primitives/canvas/widget_render_controls.zig +79 -21
- package/src/primitives/canvas/widget_render_style.zig +52 -8
- package/src/primitives/canvas/widget_text_input.zig +2 -0
- package/src/primitives/canvas/widgets.zig +53 -2
- package/src/runtime/canvas_frame.zig +60 -7
- package/src/runtime/canvas_frame_invalidation_tests.zig +80 -0
- package/src/runtime/canvas_frame_packet_tests.zig +83 -9
- package/src/runtime/canvas_frame_patch_tests.zig +16 -0
- package/src/runtime/canvas_images.zig +8 -2
- package/src/runtime/canvas_widget_clipboard_tests.zig +1 -1
- package/src/runtime/canvas_widget_runtime.zig +11 -8
- package/src/runtime/effects.zig +6 -0
- package/src/runtime/effects_tests.zig +30 -0
- package/src/runtime/gpu_surface_events.zig +38 -7
- package/src/runtime/media_surface_tests.zig +1 -1
- package/src/runtime/runtime_event_tests.zig +74 -0
- package/src/runtime/ts_core_host.zig +38 -38
- package/src/runtime/ts_ui_app.zig +12 -12
- package/src/runtime/ui_app.zig +10 -8
- package/src/runtime/ui_app_tests.zig +67 -0
- package/src/runtime/view.zig +6 -0
- package/src/runtime/view_canvas.zig +15 -0
- package/src/runtime/view_widget_text.zig +6 -4
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/manifest.zig +32 -0
- package/src/tooling/raw_manifest.zig +4 -0
- package/src/tooling/templates.zig +34 -26
- package/src/tooling/ts_core.zig +55 -34
- package/src/tooling/verbs.zig +1 -1
- package/tools/corewire/core_abi.zig +169 -0
- package/tools/corewire/emit.zig +2418 -0
- package/tools/corewire/emit_facade.zig +3984 -0
- package/tools/corewire/emit_profile.zig +501 -0
- package/tools/corewire/main.zig +561 -0
- package/tools/corewire/shim_rt.zig +632 -0
- package/tools/corewire/sidecar.zig +2507 -0
- package/packages/core/rt/rt.zig +0 -1986
- package/packages/core/src/emitter.ts +0 -11898
|
@@ -94,6 +94,16 @@ pub fn designTokens(color_scheme: ColorScheme, contrast: ColorContrast) DesignTo
|
|
|
94
94
|
// the primary ink under the active label (see the tabs
|
|
95
95
|
// entries in `controlTokens` below).
|
|
96
96
|
.tabs_indicator_thickness = 2,
|
|
97
|
+
// Primary Tabs are a 50px, full-width ruled row. Each
|
|
98
|
+
// trigger hugs 14px regular text with 2px shoulders and the
|
|
99
|
+
// list adds no pill-style outer inset; these fields are read
|
|
100
|
+
// only by the underline register, so house tabs keep their
|
|
101
|
+
// existing control ladder and 3px container hug.
|
|
102
|
+
.tabs_list_inset = 0,
|
|
103
|
+
.tabs_list_full_width = true,
|
|
104
|
+
.tabs_trigger_height = 50,
|
|
105
|
+
.tabs_trigger_inset = 2,
|
|
106
|
+
.tabs_label_size_step = 1,
|
|
97
107
|
// The underline register's inter-trigger gap: measured at a
|
|
98
108
|
// 24px flex gap between triggers on the reference strip
|
|
99
109
|
// (28px optical once each trigger's 2px horizontal padding
|
|
@@ -333,17 +343,34 @@ fn highContrastDark() ColorTokens {
|
|
|
333
343
|
}
|
|
334
344
|
|
|
335
345
|
/// The pack's control tables: the treatments that are MORE than a
|
|
336
|
-
/// palette swap. Geist's disabled register is a color SWAP
|
|
337
|
-
/// chip under gray-700 ink
|
|
338
|
-
///
|
|
346
|
+
/// palette swap. Geist's main disabled register is a color SWAP
|
|
347
|
+
/// (gray-100 chip under gray-700 ink with a gray-400 edge), while its
|
|
348
|
+
/// tertiary button is that chip at half opacity with primary ink. Its
|
|
349
|
+
/// destructive button is a FILLED error block
|
|
339
350
|
/// rather than the house quiet chip, and its floating surfaces sit on
|
|
340
351
|
/// the 12px corner while controls hold 6.
|
|
341
352
|
fn controlTokens(color_scheme: ColorScheme, contrast: ColorContrast) ControlTokens {
|
|
342
353
|
const colors = colorTokens(color_scheme, contrast);
|
|
343
|
-
// Disabled
|
|
344
|
-
// hex in both schemes
|
|
354
|
+
// Disabled register: gray-100 fill under gray-700 #8f8f8f ink (the
|
|
355
|
+
// same hex in both schemes), with the solid gray-400 edge used by
|
|
356
|
+
// bordered variants.
|
|
345
357
|
const disabled_background = colors.disabled;
|
|
346
358
|
const disabled_foreground = Color.rgb8(143, 143, 143);
|
|
359
|
+
const disabled_border: ?Color = switch (contrast) {
|
|
360
|
+
.standard => switch (color_scheme) {
|
|
361
|
+
.light => Color.rgb8(235, 235, 235),
|
|
362
|
+
.dark => Color.rgb8(31, 31, 31),
|
|
363
|
+
},
|
|
364
|
+
// High contrast keeps its louder palette edge.
|
|
365
|
+
.high => null,
|
|
366
|
+
};
|
|
367
|
+
// Tertiary is the one exception in the reference: gray-100 and the
|
|
368
|
+
// primary ink are composited together at 50% over the page. The
|
|
369
|
+
// renderer's opacity is per command, so state the equivalent opaque
|
|
370
|
+
// pair here; glyph coverage then blends between the same two final
|
|
371
|
+
// colors as the reference layer.
|
|
372
|
+
const tertiary_disabled_background = compositeOver(colors.disabled, colors.background, 0.5);
|
|
373
|
+
const tertiary_disabled_foreground = compositeOver(colors.text, colors.background, 0.5);
|
|
347
374
|
// The filled error button: solid red under white text, hover one
|
|
348
375
|
// step deeper in light (red-900 #d8001b) and one step brighter in
|
|
349
376
|
// dark (red-700 #f13242) — feedback moves TOWARD the scheme's ink.
|
|
@@ -380,6 +407,10 @@ fn controlTokens(color_scheme: ColorScheme, contrast: ColorContrast) ControlToke
|
|
|
380
407
|
.disabled_background = disabled_background,
|
|
381
408
|
.disabled_foreground = disabled_foreground,
|
|
382
409
|
},
|
|
410
|
+
.button_ghost = .{
|
|
411
|
+
.disabled_background = tertiary_disabled_background,
|
|
412
|
+
.disabled_foreground = tertiary_disabled_foreground,
|
|
413
|
+
},
|
|
383
414
|
.button_destructive = .{
|
|
384
415
|
.background = destructive_rest,
|
|
385
416
|
.hover_background = destructive_hover,
|
|
@@ -388,6 +419,7 @@ fn controlTokens(color_scheme: ColorScheme, contrast: ColorContrast) ControlToke
|
|
|
388
419
|
.disabled_foreground = disabled_foreground,
|
|
389
420
|
.stroke_width = 0,
|
|
390
421
|
},
|
|
422
|
+
.button_disabled_border = disabled_border,
|
|
391
423
|
// The slider is the one control whose fill keeps a hue in the
|
|
392
424
|
// monochrome register: rail on gray-200, range in blue-700 (the
|
|
393
425
|
// same #0072f5 step in both schemes), and a paper-white
|
|
@@ -503,3 +535,17 @@ fn controlTokens(color_scheme: ColorScheme, contrast: ColorContrast) ControlToke
|
|
|
503
535
|
.panel = .{ .radius = surface_radius },
|
|
504
536
|
};
|
|
505
537
|
}
|
|
538
|
+
|
|
539
|
+
/// Composite one opaque theme color over another at `opacity`. Used for
|
|
540
|
+
/// Geist's tertiary disabled layer, whose reference opacity applies to
|
|
541
|
+
/// the whole chip while the current display list carries opacity on
|
|
542
|
+
/// individual commands.
|
|
543
|
+
fn compositeOver(foreground: Color, background: Color, opacity: f32) Color {
|
|
544
|
+
const alpha = std.math.clamp(opacity, 0, 1);
|
|
545
|
+
return Color.rgba(
|
|
546
|
+
foreground.r * alpha + background.r * (1 - alpha),
|
|
547
|
+
foreground.g * alpha + background.g * (1 - alpha),
|
|
548
|
+
foreground.b * alpha + background.b * (1 - alpha),
|
|
549
|
+
1,
|
|
550
|
+
);
|
|
551
|
+
}
|
|
@@ -572,6 +572,21 @@ pub const ControlMetricTokens = struct {
|
|
|
572
572
|
/// active trigger's label. Unused by the house `.pill` register —
|
|
573
573
|
/// the default only matters once a theme opts into underlines.
|
|
574
574
|
tabs_indicator_thickness: f32 = 2,
|
|
575
|
+
/// Geometry of an `.underline` tab strip. These values are ignored
|
|
576
|
+
/// by the house `.pill` register, whose container inset and trigger
|
|
577
|
+
/// sizing stay on the ordinary control ladder. An underline strip
|
|
578
|
+
/// uses a full-height 50px trigger, 2px of horizontal breathing room
|
|
579
|
+
/// around its content, no outer list inset, and a one-step lift from
|
|
580
|
+
/// the label type rung (13 -> 14 in the Geist pack).
|
|
581
|
+
tabs_list_inset: f32 = 0,
|
|
582
|
+
/// Whether a primary `.underline` TabsList expands across its parent.
|
|
583
|
+
/// Underline styling alone does not imply this layout policy: packs
|
|
584
|
+
/// opt in explicitly, so a custom underline theme keeps the authored
|
|
585
|
+
/// hug width unless it requests the full-width ruled-row treatment.
|
|
586
|
+
tabs_list_full_width: bool = false,
|
|
587
|
+
tabs_trigger_height: f32 = 50,
|
|
588
|
+
tabs_trigger_inset: f32 = 2,
|
|
589
|
+
tabs_label_size_step: f32 = 1,
|
|
575
590
|
/// The inter-trigger gap of the `.underline` tab register (see
|
|
576
591
|
/// `ControlTokens.tabs_indicator`), applied only when the author
|
|
577
592
|
/// left the strip's gap at 0. Unused by the house `.pill` register —
|
|
@@ -1124,10 +1139,12 @@ pub const ControlVisualTokens = struct {
|
|
|
1124
1139
|
/// `active_background`, then to the state-formula washes — so a
|
|
1125
1140
|
/// theme that wants press and on-state to differ states both.
|
|
1126
1141
|
pressed_background: ?Color = null,
|
|
1127
|
-
/// Disabled fill and ink. Null keeps the
|
|
1128
|
-
///
|
|
1129
|
-
///
|
|
1130
|
-
///
|
|
1142
|
+
/// Disabled fill and ink. Null keeps the house treatment:
|
|
1143
|
+
/// the rest color at `StateTokens.disabled_alpha`, except that a
|
|
1144
|
+
/// filled primary precomposites its knockout ink over the page at
|
|
1145
|
+
/// that strength so the label does not double-fade through the
|
|
1146
|
+
/// already-muted fill. Themes whose disabled treatment is a color
|
|
1147
|
+
/// SWAP (a flat gray chip under gray text) state the pair here.
|
|
1131
1148
|
disabled_background: ?Color = null,
|
|
1132
1149
|
disabled_foreground: ?Color = null,
|
|
1133
1150
|
foreground: ?Color = null,
|
|
@@ -1147,6 +1164,11 @@ pub const ControlTokens = struct {
|
|
|
1147
1164
|
button_outline: ControlVisualTokens = .{},
|
|
1148
1165
|
button_ghost: ControlVisualTokens = .{},
|
|
1149
1166
|
button_destructive: ControlVisualTokens = .{},
|
|
1167
|
+
/// Shared disabled edge for the button variants that retain an
|
|
1168
|
+
/// outline. Filled variants drop their implicit edge so their disabled
|
|
1169
|
+
/// body alone defines the silhouette; ghost remains borderless. Null
|
|
1170
|
+
/// keeps the house opacity wash.
|
|
1171
|
+
button_disabled_border: ?Color = null,
|
|
1150
1172
|
toggle_button: ControlVisualTokens = .{},
|
|
1151
1173
|
accordion: ControlVisualTokens = .{},
|
|
1152
1174
|
alert: ControlVisualTokens = .{},
|
|
@@ -1381,6 +1403,11 @@ pub const ControlMetricTokenOverrides = struct {
|
|
|
1381
1403
|
slider_thumb_width: ?f32 = null,
|
|
1382
1404
|
slider_thumb_height: ?f32 = null,
|
|
1383
1405
|
tabs_indicator_thickness: ?f32 = null,
|
|
1406
|
+
tabs_list_inset: ?f32 = null,
|
|
1407
|
+
tabs_list_full_width: ?bool = null,
|
|
1408
|
+
tabs_trigger_height: ?f32 = null,
|
|
1409
|
+
tabs_trigger_inset: ?f32 = null,
|
|
1410
|
+
tabs_label_size_step: ?f32 = null,
|
|
1384
1411
|
tabs_gap: ?f32 = null,
|
|
1385
1412
|
button_group_gap: ?f32 = null,
|
|
1386
1413
|
spinner_style: ?SpinnerStyleToken = null,
|
|
@@ -1528,6 +1555,7 @@ pub const ControlTokenOverrides = struct {
|
|
|
1528
1555
|
button_outline: ControlVisualTokenOverrides = .{},
|
|
1529
1556
|
button_ghost: ControlVisualTokenOverrides = .{},
|
|
1530
1557
|
button_destructive: ControlVisualTokenOverrides = .{},
|
|
1558
|
+
button_disabled_border: ?Color = null,
|
|
1531
1559
|
toggle_button: ControlVisualTokenOverrides = .{},
|
|
1532
1560
|
accordion: ControlVisualTokenOverrides = .{},
|
|
1533
1561
|
alert: ControlVisualTokenOverrides = .{},
|
|
@@ -1576,6 +1604,7 @@ pub const ControlTokenOverrides = struct {
|
|
|
1576
1604
|
next.button_outline = self.button_outline.apply(next.button_outline);
|
|
1577
1605
|
next.button_ghost = self.button_ghost.apply(next.button_ghost);
|
|
1578
1606
|
next.button_destructive = self.button_destructive.apply(next.button_destructive);
|
|
1607
|
+
if (self.button_disabled_border) |button_disabled_border| next.button_disabled_border = button_disabled_border;
|
|
1579
1608
|
next.toggle_button = self.toggle_button.apply(next.toggle_button);
|
|
1580
1609
|
next.accordion = self.accordion.apply(next.accordion);
|
|
1581
1610
|
next.alert = self.alert.apply(next.alert);
|
|
@@ -2321,6 +2321,12 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2321
2321
|
/// Prefix each logical source line with a muted, monospace
|
|
2322
2322
|
/// number. Off by default.
|
|
2323
2323
|
line_numbers: bool = false,
|
|
2324
|
+
/// One-based logical source lines rendered with Geist Code
|
|
2325
|
+
/// Block's green added-line wash and a renderer-owned `+`.
|
|
2326
|
+
added_lines: []const usize = &.{},
|
|
2327
|
+
/// One-based logical source lines rendered with Geist Code
|
|
2328
|
+
/// Block's red removed-line wash and a renderer-owned `-`.
|
|
2329
|
+
removed_lines: []const usize = &.{},
|
|
2324
2330
|
/// Word-wrap long source lines. `false` keeps logical lines
|
|
2325
2331
|
/// intact inside one horizontal scroll region.
|
|
2326
2332
|
wrap: bool = true,
|
|
@@ -2343,6 +2349,20 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2343
2349
|
const terminal_editor_line = options.editable and source.len > 0 and source[source.len - 1] == '\n';
|
|
2344
2350
|
const numbered = options.line_numbers and line_count - @intFromBool(terminal_editor_line) <=
|
|
2345
2351
|
(if (options.editable) max_editable_code_lines else max_code_lines);
|
|
2352
|
+
const added_lines = self.codeLineMask(options.added_lines);
|
|
2353
|
+
const removed_lines = self.codeLineMask(options.removed_lines);
|
|
2354
|
+
if (added_lines & removed_lines != 0) self.failed = true;
|
|
2355
|
+
// Read-only presentation stays one bounded paragraph only up to
|
|
2356
|
+
// the same logical-line ceiling as its renderer-owned numbers.
|
|
2357
|
+
// Longer sources keep every byte and omit diff decoration.
|
|
2358
|
+
const diff_bounded = options.editable or line_count <= max_code_lines;
|
|
2359
|
+
const displayed_added_lines = if (diff_bounded) added_lines else 0;
|
|
2360
|
+
const displayed_removed_lines = if (diff_bounded) removed_lines else 0;
|
|
2361
|
+
const decorated = displayed_added_lines != 0 or displayed_removed_lines != 0;
|
|
2362
|
+
const diff_lines: ?canvas.CodeDiffLines = if (decorated) .{
|
|
2363
|
+
.added = displayed_added_lines,
|
|
2364
|
+
.removed = displayed_removed_lines,
|
|
2365
|
+
} else null;
|
|
2346
2366
|
if (options.editable) {
|
|
2347
2367
|
const retained = if (options.wrap) blk: {
|
|
2348
2368
|
// Wrapped editor geometry still uses the bounded span
|
|
@@ -2388,13 +2408,20 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2388
2408
|
@intCast(decimalDigits(line_count))
|
|
2389
2409
|
else
|
|
2390
2410
|
0;
|
|
2411
|
+
if (diff_lines) |lines| editor.widget.setCodeDiffLines(lines);
|
|
2391
2412
|
editor.widget.code_editor = true;
|
|
2392
2413
|
editor.widget.code_language = options.language;
|
|
2393
2414
|
editor.widget.layout.clip_content = true;
|
|
2394
2415
|
return editor;
|
|
2395
2416
|
}
|
|
2396
|
-
const content = if (numbered)
|
|
2397
|
-
self.
|
|
2417
|
+
const content = if (numbered or decorated)
|
|
2418
|
+
self.decoratedCodeParagraph(
|
|
2419
|
+
source,
|
|
2420
|
+
options.language,
|
|
2421
|
+
options.wrap,
|
|
2422
|
+
if (numbered) @intCast(decimalDigits(line_count)) else 0,
|
|
2423
|
+
diff_lines,
|
|
2424
|
+
)
|
|
2398
2425
|
else
|
|
2399
2426
|
self.codeParagraphChunks(source, options.language, options.wrap);
|
|
2400
2427
|
const body = if (options.wrap)
|
|
@@ -2440,19 +2467,34 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2440
2467
|
/// owns its muted gutter, so marker digits never enter retained
|
|
2441
2468
|
/// text or clipboard bytes; it derives each marker baseline from
|
|
2442
2469
|
/// this paragraph's real wrapped layout.
|
|
2443
|
-
fn
|
|
2470
|
+
fn decoratedCodeParagraph(
|
|
2444
2471
|
self: *Self,
|
|
2445
2472
|
source: []const u8,
|
|
2446
2473
|
language: code_model.Language,
|
|
2447
2474
|
wrap: bool,
|
|
2448
|
-
|
|
2475
|
+
line_number_digits: u8,
|
|
2476
|
+
diff_lines: ?canvas.CodeDiffLines,
|
|
2449
2477
|
) Node {
|
|
2450
2478
|
var state: code_model.HighlightState = .{};
|
|
2451
2479
|
var source_node = self.codeParagraphWithState(source, language, wrap, 1, &state, null);
|
|
2452
|
-
source_node.widget.code_line_number_digits =
|
|
2480
|
+
source_node.widget.code_line_number_digits = line_number_digits;
|
|
2481
|
+
if (diff_lines) |lines| source_node.widget.setCodeDiffLines(lines);
|
|
2453
2482
|
return source_node;
|
|
2454
2483
|
}
|
|
2455
2484
|
|
|
2485
|
+
fn codeLineMask(self: *Self, lines: []const usize) u128 {
|
|
2486
|
+
var mask: u128 = 0;
|
|
2487
|
+
for (lines) |line| {
|
|
2488
|
+
if (line == 0 or line > code_model.max_diff_lines) {
|
|
2489
|
+
self.failed = true;
|
|
2490
|
+
continue;
|
|
2491
|
+
}
|
|
2492
|
+
const shift: u7 = @intCast(line - 1);
|
|
2493
|
+
mask |= @as(u128, 1) << shift;
|
|
2494
|
+
}
|
|
2495
|
+
return mask;
|
|
2496
|
+
}
|
|
2497
|
+
|
|
2456
2498
|
/// Keep ordinary code in one text widget so static selection and copy
|
|
2457
2499
|
/// span logical lines. Only split when the paragraph layout's bounded
|
|
2458
2500
|
/// line capacity requires it; every chunk remains independently
|
|
@@ -2521,7 +2563,7 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
2521
2563
|
budget,
|
|
2522
2564
|
);
|
|
2523
2565
|
chunks[chunk_index].static_text_group_fingerprint = group_fingerprint;
|
|
2524
|
-
chunks[chunk_index].widget.static_text_group_offset = chunk_start;
|
|
2566
|
+
chunks[chunk_index].widget.static_text_group_offset = @intCast(chunk_start);
|
|
2525
2567
|
chunk_index += 1;
|
|
2526
2568
|
chunk_start = chunk_end;
|
|
2527
2569
|
}
|
|
@@ -3572,7 +3614,10 @@ pub fn Ui(comptime Msg: type) type {
|
|
|
3572
3614
|
/// default gap. Explicit spacing always wins for its own field.
|
|
3573
3615
|
fn applyKindDefaultLayout(kind: WidgetKind, options: ElementOptions, layout: *canvas.WidgetLayoutStyle) void {
|
|
3574
3616
|
const defaults = canvas.widgetKindDefaultLayout(kind, options.size) orelse return;
|
|
3575
|
-
if (options.padding == 0)
|
|
3617
|
+
if (options.padding == 0) {
|
|
3618
|
+
layout.padding = defaults.padding;
|
|
3619
|
+
layout.padding_is_kind_default = true;
|
|
3620
|
+
}
|
|
3576
3621
|
if (options.gap == 0) layout.gap = defaults.gap;
|
|
3577
3622
|
if (layout.cross_alignment == .stretch and defaults.cross_alignment != .stretch) {
|
|
3578
3623
|
layout.cross_alignment = defaults.cross_alignment;
|
|
@@ -1868,8 +1868,9 @@ pub const markdown_on_details_message = "on-details takes a bare Msg tag whose p
|
|
|
1868
1868
|
pub const markdown_details_expanded_message = "details-expanded takes one {binding} naming a []const bool iterable (a model field, pub decl, or fn - the same sources for each accepts)";
|
|
1869
1869
|
pub const code_source_message = "code requires a source attribute with one {binding} naming the source text (a []const u8 field or fn - arena fns work)";
|
|
1870
1870
|
pub const code_children_message = "code takes no children or text content - the source binding provides the code";
|
|
1871
|
-
pub const code_attr_message = "unknown attribute for code - it takes source, language, editable, on-input, line-numbers, wrap, width, height, min-width, grow, key, global-key, and label";
|
|
1871
|
+
pub const code_attr_message = "unknown attribute for code - it takes source, language, editable, on-input, line-numbers, added-lines, removed-lines, wrap, width, height, min-width, grow, key, global-key, and label";
|
|
1872
1872
|
pub const code_language_message = "language takes a literal lexer name: plain, zig, javascript/js/mjs, typescript/ts, jsx/tsx, json, yaml/yml, shell/sh/bash/zsh, python/py, rust/rs, c/cpp/c++/csharp/java/kotlin/swift, go, html/xml/svg, css/scss/less, sql, or markdown/md";
|
|
1873
|
+
pub const code_diff_lines_message = "added-lines and removed-lines take one-based lines/ranges up to 128 (for example \"2-4, 7\") or one text {binding} producing that form";
|
|
1873
1874
|
pub const stepper_active_message = "stepper requires an active attribute (a number or one {binding}) naming the active step index";
|
|
1874
1875
|
pub const stepper_attr_message = "unknown attribute for stepper - it takes active, key, global-key, and label";
|
|
1875
1876
|
pub const stepper_children_message = "stepper takes only step children (each step is a text leaf: <step>Work</step>)";
|
|
@@ -2233,6 +2234,27 @@ fn codeLanguageName(name: []const u8) bool {
|
|
|
2233
2234
|
return false;
|
|
2234
2235
|
}
|
|
2235
2236
|
|
|
2237
|
+
fn codeLineNumberSpec(spec_raw: []const u8) bool {
|
|
2238
|
+
const spec = std.mem.trim(u8, spec_raw, " \t\r\n");
|
|
2239
|
+
if (spec.len == 0) return true;
|
|
2240
|
+
var pieces = std.mem.splitScalar(u8, spec, ',');
|
|
2241
|
+
while (pieces.next()) |piece_raw| {
|
|
2242
|
+
const piece = std.mem.trim(u8, piece_raw, " \t\r\n");
|
|
2243
|
+
if (piece.len == 0) return false;
|
|
2244
|
+
const dash = std.mem.indexOfScalar(u8, piece, '-');
|
|
2245
|
+
const first_text = std.mem.trim(u8, if (dash) |index| piece[0..index] else piece, " \t");
|
|
2246
|
+
const last_text = if (dash) |index| std.mem.trim(u8, piece[index + 1 ..], " \t") else first_text;
|
|
2247
|
+
if (first_text.len == 0 or last_text.len == 0) return false;
|
|
2248
|
+
if (dash) |index| {
|
|
2249
|
+
if (std.mem.indexOfScalar(u8, piece[index + 1 ..], '-') != null) return false;
|
|
2250
|
+
}
|
|
2251
|
+
const first = std.fmt.parseInt(usize, first_text, 10) catch return false;
|
|
2252
|
+
const last = std.fmt.parseInt(usize, last_text, 10) catch return false;
|
|
2253
|
+
if (first == 0 or last < first or last > 128) return false;
|
|
2254
|
+
}
|
|
2255
|
+
return true;
|
|
2256
|
+
}
|
|
2257
|
+
|
|
2236
2258
|
/// `<code>` is a source-bound leaf lowered through `Ui.code`: syntax
|
|
2237
2259
|
/// language is static markup, while flags and layout values can bind.
|
|
2238
2260
|
fn validateCode(node: MarkupNode) ?MarkupErrorInfo {
|
|
@@ -2252,6 +2274,21 @@ fn validateCode(node: MarkupNode) ?MarkupErrorInfo {
|
|
|
2252
2274
|
}
|
|
2253
2275
|
continue;
|
|
2254
2276
|
}
|
|
2277
|
+
if (std.mem.eql(u8, attribute.name, "added-lines") or
|
|
2278
|
+
std.mem.eql(u8, attribute.name, "removed-lines"))
|
|
2279
|
+
{
|
|
2280
|
+
if (attrExpressionError(attribute.value, code_diff_lines_message)) |message| {
|
|
2281
|
+
return attrError(node, attribute, message);
|
|
2282
|
+
}
|
|
2283
|
+
const expression = parseAttrExpression(attribute.value);
|
|
2284
|
+
if (expression == null or expression.? == .equals) {
|
|
2285
|
+
return attrError(node, attribute, code_diff_lines_message);
|
|
2286
|
+
}
|
|
2287
|
+
if (expression.? == .literal and !codeLineNumberSpec(expression.?.literal)) {
|
|
2288
|
+
return attrError(node, attribute, code_diff_lines_message);
|
|
2289
|
+
}
|
|
2290
|
+
continue;
|
|
2291
|
+
}
|
|
2255
2292
|
if (std.mem.eql(u8, attribute.name, "line-numbers") or
|
|
2256
2293
|
std.mem.eql(u8, attribute.name, "wrap") or
|
|
2257
2294
|
std.mem.eql(u8, attribute.name, "editable"))
|
|
@@ -791,6 +791,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
791
791
|
std.mem.eql(u8, attribute.name, "editable") or
|
|
792
792
|
std.mem.eql(u8, attribute.name, "on-input") or
|
|
793
793
|
std.mem.eql(u8, attribute.name, "line-numbers") or
|
|
794
|
+
std.mem.eql(u8, attribute.name, "added-lines") or
|
|
795
|
+
std.mem.eql(u8, attribute.name, "removed-lines") or
|
|
794
796
|
std.mem.eql(u8, attribute.name, "wrap") or
|
|
795
797
|
std.mem.eql(u8, attribute.name, "width") or
|
|
796
798
|
std.mem.eql(u8, attribute.name, "height") or
|
|
@@ -815,6 +817,8 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
815
817
|
};
|
|
816
818
|
|
|
817
819
|
var options: Ui.CodeOptions = .{};
|
|
820
|
+
var added_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
821
|
+
var removed_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
818
822
|
if (comptime (node.attr("language") != null)) {
|
|
819
823
|
const name = comptime blk: {
|
|
820
824
|
const expression = markup.parseAttrExpression(node.attr("language").?) orelse fail(node, markup.code_language_message);
|
|
@@ -827,6 +831,20 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
827
831
|
if (comptime (node.attr("line-numbers") != null)) {
|
|
828
832
|
options.line_numbers = videoFlagValue(node, entries, comptime node.attr("line-numbers").?, ui, model, scope);
|
|
829
833
|
}
|
|
834
|
+
if (comptime (node.attr("added-lines") != null)) {
|
|
835
|
+
const spec = codeLineSpecAttr(node, entries, comptime node.attr("added-lines").?, ui, model, scope);
|
|
836
|
+
options.added_lines = canvas.code.parseLineNumberSpec(spec, &added_lines_storage) orelse blk: {
|
|
837
|
+
ui.failed = true;
|
|
838
|
+
break :blk added_lines_storage[0..0];
|
|
839
|
+
};
|
|
840
|
+
}
|
|
841
|
+
if (comptime (node.attr("removed-lines") != null)) {
|
|
842
|
+
const spec = codeLineSpecAttr(node, entries, comptime node.attr("removed-lines").?, ui, model, scope);
|
|
843
|
+
options.removed_lines = canvas.code.parseLineNumberSpec(spec, &removed_lines_storage) orelse blk: {
|
|
844
|
+
ui.failed = true;
|
|
845
|
+
break :blk removed_lines_storage[0..0];
|
|
846
|
+
};
|
|
847
|
+
}
|
|
830
848
|
if (comptime (node.attr("editable") != null)) {
|
|
831
849
|
options.editable = videoFlagValue(node, entries, comptime node.attr("editable").?, ui, model, scope);
|
|
832
850
|
}
|
|
@@ -863,6 +881,16 @@ fn CompiledMarkupEngine(comptime ModelT: type, comptime MsgT: type, comptime res
|
|
|
863
881
|
return ui.code(options, source);
|
|
864
882
|
}
|
|
865
883
|
|
|
884
|
+
fn codeLineSpecAttr(comptime node: markup.MarkupNode, comptime entries: []const ScopeEntry, comptime raw: []const u8, ui: *Ui, model: *const ModelT, scope: anytype) []const u8 {
|
|
885
|
+
const expression = comptime (markup.parseAttrExpression(raw) orelse fail(node, markup.code_diff_lines_message));
|
|
886
|
+
if (comptime expression == .literal) return expression.literal;
|
|
887
|
+
comptime requireVariant(exprVariant(node, entries, raw), &.{.string}, node, markup.code_diff_lines_message);
|
|
888
|
+
return switch (evalExpr(node, entries, raw, ui, model, scope)) {
|
|
889
|
+
.string => |text| text,
|
|
890
|
+
else => runtimeFail([]const u8, ui),
|
|
891
|
+
};
|
|
892
|
+
}
|
|
893
|
+
|
|
866
894
|
fn markdownLinkConstructor(comptime node: markup.MarkupNode, comptime raw: []const u8) Ui.LinkMsgFn {
|
|
867
895
|
comptime {
|
|
868
896
|
@setEvalBranchQuota(10_000);
|
|
@@ -1356,6 +1356,15 @@ const Checker = struct {
|
|
|
1356
1356
|
_ = try self.attrKind(node, attribute, attribute.value);
|
|
1357
1357
|
continue;
|
|
1358
1358
|
}
|
|
1359
|
+
if (std.mem.eql(u8, attribute.name, "added-lines") or
|
|
1360
|
+
std.mem.eql(u8, attribute.name, "removed-lines"))
|
|
1361
|
+
{
|
|
1362
|
+
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1363
|
+
if (expression == .literal) continue;
|
|
1364
|
+
const kind = try self.attrKind(node, attribute, attribute.value);
|
|
1365
|
+
try self.requireAttrKind(node, attribute, kind, &.{.string}, markup.code_diff_lines_message);
|
|
1366
|
+
continue;
|
|
1367
|
+
}
|
|
1359
1368
|
if (std.mem.eql(u8, attribute.name, "on-input")) {
|
|
1360
1369
|
try self.checkMessageAttr(node, attribute);
|
|
1361
1370
|
continue;
|
|
@@ -807,6 +807,8 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
807
807
|
if (node.children.len != 0) return self.failNode(node.children[0], markup.code_children_message);
|
|
808
808
|
var options: Ui.CodeOptions = .{};
|
|
809
809
|
var source_text: ?[]const u8 = null;
|
|
810
|
+
var added_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
811
|
+
var removed_lines_storage: [canvas.code.max_diff_lines]usize = undefined;
|
|
810
812
|
for (node.attrs) |attribute| {
|
|
811
813
|
if (std.mem.eql(u8, attribute.name, "kind")) continue;
|
|
812
814
|
if (std.mem.eql(u8, attribute.name, "source")) {
|
|
@@ -829,6 +831,32 @@ pub fn MarkupView(comptime ModelT: type, comptime MsgT: type) type {
|
|
|
829
831
|
options.line_numbers = try self.codeFlagAttr(scope, node, attribute);
|
|
830
832
|
continue;
|
|
831
833
|
}
|
|
834
|
+
if (std.mem.eql(u8, attribute.name, "added-lines")) {
|
|
835
|
+
const typed = markup.parseAttrExpression(attribute.value) orelse
|
|
836
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
837
|
+
const spec = if (typed == .literal)
|
|
838
|
+
typed.literal
|
|
839
|
+
else switch (try self.evalAttrExpression(scope, node, attribute)) {
|
|
840
|
+
.string => |text| text,
|
|
841
|
+
else => return self.failNode(node, markup.code_diff_lines_message),
|
|
842
|
+
};
|
|
843
|
+
options.added_lines = canvas.code.parseLineNumberSpec(spec, &added_lines_storage) orelse
|
|
844
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
845
|
+
continue;
|
|
846
|
+
}
|
|
847
|
+
if (std.mem.eql(u8, attribute.name, "removed-lines")) {
|
|
848
|
+
const typed = markup.parseAttrExpression(attribute.value) orelse
|
|
849
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
850
|
+
const spec = if (typed == .literal)
|
|
851
|
+
typed.literal
|
|
852
|
+
else switch (try self.evalAttrExpression(scope, node, attribute)) {
|
|
853
|
+
.string => |text| text,
|
|
854
|
+
else => return self.failNode(node, markup.code_diff_lines_message),
|
|
855
|
+
};
|
|
856
|
+
options.removed_lines = canvas.code.parseLineNumberSpec(spec, &removed_lines_storage) orelse
|
|
857
|
+
return self.failNode(node, markup.code_diff_lines_message);
|
|
858
|
+
continue;
|
|
859
|
+
}
|
|
832
860
|
if (std.mem.eql(u8, attribute.name, "editable")) {
|
|
833
861
|
options.editable = try self.codeFlagAttr(scope, node, attribute);
|
|
834
862
|
continue;
|
|
@@ -1947,11 +1947,12 @@ pub const CodeModel = struct {
|
|
|
1947
1947
|
show_lines: bool = true,
|
|
1948
1948
|
wrap_code: bool = false,
|
|
1949
1949
|
editable_code: bool = false,
|
|
1950
|
+
added_spec: []const u8 = "2",
|
|
1950
1951
|
count: usize = 3,
|
|
1951
1952
|
};
|
|
1952
1953
|
|
|
1953
1954
|
pub const code_markup_source =
|
|
1954
|
-
\\<code source="{snippet}" language="tsx" editable="{editable_code}" on-input="edit" line-numbers="{show_lines}" wrap="{wrap_code}" width="240" label="Example code" />
|
|
1955
|
+
\\<code source="{snippet}" language="tsx" editable="{editable_code}" on-input="edit" line-numbers="{show_lines}" added-lines="{added_spec}" removed-lines="3" wrap="{wrap_code}" width="240" label="Example code" />
|
|
1955
1956
|
;
|
|
1956
1957
|
|
|
1957
1958
|
pub const CodeUi = canvas.Ui(CodeMsg);
|
|
@@ -1962,6 +1963,8 @@ pub fn handCodeView(ui: *CodeUi, model: *const CodeModel) CodeUi.Node {
|
|
|
1962
1963
|
.editable = model.editable_code,
|
|
1963
1964
|
.on_input = CodeUi.inputMsg(.edit),
|
|
1964
1965
|
.line_numbers = model.show_lines,
|
|
1966
|
+
.added_lines = &.{2},
|
|
1967
|
+
.removed_lines = &.{3},
|
|
1965
1968
|
.wrap = model.wrap_code,
|
|
1966
1969
|
.width = 240,
|
|
1967
1970
|
.semantics = .{ .label = "Example code" },
|
|
@@ -1995,7 +1998,9 @@ test "code markup builds the reusable component with opt-in numbers and horizont
|
|
|
1995
1998
|
try testing.expect(markup_tree.root.style.radius == null);
|
|
1996
1999
|
try testing.expectEqual(canvas.ScrollAxes.horizontal, findByKind(markup_tree.root, .scroll_view).?.scroll_axes);
|
|
1997
2000
|
const source = findByText(markup_tree.root, .text, model.snippet).?;
|
|
1998
|
-
try testing.expectEqual(@as(u8, 1), source.
|
|
2001
|
+
try testing.expectEqual(@as(u8, 1), source.codeLineNumberDigits());
|
|
2002
|
+
try testing.expectEqual(@as(u128, 1) << 1, source.codeDiffLines().?.added);
|
|
2003
|
+
try testing.expectEqual(@as(u128, 1) << 2, source.codeDiffLines().?.removed);
|
|
1999
2004
|
try testing.expectEqualStrings("Example code", markup_tree.root.semantics.label);
|
|
2000
2005
|
|
|
2001
2006
|
var editable_model = model;
|
|
@@ -2051,6 +2056,9 @@ test "code markup misuse reports the component's closed contract" {
|
|
|
2051
2056
|
.{ .source = "<code source=\"literal\" />", .message = canvas.ui_markup.code_source_message },
|
|
2052
2057
|
.{ .source = "<code source=\"{count}\" />", .message = canvas.ui_markup.code_source_message, .model_agnostic = false },
|
|
2053
2058
|
.{ .source = "<code source=\"{snippet}\" language=\"brainwave\" />", .message = canvas.ui_markup.code_language_message },
|
|
2059
|
+
.{ .source = "<code source=\"{snippet}\" added-lines=\"0\" />", .message = canvas.ui_markup.code_diff_lines_message },
|
|
2060
|
+
.{ .source = "<code source=\"{snippet}\" removed-lines=\"4-2\" />", .message = canvas.ui_markup.code_diff_lines_message },
|
|
2061
|
+
.{ .source = "<code source=\"{snippet}\" removed-lines=\"{count}\" />", .message = canvas.ui_markup.code_diff_lines_message, .model_agnostic = false },
|
|
2054
2062
|
.{ .source = "<code source=\"{snippet}\" padding=\"8\" />", .message = canvas.ui_markup.code_attr_message },
|
|
2055
2063
|
.{ .source = "<code source=\"{snippet}\">text</code>", .message = canvas.ui_markup.code_children_message },
|
|
2056
2064
|
};
|
|
@@ -571,6 +571,11 @@ pub const attrs = [_]AttrInfo{
|
|
|
571
571
|
// hierarchy without manufacturing nested layout containers. Zero (the
|
|
572
572
|
// default when absent) keeps structural widget nesting as the source.
|
|
573
573
|
.{ .code = 93, .name = "tree-level", .class = .whole, .group = .option, .field = "tree_level" },
|
|
574
|
+
// Code diff metadata follows Geist Code Block's added/removed line
|
|
575
|
+
// declarations. Values are one-based comma/range text specs so markup
|
|
576
|
+
// can state compact runs (`2-4, 7`) without putting +/- bytes in source.
|
|
577
|
+
.{ .code = 94, .name = "added-lines", .class = .text, .group = .composite },
|
|
578
|
+
.{ .code = 95, .name = "removed-lines", .class = .text, .group = .composite },
|
|
574
579
|
};
|
|
575
580
|
|
|
576
581
|
// ----------------------------------------------------------------- events
|
|
@@ -22,7 +22,7 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
22
22
|
// the new fingerprint ONLY for additions; renames/renumbers are
|
|
23
23
|
// schema-version-bump events, not silent edits.
|
|
24
24
|
try testing.expectEqual(@as(usize, 70), schema.elements.len);
|
|
25
|
-
try testing.expectEqual(@as(usize,
|
|
25
|
+
try testing.expectEqual(@as(usize, 95), schema.attrs.len);
|
|
26
26
|
try testing.expectEqual(@as(usize, 14), schema.events.len);
|
|
27
27
|
// The element table runs through the span composite (64), the
|
|
28
28
|
// bubble-reactions composite (65), the media surface (66), the
|
|
@@ -44,9 +44,10 @@ test "registry codes are stable: assigned at birth, never renumbered or renamed"
|
|
|
44
44
|
// attributes axis (86) and value-x (87), and the terminal
|
|
45
45
|
// attributes pty (88) and scrollback (89), and the code language
|
|
46
46
|
// (90), line-numbers (91), and editable-code (92) declarations,
|
|
47
|
-
//
|
|
47
|
+
// the flat disclosure-tree hierarchy level tree-level (93), and the
|
|
48
|
+
// code-diff line sets added-lines (94) and removed-lines (95).
|
|
48
49
|
try testing.expectEqual(
|
|
49
|
-
@as(u64,
|
|
50
|
+
@as(u64, 0xf16fa9fd1d3e7f25),
|
|
50
51
|
tableFingerprint(schema.AttrInfo, &schema.attrs),
|
|
51
52
|
);
|
|
52
53
|
// The event table runs through the pointer-hover containment pair
|
|
@@ -123,6 +123,20 @@ test "ui builder emits an engine-compatible widget tree" {
|
|
|
123
123
|
try testing.expect(saw_button);
|
|
124
124
|
}
|
|
125
125
|
|
|
126
|
+
test "ui builder distinguishes inherited tab padding from an equal author value" {
|
|
127
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
128
|
+
defer arena_state.deinit();
|
|
129
|
+
|
|
130
|
+
var ui = InboxUi.init(arena_state.allocator());
|
|
131
|
+
const inherited = ui.el(.tabs, .{}, .{});
|
|
132
|
+
try testing.expectEqual(@as(f32, 3), inherited.widget.layout.padding.top);
|
|
133
|
+
try testing.expect(inherited.widget.layout.padding_is_kind_default);
|
|
134
|
+
|
|
135
|
+
const explicit = ui.el(.tabs, .{ .padding = 3 }, .{});
|
|
136
|
+
try testing.expectEqual(@as(f32, 3), explicit.widget.layout.padding.top);
|
|
137
|
+
try testing.expect(!explicit.widget.layout.padding_is_kind_default);
|
|
138
|
+
}
|
|
139
|
+
|
|
126
140
|
test "structural ids are stable across rebuilds" {
|
|
127
141
|
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
128
142
|
defer arena_state.deinit();
|