@pritzlaff/nano-ui 0.0.0-stage → 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/LICENSE +21 -0
- package/README.md +13 -2
- package/explorer-details.d.ts +44 -0
- package/explorer-nodes.d.ts +9 -0
- package/explorer.d.ts +52 -0
- package/filter/filter.d.ts +40 -0
- package/filter/model.d.ts +25 -0
- package/index.d.ts +33 -0
- package/index.js +2556 -0
- package/index.js.map +54 -0
- package/interfaces.d.ts +239 -0
- package/layout.d.ts +23 -0
- package/observe/bar.d.ts +46 -0
- package/observe/clock-driver.d.ts +16 -0
- package/observe/entry.d.ts +66 -0
- package/observe/fold.d.ts +14 -0
- package/observe/in-flight.d.ts +10 -0
- package/observe/memory-store.d.ts +5 -0
- package/observe/record.d.ts +15 -0
- package/observe/replay.d.ts +56 -0
- package/observe/restart-order.d.ts +3 -0
- package/observe/ring-view.d.ts +86 -0
- package/observe/ring.d.ts +38 -0
- package/observe/shadow.d.ts +18 -0
- package/observe/time-machine.d.ts +55 -0
- package/package.json +29 -4
- package/pods/clock.d.ts +3 -0
- package/pods/debounce.d.ts +6 -0
- package/pods/input.d.ts +5 -0
- package/pods/log.d.ts +3 -0
- package/pods/map.d.ts +3 -0
- package/pods/random.d.ts +5 -0
- package/pods/sim-clock.d.ts +3 -0
- package/provider.d.ts +1 -0
- package/views/debounce-model.d.ts +72 -0
- package/views/debounce-parts.d.ts +12 -0
- package/views/debounce.d.ts +36 -0
- package/views/define.d.ts +3 -0
- package/views/faces.d.ts +16 -0
- package/views/input.d.ts +9 -0
- package/views/pod-view.d.ts +10 -0
- package/views/view.d.ts +61 -0
- package/wiring/constants.d.ts +15 -0
- package/wiring/layout.d.ts +49 -0
- package/wiring/model.d.ts +3 -0
- package/wiring/render-drawer.d.ts +16 -0
- package/wiring/render-pills.d.ts +2 -0
- package/wiring/render-stage.d.ts +2 -0
- package/wiring/styles.d.ts +1 -0
- package/wiring/types.d.ts +68 -0
- package/wiring/wiring.d.ts +69 -0
package/index.js
ADDED
|
@@ -0,0 +1,2556 @@
|
|
|
1
|
+
// packages/ui/src/provider.ts
|
|
2
|
+
import { Coord as Coord9 } from "@pritzlaff/nano-core";
|
|
3
|
+
|
|
4
|
+
// packages/ui/src/pods/clock.ts
|
|
5
|
+
import { Coord as Coord2, Implementation, provide, success } from "@pritzlaff/nano-core";
|
|
6
|
+
|
|
7
|
+
// packages/ui/src/interfaces.ts
|
|
8
|
+
import { Type } from "typebox";
|
|
9
|
+
import { Coord, Schema, Op } from "@pritzlaff/nano-core";
|
|
10
|
+
var ns = Coord.namespace("nano.ui");
|
|
11
|
+
var Any = Schema.define(Type.Unknown(), "Any");
|
|
12
|
+
var Nothing = Schema.define(Type.Null(), "Nothing");
|
|
13
|
+
var Entries = Schema.define(Type.Array(Type.Unknown()), "Entries");
|
|
14
|
+
var Text = Schema.define(Type.String(), "Text");
|
|
15
|
+
var Approval = Schema.define(Type.Object({ title: Type.String(), detail: Type.Optional(Type.String()) }), "Approval");
|
|
16
|
+
var Num = Schema.define(Type.Number(), "Num");
|
|
17
|
+
var TimerId = Schema.define(Type.Integer({ minimum: 1 }), "TimerId");
|
|
18
|
+
var After = Schema.define(Type.Object({ ms: Type.Integer({ minimum: 0, maximum: 2147483647 }), tag: Type.Optional(Type.String()) }), "After");
|
|
19
|
+
var Fired = Schema.define(Type.Object({ id: Type.Integer({ minimum: 1 }), tag: Type.Optional(Type.String()), at: Type.Number() }), "Fired");
|
|
20
|
+
var Approved = Schema.define(Type.Boolean(), "Approved");
|
|
21
|
+
var Addition = Schema.define(Type.Object({
|
|
22
|
+
pods: Type.Record(Type.String(), Type.Unknown()),
|
|
23
|
+
runtimes: Type.Record(Type.String(), Type.Unknown()),
|
|
24
|
+
onConflict: Type.Optional(Type.Union([Type.Literal("error"), Type.Literal("overwrite")]))
|
|
25
|
+
}), "Addition");
|
|
26
|
+
var Removal = Schema.define(Type.Object({ runtimes: Type.Array(Type.String()) }), "Removal");
|
|
27
|
+
var Input = ns.interface("Input", { submit: Op.action(Any, Any), change: Op.action(Any, Any) });
|
|
28
|
+
var Debounce = ns.interface("Debounce", { push: Op.action(Any, Nothing), flushed: Op.event(Any), batch: Op.event(Entries) });
|
|
29
|
+
var MapIface = ns.interface("Map", { map: Op.action(Any, Any) });
|
|
30
|
+
var Log = ns.interface("Log", {
|
|
31
|
+
log: Op.action(Any, Nothing),
|
|
32
|
+
entries: Op.action(Nothing, Entries),
|
|
33
|
+
clear: Op.action(Nothing, Nothing)
|
|
34
|
+
});
|
|
35
|
+
var HostUI = ns.interface("HostUI", {
|
|
36
|
+
alert: Op.action(Text, Nothing),
|
|
37
|
+
approve: Op.action(Approval, Approved),
|
|
38
|
+
setAppBar: Op.action(Text, Nothing)
|
|
39
|
+
});
|
|
40
|
+
var HostDeploy = ns.interface("HostDeploy", { deploy: Op.action(Addition, Nothing), undeploy: Op.action(Removal, Nothing) });
|
|
41
|
+
var Clock = ns.interface("Clock", {
|
|
42
|
+
now: Op.action(Nothing, Num),
|
|
43
|
+
after: Op.action(After, TimerId),
|
|
44
|
+
cancel: Op.action(TimerId, Nothing),
|
|
45
|
+
fired: Op.event(Fired)
|
|
46
|
+
});
|
|
47
|
+
var ClockControl = ns.interface("ClockControl", { advance: Op.action(Num, Nothing), set: Op.action(Num, Nothing) });
|
|
48
|
+
var Random = ns.interface("Random", { next: Op.action(Nothing, Num) });
|
|
49
|
+
|
|
50
|
+
// packages/ui/src/pods/clock.ts
|
|
51
|
+
var ns2 = Coord2.namespace("nano.ui");
|
|
52
|
+
var clock = Implementation.define(ns2.implementationId("clock"), {
|
|
53
|
+
provides: [Clock],
|
|
54
|
+
make: (ctx) => {
|
|
55
|
+
const timers = new Map;
|
|
56
|
+
let next = 0, closed = false;
|
|
57
|
+
ctx.addOnCloseListener(() => {
|
|
58
|
+
closed = true;
|
|
59
|
+
timers.forEach(clearTimeout);
|
|
60
|
+
timers.clear();
|
|
61
|
+
});
|
|
62
|
+
return [provide(Clock, {
|
|
63
|
+
now: async () => success(Date.now()),
|
|
64
|
+
after: async ({ ms, tag }) => {
|
|
65
|
+
const id = ++next;
|
|
66
|
+
timers.set(id, setTimeout(() => {
|
|
67
|
+
timers.delete(id);
|
|
68
|
+
if (!closed)
|
|
69
|
+
ctx.publish(Clock.ops.fired, { id, ...tag === undefined ? {} : { tag }, at: Date.now() });
|
|
70
|
+
}, ms));
|
|
71
|
+
return success(id);
|
|
72
|
+
},
|
|
73
|
+
cancel: async (id) => {
|
|
74
|
+
clearTimeout(timers.get(id));
|
|
75
|
+
timers.delete(id);
|
|
76
|
+
return success(null);
|
|
77
|
+
}
|
|
78
|
+
})];
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
// packages/ui/src/pods/sim-clock.ts
|
|
83
|
+
import { Type as Type2 } from "typebox";
|
|
84
|
+
import { Coord as Coord3, Schema as Schema2, Implementation as Implementation2, provide as provide2, success as success2, failure } from "@pritzlaff/nano-core";
|
|
85
|
+
var ns3 = Coord3.namespace("nano.ui");
|
|
86
|
+
var simClock = Implementation2.define(ns3.implementationId("sim-clock"), {
|
|
87
|
+
provides: [Clock, ClockControl],
|
|
88
|
+
config: Schema2.define(Type2.Union([Type2.Object({ start: Type2.Optional(Type2.Number()) }), Type2.Undefined()]), "SimClockConfig"),
|
|
89
|
+
make: (ctx, config) => {
|
|
90
|
+
let time = config?.start ?? 0, next = 0;
|
|
91
|
+
let queue = Promise.resolve();
|
|
92
|
+
const run = (f) => queue = queue.then(f, f);
|
|
93
|
+
let timers = [];
|
|
94
|
+
const moveTo = async (t) => {
|
|
95
|
+
for (;; ) {
|
|
96
|
+
const due = timers.filter((x) => x.due <= t).sort((a, b) => a.due - b.due || a.id - b.id)[0];
|
|
97
|
+
if (!due)
|
|
98
|
+
break;
|
|
99
|
+
timers = timers.filter((x) => x !== due);
|
|
100
|
+
time = due.due;
|
|
101
|
+
const { id, tag } = due;
|
|
102
|
+
await ctx.publish(Clock.ops.fired, { id, ...tag === undefined ? {} : { tag }, at: time });
|
|
103
|
+
await new Promise((r) => setTimeout(r, 0));
|
|
104
|
+
}
|
|
105
|
+
time = t;
|
|
106
|
+
return success2(null);
|
|
107
|
+
};
|
|
108
|
+
const set = (t) => run(async () => t < time ? failure("invalid-input", `the clock is at ${time}; it cannot go back to ${t}`) : await moveTo(t));
|
|
109
|
+
return [
|
|
110
|
+
provide2(Clock, {
|
|
111
|
+
now: async () => success2(time),
|
|
112
|
+
after: async ({ ms, tag }) => {
|
|
113
|
+
const id = ++next;
|
|
114
|
+
timers.push({ id, due: time + ms, ...tag === undefined ? {} : { tag } });
|
|
115
|
+
return success2(id);
|
|
116
|
+
},
|
|
117
|
+
cancel: async (id) => {
|
|
118
|
+
timers = timers.filter((x) => x.id !== id);
|
|
119
|
+
return success2(null);
|
|
120
|
+
}
|
|
121
|
+
}),
|
|
122
|
+
provide2(ClockControl, {
|
|
123
|
+
advance: (ms) => run(async () => ms < 0 ? failure("invalid-input", `cannot advance by ${ms}`) : moveTo(time + ms)),
|
|
124
|
+
set
|
|
125
|
+
})
|
|
126
|
+
];
|
|
127
|
+
}
|
|
128
|
+
});
|
|
129
|
+
|
|
130
|
+
// packages/ui/src/pods/random.ts
|
|
131
|
+
import { Type as Type3 } from "typebox";
|
|
132
|
+
import { Coord as Coord4, Schema as Schema3, Implementation as Implementation3, provide as provide3, success as success3 } from "@pritzlaff/nano-core";
|
|
133
|
+
var ns4 = Coord4.namespace("nano.ui");
|
|
134
|
+
var random = Implementation3.define(ns4.implementationId("random"), {
|
|
135
|
+
provides: [Random],
|
|
136
|
+
make: () => [provide3(Random, { next: async () => success3(Math.random()) })]
|
|
137
|
+
});
|
|
138
|
+
var seededRandom = Implementation3.define(ns4.implementationId("seeded-random"), {
|
|
139
|
+
provides: [Random],
|
|
140
|
+
config: Schema3.define(Type3.Union([Type3.Object({ seed: Type3.Optional(Type3.Integer()) }), Type3.Undefined()]), "SeededRandomConfig"),
|
|
141
|
+
make: (ctx, config) => {
|
|
142
|
+
let s = (config?.seed ?? 1) >>> 0;
|
|
143
|
+
return [provide3(Random, { next: async () => {
|
|
144
|
+
s = s + 1831565813 >>> 0;
|
|
145
|
+
let t = Math.imul(s ^ s >>> 15, s | 1);
|
|
146
|
+
t ^= t + Math.imul(t ^ t >>> 7, t | 61);
|
|
147
|
+
return success3(((t ^ t >>> 14) >>> 0) / 4294967296);
|
|
148
|
+
} })];
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
// packages/ui/src/pods/debounce.ts
|
|
153
|
+
import { Type as Type4 } from "typebox";
|
|
154
|
+
import { Coord as Coord5, Schema as Schema4, Implementation as Implementation4, provide as provide4, success as success4 } from "@pritzlaff/nano-core";
|
|
155
|
+
var ns5 = Coord5.namespace("nano.ui");
|
|
156
|
+
var Ms = Type4.Integer({ minimum: 0, maximum: 60000 });
|
|
157
|
+
var debounce = Implementation4.define(ns5.implementationId("debounce"), {
|
|
158
|
+
provides: [Debounce],
|
|
159
|
+
config: Schema4.define(Type4.Union([Type4.Object({ quietMs: Ms, maxWaitMs: Type4.Optional(Ms) }), Type4.Undefined()]), "DebounceConfig"),
|
|
160
|
+
dependencies: { clock: Clock },
|
|
161
|
+
make: (ctx, config) => {
|
|
162
|
+
const quietMs = config?.quietMs ?? 300, maxWaitMs = config?.maxWaitMs;
|
|
163
|
+
let queue = [], closed = false;
|
|
164
|
+
const slots = {};
|
|
165
|
+
let pushes = Promise.resolve();
|
|
166
|
+
const wired = ctx.one(Clock);
|
|
167
|
+
const clear = (tag) => {
|
|
168
|
+
const s = slots[tag];
|
|
169
|
+
delete slots[tag];
|
|
170
|
+
if (s === undefined)
|
|
171
|
+
return;
|
|
172
|
+
if (wired.ok)
|
|
173
|
+
wired.value.call.cancel(s);
|
|
174
|
+
else
|
|
175
|
+
clearTimeout(s);
|
|
176
|
+
};
|
|
177
|
+
const start = async (tag, ms) => {
|
|
178
|
+
if (!wired.ok) {
|
|
179
|
+
slots[tag] = setTimeout(flush, ms);
|
|
180
|
+
return;
|
|
181
|
+
}
|
|
182
|
+
const r = await wired.value.call.after({ ms, tag });
|
|
183
|
+
if (!r.ok)
|
|
184
|
+
return;
|
|
185
|
+
if (closed)
|
|
186
|
+
wired.value.call.cancel(r.value);
|
|
187
|
+
else
|
|
188
|
+
slots[tag] = r.value;
|
|
189
|
+
};
|
|
190
|
+
const flush = () => {
|
|
191
|
+
clear("quiet");
|
|
192
|
+
clear("max");
|
|
193
|
+
const batch = queue;
|
|
194
|
+
queue = [];
|
|
195
|
+
if (closed || batch.length === 0)
|
|
196
|
+
return;
|
|
197
|
+
ctx.publish(Debounce.ops.flushed, batch.at(-1));
|
|
198
|
+
ctx.publish(Debounce.ops.batch, batch);
|
|
199
|
+
};
|
|
200
|
+
if (wired.ok)
|
|
201
|
+
wired.value.on(Clock.ops.fired, ({ output }) => {
|
|
202
|
+
if (output.tag && slots[output.tag] === output.id) {
|
|
203
|
+
delete slots[output.tag];
|
|
204
|
+
flush();
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
ctx.addOnCloseListener(() => {
|
|
208
|
+
closed = true;
|
|
209
|
+
clear("quiet");
|
|
210
|
+
clear("max");
|
|
211
|
+
});
|
|
212
|
+
return [provide4(Debounce, {
|
|
213
|
+
push: (value) => {
|
|
214
|
+
const run = async () => {
|
|
215
|
+
if (closed)
|
|
216
|
+
return success4(null);
|
|
217
|
+
queue.push(value);
|
|
218
|
+
clear("quiet");
|
|
219
|
+
await start("quiet", quietMs);
|
|
220
|
+
if (maxWaitMs !== undefined && slots.max === undefined)
|
|
221
|
+
await start("max", maxWaitMs);
|
|
222
|
+
return success4(null);
|
|
223
|
+
};
|
|
224
|
+
return wired.ok ? pushes = pushes.then(run, run) : run();
|
|
225
|
+
}
|
|
226
|
+
})];
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
|
|
230
|
+
// packages/ui/src/pods/input.ts
|
|
231
|
+
import { Type as Type5 } from "typebox";
|
|
232
|
+
import { Coord as Coord6, Implementation as Implementation5, Schema as Schema5, provide as provide5, success as success5 } from "@pritzlaff/nano-core";
|
|
233
|
+
var ns6 = Coord6.namespace("nano.ui");
|
|
234
|
+
var KINDS = ["text", "textarea", "number", "boolean"];
|
|
235
|
+
var input = Implementation5.define(ns6.implementationId("input"), {
|
|
236
|
+
provides: [Input],
|
|
237
|
+
config: Schema5.define(Type5.Union([Type5.Object({ kind: Type5.Optional(Type5.Union(KINDS.map((k) => Type5.Literal(k)))) }), Type5.Undefined()]), "InputConfig"),
|
|
238
|
+
make: () => [provide5(Input, { submit: async (v) => success5(v), change: async (v) => success5(v) })]
|
|
239
|
+
});
|
|
240
|
+
|
|
241
|
+
// packages/ui/src/pods/log.ts
|
|
242
|
+
import { Type as Type6 } from "typebox";
|
|
243
|
+
import { Coord as Coord7, Schema as Schema6, Implementation as Implementation6, provide as provide6, success as success6 } from "@pritzlaff/nano-core";
|
|
244
|
+
var ns7 = Coord7.namespace("nano.ui");
|
|
245
|
+
var log = Implementation6.define(ns7.implementationId("log"), {
|
|
246
|
+
provides: [Log],
|
|
247
|
+
config: Schema6.define(Type6.Union([Type6.Object({ max: Type6.Optional(Type6.Integer({ minimum: 1, maximum: 1000 })) }), Type6.Undefined()]), "LogConfig"),
|
|
248
|
+
make: (_ctx, config) => {
|
|
249
|
+
const max = config?.max ?? 100;
|
|
250
|
+
let entries = [];
|
|
251
|
+
return [provide6(Log, {
|
|
252
|
+
log: async (v) => {
|
|
253
|
+
entries = [...entries, v].slice(-max);
|
|
254
|
+
return success6(null);
|
|
255
|
+
},
|
|
256
|
+
entries: async () => success6([...entries]),
|
|
257
|
+
clear: async () => {
|
|
258
|
+
entries = [];
|
|
259
|
+
return success6(null);
|
|
260
|
+
}
|
|
261
|
+
})];
|
|
262
|
+
}
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
// packages/ui/src/pods/map.ts
|
|
266
|
+
import { Type as Type7 } from "typebox";
|
|
267
|
+
import { Coord as Coord8, Schema as Schema7, Implementation as Implementation7, provide as provide7, success as success7 } from "@pritzlaff/nano-core";
|
|
268
|
+
var ns8 = Coord8.namespace("nano.ui");
|
|
269
|
+
var map = Implementation7.define(ns8.implementationId("map"), {
|
|
270
|
+
provides: [MapIface],
|
|
271
|
+
config: Schema7.define(Type7.Object({ code: Type7.String() }, { default: { code: "return x" } }), "MapConfig"),
|
|
272
|
+
make: (_ctx, config) => {
|
|
273
|
+
const fn = new Function("x", config.code);
|
|
274
|
+
return [provide7(MapIface, { map: async (x) => success7(fn(x)) })];
|
|
275
|
+
}
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
// packages/ui/src/provider.ts
|
|
279
|
+
var ns9 = Coord9.namespace("nano.ui");
|
|
280
|
+
var uiProvider = ns9.provider([input, debounce, map, log, clock, simClock, random, seededRandom]);
|
|
281
|
+
// packages/ui/src/views/faces.ts
|
|
282
|
+
import { html as html2 } from "lit";
|
|
283
|
+
import { port } from "@pritzlaff/nano-core";
|
|
284
|
+
|
|
285
|
+
// packages/ui/src/views/view.ts
|
|
286
|
+
import { LitElement, html } from "lit";
|
|
287
|
+
import { base } from "@pritzlaff/nano-elements";
|
|
288
|
+
var defined = (tag) => tag && customElements.get(tag) ? tag : undefined;
|
|
289
|
+
function viewFor(pod, deployment, defaults, overrides = {}) {
|
|
290
|
+
const impl = deployment.pods[pod]?.implementation;
|
|
291
|
+
return defined(overrides[pod]) ?? defined(impl === undefined ? undefined : defaults[impl]) ?? "nano-pod-view";
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
class ViewElement extends LitElement {
|
|
295
|
+
static properties = { target: { attribute: false }, removed: { state: true } };
|
|
296
|
+
static styles = [base];
|
|
297
|
+
off;
|
|
298
|
+
watching;
|
|
299
|
+
constructor() {
|
|
300
|
+
super();
|
|
301
|
+
this.removed = false;
|
|
302
|
+
}
|
|
303
|
+
connectedCallback() {
|
|
304
|
+
super.connectedCallback();
|
|
305
|
+
this.watch();
|
|
306
|
+
}
|
|
307
|
+
disconnectedCallback() {
|
|
308
|
+
super.disconnectedCallback();
|
|
309
|
+
this.stop();
|
|
310
|
+
}
|
|
311
|
+
willUpdate(changed) {
|
|
312
|
+
if (changed.has("target")) {
|
|
313
|
+
this.removed = false;
|
|
314
|
+
this.watch();
|
|
315
|
+
}
|
|
316
|
+
}
|
|
317
|
+
watch() {
|
|
318
|
+
const t = this.target;
|
|
319
|
+
if (!t || !this.isConnected || this.removed || this.watching === t)
|
|
320
|
+
return;
|
|
321
|
+
this.stop();
|
|
322
|
+
this.watching = t;
|
|
323
|
+
this.off = t.app.listen((e) => {
|
|
324
|
+
if (e.type === "applied" && e.removed.includes(t.pod)) {
|
|
325
|
+
this.removed = true;
|
|
326
|
+
this.stop();
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (e.type === "applied")
|
|
330
|
+
this.requestUpdate();
|
|
331
|
+
this.hear(e, t);
|
|
332
|
+
});
|
|
333
|
+
this.started(t);
|
|
334
|
+
}
|
|
335
|
+
stop() {
|
|
336
|
+
this.off?.();
|
|
337
|
+
this.off = undefined;
|
|
338
|
+
this.watching = undefined;
|
|
339
|
+
}
|
|
340
|
+
pod(t) {
|
|
341
|
+
return t.app.call(t.runtime, t.pod);
|
|
342
|
+
}
|
|
343
|
+
started(_t) {}
|
|
344
|
+
hear(_e, _t) {}
|
|
345
|
+
face(_t) {
|
|
346
|
+
return html``;
|
|
347
|
+
}
|
|
348
|
+
render() {
|
|
349
|
+
if (this.removed)
|
|
350
|
+
return html`<div class="muted">removed</div>`;
|
|
351
|
+
return this.target ? this.face(this.target) : html``;
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
var shown = (r) => r === undefined ? "—" : r.ok ? JSON.stringify(r.value) : `failed: ${r.fail?.reason}`;
|
|
355
|
+
|
|
356
|
+
// packages/ui/src/views/faces.ts
|
|
357
|
+
var MAP = port(MapIface, MapIface.ops.map);
|
|
358
|
+
|
|
359
|
+
class NanoMap extends ViewElement {
|
|
360
|
+
mine = new Set;
|
|
361
|
+
output;
|
|
362
|
+
hear(e, tg) {
|
|
363
|
+
if (e.type === "sent" && e.to === tg.pod && e.port === MAP)
|
|
364
|
+
this.mine.add(e.id);
|
|
365
|
+
else if (e.type === "denied")
|
|
366
|
+
this.mine.delete(e.id);
|
|
367
|
+
else if (e.type === "delivered" && this.mine.delete(e.id)) {
|
|
368
|
+
this.output = e.result;
|
|
369
|
+
this.requestUpdate();
|
|
370
|
+
}
|
|
371
|
+
}
|
|
372
|
+
face(tg) {
|
|
373
|
+
const code = tg.app.deployment().pods[tg.pod]?.config?.code ?? "";
|
|
374
|
+
return html2`<pre class="code">${code}</pre><div>out ${shown(this.output)}</div>`;
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
var LOG = port(Log, Log.ops.log);
|
|
378
|
+
|
|
379
|
+
class NanoLog extends ViewElement {
|
|
380
|
+
entries = [];
|
|
381
|
+
logs = new Set;
|
|
382
|
+
started(tg) {
|
|
383
|
+
this.read(tg);
|
|
384
|
+
}
|
|
385
|
+
async read(tg) {
|
|
386
|
+
const r = await this.pod(tg).entries(null);
|
|
387
|
+
if (r.ok) {
|
|
388
|
+
this.entries = r.value;
|
|
389
|
+
this.requestUpdate();
|
|
390
|
+
}
|
|
391
|
+
}
|
|
392
|
+
hear(e, tg) {
|
|
393
|
+
if (e.type === "sent" && e.to === tg.pod && e.port === LOG)
|
|
394
|
+
this.logs.add(e.id);
|
|
395
|
+
else if (e.type === "denied")
|
|
396
|
+
this.logs.delete(e.id);
|
|
397
|
+
else if (e.type === "delivered" && this.logs.delete(e.id))
|
|
398
|
+
this.read(tg);
|
|
399
|
+
}
|
|
400
|
+
face() {
|
|
401
|
+
return html2`<ol>${this.entries.map((x) => html2`<li>${typeof x === "string" ? x : JSON.stringify(x)}</li>`)}</ol>`;
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// packages/ui/src/views/debounce.ts
|
|
406
|
+
import { css, html as html4 } from "lit";
|
|
407
|
+
import { port as port2 } from "@pritzlaff/nano-core";
|
|
408
|
+
|
|
409
|
+
// packages/ui/src/views/debounce-model.ts
|
|
410
|
+
var G = {
|
|
411
|
+
rows: 3,
|
|
412
|
+
perRow: 18,
|
|
413
|
+
sp: 54,
|
|
414
|
+
xEnd: 1110,
|
|
415
|
+
xStart: 192,
|
|
416
|
+
rowY: [176, 106, 36],
|
|
417
|
+
maxPos: 53,
|
|
418
|
+
hidePos: -2.3,
|
|
419
|
+
bucketTop: 290,
|
|
420
|
+
bucketH: 270,
|
|
421
|
+
pitch: 122,
|
|
422
|
+
history: 8,
|
|
423
|
+
enterSpeed: 0.07,
|
|
424
|
+
flushSpeed: 0.06,
|
|
425
|
+
hatchLeadMs: 180,
|
|
426
|
+
settleMs: 260,
|
|
427
|
+
slideMs: 480
|
|
428
|
+
};
|
|
429
|
+
var reasonFor = (q, quiet, maxWait = Infinity) => q.at(-1).at + quiet <= q[0].at + maxWait ? "quiet" : "max wait";
|
|
430
|
+
var dueAt = (q, quiet, maxWait = Infinity) => Math.min(q.at(-1).at + quiet, q[0].at + maxWait);
|
|
431
|
+
var arrivalPos = (slot, at, now) => Math.max(slot, G.maxPos - (now - at) * G.enterSpeed);
|
|
432
|
+
var flushTravel = (f, now) => Math.max(0, now - f.at - G.hatchLeadMs) * G.flushSpeed;
|
|
433
|
+
function startFlush(events, now, reason) {
|
|
434
|
+
const farthest = Math.max(...events.map((e, i) => arrivalPos(i, e.at, now)));
|
|
435
|
+
return { events, at: now, doneAt: now + G.hatchLeadMs + (farthest - G.hidePos) / G.flushSpeed + G.settleMs, reason };
|
|
436
|
+
}
|
|
437
|
+
function slotXY(pos) {
|
|
438
|
+
if (pos < 0)
|
|
439
|
+
return { x: G.xEnd, y: G.rowY[0] - pos * G.sp };
|
|
440
|
+
const r = Math.min(G.rows - 1, Math.floor(pos / G.perRow)), i = pos - r * G.perRow;
|
|
441
|
+
const xAt = (row, idx) => row % 2 === 0 ? G.xEnd - idx * G.sp : G.xStart + idx * G.sp;
|
|
442
|
+
if (i <= G.perRow - 1)
|
|
443
|
+
return { x: xAt(r, i), y: G.rowY[r] };
|
|
444
|
+
const frac = i - (G.perRow - 1);
|
|
445
|
+
return { x: xAt(r, G.perRow - 1), y: G.rowY[r] + (G.rowY[r + 1] - G.rowY[r]) * frac };
|
|
446
|
+
}
|
|
447
|
+
function colorOf(v) {
|
|
448
|
+
return typeof v === "number" ? "var(--nano-s1, #4C8DFF)" : typeof v === "string" ? "var(--nano-s2, #FF9F1C)" : v === null || typeof v === "boolean" ? "var(--nano-s5, #B48CFF)" : "var(--nano-s3, #2EC4A6)";
|
|
449
|
+
}
|
|
450
|
+
var tint = (color, a) => `color-mix(in srgb, ${color} ${Math.round(a * 100)}%, transparent)`;
|
|
451
|
+
var label = (v, n) => {
|
|
452
|
+
const s = typeof v === "string" ? v : JSON.stringify(v) ?? String(v);
|
|
453
|
+
return s.length > n ? s.slice(0, n - 1) + "…" : s;
|
|
454
|
+
};
|
|
455
|
+
var clamp01 = (v) => Math.max(0, Math.min(1, v));
|
|
456
|
+
function bucketView(events) {
|
|
457
|
+
const n = events.length, inner = G.bucketH - 8, gap = n > 40 ? 0 : 2;
|
|
458
|
+
const h = n === 0 ? 0 : Math.max(1, Math.min(18, Math.floor((inner - gap * (n - 1)) / n)));
|
|
459
|
+
const fill = n === 0 ? 0 : Math.min(inner, n * h + (n - 1) * gap);
|
|
460
|
+
return {
|
|
461
|
+
n,
|
|
462
|
+
gap,
|
|
463
|
+
solid: n > 0,
|
|
464
|
+
countTop: G.bucketTop + G.bucketH - 4 - fill - 24,
|
|
465
|
+
cells: events.map((e) => ({ color: colorOf(e.value), bg: tint(colorOf(e.value), 0.32), h, text: h >= 16 ? label(e.value, 8) : "" }))
|
|
466
|
+
};
|
|
467
|
+
}
|
|
468
|
+
|
|
469
|
+
// packages/ui/src/views/debounce-parts.ts
|
|
470
|
+
import { html as html3 } from "lit";
|
|
471
|
+
var MONO = "'JetBrains Mono', ui-monospace, monospace";
|
|
472
|
+
var slider = (name, aria, min, max, step, value, elapsed, color, drag, set, off) => html3`
|
|
473
|
+
<label style="display:flex; flex-direction:column; gap:6px; width:180px">
|
|
474
|
+
<span style="display:flex; justify-content:space-between"><span>${off ? html3`<input type="checkbox" aria-label=${"Use " + name} .checked=${off.on} @change=${(e) => off.toggle(e.target.checked)}> ` : ""}${name}</span><span style="color:var(--nano-fg, #E6EAF0)">${off && !off.on ? "off" : `${Math.round(Math.min(elapsed, value))} / ${value} ms`}</span></span>
|
|
475
|
+
<span style="display:block; height:6px; border-radius:3px; background:var(--nano-surface-2, #222933); overflow:hidden"><span style="display:block; height:6px; width:${off && !off.on ? 0 : Math.round(clamp01(elapsed / (value || 1)) * 100)}%; background:${color}"></span></span>
|
|
476
|
+
<input type="range" min=${min} max=${max} step=${step} .value=${String(value)} ?disabled=${off && !off.on} aria-label=${aria} style="width:180px; margin:0; accent-color:${color}"
|
|
477
|
+
@input=${(e) => drag(Number(e.target.value))} @change=${(e) => set(Number(e.target.value))}>
|
|
478
|
+
</label>`;
|
|
479
|
+
var track = () => html3`
|
|
480
|
+
<div style="position:absolute; left:100px; top:12px; width:80px; height:48px; border-radius:24px 0 0 24px; background:var(--nano-surface, #131820)"></div>
|
|
481
|
+
<div style="position:absolute; left:114px; top:28px; font-family:${MONO}; font-size:12px; color:var(--nano-muted, #9AA4B2)">in →</div>
|
|
482
|
+
<div style="position:absolute; left:164px; top:12px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
483
|
+
<div style="position:absolute; left:1086px; top:36px; width:48px; height:70px; background:var(--nano-surface-2, #161B22)"></div>
|
|
484
|
+
<div style="position:absolute; left:164px; top:82px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
485
|
+
<div style="position:absolute; left:168px; top:106px; width:48px; height:70px; background:var(--nano-surface-2, #161B22)"></div>
|
|
486
|
+
<div style="position:absolute; left:164px; top:152px; width:974px; height:48px; border-radius:24px; background:var(--nano-surface-2, #161B22)"></div>
|
|
487
|
+
<div style="position:absolute; left:1082px; top:176px; width:56px; height:114px; background:var(--nano-surface-2, #161B22)"></div>`;
|
|
488
|
+
function bucket(v, left, opacity, id, reason, reasonColor, live, border = "var(--nano-border, #2A313C)") {
|
|
489
|
+
return html3`<div class=${live ? "live" : "batch"} style="position:absolute; left:${left}px; top:0; width:122px; height:610px; opacity:${opacity}; pointer-events:none">
|
|
490
|
+
${v.n ? html3`<div style="position:absolute; left:0; top:${v.countTop}px; width:122px; text-align:center; font-family:${MONO}; font-size:13px; color:var(--nano-fg, #E6EAF0)">${v.n}</div>` : ""}
|
|
491
|
+
<div style="position:absolute; left:15px; top:290px; width:92px; height:270px; box-sizing:border-box; border:${live ? "2px solid " + border : "1px " + (v.solid ? "solid" : "dashed") + " var(--nano-border, #2A313C)"}; border-top:none; border-radius:0 0 10px 10px; padding:${live ? 3 : 4}px; display:flex; flex-direction:column-reverse; gap:${v.gap}px; overflow:hidden${live ? "; background:var(--nano-surface, #12171E)" : ""}">
|
|
492
|
+
${v.cells.map((c) => html3`<div class="cell" style="flex:none; height:${c.h}px; box-sizing:border-box; border-radius:3px; background:${c.bg}; border:1px solid ${c.color}; color:${c.color}; display:flex; align-items:center; justify-content:center; font-family:${MONO}; font-size:10px; overflow:hidden">${c.text}</div>`)}
|
|
493
|
+
</div>
|
|
494
|
+
<div style="position:absolute; left:0; top:568px; width:122px; display:flex; flex-direction:column; align-items:center; gap:3px; font-family:${MONO}; font-size:12px">
|
|
495
|
+
<span style="color:${live ? "var(--nano-warn, #E8B04B)" : "var(--nano-fg, #E6EAF0)"}">${id}</span><span style="color:${reasonColor}">${reason}</span>
|
|
496
|
+
</div>
|
|
497
|
+
</div>`;
|
|
498
|
+
}
|
|
499
|
+
|
|
500
|
+
// packages/ui/src/views/debounce.ts
|
|
501
|
+
var PUSH = port2(Debounce, Debounce.ops.push);
|
|
502
|
+
var BOX = { x: 90, w: 1090, h: 600 };
|
|
503
|
+
var REASON_COLOR = { quiet: "var(--nano-muted, #9AA4B2)", "max wait": "var(--nano-warn, #E8B04B)" };
|
|
504
|
+
|
|
505
|
+
class NanoDebounce extends ViewElement {
|
|
506
|
+
static styles = [...ViewElement.styles, css`:host { display: block; height: 100%; min-height: 160px }`];
|
|
507
|
+
pending = [];
|
|
508
|
+
flushing = null;
|
|
509
|
+
batches = [];
|
|
510
|
+
batchSeq = 0;
|
|
511
|
+
committed = 0;
|
|
512
|
+
lastCommitAt = -1e9;
|
|
513
|
+
dragged = {};
|
|
514
|
+
valued = false;
|
|
515
|
+
unsub;
|
|
516
|
+
raf = 0;
|
|
517
|
+
fit = { w: BOX.w, h: BOX.h };
|
|
518
|
+
ro;
|
|
519
|
+
config(tg) {
|
|
520
|
+
return { ...tg.app.deployment().pods[tg.pod]?.config, ...this.dragged };
|
|
521
|
+
}
|
|
522
|
+
quiet(tg) {
|
|
523
|
+
return this.config(tg).quietMs ?? 300;
|
|
524
|
+
}
|
|
525
|
+
maxWait(tg) {
|
|
526
|
+
return this.config(tg).maxWaitMs;
|
|
527
|
+
}
|
|
528
|
+
started(tg) {
|
|
529
|
+
this.unsub?.();
|
|
530
|
+
try {
|
|
531
|
+
this.unsub = tg.app.runtime(tg.runtime).subscribe(Debounce.ops.push, ({ input: input2 }) => this.arrive(input2));
|
|
532
|
+
this.valued = true;
|
|
533
|
+
} catch {
|
|
534
|
+
this.unsub = undefined;
|
|
535
|
+
this.valued = false;
|
|
536
|
+
}
|
|
537
|
+
}
|
|
538
|
+
hear(e, tg) {
|
|
539
|
+
if (e.type === "applied" && (e.changed.includes(tg.pod) || e.added.includes(tg.pod))) {
|
|
540
|
+
this.pending = [];
|
|
541
|
+
this.started(tg);
|
|
542
|
+
return;
|
|
543
|
+
}
|
|
544
|
+
if (e.type !== "sent" || e.kind === "subscribe" || e.kind === "unsubscribe")
|
|
545
|
+
return;
|
|
546
|
+
if (!this.valued && e.to === tg.pod && e.port === PUSH)
|
|
547
|
+
this.arrive("•");
|
|
548
|
+
else if (e.from === tg.pod && (e.kind === "pipe" || e.kind === "on") && e.port !== PUSH)
|
|
549
|
+
this.flush(tg);
|
|
550
|
+
}
|
|
551
|
+
arrive(value) {
|
|
552
|
+
this.pending = [...this.pending, { value, at: Date.now() }];
|
|
553
|
+
this.requestUpdate();
|
|
554
|
+
}
|
|
555
|
+
flush(tg, now = Date.now()) {
|
|
556
|
+
if (!this.pending.length)
|
|
557
|
+
return;
|
|
558
|
+
if (this.flushing)
|
|
559
|
+
this.commit(now);
|
|
560
|
+
this.flushing = startFlush(this.pending, now, reasonFor(this.pending, this.quiet(tg), this.maxWait(tg)));
|
|
561
|
+
this.pending = [];
|
|
562
|
+
this.requestUpdate();
|
|
563
|
+
}
|
|
564
|
+
commit(now) {
|
|
565
|
+
const f = this.flushing;
|
|
566
|
+
this.batchSeq += 1;
|
|
567
|
+
this.committed += f.events.length;
|
|
568
|
+
this.lastCommitAt = now;
|
|
569
|
+
this.batches = [...this.batches, { id: this.batchSeq, events: f.events, reason: f.reason }].slice(-G.history);
|
|
570
|
+
this.flushing = null;
|
|
571
|
+
}
|
|
572
|
+
async set(tg, c) {
|
|
573
|
+
const d = tg.app.deployment(), p = d.pods[tg.pod];
|
|
574
|
+
if (!p)
|
|
575
|
+
return;
|
|
576
|
+
const config = { ...p.config, ...c };
|
|
577
|
+
if (config.maxWaitMs === undefined)
|
|
578
|
+
delete config.maxWaitMs;
|
|
579
|
+
const pods = { ...d.pods, [tg.pod]: { ...p, config: { quietMs: 300, ...config } } };
|
|
580
|
+
await tg.app.apply({ ...d, pods });
|
|
581
|
+
this.dragged = {};
|
|
582
|
+
this.requestUpdate();
|
|
583
|
+
}
|
|
584
|
+
firstUpdated() {
|
|
585
|
+
const box = this.renderRoot.querySelector(".fit");
|
|
586
|
+
if (!box || typeof ResizeObserver === "undefined")
|
|
587
|
+
return;
|
|
588
|
+
this.ro = new ResizeObserver(() => {
|
|
589
|
+
this.fit = { w: box.clientWidth, h: box.clientHeight };
|
|
590
|
+
this.requestUpdate();
|
|
591
|
+
});
|
|
592
|
+
this.ro.observe(box);
|
|
593
|
+
}
|
|
594
|
+
connectedCallback() {
|
|
595
|
+
super.connectedCallback();
|
|
596
|
+
const box = this.renderRoot?.querySelector?.(".fit");
|
|
597
|
+
if (box)
|
|
598
|
+
this.ro?.observe(box);
|
|
599
|
+
}
|
|
600
|
+
disconnectedCallback() {
|
|
601
|
+
super.disconnectedCallback();
|
|
602
|
+
this.unsub?.();
|
|
603
|
+
this.unsub = undefined;
|
|
604
|
+
this.ro?.disconnect();
|
|
605
|
+
cancelAnimationFrame(this.raf);
|
|
606
|
+
this.raf = 0;
|
|
607
|
+
}
|
|
608
|
+
willUpdate(changed) {
|
|
609
|
+
super.willUpdate(changed);
|
|
610
|
+
const now = Date.now(), tg = this.target;
|
|
611
|
+
if (tg && this.pending.length && now >= dueAt(this.pending, this.quiet(tg), this.maxWait(tg)) + 40)
|
|
612
|
+
this.flush(tg, now);
|
|
613
|
+
if (this.flushing && now >= this.flushing.doneAt)
|
|
614
|
+
this.commit(now);
|
|
615
|
+
}
|
|
616
|
+
updated() {
|
|
617
|
+
const busy = this.pending.length > 0 || this.flushing !== null || Date.now() - this.lastCommitAt < G.slideMs;
|
|
618
|
+
if (busy && !this.raf && typeof requestAnimationFrame !== "undefined")
|
|
619
|
+
this.raf = requestAnimationFrame(() => {
|
|
620
|
+
this.raf = 0;
|
|
621
|
+
this.requestUpdate();
|
|
622
|
+
});
|
|
623
|
+
}
|
|
624
|
+
face(tg) {
|
|
625
|
+
const now = Date.now(), pending = this.pending, f = this.flushing, quiet = this.quiet(tg), maxWait = this.maxWait(tg);
|
|
626
|
+
const travel = f ? flushTravel(f, now) : 0;
|
|
627
|
+
const placed = [...pending.map((e, i) => ({ e, pos: arrivalPos(i, e.at, now) })), ...f ? f.events.map((e, i) => ({ e, pos: arrivalPos(i, e.at, now) - travel })) : []];
|
|
628
|
+
const items = placed.filter((p) => p.pos <= G.maxPos && p.pos > G.hidePos).map((p) => ({ ...slotXY(p.pos), v: p.e.value }));
|
|
629
|
+
const overflow = placed.filter((p) => p.pos > G.maxPos).length;
|
|
630
|
+
const live = bucketView(placed.filter((p) => p.pos <= G.hidePos).map((p) => p.e));
|
|
631
|
+
const ease = 1 - Math.pow(1 - clamp01((now - this.lastCommitAt) / G.slideMs), 3);
|
|
632
|
+
const doorDeg = f ? Math.round(80 * Math.min(clamp01((now - f.at) / 140), clamp01((f.doneAt - now - 60) / 160))) : 0;
|
|
633
|
+
const n = pending.length, first = pending[0]?.at ?? 0, last = pending.at(-1)?.at ?? 0;
|
|
634
|
+
const dropIn = n ? Math.max(0, Math.round(dueAt(pending, quiet, maxWait) - now)) : 0;
|
|
635
|
+
const status = n ? "collecting " + n + (f ? " · hatch busy" : " · drops in " + dropIn + " ms (" + reasonFor(pending, quiet, maxWait) + ")") : f ? "hatch open · dropping " + f.events.length : "idle · waiting for events";
|
|
636
|
+
const total = this.committed + (f?.events.length ?? 0) + n, batches = this.batchSeq + (f ? 1 : 0);
|
|
637
|
+
const k = Math.max(0.1, Math.min(this.fit.w / BOX.w, this.fit.h / BOX.h));
|
|
638
|
+
const dx = (this.fit.w - BOX.w * k) / 2 - BOX.x * k, dy = Math.max(0, (this.fit.h - BOX.h * k) / 2);
|
|
639
|
+
const muted = "var(--nano-muted, #9AA4B2)", fg = "var(--nano-fg, #E6EAF0)", warn = "var(--nano-warn, #E8B04B)";
|
|
640
|
+
return html4`<div style="box-sizing:border-box; height:100%; padding:12px 16px; display:flex; flex-direction:column; gap:12px; background:var(--nano-bg, #0E1116); color:${fg}; font-family:Inter, system-ui, sans-serif; overflow:hidden">
|
|
641
|
+
<div style="display:flex; justify-content:space-between; align-items:flex-end; gap:12px 20px; flex-wrap:wrap; font-family:${MONO}; font-size:12px; color:${muted}">
|
|
642
|
+
<div style="display:flex; gap:20px">
|
|
643
|
+
<div style="display:flex; flex-direction:column; gap:4px"><span>in → out</span><span class="ratio" style="color:${fg}; font-size:14px">${total} → ${batches} batches</span></div>
|
|
644
|
+
<div style="display:flex; flex-direction:column; gap:4px"><span>avg batch</span><span style="color:${fg}; font-size:14px">${this.batchSeq ? (this.committed / this.batchSeq).toFixed(1) + " values" : "—"}</span></div>
|
|
645
|
+
</div>
|
|
646
|
+
<div style="display:flex; gap:12px 20px; flex-wrap:wrap">
|
|
647
|
+
${slider("quiet", "Quiet period in milliseconds", 0, 5000, 50, quiet, n ? now - last : 0, "var(--nano-accent, #8FB3FF)", (v) => {
|
|
648
|
+
this.dragged = { ...this.dragged, quietMs: v };
|
|
649
|
+
this.requestUpdate();
|
|
650
|
+
}, (v) => this.set(tg, { quietMs: v }))}
|
|
651
|
+
${slider("max wait", "Maximum wait in milliseconds", 100, 1e4, 100, maxWait ?? 1000, n ? now - first : 0, warn, (v) => {
|
|
652
|
+
this.dragged = { ...this.dragged, maxWaitMs: v };
|
|
653
|
+
this.requestUpdate();
|
|
654
|
+
}, (v) => this.set(tg, { maxWaitMs: v }), { on: maxWait !== undefined, toggle: (on) => this.set(tg, { maxWaitMs: on ? 1000 : undefined }) })}
|
|
655
|
+
</div>
|
|
656
|
+
</div>
|
|
657
|
+
<div class="fit" style="flex:1; min-height:0; position:relative; overflow:hidden"><div style="position:absolute; left:0; top:0; width:1200px; height:610px; transform:translate(${dx}px, ${dy}px) scale(${k}); transform-origin:0 0">
|
|
658
|
+
${track()}
|
|
659
|
+
${overflow ? html4`<div style="position:absolute; left:100px; top:70px; font-family:${MONO}; font-size:12px; color:${warn}">+${overflow} queued</div>` : ""}
|
|
660
|
+
<div class="status" style="position:absolute; left:660px; top:214px; width:400px; text-align:right; font-family:${MONO}; font-size:13px; color:${muted}">${status}</div>
|
|
661
|
+
<div style="position:absolute; left:1146px; top:210px; font-family:${MONO}; font-size:11px; letter-spacing:0.08em; color:${muted}">HATCH</div>
|
|
662
|
+
<div style="position:absolute; left:1082px; top:206px; width:28px; height:6px; border-radius:2px; background:${warn}; transform-origin:0 50%; transform:rotate(${doorDeg}deg); z-index:2"></div>
|
|
663
|
+
<div style="position:absolute; left:1110px; top:206px; width:28px; height:6px; border-radius:2px; background:${warn}; transform-origin:100% 50%; transform:rotate(${-doorDeg}deg); z-index:2"></div>
|
|
664
|
+
${items.map((it) => html4`<div class="item" style="position:absolute; left:${Math.round(it.x - 20)}px; top:${Math.round(it.y - 20)}px; width:40px; height:40px; box-sizing:border-box; border-radius:10px; border:1.5px solid ${colorOf(it.v)}; background:${tint(colorOf(it.v), 0.16)}; color:${colorOf(it.v)}; display:flex; align-items:center; justify-content:center; z-index:3; font-family:${MONO}; font-size:11px; overflow:hidden">${label(it.v, 4)}</div>`)}
|
|
665
|
+
<div style="position:absolute; left:0; top:0; width:1200px; height:610px; transform:translateX(${Math.round(G.pitch * (1 - ease))}px); pointer-events:none">
|
|
666
|
+
${this.batches.slice().reverse().map((b, i) => bucket(bucketView(b.events), G.xEnd - G.pitch * (i + 1) - G.pitch / 2, i + 1 >= G.history ? Math.round((1 - ease) * 100) / 100 : 1, "#" + b.id, b.reason, REASON_COLOR[b.reason], false))}
|
|
667
|
+
</div>
|
|
668
|
+
${bucket(live, 1049, 1, "#" + (this.batchSeq + 1), f ? "filling · " + f.reason : "next batch", muted, true, f ? warn : "var(--nano-border-strong, #3A4350)")}
|
|
669
|
+
</div></div>
|
|
670
|
+
</div>`;
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
// packages/ui/src/views/input.ts
|
|
675
|
+
import { html as html5 } from "lit";
|
|
676
|
+
class NanoInput extends ViewElement {
|
|
677
|
+
value = "";
|
|
678
|
+
kind(tg) {
|
|
679
|
+
return tg.app.deployment().pods[tg.pod]?.config?.kind ?? "text";
|
|
680
|
+
}
|
|
681
|
+
async edit(tg, v) {
|
|
682
|
+
this.value = v;
|
|
683
|
+
await this.pod(tg).change(v);
|
|
684
|
+
}
|
|
685
|
+
async send(tg) {
|
|
686
|
+
await this.pod(tg).submit(this.value);
|
|
687
|
+
}
|
|
688
|
+
async setKind(tg, kind) {
|
|
689
|
+
const d = tg.app.deployment(), p = d.pods[tg.pod];
|
|
690
|
+
if (!p)
|
|
691
|
+
return;
|
|
692
|
+
const pods = { ...d.pods, [tg.pod]: { ...p, config: { ...p.config, kind } } };
|
|
693
|
+
this.value = kind === "boolean" ? false : kind === "number" ? 0 : "";
|
|
694
|
+
await tg.app.apply({ ...d, pods });
|
|
695
|
+
}
|
|
696
|
+
face(tg) {
|
|
697
|
+
const kind = this.kind(tg), box = (e) => e.target;
|
|
698
|
+
const parse = (el) => kind === "number" ? el.value === "" ? null : Number(el.value) : kind === "boolean" ? el.checked : el.value;
|
|
699
|
+
const key = (e) => {
|
|
700
|
+
if (e.key !== "Enter" || kind === "textarea" && !e.ctrlKey && !e.metaKey)
|
|
701
|
+
return;
|
|
702
|
+
e.preventDefault();
|
|
703
|
+
this.value = parse(box(e));
|
|
704
|
+
this.send(tg);
|
|
705
|
+
};
|
|
706
|
+
const field = kind === "textarea" ? html5`<textarea rows="3" aria-label=${tg.pod} .value=${String(this.value ?? "")} @input=${(e) => this.edit(tg, parse(box(e)))} @keydown=${key}></textarea>` : kind === "boolean" ? html5`<input type="checkbox" aria-label=${tg.pod} .checked=${!!this.value} @change=${async (e) => {
|
|
707
|
+
await this.edit(tg, parse(box(e)));
|
|
708
|
+
await this.send(tg);
|
|
709
|
+
}}>` : html5`<input type=${kind} aria-label=${tg.pod} .value=${String(this.value ?? "")} @input=${(e) => this.edit(tg, parse(box(e)))} @keydown=${key}>`;
|
|
710
|
+
return html5`<div class="row">
|
|
711
|
+
<select aria-label="Kind" @change=${(e) => this.setKind(tg, e.target.value)}>${KINDS.map((k) => html5`<option ?selected=${k === kind}>${k}</option>`)}</select>
|
|
712
|
+
${field}<button class="primary" @click=${() => this.send(tg)}>Send</button></div>`;
|
|
713
|
+
}
|
|
714
|
+
}
|
|
715
|
+
|
|
716
|
+
// packages/ui/src/explorer.ts
|
|
717
|
+
import { LitElement as LitElement3, css as css3, html as html9 } from "lit";
|
|
718
|
+
|
|
719
|
+
// packages/ui/src/explorer-details.ts
|
|
720
|
+
import { html as html6, nothing } from "lit";
|
|
721
|
+
var op = (port3) => port3.slice(port3.lastIndexOf("/") + 1);
|
|
722
|
+
var row = (k, v) => html6`<dt>${k}</dt><dd>${v}</dd>`;
|
|
723
|
+
var link = (c, id, label2) => html6`<a href="#" @click=${(e) => {
|
|
724
|
+
e.preventDefault();
|
|
725
|
+
c.go(id);
|
|
726
|
+
}}>${label2}</a>`;
|
|
727
|
+
var list = (items) => items.length ? html6`<ul>${items.map((i) => html6`<li>${i}</li>`)}</ul>` : html6`<span class="muted">none</span>`;
|
|
728
|
+
var placed = (d, pod) => Object.keys(d.runtimes).filter((r) => d.runtimes[r].pods.includes(pod));
|
|
729
|
+
var podLink = (c, pod) => {
|
|
730
|
+
const r = placed(c.d, pod)[0];
|
|
731
|
+
return r ? link(c, `p:${r}:${pod}`, pod) : pod;
|
|
732
|
+
};
|
|
733
|
+
var pipeText = (s, end = (p) => p) => html6`${end(s.from)}.${op(s.source)} → ${end(s.to)}.${op(s.target)}`;
|
|
734
|
+
var opAt = (c, port3) => {
|
|
735
|
+
const at = port3.lastIndexOf("/"), coord = port3.slice(0, at), name = port3.slice(at + 1);
|
|
736
|
+
return { coord, name, o: Object.values(c.registry.interface(coord)?.ops ?? {}).find((x) => x.name === name) };
|
|
737
|
+
};
|
|
738
|
+
var callRow = (c, x, from, to) => html6`${from ? html6`${podLink(c, x.from)}.` : nothing}${x.source === null ? "?" : op(x.source)} → ${to ? html6`${podLink(c, x.to)}.` : nothing}${op(x.target)}${x.declared ? nothing : html6` <span class="warn">not declared</span>`}`;
|
|
739
|
+
function pod(c, runtime, name) {
|
|
740
|
+
const p = c.d.pods[name];
|
|
741
|
+
if (!p)
|
|
742
|
+
return html6`<p class="muted">${name} is no longer deployed.</p>`;
|
|
743
|
+
const impl = c.registry.implementation(p.implementation);
|
|
744
|
+
const subs = Object.entries(c.d.runtimes).flatMap(([r, rt]) => rt.subscriptions.map((s) => ({ r, s })));
|
|
745
|
+
const calls = subs.filter(({ s }) => s.kind === "call" && s.from === name).map(({ s }) => s.to);
|
|
746
|
+
const needs = Object.entries(impl?.dependencies ?? {}).map(([role, sel]) => {
|
|
747
|
+
const to = calls.find((t) => {
|
|
748
|
+
const i = c.registry.implementation(c.d.pods[t]?.implementation ?? "");
|
|
749
|
+
return !sel.implements || i?.provides.some((x) => x.coord === String(sel.implements));
|
|
750
|
+
});
|
|
751
|
+
return html6`${role} (${sel.implements ?? "any"}) → ${to ? podLink(c, to) : html6`<span class="warn">not connected</span>`}`;
|
|
752
|
+
});
|
|
753
|
+
return html6`<h3>pod ${name}</h3><dl>
|
|
754
|
+
${row("implementation", link(c, `m:${p.implementation}`, p.implementation))}
|
|
755
|
+
${row("runtimes", placed(c.d, name).map((r, i) => html6`${i ? ", " : ""}${link(c, `r:${r}`, r)}`))}
|
|
756
|
+
${row("isolation", p.isolation ?? "host")}${row("starts", p.eager ? "eager" : "lazy")}${row("state", c.status(placed(c.d, name)[0] ?? "", name))}
|
|
757
|
+
${row("config", p.config === undefined ? html6`<span class="muted">none</span>` : html6`<code>${JSON.stringify(p.config)}</code>`)}
|
|
758
|
+
${row("needs", list(needs))}
|
|
759
|
+
${c.calls ? row("calls", list(c.calls.filter((x) => x.from === name).map((x) => callRow(c, x, false, true)))) : nothing}
|
|
760
|
+
${row("called by", c.calls?.some((x) => x.to === name) ? list(c.calls.filter((x) => x.to === name).map((x) => callRow(c, x, true, false))) : list(subs.filter(({ s }) => s.kind === "call" && s.to === name).map(({ s }) => podLink(c, s.from))))}
|
|
761
|
+
${row("pipes", list(subs.flatMap(({ s }) => s.kind === "pipe" && (s.from === name || s.to === name) ? [pipeText(s)] : [])))}
|
|
762
|
+
</dl><button class="btn" @click=${() => c.open({ runtime, pod: name })}>Open view</button>`;
|
|
763
|
+
}
|
|
764
|
+
function runtime(c, id) {
|
|
765
|
+
const r = c.d.runtimes[id];
|
|
766
|
+
if (!r)
|
|
767
|
+
return html6`<p class="muted">${id} is no longer deployed.</p>`;
|
|
768
|
+
return html6`<h3>runtime ${id}</h3><dl>
|
|
769
|
+
${row("pods", list(r.pods.map((p) => link(c, `p:${id}:${p}`, p))))}
|
|
770
|
+
${row("call edges", list(r.subscriptions.flatMap((s) => s.kind === "call" ? [html6`${podLink(c, s.from)} → ${podLink(c, s.to)}`] : [])))}
|
|
771
|
+
${row("pipes", list(r.subscriptions.flatMap((s) => s.kind === "pipe" ? [pipeText(s)] : [])))}
|
|
772
|
+
${row("policy", !r.policy ? "none (everything allowed)" : r.policy.kind === "rules" ? `${r.policy.rules.length} rules (see Settings)` : r.policy.kind)}
|
|
773
|
+
</dl><button class="btn" @click=${() => c.remove(id)}>Delete runtime</button>`;
|
|
774
|
+
}
|
|
775
|
+
var typeName = (def) => {
|
|
776
|
+
if (!def)
|
|
777
|
+
return "nothing";
|
|
778
|
+
if (def.label)
|
|
779
|
+
return def.label;
|
|
780
|
+
if (def.anyOf)
|
|
781
|
+
return def.anyOf.map(typeName).join(" | ");
|
|
782
|
+
if (def.const !== undefined)
|
|
783
|
+
return JSON.stringify(def.const);
|
|
784
|
+
if (def.type === "object") {
|
|
785
|
+
const k = Object.keys(def.properties ?? {});
|
|
786
|
+
return `{ ${k.slice(0, 4).join(", ")}${k.length > 4 ? ", …" : ""} }`;
|
|
787
|
+
}
|
|
788
|
+
if (def.type === "array")
|
|
789
|
+
return `${typeName(def.items)}[]`;
|
|
790
|
+
return def.type ?? "any";
|
|
791
|
+
};
|
|
792
|
+
function opRow(c, port3, side) {
|
|
793
|
+
const { coord, name, o } = opAt(c, port3);
|
|
794
|
+
const type = o && (side === "source" ? o.output : o.input);
|
|
795
|
+
return html6`${link(c, `i:${coord}`, coord)}/<code>${name}</code>${o ? html6` <span class="muted">${o.kind}, ${side === "source" ? "emits" : "takes"}</span> <code>${typeName(type)}</code>` : nothing}`;
|
|
796
|
+
}
|
|
797
|
+
function subscription(c, runtime2, pod2, i) {
|
|
798
|
+
const s = c.d.runtimes[runtime2]?.subscriptions.filter((x) => x.from === pod2)[i];
|
|
799
|
+
if (!s)
|
|
800
|
+
return html6`<p class="muted">That subscription is no longer deployed.</p>`;
|
|
801
|
+
return html6`<h3>${s.kind === "call" ? "call edge" : "pipe"}</h3><dl>
|
|
802
|
+
${row("runtime", link(c, `r:${runtime2}`, runtime2))}${row("from", podLink(c, s.from))}${row("to", podLink(c, s.to))}
|
|
803
|
+
${s.kind === "pipe" ? html6`${row("source", opRow(c, s.source, "source"))}${row("target", opRow(c, s.target, "target"))}` : nothing}
|
|
804
|
+
</dl>${s.kind === "call" ? html6`<button class="btn" @click=${() => c.open({ runtime: placed(c.d, s.to)[0] ?? runtime2, pod: s.to })}>Open ${s.to}</button>` : nothing}`;
|
|
805
|
+
}
|
|
806
|
+
function iface(c, coord) {
|
|
807
|
+
const i = c.registry.manifest().interfaces.find((x) => x.coord === coord);
|
|
808
|
+
if (!i)
|
|
809
|
+
return html6`<p class="muted">${coord} is not registered.</p>`;
|
|
810
|
+
return html6`<h3>interface ${coord}</h3><dl>
|
|
811
|
+
${row("ops", list(i.ops.map(({ name, kind }) => {
|
|
812
|
+
const { o } = opAt(c, `${coord}/${name}`), out = html6`<code>${typeName(o?.output)}</code>`;
|
|
813
|
+
const shape = kind === "event" ? html6`emits ${out}` : html6`<code>${typeName(o?.input)}</code> → ${out}`;
|
|
814
|
+
return html6`${link(c, `o:${coord}/${name}`, name)} ${kind} <span class="muted">${shape}</span>`;
|
|
815
|
+
})))}
|
|
816
|
+
${row("implementations", list(c.registry.implementationsOf(coord).map((m) => link(c, `m:${m.coord}`, m.coord))))}
|
|
817
|
+
</dl>`;
|
|
818
|
+
}
|
|
819
|
+
function implementation(c, coord) {
|
|
820
|
+
const m = c.registry.implementation(coord);
|
|
821
|
+
if (!m)
|
|
822
|
+
return html6`<p class="muted">${coord} is not registered.</p>`;
|
|
823
|
+
return html6`<h3>implementation ${coord}</h3>${m.description ? html6`<p>${m.description}</p>` : nothing}<dl>
|
|
824
|
+
${row("provider", m.provider)}
|
|
825
|
+
${row("provides", list(m.provides.map((i) => link(c, `i:${i.coord}`, i.coord))))}
|
|
826
|
+
${row("needs", list(Object.entries(m.dependencies).map(([role, s]) => html6`${role}: ${s.implements ? link(c, `i:${s.implements}`, String(s.implements)) : JSON.stringify(s)}`)))}
|
|
827
|
+
${row("pods", list(Object.entries(c.d.pods).filter(([, p]) => p.implementation === coord).map(([n]) => podLink(c, n))))}
|
|
828
|
+
</dl>`;
|
|
829
|
+
}
|
|
830
|
+
function operation(c, port3) {
|
|
831
|
+
const { coord, name, o } = opAt(c, port3);
|
|
832
|
+
if (!o)
|
|
833
|
+
return html6`<p class="muted">${port3} is not registered.</p>`;
|
|
834
|
+
const impls = c.registry.implementationsOf(coord).map((m) => m.coord);
|
|
835
|
+
const subs = Object.values(c.d.runtimes).flatMap((r) => r.subscriptions);
|
|
836
|
+
const pipes = subs.flatMap((s) => s.kind === "pipe" && (s.source === port3 || s.target === port3) ? [pipeText(s, (p) => podLink(c, p))] : []);
|
|
837
|
+
return html6`<h3>${o.kind} ${name}</h3>${o.description ? html6`<p>${o.description}</p>` : nothing}<dl>
|
|
838
|
+
${row("interface", link(c, `i:${coord}`, coord))}
|
|
839
|
+
${o.kind === "event" ? row("emits", html6`<code>${typeName(o.output)}</code>`) : html6`${row("takes", html6`<code>${typeName(o.input)}</code>`)}${row("returns", html6`<code>${typeName(o.output)}</code>`)}`}
|
|
840
|
+
${row("implementations", list(impls.map((m) => link(c, `m:${m}`, m))))}
|
|
841
|
+
${row("pods", list(Object.keys(c.d.pods).filter((p) => impls.includes(c.d.pods[p].implementation)).map((p) => podLink(c, p))))}
|
|
842
|
+
${row("pipes", list(pipes))}
|
|
843
|
+
${c.calls ? html6`${row("called by", list(c.calls.filter((x) => x.target === port3).map((x) => callRow(c, x, true, true))))}${row("calls", list(c.calls.filter((x) => x.source === port3).map((x) => callRow(c, x, true, true))))}` : nothing}
|
|
844
|
+
</dl>`;
|
|
845
|
+
}
|
|
846
|
+
function details(c, id) {
|
|
847
|
+
if (!id)
|
|
848
|
+
return html6`<p class="muted">Select a runtime, pod, subscription, interface, implementation or operation.</p>`;
|
|
849
|
+
const [kind, ...rest] = id.split(":"), at = rest.join(":");
|
|
850
|
+
if (kind === "r")
|
|
851
|
+
return runtime(c, at);
|
|
852
|
+
if (kind === "p")
|
|
853
|
+
return pod(c, rest[0], rest.slice(1).join(":"));
|
|
854
|
+
if (kind === "s")
|
|
855
|
+
return subscription(c, rest[0], rest[1], Number(rest[2]));
|
|
856
|
+
if (kind === "i")
|
|
857
|
+
return iface(c, at);
|
|
858
|
+
if (kind === "m")
|
|
859
|
+
return implementation(c, at);
|
|
860
|
+
if (kind === "o")
|
|
861
|
+
return operation(c, at);
|
|
862
|
+
return html6``;
|
|
863
|
+
}
|
|
864
|
+
|
|
865
|
+
// packages/ui/src/explorer-nodes.ts
|
|
866
|
+
import { html as html7 } from "lit";
|
|
867
|
+
var primary = (id) => id.slice(id.lastIndexOf("|") + 1);
|
|
868
|
+
var op2 = (port3) => port3.slice(port3.lastIndexOf("/") + 1);
|
|
869
|
+
var namespaceOf = (coord) => coord.includes("/") ? coord.slice(0, coord.indexOf("/")) : coord.slice(0, Math.max(0, coord.lastIndexOf(".")));
|
|
870
|
+
var group = (id, label2, children) => ({ id, label: label2, count: children.length, children });
|
|
871
|
+
var alias = (at, n) => ({ ...n, id: `${at}|${n.id}`, children: undefined, body: undefined });
|
|
872
|
+
function nodes(d, registry, status) {
|
|
873
|
+
const m = registry.manifest();
|
|
874
|
+
const ops = m.interfaces.flatMap((i) => i.ops.map((o) => ({ port: `${i.coord}/${o.name}`, iface: i.coord, name: o.name, kind: o.kind })));
|
|
875
|
+
const provides = (impl) => registry.implementation(impl)?.provides.map((i) => i.coord) ?? [];
|
|
876
|
+
const where = (pod2) => Object.keys(d.runtimes).find((r) => d.runtimes[r].pods.includes(pod2)) ?? "";
|
|
877
|
+
const podNode = (pod2) => ({ id: `p:${where(pod2)}:${pod2}`, label: pod2, kind: "pod", data: { ns: namespaceOf(d.pods[pod2]?.implementation ?? ""), status: status(where(pod2), pod2) } });
|
|
878
|
+
const ifaceNode = (c) => ({ id: `i:${c}`, label: c, kind: "interface", data: { ns: namespaceOf(c) } });
|
|
879
|
+
const implNode = (c) => ({ id: `m:${c}`, label: c, kind: "implementation", data: { ns: namespaceOf(c) } });
|
|
880
|
+
const opNode = (o) => ({ id: `o:${o.port}`, label: o.port, kind: o.kind, data: { ns: namespaceOf(o.iface) } });
|
|
881
|
+
const runtimes = Object.entries(d.runtimes).map(([runtime2, r]) => {
|
|
882
|
+
const at = `r:${runtime2}`;
|
|
883
|
+
const impls = [...new Set(r.pods.map((p) => d.pods[p]?.implementation).filter((x) => !!x))];
|
|
884
|
+
const ifaces = [...new Set(impls.flatMap(provides))];
|
|
885
|
+
const pods = r.pods.map((pod2) => {
|
|
886
|
+
const p = d.pods[pod2];
|
|
887
|
+
const subs = r.subscriptions.filter((s) => s.from === pod2).map((s, i) => ({
|
|
888
|
+
id: `s:${runtime2}:${pod2}:${i}`,
|
|
889
|
+
label: s.kind === "call" ? `built on → ${s.to}` : `${op2(s.source)} → ${s.to}.${op2(s.target)}`
|
|
890
|
+
}));
|
|
891
|
+
return {
|
|
892
|
+
...podNode(pod2),
|
|
893
|
+
id: `p:${runtime2}:${pod2}`,
|
|
894
|
+
terms: [p?.implementation ?? ""],
|
|
895
|
+
body: html7`${p?.implementation} ${p?.config === undefined ? "" : JSON.stringify(p.config)}`,
|
|
896
|
+
children: subs
|
|
897
|
+
};
|
|
898
|
+
});
|
|
899
|
+
return { id: at, label: runtime2, kind: "runtime", count: r.pods.length, data: { ns: namespaceOf(runtime2) }, children: [
|
|
900
|
+
group(`${at}/pods`, "Pods", pods),
|
|
901
|
+
group(`${at}/impls`, "Implementations", impls.map((c) => alias(at, implNode(c)))),
|
|
902
|
+
group(`${at}/ifaces`, "Interfaces", ifaces.map((c) => alias(at, ifaceNode(c)))),
|
|
903
|
+
group(`${at}/ops`, "Operations", ops.filter((o) => ifaces.includes(o.iface)).map((o) => alias(at, opNode(o))))
|
|
904
|
+
] };
|
|
905
|
+
});
|
|
906
|
+
return runtimes;
|
|
907
|
+
}
|
|
908
|
+
var namespaces = (list2) => [...new Set(list2.flatMap(function all(n) {
|
|
909
|
+
return [...n.data?.ns ? [n.data.ns] : [], ...(n.children ?? []).flatMap(all)];
|
|
910
|
+
}))].filter(Boolean).sort();
|
|
911
|
+
|
|
912
|
+
// packages/ui/src/filter/model.ts
|
|
913
|
+
var emptyFilter = () => ({ text: "", kinds: new Set, namespaces: new Set, statuses: new Set });
|
|
914
|
+
function matches(item, f, known) {
|
|
915
|
+
const q = f.text.toLowerCase();
|
|
916
|
+
const ns10 = known?.namespaces ? [...f.namespaces].filter((n) => known.namespaces.has(n)) : [...f.namespaces];
|
|
917
|
+
return (!q || [item.label, ...item.terms ?? []].some((s) => s.toLowerCase().includes(q))) && (!f.kinds.size || !!item.kind && f.kinds.has(item.kind)) && (!ns10.length || !!item.ns && ns10.includes(item.ns)) && (!f.statuses.size || !!item.status && f.statuses.has(item.status));
|
|
918
|
+
}
|
|
919
|
+
function filterTree(nodes2, f) {
|
|
920
|
+
const known = { namespaces: new Set(namespaces(nodes2)) };
|
|
921
|
+
const walk = (list2) => list2.flatMap((n) => {
|
|
922
|
+
const item = { label: n.label, kind: n.kind, ns: n.data?.ns, status: n.data?.status, terms: n.terms };
|
|
923
|
+
if (n.kind && matches(item, f, known))
|
|
924
|
+
return [n];
|
|
925
|
+
const kids = walk(n.children ?? []);
|
|
926
|
+
return kids.length ? [{ ...n, children: kids, body: undefined, ...n.count !== undefined && !n.kind && { count: kids.length } }] : [];
|
|
927
|
+
});
|
|
928
|
+
return walk(nodes2);
|
|
929
|
+
}
|
|
930
|
+
|
|
931
|
+
// packages/ui/src/filter/filter.ts
|
|
932
|
+
import { LitElement as LitElement2, css as css2, html as html8 } from "lit";
|
|
933
|
+
import { base as base2, kit, t } from "@pritzlaff/nano-elements";
|
|
934
|
+
var names = { kinds: "Type", namespaces: "Namespace", statuses: "Status" };
|
|
935
|
+
|
|
936
|
+
class NanoFilter extends LitElement2 {
|
|
937
|
+
static properties = { groups: { attribute: false }, value: { attribute: false }, open: { state: true } };
|
|
938
|
+
static styles = [base2, kit, css2`
|
|
939
|
+
:host { position: relative; display: flex; gap: 6px; align-items: center }
|
|
940
|
+
input { flex: 1 1 auto; min-width: 0 }
|
|
941
|
+
.pop { box-sizing: border-box; padding: 8px } .pop:popover-open { display: grid; gap: 8px }
|
|
942
|
+
.row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center } .row > span { width: 100%; font-size: 11px; color: ${t("muted")} }
|
|
943
|
+
.n { margin-left: 4px; padding: 0 6px; border-radius: 999px; background: ${t("accent-soft")}; color: ${t("fg")}; font-weight: 600; font-variant-numeric: tabular-nums }`];
|
|
944
|
+
constructor() {
|
|
945
|
+
super();
|
|
946
|
+
this.groups = {};
|
|
947
|
+
this.value = emptyFilter();
|
|
948
|
+
this.open = false;
|
|
949
|
+
}
|
|
950
|
+
emit(v) {
|
|
951
|
+
this.dispatchEvent(new CustomEvent("change", { detail: v, bubbles: true, composed: true }));
|
|
952
|
+
}
|
|
953
|
+
flip(g, o) {
|
|
954
|
+
const set = new Set(this.value[g]);
|
|
955
|
+
set.has(o) ? set.delete(o) : set.add(o);
|
|
956
|
+
this.emit({ ...this.value, [g]: set });
|
|
957
|
+
}
|
|
958
|
+
toggled(e) {
|
|
959
|
+
const panel = e.target, button = this.renderRoot.querySelector(".toggle");
|
|
960
|
+
this.open = e.newState === "open";
|
|
961
|
+
if (this.open) {
|
|
962
|
+
const h = this.getBoundingClientRect(), b = button.getBoundingClientRect();
|
|
963
|
+
Object.assign(panel.style, { top: `${b.bottom + 4}px`, left: `${Math.max(0, h.left)}px`, width: `${Math.max(220, h.width)}px`, maxWidth: `calc(100vw - ${Math.max(0, h.left)}px)` });
|
|
964
|
+
panel.querySelector(".row button")?.focus();
|
|
965
|
+
} else if (panel.contains(this.shadowRoot.activeElement))
|
|
966
|
+
button.focus();
|
|
967
|
+
}
|
|
968
|
+
render() {
|
|
969
|
+
const v = this.value, count = v.kinds.size + v.namespaces.size + v.statuses.size;
|
|
970
|
+
const rows = Object.keys(names).filter((g) => this.groups[g]);
|
|
971
|
+
return html8`
|
|
972
|
+
<input type="search" placeholder="Search" aria-label="Search" .value=${v.text} @input=${(e) => this.emit({ ...v, text: e.target.value })}>
|
|
973
|
+
<button class="toggle" popovertarget="panel" aria-haspopup="true" aria-controls="panel" aria-expanded=${this.open}>Filter${count ? ` (${count} active)` : ""}</button>
|
|
974
|
+
<div class="pop" id="panel" popover="auto" role="group" aria-label="Filters" @toggle=${this.toggled}>${rows.map((g) => html8`
|
|
975
|
+
<div class="row" role="group" aria-labelledby="h-${g}"><span id="h-${g}">${names[g]}${v[g].size ? html8` <b class="n" aria-label="${v[g].size} chosen">${v[g].size}</b>` : ""}</span>${this.groups[g].map((o) => html8`
|
|
976
|
+
<button aria-pressed=${v[g].has(o)} @click=${() => this.flip(g, o)}>${o}</button>`)}</div>`)}</div>`;
|
|
977
|
+
}
|
|
978
|
+
}
|
|
979
|
+
|
|
980
|
+
// packages/ui/src/explorer.ts
|
|
981
|
+
import { base as base3 } from "@pritzlaff/nano-elements";
|
|
982
|
+
import"@pritzlaff/nano-elements";
|
|
983
|
+
var KINDS2 = ["runtime", "pod", "interface", "implementation", "action", "event"];
|
|
984
|
+
var STATUSES = ["running", "not started", "stopped", "failed"];
|
|
985
|
+
var LIFECYCLE = new Set(["built", "closed", "restarted", "failure", "applied"]);
|
|
986
|
+
|
|
987
|
+
class NanoExplorer extends LitElement3 {
|
|
988
|
+
static properties = { target: { attribute: false }, icon: { attribute: false }, selected: { state: true }, filter: { state: true } };
|
|
989
|
+
static styles = [base3, css3`
|
|
990
|
+
:host { display: block; height: 100%; container-type: inline-size }
|
|
991
|
+
.pane { display: grid; grid-template-rows: auto minmax(0, 1fr); min-height: 0 }
|
|
992
|
+
nano-filter { padding: 0 0 6px }
|
|
993
|
+
.split { display: grid; grid-template-columns: minmax(0, max-content) minmax(0, 1fr); gap: 12px; height: 100% }
|
|
994
|
+
.details { overflow: auto; padding: 0 8px; border-left: 1px solid var(--nano-line, rgba(128,128,128,.3)) }
|
|
995
|
+
nano-tree { overflow: auto; min-height: 0 }
|
|
996
|
+
@container (max-width: 520px) { .split { grid-template-columns: 1fr; grid-template-rows: minmax(0, 3fr) minmax(0, 2fr) } .details { border-left: 0; border-top: 1px solid var(--nano-line, rgba(128,128,128,.3)); padding-top: 8px } }
|
|
997
|
+
h3 { margin: 4px 0 8px; font-size: 13px } dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 12px; margin: 0 0 12px; font-size: 12px }
|
|
998
|
+
a { color: inherit; text-decoration: underline dotted } dt { opacity: .7 } dd { margin: 0 } ul { margin: 0; padding-left: 16px } .warn { color: var(--nano-warn, #d9a400) } .muted { opacity: .7 }`];
|
|
999
|
+
off;
|
|
1000
|
+
watching;
|
|
1001
|
+
constructor() {
|
|
1002
|
+
super();
|
|
1003
|
+
this.selected = null;
|
|
1004
|
+
this.filter = emptyFilter();
|
|
1005
|
+
}
|
|
1006
|
+
connectedCallback() {
|
|
1007
|
+
super.connectedCallback();
|
|
1008
|
+
this.watch();
|
|
1009
|
+
}
|
|
1010
|
+
disconnectedCallback() {
|
|
1011
|
+
super.disconnectedCallback();
|
|
1012
|
+
this.stop();
|
|
1013
|
+
}
|
|
1014
|
+
willUpdate(changed) {
|
|
1015
|
+
if (changed.has("target"))
|
|
1016
|
+
this.watch();
|
|
1017
|
+
}
|
|
1018
|
+
watch() {
|
|
1019
|
+
const t2 = this.target;
|
|
1020
|
+
if (!t2 || !this.isConnected || this.watching === t2)
|
|
1021
|
+
return;
|
|
1022
|
+
this.stop();
|
|
1023
|
+
this.watching = t2;
|
|
1024
|
+
this.off = t2.app.listen((e) => {
|
|
1025
|
+
if (LIFECYCLE.has(e.type) || e.type === "sent" && e.kind === "call" && t2.calls)
|
|
1026
|
+
queueMicrotask(() => this.requestUpdate());
|
|
1027
|
+
});
|
|
1028
|
+
}
|
|
1029
|
+
stop() {
|
|
1030
|
+
this.off?.();
|
|
1031
|
+
this.off = undefined;
|
|
1032
|
+
this.watching = undefined;
|
|
1033
|
+
}
|
|
1034
|
+
open(w) {
|
|
1035
|
+
this.dispatchEvent(new CustomEvent("nano-open", { detail: w, bubbles: true, composed: true }));
|
|
1036
|
+
}
|
|
1037
|
+
del(runtime2) {
|
|
1038
|
+
this.dispatchEvent(new CustomEvent("nano-delete", { detail: { runtime: runtime2 }, bubbles: true, composed: true }));
|
|
1039
|
+
}
|
|
1040
|
+
dbl() {
|
|
1041
|
+
const [k, r, ...p] = (this.selected ?? "").split(":");
|
|
1042
|
+
if (k === "p")
|
|
1043
|
+
this.open({ runtime: r, pod: p.join(":") });
|
|
1044
|
+
}
|
|
1045
|
+
render() {
|
|
1046
|
+
if (!this.target)
|
|
1047
|
+
return html9``;
|
|
1048
|
+
const t2 = this.target;
|
|
1049
|
+
const status = (r, pod2) => {
|
|
1050
|
+
const s = t2.app.runtime(r).status(pod2);
|
|
1051
|
+
return s.ok ? s.value : "not started";
|
|
1052
|
+
};
|
|
1053
|
+
const c = { d: t2.app.deployment(), registry: t2.registry, status, calls: t2.calls, go: (id) => {
|
|
1054
|
+
this.selected = id;
|
|
1055
|
+
}, open: (w) => this.open(w), remove: (r) => this.del(r) };
|
|
1056
|
+
const all = nodes(c.d, t2.registry, status);
|
|
1057
|
+
const shown2 = filterTree(all, { ...this.filter, text: "" });
|
|
1058
|
+
const groups = { kinds: KINDS2, namespaces: namespaces(all), statuses: STATUSES };
|
|
1059
|
+
return html9`<div class="split"><div class="pane">
|
|
1060
|
+
<nano-filter .groups=${groups} .value=${this.filter} @change=${(e) => {
|
|
1061
|
+
this.filter = e.detail;
|
|
1062
|
+
}}></nano-filter>
|
|
1063
|
+
<nano-tree .nodes=${shown2} .icon=${this.icon} .query=${this.filter.text} .selected=${this.selected} open-depth="2" @dblclick=${() => this.dbl()}
|
|
1064
|
+
@select=${(e) => {
|
|
1065
|
+
e.preventDefault();
|
|
1066
|
+
const id = primary(e.detail.id);
|
|
1067
|
+
if (!/\/(pods|impls|ifaces|ops)$/.test(id))
|
|
1068
|
+
this.selected = id;
|
|
1069
|
+
}}></nano-tree></div>
|
|
1070
|
+
<section class="details" aria-label="Details">${details(c, this.selected)}</section></div>`;
|
|
1071
|
+
}
|
|
1072
|
+
}
|
|
1073
|
+
|
|
1074
|
+
// packages/ui/src/wiring/wiring.ts
|
|
1075
|
+
import { LitElement as LitElement4 } from "lit";
|
|
1076
|
+
|
|
1077
|
+
// packages/ui/src/wiring/constants.ts
|
|
1078
|
+
var TYPE_COLOR = { string: "#2dd4bf", number: "#fbbf24", boolean: "#f472b6", object: "#60a5fa", array: "#a78bfa", signal: "#94a3b8", any: "#e5e7eb", call: "#4CC2FF" };
|
|
1079
|
+
var TYPE_GLYPH = { string: "Aa", number: "#", boolean: "?", object: "{}", array: "[]", signal: "•", any: "*", call: "↦" };
|
|
1080
|
+
var TYPE_NAME = { string: "String", number: "Number", boolean: "Boolean", object: "Object", array: "Array", signal: "Signal", any: "Any", call: "Call" };
|
|
1081
|
+
var PW = 720;
|
|
1082
|
+
var PH = 440;
|
|
1083
|
+
var XSTEP = 140;
|
|
1084
|
+
var ZGAP = 160;
|
|
1085
|
+
var TILT = "rotateX(32deg) rotateY(-14deg)";
|
|
1086
|
+
var FADE_MIN = 0.15;
|
|
1087
|
+
var FADE_STEP = 0.35;
|
|
1088
|
+
var DIM_CABLE = 0.18;
|
|
1089
|
+
var fade = (d) => Math.max(FADE_MIN, 1 - FADE_STEP * Math.abs(d));
|
|
1090
|
+
var PAD = 24;
|
|
1091
|
+
var PAD_STEP = 30;
|
|
1092
|
+
var HEAD = 34;
|
|
1093
|
+
var SIDE_W = 280;
|
|
1094
|
+
var SIDE_GAP = 140;
|
|
1095
|
+
var BLOCK_HEAD = 30;
|
|
1096
|
+
var BLOCK_GAP = 28;
|
|
1097
|
+
var ITEM_GAP = 12;
|
|
1098
|
+
var ZOOM_MIN = 0.3;
|
|
1099
|
+
var ZOOM_MAX = 2.5;
|
|
1100
|
+
var MARGIN = 60;
|
|
1101
|
+
|
|
1102
|
+
// packages/ui/src/wiring/layout.ts
|
|
1103
|
+
var frameId = (at) => ("layer" in at) ? `l:${at.layer}` : `s:${at.side}`;
|
|
1104
|
+
var posKey = (frame, pad) => `${frame}|${pad}`;
|
|
1105
|
+
var slots = (pads, r) => {
|
|
1106
|
+
const n = { in: 0, out: 0 };
|
|
1107
|
+
return pads.map((pad) => ({ pad, x: pad.dir === "in" ? r.x : r.x + r.w, y: r.y + HEAD + PAD_STEP * n[pad.dir]++ + PAD / 2 }));
|
|
1108
|
+
};
|
|
1109
|
+
var union = (rs) => {
|
|
1110
|
+
const x0 = Math.min(...rs.map((r) => r.x)), y0 = Math.min(...rs.map((r) => r.y)), x1 = Math.max(...rs.map((r) => r.x + r.w)), y1 = Math.max(...rs.map((r) => r.y + r.h));
|
|
1111
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
|
|
1112
|
+
};
|
|
1113
|
+
var layerBoxes = (l) => l.footprints.map((f) => {
|
|
1114
|
+
const b = f.box, rect = { x: b.x * PW, y: b.y * PH, w: b.w * PW, h: b.h * PH };
|
|
1115
|
+
return { item: f, rect, pads: slots(f.pads, rect) };
|
|
1116
|
+
});
|
|
1117
|
+
function layout(c) {
|
|
1118
|
+
const pos = new Map;
|
|
1119
|
+
const register = (f) => {
|
|
1120
|
+
for (const b of f.boxes)
|
|
1121
|
+
for (const p of b.pads)
|
|
1122
|
+
pos.set(posKey(f.id, p.pad.key), { x: f.origin.x + p.x, y: f.origin.y + p.y });
|
|
1123
|
+
};
|
|
1124
|
+
const layers = c.layers.map((layer, index) => ({ layer, index, id: `l:${layer.screen}`, origin: { x: index * XSTEP, y: 0 }, rect: { x: index * XSTEP, y: 0, w: PW, h: PH }, boxes: layerBoxes(layer) }));
|
|
1125
|
+
const sideX = Math.max(0, c.layers.length - 1) * XSTEP + PW + SIDE_GAP;
|
|
1126
|
+
let y = 0;
|
|
1127
|
+
const blocks = c.side.map((block) => {
|
|
1128
|
+
let cy = BLOCK_HEAD;
|
|
1129
|
+
const boxes = block.items.map((item) => {
|
|
1130
|
+
const h = HEAD + PAD_STEP * Math.max(1, item.pads.filter((p) => p.dir === "in").length, item.pads.filter((p) => p.dir === "out").length) + 8;
|
|
1131
|
+
const rect = { x: 0, y: cy, w: SIDE_W, h };
|
|
1132
|
+
cy += h + ITEM_GAP;
|
|
1133
|
+
return { item, rect, pads: slots(item.pads, rect) };
|
|
1134
|
+
});
|
|
1135
|
+
const f = { block, id: `s:${block.system}`, origin: { x: sideX, y }, rect: { x: sideX, y, w: SIDE_W, h: cy }, boxes };
|
|
1136
|
+
y += cy + BLOCK_GAP;
|
|
1137
|
+
return f;
|
|
1138
|
+
});
|
|
1139
|
+
for (const f of [...layers, ...blocks])
|
|
1140
|
+
register(f);
|
|
1141
|
+
const pageRect = (i) => ({ x: i * XSTEP, y: 0, w: PW, h: PH });
|
|
1142
|
+
const bounds = union([...layers.map((l) => l.rect), ...blocks.map((b) => b.rect), { x: 0, y: 0, w: PW, h: PH }]);
|
|
1143
|
+
return { layers, blocks, pos, bounds, pageRect };
|
|
1144
|
+
}
|
|
1145
|
+
|
|
1146
|
+
// packages/ui/src/wiring/types.ts
|
|
1147
|
+
function padTypeOf(schema) {
|
|
1148
|
+
if (!schema)
|
|
1149
|
+
return "signal";
|
|
1150
|
+
const t2 = schema.type;
|
|
1151
|
+
if (t2 === "void" || t2 === "undefined")
|
|
1152
|
+
return "signal";
|
|
1153
|
+
if (t2 === "string" || t2 === "boolean" || t2 === "object" || t2 === "array")
|
|
1154
|
+
return t2;
|
|
1155
|
+
if (t2 === "number" || t2 === "integer")
|
|
1156
|
+
return "number";
|
|
1157
|
+
return "any";
|
|
1158
|
+
}
|
|
1159
|
+
|
|
1160
|
+
// packages/ui/src/wiring/model.ts
|
|
1161
|
+
var padsOf = (scope, pod2, deployment, registry) => {
|
|
1162
|
+
const impl = registry.implementation(deployment.pods[pod2]?.implementation ?? "");
|
|
1163
|
+
const pad = (port3, o, dir, kind, schema) => ({
|
|
1164
|
+
key: `${scope}${pod2} ${port3}:${dir}`,
|
|
1165
|
+
instance: pod2,
|
|
1166
|
+
op: port3,
|
|
1167
|
+
label: o.name,
|
|
1168
|
+
dir,
|
|
1169
|
+
kind,
|
|
1170
|
+
type: padTypeOf(schema?.schema),
|
|
1171
|
+
...o.description !== undefined && { description: o.description },
|
|
1172
|
+
...schema && { schema: schema.schema }
|
|
1173
|
+
});
|
|
1174
|
+
return (impl?.provides ?? []).flatMap((i) => Object.values(i.ops).flatMap((o) => {
|
|
1175
|
+
const port3 = `${i.coord}/${o.name}`;
|
|
1176
|
+
return o.kind === "action" ? [pad(port3, o, "in", "call", o.input), pad(port3, o, "out", "event", o.output)] : [pad(port3, o, "out", "event", o.output)];
|
|
1177
|
+
}));
|
|
1178
|
+
};
|
|
1179
|
+
var gridBoxes = (n) => {
|
|
1180
|
+
const cols = Math.ceil(Math.sqrt(n)), rows = Math.ceil(n / cols);
|
|
1181
|
+
return Array.from({ length: n }, (_, i) => ({ x: i % cols / cols, y: Math.floor(i / cols) / rows, w: 1 / cols, h: 1 / rows }));
|
|
1182
|
+
};
|
|
1183
|
+
function circuitOf(deployment, registry) {
|
|
1184
|
+
const runtimes = Object.entries(deployment.runtimes);
|
|
1185
|
+
const count = new Map;
|
|
1186
|
+
for (const [, r] of runtimes)
|
|
1187
|
+
for (const p of r.pods)
|
|
1188
|
+
count.set(p, (count.get(p) ?? 0) + 1);
|
|
1189
|
+
const shared = [...count].filter(([, n]) => n > 1).map(([p]) => p);
|
|
1190
|
+
const layers = runtimes.map(([id, r]) => {
|
|
1191
|
+
const grid = gridBoxes(r.pods.length);
|
|
1192
|
+
return { screen: id, title: id, system: id, footprints: r.pods.map((pod2, i) => ({ system: id, instance: pod2, title: pod2, box: grid[i], shared: shared.includes(pod2), pads: padsOf(`${id}/`, pod2, deployment, registry) })) };
|
|
1193
|
+
});
|
|
1194
|
+
const side = shared.map((pod2) => ({ system: pod2, items: [{ system: pod2, instance: pod2, title: pod2, pads: padsOf("shared:", pod2, deployment, registry) }] }));
|
|
1195
|
+
const cables = runtimes.flatMap(([id, r]) => r.subscriptions.flatMap((s) => {
|
|
1196
|
+
const pads = (pod2) => layers.find((l) => l.screen === id).footprints.find((f) => f.instance === pod2).pads;
|
|
1197
|
+
const at = { layer: id };
|
|
1198
|
+
if (s.kind === "call") {
|
|
1199
|
+
const a2 = pads(s.from).find((p) => p.dir === "out") ?? pads(s.from)[0], b2 = pads(s.to).find((p) => p.dir === "in") ?? pads(s.to)[0];
|
|
1200
|
+
return a2 && b2 ? [{ id: `${id}|${s.from}|${s.to}|call|`, system: id, from: { pad: a2.key, at }, to: { pad: b2.key, at }, type: "call" }] : [];
|
|
1201
|
+
}
|
|
1202
|
+
const a = pads(s.from).find((p) => p.op === s.source && p.dir === "out"), b = pads(s.to).find((p) => p.op === s.target && p.dir === "in");
|
|
1203
|
+
return a && b ? [{ id: `${id}|${s.from}|${s.to}|${s.target}|${s.source}`, system: id, from: { pad: a.key, at }, to: { pad: b.key, at }, type: a.type }] : [];
|
|
1204
|
+
}));
|
|
1205
|
+
for (const pod2 of shared) {
|
|
1206
|
+
const sp = side.find((b) => b.system === pod2).items[0].pads[0];
|
|
1207
|
+
for (const l of layers) {
|
|
1208
|
+
const p = l.footprints.find((f) => f.instance === pod2)?.pads[0];
|
|
1209
|
+
if (p && sp)
|
|
1210
|
+
cables.push({ id: `link|${l.screen}|${pod2}`, system: pod2, from: { pad: p.key, at: { layer: l.screen } }, to: { pad: sp.key, at: { side: pod2 } }, type: "signal" });
|
|
1211
|
+
}
|
|
1212
|
+
}
|
|
1213
|
+
return { layers, side, cables };
|
|
1214
|
+
}
|
|
1215
|
+
|
|
1216
|
+
// packages/ui/src/wiring/render-pills.ts
|
|
1217
|
+
import { html as html10 } from "lit";
|
|
1218
|
+
function renderPills(el) {
|
|
1219
|
+
const { focus } = el.s;
|
|
1220
|
+
return html10`<nav class="pills" aria-label="Wiring views">
|
|
1221
|
+
<button class="pill" data-whole @click=${() => el.fitAll()}>Whole board</button>
|
|
1222
|
+
${el.model.layers.map((l) => html10`<button class="pill" data-screen=${l.screen} aria-pressed=${focus === l.screen} @click=${() => el.go(l.screen)}>
|
|
1223
|
+
<span class="ic" aria-hidden="true">${l.title.slice(0, 1).toUpperCase()}</span>${l.title}</button>`)}
|
|
1224
|
+
</nav>`;
|
|
1225
|
+
}
|
|
1226
|
+
|
|
1227
|
+
// packages/ui/src/wiring/render-stage.ts
|
|
1228
|
+
import { html as html12, svg } from "lit";
|
|
1229
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
1230
|
+
|
|
1231
|
+
// packages/ui/src/wiring/render-drawer.ts
|
|
1232
|
+
import { html as html11, nothing as nothing2 } from "lit";
|
|
1233
|
+
var uniq = (xs) => [...new Set(xs)];
|
|
1234
|
+
function describe(el) {
|
|
1235
|
+
const { sel } = el.s, m = el.model;
|
|
1236
|
+
if (!sel)
|
|
1237
|
+
return null;
|
|
1238
|
+
const [what, id = ""] = [sel.slice(0, sel.indexOf(":")), sel.slice(sel.indexOf(":") + 1)];
|
|
1239
|
+
const items = [...m.layers.flatMap((l) => l.footprints), ...m.side.flatMap((b) => b.items)];
|
|
1240
|
+
const pads = items.flatMap((i) => i.pads), padOf = (key) => pads.find((p) => p.key === key);
|
|
1241
|
+
const routes = (p) => m.cables.filter((c) => c.from.pad === p.key || c.to.pad === p.key).length;
|
|
1242
|
+
const name = (p) => `${p.instance}.${p.label}`;
|
|
1243
|
+
if (what === "pad") {
|
|
1244
|
+
const p = padOf(id);
|
|
1245
|
+
if (!p)
|
|
1246
|
+
return null;
|
|
1247
|
+
return {
|
|
1248
|
+
kicker: `${p.dir === "in" ? "Input" : "Output"} pad`,
|
|
1249
|
+
title: name(p),
|
|
1250
|
+
sub: p.op,
|
|
1251
|
+
types: [p.type],
|
|
1252
|
+
rows: [["Kind", p.kind], ["Type", TYPE_NAME[p.type]], ["Routes", String(routes(p))], ["Description", p.description ?? "-"]],
|
|
1253
|
+
schemaLabel: p.dir === "in" ? "Input schema" : "Output schema",
|
|
1254
|
+
schema: p.schema,
|
|
1255
|
+
follow: routes(p) > 0
|
|
1256
|
+
};
|
|
1257
|
+
}
|
|
1258
|
+
if (what === "cable") {
|
|
1259
|
+
const c = m.cables.find((x) => x.id === id), a = c && padOf(c.from.pad), b = c && padOf(c.to.pad);
|
|
1260
|
+
if (!c || !a || !b)
|
|
1261
|
+
return null;
|
|
1262
|
+
return {
|
|
1263
|
+
kicker: "Cable",
|
|
1264
|
+
title: `${name(a)} → ${name(b)}`,
|
|
1265
|
+
sub: c.system,
|
|
1266
|
+
types: [c.type],
|
|
1267
|
+
rows: [["Kind", a.kind], ["Type", TYPE_NAME[c.type]], ["From", name(a)], ["To", name(b)]],
|
|
1268
|
+
schemaLabel: "Output schema",
|
|
1269
|
+
schema: a.schema,
|
|
1270
|
+
follow: true
|
|
1271
|
+
};
|
|
1272
|
+
}
|
|
1273
|
+
const it = items.find((i) => `${i.system}/${i.instance}` === id);
|
|
1274
|
+
if (!it)
|
|
1275
|
+
return null;
|
|
1276
|
+
return {
|
|
1277
|
+
kicker: "Pod",
|
|
1278
|
+
title: it.title,
|
|
1279
|
+
sub: `${it.system}/${it.instance}`,
|
|
1280
|
+
types: uniq(it.pads.map((p) => p.type)),
|
|
1281
|
+
rows: [["Pads", String(it.pads.length)], ["Routes", String(it.pads.reduce((n, p) => n + routes(p), 0))]],
|
|
1282
|
+
follow: false
|
|
1283
|
+
};
|
|
1284
|
+
}
|
|
1285
|
+
function renderDrawer(el) {
|
|
1286
|
+
const d = describe(el);
|
|
1287
|
+
return html11`<aside class="drawer" aria-label="Details" ?hidden=${!d} @wheel=${(e) => e.stopPropagation()}>${!d ? nothing2 : html11`
|
|
1288
|
+
<div class="d-head"><div><div class="kicker">${d.kicker}</div><div class="d-title">${d.title}</div><div class="d-sub">${d.sub}</div></div>
|
|
1289
|
+
<button aria-label="Close details" @click=${() => {
|
|
1290
|
+
el.select(null);
|
|
1291
|
+
el.refocus();
|
|
1292
|
+
}}>✕</button></div>
|
|
1293
|
+
<div class="chips">${d.types.map((t2) => html11`<span class="chip"><span class="glyph" aria-hidden="true" style="background:${TYPE_COLOR[t2]}">${TYPE_GLYPH[t2]}</span>${TYPE_NAME[t2]}</span>`)}</div>
|
|
1294
|
+
<dl>${d.rows.map(([k, v]) => html11`<dt>${k}</dt><dd>${v}</dd>`)}</dl>
|
|
1295
|
+
${d.schemaLabel ? html11`<div class="kicker">${d.schemaLabel}</div><pre>${d.schema === undefined ? "none (signal)" : JSON.stringify(d.schema, null, 2)}</pre>` : nothing2}
|
|
1296
|
+
${d.follow ? html11`<div class="actions"><button @click=${() => el.follow()}>Follow cable</button></div>` : nothing2}`}</aside>`;
|
|
1297
|
+
}
|
|
1298
|
+
|
|
1299
|
+
// packages/ui/src/wiring/render-stage.ts
|
|
1300
|
+
var px = (r) => ({ left: `${r.x}px`, top: `${r.y}px`, width: `${r.w}px`, height: `${r.h}px` });
|
|
1301
|
+
function pad(el, { pad: p, x, y }) {
|
|
1302
|
+
const c = TYPE_COLOR[p.type], out = p.dir === "out";
|
|
1303
|
+
const style = { left: `${x - 12}px`, top: `${y - 12}px`, borderColor: c, background: out ? c : "transparent", color: out ? "#0B0E12" : c, borderRadius: p.kind === "event" ? "50%" : "6px" };
|
|
1304
|
+
return html12`<button class="pad" data-pad=${p.key} data-dir=${p.dir} data-kind=${p.kind} style=${styleMap(style)} title=${p.description ?? ""}
|
|
1305
|
+
aria-label=${`${p.instance}.${p.label}, ${TYPE_NAME[p.type]}, ${p.dir}`}
|
|
1306
|
+
aria-pressed=${el.s.sel === `pad:${p.key}`} @click=${() => el.select(`pad:${p.key}`)}>${TYPE_GLYPH[p.type]}</button>
|
|
1307
|
+
<span class="plabel ${p.dir}" style=${styleMap({ top: `${y - 7}px`, ...out ? { right: `calc(100% - ${x - 18}px)`, textAlign: "right" } : { left: `${x + 18}px` } })}>${p.label}</span>`;
|
|
1308
|
+
}
|
|
1309
|
+
function box(el, b, shared) {
|
|
1310
|
+
const { item } = b, fp = (i) => `fp:${i.system}/${i.instance}`;
|
|
1311
|
+
return html12`<div class="fp" data-instance=${item.instance} data-sel=${el.s.sel === fp(item)} style=${styleMap(px(b.rect))}>
|
|
1312
|
+
<button class="ftitle" @click=${() => el.select(fp(item))}>${item.title}${shared ? " ⧉" : ""}</button>
|
|
1313
|
+
${b.pads.map((p) => pad(el, p))}</div>`;
|
|
1314
|
+
}
|
|
1315
|
+
var padName = (el, key) => {
|
|
1316
|
+
const p = [...el.model.layers.flatMap((l) => l.footprints), ...el.model.side.flatMap((b) => b.items)].flatMap((i) => i.pads).find((x) => x.key === key);
|
|
1317
|
+
return p ? `${p.instance}.${p.label}` : key;
|
|
1318
|
+
};
|
|
1319
|
+
function cables(el, f) {
|
|
1320
|
+
const { pos } = el.geo, focusFrame = `l:${el.s.focus}`;
|
|
1321
|
+
return svg`<svg class="cables" width="1" height="1">${el.model.cables.filter((c) => frameId(c.from.at) === f.id).map((c) => {
|
|
1322
|
+
const a = pos.get(posKey(f.id, c.from.pad)), b = pos.get(posKey(frameId(c.to.at), c.to.pad));
|
|
1323
|
+
if (!a || !b)
|
|
1324
|
+
return "";
|
|
1325
|
+
const x1 = a.x - f.origin.x, y1 = a.y - f.origin.y, x2 = b.x - f.origin.x, y2 = b.y - f.origin.y, dx = Math.max(40, Math.abs(x2 - x1) / 2);
|
|
1326
|
+
const full = frameId(c.from.at) === focusFrame || frameId(c.to.at) === focusFrame || f.id.startsWith("s:") && frameId(c.to.at).startsWith("s:");
|
|
1327
|
+
const d = `M${x1},${y1} C${x1 + dx},${y1} ${x2 - dx},${y2} ${x2},${y2}`, sel = el.s.sel === `cable:${c.id}`, lit = el.isLit(c.id);
|
|
1328
|
+
return svg`<g data-cable-hit=${c.id} role="button" tabindex="0" aria-label=${`Cable ${padName(el, c.from.pad)} to ${padName(el, c.to.pad)}`} aria-pressed=${sel} @click=${() => el.select(`cable:${c.id}`)}
|
|
1329
|
+
@keydown=${(e) => {
|
|
1330
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
1331
|
+
e.preventDefault();
|
|
1332
|
+
el.select(`cable:${c.id}`);
|
|
1333
|
+
}
|
|
1334
|
+
}}>
|
|
1335
|
+
<path data-cable=${c.id} data-x1=${x1} data-y1=${y1} data-x2=${x2} data-y2=${y2} d=${d}
|
|
1336
|
+
fill="none" stroke=${TYPE_COLOR[c.type]} stroke-width=${sel || lit ? 4 : 2} opacity=${full || lit ? 1 : DIM_CABLE} data-lit=${lit}/><path class="hit" d=${d}/></g>`;
|
|
1337
|
+
})}</svg>`;
|
|
1338
|
+
}
|
|
1339
|
+
function minimap(el) {
|
|
1340
|
+
const { bounds: b, layers, blocks } = el.geo, { panX, panY, zoom, focus } = el.s, { w, h } = el.stageSize();
|
|
1341
|
+
const vp = { x: -panX / zoom - w / zoom / 2, y: -panY / zoom - h / zoom / 2, w: w / zoom, h: h / zoom };
|
|
1342
|
+
return html12`<svg class="minimap" role="img" aria-label="Minimap" viewBox=${`${b.x - MARGIN} ${b.y - MARGIN} ${b.w + 2 * MARGIN} ${b.h + 2 * MARGIN}`}
|
|
1343
|
+
@click=${(e) => el.panFromMinimap(e)}>
|
|
1344
|
+
${layers.map((l) => svg`<rect class="mm-layer" data-focus=${l.layer.screen === focus} x=${l.rect.x} y=${l.rect.y} width=${l.rect.w} height=${l.rect.h}/>`)}
|
|
1345
|
+
${blocks.map((l) => svg`<rect class="mm-side" x=${l.rect.x} y=${l.rect.y} width=${l.rect.w} height=${l.rect.h}/>`)}
|
|
1346
|
+
<rect class="mm-view" x=${vp.x} y=${vp.y} width=${vp.w} height=${vp.h}/></svg>`;
|
|
1347
|
+
}
|
|
1348
|
+
function renderStage(el) {
|
|
1349
|
+
const { focus, zoom, panX, panY } = el.s, reduced = el.reduced(), at = el.model.layers.findIndex((l) => l.screen === focus);
|
|
1350
|
+
const world = { transform: `${reduced ? "" : TILT} translate(${panX}px, ${panY}px) scale(${zoom})` };
|
|
1351
|
+
return html12`<div class="stage" tabindex="0" aria-label="Wiring" @pointerdown=${(e) => el.dragStart(e)} @wheel=${(e) => el.wheel(e)}>
|
|
1352
|
+
<div class="world ${el.dragging || reduced ? "" : "anim"}" style=${styleMap(world)}>
|
|
1353
|
+
${el.geo.layers.map((f) => {
|
|
1354
|
+
const d = f.index - at, l = f.layer;
|
|
1355
|
+
return html12`<div class="frame" data-screen=${l.screen} style=${styleMap({ left: `${f.origin.x}px`, top: `${f.origin.y}px`, transform: `translateZ(${-Math.abs(d) * ZGAP}px)` })}>
|
|
1356
|
+
<section class="layer" aria-label=${l.title} data-focus=${d === 0} style=${styleMap({ width: `${PW}px`, height: `${PH}px`, opacity: String(fade(d)) })}>
|
|
1357
|
+
<h3 class="ltitle">${l.title}</h3>
|
|
1358
|
+
${f.boxes.map((b) => box(el, b, "shared" in b.item && b.item.shared))}</section>
|
|
1359
|
+
${cables(el, f)}</div>`;
|
|
1360
|
+
})}
|
|
1361
|
+
${el.geo.blocks.map((f) => html12`<div class="frame side" data-system=${f.block.system} style=${styleMap({ left: `${f.origin.x}px`, top: `${f.origin.y}px` })}>
|
|
1362
|
+
<h3 class="ltitle">${f.block.system}</h3>${f.boxes.map((b) => box(el, b, false))}${cables(el, f)}</div>`)}
|
|
1363
|
+
</div>
|
|
1364
|
+
${minimap(el)}${renderDrawer(el)}</div>`;
|
|
1365
|
+
}
|
|
1366
|
+
|
|
1367
|
+
// packages/ui/src/wiring/styles.ts
|
|
1368
|
+
import { css as css4 } from "lit";
|
|
1369
|
+
import { base as base4, t as t2 } from "@pritzlaff/nano-elements";
|
|
1370
|
+
var styles = [base4, css4`
|
|
1371
|
+
:host { display: block; height: 100%; min-height: 360px; color: ${t2("fg")} }
|
|
1372
|
+
.pills { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px; background: ${t2("bg")} }
|
|
1373
|
+
.ic { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; background: ${t2("surface-2")}; font-size: 10px }
|
|
1374
|
+
.stage { position: relative; height: calc(100% - 44px); overflow: hidden; perspective: 2400px; background: ${t2("bg")} radial-gradient(${t2("surface-2")} 1px, transparent 1px) 0 0 / 22px 22px; cursor: grab; user-select: none; touch-action: none }
|
|
1375
|
+
.world { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d; transform-origin: 0 0 }
|
|
1376
|
+
.world.anim { transition: transform .5s ease }
|
|
1377
|
+
.frame { position: absolute; transform-style: preserve-3d }
|
|
1378
|
+
.layer { position: absolute; left: 0; top: 0; background: ${t2("surface")}; border: 1px solid ${t2("border")}; border-radius: 8px }
|
|
1379
|
+
.ltitle { position: absolute; left: 0; top: -22px; margin: 0; font-size: 12px; color: ${t2("muted")}; white-space: nowrap }
|
|
1380
|
+
.layer .ltitle { left: 8px; top: 6px }
|
|
1381
|
+
.fp { position: absolute; box-sizing: border-box; border: 1px solid ${t2("border")}; border-radius: 6px; background: ${t2("surface-2")} }
|
|
1382
|
+
.ftitle { position: absolute; left: 14px; top: 8px; padding: 0; border: 0; background: none; font-weight: 600 }
|
|
1383
|
+
.pad { position: absolute; width: 24px; height: 24px; padding: 0; border: 2px solid; font: 600 10px ${t2("font-mono")} }
|
|
1384
|
+
.plabel { position: absolute; font-size: 10px; color: ${t2("muted")}; white-space: nowrap }
|
|
1385
|
+
.pad[aria-pressed="true"], .fp[data-sel="true"] { border-color: ${t2("accent")} }
|
|
1386
|
+
.hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer }
|
|
1387
|
+
g[data-cable-hit]:focus-visible { outline: 2px solid ${t2("focus")} }
|
|
1388
|
+
path[data-lit="true"] { filter: drop-shadow(0 0 4px currentColor) }
|
|
1389
|
+
.cables { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none }
|
|
1390
|
+
.drawer { position: absolute; top: 0; right: 0; bottom: 0; z-index: 3; width: 340px; max-width: 100%; box-sizing: border-box; padding: 16px; display: flex; flex-direction: column; gap: 12px; overflow-y: auto; background: ${t2("bg")}; border-left: 1px solid ${t2("border")}; cursor: auto; user-select: text }
|
|
1391
|
+
.drawer[hidden] { display: none }
|
|
1392
|
+
.d-head { display: flex; justify-content: space-between; gap: 12px } .d-title { font: 700 14px ${t2("font-mono")}; word-break: break-word } .d-sub { font: 11px ${t2("font-mono")}; color: ${t2("muted")}; word-break: break-word }
|
|
1393
|
+
.kicker { font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: ${t2("muted")} }
|
|
1394
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px }
|
|
1395
|
+
.glyph { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: ${t2("on-accent")}; font: 700 9px ${t2("font-mono")} }
|
|
1396
|
+
dl { display: grid; grid-template-columns: 90px minmax(0, 1fr); gap: 6px 10px; margin: 0 } dt { color: ${t2("muted")} } dd { margin: 0; font: 11px ${t2("font-mono")}; word-break: break-word }
|
|
1397
|
+
pre { margin: 0; padding: 10px; border: 1px solid ${t2("border")}; border-radius: 6px; background: ${t2("surface")}; font: 11px/16px ${t2("font-mono")}; white-space: pre-wrap }
|
|
1398
|
+
.actions { margin-top: auto; padding-top: 8px; border-top: 1px solid ${t2("border")} }
|
|
1399
|
+
@media (prefers-reduced-motion: reduce) { .world.anim { transition: none } }
|
|
1400
|
+
.minimap { position: absolute; right: 12px; bottom: 12px; width: 176px; height: 108px; background: ${t2("bg")}; border: 1px solid ${t2("border")}; border-radius: 6px }
|
|
1401
|
+
.mm-layer { fill: ${t2("surface-2")} } .mm-layer[data-focus="true"] { fill: ${t2("accent-soft")} } .mm-side { fill: ${t2("border")} } .mm-view { fill: none; stroke: ${t2("accent")}; stroke-width: 12 }`];
|
|
1402
|
+
|
|
1403
|
+
// packages/ui/src/wiring/wiring.ts
|
|
1404
|
+
var clamp = (z) => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, z));
|
|
1405
|
+
|
|
1406
|
+
class NanoWiring extends LitElement4 {
|
|
1407
|
+
static properties = { target: { attribute: false } };
|
|
1408
|
+
static styles = styles;
|
|
1409
|
+
s = { focus: null, zoom: 1, panX: 0, panY: 0, sel: null };
|
|
1410
|
+
model = { layers: [], side: [], cables: [] };
|
|
1411
|
+
geo = layout(this.model);
|
|
1412
|
+
dragging = false;
|
|
1413
|
+
off;
|
|
1414
|
+
watching;
|
|
1415
|
+
fitted = false;
|
|
1416
|
+
drag = null;
|
|
1417
|
+
lit = new Map;
|
|
1418
|
+
constructor() {
|
|
1419
|
+
super();
|
|
1420
|
+
this.addEventListener("keydown", (e) => this.key(e));
|
|
1421
|
+
}
|
|
1422
|
+
connectedCallback() {
|
|
1423
|
+
super.connectedCallback();
|
|
1424
|
+
this.watch();
|
|
1425
|
+
}
|
|
1426
|
+
disconnectedCallback() {
|
|
1427
|
+
super.disconnectedCallback();
|
|
1428
|
+
this.stop();
|
|
1429
|
+
}
|
|
1430
|
+
willUpdate(changed) {
|
|
1431
|
+
if (changed.has("target"))
|
|
1432
|
+
this.watch();
|
|
1433
|
+
}
|
|
1434
|
+
render() {
|
|
1435
|
+
return [renderPills(this), renderStage(this)];
|
|
1436
|
+
}
|
|
1437
|
+
watch() {
|
|
1438
|
+
const t3 = this.target;
|
|
1439
|
+
if (!t3 || !this.isConnected || this.watching === t3)
|
|
1440
|
+
return;
|
|
1441
|
+
this.stop();
|
|
1442
|
+
this.watching = t3;
|
|
1443
|
+
this.off = t3.app.listen((e) => {
|
|
1444
|
+
if (e.type === "applied")
|
|
1445
|
+
this.load(t3);
|
|
1446
|
+
else if (e.type === "sent" && e.kind !== "start")
|
|
1447
|
+
this.light(e.kind === "call" ? `${e.runtime}|${e.from}|${e.to}|call|` : `${e.runtime}|${e.from}|${e.to}|${e.port}|`);
|
|
1448
|
+
});
|
|
1449
|
+
this.load(t3);
|
|
1450
|
+
}
|
|
1451
|
+
stop() {
|
|
1452
|
+
this.off?.();
|
|
1453
|
+
this.off = undefined;
|
|
1454
|
+
this.watching = undefined;
|
|
1455
|
+
this.lit.forEach(clearTimeout);
|
|
1456
|
+
this.lit.clear();
|
|
1457
|
+
}
|
|
1458
|
+
load(t3) {
|
|
1459
|
+
this.model = circuitOf(t3.app.deployment(), t3.registry);
|
|
1460
|
+
this.geo = layout(this.model);
|
|
1461
|
+
if (!this.model.layers.some((l) => l.screen === this.s.focus))
|
|
1462
|
+
this.s = { ...this.s, focus: this.model.layers[0]?.screen ?? null };
|
|
1463
|
+
if (!this.fitted && this.s.focus !== null) {
|
|
1464
|
+
this.fitted = true;
|
|
1465
|
+
this.fitPage(this.s.focus);
|
|
1466
|
+
}
|
|
1467
|
+
this.requestUpdate();
|
|
1468
|
+
}
|
|
1469
|
+
light(prefix) {
|
|
1470
|
+
clearTimeout(this.lit.get(prefix));
|
|
1471
|
+
this.lit.set(prefix, setTimeout(() => {
|
|
1472
|
+
this.lit.delete(prefix);
|
|
1473
|
+
this.requestUpdate();
|
|
1474
|
+
}, 600));
|
|
1475
|
+
this.requestUpdate();
|
|
1476
|
+
}
|
|
1477
|
+
isLit(id) {
|
|
1478
|
+
return [...this.lit.keys()].some((p) => id.startsWith(p));
|
|
1479
|
+
}
|
|
1480
|
+
reduced() {
|
|
1481
|
+
return globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
1482
|
+
}
|
|
1483
|
+
stageSize() {
|
|
1484
|
+
const st = this.renderRoot.querySelector(".stage");
|
|
1485
|
+
return { w: st?.clientWidth || 1000, h: st?.clientHeight || 600 };
|
|
1486
|
+
}
|
|
1487
|
+
fitRect(r) {
|
|
1488
|
+
const { w, h } = this.stageSize(), zoom = clamp(Math.min(w / (r.w + 2 * MARGIN), h / (r.h + 2 * MARGIN)));
|
|
1489
|
+
this.s = { ...this.s, zoom, panX: -(r.x + r.w / 2) * zoom, panY: -(r.y + r.h / 2) * zoom };
|
|
1490
|
+
this.requestUpdate();
|
|
1491
|
+
}
|
|
1492
|
+
fitPage(id) {
|
|
1493
|
+
const i = this.model.layers.findIndex((l) => l.screen === id);
|
|
1494
|
+
if (i >= 0)
|
|
1495
|
+
this.fitRect(this.geo.pageRect(i));
|
|
1496
|
+
}
|
|
1497
|
+
fitAll() {
|
|
1498
|
+
this.fitRect(this.geo.bounds);
|
|
1499
|
+
}
|
|
1500
|
+
go(id) {
|
|
1501
|
+
this.s = { ...this.s, focus: id };
|
|
1502
|
+
this.fitPage(id);
|
|
1503
|
+
}
|
|
1504
|
+
move(by) {
|
|
1505
|
+
const ls = this.model.layers, i = ls.findIndex((l) => l.screen === this.s.focus), j = Math.min(ls.length - 1, Math.max(0, i + by));
|
|
1506
|
+
if (ls[j])
|
|
1507
|
+
this.go(ls[j].screen);
|
|
1508
|
+
}
|
|
1509
|
+
key(e) {
|
|
1510
|
+
if (e.key === "ArrowRight" || e.key === "PageDown")
|
|
1511
|
+
this.move(1);
|
|
1512
|
+
else if (e.key === "ArrowLeft" || e.key === "PageUp")
|
|
1513
|
+
this.move(-1);
|
|
1514
|
+
else if (e.key === "Escape" && this.s.sel) {
|
|
1515
|
+
this.select(null);
|
|
1516
|
+
this.refocus();
|
|
1517
|
+
} else
|
|
1518
|
+
return;
|
|
1519
|
+
e.preventDefault();
|
|
1520
|
+
}
|
|
1521
|
+
refocus() {
|
|
1522
|
+
this.renderRoot.querySelector(".stage")?.focus();
|
|
1523
|
+
}
|
|
1524
|
+
select(sel) {
|
|
1525
|
+
this.s = { ...this.s, sel };
|
|
1526
|
+
this.requestUpdate();
|
|
1527
|
+
}
|
|
1528
|
+
follow() {
|
|
1529
|
+
const m = this.model, { sel } = this.s;
|
|
1530
|
+
if (!sel)
|
|
1531
|
+
return;
|
|
1532
|
+
const [what, ...rest] = sel.split(":"), id = rest.join(":");
|
|
1533
|
+
const cable = what === "cable" ? m.cables.find((c) => c.id === id) : m.cables.find((c) => c.from.pad === id || c.to.pad === id);
|
|
1534
|
+
if (!cable)
|
|
1535
|
+
return;
|
|
1536
|
+
const end = what === "pad" && cable.from.pad === id ? cable.to : what === "pad" ? cable.from : cable.to;
|
|
1537
|
+
const p = this.geo.pos.get(posKey(frameId(end.at), end.pad));
|
|
1538
|
+
if (!p)
|
|
1539
|
+
return;
|
|
1540
|
+
this.s = { ...this.s, sel: `pad:${end.pad}`, ..."layer" in end.at && { focus: end.at.layer }, panX: -p.x * this.s.zoom, panY: -p.y * this.s.zoom };
|
|
1541
|
+
this.requestUpdate();
|
|
1542
|
+
}
|
|
1543
|
+
wheel(e) {
|
|
1544
|
+
e.preventDefault();
|
|
1545
|
+
this.s = { ...this.s, zoom: clamp(this.s.zoom * Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.002))) };
|
|
1546
|
+
this.requestUpdate();
|
|
1547
|
+
}
|
|
1548
|
+
dragStart(e) {
|
|
1549
|
+
if (e.target.closest("button, input, aside, g[data-cable-hit]"))
|
|
1550
|
+
return;
|
|
1551
|
+
this.drag = { x: e.clientX, y: e.clientY };
|
|
1552
|
+
this.dragging = true;
|
|
1553
|
+
const move = (m) => {
|
|
1554
|
+
if (!this.drag)
|
|
1555
|
+
return;
|
|
1556
|
+
this.s = { ...this.s, panX: this.s.panX + m.clientX - this.drag.x, panY: this.s.panY + m.clientY - this.drag.y };
|
|
1557
|
+
this.drag = { x: m.clientX, y: m.clientY };
|
|
1558
|
+
this.requestUpdate();
|
|
1559
|
+
};
|
|
1560
|
+
const up = () => {
|
|
1561
|
+
this.drag = null;
|
|
1562
|
+
this.dragging = false;
|
|
1563
|
+
window.removeEventListener("pointermove", move);
|
|
1564
|
+
window.removeEventListener("pointerup", up);
|
|
1565
|
+
window.removeEventListener("pointercancel", up);
|
|
1566
|
+
this.requestUpdate();
|
|
1567
|
+
};
|
|
1568
|
+
window.addEventListener("pointermove", move);
|
|
1569
|
+
window.addEventListener("pointerup", up);
|
|
1570
|
+
window.addEventListener("pointercancel", up);
|
|
1571
|
+
}
|
|
1572
|
+
panFromMinimap(e) {
|
|
1573
|
+
const el = e.currentTarget, r = el.getBoundingClientRect(), b = this.geo.bounds;
|
|
1574
|
+
if (!r.width || !r.height)
|
|
1575
|
+
return;
|
|
1576
|
+
const k = Math.max((b.w + 2 * MARGIN) / r.width, (b.h + 2 * MARGIN) / r.height);
|
|
1577
|
+
const wx = b.x + b.w / 2 + (e.clientX - r.left - r.width / 2) * k, wy = b.y + b.h / 2 + (e.clientY - r.top - r.height / 2) * k;
|
|
1578
|
+
this.s = { ...this.s, panX: -wx * this.s.zoom, panY: -wy * this.s.zoom };
|
|
1579
|
+
this.requestUpdate();
|
|
1580
|
+
}
|
|
1581
|
+
}
|
|
1582
|
+
|
|
1583
|
+
// packages/ui/src/views/pod-view.ts
|
|
1584
|
+
import { css as css5, html as html13 } from "lit";
|
|
1585
|
+
import { base as base5, t as t3 } from "@pritzlaff/nano-elements";
|
|
1586
|
+
class NanoPodView extends ViewElement {
|
|
1587
|
+
static styles = [base5, css5`
|
|
1588
|
+
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px }
|
|
1589
|
+
dt { color: ${t3("muted")} } dd { margin: 0; font-family: ${t3("font-mono")} }
|
|
1590
|
+
table { width: 100%; border-collapse: collapse } td { padding: 3px 6px; border-top: 1px solid ${t3("border")} }
|
|
1591
|
+
.iface { margin-top: 8px; font-weight: 600 }
|
|
1592
|
+
`];
|
|
1593
|
+
ports = new Map;
|
|
1594
|
+
stats = new Map;
|
|
1595
|
+
started() {
|
|
1596
|
+
this.ports.clear();
|
|
1597
|
+
this.stats.clear();
|
|
1598
|
+
this.requestUpdate();
|
|
1599
|
+
}
|
|
1600
|
+
hear(e, tg) {
|
|
1601
|
+
if (e.type === "sent" && e.kind !== "start" && e.to === tg.pod) {
|
|
1602
|
+
this.ports.set(e.id, e.port);
|
|
1603
|
+
const s = this.stats.get(e.port) ?? { calls: 0 };
|
|
1604
|
+
this.stats.set(e.port, { ...s, calls: s.calls + 1 });
|
|
1605
|
+
} else if ((e.type === "delivered" || e.type === "denied") && this.ports.has(e.id)) {
|
|
1606
|
+
const p = this.ports.get(e.id);
|
|
1607
|
+
this.ports.delete(e.id);
|
|
1608
|
+
if (e.type === "delivered")
|
|
1609
|
+
this.stats.set(p, { ...this.stats.get(p), last: e.result });
|
|
1610
|
+
} else
|
|
1611
|
+
return;
|
|
1612
|
+
this.requestUpdate();
|
|
1613
|
+
}
|
|
1614
|
+
face(tg) {
|
|
1615
|
+
const d = tg.app.deployment();
|
|
1616
|
+
const pod2 = d.pods[tg.pod];
|
|
1617
|
+
const runtimes = Object.entries(d.runtimes).filter(([, r]) => r.pods.includes(tg.pod)).map(([id]) => id);
|
|
1618
|
+
const provides = tg.registry.implementation(pod2?.implementation ?? "")?.provides ?? [];
|
|
1619
|
+
return html13`
|
|
1620
|
+
<dl>
|
|
1621
|
+
<dt>pod</dt><dd>${tg.pod}</dd>
|
|
1622
|
+
<dt>implementation</dt><dd>${pod2?.implementation ?? "—"}</dd>
|
|
1623
|
+
<dt>config</dt><dd>${JSON.stringify(pod2?.config ?? null)}</dd>
|
|
1624
|
+
<dt>runtimes</dt><dd>${runtimes.join(", ") || "—"}</dd>
|
|
1625
|
+
</dl>
|
|
1626
|
+
${provides.map((i) => html13`
|
|
1627
|
+
<div class="iface">${i.coord}</div>
|
|
1628
|
+
<table>${Object.values(i.ops).map((o) => {
|
|
1629
|
+
const p = `${i.coord}/${o.name}`, s = this.stats.get(p);
|
|
1630
|
+
return html13`<tr data-port=${p}><td>${o.name}</td><td class="badge">${o.kind}</td>
|
|
1631
|
+
<td>${s?.calls ?? 0} calls</td><td>${shown(s?.last)}</td></tr>`;
|
|
1632
|
+
})}</table>`)}`;
|
|
1633
|
+
}
|
|
1634
|
+
}
|
|
1635
|
+
|
|
1636
|
+
// packages/ui/src/observe/bar.ts
|
|
1637
|
+
import { LitElement as LitElement5, css as css6, html as html14 } from "lit";
|
|
1638
|
+
|
|
1639
|
+
// packages/ui/src/observe/replay.ts
|
|
1640
|
+
import { failure as failure2, success as success8 } from "@pritzlaff/nano-core";
|
|
1641
|
+
|
|
1642
|
+
// packages/ui/src/observe/in-flight.ts
|
|
1643
|
+
var wait = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1644
|
+
var QUIET_MS = 31000;
|
|
1645
|
+
function inFlight(app) {
|
|
1646
|
+
const open = new Set;
|
|
1647
|
+
let wake = () => {};
|
|
1648
|
+
const stop = app.listen((e) => {
|
|
1649
|
+
if (e.type === "sent")
|
|
1650
|
+
open.add(e.id);
|
|
1651
|
+
else if ((e.type === "delivered" || e.type === "denied") && open.delete(e.id) && !open.size)
|
|
1652
|
+
wake();
|
|
1653
|
+
});
|
|
1654
|
+
const quiet = async () => {
|
|
1655
|
+
const end = Date.now() + QUIET_MS;
|
|
1656
|
+
for (;; ) {
|
|
1657
|
+
while (open.size) {
|
|
1658
|
+
if (Date.now() >= end)
|
|
1659
|
+
return false;
|
|
1660
|
+
let timer;
|
|
1661
|
+
await new Promise((r) => {
|
|
1662
|
+
wake = r;
|
|
1663
|
+
timer = setTimeout(r, end - Date.now());
|
|
1664
|
+
});
|
|
1665
|
+
clearTimeout(timer);
|
|
1666
|
+
}
|
|
1667
|
+
await wait(0);
|
|
1668
|
+
if (!open.size)
|
|
1669
|
+
return true;
|
|
1670
|
+
}
|
|
1671
|
+
};
|
|
1672
|
+
return { quiet, stop };
|
|
1673
|
+
}
|
|
1674
|
+
|
|
1675
|
+
// packages/ui/src/observe/restart-order.ts
|
|
1676
|
+
import { lookup } from "@pritzlaff/nano-core";
|
|
1677
|
+
function restartOrder(d) {
|
|
1678
|
+
const calls = lookup(d).callsFrom, out = [], seen = new Set;
|
|
1679
|
+
const visit = (pod2) => {
|
|
1680
|
+
if (seen.has(pod2) || !(pod2 in d.pods))
|
|
1681
|
+
return;
|
|
1682
|
+
seen.add(pod2);
|
|
1683
|
+
for (const { to } of calls.get(pod2) ?? [])
|
|
1684
|
+
visit(to);
|
|
1685
|
+
out.push(pod2);
|
|
1686
|
+
};
|
|
1687
|
+
Object.keys(d.pods).forEach(visit);
|
|
1688
|
+
return out;
|
|
1689
|
+
}
|
|
1690
|
+
|
|
1691
|
+
// packages/ui/src/observe/entry.ts
|
|
1692
|
+
var CAP = 65536;
|
|
1693
|
+
var MARK = "…truncated";
|
|
1694
|
+
function snap(v) {
|
|
1695
|
+
const stack = [];
|
|
1696
|
+
let text;
|
|
1697
|
+
try {
|
|
1698
|
+
text = String(JSON.stringify(v, function(_k, x) {
|
|
1699
|
+
if (typeof x === "bigint")
|
|
1700
|
+
return `${x}n`;
|
|
1701
|
+
if (typeof x === "function")
|
|
1702
|
+
return "[function]";
|
|
1703
|
+
if (x !== null && typeof x === "object") {
|
|
1704
|
+
while (stack.length && stack[stack.length - 1] !== this)
|
|
1705
|
+
stack.pop();
|
|
1706
|
+
if (stack.includes(x))
|
|
1707
|
+
return "[cycle]";
|
|
1708
|
+
stack.push(x);
|
|
1709
|
+
}
|
|
1710
|
+
return x;
|
|
1711
|
+
}));
|
|
1712
|
+
} catch {
|
|
1713
|
+
text = '"[unserializable]"';
|
|
1714
|
+
}
|
|
1715
|
+
return text.length > CAP ? text.slice(0, CAP) + MARK : text;
|
|
1716
|
+
}
|
|
1717
|
+
var truncated = (text) => text.endsWith(MARK);
|
|
1718
|
+
function pair(entries) {
|
|
1719
|
+
const byId = new Map;
|
|
1720
|
+
const out = [];
|
|
1721
|
+
for (const { seq, at, event } of entries) {
|
|
1722
|
+
if (event.type === "sent") {
|
|
1723
|
+
const m = { seq, at, sent: event };
|
|
1724
|
+
byId.set(event.id, m);
|
|
1725
|
+
out.push(m);
|
|
1726
|
+
} else if (event.type === "delivered" || event.type === "denied") {
|
|
1727
|
+
const m = byId.get(event.id);
|
|
1728
|
+
if (m)
|
|
1729
|
+
m.outcome = event;
|
|
1730
|
+
}
|
|
1731
|
+
}
|
|
1732
|
+
return out;
|
|
1733
|
+
}
|
|
1734
|
+
|
|
1735
|
+
// packages/ui/src/observe/replay.ts
|
|
1736
|
+
async function cleanStart(store) {
|
|
1737
|
+
await store.flush();
|
|
1738
|
+
const [start] = await store.range(undefined, undefined, 1);
|
|
1739
|
+
return start?.event.type === "deployment" && start.event.clean ? start : undefined;
|
|
1740
|
+
}
|
|
1741
|
+
var roots = (messages) => messages.filter((m) => m.sent.from === "host" && (m.sent.kind === "call" || m.sent.kind === "start") && m.sent.cause === undefined);
|
|
1742
|
+
var wait2 = (ms) => new Promise((r) => setTimeout(r, ms));
|
|
1743
|
+
async function replay(app, store, opts = {}) {
|
|
1744
|
+
const start = await cleanStart(store);
|
|
1745
|
+
if (!start)
|
|
1746
|
+
return failure2("not-found", "the recording no longer holds a clean start");
|
|
1747
|
+
const entries = await store.range(start.seq, opts.to);
|
|
1748
|
+
if (!entries.length)
|
|
1749
|
+
return failure2("not-found", `the recording starts after ${opts.to}`);
|
|
1750
|
+
const sends = new Map(roots(pair(entries)).map((m) => [m.seq, m]));
|
|
1751
|
+
const cut = [...sends.values()].find((m) => m.sent.input !== undefined && truncated(m.sent.input));
|
|
1752
|
+
if (cut)
|
|
1753
|
+
return failure2("invalid-input", `message ${cut.seq}: its input was truncated when recorded`);
|
|
1754
|
+
const inputs = entries.filter((e) => sends.has(e.seq) || e.event.type === "restarted" || e.event.type === "deployment" && e !== start && (e.event.caller ?? "host") === "host");
|
|
1755
|
+
const flight = opts.pace === "fast" ? inFlight(app) : undefined;
|
|
1756
|
+
try {
|
|
1757
|
+
const reset = await app.apply(start.event.deployment);
|
|
1758
|
+
if (!reset.ok)
|
|
1759
|
+
return reset;
|
|
1760
|
+
for (const pod2 of restartOrder(start.event.deployment)) {
|
|
1761
|
+
const r = await app.restart(pod2);
|
|
1762
|
+
if (!r.ok)
|
|
1763
|
+
return r;
|
|
1764
|
+
}
|
|
1765
|
+
const now = opts.now ?? Date.now, sleep = opts.sleep ?? wait2, began = now();
|
|
1766
|
+
const n = { sent: 0, failed: 0, applied: 0, restarted: 0, from: start.seq, to: entries.at(-1).seq };
|
|
1767
|
+
const settled = new Map(entries.flatMap((e) => e.event.type === "delivered" || e.event.type === "denied" ? [[e.event.id, e.seq]] : []));
|
|
1768
|
+
const calls = [];
|
|
1769
|
+
for (const { seq, at, event } of inputs) {
|
|
1770
|
+
if (flight) {
|
|
1771
|
+
if (!await flight.quiet())
|
|
1772
|
+
n.failed++;
|
|
1773
|
+
} else
|
|
1774
|
+
await sleep(Math.max(at - start.at - (now() - began), 0));
|
|
1775
|
+
await Promise.all(calls.filter((c) => c.settled < seq).map((c) => c.done));
|
|
1776
|
+
if (event.type === "deployment" || event.type === "restarted") {
|
|
1777
|
+
const r = event.type === "deployment" ? await app.apply(event.deployment) : await app.restart(event.pod);
|
|
1778
|
+
if (!r.ok) {
|
|
1779
|
+
await Promise.all(calls.map((c) => c.done));
|
|
1780
|
+
return r;
|
|
1781
|
+
}
|
|
1782
|
+
n[event.type === "deployment" ? "applied" : "restarted"]++;
|
|
1783
|
+
continue;
|
|
1784
|
+
}
|
|
1785
|
+
const { sent } = sends.get(seq);
|
|
1786
|
+
const input2 = sent.input === undefined || sent.input === "undefined" ? undefined : JSON.parse(sent.input);
|
|
1787
|
+
const port3 = sent.port ?? "", op3 = port3.slice(port3.lastIndexOf("/") + 1);
|
|
1788
|
+
n.sent++;
|
|
1789
|
+
const rt = app.runtime(sent.runtime);
|
|
1790
|
+
const done = Promise.resolve().then(() => sent.kind === "start" ? rt.start(sent.to) : rt.call(sent.to)[op3](input2)).then((r) => {
|
|
1791
|
+
if (!r.ok)
|
|
1792
|
+
n.failed++;
|
|
1793
|
+
}, () => {
|
|
1794
|
+
n.failed++;
|
|
1795
|
+
});
|
|
1796
|
+
calls.push({ settled: settled.get(sent.id) ?? Infinity, done });
|
|
1797
|
+
}
|
|
1798
|
+
await Promise.all(calls.map((c) => c.done));
|
|
1799
|
+
if (flight && !await flight.quiet())
|
|
1800
|
+
n.failed++;
|
|
1801
|
+
return success8(n);
|
|
1802
|
+
} finally {
|
|
1803
|
+
flight?.stop();
|
|
1804
|
+
}
|
|
1805
|
+
}
|
|
1806
|
+
var same = (m) => JSON.stringify([
|
|
1807
|
+
m.sent.kind,
|
|
1808
|
+
m.sent.from,
|
|
1809
|
+
m.sent.to,
|
|
1810
|
+
m.sent.port,
|
|
1811
|
+
m.sent.input,
|
|
1812
|
+
m.outcome?.type,
|
|
1813
|
+
m.outcome?.type === "delivered" ? [m.outcome.ok, m.outcome.result] : undefined
|
|
1814
|
+
]);
|
|
1815
|
+
function diverge(recorded, replayed) {
|
|
1816
|
+
const msgs = (ms) => ms.filter((m) => m.sent.kind !== "subscribe" && m.sent.kind !== "unsubscribe");
|
|
1817
|
+
const a = msgs(recorded), b = msgs(replayed);
|
|
1818
|
+
for (let i = 0;i < Math.max(a.length, b.length); i++)
|
|
1819
|
+
if (!a[i] || !b[i] || same(a[i]) !== same(b[i]))
|
|
1820
|
+
return { index: i, recorded: a[i], replayed: b[i] };
|
|
1821
|
+
return null;
|
|
1822
|
+
}
|
|
1823
|
+
|
|
1824
|
+
// packages/ui/src/observe/time-machine.ts
|
|
1825
|
+
var IDLE = 1000;
|
|
1826
|
+
var SPEEDS = [1 / 30, 1 / 10, 1 / 4, 1 / 2, 1, 2];
|
|
1827
|
+
var raf = { now: () => Date.now(), frame: (fn) => {
|
|
1828
|
+
const id = requestAnimationFrame(fn);
|
|
1829
|
+
return () => cancelAnimationFrame(id);
|
|
1830
|
+
} };
|
|
1831
|
+
async function timeMachine(source, opts = {}) {
|
|
1832
|
+
const ticker = opts.ticker ?? raf, keep = opts.recent ?? 200, travelMs = opts.travelMs ?? 600;
|
|
1833
|
+
const msgs = [];
|
|
1834
|
+
const byId = new Map;
|
|
1835
|
+
const span = { from: 0, to: 0 };
|
|
1836
|
+
let empty = true, lastSeq = 0;
|
|
1837
|
+
let mode = "live", speed = 1, cursor = 0;
|
|
1838
|
+
let pinned;
|
|
1839
|
+
let cancel, last = 0;
|
|
1840
|
+
const subs = new Set;
|
|
1841
|
+
const upTo = (t4) => {
|
|
1842
|
+
let lo = 0, hi = msgs.length;
|
|
1843
|
+
while (lo < hi) {
|
|
1844
|
+
const mid = lo + hi >> 1;
|
|
1845
|
+
if (msgs[mid].at <= t4)
|
|
1846
|
+
lo = mid + 1;
|
|
1847
|
+
else
|
|
1848
|
+
hi = mid;
|
|
1849
|
+
}
|
|
1850
|
+
return lo;
|
|
1851
|
+
};
|
|
1852
|
+
const inFlightAt = (t4) => {
|
|
1853
|
+
const out = [];
|
|
1854
|
+
for (let i = upTo(t4) - 1;i >= 0 && msgs[i].at >= t4 - travelMs; i--)
|
|
1855
|
+
out.unshift({ message: msgs[i], progress: (t4 - msgs[i].at) / travelMs });
|
|
1856
|
+
return out;
|
|
1857
|
+
};
|
|
1858
|
+
const frame = () => {
|
|
1859
|
+
const end = pinned !== undefined ? pinned + 1 : upTo(cursor);
|
|
1860
|
+
return { t: cursor, inFlight: inFlightAt(cursor), recent: msgs.slice(Math.max(0, end - keep), end), ...end ? { at: msgs[end - 1] } : {} };
|
|
1861
|
+
};
|
|
1862
|
+
const emit = () => {
|
|
1863
|
+
const f = frame();
|
|
1864
|
+
for (const fn of subs)
|
|
1865
|
+
try {
|
|
1866
|
+
fn(f);
|
|
1867
|
+
} catch {}
|
|
1868
|
+
};
|
|
1869
|
+
const add = (e) => {
|
|
1870
|
+
if (e.seq <= lastSeq)
|
|
1871
|
+
return;
|
|
1872
|
+
lastSeq = e.seq;
|
|
1873
|
+
if (empty) {
|
|
1874
|
+
span.from = e.at;
|
|
1875
|
+
empty = false;
|
|
1876
|
+
}
|
|
1877
|
+
span.to = Math.max(span.to, e.at);
|
|
1878
|
+
const ev = e.event;
|
|
1879
|
+
if (ev.type === "sent") {
|
|
1880
|
+
const m = { seq: e.seq, at: e.at, sent: ev };
|
|
1881
|
+
byId.set(ev.id, m);
|
|
1882
|
+
msgs.splice(upTo(e.at), 0, m);
|
|
1883
|
+
} else if (ev.type === "delivered" || ev.type === "denied") {
|
|
1884
|
+
const m = byId.get(ev.id);
|
|
1885
|
+
if (m)
|
|
1886
|
+
m.outcome = ev;
|
|
1887
|
+
}
|
|
1888
|
+
};
|
|
1889
|
+
const stopTicking = () => {
|
|
1890
|
+
cancel?.();
|
|
1891
|
+
cancel = undefined;
|
|
1892
|
+
};
|
|
1893
|
+
const liveFrame = () => {
|
|
1894
|
+
emit();
|
|
1895
|
+
if (!cancel && inFlightAt(cursor).length)
|
|
1896
|
+
cancel = ticker.frame(tick);
|
|
1897
|
+
};
|
|
1898
|
+
const goLive = () => {
|
|
1899
|
+
stopTicking();
|
|
1900
|
+
mode = "live";
|
|
1901
|
+
pinned = undefined;
|
|
1902
|
+
cursor = span.to;
|
|
1903
|
+
liveFrame();
|
|
1904
|
+
};
|
|
1905
|
+
const tick = () => {
|
|
1906
|
+
cancel = undefined;
|
|
1907
|
+
const now = ticker.now();
|
|
1908
|
+
if (mode === "live") {
|
|
1909
|
+
cursor = Math.max(now, span.to);
|
|
1910
|
+
return liveFrame();
|
|
1911
|
+
}
|
|
1912
|
+
let c = cursor + (now - last) * speed;
|
|
1913
|
+
last = now;
|
|
1914
|
+
const target = msgs[upTo(cursor)]?.at ?? span.to;
|
|
1915
|
+
if (inFlightAt(c).length === 0 && target - c > IDLE)
|
|
1916
|
+
c = target;
|
|
1917
|
+
if (c >= span.to)
|
|
1918
|
+
return goLive();
|
|
1919
|
+
cursor = c;
|
|
1920
|
+
pinned = undefined;
|
|
1921
|
+
emit();
|
|
1922
|
+
cancel = ticker.frame(tick);
|
|
1923
|
+
};
|
|
1924
|
+
let held = [];
|
|
1925
|
+
const unlisten = source.listen((e) => {
|
|
1926
|
+
if (held) {
|
|
1927
|
+
held.push(e);
|
|
1928
|
+
return;
|
|
1929
|
+
}
|
|
1930
|
+
add(e);
|
|
1931
|
+
if (mode === "live") {
|
|
1932
|
+
cursor = Math.max(cursor, span.to);
|
|
1933
|
+
liveFrame();
|
|
1934
|
+
}
|
|
1935
|
+
});
|
|
1936
|
+
try {
|
|
1937
|
+
for (const e of await source.store.range())
|
|
1938
|
+
add(e);
|
|
1939
|
+
} catch (err) {
|
|
1940
|
+
unlisten();
|
|
1941
|
+
throw err;
|
|
1942
|
+
}
|
|
1943
|
+
for (const e of held)
|
|
1944
|
+
add(e);
|
|
1945
|
+
held = undefined;
|
|
1946
|
+
cursor = span.to;
|
|
1947
|
+
liveFrame();
|
|
1948
|
+
return {
|
|
1949
|
+
get cursor() {
|
|
1950
|
+
return cursor;
|
|
1951
|
+
},
|
|
1952
|
+
get mode() {
|
|
1953
|
+
return mode;
|
|
1954
|
+
},
|
|
1955
|
+
get speed() {
|
|
1956
|
+
return speed;
|
|
1957
|
+
},
|
|
1958
|
+
get span() {
|
|
1959
|
+
return { ...span };
|
|
1960
|
+
},
|
|
1961
|
+
seek(t4) {
|
|
1962
|
+
stopTicking();
|
|
1963
|
+
mode = "paused";
|
|
1964
|
+
pinned = undefined;
|
|
1965
|
+
cursor = t4;
|
|
1966
|
+
emit();
|
|
1967
|
+
},
|
|
1968
|
+
step(dir) {
|
|
1969
|
+
stopTicking();
|
|
1970
|
+
mode = "paused";
|
|
1971
|
+
const i = (pinned ?? upTo(cursor) - 1) + dir;
|
|
1972
|
+
if (i >= 0 && i < msgs.length) {
|
|
1973
|
+
pinned = i;
|
|
1974
|
+
cursor = msgs[i].at;
|
|
1975
|
+
}
|
|
1976
|
+
emit();
|
|
1977
|
+
},
|
|
1978
|
+
play() {
|
|
1979
|
+
if (mode === "playing")
|
|
1980
|
+
return;
|
|
1981
|
+
if (cursor >= span.to)
|
|
1982
|
+
return goLive();
|
|
1983
|
+
mode = "playing";
|
|
1984
|
+
last = ticker.now();
|
|
1985
|
+
cancel = ticker.frame(tick);
|
|
1986
|
+
},
|
|
1987
|
+
pause() {
|
|
1988
|
+
stopTicking();
|
|
1989
|
+
mode = "paused";
|
|
1990
|
+
emit();
|
|
1991
|
+
},
|
|
1992
|
+
live: goLive,
|
|
1993
|
+
setSpeed(s) {
|
|
1994
|
+
const known = SPEEDS.find((x) => Math.abs(x - s) < 0.000000001);
|
|
1995
|
+
if (known === undefined)
|
|
1996
|
+
throw new RangeError(`speed ${s} is not one of 1/30, 1/10, 1/4, 1/2, 1, 2`);
|
|
1997
|
+
speed = known;
|
|
1998
|
+
emit();
|
|
1999
|
+
},
|
|
2000
|
+
subscribe(fn) {
|
|
2001
|
+
subs.add(fn);
|
|
2002
|
+
return () => {
|
|
2003
|
+
subs.delete(fn);
|
|
2004
|
+
};
|
|
2005
|
+
},
|
|
2006
|
+
close() {
|
|
2007
|
+
stopTicking();
|
|
2008
|
+
unlisten();
|
|
2009
|
+
subs.clear();
|
|
2010
|
+
}
|
|
2011
|
+
};
|
|
2012
|
+
}
|
|
2013
|
+
|
|
2014
|
+
// packages/ui/src/observe/bar.ts
|
|
2015
|
+
var label2 = (s) => (s < 1 ? `1/${Math.round(1 / s)}` : String(s)) + "×";
|
|
2016
|
+
|
|
2017
|
+
class NanoTimeMachine extends LitElement5 {
|
|
2018
|
+
static properties = { tm: { attribute: false }, store: { attribute: false }, driver: { attribute: false }, tooLong: { state: true } };
|
|
2019
|
+
static styles = css6`
|
|
2020
|
+
:host { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 6px 8px; color: #E6EDF3; font: 12px system-ui, sans-serif; background: #0B0E12 }
|
|
2021
|
+
button, select { padding: 4px 10px; border: 1px solid #2A323D; border-radius: 999px; background: #12161C; color: inherit; font: inherit; cursor: pointer }
|
|
2022
|
+
button[aria-pressed="true"] { border-color: #4CC2FF; color: #4CC2FF }
|
|
2023
|
+
input[type=range] { flex: 1 1 160px; min-width: 0; accent-color: #4CC2FF }
|
|
2024
|
+
small { color: #94a3b8 } small.warn { color: #fbbf24 }`;
|
|
2025
|
+
off;
|
|
2026
|
+
clean;
|
|
2027
|
+
constructor() {
|
|
2028
|
+
super();
|
|
2029
|
+
this.tooLong = false;
|
|
2030
|
+
}
|
|
2031
|
+
connectedCallback() {
|
|
2032
|
+
super.connectedCallback();
|
|
2033
|
+
this.watch();
|
|
2034
|
+
}
|
|
2035
|
+
disconnectedCallback() {
|
|
2036
|
+
super.disconnectedCallback();
|
|
2037
|
+
this.off?.();
|
|
2038
|
+
this.off = undefined;
|
|
2039
|
+
}
|
|
2040
|
+
willUpdate(changed) {
|
|
2041
|
+
if (changed.has("tm") || changed.has("store")) {
|
|
2042
|
+
this.tooLong = false;
|
|
2043
|
+
this.clean = undefined;
|
|
2044
|
+
this.watch();
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
watch() {
|
|
2048
|
+
this.off?.();
|
|
2049
|
+
this.off = this.isConnected ? this.tm?.subscribe(() => {
|
|
2050
|
+
this.requestUpdate();
|
|
2051
|
+
this.check();
|
|
2052
|
+
}) : undefined;
|
|
2053
|
+
this.check();
|
|
2054
|
+
}
|
|
2055
|
+
async check() {
|
|
2056
|
+
const store = this.store;
|
|
2057
|
+
if (!store || this.tooLong)
|
|
2058
|
+
return;
|
|
2059
|
+
const oldest = await store.oldest();
|
|
2060
|
+
if (oldest === this.clean)
|
|
2061
|
+
return;
|
|
2062
|
+
const start = await cleanStart(store);
|
|
2063
|
+
if (store !== this.store)
|
|
2064
|
+
return;
|
|
2065
|
+
this.clean = start?.seq;
|
|
2066
|
+
this.tooLong = !start;
|
|
2067
|
+
}
|
|
2068
|
+
act(fn) {
|
|
2069
|
+
return () => {
|
|
2070
|
+
if (this.tm) {
|
|
2071
|
+
fn(this.tm);
|
|
2072
|
+
this.requestUpdate();
|
|
2073
|
+
}
|
|
2074
|
+
};
|
|
2075
|
+
}
|
|
2076
|
+
render() {
|
|
2077
|
+
const tm = this.tm;
|
|
2078
|
+
if (!tm)
|
|
2079
|
+
return html14``;
|
|
2080
|
+
const playing = tm.mode === "playing", span = tm.span, reason = this.driver?.reason;
|
|
2081
|
+
return html14`
|
|
2082
|
+
<button aria-label=${playing ? "Pause" : "Play"} @click=${this.act((t4) => playing ? t4.pause() : t4.play())}>${playing ? "❚❚" : "▶"}</button>
|
|
2083
|
+
<button aria-label="Step back" @click=${this.act((t4) => t4.step(-1))}>◀|</button>
|
|
2084
|
+
<button aria-label="Step forward" @click=${this.act((t4) => t4.step(1))}>|▶</button>
|
|
2085
|
+
<input type="range" aria-label="Time" min=${span.from} max=${span.to} step="1" .value=${String(Math.min(tm.cursor, span.to))}
|
|
2086
|
+
@input=${(e) => this.act((t4) => t4.seek(Number(e.target.value)))()}>
|
|
2087
|
+
<select aria-label="Speed" @change=${(e) => this.act((t4) => t4.setSpeed(Number(e.target.value)))()}>
|
|
2088
|
+
${SPEEDS.map((s) => html14`<option value=${String(s)} ?selected=${s === tm.speed}>${label2(s)}</option>`)}</select>
|
|
2089
|
+
<button aria-label="Live" aria-pressed=${tm.mode === "live"} @click=${this.act((t4) => t4.live())}>Live</button>
|
|
2090
|
+
<button aria-label="Reset" @click=${() => this.dispatchEvent(new CustomEvent("reset", { bubbles: true, composed: true }))}>Reset</button>
|
|
2091
|
+
${this.tooLong ? html14`<small class="warn">history too long to rebuild state</small>` : ""}
|
|
2092
|
+
${reason ? html14`<small>${reason}</small>` : ""}`;
|
|
2093
|
+
}
|
|
2094
|
+
}
|
|
2095
|
+
|
|
2096
|
+
// packages/ui/src/observe/ring-view.ts
|
|
2097
|
+
import { LitElement as LitElement6, css as css7, html as html15, svg as svg2 } from "lit";
|
|
2098
|
+
import { t as t4, tv } from "@pritzlaff/nano-elements";
|
|
2099
|
+
|
|
2100
|
+
// packages/ui/src/observe/ring.ts
|
|
2101
|
+
var placedIn = (d, pod2) => Object.keys(d.runtimes).filter((r) => d.runtimes[r].pods.includes(pod2));
|
|
2102
|
+
var around = (o, n) => Array.from({ length: n }, (_, i) => n === 1 ? { x: o.x, y: o.y } : { x: o.x + o.r * Math.cos(2 * Math.PI * i / n - Math.PI / 2), y: o.y + o.r * Math.sin(2 * Math.PI * i / n - Math.PI / 2) });
|
|
2103
|
+
function ringLayout(d, opts) {
|
|
2104
|
+
const { size } = opts, c = size / 2, ids = Object.keys(d.runtimes), one = ids.length === 1;
|
|
2105
|
+
const ring = one ? 0 : 0.36 * size, r = one ? 0.38 * size : Math.min(0.12 * size, ring * Math.sin(Math.PI / ids.length) * 0.9);
|
|
2106
|
+
const runtimes = around({ x: c, y: c, r: ring }, ids.length).map((p, i) => ({ id: ids[i], ...p, r }));
|
|
2107
|
+
const shown2 = (p) => !opts.show || opts.show(p, d.pods[p].implementation);
|
|
2108
|
+
const own = runtimes.flatMap((rt) => {
|
|
2109
|
+
const ps = d.runtimes[rt.id].pods.filter((p) => d.pods[p] && placedIn(d, p).length === 1 && shown2(p));
|
|
2110
|
+
return around(rt, ps.length).map((xy, i) => ({ pod: ps[i], runtime: rt.id, ...xy }));
|
|
2111
|
+
});
|
|
2112
|
+
const shared = Object.keys(d.pods).filter((p) => placedIn(d, p).length > 1 && shown2(p));
|
|
2113
|
+
return { runtimes, pods: [...own, ...around({ x: c, y: c, r: 0.1 * size }, shared.length).map((xy, i) => ({ pod: shared[i], runtime: null, ...xy }))] };
|
|
2114
|
+
}
|
|
2115
|
+
function placeOf(l, d, pod2, runtime2) {
|
|
2116
|
+
const own = l.pods.find((p) => p.pod === pod2);
|
|
2117
|
+
if (own)
|
|
2118
|
+
return own;
|
|
2119
|
+
const places = placedIn(d, pod2), rt = places.includes(runtime2) ? runtime2 : places[0];
|
|
2120
|
+
return l.runtimes.find((r) => r.id === rt);
|
|
2121
|
+
}
|
|
2122
|
+
function ringDot(l, d, m, progress) {
|
|
2123
|
+
const a = placeOf(l, d, m.sent.from, m.sent.runtime), b = placeOf(l, d, m.sent.to, m.sent.runtime);
|
|
2124
|
+
return a && b ? { x: a.x + (b.x - a.x) * progress, y: a.y + (b.y - a.y) * progress } : undefined;
|
|
2125
|
+
}
|
|
2126
|
+
function ringSource(mode, atNewest, rebuildable) {
|
|
2127
|
+
return mode === "live" || atNewest ? "live" : rebuildable ? "past" : "too-long";
|
|
2128
|
+
}
|
|
2129
|
+
|
|
2130
|
+
// packages/ui/src/observe/shadow.ts
|
|
2131
|
+
import { failure as failure3 } from "@pritzlaff/nano-core";
|
|
2132
|
+
|
|
2133
|
+
// packages/ui/src/observe/memory-store.ts
|
|
2134
|
+
function memoryStore(opts = {}) {
|
|
2135
|
+
const max = opts.max ?? 1e5;
|
|
2136
|
+
let all = [];
|
|
2137
|
+
return {
|
|
2138
|
+
append(e) {
|
|
2139
|
+
all.push(e);
|
|
2140
|
+
if (all.length > max)
|
|
2141
|
+
all.shift();
|
|
2142
|
+
},
|
|
2143
|
+
flush: async () => {},
|
|
2144
|
+
range: async (from = -Infinity, to = Infinity, limit = Infinity) => limit <= 0 ? [] : all.filter((e) => e.seq >= from && e.seq <= to).slice(0, limit),
|
|
2145
|
+
search: async (text, limit = Infinity) => {
|
|
2146
|
+
const t4 = text.toLowerCase();
|
|
2147
|
+
return limit <= 0 ? [] : all.filter((e) => JSON.stringify(e.event).toLowerCase().includes(t4)).slice(-limit);
|
|
2148
|
+
},
|
|
2149
|
+
oldest: async () => all[0]?.seq,
|
|
2150
|
+
size: async () => all.length,
|
|
2151
|
+
clear: async () => {
|
|
2152
|
+
all = [];
|
|
2153
|
+
}
|
|
2154
|
+
};
|
|
2155
|
+
}
|
|
2156
|
+
|
|
2157
|
+
// packages/ui/src/observe/shadow.ts
|
|
2158
|
+
function without(d, host) {
|
|
2159
|
+
const out = structuredClone(d);
|
|
2160
|
+
delete out.pods[host];
|
|
2161
|
+
delete out.tags?.[host];
|
|
2162
|
+
for (const r of Object.values(out.runtimes)) {
|
|
2163
|
+
r.pods = r.pods.filter((p) => p !== host);
|
|
2164
|
+
r.subscriptions = r.subscriptions.filter((s) => s.from !== host && s.to !== host);
|
|
2165
|
+
}
|
|
2166
|
+
return out;
|
|
2167
|
+
}
|
|
2168
|
+
async function shadowAt(store, t4, create, opts = {}) {
|
|
2169
|
+
const host = opts.host ?? "ui";
|
|
2170
|
+
const start = await cleanStart(store);
|
|
2171
|
+
if (!start)
|
|
2172
|
+
return failure3("not-found", "the recording no longer holds a clean start");
|
|
2173
|
+
const all = await store.range(), last = all.findLast((e) => e.at <= t4);
|
|
2174
|
+
if (!last)
|
|
2175
|
+
return failure3("not-found", `the recording starts after ${t4}`);
|
|
2176
|
+
const copy = memoryStore({ max: Infinity }), dropped = new Set;
|
|
2177
|
+
for (const e of all) {
|
|
2178
|
+
if (e.seq > last.seq)
|
|
2179
|
+
break;
|
|
2180
|
+
const kept = shadowed(e, host, dropped);
|
|
2181
|
+
if (kept)
|
|
2182
|
+
copy.append(kept);
|
|
2183
|
+
}
|
|
2184
|
+
const made = await create(without(start.event.deployment, host));
|
|
2185
|
+
if (!made.ok)
|
|
2186
|
+
return made;
|
|
2187
|
+
const r = await replay(made.value, copy, { pace: "fast" });
|
|
2188
|
+
if (!r.ok) {
|
|
2189
|
+
await made.value.close();
|
|
2190
|
+
return r;
|
|
2191
|
+
}
|
|
2192
|
+
return made;
|
|
2193
|
+
}
|
|
2194
|
+
function shadowed(e, host, dropped) {
|
|
2195
|
+
const ev = e.event;
|
|
2196
|
+
if (ev.type === "deployment")
|
|
2197
|
+
return { ...e, event: { ...ev, deployment: without(ev.deployment, host) } };
|
|
2198
|
+
if (ev.type === "sent" && ev.from === "host" && ev.to === host) {
|
|
2199
|
+
dropped.add(ev.id);
|
|
2200
|
+
return;
|
|
2201
|
+
}
|
|
2202
|
+
if ((ev.type === "delivered" || ev.type === "denied") && dropped.has(ev.id))
|
|
2203
|
+
return;
|
|
2204
|
+
if (ev.type === "restarted" && ev.pod === host)
|
|
2205
|
+
return;
|
|
2206
|
+
return e;
|
|
2207
|
+
}
|
|
2208
|
+
|
|
2209
|
+
// packages/ui/src/observe/ring-view.ts
|
|
2210
|
+
var SIZE = 600;
|
|
2211
|
+
var STILL_MS = 200;
|
|
2212
|
+
|
|
2213
|
+
class NanoRing extends LitElement6 {
|
|
2214
|
+
static properties = {
|
|
2215
|
+
app: { attribute: false },
|
|
2216
|
+
registry: { attribute: false },
|
|
2217
|
+
tm: { attribute: false },
|
|
2218
|
+
store: { attribute: false },
|
|
2219
|
+
create: { attribute: false },
|
|
2220
|
+
show: { attribute: false },
|
|
2221
|
+
views: { attribute: false },
|
|
2222
|
+
frame: { state: true },
|
|
2223
|
+
shadow: { state: true },
|
|
2224
|
+
tooLong: { state: true },
|
|
2225
|
+
failed: { state: true }
|
|
2226
|
+
};
|
|
2227
|
+
static styles = css7`
|
|
2228
|
+
:host { display: block; overflow: auto; color: ${t4("fg")}; font: 12px ${t4("font")}; background: ${t4("bg")} }
|
|
2229
|
+
.stage { position: relative; margin: 8px auto }
|
|
2230
|
+
svg { position: absolute; inset: 0; overflow: visible; pointer-events: none }
|
|
2231
|
+
circle.rt { fill: none; stroke: ${t4("border")}; stroke-width: 2 } circle[data-dot] { pointer-events: all; cursor: pointer }
|
|
2232
|
+
.pod { position: absolute; transform: translate(-50%, -50%); width: 150px; max-height: 120px; overflow: auto; padding: 4px; border: 1px solid ${t4("border")}; border-radius: ${t4("radius")}; background: ${t4("surface")} }
|
|
2233
|
+
.pod[inert] { opacity: .85; border-style: dashed } .pod > b { display: block; font-size: 11px; color: ${t4("muted")} }
|
|
2234
|
+
small.warn { display: block; padding: 6px 8px; color: ${t4("warn")} }`;
|
|
2235
|
+
offs = [];
|
|
2236
|
+
els = new Map;
|
|
2237
|
+
timer;
|
|
2238
|
+
still;
|
|
2239
|
+
build = 0;
|
|
2240
|
+
shown = false;
|
|
2241
|
+
resized = new ResizeObserver(() => {
|
|
2242
|
+
if ((this.checkVisibility?.() ?? true) !== this.shown)
|
|
2243
|
+
this.requestUpdate();
|
|
2244
|
+
});
|
|
2245
|
+
constructor() {
|
|
2246
|
+
super();
|
|
2247
|
+
this.tooLong = false;
|
|
2248
|
+
}
|
|
2249
|
+
connectedCallback() {
|
|
2250
|
+
super.connectedCallback();
|
|
2251
|
+
this.resized.observe(this);
|
|
2252
|
+
this.watch();
|
|
2253
|
+
}
|
|
2254
|
+
disconnectedCallback() {
|
|
2255
|
+
super.disconnectedCallback();
|
|
2256
|
+
this.resized.disconnect();
|
|
2257
|
+
for (const off of this.offs.splice(0))
|
|
2258
|
+
off();
|
|
2259
|
+
this.toLive();
|
|
2260
|
+
}
|
|
2261
|
+
willUpdate(changed) {
|
|
2262
|
+
if (changed.has("store") || changed.has("tm")) {
|
|
2263
|
+
this.tooLong = false;
|
|
2264
|
+
this.toLive();
|
|
2265
|
+
}
|
|
2266
|
+
if (changed.has("app") || changed.has("tm"))
|
|
2267
|
+
this.watch();
|
|
2268
|
+
}
|
|
2269
|
+
watch() {
|
|
2270
|
+
for (const off of this.offs.splice(0))
|
|
2271
|
+
off();
|
|
2272
|
+
if (!this.isConnected)
|
|
2273
|
+
return;
|
|
2274
|
+
if (this.app)
|
|
2275
|
+
this.offs.push(this.app.listen((e) => {
|
|
2276
|
+
if (e.type === "applied")
|
|
2277
|
+
this.requestUpdate();
|
|
2278
|
+
}));
|
|
2279
|
+
if (this.tm)
|
|
2280
|
+
this.offs.push(this.tm.subscribe((f) => {
|
|
2281
|
+
this.frame = f;
|
|
2282
|
+
this.sync();
|
|
2283
|
+
}));
|
|
2284
|
+
this.sync();
|
|
2285
|
+
}
|
|
2286
|
+
sync() {
|
|
2287
|
+
const tm = this.tm;
|
|
2288
|
+
if (!tm || ringSource(tm.mode, tm.cursor >= tm.span.to, !this.tooLong) !== "past")
|
|
2289
|
+
return this.toLive();
|
|
2290
|
+
if (tm.cursor === this.still)
|
|
2291
|
+
return;
|
|
2292
|
+
this.still = tm.cursor;
|
|
2293
|
+
clearTimeout(this.timer);
|
|
2294
|
+
this.timer = setTimeout(() => void this.rebuild(tm.cursor), STILL_MS);
|
|
2295
|
+
}
|
|
2296
|
+
toLive() {
|
|
2297
|
+
clearTimeout(this.timer);
|
|
2298
|
+
this.still = undefined;
|
|
2299
|
+
this.build++;
|
|
2300
|
+
this.failed = undefined;
|
|
2301
|
+
this.bind(undefined);
|
|
2302
|
+
}
|
|
2303
|
+
bind(shadow) {
|
|
2304
|
+
const old = this.shadow;
|
|
2305
|
+
this.shadow = shadow;
|
|
2306
|
+
if (old && old !== shadow)
|
|
2307
|
+
old.close();
|
|
2308
|
+
}
|
|
2309
|
+
async rebuild(t5) {
|
|
2310
|
+
const mine = ++this.build, store = this.store, create = this.create;
|
|
2311
|
+
if (!store || !create)
|
|
2312
|
+
return;
|
|
2313
|
+
if (!await cleanStart(store)) {
|
|
2314
|
+
if (mine === this.build) {
|
|
2315
|
+
this.tooLong = true;
|
|
2316
|
+
this.toLive();
|
|
2317
|
+
}
|
|
2318
|
+
return;
|
|
2319
|
+
}
|
|
2320
|
+
const made = await shadowAt(store, t5, create);
|
|
2321
|
+
if (mine !== this.build) {
|
|
2322
|
+
if (made.ok)
|
|
2323
|
+
await made.value.close();
|
|
2324
|
+
return;
|
|
2325
|
+
}
|
|
2326
|
+
if (made.ok) {
|
|
2327
|
+
this.failed = undefined;
|
|
2328
|
+
this.bind(made.value);
|
|
2329
|
+
} else {
|
|
2330
|
+
this.failed = made.fail.reason;
|
|
2331
|
+
this.bind(undefined);
|
|
2332
|
+
}
|
|
2333
|
+
}
|
|
2334
|
+
view(d, pod2, runtime2, app, registry) {
|
|
2335
|
+
const map2 = { ...views, ...this.views }, tag = viewFor(pod2, d, map2), key = `${pod2} ${tag}`;
|
|
2336
|
+
if (tag === "nano-pod-view" && map2[d.pods[pod2]?.implementation ?? ""] !== tag)
|
|
2337
|
+
return "";
|
|
2338
|
+
let el = this.els.get(key);
|
|
2339
|
+
if (!el)
|
|
2340
|
+
this.els.set(key, el = document.createElement(tag));
|
|
2341
|
+
const t5 = el.target;
|
|
2342
|
+
if (!t5 || t5.app !== app || t5.runtime !== runtime2 || t5.registry !== registry)
|
|
2343
|
+
el.target = { app, registry, runtime: runtime2, pod: pod2 };
|
|
2344
|
+
return el;
|
|
2345
|
+
}
|
|
2346
|
+
render() {
|
|
2347
|
+
const { app, registry, tm } = this;
|
|
2348
|
+
this.shown = this.checkVisibility?.() ?? true;
|
|
2349
|
+
if (!app || !registry || !this.shown)
|
|
2350
|
+
return html15``;
|
|
2351
|
+
const bound = this.shadow ?? app, past = !!this.shadow, d = bound.deployment(), l = ringLayout(d, { size: SIZE, show: this.show });
|
|
2352
|
+
const tooLong = !!tm && this.tooLong && ringSource(tm.mode, tm.cursor >= tm.span.to, false) === "too-long";
|
|
2353
|
+
const home = (pod2, rt) => rt ?? Object.keys(d.runtimes).find((r) => d.runtimes[r].pods.includes(pod2));
|
|
2354
|
+
const dots = (this.frame?.inFlight ?? []).flatMap(({ message, progress }) => {
|
|
2355
|
+
const p = ringDot(l, d, message, Math.min(1, progress));
|
|
2356
|
+
return p ? [svg2`<circle data-dot=${message.sent.id} cx=${p.x} cy=${p.y} r="6" fill=${tv("s2")} stroke=${tv("bg")} stroke-width="2" @click=${() => tm?.seek(message.at)}></circle>`] : [];
|
|
2357
|
+
});
|
|
2358
|
+
return html15`
|
|
2359
|
+
${tooLong ? html15`<small class="warn">history too long to rebuild state</small>` : ""}
|
|
2360
|
+
${this.failed ? html15`<small class="warn">${this.failed}</small>` : ""}
|
|
2361
|
+
<div class="stage" style="width:${SIZE}px;height:${SIZE}px">
|
|
2362
|
+
<svg>${l.runtimes.map((r) => svg2`<circle class="rt" cx=${r.x} cy=${r.y} r=${r.r}></circle><text x=${r.x} y=${r.y - r.r - 8} text-anchor="middle" fill=${tv("muted")}>${r.id}</text>`)}</svg>
|
|
2363
|
+
${l.pods.map((p) => html15`<div class="pod" data-pod=${p.pod} .inert=${past} style="left:${p.x}px;top:${p.y}px"><b>${p.pod}</b>${this.view(d, p.pod, home(p.pod, p.runtime), bound, registry)}</div>`)}
|
|
2364
|
+
<svg>${dots}</svg>
|
|
2365
|
+
</div>`;
|
|
2366
|
+
}
|
|
2367
|
+
}
|
|
2368
|
+
|
|
2369
|
+
// packages/ui/src/views/define.ts
|
|
2370
|
+
var views = { "nano.ui/input": "nano-input", "nano.ui/debounce": "nano-debounce", "nano.ui/map": "nano-map", "nano.ui/log": "nano-log" };
|
|
2371
|
+
var tags = { "nano-filter": NanoFilter, "nano-time-machine": NanoTimeMachine, "nano-ring": NanoRing, "nano-explorer": NanoExplorer, "nano-wiring": NanoWiring, "nano-pod-view": NanoPodView, "nano-input": NanoInput, "nano-debounce": NanoDebounce, "nano-map": NanoMap, "nano-log": NanoLog };
|
|
2372
|
+
function defineViews() {
|
|
2373
|
+
for (const [tag, cls] of Object.entries(tags))
|
|
2374
|
+
if (!customElements.get(tag))
|
|
2375
|
+
customElements.define(tag, cls);
|
|
2376
|
+
}
|
|
2377
|
+
// packages/ui/src/observe/record.ts
|
|
2378
|
+
var recorded = (e) => {
|
|
2379
|
+
if (e.type === "sent") {
|
|
2380
|
+
const { input: input2, ...rest } = e;
|
|
2381
|
+
return "input" in e ? { ...rest, input: snap(input2) } : rest;
|
|
2382
|
+
}
|
|
2383
|
+
if (e.type === "delivered")
|
|
2384
|
+
return { type: "delivered", id: e.id, ok: e.result.ok, result: snap(e.result.ok ? e.result.value : e.result.fail), ms: e.ms };
|
|
2385
|
+
return e;
|
|
2386
|
+
};
|
|
2387
|
+
async function record(app, store, opts = {}) {
|
|
2388
|
+
const now = opts.now ?? Date.now;
|
|
2389
|
+
let seq = 0;
|
|
2390
|
+
const heard = new Set;
|
|
2391
|
+
let held = [];
|
|
2392
|
+
const add = (event, at = now()) => {
|
|
2393
|
+
try {
|
|
2394
|
+
if (held)
|
|
2395
|
+
held.push({ at, event });
|
|
2396
|
+
else {
|
|
2397
|
+
const entry = { seq: ++seq, at, event };
|
|
2398
|
+
store.append(entry);
|
|
2399
|
+
for (const fn of heard)
|
|
2400
|
+
try {
|
|
2401
|
+
fn(entry);
|
|
2402
|
+
} catch {}
|
|
2403
|
+
}
|
|
2404
|
+
} catch {}
|
|
2405
|
+
};
|
|
2406
|
+
const deployment = (clean, caller) => add({ type: "deployment", deployment: app.deployment(), ...clean ? { clean: true } : {}, ...caller ? { caller } : {} });
|
|
2407
|
+
deployment(opts.clean);
|
|
2408
|
+
const stop = app.listen((e) => {
|
|
2409
|
+
try {
|
|
2410
|
+
add(recorded(e));
|
|
2411
|
+
if (e.type === "applied")
|
|
2412
|
+
deployment(false, e.caller);
|
|
2413
|
+
} catch {}
|
|
2414
|
+
});
|
|
2415
|
+
try {
|
|
2416
|
+
await store.flush();
|
|
2417
|
+
const n = await store.size();
|
|
2418
|
+
seq = n ? (await store.range(await store.oldest() + n - 1)).at(-1)?.seq ?? 0 : 0;
|
|
2419
|
+
} catch (e) {
|
|
2420
|
+
stop();
|
|
2421
|
+
throw e;
|
|
2422
|
+
}
|
|
2423
|
+
const waiting = held;
|
|
2424
|
+
held = undefined;
|
|
2425
|
+
for (const { at, event } of waiting)
|
|
2426
|
+
add(event, at);
|
|
2427
|
+
return { stop, listen: (fn) => {
|
|
2428
|
+
heard.add(fn);
|
|
2429
|
+
return () => {
|
|
2430
|
+
heard.delete(fn);
|
|
2431
|
+
};
|
|
2432
|
+
} };
|
|
2433
|
+
}
|
|
2434
|
+
// packages/ui/src/observe/clock-driver.ts
|
|
2435
|
+
import { lookup as lookup2 } from "@pritzlaff/nano-core";
|
|
2436
|
+
var raf2 = { now: () => Date.now(), frame: (fn) => {
|
|
2437
|
+
const id = requestAnimationFrame(fn);
|
|
2438
|
+
return () => cancelAnimationFrame(id);
|
|
2439
|
+
} };
|
|
2440
|
+
function clockDriver(app, registry, tm, opts = {}) {
|
|
2441
|
+
const ticker = opts.ticker ?? raf2, gap = 1000 / (opts.maxHz ?? 20);
|
|
2442
|
+
let driving = null, reason;
|
|
2443
|
+
const find = () => {
|
|
2444
|
+
const d = app.deployment();
|
|
2445
|
+
const clocks = Object.keys(d.pods).filter((p) => registry.implementation(d.pods[p].implementation)?.provides.some((i) => i.coord === ClockControl.coord));
|
|
2446
|
+
driving = clocks.length === 1 ? clocks[0] : null;
|
|
2447
|
+
reason = driving ? undefined : clocks.length ? `${clocks.length} pods provide ClockControl: ${clocks.join(", ")}` : "no pod provides ClockControl";
|
|
2448
|
+
};
|
|
2449
|
+
find();
|
|
2450
|
+
const unlisten = app.listen((e) => {
|
|
2451
|
+
if (e.type === "applied")
|
|
2452
|
+
find();
|
|
2453
|
+
});
|
|
2454
|
+
const flight = inFlight(app);
|
|
2455
|
+
let last = ticker.now(), cancel, closed = false;
|
|
2456
|
+
const loop = async () => {
|
|
2457
|
+
const now = ticker.now();
|
|
2458
|
+
if (driving && tm.mode === "live") {
|
|
2459
|
+
if (now - last >= gap) {
|
|
2460
|
+
const ms = (now - last) * tm.speed;
|
|
2461
|
+
last = now;
|
|
2462
|
+
const runtime2 = lookup2(app.deployment()).placedIn.get(driving)?.[0];
|
|
2463
|
+
if (runtime2) {
|
|
2464
|
+
await app.call(runtime2, driving).advance(ms);
|
|
2465
|
+
await flight.quiet();
|
|
2466
|
+
}
|
|
2467
|
+
}
|
|
2468
|
+
} else
|
|
2469
|
+
last = now;
|
|
2470
|
+
if (!closed)
|
|
2471
|
+
cancel = ticker.frame(loop);
|
|
2472
|
+
};
|
|
2473
|
+
cancel = ticker.frame(loop);
|
|
2474
|
+
return {
|
|
2475
|
+
get driving() {
|
|
2476
|
+
return driving;
|
|
2477
|
+
},
|
|
2478
|
+
get reason() {
|
|
2479
|
+
return reason;
|
|
2480
|
+
},
|
|
2481
|
+
close() {
|
|
2482
|
+
closed = true;
|
|
2483
|
+
cancel?.();
|
|
2484
|
+
unlisten();
|
|
2485
|
+
flight.stop();
|
|
2486
|
+
}
|
|
2487
|
+
};
|
|
2488
|
+
}
|
|
2489
|
+
// packages/ui/src/observe/fold.ts
|
|
2490
|
+
async function foldAt(store, t5, r) {
|
|
2491
|
+
await store.flush();
|
|
2492
|
+
const entries = await store.range();
|
|
2493
|
+
const last = entries.findLast((e) => e.at <= t5)?.seq ?? -Infinity;
|
|
2494
|
+
const messages = new Map(pair(entries).map((m) => [m.seq, m]));
|
|
2495
|
+
let s = r.initial;
|
|
2496
|
+
for (const e of entries) {
|
|
2497
|
+
if (e.seq > last)
|
|
2498
|
+
break;
|
|
2499
|
+
const m = messages.get(e.seq);
|
|
2500
|
+
if (m)
|
|
2501
|
+
s = r.step(s, m);
|
|
2502
|
+
else if (e.event.type === "deployment" && r.deployment)
|
|
2503
|
+
s = r.deployment(s, e.event.deployment);
|
|
2504
|
+
}
|
|
2505
|
+
return s;
|
|
2506
|
+
}
|
|
2507
|
+
// packages/ui/src/index.ts
|
|
2508
|
+
var src_default = uiProvider;
|
|
2509
|
+
export {
|
|
2510
|
+
views,
|
|
2511
|
+
viewFor,
|
|
2512
|
+
uiProvider,
|
|
2513
|
+
truncated,
|
|
2514
|
+
timeMachine,
|
|
2515
|
+
snap,
|
|
2516
|
+
simClock,
|
|
2517
|
+
shadowAt,
|
|
2518
|
+
seededRandom,
|
|
2519
|
+
roots,
|
|
2520
|
+
replay,
|
|
2521
|
+
record,
|
|
2522
|
+
random,
|
|
2523
|
+
pair,
|
|
2524
|
+
memoryStore,
|
|
2525
|
+
matches,
|
|
2526
|
+
map,
|
|
2527
|
+
log,
|
|
2528
|
+
input,
|
|
2529
|
+
foldAt,
|
|
2530
|
+
filterTree,
|
|
2531
|
+
emptyFilter,
|
|
2532
|
+
diverge,
|
|
2533
|
+
defineViews,
|
|
2534
|
+
src_default as default,
|
|
2535
|
+
debounce,
|
|
2536
|
+
clockDriver,
|
|
2537
|
+
clock,
|
|
2538
|
+
circuitOf,
|
|
2539
|
+
Random,
|
|
2540
|
+
Nothing,
|
|
2541
|
+
NanoTimeMachine,
|
|
2542
|
+
NanoRing,
|
|
2543
|
+
NanoFilter,
|
|
2544
|
+
MapIface,
|
|
2545
|
+
Log,
|
|
2546
|
+
Input,
|
|
2547
|
+
HostUI,
|
|
2548
|
+
HostDeploy,
|
|
2549
|
+
Debounce,
|
|
2550
|
+
ClockControl,
|
|
2551
|
+
Clock,
|
|
2552
|
+
Any
|
|
2553
|
+
};
|
|
2554
|
+
|
|
2555
|
+
//# debugId=E83F4F542A4BD60B64756E2164756E21
|
|
2556
|
+
//# sourceMappingURL=index.js.map
|