@teacss/engine 0.8.5-alpha.4 → 0.9.0-alpha.3

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,44 @@
1
+ import type { HighlightAnnotation, TransformResult } from "../../contract.js";
2
+ import { ENGINE_INSTANCE } from "./constants.js";
3
+ interface EditTarget {
4
+ update(start: number, end: number, text: string): unknown;
5
+ appendLeft(index: number, text: string): unknown;
6
+ }
7
+ /** The part of the native `Engine` the transformer calls. */
8
+ interface TransformEngine {
9
+ transformSource(id: string, code: string): TransformResult | null;
10
+ clearModuleDefinitions(id: string): boolean;
11
+ }
12
+ /** The runtime's transformer context; only the fields the transformer reads. */
13
+ interface TransformContext {
14
+ generator?: {
15
+ [ENGINE_INSTANCE]?: TransformEngine;
16
+ };
17
+ tokens?: Set<string>;
18
+ invalidate?: () => void;
19
+ }
20
+ /**
21
+ * Replays v02.2 `TransformResult.edits` on the host MagicString. A zero-length range is an insert:
22
+ * magic-string throws on a zero-length `update`.
23
+ */
24
+ export declare function replayEdits(s: EditTarget, edits: ReadonlyArray<{
25
+ start: number;
26
+ end: number;
27
+ text: string;
28
+ }>): void;
29
+ /**
30
+ * The object shape of preset-standard/transformers/compile-class.ts:178-274, backed by Rust
31
+ * `transformSource`. It has no `idFilter`: the runtime's pipeline filter picks the modules.
32
+ */
33
+ export declare function createCompileClassTransformer(): {
34
+ name: "@teacss/transformer-compile-class";
35
+ enforce: "pre";
36
+ transform(s: EditTarget & {
37
+ original: string;
38
+ }, id: string, ctx: TransformContext): Promise<{
39
+ highlightAnnotations: HighlightAnnotation[];
40
+ } | undefined>;
41
+ onModuleRemoved(id: string, ctx: TransformContext): void;
42
+ };
43
+ export {};
44
+ //# sourceMappingURL=transformer.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { ENGINE_INSTANCE } from "./constants.js";
2
+ /**
3
+ * Replays v02.2 `TransformResult.edits` on the host MagicString. A zero-length range is an insert:
4
+ * magic-string throws on a zero-length `update`.
5
+ */
6
+ export function replayEdits(s, edits) {
7
+ for (const { start, end, text } of edits) {
8
+ if (start === end)
9
+ s.appendLeft(start, text);
10
+ else
11
+ s.update(start, end, text);
12
+ }
13
+ }
14
+ const engineOf = (ctx) => ctx?.generator?.[ENGINE_INSTANCE] ?? null;
15
+ /**
16
+ * The object shape of preset-standard/transformers/compile-class.ts:178-274, backed by Rust
17
+ * `transformSource`. It has no `idFilter`: the runtime's pipeline filter picks the modules.
18
+ */
19
+ export function createCompileClassTransformer() {
20
+ return {
21
+ name: "@teacss/transformer-compile-class",
22
+ enforce: "pre",
23
+ async transform(s, id, ctx) {
24
+ const engine = engineOf(ctx);
25
+ if (!engine)
26
+ return;
27
+ const result = engine.transformSource(id, s.original);
28
+ if (!result)
29
+ return;
30
+ replayEdits(s, result.edits);
31
+ if (ctx.tokens)
32
+ for (const name of result.compiledClasses)
33
+ ctx.tokens.add(name);
34
+ if (result.definitionsChanged)
35
+ ctx.invalidate?.();
36
+ return { highlightAnnotations: result.highlightAnnotations };
37
+ },
38
+ /**
39
+ * Releases the module's definitions only: the runtime also calls this when a module stays
40
+ * (context switches, failed transforms), so its tokens are kept (v02.9 §6.1 step 8).
41
+ */
42
+ onModuleRemoved(id, ctx) {
43
+ const engine = engineOf(ctx);
44
+ if (!engine)
45
+ return;
46
+ let changed = false;
47
+ try {
48
+ changed = engine.clearModuleDefinitions(id);
49
+ }
50
+ catch (error) {
51
+ if (error?.code !== "E_DISPOSED")
52
+ throw error;
53
+ }
54
+ if (changed)
55
+ ctx.invalidate?.();
56
+ },
57
+ };
58
+ }
59
+ //# sourceMappingURL=transformer.js.map
@@ -0,0 +1,32 @@
1
+ /** A TypeScript generator from `@teacss/core`; the facade only forwards to it. */
2
+ export type TsGenerator = any;
3
+ export interface CoreBinding {
4
+ version: string;
5
+ createGenerator: (config?: object, defaults?: object) => Promise<TsGenerator>;
6
+ createTsGenerator?: (config?: object, defaults?: object) => Promise<TsGenerator>;
7
+ extractorSplit: object;
8
+ }
9
+ /** Test seam that replaces the dynamic import of `@teacss/core`. */
10
+ export declare const coreLoader: {
11
+ load: (() => Promise<CoreBinding>) | null;
12
+ };
13
+ /** Rejects with `E_TS_REQUIRED` when the peer is missing. */
14
+ export declare function importCore(member: string): Promise<CoreBinding>;
15
+ export interface TsFallback {
16
+ invalidate(userConfig: object, defaults: object): void;
17
+ generator(member?: string): Promise<TsGenerator>;
18
+ peek(): TsGenerator | null;
19
+ create(userConfig: object, defaults: object): Promise<TsGenerator>;
20
+ }
21
+ /**
22
+ * `engine: "ts"` goes into the defaults, which take precedence over `config.engine`, so the TS
23
+ * generator does not enter the hook again. `committed` is the configuration committed at
24
+ * construction.
25
+ */
26
+ export declare function createTsFallback(host: {
27
+ core?: CoreBinding | undefined;
28
+ }, committed: {
29
+ userConfig: object;
30
+ defaults: object;
31
+ }): TsFallback;
32
+ //# sourceMappingURL=ts-fallback.d.ts.map
@@ -0,0 +1,78 @@
1
+ // The lazily created TypeScript generator behind the facade (v02.9 §3.3).
2
+ import { ENGINE_INSTANCE } from "./constants.js";
3
+ import { tsRequiredError } from "./errors.js";
4
+ /** Test seam that replaces the dynamic import of `@teacss/core`. */
5
+ export const coreLoader = {
6
+ load: null,
7
+ };
8
+ /** Rejects with `E_TS_REQUIRED` when the peer is missing. */
9
+ export async function importCore(member) {
10
+ try {
11
+ // biome-ignore lint/suspicious/noTsIgnore: the optional peer may or may not be installed
12
+ // @ts-ignore optional peer: @teacss/core may be absent at compile time
13
+ return await (coreLoader.load ? coreLoader.load() : import("@teacss/core"));
14
+ }
15
+ catch {
16
+ throw tsRequiredError(member);
17
+ }
18
+ }
19
+ /**
20
+ * `engine: "ts"` goes into the defaults, which take precedence over `config.engine`, so the TS
21
+ * generator does not enter the hook again. `committed` is the configuration committed at
22
+ * construction.
23
+ */
24
+ export function createTsFallback(host, committed) {
25
+ let generatorPromise = null;
26
+ let resolved = null;
27
+ const core = (member) => (host.core ? Promise.resolve(host.core) : importCore(member));
28
+ /**
29
+ * A TypeScript generator. The hook's `createTsGenerator` bypasses it; `createGenerator` (an older
30
+ * core, or `@teacss/core` imported without a hook) re-enters it when TEACSS_ENGINE overrides
31
+ * `engine: "ts"`, and returns a facade for a configuration Rust can serve.
32
+ */
33
+ const createTs = (binding, userConfig, defaults) => {
34
+ const tsDefaults = { ...defaults, engine: "ts" };
35
+ return typeof binding.createTsGenerator === "function" ? binding.createTsGenerator(userConfig, tsDefaults) : binding.createGenerator(userConfig, tsDefaults);
36
+ };
37
+ return {
38
+ /** Called after a successful `commitConfig`; drops the lazy instance. */
39
+ invalidate(userConfig, defaults) {
40
+ committed = { userConfig, defaults };
41
+ generatorPromise = null;
42
+ resolved = null;
43
+ },
44
+ /** The lazy TS generator; a rejection is not cached. */
45
+ generator(member = "materialize") {
46
+ generatorPromise ??= (async () => {
47
+ const binding = await core(member);
48
+ const generator = await createTs(binding, committed.userConfig, committed.defaults);
49
+ resolved = generator;
50
+ return generator;
51
+ })().catch((error) => {
52
+ generatorPromise = null;
53
+ throw error;
54
+ });
55
+ return generatorPromise;
56
+ },
57
+ /** The ready instance, or `null` before `generator()` resolves. */
58
+ peek() {
59
+ return resolved;
60
+ },
61
+ /**
62
+ * A TS candidate for a configuration (v02.9 §5.2), made by the TS generator's own
63
+ * `prepareConfig` so it tracks in-place edits of its config as an oracle candidate does
64
+ * (generator.ts:1986-2011). The lazy instance is untouched.
65
+ */
66
+ async create(userConfig, defaults) {
67
+ const binding = await core("prepareConfig");
68
+ const tsDefaults = { ...defaults, engine: "ts" };
69
+ // Without `createTsGenerator` the base is built from the configuration itself: Rust cannot
70
+ // translate it, so `createGenerator` resolves to TS and creates no Engine.
71
+ const base = await createTs(binding, typeof binding.createTsGenerator === "function" ? {} : userConfig, defaults);
72
+ if (ENGINE_INSTANCE in Object(base) || typeof base?.prepareConfig !== "function")
73
+ return base;
74
+ return (await base.prepareConfig(userConfig, tsDefaults)).generator;
75
+ },
76
+ };
77
+ }
78
+ //# sourceMappingURL=ts-fallback.js.map
@@ -0,0 +1,4 @@
1
+ export * from "../binding.js";
2
+ export type * from "../contract.js";
3
+ export * from "./facade/index.js";
4
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,3 @@
1
+ export * from "../binding.js";
2
+ export * from "./facade/index.js";
3
+ //# sourceMappingURL=index.js.map
package/index.d.ts CHANGED
@@ -1,387 +1 @@
1
- // Mirror of docs/specs/v02.2-engine-contract.md §3 (spec-revision 2). Do not edit without bumping the spec revision.
2
- /** 原生绑定的 crate 版本(Cargo.toml 的 version)。 */
3
- export declare function version(): string;
4
-
5
- export declare class Engine {
6
- constructor();
7
-
8
- /** 读入口 CSS 与本地 @import 图,返回 JS 完成预设与 @source 枚举所需的信息。不改变实例状态。 */
9
- inspectEntry(request: InspectEntryRequest): InspectEntryResult;
10
-
11
- /** 解析配置、构建 program。可重复调用以重载;返回 programKey 是否变化。 */
12
- loadProject(request: LoadProjectRequest): LoadProjectResult;
13
-
14
- /** 当前 program key;未 loadProject 时抛 E_PROJECT_NOT_LOADED。 */
15
- programKey(): string;
16
-
17
- /** 0.8.2 `ResolvedConfig` 的只读视图(§5)。 */
18
- configView(): ResolvedConfigView;
19
-
20
- /** 入口、本地 @import、declaration CSS 的绝对路径,供宿主 watch。顺序:入口、import(深度优先)、declarationFiles(v02.5 §6 归一化后的顺序)。 */
21
- configFiles(): string[];
22
-
23
- /** 当前 program 允许的 @custom 命名空间键(oracle `scaleThemeKeys` 的结果),供 facade 的 `diagnoseCustom` 调用。 */
24
- customThemeKeys(): string[];
25
-
26
- /** 对宿主模块抽取 token 并记录所有权。code 为宿主交付的(已转换的)代码。 */
27
- updateModule(id: string, code: string): ModuleUpdateResult;
28
-
29
- /** 删除模块及其 token、compile-class 定义。返回是否存在。 */
30
- removeModule(id: string): boolean;
31
-
32
- /** 只清除该模块登记的 compile-class 定义,保留 token(facade 的 `onModuleRemoved` 使用,v02.9 §6)。返回是否有定义被清除。 */
33
- clearModuleDefinitions(id: string): boolean;
34
- /** 转换器登记的 compile-class shortcut,按登记顺序;即 oracle 追加到 `config.shortcuts` 的条目,转换器设了 `layer` 时带 `{ layer }`。 */
35
- compileClassShortcuts(): Array<[string, string] | [string, string, { layer: string }]>;
36
-
37
- /** 模块当前 token(去重,首次出现顺序);不存在返回 null。 */
38
- moduleTokens(id: string): string[] | null;
39
-
40
- /** 所有模块 token 的并集,顺序为模块 id 的字典序,再模块内顺序。 */
41
- allTokens(): string[];
42
-
43
- /** 无状态抽取,等价 oracle `generator.applyExtractors(code, id, new Set())`。 */
44
- extract(code: string, id?: string | undefined | null): string[];
45
-
46
- /** 无状态抽取并计数,等价 oracle 以 `CountableSet` 调用 `applyExtractors`;顺序同 extract。 */
47
- extractCounted(code: string, id?: string | undefined | null): Array<{ token: string; count: number }>;
48
-
49
- /** 读取并抽取磁盘文件;允许并行读取,结果按输入顺序。读失败的文件给出 error 字段。 */
50
- extractFiles(paths: string[]): ExtractFileResult[];
51
-
52
- /** JS/TS/JSX/TSX 源码的 compileClass 转换。无改动返回 null。有状态:登记该模块的 compile-class 定义。 */
53
- transformSource(id: string, code: string): TransformResult | null;
54
-
55
- /** CSS 的 @apply / --at-apply / @screen / theme() / icon() 转换。无改动返回 null。 */
56
- transformStylesheet(id: string, code: string): TransformResult | null;
57
-
58
- /** 生成 CSS。 */
59
- generate(input: GenerateInput, options?: GenerateOptions | undefined | null): GenerateResult;
60
-
61
- /** 等价 oracle `generator.parseToken(raw, alias)`:null = 未匹配或被 blocklist 拦截(见 §6.6)。 */
62
- parseToken(raw: string, alias?: string | undefined | null): StringifiedUtil[] | null;
63
-
64
- /** 等价 oracle `generator.isBlocked(raw)`。 */
65
- isBlocked(raw: string): boolean;
66
-
67
- /** 对未匹配 token 计算近似建议,等价 oracle `diagnoseUnmatchedToken`。 */
68
- diagnoseUnmatched(tokens: string[]): UnmatchedDiagnostic[];
69
-
70
- /** theme("a.b.c") 的取值;不存在返回 null。 */
71
- themeValue(path: string): string | null;
72
-
73
- /** 释放状态;之后任何方法抛 E_DISPOSED。 */
74
- dispose(): void;
75
- }
76
-
77
- /** 等价 config `parseEntry(css, file)`。 */
78
- export declare function parseEntry(css: string, file?: string | undefined | null): EntryConfig;
79
- /** 等价 config `diagnoseEntry(css)`。 */
80
- export declare function diagnoseEntry(css: string): EntryDiagnostic[];
81
- /** 等价 config `diagnoseCustom(css, themeKeys)`。 */
82
- export declare function diagnoseCustom(css: string, themeKeys: string[]): CustomDiagnostic[];
83
- /** 等价 core `expandClassGroups(code)`。 */
84
- export declare function expandClassGroups(code: string): string;
85
- /** 等价 core `splitClassTokens(body)`。 */
86
- export declare function splitClassTokens(body: string): string[];
87
- /** 等价 core `hash(str)`(compileClass 类名哈希)。 */
88
- export declare function hash(input: string): string;
89
-
90
- export interface InspectEntryRequest {
91
- /** 项目根(绝对路径)。相对 @source 以声明它的文件所在目录为基准。 */
92
- root: string;
93
- /** 入口 CSS 绝对路径。 */
94
- entryPath: string;
95
- /** 若宿主已持有入口内容(未保存的编辑器缓冲等),传入以替代磁盘读取。 */
96
- entryCss?: string | undefined | null;
97
- }
98
-
99
- export interface InspectEntryResult {
100
- /** @presets 列表,按声明顺序、去重(oracle resolvePresetGraph 的输入)。 */
101
- presets: string[];
102
- /** @source 声明;glob 已按声明文件目录解析为相对 root 的形式,exclude 以 `!` 前缀表示。 */
103
- sources: string[];
104
- /** 入口与本地 @import 图中读取过的文件(绝对路径,深度优先)。 */
105
- configFiles: string[];
106
- hasTeacss: boolean;
107
- /** 入口语法诊断;非空时 loadProject 会以 E_ENTRY_INVALID 失败。 */
108
- diagnostics: EntryDiagnostic[];
109
- }
110
-
111
- export interface LoadProjectRequest {
112
- root: string;
113
- /** null 表示没有入口文件(oracle loadConfig 找不到 entry 的情形)。 */
114
- entry: { path: string; css?: string | undefined | null } | null;
115
- /** 已解析顺序的预设(oracle 排序规则:pre、normal、post,见 core/config.ts:209)。 */
116
- presets: PresetSpec[];
117
- /** @source 匹配到的 .css 文件(绝对路径),只贡献 @shortcut/@safelist。由 JS 枚举。 */
118
- declarationFiles: string[];
119
- /** 内联 UserConfig / defaults 中可静态表示的部分。 */
120
- inline?: StaticConfig | undefined | null;
121
- envMode: "dev" | "build";
122
- unmatched: "warn" | "error" | "off";
123
- /** 对应 UserConfig.outputToCssLayers;函数形式由 facade 判定回退。 */
124
- outputToCssLayers?: boolean | { allLayers?: boolean } | undefined | null;
125
- shortcutsLayer?: string | undefined | null;
126
- virtualModulePrefix?: string | undefined | null;
127
- }
128
-
129
- export interface LoadProjectResult {
130
- programKey: string;
131
- /** 与上一次 loadProject 相比 programKey 是否变化;首次为 true。 */
132
- changed: boolean;
133
- /** 声明文件中解析失败的位置(不阻止加载,oracle 行为相同)。 */
134
- warnings: EntryDiagnostic[];
135
- /** @custom 中不属于任何命名空间的属性名(oracle `ResolveEntryResult.unknown`),facade 的 `resolveEntryConfig` 透传。 */
136
- unknownCustom: string[];
137
- }
138
-
139
- export type PresetSpec =
140
- | { kind: "standard"; options?: PresetStandardOptions | undefined | null }
141
- | { kind: "official" }
142
- | { kind: "icons"; options?: PresetIconsOptions | undefined | null }
143
- | { kind: "static"; preset: StaticPreset };
144
-
145
- export interface PresetStandardOptions {
146
- modeSelectors?: { dark?: string; light?: string } | undefined | null;
147
- containers?: Record<string, string> | undefined | null;
148
- preflight?: boolean | "on-demand" | undefined | null;
149
- variablePrefix?: string | undefined | null;
150
- compileClass?: boolean | CompileClassOptions | undefined | null;
151
- }
152
-
153
- export interface CompileClassOptions {
154
- classPrefix?: string | undefined | null;
155
- alwaysHash?: boolean | undefined | null;
156
- keepUnknown?: boolean | undefined | null;
157
- layer?: string | undefined | null;
158
- }
159
-
160
- export interface PresetIconsOptions {
161
- scale?: number | undefined | null;
162
- mode?: "mask" | "bg" | "auto" | undefined | null;
163
- extraProperties?: Record<string, string> | undefined | null;
164
- warn?: boolean | undefined | null;
165
- layer?: string | undefined | null;
166
- unit?: string | undefined | null;
167
- /** 只允许内置集合名;其他集合由 facade 判定回退。 */
168
- collections?: string[] | undefined | null;
169
- }
170
-
171
- /** 本地/第三方 preset 的可静态表示部分。任何不能表示的字段都由 facade 判定回退,不进入这里。 */
172
- export interface StaticPreset {
173
- name: string;
174
- enforce?: "pre" | "post" | undefined | null;
175
- layer?: string | undefined | null;
176
- layers?: Record<string, number> | undefined | null;
177
- shortcuts?: Array<[string, string]> | undefined | null;
178
- safelist?: string[] | undefined | null;
179
- blocklist?: string[] | undefined | null;
180
- /** 只接受 oracle `Theme` 中的标量叶子;对象按点路径展平后传入。 */
181
- theme?: Record<string, string> | undefined | null;
182
- }
183
-
184
- export interface StaticConfig {
185
- shortcuts?: Array<[string, string]> | undefined | null;
186
- safelist?: string[] | undefined | null;
187
- blocklist?: string[] | undefined | null;
188
- layers?: Record<string, number> | undefined | null;
189
- theme?: Record<string, string> | undefined | null;
190
- content?: { filesystem?: string[] | undefined | null } | undefined | null;
191
- }
192
-
193
- export interface ModuleUpdateResult {
194
- tokens: string[];
195
- /** 该模块 token 集或 compile-class 定义相对上一次是否变化。 */
196
- changed: boolean;
197
- }
198
-
199
- export interface ExtractFileResult {
200
- path: string;
201
- tokens: string[];
202
- /** 读取失败时的错误码(E_IO);成功为 null。 */
203
- error: string | null;
204
- }
205
-
206
- export interface TransformResult {
207
- code: string;
208
- /** 从原文到 code 的替换序列,UTF-16 code unit 偏移,按 (start, end) 升序且互不重叠。facade 在宿主的 MagicString 上按顺序回放:`start === end ? s.appendLeft(start, text) : s.update(start, end, text)`(magic-string 1.x 的 `update` 与 `overwrite` 除 `storeName` 默认值外相同),使 runtime 生成的 source map 与 0.8.2 完全一致(v02.8 §7)。 */
209
- edits: Array<{ start: number; end: number; text: string }>;
210
- /** 独立使用者(无 MagicString)用的 Source Map v3:sources = [id],sourcesContent = [原文]。 */
211
- map: SourceMap;
212
- /** oracle SourceCodeTransformer 返回的高亮区间(compileClass 提供)。 */
213
- highlightAnnotations: HighlightAnnotation[];
214
- /** transformSource:本次登记的 compile-class 类名(facade 并入 `ctx.tokens`,v02.9 §6);transformStylesheet 为空数组。 */
215
- compiledClasses: string[];
216
- /** transformSource:该模块的定义集相对上一次是否变化(facade 据此调用 `ctx.invalidate()`);transformStylesheet 为 false。 */
217
- definitionsChanged: boolean;
218
- }
219
-
220
- export interface SourceMap {
221
- version: 3;
222
- file: string | null;
223
- sources: string[];
224
- sourcesContent: string[];
225
- names: string[];
226
- mappings: string;
227
- }
228
-
229
- export interface HighlightAnnotation { offset: number; length: number; className: string }
230
-
231
- export type GenerateInput =
232
- | { kind: "tokens"; tokens: string[] }
233
- | { kind: "code"; code: string; id?: string | undefined | null }
234
- | { kind: "all" };
235
-
236
- export interface GenerateOptions {
237
- id?: string | undefined | null;
238
- /** 默认 true */
239
- preflights?: boolean | undefined | null;
240
- /** 默认 true */
241
- safelist?: boolean | undefined | null;
242
- /** 默认 false */
243
- minify?: boolean | undefined | null;
244
- /** 默认 false;为 true 时填充 matchedInfo */
245
- extendedInfo?: boolean | undefined | null;
246
- scope?: string | undefined | null;
247
- }
248
-
249
- export interface GenerateResult {
250
- /** 与 oracle `result.css` 逐字节相同。 */
251
- css: string;
252
- /** 有序层;oracle `result.layers` 与 `getLayer(name)` 的来源。 */
253
- layers: Array<{ name: string; css: string }>;
254
- /** oracle `result.matched`(Set)按首次出现顺序。 */
255
- matched: string[];
256
- /** extendedInfo 时填充。input 为 {kind:"code"} 时 count 是该 token 在抽取结果中的出现次数(oracle CountableSet 语义);tokens/all 输入时为 -1(oracle 对不可计数输入的语义)。 */
257
- matchedInfo: Array<{ token: string; data: StringifiedUtil[]; count: number }> | null;
258
- programKey: string;
259
- }
260
-
261
- /** oracle `StringifiedUtil` 元组的对象形式;`context` 字段不跨边界,facade 以 undefined 填充。 */
262
- export interface StringifiedUtil {
263
- index: number;
264
- selector: string | null;
265
- body: string;
266
- parent: string | null;
267
- meta: RuleMeta | null;
268
- noMerge: boolean | null;
269
- }
270
-
271
- export interface RuleMeta {
272
- layer?: string | undefined | null;
273
- noMerge?: boolean | undefined | null;
274
- noScope?: boolean | undefined | null;
275
- sort?: number | undefined | null;
276
- prefix?: string | string[] | undefined | null;
277
- internal?: boolean | undefined | null;
278
- }
279
-
280
- export interface UnmatchedDiagnostic { token: string; suggestions: string[] }
281
-
282
- export interface EntryConfig {
283
- presets: string[];
284
- rolePalettes: Partial<Record<"primary" | "neutral" | "success" | "warning" | "failure" | "general" | "focused", string[]>> | null;
285
- sources: Array<{ glob: string; exclude: boolean }>;
286
- custom: Array<{
287
- alias: { name: string; family: string } | null;
288
- mode: string | null;
289
- declarations: Array<{ property: string; value: string }>;
290
- }>;
291
- shortcuts: Array<{ name: string; expansion: string }>;
292
- safelist: string[];
293
- hasTeacss: boolean;
294
- }
295
-
296
- export interface EntryDiagnostic { file: string | null; start: number; end: number; message: string }
297
-
298
- export interface CustomDiagnostic {
299
- property: string;
300
- start: number;
301
- end: number;
302
- reason: "unknown-prefix" | "illegal-color-step" | "removed-theme";
303
- message: string;
304
- }
305
-
306
- export interface ResolvedConfigView {
307
- presets: Array<{ name: string; enforce: "pre" | "post" | null; layer: string | null }>;
308
- layers: Record<string, number>;
309
- content: { filesystem: string[] } | null;
310
- /** 合并后的 theme(oracle `config.theme`);嵌套对象原样。 */
311
- theme: Record<string, unknown>;
312
- shortcuts: Array<[string, string]>;
313
- safelist: string[];
314
- blocklist: string[];
315
- separators: string[];
316
- envMode: "dev" | "build";
317
- unmatched: "warn" | "error" | "off";
318
- shortcutsLayer: string;
319
- virtualModulePrefix: string;
320
- mergeSelectors: boolean;
321
- warn: boolean;
322
- details: boolean;
323
- outputToCssLayers: boolean | { allLayers: boolean } | false;
324
- rulesSize: number;
325
- transformers: Array<{ name: string; enforce: "pre" | "post" | "default" }>;
326
- extractors: Array<{ name: string }>;
327
- standard: { preflight: boolean | "on-demand"; variablePrefix: string; compileClass: boolean } | null;
328
- icons: { collections: string[]; mode: "mask" | "bg" | "auto"; layer: string } | null;
329
- }
330
-
331
- // ---- facade (v02.9) ----
332
- export interface FacadeHost {
333
- /** 挂钩注入的 @teacss/core 绑定;缺省时 facade 按需动态 import。 */
334
- core?: { version: string; createGenerator: (config?: object, defaults?: object) => Promise<object>; extractorSplit: object; isCountableSet?: (value: unknown) => boolean; isTokenShaped?: (token: string) => boolean; toEscapedSelector?: (raw: string) => string } | undefined;
335
- /** 挂钩注入的日志出口;缺省时写 process.stderr。 */
336
- report?: (reason: string, path: string, level: "info" | "warn") => void;
337
- }
338
- export type FacadeCreateResult = { ok: true; generator: FacadeGenerator } | { ok: false; reason: string; path: string };
339
- /** 0.8.2 TeacssGenerator 的结构子集;成员语义见 v02.9 §3。实例由 createGenerator 创建。 */
340
- export declare class FacadeGenerator {
341
- private constructor();
342
- readonly version: string;
343
- readonly events: { events: Record<string, Array<(...args: unknown[]) => unknown>>; on(event: "config", cb: (config: object) => unknown): () => void; emit(event: "config", config: object): void };
344
- readonly config: object;
345
- readonly cache: Map<string, unknown[] | null>;
346
- readonly blocked: Set<string>;
347
- readonly parentOrders: Map<string, number>;
348
- readonly activatedRules: Set<unknown>;
349
- userConfig: object;
350
- defaults: object;
351
- setConfig(userConfig?: object, defaults?: object): Promise<void>;
352
- prepareConfig(userConfig: object, defaults?: object): Promise<{ readonly config: object; readonly defaults: object; readonly generator: FacadeGenerator; readonly userConfig: object; readonly version: number }>;
353
- commitConfig(prepared: object): boolean;
354
- applyExtractors<T extends Set<string>>(code: string, id?: string, extracted?: T): Promise<T>;
355
- makeContext(raw: string, applied: unknown): unknown;
356
- parseToken(raw: string, alias?: string): Promise<unknown[] | undefined | null>;
357
- getCachedEquivalentTokens(raw: string): string[];
358
- generate(input: string | string[] | Set<string>, options?: GenerateOptions & { isInputCurrent?: () => boolean; tokenConcurrency?: number }): Promise<{ readonly css: string; layers: string[]; matched: Set<string> | Map<string, { data: unknown[]; count: number }>; getLayer(name?: string): string; getLayers(includes?: string[], excludes?: string[]): string; setLayer(layer: string, callback: (content: string) => string | Promise<string>): Promise<string>; readonly diagnostics: { unmatched: UnmatchedDiagnostic[] } }>;
359
- matchVariants(raw: string, current?: string): Promise<unknown>;
360
- constructCustomCSS(context: unknown, body: unknown, overrideSelector?: string): string;
361
- parseUtil(input: unknown, context: unknown, internal?: boolean, shortcutPrefix?: unknown): Promise<unknown>;
362
- stringifyUtil(parsed?: unknown, context?: unknown): unknown;
363
- expandShortcut(input: string, context: unknown, depth?: number): Promise<unknown>;
364
- stringifyShortcuts(parent: unknown, context: unknown, expanded: unknown, meta?: unknown, matchedPrefixes?: unknown): Promise<unknown>;
365
- isBlocked(raw: string): boolean;
366
- getBlocked(raw: string): [string, undefined] | undefined;
367
- }
368
- export declare function createGenerator(config?: object, defaults?: object, host?: FacadeHost): Promise<FacadeCreateResult>;
369
- export type TranslateResult = { ok: true; request: LoadProjectRequest; presets: object[]; transformers: object[] } | { ok: false; reason: string; path: string };
370
- export declare function translateConfig(config: object, defaults: object): Promise<TranslateResult>;
371
- export declare function selectEngineRequest(args: { hostCoreVersion?: string; option?: unknown; env?: string; compat?: { core?: string; defaultMode?: "opt-in" | "auto" } }): { engine: "rust" | "ts"; mode: "auto" | "rust" | "ts"; source: "env" | "option" | "default"; invalidEnv?: string; resolvedBy?: "opt-in"; reason?: string; path?: string; detail?: { hostCoreVersion: string; engineVersion: string; range: string } };
372
- /** SemVer 2.0 precedence, prereleases included (`0.9.0-alpha.1 < 0.9.0`); an invalid version throws TypeError (v02.11 §7.3). */
373
- export declare function compareSemver(a: string, b: string): -1 | 0 | 1;
374
- /** Only the `>=A <B` form of `engineCompat.core`; any other range throws TypeError. */
375
- export declare function satisfiesRange(version: string, range: string): boolean;
376
- export declare function createCompileClassTransformer(): { name: "@teacss/transformer-compile-class"; enforce: "pre"; transform(s: object, id: string, ctx: object): Promise<{ highlightAnnotations: HighlightAnnotation[] } | undefined>; onModuleRemoved(id: string, ctx: object): void };
377
- export declare function engineStats(): { rust: number; ts: number; fallbacks: Record<string, number> };
378
- export declare function reportFallback(reason: string, path: string, host?: FacadeHost, level?: "info" | "warn"): void;
379
- export declare class TeacssEngineError extends Error { code: string; details: Record<string, unknown> }
380
- export declare const ENGINE_PACKAGE_VERSION: string;
381
- export declare const ENGINE_COMPAT: { core: string | undefined; defaultMode: "opt-in" | "auto"; oracle: { teacssTs: string; commit: string } | undefined };
382
- export declare const ENGINE_INSTANCE: unique symbol;
383
- export declare const ENGINE_MATERIALIZE: unique symbol;
384
- export declare const ENGINE_STATS: unique symbol;
385
- export declare const PRESET_OPTIONS: { readonly standard: unique symbol; readonly icons: unique symbol; readonly official: unique symbol };
386
- export declare const CONFIG_SOURCE_DECLARATIONS: unique symbol;
387
- export declare const CONFIG_ENTRY_PROVENANCE: unique symbol;
1
+ export * from "./dist/index.js";
package/index.js CHANGED
@@ -1,2 +1,2 @@
1
1
  export * from "./binding.js";
2
- export * from "./src/facade/index.mjs";
2
+ export * from "./dist/facade/index.js";