cssints 0.0.0-stage → 0.2.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.
Files changed (148) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +188 -2
  3. package/dist/author-types-C1AhsnrT.d.mts +80 -0
  4. package/dist/check.d.mts +22 -0
  5. package/dist/check.mjs +37 -0
  6. package/dist/color-BYIxVLlS.mjs +29 -0
  7. package/dist/color-C8OzjAeg.mjs +2 -0
  8. package/dist/contrast-DhK69Xak.mjs +83 -0
  9. package/dist/derived.d.mts +14 -0
  10. package/dist/derived.mjs +391 -0
  11. package/dist/errors-D4ZbcwRo.d.mts +32 -0
  12. package/dist/frame-BoBKjgBB.mjs +92 -0
  13. package/dist/frame.d.mts +72 -0
  14. package/dist/frame.mjs +2 -0
  15. package/dist/group-common-9zpBxfUF.d.mts +1 -0
  16. package/dist/group-types-9ttphdku.d.mts +55 -0
  17. package/dist/groups/compositing-2.d.mts +20 -0
  18. package/dist/groups/css-align-3.d.mts +29 -0
  19. package/dist/groups/css-anchor-position-1.d.mts +49 -0
  20. package/dist/groups/css-anchor-position-2.d.mts +50 -0
  21. package/dist/groups/css-animations-1.d.mts +28 -0
  22. package/dist/groups/css-animations-2.d.mts +29 -0
  23. package/dist/groups/css-backgrounds-3.d.mts +27 -0
  24. package/dist/groups/css-backgrounds-4.d.mts +29 -0
  25. package/dist/groups/css-borders-4.d.mts +95 -0
  26. package/dist/groups/css-box-4.d.mts +38 -0
  27. package/dist/groups/css-break-4.d.mts +23 -0
  28. package/dist/groups/css-cascade-5.d.mts +18 -0
  29. package/dist/groups/css-cascade-6.d.mts +18 -0
  30. package/dist/groups/css-color-4.d.mts +29 -0
  31. package/dist/groups/css-color-5.d.mts +32 -0
  32. package/dist/groups/css-color-6.d.mts +32 -0
  33. package/dist/groups/css-color-adjust-1.d.mts +20 -0
  34. package/dist/groups/css-color-hdr-1.d.mts +19 -0
  35. package/dist/groups/css-conditional-3.d.mts +17 -0
  36. package/dist/groups/css-conditional-4.d.mts +17 -0
  37. package/dist/groups/css-conditional-5.d.mts +22 -0
  38. package/dist/groups/css-contain-2.d.mts +19 -0
  39. package/dist/groups/css-content-3.d.mts +23 -0
  40. package/dist/groups/css-counter-styles-3.d.mts +16 -0
  41. package/dist/groups/css-display-4.d.mts +22 -0
  42. package/dist/groups/css-easing-2.d.mts +18 -0
  43. package/dist/groups/css-env-1.d.mts +16 -0
  44. package/dist/groups/css-flexbox-1.d.mts +24 -0
  45. package/dist/groups/css-fonts-4.d.mts +46 -0
  46. package/dist/groups/css-fonts-5.d.mts +44 -0
  47. package/dist/groups/css-forms-1.d.mts +19 -0
  48. package/dist/groups/css-gaps-1.d.mts +21 -0
  49. package/dist/groups/css-gcpm-3.d.mts +20 -0
  50. package/dist/groups/css-gcpm-4.d.mts +20 -0
  51. package/dist/groups/css-grid-2.d.mts +34 -0
  52. package/dist/groups/css-grid-3.d.mts +34 -0
  53. package/dist/groups/css-images-3.d.mts +25 -0
  54. package/dist/groups/css-images-4.d.mts +32 -0
  55. package/dist/groups/css-images-5.d.mts +33 -0
  56. package/dist/groups/css-inline-3.d.mts +28 -0
  57. package/dist/groups/css-lists-3.d.mts +26 -0
  58. package/dist/groups/css-logical-1.d.mts +35 -0
  59. package/dist/groups/css-masking-1.d.mts +37 -0
  60. package/dist/groups/css-multicol-2.d.mts +24 -0
  61. package/dist/groups/css-overflow-3.d.mts +28 -0
  62. package/dist/groups/css-overflow-4.d.mts +29 -0
  63. package/dist/groups/css-overflow-5.d.mts +31 -0
  64. package/dist/groups/css-overscroll-1.d.mts +22 -0
  65. package/dist/groups/css-page-3.d.mts +18 -0
  66. package/dist/groups/css-page-floats-3.d.mts +19 -0
  67. package/dist/groups/css-position-3.d.mts +29 -0
  68. package/dist/groups/css-position-4.d.mts +30 -0
  69. package/dist/groups/css-rhythm-1.d.mts +18 -0
  70. package/dist/groups/css-round-display-1.d.mts +16 -0
  71. package/dist/groups/css-ruby-1.d.mts +21 -0
  72. package/dist/groups/css-scroll-anchoring-1.d.mts +18 -0
  73. package/dist/groups/css-scroll-snap-1.d.mts +42 -0
  74. package/dist/groups/css-scroll-snap-2.d.mts +43 -0
  75. package/dist/groups/css-scrollbars-1.d.mts +19 -0
  76. package/dist/groups/css-shapes-1.d.mts +27 -0
  77. package/dist/groups/css-shapes-2.d.mts +27 -0
  78. package/dist/groups/css-size-adjust-1.d.mts +18 -0
  79. package/dist/groups/css-sizing-3.d.mts +34 -0
  80. package/dist/groups/css-sizing-4.d.mts +33 -0
  81. package/dist/groups/css-speech-1.d.mts +18 -0
  82. package/dist/groups/css-tables-3.d.mts +22 -0
  83. package/dist/groups/css-text-3.d.mts +36 -0
  84. package/dist/groups/css-text-4.d.mts +40 -0
  85. package/dist/groups/css-text-decor-3.d.mts +30 -0
  86. package/dist/groups/css-text-decor-4.d.mts +31 -0
  87. package/dist/groups/css-transforms-1.d.mts +31 -0
  88. package/dist/groups/css-transforms-2.d.mts +48 -0
  89. package/dist/groups/css-transitions-1.d.mts +22 -0
  90. package/dist/groups/css-transitions-2.d.mts +23 -0
  91. package/dist/groups/css-ui-4.d.mts +35 -0
  92. package/dist/groups/css-values-4.d.mts +38 -0
  93. package/dist/groups/css-values-5.d.mts +43 -0
  94. package/dist/groups/css-variables-2.d.mts +6 -0
  95. package/dist/groups/css-view-transitions-2.d.mts +20 -0
  96. package/dist/groups/css-viewport.d.mts +18 -0
  97. package/dist/groups/css-will-change-1.d.mts +18 -0
  98. package/dist/groups/css-writing-modes-4.d.mts +22 -0
  99. package/dist/groups/css2.d.mts +19 -0
  100. package/dist/groups/fill-stroke-3.d.mts +27 -0
  101. package/dist/groups/filter-effects-1.d.mts +32 -0
  102. package/dist/groups/filter-effects-2.d.mts +33 -0
  103. package/dist/groups/limited-availability.d.mts +2 -0
  104. package/dist/groups/mediaqueries-4.d.mts +16 -0
  105. package/dist/groups/mediaqueries-5.d.mts +16 -0
  106. package/dist/groups/motion-1.d.mts +24 -0
  107. package/dist/groups/newly-available.d.mts +631 -0
  108. package/dist/groups/not-discouraged.d.mts +727 -0
  109. package/dist/groups/scroll-animations-1.d.mts +30 -0
  110. package/dist/groups/selectors-4.d.mts +54 -0
  111. package/dist/groups/selectors-5.d.mts +54 -0
  112. package/dist/groups/widely-available.d.mts +616 -0
  113. package/dist/index.d.mts +48 -0
  114. package/dist/index.mjs +1269 -0
  115. package/dist/instrument-gCazujmb.mjs +1624 -0
  116. package/dist/lowered-D2KusPLp.mjs +28 -0
  117. package/dist/node-OJ_w_Usj.d.mts +233 -0
  118. package/dist/parent-vars.d.mts +13 -0
  119. package/dist/parent-vars.mjs +65 -0
  120. package/dist/plugin-types.d.mts +377 -0
  121. package/dist/plugin.d.mts +3 -0
  122. package/dist/plugin.mjs +30 -0
  123. package/dist/registry-CTumHB8p.mjs +73 -0
  124. package/dist/runtime-Dt4Tm0Q7.d.mts +19 -0
  125. package/dist/runtime.d.mts +18 -0
  126. package/dist/runtime.mjs +25 -0
  127. package/dist/scope-ZVhUxQH1.d.mts +2101 -0
  128. package/dist/sheet-BKsMTa0c.mjs +757 -0
  129. package/dist/surface.d.mts +228 -0
  130. package/dist/surface.mjs +101 -0
  131. package/dist/theme-BsP2E4LB.mjs +929 -0
  132. package/dist/theme-types-Bqv0Ggz_.d.mts +1808 -0
  133. package/dist/trace-otlp-CbKFDsn9.mjs +14 -0
  134. package/dist/tui-types.d.mts +181 -0
  135. package/dist/tui.d.mts +23 -0
  136. package/dist/tui.mjs +427 -0
  137. package/dist/types.d.mts +2 -0
  138. package/dist/vite.d.mts +134 -0
  139. package/dist/vite.mjs +977 -0
  140. package/docs/API.md +1193 -0
  141. package/package.json +85 -4
  142. package/skills/cssints/SKILL.md +203 -0
  143. package/skills/cssints/references/errors.md +86 -0
  144. package/skills/cssints/references/plugins.md +91 -0
  145. package/skills/cssints/references/tokens.md +91 -0
  146. package/skills/cssints-plugin/SKILL.md +177 -0
  147. package/skills/cssints-plugin/references/table.md +124 -0
  148. package/skills/cssints-plugin/references/testing.md +122 -0
package/dist/index.mjs ADDED
@@ -0,0 +1,1269 @@
1
+ import { a as registry, d as MacroError, f as MemberError, o as warn, r as forgetKernels, t as Registry } from "./registry-CTumHB8p.mjs";
2
+ import { A as camel, C as hashClass, D as settled, E as minWidth, F as probed, M as failIn, N as isNode, O as toDecls, P as node, S as edge, T as merged, _ as PSEUDOS, a as createTokens, b as checkVars, c as tokensOf, d as style, f as token, g as PROPS, h as LAYER, i as createGlobalTheme, j as fail, k as VAR, l as CSSTokenValue, m as FUNCTIONS, n as addTheme, o as isDone, p as CONTEXTS, r as check$1, t as DONE, u as isStyle, v as carried, w as isFallback, x as dropsOf, y as chainDecl } from "./theme-BsP2E4LB.mjs";
3
+ import { D as relation, S as addRuntime, _ as addKernel, i as byOrder, n as addGlobal, r as addLayers, y as kernelWarnings } from "./sheet-BKsMTa0c.mjs";
4
+ import { n as loweredOf } from "./lowered-D2KusPLp.mjs";
5
+ import { n as CX_CALL, s as groups$1, t as CV_CALL } from "./instrument-gCazujmb.mjs";
6
+ import { checkDeclarationNow, checkQuery, checkSelector, checkValueNow, isDeclarationError } from "@cssints/css-grammar/check";
7
+ import { lackingOf, messageOf } from "@cssints/css-grammar/support";
8
+ import { CSS, CSSColorValue, CSSImageValue, CSSStyleValue, CSSStyleValue as CSSStyleValue$1, CSSUnitValue } from "@cssints/css-grammar/values";
9
+ import { Cause, Effect, Exit, Formatter, Predicate, Result, Schema } from "effect";
10
+ import { createHash } from "node:crypto";
11
+ import { functions } from "@cssints/css-grammar/functions";
12
+ import { properties } from "@cssints/css-grammar/mdn";
13
+ import { grammarOf } from "@cssints/css-grammar/token";
14
+ import { checkSelectorNow } from "@cssints/css-grammar/selector";
15
+ //#region src/functions.ts
16
+ var CSSFunctionValue = class extends CSSStyleValue$1 {
17
+ value;
18
+ constructor(value) {
19
+ super();
20
+ this.value = value;
21
+ }
22
+ toString() {
23
+ return this.value;
24
+ }
25
+ };
26
+ const MATH = "<number> | <length-percentage> | <angle-percentage> | <time> | <resolution>";
27
+ const OPERATORS = /* @__PURE__ */ new Set([
28
+ "+",
29
+ "-",
30
+ "*",
31
+ "/"
32
+ ]);
33
+ const isGroup$1 = (p) => Array.isArray(p);
34
+ const build = (member, name) => {
35
+ const { sep, math } = functions[name];
36
+ const grammar = math ? MATH : `<${name}()>`;
37
+ return (...parts) => {
38
+ const atom = (p) => {
39
+ if (typeof p === "string") checkVars(`${member}()`, p);
40
+ else if (typeof p !== "number" && !(p instanceof CSSStyleValue$1)) throw fail(`cssints: ${member}() takes strings, numbers and Typed OM values (tokens, other calls), got ${Formatter.formatJson(p)}`);
41
+ return String(p);
42
+ };
43
+ const texts = parts.map((p, i) => isGroup$1(p) ? p.map(atom).join(" ") : name === "var" && !i && p instanceof CSSTokenValue ? p.name : atom(p));
44
+ const join = (ts) => ts.reduce((acc, t, i) => i ? `${acc}${OPERATORS.has(t) || OPERATORS.has(ts[i - 1]) ? " " : sep}${t}` : t, "");
45
+ const value = `${name}(${join(texts)})`;
46
+ const first = parts[0];
47
+ if (name === "var") {
48
+ if (!registry.properties.has(texts[0] ?? "")) throw fail(`cssints: var() takes a token and an optional fallback, got ${Formatter.formatJson(texts[0])}`);
49
+ if (first instanceof CSSTokenValue && texts.length > 1) checkText(`var(${first.name}) fallback`, `<${first.syntax}>`, texts.slice(1).join(sep));
50
+ } else checkText(`${name}()`, grammar, value, math ? void 0 : () => argumentOf(name, grammar, texts, sep, join));
51
+ return new CSSFunctionValue(value);
52
+ };
53
+ };
54
+ const argumentOf = (name, grammar, texts, sep, join) => {
55
+ const fits = (s) => {
56
+ try {
57
+ checkValueNow(name, grammar, s);
58
+ return true;
59
+ } catch (e) {
60
+ if (!isDeclarationError(e)) throw e;
61
+ return false;
62
+ }
63
+ };
64
+ const i = texts.findIndex((t, n) => probed(join(texts.slice(0, n + 1)), registry.properties).some((h) => !fits(`${name}(${h}${OPERATORS.has(t) ? " " : sep}var(--x))`) && !fits(`${name}(${h})`)));
65
+ return !texts.length ? "" : i < 0 ? ` (after argument ${texts.length})` : ` (argument ${i + 1})`;
66
+ };
67
+ const checkText = (label, grammar, text, where) => {
68
+ for (const v of probed(text, registry.properties)) try {
69
+ checkValueNow(label, grammar, v);
70
+ } catch (e) {
71
+ if (!isDeclarationError(e)) throw e;
72
+ throw new MacroError({
73
+ message: `${e.message.replace(`, expected ${MATH}`, "")}${where?.() ?? ""}${v === text ? "" : ` ("${text}" is checked as "${v}": a token stands for a value of its type)`}`,
74
+ cause: e,
75
+ ...registry.at
76
+ });
77
+ }
78
+ };
79
+ /** The members of `css` that are functions, by name. */
80
+ const fns = Object.fromEntries(Object.entries(FUNCTIONS).map(([member, name]) => [member, build(member, name)]));
81
+ //#endregion
82
+ //#region src/group.ts
83
+ const CONDITIONS = [
84
+ "media",
85
+ "container",
86
+ "supports"
87
+ ];
88
+ const TIED = /* @__PURE__ */ new Set([
89
+ ...Object.keys(PROPS),
90
+ ...Object.keys(FUNCTIONS),
91
+ ...Object.keys(PSEUDOS),
92
+ ...CONDITIONS,
93
+ "keyframes",
94
+ "positionTry"
95
+ ]);
96
+ const WORDS = /[^ ,)/:;"'<>=+*[\]{}!#%.⟨⟩&|\n\t(]+\(?/g;
97
+ const words = (s) => new Set(s ? s.split(" ") : []);
98
+ const groups = new Map(Object.entries(groups$1));
99
+ const compiled$1 = /* @__PURE__ */ new Map();
100
+ const compile$1 = (id) => {
101
+ const g = groups.get(id);
102
+ if (!g) throw fail(`cssints: no export group cssints/${id}`);
103
+ const members = words(g.members);
104
+ const units = g.ban.unit ? g.ban.unit.split(" ") : [];
105
+ return {
106
+ id,
107
+ members,
108
+ props: new Set([...members].flatMap((m) => PROPS[m] ? [PROPS[m]] : [])),
109
+ kw: new Map(Object.entries(g.ban.kw).map(([p, ws]) => [p, words(ws)])),
110
+ fn: new Set((g.ban.fn ? g.ban.fn.split(" ") : []).map((f) => `${f}(`)),
111
+ unit: units.length ? new RegExp(`^[0-9]+(?:e[0-9]+)?(?:${units.toSorted((a, b) => b.length - a.length).join("|")})$`) : void 0,
112
+ query: {
113
+ media: words(g.ban.media),
114
+ container: words(g.ban.container),
115
+ supports: words(g.ban.supports)
116
+ }
117
+ };
118
+ };
119
+ const hit = (c, own, text) => text.match(WORDS)?.find((w) => own?.has(w) || c.fn.has(w) || c.unit?.test(w));
120
+ const said = (w) => w.endsWith("(") ? `${w.slice(0, -1)}()` : w;
121
+ const refuse = (c, label, w) => fail(`cssints: ${label}: "${said(w)}" is not in cssints/${c.id}`);
122
+ const guard = (c, n) => {
123
+ for (const [prop, value, , fallbacks] of n.__cssints) {
124
+ const own = c.kw.get(prop);
125
+ for (const v of fallbacks ? [value, ...fallbacks] : [value]) {
126
+ const w = hit(c, own, v);
127
+ if (w) throw refuse(c, prop, w);
128
+ }
129
+ }
130
+ return n;
131
+ };
132
+ const chained = (c, n) => new Proxy(n, { get: (t, k) => {
133
+ const v = Reflect.get(t, k);
134
+ if (typeof k !== "string" || k in t || typeof v !== "function") return v;
135
+ return (...args) => {
136
+ const next = guard(c, v(...args));
137
+ const prop = next.__cssints.at(-1)?.[0];
138
+ if (prop && !c.props.has(prop)) throw fail(`cssints: ${prop} is not in cssints/${c.id} (.${k}())`);
139
+ return chained(c, next);
140
+ };
141
+ } });
142
+ const texts = (q) => typeof q === "string" ? [q] : q && typeof q === "object" ? Object.values(q).flatMap(texts) : [];
143
+ const wrap = (c, name, member) => {
144
+ const fn = member;
145
+ if (CONDITIONS.includes(name)) return (...qs) => {
146
+ const kind = name;
147
+ for (const q of qs.flatMap(texts)) {
148
+ const w = hit(c, c.query[kind], q);
149
+ if (w) throw refuse(c, `@${kind}`, w);
150
+ }
151
+ return fn(...qs);
152
+ };
153
+ if (!(name in PROPS) || typeof member !== "function") return member;
154
+ return (...args) => {
155
+ const made = fn(...args);
156
+ if (!isNode(made)) return made;
157
+ return name in CONTEXTS ? chained(c, guard(c, made)) : guard(c, made);
158
+ };
159
+ };
160
+ /**
161
+ * The members of an export group.
162
+ * @param {Record<string, unknown>} css `css` of macro.ts, passed in so that this file imports no engine module
163
+ * @param {string} id the group: `widely-available`, `css-grid-2`, ...
164
+ * @returns {Record<string, unknown>} `css` with the members of the group, as they are, and the ones it has not throwing, naming the group, when called
165
+ */
166
+ const groupOf = (css, id) => {
167
+ if (id === "limited-availability") return css;
168
+ const c = compiled$1.get(id) ?? compiled$1.set(id, compile$1(id)).get(id);
169
+ return new Proxy(css, { get: (t, k) => {
170
+ if (typeof k !== "string") return Reflect.get(t, k);
171
+ if (TIED.has(k) && !c.members.has(k)) return () => {
172
+ throw fail(`cssints: ${k} is not in cssints/${id}`);
173
+ };
174
+ return wrap(c, k, t[k]);
175
+ } });
176
+ };
177
+ //#endregion
178
+ //#region src/scope-engine.ts
179
+ const NAME$1 = /^[a-z][a-z0-9-]*$/;
180
+ const KEY = /^[A-Za-z][\w-]*$/;
181
+ const RESERVED = /* @__PURE__ */ new Set(["cssints", "derived"]);
182
+ const OWN_VAR = /--_([\w-]*)/g;
183
+ const MARKER = /&\(([\w.-]+)\)|&/g;
184
+ const isScope = (v) => !!v && typeof v === "object" && typeof v["~scope"] === "string";
185
+ const isRecord = (v) => !!v && typeof v === "object" && !isTyped(v);
186
+ const isTyped = (v) => !!v && typeof v === "object" && v["~arg"] === 1;
187
+ const strip = (k) => k.startsWith("#") ? k.slice(1) : k;
188
+ const isPrivate = (k) => k.startsWith("#");
189
+ const has = (v, k) => !!v && typeof v === "object" && Object.hasOwn(v, k);
190
+ const kindOf = (k, v) => {
191
+ if (typeof v === "string") return k.startsWith("-") ? "prop" : "alias";
192
+ if (isScope(v)) return "module";
193
+ if (has(v, "chain")) return "chain";
194
+ if (has(v, "args") && has(v, "value")) return "value";
195
+ if (has(v, "args")) return "call";
196
+ if (has(v, "tokens")) return "tokens";
197
+ if (has(v, "polyfills")) return "runtime";
198
+ if (has(v, "props")) return "conflicts";
199
+ if (has(v, "rule")) return "global";
200
+ if (has(v, "layers")) return "layers";
201
+ if (has(v, "css")) return "kernel";
202
+ return "?";
203
+ };
204
+ const expand = (g, a, depth = 0) => depth > 5 || !g.includes("<") ? g : g.replace(/<([^>]*)>/g, (m, n) => Object.hasOwn(a, n) ? `[ ${expand(a[n], a, depth + 1)} ]` : m);
205
+ const tokenSyntaxes = (tokens, prefix, out) => {
206
+ if (tokens && typeof tokens === "object") for (const [k, v] of Object.entries(tokens)) if (v && typeof v === "object" && typeof v["syntax"] === "string") out[`${prefix}${k}`] = grammarOf(v["syntax"]);
207
+ else tokenSyntaxes(v, `${prefix}${k}.`, out);
208
+ return out;
209
+ };
210
+ const canon = (v) => {
211
+ if (typeof v === "function") return v.toString();
212
+ if (v instanceof RegExp) return String(v);
213
+ if (isScope(v)) return `scope(${v.name},${canon(v["~text"])})`;
214
+ if (Array.isArray(v)) return `[${v.map(canon).join(",")}]`;
215
+ if (v && typeof v === "object") {
216
+ const json = v.toJSON;
217
+ if (typeof json === "function") return canon(json.call(v));
218
+ return `{${Object.entries(v).map(([k, x]) => `${JSON.stringify(k)}:${canon(x)}`).join(",")}}`;
219
+ }
220
+ return JSON.stringify(v) ?? "undefined";
221
+ };
222
+ const check = (plugin, label, grammar, value) => {
223
+ for (const v of probed(value, registry.properties)) Result.getOrThrowWith(Result.try({
224
+ try: () => checkValueNow(label, grammar, v),
225
+ catch: (e) => isDeclarationError(e) ? failIn(plugin, e.message) : e
226
+ }), (e) => e);
227
+ };
228
+ const valueOf = (plugin, label, args, spacing = false) => {
229
+ if (!args.length) throw failIn(plugin, `cssints: ${label}() expects a value`);
230
+ if (args.some(isNode)) throw failIn(plugin, `cssints: ${label}() takes values, not styles; merge styles with cn(...)`);
231
+ const [only] = args;
232
+ return spacing && args.length === 1 && typeof only === "number" ? `${only * .25}rem` : args.join(" ");
233
+ };
234
+ const ran = (plugin, run) => Result.getOrThrowWith(Result.try({
235
+ try: run,
236
+ catch: (e) => e instanceof MemberError ? e : failIn(plugin, e instanceof Error ? e.message : String(e))
237
+ }), (e) => e);
238
+ const thrown = (name, message) => failIn(name, `cssints: ${message}`);
239
+ var Compiler = class {
240
+ name;
241
+ table;
242
+ impl;
243
+ compiled;
244
+ carries = /* @__PURE__ */ new Map();
245
+ kernels = /* @__PURE__ */ new Map();
246
+ derived = /* @__PURE__ */ new Map();
247
+ sets = /* @__PURE__ */ new Map();
248
+ atRules = /* @__PURE__ */ new Map();
249
+ constructor(s, compiled) {
250
+ this.name = s.name;
251
+ this.table = s.table;
252
+ this.impl = s.impl;
253
+ this.compiled = compiled;
254
+ }
255
+ own = (s) => s.includes("--_") ? s.replace(OWN_VAR, (_, n) => `--${this.name}-${n}`) : s;
256
+ grammar = (g) => expand(g, this.compiled.aliases);
257
+ find(path) {
258
+ const dot = path.indexOf(".");
259
+ if (dot < 0) return [this, path];
260
+ const mod = this.table[path.slice(0, dot)];
261
+ if (!isScope(mod)) throw thrown(this.name, `${this.name}: ${path} is not an entry of this scope`);
262
+ return compile(mod).find(path.slice(dot + 1));
263
+ }
264
+ entry(key) {
265
+ const k = Object.hasOwn(this.table, key) ? key : `#${key}`;
266
+ const v = this.table[k];
267
+ return [kindOf(k, v), v];
268
+ }
269
+ marker = (path) => {
270
+ const [s, key] = this.find(path);
271
+ return `_${s.name}-${key}`;
272
+ };
273
+ mark = (css, own) => css.includes("&") ? css.replace(MARKER, (_, path) => `.${path ? this.marker(path) : own}`) : css;
274
+ kernel(key) {
275
+ let k = this.kernels.get(key);
276
+ if (k) return k;
277
+ const [, def] = this.entry(key);
278
+ const d = def;
279
+ const marker = this.marker(key);
280
+ let css = d.css;
281
+ let warnings = [];
282
+ if (typeof d.css === "function") {
283
+ const lib = registry.lib;
284
+ if (!lib) throw thrown(this.name, `${this.name}.${key}: the css library is not loaded`);
285
+ const made = ran(this.name, () => d.css(lib.css));
286
+ const nodes = Array.isArray(made) ? made : [made];
287
+ const merged = lib.css["cn"](...nodes);
288
+ const built = Result.getOrThrowWith(Result.try({
289
+ try: () => lib.kernelOf(`${this.name}.${key}`, merged, marker),
290
+ catch: (e) => e instanceof Error ? Object.assign(e, { message: this.own(e.message) }) : e
291
+ }), (e) => e);
292
+ css = built.css;
293
+ warnings = built.warnings.map((w) => ({
294
+ ...w,
295
+ value: this.own(w.value)
296
+ }));
297
+ if (built.kernels) this.atRules.set(key, built.kernels.map((r) => {
298
+ if (!r.css.includes("--_")) return r;
299
+ const name = r.key.slice(r.key.indexOf(" ") + 1);
300
+ const scoped = `${name}-${this.name}`;
301
+ css = css.replaceAll(name, scoped);
302
+ return {
303
+ ...r,
304
+ key: r.key.replace(name, scoped),
305
+ css: this.own(r.css.replace(name, scoped))
306
+ };
307
+ }));
308
+ this.sets.set(key, built.props);
309
+ this.derived.set(key, {
310
+ props: Object.keys(properties).filter((p) => built.props.some((k) => relation(p, k) !== "apart")),
311
+ message: `kernel ${key} sets ${built.props.join(", ")}`
312
+ });
313
+ }
314
+ k = {
315
+ key: `${this.name}.${key}`,
316
+ css: this.own(this.mark(css, marker)),
317
+ atProperty: d.atProperty && this.own(d.atProperty),
318
+ requires: d.requires
319
+ };
320
+ if (warnings.length) kernelWarnings.set(k, warnings);
321
+ this.kernels.set(key, k);
322
+ return k;
323
+ }
324
+ carry(uses) {
325
+ const id = uses.join(",");
326
+ let c = this.carries.get(id);
327
+ if (c) return c;
328
+ c = {};
329
+ const kinds = uses.map((u) => {
330
+ const [s, key] = this.find(u);
331
+ return [
332
+ u,
333
+ s,
334
+ key,
335
+ ...s.entry(key)
336
+ ];
337
+ });
338
+ const first = kinds.find((k) => k[3] === "kernel");
339
+ const explicit = kinds.some((k) => k[3] === "conflicts");
340
+ const set = [];
341
+ for (const [u, s, key, kind, def] of kinds) if (kind === "kernel") {
342
+ const k = s.kernel(key);
343
+ const props = s.sets.get(key);
344
+ if (props) {
345
+ const meets = (a, b) => a.filter((p) => b.some((q) => relation(p, q) !== "apart"));
346
+ for (const [v, other, ps] of set) {
347
+ const both = [.../* @__PURE__ */ new Set([...meets(ps, props), ...meets(props, ps)])];
348
+ if (other !== k.key && both.length) throw thrown(this.name, `${this.name}: kernels ${v} and ${u} both set ${both.join(", ")} (they are one element's styles and print in no set order): write those in one kernel`);
349
+ }
350
+ set.push([
351
+ u,
352
+ k.key,
353
+ props
354
+ ]);
355
+ }
356
+ (c.kernels ??= []).push(...s.atRules.get(key) ?? [], k);
357
+ (c.markers ??= []).push([s.marker(key), k.key]);
358
+ const conflicts = explicit ? void 0 : s.derived.get(key);
359
+ if (conflicts) (c.plugs ??= []).push({
360
+ name: k.key,
361
+ label: s.name,
362
+ marker: s.marker(key),
363
+ conflicts
364
+ });
365
+ } else if (kind === "global") {
366
+ const g = def;
367
+ (c.globals ??= []).push({
368
+ css: s.own(g.rule),
369
+ layer: g.layer
370
+ });
371
+ } else if (kind === "layers") {
372
+ const l = def;
373
+ (c.layers ??= []).push({
374
+ names: l.layers,
375
+ before: l.before
376
+ });
377
+ } else if (kind === "runtime" || kind === "conflicts") {
378
+ const r = def;
379
+ if (!first && kind === "runtime" && (r.parentVars?.length || r.css?.includes("&"))) throw thrown(this.name, `${this.name}: ${u} uses & but no kernel goes with it in uses`);
380
+ const own = first ? first[1].marker(first[2]) : "";
381
+ const plug = {
382
+ name: `${s.name}.${key}`,
383
+ label: s.name,
384
+ marker: own
385
+ };
386
+ if (kind === "conflicts") plug.conflicts = def;
387
+ else plug.runtime = {
388
+ polyfills: r.polyfills,
389
+ parentVars: r.parentVars?.map((p) => ({
390
+ marker: own,
391
+ read: s.own(p.read),
392
+ write: s.own(p.write),
393
+ watch: p.watch && s.own(p.watch)
394
+ })),
395
+ css: r.css && s.own(s.mark(r.css, own)),
396
+ script: r.script
397
+ };
398
+ (c.plugs ??= []).push(plug);
399
+ }
400
+ this.carries.set(id, c);
401
+ return c;
402
+ }
403
+ };
404
+ const hashOf = (text) => {
405
+ let a = 5381;
406
+ let b = 52711;
407
+ for (let i = 0; i < text.length; i++) {
408
+ const c = text.charCodeAt(i);
409
+ a = Math.imul(a ^ c, 2654435761);
410
+ b = Math.imul(b ^ c, 1597334677);
411
+ }
412
+ return (a >>> 0).toString(36) + (b >>> 0).toString(36);
413
+ };
414
+ const register = (s) => {
415
+ if (s["~hash"]) return s["~hash"];
416
+ const table = s.table;
417
+ for (const v of Object.values(table)) if (isScope(v)) register(v);
418
+ const text = canon([table, s.impl]);
419
+ const hash = hashOf(text);
420
+ s["~text"] = text;
421
+ s["~hash"] = hash;
422
+ const old = registry.scopes.get(s.name);
423
+ if (old && old !== hash) {
424
+ const prefix = `${s.name}.`;
425
+ const users = /* @__PURE__ */ new Set();
426
+ for (const [key, e] of registry.kernels) if (key.startsWith(prefix)) e.users.forEach((u) => users.add(u));
427
+ for (const [name, e] of registry.runtimes) if (name.startsWith(prefix)) e.users.forEach((u) => users.add(u));
428
+ if (users.size) throw thrown(s.name, `scope "${s.name}" is defined twice with different content (${old}, now ${hash}) while ${[...users].join(", ")} still uses the old one: pick another name`);
429
+ }
430
+ registry.scopes.set(s.name, hash);
431
+ return hash;
432
+ };
433
+ const compiled = /* @__PURE__ */ new WeakMap();
434
+ const compile = (s) => {
435
+ const hit = compiled.get(s);
436
+ if (hit) return hit;
437
+ const own = {};
438
+ const mods = {};
439
+ for (const [k, v] of Object.entries(s.table)) {
440
+ const kind = kindOf(k, v);
441
+ if (kind === "alias") own[strip(k)] = v;
442
+ else if (kind === "tokens") Object.assign(mods, tokenSyntaxes(v.tokens, `${k}.`, {}));
443
+ else if (isScope(v)) for (const [n, g] of Object.entries(compile(v).compiled.exposed)) mods[`${k}.${n}`] = g;
444
+ }
445
+ const aliases = {
446
+ ...own,
447
+ ...mods
448
+ };
449
+ const exposed = {};
450
+ for (const k of Object.keys(s.table)) if (!isPrivate(k) && kindOf(k, s.table[k]) === "alias") exposed[k] = expand(s.table[k], aliases);
451
+ const c = new Compiler(s, {
452
+ aliases,
453
+ exposed
454
+ });
455
+ compiled.set(s, c);
456
+ return c;
457
+ };
458
+ const member$1 = (c, key, kind, def) => {
459
+ const name = c.name;
460
+ const d = def;
461
+ if (kind === "prop") {
462
+ if (Object.hasOwn(properties, key)) throw thrown(name, `${key} is a CSS property already, with its own grammar`);
463
+ const grammar = c.grammar(d);
464
+ return (...args) => {
465
+ const value = valueOf(name, key, args);
466
+ check(name, key, grammar, value);
467
+ registry.userProps.add(key);
468
+ return node([[key, value]]);
469
+ };
470
+ }
471
+ if (kind === "value") {
472
+ const def = d;
473
+ const { args: spec, label = key } = def;
474
+ return (...args) => {
475
+ const given = argsOf(c, label, spec, args);
476
+ const out = ran(name, () => def.value(typeof spec === "string" ? args.map(String) : given));
477
+ if (typeof out !== "string" && !(out instanceof CSSStyleValue$1)) throw thrown(name, `${label}() value must return a string or a Typed OM value`);
478
+ return out;
479
+ };
480
+ }
481
+ if (kind === "chain") return chainOf(c, key, d);
482
+ return callOf(c, key, d);
483
+ };
484
+ const chainOf = (c, key, def) => {
485
+ const { name } = c;
486
+ const methods = def.chain;
487
+ const grammars = /* @__PURE__ */ new Map();
488
+ let base;
489
+ const next = (used) => (m, args, self) => {
490
+ const meth = Object.hasOwn(methods, m) ? methods[m] : void 0;
491
+ if (!meth) throw failIn(name, `cssints: ${key}() has no .${m}(); it chains ${Object.keys(methods).filter((k) => !used.has(k)).join(", ")}`);
492
+ const by = used.get(m);
493
+ if (by === m) throw failIn(name, `cssints: ${key}().${m}() is used twice`);
494
+ if (by) throw failIn(name, `cssints: ${key}().${m}() cannot go with .${by}()`);
495
+ let value = "";
496
+ if (meth.args === "") {
497
+ if (args.length) throw failIn(name, `cssints: ${key}().${m}() takes no value`);
498
+ } else {
499
+ value = valueOf(name, `${key}.${m}`, args, meth.spacing);
500
+ let g = grammars.get(m);
501
+ if (g === void 0) grammars.set(m, g = c.grammar(meth.args));
502
+ check(name, `${key}.${m}`, g, value);
503
+ }
504
+ const taken = new Map(used).set(m, m);
505
+ for (const x of meth.excludes ?? []) taken.set(x, m);
506
+ const emitted = ran(name, () => meth.emit(value));
507
+ return node([...self.__cssints, ...ownDecls(c, emitted)], self, next(taken));
508
+ };
509
+ return () => node([], base ??= grouped(c, def, def.uses ? c.carry(def.uses) : {}), next(/* @__PURE__ */ new Map()));
510
+ };
511
+ const grouped = (c, def, carry) => def.group ? {
512
+ ...carry,
513
+ markers: [...carry.markers ?? [], [`_g-${c.name}`, "group"]]
514
+ } : carry;
515
+ const ownDecls = (c, emitted) => emitted.map(([p, v]) => [c.own(p), c.own(v)]);
516
+ const argOf = (c, label, def, v, tokens) => {
517
+ const { name } = c;
518
+ if (def === "$tokens") {
519
+ if (!v || typeof v !== "object" || isNode(v) || v instanceof CSSStyleValue$1) throw failIn(name, `cssints: ${label} expects a token set (createTokens)`);
520
+ return v;
521
+ }
522
+ if (def === "$overrides") {
523
+ if (!tokens || !v || typeof v !== "object" || Array.isArray(v)) throw failIn(name, `cssints: ${label} expects an object of values by token path`);
524
+ return v;
525
+ }
526
+ if (def === "$selector") {
527
+ if (typeof v !== "string") throw failIn(name, `cssints: ${label} expects a selector`);
528
+ Result.getOrThrowWith(Result.try({
529
+ try: () => checkSelectorNow(v),
530
+ catch: (e) => isDeclarationError(e) ? failIn(name, `cssints: ${label}: ${e.message}`) : e
531
+ }), (e) => e);
532
+ return v;
533
+ }
534
+ if (typeof def === "string") {
535
+ const value = valueOf(name, label, [v]);
536
+ check(name, label, c.grammar(def), value);
537
+ return value;
538
+ }
539
+ if (isTyped(def)) return v;
540
+ if (!v || typeof v !== "object" || Array.isArray(v)) throw failIn(name, `cssints: ${label} expects an object`);
541
+ const out = {};
542
+ const rec = def;
543
+ for (const [k, leaf] of Object.entries(rec)) {
544
+ const optional = k.endsWith("?");
545
+ const field = optional ? k.slice(0, -1) : k;
546
+ const x = v[field];
547
+ if (x === void 0) {
548
+ if (!optional) throw failIn(name, `cssints: ${label}: ${field} is missing`);
549
+ continue;
550
+ }
551
+ out[field] = argOf(c, `${label}.${field}`, leaf, x);
552
+ }
553
+ for (const k of Object.keys(v)) if (!(k in out) && !(k in rec) && !(`${k}?` in rec)) throw failIn(name, `cssints: ${label}: no argument ${k}`);
554
+ return out;
555
+ };
556
+ const argsOf = (c, label, spec, args) => {
557
+ const { name } = c;
558
+ if (typeof spec === "string") {
559
+ const value = valueOf(name, label, args);
560
+ check(name, label, c.grammar(spec), value);
561
+ return [value];
562
+ }
563
+ if (isTyped(spec)) return args;
564
+ const list = spec;
565
+ if (args.length > list.length) throw failIn(name, `cssints: ${label}() takes at most ${list.length} arguments`);
566
+ let tokens;
567
+ return list.map((d, i) => {
568
+ const v = argOf(c, `${label}(${i + 1})`, d, args[i] ?? (isRecord(d) ? {} : void 0), tokens);
569
+ if (d === "$tokens") tokens = v;
570
+ return v;
571
+ });
572
+ };
573
+ const callOf = (c, key, def) => {
574
+ const { name } = c;
575
+ const build = c.impl?.[key];
576
+ if (!build) throw thrown(name, `${name}.${key} has no function in build()`);
577
+ const spec = def.args;
578
+ const uses = def.uses ?? [];
579
+ let base;
580
+ return (...args) => {
581
+ const given = argsOf(c, key, spec, args);
582
+ const made = ran(name, () => build(...given));
583
+ const carry = made.uses ? grouped(c, def, c.carry([...uses, ...made.uses])) : base ??= grouped(c, def, c.carry(uses));
584
+ return node(made.decls ? ownDecls(c, made.decls) : [], {
585
+ ...carry,
586
+ globals: made.globals ? [...carry.globals ?? [], ...made.globals] : carry.globals,
587
+ themes: made.themes,
588
+ layers: made.layers ? [...carry.layers ?? [], has(made.layers, "layers") ? {
589
+ names: made.layers.layers,
590
+ before: made.layers.before
591
+ } : { names: made.layers }] : carry.layers
592
+ });
593
+ };
594
+ };
595
+ const exportOf = (s) => {
596
+ const c = compile(s);
597
+ register(s);
598
+ const calls = Object.keys(s.table).filter((k) => kindOf(k, s.table[k]) === "call");
599
+ if (calls.length && !s.impl) throw thrown(s.name, `${s.name}: call .build({ ${calls.join(", ")} }) before .export()`);
600
+ const out = {};
601
+ for (const [k, v] of Object.entries(s.table)) {
602
+ if (isPrivate(k)) continue;
603
+ const kind = kindOf(k, v);
604
+ if (isScope(v)) out[k] = exportOf(v);
605
+ else if (kind === "prop") out[camel(k.slice(1))] = member$1(c, k, kind, v);
606
+ else if (kind === "chain" || kind === "call" || kind === "value") out[k] = member$1(c, k, kind, v);
607
+ }
608
+ return out;
609
+ };
610
+ function scope(name, table) {
611
+ if (!NAME$1.test(name) || RESERVED.has(name)) throw thrown(name, RESERVED.has(name) ? `scope "${name}" is reserved by the engine` : `scope(${JSON.stringify(name)}): a name is lowercase letters, digits and -, and starts with a letter`);
612
+ for (const k of Object.keys(table)) {
613
+ if (!KEY.test(strip(k)) && !k.startsWith("-")) throw thrown(name, `${name}: the entry ${JSON.stringify(k)} is not a name`);
614
+ if (isPrivate(k) && Object.hasOwn(table, strip(k))) throw thrown(name, `${name}: ${k} and ${strip(k)} share a name: rename one`);
615
+ }
616
+ const s = {
617
+ name,
618
+ table,
619
+ "~scope": name,
620
+ "~table": table,
621
+ build(impl) {
622
+ const keys = Object.keys(table).filter((k) => kindOf(k, table[k]) === "call");
623
+ if (Object.keys(impl).filter((k) => !keys.includes(k)).length || keys.some((k) => !Object.hasOwn(impl, k))) throw thrown(name, `${name}: build() takes a function for each call member: ${keys.join(", ")}`);
624
+ s.impl = impl;
625
+ return s;
626
+ },
627
+ export: () => exportOf(s)
628
+ };
629
+ return s;
630
+ }
631
+ const lacking$1 = (keys) => [...new Set(keys.flatMap((k) => lackingOf(k).map((t) => t.join(" "))))];
632
+ const dependsOn = (path) => {
633
+ registry.files.add(path);
634
+ };
635
+ /** What the front (scope.ts) calls; macro.ts puts it in the registry. */
636
+ const engine = {
637
+ scope,
638
+ lacking: lacking$1,
639
+ dependsOn
640
+ };
641
+ //#endregion
642
+ //#region src/runtime.ts
643
+ function _cx(drops, ...a) {
644
+ const on = a.flat(Infinity).filter(Boolean).join(" ").split(" ");
645
+ const gone = drops.flatMap(([by, c]) => on.includes(by) ? c.split(" ") : []);
646
+ return on.filter((c) => c && !gone.includes(c)).join(" ");
647
+ }
648
+ function _cv(config) {
649
+ return (props = {}) => {
650
+ const out = [config.base];
651
+ const gone = [];
652
+ const val = {};
653
+ const take = (c, d) => {
654
+ if (c) out.push(c);
655
+ if (c && d) gone.push(...d.split(" "));
656
+ };
657
+ for (const name in config.variants) {
658
+ const v = val[name] = String(props[name] ?? config.defaultVariants[name]);
659
+ take(config.variants[name][v], config.drops?.[name]?.[v]);
660
+ }
661
+ for (const m of config.compound ?? []) if (Object.keys(m.when).every((k) => val[k] === m.when[k])) take(m.class, m.drops);
662
+ return out.join(" ").split(" ").filter((c) => c && !gone.includes(c)).join(" ");
663
+ };
664
+ }
665
+ //#endregion
666
+ //#region src/macro.ts
667
+ const flexChain = (ctx) => (name, args, self) => node([...self.__cssints, chainDecl(ctx, name, args)], self, flexChain(ctx));
668
+ const member = (k) => (...args) => CONTEXTS[k] && !args.length ? node(toDecls(k, args), {}, flexChain(k)) : node(toDecls(k, args), { kernels: kernelsOf(args) });
669
+ const firstThatWorks = (...values) => {
670
+ if (values.length < 2) throw fail("cssints: firstThatWorks() takes at least two values: the one you want, then what to use where it fails");
671
+ for (const v of values) {
672
+ if (v instanceof CSSAtRuleValue) throw fail(`cssints: firstThatWorks() cannot hold ${v.name}: a keyframes() or positionTry() name carries its at-rule, which a fallback would drop`);
673
+ if ((typeof v !== "string" || !v.trim()) && !(v instanceof CSSStyleValue)) throw fail(`cssints: firstThatWorks() takes non-empty strings and Typed OM values (tokens), got ${Formatter.formatJson(v)}`);
674
+ }
675
+ return { __fallback: values.map((v) => String(v).trim()) };
676
+ };
677
+ var CSSAtRuleValue = class extends CSSStyleValue {
678
+ kernel;
679
+ name;
680
+ constructor(name, kernel) {
681
+ super();
682
+ this.name = name;
683
+ this.kernel = kernel;
684
+ }
685
+ toString() {
686
+ return this.name;
687
+ }
688
+ };
689
+ const kernelsOf = (args) => {
690
+ let out;
691
+ for (const a of args) if (a instanceof CSSAtRuleValue) (out ??= []).push(a.kernel);
692
+ return out;
693
+ };
694
+ const POSITION_TRY = /^(?:top|right|bottom|left|inset(?:-(?:block|inline)(?:-(?:start|end))?)?|margin(?:-(?:top|right|bottom|left|block|inline)(?:-(?:start|end))?)?|(?:min-|max-)?(?:width|height|block-size|inline-size)|align-self|justify-self|place-self|position-anchor|position-area)$/;
695
+ const STEP = /^(?:from|to|\d+(?:\.\d+)?%)$/;
696
+ const blockOf = (what, style, allowed) => {
697
+ if (!isNode(style)) throw fail(`cssints: ${what} takes css.* declarations (a member call or cn(...)), got ${Formatter.formatJson(style)}`);
698
+ return declsOf(what, style, false, allowed).map(([prop, value]) => `${prop}:${value}`).join(";");
699
+ };
700
+ const declsOf = (what, style, conditions, allowed, sink) => {
701
+ if (!style.__cssints.length) throw fail(`cssints: ${what} takes css.* declarations (a member call or cn(...)), got ${Formatter.formatJson(style)}`);
702
+ if (style.markers || style.plugs || style.kernels && !(conditions && style.kernels.every((k) => k.key.startsWith("@")))) throw fail(`cssints: ${what} takes plain declarations: no marker class or kernel of a member`);
703
+ for (const d of style.__cssints) {
704
+ const [prop, , conds, fallbacks] = d;
705
+ if (!conditions && conds?.length || fallbacks) throw fail(`cssints: ${what} takes declarations without ${conditions ? "" : "conditions or "}firstThatWorks(...), got ${prop}`);
706
+ if (allowed && !allowed.test(prop)) throw fail(`cssints: ${what}: ${prop} is not allowed in @position-try, which takes inset, margin, sizing and self-alignment properties, position-anchor and position-area`);
707
+ Result.getOrThrowWith(Result.try({
708
+ try: () => checkNow(d, registry, true, sink),
709
+ catch: (e) => isDeclarationError(e) ? new MacroError({
710
+ message: `cssints: ${what}: ${e.message}`,
711
+ cause: e,
712
+ ...registry.at
713
+ }) : e
714
+ }), (e) => e);
715
+ }
716
+ return style.__cssints;
717
+ };
718
+ const atRule = (rule, prefix, body) => {
719
+ const name = `${prefix}${createHash("sha1").update(body).digest("hex").slice(0, 8)}`;
720
+ return new CSSAtRuleValue(name, {
721
+ key: `@${rule} ${name}`,
722
+ css: `@${rule} ${name}{${body}}`,
723
+ requires: [`css.at-rules.${rule}`]
724
+ });
725
+ };
726
+ const keyframes = (steps) => {
727
+ const entries = Predicate.isObjectOrArray(steps) ? Object.entries(steps) : [];
728
+ if (!entries.length) throw fail("cssints: keyframes() takes { from: style, to: style }: the steps are css.* styles");
729
+ const body = entries.map(([step, style]) => {
730
+ if (!STEP.test(step) || parseFloat(step) > 100) throw fail(`cssints: keyframes() step "${step}" is not from, to or a percentage from 0% to 100%`);
731
+ return `${step}{${blockOf(`keyframes() "${step}"`, style)}}`;
732
+ });
733
+ return atRule("keyframes", "kf-", body.join(""));
734
+ };
735
+ const positionTryProp = member("positionTry");
736
+ const positionTry = (...args) => args.length === 1 && isNode(args[0]) ? atRule("position-try", "--pt-", blockOf("positionTry()", args[0], POSITION_TRY)) : positionTryProp(...args);
737
+ const cn = (...all) => {
738
+ const args = all.filter(Boolean);
739
+ return node(toDecls("cn", args), carried(args));
740
+ };
741
+ const flex = member("flex");
742
+ const grid = member("grid");
743
+ const isWrapper = (v) => typeof v === "function" && Predicate.hasProperty(v, "__cond");
744
+ const wrapper = (cond) => Object.assign((...styles) => {
745
+ if (!styles.length || !styles.every(isNode)) throw fail(`cssints: ${cond.text} wraps css.* styles, got ${Formatter.formatJson(styles.filter((s) => !isNode(s)))}`);
746
+ const carry = carried(styles);
747
+ const [bare] = carry.bare ?? [];
748
+ if (bare) throw fail(`cssints: ${cond.text} wraps ${bare[0]}, the marker of kernel ${bare[1]}, with no declaration of its own: a kernel is global CSS keyed to its marker class and cannot be conditional, so the marker would apply everywhere. Put the member outside the condition; a condition can wrap the declarations a member sets (its methods)`);
749
+ return node(merged(styles.flatMap((n) => n.__cssints.map(([p, v, inner = [], fallbacks]) => {
750
+ if (inner.length >= 4) throw fail(`cssints: a style takes at most 4 conditions (layers ${LAYER[0]} to ${LAYER[4]}); this one has ${inner.length + 1}: ${[cond, ...inner].map((c) => c.text).join(" > ")}`);
751
+ return [
752
+ p,
753
+ v,
754
+ [cond, ...inner],
755
+ fallbacks
756
+ ];
757
+ }))), carry);
758
+ }, {
759
+ __cond: true,
760
+ cond
761
+ });
762
+ const query = (kind, q) => {
763
+ if (typeof q !== "string") throw fail(`cssints: ${kind}() takes a query string, got ${Formatter.formatJson(q)}`);
764
+ const exit = Effect.runSyncExit(checkQuery(kind, q));
765
+ if (Exit.isFailure(exit)) {
766
+ const e = Cause.squash(exit.cause);
767
+ throw new MacroError({
768
+ message: e.message,
769
+ cause: e,
770
+ ...registry.at
771
+ });
772
+ }
773
+ const text = q.trim();
774
+ return wrapper({
775
+ text: `@${kind} ${text}`,
776
+ rank: kind === "supports" ? 0 : minWidth(text)
777
+ });
778
+ };
779
+ const condition = (kind) => (...args) => {
780
+ const [only] = args;
781
+ if (!args.length) throw fail(`cssints: ${kind}() expects a query string`);
782
+ if (args.length > 1) return args.map((q) => query(kind, q));
783
+ if (Predicate.isObject(only)) return Object.fromEntries(Object.entries(only).map(([k, q]) => [k, query(kind, q)]));
784
+ return query(kind, only);
785
+ };
786
+ const NAME = /^-?[A-Za-z_][\w-]*$/;
787
+ const OPS = [
788
+ "=",
789
+ "~=",
790
+ "|=",
791
+ "^=",
792
+ "$=",
793
+ "*="
794
+ ];
795
+ const attr = (...args) => {
796
+ const [name, value, given] = args;
797
+ const op = typeof given === "string" ? given : "=";
798
+ if (args.length > 3 || typeof name !== "string" || !NAME.test(name) || value !== void 0 && typeof value !== "string" || !OPS.includes(op) || given !== void 0 && (typeof given !== "string" || value === void 0)) throw fail(`cssints: attr(name, value?, op?) takes an attribute name, then a string value and one of ${OPS.join(" ")}, got ${Formatter.formatJson(args)}`);
799
+ const quoted = value?.replace(/["\\]/g, "\\$&").replace(/\n/g, "\\a ");
800
+ return wrapper({
801
+ text: `[${name}${quoted === void 0 ? "" : `${op}"${quoted}"`}]`,
802
+ rank: 1e3
803
+ });
804
+ };
805
+ const markerOf = (what, name) => {
806
+ if (name !== void 0 && (typeof name !== "string" || !NAME.test(name))) throw fail(`cssints: ${what} takes a name such as "row", got ${Formatter.formatJson(name)}`);
807
+ return name === void 0 ? "_g" : `_g-${name}`;
808
+ };
809
+ const group = (name) => node([], { markers: [[markerOf("group()", name), "group"]] });
810
+ const within = (state, name) => {
811
+ if (!isWrapper(state) || state.cond.ancestor || !/^[:[]/.test(state.cond.text)) throw fail("cssints: within() takes a pseudo-class wrapper (hover) or attr(...), then the name of the group");
812
+ return wrapper({
813
+ text: `:where(.${markerOf("within()", name)}${state.cond.text})`,
814
+ rank: state.cond.rank - 2e3,
815
+ ancestor: true
816
+ });
817
+ };
818
+ const nest = (...args) => {
819
+ const [selector] = args;
820
+ const text = typeof selector === "string" ? selector.trim().replace(/\s+/g, " ") : "";
821
+ let depth = 0;
822
+ let own = false;
823
+ let list = false;
824
+ for (const ch of text) if (ch === "(" || ch === "[") depth++;
825
+ else if (ch === ")" || ch === "]") depth--;
826
+ else if (depth) continue;
827
+ else if (ch === "&") own = true;
828
+ else if (ch === ",") list = true;
829
+ else if (" >+~".includes(ch)) own = false;
830
+ if (!text.includes("&") || list) throw fail(`cssints: nest() takes one selector with & (the kernel's class): "& > *", "& p", ":root:has(&)", ".x &", got ${Formatter.formatJson(selector)}`);
831
+ const exit = Effect.runSyncExit(checkSelector(text.replaceAll("&", "._k")));
832
+ if (Exit.isFailure(exit)) {
833
+ const e = Cause.squash(exit.cause);
834
+ throw new MacroError({
835
+ message: `cssints: nest(): ${e.message}`,
836
+ cause: e,
837
+ ...registry.at
838
+ });
839
+ }
840
+ return wrapper({
841
+ text,
842
+ rank: 3e3,
843
+ nest: true,
844
+ ...own ? { own: true } : {}
845
+ });
846
+ };
847
+ const vars = (...args) => {
848
+ const [set] = args;
849
+ const entries = Predicate.isObject(set) ? Object.entries(set) : [];
850
+ const bad = entries.find(([k, v]) => !/^--[\w-]+$/.test(k) || !(typeof v === "string" || typeof v === "number" || v instanceof CSSStyleValue));
851
+ if (!entries.length || bad) throw fail(`cssints: vars() takes { "--_name": value }, values strings, numbers or Typed OM values, got ${Formatter.formatJson(bad ?? set)}`);
852
+ const decls = entries.map(([k, v]) => [k, String(v)]);
853
+ return node(decls, { kernels: kernelsOf(entries.map(([, v]) => v)) });
854
+ };
855
+ const globalRule = (selector, ...styles) => {
856
+ const at = registry.at;
857
+ if (!at || typeof selector !== "string") throw fail("cssints: global(selector, ...styles) takes a selector string and css.* styles");
858
+ const exit = Effect.runSyncExit(checkSelector(selector));
859
+ if (Exit.isFailure(exit)) {
860
+ const e = Cause.squash(exit.cause);
861
+ throw new MacroError({
862
+ message: `cssints: global(): ${e.message}`,
863
+ cause: e,
864
+ ...at
865
+ });
866
+ }
867
+ if (!styles.length || !styles.every(isNode)) throw fail(`cssints: global() takes css.* styles after the selector, got ${Formatter.formatJson(styles.filter((s) => !isNode(s)))}`);
868
+ if (styles.some((s) => s.markers || s.kernels || s.plugs)) throw fail("cssints: global() takes plain declarations: no marker class or kernel of a member");
869
+ const blocks = /* @__PURE__ */ new Map();
870
+ for (const d of merged(styles.flatMap((s) => s.__cssints))) {
871
+ const [prop, value, conds = [], fallbacks] = d;
872
+ const state = conds.find((c) => !c.text.startsWith("@"));
873
+ if (state) throw fail(`cssints: global() takes media(), container() and supports() conditions, not ${state.text}: write the state in the selector`);
874
+ Result.getOrThrowWith(Result.try({
875
+ try: () => checkNow(d, registry),
876
+ catch: (e) => isDeclarationError(e) ? located(at)(e) : e
877
+ }), (e) => e);
878
+ const key = conds.map((c) => c.text).join("{");
879
+ const block = blocks.get(key) ?? blocks.set(key, {
880
+ conds,
881
+ body: []
882
+ }).get(key);
883
+ for (const v of fallbacks ? [...fallbacks.toReversed(), value] : [value]) block.body.push(`${prop}:${v}`);
884
+ }
885
+ const css = [...blocks.values()].map(({ conds, body }) => conds.toReversed().reduce((r, c) => `${c.text}{${r}}`, `${selector.trim()}{${body.join(";")}}`)).join("").replace(/[\t\n\r\f]/g, " ");
886
+ const n = registry.tokens++;
887
+ registry.themed.set(`${at.file}#${at.site}.${n}`, {
888
+ file: at.file,
889
+ key: `-:${at.file}#${String(at.site).padStart(6, "0")}.${n}`,
890
+ css,
891
+ names: []
892
+ });
893
+ return DONE;
894
+ };
895
+ const layersRule = (...args) => {
896
+ const at = registry.at;
897
+ const last = args.at(-1);
898
+ const options = Predicate.isObject(last) ? last : void 0;
899
+ const names = options ? args.slice(0, -1) : args;
900
+ if (!at || !names.every((n) => typeof n === "string") || options && typeof options.before !== "boolean") throw fail("cssints: layers(...names, { before? }) takes the names of layers, strings, and at the end { before: true } or none");
901
+ return edge(addLayers({
902
+ names,
903
+ before: options?.before === true
904
+ }, at).pipe(Effect.as(DONE)));
905
+ };
906
+ const conditions = {
907
+ media: condition("media"),
908
+ container: condition("container"),
909
+ supports: condition("supports"),
910
+ attr,
911
+ within,
912
+ ...Object.fromEntries(Object.entries(PSEUDOS).map(([n, c]) => [n, wrapper(c)]))
913
+ };
914
+ const isCv = (v) => Predicate.hasProperty(v, "__cv");
915
+ const located = (at) => (e) => (Predicate.isTagged(e, "MacroError") || Predicate.isTagged(e, "MemberError")) && e.file !== void 0 ? e : Predicate.isTagged(e, "MemberError") ? new MemberError({
916
+ message: e.message,
917
+ pluginName: e.pluginName,
918
+ cause: e,
919
+ ...at
920
+ }) : new MacroError({
921
+ message: e.message,
922
+ cause: e,
923
+ ...at
924
+ });
925
+ const ruleOf = (cls, [prop, value, conds = [], fallbacks]) => {
926
+ const wrap = [];
927
+ const ranks = [];
928
+ let before = "";
929
+ let sel = `.${cls}`;
930
+ let width = 0;
931
+ for (const c of conds) if (c.text.startsWith("@")) {
932
+ wrap.push(c.text);
933
+ width = Math.max(width, c.rank);
934
+ } else {
935
+ if (c.ancestor) before += `${c.text} `;
936
+ else if (!c.nest) sel += c.text;
937
+ else if (c.text.lastIndexOf("&") === 0) sel += c.text.slice(1);
938
+ else {
939
+ const amp = `${before}${sel}`;
940
+ sel = c.text.replaceAll("&", /[\s>+~]/.test(amp) ? `:is(${amp})` : amp);
941
+ before = "";
942
+ }
943
+ ranks.push(c.rank);
944
+ }
945
+ const all = fallbacks ? `${value};${fallbacks.join(";")}` : value;
946
+ const tokens = all.includes("var(--") ? [...all.matchAll(VAR)].map((m) => m[1]) : void 0;
947
+ return {
948
+ layer: LAYER[conds.length],
949
+ cond: conds.length ? [width, ...ranks] : [],
950
+ wrap,
951
+ prop,
952
+ css: `${before}${sel}{${fallbacks ? [...fallbacks.toReversed(), value].map((v) => `${prop}:${v}`).join(";") : `${prop}:${value}`}}`,
953
+ tokens
954
+ };
955
+ };
956
+ const kernelOf = (what, style, cls) => {
957
+ const warnings = [];
958
+ const decls = declsOf(what, style, true, void 0, warnings);
959
+ const blocks = [];
960
+ const open = /* @__PURE__ */ new Map();
961
+ for (const r of decls.map((d) => ({
962
+ cls,
963
+ ...ruleOf(cls, d)
964
+ })).sort(byOrder)) {
965
+ const brace = r.css.indexOf("{");
966
+ const selector = r.css.slice(0, brace);
967
+ const body = r.css.slice(brace + 1, -1);
968
+ const key = `${r.layer}|${r.cond.join()}|${r.wrap.join("{")}|${selector}`;
969
+ const block = open.get(key);
970
+ if (block) block.body.push(body);
971
+ else {
972
+ const b = {
973
+ wrap: r.wrap,
974
+ selector,
975
+ body: [body]
976
+ };
977
+ blocks.push(b);
978
+ open.set(key, b);
979
+ }
980
+ }
981
+ return {
982
+ css: blocks.map((b) => b.wrap.reduceRight((css, w) => `${w}{${css}}`, `${b.selector}{${b.body.join(";")}}`)).join(" "),
983
+ props: [...new Set(decls.flatMap(([prop, , conds]) => prop.startsWith("--") || conds?.some((c) => c.nest && !c.own) ? [] : [prop]))],
984
+ kernels: style.kernels,
985
+ warnings
986
+ };
987
+ };
988
+ const checkValue = (prop, value, properties) => {
989
+ let out = [];
990
+ for (const v of probed(value, properties)) {
991
+ const found = Result.getOrThrowWith(Result.try({
992
+ try: () => checkDeclarationNow(prop, v, true),
993
+ catch: (e) => {
994
+ if (v !== value && isDeclarationError(e)) Object.assign(e, { message: `${e.message} ("${value}" is checked as "${v}": a token stands for a value of its type)` });
995
+ return e;
996
+ }
997
+ }), (e) => e);
998
+ out = out.length ? out.concat(found) : found;
999
+ }
1000
+ return out;
1001
+ };
1002
+ const checkNow = ([prop, value, , fallbacks], registry, sheet = true, sink) => {
1003
+ const { properties, userProps } = registry;
1004
+ if (userProps.has(prop)) return;
1005
+ let found = checkValue(prop, value, properties);
1006
+ if (fallbacks) {
1007
+ const lacking = [value, ...fallbacks].map((v, i) => new Set((i ? checkValue(prop, v, properties) : found).flatMap((w) => w.lacking)));
1008
+ found = found.map((w) => ({
1009
+ ...w,
1010
+ lacking: w.lacking.filter((t) => lacking.every((s) => s.has(t)))
1011
+ })).filter((w) => w.lacking.length);
1012
+ }
1013
+ for (const w of found) {
1014
+ if (sink) {
1015
+ if (!(sheet && loweredOf(prop, value, w))) sink.push({
1016
+ prop,
1017
+ value,
1018
+ warning: w
1019
+ });
1020
+ continue;
1021
+ }
1022
+ const k = `${prop} ${w.key}${fallbacks ? ` ${w.lacking.join()}` : ""}`;
1023
+ if (!(sheet && loweredOf(prop, value, w))) warn(registry, k, messageOf(prop, value, w) + (fallbacks ? ", and no fallback of its firstThatWorks covers them" : ""));
1024
+ }
1025
+ };
1026
+ const classesNow = (decls, registry, markers) => {
1027
+ const { rules } = registry;
1028
+ const out = markers ? [...new Set(markers.map((m) => m[0]))] : [];
1029
+ for (const d of decls) {
1030
+ const cls = hashClass(d);
1031
+ checkNow(d, registry);
1032
+ if (!out.includes(cls)) out.push(cls);
1033
+ if (!rules.has(cls)) rules.set(cls, ruleOf(cls, d));
1034
+ }
1035
+ return out.join(" ");
1036
+ };
1037
+ const conflictOf = ({ name, label = name, conflicts }, decls, at) => {
1038
+ const hit = conflicts && decls.find(([p]) => conflicts.props.some((c) => typeof c === "string" ? c === p : c.test(p)));
1039
+ return hit ? new MemberError({
1040
+ message: `cssints: ${label}: ${conflicts.message} (this style also sets ${hit[0]})`,
1041
+ pluginName: label,
1042
+ ...at
1043
+ }) : void 0;
1044
+ };
1045
+ const classesOf = Effect.fnUntraced(function* ({ __cssints: decls, markers, kernels, globals, themes, layers, plugs }, at) {
1046
+ const registry = yield* Registry;
1047
+ if (kernels) {
1048
+ const runtimes = plugs?.flatMap((p) => p.runtime ? [p.runtime] : []);
1049
+ for (const k of kernels) yield* addKernel(k, markers ?? [], at, runtimes);
1050
+ }
1051
+ if (layers) for (const l of layers) yield* addLayers(l, at);
1052
+ if (globals) for (const g of globals) yield* addGlobal(g, at);
1053
+ if (themes && at) for (const t of themes) yield* addTheme(t, at);
1054
+ if (plugs) for (const plug of plugs) {
1055
+ const conflict = conflictOf(plug, decls, at);
1056
+ if (conflict) return yield* conflict;
1057
+ if (plug.runtime) yield* addRuntime(plug, at);
1058
+ }
1059
+ return yield* Effect.try({
1060
+ try: () => classesNow(decls, registry, markers),
1061
+ catch: (e) => {
1062
+ if (isDeclarationError(e)) return e;
1063
+ throw e;
1064
+ }
1065
+ });
1066
+ });
1067
+ const styleOf = Effect.fnUntraced(function* (s, where, at) {
1068
+ if (!isNode(s)) return yield* new MacroError({ message: `cssints: cv() ${where} must be a css.* value (cn(...), a flex() chain or one property), got ${Formatter.formatJson(s)}. CSS strings are gone: write cn(p(4), fontSize("1rem"))` });
1069
+ return yield* classesOf(s, at);
1070
+ });
1071
+ const cvOf = Effect.fnUntraced(function* (config, at) {
1072
+ const variants = {};
1073
+ const base = config.base === void 0 ? "" : yield* styleOf(config.base, "base", at);
1074
+ for (const [k, vs] of Object.entries(config.variants ?? {})) {
1075
+ const classes = {};
1076
+ for (const [n, s] of Object.entries(vs)) classes[n] = yield* styleOf(s, `variant ${k}.${n}`, at);
1077
+ variants[k] = classes;
1078
+ }
1079
+ const compound = [];
1080
+ const whens = [];
1081
+ for (const [i, { class: style, ...values }] of (config.compoundVariants ?? []).entries()) {
1082
+ const when = Object.fromEntries(Object.entries(values).map(([k, v]) => [k, String(v)]));
1083
+ compound.push({
1084
+ when,
1085
+ class: yield* styleOf(style, `compoundVariants[${i}] class`, at)
1086
+ });
1087
+ whens.push({
1088
+ when,
1089
+ decls: style.__cssints
1090
+ });
1091
+ }
1092
+ const declsOf = (s) => s.__cssints;
1093
+ const { drops, compound: gone } = yield* Effect.try({
1094
+ try: () => settled(config.base === void 0 ? [] : declsOf(config.base), Object.fromEntries(Object.entries(config.variants ?? {}).map(([k, vs]) => [k, Object.fromEntries(Object.entries(vs).map(([n, s]) => [n, declsOf(s)]))])), whens),
1095
+ catch: (e) => {
1096
+ if (e instanceof MacroError) return e;
1097
+ throw e;
1098
+ }
1099
+ });
1100
+ return Formatter.formatJson({
1101
+ base,
1102
+ variants,
1103
+ defaultVariants: config.defaultVariants ?? {},
1104
+ ...Object.keys(drops).length && { drops },
1105
+ ...compound.length && { compound: compound.map((c, i) => gone[i] ? {
1106
+ ...c,
1107
+ drops: gone[i]
1108
+ } : c) }
1109
+ });
1110
+ });
1111
+ const fromJson = Schema.decodeSync(Schema.fromJsonString(Schema.Unknown));
1112
+ const cv = (config) => {
1113
+ const built = [];
1114
+ const build = () => {
1115
+ const exit = Effect.runSyncExit(cvOf(config));
1116
+ if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
1117
+ return _cv(fromJson(exit.value));
1118
+ };
1119
+ return Object.assign((props) => (built[0] ??= build())(props), { __cv: config });
1120
+ };
1121
+ const isGroup = (v) => Predicate.hasProperty(v, "__cnGroup");
1122
+ const headOf = Effect.fnUntraced(function* ({ __cnGroup: { statics, parts } }, at) {
1123
+ const { nodes } = yield* Registry;
1124
+ const merged = cn(...statics.map(([, s]) => s));
1125
+ const where = /* @__PURE__ */ new Map();
1126
+ for (const [pos, s] of statics) if (isNode(s)) for (const d of s.__cssints) where.set(d, pos);
1127
+ const all = nodes.get(at.file) ?? nodes.set(at.file, /* @__PURE__ */ new Map()).get(at.file);
1128
+ all.set(at.site, merged.__cssints);
1129
+ const drops = yield* Effect.try({
1130
+ try: () => dropsOf([...merged.__cssints.map((decl) => ({
1131
+ at: where.get(decl),
1132
+ decl,
1133
+ conditional: false
1134
+ })), ...parts.flatMap(([pos, site]) => (all.get(site) ?? []).map((decl) => ({
1135
+ at: pos,
1136
+ decl,
1137
+ conditional: true
1138
+ })))]),
1139
+ catch: (e) => {
1140
+ if (e instanceof MacroError) return e;
1141
+ throw e;
1142
+ }
1143
+ });
1144
+ const classes = yield* classesOf(merged, at);
1145
+ return `${CX_CALL}${Formatter.formatJson(drops)}, ${classes ? `${Formatter.formatJson(classes)}, ` : ""}`;
1146
+ });
1147
+ const __cnGroup = (statics, parts) => ({ __cnGroup: {
1148
+ statics,
1149
+ parts
1150
+ } });
1151
+ const __nocn = () => void 0;
1152
+ const named = {
1153
+ cn,
1154
+ firstThatWorks,
1155
+ ...fns,
1156
+ keyframes,
1157
+ positionTry,
1158
+ flex,
1159
+ grid,
1160
+ cv,
1161
+ group,
1162
+ global: globalRule,
1163
+ layers: layersRule,
1164
+ ...conditions,
1165
+ token,
1166
+ style,
1167
+ createTokens,
1168
+ createGlobalTheme,
1169
+ check: check$1,
1170
+ CSS,
1171
+ CSSColorValue,
1172
+ CSSImageValue,
1173
+ CSSStyleValue,
1174
+ CSSUnitValue
1175
+ };
1176
+ const css = new Proxy(named, { get: (t, k) => Object.hasOwn(t, k) ? t[k] : member(String(k)) });
1177
+ named.css = css;
1178
+ const __group = (id) => groupOf(css, id);
1179
+ const kernelCss = new Proxy({
1180
+ ...named,
1181
+ nest,
1182
+ vars
1183
+ }, { get: (t, k) => Object.hasOwn(t, k) ? t[k] : member(String(k)) });
1184
+ registry.lib = {
1185
+ css: kernelCss,
1186
+ kernelOf
1187
+ };
1188
+ registry.engine = engine;
1189
+ const inertOf = (v) => {
1190
+ if (isWrapper(v) || isFallback(v)) return "null";
1191
+ if (Array.isArray(v) && v.length && v.every(isWrapper)) return `[${v.map(() => "null").join(",")}]`;
1192
+ if (!Predicate.isObject(v)) return void 0;
1193
+ const entries = Object.entries(v);
1194
+ return entries.length && entries.every(([, w]) => isWrapper(w)) ? `{${entries.map(([k]) => `${Formatter.formatJson(k)}:null`).join(",")}}` : void 0;
1195
+ };
1196
+ const inlineOf = Effect.fnUntraced(function* ({ __style: { sets, decls } }) {
1197
+ const registry = yield* Registry;
1198
+ return yield* Effect.try({
1199
+ try: () => {
1200
+ for (const d of decls) checkNow(d, registry, false);
1201
+ return `{ ${[...new Map([...sets, ...decls.map(([p, v]) => [camel(p), v])])].map(([k, v]) => `${k.startsWith("--") ? Formatter.formatJson(k) : k}: ${Formatter.formatJson(v)}`).join(", ")} }`;
1202
+ },
1203
+ catch: (e) => {
1204
+ if (isDeclarationError(e)) return e;
1205
+ throw e;
1206
+ }
1207
+ });
1208
+ });
1209
+ const isPluginValue = Predicate.isObjectKeyword;
1210
+ const replacementOf = Effect.fnUntraced(function* (at, value) {
1211
+ if (isNode(value)) return Formatter.formatJson(yield* classesOf(value, at));
1212
+ if (isCv(value)) return `${CV_CALL}${yield* cvOf(value.__cv, at)})`;
1213
+ if (isGroup(value)) return yield* headOf(value, at);
1214
+ if (isStyle(value)) return yield* inlineOf(value);
1215
+ const tokens = tokensOf(value);
1216
+ if (tokens !== void 0) return tokens;
1217
+ if (isDone(value)) return "undefined";
1218
+ if (value instanceof CSSStyleValue) return Formatter.formatJson(String(value));
1219
+ if (typeof value === "string") return Formatter.formatJson(value);
1220
+ const inert = inertOf(value);
1221
+ if (inert !== void 0) return inert;
1222
+ if (registry.tui && Predicate.hasProperty(value, "__tui")) return yield* Effect.try({
1223
+ try: () => registry.tui(value),
1224
+ catch: (e) => {
1225
+ if (e instanceof MacroError) return e;
1226
+ throw e;
1227
+ }
1228
+ });
1229
+ if (isPluginValue(value)) return void 0;
1230
+ return yield* new MacroError({ message: `cssints: site ${at.site} in ${at.file} did not produce a css.*, cv(), style(), condition or Typed OM value` });
1231
+ });
1232
+ const recordSite = Effect.fnUntraced(function* (at, value) {
1233
+ const { sites } = yield* Registry;
1234
+ const replacement = yield* replacementOf(at, value).pipe(Effect.mapError(located(at)));
1235
+ if (replacement === void 0) return value;
1236
+ if (isNode(value)) {
1237
+ const { nodes } = yield* Registry;
1238
+ (nodes.get(at.file) ?? nodes.set(at.file, /* @__PURE__ */ new Map()).get(at.file)).set(at.site, value.__cssints);
1239
+ }
1240
+ if (!sites.has(at.file)) sites.set(at.file, /* @__PURE__ */ new Map());
1241
+ sites.get(at.file).set(at.site, replacement);
1242
+ return value;
1243
+ });
1244
+ function __at(file, site, offset) {
1245
+ const key = `${file}#${site}`;
1246
+ if (registry.site !== key) {
1247
+ registry.site = key;
1248
+ registry.tokens = 0;
1249
+ }
1250
+ if (registry.seen.get(file) !== registry.gen) {
1251
+ registry.seen.set(file, registry.gen);
1252
+ forgetKernels(file);
1253
+ }
1254
+ return registry.at = {
1255
+ file,
1256
+ site,
1257
+ offset
1258
+ };
1259
+ }
1260
+ const __unseen = (file, site) => !registry.sites.get(file)?.has(site);
1261
+ function __site(at, value) {
1262
+ registry.at = at;
1263
+ const exit = Effect.runSyncExit(recordSite(at, value));
1264
+ registry.at = void 0;
1265
+ if (Exit.isFailure(exit)) throw Cause.squash(exit.cause);
1266
+ return exit.value;
1267
+ }
1268
+ //#endregion
1269
+ export { CSS, CSSAtRuleValue, CSSColorValue, CSSImageValue, CSSStyleValue, CSSUnitValue, __at, __cnGroup, __group, __nocn, __site, __unseen, _cv, _cx, cn, css, cv, firstThatWorks, flex, grid, keyframes, positionTry };