@pritzlaff/nano-ui 0.0.0-stage → 0.4.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.d.ts +36 -0
- package/index.d.ts +18 -0
- package/index.js +958 -0
- package/index.js.map +30 -0
- package/interfaces.d.ts +113 -0
- package/layout.d.ts +31 -0
- package/package.json +29 -4
- package/pods/debounce.d.ts +3 -0
- package/pods/input.d.ts +2 -0
- package/pods/log.d.ts +3 -0
- package/pods/map.d.ts +3 -0
- package/provider.d.ts +1 -0
- package/views/define.d.ts +3 -0
- package/views/faces.d.ts +29 -0
- package/views/pod-view.d.ts +10 -0
- package/views/view.d.ts +60 -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,958 @@
|
|
|
1
|
+
// packages/ui/src/provider.ts
|
|
2
|
+
import { Coord as Coord6 } from "@pritzlaff/nano-core";
|
|
3
|
+
|
|
4
|
+
// packages/ui/src/pods/debounce.ts
|
|
5
|
+
import { Type as Type2 } from "typebox";
|
|
6
|
+
import { Coord as Coord2, Schema as Schema2, Implementation, provide, success } from "@pritzlaff/nano-core";
|
|
7
|
+
|
|
8
|
+
// packages/ui/src/interfaces.ts
|
|
9
|
+
import { Type } from "typebox";
|
|
10
|
+
import { Coord, Schema, Op } from "@pritzlaff/nano-core";
|
|
11
|
+
var ns = Coord.namespace("nano.ui");
|
|
12
|
+
var Any = Schema.define(Type.Unknown(), "Any");
|
|
13
|
+
var Nothing = Schema.define(Type.Null(), "Nothing");
|
|
14
|
+
var Entries = Schema.define(Type.Array(Type.Unknown()), "Entries");
|
|
15
|
+
var Text = Schema.define(Type.String(), "Text");
|
|
16
|
+
var Approval = Schema.define(Type.Object({ title: Type.String(), detail: Type.Optional(Type.String()) }), "Approval");
|
|
17
|
+
var Approved = Schema.define(Type.Boolean(), "Approved");
|
|
18
|
+
var Input = ns.interface("Input", { submit: Op.action(Any, Any) });
|
|
19
|
+
var Debounce = ns.interface("Debounce", { push: Op.action(Any, Nothing), flushed: Op.event(Any) });
|
|
20
|
+
var MapIface = ns.interface("Map", { map: Op.action(Any, Any) });
|
|
21
|
+
var Log = ns.interface("Log", {
|
|
22
|
+
log: Op.action(Any, Nothing),
|
|
23
|
+
entries: Op.action(Nothing, Entries),
|
|
24
|
+
clear: Op.action(Nothing, Nothing)
|
|
25
|
+
});
|
|
26
|
+
var HostUI = ns.interface("HostUI", {
|
|
27
|
+
alert: Op.action(Text, Nothing),
|
|
28
|
+
approve: Op.action(Approval, Approved),
|
|
29
|
+
setAppBar: Op.action(Text, Nothing)
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
// packages/ui/src/pods/debounce.ts
|
|
33
|
+
var ns2 = Coord2.namespace("nano.ui");
|
|
34
|
+
var debounce = Implementation.define(ns2.implementationId("debounce"), {
|
|
35
|
+
provides: [Debounce],
|
|
36
|
+
config: Schema2.define(Type2.Union([Type2.Object({ quietMs: Type2.Integer({ minimum: 0, maximum: 60000 }) }), Type2.Undefined()]), "DebounceConfig"),
|
|
37
|
+
make: (ctx, config) => {
|
|
38
|
+
const quietMs = config?.quietMs ?? 300;
|
|
39
|
+
let timer;
|
|
40
|
+
let closed = false;
|
|
41
|
+
ctx.addOnCloseListener(() => {
|
|
42
|
+
closed = true;
|
|
43
|
+
clearTimeout(timer);
|
|
44
|
+
});
|
|
45
|
+
return [provide(Debounce, {
|
|
46
|
+
push: async (value) => {
|
|
47
|
+
if (closed)
|
|
48
|
+
return success(null);
|
|
49
|
+
clearTimeout(timer);
|
|
50
|
+
timer = setTimeout(() => {
|
|
51
|
+
ctx.publish(Debounce.ops.flushed, value);
|
|
52
|
+
}, quietMs);
|
|
53
|
+
return success(null);
|
|
54
|
+
}
|
|
55
|
+
})];
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
// packages/ui/src/pods/input.ts
|
|
60
|
+
import { Coord as Coord3, Implementation as Implementation2, provide as provide2, success as success2 } from "@pritzlaff/nano-core";
|
|
61
|
+
var ns3 = Coord3.namespace("nano.ui");
|
|
62
|
+
var input = Implementation2.define(ns3.implementationId("input"), {
|
|
63
|
+
provides: [Input],
|
|
64
|
+
make: () => [provide2(Input, { submit: async (v) => success2(v) })]
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
// packages/ui/src/pods/log.ts
|
|
68
|
+
import { Type as Type3 } from "typebox";
|
|
69
|
+
import { Coord as Coord4, Schema as Schema3, Implementation as Implementation3, provide as provide3, success as success3 } from "@pritzlaff/nano-core";
|
|
70
|
+
var ns4 = Coord4.namespace("nano.ui");
|
|
71
|
+
var log = Implementation3.define(ns4.implementationId("log"), {
|
|
72
|
+
provides: [Log],
|
|
73
|
+
config: Schema3.define(Type3.Union([Type3.Object({ max: Type3.Optional(Type3.Integer({ minimum: 1, maximum: 1000 })) }), Type3.Undefined()]), "LogConfig"),
|
|
74
|
+
make: (_ctx, config) => {
|
|
75
|
+
const max = config?.max ?? 100;
|
|
76
|
+
let entries = [];
|
|
77
|
+
return [provide3(Log, {
|
|
78
|
+
log: async (v) => {
|
|
79
|
+
entries = [...entries, v].slice(-max);
|
|
80
|
+
return success3(null);
|
|
81
|
+
},
|
|
82
|
+
entries: async () => success3([...entries]),
|
|
83
|
+
clear: async () => {
|
|
84
|
+
entries = [];
|
|
85
|
+
return success3(null);
|
|
86
|
+
}
|
|
87
|
+
})];
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
// packages/ui/src/pods/map.ts
|
|
92
|
+
import { Type as Type4 } from "typebox";
|
|
93
|
+
import { Coord as Coord5, Schema as Schema4, Implementation as Implementation4, provide as provide4, success as success4 } from "@pritzlaff/nano-core";
|
|
94
|
+
var ns5 = Coord5.namespace("nano.ui");
|
|
95
|
+
var map = Implementation4.define(ns5.implementationId("map"), {
|
|
96
|
+
provides: [MapIface],
|
|
97
|
+
config: Schema4.define(Type4.Object({ code: Type4.String() }), "MapConfig"),
|
|
98
|
+
make: (_ctx, config) => {
|
|
99
|
+
const fn = new Function("x", config.code);
|
|
100
|
+
return [provide4(MapIface, { map: async (x) => success4(fn(x)) })];
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// packages/ui/src/provider.ts
|
|
105
|
+
var ns6 = Coord6.namespace("nano.ui");
|
|
106
|
+
var uiProvider = ns6.provider([input, debounce, map, log]);
|
|
107
|
+
// packages/ui/src/views/faces.ts
|
|
108
|
+
import { css, html as html2 } from "lit";
|
|
109
|
+
import { port } from "@pritzlaff/nano-core";
|
|
110
|
+
import { base as base2, t } from "@pritzlaff/nano-elements";
|
|
111
|
+
|
|
112
|
+
// packages/ui/src/views/view.ts
|
|
113
|
+
import { LitElement, html } from "lit";
|
|
114
|
+
import { base } from "@pritzlaff/nano-elements";
|
|
115
|
+
var defined = (tag) => tag && customElements.get(tag) ? tag : undefined;
|
|
116
|
+
function viewFor(pod, deployment, defaults) {
|
|
117
|
+
const impl = deployment.pods[pod]?.implementation;
|
|
118
|
+
return defined(deployment.views?.[pod]) ?? defined(impl === undefined ? undefined : defaults[impl]) ?? "nano-pod-view";
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
class ViewElement extends LitElement {
|
|
122
|
+
static properties = { target: { attribute: false }, removed: { state: true } };
|
|
123
|
+
static styles = [base];
|
|
124
|
+
off;
|
|
125
|
+
watching;
|
|
126
|
+
constructor() {
|
|
127
|
+
super();
|
|
128
|
+
this.removed = false;
|
|
129
|
+
}
|
|
130
|
+
connectedCallback() {
|
|
131
|
+
super.connectedCallback();
|
|
132
|
+
this.watch();
|
|
133
|
+
}
|
|
134
|
+
disconnectedCallback() {
|
|
135
|
+
super.disconnectedCallback();
|
|
136
|
+
this.stop();
|
|
137
|
+
}
|
|
138
|
+
willUpdate(changed) {
|
|
139
|
+
if (changed.has("target")) {
|
|
140
|
+
this.removed = false;
|
|
141
|
+
this.watch();
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
watch() {
|
|
145
|
+
const t = this.target;
|
|
146
|
+
if (!t || !this.isConnected || this.removed || this.watching === t)
|
|
147
|
+
return;
|
|
148
|
+
this.stop();
|
|
149
|
+
this.watching = t;
|
|
150
|
+
this.off = t.app.listen((e) => {
|
|
151
|
+
if (e.type === "applied" && e.removed.includes(t.pod)) {
|
|
152
|
+
this.removed = true;
|
|
153
|
+
this.stop();
|
|
154
|
+
return;
|
|
155
|
+
}
|
|
156
|
+
if (e.type === "applied")
|
|
157
|
+
this.requestUpdate();
|
|
158
|
+
this.hear(e, t);
|
|
159
|
+
});
|
|
160
|
+
this.started(t);
|
|
161
|
+
}
|
|
162
|
+
stop() {
|
|
163
|
+
this.off?.();
|
|
164
|
+
this.off = undefined;
|
|
165
|
+
this.watching = undefined;
|
|
166
|
+
}
|
|
167
|
+
pod(t) {
|
|
168
|
+
return t.app.call(t.runtime, t.pod);
|
|
169
|
+
}
|
|
170
|
+
started(_t) {}
|
|
171
|
+
hear(_e, _t) {}
|
|
172
|
+
face(_t) {
|
|
173
|
+
return html``;
|
|
174
|
+
}
|
|
175
|
+
render() {
|
|
176
|
+
if (this.removed)
|
|
177
|
+
return html`<div class="muted">removed</div>`;
|
|
178
|
+
return this.target ? this.face(this.target) : html``;
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
var shown = (r) => r === undefined ? "—" : r.ok ? JSON.stringify(r.value) : `failed: ${r.fail?.reason}`;
|
|
182
|
+
|
|
183
|
+
// packages/ui/src/views/faces.ts
|
|
184
|
+
class NanoInput extends ViewElement {
|
|
185
|
+
async enter(e, tg) {
|
|
186
|
+
if (e.key !== "Enter")
|
|
187
|
+
return;
|
|
188
|
+
const box = e.target;
|
|
189
|
+
await this.pod(tg).submit(box.value);
|
|
190
|
+
}
|
|
191
|
+
face(tg) {
|
|
192
|
+
return html2`<input type="text" aria-label=${tg.pod} @keydown=${(e) => this.enter(e, tg)}>`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
var PUSH = port(Debounce, Debounce.ops.push);
|
|
196
|
+
|
|
197
|
+
class NanoDebounce extends ViewElement {
|
|
198
|
+
static styles = [base2, css`.flash { color: ${t("accent")} }`];
|
|
199
|
+
pending = false;
|
|
200
|
+
flash = false;
|
|
201
|
+
timer;
|
|
202
|
+
hear(e, tg) {
|
|
203
|
+
if (e.type !== "sent")
|
|
204
|
+
return;
|
|
205
|
+
if (e.to === tg.pod && e.port === PUSH)
|
|
206
|
+
this.pending = true;
|
|
207
|
+
else if (e.from === tg.pod) {
|
|
208
|
+
this.pending = false;
|
|
209
|
+
this.flash = true;
|
|
210
|
+
clearTimeout(this.timer);
|
|
211
|
+
this.timer = setTimeout(() => {
|
|
212
|
+
this.flash = false;
|
|
213
|
+
this.requestUpdate();
|
|
214
|
+
}, 300);
|
|
215
|
+
} else
|
|
216
|
+
return;
|
|
217
|
+
this.requestUpdate();
|
|
218
|
+
}
|
|
219
|
+
disconnectedCallback() {
|
|
220
|
+
super.disconnectedCallback();
|
|
221
|
+
clearTimeout(this.timer);
|
|
222
|
+
}
|
|
223
|
+
face() {
|
|
224
|
+
return html2`<span class=${this.flash ? "badge accent flash" : "badge"}>${this.flash ? "flushed" : this.pending ? "pending" : "idle"}</span>`;
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
var MAP = port(MapIface, MapIface.ops.map);
|
|
228
|
+
|
|
229
|
+
class NanoMap extends ViewElement {
|
|
230
|
+
mine = new Set;
|
|
231
|
+
output;
|
|
232
|
+
hear(e, tg) {
|
|
233
|
+
if (e.type === "sent" && e.to === tg.pod && e.port === MAP)
|
|
234
|
+
this.mine.add(e.id);
|
|
235
|
+
else if (e.type === "denied")
|
|
236
|
+
this.mine.delete(e.id);
|
|
237
|
+
else if (e.type === "delivered" && this.mine.delete(e.id)) {
|
|
238
|
+
this.output = e.result;
|
|
239
|
+
this.requestUpdate();
|
|
240
|
+
}
|
|
241
|
+
}
|
|
242
|
+
face(tg) {
|
|
243
|
+
const code = tg.app.deployment().pods[tg.pod]?.config?.code ?? "";
|
|
244
|
+
return html2`<pre class="code">${code}</pre><div>out ${shown(this.output)}</div>`;
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
var LOG = port(Log, Log.ops.log);
|
|
248
|
+
|
|
249
|
+
class NanoLog extends ViewElement {
|
|
250
|
+
entries = [];
|
|
251
|
+
logs = new Set;
|
|
252
|
+
started(tg) {
|
|
253
|
+
this.read(tg);
|
|
254
|
+
}
|
|
255
|
+
async read(tg) {
|
|
256
|
+
const r = await this.pod(tg).entries(null);
|
|
257
|
+
if (r.ok) {
|
|
258
|
+
this.entries = r.value;
|
|
259
|
+
this.requestUpdate();
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
hear(e, tg) {
|
|
263
|
+
if (e.type === "sent" && e.to === tg.pod && e.port === LOG)
|
|
264
|
+
this.logs.add(e.id);
|
|
265
|
+
else if (e.type === "denied")
|
|
266
|
+
this.logs.delete(e.id);
|
|
267
|
+
else if (e.type === "delivered" && this.logs.delete(e.id))
|
|
268
|
+
this.read(tg);
|
|
269
|
+
}
|
|
270
|
+
face() {
|
|
271
|
+
return html2`<ol>${this.entries.map((x) => html2`<li>${typeof x === "string" ? x : JSON.stringify(x)}</li>`)}</ol>`;
|
|
272
|
+
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// packages/ui/src/explorer.ts
|
|
276
|
+
import { LitElement as LitElement2, html as html3 } from "lit";
|
|
277
|
+
import { base as base3 } from "@pritzlaff/nano-elements";
|
|
278
|
+
import"@pritzlaff/nano-elements";
|
|
279
|
+
var op = (port2) => port2.slice(port2.lastIndexOf("/") + 1);
|
|
280
|
+
|
|
281
|
+
class NanoExplorer extends LitElement2 {
|
|
282
|
+
static properties = { target: { attribute: false }, states: { state: true } };
|
|
283
|
+
static styles = [base3];
|
|
284
|
+
off;
|
|
285
|
+
watching;
|
|
286
|
+
opens = new Map;
|
|
287
|
+
constructor() {
|
|
288
|
+
super();
|
|
289
|
+
this.states = {};
|
|
290
|
+
}
|
|
291
|
+
connectedCallback() {
|
|
292
|
+
super.connectedCallback();
|
|
293
|
+
this.watch();
|
|
294
|
+
}
|
|
295
|
+
disconnectedCallback() {
|
|
296
|
+
super.disconnectedCallback();
|
|
297
|
+
this.stop();
|
|
298
|
+
}
|
|
299
|
+
willUpdate(changed) {
|
|
300
|
+
if (changed.has("target"))
|
|
301
|
+
this.watch();
|
|
302
|
+
}
|
|
303
|
+
watch() {
|
|
304
|
+
const t2 = this.target;
|
|
305
|
+
if (!t2 || !this.isConnected || this.watching === t2)
|
|
306
|
+
return;
|
|
307
|
+
this.stop();
|
|
308
|
+
this.watching = t2;
|
|
309
|
+
this.off = t2.app.listen((e) => {
|
|
310
|
+
if (e.type === "built" || e.type === "closed")
|
|
311
|
+
this.states = { ...this.states, [e.pod]: e.type };
|
|
312
|
+
else if (e.type === "applied") {
|
|
313
|
+
const live = t2.app.deployment().pods;
|
|
314
|
+
this.states = Object.fromEntries(Object.entries(this.states).filter(([pod]) => Object.hasOwn(live, pod)));
|
|
315
|
+
}
|
|
316
|
+
});
|
|
317
|
+
}
|
|
318
|
+
stop() {
|
|
319
|
+
this.off?.();
|
|
320
|
+
this.off = undefined;
|
|
321
|
+
this.watching = undefined;
|
|
322
|
+
}
|
|
323
|
+
nodes(t2) {
|
|
324
|
+
const d = t2.app.deployment();
|
|
325
|
+
this.opens.clear();
|
|
326
|
+
return Object.entries(d.runtimes).map(([runtime, r]) => ({
|
|
327
|
+
id: `r:${runtime}`,
|
|
328
|
+
label: runtime,
|
|
329
|
+
kind: "runtime",
|
|
330
|
+
count: r.pods.length,
|
|
331
|
+
children: r.pods.map((pod) => {
|
|
332
|
+
const p = d.pods[pod], id = `p:${runtime}:${pod}`;
|
|
333
|
+
this.opens.set(id, { runtime, pod });
|
|
334
|
+
const subs = r.subscriptions.filter((s) => s.from === pod).map((s, i) => {
|
|
335
|
+
const sid = `s:${runtime}:${pod}:${i}`;
|
|
336
|
+
if (s.kind === "call") {
|
|
337
|
+
this.opens.set(sid, { runtime, pod: s.to });
|
|
338
|
+
return { id: sid, label: `built on → ${s.to}` };
|
|
339
|
+
}
|
|
340
|
+
return { id: sid, label: `${op(s.source)} → ${s.to}.${op(s.target)}` };
|
|
341
|
+
});
|
|
342
|
+
return {
|
|
343
|
+
id,
|
|
344
|
+
label: pod,
|
|
345
|
+
kind: "pod",
|
|
346
|
+
badge: this.states[pod],
|
|
347
|
+
terms: [p?.implementation ?? ""],
|
|
348
|
+
body: html3`${p?.implementation} ${p?.config === undefined ? "" : JSON.stringify(p.config)}`,
|
|
349
|
+
children: subs
|
|
350
|
+
};
|
|
351
|
+
})
|
|
352
|
+
}));
|
|
353
|
+
}
|
|
354
|
+
render() {
|
|
355
|
+
if (!this.target)
|
|
356
|
+
return html3``;
|
|
357
|
+
return html3`<nano-tree .nodes=${this.nodes(this.target)} open-depth="2" @select=${(e) => {
|
|
358
|
+
const open = this.opens.get(e.detail.id);
|
|
359
|
+
if (open)
|
|
360
|
+
this.dispatchEvent(new CustomEvent("nano-open", { detail: open, bubbles: true, composed: true }));
|
|
361
|
+
}}></nano-tree>`;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
// packages/ui/src/wiring/wiring.ts
|
|
366
|
+
import { LitElement as LitElement3 } from "lit";
|
|
367
|
+
|
|
368
|
+
// packages/ui/src/wiring/constants.ts
|
|
369
|
+
var TYPE_COLOR = { string: "#2dd4bf", number: "#fbbf24", boolean: "#f472b6", object: "#60a5fa", array: "#a78bfa", signal: "#94a3b8", any: "#e5e7eb", call: "#4CC2FF" };
|
|
370
|
+
var TYPE_GLYPH = { string: "Aa", number: "#", boolean: "?", object: "{}", array: "[]", signal: "•", any: "*", call: "↦" };
|
|
371
|
+
var TYPE_NAME = { string: "String", number: "Number", boolean: "Boolean", object: "Object", array: "Array", signal: "Signal", any: "Any", call: "Call" };
|
|
372
|
+
var PW = 720;
|
|
373
|
+
var PH = 440;
|
|
374
|
+
var XSTEP = 140;
|
|
375
|
+
var ZGAP = 160;
|
|
376
|
+
var TILT = "rotateX(32deg) rotateY(-14deg)";
|
|
377
|
+
var FADE_MIN = 0.15;
|
|
378
|
+
var FADE_STEP = 0.35;
|
|
379
|
+
var DIM_CABLE = 0.18;
|
|
380
|
+
var fade = (d) => Math.max(FADE_MIN, 1 - FADE_STEP * Math.abs(d));
|
|
381
|
+
var PAD = 24;
|
|
382
|
+
var PAD_STEP = 30;
|
|
383
|
+
var HEAD = 34;
|
|
384
|
+
var SIDE_W = 280;
|
|
385
|
+
var SIDE_GAP = 140;
|
|
386
|
+
var BLOCK_HEAD = 30;
|
|
387
|
+
var BLOCK_GAP = 28;
|
|
388
|
+
var ITEM_GAP = 12;
|
|
389
|
+
var ZOOM_MIN = 0.3;
|
|
390
|
+
var ZOOM_MAX = 2.5;
|
|
391
|
+
var MARGIN = 60;
|
|
392
|
+
|
|
393
|
+
// packages/ui/src/wiring/layout.ts
|
|
394
|
+
var frameId = (at) => ("layer" in at) ? `l:${at.layer}` : `s:${at.side}`;
|
|
395
|
+
var posKey = (frame, pad) => `${frame}|${pad}`;
|
|
396
|
+
var slots = (pads, r) => {
|
|
397
|
+
const n = { in: 0, out: 0 };
|
|
398
|
+
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 }));
|
|
399
|
+
};
|
|
400
|
+
var union = (rs) => {
|
|
401
|
+
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));
|
|
402
|
+
return { x: x0, y: y0, w: x1 - x0, h: y1 - y0 };
|
|
403
|
+
};
|
|
404
|
+
var layerBoxes = (l) => l.footprints.map((f) => {
|
|
405
|
+
const b = f.box, rect = { x: b.x * PW, y: b.y * PH, w: b.w * PW, h: b.h * PH };
|
|
406
|
+
return { item: f, rect, pads: slots(f.pads, rect) };
|
|
407
|
+
});
|
|
408
|
+
function layout(c) {
|
|
409
|
+
const pos = new Map;
|
|
410
|
+
const register = (f) => {
|
|
411
|
+
for (const b of f.boxes)
|
|
412
|
+
for (const p of b.pads)
|
|
413
|
+
pos.set(posKey(f.id, p.pad.key), { x: f.origin.x + p.x, y: f.origin.y + p.y });
|
|
414
|
+
};
|
|
415
|
+
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) }));
|
|
416
|
+
const sideX = Math.max(0, c.layers.length - 1) * XSTEP + PW + SIDE_GAP;
|
|
417
|
+
let y = 0;
|
|
418
|
+
const blocks = c.side.map((block) => {
|
|
419
|
+
let cy = BLOCK_HEAD;
|
|
420
|
+
const boxes = block.items.map((item) => {
|
|
421
|
+
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;
|
|
422
|
+
const rect = { x: 0, y: cy, w: SIDE_W, h };
|
|
423
|
+
cy += h + ITEM_GAP;
|
|
424
|
+
return { item, rect, pads: slots(item.pads, rect) };
|
|
425
|
+
});
|
|
426
|
+
const f = { block, id: `s:${block.system}`, origin: { x: sideX, y }, rect: { x: sideX, y, w: SIDE_W, h: cy }, boxes };
|
|
427
|
+
y += cy + BLOCK_GAP;
|
|
428
|
+
return f;
|
|
429
|
+
});
|
|
430
|
+
for (const f of [...layers, ...blocks])
|
|
431
|
+
register(f);
|
|
432
|
+
const pageRect = (i) => ({ x: i * XSTEP, y: 0, w: PW, h: PH });
|
|
433
|
+
const bounds = union([...layers.map((l) => l.rect), ...blocks.map((b) => b.rect), { x: 0, y: 0, w: PW, h: PH }]);
|
|
434
|
+
return { layers, blocks, pos, bounds, pageRect };
|
|
435
|
+
}
|
|
436
|
+
|
|
437
|
+
// packages/ui/src/wiring/types.ts
|
|
438
|
+
function padTypeOf(schema) {
|
|
439
|
+
if (!schema)
|
|
440
|
+
return "signal";
|
|
441
|
+
const t2 = schema.type;
|
|
442
|
+
if (t2 === "void" || t2 === "undefined")
|
|
443
|
+
return "signal";
|
|
444
|
+
if (t2 === "string" || t2 === "boolean" || t2 === "object" || t2 === "array")
|
|
445
|
+
return t2;
|
|
446
|
+
if (t2 === "number" || t2 === "integer")
|
|
447
|
+
return "number";
|
|
448
|
+
return "any";
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// packages/ui/src/wiring/model.ts
|
|
452
|
+
var padsOf = (scope, pod, deployment, registry) => {
|
|
453
|
+
const impl = registry.implementation(deployment.pods[pod]?.implementation ?? "");
|
|
454
|
+
const pad = (port2, o, dir, kind, schema) => ({
|
|
455
|
+
key: `${scope}${pod} ${port2}:${dir}`,
|
|
456
|
+
instance: pod,
|
|
457
|
+
op: port2,
|
|
458
|
+
label: o.name,
|
|
459
|
+
dir,
|
|
460
|
+
kind,
|
|
461
|
+
type: padTypeOf(schema?.schema),
|
|
462
|
+
...o.description !== undefined && { description: o.description },
|
|
463
|
+
...schema && { schema: schema.schema }
|
|
464
|
+
});
|
|
465
|
+
return (impl?.provides ?? []).flatMap((i) => Object.values(i.ops).flatMap((o) => {
|
|
466
|
+
const port2 = `${i.coord}/${o.name}`;
|
|
467
|
+
return o.kind === "action" ? [pad(port2, o, "in", "call", o.input), pad(port2, o, "out", "event", o.output)] : [pad(port2, o, "out", "event", o.output)];
|
|
468
|
+
}));
|
|
469
|
+
};
|
|
470
|
+
var gridBoxes = (n) => {
|
|
471
|
+
const cols = Math.ceil(Math.sqrt(n)), rows = Math.ceil(n / cols);
|
|
472
|
+
return Array.from({ length: n }, (_, i) => ({ x: i % cols / cols, y: Math.floor(i / cols) / rows, w: 1 / cols, h: 1 / rows }));
|
|
473
|
+
};
|
|
474
|
+
function circuitOf(deployment, registry) {
|
|
475
|
+
const runtimes = Object.entries(deployment.runtimes);
|
|
476
|
+
const count = new Map;
|
|
477
|
+
for (const [, r] of runtimes)
|
|
478
|
+
for (const p of r.pods)
|
|
479
|
+
count.set(p, (count.get(p) ?? 0) + 1);
|
|
480
|
+
const shared = [...count].filter(([, n]) => n > 1).map(([p]) => p);
|
|
481
|
+
const layers = runtimes.map(([id, r]) => {
|
|
482
|
+
const grid = gridBoxes(r.pods.length);
|
|
483
|
+
return { screen: id, title: id, system: id, footprints: r.pods.map((pod, i) => ({ system: id, instance: pod, title: pod, box: grid[i], shared: shared.includes(pod), pads: padsOf(`${id}/`, pod, deployment, registry) })) };
|
|
484
|
+
});
|
|
485
|
+
const side = shared.map((pod) => ({ system: pod, items: [{ system: pod, instance: pod, title: pod, pads: padsOf("shared:", pod, deployment, registry) }] }));
|
|
486
|
+
const cables = runtimes.flatMap(([id, r]) => r.subscriptions.flatMap((s) => {
|
|
487
|
+
const pads = (pod) => layers.find((l) => l.screen === id).footprints.find((f) => f.instance === pod).pads;
|
|
488
|
+
const at = { layer: id };
|
|
489
|
+
if (s.kind === "call") {
|
|
490
|
+
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];
|
|
491
|
+
return a2 && b2 ? [{ id: `${id}|${s.from}|${s.to}|call|`, system: id, from: { pad: a2.key, at }, to: { pad: b2.key, at }, type: "call" }] : [];
|
|
492
|
+
}
|
|
493
|
+
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");
|
|
494
|
+
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 }] : [];
|
|
495
|
+
}));
|
|
496
|
+
for (const pod of shared) {
|
|
497
|
+
const sp = side.find((b) => b.system === pod).items[0].pads[0];
|
|
498
|
+
for (const l of layers) {
|
|
499
|
+
const p = l.footprints.find((f) => f.instance === pod)?.pads[0];
|
|
500
|
+
if (p && sp)
|
|
501
|
+
cables.push({ id: `link|${l.screen}|${pod}`, system: pod, from: { pad: p.key, at: { layer: l.screen } }, to: { pad: sp.key, at: { side: pod } }, type: "signal" });
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
return { layers, side, cables };
|
|
505
|
+
}
|
|
506
|
+
|
|
507
|
+
// packages/ui/src/wiring/render-pills.ts
|
|
508
|
+
import { html as html4 } from "lit";
|
|
509
|
+
function renderPills(el) {
|
|
510
|
+
const { focus } = el.s;
|
|
511
|
+
return html4`<nav class="pills" aria-label="Wiring views">
|
|
512
|
+
<button class="pill" data-whole @click=${() => el.fitAll()}>Whole board</button>
|
|
513
|
+
${el.model.layers.map((l) => html4`<button class="pill" data-screen=${l.screen} aria-pressed=${focus === l.screen} @click=${() => el.go(l.screen)}>
|
|
514
|
+
<span class="ic" aria-hidden="true">${l.title.slice(0, 1).toUpperCase()}</span>${l.title}</button>`)}
|
|
515
|
+
</nav>`;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// packages/ui/src/wiring/render-stage.ts
|
|
519
|
+
import { html as html6, svg } from "lit";
|
|
520
|
+
import { styleMap } from "lit/directives/style-map.js";
|
|
521
|
+
|
|
522
|
+
// packages/ui/src/wiring/render-drawer.ts
|
|
523
|
+
import { html as html5, nothing } from "lit";
|
|
524
|
+
var uniq = (xs) => [...new Set(xs)];
|
|
525
|
+
function describe(el) {
|
|
526
|
+
const { sel } = el.s, m = el.model;
|
|
527
|
+
if (!sel)
|
|
528
|
+
return null;
|
|
529
|
+
const [what, id = ""] = [sel.slice(0, sel.indexOf(":")), sel.slice(sel.indexOf(":") + 1)];
|
|
530
|
+
const items = [...m.layers.flatMap((l) => l.footprints), ...m.side.flatMap((b) => b.items)];
|
|
531
|
+
const pads = items.flatMap((i) => i.pads), padOf = (key) => pads.find((p) => p.key === key);
|
|
532
|
+
const routes = (p) => m.cables.filter((c) => c.from.pad === p.key || c.to.pad === p.key).length;
|
|
533
|
+
const name = (p) => `${p.instance}.${p.label}`;
|
|
534
|
+
if (what === "pad") {
|
|
535
|
+
const p = padOf(id);
|
|
536
|
+
if (!p)
|
|
537
|
+
return null;
|
|
538
|
+
return {
|
|
539
|
+
kicker: `${p.dir === "in" ? "Input" : "Output"} pad`,
|
|
540
|
+
title: name(p),
|
|
541
|
+
sub: p.op,
|
|
542
|
+
types: [p.type],
|
|
543
|
+
rows: [["Kind", p.kind], ["Type", TYPE_NAME[p.type]], ["Routes", String(routes(p))], ["Description", p.description ?? "-"]],
|
|
544
|
+
schemaLabel: p.dir === "in" ? "Input schema" : "Output schema",
|
|
545
|
+
schema: p.schema,
|
|
546
|
+
follow: routes(p) > 0
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
if (what === "cable") {
|
|
550
|
+
const c = m.cables.find((x) => x.id === id), a = c && padOf(c.from.pad), b = c && padOf(c.to.pad);
|
|
551
|
+
if (!c || !a || !b)
|
|
552
|
+
return null;
|
|
553
|
+
return {
|
|
554
|
+
kicker: "Cable",
|
|
555
|
+
title: `${name(a)} → ${name(b)}`,
|
|
556
|
+
sub: c.system,
|
|
557
|
+
types: [c.type],
|
|
558
|
+
rows: [["Kind", a.kind], ["Type", TYPE_NAME[c.type]], ["From", name(a)], ["To", name(b)]],
|
|
559
|
+
schemaLabel: "Output schema",
|
|
560
|
+
schema: a.schema,
|
|
561
|
+
follow: true
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
const it = items.find((i) => `${i.system}/${i.instance}` === id);
|
|
565
|
+
if (!it)
|
|
566
|
+
return null;
|
|
567
|
+
return {
|
|
568
|
+
kicker: "Pod",
|
|
569
|
+
title: it.title,
|
|
570
|
+
sub: `${it.system}/${it.instance}`,
|
|
571
|
+
types: uniq(it.pads.map((p) => p.type)),
|
|
572
|
+
rows: [["Pads", String(it.pads.length)], ["Routes", String(it.pads.reduce((n, p) => n + routes(p), 0))]],
|
|
573
|
+
follow: false
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
function renderDrawer(el) {
|
|
577
|
+
const d = describe(el);
|
|
578
|
+
return html5`<aside class="drawer" aria-label="Details" ?hidden=${!d} @wheel=${(e) => e.stopPropagation()}>${!d ? nothing : html5`
|
|
579
|
+
<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>
|
|
580
|
+
<button aria-label="Close details" @click=${() => {
|
|
581
|
+
el.select(null);
|
|
582
|
+
el.refocus();
|
|
583
|
+
}}>✕</button></div>
|
|
584
|
+
<div class="chips">${d.types.map((t2) => html5`<span class="chip"><span class="glyph" aria-hidden="true" style="background:${TYPE_COLOR[t2]}">${TYPE_GLYPH[t2]}</span>${TYPE_NAME[t2]}</span>`)}</div>
|
|
585
|
+
<dl>${d.rows.map(([k, v]) => html5`<dt>${k}</dt><dd>${v}</dd>`)}</dl>
|
|
586
|
+
${d.schemaLabel ? html5`<div class="kicker">${d.schemaLabel}</div><pre>${d.schema === undefined ? "none (signal)" : JSON.stringify(d.schema, null, 2)}</pre>` : nothing}
|
|
587
|
+
${d.follow ? html5`<div class="actions"><button @click=${() => el.follow()}>Follow cable</button></div>` : nothing}`}</aside>`;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
// packages/ui/src/wiring/render-stage.ts
|
|
591
|
+
var px = (r) => ({ left: `${r.x}px`, top: `${r.y}px`, width: `${r.w}px`, height: `${r.h}px` });
|
|
592
|
+
function pad(el, { pad: p, x, y }) {
|
|
593
|
+
const c = TYPE_COLOR[p.type], out = p.dir === "out";
|
|
594
|
+
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" };
|
|
595
|
+
return html6`<button class="pad" data-pad=${p.key} data-dir=${p.dir} data-kind=${p.kind} style=${styleMap(style)} title=${p.description ?? ""}
|
|
596
|
+
aria-label=${`${p.instance}.${p.label}, ${TYPE_NAME[p.type]}, ${p.dir}`}
|
|
597
|
+
aria-pressed=${el.s.sel === `pad:${p.key}`} @click=${() => el.select(`pad:${p.key}`)}>${TYPE_GLYPH[p.type]}</button>
|
|
598
|
+
<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>`;
|
|
599
|
+
}
|
|
600
|
+
function box(el, b, shared) {
|
|
601
|
+
const { item } = b, fp = (i) => `fp:${i.system}/${i.instance}`;
|
|
602
|
+
return html6`<div class="fp" data-instance=${item.instance} data-sel=${el.s.sel === fp(item)} style=${styleMap(px(b.rect))}>
|
|
603
|
+
<button class="ftitle" @click=${() => el.select(fp(item))}>${item.title}${shared ? " ⧉" : ""}</button>
|
|
604
|
+
${b.pads.map((p) => pad(el, p))}</div>`;
|
|
605
|
+
}
|
|
606
|
+
var padName = (el, key) => {
|
|
607
|
+
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);
|
|
608
|
+
return p ? `${p.instance}.${p.label}` : key;
|
|
609
|
+
};
|
|
610
|
+
function cables(el, f) {
|
|
611
|
+
const { pos } = el.geo, focusFrame = `l:${el.s.focus}`;
|
|
612
|
+
return svg`<svg class="cables" width="1" height="1">${el.model.cables.filter((c) => frameId(c.from.at) === f.id).map((c) => {
|
|
613
|
+
const a = pos.get(posKey(f.id, c.from.pad)), b = pos.get(posKey(frameId(c.to.at), c.to.pad));
|
|
614
|
+
if (!a || !b)
|
|
615
|
+
return "";
|
|
616
|
+
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);
|
|
617
|
+
const full = frameId(c.from.at) === focusFrame || frameId(c.to.at) === focusFrame || f.id.startsWith("s:") && frameId(c.to.at).startsWith("s:");
|
|
618
|
+
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);
|
|
619
|
+
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}`)}
|
|
620
|
+
@keydown=${(e) => {
|
|
621
|
+
if (e.key === "Enter" || e.key === " ") {
|
|
622
|
+
e.preventDefault();
|
|
623
|
+
el.select(`cable:${c.id}`);
|
|
624
|
+
}
|
|
625
|
+
}}>
|
|
626
|
+
<path data-cable=${c.id} data-x1=${x1} data-y1=${y1} data-x2=${x2} data-y2=${y2} d=${d}
|
|
627
|
+
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>`;
|
|
628
|
+
})}</svg>`;
|
|
629
|
+
}
|
|
630
|
+
function minimap(el) {
|
|
631
|
+
const { bounds: b, layers, blocks } = el.geo, { panX, panY, zoom, focus } = el.s, { w, h } = el.stageSize();
|
|
632
|
+
const vp = { x: -panX / zoom - w / zoom / 2, y: -panY / zoom - h / zoom / 2, w: w / zoom, h: h / zoom };
|
|
633
|
+
return html6`<svg class="minimap" role="img" aria-label="Minimap" viewBox=${`${b.x - MARGIN} ${b.y - MARGIN} ${b.w + 2 * MARGIN} ${b.h + 2 * MARGIN}`}
|
|
634
|
+
@click=${(e) => el.panFromMinimap(e)}>
|
|
635
|
+
${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}/>`)}
|
|
636
|
+
${blocks.map((l) => svg`<rect class="mm-side" x=${l.rect.x} y=${l.rect.y} width=${l.rect.w} height=${l.rect.h}/>`)}
|
|
637
|
+
<rect class="mm-view" x=${vp.x} y=${vp.y} width=${vp.w} height=${vp.h}/></svg>`;
|
|
638
|
+
}
|
|
639
|
+
function renderStage(el) {
|
|
640
|
+
const { focus, zoom, panX, panY } = el.s, reduced = el.reduced(), at = el.model.layers.findIndex((l) => l.screen === focus);
|
|
641
|
+
const world = { transform: `${reduced ? "" : TILT} translate(${panX}px, ${panY}px) scale(${zoom})` };
|
|
642
|
+
return html6`<div class="stage" tabindex="0" aria-label="Wiring" @pointerdown=${(e) => el.dragStart(e)} @wheel=${(e) => el.wheel(e)}>
|
|
643
|
+
<div class="world ${el.dragging || reduced ? "" : "anim"}" style=${styleMap(world)}>
|
|
644
|
+
${el.geo.layers.map((f) => {
|
|
645
|
+
const d = f.index - at, l = f.layer;
|
|
646
|
+
return html6`<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)` })}>
|
|
647
|
+
<section class="layer" aria-label=${l.title} data-focus=${d === 0} style=${styleMap({ width: `${PW}px`, height: `${PH}px`, opacity: String(fade(d)) })}>
|
|
648
|
+
<h3 class="ltitle">${l.title}</h3>
|
|
649
|
+
${f.boxes.map((b) => box(el, b, "shared" in b.item && b.item.shared))}</section>
|
|
650
|
+
${cables(el, f)}</div>`;
|
|
651
|
+
})}
|
|
652
|
+
${el.geo.blocks.map((f) => html6`<div class="frame side" data-system=${f.block.system} style=${styleMap({ left: `${f.origin.x}px`, top: `${f.origin.y}px` })}>
|
|
653
|
+
<h3 class="ltitle">${f.block.system}</h3>${f.boxes.map((b) => box(el, b, false))}${cables(el, f)}</div>`)}
|
|
654
|
+
</div>
|
|
655
|
+
${minimap(el)}${renderDrawer(el)}</div>`;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
// packages/ui/src/wiring/styles.ts
|
|
659
|
+
import { css as css2 } from "lit";
|
|
660
|
+
import { base as base4, t as t2 } from "@pritzlaff/nano-elements";
|
|
661
|
+
var styles = [base4, css2`
|
|
662
|
+
:host { display: block; height: 100%; min-height: 360px; color: ${t2("fg")} }
|
|
663
|
+
.pills { display: flex; gap: 6px; flex-wrap: wrap; padding: 8px; background: ${t2("bg")} }
|
|
664
|
+
.ic { display: inline-grid; place-items: center; width: 16px; height: 16px; border-radius: 4px; background: ${t2("surface-2")}; font-size: 10px }
|
|
665
|
+
.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 }
|
|
666
|
+
.world { position: absolute; left: 50%; top: 50%; width: 0; height: 0; transform-style: preserve-3d; transform-origin: 0 0 }
|
|
667
|
+
.world.anim { transition: transform .5s ease }
|
|
668
|
+
.frame { position: absolute; transform-style: preserve-3d }
|
|
669
|
+
.layer { position: absolute; left: 0; top: 0; background: ${t2("surface")}; border: 1px solid ${t2("border")}; border-radius: 8px }
|
|
670
|
+
.ltitle { position: absolute; left: 0; top: -22px; margin: 0; font-size: 12px; color: ${t2("muted")}; white-space: nowrap }
|
|
671
|
+
.layer .ltitle { left: 8px; top: 6px }
|
|
672
|
+
.fp { position: absolute; box-sizing: border-box; border: 1px solid ${t2("border")}; border-radius: 6px; background: ${t2("surface-2")} }
|
|
673
|
+
.ftitle { position: absolute; left: 14px; top: 8px; padding: 0; border: 0; background: none; font-weight: 600 }
|
|
674
|
+
.pad { position: absolute; width: 24px; height: 24px; padding: 0; border: 2px solid; font: 600 10px ${t2("font-mono")} }
|
|
675
|
+
.plabel { position: absolute; font-size: 10px; color: ${t2("muted")}; white-space: nowrap }
|
|
676
|
+
.pad[aria-pressed="true"], .fp[data-sel="true"] { border-color: ${t2("accent")} }
|
|
677
|
+
.hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; cursor: pointer }
|
|
678
|
+
g[data-cable-hit]:focus-visible { outline: 2px solid ${t2("focus")} }
|
|
679
|
+
path[data-lit="true"] { filter: drop-shadow(0 0 4px currentColor) }
|
|
680
|
+
.cables { position: absolute; left: 0; top: 0; overflow: visible; pointer-events: none }
|
|
681
|
+
.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 }
|
|
682
|
+
.drawer[hidden] { display: none }
|
|
683
|
+
.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 }
|
|
684
|
+
.kicker { font-size: 10px; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: ${t2("muted")} }
|
|
685
|
+
.chips { display: flex; flex-wrap: wrap; gap: 6px }
|
|
686
|
+
.glyph { display: inline-grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; color: ${t2("on-accent")}; font: 700 9px ${t2("font-mono")} }
|
|
687
|
+
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 }
|
|
688
|
+
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 }
|
|
689
|
+
.actions { margin-top: auto; padding-top: 8px; border-top: 1px solid ${t2("border")} }
|
|
690
|
+
@media (prefers-reduced-motion: reduce) { .world.anim { transition: none } }
|
|
691
|
+
.minimap { position: absolute; right: 12px; bottom: 12px; width: 176px; height: 108px; background: ${t2("bg")}; border: 1px solid ${t2("border")}; border-radius: 6px }
|
|
692
|
+
.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 }`];
|
|
693
|
+
|
|
694
|
+
// packages/ui/src/wiring/wiring.ts
|
|
695
|
+
var clamp = (z) => Math.min(ZOOM_MAX, Math.max(ZOOM_MIN, z));
|
|
696
|
+
|
|
697
|
+
class NanoWiring extends LitElement3 {
|
|
698
|
+
static properties = { target: { attribute: false } };
|
|
699
|
+
static styles = styles;
|
|
700
|
+
s = { focus: null, zoom: 1, panX: 0, panY: 0, sel: null };
|
|
701
|
+
model = { layers: [], side: [], cables: [] };
|
|
702
|
+
geo = layout(this.model);
|
|
703
|
+
dragging = false;
|
|
704
|
+
off;
|
|
705
|
+
watching;
|
|
706
|
+
fitted = false;
|
|
707
|
+
drag = null;
|
|
708
|
+
lit = new Map;
|
|
709
|
+
constructor() {
|
|
710
|
+
super();
|
|
711
|
+
this.addEventListener("keydown", (e) => this.key(e));
|
|
712
|
+
}
|
|
713
|
+
connectedCallback() {
|
|
714
|
+
super.connectedCallback();
|
|
715
|
+
this.watch();
|
|
716
|
+
}
|
|
717
|
+
disconnectedCallback() {
|
|
718
|
+
super.disconnectedCallback();
|
|
719
|
+
this.stop();
|
|
720
|
+
}
|
|
721
|
+
willUpdate(changed) {
|
|
722
|
+
if (changed.has("target"))
|
|
723
|
+
this.watch();
|
|
724
|
+
}
|
|
725
|
+
render() {
|
|
726
|
+
return [renderPills(this), renderStage(this)];
|
|
727
|
+
}
|
|
728
|
+
watch() {
|
|
729
|
+
const t3 = this.target;
|
|
730
|
+
if (!t3 || !this.isConnected || this.watching === t3)
|
|
731
|
+
return;
|
|
732
|
+
this.stop();
|
|
733
|
+
this.watching = t3;
|
|
734
|
+
this.off = t3.app.listen((e) => {
|
|
735
|
+
if (e.type === "applied")
|
|
736
|
+
this.load(t3);
|
|
737
|
+
else if (e.type === "sent")
|
|
738
|
+
this.light(e.kind === "call" ? `${e.runtime}|${e.from}|${e.to}|call|` : `${e.runtime}|${e.from}|${e.to}|${e.port}|`);
|
|
739
|
+
});
|
|
740
|
+
this.load(t3);
|
|
741
|
+
}
|
|
742
|
+
stop() {
|
|
743
|
+
this.off?.();
|
|
744
|
+
this.off = undefined;
|
|
745
|
+
this.watching = undefined;
|
|
746
|
+
this.lit.forEach(clearTimeout);
|
|
747
|
+
this.lit.clear();
|
|
748
|
+
}
|
|
749
|
+
load(t3) {
|
|
750
|
+
this.model = circuitOf(t3.app.deployment(), t3.registry);
|
|
751
|
+
this.geo = layout(this.model);
|
|
752
|
+
if (!this.model.layers.some((l) => l.screen === this.s.focus))
|
|
753
|
+
this.s = { ...this.s, focus: this.model.layers[0]?.screen ?? null };
|
|
754
|
+
if (!this.fitted && this.s.focus !== null) {
|
|
755
|
+
this.fitted = true;
|
|
756
|
+
this.fitPage(this.s.focus);
|
|
757
|
+
}
|
|
758
|
+
this.requestUpdate();
|
|
759
|
+
}
|
|
760
|
+
light(prefix) {
|
|
761
|
+
clearTimeout(this.lit.get(prefix));
|
|
762
|
+
this.lit.set(prefix, setTimeout(() => {
|
|
763
|
+
this.lit.delete(prefix);
|
|
764
|
+
this.requestUpdate();
|
|
765
|
+
}, 600));
|
|
766
|
+
this.requestUpdate();
|
|
767
|
+
}
|
|
768
|
+
isLit(id) {
|
|
769
|
+
return [...this.lit.keys()].some((p) => id.startsWith(p));
|
|
770
|
+
}
|
|
771
|
+
reduced() {
|
|
772
|
+
return globalThis.matchMedia?.("(prefers-reduced-motion: reduce)").matches ?? false;
|
|
773
|
+
}
|
|
774
|
+
stageSize() {
|
|
775
|
+
const st = this.renderRoot.querySelector(".stage");
|
|
776
|
+
return { w: st?.clientWidth || 1000, h: st?.clientHeight || 600 };
|
|
777
|
+
}
|
|
778
|
+
fitRect(r) {
|
|
779
|
+
const { w, h } = this.stageSize(), zoom = clamp(Math.min(w / (r.w + 2 * MARGIN), h / (r.h + 2 * MARGIN)));
|
|
780
|
+
this.s = { ...this.s, zoom, panX: -(r.x + r.w / 2) * zoom, panY: -(r.y + r.h / 2) * zoom };
|
|
781
|
+
this.requestUpdate();
|
|
782
|
+
}
|
|
783
|
+
fitPage(id) {
|
|
784
|
+
const i = this.model.layers.findIndex((l) => l.screen === id);
|
|
785
|
+
if (i >= 0)
|
|
786
|
+
this.fitRect(this.geo.pageRect(i));
|
|
787
|
+
}
|
|
788
|
+
fitAll() {
|
|
789
|
+
this.fitRect(this.geo.bounds);
|
|
790
|
+
}
|
|
791
|
+
go(id) {
|
|
792
|
+
this.s = { ...this.s, focus: id };
|
|
793
|
+
this.fitPage(id);
|
|
794
|
+
}
|
|
795
|
+
move(by) {
|
|
796
|
+
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));
|
|
797
|
+
if (ls[j])
|
|
798
|
+
this.go(ls[j].screen);
|
|
799
|
+
}
|
|
800
|
+
key(e) {
|
|
801
|
+
if (e.key === "ArrowRight" || e.key === "PageDown")
|
|
802
|
+
this.move(1);
|
|
803
|
+
else if (e.key === "ArrowLeft" || e.key === "PageUp")
|
|
804
|
+
this.move(-1);
|
|
805
|
+
else if (e.key === "Escape" && this.s.sel) {
|
|
806
|
+
this.select(null);
|
|
807
|
+
this.refocus();
|
|
808
|
+
} else
|
|
809
|
+
return;
|
|
810
|
+
e.preventDefault();
|
|
811
|
+
}
|
|
812
|
+
refocus() {
|
|
813
|
+
this.renderRoot.querySelector(".stage")?.focus();
|
|
814
|
+
}
|
|
815
|
+
select(sel) {
|
|
816
|
+
this.s = { ...this.s, sel };
|
|
817
|
+
this.requestUpdate();
|
|
818
|
+
}
|
|
819
|
+
follow() {
|
|
820
|
+
const m = this.model, { sel } = this.s;
|
|
821
|
+
if (!sel)
|
|
822
|
+
return;
|
|
823
|
+
const [what, ...rest] = sel.split(":"), id = rest.join(":");
|
|
824
|
+
const cable = what === "cable" ? m.cables.find((c) => c.id === id) : m.cables.find((c) => c.from.pad === id || c.to.pad === id);
|
|
825
|
+
if (!cable)
|
|
826
|
+
return;
|
|
827
|
+
const end = what === "pad" && cable.from.pad === id ? cable.to : what === "pad" ? cable.from : cable.to;
|
|
828
|
+
const p = this.geo.pos.get(posKey(frameId(end.at), end.pad));
|
|
829
|
+
if (!p)
|
|
830
|
+
return;
|
|
831
|
+
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 };
|
|
832
|
+
this.requestUpdate();
|
|
833
|
+
}
|
|
834
|
+
wheel(e) {
|
|
835
|
+
e.preventDefault();
|
|
836
|
+
this.s = { ...this.s, zoom: clamp(this.s.zoom * Math.exp(-e.deltaY * (e.ctrlKey ? 0.01 : 0.002))) };
|
|
837
|
+
this.requestUpdate();
|
|
838
|
+
}
|
|
839
|
+
dragStart(e) {
|
|
840
|
+
if (e.target.closest("button, input, aside, g[data-cable-hit]"))
|
|
841
|
+
return;
|
|
842
|
+
this.drag = { x: e.clientX, y: e.clientY };
|
|
843
|
+
this.dragging = true;
|
|
844
|
+
const move = (m) => {
|
|
845
|
+
if (!this.drag)
|
|
846
|
+
return;
|
|
847
|
+
this.s = { ...this.s, panX: this.s.panX + m.clientX - this.drag.x, panY: this.s.panY + m.clientY - this.drag.y };
|
|
848
|
+
this.drag = { x: m.clientX, y: m.clientY };
|
|
849
|
+
this.requestUpdate();
|
|
850
|
+
};
|
|
851
|
+
const up = () => {
|
|
852
|
+
this.drag = null;
|
|
853
|
+
this.dragging = false;
|
|
854
|
+
window.removeEventListener("pointermove", move);
|
|
855
|
+
window.removeEventListener("pointerup", up);
|
|
856
|
+
window.removeEventListener("pointercancel", up);
|
|
857
|
+
this.requestUpdate();
|
|
858
|
+
};
|
|
859
|
+
window.addEventListener("pointermove", move);
|
|
860
|
+
window.addEventListener("pointerup", up);
|
|
861
|
+
window.addEventListener("pointercancel", up);
|
|
862
|
+
}
|
|
863
|
+
panFromMinimap(e) {
|
|
864
|
+
const el = e.currentTarget, r = el.getBoundingClientRect(), b = this.geo.bounds;
|
|
865
|
+
if (!r.width || !r.height)
|
|
866
|
+
return;
|
|
867
|
+
const k = Math.max((b.w + 2 * MARGIN) / r.width, (b.h + 2 * MARGIN) / r.height);
|
|
868
|
+
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;
|
|
869
|
+
this.s = { ...this.s, panX: -wx * this.s.zoom, panY: -wy * this.s.zoom };
|
|
870
|
+
this.requestUpdate();
|
|
871
|
+
}
|
|
872
|
+
}
|
|
873
|
+
|
|
874
|
+
// packages/ui/src/views/pod-view.ts
|
|
875
|
+
import { css as css3, html as html7 } from "lit";
|
|
876
|
+
import { base as base5, t as t3 } from "@pritzlaff/nano-elements";
|
|
877
|
+
class NanoPodView extends ViewElement {
|
|
878
|
+
static styles = [base5, css3`
|
|
879
|
+
dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 0 0 12px }
|
|
880
|
+
dt { color: ${t3("muted")} } dd { margin: 0; font-family: ${t3("font-mono")} }
|
|
881
|
+
table { width: 100%; border-collapse: collapse } td { padding: 3px 6px; border-top: 1px solid ${t3("border")} }
|
|
882
|
+
.iface { margin-top: 8px; font-weight: 600 }
|
|
883
|
+
`];
|
|
884
|
+
ports = new Map;
|
|
885
|
+
stats = new Map;
|
|
886
|
+
started() {
|
|
887
|
+
this.ports.clear();
|
|
888
|
+
this.stats.clear();
|
|
889
|
+
this.requestUpdate();
|
|
890
|
+
}
|
|
891
|
+
hear(e, tg) {
|
|
892
|
+
if (e.type === "sent" && e.to === tg.pod) {
|
|
893
|
+
this.ports.set(e.id, e.port);
|
|
894
|
+
const s = this.stats.get(e.port) ?? { calls: 0 };
|
|
895
|
+
this.stats.set(e.port, { ...s, calls: s.calls + 1 });
|
|
896
|
+
} else if ((e.type === "delivered" || e.type === "denied") && this.ports.has(e.id)) {
|
|
897
|
+
const p = this.ports.get(e.id);
|
|
898
|
+
this.ports.delete(e.id);
|
|
899
|
+
if (e.type === "delivered")
|
|
900
|
+
this.stats.set(p, { ...this.stats.get(p), last: e.result });
|
|
901
|
+
} else
|
|
902
|
+
return;
|
|
903
|
+
this.requestUpdate();
|
|
904
|
+
}
|
|
905
|
+
face(tg) {
|
|
906
|
+
const d = tg.app.deployment();
|
|
907
|
+
const pod = d.pods[tg.pod];
|
|
908
|
+
const runtimes = Object.entries(d.runtimes).filter(([, r]) => r.pods.includes(tg.pod)).map(([id]) => id);
|
|
909
|
+
const provides = tg.registry.implementation(pod?.implementation ?? "")?.provides ?? [];
|
|
910
|
+
return html7`
|
|
911
|
+
<dl>
|
|
912
|
+
<dt>pod</dt><dd>${tg.pod}</dd>
|
|
913
|
+
<dt>implementation</dt><dd>${pod?.implementation ?? "—"}</dd>
|
|
914
|
+
<dt>config</dt><dd>${JSON.stringify(pod?.config ?? null)}</dd>
|
|
915
|
+
<dt>runtimes</dt><dd>${runtimes.join(", ") || "—"}</dd>
|
|
916
|
+
</dl>
|
|
917
|
+
${provides.map((i) => html7`
|
|
918
|
+
<div class="iface">${i.coord}</div>
|
|
919
|
+
<table>${Object.values(i.ops).map((o) => {
|
|
920
|
+
const p = `${i.coord}/${o.name}`, s = this.stats.get(p);
|
|
921
|
+
return html7`<tr data-port=${p}><td>${o.name}</td><td class="badge">${o.kind}</td>
|
|
922
|
+
<td>${s?.calls ?? 0} calls</td><td>${shown(s?.last)}</td></tr>`;
|
|
923
|
+
})}</table>`)}`;
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
|
|
927
|
+
// packages/ui/src/views/define.ts
|
|
928
|
+
var views = { "nano.ui/input": "nano-input", "nano.ui/debounce": "nano-debounce", "nano.ui/map": "nano-map", "nano.ui/log": "nano-log" };
|
|
929
|
+
var tags = { "nano-explorer": NanoExplorer, "nano-wiring": NanoWiring, "nano-pod-view": NanoPodView, "nano-input": NanoInput, "nano-debounce": NanoDebounce, "nano-map": NanoMap, "nano-log": NanoLog };
|
|
930
|
+
function defineViews() {
|
|
931
|
+
for (const [tag, cls] of Object.entries(tags))
|
|
932
|
+
if (!customElements.get(tag))
|
|
933
|
+
customElements.define(tag, cls);
|
|
934
|
+
}
|
|
935
|
+
// packages/ui/src/index.ts
|
|
936
|
+
var src_default = uiProvider;
|
|
937
|
+
export {
|
|
938
|
+
views,
|
|
939
|
+
viewFor,
|
|
940
|
+
uiProvider,
|
|
941
|
+
map,
|
|
942
|
+
log,
|
|
943
|
+
input,
|
|
944
|
+
defineViews,
|
|
945
|
+
src_default as default,
|
|
946
|
+
debounce,
|
|
947
|
+
circuitOf,
|
|
948
|
+
Nothing,
|
|
949
|
+
MapIface,
|
|
950
|
+
Log,
|
|
951
|
+
Input,
|
|
952
|
+
HostUI,
|
|
953
|
+
Debounce,
|
|
954
|
+
Any
|
|
955
|
+
};
|
|
956
|
+
|
|
957
|
+
//# debugId=D37CB6EA5B8DBD2664756E2164756E21
|
|
958
|
+
//# sourceMappingURL=index.js.map
|