@native-sdk/cli 0.4.4 → 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 +187 -6
- package/build/ts_run.mjs +63 -0
- package/build.zig +213 -1
- 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/native-ui/SKILL.md +14 -0
- package/skill-data/ts-core/SKILL.md +493 -0
- package/skill-data/zig/SKILL.md +10 -0
- package/src/app_runner/root.zig +24 -0
- package/src/app_runner/ts_core_main.zig +231 -0
- package/src/primitives/app_manifest/comptime_scene.zig +341 -0
- package/src/primitives/app_manifest/root.zig +5 -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/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/root.zig +18 -0
- package/src/runtime/session_replay.zig +7 -1
- 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/tooling/codesign.zig +212 -105
- package/src/tooling/doctor.zig +78 -0
- package/src/tooling/manifest.zig +47 -0
- package/src/tooling/package.zig +124 -12
- package/src/tooling/raw_manifest.zig +15 -0
- package/src/tooling/root.zig +1 -0
- package/src/tooling/templates.zig +683 -28
- package/src/tooling/ts_core.zig +486 -0
- package/src/tooling/verbs.zig +17 -0
|
@@ -0,0 +1,469 @@
|
|
|
1
|
+
//! `TsUiApp(core)` — the first-class UiApp adapter for transpiled app
|
|
2
|
+
//! cores: the committed TS model IS the app model. Where a Zig core
|
|
3
|
+
//! hands `UiApp` a mutable model plus `update`, a transpiled core is an
|
|
4
|
+
//! immutable committed graph plus a pure `update` returning the next
|
|
5
|
+
//! root — this adapter closes that gap with no per-app glue:
|
|
6
|
+
//!
|
|
7
|
+
//! Model = core.Model — the emitted struct itself. Markup views
|
|
8
|
+
//! (`canvas.CompiledMarkupView(core.Model, core.Msg, src)`)
|
|
9
|
+
//! and Zig builder views bind its fields directly; the
|
|
10
|
+
//! binding names are the TS interface's own field names
|
|
11
|
+
//! (`lastTickAt` binds as `{lastTickAt}` — the emitted
|
|
12
|
+
//! struct keeps the TS spellings), and record arrays /
|
|
13
|
+
//! nested records bind through markup's `*const`
|
|
14
|
+
//! transparency.
|
|
15
|
+
//! update = the bridge (`TsCoreHost(core)`): every Msg runs the
|
|
16
|
+
//! core's dispatch cycle — update, commit, command walk,
|
|
17
|
+
//! subscription reconcile — and the UiApp-held root is
|
|
18
|
+
//! refreshed to the committed value. Every pointer inside
|
|
19
|
+
//! it IS the committed graph (valid until the next
|
|
20
|
+
//! dispatch, exactly a view build's lifetime).
|
|
21
|
+
//! init = the core's `initialModel`: the boot model commits at
|
|
22
|
+
//! construction (so `tokens_fn`, pre-install appearance /
|
|
23
|
+
//! chrome dispatches, and the installing view build all
|
|
24
|
+
//! read real state), and the boot command + initial
|
|
25
|
+
//! subscriptions fire through `init_fx` on the installing
|
|
26
|
+
//! frame — the same init semantics Zig cores get.
|
|
27
|
+
//!
|
|
28
|
+
//! THE HOST-EVENT CHANNELS are the core's own, comptime-detected from
|
|
29
|
+
//! its exports (export exists -> wired; a wiring that also sets the
|
|
30
|
+
//! seam is a teaching panic): `frameMsg(model, frame)` -> `on_frame`,
|
|
31
|
+
//! `keyMsg(key)` -> `on_key`, and the arm exports `appearanceMsg` /
|
|
32
|
+
//! `chromeMsg` -> `on_appearance`/`on_chrome`, each host event built
|
|
33
|
+
//! structurally by field name from the core's declared records (the
|
|
34
|
+
//! effects-routing rule applied to the app shell; every shape mismatch
|
|
35
|
+
//! is a teaching compile error re-deriving the transpiler's NS1033).
|
|
36
|
+
//! `CoreOptions` carries the launch-boundary channels the wiring
|
|
37
|
+
//! resolves: `boot_images` (app.zon assets, registered on the
|
|
38
|
+
//! installing frame) and `env_values` (the core's `envMsgs` variables,
|
|
39
|
+
//! dispatched as journaled Msgs right after the boot command).
|
|
40
|
+
//!
|
|
41
|
+
//! Everything else on `UiApp.Options` is the wiring's, unchanged: view
|
|
42
|
+
//! or markup, scene, `on_command` maps command ids through the core's
|
|
43
|
+
//! `commandMsg`, `tokens_fn`/`windows_fn`/`status_item_fn` derive from
|
|
44
|
+
//! the committed model. The two seams the core owns — `update_fx` and
|
|
45
|
+
//! `init_fx` — are stamped by this adapter and must be left null.
|
|
46
|
+
//!
|
|
47
|
+
//! `Options.sync` is deliberately unsupported: it mutates the model in
|
|
48
|
+
//! place, which cannot exist for a committed graph. TS apps keep
|
|
49
|
+
//! continuous controls model-driven (`on-change`/`on-scroll` Msgs echo
|
|
50
|
+
//! the value back into the model — the pattern UiApp already supports).
|
|
51
|
+
//!
|
|
52
|
+
//! Record/replay, automation, and pixel fingerprints need nothing
|
|
53
|
+
//! extra: the adapter rides the ordinary UiApp dispatch path, so the
|
|
54
|
+
//! session journal, the automation verbs, and the screenshot marks see
|
|
55
|
+
//! a transpiled core exactly as they see a Zig one. The v1 process
|
|
56
|
+
//! contract is the bridge's: one live app per core module (two apps
|
|
57
|
+
//! over one emitted core would share a committed root; distinct core
|
|
58
|
+
//! modules coexist).
|
|
59
|
+
|
|
60
|
+
const std = @import("std");
|
|
61
|
+
const canvas = @import("canvas");
|
|
62
|
+
const platform = @import("../platform/root.zig");
|
|
63
|
+
const ui_app = @import("ui_app.zig");
|
|
64
|
+
const ts_core_host = @import("ts_core_host.zig");
|
|
65
|
+
|
|
66
|
+
pub fn TsUiApp(comptime core: type) type {
|
|
67
|
+
return struct {
|
|
68
|
+
/// The effect bridge — shared with any direct `TsCoreHost(core)`
|
|
69
|
+
/// instantiation (comptime memoization), so harnesses can read
|
|
70
|
+
/// `Host.model()` and tests can name the bridge's key bases.
|
|
71
|
+
pub const Host = ts_core_host.TsCoreHost(core);
|
|
72
|
+
pub const Model = core.Model;
|
|
73
|
+
pub const Msg = core.Msg;
|
|
74
|
+
pub const App = ui_app.UiApp(Model, Msg);
|
|
75
|
+
pub const Options = App.Options;
|
|
76
|
+
pub const Effects = App.Effects;
|
|
77
|
+
pub const Ui = App.Ui;
|
|
78
|
+
|
|
79
|
+
/// One boot-registered image: the wiring reads the encoded bytes
|
|
80
|
+
/// (app.zon's `.assets.images` paths) and the adapter registers
|
|
81
|
+
/// them on the installing frame — `fx.registerImageBytes`, the
|
|
82
|
+
/// Zig apps' `init_fx` convention. A failed decode skips the
|
|
83
|
+
/// entry: views keep their fallback (avatar initials), a bad
|
|
84
|
+
/// asset never breaks presentation.
|
|
85
|
+
pub const BootImage = struct {
|
|
86
|
+
id: u64,
|
|
87
|
+
bytes: []const u8,
|
|
88
|
+
};
|
|
89
|
+
|
|
90
|
+
/// One launch-time environment override (the core's `envMsgs`
|
|
91
|
+
/// channel): `msg` names the core's one-bytes-field arm, `value`
|
|
92
|
+
/// the variable's bytes. Dispatched as ordinary Msgs right after
|
|
93
|
+
/// the boot command on the installing frame — each delivery is
|
|
94
|
+
/// journaled (an `.env` effect record), so replay feeds the
|
|
95
|
+
/// recorded values and never re-reads the environment (see
|
|
96
|
+
/// `dispatchEnvValues`).
|
|
97
|
+
pub const EnvValue = struct {
|
|
98
|
+
msg: []const u8,
|
|
99
|
+
value: []const u8,
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
/// Adapter-owned configuration — the knobs that exist because
|
|
103
|
+
/// the core is transpiled, kept separate from `App.Options` so
|
|
104
|
+
/// the wiring surface reads as ordinary UiApp wiring.
|
|
105
|
+
pub const CoreOptions = struct {
|
|
106
|
+
/// Platform caches directory for URL audio playback: when a
|
|
107
|
+
/// core's `Cmd.audioPlay` names a URL with no cachePath, the
|
|
108
|
+
/// bridge derives the engine's conventional content-addressed
|
|
109
|
+
/// path under this directory (soundboard's convention,
|
|
110
|
+
/// resolved by the wiring at boot via `app_dirs` — never
|
|
111
|
+
/// read from the environment inside update). Empty disables
|
|
112
|
+
/// derivation: URL playback still works, it just re-streams.
|
|
113
|
+
audio_cache_dir: []const u8 = "",
|
|
114
|
+
/// Images registered at install, before the first view build
|
|
115
|
+
/// (see `BootImage`). The slices must outlive install (the
|
|
116
|
+
/// wiring reads them into launch-lifetime buffers).
|
|
117
|
+
boot_images: []const BootImage = &.{},
|
|
118
|
+
/// Launch-time environment overrides (see `EnvValue`), only
|
|
119
|
+
/// meaningful for cores exporting `envMsgs`. The slices must
|
|
120
|
+
/// outlive install.
|
|
121
|
+
env_values: []const EnvValue = &.{},
|
|
122
|
+
};
|
|
123
|
+
|
|
124
|
+
/// Construct the UiApp over the committed TS model. `options`
|
|
125
|
+
/// carries the wiring seams only — `update`, `update_fx`, and
|
|
126
|
+
/// `init_fx` belong to the core and must be null; `sync` cannot
|
|
127
|
+
/// exist for a committed model (see the module doc).
|
|
128
|
+
pub fn init(backing: std.mem.Allocator, core_options: CoreOptions, options: Options) App {
|
|
129
|
+
const stamped = stampOptions(options);
|
|
130
|
+
Host.boot();
|
|
131
|
+
applyCoreOptions(core_options);
|
|
132
|
+
return App.init(backing, Host.model().*, stamped);
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/// Heap counterpart of `init`, mirroring `UiApp.create`: the app
|
|
136
|
+
/// struct (and any real model) is multi-MB, so construct it in
|
|
137
|
+
/// place on the heap — the shape generated wiring and `main`
|
|
138
|
+
/// functions use. Pair with `App.destroy`.
|
|
139
|
+
pub fn create(backing: std.mem.Allocator, core_options: CoreOptions, options: Options) error{OutOfMemory}!*App {
|
|
140
|
+
const stamped = stampOptions(options);
|
|
141
|
+
Host.boot();
|
|
142
|
+
applyCoreOptions(core_options);
|
|
143
|
+
const self = try backing.create(App);
|
|
144
|
+
App.initInPlace(self, backing, stamped);
|
|
145
|
+
self.model = Host.model().*;
|
|
146
|
+
return self;
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
/// Adapter-held install state (container-level like the bridge's
|
|
150
|
+
/// tables — one live app per core module is the v1 contract):
|
|
151
|
+
/// `initFx` is a plain fn pointer, so the boot images and env
|
|
152
|
+
/// values it performs ride here between construction and the
|
|
153
|
+
/// installing frame.
|
|
154
|
+
var boot_images_store: []const BootImage = &.{};
|
|
155
|
+
var env_values_store: []const EnvValue = &.{};
|
|
156
|
+
|
|
157
|
+
fn applyCoreOptions(core_options: CoreOptions) void {
|
|
158
|
+
Host.setAudioCacheDir(core_options.audio_cache_dir);
|
|
159
|
+
boot_images_store = core_options.boot_images;
|
|
160
|
+
env_values_store = core_options.env_values;
|
|
161
|
+
if (core_options.env_values.len > 0 and comptime !@hasDecl(core, "envMsgs")) {
|
|
162
|
+
@panic("TsUiApp received env_values but the core exports no envMsgs channel - declare `export const envMsgs = [{ env: \"NAME\", msg: \"<arm>\" }] as const` in core.ts");
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
fn stampOptions(options: Options) Options {
|
|
167
|
+
if (options.update != null or options.update_fx != null) {
|
|
168
|
+
@panic("TsUiApp owns update: the transpiled core is the update loop - remove the wiring's update/update_fx");
|
|
169
|
+
}
|
|
170
|
+
if (options.init_fx != null) {
|
|
171
|
+
@panic("TsUiApp owns init_fx: the core's initialModel boots the app - remove the wiring's init_fx");
|
|
172
|
+
}
|
|
173
|
+
if (options.sync != null) {
|
|
174
|
+
@panic("TsUiApp does not support Options.sync: a committed model cannot be mutated in place - echo widget state through on-change/on-scroll Msgs instead");
|
|
175
|
+
}
|
|
176
|
+
var stamped = options;
|
|
177
|
+
stamped.init_fx = initFx;
|
|
178
|
+
stamped.update_fx = updateFx;
|
|
179
|
+
// The core's host-event channels, comptime-detected from its
|
|
180
|
+
// exports (export exists -> wired; every shape mismatch is a
|
|
181
|
+
// teaching compile error in the adapter below). A wiring that
|
|
182
|
+
// also set the seam would silently shadow the core's channel,
|
|
183
|
+
// so that conflict is a loud teaching panic.
|
|
184
|
+
if (comptime @hasDecl(core, "frameMsg")) {
|
|
185
|
+
if (options.on_frame != null) {
|
|
186
|
+
@panic("TsUiApp wires on_frame from the core's frameMsg export - remove the wiring's on_frame");
|
|
187
|
+
}
|
|
188
|
+
stamped.on_frame = frameMsgAdapter;
|
|
189
|
+
}
|
|
190
|
+
if (comptime @hasDecl(core, "keyMsg")) {
|
|
191
|
+
if (options.on_key != null) {
|
|
192
|
+
@panic("TsUiApp wires on_key from the core's keyMsg export - remove the wiring's on_key");
|
|
193
|
+
}
|
|
194
|
+
stamped.on_key = keyMsgAdapter;
|
|
195
|
+
}
|
|
196
|
+
if (comptime @hasDecl(core, "appearanceMsg")) {
|
|
197
|
+
if (options.on_appearance != null) {
|
|
198
|
+
@panic("TsUiApp wires on_appearance from the core's appearanceMsg export - remove the wiring's on_appearance");
|
|
199
|
+
}
|
|
200
|
+
stamped.on_appearance = appearanceMsgAdapter;
|
|
201
|
+
}
|
|
202
|
+
if (comptime @hasDecl(core, "chromeMsg")) {
|
|
203
|
+
if (options.on_chrome != null) {
|
|
204
|
+
@panic("TsUiApp wires on_chrome from the core's chromeMsg export - remove the wiring's on_chrome");
|
|
205
|
+
}
|
|
206
|
+
stamped.on_chrome = chromeMsgAdapter;
|
|
207
|
+
}
|
|
208
|
+
return stamped;
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
/// `Options.init_fx`: register the wiring's boot images, perform
|
|
212
|
+
/// the boot command and initial subscriptions on the installing
|
|
213
|
+
/// frame (the boot model itself committed in `init`), dispatch
|
|
214
|
+
/// the launch environment overrides as ordinary journaled Msgs,
|
|
215
|
+
/// then refresh the app-held root.
|
|
216
|
+
fn initFx(model: *Model, fx: *Effects) void {
|
|
217
|
+
for (boot_images_store) |image| {
|
|
218
|
+
// Registration is synchronous; a failed decode leaves the
|
|
219
|
+
// views on their fallback (avatar initials) — a bad asset
|
|
220
|
+
// never breaks presentation (the Zig apps' convention).
|
|
221
|
+
_ = fx.registerImageBytes(image.id, image.bytes) catch continue;
|
|
222
|
+
}
|
|
223
|
+
Host.performBoot(fx);
|
|
224
|
+
dispatchEnvValues(fx);
|
|
225
|
+
model.* = Host.model().*;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
/// The `envMsgs` channel's delivery: each launch-resolved value
|
|
229
|
+
/// dispatches its named one-bytes-field arm — a full core cycle
|
|
230
|
+
/// per value, in declaration order, right after the boot command.
|
|
231
|
+
///
|
|
232
|
+
/// Record/replay is the channel's whole point, so the values are
|
|
233
|
+
/// JOURNALED at record time (one `.env` effect record per
|
|
234
|
+
/// delivery, written during the installing frame's dispatch) and
|
|
235
|
+
/// FED from the journal under replay — zero env reads, so a
|
|
236
|
+
/// recording replays byte-identically even when the variables
|
|
237
|
+
/// are unset or changed at replay launch. Backward compatibility:
|
|
238
|
+
/// a journal with NO `.env` records (an older recording, or a
|
|
239
|
+
/// launch with no variables set) re-derives from the launch
|
|
240
|
+
/// configuration exactly as before.
|
|
241
|
+
fn dispatchEnvValues(fx: *Effects) void {
|
|
242
|
+
if (comptime !@hasDecl(core, "envMsgs")) return;
|
|
243
|
+
comptime validateEnvMsgs();
|
|
244
|
+
if (fx.replay and fx.replay_env_len > 0) {
|
|
245
|
+
while (fx.takeReplayEnv()) |entry| dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
246
|
+
return;
|
|
247
|
+
}
|
|
248
|
+
for (env_values_store, 0..) |entry, index| {
|
|
249
|
+
fx.journalEnvValue(index, entry.msg, entry.value);
|
|
250
|
+
dispatchOneEnvValue(fx, entry.msg, entry.value);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/// One env delivery: resolve the arm by name and dispatch the
|
|
255
|
+
/// value through a full core cycle.
|
|
256
|
+
fn dispatchOneEnvValue(fx: *Effects, msg: []const u8, value: []const u8) void {
|
|
257
|
+
inline for (@typeInfo(Msg).@"union".fields) |arm| {
|
|
258
|
+
if (comptime arm.type == []const u8) {
|
|
259
|
+
if (std.mem.eql(u8, arm.name, msg)) {
|
|
260
|
+
// The value copies into the core's frame arena
|
|
261
|
+
// first, like every routed bytes payload: the
|
|
262
|
+
// commit walkers copy frame-resident bytes the
|
|
263
|
+
// model keeps into the heap.
|
|
264
|
+
const copy = core.rt.frameAlloc(u8, value.len);
|
|
265
|
+
@memcpy(copy, value);
|
|
266
|
+
Host.dispatch(fx, @unionInit(Msg, arm.name, copy));
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/// Teaching re-derivation of the transpiler's NS1033 for
|
|
273
|
+
/// hand-assembled cores: every `envMsgs` entry must name a Msg
|
|
274
|
+
/// arm carrying exactly one bytes payload.
|
|
275
|
+
fn validateEnvMsgs() void {
|
|
276
|
+
for (core.envMsgs) |entry| {
|
|
277
|
+
var found = false;
|
|
278
|
+
for (@typeInfo(Msg).@"union".fields) |arm| {
|
|
279
|
+
if (std.mem.eql(u8, arm.name, entry.msg)) {
|
|
280
|
+
if (arm.type != []const u8) {
|
|
281
|
+
@compileError("TsUiApp: envMsgs entry '" ++ entry.env ++ "' targets Msg arm '" ++ entry.msg ++ "', whose payload is not one Uint8Array field");
|
|
282
|
+
}
|
|
283
|
+
found = true;
|
|
284
|
+
}
|
|
285
|
+
}
|
|
286
|
+
if (!found) {
|
|
287
|
+
@compileError("TsUiApp: envMsgs entry '" ++ entry.env ++ "' names '" ++ entry.msg ++ "', which is not an arm of Msg");
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/// Widen one host number into a channel record's declared field
|
|
293
|
+
/// class: floats take the value exactly, integer-classed fields
|
|
294
|
+
/// round to the nearest whole number.
|
|
295
|
+
fn channelNum(comptime N: type, value: f64) N {
|
|
296
|
+
return if (@typeInfo(N) == .float) @floatCast(value) else @intFromFloat(@round(value));
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
/// `Options.on_frame` over the core's `frameMsg(model, frame)`
|
|
300
|
+
/// export: the emitted FrameEvent record — `width`/`height`
|
|
301
|
+
/// (canvas points) plus `timestampMs`/`intervalMs` (fractional
|
|
302
|
+
/// milliseconds, the timer-fire clock; emitted fields keep their
|
|
303
|
+
/// TS names) — built by field NAME from
|
|
304
|
+
/// the presented frame. The core's return gates the channel
|
|
305
|
+
/// exactly like a Zig `on_frame` (null while idle keeps the idle
|
|
306
|
+
/// law: no Msg, no rebuild, the frame channel starves on its own).
|
|
307
|
+
fn frameMsgAdapter(model: *const Model, frame: platform.GpuFrame) ?Msg {
|
|
308
|
+
const params = @typeInfo(@TypeOf(core.frameMsg)).@"fn".params;
|
|
309
|
+
if (comptime (params.len != 2 or params[0].type != *const Model)) {
|
|
310
|
+
@compileError("TsUiApp: frameMsg must take (model: Model, frame: FrameEvent) - regenerate the core");
|
|
311
|
+
}
|
|
312
|
+
const FrameArg = params[1].type.?;
|
|
313
|
+
comptime validateChannelRecord(FrameArg, &.{ "width", "height", "timestampMs", "intervalMs" }, "frameMsg's FrameEvent");
|
|
314
|
+
var arg: FrameArg = undefined;
|
|
315
|
+
inline for (@typeInfo(FrameArg).@"struct".fields) |field| {
|
|
316
|
+
const value: f64 = if (comptime std.mem.eql(u8, field.name, "width"))
|
|
317
|
+
frame.size.width
|
|
318
|
+
else if (comptime std.mem.eql(u8, field.name, "height"))
|
|
319
|
+
frame.size.height
|
|
320
|
+
else if (comptime std.mem.eql(u8, field.name, "timestampMs"))
|
|
321
|
+
@as(f64, @floatFromInt(frame.timestamp_ns)) / std.time.ns_per_ms
|
|
322
|
+
else
|
|
323
|
+
@as(f64, @floatFromInt(frame.frame_interval_ns)) / std.time.ns_per_ms;
|
|
324
|
+
@field(arg, field.name) = channelNum(field.type, value);
|
|
325
|
+
}
|
|
326
|
+
return core.frameMsg(model, arg);
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
/// `Options.on_key` over the core's `keyMsg(key)` export: the
|
|
330
|
+
/// emitted KeyEvent record — the key NAME (lowercased, so
|
|
331
|
+
/// `key.key === "space"` compares the way the Zig examples'
|
|
332
|
+
/// case-insensitive checks do) plus the four modifier booleans.
|
|
333
|
+
/// The UiApp precedence rule applies before this fires: focused
|
|
334
|
+
/// widgets consume their own keys, editable text keeps typing.
|
|
335
|
+
fn keyMsgAdapter(keyboard: canvas.WidgetKeyboardEvent) ?Msg {
|
|
336
|
+
const params = @typeInfo(@TypeOf(core.keyMsg)).@"fn".params;
|
|
337
|
+
if (comptime params.len != 1) {
|
|
338
|
+
@compileError("TsUiApp: keyMsg must take one KeyEvent parameter - regenerate the core");
|
|
339
|
+
}
|
|
340
|
+
const KeyArg = params[0].type.?;
|
|
341
|
+
comptime {
|
|
342
|
+
const fields = @typeInfo(KeyArg).@"struct".fields;
|
|
343
|
+
if (fields.len != 5 or !@hasField(KeyArg, "key") or !@hasField(KeyArg, "shift") or
|
|
344
|
+
!@hasField(KeyArg, "control") or !@hasField(KeyArg, "alt") or !@hasField(KeyArg, "super"))
|
|
345
|
+
{
|
|
346
|
+
@compileError("TsUiApp: keyMsg's KeyEvent must be exactly { key: string; shift: boolean; control: boolean; alt: boolean; super: boolean }");
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
// The key name copies lowercased into the core's frame arena:
|
|
350
|
+
// the arena is empty between dispatches, and a Msg the core
|
|
351
|
+
// builds from it commits like every routed bytes payload.
|
|
352
|
+
const lowered = core.rt.frameAlloc(u8, keyboard.key.len);
|
|
353
|
+
for (keyboard.key, 0..) |c, index| lowered[index] = std.ascii.toLower(c);
|
|
354
|
+
var arg: KeyArg = undefined;
|
|
355
|
+
arg.key = lowered;
|
|
356
|
+
arg.shift = keyboard.modifiers.shift;
|
|
357
|
+
arg.control = keyboard.modifiers.control;
|
|
358
|
+
arg.alt = keyboard.modifiers.alt;
|
|
359
|
+
arg.super = keyboard.modifiers.super;
|
|
360
|
+
return core.keyMsg(arg);
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
/// `Options.on_appearance` over the core's `appearanceMsg` arm
|
|
364
|
+
/// export: the appearance record — `colorScheme` (a declared
|
|
365
|
+
/// light/dark enum, matched by member name), `reduceMotion`,
|
|
366
|
+
/// `highContrast` — built by field NAME (emitted fields keep
|
|
367
|
+
/// their TS names), always dispatched (the channel exists so the
|
|
368
|
+
/// MODEL owns appearance state).
|
|
369
|
+
fn appearanceMsgAdapter(appearance: platform.Appearance) ?Msg {
|
|
370
|
+
const arm_index = comptime channelArmIndex(core.appearanceMsg, "appearanceMsg");
|
|
371
|
+
const arm = @typeInfo(Msg).@"union".fields[arm_index];
|
|
372
|
+
comptime validateAppearanceArm(arm.type);
|
|
373
|
+
var payload: arm.type = undefined;
|
|
374
|
+
payload.reduceMotion = appearance.reduce_motion;
|
|
375
|
+
payload.highContrast = appearance.high_contrast;
|
|
376
|
+
const Scheme = @FieldType(arm.type, "colorScheme");
|
|
377
|
+
payload.colorScheme = switch (appearance.color_scheme) {
|
|
378
|
+
inline else => |scheme| @field(Scheme, @tagName(scheme)),
|
|
379
|
+
};
|
|
380
|
+
return @unionInit(Msg, arm.name, payload);
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
/// `Options.on_chrome` over the core's `chromeMsg` arm export:
|
|
384
|
+
/// the chrome record — `insets` (top/right/bottom/left), `buttons`
|
|
385
|
+
/// (x/y/width/height), `tabsProjected` — built by field NAME from
|
|
386
|
+
/// the window-chrome geometry, delivered before the first view
|
|
387
|
+
/// build and again whenever it changes.
|
|
388
|
+
fn chromeMsgAdapter(chrome: platform.WindowChrome) ?Msg {
|
|
389
|
+
const arm_index = comptime channelArmIndex(core.chromeMsg, "chromeMsg");
|
|
390
|
+
const arm = @typeInfo(Msg).@"union".fields[arm_index];
|
|
391
|
+
comptime validateChromeArm(arm.type);
|
|
392
|
+
var payload: arm.type = undefined;
|
|
393
|
+
const Insets = @FieldType(arm.type, "insets");
|
|
394
|
+
payload.insets = .{
|
|
395
|
+
.top = channelNum(@FieldType(Insets, "top"), chrome.insets.top),
|
|
396
|
+
.right = channelNum(@FieldType(Insets, "right"), chrome.insets.right),
|
|
397
|
+
.bottom = channelNum(@FieldType(Insets, "bottom"), chrome.insets.bottom),
|
|
398
|
+
.left = channelNum(@FieldType(Insets, "left"), chrome.insets.left),
|
|
399
|
+
};
|
|
400
|
+
const Buttons = @FieldType(arm.type, "buttons");
|
|
401
|
+
payload.buttons = .{
|
|
402
|
+
.x = channelNum(@FieldType(Buttons, "x"), chrome.buttons.x),
|
|
403
|
+
.y = channelNum(@FieldType(Buttons, "y"), chrome.buttons.y),
|
|
404
|
+
.width = channelNum(@FieldType(Buttons, "width"), chrome.buttons.width),
|
|
405
|
+
.height = channelNum(@FieldType(Buttons, "height"), chrome.buttons.height),
|
|
406
|
+
};
|
|
407
|
+
payload.tabsProjected = chrome.tabs_projected;
|
|
408
|
+
return @unionInit(Msg, arm.name, payload);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
/// The Msg arm index a channel export names, with the teaching
|
|
412
|
+
/// error the transpiler's NS1033 re-derives for hand-written
|
|
413
|
+
/// cores.
|
|
414
|
+
fn channelArmIndex(comptime tag: []const u8, comptime channel: []const u8) usize {
|
|
415
|
+
for (@typeInfo(Msg).@"union".fields, 0..) |arm, index| {
|
|
416
|
+
if (std.mem.eql(u8, arm.name, tag)) return index;
|
|
417
|
+
}
|
|
418
|
+
@compileError("TsUiApp: " ++ channel ++ " names '" ++ tag ++ "', which is not an arm of Msg");
|
|
419
|
+
}
|
|
420
|
+
|
|
421
|
+
fn validateChannelRecord(comptime T: type, comptime names: []const []const u8, comptime what: []const u8) void {
|
|
422
|
+
const info = @typeInfo(T);
|
|
423
|
+
if (info != .@"struct" or info.@"struct".fields.len != names.len) {
|
|
424
|
+
@compileError("TsUiApp: " ++ what ++ " record has the wrong field set");
|
|
425
|
+
}
|
|
426
|
+
for (names) |name| {
|
|
427
|
+
if (!@hasField(T, name)) {
|
|
428
|
+
@compileError("TsUiApp: " ++ what ++ " record is missing field '" ++ name ++ "'");
|
|
429
|
+
}
|
|
430
|
+
}
|
|
431
|
+
for (info.@"struct".fields) |field| {
|
|
432
|
+
if (field.type != i64 and field.type != f64 and field.type != f32) {
|
|
433
|
+
@compileError("TsUiApp: " ++ what ++ " field '" ++ field.name ++ "' must be a number");
|
|
434
|
+
}
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
fn validateAppearanceArm(comptime T: type) void {
|
|
439
|
+
const teaching = "TsUiApp: appearanceMsg's arm must carry exactly { colorScheme: a named light/dark alias; reduceMotion: boolean; highContrast: boolean }";
|
|
440
|
+
const info = @typeInfo(T);
|
|
441
|
+
if (info != .@"struct" or info.@"struct".fields.len != 3) @compileError(teaching);
|
|
442
|
+
if (!@hasField(T, "colorScheme") or !@hasField(T, "reduceMotion") or !@hasField(T, "highContrast")) @compileError(teaching);
|
|
443
|
+
const Scheme = @FieldType(T, "colorScheme");
|
|
444
|
+
const scheme_info = @typeInfo(Scheme);
|
|
445
|
+
if (scheme_info != .@"enum" or scheme_info.@"enum".fields.len != 2 or
|
|
446
|
+
!@hasField(Scheme, "light") or !@hasField(Scheme, "dark")) @compileError(teaching);
|
|
447
|
+
if (@FieldType(T, "reduceMotion") != bool or @FieldType(T, "highContrast") != bool) @compileError(teaching);
|
|
448
|
+
}
|
|
449
|
+
|
|
450
|
+
fn validateChromeArm(comptime T: type) void {
|
|
451
|
+
const teaching = "TsUiApp: chromeMsg's arm must carry exactly { insets: top/right/bottom/left numbers; buttons: x/y/width/height numbers; tabsProjected: boolean }";
|
|
452
|
+
const info = @typeInfo(T);
|
|
453
|
+
if (info != .@"struct" or info.@"struct".fields.len != 3) @compileError(teaching);
|
|
454
|
+
if (!@hasField(T, "insets") or !@hasField(T, "buttons") or !@hasField(T, "tabsProjected")) @compileError(teaching);
|
|
455
|
+
if (@FieldType(T, "tabsProjected") != bool) @compileError(teaching);
|
|
456
|
+
validateChannelRecord(@FieldType(T, "insets"), &.{ "top", "right", "bottom", "left" }, "chromeMsg's insets");
|
|
457
|
+
validateChannelRecord(@FieldType(T, "buttons"), &.{ "x", "y", "width", "height" }, "chromeMsg's buttons");
|
|
458
|
+
}
|
|
459
|
+
|
|
460
|
+
/// `Options.update_fx`: one full core dispatch cycle, then the
|
|
461
|
+
/// app-held root becomes the new committed value. The incoming
|
|
462
|
+
/// model pointer is the previous root value — the bridge holds
|
|
463
|
+
/// the authoritative one, so it is overwritten, never read.
|
|
464
|
+
fn updateFx(model: *Model, msg: Msg, fx: *Effects) void {
|
|
465
|
+
Host.dispatch(fx, msg);
|
|
466
|
+
model.* = Host.model().*;
|
|
467
|
+
}
|
|
468
|
+
};
|
|
469
|
+
}
|
package/src/runtime/ui_app.zig
CHANGED
|
@@ -390,6 +390,18 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
390
390
|
/// The scaffold wires this to app.zon's `theme` field
|
|
391
391
|
/// through `app_runner.manifestThemePack()`.
|
|
392
392
|
theme: canvas.ThemePack = .house,
|
|
393
|
+
/// The app's ONE-accent brand statement over the stock
|
|
394
|
+
/// tokens: when set (and the app claims neither `tokens`
|
|
395
|
+
/// nor `tokens_fn` — apps that own their tokens own their
|
|
396
|
+
/// brand), the accent identity bundle
|
|
397
|
+
/// (`canvas.accentOverrides`: accent + derived knockout
|
|
398
|
+
/// ink, focus ring, slider active range) layers over the
|
|
399
|
+
/// resolved pack on every rebuild. High-contrast requests
|
|
400
|
+
/// skip it — accessibility beats brand, the same rule an
|
|
401
|
+
/// app-owned tokens_fn states by hand. The scaffold wires
|
|
402
|
+
/// this to app.zon's `theme_accent` field through
|
|
403
|
+
/// `app_runner.manifestThemeAccent()`.
|
|
404
|
+
theme_accent: ?canvas.Color = null,
|
|
393
405
|
/// App font faces registered once, on the installing frame,
|
|
394
406
|
/// BEFORE the first view build — so the very first layout
|
|
395
407
|
/// already measures (and the first paint inks) with them.
|
|
@@ -1047,7 +1059,17 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1047
1059
|
.response => try self.effects.feedResponseOutcome(record.key, record.fetch_outcome, record.status, record.payload),
|
|
1048
1060
|
.file => try self.effects.feedFileResult(record.key, record.file_outcome, record.payload),
|
|
1049
1061
|
.clipboard => try self.effects.feedClipboardResult(record.key, record.clipboard_outcome, record.payload),
|
|
1062
|
+
// `.host` records ride the route in `code` (0 ok / 1
|
|
1063
|
+
// err); rejections never reach here — they carry
|
|
1064
|
+
// `.rejected` and regenerate from the same
|
|
1065
|
+
// deterministic validation, like `.timer` records.
|
|
1066
|
+
.host => try self.effects.feedHostResult(record.key, record.code == 0, record.payload),
|
|
1050
1067
|
.clock => try self.effects.pushReplayClock(record.clock_wall_ms),
|
|
1068
|
+
// `.env` records carry the arm name in `stderr_tail`
|
|
1069
|
+
// and the value in `payload`; the TS adapter's
|
|
1070
|
+
// envMsgs dispatch consumes the queue on the
|
|
1071
|
+
// replayed installing frame (zero env reads).
|
|
1072
|
+
.env => try self.effects.pushReplayEnv(record.stderr_tail, record.payload),
|
|
1051
1073
|
// Spectrum records feed through the band-carrying
|
|
1052
1074
|
// helper so replay repaints identical bars; every
|
|
1053
1075
|
// other audio kind rides the plain shape.
|
|
@@ -1164,6 +1186,14 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
1164
1186
|
.reduce_motion = self.system_appearance.reduce_motion,
|
|
1165
1187
|
.pack = self.options.theme,
|
|
1166
1188
|
});
|
|
1189
|
+
if (self.options.theme_accent) |accent| {
|
|
1190
|
+
// The manifest accent layers over the resolved pack —
|
|
1191
|
+
// except under high contrast, where the pack's own loud
|
|
1192
|
+
// register wins untouched (accessibility beats brand).
|
|
1193
|
+
if (!self.system_appearance.high_contrast) {
|
|
1194
|
+
tokens = tokens.withOverrides(canvas.accentOverrides(accent));
|
|
1195
|
+
}
|
|
1196
|
+
}
|
|
1167
1197
|
tokens.pixel_snap.scale = self.pixel_snap_scale;
|
|
1168
1198
|
return tokens;
|
|
1169
1199
|
}
|
|
@@ -2800,6 +2830,24 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2800
2830
|
// against the new grid.
|
|
2801
2831
|
self.pixel_snap_scale = scale;
|
|
2802
2832
|
try self.rebuild(runtime, frame_event.window_id);
|
|
2833
|
+
} else if (frame_event.size.width != self.canvas_size.width or
|
|
2834
|
+
frame_event.size.height != self.canvas_size.height)
|
|
2835
|
+
{
|
|
2836
|
+
// The presented frame IS the drawable's honest size:
|
|
2837
|
+
// during a live resize the frames carry the new size
|
|
2838
|
+
// before the window-manager resize event lands, and
|
|
2839
|
+
// every dispatch-driven rebuild inside that gap (a
|
|
2840
|
+
// playback clock tick, a frame-channel Msg) would lay
|
|
2841
|
+
// out at the STALE bounds — content anchored to the old
|
|
2842
|
+
// bottom edge paints below (or short of) a window that
|
|
2843
|
+
// already shrank or grew. Adopt the size and rebuild,
|
|
2844
|
+
// exactly what `handleResize` does when the event
|
|
2845
|
+
// arrives; the resize event that follows becomes a
|
|
2846
|
+
// no-reflow confirmation (its rebuild lays out the same
|
|
2847
|
+
// bounds), and fullscreen chrome re-queries stay its
|
|
2848
|
+
// job.
|
|
2849
|
+
self.canvas_size = frame_event.size;
|
|
2850
|
+
try self.rebuild(runtime, frame_event.window_id);
|
|
2803
2851
|
} else if (self.options.web_panes != null) {
|
|
2804
2852
|
// Re-snap the webview panes each presented frame: a shell
|
|
2805
2853
|
// relayout that stomped a pane frame also invalidated the
|
|
@@ -2844,6 +2892,16 @@ pub fn UiAppWithFeatures(comptime ModelT: type, comptime MsgT: type, comptime fe
|
|
|
2844
2892
|
// holds the stale scale (`rebuildEmitsTokens`).
|
|
2845
2893
|
slot.pixel_snap_scale = scale;
|
|
2846
2894
|
try self.rebuildWindowSlot(runtime, slot);
|
|
2895
|
+
} else if (frame_event.size.width != slot.canvas_size.width or
|
|
2896
|
+
frame_event.size.height != slot.canvas_size.height)
|
|
2897
|
+
{
|
|
2898
|
+
// The slot's drawable resized before its resize event
|
|
2899
|
+
// landed (the same live-resize gap the main canvas
|
|
2900
|
+
// closes above): adopt the presented size and rebuild so
|
|
2901
|
+
// dispatch-driven rebuilds never lay this window out at
|
|
2902
|
+
// stale bounds.
|
|
2903
|
+
slot.canvas_size = frame_event.size;
|
|
2904
|
+
try self.rebuildWindowSlot(runtime, slot);
|
|
2847
2905
|
}
|
|
2848
2906
|
try self.presentFrame(runtime, frame_event, slot.canvasLabel(), installing);
|
|
2849
2907
|
}
|
|
@@ -209,8 +209,14 @@ fn addCanvasCount(value: *usize, amount: usize, max_value: usize, comptime failu
|
|
|
209
209
|
/// the half-full bound; small lists keep the linear scans.
|
|
210
210
|
const summary_id_index_slots = 4096;
|
|
211
211
|
const SummaryIdIndex = canvas.plan_key_index.HashSlots(summary_id_index_slots);
|
|
212
|
-
|
|
213
|
-
|
|
212
|
+
// Lazily heap-allocated per thread (32 KiB of probe tables): reset per
|
|
213
|
+
// diff, so first-use init on the diffing thread is the only contract —
|
|
214
|
+
// threads that never diff summaries never allocate it.
|
|
215
|
+
const SummaryIdScratch = struct {
|
|
216
|
+
current: SummaryIdIndex = .{},
|
|
217
|
+
presented: SummaryIdIndex = .{},
|
|
218
|
+
};
|
|
219
|
+
const summary_id_scratch = canvas.lazy_tls.LazyTls(SummaryIdScratch);
|
|
214
220
|
|
|
215
221
|
pub const PresentedCanvasCommand = struct {
|
|
216
222
|
id: ?canvas.ObjectId = null,
|
|
@@ -647,28 +653,29 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
|
|
|
647
653
|
presented.len >= canvas.plan_key_index.min_entries_for_index) and
|
|
648
654
|
canvas.plan_key_index.fitsHashSlots(summary_id_index_slots, current_commands.len) and
|
|
649
655
|
canvas.plan_key_index.fitsHashSlots(summary_id_index_slots, presented.len);
|
|
650
|
-
if (use_index)
|
|
651
|
-
|
|
656
|
+
const id_scratch: ?*SummaryIdScratch = if (use_index) summary_id_scratch.get() else null;
|
|
657
|
+
if (id_scratch) |scratch| {
|
|
658
|
+
scratch.current.reset();
|
|
652
659
|
for (current_commands, 0..) |command, index| {
|
|
653
660
|
const id = command.objectId() orelse continue;
|
|
654
661
|
var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
|
|
655
|
-
while (
|
|
656
|
-
|
|
662
|
+
while (scratch.current.next(&p)) |_| {}
|
|
663
|
+
scratch.current.insert(p, @intCast(index));
|
|
657
664
|
}
|
|
658
|
-
|
|
665
|
+
scratch.presented.reset();
|
|
659
666
|
for (presented, 0..) |command, index| {
|
|
660
667
|
const id = command.id orelse continue;
|
|
661
668
|
var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
|
|
662
|
-
while (
|
|
663
|
-
|
|
669
|
+
while (scratch.presented.next(&p)) |_| {}
|
|
670
|
+
scratch.presented.insert(p, @intCast(index));
|
|
664
671
|
}
|
|
665
672
|
}
|
|
666
673
|
|
|
667
674
|
var len: usize = 0;
|
|
668
675
|
for (presented) |previous| {
|
|
669
676
|
const id = previous.id orelse continue;
|
|
670
|
-
const current_ref = if (
|
|
671
|
-
currentCanvasCommandByIdIndexed(current_commands, id)
|
|
677
|
+
const current_ref = if (id_scratch) |scratch|
|
|
678
|
+
currentCanvasCommandByIdIndexed(&scratch.current, current_commands, id)
|
|
672
679
|
else
|
|
673
680
|
self.currentCanvasCommandById(id);
|
|
674
681
|
if (current_ref == null) {
|
|
@@ -683,8 +690,8 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
|
|
|
683
690
|
for (current_commands, 0..) |command, index| {
|
|
684
691
|
const id = command.objectId() orelse continue;
|
|
685
692
|
const bounds = command.bounds();
|
|
686
|
-
const previous_ref = if (
|
|
687
|
-
presentedCanvasCommandByIdIndexed(presented, id)
|
|
693
|
+
const previous_ref = if (id_scratch) |scratch|
|
|
694
|
+
presentedCanvasCommandByIdIndexed(&scratch.presented, presented, id)
|
|
688
695
|
else
|
|
689
696
|
self.presentedCanvasCommandById(id);
|
|
690
697
|
if (previous_ref) |previous| {
|
|
@@ -708,17 +715,17 @@ pub fn RuntimeViewCanvasFrame(comptime RuntimeView: type) type {
|
|
|
708
715
|
return output[0..len];
|
|
709
716
|
}
|
|
710
717
|
|
|
711
|
-
fn currentCanvasCommandByIdIndexed(commands: []const canvas.CanvasCommand, id: canvas.ObjectId) ?canvas.CommandRef {
|
|
718
|
+
fn currentCanvasCommandByIdIndexed(current_index: *const SummaryIdIndex, commands: []const canvas.CanvasCommand, id: canvas.ObjectId) ?canvas.CommandRef {
|
|
712
719
|
var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
|
|
713
|
-
while (
|
|
720
|
+
while (current_index.next(&p)) |candidate| {
|
|
714
721
|
if (commands[candidate].objectId() == id) return .{ .index = candidate, .command = commands[candidate] };
|
|
715
722
|
}
|
|
716
723
|
return null;
|
|
717
724
|
}
|
|
718
725
|
|
|
719
|
-
fn presentedCanvasCommandByIdIndexed(presented: []const PresentedCanvasCommand, id: canvas.ObjectId) ?PresentedCanvasCommandRef {
|
|
726
|
+
fn presentedCanvasCommandByIdIndexed(presented_index: *const SummaryIdIndex, presented: []const PresentedCanvasCommand, id: canvas.ObjectId) ?PresentedCanvasCommandRef {
|
|
720
727
|
var p = SummaryIdIndex.probe(canvas.plan_key_index.mixHash(id));
|
|
721
|
-
while (
|
|
728
|
+
while (presented_index.next(&p)) |candidate| {
|
|
722
729
|
if (presented[candidate].id == id) return .{ .index = candidate, .command = presented[candidate] };
|
|
723
730
|
}
|
|
724
731
|
return null;
|