@popcorn245/cornfield-components 0.50.1 → 0.51.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.
@@ -0,0 +1,60 @@
1
+ import { n as e, t } from "./status-CYQD5PwL.js";
2
+ // ../explorer/pieces/review-source.js
3
+ function n(n, r) {
4
+ let { root: i, stage: a, parsed: o } = r, s = i.nodeType === 11 ? i.host : i, c = !!r.useTheme, l = r.theme, u = !1, d = !1, f = e(n, {
5
+ host: s,
6
+ tokens: r.tokens,
7
+ version: r.version,
8
+ pageUrl: r.pageUrl,
9
+ theme: () => l,
10
+ useTheme: () => c,
11
+ onConfig: (e) => r.onConfig(e),
12
+ onReady: () => {
13
+ u = !1, f.source.topology && r.onTopology(f.source.topology);
14
+ },
15
+ onAuth: ({ status: e, signIn: t }) => r.onAuth({
16
+ status: e,
17
+ signIn: t,
18
+ during: "load"
19
+ }),
20
+ onError: (e) => r.onError(e),
21
+ onMode: () => r.onMode(),
22
+ onSheet: () => r.onMode()
23
+ }), { source: p } = f, m = [];
24
+ i.nodeType === 11 && m.push(f.theme.adopt(i));
25
+ let h = t(a, n, {
26
+ onRetry: () => p.load(),
27
+ focusMap: r.focusMap
28
+ });
29
+ return p.provide({
30
+ topology: r.topology || void 0,
31
+ config: r.config || void 0,
32
+ strings: r.strings || void 0
33
+ }), o && !o.ok ? p.say({
34
+ state: "address",
35
+ problem: o.problem
36
+ }) : o && p.load(), {
37
+ source: p,
38
+ provide: (e) => p.provide(e),
39
+ setUseTheme(e) {
40
+ e = !!e, e !== c && (c = e, f.setUseTheme(c));
41
+ },
42
+ setTheme(e) {
43
+ l = e, f.follow();
44
+ },
45
+ showSignIn(e) {
46
+ u = !0, h.show({
47
+ state: "sign-in",
48
+ status: e.status,
49
+ signIn: e.signIn
50
+ });
51
+ },
52
+ clearSignIn() {
53
+ u && (u = !1, h.clear());
54
+ },
55
+ destroy() {
56
+ d || (d = !0, m.forEach((e) => e()), h.destroy(), f.destroy());
57
+ }
58
+ };
59
+ }
60
+ export { n as attachSource };
@@ -0,0 +1,136 @@
1
+ import { t as e } from "./rolldown-runtime-CGnMp29N.js";
2
+ import { i as t, ln as n, n as r, r as i, s as a } from "./engine-ClfnAsgM.js";
3
+ import { n as o, t as s } from "./status-CYQD5PwL.js";
4
+ import { d as c, n as l } from "./source-address-B7hYRgt8.js";
5
+ // ../explorer/pieces/scope.js
6
+ var u = /* @__PURE__ */ e({ mountScope: () => f }), d = [
7
+ "light",
8
+ "dark",
9
+ "auto"
10
+ ];
11
+ function f(e, u = {}) {
12
+ let f = {
13
+ src: u.src,
14
+ theme: u.theme,
15
+ useTheme: !!u.useTheme,
16
+ topology: u.topology,
17
+ config: u.config,
18
+ strings: u.strings
19
+ }, m = u.pageUrl || (() => ""), h = /* @__PURE__ */ new Set(), g = null, _ = null, v = null, y = !1, b = !1, x = (e) => {
20
+ if (b || !g || !e.detail || typeof e.detail.claim != "function") return;
21
+ e.stopPropagation();
22
+ let t = {
23
+ el: e.detail.el,
24
+ inst: g,
25
+ scope: E,
26
+ release: () => h.delete(t)
27
+ };
28
+ h.add(t), e.detail.claim(t);
29
+ };
30
+ e.addEventListener(i, x);
31
+ function S() {
32
+ let t = new Set(p(e));
33
+ for (let e of [...h]) h.delete(e), e.el && t.add(e.el);
34
+ for (let e of t) e.isConnected !== !1 && e.dispatchEvent(new Event(r));
35
+ }
36
+ function C() {
37
+ v && v.follow();
38
+ }
39
+ function w() {
40
+ let i = f.src === void 0 || f.src === null || f.src === "" ? null : l(f.src);
41
+ g = n({
42
+ root: e,
43
+ base: i && i.ok ? i.base : ""
44
+ }), c(g, null);
45
+ let a = t(g);
46
+ a.host = e, a.theme = d.includes(f.theme) ? f.theme : "auto";
47
+ let p = g, h = o(g, {
48
+ host: e,
49
+ tokens: u.tokens,
50
+ version: u.version,
51
+ pageUrl: m,
52
+ theme: () => d.includes(f.theme) ? f.theme : "auto",
53
+ useTheme: () => f.useTheme,
54
+ onReady: () => {
55
+ !y && g === p && (y = !0, u.onReady && u.onReady());
56
+ },
57
+ onAuth: (e) => {
58
+ u.onAuth && u.onAuth(e);
59
+ },
60
+ onError: (e) => {
61
+ u.onError && u.onError(e);
62
+ },
63
+ onMode: () => p.emit("scope:theme")
64
+ });
65
+ v = h, a.serverTheme = h.theme, g.own(() => h.destroy()), _ = h.source, a.source = _, a.mountStatus = s, y = !1;
66
+ let x = [];
67
+ g.on("piece:refused", (e) => {
68
+ e.host && !x.includes(e.host) && x.push(e.host), u.onError && u.onError({
69
+ kind: e.reason,
70
+ message: e.message
71
+ });
72
+ }), g.on("attach:released", () => {
73
+ Promise.resolve().then(() => {
74
+ if (!(b || g !== p)) for (; x.length;) {
75
+ let e = x.shift();
76
+ if (e.isConnected) {
77
+ e.dispatchEvent(new Event(r));
78
+ return;
79
+ }
80
+ }
81
+ });
82
+ }), i && !i.ok && _.say({
83
+ state: "address",
84
+ problem: i.problem
85
+ }), _.provide({
86
+ topology: f.topology || void 0,
87
+ config: f.config || void 0,
88
+ strings: f.strings || void 0
89
+ }), i && i.ok && _.load();
90
+ }
91
+ function T() {
92
+ S(), g && g.destroy(), g = null, _ = null, v = null;
93
+ }
94
+ let E = {
95
+ update(e = {}) {
96
+ if (b) return;
97
+ let n = !1;
98
+ if ("src" in e && e.src !== f.src && (f.src = e.src, n = !0), "theme" in e && e.theme !== f.theme && (f.theme = e.theme, t(g).theme = d.includes(f.theme) ? f.theme : "auto", C()), "useTheme" in e && !!e.useTheme !== f.useTheme && (f.useTheme = !!e.useTheme, v.setUseTheme(f.useTheme)), n) {
99
+ let e = g;
100
+ v.destroy(), w(), S(), e.destroy();
101
+ return;
102
+ }
103
+ let r = {};
104
+ for (let t of [
105
+ "topology",
106
+ "config",
107
+ "strings"
108
+ ]) t in e && e[t] !== f[t] && (f[t] = e[t], r[t] = e[t] === void 0 ? null : e[t]);
109
+ Object.keys(r).length && _.provide(r);
110
+ },
111
+ destroy() {
112
+ b || (e.removeEventListener(i, x), T(), b = !0, h.clear());
113
+ },
114
+ get instance() {
115
+ return g;
116
+ },
117
+ get source() {
118
+ return _;
119
+ }
120
+ };
121
+ return u.tokens && a(e.getRootNode(), u.tokens), w(), S(), E;
122
+ }
123
+ function p(e) {
124
+ let t = [], n = (e) => {
125
+ for (let r of e.children || []) {
126
+ let e = r.localName || "";
127
+ if (e.startsWith("corn-")) {
128
+ if (e === "corn-scope") continue;
129
+ t.push(r);
130
+ }
131
+ r.shadowRoot && n(r.shadowRoot), n(r);
132
+ }
133
+ };
134
+ return n(e), t;
135
+ }
136
+ export { u as n, f as t };
@@ -0,0 +1,251 @@
1
+ import { B as e, Bt as t, Ft as n, Lt as r, Pt as i, R as a, Rt as o, Zt as s, _t as c, et as l, jt as u, kt as d, nt as f, p, zt as m } from "./engine-ClfnAsgM.js";
2
+ // ../explorer/engine/layers.js
3
+ var h = (e) => e.match && e.match.type ? [].concat(e.match.type) : [], g = {
4
+ flow: "#fb923c",
5
+ runs: "#5eead4"
6
+ }, _ = (e) => {
7
+ let t = h(e)[0];
8
+ return t && s[t] ? s[t].color : g[e.key];
9
+ }, v = /* @__PURE__ */ new Set([
10
+ "stack",
11
+ "machine",
12
+ "container",
13
+ "device",
14
+ "house",
15
+ "persona"
16
+ ]), y = r.map((e) => ({
17
+ ...e,
18
+ color: _(e)
19
+ })), b = "cornfield:layers", x = /^[a-z][a-z0-9-]{0,40}$/, S = (e) => e.slot("layers", () => ({
20
+ changes: {},
21
+ storeKey: b
22
+ }));
23
+ function C(e, t) {
24
+ S(e).storeKey = t;
25
+ }
26
+ var w = (e, t) => Object.hasOwn(e.state.layerDefaults, t) ? e.state.layerDefaults[t] : !v.has(t), T = (e, t) => u(e.state, t), E = "#94a3b8", D = "\\d{1,3}(?:\\.\\d+)?%?", O = RegExp(`^(?:#(?:[0-9a-f]{3,4}|[0-9a-f]{6}|[0-9a-f]{8})|rgba?\\(\\s*${D}(?:\\s*,\\s*|\\s+)${D}(?:\\s*,\\s*|\\s+)${D}(?:\\s*[,/]\\s*(?:\\d*\\.)?\\d+%?)?\\s*\\))$`, "i"), k = (e) => typeof e == "string" && e.length <= 64 && O.test(e.trim()) ? e.trim() : E;
27
+ function A(t, n, r) {
28
+ return k(a(e(t).get().values, n) || c(d(r, t.state.theme)));
29
+ }
30
+ var j = (e, t) => {
31
+ let n = h(t);
32
+ return n.length > 1 && n.find((t) => e.state.nodes.some((e) => e.type === t)) || n[0] || t.key;
33
+ };
34
+ function M(e) {
35
+ let { state: r } = e, i = (t) => {
36
+ let n = j(e, t);
37
+ return {
38
+ ...t,
39
+ color: A(e, {
40
+ type: n,
41
+ group: t.key
42
+ }, s[n] ? s[n].color : t.color)
43
+ };
44
+ }, a = /* @__PURE__ */ new Set(), o = /* @__PURE__ */ new Set();
45
+ r.nodes.forEach((e) => {
46
+ let i = n(r, e);
47
+ if (!i) return;
48
+ a.add(i);
49
+ let s = t(e);
50
+ s !== i && o.add(s);
51
+ });
52
+ let c = (t) => {
53
+ let i = r.nodes.find((e) => n(r, e) === t.key);
54
+ return { color: A(e, i ? {
55
+ type: i.type,
56
+ layer: t.key,
57
+ group: f(i)
58
+ } : {
59
+ type: t.key,
60
+ layer: t.key
61
+ }, i ? l(i) : E) };
62
+ }, u = r.projectLayers.filter((e) => a.has(e.key)).map((e) => ({
63
+ key: e.key,
64
+ label: e.label,
65
+ desc: e.desc || "",
66
+ project: !0,
67
+ ...c(e)
68
+ })), d = y.filter((e) => !e.overlay && (a.has(e.key) || !o.has(e.key))).map(i), p = /* @__PURE__ */ new Set([...y.map((e) => e.key), ...r.projectLayers.map((e) => e.key)]), h = [];
69
+ return a.forEach((t) => {
70
+ p.has(t) || (p.add(t), h.push({
71
+ key: t,
72
+ label: t.charAt(0).toUpperCase() + t.slice(1),
73
+ color: A(e, {
74
+ type: t,
75
+ group: t
76
+ }, E),
77
+ desc: `Nodes of the type ${t}`
78
+ }));
79
+ }), {
80
+ layers: [...m(u, d, r.layerOrder), ...h],
81
+ overlays: y.filter((e) => e.overlay).map(i)
82
+ };
83
+ }
84
+ function N(e) {
85
+ let t = S(e).storeKey;
86
+ if (!t) return {};
87
+ try {
88
+ let n = JSON.parse(e.store.get(t) || "{}");
89
+ return !n || typeof n != "object" || Array.isArray(n) ? {} : Object.fromEntries(Object.entries(n).filter(([e, t]) => x.test(e) && typeof t == "boolean"));
90
+ } catch {
91
+ return {};
92
+ }
93
+ }
94
+ function P(e) {
95
+ let { changes: t, storeKey: n } = S(e);
96
+ n && (Object.keys(t).length ? e.store.set(n, JSON.stringify(t)) : e.store.remove(n));
97
+ }
98
+ function F(e, t, n) {
99
+ let { changes: r } = S(e);
100
+ n === w(e, t) ? delete r[t] : r[t] = n;
101
+ }
102
+ function I(e, t) {
103
+ let { state: n } = e, r = o(t);
104
+ n.projectLayers = r.add, n.layerOrder = r.order;
105
+ let i = {};
106
+ for (let e of y) i[e.key] = !v.has(e.key);
107
+ for (let e of r.add) i[e.key] = !0;
108
+ for (let e of r.off) i[e] = !1;
109
+ n.layerDefaults = i;
110
+ let a = S(e);
111
+ a.changes = N(e);
112
+ for (let [e, t] of Object.entries(i)) n.activeLayers[e] = t;
113
+ for (let [e, t] of Object.entries(a.changes)) n.activeLayers[e] = t;
114
+ B(e);
115
+ }
116
+ function L(t) {
117
+ let { state: n } = t, r = /* @__PURE__ */ new Set(), i = [];
118
+ n.nodes.forEach((e) => {
119
+ if (typeof e.kind != "string" || !e.kind) return;
120
+ let t = `${e.type}\u0000${e.kind}`;
121
+ r.has(t) || (r.add(t), i.push([e.type, e.kind]));
122
+ }), e(t).setSubjects({
123
+ kinds: i,
124
+ layers: n.projectLayers.map((e) => e.key)
125
+ });
126
+ }
127
+ function R(e) {
128
+ let t = e.slot("layers-draw", () => ({ drawing: !1 }));
129
+ t.drawing = !0;
130
+ try {
131
+ L(e);
132
+ } finally {
133
+ t.drawing = !1;
134
+ }
135
+ e.emit("layers:redraw");
136
+ }
137
+ var z = (e, t) => e.on("layers", t);
138
+ function B(e) {
139
+ e.touchScene(), e.emit("layers"), R(e), e.map && (e.map.render(), e.map.ensureFlowLoop());
140
+ }
141
+ function V(e, t, n, { viewer: r = !1, scenario: i = !1 } = {}) {
142
+ let { state: a } = e, o = a.review && a.proposal ? a.review : null;
143
+ if (o ? ((i ? o.step : o.manual)[t] = n, o.rev++) : (a.activeLayers[t] = n, r && (F(e, t, n), P(e))), B(e), r) {
144
+ let { layers: r, overlays: i } = M(e), s = [...r, ...i].find((e) => e.key === t), c = a.nodes.filter((t) => e.map.isNodeVisible(t)).length;
145
+ p(e, `${s ? s.label : t} ${n ? "on" : "off"}${o ? " for this review" : ""}. ${c} ${c === 1 ? "node" : "nodes"} shown.`);
146
+ }
147
+ }
148
+ function H(e) {
149
+ e.state.review = {
150
+ whole: !1,
151
+ manual: {},
152
+ step: {},
153
+ rev: 0
154
+ };
155
+ }
156
+ function U(e) {
157
+ e.state.review && (e.state.review = null, e.touchScene(), R(e));
158
+ }
159
+ function W(e) {
160
+ let { state: t } = e;
161
+ if (!t.review || !t.proposal || t.review.whole) return "";
162
+ let { layers: r } = M(e), a = new Set(t.nodes.map((e) => n(t, e)));
163
+ return r.some((e) => a.has(e.key) && i(t, e.key)) ? `Showing ${r.filter((t) => T(e, t.key)).length} of ${r.length} layers: the ones this proposal changes.` : "";
164
+ }
165
+ function G(e, t) {
166
+ let { state: n } = e, r = n.review && n.proposal ? n.review : null;
167
+ r && r.whole !== t && (r.whole = t, r.rev++, B(e), p(e, t ? "Showing the whole map." : W(e) || "Showing the change: the rest of the map is greyed."));
168
+ }
169
+ function K(e) {
170
+ let { review: t } = e.state;
171
+ return !t || !Object.keys(t.step).length ? !1 : (t.step = {}, t.rev++, e.touchScene(), R(e), !0);
172
+ }
173
+ // ../explorer/engine/connection.js
174
+ function q(e, t) {
175
+ return e.offline() ? `You are offline. ${t} was not sent; what you typed is kept. Try again when you are back.` : `cornfield did not answer. ${t} was not sent; what you typed is kept.`;
176
+ }
177
+ function J(e) {
178
+ return (t, n) => e.fetch(t, Y(e, t, n));
179
+ }
180
+ function Y(e, t, n) {
181
+ return e.base && X(e, t) ? {
182
+ credentials: "include",
183
+ redirect: "error",
184
+ ...n
185
+ } : n;
186
+ }
187
+ function X(e, t) {
188
+ if (!e.base) return !1;
189
+ try {
190
+ return new URL(e.url(String(t)), e.base).origin === new URL(e.base).origin;
191
+ } catch {
192
+ return !1;
193
+ }
194
+ }
195
+ // ../explorer/engine/source-address.js
196
+ var Z = "/auth/start", Q = /[\u0000- \u007f\\]/;
197
+ function $(e) {
198
+ if (typeof e != "string" || !e.trim()) return {
199
+ ok: !1,
200
+ problem: "is empty"
201
+ };
202
+ let t = e.trim();
203
+ if (Q.test(t)) return {
204
+ ok: !1,
205
+ problem: "has a space, a control character or a backslash"
206
+ };
207
+ let n;
208
+ try {
209
+ n = new URL(t);
210
+ } catch {
211
+ return {
212
+ ok: !1,
213
+ problem: "is not an address (an http or https address, as the server is opened in a browser)"
214
+ };
215
+ }
216
+ return n.protocol !== "https:" && n.protocol !== "http:" ? {
217
+ ok: !1,
218
+ problem: "is not http or https"
219
+ } : /^https?:\/\/[^/?#]/i.test(t) ? n.username || n.password ? {
220
+ ok: !1,
221
+ problem: "has a user name or password"
222
+ } : t.includes("?") || t.includes("#") ? {
223
+ ok: !1,
224
+ problem: "has a query or a fragment"
225
+ } : {
226
+ ok: !0,
227
+ base: n.origin + n.pathname.replace(/\/+$/, ""),
228
+ origin: n.origin
229
+ } : {
230
+ ok: !1,
231
+ problem: "has no host"
232
+ };
233
+ }
234
+ function ee(e, t) {
235
+ let n = "";
236
+ if (typeof t == "string" && /^https?:\/\//i.test(t)) try {
237
+ let e = new URL(t);
238
+ e.username = "", e.password = "", n = `?returnTo=${encodeURIComponent(e.href)}`;
239
+ } catch {
240
+ n = "";
241
+ }
242
+ return `${e}${Z}${n}`;
243
+ }
244
+ function te(e) {
245
+ try {
246
+ return /^https?:/i.test(e) ? new URL(e).origin : "";
247
+ } catch {
248
+ return "";
249
+ }
250
+ }
251
+ export { G as _, q as a, H as c, C as d, z as f, I as g, V as h, J as i, K as l, W as m, $ as n, Y as o, R as p, ee as r, y as s, te as t, U as u };