@pritzlaff/nano-app 0.0.0-stage → 0.5.1
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/AGENTS.md +66 -0
- package/LICENSE +21 -0
- package/README.md +6 -2
- package/app/app.css +160 -0
- package/app/bundle/nano-ui.js +2553 -0
- package/app/examples/auth/example.auth.js +6 -0
- package/app/examples/auth/nano.json +46 -0
- package/app/examples/chat/example.chat.js +6 -0
- package/app/examples/chat/example.messaging.js +3 -0
- package/app/examples/chat/nano.json +115 -0
- package/app/examples/drift/example.drift.js +3 -0
- package/app/examples/drift/nano.json +31 -0
- package/app/examples/kv/example.kv.js +3 -0
- package/app/examples/nano.json +353 -0
- package/app/examples/originkey/_nano/bundle/nano-ui.js +212 -0
- package/app/examples/originkey/_nano/sandbox/boot.js +1 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-2gg2vg5g.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-5h5dssvv.js +3 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-72b5e6vd.js +17 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-87v2yejk.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-hm29e227.js +7 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-jtgk4ch8.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-mqaje7vc.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-mxgap7rs.js +2 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-qy0mwf7y.js +1 -0
- package/app/examples/originkey/_nano/shared/chunks/nano-core-wanb7xw1.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-class-map.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-decorators.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-directive.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-if-defined.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-ref.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-repeat.js +1 -0
- package/app/examples/originkey/_nano/shared/lit-style-map.js +1 -0
- package/app/examples/originkey/_nano/shared/lit.js +1 -0
- package/app/examples/originkey/_nano/shared/nano-core.js +1 -0
- package/app/examples/originkey/_nano/shared/nano-elements.js +280 -0
- package/app/examples/originkey/_nano/shared/typebox-value.js +1 -0
- package/app/examples/originkey/_nano/shared/typebox.js +1 -0
- package/app/examples/originkey/example.originkey.js +6 -0
- package/app/examples/originkey/frame.html +1 -0
- package/app/examples/originkey/nano.json +50 -0
- package/app/examples/raft/example.raft.js +30 -0
- package/app/examples/raft/nano.json +74 -0
- package/app/examples/slice/nano.json +63 -0
- package/app/examples/slice/shout.js +14 -0
- package/app/examples/template/acme.template.js +11 -0
- package/app/examples/template/index.js +194 -0
- package/app/examples/template/nano.json +32 -0
- package/app/examples/todo/example.todo.js +8 -0
- package/app/examples/todo/nano.json +77 -0
- package/app/examples/typing/nano.json +33 -0
- package/app/favicon.svg +1 -0
- package/app/index.html +152 -0
- package/app/main.js +15906 -0
- package/app/react/index.html +50 -0
- package/app/react/main.js +9 -0
- package/app/sandbox/boot.js +980 -0
- package/app/shared/chunks/nano-core-296y9rgd.js +4321 -0
- package/app/shared/chunks/nano-core-2zz7d74m.js +16 -0
- package/app/shared/chunks/nano-core-35ryhkm1.js +33 -0
- package/app/shared/chunks/nano-core-5a3r312d.js +866 -0
- package/app/shared/chunks/nano-core-89mtxedm.js +186 -0
- package/app/shared/chunks/nano-core-bf13r20v.js +77 -0
- package/app/shared/chunks/nano-core-g3414rnc.js +248 -0
- package/app/shared/chunks/nano-core-hyg0qdwg.js +547 -0
- package/app/shared/chunks/nano-core-sxgrxy03.js +53 -0
- package/app/shared/chunks/nano-core-wg5c961d.js +4564 -0
- package/app/shared/lit-class-map.js +60 -0
- package/app/shared/lit-decorators.js +228 -0
- package/app/shared/lit-directive.js +11 -0
- package/app/shared/lit-if-defined.js +10 -0
- package/app/shared/lit-ref.js +12 -0
- package/app/shared/lit-repeat.js +141 -0
- package/app/shared/lit-style-map.js +67 -0
- package/app/shared/lit.js +47 -0
- package/app/shared/nano-core.js +2348 -0
- package/app/shared/nano-elements.js +1178 -0
- package/app/shared/typebox-value.js +78 -0
- package/app/shared/typebox.js +580 -0
- package/app/shared/versions.json +6 -0
- package/bin/nano-app.ts +34 -0
- package/package.json +22 -4
- package/src/events.ts +11 -0
- package/src/serve.ts +68 -0
- package/src/watch.ts +27 -0
|
@@ -0,0 +1,980 @@
|
|
|
1
|
+
// src/sandbox/boot.ts
|
|
2
|
+
import { Registry } from "@pritzlaff/nano-core";
|
|
3
|
+
import { defineViews, viewFor } from "@pritzlaff/nano-ui";
|
|
4
|
+
|
|
5
|
+
// src/sandbox/protocol.ts
|
|
6
|
+
import { isNanoResult } from "@pritzlaff/nano-core";
|
|
7
|
+
|
|
8
|
+
// src/lib/ledger-themes.ts
|
|
9
|
+
var SANS = "'IBM Plex Sans', system-ui, sans-serif";
|
|
10
|
+
var MONO = "'IBM Plex Mono', ui-monospace, monospace";
|
|
11
|
+
var BRICOLAGE = "'Bricolage Grotesque', system-ui, sans-serif";
|
|
12
|
+
var grid = (line) => `linear-gradient(${line} 1px, transparent 1px), linear-gradient(90deg, ${line} 1px, transparent 1px)`;
|
|
13
|
+
var series = (s) => Object.fromEntries(s.split(" ").map((c, i) => [`s${i + 1}`, c]));
|
|
14
|
+
var LEDGER_THEMES = {
|
|
15
|
+
paper: {
|
|
16
|
+
label: "Graph paper",
|
|
17
|
+
desc: "Ink on graph paper, with an orange mark.",
|
|
18
|
+
fonts: ["Bricolage Grotesque", "IBM Plex Sans", "IBM Plex Mono"],
|
|
19
|
+
background: grid("#DFE3E1"),
|
|
20
|
+
schemes: { light: {
|
|
21
|
+
bg: "#F2F4F3",
|
|
22
|
+
surface: "#FFFFFF",
|
|
23
|
+
"surface-2": "#F7F8F7",
|
|
24
|
+
fg: "#15181C",
|
|
25
|
+
muted: "#4D555C",
|
|
26
|
+
line: "#D9DDDB",
|
|
27
|
+
accent: "#1F45B0",
|
|
28
|
+
"on-accent": "#FFFFFF",
|
|
29
|
+
"accent-soft": "#F1F5FE",
|
|
30
|
+
"appbar-bg": "#15181C",
|
|
31
|
+
"appbar-fg": "#F2F4F3",
|
|
32
|
+
"drawer-bg": "#FFFFFF",
|
|
33
|
+
font: SANS,
|
|
34
|
+
display: BRICOLAGE,
|
|
35
|
+
mono: MONO,
|
|
36
|
+
radius: "14px",
|
|
37
|
+
"card-border": "1px solid #D9DDDB",
|
|
38
|
+
"card-shadow": "none",
|
|
39
|
+
focus: "#2E5BDA"
|
|
40
|
+
} },
|
|
41
|
+
nano: {
|
|
42
|
+
"fg-2": "#3A4148",
|
|
43
|
+
"border-strong": "#8A9197",
|
|
44
|
+
"radius-s": "8px",
|
|
45
|
+
good: "#0B6B5F",
|
|
46
|
+
"good-bg": "#DDF1EC",
|
|
47
|
+
bad: "#A3283C",
|
|
48
|
+
"bad-bg": "#F8E1E3",
|
|
49
|
+
warn: "#6E5100",
|
|
50
|
+
"warn-bg": "#F6ECD2",
|
|
51
|
+
...series("#2E5BDA #E0662B #0E8576 #8A4FD0 #A97C00 #C2416B #1E8FB8 #4D555C")
|
|
52
|
+
}
|
|
53
|
+
},
|
|
54
|
+
night: {
|
|
55
|
+
label: "Night shift",
|
|
56
|
+
desc: "The ledger after dark.",
|
|
57
|
+
fonts: ["Bricolage Grotesque", "IBM Plex Sans", "IBM Plex Mono"],
|
|
58
|
+
background: grid("#2C3137"),
|
|
59
|
+
schemes: { dark: {
|
|
60
|
+
bg: "#111316",
|
|
61
|
+
surface: "#1A1D21",
|
|
62
|
+
"surface-2": "#20242A",
|
|
63
|
+
fg: "#ECEFED",
|
|
64
|
+
muted: "#A9B0B6",
|
|
65
|
+
line: "#2E333A",
|
|
66
|
+
accent: "#8FB0FF",
|
|
67
|
+
"on-accent": "#111316",
|
|
68
|
+
"accent-soft": "#1E2635",
|
|
69
|
+
"appbar-bg": "#0B0D0F",
|
|
70
|
+
"appbar-fg": "#ECEFED",
|
|
71
|
+
"drawer-bg": "#1A1D21",
|
|
72
|
+
font: SANS,
|
|
73
|
+
display: BRICOLAGE,
|
|
74
|
+
mono: MONO,
|
|
75
|
+
radius: "14px",
|
|
76
|
+
"card-border": "1px solid #2E333A",
|
|
77
|
+
"card-shadow": "none",
|
|
78
|
+
focus: "#8FB0FF"
|
|
79
|
+
} },
|
|
80
|
+
nano: {
|
|
81
|
+
"fg-2": "#C9CED2",
|
|
82
|
+
"border-strong": "#6B737B",
|
|
83
|
+
"radius-s": "8px",
|
|
84
|
+
good: "#5FD0B8",
|
|
85
|
+
"good-bg": "#12342E",
|
|
86
|
+
bad: "#FF8A9A",
|
|
87
|
+
"bad-bg": "#3A1D22",
|
|
88
|
+
warn: "#F1D488",
|
|
89
|
+
"warn-bg": "#3A3016",
|
|
90
|
+
...series("#7FA2FF #FF9A5C #3FC9AE #B58CF0 #E0B43C #F07BA0 #5CC4EC #AEB6BD")
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
blueprint: {
|
|
94
|
+
label: "Blueprint",
|
|
95
|
+
desc: "White lines on blueprint blue, in mono.",
|
|
96
|
+
fonts: ["IBM Plex Sans", "IBM Plex Mono"],
|
|
97
|
+
background: grid("#1D4072"),
|
|
98
|
+
schemes: { dark: {
|
|
99
|
+
bg: "#0F2747",
|
|
100
|
+
surface: "#133059",
|
|
101
|
+
"surface-2": "#17386A",
|
|
102
|
+
fg: "#F1F6FF",
|
|
103
|
+
muted: "#B4C8E8",
|
|
104
|
+
line: "#2A4F84",
|
|
105
|
+
accent: "#9CC8FF",
|
|
106
|
+
"on-accent": "#0F2747",
|
|
107
|
+
"accent-soft": "#1C4479",
|
|
108
|
+
"appbar-bg": "#0A1C35",
|
|
109
|
+
"appbar-fg": "#F1F6FF",
|
|
110
|
+
"drawer-bg": "#133059",
|
|
111
|
+
font: SANS,
|
|
112
|
+
display: MONO,
|
|
113
|
+
mono: MONO,
|
|
114
|
+
radius: "14px",
|
|
115
|
+
"card-border": "1px solid #2A4F84",
|
|
116
|
+
"card-shadow": "none",
|
|
117
|
+
focus: "#FFB347"
|
|
118
|
+
} },
|
|
119
|
+
nano: {
|
|
120
|
+
"fg-2": "#CFDDF5",
|
|
121
|
+
"border-strong": "#7FA3D6",
|
|
122
|
+
"radius-s": "8px",
|
|
123
|
+
good: "#7EE0C3",
|
|
124
|
+
"good-bg": "#12403F",
|
|
125
|
+
bad: "#FF9DA8",
|
|
126
|
+
"bad-bg": "#4A1F33",
|
|
127
|
+
warn: "#FFE29A",
|
|
128
|
+
"warn-bg": "#4A3D17",
|
|
129
|
+
...series("#9CC8FF #FFB347 #7EE0C3 #D3A6FF #FFE07A #FF9DB8 #6FE3FF #C9D6EA")
|
|
130
|
+
}
|
|
131
|
+
},
|
|
132
|
+
warm: {
|
|
133
|
+
label: "Warm ledger",
|
|
134
|
+
desc: "Oxblood ink on cream, with a serif.",
|
|
135
|
+
fonts: ["Fraunces", "IBM Plex Sans", "IBM Plex Mono"],
|
|
136
|
+
background: grid("#E2D8C5"),
|
|
137
|
+
schemes: { light: {
|
|
138
|
+
bg: "#F5F0E6",
|
|
139
|
+
surface: "#FFFDF8",
|
|
140
|
+
"surface-2": "#F9F4EA",
|
|
141
|
+
fg: "#231C14",
|
|
142
|
+
muted: "#5C5044",
|
|
143
|
+
line: "#DDD2BE",
|
|
144
|
+
accent: "#8A3B1F",
|
|
145
|
+
"on-accent": "#FFF8EE",
|
|
146
|
+
"accent-soft": "#F7EBDD",
|
|
147
|
+
"appbar-bg": "#2B211A",
|
|
148
|
+
"appbar-fg": "#F5F0E6",
|
|
149
|
+
"drawer-bg": "#FFFDF8",
|
|
150
|
+
font: SANS,
|
|
151
|
+
display: "'Fraunces', Georgia, 'Times New Roman', serif",
|
|
152
|
+
mono: MONO,
|
|
153
|
+
radius: "14px",
|
|
154
|
+
"card-border": "1px solid #DDD2BE",
|
|
155
|
+
"card-shadow": "none",
|
|
156
|
+
focus: "#7A2E1C"
|
|
157
|
+
} },
|
|
158
|
+
nano: {
|
|
159
|
+
"fg-2": "#4A3F33",
|
|
160
|
+
"border-strong": "#8F806A",
|
|
161
|
+
"radius-s": "8px",
|
|
162
|
+
good: "#2F6B3A",
|
|
163
|
+
"good-bg": "#E0EBD9",
|
|
164
|
+
bad: "#9E2A2A",
|
|
165
|
+
"bad-bg": "#F3DCD6",
|
|
166
|
+
warn: "#6A4B0B",
|
|
167
|
+
"warn-bg": "#F2E3C2",
|
|
168
|
+
...series("#2F5A9E #C8642B #2F6B3A #7A4A9E #A07800 #9E2A4A #2A7F95 #6E6152")
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
};
|
|
172
|
+
|
|
173
|
+
// src/lib/themes.ts
|
|
174
|
+
var TOKEN_NAMES = [
|
|
175
|
+
"bg",
|
|
176
|
+
"surface",
|
|
177
|
+
"surface-2",
|
|
178
|
+
"fg",
|
|
179
|
+
"muted",
|
|
180
|
+
"line",
|
|
181
|
+
"accent",
|
|
182
|
+
"on-accent",
|
|
183
|
+
"accent-soft",
|
|
184
|
+
"appbar-bg",
|
|
185
|
+
"appbar-fg",
|
|
186
|
+
"drawer-bg",
|
|
187
|
+
"font",
|
|
188
|
+
"display",
|
|
189
|
+
"mono",
|
|
190
|
+
"radius",
|
|
191
|
+
"card-border",
|
|
192
|
+
"card-shadow",
|
|
193
|
+
"focus"
|
|
194
|
+
];
|
|
195
|
+
var SANS2 = "'IBM Plex Sans', system-ui, sans-serif";
|
|
196
|
+
var MONO2 = "'IBM Plex Mono', ui-monospace, monospace";
|
|
197
|
+
var GEIST = "Geist, Inter, system-ui, sans-serif";
|
|
198
|
+
var GEIST_MONO = "'Geist Mono', ui-monospace, monospace";
|
|
199
|
+
var THEMES = {
|
|
200
|
+
enterprise: {
|
|
201
|
+
label: "Enterprise",
|
|
202
|
+
desc: "Navy app bar, white panels, quiet borders.",
|
|
203
|
+
fonts: ["IBM Plex Sans", "IBM Plex Mono"],
|
|
204
|
+
schemes: {
|
|
205
|
+
light: {
|
|
206
|
+
bg: "#F2F4F7",
|
|
207
|
+
surface: "#FFFFFF",
|
|
208
|
+
"surface-2": "#E9EDF2",
|
|
209
|
+
fg: "#14212F",
|
|
210
|
+
muted: "#566476",
|
|
211
|
+
line: "#D5DBE3",
|
|
212
|
+
accent: "#1F5AA6",
|
|
213
|
+
"on-accent": "#FFFFFF",
|
|
214
|
+
"accent-soft": "#E3ECF8",
|
|
215
|
+
"appbar-bg": "#0F2A4A",
|
|
216
|
+
"appbar-fg": "#FFFFFF",
|
|
217
|
+
"drawer-bg": "#FFFFFF",
|
|
218
|
+
font: SANS2,
|
|
219
|
+
display: SANS2,
|
|
220
|
+
mono: MONO2,
|
|
221
|
+
radius: "8px",
|
|
222
|
+
"card-border": "1px solid #D5DBE3",
|
|
223
|
+
"card-shadow": "0 1px 2px rgba(20,33,47,.06)",
|
|
224
|
+
focus: "#1F5AA6"
|
|
225
|
+
},
|
|
226
|
+
dark: {
|
|
227
|
+
bg: "#0E141C",
|
|
228
|
+
surface: "#151D28",
|
|
229
|
+
"surface-2": "#1C2633",
|
|
230
|
+
fg: "#E3E9F1",
|
|
231
|
+
muted: "#93A1B3",
|
|
232
|
+
line: "#2A3644",
|
|
233
|
+
accent: "#6EA8F2",
|
|
234
|
+
"on-accent": "#0B1622",
|
|
235
|
+
"accent-soft": "#1B2D45",
|
|
236
|
+
"appbar-bg": "#0A1A2E",
|
|
237
|
+
"appbar-fg": "#E3E9F1",
|
|
238
|
+
"drawer-bg": "#121A24",
|
|
239
|
+
font: SANS2,
|
|
240
|
+
display: SANS2,
|
|
241
|
+
mono: MONO2,
|
|
242
|
+
radius: "8px",
|
|
243
|
+
"card-border": "1px solid #2A3644",
|
|
244
|
+
"card-shadow": "none",
|
|
245
|
+
focus: "#6EA8F2"
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
},
|
|
249
|
+
terminal: {
|
|
250
|
+
label: "Terminal",
|
|
251
|
+
desc: "Monospace panes, green on black.",
|
|
252
|
+
fonts: ["JetBrains Mono"],
|
|
253
|
+
schemes: {
|
|
254
|
+
dark: {
|
|
255
|
+
bg: "#0B0E0C",
|
|
256
|
+
surface: "#101512",
|
|
257
|
+
"surface-2": "#151C18",
|
|
258
|
+
fg: "#CFE3D2",
|
|
259
|
+
muted: "#7F9A86",
|
|
260
|
+
line: "#2A3A30",
|
|
261
|
+
accent: "#7EE787",
|
|
262
|
+
"on-accent": "#0B0E0C",
|
|
263
|
+
"accent-soft": "#16301D",
|
|
264
|
+
"appbar-bg": "#0B0E0C",
|
|
265
|
+
"appbar-fg": "#7EE787",
|
|
266
|
+
"drawer-bg": "#0D110F",
|
|
267
|
+
font: "'JetBrains Mono', ui-monospace, monospace",
|
|
268
|
+
display: "'JetBrains Mono', ui-monospace, monospace",
|
|
269
|
+
mono: "'JetBrains Mono', ui-monospace, monospace",
|
|
270
|
+
radius: "0px",
|
|
271
|
+
"card-border": "1px solid #2A3A30",
|
|
272
|
+
"card-shadow": "none",
|
|
273
|
+
focus: "#7EE787"
|
|
274
|
+
}
|
|
275
|
+
}
|
|
276
|
+
},
|
|
277
|
+
sketch: {
|
|
278
|
+
label: "Sketch",
|
|
279
|
+
desc: "Hand-drawn outlines on dotted paper.",
|
|
280
|
+
fonts: ["Architects Daughter", "Caveat"],
|
|
281
|
+
schemes: {
|
|
282
|
+
light: {
|
|
283
|
+
bg: "#FBFAF5",
|
|
284
|
+
surface: "#FFFFFF",
|
|
285
|
+
"surface-2": "#FFF3BF",
|
|
286
|
+
fg: "#1E1E1E",
|
|
287
|
+
muted: "#55524A",
|
|
288
|
+
line: "#1E1E1E",
|
|
289
|
+
accent: "#1971C2",
|
|
290
|
+
"on-accent": "#FFFFFF",
|
|
291
|
+
"accent-soft": "#D0EBFF",
|
|
292
|
+
"appbar-bg": "#FFF3BF",
|
|
293
|
+
"appbar-fg": "#1E1E1E",
|
|
294
|
+
"drawer-bg": "#FBFAF5",
|
|
295
|
+
font: "'Architects Daughter', 'Comic Sans MS', cursive",
|
|
296
|
+
display: "'Caveat', 'Architects Daughter', cursive",
|
|
297
|
+
mono: "'Architects Daughter', monospace",
|
|
298
|
+
radius: "255px 15px 225px 15px / 15px 225px 15px 255px",
|
|
299
|
+
"card-border": "2px solid #1E1E1E",
|
|
300
|
+
"card-shadow": "3px 3px 0 #1E1E1E",
|
|
301
|
+
focus: "#1971C2"
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
},
|
|
305
|
+
retro: {
|
|
306
|
+
label: "Retro",
|
|
307
|
+
desc: "Bevelled grey windows on a teal desktop.",
|
|
308
|
+
fonts: ["Pixelify Sans"],
|
|
309
|
+
nano: { bg: "#FFFFFF" },
|
|
310
|
+
schemes: {
|
|
311
|
+
light: {
|
|
312
|
+
bg: "#2A7F7F",
|
|
313
|
+
surface: "#C3C3C3",
|
|
314
|
+
"surface-2": "#FFFFFF",
|
|
315
|
+
fg: "#000000",
|
|
316
|
+
muted: "#3A3A3A",
|
|
317
|
+
line: "#808080",
|
|
318
|
+
accent: "#00007B",
|
|
319
|
+
"on-accent": "#FFFFFF",
|
|
320
|
+
"accent-soft": "#C7C7F0",
|
|
321
|
+
"appbar-bg": "#00007B",
|
|
322
|
+
"appbar-fg": "#FFFFFF",
|
|
323
|
+
"drawer-bg": "#C3C3C3",
|
|
324
|
+
font: "Verdana, Tahoma, sans-serif",
|
|
325
|
+
display: "'Pixelify Sans', Verdana, sans-serif",
|
|
326
|
+
mono: "'Courier New', monospace",
|
|
327
|
+
radius: "0px",
|
|
328
|
+
"card-border": "2px outset #E8E8E8",
|
|
329
|
+
"card-shadow": "1px 1px 0 #000",
|
|
330
|
+
focus: "#00007B"
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
},
|
|
334
|
+
shadcn: {
|
|
335
|
+
label: "shadcn",
|
|
336
|
+
desc: "Neutral greys, hairline borders, near-black accent.",
|
|
337
|
+
fonts: ["Geist", "Geist Mono"],
|
|
338
|
+
nano: { "radius-s": "8px" },
|
|
339
|
+
schemes: {
|
|
340
|
+
light: {
|
|
341
|
+
bg: "#FFFFFF",
|
|
342
|
+
surface: "#FFFFFF",
|
|
343
|
+
"surface-2": "#F5F5F5",
|
|
344
|
+
fg: "#0A0A0A",
|
|
345
|
+
muted: "#737373",
|
|
346
|
+
line: "#E5E5E5",
|
|
347
|
+
accent: "#171717",
|
|
348
|
+
"on-accent": "#FAFAFA",
|
|
349
|
+
"accent-soft": "#F5F5F5",
|
|
350
|
+
"appbar-bg": "#FFFFFF",
|
|
351
|
+
"appbar-fg": "#0A0A0A",
|
|
352
|
+
"drawer-bg": "#FAFAFA",
|
|
353
|
+
font: GEIST,
|
|
354
|
+
display: GEIST,
|
|
355
|
+
mono: GEIST_MONO,
|
|
356
|
+
radius: "10px",
|
|
357
|
+
"card-border": "1px solid #E5E5E5",
|
|
358
|
+
"card-shadow": "0 1px 2px rgba(0,0,0,.05)",
|
|
359
|
+
focus: "#A3A3A3"
|
|
360
|
+
},
|
|
361
|
+
dark: {
|
|
362
|
+
bg: "#0A0A0A",
|
|
363
|
+
surface: "#171717",
|
|
364
|
+
"surface-2": "#262626",
|
|
365
|
+
fg: "#FAFAFA",
|
|
366
|
+
muted: "#A1A1A1",
|
|
367
|
+
line: "#262626",
|
|
368
|
+
accent: "#E5E5E5",
|
|
369
|
+
"on-accent": "#171717",
|
|
370
|
+
"accent-soft": "#262626",
|
|
371
|
+
"appbar-bg": "#0A0A0A",
|
|
372
|
+
"appbar-fg": "#FAFAFA",
|
|
373
|
+
"drawer-bg": "#0A0A0A",
|
|
374
|
+
font: GEIST,
|
|
375
|
+
display: GEIST,
|
|
376
|
+
mono: GEIST_MONO,
|
|
377
|
+
radius: "10px",
|
|
378
|
+
"card-border": "1px solid #262626",
|
|
379
|
+
"card-shadow": "none",
|
|
380
|
+
focus: "#737373"
|
|
381
|
+
}
|
|
382
|
+
}
|
|
383
|
+
},
|
|
384
|
+
...LEDGER_THEMES
|
|
385
|
+
};
|
|
386
|
+
var THEME_IDS = Object.keys(THEMES);
|
|
387
|
+
var isThemeId = (v) => THEME_IDS.includes(v);
|
|
388
|
+
var isMode = (v) => v === "system" || v === "light" || v === "dark";
|
|
389
|
+
var schemesOf = (id) => ["light", "dark"].filter((s) => THEMES[id].schemes[s] !== undefined);
|
|
390
|
+
var resolveScheme = (id, mode, systemDark) => {
|
|
391
|
+
const available = schemesOf(id);
|
|
392
|
+
const want = mode === "system" ? systemDark ? "dark" : "light" : mode;
|
|
393
|
+
if (available.includes(want))
|
|
394
|
+
return want;
|
|
395
|
+
const only = available[0];
|
|
396
|
+
if (!only)
|
|
397
|
+
throw new Error(`bug: theme ${id} defines no schemes`);
|
|
398
|
+
return only;
|
|
399
|
+
};
|
|
400
|
+
var themeVars = (id, scheme) => {
|
|
401
|
+
const tokens = THEMES[id].schemes[scheme];
|
|
402
|
+
if (!tokens)
|
|
403
|
+
throw new Error(`theme ${id} has no ${scheme} scheme`);
|
|
404
|
+
return Object.fromEntries(TOKEN_NAMES.map((k) => [`--${k}`, tokens[k]]));
|
|
405
|
+
};
|
|
406
|
+
|
|
407
|
+
// src/sandbox/protocol.ts
|
|
408
|
+
var json = (s) => ({ type: s.label ?? "", schema: JSON.parse(JSON.stringify(s.schema)) });
|
|
409
|
+
var describeProvider = (p, views) => ({
|
|
410
|
+
coord: p.coord,
|
|
411
|
+
meta: { ...p.meta },
|
|
412
|
+
views: { ...views },
|
|
413
|
+
implementations: [...p.implementations.values()].map((i) => ({
|
|
414
|
+
coord: i.coord,
|
|
415
|
+
...i.description !== undefined && { description: i.description },
|
|
416
|
+
provides: i.provides.map((f) => ({ coord: f.coord, ops: Object.values(f.ops).map((o) => ({
|
|
417
|
+
name: o.name,
|
|
418
|
+
kind: o.kind,
|
|
419
|
+
...o.input && { input: json(o.input) },
|
|
420
|
+
...o.output && { output: json(o.output) },
|
|
421
|
+
...o.description !== undefined && { description: o.description }
|
|
422
|
+
})) })),
|
|
423
|
+
dependencies: JSON.parse(JSON.stringify(i.dependencies)),
|
|
424
|
+
...i.config && { config: json(i.config) }
|
|
425
|
+
}))
|
|
426
|
+
});
|
|
427
|
+
var MAX = 1024 * 1024;
|
|
428
|
+
var obj = (x) => !!x && typeof x === "object" && !Array.isArray(x);
|
|
429
|
+
var str = (v) => typeof v === "string";
|
|
430
|
+
var num = (v) => typeof v === "number";
|
|
431
|
+
var any = () => true;
|
|
432
|
+
var optStr = (v) => v === undefined || str(v);
|
|
433
|
+
var optNum = (v) => v === undefined || num(v);
|
|
434
|
+
var strs = (v) => Array.isArray(v) && v.every(str);
|
|
435
|
+
var arrOf = (c) => (v) => Array.isArray(v) && v.every((x) => c(x) === undefined);
|
|
436
|
+
var edge = (v) => obj(v) && ["pod", "runtime", "implementation", "provider"].every((k) => str(v[k])) && strs(v.provides) && strs(v.tags) ? undefined : "bad edge";
|
|
437
|
+
var RECORD_KEYS = new Set(["^.*$", "^-?(?:0|[1-9][0-9]*)(?:\\.[0-9]+)?$", "^-?(?:0|[1-9][0-9]*)$"]);
|
|
438
|
+
var safeKeys = (v) => !!v && typeof v === "object" && Object.keys(v).every((k) => RECORD_KEYS.has(k));
|
|
439
|
+
var hasRegex = (x) => !!x && typeof x === "object" && Object.entries(x).some(([k, v]) => k === "pattern" || k === "format" || k === "patternProperties" && !safeKeys(v) || hasRegex(v));
|
|
440
|
+
var schema = (s, what) => s === undefined ? undefined : !obj(s) || !str(s.type) || !obj(s.schema) ? `${what} is not a schema` : hasRegex(s.schema) ? `${what} uses pattern or format` : undefined;
|
|
441
|
+
var selector = (d) => obj(d) && ["implements", "implementation", "provider", "runtime"].every((k) => optStr(d[k])) && (d.tags === undefined || strs(d.tags));
|
|
442
|
+
function implError(i) {
|
|
443
|
+
if (!obj(i) || !str(i.coord) || !optStr(i.description))
|
|
444
|
+
return "an implementation needs a coord";
|
|
445
|
+
if (!Array.isArray(i.provides) || !obj(i.dependencies) || !Object.values(i.dependencies).every(selector))
|
|
446
|
+
return `${i.coord}: bad provides or dependencies`;
|
|
447
|
+
for (const f of i.provides) {
|
|
448
|
+
if (!obj(f) || !str(f.coord) || !Array.isArray(f.ops))
|
|
449
|
+
return `${i.coord}: an interface needs a coord and ops`;
|
|
450
|
+
const names = new Set;
|
|
451
|
+
for (const o of f.ops) {
|
|
452
|
+
if (!obj(o) || !str(o.name) || !o.name || o.name.includes("/") || names.has(o.name))
|
|
453
|
+
return `${f.coord}: bad or duplicate op name`;
|
|
454
|
+
names.add(o.name);
|
|
455
|
+
if (o.kind !== "action" && o.kind !== "event" || !optStr(o.description))
|
|
456
|
+
return `${f.coord}/${o.name}: bad kind or description`;
|
|
457
|
+
const why = schema(o.input, `${f.coord}/${o.name} input`) ?? schema(o.output, `${f.coord}/${o.name} output`);
|
|
458
|
+
if (why)
|
|
459
|
+
return why;
|
|
460
|
+
}
|
|
461
|
+
}
|
|
462
|
+
return schema(i.config, `${i.coord} config`);
|
|
463
|
+
}
|
|
464
|
+
var described = (p) => !obj(p) || !str(p.coord) || !obj(p.meta) || !Object.values(p.meta).every(str) || !obj(p.views) || !Object.values(p.views).every(str) || !Array.isArray(p.implementations) || p.built !== undefined && (!obj(p.built) || !Object.values(p.built).every(str)) ? "a provider needs coord, meta, views and implementations (and a built, if any, of strings)" : p.implementations.map(implError).find((w) => w !== undefined);
|
|
465
|
+
var result = (v) => isNanoResult(v);
|
|
466
|
+
var FIELDS = {
|
|
467
|
+
build: { pod: str, runtimes: strs, coord: str, url: str, config: any, edges: arrOf(edge) },
|
|
468
|
+
call: { id: num, port: str, input: any },
|
|
469
|
+
outresult: { id: num, result },
|
|
470
|
+
edges: { edges: arrOf(edge) },
|
|
471
|
+
close: { reason: (v) => ["restarted", "removed", "changed", "closed"].includes(v) },
|
|
472
|
+
"view-result": { id: num, result },
|
|
473
|
+
stream: { event: obj },
|
|
474
|
+
probe: { url: str },
|
|
475
|
+
theme: { theme: (v) => str(v) && isThemeId(v), mode: (v) => str(v) && isMode(v) },
|
|
476
|
+
ready: {},
|
|
477
|
+
closed: {},
|
|
478
|
+
failed: { error: str },
|
|
479
|
+
result: { id: num, result },
|
|
480
|
+
publish: { op: str, data: any },
|
|
481
|
+
outcall: { id: num, pod: str, runtime: str, op: str, input: any, via: optNum },
|
|
482
|
+
"view-call": { id: num, op: str, input: any },
|
|
483
|
+
described: { providers: Array.isArray },
|
|
484
|
+
warn: { reason: str },
|
|
485
|
+
emission: { id: num, event: any },
|
|
486
|
+
ended: { id: num, result },
|
|
487
|
+
on: { id: num, pod: str, runtime: str, op: str },
|
|
488
|
+
"view-on": { id: num, op: str },
|
|
489
|
+
off: { id: num }
|
|
490
|
+
};
|
|
491
|
+
function checkMsg(input) {
|
|
492
|
+
let text;
|
|
493
|
+
try {
|
|
494
|
+
text = JSON.stringify(input);
|
|
495
|
+
} catch {
|
|
496
|
+
return "not JSON";
|
|
497
|
+
}
|
|
498
|
+
if (text === undefined)
|
|
499
|
+
return "not JSON";
|
|
500
|
+
if (text.length > MAX)
|
|
501
|
+
return `${text.length} characters of JSON is over 1 MiB`;
|
|
502
|
+
const x = JSON.parse(text);
|
|
503
|
+
if (!obj(x) || !str(x.type) || !Object.hasOwn(FIELDS, x.type))
|
|
504
|
+
return `unknown type ${obj(x) ? String(x.type) : typeof x}`;
|
|
505
|
+
if (obj(x.result) && x.result.ok === true && !("value" in x.result))
|
|
506
|
+
x.result.value = undefined;
|
|
507
|
+
const bad = Object.entries(FIELDS[x.type]).find(([k, c]) => !c(x[k]));
|
|
508
|
+
if (bad)
|
|
509
|
+
return `${x.type}: bad ${bad[0]}`;
|
|
510
|
+
if (x.type === "described") {
|
|
511
|
+
const why = x.providers.map(described).find((w) => w !== undefined);
|
|
512
|
+
if (why)
|
|
513
|
+
return `described: ${why}`;
|
|
514
|
+
}
|
|
515
|
+
return x;
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/sandbox/serve.ts
|
|
519
|
+
import { failure as failure2 } from "@pritzlaff/nano-core";
|
|
520
|
+
|
|
521
|
+
// src/sandbox/frame-context.ts
|
|
522
|
+
import {
|
|
523
|
+
failure,
|
|
524
|
+
matches,
|
|
525
|
+
success,
|
|
526
|
+
selectorData
|
|
527
|
+
} from "@pritzlaff/nano-core";
|
|
528
|
+
var client = (call) => new Proxy({}, { get: (_, name) => typeof name === "string" && name !== "then" ? (input) => call(name, input) : undefined });
|
|
529
|
+
function frameContext(self, runtimes, edges, post, out, hear) {
|
|
530
|
+
const listeners = [];
|
|
531
|
+
const send = (m) => {
|
|
532
|
+
try {
|
|
533
|
+
post(m);
|
|
534
|
+
} catch (e) {
|
|
535
|
+
console.warn(`sandbox ${self}: not sent: ${e instanceof Error ? e.message : e}`);
|
|
536
|
+
}
|
|
537
|
+
};
|
|
538
|
+
const selection = (e, via) => ({
|
|
539
|
+
pod: e.pod,
|
|
540
|
+
runtime: e.runtime,
|
|
541
|
+
call: client((op, input) => out(e.pod, e.runtime, op, input, via)),
|
|
542
|
+
on: (o, fn) => hear((id) => ({ type: "on", id, pod: e.pod, runtime: e.runtime, op: o.coord }), fn)
|
|
543
|
+
});
|
|
544
|
+
const all = (s, via) => {
|
|
545
|
+
const want = selectorData(s);
|
|
546
|
+
return edges().filter((e) => matches(want, {
|
|
547
|
+
name: e.pod,
|
|
548
|
+
runtime: e.runtime,
|
|
549
|
+
implementation: e.implementation,
|
|
550
|
+
provider: e.provider,
|
|
551
|
+
provides: new Set(e.provides),
|
|
552
|
+
tags: new Set(e.tags)
|
|
553
|
+
})).map((e) => selection(e, via));
|
|
554
|
+
};
|
|
555
|
+
const at = (via) => ({
|
|
556
|
+
self,
|
|
557
|
+
runtimes,
|
|
558
|
+
one(s) {
|
|
559
|
+
const found = all(s, via), what = JSON.stringify(selectorData(s));
|
|
560
|
+
if (found.length === 1)
|
|
561
|
+
return success(found[0]);
|
|
562
|
+
return found.length ? failure("not-unique", `${self}: ${found.length} wired match ${what}`) : failure("not-found", `${self}: nothing wired matches ${what}`);
|
|
563
|
+
},
|
|
564
|
+
all: (s) => all(s, via),
|
|
565
|
+
async publish(o, data) {
|
|
566
|
+
send({ type: "publish", op: o.name, data });
|
|
567
|
+
},
|
|
568
|
+
addOnPodChangeListener() {},
|
|
569
|
+
addOnCloseListener(fn) {
|
|
570
|
+
listeners.push(fn);
|
|
571
|
+
}
|
|
572
|
+
});
|
|
573
|
+
const ctx = at();
|
|
574
|
+
async function close(reason) {
|
|
575
|
+
for (const fn of listeners)
|
|
576
|
+
try {
|
|
577
|
+
await fn({ reason });
|
|
578
|
+
} catch (e) {
|
|
579
|
+
console.warn(`sandbox ${self}: a close listener threw: ${e instanceof Error ? e.message : e}`);
|
|
580
|
+
}
|
|
581
|
+
}
|
|
582
|
+
return { ctx, close, at };
|
|
583
|
+
}
|
|
584
|
+
|
|
585
|
+
// src/sandbox/hearings.ts
|
|
586
|
+
function hearings(post) {
|
|
587
|
+
const held = new Map;
|
|
588
|
+
let n = 0;
|
|
589
|
+
function open(msg, fn) {
|
|
590
|
+
const id = ++n, queue = [];
|
|
591
|
+
let done = false, failed, wake, used = false;
|
|
592
|
+
const stop = () => {
|
|
593
|
+
done = true;
|
|
594
|
+
wake?.();
|
|
595
|
+
if (held.delete(id))
|
|
596
|
+
try {
|
|
597
|
+
post({ type: "off", id });
|
|
598
|
+
} catch {}
|
|
599
|
+
};
|
|
600
|
+
held.set(id, {
|
|
601
|
+
push: (e) => {
|
|
602
|
+
if (fn)
|
|
603
|
+
Promise.resolve().then(() => fn(e)).catch((x) => console.warn(`sandbox: a listener threw: ${x}`));
|
|
604
|
+
else {
|
|
605
|
+
queue.push(e);
|
|
606
|
+
wake?.();
|
|
607
|
+
}
|
|
608
|
+
},
|
|
609
|
+
end: (r) => {
|
|
610
|
+
held.delete(id);
|
|
611
|
+
done = true;
|
|
612
|
+
if (!r.ok) {
|
|
613
|
+
failed = r.fail;
|
|
614
|
+
if (fn)
|
|
615
|
+
post({ type: "warn", reason: `${r.fail.type}: ${r.fail.reason}` });
|
|
616
|
+
}
|
|
617
|
+
wake?.();
|
|
618
|
+
}
|
|
619
|
+
});
|
|
620
|
+
post(msg(id));
|
|
621
|
+
if (fn)
|
|
622
|
+
return stop;
|
|
623
|
+
return { [Symbol.asyncIterator]() {
|
|
624
|
+
if (used)
|
|
625
|
+
throw new Error("iterable: iterate once; subscribe again for another");
|
|
626
|
+
used = true;
|
|
627
|
+
return {
|
|
628
|
+
async next() {
|
|
629
|
+
while (!queue.length && !done)
|
|
630
|
+
await new Promise((r) => {
|
|
631
|
+
wake = r;
|
|
632
|
+
});
|
|
633
|
+
if (queue.length)
|
|
634
|
+
return { done: false, value: queue.shift() };
|
|
635
|
+
if (failed)
|
|
636
|
+
throw Object.assign(new Error(`${failed.type}: ${failed.reason}`), { fail: failed });
|
|
637
|
+
return { done: true, value: undefined };
|
|
638
|
+
},
|
|
639
|
+
async return() {
|
|
640
|
+
stop();
|
|
641
|
+
return { done: true, value: undefined };
|
|
642
|
+
}
|
|
643
|
+
};
|
|
644
|
+
} };
|
|
645
|
+
}
|
|
646
|
+
return {
|
|
647
|
+
open,
|
|
648
|
+
emission(id, e) {
|
|
649
|
+
held.get(id)?.push(e);
|
|
650
|
+
},
|
|
651
|
+
ended(id, r) {
|
|
652
|
+
held.get(id)?.end(r);
|
|
653
|
+
},
|
|
654
|
+
close() {
|
|
655
|
+
for (const [id, h] of [...held]) {
|
|
656
|
+
h.end({ ok: true, value: undefined });
|
|
657
|
+
try {
|
|
658
|
+
post({ type: "off", id });
|
|
659
|
+
} catch {}
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
};
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
// src/sandbox/serve.ts
|
|
666
|
+
var message = (e) => e instanceof Error ? e.message : String(e);
|
|
667
|
+
function serve(port, load, opts = {}) {
|
|
668
|
+
const post = (m) => port.postMessage(m);
|
|
669
|
+
const outs = new Map, heard = new Set, subs = hearings(post);
|
|
670
|
+
let edges = [], handlers, building = false, n = 0, at;
|
|
671
|
+
let close;
|
|
672
|
+
const ask = (m) => new Promise((res) => {
|
|
673
|
+
const id = ++n;
|
|
674
|
+
outs.set(id, res);
|
|
675
|
+
try {
|
|
676
|
+
post(m(id));
|
|
677
|
+
} catch (e) {
|
|
678
|
+
outs.delete(id);
|
|
679
|
+
res(failure2("invalid-input", message(e)));
|
|
680
|
+
}
|
|
681
|
+
});
|
|
682
|
+
const out = (pod, runtime, op, input, via) => ask((id) => ({ type: "outcall", id, pod, runtime, op, input, ...via !== undefined && { via } }));
|
|
683
|
+
function viewApp(m) {
|
|
684
|
+
const no = async () => failure2("invalid-input", `${m.pod}: a sandboxed view reaches only its own pod`);
|
|
685
|
+
const refused = { type: "not-found", reason: `${m.pod}: a sandboxed view reaches only its own pod` };
|
|
686
|
+
const client2 = (pod) => new Proxy({}, { get: (_, op) => typeof op !== "string" || op === "then" ? undefined : pod === m.pod ? (input) => ask((id) => ({ type: "view-call", id, op, input })) : no });
|
|
687
|
+
const deployment = {
|
|
688
|
+
pods: { [m.pod]: { implementation: m.coord, eager: true, config: m.config } },
|
|
689
|
+
runtimes: Object.fromEntries(m.runtimes.map((r) => [r, { pods: [m.pod], subscriptions: [] }]))
|
|
690
|
+
};
|
|
691
|
+
const thrown = () => {
|
|
692
|
+
throw Object.assign(new Error(refused.reason), { fail: refused });
|
|
693
|
+
};
|
|
694
|
+
const viewOn = (o, fn) => subs.open((id) => ({ type: "view-on", id, op: o.coord }), fn);
|
|
695
|
+
const own = (api) => new Proxy({}, { get: (_, op) => typeof op !== "string" || op === "then" ? undefined : api.ops[op]?.kind === "event" ? () => viewOn(api.ops[op]) : async (input) => {
|
|
696
|
+
const r = await ask((id) => ({ type: "view-call", id, op, input: input ?? null }));
|
|
697
|
+
if (r.ok)
|
|
698
|
+
return r.value;
|
|
699
|
+
throw Object.assign(new Error(`${r.fail.type}: ${r.fail.reason}`), { fail: r.fail });
|
|
700
|
+
} });
|
|
701
|
+
const one = {
|
|
702
|
+
call: client2,
|
|
703
|
+
get: (api, where) => where?.pod === m.pod ? own(api) : thrown(),
|
|
704
|
+
subscribe: viewOn,
|
|
705
|
+
resolve: () => ({ ok: false, reason: refused.type, fail: refused, getOrThrow: thrown }),
|
|
706
|
+
listen: () => () => {},
|
|
707
|
+
status: () => failure2(refused.type, refused.reason),
|
|
708
|
+
start: no,
|
|
709
|
+
getOrCreate: no
|
|
710
|
+
};
|
|
711
|
+
return {
|
|
712
|
+
...one,
|
|
713
|
+
runtime: () => one,
|
|
714
|
+
call: (...at2) => client2(at2[at2.length - 1]),
|
|
715
|
+
deployment: () => structuredClone(deployment),
|
|
716
|
+
listen(fn) {
|
|
717
|
+
heard.add(fn);
|
|
718
|
+
return () => {
|
|
719
|
+
heard.delete(fn);
|
|
720
|
+
};
|
|
721
|
+
},
|
|
722
|
+
apply: no,
|
|
723
|
+
restart: no,
|
|
724
|
+
close: no
|
|
725
|
+
};
|
|
726
|
+
}
|
|
727
|
+
async function build(m) {
|
|
728
|
+
if (building)
|
|
729
|
+
return console.warn("sandbox: dropped a second build");
|
|
730
|
+
building = true;
|
|
731
|
+
edges = m.edges;
|
|
732
|
+
try {
|
|
733
|
+
const impl = await load(m.url, m.coord);
|
|
734
|
+
if (impl.coord !== m.coord)
|
|
735
|
+
throw new Error(`${m.url} gave ${impl.coord} for ${m.coord}`);
|
|
736
|
+
const made = frameContext(m.pod, m.runtimes, () => edges, post, out, subs.open);
|
|
737
|
+
close = async (reason) => {
|
|
738
|
+
subs.close();
|
|
739
|
+
await made.close(reason);
|
|
740
|
+
};
|
|
741
|
+
const built = await impl.make(made.ctx, m.config);
|
|
742
|
+
handlers = built.handlers;
|
|
743
|
+
at = made.at;
|
|
744
|
+
post({ type: "ready" });
|
|
745
|
+
for (const { op, run } of built.sources.values()) {
|
|
746
|
+
const it = run()[Symbol.asyncIterator]();
|
|
747
|
+
made.ctx.addOnCloseListener(() => {
|
|
748
|
+
it.return?.();
|
|
749
|
+
});
|
|
750
|
+
(async () => {
|
|
751
|
+
try {
|
|
752
|
+
for (let r = await it.next();!r.done; r = await it.next())
|
|
753
|
+
await made.ctx.publish(op, r.value);
|
|
754
|
+
} catch (e) {
|
|
755
|
+
post({ type: "warn", reason: `${m.pod}: ${op.name} threw ${message(e)}` });
|
|
756
|
+
}
|
|
757
|
+
})();
|
|
758
|
+
}
|
|
759
|
+
} catch (e) {
|
|
760
|
+
return post({ type: "failed", error: message(e) });
|
|
761
|
+
}
|
|
762
|
+
try {
|
|
763
|
+
opts.render?.(m.coord, { app: viewApp(m), runtime: m.runtimes[0], pod: m.pod });
|
|
764
|
+
} catch (e) {
|
|
765
|
+
post({ type: "warn", reason: `${m.pod}: its view failed: ${message(e)}` });
|
|
766
|
+
}
|
|
767
|
+
}
|
|
768
|
+
async function call(id, p, input) {
|
|
769
|
+
const h = handlers?.get(p), inv = at;
|
|
770
|
+
const r = h && inv ? await Promise.resolve().then(() => h(input, inv(id))).catch((e) => failure2("threw", message(e))) : failure2("unknown-op", `no handler for ${p}`);
|
|
771
|
+
try {
|
|
772
|
+
post({ type: "result", id, result: r });
|
|
773
|
+
} catch (e) {
|
|
774
|
+
post({ type: "result", id, result: failure2("invalid-output", message(e)) });
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
async function probe(url) {
|
|
778
|
+
try {
|
|
779
|
+
post({ type: "described", providers: await (opts.probe ?? (async () => {
|
|
780
|
+
throw new Error("no probe here");
|
|
781
|
+
}))(url) });
|
|
782
|
+
} catch (e) {
|
|
783
|
+
post({ type: "failed", error: message(e) });
|
|
784
|
+
}
|
|
785
|
+
}
|
|
786
|
+
port.onmessage = ({ data }) => {
|
|
787
|
+
const m = checkMsg(data);
|
|
788
|
+
if (typeof m === "string")
|
|
789
|
+
return console.warn(`sandbox: dropped message: ${m}`);
|
|
790
|
+
switch (m.type) {
|
|
791
|
+
case "build":
|
|
792
|
+
return void build(m);
|
|
793
|
+
case "call":
|
|
794
|
+
return void call(m.id, m.port, m.input);
|
|
795
|
+
case "outresult":
|
|
796
|
+
case "view-result": {
|
|
797
|
+
const res = outs.get(m.id);
|
|
798
|
+
outs.delete(m.id);
|
|
799
|
+
return res?.(m.result);
|
|
800
|
+
}
|
|
801
|
+
case "edges":
|
|
802
|
+
edges = m.edges;
|
|
803
|
+
return;
|
|
804
|
+
case "emission":
|
|
805
|
+
return subs.emission(m.id, m.event);
|
|
806
|
+
case "ended":
|
|
807
|
+
return subs.ended(m.id, m.result);
|
|
808
|
+
case "stream":
|
|
809
|
+
for (const fn of heard)
|
|
810
|
+
try {
|
|
811
|
+
fn(m.event);
|
|
812
|
+
} catch (e) {
|
|
813
|
+
console.warn(`sandbox: a listener threw: ${message(e)}`);
|
|
814
|
+
}
|
|
815
|
+
return;
|
|
816
|
+
case "probe":
|
|
817
|
+
return void probe(m.url);
|
|
818
|
+
case "theme":
|
|
819
|
+
return opts.theme?.({ theme: m.theme, mode: m.mode });
|
|
820
|
+
case "close":
|
|
821
|
+
return void (close ?? (async () => {}))(m.reason).then(() => post({ type: "closed" }));
|
|
822
|
+
default:
|
|
823
|
+
return console.warn(`sandbox: dropped message of type ${m.type}`);
|
|
824
|
+
}
|
|
825
|
+
};
|
|
826
|
+
}
|
|
827
|
+
|
|
828
|
+
// src/lib/nano-vars.ts
|
|
829
|
+
import { NANO_TOKENS } from "@pritzlaff/nano-elements";
|
|
830
|
+
var DEFAULTS = {
|
|
831
|
+
light: {
|
|
832
|
+
bg: "",
|
|
833
|
+
"fg-2": "",
|
|
834
|
+
"border-strong": "",
|
|
835
|
+
"radius-s": "",
|
|
836
|
+
good: "#0B6B5F",
|
|
837
|
+
"good-bg": "#DDF1EC",
|
|
838
|
+
bad: "#A3283C",
|
|
839
|
+
"bad-bg": "#F8E1E3",
|
|
840
|
+
warn: "#6E5100",
|
|
841
|
+
"warn-bg": "#F6ECD2",
|
|
842
|
+
s1: "#2E5BDA",
|
|
843
|
+
s2: "#E0662B",
|
|
844
|
+
s3: "#0E8576",
|
|
845
|
+
s4: "#8A4FD0",
|
|
846
|
+
s5: "#A97C00",
|
|
847
|
+
s6: "#C2416B",
|
|
848
|
+
s7: "#1E8FB8",
|
|
849
|
+
s8: "#4D555C"
|
|
850
|
+
},
|
|
851
|
+
dark: {
|
|
852
|
+
bg: "",
|
|
853
|
+
"fg-2": "",
|
|
854
|
+
"border-strong": "",
|
|
855
|
+
"radius-s": "",
|
|
856
|
+
good: "#5FD0B8",
|
|
857
|
+
"good-bg": "#12342E",
|
|
858
|
+
bad: "#FF8A9A",
|
|
859
|
+
"bad-bg": "#3A1D22",
|
|
860
|
+
warn: "#F1D488",
|
|
861
|
+
"warn-bg": "#3A3016",
|
|
862
|
+
s1: "#7FA2FF",
|
|
863
|
+
s2: "#FF9A5C",
|
|
864
|
+
s3: "#3FC9AE",
|
|
865
|
+
s4: "#B58CF0",
|
|
866
|
+
s5: "#E0B43C",
|
|
867
|
+
s6: "#F07BA0",
|
|
868
|
+
s7: "#5CC4EC",
|
|
869
|
+
s8: "#AEB6BD"
|
|
870
|
+
}
|
|
871
|
+
};
|
|
872
|
+
function nanoVars(id, scheme) {
|
|
873
|
+
const theme = THEMES[id];
|
|
874
|
+
const k = theme.schemes[scheme];
|
|
875
|
+
if (!k)
|
|
876
|
+
throw new Error(`theme ${id} has no ${scheme} scheme`);
|
|
877
|
+
const x = { ...DEFAULTS[scheme], ...theme.nano ?? {} };
|
|
878
|
+
const v = {
|
|
879
|
+
bg: x.bg || k.bg,
|
|
880
|
+
surface: k.surface,
|
|
881
|
+
"surface-2": k["surface-2"],
|
|
882
|
+
border: k.line,
|
|
883
|
+
"border-strong": x["border-strong"] || k.muted,
|
|
884
|
+
fg: k.fg,
|
|
885
|
+
"fg-2": x["fg-2"] || k.fg,
|
|
886
|
+
muted: k.muted,
|
|
887
|
+
"on-accent": k["on-accent"],
|
|
888
|
+
accent: k.accent,
|
|
889
|
+
"accent-soft": k["accent-soft"],
|
|
890
|
+
focus: k.focus,
|
|
891
|
+
good: x.good,
|
|
892
|
+
"good-bg": x["good-bg"],
|
|
893
|
+
bad: x.bad,
|
|
894
|
+
"bad-bg": x["bad-bg"],
|
|
895
|
+
warn: x.warn,
|
|
896
|
+
"warn-bg": x["warn-bg"],
|
|
897
|
+
font: k.font,
|
|
898
|
+
"font-display": k.display,
|
|
899
|
+
"font-mono": k.mono,
|
|
900
|
+
radius: k.radius,
|
|
901
|
+
"radius-s": x["radius-s"] || k.radius,
|
|
902
|
+
s1: x.s1,
|
|
903
|
+
s2: x.s2,
|
|
904
|
+
s3: x.s3,
|
|
905
|
+
s4: x.s4,
|
|
906
|
+
s5: x.s5,
|
|
907
|
+
s6: x.s6,
|
|
908
|
+
s7: x.s7,
|
|
909
|
+
s8: x.s8
|
|
910
|
+
};
|
|
911
|
+
return Object.fromEntries(Object.keys(NANO_TOKENS).map((t) => [`--nano-${t}`, v[t]]));
|
|
912
|
+
}
|
|
913
|
+
|
|
914
|
+
// src/lib/theme-state.ts
|
|
915
|
+
var KEY = "workspace-starter.theme";
|
|
916
|
+
var THEME_EVENT = "app-theme-change";
|
|
917
|
+
var systemDark = () => matchMedia("(prefers-color-scheme: dark)").matches;
|
|
918
|
+
var storageWorks = true;
|
|
919
|
+
var applyChoice = (doc, choice) => {
|
|
920
|
+
const root = doc.documentElement;
|
|
921
|
+
const scheme = resolveScheme(choice.theme, choice.mode, systemDark());
|
|
922
|
+
for (const [k, v] of Object.entries(themeVars(choice.theme, scheme)))
|
|
923
|
+
root.style.setProperty(k, v);
|
|
924
|
+
for (const [k, v] of Object.entries(nanoVars(choice.theme, scheme)))
|
|
925
|
+
root.style.setProperty(k, v);
|
|
926
|
+
root.style.setProperty("--page-bg", THEMES[choice.theme].background ?? "none");
|
|
927
|
+
root.dataset["theme"] = choice.theme;
|
|
928
|
+
root.dataset["mode"] = choice.mode;
|
|
929
|
+
root.dataset["scheme"] = scheme;
|
|
930
|
+
root.style.colorScheme = scheme;
|
|
931
|
+
try {
|
|
932
|
+
localStorage.setItem(KEY, `${choice.theme}:${choice.mode}`);
|
|
933
|
+
storageWorks = true;
|
|
934
|
+
} catch {
|
|
935
|
+
storageWorks = false;
|
|
936
|
+
}
|
|
937
|
+
doc.dispatchEvent(new CustomEvent(THEME_EVENT, { detail: choice }));
|
|
938
|
+
};
|
|
939
|
+
|
|
940
|
+
// src/sandbox/boot.ts
|
|
941
|
+
var mods = new Map;
|
|
942
|
+
function mod(url) {
|
|
943
|
+
if (location.href !== "about:srcdoc" && new URL(url, location.href).origin !== location.origin)
|
|
944
|
+
return Promise.reject(new Error(`${url} is not from this frame's origin, ${location.origin}`));
|
|
945
|
+
if (!mods.has(url))
|
|
946
|
+
mods.set(url, import(url).then((m) => {
|
|
947
|
+
const p = m.default;
|
|
948
|
+
if (!p || typeof p.coord !== "string" || !(p.implementations instanceof Map))
|
|
949
|
+
throw new Error(`${url} has no default Provider`);
|
|
950
|
+
return { default: p, views: { ...m.views }, ...m.built && { built: { ...m.built } } };
|
|
951
|
+
}));
|
|
952
|
+
return mods.get(url);
|
|
953
|
+
}
|
|
954
|
+
addEventListener("message", function once(e) {
|
|
955
|
+
if (e.source !== parent || !e.ports[0])
|
|
956
|
+
return;
|
|
957
|
+
removeEventListener("message", once);
|
|
958
|
+
let built;
|
|
959
|
+
serve(e.ports[0], async (u, coord) => {
|
|
960
|
+
const i = (built = await mod(u)).default.implementations.get(coord);
|
|
961
|
+
if (!i)
|
|
962
|
+
throw new Error(`${u} has no implementation ${coord}`);
|
|
963
|
+
return i;
|
|
964
|
+
}, {
|
|
965
|
+
theme: (c) => applyChoice(document, c),
|
|
966
|
+
probe: async (u) => {
|
|
967
|
+
const m = await mod(u);
|
|
968
|
+
return [{ ...describeProvider(m.default, m.views), ...m.built && { built: m.built } }];
|
|
969
|
+
},
|
|
970
|
+
render(coord, target) {
|
|
971
|
+
const m = built, registry = Registry.create();
|
|
972
|
+
registry.add(m.default);
|
|
973
|
+
defineViews();
|
|
974
|
+
const tag = viewFor(target.pod, { pods: { [target.pod]: { implementation: coord, eager: true } }, runtimes: {} }, m.views);
|
|
975
|
+
const el = document.createElement(tag);
|
|
976
|
+
el.target = { ...target, registry };
|
|
977
|
+
document.body.append(el);
|
|
978
|
+
}
|
|
979
|
+
});
|
|
980
|
+
});
|