@native-sdk/cli 0.4.3 → 0.5.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 +308 -72
- package/build/ts_run.mjs +63 -0
- package/build.zig +336 -7
- package/build.zig.zon +1 -0
- package/package.json +15 -10
- package/packages/core/package-lock.json +43 -0
- package/packages/core/package.json +37 -0
- package/packages/core/rt/rt.zig +1579 -0
- package/packages/core/sdk/bytes_text_methods.d.ts +88 -0
- package/packages/core/sdk/core.ts +694 -0
- package/packages/core/sdk/events.ts +137 -0
- package/packages/core/sdk/text.ts +519 -0
- package/packages/core/src/checker.ts +1869 -0
- package/packages/core/src/cli.ts +68 -0
- package/packages/core/src/devhost.ts +291 -0
- package/packages/core/src/devhost_resolver.mjs +22 -0
- package/packages/core/src/diagnostics.ts +417 -0
- package/packages/core/src/emitter.ts +8815 -0
- package/packages/core/src/infer.ts +1515 -0
- package/packages/core/src/modules.ts +173 -0
- package/packages/core/src/ownership.ts +740 -0
- package/packages/core/src/text_polyfill.ts +337 -0
- package/packages/core/src/text_tables.ts +408 -0
- package/packages/core/src/transpile.ts +146 -0
- package/packages/core/src/typed_ast.ts +536 -0
- package/packages/core/src/types.ts +815 -0
- package/skill-data/core/SKILL.md +3 -0
- package/skill-data/native-ui/SKILL.md +30 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +208 -0
- package/skills/native-sdk/SKILL.md +1 -1
- package/src/app_runner/root.zig +75 -9
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/platform/linux/gtk_host.c +226 -21
- package/src/platform/windows/webview2_host.cpp +16 -10
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +13 -0
- package/src/primitives/app_manifest/types.zig +14 -0
- package/src/primitives/app_manifest/validation.zig +18 -0
- package/src/primitives/app_manifest/web_layer.zig +366 -0
- package/src/primitives/canvas/commands.zig +14 -7
- package/src/primitives/canvas/lazy_tls.zig +73 -0
- package/src/primitives/canvas/render_generic_resources.zig +22 -15
- package/src/primitives/canvas/root.zig +6 -0
- package/src/primitives/canvas/tests.zig +1 -0
- package/src/primitives/canvas/text_atlas.zig +40 -32
- package/src/primitives/canvas/text_layout_cache.zig +29 -22
- package/src/primitives/canvas/text_measure_cache.zig +56 -41
- package/src/primitives/canvas/text_spans.zig +39 -26
- package/src/primitives/canvas/tokens.zig +54 -0
- package/src/primitives/canvas/ui.zig +125 -0
- package/src/primitives/canvas/ui_markup.zig +22 -3
- package/src/primitives/canvas/ui_markup_compiled.zig +97 -7
- package/src/primitives/canvas/ui_markup_compiled_tests.zig +275 -0
- package/src/primitives/canvas/ui_markup_contract.zig +68 -14
- package/src/primitives/canvas/ui_markup_contract_tests.zig +257 -2
- package/src/primitives/canvas/ui_markup_reflect.zig +214 -0
- package/src/primitives/canvas/ui_markup_view.zig +105 -1
- package/src/primitives/canvas/ui_markup_view_tests.zig +336 -0
- package/src/primitives/canvas/ui_schema.zig +8 -0
- package/src/primitives/canvas/ui_schema_tests.zig +5 -4
- package/src/primitives/canvas/widget_invalidation.zig +14 -7
- package/src/primitives/canvas/widget_render.zig +25 -15
- package/src/primitives/canvas/widget_render_controls.zig +15 -9
- package/src/primitives/canvas/widget_runtime_tests.zig +44 -0
- package/src/root.zig +7 -0
- package/src/runtime/api.zig +7 -0
- package/src/runtime/bridge_responses.zig +2 -0
- package/src/runtime/builtin_bridge.zig +6 -0
- package/src/runtime/canvas_frame.zig +57 -36
- package/src/runtime/canvas_images.zig +9 -3
- package/src/runtime/canvas_widget_control_tests.zig +5 -6
- package/src/runtime/canvas_widget_runtime.zig +7 -4
- package/src/runtime/effects.zig +490 -2
- package/src/runtime/effects_host_tests.zig +594 -0
- package/src/runtime/flow.zig +8 -0
- package/src/runtime/platform_bridge_tests.zig +1 -0
- package/src/runtime/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- package/src/runtime/session_tests.zig +35 -8
- package/src/runtime/tests.zig +2 -0
- package/src/runtime/ts_core_host.zig +1505 -0
- package/src/runtime/ts_core_host_tests.zig +1408 -0
- package/src/runtime/ts_ui_app.zig +469 -0
- package/src/runtime/ui_app.zig +58 -0
- package/src/runtime/view_canvas.zig +24 -17
- package/src/runtime/view_widget_tree.zig +2 -2
- package/src/runtime/web_layer_gate_tests.zig +242 -0
- package/src/runtime/window_storage.zig +5 -0
- package/src/runtime/window_view_runtime.zig +1 -0
- package/src/tooling/buildgraph.zig +7 -1
- package/src/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +314 -1
- package/src/tooling/package.zig +722 -18
- package/src/tooling/raw_manifest.zig +16 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +911 -88
- package/src/tooling/ts_core.zig +486 -0
- package/src/tooling/verbs.zig +22 -0
|
@@ -1502,6 +1502,35 @@ test "compiled charts match the interpreter and the hand-written Ui.chart tree"
|
|
|
1502
1502
|
try testing.expectEqual(canvas.WidgetKind.chart, compiled_chart.kind);
|
|
1503
1503
|
}
|
|
1504
1504
|
|
|
1505
|
+
const ChartF64Interpreter = markup_view.MarkupView(fixture.ChartF64Model, fixture.ChartMsg);
|
|
1506
|
+
const ChartF64Compiled = canvas.CompiledMarkupView(fixture.ChartF64Model, fixture.ChartMsg, fixture.chart_f64_markup_source);
|
|
1507
|
+
|
|
1508
|
+
test "compiled charts bind f64 series (the transpiled-core float class) identically to the interpreter" {
|
|
1509
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1510
|
+
defer arena_state.deinit();
|
|
1511
|
+
const arena = arena_state.allocator();
|
|
1512
|
+
|
|
1513
|
+
const model = fixture.ChartF64Model{};
|
|
1514
|
+
|
|
1515
|
+
var view = try ChartF64Interpreter.init(arena, fixture.chart_f64_markup_source);
|
|
1516
|
+
var interpreted_ui = ChartUi.init(arena);
|
|
1517
|
+
const interpreted = try interpreted_ui.finalize(try view.build(&interpreted_ui, &model));
|
|
1518
|
+
var compiled_ui = ChartUi.init(arena);
|
|
1519
|
+
const compiled = try compiled_ui.finalize(ChartF64Compiled.build(&compiled_ui, &model));
|
|
1520
|
+
|
|
1521
|
+
try expectSameTree(fixture.ChartMsg, interpreted, compiled);
|
|
1522
|
+
const interpreted_chart = firstChartWidget(interpreted.root).?;
|
|
1523
|
+
const compiled_chart = firstChartWidget(compiled.root).?;
|
|
1524
|
+
try expectSameChartData(interpreted_chart.chart, compiled_chart.chart);
|
|
1525
|
+
|
|
1526
|
+
// The narrowing itself: f64 model samples land as exact f32 casts,
|
|
1527
|
+
// NaN gaps preserved, in BOTH engines (field and arena-fn sources).
|
|
1528
|
+
try testing.expectEqual(@as(f32, 0.25), compiled_chart.chart.series[0].values[0]);
|
|
1529
|
+
try testing.expect(std.math.isNan(compiled_chart.chart.series[0].values[1]));
|
|
1530
|
+
try testing.expectEqual(@as(f32, 0.125), compiled_chart.chart.series[1].values[0]);
|
|
1531
|
+
try testing.expectEqual(@as(f32, 0.5), compiled_chart.chart.series[1].values[3]);
|
|
1532
|
+
}
|
|
1533
|
+
|
|
1505
1534
|
// ---------------------------------------------- input-group fixture parity
|
|
1506
1535
|
|
|
1507
1536
|
const ComposerUi = fixture.ComposerUi;
|
|
@@ -1667,3 +1696,249 @@ test "compiled reactions lower onto the bubble's chrome-text channel exactly lik
|
|
|
1667
1696
|
try testing.expectEqual(canvas.TextAlign.start, sent.text_alignment);
|
|
1668
1697
|
try testing.expectEqual(@as(usize, 0), compiled.root.children[2].text.len);
|
|
1669
1698
|
}
|
|
1699
|
+
|
|
1700
|
+
// ------------------------------------------- committed-model (pointer) shape
|
|
1701
|
+
|
|
1702
|
+
const Track = struct {
|
|
1703
|
+
id: i64,
|
|
1704
|
+
title: []const u8,
|
|
1705
|
+
plays: f64,
|
|
1706
|
+
starred: bool,
|
|
1707
|
+
};
|
|
1708
|
+
|
|
1709
|
+
const LibraryMeta = struct {
|
|
1710
|
+
name: []const u8,
|
|
1711
|
+
track_total: i64,
|
|
1712
|
+
};
|
|
1713
|
+
|
|
1714
|
+
const LibraryMsg = union(enum) {
|
|
1715
|
+
open_track: i64,
|
|
1716
|
+
star_track: i64,
|
|
1717
|
+
refresh,
|
|
1718
|
+
};
|
|
1719
|
+
|
|
1720
|
+
/// The committed-model shape transpiled cores emit: record arrays are
|
|
1721
|
+
/// slices of shared `*const` nodes and nested records are `*const`
|
|
1722
|
+
/// fields. `reflect.Pointee` makes both bind exactly like their by-value
|
|
1723
|
+
/// counterparts.
|
|
1724
|
+
const LibraryModel = struct {
|
|
1725
|
+
meta: *const LibraryMeta,
|
|
1726
|
+
tracks: []const *const Track,
|
|
1727
|
+
selected: ?i64 = null,
|
|
1728
|
+
};
|
|
1729
|
+
|
|
1730
|
+
const library_markup =
|
|
1731
|
+
\\<column gap="4">
|
|
1732
|
+
\\ <text>{meta.name} holds {meta.track_total}</text>
|
|
1733
|
+
\\ <if test="{selected}">
|
|
1734
|
+
\\ <text>picked</text>
|
|
1735
|
+
\\ </if>
|
|
1736
|
+
\\ <for each="tracks" as="t" key="id">
|
|
1737
|
+
\\ <row key="{t.id}" gap="2" cross="center">
|
|
1738
|
+
\\ <text grow="1">{t.title} ({t.plays})</text>
|
|
1739
|
+
\\ <if test="{t.starred}">
|
|
1740
|
+
\\ <badge>starred</badge>
|
|
1741
|
+
\\ </if>
|
|
1742
|
+
\\ <button size="sm" on-press="open_track:{t.id}">Open</button>
|
|
1743
|
+
\\ </row>
|
|
1744
|
+
\\ </for>
|
|
1745
|
+
\\ <else>
|
|
1746
|
+
\\ <text>empty library</text>
|
|
1747
|
+
\\ </else>
|
|
1748
|
+
\\</column>
|
|
1749
|
+
;
|
|
1750
|
+
|
|
1751
|
+
const LibraryUi = canvas.Ui(LibraryMsg);
|
|
1752
|
+
const LibraryInterpreter = markup_view.MarkupView(LibraryModel, LibraryMsg);
|
|
1753
|
+
const LibraryCompiled = canvas.CompiledMarkupView(LibraryModel, LibraryMsg, library_markup);
|
|
1754
|
+
|
|
1755
|
+
fn interpretLibrary(arena: std.mem.Allocator, model: *const LibraryModel) !LibraryUi.Tree {
|
|
1756
|
+
var view = try LibraryInterpreter.init(arena, library_markup);
|
|
1757
|
+
var ui = LibraryUi.init(arena);
|
|
1758
|
+
return ui.finalize(try view.build(&ui, model));
|
|
1759
|
+
}
|
|
1760
|
+
|
|
1761
|
+
fn compileLibrary(arena: std.mem.Allocator, model: *const LibraryModel) !LibraryUi.Tree {
|
|
1762
|
+
var ui = LibraryUi.init(arena);
|
|
1763
|
+
return ui.finalize(LibraryCompiled.build(&ui, model));
|
|
1764
|
+
}
|
|
1765
|
+
|
|
1766
|
+
test "compiled pointer-item lists and pointer-record paths match the interpreter" {
|
|
1767
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1768
|
+
defer arena_state.deinit();
|
|
1769
|
+
const arena = arena_state.allocator();
|
|
1770
|
+
|
|
1771
|
+
const meta = LibraryMeta{ .name = "field notes", .track_total = 2 };
|
|
1772
|
+
const first = Track{ .id = 7, .title = "one", .plays = 3.5, .starred = false };
|
|
1773
|
+
const second = Track{ .id = 9, .title = "two", .plays = 12, .starred = true };
|
|
1774
|
+
const tracks = [_]*const Track{ &first, &second };
|
|
1775
|
+
var model = LibraryModel{ .meta = &meta, .tracks = &tracks };
|
|
1776
|
+
|
|
1777
|
+
const interpreted = try interpretLibrary(arena, &model);
|
|
1778
|
+
const compiled = try compileLibrary(arena, &model);
|
|
1779
|
+
try expectSameTree(LibraryMsg, interpreted, compiled);
|
|
1780
|
+
try expectSameTexts(interpreted.root, compiled.root);
|
|
1781
|
+
|
|
1782
|
+
// Dotted paths through the `*const` record field interpolate its
|
|
1783
|
+
// fields; pointer items bind their struct's fields, floats included.
|
|
1784
|
+
try testing.expect(findText(compiled.root, "field notes holds 2") != null);
|
|
1785
|
+
try testing.expect(findText(compiled.root, "one (3.5)") != null);
|
|
1786
|
+
try testing.expect(findText(compiled.root, "two (12)") != null);
|
|
1787
|
+
try testing.expect(findText(compiled.root, "starred") != null);
|
|
1788
|
+
try testing.expect(findText(compiled.root, "picked") == null);
|
|
1789
|
+
try testing.expect(findText(compiled.root, "empty library") == null);
|
|
1790
|
+
|
|
1791
|
+
// Message payloads built from pointer items dispatch identically.
|
|
1792
|
+
const open_button = fixture.findByKind(compiled.root, .button).?;
|
|
1793
|
+
try testing.expectEqual(
|
|
1794
|
+
interpreted.msgForPointer(open_button.id, .up).?,
|
|
1795
|
+
compiled.msgForPointer(open_button.id, .up).?,
|
|
1796
|
+
);
|
|
1797
|
+
try testing.expectEqual(@as(i64, 7), compiled.msgForPointer(open_button.id, .up).?.open_track);
|
|
1798
|
+
|
|
1799
|
+
// The optional scalar flips the gate at runtime, like every optional.
|
|
1800
|
+
model.selected = 9;
|
|
1801
|
+
const picked = try compileLibrary(arena, &model);
|
|
1802
|
+
try testing.expect(findText(picked.root, "picked") != null);
|
|
1803
|
+
|
|
1804
|
+
// An empty pointer list renders the for-else branch.
|
|
1805
|
+
model.tracks = &.{};
|
|
1806
|
+
const emptied_interpreted = try interpretLibrary(arena, &model);
|
|
1807
|
+
const emptied_compiled = try compileLibrary(arena, &model);
|
|
1808
|
+
try expectSameTree(LibraryMsg, emptied_interpreted, emptied_compiled);
|
|
1809
|
+
try testing.expect(findText(emptied_compiled.root, "empty library") != null);
|
|
1810
|
+
}
|
|
1811
|
+
|
|
1812
|
+
test "the compiled engine binds on-input to a declared mirror union in parity with the interpreter" {
|
|
1813
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1814
|
+
defer arena_state.deinit();
|
|
1815
|
+
const arena = arena_state.allocator();
|
|
1816
|
+
|
|
1817
|
+
const source =
|
|
1818
|
+
\\<column>
|
|
1819
|
+
\\ <text-field text="{draft}" label="Draft" on-input="edit" on-submit="submit" />
|
|
1820
|
+
\\</column>
|
|
1821
|
+
;
|
|
1822
|
+
const model = fixture.MirrorModel{ .draft = "hi" };
|
|
1823
|
+
|
|
1824
|
+
const Compiled = canvas.CompiledMarkupView(fixture.MirrorModel, fixture.MirrorMsg, source);
|
|
1825
|
+
var compiled_ui = canvas.Ui(fixture.MirrorMsg).init(arena);
|
|
1826
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
1827
|
+
|
|
1828
|
+
var view = try markup_view.MarkupView(fixture.MirrorModel, fixture.MirrorMsg).init(arena, source);
|
|
1829
|
+
var interpreter_ui = canvas.Ui(fixture.MirrorMsg).init(arena);
|
|
1830
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1831
|
+
|
|
1832
|
+
const field = fixture.findByKind(compiled.root, .text_field).?;
|
|
1833
|
+
try testing.expectEqual(fixture.findByKind(interpreted.root, .text_field).?.id, field.id);
|
|
1834
|
+
|
|
1835
|
+
// Both engines translate the runtime event into the DECLARED union.
|
|
1836
|
+
const compiled_insert = compiled.msgForTextEdit(field.id, .{ .insert_text = "abc" }).?;
|
|
1837
|
+
const interpreted_insert = interpreted.msgForTextEdit(field.id, .{ .insert_text = "abc" }).?;
|
|
1838
|
+
try testing.expectEqualStrings("abc", compiled_insert.edit.insert_text);
|
|
1839
|
+
try testing.expectEqualStrings("abc", interpreted_insert.edit.insert_text);
|
|
1840
|
+
const compiled_move = compiled.msgForTextEdit(field.id, .{ .move_caret = .{ .direction = .end, .extend = false } }).?;
|
|
1841
|
+
try testing.expectEqual(fixture.MirrorCaretDirection.end, compiled_move.edit.move_caret.direction);
|
|
1842
|
+
try testing.expectEqual(
|
|
1843
|
+
interpreted.msgForTextEdit(field.id, .delete_backward).?,
|
|
1844
|
+
compiled.msgForTextEdit(field.id, .delete_backward).?,
|
|
1845
|
+
);
|
|
1846
|
+
}
|
|
1847
|
+
|
|
1848
|
+
// ---------------------------- declared scroll-state + value arms (parity)
|
|
1849
|
+
|
|
1850
|
+
test "compiled on-scroll binds a declared scroll-state mirror identically to the interpreter" {
|
|
1851
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1852
|
+
defer arena_state.deinit();
|
|
1853
|
+
const arena = arena_state.allocator();
|
|
1854
|
+
|
|
1855
|
+
const source =
|
|
1856
|
+
\\<scroll value="{scroll_top}" on-scroll="library_scrolled">
|
|
1857
|
+
\\ <text>rows</text>
|
|
1858
|
+
\\</scroll>
|
|
1859
|
+
;
|
|
1860
|
+
const model = fixture.MirrorControlsModel{};
|
|
1861
|
+
|
|
1862
|
+
const Compiled = canvas.CompiledMarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg, source);
|
|
1863
|
+
var compiled_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1864
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
1865
|
+
|
|
1866
|
+
var view = try markup_view.MarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg).init(arena, source);
|
|
1867
|
+
var interpreter_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1868
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1869
|
+
try expectSameTree(fixture.MirrorControlsMsg, interpreted, compiled);
|
|
1870
|
+
|
|
1871
|
+
// Both engines translate the runtime state into the DECLARED record:
|
|
1872
|
+
// float fields widen exactly, integer-classed fields round.
|
|
1873
|
+
const region = fixture.findByKind(compiled.root, .scroll_view).?;
|
|
1874
|
+
const state = canvas.ScrollState{ .offset = 41.5, .velocity = -3.25, .viewport_extent = 480.4, .content_extent = 2000.6 };
|
|
1875
|
+
const compiled_msg = compiled.msgForScroll(region.id, state).?;
|
|
1876
|
+
try testing.expectEqual(@as(f64, 41.5), compiled_msg.library_scrolled.offset);
|
|
1877
|
+
try testing.expectEqual(@as(i64, 480), compiled_msg.library_scrolled.viewportExtent);
|
|
1878
|
+
try testing.expectEqual(@as(i64, 2001), compiled_msg.library_scrolled.contentExtent);
|
|
1879
|
+
try testing.expectEqual(
|
|
1880
|
+
interpreted.msgForScroll(region.id, state).?,
|
|
1881
|
+
compiled.msgForScroll(region.id, state).?,
|
|
1882
|
+
);
|
|
1883
|
+
}
|
|
1884
|
+
|
|
1885
|
+
test "compiled slider on-change value arms match the interpreter" {
|
|
1886
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1887
|
+
defer arena_state.deinit();
|
|
1888
|
+
const arena = arena_state.allocator();
|
|
1889
|
+
|
|
1890
|
+
const source =
|
|
1891
|
+
\\<column>
|
|
1892
|
+
\\ <slider value="{seek_fraction}" label="Seek" on-change="scrubbed" />
|
|
1893
|
+
\\ <slider value="{volume}" label="Volume" on-change="set_volume" />
|
|
1894
|
+
\\ <slider value="{volume}" label="Nudge" on-change="nudged" />
|
|
1895
|
+
\\</column>
|
|
1896
|
+
;
|
|
1897
|
+
const model = fixture.MirrorControlsModel{};
|
|
1898
|
+
|
|
1899
|
+
const Compiled = canvas.CompiledMarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg, source);
|
|
1900
|
+
var compiled_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1901
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
1902
|
+
|
|
1903
|
+
var view = try markup_view.MarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg).init(arena, source);
|
|
1904
|
+
var interpreter_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1905
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1906
|
+
try expectSameTree(fixture.MirrorControlsMsg, interpreted, compiled);
|
|
1907
|
+
|
|
1908
|
+
const seek = fixture.findByKind(compiled.root, .slider).?;
|
|
1909
|
+
// The transpiled f64 arm carries the applied fraction widened exactly,
|
|
1910
|
+
// through both engines' handler tables.
|
|
1911
|
+
try testing.expectEqual(@as(f64, 0.25), compiled.msgForChange(seek.id, 0.25).?.scrubbed);
|
|
1912
|
+
try testing.expectEqual(
|
|
1913
|
+
interpreted.msgForChange(seek.id, 0.25).?,
|
|
1914
|
+
compiled.msgForChange(seek.id, 0.25).?,
|
|
1915
|
+
);
|
|
1916
|
+
}
|
|
1917
|
+
|
|
1918
|
+
test "compiled split on-resize binds a declared float arm identically to the interpreter" {
|
|
1919
|
+
var arena_state = std.heap.ArenaAllocator.init(testing.allocator);
|
|
1920
|
+
defer arena_state.deinit();
|
|
1921
|
+
const arena = arena_state.allocator();
|
|
1922
|
+
|
|
1923
|
+
const source =
|
|
1924
|
+
\\<split value="{seek_fraction}" on-resize="scrubbed">
|
|
1925
|
+
\\ <column><text>left</text></column>
|
|
1926
|
+
\\ <column><text>right</text></column>
|
|
1927
|
+
\\</split>
|
|
1928
|
+
;
|
|
1929
|
+
const model = fixture.MirrorControlsModel{};
|
|
1930
|
+
|
|
1931
|
+
const Compiled = canvas.CompiledMarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg, source);
|
|
1932
|
+
var compiled_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1933
|
+
const compiled = try compiled_ui.finalize(Compiled.build(&compiled_ui, &model));
|
|
1934
|
+
|
|
1935
|
+
var view = try markup_view.MarkupView(fixture.MirrorControlsModel, fixture.MirrorControlsMsg).init(arena, source);
|
|
1936
|
+
var interpreter_ui = canvas.Ui(fixture.MirrorControlsMsg).init(arena);
|
|
1937
|
+
const interpreted = try interpreter_ui.finalize(try view.build(&interpreter_ui, &model));
|
|
1938
|
+
try expectSameTree(fixture.MirrorControlsMsg, interpreted, compiled);
|
|
1939
|
+
|
|
1940
|
+
try testing.expectEqual(
|
|
1941
|
+
interpreted.msgForResize(interpreted.root.id, 0.25).?,
|
|
1942
|
+
compiled.msgForResize(compiled.root.id, 0.25).?,
|
|
1943
|
+
);
|
|
1944
|
+
}
|
|
@@ -191,6 +191,10 @@ pub fn describe(comptime Model: type, comptime Msg: type, comptime specials: Spe
|
|
|
191
191
|
}
|
|
192
192
|
|
|
193
193
|
fn describeGroup(comptime T: type) Group {
|
|
194
|
+
return describeGroupSeen(T, &.{});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
fn describeGroupSeen(comptime T: type, comptime seen: []const type) Group {
|
|
194
198
|
comptime {
|
|
195
199
|
var scalars: []const Scalar = &.{};
|
|
196
200
|
var groups: []const NamedGroup = &.{};
|
|
@@ -203,11 +207,17 @@ fn describeGroup(comptime T: type) Group {
|
|
|
203
207
|
}};
|
|
204
208
|
continue;
|
|
205
209
|
}
|
|
206
|
-
|
|
210
|
+
// `reflect.Pointee` transparency: a `*const Row` field
|
|
211
|
+
// traverses like the struct it shares. Pointer models can
|
|
212
|
+
// cycle (unlike by-value structs), so already-described
|
|
213
|
+
// types stop the walk — the engines resolve such paths
|
|
214
|
+
// segment by segment and never recurse into the type graph.
|
|
215
|
+
const Nested = reflect.Pointee(field.type);
|
|
216
|
+
if (@typeInfo(Nested) == .@"struct" and !typeListed(Nested, seen ++ &[_]type{T})) {
|
|
207
217
|
groups = groups ++ &[_]NamedGroup{.{
|
|
208
218
|
.name = field.name,
|
|
209
|
-
.type_name = @typeName(
|
|
210
|
-
.group =
|
|
219
|
+
.type_name = @typeName(Nested),
|
|
220
|
+
.group = describeGroupSeen(Nested, seen ++ &[_]type{T}),
|
|
211
221
|
}};
|
|
212
222
|
}
|
|
213
223
|
}
|
|
@@ -238,14 +248,24 @@ fn describeGroup(comptime T: type) Group {
|
|
|
238
248
|
}
|
|
239
249
|
}
|
|
240
250
|
|
|
251
|
+
fn typeListed(comptime T: type, comptime seen: []const type) bool {
|
|
252
|
+
for (seen) |S| {
|
|
253
|
+
if (S == T) return true;
|
|
254
|
+
}
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
241
258
|
fn describeItem(comptime Item: type) Iterable {
|
|
242
259
|
comptime {
|
|
260
|
+
// `reflect.Pointee` transparency: `[]const *const Row` iterates
|
|
261
|
+
// items that bind like Row itself.
|
|
262
|
+
const Bare = reflect.Pointee(Item);
|
|
243
263
|
return .{
|
|
244
264
|
.name = "",
|
|
245
|
-
.item_type = @typeName(
|
|
265
|
+
.item_type = @typeName(Bare),
|
|
246
266
|
.item_kind = if (reflect.supportedScalar(Item)) reflect.scalarKindOf(Item) else null,
|
|
247
267
|
.item_scalar = reflect.supportedScalar(Item),
|
|
248
|
-
.item = if (@typeInfo(
|
|
268
|
+
.item = if (@typeInfo(Bare) == .@"struct") describeGroup(Bare) else .{},
|
|
249
269
|
};
|
|
250
270
|
}
|
|
251
271
|
}
|
|
@@ -299,7 +319,16 @@ fn describeMsgs(comptime Msg: type, comptime specials: Specials) []const MsgTag
|
|
|
299
319
|
fn payloadClassOf(comptime T: type, comptime specials: Specials) PayloadClass {
|
|
300
320
|
if (T == void) return .none;
|
|
301
321
|
if (T == specials.TextInputEvent) return .text_input;
|
|
322
|
+
// A declared mirror of the text-input event union (transpiled cores,
|
|
323
|
+
// where type identity cannot cross the emission boundary) binds
|
|
324
|
+
// through on-input exactly like the canvas type — same resolution as
|
|
325
|
+
// both engines' inputConstructor.
|
|
326
|
+
if (reflect.declaredTextInputUnion(T)) return .text_input;
|
|
302
327
|
if (T == specials.ScrollState) return .scroll_state;
|
|
328
|
+
// A declared mirror of the scroll-state record (transpiled cores) binds
|
|
329
|
+
// through on-scroll exactly like the canvas type — same resolution as
|
|
330
|
+
// both engines' scrollConstructor.
|
|
331
|
+
if (reflect.declaredScrollStateRecord(T)) return .scroll_state;
|
|
303
332
|
return switch (@typeInfo(T)) {
|
|
304
333
|
.int => .integer,
|
|
305
334
|
.float => .float,
|
|
@@ -831,12 +860,29 @@ const Checker = struct {
|
|
|
831
860
|
return;
|
|
832
861
|
}
|
|
833
862
|
if (std.mem.eql(u8, event, "resize")) {
|
|
863
|
+
// f32 is the canvas-native arm; f64 the transpiled one-number
|
|
864
|
+
// float arm (engine parity — integer arms stay excluded, a
|
|
865
|
+
// fraction rounded into an integer would be useless data).
|
|
834
866
|
const found = tag orelse return self.failAttr(node, attribute, markup.on_resize_payload_message);
|
|
835
|
-
|
|
867
|
+
const resize_ok = found.payload == .float and
|
|
868
|
+
(std.mem.eql(u8, found.payload_type, "f32") or std.mem.eql(u8, found.payload_type, "f64"));
|
|
869
|
+
if (!resize_ok) {
|
|
836
870
|
return self.failAttr(node, attribute, markup.on_resize_payload_message);
|
|
837
871
|
}
|
|
838
872
|
return;
|
|
839
873
|
}
|
|
874
|
+
// The value-payload change event (engine parity): a slider's
|
|
875
|
+
// on-change with a bare tag naming a value-carrying arm — f32 (the
|
|
876
|
+
// canvas-native shape) or the transpiled one-number float arm
|
|
877
|
+
// (f64) — dispatches the applied 0..1 fraction. Void arms fall
|
|
878
|
+
// through to the static form below.
|
|
879
|
+
if (std.mem.eql(u8, event, "change") and std.mem.eql(u8, node.name, "slider") and expression.payload.len == 0) {
|
|
880
|
+
if (tag) |found| {
|
|
881
|
+
const value_arm = found.payload == .float and
|
|
882
|
+
(std.mem.eql(u8, found.payload_type, "f32") or std.mem.eql(u8, found.payload_type, "f64"));
|
|
883
|
+
if (value_arm) return;
|
|
884
|
+
}
|
|
885
|
+
}
|
|
840
886
|
const found = tag orelse return self.failNamed(node, unknown_tag_message, expression.tag, .{ .msgs = self.contract });
|
|
841
887
|
if (found.payload == .none) {
|
|
842
888
|
if (expression.payload.len > 0) return self.failAttr(node, attribute, no_payload_message);
|
|
@@ -1258,7 +1304,7 @@ const Checker = struct {
|
|
|
1258
1304
|
|
|
1259
1305
|
/// `<chart>` and its `<series>` children: options resolve like the
|
|
1260
1306
|
/// engines' (numbers, whole numbers, truthy flags, text), and every
|
|
1261
|
-
/// series `values` binding must name an f32 iterable — a wrong item
|
|
1307
|
+
/// series `values` binding must name an f32 or f64 iterable — a wrong item
|
|
1262
1308
|
/// type fails with the model type named, so the fix is visible from
|
|
1263
1309
|
/// the finding.
|
|
1264
1310
|
fn checkChart(self: *Checker, node: markup.MarkupNode) CheckErr!void {
|
|
@@ -1321,7 +1367,9 @@ const Checker = struct {
|
|
|
1321
1367
|
const expression = markup.parseAttrExpression(attribute.value) orelse continue;
|
|
1322
1368
|
if (expression != .binding) continue;
|
|
1323
1369
|
const item = try self.resolveIterable(node, expression.binding, markup.series_values_message);
|
|
1324
|
-
|
|
1370
|
+
// f32 is the canvas-native series element; f64 the
|
|
1371
|
+
// transpiled-core one (both engines narrow it per sample).
|
|
1372
|
+
if (!std.mem.eql(u8, item.type_name, "f32") and !std.mem.eql(u8, item.type_name, "f64")) {
|
|
1325
1373
|
const message = std.fmt.allocPrint(self.arena, "{s} (\"{s}\" iterates {s})", .{
|
|
1326
1374
|
markup.series_values_message, expression.binding, item.type_name,
|
|
1327
1375
|
}) catch return error.OutOfMemory;
|
|
@@ -1520,11 +1568,16 @@ fn editDistance(a: []const u8, b: []const u8) ?usize {
|
|
|
1520
1568
|
|
|
1521
1569
|
// -------------------------------------------------------------- artifact
|
|
1522
1570
|
|
|
1523
|
-
/// Hash the app's
|
|
1524
|
-
/// path-sorted, path and contents both mixed in.
|
|
1525
|
-
///
|
|
1526
|
-
///
|
|
1527
|
-
///
|
|
1571
|
+
/// Hash the app's core sources: every `.zig` and `.ts` file under
|
|
1572
|
+
/// `root_path`, path-sorted, path and contents both mixed in. TypeScript
|
|
1573
|
+
/// cores are hashed too because on that track the Model/Msg truth lives
|
|
1574
|
+
/// in `src/core.ts` — a core edit changes no `.zig` file, and a contract
|
|
1575
|
+
/// that stays "fresh" through it reports phantom unknown-tag and
|
|
1576
|
+
/// unknown-field errors against the user's new state. The emit step
|
|
1577
|
+
/// stamps this into the artifact; `native check` recomputes it and
|
|
1578
|
+
/// DEGRADES to structural checking on any mismatch — a stale contract
|
|
1579
|
+
/// can hide new fields or resurrect deleted ones, so it must never pass
|
|
1580
|
+
/// silently.
|
|
1528
1581
|
pub fn hashSourceDir(allocator: std.mem.Allocator, io: std.Io, root_path: []const u8) !u64 {
|
|
1529
1582
|
return hashSourceDirAt(allocator, io, std.Io.Dir.cwd(), root_path);
|
|
1530
1583
|
}
|
|
@@ -1540,7 +1593,8 @@ pub fn hashSourceDirAt(allocator: std.mem.Allocator, io: std.Io, base: std.Io.Di
|
|
|
1540
1593
|
var walker = try root.walk(allocator);
|
|
1541
1594
|
defer walker.deinit();
|
|
1542
1595
|
while (try walker.next(io)) |entry| {
|
|
1543
|
-
if (entry.kind
|
|
1596
|
+
if (entry.kind != .file) continue;
|
|
1597
|
+
if (std.mem.endsWith(u8, entry.path, ".zig") or std.mem.endsWith(u8, entry.path, ".ts")) {
|
|
1544
1598
|
try paths.append(allocator, try allocator.dupe(u8, entry.path));
|
|
1545
1599
|
}
|
|
1546
1600
|
}
|