@master/css-compiler 0.0.0-site.1793659883.g69c9aebcf628

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (80) hide show
  1. package/README.md +466 -0
  2. package/dist/compiler.d.ts +42 -0
  3. package/dist/compiler.js +248 -0
  4. package/dist/contracts.d.ts +31 -0
  5. package/dist/contracts.js +13 -0
  6. package/dist/diagnostics/contracts.d.ts +119 -0
  7. package/dist/diagnostics/contracts.js +1 -0
  8. package/dist/diagnostics/design-system.d.ts +31 -0
  9. package/dist/diagnostics/design-system.js +75 -0
  10. package/dist/diagnostics/index.d.ts +28 -0
  11. package/dist/diagnostics/index.js +304 -0
  12. package/dist/diagnostics/project-comparison.d.ts +4 -0
  13. package/dist/diagnostics/project-comparison.js +8 -0
  14. package/dist/index.d.ts +95 -0
  15. package/dist/index.js +34 -0
  16. package/dist/node-compiler.d.ts +133 -0
  17. package/dist/node-compiler.js +417 -0
  18. package/dist/node-imports.d.ts +54 -0
  19. package/dist/node-imports.js +253 -0
  20. package/dist/node.d.ts +21 -0
  21. package/dist/node.js +47 -0
  22. package/dist/notices.d.ts +5 -0
  23. package/dist/notices.js +29 -0
  24. package/dist/prepared-graph-cache.d.ts +5 -0
  25. package/dist/prepared-graph-cache.js +31 -0
  26. package/dist/project/binding-project.d.ts +29 -0
  27. package/dist/project/binding-project.js +100 -0
  28. package/dist/project/entries.d.ts +7 -0
  29. package/dist/project/entries.js +30 -0
  30. package/dist/project/manifest-sync.d.ts +5 -0
  31. package/dist/project/manifest-sync.js +40 -0
  32. package/dist/project/manifest.d.ts +5 -0
  33. package/dist/project/manifest.js +49 -0
  34. package/dist/project/options.d.ts +43 -0
  35. package/dist/project/options.js +1 -0
  36. package/dist/pure-css-cache.d.ts +11 -0
  37. package/dist/pure-css-cache.js +39 -0
  38. package/dist/session.d.ts +19 -0
  39. package/dist/session.js +46 -0
  40. package/dist/stylesheet/browser.d.ts +32 -0
  41. package/dist/stylesheet/browser.js +71 -0
  42. package/dist/stylesheet/compiled-source.d.ts +11 -0
  43. package/dist/stylesheet/compiled-source.js +96 -0
  44. package/dist/stylesheet/composition-cache.d.ts +18 -0
  45. package/dist/stylesheet/composition-cache.js +79 -0
  46. package/dist/stylesheet/delivery.d.ts +103 -0
  47. package/dist/stylesheet/delivery.js +367 -0
  48. package/dist/stylesheet/directives.d.ts +31 -0
  49. package/dist/stylesheet/directives.js +105 -0
  50. package/dist/stylesheet/index-public.d.ts +3 -0
  51. package/dist/stylesheet/index-public.js +4 -0
  52. package/dist/stylesheet/index.d.ts +39 -0
  53. package/dist/stylesheet/index.js +501 -0
  54. package/dist/stylesheet/linked-stylesheet.d.ts +10 -0
  55. package/dist/stylesheet/linked-stylesheet.js +13 -0
  56. package/dist/stylesheet/output-map.d.ts +20 -0
  57. package/dist/stylesheet/output-map.js +222 -0
  58. package/dist/stylesheet/public.d.ts +171 -0
  59. package/dist/stylesheet/public.js +346 -0
  60. package/dist/stylesheet/reference-files.d.ts +6 -0
  61. package/dist/stylesheet/reference-files.js +13 -0
  62. package/dist/stylesheet/reference-origins.d.ts +4 -0
  63. package/dist/stylesheet/reference-origins.js +28 -0
  64. package/dist/stylesheet/render-core.d.ts +35 -0
  65. package/dist/stylesheet/render-core.js +28 -0
  66. package/dist/stylesheet/render-delivery.d.ts +4 -0
  67. package/dist/stylesheet/render-delivery.js +61 -0
  68. package/dist/stylesheet/render.d.ts +5 -0
  69. package/dist/stylesheet/render.js +31 -0
  70. package/dist/stylesheet/source-context.d.ts +8 -0
  71. package/dist/stylesheet/source-context.js +71 -0
  72. package/dist/stylesheet/source-map-url.d.ts +4 -0
  73. package/dist/stylesheet/source-map-url.js +11 -0
  74. package/dist/stylesheet/source.d.ts +3 -0
  75. package/dist/stylesheet/source.js +52 -0
  76. package/dist/stylesheet/types.d.ts +162 -0
  77. package/dist/stylesheet/types.js +1 -0
  78. package/dist/value-validation.d.ts +19 -0
  79. package/dist/value-validation.js +96 -0
  80. package/package.json +79 -0
@@ -0,0 +1,304 @@
1
+ import { createExtractedCSSResult, registerStylesheetSource } from "../stylesheet/index.js";
2
+ import { discoverManifestEntries, loadProjectManifest } from "../project/manifest.js";
3
+ import { compareProjectSnapshots } from "./project-comparison.js";
4
+ import { createMasterCSSDesignSystemReport, inspectResolvedProjectDesignSystem } from "./design-system.js";
5
+ import { pathToFileURL } from "node:url";
6
+ import path from "node:path";
7
+ import { validateClassNames } from "@master/css-tooling/validator";
8
+ import fs from "node:fs";
9
+ import { MasterCSSScanner } from "@master/css-tooling/scanner/node";
10
+ import fg from "fast-glob";
11
+ import { MASTER_CSS_DIAGNOSTICS_REPORT_VERSION, createCompilerBindingSession } from "@master/css-binding/compiler";
12
+ // src/diagnostics/index.ts
13
+ const MASTER_CSS_INSPECTION_REPORT_VERSION = MASTER_CSS_DIAGNOSTICS_REPORT_VERSION;
14
+ const DEFAULT_SOURCE_PATTERNS = ["**/*.{html,htm,js,jsx,mjs,cjs,ts,tsx,mts,cts,svelte,astro,vue,md,mdx,pug,php}"];
15
+ const DEFAULT_IGNORE_PATTERNS = ["**/node_modules/**", "node_modules"];
16
+ async function createBindingInspectionReport(input) {
17
+ using compiler = await createCompilerBindingSession();
18
+ return await compiler.createInspectionReport(input);
19
+ }
20
+ function normalizeSourcePatterns(specifiedSourcePaths) {
21
+ return specifiedSourcePaths?.length ? specifiedSourcePaths : DEFAULT_SOURCE_PATTERNS;
22
+ }
23
+ function normalizeGlobPatterns(patterns) {
24
+ return patterns.map((pattern) => pattern.replace(/\\/g, "/"));
25
+ }
26
+ function resolveSourcePaths(cwd, sourcePatterns, ignore = []) {
27
+ return fg.sync(normalizeGlobPatterns(sourcePatterns), {
28
+ cwd,
29
+ ignore: normalizeGlobPatterns(ignore),
30
+ onlyFiles: true
31
+ }).filter(Boolean);
32
+ }
33
+ function parseClassChecks(value) {
34
+ return typeof value === "string" ? value.split(/\s+/).map((item) => item.trim()).filter(Boolean) : (value ?? []).map((item) => item.trim()).filter(Boolean);
35
+ }
36
+ async function resolveFilePath(cwd, filePath, resolver) {
37
+ return resolver ? await resolver(filePath) : path.resolve(cwd, filePath);
38
+ }
39
+ function preserveWorkspacePath(cwd, filePath) {
40
+ let realCwd;
41
+ try {
42
+ realCwd = fs.realpathSync.native(cwd);
43
+ } catch {
44
+ return filePath;
45
+ }
46
+ if (realCwd === cwd || filePath !== realCwd && !filePath.startsWith(`${realCwd}${path.sep}`)) return filePath;
47
+ return path.join(cwd, path.relative(realCwd, filePath));
48
+ }
49
+ async function registerManagedCSSEntries(scanner, stylesheetSources, baseManifest, resolveExistingFile) {
50
+ const entries = [];
51
+ const warnings = [];
52
+ const errors = [];
53
+ stylesheetSources.clear();
54
+ for (const entry of await discoverManifestEntries({ root: scanner.cwd })) {
55
+ const filePath = preserveWorkspacePath(scanner.cwd, await resolveFilePath(scanner.cwd, entry, resolveExistingFile));
56
+ try {
57
+ const result = await registerStylesheetSource(scanner, stylesheetSources, filePath, fs.readFileSync(filePath, "utf8"), {
58
+ baseManifest,
59
+ projectDir: scanner.cwd
60
+ });
61
+ const styleSource = stylesheetSources.get(filePath);
62
+ entries.push({
63
+ filePath,
64
+ masterCSS: Boolean(styleSource?.masterCSS),
65
+ pruneNativeCSS: Boolean(styleSource?.pruneNativeCSS),
66
+ dependencies: [...styleSource?.dependencies ?? []].map((dependency) => preserveWorkspacePath(scanner.cwd, dependency)),
67
+ sourceDependencies: [...styleSource?.sourceDependencies ?? []].map((dependency) => preserveWorkspacePath(scanner.cwd, dependency)),
68
+ warnings: result.warnings ?? [],
69
+ errors: []
70
+ });
71
+ warnings.push(...result.warnings ?? []);
72
+ } catch (error) {
73
+ const message = error instanceof Error ? error.message : String(error);
74
+ entries.push({
75
+ filePath,
76
+ masterCSS: false,
77
+ pruneNativeCSS: false,
78
+ dependencies: [],
79
+ sourceDependencies: [],
80
+ warnings: [],
81
+ errors: [message]
82
+ });
83
+ errors.push({
84
+ filePath,
85
+ message
86
+ });
87
+ }
88
+ }
89
+ scanner.resetDependencies = Array.from(stylesheetSources.values()).flatMap((source) => source.dependencies);
90
+ return {
91
+ entries,
92
+ warnings,
93
+ errors
94
+ };
95
+ }
96
+ function inspectSourceFile(classes, source, filePath, scan, firstSourceByClass) {
97
+ const candidates = [...new Set(scan.candidates)];
98
+ const latent = candidates.filter((value) => classes.latent.has(value));
99
+ const valid = candidates.filter((value) => classes.valid.has(value));
100
+ const invalid = candidates.filter((value) => classes.invalid.has(value));
101
+ const usedNative = candidates.filter((value) => classes.usedNative.has(value));
102
+ for (const className of [
103
+ ...latent,
104
+ ...valid,
105
+ ...invalid,
106
+ ...usedNative
107
+ ]) if (!firstSourceByClass.has(className)) firstSourceByClass.set(className, filePath);
108
+ return {
109
+ filePath,
110
+ source,
111
+ scanned: true,
112
+ changed: scan.changed,
113
+ discovered: {
114
+ latent,
115
+ valid,
116
+ invalid,
117
+ usedNative
118
+ }
119
+ };
120
+ }
121
+ async function inspectProject(options, capture) {
122
+ const cwd = path.resolve(options.cwd || process.cwd());
123
+ const classChecks = parseClassChecks(options.classes);
124
+ const specifiedPatterns = options.patterns;
125
+ const sourcePatterns = normalizeSourcePatterns(specifiedPatterns);
126
+ options.validatePatterns?.(sourcePatterns);
127
+ const scanner = new MasterCSSScanner({
128
+ manifest: options.manifest,
129
+ exclude: specifiedPatterns?.length ? void 0 : DEFAULT_IGNORE_PATTERNS,
130
+ verbose: 0
131
+ }, cwd);
132
+ const stylesheetSources = /* @__PURE__ */ new Map();
133
+ const firstSourceByClass = /* @__PURE__ */ new Map();
134
+ let reportInput;
135
+ let stylesheetInspection;
136
+ let snapshot;
137
+ let designSystem;
138
+ try {
139
+ let projectManifest = options.manifest;
140
+ let projectError;
141
+ try {
142
+ const project = await loadProjectManifest({
143
+ root: cwd,
144
+ baseManifest: options.manifest,
145
+ includeSourceGraph: Boolean(options.designSystem)
146
+ });
147
+ projectManifest = project.manifest;
148
+ if (options.designSystem) designSystem = await inspectResolvedProjectDesignSystem(project, cwd, options);
149
+ } catch (error) {
150
+ projectError = error;
151
+ }
152
+ if (projectError && options.designSystem) throw projectError;
153
+ await scanner.init({
154
+ ...scanner.customOptions,
155
+ manifest: projectManifest
156
+ });
157
+ stylesheetInspection = await registerManagedCSSEntries(scanner, stylesheetSources, options.manifest, options.resolveExistingFile);
158
+ if (projectError) throw projectError;
159
+ const sourcePaths = resolveSourcePaths(cwd, sourcePatterns, options.ignore ?? (specifiedPatterns?.length ? [] : scanner.options.exclude)).filter((source) => scanner.isSourceAllowed(source, { explicit: Boolean(specifiedPatterns?.length) }));
160
+ const resolvedSourcePaths = await Promise.all(sourcePaths.map((source) => resolveFilePath(cwd, source, options.resolveExistingFile)));
161
+ const scans = await Promise.all(sourcePaths.map((source, index) => scanner.scanSource(source, fs.readFileSync(resolvedSourcePaths[index], "utf8"))));
162
+ const classes = {
163
+ latent: new Set(scanner.latentClasses),
164
+ valid: new Set(scanner.validClasses),
165
+ invalid: new Set(scanner.invalidClasses),
166
+ usedNative: new Set(scanner.usedNativeClasses)
167
+ };
168
+ const files = sourcePaths.map((source, index) => inspectSourceFile(classes, source, resolvedSourcePaths[index], scans[index], firstSourceByClass));
169
+ const entry = pathToFileURL(path.join(cwd, "master.snapshot.css")).href;
170
+ const delivery = capture ? {
171
+ entryURL: entry,
172
+ stylesheetURL: (file, variant) => `${pathToFileURL(file).href}${variant ? `?variant=${encodeURIComponent(variant)}` : ""}`,
173
+ resourceURL: (file) => pathToFileURL(file).href
174
+ } : void 0;
175
+ const cssResult = await createExtractedCSSResult({
176
+ scanner,
177
+ stylesheetSources,
178
+ baseManifest: options.manifest,
179
+ projectDir: scanner.cwd,
180
+ delivery
181
+ });
182
+ const safelist = scanner.options.safelist ?? [];
183
+ const blocklist = scanner.options.blocklist ?? [];
184
+ if (capture) {
185
+ if (stylesheetInspection.errors.length) throw new Error("Cannot capture a project with stylesheet errors.");
186
+ const delivered = cssResult;
187
+ const native = await createExtractedCSSResult({
188
+ scanner,
189
+ stylesheetSources,
190
+ baseManifest: options.manifest,
191
+ projectDir: cwd,
192
+ delivery,
193
+ includeGeneratedCSS: false
194
+ });
195
+ const resolvedSources = new Map(files.map((file) => [file.source, file.filePath]));
196
+ const consumers = /* @__PURE__ */ new Map();
197
+ for (const source of scanner.sources) {
198
+ const identity = source.parentSource ?? source.source;
199
+ const file = resolvedSources.get(identity) ?? identity;
200
+ const candidates = consumers.get(file) ?? /* @__PURE__ */ new Set();
201
+ for (const name of source.candidates) if (Object.values(classes).some((group) => group.has(name))) candidates.add(name);
202
+ consumers.set(file, candidates);
203
+ }
204
+ snapshot = {
205
+ version: 1,
206
+ manifest: scanner.manifest,
207
+ sources: [...[...consumers].map(([path, classes]) => ({
208
+ path,
209
+ classes: [...classes]
210
+ })), {
211
+ path: "master:safelist",
212
+ classes: [...safelist]
213
+ }],
214
+ stylesheets: [{
215
+ path: entry,
216
+ css: native.css
217
+ }, ...(native.stylesheets ?? []).map((asset) => ({
218
+ path: asset.href,
219
+ css: asset.css
220
+ }))],
221
+ outputs: [{
222
+ path: entry,
223
+ css: delivered.css
224
+ }, ...(delivered.stylesheets ?? []).map((asset) => ({
225
+ path: asset.href,
226
+ css: asset.css
227
+ }))],
228
+ excluded: [...options.ignore ?? scanner.options.exclude ?? [], ...blocklist.map(String)],
229
+ unresolved: ["Class names constructed dynamically and remote content are not exhaustively enumerated.", `Only source patterns ${JSON.stringify(sourcePatterns)} and discovered stylesheet entries are included.`]
230
+ };
231
+ }
232
+ reportInput = {
233
+ version: MASTER_CSS_DIAGNOSTICS_REPORT_VERSION,
234
+ cwd,
235
+ patterns: sourcePatterns,
236
+ files,
237
+ classes: classChecks,
238
+ inspections: (await validateClassNames([.../* @__PURE__ */ new Set([
239
+ ...scanner.latentClasses,
240
+ ...scanner.validClasses,
241
+ ...scanner.invalidClasses,
242
+ ...classChecks
243
+ ])].filter((name) => !scanner.usedNativeClasses.has(name)), { manifest: scanner.manifest })).classes,
244
+ scanner: {
245
+ latent: [...scanner.latentClasses],
246
+ valid: [...scanner.validClasses],
247
+ invalid: [...scanner.invalidClasses],
248
+ native: [...scanner.nativeClassNames],
249
+ usedNative: [...scanner.usedNativeClasses],
250
+ safelist,
251
+ blocklist: blocklist.map((entry) => entry instanceof RegExp ? {
252
+ source: entry.source,
253
+ flags: entry.flags
254
+ } : entry),
255
+ resetDependencies: scanner.resetDependencies
256
+ },
257
+ stylesheets: stylesheetInspection,
258
+ css: {
259
+ included: Boolean(options.includeCss),
260
+ text: cssResult.css,
261
+ variables: Object.keys(cssResult.emittedGlobals.variables),
262
+ keyframes: Object.keys(cssResult.emittedGlobals.keyframes)
263
+ },
264
+ firstSourceByClass: Object.fromEntries(firstSourceByClass)
265
+ };
266
+ } catch (error) {
267
+ if (options.designSystem && !designSystem) throw error;
268
+ snapshot = void 0;
269
+ reportInput = {
270
+ version: MASTER_CSS_DIAGNOSTICS_REPORT_VERSION,
271
+ cwd,
272
+ patterns: sourcePatterns,
273
+ files: [],
274
+ classes: classChecks,
275
+ scanner: {},
276
+ stylesheets: stylesheetInspection ?? {},
277
+ css: {},
278
+ fatalError: error instanceof Error ? error.message : String(error)
279
+ };
280
+ } finally {
281
+ await scanner.dispose();
282
+ }
283
+ const report = await createBindingInspectionReport(reportInput);
284
+ return {
285
+ report: designSystem ? {
286
+ ...report,
287
+ designSystem
288
+ } : report,
289
+ snapshot
290
+ };
291
+ }
292
+ async function createMasterCSSInspectionReport(options) {
293
+ return (await inspectProject(options, false)).report;
294
+ }
295
+ /** Capture known project consumers and resolved CSS assets in one inspection session. */
296
+ async function captureMasterCSSProject(options) {
297
+ const { report, snapshot } = await inspectProject(options, true);
298
+ if (!snapshot) throw new Error(`Cannot capture project snapshot: ${report.diagnostics.map((item) => item.message).join("; ")}`);
299
+ return {
300
+ report,
301
+ snapshot
302
+ };
303
+ }
304
+ export { MASTER_CSS_INSPECTION_REPORT_VERSION, captureMasterCSSProject, compareProjectSnapshots, createMasterCSSDesignSystemReport, createMasterCSSInspectionReport };
@@ -0,0 +1,4 @@
1
+ import { MasterCSSProjectComparison, MasterCSSProjectComparisonRequest } from "../index.js";
2
+ /** Compare prepared project states without reading files or evaluating browser styles. */
3
+ declare function compareProjectSnapshots(request: MasterCSSProjectComparisonRequest): Promise<MasterCSSProjectComparison>;
4
+ export { compareProjectSnapshots };
@@ -0,0 +1,8 @@
1
+ import { createCompiler } from "../index.js";
2
+ // src/diagnostics/project-comparison.ts
3
+ /** Compare prepared project states without reading files or evaluating browser styles. */
4
+ async function compareProjectSnapshots(request) {
5
+ using compiler = await createCompiler();
6
+ return compiler.compareProjectSnapshots(request);
7
+ }
8
+ export { compareProjectSnapshots };
@@ -0,0 +1,95 @@
1
+ import { MasterCSSDiagnostic } from "@master/css-schema";
2
+ import { MasterCSSProjectAssetChange, MasterCSSProjectComparison, MasterCSSProjectComparisonRequest, MasterCSSProjectSnapshot } from "@master/css-binding/compiler";
3
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
4
+ import { MasterCSSBinding, MasterCSSWasmBindingLoadOptions } from "@master/css-binding";
5
+ import { MasterCSSCompiler, MasterCSSCompiler as MasterCSSCompiler$1 } from "./compiler.js";
6
+ interface MasterCSSCompilerOptions {
7
+ readonly binding?: MasterCSSBinding;
8
+ readonly wasm?: MasterCSSWasmBindingLoadOptions;
9
+ }
10
+ interface MasterCSSCompileOptions {
11
+ readonly classes?: readonly string[];
12
+ readonly from?: string;
13
+ readonly preserveNativeCSS?: boolean;
14
+ /** Opt in to pruning native rules in project-owned files. */
15
+ readonly pruneNativeCSS?: boolean;
16
+ /** Keep untouched native source for host transforms; incompatible with class pruning. */
17
+ readonly preserveNativeSource?: boolean;
18
+ /** Report CSS value errors by default; error rejects the complete output. */
19
+ readonly validation?: 'report' | 'error';
20
+ readonly onDiagnostic?: (diagnostic: MasterCSSDiagnostic) => void;
21
+ }
22
+ interface MasterCSSCompileResult {
23
+ /** Serialized map v3 for css when produced by a stylesheet host. */
24
+ readonly sourceMap?: string;
25
+ readonly css: string;
26
+ readonly nativeCSS: string;
27
+ readonly generatedCSS: string;
28
+ readonly classNames: readonly string[];
29
+ readonly nativeClassNames: readonly string[];
30
+ readonly dependencies: readonly string[];
31
+ readonly diagnostics: readonly MasterCSSDiagnostic[];
32
+ readonly directiveSummary: Readonly<{
33
+ readonly manifestInput: Readonly<{
34
+ readonly keys: readonly string[];
35
+ readonly counts: Readonly<Record<string, number>>;
36
+ }>;
37
+ readonly styleDefinitions: number;
38
+ readonly extractionPolicy: Readonly<{
39
+ readonly include: readonly string[];
40
+ readonly exclude: readonly string[];
41
+ readonly safelist: readonly string[];
42
+ readonly safelistKeyframes: readonly string[];
43
+ readonly blocklist: readonly (string | RegExp)[];
44
+ readonly preserveNative: boolean;
45
+ readonly pruneNative: boolean;
46
+ }>;
47
+ }>;
48
+ }
49
+ interface MasterCSSCompileManifestOptions extends MasterCSSCompileOptions {
50
+ readonly baseManifest: MasterCSSManifest;
51
+ }
52
+ interface MasterCSSCompileManifestResult extends MasterCSSCompileResult {
53
+ readonly manifest: MasterCSSManifest;
54
+ readonly directives: MasterCSSCompileResult;
55
+ }
56
+ /**
57
+ * Prepared files/edges and delivery URLs for boundary-preserving compilation.
58
+ * Resolve @reference inputs into resolutionManifest before calling this API.
59
+ * Supply resourceURLs to relocate parsed url()/image-set() resources before definition merging.
60
+ * Without that map, delivery URLs must retain the original resource bases.
61
+ */
62
+ type MasterCSSCompileStylesheetsRequest = import('@master/css-binding/compiler').MasterCSSCompileStylesheetGraphRequest;
63
+ interface MasterCSSCompileStylesheetsResult extends MasterCSSCompileManifestResult {
64
+ readonly entry: string;
65
+ /** Every stylesheet must be delivered at its href, including the entry. */
66
+ readonly stylesheets: readonly Readonly<import('@master/css-binding/compiler').MasterCSSCompiledStylesheet>[];
67
+ }
68
+ /** Prepare source boundaries before the host assigns final asset URLs. */
69
+ type MasterCSSPrepareStylesheetBundleRequest = import('@master/css-binding/compiler').MasterCSSPrepareStylesheetBundleRequest;
70
+ type MasterCSSStylesheetBundle = import('@master/css-binding/compiler').MasterCSSStylesheetBundle;
71
+ /** Render all assets; relative ordinary resources/imports require explicit URL mappings. */
72
+ type MasterCSSRenderStylesheetBundleRequest = import('@master/css-binding/compiler').MasterCSSRenderStylesheetBundleRequest;
73
+ type MasterCSSStylesheetAsset = import('@master/css-binding/compiler').MasterCSSStylesheetAsset;
74
+ interface MasterCSSCompilerInspection {
75
+ readonly hasMasterCSSImport: boolean;
76
+ readonly hasMasterEntry: boolean;
77
+ readonly directives: readonly {
78
+ readonly name: string;
79
+ readonly range: {
80
+ readonly start: number;
81
+ readonly end: number;
82
+ };
83
+ readonly preludeRange: {
84
+ readonly start: number;
85
+ readonly end: number;
86
+ };
87
+ readonly hasBlock: boolean;
88
+ readonly quotedStrings: number;
89
+ }[];
90
+ }
91
+ declare function createCompiler(options?: MasterCSSCompilerOptions): Promise<MasterCSSCompiler$1>;
92
+ declare function inspectCSS(source: string): Promise<MasterCSSCompilerInspection>;
93
+ declare function compileCSS(source: string, options?: MasterCSSCompileOptions): Promise<MasterCSSCompileResult>;
94
+ declare function compileManifest(source: string, options: MasterCSSCompileManifestOptions): Promise<MasterCSSCompileManifestResult>;
95
+ export { MasterCSSCompileManifestOptions, MasterCSSCompileManifestResult, MasterCSSCompileOptions, MasterCSSCompileResult, MasterCSSCompileStylesheetsRequest, MasterCSSCompileStylesheetsResult, MasterCSSCompiler, MasterCSSCompilerInspection, MasterCSSCompilerOptions, MasterCSSPrepareStylesheetBundleRequest, type MasterCSSProjectAssetChange, type MasterCSSProjectComparison, type MasterCSSProjectComparisonRequest, type MasterCSSProjectSnapshot, MasterCSSRenderStylesheetBundleRequest, MasterCSSStylesheetAsset, MasterCSSStylesheetBundle, compileCSS, compileManifest, createCompiler, inspectCSS };
package/dist/index.js ADDED
@@ -0,0 +1,34 @@
1
+ import { MasterCSSCompiler, bindCompilerSessionInternal } from "./compiler.js";
2
+ import { createCompilerBindingSession } from "./session.js";
3
+ // src/index.ts
4
+ async function createCompiler(options = {}) {
5
+ return bindCompilerSessionInternal(await createCompilerBindingSession({
6
+ binding: options.binding,
7
+ wasm: options.wasm
8
+ }));
9
+ }
10
+ async function inspectCSS(source) {
11
+ const compiler = await createCompiler();
12
+ try {
13
+ return compiler.inspectCSS(source);
14
+ } finally {
15
+ compiler.dispose();
16
+ }
17
+ }
18
+ async function compileCSS(source, options = {}) {
19
+ const compiler = await createCompiler();
20
+ try {
21
+ return compiler.compileCSS(source, options);
22
+ } finally {
23
+ compiler.dispose();
24
+ }
25
+ }
26
+ async function compileManifest(source, options) {
27
+ const compiler = await createCompiler();
28
+ try {
29
+ return compiler.compileManifest(source, options);
30
+ } finally {
31
+ compiler.dispose();
32
+ }
33
+ }
34
+ export { MasterCSSCompiler, compileCSS, compileManifest, createCompiler, inspectCSS };
@@ -0,0 +1,133 @@
1
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
2
+ import { CSSReferenceStatement, CSSReferenceStatement as CSSReferenceStatement$1, CompileCSSFileOptions, CompileCSSFileOptions as CompileCSSFileOptions$1, CompileCSSOptions, CompileCSSOptions as CompileCSSOptions$1, CompileCSSResult, CompileCSSResult as CompileCSSResult$1, ResolvedCSSImportGraph, ResolvedCSSImportGraph as ResolvedCSSImportGraph$1 } from "./contracts.js";
3
+ import { CSSDefinitionSource, CSSDirectiveExtractionPolicy, CSSDirectiveReference } from "@master/css-schema/css-directives";
4
+ import { PreparedCSSImportGraph, resolveMasterCSSPackageEntryFile } from "./node-imports.js";
5
+ interface CSSDependencyImport {
6
+ start: number;
7
+ end: number;
8
+ statement: string;
9
+ source: string;
10
+ }
11
+ interface CSSDependencyAnalysis {
12
+ sourceWithoutReferences: string;
13
+ imports: CSSDependencyImport[];
14
+ resources: {
15
+ start: number;
16
+ end: number;
17
+ url: string;
18
+ }[];
19
+ usesCustomMedia?: boolean;
20
+ }
21
+ interface InspectCSSResult {
22
+ hasMasterCSSImport: boolean;
23
+ hasMasterEntry: boolean;
24
+ directives: {
25
+ name: string;
26
+ range: {
27
+ start: number;
28
+ end: number;
29
+ };
30
+ preludeRange: {
31
+ start: number;
32
+ end: number;
33
+ };
34
+ hasBlock: boolean;
35
+ quotedStrings: number;
36
+ }[];
37
+ }
38
+ interface ResolveCSSImportGraphOptions {
39
+ onDependency?: (file: string) => void;
40
+ onSource?: (file: string, source: string) => void;
41
+ projectDir?: string;
42
+ expandPackageImports?: boolean;
43
+ onReference?: (reference: CSSReferenceStatement$1, fromFile: string) => void;
44
+ }
45
+ type CompileCSSManifestOptions = CompileCSSFileOptions$1 & {
46
+ baseManifest?: MasterCSSManifest;
47
+ };
48
+ type CompileCSSManifestSourceOptions = CompileCSSOptions$1 & {
49
+ baseManifest?: MasterCSSManifest;
50
+ root?: string;
51
+ };
52
+ type CompileCSSManifestInternalOptions = CompileCSSManifestSourceOptions & {
53
+ /** Host context definitions retain file URL owners until the host publishes assets. */
54
+ resolveReferenceResources?: boolean;
55
+ definitionsOnly?: boolean;
56
+ referenceResources?: boolean;
57
+ referenceStack?: string[];
58
+ sourceText?: string;
59
+ onDependency?: (file: string) => void;
60
+ };
61
+ interface CompileCSSManifestResult extends Omit<CompileCSSResult$1, 'manifestInput'> {
62
+ sourceTexts?: Record<string, string>;
63
+ manifest: MasterCSSManifest;
64
+ resolutionManifest: MasterCSSManifest;
65
+ directives: CompileCSSResult$1;
66
+ }
67
+ interface CompileProjectManifestResult extends CompileCSSManifestResult {
68
+ entries: string[];
69
+ }
70
+ declare function inspectCSS(source: string): InspectCSSResult;
71
+ declare function resolveCSSImportGraph(file: string, options?: ResolveCSSImportGraphOptions): ResolvedCSSImportGraph$1;
72
+ declare function resolveCSSImportGraphSource(file: string, source: string | undefined, options?: ResolveCSSImportGraphOptions): ResolvedCSSImportGraph$1;
73
+ declare function analyzeCSSDependencies(source: string): CSSDependencyAnalysis;
74
+ declare function resolveMasterCSSPackageImportGraph(projectDir?: string): ResolvedCSSImportGraph$1;
75
+ declare function stripRequestSuffix(id: string): string;
76
+ declare function stripWindowsExtendedPathPrefix(file: string): string;
77
+ declare function isMasterCSSPackageStyleFile(id: string, projectDir?: string): boolean;
78
+ declare function compileCSS(source: string, options?: CompileCSSOptions$1): CompileCSSResult$1;
79
+ declare function filterCSSExtractionCandidates(candidates: string[], blocklist?: Iterable<string | RegExp>): string[];
80
+ declare function mergeCSSDirectiveExtractionPolicy(...policies: (Partial<CSSDirectiveExtractionPolicy> | undefined)[]): CSSDirectiveExtractionPolicy;
81
+ declare function createCSSDirectiveExtractionPolicy(): CSSDirectiveExtractionPolicy;
82
+ interface StandaloneCSSDirectiveStatement {
83
+ start: number;
84
+ end: number;
85
+ atRuleName: 'master' | 'source' | 'safelist' | 'blocklist' | 'preserve';
86
+ name: string;
87
+ statement: string;
88
+ args: string[];
89
+ modifiers: string[];
90
+ }
91
+ declare function findStandaloneCSSDirectiveStatements(source: string): StandaloneCSSDirectiveStatement[];
92
+ declare function collectStandaloneCSSDirectiveExtractionPolicy(source: string): CSSDirectiveExtractionPolicy;
93
+ declare function removeStandaloneCSSDirectives(source: string): string;
94
+ declare function resolveCSSReferenceFile(reference: CSSDirectiveReference & {
95
+ resolvedFile?: string;
96
+ }, options?: CompileCSSManifestSourceOptions): string;
97
+ /** Compile original files independently before merging their manifest and native output. */
98
+ declare function compileCSSManifestGraph(graph: PreparedCSSImportGraph, options?: CompileCSSManifestInternalOptions & {
99
+ mapReferences?: (file: string, source: string, references: CSSDirectiveReference[]) => readonly CSSDirectiveReference[];
100
+ }): {
101
+ notices?: import("@master/css-schema/css-directives").CSSDirectiveNotice[];
102
+ definitionSources?: CSSDefinitionSource[];
103
+ nativeOutput?: import("@master/css-schema/css-directives").CSSNativeOutput;
104
+ sourceMap?: string;
105
+ nativeMappings?: import("@master/css-schema/css-directives").CSSOutputMapping[];
106
+ generatedMappings?: import("@master/css-schema/css-directives").CSSOutputMapping[];
107
+ manifestInput: import("@master/css-schema/css-directives").CSSDirectiveManifestInput;
108
+ extractionPolicy: CSSDirectiveExtractionPolicy;
109
+ classNames: string[];
110
+ nativeClassNames: string[];
111
+ nativeCSS: string;
112
+ generatedCSS: string;
113
+ references?: CSSDirectiveReference[];
114
+ styleDefinitions?: import("@master/css-schema/css-directives").CSSDirectiveStyleDefinition[];
115
+ dependencies: string[];
116
+ warnings: string[];
117
+ css: string;
118
+ outputMappings: import("@master/css-schema/css-directives").CSSOutputMapping[];
119
+ sourceTexts: Record<string, string>;
120
+ manifest: MasterCSSManifest;
121
+ resolutionManifest: MasterCSSManifest;
122
+ directives: import("@master/css-schema/css-directives").CSSDirectiveResult;
123
+ stylesheets: import("@master/css-binding/protocol").MasterCSSCompiledStylesheet[];
124
+ };
125
+ declare function createManifestFromCSSResult(result: CompileCSSResult$1, options?: CompileCSSManifestSourceOptions & {
126
+ sourceText?: string;
127
+ onDependency?: (file: string) => void;
128
+ resolveReferenceResources?: boolean;
129
+ }): CompileCSSManifestResult;
130
+ declare function compileCSSManifest(source: string, options?: CompileCSSManifestSourceOptions): CompileCSSManifestResult;
131
+ declare function compileCSSManifestFile(file: string, options?: CompileCSSManifestOptions): CompileCSSManifestResult;
132
+ declare function compileProjectManifest(entries: string[], options?: CompileCSSManifestOptions): CompileProjectManifestResult;
133
+ export { CSSDependencyAnalysis, CSSDependencyImport, type CSSReferenceStatement, type CompileCSSFileOptions, CompileCSSManifestOptions, CompileCSSManifestResult, CompileCSSManifestSourceOptions, type CompileCSSOptions, type CompileCSSResult, CompileProjectManifestResult, InspectCSSResult, ResolveCSSImportGraphOptions, type ResolvedCSSImportGraph, StandaloneCSSDirectiveStatement, analyzeCSSDependencies, collectStandaloneCSSDirectiveExtractionPolicy, compileCSS, compileCSSManifest, compileCSSManifestFile, compileCSSManifestGraph, compileProjectManifest, createCSSDirectiveExtractionPolicy, createManifestFromCSSResult, filterCSSExtractionCandidates, findStandaloneCSSDirectiveStatements, inspectCSS, isMasterCSSPackageStyleFile, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives, resolveCSSImportGraph, resolveCSSImportGraphSource, resolveCSSReferenceFile, resolveMasterCSSPackageEntryFile, resolveMasterCSSPackageImportGraph, stripRequestSuffix, stripWindowsExtendedPathPrefix };