@navecss/core 0.3.0 → 0.5.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.
@@ -0,0 +1,317 @@
1
+ export { R as ResolvedUsedOptions, U as UsedAtomOptions, a as assertOptions, k as keptAtoms, r as resolveUsedOptions } from './vite-options-sOCeGn9B.js';
2
+ import './atom-names-B8Ud-7zD.js';
3
+
4
+ /**
5
+ * The few shapes of the ESTree `this.parse` returns that the collector reads, declared here
6
+ * rather than imported: the plugin takes no dependency, and a node is read through a handful of
7
+ * typed accessors instead of a full ESTree type package.
8
+ */
9
+ interface AstNode {
10
+ readonly type: string;
11
+ readonly start: number;
12
+ readonly end: number;
13
+ readonly [key: string]: unknown;
14
+ }
15
+
16
+ /**
17
+ * One thing the collector could not read in a module, before it has a position or a path: what
18
+ * it is, where it starts (an offset into the module as the post-order half saw it), the
19
+ * construct as the plugin reads it, and the sentence that follows the construct in the report.
20
+ */
21
+ /**
22
+ * The kinds a report groups its remedy lines by; the order here is the order the lines print.
23
+ */
24
+ declare const PROBLEM_KINDS: readonly ["argument", "reference", "reexport", "declared", "concatenation", "dynamic", "unknown", "own", "unreadable"];
25
+ type ProblemKind = (typeof PROBLEM_KINDS)[number];
26
+ interface Problem {
27
+ readonly kind: ProblemKind;
28
+ readonly offset: number;
29
+ /**
30
+ * The construct, quoted as the plugin reads it, before it is cut for the report.
31
+ */
32
+ readonly construct: string;
33
+ /**
34
+ * The sentence after the construct.
35
+ */
36
+ readonly text: string;
37
+ /**
38
+ * For an unknown atom with no near candidate: the report closes with `Available:`.
39
+ */
40
+ readonly needsAvailable?: boolean;
41
+ /**
42
+ * For a re-export: whether listing the module in `cxModules` would clear it, which it does not
43
+ * when the module re-exports the `cx` of a module that is already listed (a second hop).
44
+ */
45
+ readonly isListable?: boolean;
46
+ /**
47
+ * For a re-export of Nave's `cx`: whether it gives `cx` under a name other than `cx`, as a default
48
+ * or inside a namespace. A listed module may not do that, so listing the module would only turn
49
+ * this problem into another one: no `cxModules` entry clears it.
50
+ */
51
+ readonly isRenamed?: boolean;
52
+ /**
53
+ * For a problem that gives Nave's `cx` out of its module, or a namespace holding it, or the `cx`
54
+ * of a module listed in `cxModules`: the names it is exported under (`default` for the default
55
+ * export), so a build-end check can tell whether an importer takes it.
56
+ */
57
+ readonly exportedAs?: readonly string[];
58
+ /**
59
+ * For a problem in a module listed in `cxModules`: whether the module also exports Nave's own
60
+ * `cx`. An importer's `cx` is then Nave's, so what the build says of its calls is not an echo of
61
+ * this problem and stays when the problem is reported.
62
+ */
63
+ readonly hasNaveCx?: boolean;
64
+ }
65
+
66
+ /**
67
+ * Replaces the text from `start` up to `end` of the module with `text`.
68
+ */
69
+ interface Edit {
70
+ readonly start: number;
71
+ readonly end: number;
72
+ readonly text: string;
73
+ }
74
+
75
+ /**
76
+ * What a compiled Vue component's script exposes to its template, and how a template reads it:
77
+ * `$setup.<name>`.
78
+ */
79
+
80
+ type SetupExposure = {
81
+ readonly kind: 'cx';
82
+ } | {
83
+ readonly kind: 'values';
84
+ readonly values: readonly string[];
85
+ };
86
+ type SetupExposures = ReadonlyMap<string, SetupExposure>;
87
+
88
+ interface ReadOptions {
89
+ /**
90
+ * The import specifiers that bind Nave's `cx`: its own module, and every module listed in
91
+ * `cxModules` that this module imports.
92
+ */
93
+ readonly cxSources: ReadonlySet<string>;
94
+ /**
95
+ * The specifiers in `cxSources` that name a module listed in `cxModules`.
96
+ */
97
+ readonly declaredSources?: ReadonlySet<string>;
98
+ /**
99
+ * Whether this module is itself listed in `cxModules`, so its exports of `cx` are judged as a
100
+ * listed module's.
101
+ */
102
+ readonly isDeclared?: boolean;
103
+ /**
104
+ * The names of the consumer's own atoms, which have no class.
105
+ */
106
+ readonly ownAtoms: ReadonlySet<string>;
107
+ /**
108
+ * Whether this module belongs to a dependency, where a Nave class built from pieces is only
109
+ * refused if the module also imports `cx`.
110
+ */
111
+ readonly isDependency: boolean;
112
+ /**
113
+ * For a compiled Vue template: what its component's script exposes to it.
114
+ */
115
+ readonly setup?: SetupExposures | undefined;
116
+ /**
117
+ * Whether the module is a compiled Vue component's `<script setup>`.
118
+ */
119
+ readonly isVueScript?: boolean;
120
+ /**
121
+ * Set in a build: the reading also returns the edits that turn each call it read into the
122
+ * string the call returns, and `keep` is the map a `cx.dynamic()` call looks a name up in.
123
+ */
124
+ readonly rewrite?: {
125
+ readonly keep: Readonly<Record<string, string>>;
126
+ };
127
+ }
128
+ interface ModuleReading {
129
+ /**
130
+ * Built-in atoms named by a readable `cx()` call.
131
+ */
132
+ readonly atoms: Set<string>;
133
+ /**
134
+ * Built-in atoms whose class is written whole in the module.
135
+ */
136
+ readonly classes: Set<string>;
137
+ readonly problems: Problem[];
138
+ /**
139
+ * Where `cx.dynamic()` is called, and the call as the plugin reads it.
140
+ */
141
+ readonly dynamicCalls: {
142
+ readonly construct: string;
143
+ readonly offset: number;
144
+ }[];
145
+ /**
146
+ * For a compiled Vue `<script setup>`: what it exposes to its template.
147
+ */
148
+ readonly exposes: Map<string, SetupExposure>;
149
+ /**
150
+ * Whether the module imports from a `cx` source, whether or not it uses the import.
151
+ */
152
+ readonly usesCx: boolean;
153
+ /**
154
+ * With `rewrite` set: the edits that replace the calls the reading found, empty otherwise.
155
+ */
156
+ readonly edits: Edit[];
157
+ }
158
+
159
+ /**
160
+ * Reads one module for the atoms its `cx()` calls and written classes name, and for everything
161
+ * in it the build cannot read. Pure: it takes the parsed module and returns what it found, so the
162
+ * host (the post-order plugin) decides where the findings go.
163
+ */
164
+
165
+ declare const CX_SOURCE = "@navecss/core/cx";
166
+
167
+ /**
168
+ * Reads `program`, the parse of `code`.
169
+ */
170
+ declare function readModule(code: string, program: AstNode, options: ReadOptions): ModuleReading;
171
+
172
+ interface LayerReading {
173
+ /**
174
+ * Whether the stylesheet holds an `@layer atomic { ... }` block.
175
+ */
176
+ readonly hasLayer: boolean;
177
+ /**
178
+ * The built-in atoms whose class a rule in the layer selects.
179
+ */
180
+ readonly atoms: Set<string>;
181
+ }
182
+ /**
183
+ * `css` with every rule in an `@layer atomic` block that needs an atom outside `emitted` removed.
184
+ */
185
+ declare function pruneAtomicLayer(css: string, emitted: ReadonlySet<string>): string;
186
+ /**
187
+ * What the `@layer atomic` blocks of `css` hold.
188
+ */
189
+ declare function inspectAtomicLayer(css: string): LayerReading;
190
+ /**
191
+ * The atoms outside `emitted` that a rule left in the `@layer atomic` blocks of `css` still needs
192
+ * an element of: what a pruning to `emitted` would still remove, sorted.
193
+ */
194
+ declare function unprunedAtoms(css: string, emitted: ReadonlySet<string>): string[];
195
+
196
+ /**
197
+ * `atoms` with the atoms added that restore what an atom in it removes: `srOnlyFocusable` shows
198
+ * again on focus what `srOnly` hides, so a set that holds `srOnly` holds it too. This adds to the
199
+ * emitted set only, not to `keep` or to what `cx.dynamic()` accepts.
200
+ */
201
+ declare function withRestorers(atoms: Set<string>): Set<string>;
202
+
203
+ /**
204
+ * What an importer takes from a module that gives out Nave's `cx`: which of its `cx` exports it
205
+ * imports, re-exports or reads off a namespace. The test is by name, not by file: an importer that
206
+ * takes only `Button` from a module which also exports `cx` as `cn` takes no `cx` from it, so
207
+ * nothing of its own routes calls through `cn`. A take the parse cannot tell apart (a namespace
208
+ * passed on, a computed key, a rest element, an `import()` used any other way) counts as taken, and
209
+ * so does an importer whose text names the module in no way the build reads (a `require()`).
210
+ */
211
+
212
+ /**
213
+ * How an importer takes the module: by the names it imports or re-exports, as a namespace, as
214
+ * `export *`, as an `import()`, or in a way the build cannot read.
215
+ */
216
+ type TakeShape = 'dynamic-import' | 'names' | 'namespace' | 'star' | 'unreadable';
217
+ interface Taken {
218
+ readonly shape: TakeShape;
219
+ /**
220
+ * The `cx` exports the importer takes by name; none when it takes the module whole.
221
+ */
222
+ readonly names: readonly string[];
223
+ /**
224
+ * Whether the importer only passes on what it takes: a named re-export, or an import that it
225
+ * then exports.
226
+ */
227
+ readonly isPassedOn?: boolean;
228
+ /**
229
+ * Whether the importer does nothing with what it takes but re-export it: `export ... from`, or an
230
+ * import that every use of is an export. A forward is followed to what takes it; it is not a
231
+ * take on the `cxModules` route.
232
+ */
233
+ readonly isForward?: boolean;
234
+ /**
235
+ * Whether the take comes from what an earlier server command left in the cache directory.
236
+ */
237
+ readonly isRecorded?: boolean;
238
+ }
239
+ interface Take extends Taken {
240
+ /**
241
+ * The importer's path, relative to the project root, with forward slashes.
242
+ */
243
+ readonly taker: string;
244
+ /**
245
+ * Whether the module taken from is reached through another module of its package, which
246
+ * re-exports the `cx` it gives out.
247
+ */
248
+ readonly isReached: boolean;
249
+ }
250
+
251
+ /**
252
+ * The report a build fails with when it meets a use it cannot read: a first line counting the
253
+ * problems and stating the cause, one line per problem with a 1-based, root-relative position,
254
+ * and the remedy block printed once, last. Under the default nobody set the option, so the first
255
+ * line never names it, and no remedy printed for application code is `atomic: 'all'`: an agent
256
+ * takes the first remedy that clears the error, and that one always does.
257
+ */
258
+
259
+ interface LocatedProblem extends Problem {
260
+ /**
261
+ * The module's path, relative to the project root, with forward slashes.
262
+ */
263
+ readonly file: string;
264
+ readonly line: number;
265
+ readonly column: number;
266
+ /**
267
+ * Set when the source map does not lead to the authored position: `line` and `column` are then
268
+ * zero and mean nothing, and this is the sentence that ends the problem's line.
269
+ */
270
+ readonly unknownLine?: string | undefined;
271
+ /**
272
+ * The package name when the module lies under `node_modules`.
273
+ */
274
+ readonly pkg?: string | undefined;
275
+ /**
276
+ * The id of the module the problem is in, for a problem the build-end check looks into the
277
+ * module graph for.
278
+ */
279
+ readonly moduleId?: string | undefined;
280
+ /**
281
+ * For a dependency's re-export of `cx`: the specifier that resolves from the project root to the
282
+ * module that holds it, when a `cxModules` entry can name it.
283
+ */
284
+ readonly specifier?: string | undefined;
285
+ /**
286
+ * For a dependency's listed module that exports a `cx` the build does not follow: the
287
+ * `cxModules` entries, as written, that name it.
288
+ */
289
+ readonly entries?: readonly string[] | undefined;
290
+ /**
291
+ * For a module of a package `keepFor` lists that gives `cx` out under another name: the
292
+ * application modules that take one of its `cx` exports, which `keepFor` does not clear.
293
+ */
294
+ readonly takes?: readonly Take[] | undefined;
295
+ /**
296
+ * For a dependency module that re-exports the `cx` of a module `cxModules` lists: the modules of
297
+ * other dependencies that call through it, root-relative, which only the package's `keepFor`
298
+ * entry can stand in for.
299
+ */
300
+ readonly callers?: readonly string[] | undefined;
301
+ }
302
+ declare const REPORT_CAUSE = "the build cannot tell which atoms these apply, and it ships only the atoms it can read.";
303
+ /**
304
+ * The remedy lines only a host can write, given the application's problems: they print after the
305
+ * lines of the application's kinds and before any package's line.
306
+ */
307
+ type HostRemedies = (application: readonly LocatedProblem[]) => readonly string[];
308
+ /**
309
+ * The build report for every problem of an environment. `configured` is the `cxModules` list the
310
+ * remedies that print one extend, and `home` is how the host spells where the options are written,
311
+ * the call of its plugin or its wrapper: the one place the report names its host. `hostRemedies`
312
+ * adds the lines only the host can write.
313
+ */
314
+ declare function buildReport(problems: readonly LocatedProblem[], configured: readonly string[], home: string, hostRemedies?: HostRemedies): string;
315
+
316
+ export { CX_SOURCE, REPORT_CAUSE, buildReport, inspectAtomicLayer, pruneAtomicLayer, readModule, unprunedAtoms, withRestorers };
317
+ export type { AstNode, HostRemedies, LayerReading, LocatedProblem, ModuleReading, Problem, ProblemKind, ReadOptions };
@@ -0,0 +1,5 @@
1
+ export { CX_SOURCE, REPORT_CAUSE, assertOptions, buildReport, inspectAtomicLayer, keptAtoms, pruneAtomicLayer, readModule, resolveUsedOptions, unprunedAtoms, withRestorers } from './chunk-BCUK4M4P.js';
2
+ import './chunk-SYNQJNVB.js';
3
+ import './chunk-CUL5PLPI.js';
4
+ import './chunk-2K5EBBF2.js';
5
+ import './chunk-GZL2VW7C.js';
package/dist/css.d.ts ADDED
@@ -0,0 +1 @@
1
+ export {}
package/dist/cx.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { AtomName } from './atoms.js';
1
+ import { A as AtomName } from './atom-names-B8Ud-7zD.js';
2
2
 
3
3
  /**
4
4
  * cx — typed atomic class composer for Nave.
package/dist/cx.js CHANGED
@@ -1,12 +1,25 @@
1
- import { atomClassMap } from './chunk-LIUB4EES.js';
1
+ import { atomClassMap } from './chunk-GZL2VW7C.js';
2
2
 
3
3
  // src/cx.ts
4
+ var decodedKeep = /* @__PURE__ */ new Map();
5
+ function decodedMap(text) {
6
+ let map = decodedKeep.get(text);
7
+ if (map === void 0) {
8
+ map = JSON.parse(text);
9
+ decodedKeep.set(text, map);
10
+ }
11
+ return map;
12
+ }
4
13
  var cx = (...args) => args.filter(Boolean).map(
5
14
  (arg) => Object.hasOwn(atomClassMap, arg) ? atomClassMap[arg] : arg
6
15
  ).join(" ");
7
16
  cx.raw = (...args) => args.filter(Boolean).join(" ");
8
17
  cx.dynamic = (name) => {
9
18
  if (!name) return "";
19
+ if (typeof __NAVE_KEEP_CLASSES__ === "string") {
20
+ const decoded = decodedMap(__NAVE_KEEP_CLASSES__);
21
+ return Object.hasOwn(decoded, name) ? decoded[name] ?? "" : "";
22
+ }
10
23
  const map = typeof __NAVE_KEEP_CLASSES__ === "undefined" ? atomClassMap : __NAVE_KEEP_CLASSES__;
11
24
  return Object.hasOwn(map, name) ? map[name] : "";
12
25
  };
@@ -1,4 +1,5 @@
1
1
  import { AtomDefinition } from './atoms.js';
2
+ import './atom-names-B8Ud-7zD.js';
2
3
 
3
4
  interface NaveLightningOptions {
4
5
  /**
@@ -47,4 +48,5 @@ interface NaveLightningAdapter {
47
48
  */
48
49
  declare function navePlugin(options?: NaveLightningOptions): NaveLightningAdapter;
49
50
 
50
- export { type NaveLightningAdapter, type NaveLightningOptions, navePlugin as default, navePlugin };
51
+ export { navePlugin as default, navePlugin };
52
+ export type { NaveLightningAdapter, NaveLightningOptions };
@@ -1,8 +1,12 @@
1
- import { splitByteOrderMark, warningTexts, foldedText } from './chunk-IZQLFUQU.js';
2
- import { validateExtendAtomsHostFree } from './chunk-R6JJZGXC.js';
3
- import { snapshotExtendMap, expandText } from './chunk-S7DZUVV3.js';
4
- import './chunk-NFS2REPQ.js';
5
- import './chunk-LIUB4EES.js';
1
+ import { splitByteOrderMark } from './chunk-2TNTYI4L.js';
2
+ import { orderWarningTexts, warningTexts, foldedText } from './chunk-KKUYU75D.js';
3
+ import { validateExtendAtomsHostFree } from './chunk-63H2FLGU.js';
4
+ import { snapshotExtendMap, expandText } from './chunk-MWHZ26S4.js';
5
+ import './chunk-UVHGEVMV.js';
6
+ import './chunk-SYNQJNVB.js';
7
+ import './chunk-CUL5PLPI.js';
8
+ import './chunk-2K5EBBF2.js';
9
+ import './chunk-GZL2VW7C.js';
6
10
  import { readFileSync } from 'fs';
7
11
 
8
12
  function report(diagnostics, file, extend, onUnknown) {
@@ -19,6 +23,7 @@ function navePlugin(options = {}) {
19
23
  validateExtendAtomsHostFree(extend);
20
24
  const expandToText = (text, file) => {
21
25
  const result = expandText(text, { extend, onUnknown, from: file });
26
+ for (const line of orderWarningTexts(result.warnings, file)) console.warn(line);
22
27
  report(result.diagnostics, file, extend, onUnknown);
23
28
  return result;
24
29
  };
package/dist/postcss.d.ts CHANGED
@@ -1,5 +1,22 @@
1
- import { Plugin } from 'postcss';
1
+ import { Warning, Plugin } from 'postcss';
2
2
  import { AtomDefinition } from './atoms.js';
3
+ import './atom-names-B8Ud-7zD.js';
4
+
5
+ /**
6
+ * The one place the PostCSS host reports a warning: `node.warn()`, except under Next.js's
7
+ * Turbopack, which drops every PostCSS warning. There (detected by `process.env.TURBOPACK` being
8
+ * set) the text is printed with `console.warn` behind the same `file:line:column: ` frame the
9
+ * Lightning CSS adapter prints, and `node.warn()` is not called as well. A tool that runs the
10
+ * plugin itself and reports its warnings turns the printing off (`printWarnings: false`): every
11
+ * warning is then raised, whatever `TURBOPACK` says.
12
+ */
13
+
14
+ /**
15
+ * Whether `warning` is an order warning (one `order-warnings.ts` or `shape-warnings.ts` makes)
16
+ * and not an `onUnknown` problem. No `onUnknown` governs it and it never fails a build, so a tool
17
+ * running the plugin with `printWarnings: false` reports it as a warning, never as a problem.
18
+ */
19
+ declare function isOrderWarning(warning: Warning): boolean;
3
20
 
4
21
  /**
5
22
  * Nave PostCSS plugin — resolves @nave directives.
@@ -17,6 +34,7 @@ import { AtomDefinition } from './atoms.js';
17
34
  * navePlugin() // Nave atoms only, fails build on unknown atom
18
35
  * navePlugin({ extend: myAtoms }) // Nave + consumer atoms
19
36
  * navePlugin({ onUnknown: 'warn' }) // Log and skip instead of failing the build
37
+ * navePlugin({ onUnknown: 'warn', printWarnings: false }) // Raise warnings only, never print
20
38
  *
21
39
  * `extend` is trusted, consumer-authored code (your build config, or the module a path names),
22
40
  * which can already run arbitrary JavaScript at build time: it is not sanitised input. Every
@@ -76,10 +94,19 @@ interface NavePluginOptions {
76
94
  * 'ignore' — silently skip
77
95
  */
78
96
  onUnknown?: 'warn' | 'error' | 'ignore';
97
+ /**
98
+ * Whether a warning may be printed: a problem under 'warn', or an order warning. Under
99
+ * Turbopack (`TURBOPACK` set), which shows no PostCSS warning, the plugin prints each one with
100
+ * `console.warn` instead of raising it (default `true`). `false` raises it as a PostCSS warning
101
+ * only, whatever `TURBOPACK` says: for a tool that runs the plugin itself and reports the
102
+ * warnings it raises, telling the two apart with `isOrderWarning()`.
103
+ */
104
+ printWarnings?: boolean;
79
105
  }
80
106
  declare const navePlugin: {
81
107
  (options?: NavePluginOptions): Plugin;
82
108
  postcss: boolean;
83
109
  };
84
110
 
85
- export { AtomDefinition, type NavePluginOptions, navePlugin as default, navePlugin };
111
+ export { AtomDefinition, navePlugin as default, isOrderWarning, navePlugin };
112
+ export type { NavePluginOptions };