@floegence/floe-webapp-core 0.102.0 → 0.103.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.
@@ -1,10 +1,10 @@
1
- import { builtInShellThemePresets as z, REQUIRED_SHELL_THEME_TOKENS as N } from "./presets.js";
2
- import { resolveFloeThemeDocument as v, readFloeThemeDocument as M } from "./themeDocument.js";
3
- const x = 128 * 1024, h = "--floe-window-shadow", C = [
1
+ import { builtInShellThemePresets as z, REQUIRED_SHELL_THEME_TOKENS as M } from "./presets.js";
2
+ import { resolveFloeThemeDocument as C, readFloeThemeDocument as F } from "./themeDocument.js";
3
+ const O = 128 * 1024, h = "--floe-window-shadow", B = [
4
4
  ...new Set(
5
5
  z.flatMap((t) => Object.keys(t.semanticTokens ?? {}))
6
6
  )
7
- ].filter((t) => t !== h).sort(), j = new Set(C), T = [
7
+ ].filter((t) => t !== h).sort(), T = new Set(B), A = [
8
8
  "background",
9
9
  "foreground",
10
10
  "cursor",
@@ -15,7 +15,7 @@ const x = 128 * 1024, h = "--floe-window-shadow", C = [
15
15
  t,
16
16
  `bright${t[0].toUpperCase()}${t.slice(1)}`
17
17
  ])
18
- ], F = /* @__PURE__ */ new Set([
18
+ ], I = /* @__PURE__ */ new Set([
19
19
  "--background",
20
20
  "--foreground",
21
21
  "--primary",
@@ -31,39 +31,42 @@ const x = 128 * 1024, h = "--floe-window-shadow", C = [
31
31
  "--warning",
32
32
  "--error",
33
33
  "--info"
34
- ]), I = N.filter((t) => t !== h), R = /^(?:100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%$/, A = /^#[a-f\d]{6}(?:[a-f\d]{2})?$/i, E = /^rgb\((?:\d{1,3} ){2}\d{1,3}(?: \/ (?:100|\d{1,2})%)?\)$/, B = /^(?:hsl\(\d{1,3} \d{1,3}% \d{1,3}%\)|oklch\((?:0(?:\.\d+)?|1) 0(?:\.\d+)? \d{1,3}\))$/, L = /^var\((--[a-z0-9-]+)\)$/, _ = /^color-mix\(in srgb, (var\(--[a-z0-9-]+\)|#[a-fA-F0-9]{6}) (\d{1,3}%), (var\(--[a-z0-9-]+\)|white|#[a-fA-F0-9]{6})\)$/, a = (t) => {
34
+ ]), R = M.filter((t) => t !== h), L = /^(?:100(?:\.0+)?|\d{1,2}(?:\.\d+)?)%$/, S = /^#[a-f\d]{6}(?:[a-f\d]{2})?$/i, E = /^rgb\((?:\d{1,3} ){2}\d{1,3}(?: \/ (?:100|\d{1,2})%)?\)$/, W = /^(?:hsl\(\d{1,3} \d{1,3}% \d{1,3}%\)|oklch\((?:0(?:\.\d+)?|1) 0(?:\.\d+)? \d{1,3}\))$/, _ = /^var\((--[a-z0-9-]+)\)$/, K = /^color-mix\(in srgb, (var\(--[a-z0-9-]+\)|#[a-fA-F0-9]{6}) (\d{1,3}%), (var\(--[a-z0-9-]+\)|white|#[a-fA-F0-9]{6})\)$/, c = (t) => {
35
35
  throw new Error(t);
36
- }, w = (t) => !!t && typeof t == "object" && !Array.isArray(t), O = (t, r, n) => {
37
- for (const s of Object.keys(t))
38
- r.includes(s) || a(`${n}.${s.slice(0, 80)}`);
36
+ }, w = (t) => !!t && typeof t == "object" && !Array.isArray(t), x = (t, r, o) => {
37
+ for (const n of Object.keys(t))
38
+ r.includes(n) || c(`${o}.${n.slice(0, 80)}`);
39
39
  }, $ = (t) => t === 0 ? "0" : `${t}px`;
40
- function K(t) {
40
+ function P(t) {
41
41
  return t === "none" ? [] : t.split(", ").map((r) => {
42
- const n = /^(-?\d+)(?:px)? (-?\d+)(?:px)? (\d+)(?:px)?(?: (-?\d+)(?:px)?)? (.+)$/.exec(
42
+ const o = /^(-?\d+)(?:px)? (-?\d+)(?:px)? (\d+)(?:px)?(?: (-?\d+)(?:px)?)? (.+)$/.exec(
43
43
  r
44
44
  );
45
- return n ? {
46
- x: +n[1],
47
- y: +n[2],
48
- blur: +n[3],
49
- spread: Number(n[4] ?? 0),
50
- color: n[5]
51
- } : a(h);
45
+ return o ? {
46
+ x: +o[1],
47
+ y: +o[2],
48
+ blur: +o[3],
49
+ spread: Number(o[4] ?? 0),
50
+ color: o[5]
51
+ } : c(h);
52
52
  });
53
53
  }
54
- function P(t) {
55
- const r = t.mode;
56
- if (r !== "light" && r !== "dark") return a("mode");
57
- const n = t.monaco?.[r];
58
- if (!n) return a("editor");
59
- const s = Object.fromEntries(
54
+ const N = /* @__PURE__ */ new WeakMap();
55
+ function v(t) {
56
+ const r = N.get(t);
57
+ if (r) return structuredClone(r);
58
+ const o = t.mode;
59
+ if (o !== "light" && o !== "dark") return c("mode");
60
+ const n = t.monaco?.[o];
61
+ if (!n) return c("editor");
62
+ const a = Object.fromEntries(
60
63
  Object.entries(t.semanticTokens ?? {}).filter(
61
- (i) => typeof i[1] == "string"
64
+ (f) => typeof f[1] == "string"
62
65
  )
63
- ), d = K(s[h] ?? "none");
64
- delete s[h];
65
- const c = { ...n.colors };
66
- for (const [i, f] of Object.entries({
66
+ ), d = P(a[h] ?? "none");
67
+ delete a[h];
68
+ const i = { ...n.colors };
69
+ for (const [f, u] of Object.entries({
67
70
  "editor.background": "background",
68
71
  "editorGutter.background": "background",
69
72
  "editor.foreground": "foreground",
@@ -71,86 +74,86 @@ function P(t) {
71
74
  "editor.selectionBackground": "selection-bg",
72
75
  "editor.selectionForeground": "selection-fg"
73
76
  }))
74
- c[i] === s[`--${f}`] && (c[i] = `@${f}`);
77
+ i[f] === a[`--${u}`] && (i[f] = `@${u}`);
75
78
  return {
76
79
  version: 2,
77
80
  name: t.displayName,
78
- mode: r,
81
+ mode: o,
79
82
  features: [...t.features ?? []],
80
83
  palette: {},
81
- colors: s,
84
+ colors: a,
82
85
  shadow: d,
83
- editor: c,
84
- syntax: n.rules.map((i) => ({ ...i }))
86
+ editor: i,
87
+ syntax: n.rules.map((f) => ({ ...f }))
85
88
  };
86
89
  }
87
- function b(t, r, n, s) {
88
- return !w(t) || Object.keys(t).length > s ? a(r) : Object.fromEntries(
89
- Object.entries(t).map(([d, c]) => !n(d) || typeof c != "string" || c.length > 256 ? a(`${r}.${d.slice(0, 80)}`) : [d, c])
90
+ function b(t, r, o, n) {
91
+ return !w(t) || Object.keys(t).length > n ? c(r) : Object.fromEntries(
92
+ Object.entries(t).map(([a, d]) => !o(a) || typeof d != "string" || d.length > 256 ? c(`${r}.${a.slice(0, 80)}`) : [a, d])
90
93
  );
91
94
  }
92
- function S(t) {
93
- const r = /* @__PURE__ */ new Map(), n = /* @__PURE__ */ new Set(), s = (e, o) => {
95
+ function j(t) {
96
+ const r = /* @__PURE__ */ new Map(), o = /* @__PURE__ */ new Set(), n = (e, s) => {
94
97
  if (!e.startsWith("$") && !e.startsWith("@")) return e;
95
98
  const m = r.get(e);
96
99
  if (m !== void 0) return m;
97
100
  const l = e.startsWith("$") ? t.palette : t.colors, y = (e.startsWith("@") ? "--" : "") + e.slice(1);
98
- if (!Object.hasOwn(l, y) || n.has(e)) return a(`${o}: ${e}`);
99
- n.add(e);
100
- const p = s(l[y], o);
101
- return n.delete(e), r.set(e, p), p;
102
- }, d = (e, o, m) => {
103
- const l = s(e, o);
104
- return A.test(l) || m && (E.test(l) || B.test(l) || L.test(l) || _.test(l)) ? l : a(o);
101
+ if (!Object.hasOwn(l, y) || o.has(e)) return c(`${s}: ${e}`);
102
+ o.add(e);
103
+ const p = n(l[y], s);
104
+ return o.delete(e), r.set(e, p), p;
105
+ }, a = (e, s, m) => {
106
+ const l = n(e, s);
107
+ return S.test(l) || m && (E.test(l) || W.test(l) || _.test(l) || K.test(l)) ? l : c(s);
105
108
  };
106
- for (const [e, o] of Object.entries(t.palette)) d(o, `palette.${e}`, !1);
107
- const c = Object.fromEntries(
108
- Object.entries(t.colors).map(([e, o]) => [
109
+ for (const [e, s] of Object.entries(t.palette)) a(s, `palette.${e}`, !1);
110
+ const d = Object.fromEntries(
111
+ Object.entries(t.colors).map(([e, s]) => [
109
112
  e,
110
- e === "--floe-progress-primary-white-mix" ? R.test(o) ? o : a(e) : d(o, `colors.${e}`, !F.has(e))
113
+ e === "--floe-progress-primary-white-mix" ? L.test(s) ? s : c(e) : a(s, `colors.${e}`, !I.has(e))
111
114
  ])
112
115
  );
113
- for (const [e, o] of Object.entries(t.terminal ?? {}))
114
- c[`--terminal-${e.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}`] = d(
115
- o,
116
+ for (const [e, s] of Object.entries(t.terminal ?? {}))
117
+ d[`--terminal-${e.replace(/[A-Z]/g, (m) => `-${m.toLowerCase()}`)}`] = a(
118
+ s,
116
119
  `terminal.${e}`,
117
120
  !1
118
121
  );
119
- for (const [e, o] of Object.entries(t.parts ?? {}))
120
- c[`--theme-part-${e}`] = d(o, `parts.${e}`, !1);
122
+ for (const [e, s] of Object.entries(t.parts ?? {}))
123
+ d[`--theme-part-${e}`] = a(s, `parts.${e}`, !1);
121
124
  const i = /* @__PURE__ */ new Set(), f = (e) => {
122
125
  if (!i.has(e)) {
123
- (n.has(e) || !Object.hasOwn(c, e)) && a(`colors.${e}`), n.add(e);
124
- for (const o of c[e].matchAll(/var\((--[a-z0-9-]+)\)/g)) f(o[1]);
125
- n.delete(e), i.add(e);
126
+ (o.has(e) || !Object.hasOwn(d, e)) && c(`colors.${e}`), o.add(e);
127
+ for (const s of d[e].matchAll(/var\((--[a-z0-9-]+)\)/g)) f(s[1]);
128
+ o.delete(e), i.add(e);
126
129
  }
127
130
  };
128
- for (const e of Object.keys(c)) f(e);
129
- c[h] = t.shadow.map(({ x: e, y: o, blur: m, spread: l, color: y }, p) => {
130
- const k = s(y, `shadow.${p}.color`);
131
- return !A.test(k) && !E.test(k) && a(`shadow.${p}.color`), [
131
+ for (const e of Object.keys(d)) f(e);
132
+ d[h] = t.shadow.map(({ x: e, y: s, blur: m, spread: l, color: y }, p) => {
133
+ const k = n(y, `shadow.${p}.color`);
134
+ return !S.test(k) && !E.test(k) && c(`shadow.${p}.color`), [
132
135
  $(e),
133
- $(o),
136
+ $(s),
134
137
  $(m),
135
138
  ...l ? [$(l)] : [],
136
139
  k
137
140
  ].join(" ");
138
141
  }).join(", ") || "none";
139
142
  const u = Object.fromEntries(
140
- Object.entries(t.editor).map(([e, o]) => [e, d(o, `editor.${e}`, !1)])
141
- ), g = t.syntax.map((e, o) => {
142
- const m = d(e.foreground, `syntax.${o}.foreground`, !1);
143
- return m.length !== 7 && a(`syntax.${o}.foreground`), { ...e, foreground: m };
143
+ Object.entries(t.editor).map(([e, s]) => [e, a(s, `editor.${e}`, !1)])
144
+ ), g = t.syntax.map((e, s) => {
145
+ const m = a(e.foreground, `syntax.${s}.foreground`, !1);
146
+ return m.length !== 7 && c(`syntax.${s}.foreground`), { ...e, foreground: m };
144
147
  });
145
- return { tokens: c, editor: u, syntax: g };
148
+ return { tokens: d, editor: u, syntax: g };
146
149
  }
147
- function W(t) {
148
- typeof t == "string" && (t.length > x || new TextEncoder().encode(t).length > x) && a("128 KiB");
150
+ function D(t) {
151
+ typeof t == "string" && (t.length > O || new TextEncoder().encode(t).length > O) && c("128 KiB");
149
152
  const r = typeof t == "string" ? JSON.parse(t) : t;
150
- if (!w(r)) return a("theme");
153
+ if (!w(r)) return c("theme");
151
154
  if (r.version === 1)
152
- return P(v("migration", M(r)));
153
- if (O(
155
+ return v(C("migration", F(r)));
156
+ if (x(
154
157
  r,
155
158
  [
156
159
  "version",
@@ -166,37 +169,37 @@ function W(t) {
166
169
  "parts"
167
170
  ],
168
171
  "theme"
169
- ), r.version !== 2) return a("version");
172
+ ), r.version !== 2) return c("version");
170
173
  if (typeof r.name != "string" || !r.name.trim() || r.name.length > 80 || /[\p{Cc}\p{Cf}]/u.test(r.name))
171
- return a("name");
172
- if (r.mode !== "light" && r.mode !== "dark") return a("mode");
174
+ return c("name");
175
+ if (r.mode !== "light" && r.mode !== "dark") return c("mode");
173
176
  if (!Array.isArray(r.features) || r.features.length > 32 || r.features.some(
174
177
  (e) => typeof e != "string" || !/^[a-z][a-z0-9-]{0,63}$/.test(e)
175
178
  ) || new Set(r.features).size !== r.features.length)
176
- return a("features");
177
- const n = b(
179
+ return c("features");
180
+ const o = b(
178
181
  r.palette,
179
182
  "palette",
180
183
  (e) => /^[a-z][a-z0-9-]{0,63}$/.test(e),
181
184
  256
182
- ), s = b(r.colors, "colors", (e) => j.has(e), j.size);
183
- for (const e of I) Object.hasOwn(s, e) || a(`colors.${e}`);
184
- if (!Array.isArray(r.shadow) || r.shadow.length > 8) return a("shadow");
185
- const d = r.shadow.map((e, o) => {
186
- if (!w(e)) return a(`shadow.${o}`);
187
- O(e, ["x", "y", "blur", "spread", "color"], `shadow.${o}`);
185
+ ), n = b(r.colors, "colors", (e) => T.has(e), T.size);
186
+ for (const e of R) Object.hasOwn(n, e) || c(`colors.${e}`);
187
+ if (!Array.isArray(r.shadow) || r.shadow.length > 8) return c("shadow");
188
+ const a = r.shadow.map((e, s) => {
189
+ if (!w(e)) return c(`shadow.${s}`);
190
+ x(e, ["x", "y", "blur", "spread", "color"], `shadow.${s}`);
188
191
  for (const m of ["x", "y", "blur", "spread"]) {
189
192
  const l = e[m];
190
- (typeof l != "number" || !Number.isFinite(l) || Math.abs(l) > 256 || m === "blur" && l < 0) && a(`shadow.${o}.${m}`);
193
+ (typeof l != "number" || !Number.isFinite(l) || Math.abs(l) > 256 || m === "blur" && l < 0) && c(`shadow.${s}.${m}`);
191
194
  }
192
- return typeof e.color != "string" || e.color.length > 100 ? a(`shadow.${o}.color`) : {
195
+ return typeof e.color != "string" || e.color.length > 100 ? c(`shadow.${s}.color`) : {
193
196
  x: Number(e.x),
194
197
  y: Number(e.y),
195
198
  blur: Number(e.blur),
196
199
  spread: Number(e.spread),
197
200
  color: e.color
198
201
  };
199
- }), c = b(
202
+ }), d = b(
200
203
  r.editor,
201
204
  "editor",
202
205
  (e) => /^[a-zA-Z][\w-]{0,79}(?:\.[\w-]{1,80}){1,5}$/.test(e),
@@ -204,11 +207,11 @@ function W(t) {
204
207
  ), i = r.terminal === void 0 ? void 0 : b(
205
208
  r.terminal,
206
209
  "terminal",
207
- (e) => T.includes(e),
208
- T.length
210
+ (e) => A.includes(e),
211
+ A.length
209
212
  ), f = r.parts === void 0 ? void 0 : b(r.parts, "parts", (e) => /^[a-z][a-z0-9-]{0,79}$/.test(e), 256);
210
- if (!Array.isArray(r.syntax) || r.syntax.length > 512) return a("syntax");
211
- const u = r.syntax.map((e, o) => !w(e) || typeof e.token != "string" || !/^[\w.-]{0,128}$/.test(e.token) || typeof e.foreground != "string" || e.foreground.length > 128 ? a(`syntax.${o}`) : (O(e, ["token", "foreground", "fontStyle"], `syntax.${o}`), e.fontStyle !== void 0 && (typeof e.fontStyle != "string" || !/^(?:(?:bold|italic|underline|strikethrough)(?: |$)){0,4}$/.test(e.fontStyle)) ? a(`syntax.${o}.fontStyle`) : {
213
+ if (!Array.isArray(r.syntax) || r.syntax.length > 512) return c("syntax");
214
+ const u = r.syntax.map((e, s) => !w(e) || typeof e.token != "string" || !/^[\w.-]{0,128}$/.test(e.token) || typeof e.foreground != "string" || e.foreground.length > 128 ? c(`syntax.${s}`) : (x(e, ["token", "foreground", "fontStyle"], `syntax.${s}`), e.fontStyle !== void 0 && (typeof e.fontStyle != "string" || !/^(?:(?:bold|italic|underline|strikethrough)(?: |$)){0,4}$/.test(e.fontStyle)) ? c(`syntax.${s}.fontStyle`) : {
212
215
  token: e.token,
213
216
  foreground: e.foreground,
214
217
  ...typeof e.fontStyle == "string" ? { fontStyle: e.fontStyle } : {}
@@ -217,73 +220,84 @@ function W(t) {
217
220
  name: r.name.trim(),
218
221
  mode: r.mode,
219
222
  features: [...r.features],
220
- palette: n,
221
- colors: s,
222
- shadow: d,
223
- editor: c,
223
+ palette: o,
224
+ colors: n,
225
+ shadow: a,
226
+ editor: d,
224
227
  syntax: u,
225
228
  ...i && { terminal: i },
226
229
  ...f && { parts: f }
227
230
  };
228
231
  return new TextEncoder().encode(JSON.stringify(g, null, 2) + `
229
- `).length > x && a("128 KiB"), S(g), g;
232
+ `).length > O && c("128 KiB"), j(g), g;
230
233
  }
231
- function J(t) {
232
- const { tokens: r } = S(t), n = (i) => [1, 3, 5, 7].map(
234
+ function U(t) {
235
+ const { tokens: r } = j(t), o = (i) => [1, 3, 5, 7].map(
233
236
  (f, u) => u === 3 && i.length === 7 ? 1 : parseInt(i.slice(f, f + 2), 16) / 255
234
- ), s = (i, f) => i.slice(0, 3).map((u, g) => u * i[3] + f[g] * (1 - i[3])), d = (i) => i.reduce(
237
+ ), n = (i, f) => i.slice(0, 3).map((u, g) => u * i[3] + f[g] * (1 - i[3])), a = (i) => i.reduce(
235
238
  (f, u, g) => f + [0.2126, 0.7152, 0.0722][g] * (u <= 0.04045 ? u / 12.92 : ((u + 0.055) / 1.055) ** 2.4),
236
239
  0
237
- ), c = s(n(r["--background"]), Array(3).fill(t.mode === "light" ? 1 : 0));
240
+ ), d = n(o(r["--background"]), Array(3).fill(t.mode === "light" ? 1 : 0));
238
241
  for (const [i, f] of [
239
242
  ["--background", "--foreground"],
240
243
  ["--card", "--card-foreground"],
241
244
  ["--primary", "--primary-foreground"],
242
245
  ["--sidebar", "--sidebar-foreground"]
243
246
  ]) {
244
- const u = i === "--background" ? c : s(n(r[i]), c), g = d(u), e = d(s(n(r[f]), u)), o = (Math.max(g, e) + 0.05) / (Math.min(g, e) + 0.05);
245
- if (o < 4.5) return `${f} / ${i}: ${o.toFixed(2)}:1 < 4.5:1`;
247
+ const u = i === "--background" ? d : n(o(r[i]), d), g = a(u), e = a(n(o(r[f]), u)), s = (Math.max(g, e) + 0.05) / (Math.min(g, e) + 0.05);
248
+ if (s < 4.5) return `${f} / ${i}: ${s.toFixed(2)}:1 < 4.5:1`;
246
249
  }
247
250
  }
248
- function U(t, r) {
249
- const n = W(r), { tokens: s, editor: d, syntax: c } = S(n);
250
- return {
251
+ function Z(t, r) {
252
+ const o = D(r), { tokens: n, editor: a, syntax: d } = j(o), i = {
251
253
  name: t,
252
- displayName: n.name,
253
- mode: n.mode,
254
- features: n.features,
255
- semanticTokens: s,
256
- tokens: { [n.mode]: s },
254
+ displayName: o.name,
255
+ mode: o.mode,
256
+ features: o.features,
257
+ semanticTokens: n,
258
+ tokens: { [o.mode]: n },
257
259
  preview: {
258
- background: s["--background"],
259
- surface: s["--card"],
260
- sidebar: s["--sidebar"],
261
- primary: s["--primary"],
262
- border: s["--border"],
260
+ background: n["--background"],
261
+ surface: n["--card"],
262
+ sidebar: n["--sidebar"],
263
+ primary: n["--primary"],
264
+ border: n["--border"],
263
265
  colors: [
264
- s["--chart-1"],
265
- s["--chart-2"],
266
- s["--chart-3"],
267
- s["--chart-4"],
268
- s["--chart-5"]
266
+ n["--chart-1"],
267
+ n["--chart-2"],
268
+ n["--chart-3"],
269
+ n["--chart-4"],
270
+ n["--chart-5"]
269
271
  ]
270
272
  },
271
273
  monaco: {
272
- [n.mode]: {
273
- base: n.mode === "light" ? "vs" : "vs-dark",
274
+ [o.mode]: {
275
+ base: o.mode === "light" ? "vs" : "vs-dark",
274
276
  inherit: !0,
275
- colors: d,
276
- rules: c
277
+ colors: a,
278
+ rules: d
277
279
  }
278
280
  }
279
281
  };
282
+ return N.set(i, o), i;
283
+ }
284
+ function q(t, r) {
285
+ const o = z.find((a) => a.mode === t && a.inheritsBaseTokens), n = v(o);
286
+ n.name = r;
287
+ for (const [a, d] of Object.entries(n.colors)) {
288
+ if (!S.test(d)) continue;
289
+ const i = a.slice(2);
290
+ n.palette[i] = d, n.colors[a] = `$${i}`;
291
+ }
292
+ return n;
280
293
  }
281
294
  export {
282
- x as PORTABLE_THEME_LIMIT,
283
- P as exportShellTheme,
284
- J as portableContrastIssue,
285
- W as readPortableShellTheme,
286
- U as resolvePortableShellTheme,
287
- C as shellColorRoles,
288
- T as terminalThemeRoles
295
+ O as PORTABLE_THEME_LIMIT,
296
+ q as createBlankShellTheme,
297
+ v as exportShellTheme,
298
+ U as portableContrastIssue,
299
+ D as readPortableShellTheme,
300
+ Z as resolvePortableShellTheme,
301
+ B as shellColorRoles,
302
+ A as terminalThemeRoles
289
303
  };