@teacss/engine 0.9.4 → 0.10.2
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/LICENSE +22 -0
- package/README.md +28 -109
- package/binding-header.d.ts +8 -0
- package/binding.d.ts +26 -0
- package/binding.js +56 -55
- package/contract.d.ts +114 -16
- package/dist/entry.d.ts +20 -0
- package/dist/entry.js +279 -0
- package/dist/errors.d.ts +1 -7
- package/dist/errors.js +1 -13
- package/dist/fonts.d.ts +21 -0
- package/dist/fonts.js +32 -0
- package/dist/index.d.ts +3 -4
- package/dist/index.js +4 -7
- package/dist/project.d.ts +80 -0
- package/dist/project.js +136 -0
- package/package.json +19 -49
- package/dist/config-view.d.ts +0 -36
- package/dist/config-view.js +0 -135
- package/dist/constants.d.ts +0 -22
- package/dist/constants.js +0 -23
- package/dist/countable-set.d.ts +0 -57
- package/dist/countable-set.js +0 -205
- package/dist/generator.d.ts +0 -163
- package/dist/generator.js +0 -893
- package/dist/result.d.ts +0 -83
- package/dist/result.js +0 -142
- package/dist/select.d.ts +0 -183
- package/dist/select.js +0 -741
- package/dist/transformer.d.ts +0 -44
- package/dist/transformer.js +0 -59
- package/dist/ts-fallback.d.ts +0 -41
- package/dist/ts-fallback.js +0 -79
package/dist/transformer.d.ts
DELETED
|
@@ -1,44 +0,0 @@
|
|
|
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
|
package/dist/transformer.js
DELETED
|
@@ -1,59 +0,0 @@
|
|
|
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
|
package/dist/ts-fallback.d.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
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<TsCandidate>;
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* A prepared TS configuration. `commit` runs the base generator's own `commitConfig`, which
|
|
23
|
-
* re-reads in-place edits of the prepared config (generator.ts:2036-2063), and returns the
|
|
24
|
-
* generator that now serves it, or `null` when the TS generator refused the commit.
|
|
25
|
-
*/
|
|
26
|
-
export interface TsCandidate {
|
|
27
|
-
generator: TsGenerator;
|
|
28
|
-
commit(): TsGenerator | null;
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* `engine: "ts"` goes into the defaults, which take precedence over `config.engine`, so the TS
|
|
32
|
-
* generator does not enter the hook again. `committed` is the configuration committed at
|
|
33
|
-
* construction.
|
|
34
|
-
*/
|
|
35
|
-
export declare function createTsFallback(host: {
|
|
36
|
-
core?: CoreBinding | undefined;
|
|
37
|
-
}, committed: {
|
|
38
|
-
userConfig: object;
|
|
39
|
-
defaults: object;
|
|
40
|
-
}): TsFallback;
|
|
41
|
-
//# sourceMappingURL=ts-fallback.d.ts.map
|
package/dist/ts-fallback.js
DELETED
|
@@ -1,79 +0,0 @@
|
|
|
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 { generator: base, commit: () => base };
|
|
74
|
-
const prepared = await base.prepareConfig(userConfig, tsDefaults);
|
|
75
|
-
return { generator: prepared.generator, commit: () => (base.commitConfig(prepared) ? base : null) };
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
}
|
|
79
|
-
//# sourceMappingURL=ts-fallback.js.map
|