@teacss/config 0.4.7 → 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.
- package/README.md +41 -82
- package/dist/index.d.ts +36 -36
- package/dist/index.js +1 -1
- package/dist/presetTransformDiskCache-BNUNLsPo.js +1 -0
- package/package.json +2 -2
- package/dist/presetTransformDiskCache-Cp5NmI8Q.js +0 -1
package/README.md
CHANGED
|
@@ -1,32 +1,22 @@
|
|
|
1
1
|
# @teacss/config
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Discovery and parsing for TeaCSS CSS-entry configuration.
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
TeaCSS does not use `teacss.config.*`. Configuration is resolved from the CSS
|
|
8
|
-
entry: `package.json` `teacss.entry`, then `index.css`, then `src/index.css`.
|
|
9
|
-
Only existing regular files qualify as entry candidates.
|
|
10
|
-
|
|
11
|
-
`@teacss/config` provides that discovery, directive parsing, preset resolution,
|
|
12
|
-
and recovery behavior to build and editor integrations. It does not scan
|
|
13
|
-
application modules, generate CSS, or own a build tool's watch lifecycle; those
|
|
14
|
-
consumers use its resolved config and source-dependency list.
|
|
15
|
-
|
|
16
|
-
## Usage
|
|
5
|
+
TeaCSS has no `teacss.config.*` file. Entry discovery checks
|
|
6
|
+
`package.json#teacss.entry`, `index.css`, then `src/index.css`.
|
|
17
7
|
|
|
18
8
|
```css
|
|
19
9
|
@preset "standard";
|
|
20
10
|
@source "./src/**/*.{ts,tsx}";
|
|
21
|
-
@custom {
|
|
11
|
+
@custom {
|
|
12
|
+
--color-brand-500: #58a6ff;
|
|
13
|
+
}
|
|
22
14
|
@teacss;
|
|
23
15
|
```
|
|
24
16
|
|
|
25
|
-
The
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
articles short name maps to `@teacss/preset-articles`. Explicit package and
|
|
29
|
-
local-file specifiers remain supported.
|
|
17
|
+
The built-in preset names are `standard`, `shortcuts`, and `icons`.
|
|
18
|
+
Shortcuts does not enable Standard. Package and local-file preset
|
|
19
|
+
specifiers are also supported.
|
|
30
20
|
|
|
31
21
|
```ts
|
|
32
22
|
import { createRecoveryConfigLoader } from "@teacss/config";
|
|
@@ -35,66 +25,35 @@ const loadConfig = createRecoveryConfigLoader();
|
|
|
35
25
|
const { config, sources } = await loadConfig(process.cwd());
|
|
36
26
|
```
|
|
37
27
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
Local preset entries may use top-level `await`. Transitive modules must remain
|
|
71
|
-
synchronous, and every local dependency must use static `import` / `export` or a
|
|
72
|
-
top-level literal CommonJS `require`. A literal `require` inside a function, a
|
|
73
|
-
non-literal `require`, and `require` combined with top-level `await` are rejected,
|
|
74
|
-
as is dynamic `import()`, because those forms cannot be represented as a
|
|
75
|
-
complete, concurrency-safe watch graph.
|
|
76
|
-
|
|
77
|
-
The recovery loader keeps the last valid config while files are temporarily
|
|
78
|
-
invalid during watch mode. Recovery state is isolated by resolved config path
|
|
79
|
-
or inline-config object identity. Superseded concurrent requests cannot replace
|
|
80
|
-
that state or report stale failures. If a local preset or static transitive
|
|
81
|
-
dependency is temporarily missing, its intended path remains in `sources` so
|
|
82
|
-
creating the file can trigger recovery. For an extensionless static dependency
|
|
83
|
-
specifier, the supported exact, extension, and directory-index candidates are
|
|
84
|
-
retained, so creating a file such as `missing.ts` also triggers recovery.
|
|
85
|
-
Consumers that resolve current in-memory CSS through `resolveEntryConfig` can
|
|
86
|
-
use `getConfigSourcesFromError(error)` to retain the same bounded missing-file
|
|
87
|
-
candidates while keeping their own last-valid config snapshot. When that CSS
|
|
88
|
-
has a filesystem identity, pass its filename as the third argument so an
|
|
89
|
-
imported file that points back to the root entry is deduplicated as part of the
|
|
90
|
-
same cycle.
|
|
91
|
-
|
|
92
|
-
`parseEntry`, `scanTopLevelAtRules`, `scanCustomBlocks`, and `diagnoseCustom`
|
|
93
|
-
expose the same structural CSS-entry parsing used by build and editor
|
|
94
|
-
integrations. The scanners ignore directive-like text in comments, strings, and
|
|
95
|
-
nested CSS.
|
|
96
|
-
|
|
97
|
-
## Status
|
|
98
|
-
|
|
99
|
-
Pre-1.0. Keep config behavior aligned across build tools, the CLI, and editor
|
|
100
|
-
tooling.
|
|
28
|
+
`sources` contains the CSS entry, imported and sourced CSS, package preset entry
|
|
29
|
+
files, and static local preset dependency graphs. Build integrations watch this
|
|
30
|
+
list. Package dependency trees and dynamic imports are excluded. Local preset
|
|
31
|
+
entries may use top-level `await`; transitive
|
|
32
|
+
dependencies must stay synchronous and statically discoverable.
|
|
33
|
+
|
|
34
|
+
The recovery loader keeps the last valid configuration during temporary edit
|
|
35
|
+
errors. Recovery state is isolated by entry path or inline-config identity, and
|
|
36
|
+
missing dependency candidates remain in `sources` so file creation can trigger
|
|
37
|
+
a retry.
|
|
38
|
+
Failed loads also retain imported stylesheets, resolved package entries, and
|
|
39
|
+
dependencies found before a later specifier failed to resolve.
|
|
40
|
+
|
|
41
|
+
Local preset transforms use a bounded content-addressed cache under the nearest
|
|
42
|
+
`node_modules/.cache/teacss/preset-transform`. Set
|
|
43
|
+
`TEACSS_PRESET_TRANSFORM_CACHE=false` to disable it.
|
|
44
|
+
|
|
45
|
+
Lower-level APIs:
|
|
46
|
+
|
|
47
|
+
| API | Purpose |
|
|
48
|
+
| ------------------------------------- | ------------------------------------------------------------ |
|
|
49
|
+
| `resolveEntryConfig` | Resolves an entry and returns its source graph. |
|
|
50
|
+
| `entryDiscoveryFiles` | Lists files an integration should watch for entry selection. |
|
|
51
|
+
| `getConfigSourcesFromError` | Recovers bounded source candidates from a failed load. |
|
|
52
|
+
| `parseEntry` | Parses a complete CSS entry. |
|
|
53
|
+
| `scanTopLevelAtRules` | Finds top-level TeaCSS directives safely. |
|
|
54
|
+
| `scanCustomBlocks` / `diagnoseCustom` | Parses and diagnoses `@custom` blocks. |
|
|
55
|
+
|
|
56
|
+
This package does not scan application modules, generate CSS, or manage a build
|
|
57
|
+
tool's lifecycle.
|
|
58
|
+
|
|
59
|
+
Pre-1.0. Keep behavior aligned across build, CLI, and editor integrations.
|
package/dist/index.d.ts
CHANGED
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Preset, UserConfig, UserConfigDefaults } from "@teacss/core";
|
|
2
2
|
//#region src/parseEntry.d.ts
|
|
3
|
-
interface EntrySource {
|
|
3
|
+
export interface EntrySource {
|
|
4
4
|
/** The glob pattern (with any leading `!` stripped). */
|
|
5
5
|
glob: string;
|
|
6
6
|
/** True when the `@source` value was `!`-prefixed (an exclude). */
|
|
7
7
|
exclude: boolean;
|
|
8
8
|
}
|
|
9
|
-
interface EntryCustomDecl {
|
|
9
|
+
export interface EntryCustomDecl {
|
|
10
10
|
/** Custom-property name, e.g. `--color-brand-500`. */
|
|
11
11
|
property: string;
|
|
12
12
|
/** Raw value text, e.g. `#0f766e` or `0 1px 2px #0001, 0 2px 4px #0001`. */
|
|
13
13
|
value: string;
|
|
14
14
|
}
|
|
15
|
-
interface EntryCustomBlock {
|
|
15
|
+
export interface EntryCustomBlock {
|
|
16
16
|
/**
|
|
17
17
|
* Mode name from the prelude (`@custom dark`); undefined for the base
|
|
18
18
|
* `@custom {}`. On a theme variant block, the `dark` sub-block mode.
|
|
@@ -23,7 +23,7 @@ interface EntryCustomBlock {
|
|
|
23
23
|
declarations: EntryCustomDecl[];
|
|
24
24
|
}
|
|
25
25
|
/** A `@custom` prelude, interpreted: base block, mode block, theme variant block, or invalid. */
|
|
26
|
-
type CustomPrelude = {
|
|
26
|
+
export type CustomPrelude = {
|
|
27
27
|
kind: "base";
|
|
28
28
|
} | {
|
|
29
29
|
kind: "mode";
|
|
@@ -43,14 +43,14 @@ type CustomPrelude = {
|
|
|
43
43
|
* whole prelude is the mode name. Shared by `parseEntry` and `diagnoseCustom`
|
|
44
44
|
* so the build and the editor agree on which blocks are alive.
|
|
45
45
|
*/
|
|
46
|
-
declare function parseCustomPrelude(prelude: string | undefined): CustomPrelude;
|
|
47
|
-
interface EntryShortcut {
|
|
46
|
+
export declare function parseCustomPrelude(prelude: string | undefined): CustomPrelude;
|
|
47
|
+
export interface EntryShortcut {
|
|
48
48
|
/** Shortcut class name, e.g. `popup-surface`. */
|
|
49
49
|
name: string;
|
|
50
50
|
/** The shortcut's token expansion, e.g. `p:1 rd:2x bg-color:gray-200@hover`. */
|
|
51
51
|
expansion: string;
|
|
52
52
|
}
|
|
53
|
-
interface EntryConfig {
|
|
53
|
+
export interface EntryConfig {
|
|
54
54
|
/** `@preset "<spec>"` specifiers, in source order. */
|
|
55
55
|
presets: string[];
|
|
56
56
|
/** `@source "<glob>"` entries (`!`-prefixed → exclude). */
|
|
@@ -71,10 +71,10 @@ interface EntryConfig {
|
|
|
71
71
|
* are ignored. Resolving the returned data (loading presets, scanning sources,
|
|
72
72
|
* registering `@custom`) lives in the config/integration layer.
|
|
73
73
|
*/
|
|
74
|
-
declare function parseEntry(css: string): EntryConfig;
|
|
74
|
+
export declare function parseEntry(css: string): EntryConfig;
|
|
75
75
|
//#endregion
|
|
76
76
|
//#region src/customToTheme.d.ts
|
|
77
|
-
interface CustomToThemeResult {
|
|
77
|
+
export interface CustomToThemeResult {
|
|
78
78
|
/**
|
|
79
79
|
* Theme patch to deep-merge over the preset theme (pass as `createGenerator`'s
|
|
80
80
|
* `theme`). Base blocks land at `theme.<ns>...`; mode blocks at
|
|
@@ -94,7 +94,7 @@ interface CustomToThemeResult {
|
|
|
94
94
|
*/
|
|
95
95
|
undeclared: string[];
|
|
96
96
|
}
|
|
97
|
-
interface Namespace {
|
|
97
|
+
export interface Namespace {
|
|
98
98
|
/** Var-name prefix, e.g. `color`, `font-family`, `spacing`. */
|
|
99
99
|
prefix: string;
|
|
100
100
|
/** Theme object key, e.g. `colors`, `fontFamily`, `spacing`. */
|
|
@@ -116,9 +116,9 @@ interface Namespace {
|
|
|
116
116
|
* keyframe registry with a string, so every `animation:*` utility stopped
|
|
117
117
|
* matching. `colors` is the one scale that is deliberately two-level.
|
|
118
118
|
*/
|
|
119
|
-
declare function scaleThemeKeys(theme: Record<string, unknown>): string[];
|
|
120
|
-
declare function buildNamespaces(themeKeys: string[]): Namespace[];
|
|
121
|
-
type CustomClassification = {
|
|
119
|
+
export declare function scaleThemeKeys(theme: Record<string, unknown>): string[];
|
|
120
|
+
export declare function buildNamespaces(themeKeys: string[]): Namespace[];
|
|
121
|
+
export type CustomClassification = {
|
|
122
122
|
ok: true;
|
|
123
123
|
nsKey: string;
|
|
124
124
|
twoLevel: boolean;
|
|
@@ -134,14 +134,14 @@ type CustomClassification = {
|
|
|
134
134
|
* table: which theme key it registers into, or why it can't. Shared by the
|
|
135
135
|
* theme-patch builder and the LSP/build diagnostics so they never drift.
|
|
136
136
|
*/
|
|
137
|
-
declare function classifyCustomVar(name: string, namespaces: Namespace[]): CustomClassification;
|
|
137
|
+
export declare function classifyCustomVar(name: string, namespaces: Namespace[]): CustomClassification;
|
|
138
138
|
/**
|
|
139
139
|
* Whether a classified theme var already has a base value in one of `sources`
|
|
140
140
|
* (the resolved preset theme, or the base-`@custom` patch built beside it).
|
|
141
141
|
* Shared by `customToTheme` and `diagnoseCustom` so the build and the editor
|
|
142
142
|
* agree on what a theme variant may override.
|
|
143
143
|
*/
|
|
144
|
-
declare function hasBaseThemeValue(c: Extract<CustomClassification, {
|
|
144
|
+
export declare function hasBaseThemeValue(c: Extract<CustomClassification, {
|
|
145
145
|
ok: true;
|
|
146
146
|
}>, sources: readonly Record<string, unknown>[]): boolean;
|
|
147
147
|
/**
|
|
@@ -154,10 +154,10 @@ declare function hasBaseThemeValue(c: Extract<CustomClassification, {
|
|
|
154
154
|
* `blocks`, regardless of entry order) already declares, else it lands on
|
|
155
155
|
* `undeclared` and registers nothing. Pure: no generator, no I/O.
|
|
156
156
|
*/
|
|
157
|
-
declare function customToTheme(blocks: EntryCustomBlock[], themeKeys: string[], baseTheme?: Record<string, unknown>): CustomToThemeResult;
|
|
157
|
+
export declare function customToTheme(blocks: EntryCustomBlock[], themeKeys: string[], baseTheme?: Record<string, unknown>): CustomToThemeResult;
|
|
158
158
|
//#endregion
|
|
159
159
|
//#region src/diagnoseCustom.d.ts
|
|
160
|
-
interface CustomDiagnostic {
|
|
160
|
+
export interface CustomDiagnostic {
|
|
161
161
|
/** The custom-property name (`--colour-brand-500`), or the raw prelude for a block-level diagnostic. */
|
|
162
162
|
property: string;
|
|
163
163
|
/** Offset range of the property name (or the at-rule header) in the source (for mapping to an editor range). */
|
|
@@ -181,10 +181,10 @@ interface CustomDiagnostic {
|
|
|
181
181
|
* agree on what registers. Pure: offsets in, no I/O — the caller maps offsets
|
|
182
182
|
* to an editor `Range`.
|
|
183
183
|
*/
|
|
184
|
-
declare function diagnoseCustom(css: string, themeKeys: string[], baseTheme?: Record<string, unknown>): CustomDiagnostic[];
|
|
184
|
+
export declare function diagnoseCustom(css: string, themeKeys: string[], baseTheme?: Record<string, unknown>): CustomDiagnostic[];
|
|
185
185
|
//#endregion
|
|
186
186
|
//#region src/resolveEntryConfig.d.ts
|
|
187
|
-
interface ResolveEntryResult {
|
|
187
|
+
export interface ResolveEntryResult {
|
|
188
188
|
/** UserConfig assembled from the entry — feed straight to `createGenerator`. */
|
|
189
189
|
config: UserConfig;
|
|
190
190
|
/** `@custom` var names that didn't register (decision 11 — for diagnostics/warnings). */
|
|
@@ -193,7 +193,7 @@ interface ResolveEntryResult {
|
|
|
193
193
|
undeclared: string[];
|
|
194
194
|
/** Whether the entry has a `@teacss;` placeholder. */
|
|
195
195
|
hasTeacss: boolean;
|
|
196
|
-
/** Absolute
|
|
196
|
+
/** Absolute config dependencies: followed imports, sourced CSS, package preset entries, and local preset modules. */
|
|
197
197
|
sources: string[];
|
|
198
198
|
}
|
|
199
199
|
/**
|
|
@@ -215,7 +215,7 @@ interface ResolveEntryResult {
|
|
|
215
215
|
* `@import` resolution). Pass `entryFile` when the CSS has a filesystem identity
|
|
216
216
|
* so an imported file that points back to the root entry closes the cycle.
|
|
217
217
|
*/
|
|
218
|
-
declare function resolveEntryConfig(entryCss: string, base: string, entryFile?: string): Promise<ResolveEntryResult>;
|
|
218
|
+
export declare function resolveEntryConfig(entryCss: string, base: string, entryFile?: string): Promise<ResolveEntryResult>;
|
|
219
219
|
//#endregion
|
|
220
220
|
//#region src/resolvePresets.d.ts
|
|
221
221
|
declare function getPresetSourcesFromError(error: unknown): string[];
|
|
@@ -228,10 +228,10 @@ declare function getPresetSourcesFromError(error: unknown): string[];
|
|
|
228
228
|
* local dependency graph take effect on the next resolution. There is no
|
|
229
229
|
* implicit default preset.
|
|
230
230
|
*/
|
|
231
|
-
declare function resolvePresets<Theme extends object = object>(specifiers: string[], base: string): Promise<Preset<Theme>[]>;
|
|
231
|
+
export declare function resolvePresets<Theme extends object = object>(specifiers: string[], base: string): Promise<Preset<Theme>[]>;
|
|
232
232
|
//#endregion
|
|
233
233
|
//#region src/scanCustom.d.ts
|
|
234
|
-
interface ScannedCustomDeclaration {
|
|
234
|
+
export interface ScannedCustomDeclaration {
|
|
235
235
|
property: string;
|
|
236
236
|
value: string;
|
|
237
237
|
/** Property-name offsets in the original source (`end` is exclusive). */
|
|
@@ -243,7 +243,7 @@ interface ScannedCustomDeclaration {
|
|
|
243
243
|
valueStart: number;
|
|
244
244
|
valueEnd: number;
|
|
245
245
|
}
|
|
246
|
-
interface ScannedCustomBlock {
|
|
246
|
+
export interface ScannedCustomBlock {
|
|
247
247
|
mode?: string;
|
|
248
248
|
declarations: ScannedCustomDeclaration[];
|
|
249
249
|
/** Offset of the at-rule's `@` (for block-level diagnostics). */
|
|
@@ -252,7 +252,7 @@ interface ScannedCustomBlock {
|
|
|
252
252
|
open: number;
|
|
253
253
|
close: number;
|
|
254
254
|
}
|
|
255
|
-
interface ScannedTopLevelAtRule {
|
|
255
|
+
export interface ScannedTopLevelAtRule {
|
|
256
256
|
/** At-rule name without the leading `@`. */
|
|
257
257
|
name: string;
|
|
258
258
|
/** Trimmed text between the name and its terminator/opening brace. */
|
|
@@ -263,24 +263,24 @@ interface ScannedTopLevelAtRule {
|
|
|
263
263
|
terminator: ";" | "block" | "eof";
|
|
264
264
|
}
|
|
265
265
|
/** Return string values from exact, top-level at-rules such as `@preset "…"`. */
|
|
266
|
-
declare function scanQuotedDirectives(css: string, directive: string): string[];
|
|
266
|
+
export declare function scanQuotedDirectives(css: string, directive: string): string[];
|
|
267
267
|
/** Whether an exact at-rule name occurs at the top level outside strings/comments. */
|
|
268
|
-
declare function hasTopLevelDirective(css: string, directive: string): boolean;
|
|
268
|
+
export declare function hasTopLevelDirective(css: string, directive: string): boolean;
|
|
269
269
|
/** Scan complete top-level at-rules without matching text in comments, strings, or nested CSS. */
|
|
270
|
-
declare function scanTopLevelAtRules(css: string): ScannedTopLevelAtRule[];
|
|
270
|
+
export declare function scanTopLevelAtRules(css: string): ScannedTopLevelAtRule[];
|
|
271
271
|
/** Scan top-level `@custom` blocks without treating strings, comments, or nested CSS as directives. */
|
|
272
|
-
declare function scanCustomBlocks(css: string): ScannedCustomBlock[];
|
|
272
|
+
export declare function scanCustomBlocks(css: string): ScannedCustomBlock[];
|
|
273
273
|
//#endregion
|
|
274
274
|
//#region src/index.d.ts
|
|
275
|
-
interface LoadConfigResult<U> {
|
|
275
|
+
export interface LoadConfigResult<U> {
|
|
276
276
|
config: U;
|
|
277
|
-
/**
|
|
277
|
+
/** CSS entry graph, package preset entries, and bounded local preset graphs. */
|
|
278
278
|
sources: string[];
|
|
279
279
|
}
|
|
280
280
|
/** Relative files that can change CSS-entry discovery, in resolution order. */
|
|
281
|
-
declare const entryDiscoveryFiles: readonly ["package.json", "index.css", "src/index.css"];
|
|
281
|
+
export declare const entryDiscoveryFiles: readonly ["package.json", "index.css", "src/index.css"];
|
|
282
282
|
/** Find the CSS entry: package.json override → index.css → src/index.css. */
|
|
283
|
-
declare function findEntry(root: string): string | undefined;
|
|
283
|
+
export declare function findEntry(root: string): string | undefined;
|
|
284
284
|
/**
|
|
285
285
|
* Resolve the TeaCSS config from the CSS entry. `configOrPath` is either an
|
|
286
286
|
* inline `UserConfig` (used as-is — programmatic / preset authors) or a root
|
|
@@ -289,11 +289,11 @@ declare function findEntry(root: string): string | undefined;
|
|
|
289
289
|
* empty config (just the caller's `defaults`). An entry that declares no
|
|
290
290
|
* `@preset` warns: config never reaches for a specific preset itself.
|
|
291
291
|
*/
|
|
292
|
-
declare function loadConfig<U extends UserConfig>(cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults): Promise<LoadConfigResult<U>>;
|
|
292
|
+
export declare function loadConfig<U extends UserConfig>(cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults): Promise<LoadConfigResult<U>>;
|
|
293
293
|
/**
|
|
294
294
|
* A config loader that recovers from errors by returning the last good result —
|
|
295
295
|
* useful in dev where the entry CSS may be momentarily broken between edits.
|
|
296
296
|
*/
|
|
297
|
-
declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
|
|
297
|
+
export declare function createRecoveryConfigLoader<U extends UserConfig>(): (cwd?: string, configOrPath?: string | U, defaults?: UserConfigDefaults) => Promise<LoadConfigResult<U>>;
|
|
298
298
|
//#endregion
|
|
299
|
-
export {
|
|
299
|
+
export { getPresetSourcesFromError as getConfigSourcesFromError };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,resolveConfig as g,splitClassTokens as _}from"@teacss/core";import{glob as v}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as b,stat as ee}from"node:fs/promises";import{fileURLToPath as te,pathToFileURL as x}from"node:url";const ne=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],re=new Set(ne);function ie(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function S(e){return Object.keys(e).filter(t=>{if(t===`modes`||t===`defaultMode`||t===`themes`)return!1;let n=e[t];return typeof n!=`object`||!n?!1:t===`colors`||Object.values(n).every(e=>e==null||typeof e==`string`||typeof e==`number`||Array.isArray(e))})}function C(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:ie(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function w(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function T(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return w(e,t,r),r}function E(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&re.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!re.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function D(e,t){if(!(typeof e!=`object`||!e||!Object.hasOwn(e,t)))return e[t]}function O(e,t){for(let n of t){let t=D(n,e.nsKey);if((e.twoLevel?D(D(t,e.colorName),e.step):D(t,e.rest||`DEFAULT`))!=null)return!0}return!1}function k(e,t,n){let r=C(t),i={},a=[],o=[],s=e=>{let t=E(e.startsWith(`--`)?e.slice(2):e,r);return t.ok||a.push(e),t},c=(e,t,n)=>{let r=T(e,t.nsKey);t.twoLevel?w(T(r,t.colorName),t.step,n):w(r,t.rest||`DEFAULT`,n)};for(let t of e){if(t.theme)continue;let e=t.mode?T(T(i,`modes`),t.mode):i;for(let{property:n,value:r}of t.declarations){let t=s(n);t.ok&&c(e,t,r)}}let l=n?[n,i]:void 0;for(let t of e){if(!t.theme)continue;let e=T(T(i,`themes`),t.theme),n=t.mode?T(T(e,`modes`),t.mode):e;for(let{property:e,value:r}of t.declarations){let t=s(e);if(t.ok){if(l&&!O(t,l)){o.push(e);continue}c(n,t,r)}}}return{theme:i,unknown:a,undeclared:o}}const ae=/[A-Za-z0-9-]/,oe=/[\w-]/;function A(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function j(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function M(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=A(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=j(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function se(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of N(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=j(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function ce(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return N(e).some(e=>e.name===n)}function le(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=A(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=j(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function ue(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=A(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=j(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function N(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=A(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=j(e,r,e.length)-1;continue}if(e[r]===`{`){n++;continue}if(e[r]===`}`){n=Math.max(0,n-1);continue}if(n!==0||e[r]!==`@`)continue;let i=r,a=i+1;for(;oe.test(e[a]??``);)a++;if(a===i+1)continue;let o=e.slice(i+1,a),s=[],c=!1;for(let n=a;n<e.length;n++){let l=e[n];if(l===`/`&&e[n+1]===`*`)n=A(e,n,e.length)-1;else if(l===`"`||l===`'`)n=j(e,n,e.length)-1;else if(l===`(`)s.push(`)`);else if(l===`[`)s.push(`]`);else if(l===s.at(-1))s.pop();else if(s.length===0&&l===`;`){t.push({name:o,prelude:M(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=ue(e,n);s>=0&&(t.push({name:o,prelude:M(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&M(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function de(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=A(e,i,n)-1;else if(t===`"`||t===`'`)i=j(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function fe(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=A(e,i,n);else break;let t=de(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&ae.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=A(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function P(e){let t=[];for(let n of N(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=le(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:fe(e,r+1,i),start:n.start,open:r,close:i})}return t}function pe(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function me(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function he(e){return e.split(`\\`).join(`/`)}function ge(e,t,n,r){if(!me(e)||c(e)||!r&&!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let i=he(u(n,d(t,e)));return i.startsWith(`.`)?i:`./${i}`}function _e(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function ve(e,t,n){if(t===n)return e;let r=[];for(let i of N(e)){if(i.terminator!==`;`||i.name!==`preset`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;let o=i.prelude.slice(1,-1).trim(),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=ge(c,t,n,i.name===`source`);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return _e(e,r)}function F(e,n,r,i,a){if(a>32)return e;let s=[];for(let c of N(e)){if(c.name!==`import`||c.terminator!==`;`)continue;let e=pe(c.prelude);if(e===void 0||!me(e))continue;let l=d(n,e),u;try{u=t.statSync(l)}catch{continue}if(!u.isFile())continue;if(r.has(l)){s.push({start:c.start,end:c.end,replacement:``});continue}r.add(l),i.push(l);let f=o(l),p=F(t.readFileSync(l,`utf8`),f,r,i,a+1);p=ve(p,f,n),s.push({start:c.start,end:c.end,replacement:p})}return _e(e,s)}function ye(e,t,n){if(!e.includes(`@import`))return{css:e,files:[]};let r=[];return{css:F(e,t,new Set(n?[d(t,n)]:[]),r,0),files:r}}const be=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function I(e){if(!e)return{kind:`base`};let t=e.split(/\s+/);if(t[0]!==`theme`)return{kind:`mode`,mode:e};let n=t[1];return!n||!be.test(n)||n===`dark`||n===`light`?{kind:`invalid`}:t.length===2?{kind:`theme`,theme:n}:t.length===3&&t[2]===`dark`?{kind:`theme`,theme:n,mode:`dark`}:{kind:`invalid`}}function xe(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function Se(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function L(e){let t=N(e),n=[],r=[],i=[],a=[],o=!1,s=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?o=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(s=!0),e.terminator!==`;`)continue;if(e.name===`shortcut`){let t=e.prelude.search(/\s/);if(t<=0)continue;let n=e.prelude.slice(0,t);if(!/^[A-Za-z_][\w-]*$/.test(n))continue;let r=Se(e.prelude.slice(t).trimStart())?.trim();r&&i.push({name:n,expansion:r});continue}if(e.name!==`preset`&&e.name!==`source`&&e.name!==`safelist`)continue;let t=Se(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}if(e.name===`safelist`){a.push(t);continue}let c=t.startsWith(`!`),l=c?t.slice(1):t;l&&r.push({glob:l,exclude:c})}return{presets:n,sources:r,custom:o?P(e).flatMap(({mode:e,declarations:t})=>{let n=I(e);return n.kind===`invalid`?[]:[{mode:n.kind===`base`?void 0:n.mode,...n.kind===`theme`?{theme:n.theme}:{},declarations:t.map(({property:e,value:t})=>({property:e,value:xe(t).trim()}))}]}):[],shortcuts:i,safelist:a,hasTeacss:s}}let Ce;function we(){return Ce??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const R=new Map,z=new WeakMap,Te=16*1024*1024,B=new Map;let V=0;const Ee={articles:`@teacss/preset-articles`,icons:`@teacss/preset-icons`,standard:`@teacss/preset-standard`};function De(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function Oe(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(Ee,t)?Ee[t]:void 0;return i?De(i,r):r.resolve(t)}function H(e){return e.startsWith(`.`)||c(e)}function U(e){try{return a(e)}catch{return d(e)}}function W(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function ke(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function G(e,t,n){let r=W(e,n);return t.packageRoot===void 0?r===void 0&&ke(e,t.fallbackRoot):r===t.packageRoot}function K(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=U(e.filename);if(G(a,r,i)){t.add(a);for(let a of e.children)K(a,t,n,r,i)}}function Ae(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&c(t))return U(t);if(typeof n==`string`&&n.startsWith(`file:`))return U(te(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(!(!l||!u||!l.startsWith(`.`)&&!c(l)))return U(c(l)?l:d(o(u),l))}async function je(e,t){let n=R.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);R.set(e,a),await n;try{return{evaluation:t()}}finally{r(),R.get(e)===a&&R.delete(e)}}function Me(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function q(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const J=Symbol(`uncacheable transform option`);function Y(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw J;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw J;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw J}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?Y(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw J;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw J;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw J;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${Y(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function Ne(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function Pe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Fe(e){try{return Y({babel:Pe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ie(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function Le(e,t){let n=B.get(e);n&&(V-=n.bytes,B.delete(e));let r=Ie(e,t.source,t.code,t.facts);if(!(r>Te))for(B.set(e,{...t,bytes:r}),V+=r;B.size>256||V>Te;){let e=B.keys().next();if(e.done)break;let t=B.get(e.value);B.delete(e.value),t&&(V-=t.bytes)}}function Re(e){return{...e,dependencies:Array.from(e.dependencies)}}function ze(e,t,n,r,i,a){let o=t.filename?U(t.filename):n,s=Ne(e,t),c=Fe(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:B.get(l);if(l!==void 0&&u?.source===s.source)return B.delete(l),B.set(l,u),G(o,r,i)&&q(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return Le(l,{code:f.code,facts:e,source:s.source}),G(o,r,i)&&q(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=Me(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&Le(l,{code:t,facts:p,source:s.source}),G(o,r,i)&&q(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Re(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Be=/\.[cm]?[jt]sx?$/;function Ve(e,t,n){let r=U(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function He(t,n,r){if(r.startsWith(`node:`))return[];try{let i=H(r)?t.esmResolve(r,{parentURL:x(n).href,try:!0}):e(n).resolve(r);if(!i)return H(r)?Ve(t,n,r):[];let a=i.startsWith(`file:`)?te(i):i;return c(a)?[U(a)]:[]}catch{return H(r)?Ve(t,n,r):[]}}async function Ue(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Be.test(s(d)))continue;let f;try{f=await b(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=ze(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of He(t,d,e))a.has(n)||!G(n,r,i)||(a.add(n),c.push(n))}return l}async function We(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-Cp5NmI8Q.js`);return n(e,import.meta.url,t)}catch{return}}function X(e,t){if(!e||typeof e!=`object`)return;let n=z.get(e)??[];z.set(e,Array.from(new Set([...n,...t])))}function Z(e){return e&&typeof e==`object`?[...z.get(e)??[]]:[]}async function Ge(t,n,r){let i=U(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:W(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([we(),We(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=ze(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))K(t,c,e,u,l);for(let t of c)K(a.cache[t],c,e,u,l)};try{let e=await Ue(i,m,f,u,l,c,p)??await b(i,`utf8`),{evaluation:t}=await je(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=Ae(e);throw X(e,t&&G(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ke(e){let t=await ee(e),n=x(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function qe(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e=Oe(a,t);try{let t;if(H(a)){let t=await Ge(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}else t=await Ke(e);if(t==null)throw Error(`@preset "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof t==`function`?await t():t)}catch(t){throw X(t,H(a)?[...r,U(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function Je(e,t){return(await qe(e,t)).presets}async function Ye(e,t,n){let r=e.filter(e=>!e.exclude).map(e=>e.glob);if(r.length===0)return{shortcuts:[],safelist:[],files:[]};let a=await v(r,{cwd:t,absolute:!0,ignore:e.filter(e=>e.exclude).map(e=>e.glob),expandDirectories:!1}),o=new Set(n),s=a.filter(e=>e.endsWith(`.css`)&&!o.has(e)).sort(),c=[],l=[];for(let e of s){let t;try{t=i(e,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=L(t);c.push(...n.shortcuts),l.push(...n.safelist)}return{shortcuts:c,safelist:l,files:s}}async function Xe(e,t,n){let r=ye(e,t,n),i=L(r.css),[a,o]=await Promise.all([i.presets.length?qe(i.presets,t):{presets:[],sources:[]},Ye(i.sources,t,r.files)]),s=a.presets,c=await g({presets:s}),l=S(c.theme),{theme:u,unknown:d,undeclared:f}=k(i.custom,l,c.theme),p=[...i.sources.filter(e=>!e.exclude).map(e=>e.glob),...i.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],m=[...o.shortcuts,...i.shortcuts],v=Object.fromEntries(m.map(({name:e,expansion:t})=>[e,t])),y=[...new Set([...o.safelist,...i.safelist].flatMap(e=>_(h(e))))],b=[...new Set(i.custom.map(e=>e.theme).filter(e=>!!e))];return{config:{presets:s,theme:u,...i.sources.length?{content:{filesystem:p}}:{},...m.length?{shortcuts:v}:{},...y.length?{safelist:y}:{},...b.length?{autocomplete:{templates:[`theme-(${b.join(`|`)})`]}}:{}},unknown:d,undeclared:f,hasTeacss:r.files.length===0?i.hasTeacss:L(e).hasTeacss,sources:[...r.files,...o.files,...a.sources]}}const Ze=ne.join(` `);function Q(e,t){switch(t){case`unknown-prefix`:return`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`;case`illegal-color-step`:return`@custom var "${e}" has an illegal color step — palette steps are ${Ze}.`;case`undeclared-theme-variable`:return`@custom theme var "${e}" overrides no declared base value — not registered. Declare it in the preset theme or a base @custom block first.`;case`invalid-theme-prelude`:return`@custom prelude "${e}" is not a theme declaration — use \`@custom theme <name> {}\` or \`@custom theme <name> dark {}\` with a kebab-case name (\`dark\`/\`light\` reserved). The block registers nothing.`}}function Qe(e,t,n){let r=C(t),i=[],a=P(e),o=n?[n,k(a.filter(e=>I(e.mode).kind===`base`).map(e=>({declarations:e.declarations})),t).theme]:void 0;for(let e of a){let t=I(e.mode);if(t.kind===`invalid`){i.push({property:e.mode,start:e.start,end:e.open,reason:`invalid-theme-prelude`,message:Q(e.mode,`invalid-theme-prelude`)});continue}for(let n of e.declarations){let{property:e,start:a,end:s}=n,c=E(e.slice(2),r);if(!c.ok){i.push({property:e,start:a,end:s,reason:c.reason,message:Q(e,c.reason)});continue}t.kind===`theme`&&o&&!O(c,o)&&i.push({property:e,start:a,end:s,reason:`undeclared-theme-variable`,message:Q(e,`undeclared-theme-variable`)})}}return i}const $=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[$e,...et]=$;function tt(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(Z(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function nt(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function rt(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?N(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function it(e){try{let t=JSON.parse(n.readFileSync(l(e,$e),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function at(e){let t=it(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of et){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&rt(r))return r}}async function ot(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:nt(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:at(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await Xe(n.readFileSync(a,`utf8`),o(a),a)}catch(e){throw X(e,[a]),e}let{config:c}=s,l=nt(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function st(){let e=new Map,t=new Map,n=new Map,r=new Map,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=(e,n)=>e?t.get(e):n?a.get(n):void 0,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l:void 0,_=h?(t.get(h)??0)+1:g?(a.get(g)??0)+1:0;h?t.set(h,_):g&&a.set(g,_);let v=ot(c,l,f).then(n=>(h&&t.get(h)===_?(e.set(h,n),r.delete(h)):g&&a.get(g)===_&&(i.set(g,n),s.delete(g)),n),async n=>{let o=h?t.get(h)===_:!g||a.get(g)===_;if(!o){let e=await u(h,g);if(e)return e}let c=h?e.get(h):g?i.get(g):void 0;if(!c)throw n;if(o){let e=tt(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.error(`[@teacss/config] Error resolving config from the CSS entry:`,n),h?r.set(h,e):g&&s.set(g,e));let t=Array.from(new Set([...c.sources,...Z(n)]));return t.length===c.sources.length?c:{...c,sources:t}}return c});return h?n.set(h,v):g&&o.set(g,v),v}}export{C as buildNamespaces,E as classifyCustomVar,st as createRecoveryConfigLoader,k as customToTheme,Qe as diagnoseCustom,$ as entryDiscoveryFiles,at as findEntry,Z as getConfigSourcesFromError,O as hasBaseThemeValue,ce as hasTopLevelDirective,ot as loadConfig,I as parseCustomPrelude,L as parseEntry,Xe as resolveEntryConfig,Je as resolvePresets,S as scaleThemeKeys,P as scanCustomBlocks,se as scanQuotedDirectives,N as scanTopLevelAtRules};
|
|
1
|
+
import{createRequire as e}from"node:module";import*as t from"node:fs";import n,{existsSync as r,readFileSync as i,realpathSync as a}from"node:fs";import{dirname as o,extname as s,isAbsolute as c,join as l,relative as u,resolve as d,sep as f}from"node:path";import p from"node:process";import{consola as m}from"consola";import{expandClassGroups as h,resolveConfig as g,splitClassTokens as _}from"@teacss/core";import{glob as v}from"tinyglobby";import{Buffer as y}from"node:buffer";import{readFile as b,stat as ee}from"node:fs/promises";import{fileURLToPath as te,pathToFileURL as x}from"node:url";const ne=[`100`,`150`,`200`,`300`,`400`,`500`,`600`,`700`,`800`,`850`,`900`,`950`],re=new Set(ne);function ie(e){return e.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function S(e){return Object.keys(e).filter(t=>{if(t===`modes`||t===`defaultMode`||t===`themes`)return!1;let n=e[t];return typeof n!=`object`||!n?!1:t===`colors`||Object.values(n).every(e=>e==null||typeof e==`string`||typeof e==`number`||Array.isArray(e))})}function C(e){return e.map(e=>({key:e,prefix:e===`colors`||e===`semanticColors`?`color`:ie(e),twoLevel:e===`colors`,semanticColor:e===`semanticColors`})).sort((e,t)=>t.prefix.length-e.prefix.length)}function w(e,t,n){Object.defineProperty(e,t,{value:n,configurable:!0,enumerable:!0,writable:!0})}function T(e,t){let n=Object.hasOwn(e,t)?e[t]:void 0;if(typeof n==`object`&&n&&!Array.isArray(n))return n;let r={};return w(e,t,r),r}function E(e,t){let n=t.filter(t=>e===t.prefix||e.startsWith(`${t.prefix}-`)),r=n.find(e=>e.key===`colors`),i=n.find(e=>e.semanticColor);if(r&&i){let t=e===`color`?``:e.slice(6),n=t.lastIndexOf(`-`),a=n>0?t.slice(0,n):``,o=n>0?t.slice(n+1):``;return a&&re.has(o)?{ok:!0,nsKey:r.key,twoLevel:!0,rest:t,colorName:a,step:o}:a&&/^\d+$/.test(o)?{ok:!1,reason:`illegal-color-step`}:t?{ok:!0,nsKey:i.key,twoLevel:!1,rest:t}:{ok:!1,reason:`unknown-prefix`}}let a=n[0];if(!a)return{ok:!1,reason:`unknown-prefix`};let o=e===a.prefix?``:e.slice(a.prefix.length+1);if(a.twoLevel){let e=o.lastIndexOf(`-`),t=e>0?o.slice(0,e):``,n=e>0?o.slice(e+1):``;return!t||!re.has(n)?{ok:!1,reason:`illegal-color-step`}:{ok:!0,nsKey:a.key,twoLevel:!0,rest:o,colorName:t,step:n}}return{ok:!0,nsKey:a.key,twoLevel:!1,rest:o}}function D(e,t){if(typeof e==`object`&&e&&Object.hasOwn(e,t))return e[t]}function O(e,t){for(let n of t){let t=D(n,e.nsKey);if((e.twoLevel?D(D(t,e.colorName),e.step):D(t,e.rest||`DEFAULT`))!=null)return!0}return!1}function k(e,t,n){let r=C(t),i={},a=[],o=[],s=e=>{let t=E(e.startsWith(`--`)?e.slice(2):e,r);return t.ok||a.push(e),t},c=(e,t,n)=>{let r=T(e,t.nsKey);t.twoLevel?w(T(r,t.colorName),t.step,n):w(r,t.rest||`DEFAULT`,n)};for(let t of e){if(t.theme)continue;let e=t.mode?T(T(i,`modes`),t.mode):i;for(let{property:n,value:r}of t.declarations){let t=s(n);t.ok&&c(e,t,r)}}let l=n?[n,i]:void 0;for(let t of e){if(!t.theme)continue;let e=T(T(i,`themes`),t.theme),n=t.mode?T(T(e,`modes`),t.mode):e;for(let{property:e,value:r}of t.declarations){let t=s(e);if(t.ok){if(l&&!O(t,l)){o.push(e);continue}c(n,t,r)}}}return{theme:i,unknown:a,undeclared:o}}const ae=/[A-Za-z0-9-]/,oe=/[\w-]/;function A(e,t,n){let r=e.indexOf(`*/`,t+2);return r<0||r>=n?n:r+2}function j(e,t,n){let r=e[t];for(let i=t+1;i<n;i++)if(e[i]===`\\`)i++;else if(e[i]===r)return i+1;return n}function M(e,t,n){let r=``;for(let i=t;i<n;i++)if(e[i]===`/`&&e[i+1]===`*`)i=A(e,i,n)-1,r+=` `;else if(e[i]===`"`||e[i]===`'`){let t=j(e,i,n);r+=e.slice(i,t),i=t-1}else r+=e[i];return r.trim()}function se(e,t){let n=[],r=t.startsWith(`@`)?t.slice(1):t;for(let t of N(e)){if(t.name!==r||t.terminator!==`;`)continue;let e=t.prelude[0];if(e!==`"`&&e!==`'`)continue;let i=j(t.prelude,0,t.prelude.length);i!==t.prelude.length||i<=1||t.prelude[i-1]!==e||n.push(t.prelude.slice(1,i-1))}return n}function ce(e,t){let n=t.startsWith(`@`)?t.slice(1):t;return N(e).some(e=>e.name===n)}function le(e,t){for(let n=t;n<e.length;n++)if(e[n]===`/`&&e[n+1]===`*`)n=A(e,n,e.length)-1;else if(e[n]===`"`||e[n]===`'`)n=j(e,n,e.length)-1;else if(e[n]===`{`)return n;else if(e[n]===`;`||e[n]===`}`)return-1;return-1}function ue(e,t){let n=1;for(let r=t+1;r<e.length;r++)if(e[r]===`/`&&e[r+1]===`*`)r=A(e,r,e.length)-1;else if(e[r]===`"`||e[r]===`'`)r=j(e,r,e.length)-1;else if(e[r]===`{`)n++;else if(e[r]===`}`&&--n===0)return r;return-1}function N(e){let t=[],n=0;for(let r=0;r<e.length;r++){if(e[r]===`/`&&e[r+1]===`*`){r=A(e,r,e.length)-1;continue}if(e[r]===`"`||e[r]===`'`){r=j(e,r,e.length)-1;continue}if(e[r]===`{`){n++;continue}if(e[r]===`}`){n=Math.max(0,n-1);continue}if(n!==0||e[r]!==`@`)continue;let i=r,a=i+1;for(;oe.test(e[a]??``);)a++;if(a===i+1)continue;let o=e.slice(i+1,a),s=[],c=!1;for(let n=a;n<e.length;n++){let l=e[n];if(l===`/`&&e[n+1]===`*`)n=A(e,n,e.length)-1;else if(l===`"`||l===`'`)n=j(e,n,e.length)-1;else if(l===`(`)s.push(`)`);else if(l===`[`)s.push(`]`);else if(l===s.at(-1))s.pop();else if(s.length===0&&l===`;`){t.push({name:o,prelude:M(e,a,n),start:i,end:n+1,terminator:`;`}),r=n,c=!0;break}else if(s.length===0&&l===`{`){let s=ue(e,n);s>=0&&(t.push({name:o,prelude:M(e,a,n),start:i,end:s+1,terminator:`block`}),r=s,c=!0);break}}if(!c&&M(e,a,e.length)===``){t.push({name:o,prelude:``,start:i,end:e.length,terminator:`eof`});break}}return t}function de(e,t,n){let r=[];for(let i=t;i<n;i++){let t=e[i];if(t===`/`&&e[i+1]===`*`)i=A(e,i,n)-1;else if(t===`"`||t===`'`)i=j(e,i,n)-1;else if(t===`(`)r.push(`)`);else if(t===`[`)r.push(`]`);else if(t===`{`)r.push(`}`);else if(t===r.at(-1))r.pop();else if(t===`;`&&r.length===0)return i}return n}function fe(e,t,n){let r=[];for(let i=t;i<n;){for(;i<n;)if(/\s/.test(e[i]))i++;else if(e[i]===`/`&&e[i+1]===`*`)i=A(e,i,n);else break;let t=de(e,i,n);if(e[i]!==`-`||e[i+1]!==`-`){i=t+1;continue}let a=i+2;for(;a<n&&ae.test(e[a]);)a++;if(a===i+2){i=t+1;continue}let o=a;for(;o<n;)if(/\s/.test(e[o]))o++;else if(e[o]===`/`&&e[o+1]===`*`)o=A(e,o,n);else break;if(e[o]!==`:`){i=t+1;continue}let s=o+1,c=e.slice(s,t),l=c.trim(),u=s+c.length-c.trimStart().length,d=u+l.length;r.push({property:e.slice(i,a),value:l,start:i,end:a,colon:o,valueStart:u,valueEnd:d}),i=t+1}return r}function P(e){let t=[];for(let n of N(e)){if(n.name!==`custom`||n.terminator!==`block`)continue;let r=le(e,n.start+7);if(r<0)continue;let i=n.end-1;t.push({mode:n.prelude||void 0,declarations:fe(e,r+1,i),start:n.start,open:r,close:i})}return t}function pe(e){let t=e,n=/^url\(\s*([^)]*?)\s*\)$/i.exec(t);if(n)t=n[1];else if(/^url\(/i.test(t))return;let r=t[0];if(r===`"`||r===`'`){if(t.length<2||t[t.length-1]!==r)return;let e=t.slice(1,-1);return e.includes(r)?void 0:e}return n?t:void 0}function me(e){return!(!e||e.startsWith(`//`)||/^[a-z][\w+.-]*:/i.test(e))}function he(e){return e.split(`\\`).join(`/`)}function ge(e,t,n,r){if(!me(e)||c(e)||!r&&!e.startsWith(`./`)&&!e.startsWith(`../`))return e;let i=he(u(n,d(t,e)));return i.startsWith(`.`)?i:`./${i}`}function _e(e,t){if(t.length===0)return e;t.sort((e,t)=>e.start-t.start);let n=``,r=0;for(let i of t)n+=e.slice(r,i.start)+i.replacement,r=i.end;return n+e.slice(r)}function ve(e,t,n){if(t===n)return e;let r=[];for(let i of N(e)){if(i.terminator!==`;`||i.name!==`preset`&&i.name!==`source`)continue;let a=i.prelude[0];if(a!==`"`&&a!==`'`||i.prelude[i.prelude.length-1]!==a)continue;let o=i.prelude.slice(1,-1).trim(),s=i.name===`source`&&o.startsWith(`!`),c=s?o.slice(1):o,l=ge(c,t,n,i.name===`source`);if(l===c)continue;let u=e.slice(i.start,i.end).replace(i.prelude,`${a}${s?`!`:``}${l}${a}`);r.push({start:i.start,end:i.end,replacement:u})}return _e(e,r)}function F(e,n,r,i,a){if(a>32)return e;let s=[];for(let c of N(e)){if(c.name!==`import`||c.terminator!==`;`)continue;let e=pe(c.prelude);if(e===void 0||!me(e))continue;let l=d(n,e),u;try{u=t.statSync(l)}catch{continue}if(!u.isFile())continue;if(r.has(l)){s.push({start:c.start,end:c.end,replacement:``});continue}r.add(l),i.push(l);let f=o(l),p=F(t.readFileSync(l,`utf8`),f,r,i,a+1);p=ve(p,f,n),s.push({start:c.start,end:c.end,replacement:p})}return _e(e,s)}function ye(e,t,n){if(!e.includes(`@import`))return{css:e,files:[]};let r=[];return{css:F(e,t,new Set(n?[d(t,n)]:[]),r,0),files:r}}const be=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/;function I(e){if(!e)return{kind:`base`};let t=e.split(/\s+/);if(t[0]!==`theme`)return{kind:`mode`,mode:e};let n=t[1];return!n||!be.test(n)||n===`dark`||n===`light`?{kind:`invalid`}:t.length===2?{kind:`theme`,theme:n}:t.length===3&&t[2]===`dark`?{kind:`theme`,theme:n,mode:`dark`}:{kind:`invalid`}}function xe(e){let t,n=0,r=null;for(let i=0;i<e.length;i++){let a=e[i];if(r)a===`\\`?i++:a===r&&(r=null);else if(a===`"`||a===`'`)r=a;else if(a===`/`&&e[i+1]===`*`){let r=e.indexOf(`*/`,i+2),a=r<0?e.length:r+2;(t??=[]).push(e.slice(n,i),` `),n=a,i=a-1}}return t?`${t.join(``)}${e.slice(n)}`:e}function Se(e){let t=e[0];if(t===`"`||t===`'`)for(let n=1;n<e.length;n++){let r=e[n];if(r===`\\`)n++;else if(r===t)return n===e.length-1?e.slice(1,n):void 0}}function L(e){let t=N(e),n=[],r=[],i=[],a=[],o=!1,s=!1;for(let e of t){if(e.name===`custom`&&e.terminator===`block`?o=!0:e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`&&(s=!0),e.terminator!==`;`)continue;if(e.name===`shortcut`){let t=e.prelude.search(/\s/);if(t<=0)continue;let n=e.prelude.slice(0,t);if(!/^[A-Za-z_][\w-]*$/.test(n))continue;let r=Se(e.prelude.slice(t).trimStart())?.trim();r&&i.push({name:n,expansion:r});continue}if(e.name!==`preset`&&e.name!==`source`&&e.name!==`safelist`)continue;let t=Se(e.prelude)?.trim();if(!t)continue;if(e.name===`preset`){n.push(t);continue}if(e.name===`safelist`){a.push(t);continue}let c=t.startsWith(`!`),l=c?t.slice(1):t;l&&r.push({glob:l,exclude:c})}return{presets:n,sources:r,custom:o?P(e).flatMap(({mode:e,declarations:t})=>{let n=I(e);return n.kind===`invalid`?[]:[{mode:n.kind===`base`?void 0:n.mode,...n.kind===`theme`?{theme:n.theme}:{},declarations:t.map(({property:e,value:t})=>({property:e,value:xe(t).trim()}))}]}):[],shortcuts:i,safelist:a,hasTeacss:s}}let Ce;function we(){return Ce??=import(`jiti`).then(({createJiti:e})=>({createJiti:e,transformer:e(import.meta.url,{fsCache:!1,interopDefault:!0,moduleCache:!1})}))}const R=new Map,z=new WeakMap,Te=16777216,B=new Map;let V=0;const Ee={icons:`@teacss/preset-icons`,shortcuts:`@teacss/preset-shortcuts`,standard:`@teacss/preset-standard`};function De(t,n){try{return n.resolve(t)}catch(r){let i;try{i=n.resolve(`teacss/package.json`)}catch{throw r}return e(i).resolve(t)}}function Oe(t,n){if(t.startsWith(`.`)||c(t))return d(n,t);let r=e(d(n,`_`)),i=Object.hasOwn(Ee,t)?Ee[t]:void 0;return i?De(i,r):r.resolve(t)}function H(e){return e.startsWith(`.`)||c(e)}function U(e){try{return a(e)}catch{return d(e)}}function W(e,t){let n=o(e),i=[];for(;;){if(t.has(n)){let e=t.get(n);for(let n of i)t.set(n,e);return e}if(i.push(n),r(d(n,`package.json`))){for(let e of i)t.set(e,n);return n}let e=o(n);if(e===n){for(let e of i)t.set(e,void 0);return}n=e}}function ke(e,t){let n=u(t,e);return n===``||!c(n)&&n!==`..`&&!n.startsWith(`..${f}`)}function G(e,t,n){let r=W(e,n);return t.packageRoot===void 0?r===void 0&&ke(e,t.fallbackRoot):r===t.packageRoot}function K(e,t,n,r,i){if(!e||n.has(e)||(n.add(e),!c(e.filename)))return;let a=U(e.filename);if(G(a,r,i)){t.add(a);for(let a of e.children)K(a,t,n,r,i)}}function Ae(e){if(!e||typeof e!=`object`)return;let t,n,r;try{t=Reflect.get(e,`path`),n=Reflect.get(e,`url`),r=Reflect.get(e,`message`)}catch{return}if(typeof t==`string`&&c(t))return U(t);if(typeof n==`string`&&n.startsWith(`file:`))return U(te(n));if(typeof r!=`string`)return;let i=/Cannot find module ['"]([^'"]+)['"] from ['"]([^'"]+)['"]/.exec(r),a=/Cannot find module ['"]([^'"]+)['"][\s\S]*?Require stack:\s*\n- ([^\n]+)/.exec(r),s=i??a;if(!s)return;let l=s[1],u=s[2];if(l&&u&&(l.startsWith(`.`)||c(l)))return U(c(l)?l:d(o(u),l))}async function je(e,t){let n=R.get(e)??Promise.resolve(),r,i=new Promise(e=>{r=e}),a=n.then(()=>i);R.set(e,a),await n;try{return{evaluation:t()}}finally{r(),R.get(e)===a&&R.delete(e)}}function Me(e){return()=>({visitor:{AwaitExpression(t){t.getFunctionParent()||(e.hasTopLevelAwait=!0)},CallExpression(t){t.node.callee?.type===`Identifier`&&t.node.callee.name===`jitiImport`&&(e.hasDynamicImport=!0);let n=t.node.arguments?.[0];if(t.node.callee?.type!==`Identifier`||t.node.callee.name!==`require`)return;let r=n?.type===`StringLiteral`&&typeof n.value==`string`;r&&e.dependencies.add(n.value),typeof t.node.start==`number`&&(r?t.getFunctionParent()?e.hasNestedRequire=!0:e.hasTopLevelRequire=!0:e.hasNonLiteralRequire=!0)},ForOfStatement(t){t.node.await&&!t.getFunctionParent()&&(e.hasTopLevelAwait=!0)}}})}function q(e,t,n){if(e.hasDynamicImport)throw Error(`Dynamic imports are not supported in local preset modules: "${t}". Use static imports so TeaCSS can track and reload the complete graph.`);if(e.hasNonLiteralRequire)throw Error(`CommonJS require() specifiers must be string literals in local preset modules: "${t}".`);if(e.hasNestedRequire)throw Error(`CommonJS require() is only supported at module top level in local preset modules: "${t}".`);if(e.hasTopLevelRequire&&e.hasTopLevelAwait)throw Error(`CommonJS require() cannot be combined with top-level await in a local preset module: "${t}". Use a static import instead.`);if(t!==n&&e.hasTopLevelAwait)throw Error(`Top-level await is only supported in the local preset entry module: "${t}".`)}const J=Symbol(`uncacheable transform option`);function Y(e,t=new Set){if(e===null)return`n`;if(typeof e==`string`)return`s${JSON.stringify(e)}`;if(typeof e==`boolean`)return e?`b1`:`b0`;if(typeof e==`number`)return Number.isNaN(e)?`dNaN`:e===1/0?`dInfinity`:e===-1/0?`d-Infinity`:Object.is(e,-0)?`d-0`:`d${JSON.stringify(e)}`;if(e===void 0)return`u`;if(typeof e!=`object`||t.has(e))throw J;t.add(e);try{if(Array.isArray(e)){for(let t of Reflect.ownKeys(e)){if(t===`length`)continue;if(typeof t!=`string`)throw J;let n=Number(t),r=Object.getOwnPropertyDescriptor(e,t);if(!Number.isSafeInteger(n)||n<0||String(n)!==t||n>=e.length||!r?.enumerable||!(`value`in r))throw J}let n=Array.from({length:e.length},(n,r)=>{let i=Object.getOwnPropertyDescriptor(e,String(r));return i&&`value`in i?Y(i.value,t):`h`});return`a${e.length}[${n.join(`,`)}]`}if(Object.getPrototypeOf(e)!==Object.prototype&&Object.getPrototypeOf(e)!==null)throw J;return`o{${Reflect.ownKeys(e).map(t=>{if(typeof t!=`string`)throw J;let n=Object.getOwnPropertyDescriptor(e,t);if(!n?.enumerable||!(`value`in n))throw J;return[t,n.value]}).sort(([e],[t])=>e.localeCompare(t)).map(([e,n])=>`${JSON.stringify(e)}:${Y(n,t)}`).join(`,`)}}`}finally{t.delete(e)}}function Ne(e,t){return{...t,async:!1,interopDefault:t.interopDefault??!0,jsx:t.jsx??e.options.jsx,retainLines:t.retainLines??e.options.transformOptions?.retainLines}}function Pe(e){if(!(e&&Object.getPrototypeOf(e)===Object.prototype&&Reflect.ownKeys(e).length===0))return e}function Fe(e){try{return Y({babel:Pe(e.babel),interopDefault:e.interopDefault,jsx:e.jsx,retainLines:e.retainLines,ts:e.ts})}catch{return}}function Ie(e,t,n,r){let i=y.byteLength(e)+y.byteLength(t)+y.byteLength(n);for(let e of r.dependencies)i+=y.byteLength(e);return i}function Le(e,t){let n=B.get(e);n&&(V-=n.bytes,B.delete(e));let r=Ie(e,t.source,t.code,t.facts);if(!(r>Te))for(B.set(e,{...t,bytes:r}),V+=r;B.size>256||V>Te;){let e=B.keys().next();if(e.done)break;let t=B.get(e.value);B.delete(e.value),t&&(V-=t.bytes)}}function Re(e){return{...e,dependencies:Array.from(e.dependencies)}}function ze(e,t,n,r,i,a){let o=t.filename?U(t.filename):n,s=Ne(e,t),c=Fe(s),l=c===void 0?void 0:`${o}\0${c}`,u=l===void 0?void 0:B.get(l);if(l!==void 0&&u?.source===s.source)return B.delete(l),B.set(l,u),G(o,r,i)&&q(u.facts,o,n),{code:u.code,dependencies:u.facts.dependencies};let d=c===void 0?void 0:{filename:o,mode:c,source:s.source},f=d===void 0?void 0:a?.read(d);if(l!==void 0&&f){let e={...f.facts,dependencies:new Set(f.facts.dependencies)};return Le(l,{code:f.code,facts:e,source:s.source}),G(o,r,i)&&q(e,o,n),{code:f.code,dependencies:e.dependencies}}let p={dependencies:new Set,hasDynamicImport:!1,hasNestedRequire:!1,hasNonLiteralRequire:!1,hasTopLevelAwait:!1,hasTopLevelRequire:!1},m=Me(p),h=Error.prepareStackTrace,g=Error.stackTraceLimit;try{let t=e.transform({...s,babel:{...s.babel,plugins:[...Array.isArray(s.babel?.plugins)?s.babel.plugins:[],m]}});return l!==void 0&&Le(l,{code:t,facts:p,source:s.source}),G(o,r,i)&&q(p,o,n),d!==void 0&&a?.write(d,{code:t,facts:Re(p)}),{code:t,dependencies:p.dependencies}}finally{Error.prepareStackTrace=h,Error.stackTraceLimit=g}}const Be=/\.[cm]?[jt]sx?$/;function X(e,t,n){let r=U(c(n)?n:d(o(t),n));if(s(r))return[r];let i=Array.from(new Set([``,...e.options.extensions??[],`.json`])),a=[r,d(r,`index`)].flatMap(e=>i.map(t=>`${e}${t}`));return a.push(d(r,`package.json`)),a}function Ve(t,n,r){if(r.startsWith(`node:`))return[];try{let i=H(r)?t.esmResolve(r,{parentURL:x(n).href,try:!0}):e(n).resolve(r);if(!i)return H(r)?X(t,n,r):[];let a=i.startsWith(`file:`)?te(i):i;return c(a)?[U(a)]:[]}catch{return H(r)?X(t,n,r):[]}}async function He(e,t,n,r,i,a,o){let c=[e],l;for(let u=0;u<c.length;u++){let d=c[u];if(!d||!Be.test(s(d)))continue;let f;try{f=await b(d,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}d===e&&(l=f);let{dependencies:p}=ze(n,{source:f,filename:d,async:d===e,ts:/\.[cm]?tsx?$/.test(d)},e,r,i,o);for(let e of p)for(let n of Ve(t,d,e))!a.has(n)&&G(n,r,i)&&(a.add(n),c.push(n))}return l}async function Ue(e,t){try{let{createPresetTransformDiskCache:n}=await import(`./presetTransformDiskCache-BNUNLsPo.js`);return n(e,import.meta.url,t)}catch{return}}function Z(e,t){if(!e||typeof e!=`object`)return;let n=z.get(e)??[];z.set(e,Array.from(new Set([...n,...t])))}function Q(e){return e&&typeof e==`object`?[...z.get(e)??[]]:[]}async function We(t,n,r){let i=U(t),a=e(i),s=Object.create(null),c=new Set([i]),l=new Map,u={packageRoot:W(i,l),fallbackRoot:o(i)},[{createJiti:d,transformer:f},p]=await Promise.all([we(),Ue(i,r)]),m=d(i,{fsCache:!1,interopDefault:!0,moduleCache:!1,tryNative:!1,transform:e=>{let{code:t}=ze(f,e,i,u,l,p);return{code:t}}}),h=()=>{let e=new Set;for(let t of Object.values(s))K(t,c,e,u,l);for(let t of c)K(a.cache[t],c,e,u,l)};try{let e=await He(i,m,f,u,l,c,p)??await b(i,`utf8`),{evaluation:t}=await je(u.packageRoot??u.fallbackRoot,()=>{for(let e of c)delete a.cache[e];return m.evalModule(e,{async:!0,cache:s,filename:i,forceTranspile:!0})}),r=await t,o=r?.__esModule?r.default:r;if(o==null)throw Error(`@preset "${n}" has no default export (expected a Preset or preset factory)`);let d=typeof o==`function`?await o():o;return h(),{preset:d,sources:Array.from(c)}}catch(e){h();let t=Ae(e);throw Z(e,t&&G(t,u,l)?[...c,t]:Array.from(c)),e}}async function Ge(e){let t=await ee(e),n=x(e);return n.searchParams.set(`version`,`${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`),(await import(n.href)).default}async function Ke(e,t){let n=[],r=new Set,i={protectedSlotsByDirectory:new Map};for(let a of e){let e;try{e=Oe(a,t);let o;if(H(a)){let t=await We(e,a,i);for(let e of t.sources)r.add(e);n.push(t.preset);continue}if(r.add(U(e)),o=await Ge(e),o==null)throw Error(`@preset "${a}" has no default export (expected a Preset or preset factory)`);n.push(typeof o==`function`?await o():o)}catch(t){throw Z(t,e!==void 0&&H(a)?[...r,U(e)]:r),t}}return{presets:n,sources:Array.from(r)}}async function qe(e,t){return(await Ke(e,t)).presets}async function Je(e,t,n){let r=e.filter(e=>!e.exclude).map(e=>e.glob);if(r.length===0)return{shortcuts:[],safelist:[],files:[]};let a=e.filter(e=>e.exclude).map(e=>e.glob),o=await v(r,{cwd:t,absolute:!0,ignore:a,expandDirectories:!1}),s=new Set(n),c=o.filter(e=>e.endsWith(`.css`)&&!s.has(e)).sort(),l=[],u=[];for(let e of c){let t;try{t=i(e,`utf8`)}catch(e){if(e.code===`ENOENT`)continue;throw e}if(!t.includes(`@shortcut`)&&!t.includes(`@safelist`))continue;let n=L(t);l.push(...n.shortcuts),u.push(...n.safelist)}return{shortcuts:l,safelist:u,files:c}}async function Ye(e,t,n){let r=ye(e,t,n),i=L(r.css),[a,o]=await Promise.all([i.presets.length?Ke(i.presets,t):{presets:[],sources:[]},Je(i.sources,t,r.files)]).catch(e=>{throw Z(e,r.files),e}),s=a.presets,c=await g({presets:s}).catch(e=>{throw Z(e,[...r.files,...o.files,...a.sources]),e}),l=S(c.theme),{theme:u,unknown:d,undeclared:f}=k(i.custom,l,c.theme),p=[...i.sources.filter(e=>!e.exclude).map(e=>e.glob),...i.sources.filter(e=>e.exclude).map(e=>`!${e.glob}`)],m=[...o.shortcuts,...i.shortcuts],v=Object.fromEntries(m.map(({name:e,expansion:t})=>[e,t])),y=[...new Set([...o.safelist,...i.safelist].flatMap(e=>_(h(e))))],b=[...new Set(i.custom.map(e=>e.theme).filter(e=>!!e))];return{config:{presets:s,theme:u,...i.sources.length?{content:{filesystem:p}}:{},...m.length?{shortcuts:v}:{},...y.length?{safelist:y}:{},...b.length?{autocomplete:{templates:[`theme-(${b.join(`|`)})`]}}:{}},unknown:d,undeclared:f,hasTeacss:r.files.length===0?i.hasTeacss:L(e).hasTeacss,sources:[...r.files,...o.files,...a.sources]}}const Xe=ne.join(` `);function $(e,t){switch(t){case`unknown-prefix`:return`@custom var "${e}" matches no theme namespace — not registered (emitted as a plain :root var).`;case`illegal-color-step`:return`@custom var "${e}" has an illegal color step — palette steps are ${Xe}.`;case`undeclared-theme-variable`:return`@custom theme var "${e}" overrides no declared base value — not registered. Declare it in the preset theme or a base @custom block first.`;case`invalid-theme-prelude`:return`@custom prelude "${e}" is not a theme declaration — use \`@custom theme <name> {}\` or \`@custom theme <name> dark {}\` with a kebab-case name (\`dark\`/\`light\` reserved). The block registers nothing.`}}function Ze(e,t,n){let r=C(t),i=[],a=P(e),o=n?[n,k(a.filter(e=>I(e.mode).kind===`base`).map(e=>({declarations:e.declarations})),t).theme]:void 0;for(let e of a){let t=I(e.mode);if(t.kind===`invalid`){i.push({property:e.mode,start:e.start,end:e.open,reason:`invalid-theme-prelude`,message:$(e.mode,`invalid-theme-prelude`)});continue}for(let n of e.declarations){let{property:e,start:a,end:s}=n,c=E(e.slice(2),r);if(!c.ok){i.push({property:e,start:a,end:s,reason:c.reason,message:$(e,c.reason)});continue}t.kind===`theme`&&o&&!O(c,o)&&i.push({property:e,start:a,end:s,reason:`undeclared-theme-variable`,message:$(e,`undeclared-theme-variable`)})}}return i}const Qe=Object.freeze([`package.json`,`index.css`,`src/index.css`]),[$e,...et]=Qe;function tt(e){let t=e instanceof Error?`${e.name}:${e.message}`:`${typeof e}:${String(e)}`,r=Array.from(new Set(Q(e))).sort().map(e=>{try{let t=n.statSync(e);return`${e}:${t.mtimeMs}:${t.ctimeMs}:${t.size}:${t.ino}`}catch(t){let n=t.code;return`${e}:${n===`ENOENT`?`missing`:`unreadable:${n??String(t)}`}`}});return JSON.stringify([t,r])}function nt(e,t){let n={...e};for(let e of Reflect.ownKeys(t)){if(!Object.getOwnPropertyDescriptor(t,e)?.enumerable)continue;let r=Reflect.get(t,e);r!==void 0&&Object.defineProperty(n,e,{value:r,configurable:!0,enumerable:!0,writable:!0})}return n}function rt(e){try{let t=n.readFileSync(e,`utf8`);return t.includes(`@teacss`)?N(t).some(e=>e.name===`teacss`&&e.prelude===``&&e.terminator!==`block`):!1}catch(e){if(e.code===`ENOENT`)return!1;throw e}}function it(e){try{let t=JSON.parse(n.readFileSync(l(e,$e),`utf8`))?.teacss?.entry;return typeof t==`string`?t:void 0}catch(e){if(e.code===`ENOENT`)return;throw e}}function at(e){let t=it(e);if(t){let r=d(e,t);if(n.existsSync(r)&&n.statSync(r).isFile())return r}for(let t of et){let r=l(e,t);if(n.existsSync(r)&&n.statSync(r).isFile()&&rt(r))return r}}async function ot(e=p.cwd(),t=e,r={}){if(typeof t!=`string`)return{config:nt(r,t),sources:[]};let i=d(e,t),a=n.existsSync(i)&&n.statSync(i).isFile()?i:at(i);if(!a)return{config:{...r},sources:[]};let s;try{s=await Ye(n.readFileSync(a,`utf8`),o(a),a)}catch(e){throw Z(e,[a]),e}let{config:c}=s,l=nt(r,c);return c.presets?.length||(r.presets?.length?l.presets=r.presets:m.warn(`[@teacss/config] "${a}" declares no @preset — no utilities will be generated. Add one, e.g. \`@preset "standard";\``)),{config:l,sources:Array.from(new Set([a,...s.sources]))}}function st(){let e=new Map,t=new Map,n=new Map,r=new Map,i=new WeakMap,a=new WeakMap,o=new WeakMap,s=new WeakMap,c=(e,n)=>e?t.get(e):n?a.get(n):void 0,l=(e,t)=>e?n.get(e):t?o.get(t):void 0,u=async(e,t)=>{for(;;){let n=c(e,t),r=l(e,t);if(!r)return;let i=await r;if(c(e,t)===n)return i}};return(c=p.cwd(),l=c,f={})=>{let h=typeof l==`string`?d(c,l):void 0,g=typeof l==`object`&&l?l:void 0,_=h?(t.get(h)??0)+1:g?(a.get(g)??0)+1:0;h?t.set(h,_):g&&a.set(g,_);let v=ot(c,l,f).then(n=>(h&&t.get(h)===_?(e.set(h,n),r.delete(h)):g&&a.get(g)===_&&(i.set(g,n),s.delete(g)),n),async n=>{let o=h?t.get(h)===_:!g||a.get(g)===_;if(!o){let e=await u(h,g);if(e)return e}let c=h?e.get(h):g?i.get(g):void 0;if(!c)throw n;if(o){let e=tt(n);e!==(h?r.get(h):g?s.get(g):void 0)&&(m.error(`[@teacss/config] Error resolving config from the CSS entry:`,n),h?r.set(h,e):g&&s.set(g,e));let t=Array.from(new Set([...c.sources,...Q(n)]));return t.length===c.sources.length?c:{...c,sources:t}}return c});return h?n.set(h,v):g&&o.set(g,v),v}}export{C as buildNamespaces,E as classifyCustomVar,st as createRecoveryConfigLoader,k as customToTheme,Ze as diagnoseCustom,Qe as entryDiscoveryFiles,at as findEntry,Q as getConfigSourcesFromError,O as hasBaseThemeValue,ce as hasTopLevelDirective,ot as loadConfig,I as parseCustomPrelude,L as parseEntry,Ye as resolveEntryConfig,qe as resolvePresets,S as scaleThemeKeys,P as scanCustomBlocks,se as scanQuotedDirectives,N as scanTopLevelAtRules};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{createRequire as e}from"node:module";import{accessSync as t,closeSync as n,constants as r,fstatSync as i,lstatSync as a,mkdirSync as o,openSync as s,readFileSync as c,renameSync as l,unlinkSync as u,writeFileSync as d}from"node:fs";import{dirname as f,join as p,resolve as m}from"node:path";import{Buffer as h}from"node:buffer";import{fileURLToPath as g}from"node:url";import{createHash as _}from"node:crypto";const v=`teacss-preset-transform-v3`,y=[`.cache`,`teacss`,`preset-transform`],b=524288,x=e(import.meta.url),S=new Map;function C(e){return _(`sha256`).update(e).digest(`hex`)}function w(e,t){e.update(c(t))}function T(){let e=process.versions.node.split(`.`)[0]??process.versions.node;return typeof Bun>`u`?`node:${e}`:`bun:${Bun.version}:node:${e}`}function E(e){let t=T(),n=`${e}\0${t}`;if(S.has(n))return S.get(n);let r;try{let n=g(e),i=g(import.meta.url),a=m(f(n),`../package.json`),o=JSON.parse(c(a,`utf8`)),s=x.resolve(`jiti/package.json`),l=f(s),u=JSON.parse(c(s,`utf8`));if(typeof o.version!=`string`||typeof u.version!=`string`)throw TypeError(`Invalid package version`);let d=_(`sha256`);d.update(`${v}\0@teacss/config:${o.version}\0`),w(d,n),i!==n&&w(d,i),d.update(`\0jiti:${u.version}\0`),w(d,p(l,`lib`,`jiti.mjs`)),w(d,p(l,`dist`,`jiti.cjs`)),d.update(`\0babel\0`),w(d,p(l,`dist`,`babel.cjs`)),d.update(`\0runtime:${t}`),r=d.digest(`hex`)}catch{r=void 0}if(S.size>=8){let e=S.keys().next().value;e!==void 0&&S.delete(e)}return S.set(n,r),r}function D(){return/^(?:0|false)$/i.test(process.env.TEACSS_PRESET_TRANSFORM_CACHE??``)}function O(e){if(process.platform===`win32`)return!0;let t=process.getuid?.();return(t===void 0||e.uid===t)&&!(e.mode&18)}function k(e){try{try{o(e,{mode:448})}catch(e){if(e.code!==`EEXIST`)return!1}let t=a(e);return t.isDirectory()&&O(t)}catch{return!1}}function A(e){let n=f(e);for(;;){let e=p(n,`node_modules`),i;try{i=a(e)}catch(e){if(e.code!==`ENOENT`)return}if(i!==void 0){if(!i.isDirectory()||!O(i))return;try{let n=e;for(let e of y)if(n=p(n,e),!k(n))return;return t(n,r.R_OK|r.W_OK),n}catch{return}}let o=f(n);if(o===n)return;n=o}}function j(e,t){return C(`${e}\0${t.filename}\0${t.mode}\0${C(t.source)}`)}function M(e,t){return(Number.parseInt(e.slice(0,2),16)%256+t*(Number.parseInt(e.slice(2,4),16)|1))%256}function N(e,t){return p(e,`${t.toString(16).padStart(2,`0`)}.json`)}function P(e,t,n,r){return JSON.stringify([e,t,n,r.dependencies,r.hasDynamicImport,r.hasNestedRequire,r.hasNonLiteralRequire,r.hasTopLevelAwait,r.hasTopLevelRequire])}function F(e){if(!e||typeof e!=`object`)return;let t=e;if(!Array.isArray(t.dependencies)||t.dependencies.length>4096)return;let n=0;for(let e of t.dependencies){if(typeof e!=`string`)return;let t=h.byteLength(e);if(t>16384||(n+=t,n>b))return}if(typeof t.hasDynamicImport==`boolean`&&typeof t.hasNestedRequire==`boolean`&&typeof t.hasNonLiteralRequire==`boolean`&&typeof t.hasTopLevelAwait==`boolean`&&typeof t.hasTopLevelRequire==`boolean`)return n}function I(e){return F(e)!==void 0}function L(e,t,o){let l=N(e,t);try{let e=a(l);if(!e.isFile()||!O(e))return{kind:`blocked`}}catch(e){return{kind:e.code===`ENOENT`?`empty`:`blocked`}}let u;try{u=s(l,r.O_RDONLY|(r.O_NOFOLLOW??0))}catch(e){return{kind:e.code===`ENOENT`?`empty`:`blocked`}}try{let e=i(u);if(!e.isFile()||!O(e))return{kind:`blocked`};if(e.size<=0||e.size>b)return{kind:`reusable`};let t;try{t=JSON.parse(c(u,`utf8`))}catch{return{kind:`reusable`}}if(!t||typeof t!=`object`)return{kind:`reusable`};let n=t;return n.schema!==v||n.fingerprint!==o||!/^[0-9a-f]{64}$/.test(n.fingerprint)||typeof n.key!=`string`||!/^[0-9a-f]{64}$/.test(n.key)?{kind:`reusable`}:{kind:`payload`,payload:n}}catch{return{kind:`blocked`}}finally{try{n(u)}catch{}}}function R(e,t,n,r){for(let i=0;i<256;i++){let a=M(n,i),o=L(e,a,t);if(o.kind===`empty`)return;if(o.kind!==`payload`||o.payload.key!==n)continue;let s=o.payload;if(typeof s.code==`string`&&I(s.facts)&&s.checksum===C(P(t,n,s.code,s.facts)))return r.add(a),{code:s.code,facts:s.facts}}}function z(e,t,n,r){let i=Array(256),a;for(let r=0;r<256;r++){let o=M(n,r),s=L(e,o,t);if(i[o]=s,s.kind===`payload`&&s.payload.key===n)return o;if(s.kind===`reusable`&&a===void 0&&(a=o),s.kind===`empty`)return a??o}if(a!==void 0)return a;let o=Number.parseInt(n.slice(4,6),16)%256;for(let e=0;e<256;e++){let t=M(n,(o+e)%256);if(i[t]?.kind===`payload`&&!r.has(t))return t}}function B(e,t,n,r,i){if(typeof r.code!=`string`)return;let o=F(r.facts);if(o===void 0||h.byteLength(r.code)+o>b)return;let s={checksum:C(P(t,n,r.code,r.facts)),code:r.code,facts:r.facts,fingerprint:t,key:n,schema:v},c=JSON.stringify(s);if(h.byteLength(c)>b)return;let f=z(e,t,n,i);if(f===void 0)return;let m=N(e,f),g=p(e,`.${f.toString(16).padStart(2,`0`)}.tmp`),_=!1,y=!1;try{try{d(g,c,{encoding:`utf8`,flag:`wx`,mode:384}),_=!0}catch(e){if(e.code!==`EEXIST`)throw e;let t=!1;try{let e=a(g);e.isFile()&&O(e)&&Date.now()-e.mtimeMs>6e4&&(u(g),t=!0)}catch{}if(!t)return;d(g,c,{encoding:`utf8`,flag:`wx`,mode:384}),_=!0}try{l(g,m),_=!1,y=!0}catch(e){let t=e.code;if(t!==`EEXIST`&&t!==`EPERM`)throw e;u(m),l(g,m),_=!1,y=!0}}catch{}finally{if(_)try{u(g)}catch{}}return y?f:void 0}function V(e,t,n){if(D())return;let r=A(e);if(!r)return;let i=E(t);if(!i)return;let a=n?.protectedSlotsByDirectory.get(r);return a||(a=new Set,n?.protectedSlotsByDirectory.set(r,a)),{read(e){return R(r,i,j(i,e),a)},write(e,t){let n=B(r,i,j(i,e),t,a);n!==void 0&&a.add(n)}}}export{V as createPresetTransformDiskCache};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teacss/config",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.5.0",
|
|
4
4
|
"description": "TeaCSS config loader — discovers the CSS entry and resolves its directives into a config (no teacss.config file).",
|
|
5
5
|
"homepage": "https://css.teasim.com",
|
|
6
6
|
"funding": "https://github.com/sponsors/billgo",
|
|
@@ -22,7 +22,7 @@
|
|
|
22
22
|
"dev": "tsdown --watch"
|
|
23
23
|
},
|
|
24
24
|
"dependencies": {
|
|
25
|
-
"@teacss/core": "0.
|
|
25
|
+
"@teacss/core": "0.5.0",
|
|
26
26
|
"consola": "^3.4.2",
|
|
27
27
|
"jiti": "^2.7.0",
|
|
28
28
|
"tinyglobby": "^0.2.17"
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
import{createRequire as e}from"node:module";import{accessSync as t,closeSync as n,constants as r,fstatSync as i,lstatSync as a,mkdirSync as o,openSync as s,readFileSync as c,renameSync as l,unlinkSync as u,writeFileSync as d}from"node:fs";import{dirname as f,join as p,resolve as m}from"node:path";import{Buffer as h}from"node:buffer";import{fileURLToPath as g}from"node:url";import{createHash as _}from"node:crypto";const v=`teacss-preset-transform-v3`,y=[`.cache`,`teacss`,`preset-transform`],b=512*1024,x=e(import.meta.url),S=new Map;function C(e){return _(`sha256`).update(e).digest(`hex`)}function w(e,t){e.update(c(t))}function T(){let e=process.versions.node.split(`.`)[0]??process.versions.node;return typeof Bun>`u`?`node:${e}`:`bun:${Bun.version}:node:${e}`}function E(e){let t=T(),n=`${e}\0${t}`;if(S.has(n))return S.get(n);let r;try{let n=g(e),i=g(import.meta.url),a=m(f(n),`../package.json`),o=JSON.parse(c(a,`utf8`)),s=x.resolve(`jiti/package.json`),l=f(s),u=JSON.parse(c(s,`utf8`));if(typeof o.version!=`string`||typeof u.version!=`string`)throw TypeError(`Invalid package version`);let d=_(`sha256`);d.update(`${v}\0@teacss/config:${o.version}\0`),w(d,n),i!==n&&w(d,i),d.update(`\0jiti:${u.version}\0`),w(d,p(l,`lib`,`jiti.mjs`)),w(d,p(l,`dist`,`jiti.cjs`)),d.update(`\0babel\0`),w(d,p(l,`dist`,`babel.cjs`)),d.update(`\0runtime:${t}`),r=d.digest(`hex`)}catch{r=void 0}if(S.size>=8){let e=S.keys().next().value;e!==void 0&&S.delete(e)}return S.set(n,r),r}function D(){return/^(?:0|false)$/i.test(process.env.TEACSS_PRESET_TRANSFORM_CACHE??``)}function O(e){if(process.platform===`win32`)return!0;let t=process.getuid?.();return(t===void 0||e.uid===t)&&(e.mode&18)==0}function k(e){try{try{o(e,{mode:448})}catch(e){if(e.code!==`EEXIST`)return!1}let t=a(e);return t.isDirectory()&&O(t)}catch{return!1}}function A(e){let n=f(e);for(;;){let e=p(n,`node_modules`),i;try{i=a(e)}catch(e){if(e.code!==`ENOENT`)return}if(i!==void 0){if(!i.isDirectory()||!O(i))return;try{let n=e;for(let e of y)if(n=p(n,e),!k(n))return;return t(n,r.R_OK|r.W_OK),n}catch{return}}let o=f(n);if(o===n)return;n=o}}function j(e,t){return C(`${e}\0${t.filename}\0${t.mode}\0${C(t.source)}`)}function M(e,t){return(Number.parseInt(e.slice(0,2),16)%256+t*(Number.parseInt(e.slice(2,4),16)|1))%256}function N(e,t){return p(e,`${t.toString(16).padStart(2,`0`)}.json`)}function P(e,t,n,r){return JSON.stringify([e,t,n,r.dependencies,r.hasDynamicImport,r.hasNestedRequire,r.hasNonLiteralRequire,r.hasTopLevelAwait,r.hasTopLevelRequire])}function F(e){if(!e||typeof e!=`object`)return;let t=e;if(!Array.isArray(t.dependencies)||t.dependencies.length>4096)return;let n=0;for(let e of t.dependencies){if(typeof e!=`string`)return;let t=h.byteLength(e);if(t>16384||(n+=t,n>b))return}if(typeof t.hasDynamicImport==`boolean`&&typeof t.hasNestedRequire==`boolean`&&typeof t.hasNonLiteralRequire==`boolean`&&typeof t.hasTopLevelAwait==`boolean`&&typeof t.hasTopLevelRequire==`boolean`)return n}function I(e){return F(e)!==void 0}function L(e,t,o){let l=N(e,t);try{let e=a(l);if(!e.isFile()||!O(e))return{kind:`blocked`}}catch(e){return{kind:e.code===`ENOENT`?`empty`:`blocked`}}let u;try{u=s(l,r.O_RDONLY|(r.O_NOFOLLOW??0))}catch(e){return{kind:e.code===`ENOENT`?`empty`:`blocked`}}try{let e=i(u);if(!e.isFile()||!O(e))return{kind:`blocked`};if(e.size<=0||e.size>b)return{kind:`reusable`};let t;try{t=JSON.parse(c(u,`utf8`))}catch{return{kind:`reusable`}}if(!t||typeof t!=`object`)return{kind:`reusable`};let n=t;return n.schema!==v||n.fingerprint!==o||!/^[0-9a-f]{64}$/.test(n.fingerprint)||typeof n.key!=`string`||!/^[0-9a-f]{64}$/.test(n.key)?{kind:`reusable`}:{kind:`payload`,payload:n}}catch{return{kind:`blocked`}}finally{try{n(u)}catch{}}}function R(e,t,n,r){for(let i=0;i<256;i++){let a=M(n,i),o=L(e,a,t);if(o.kind===`empty`)return;if(o.kind!==`payload`||o.payload.key!==n)continue;let s=o.payload;if(!(typeof s.code!=`string`||!I(s.facts))&&s.checksum===C(P(t,n,s.code,s.facts)))return r.add(a),{code:s.code,facts:s.facts}}}function z(e,t,n,r){let i=Array(256),a;for(let r=0;r<256;r++){let o=M(n,r),s=L(e,o,t);if(i[o]=s,s.kind===`payload`&&s.payload.key===n)return o;if(s.kind===`reusable`&&a===void 0&&(a=o),s.kind===`empty`)return a??o}if(a!==void 0)return a;let o=Number.parseInt(n.slice(4,6),16)%256;for(let e=0;e<256;e++){let t=M(n,(o+e)%256);if(i[t]?.kind===`payload`&&!r.has(t))return t}}function B(e,t,n,r,i){if(typeof r.code!=`string`)return;let o=F(r.facts);if(o===void 0||h.byteLength(r.code)+o>b)return;let s={checksum:C(P(t,n,r.code,r.facts)),code:r.code,facts:r.facts,fingerprint:t,key:n,schema:v},c=JSON.stringify(s);if(h.byteLength(c)>b)return;let f=z(e,t,n,i);if(f===void 0)return;let m=N(e,f),g=p(e,`.${f.toString(16).padStart(2,`0`)}.tmp`),_=!1,y=!1;try{try{d(g,c,{encoding:`utf8`,flag:`wx`,mode:384}),_=!0}catch(e){if(e.code!==`EEXIST`)throw e;let t=!1;try{let e=a(g);e.isFile()&&O(e)&&Date.now()-e.mtimeMs>6e4&&(u(g),t=!0)}catch{}if(!t)return;d(g,c,{encoding:`utf8`,flag:`wx`,mode:384}),_=!0}try{l(g,m),_=!1,y=!0}catch(e){let t=e.code;if(t!==`EEXIST`&&t!==`EPERM`)throw e;u(m),l(g,m),_=!1,y=!0}}catch{}finally{if(_)try{u(g)}catch{}}return y?f:void 0}function V(e,t,n){if(D())return;let r=A(e);if(!r)return;let i=E(t);if(!i)return;let a=n?.protectedSlotsByDirectory.get(r);return a||(a=new Set,n?.protectedSlotsByDirectory.set(r,a)),{read(e){return R(r,i,j(i,e),a)},write(e,t){let n=B(r,i,j(i,e),t,a);n!==void 0&&a.add(n)}}}export{V as createPresetTransformDiskCache};
|