@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,253 @@
1
+ import { createRequire } from "node:module";
2
+ import { fileURLToPath, pathToFileURL } from "node:url";
3
+ import { dirname, extname, isAbsolute, relative, resolve } from "node:path";
4
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
5
+ // src/node-imports.ts
6
+ /** @internal Node filesystem and package inputs for the Rust import graph. */
7
+ const require = createRequire(import.meta.url);
8
+ const MASTER_CSS_PACKAGE_IDS = /* @__PURE__ */ new Set(["@master/css", "@master/css-preset"]);
9
+ function normalizeStylesheetGraphID(id) {
10
+ return id.startsWith("\0") ? id : resolve(id);
11
+ }
12
+ function isExpandableImportSource(source, fromFile) {
13
+ if (source.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(source)) return false;
14
+ if (extname(decodeURIComponent(new URL(source, "file:///").pathname)).toLowerCase() !== ".css") return false;
15
+ return source.startsWith("./") || source.startsWith("../") || existsSync(resolveRelativeCSSFile(source, fromFile));
16
+ }
17
+ function resolveRelativeCSSFile(source, fromFile) {
18
+ return fileURLToPath(new URL(source, pathToFileURL(fromFile)));
19
+ }
20
+ function readJSONFile(file) {
21
+ return JSON.parse(readFileSync(file, "utf-8"));
22
+ }
23
+ function findPackageRoot(entryFile, packageName) {
24
+ let directory = dirname(entryFile);
25
+ while (true) {
26
+ const packageJSONFile = resolve(directory, "package.json");
27
+ if (existsSync(packageJSONFile)) try {
28
+ const packageJSON = readJSONFile(packageJSONFile);
29
+ if (packageJSON.name === packageName) return {
30
+ directory,
31
+ packageJSON
32
+ };
33
+ } catch {}
34
+ const parentDirectory = dirname(directory);
35
+ if (parentDirectory === directory) return;
36
+ directory = parentDirectory;
37
+ }
38
+ }
39
+ /**
40
+ * Package file identity survives checkout, installation and publication paths:
41
+ * the nearest named package plus the package-relative path. Keyframe IDs hash
42
+ * this owner into delivered CSS, so absolute paths remain only without a name.
43
+ */
44
+ function stylesheetResourceOwner(file) {
45
+ if (!isAbsolute(file)) return file;
46
+ try {
47
+ file = realpathSync(file);
48
+ } catch {}
49
+ let directory = dirname(file);
50
+ while (true) {
51
+ const manifest = resolve(directory, "package.json");
52
+ if (existsSync(manifest)) try {
53
+ const { name } = readJSONFile(manifest);
54
+ if (typeof name === "string" && name) return `${name}/${relative(directory, file).replace(/\\/g, "/")}`;
55
+ } catch {}
56
+ const parent = dirname(directory);
57
+ if (parent === directory) return file;
58
+ directory = parent;
59
+ }
60
+ }
61
+ function resolvePackageDirectory(directory) {
62
+ try {
63
+ return realpathSync(directory);
64
+ } catch {
65
+ return directory;
66
+ }
67
+ }
68
+ function findNodeModulesPackageRoot(baseDirectory, packageName) {
69
+ let directory = resolve(baseDirectory);
70
+ const packagePath = packageName.split("/");
71
+ while (true) {
72
+ const packageJSONFile = resolve(directory, "node_modules", ...packagePath, "package.json");
73
+ if (existsSync(packageJSONFile)) try {
74
+ const packageJSON = readJSONFile(packageJSONFile);
75
+ if (packageJSON.name === packageName) return {
76
+ directory: resolvePackageDirectory(dirname(packageJSONFile)),
77
+ packageJSON
78
+ };
79
+ } catch {}
80
+ const parentDirectory = dirname(directory);
81
+ if (parentDirectory === directory) return;
82
+ directory = parentDirectory;
83
+ }
84
+ }
85
+ function resolvePackageRoot(packageName, fromFile, projectDir) {
86
+ const resolvedFromFile = resolve(projectDir || "", fromFile);
87
+ const searchDirectories = [
88
+ projectDir,
89
+ resolvedFromFile,
90
+ dirname(resolvedFromFile),
91
+ process.cwd()
92
+ ].filter((directory) => typeof directory === "string");
93
+ for (const directory of new Set(searchDirectories)) {
94
+ const packageRoot = findNodeModulesPackageRoot(directory, packageName);
95
+ if (packageRoot) return packageRoot;
96
+ }
97
+ const resolver = createProjectRequire(fromFile, projectDir);
98
+ let packageEntryFile;
99
+ try {
100
+ packageEntryFile = resolver.resolve(packageName);
101
+ } catch {
102
+ packageEntryFile = require.resolve(
103
+ /* webpackIgnore: true */
104
+ packageName
105
+ );
106
+ }
107
+ return findPackageRoot(packageEntryFile, packageName);
108
+ }
109
+ function getPackageStyleEntry(packageJSON) {
110
+ if (typeof packageJSON.style === "string") return packageJSON.style;
111
+ if (!packageJSON.exports || typeof packageJSON.exports !== "object") return;
112
+ const rootExport = packageJSON.exports["."];
113
+ if (!rootExport || typeof rootExport !== "object") return;
114
+ const styleExport = rootExport.style;
115
+ return typeof styleExport === "string" ? styleExport : void 0;
116
+ }
117
+ function createProjectRequire(fromFile, projectDir) {
118
+ return createRequire(resolve(projectDir || dirname(fromFile), "package.json"));
119
+ }
120
+ function resolveMasterCSSPackageEntryFile(importSource, fromFile = process.cwd(), projectDir) {
121
+ if (!MASTER_CSS_PACKAGE_IDS.has(importSource)) return;
122
+ const packageRoot = resolvePackageRoot(importSource, fromFile, projectDir);
123
+ if (!packageRoot) return;
124
+ const styleEntry = getPackageStyleEntry(packageRoot.packageJSON);
125
+ if (!styleEntry) return;
126
+ const styleFile = resolve(packageRoot.directory, styleEntry);
127
+ if (!existsSync(styleFile)) throw new Error(`${importSource} CSS style entry was not found: ${styleFile}`);
128
+ return styleFile;
129
+ }
130
+ function resolveNodePackageCSS(importSource, fromFile) {
131
+ if (importSource.startsWith(".") || importSource.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(importSource)) return;
132
+ try {
133
+ const file = createRequire(fromFile).resolve(importSource);
134
+ if (extname(file).toLowerCase() === ".css") return file;
135
+ } catch {}
136
+ }
137
+ /** A bare alias is not package ownership; verify the resolved file's package root. */
138
+ function isResolvedPackageCSS(specifier, importer, file, projectDir) {
139
+ if (specifier.startsWith(".") || specifier.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(specifier)) return false;
140
+ const packageName = specifier.split("/").slice(0, specifier.startsWith("@") ? 2 : 1).join("/");
141
+ try {
142
+ const root = resolvePackageRoot(packageName, importer, projectDir);
143
+ if (!root) return false;
144
+ const path = relative(resolvePackageDirectory(root.directory), resolvePackageDirectory(file));
145
+ return path !== ".." && !path.startsWith("../") && !path.startsWith("..\\") && !isAbsolute(path);
146
+ } catch {
147
+ return false;
148
+ }
149
+ }
150
+ function resolvePreparedImport(importSource, file, options) {
151
+ const packageFile = options.expandPackageImports !== false ? resolveMasterCSSPackageEntryFile(importSource, file, options.projectDir) : void 0;
152
+ const nodePackageFile = !packageFile && options.resolveNodePackageImports ? resolveNodePackageCSS(importSource, file) : void 0;
153
+ if (packageFile || nodePackageFile || isExpandableImportSource(importSource, file)) return {
154
+ file: packageFile || nodePackageFile || resolveRelativeCSSFile(importSource, file),
155
+ packageCSS: Boolean(nodePackageFile)
156
+ };
157
+ }
158
+ function prepareCSSImportGraphFile(file, graph, visited, options, sourceOverride, analyzeDependencies, packageCSS = false) {
159
+ const absoluteFile = resolve(file);
160
+ options.onDependency?.(absoluteFile);
161
+ if (packageCSS && !graph.packageFiles?.includes(absoluteFile)) (graph.packageFiles ??= []).push(absoluteFile);
162
+ if (sourceOverride === void 0 && !existsSync(absoluteFile)) throw new Error(`CSS file not found: ${absoluteFile}`);
163
+ if (visited.has(absoluteFile)) return;
164
+ visited.add(absoluteFile);
165
+ const source = sourceOverride ?? readFileSync(absoluteFile, "utf-8");
166
+ graph.files[absoluteFile] = source;
167
+ (graph.resourceOwners ??= {})[absoluteFile] = stylesheetResourceOwner(absoluteFile);
168
+ const analysis = analyzeDependencies(source);
169
+ for (const importStatement of analysis.imports) {
170
+ const importSource = importStatement.source;
171
+ const imported = resolvePreparedImport(importSource, absoluteFile, options);
172
+ if (imported) {
173
+ const importedFile = imported.file;
174
+ graph.edges.push({
175
+ from: absoluteFile,
176
+ specifier: importSource,
177
+ resolved: importedFile
178
+ });
179
+ prepareCSSImportGraphFile(importedFile, graph, visited, options, void 0, analyzeDependencies, packageCSS || imported.packageCSS);
180
+ }
181
+ }
182
+ }
183
+ function prepareCSSImportGraph(file, source, options, analyzeDependencies) {
184
+ const graph = {
185
+ entry: resolve(file),
186
+ files: {},
187
+ edges: []
188
+ };
189
+ prepareCSSImportGraphFile(graph.entry, graph, /* @__PURE__ */ new Set(), options, source, analyzeDependencies);
190
+ return graph;
191
+ }
192
+ /** Async build-host file resolution, sharing Node fallback and Rust dependency analysis. */
193
+ async function prepareCSSImportGraphWithResolver(file, source, options, analyzeDependencies, resolveImport) {
194
+ const graph = {
195
+ entry: normalizeStylesheetGraphID(file),
196
+ files: {},
197
+ edges: []
198
+ };
199
+ if (options.sourceMap) graph.sourceMaps = { [graph.entry]: options.sourceMap };
200
+ if (options.baseFile) {
201
+ if (!isAbsolute(options.baseFile)) throw new TypeError("A stylesheet source baseFile must be an absolute filesystem path.");
202
+ graph.baseFiles = { [graph.entry]: options.baseFile };
203
+ }
204
+ const pending = [{
205
+ file: graph.entry,
206
+ source,
207
+ packageCSS: false
208
+ }];
209
+ const visited = /* @__PURE__ */ new Set();
210
+ while (pending.length) {
211
+ options.signal?.throwIfAborted();
212
+ const item = pending.pop();
213
+ options.onDependency?.(item.file);
214
+ if (item.packageCSS && !graph.packageFiles?.includes(item.file)) (graph.packageFiles ??= []).push(item.file);
215
+ if (visited.has(item.file)) continue;
216
+ visited.add(item.file);
217
+ const text = item.source ?? readFileSync(item.file, "utf8");
218
+ graph.files[item.file] = text;
219
+ (graph.resourceOwners ??= {})[item.file] = stylesheetResourceOwner(graph.baseFiles?.[item.file] ?? item.file);
220
+ const children = [];
221
+ for (const { source: specifier } of analyzeDependencies(text).imports) {
222
+ const resolved = await resolveImport(specifier, item.file);
223
+ options.signal?.throwIfAborted();
224
+ if (resolved === null) continue;
225
+ const supplied = typeof resolved === "object" ? resolved : void 0;
226
+ const id = supplied?.id ?? resolved;
227
+ if (typeof id === "string" && !isAbsolute(id) && !(supplied && id.startsWith("\0"))) throw new TypeError("A stylesheet import resolver must return an absolute filesystem path or a source with a virtual ID.");
228
+ if (supplied?.baseFile && !isAbsolute(supplied.baseFile)) throw new TypeError("A stylesheet source baseFile must be an absolute filesystem path.");
229
+ const importer = graph.baseFiles?.[item.file] ?? item.file;
230
+ const owner = supplied?.baseFile ?? id;
231
+ const imported = resolved === void 0 ? resolvePreparedImport(specifier, importer, options) : {
232
+ file: normalizeStylesheetGraphID(id),
233
+ packageCSS: isAbsolute(owner) && isResolvedPackageCSS(specifier, importer, owner, options.projectDir)
234
+ };
235
+ if (!imported) continue;
236
+ if (supplied?.baseFile) (graph.baseFiles ??= {})[imported.file] = supplied.baseFile;
237
+ if (supplied?.sourceMap) (graph.sourceMaps ??= {})[imported.file] = supplied.sourceMap;
238
+ graph.edges.push({
239
+ from: item.file,
240
+ specifier,
241
+ resolved: imported.file
242
+ });
243
+ children.push({
244
+ file: imported.file,
245
+ source: supplied?.source,
246
+ packageCSS: item.packageCSS || imported.packageCSS
247
+ });
248
+ }
249
+ pending.push(...children.reverse());
250
+ }
251
+ return graph;
252
+ }
253
+ export { isExpandableImportSource, normalizeStylesheetGraphID, prepareCSSImportGraph, prepareCSSImportGraphWithResolver, resolveMasterCSSPackageEntryFile, resolveNodePackageCSS, resolveRelativeCSSFile, stylesheetResourceOwner };
package/dist/node.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { MasterCSSCompileManifestOptions, MasterCSSCompileManifestOptions as MasterCSSCompileManifestOptions$1, MasterCSSCompileManifestResult, MasterCSSCompileManifestResult as MasterCSSCompileManifestResult$1, MasterCSSCompileOptions, MasterCSSCompileResult, MasterCSSCompileStylesheetsRequest, MasterCSSCompileStylesheetsResult, MasterCSSCompileStylesheetsResult as MasterCSSCompileStylesheetsResult$1, MasterCSSCompilerInspection, MasterCSSPrepareStylesheetBundleRequest, MasterCSSRenderStylesheetBundleRequest, MasterCSSStylesheetAsset, MasterCSSStylesheetBundle } from "./index.js";
2
+ import { MasterCSSCompiler } from "./compiler.js";
3
+ import { StylesheetDeliveryOptions, StylesheetResourceAsset } from "./stylesheet/delivery.js";
4
+ import { MasterCSSStylesheetDependencies, MasterCSSStylesheetDependencyOptions, MasterCSSStylesheetHostOptions, MasterCSSStylesheetResolution, MasterCSSStylesheetResolutionOptions, collectStylesheetDependenciesSync, composeStylesheetHostSync, resolveStylesheetDependenciesSync, resolveStylesheetSync } from "./stylesheet/public.js";
5
+ interface MasterCSSCompileManifestFileOptions extends MasterCSSCompileManifestOptions$1 {
6
+ readonly root?: string;
7
+ }
8
+ interface MasterCSSCompileManifestFileDeliveryOptions extends MasterCSSCompileManifestFileOptions {
9
+ readonly delivery: StylesheetDeliveryOptions;
10
+ }
11
+ interface MasterCSSCompileManifestFileResult extends MasterCSSCompileStylesheetsResult$1 {
12
+ /** Copy these files to their hrefs before publishing the entry stylesheet. */
13
+ readonly resources: readonly Readonly<StylesheetResourceAsset>[];
14
+ }
15
+ declare function createCompilerSync(): MasterCSSCompiler;
16
+ declare function inspectCSSSync(source: string): import("./index.js").MasterCSSCompilerInspection;
17
+ declare function compileCSSSync(source: string, options?: import('./index.js').MasterCSSCompileOptions): import("./index.js").MasterCSSCompileResult;
18
+ declare function compileManifestSync(source: string, options: import('./index.js').MasterCSSCompileManifestOptions): MasterCSSCompileManifestResult$1;
19
+ declare function compileManifestFileSync(file: string, options: MasterCSSCompileManifestFileDeliveryOptions): MasterCSSCompileManifestFileResult;
20
+ declare function compileManifestFileSync(file: string, options: MasterCSSCompileManifestFileOptions): MasterCSSCompileManifestResult$1;
21
+ export { MasterCSSCompileManifestFileDeliveryOptions, MasterCSSCompileManifestFileOptions, MasterCSSCompileManifestFileResult, type MasterCSSCompileManifestOptions, type MasterCSSCompileManifestResult, type MasterCSSCompileOptions, type MasterCSSCompileResult, type MasterCSSCompileStylesheetsRequest, type MasterCSSCompileStylesheetsResult, type MasterCSSCompilerInspection, type MasterCSSPrepareStylesheetBundleRequest, type MasterCSSRenderStylesheetBundleRequest, type MasterCSSStylesheetAsset, type MasterCSSStylesheetBundle, type MasterCSSStylesheetDependencies, type MasterCSSStylesheetDependencyOptions, type MasterCSSStylesheetHostOptions, type MasterCSSStylesheetResolution, type MasterCSSStylesheetResolutionOptions, collectStylesheetDependenciesSync, compileCSSSync, compileManifestFileSync, compileManifestSync, composeStylesheetHostSync, createCompilerSync, inspectCSSSync, resolveStylesheetDependenciesSync, resolveStylesheetSync };
package/dist/node.js ADDED
@@ -0,0 +1,47 @@
1
+ import { stylesheetValidationSource } from "./stylesheet/output-map.js";
2
+ import { assertValidationOptions, validateCompiledCSS } from "./value-validation.js";
3
+ import { bindCompilerSessionInternal, toMasterCSSCompileManifestResultInternal } from "./compiler.js";
4
+ import { compileCSSManifestFile } from "./node-compiler.js";
5
+ import { compileDeliveredFile } from "./stylesheet/delivery.js";
6
+ import { bindCompilerBindingSessionInternal } from "./session.js";
7
+ import { collectStylesheetDependenciesSync, composeStylesheetHostSync, resolveStylesheetDependenciesSync, resolveStylesheetSync } from "./stylesheet/public.js";
8
+ import { createCompilerBindingSessionSync } from "@master/css-binding/compiler/node";
9
+ // src/node.ts
10
+ function createCompilerSync() {
11
+ return bindCompilerSessionInternal(bindCompilerBindingSessionInternal(createCompilerBindingSessionSync()));
12
+ }
13
+ function inspectCSSSync(source) {
14
+ using compiler = createCompilerSync();
15
+ return compiler.inspectCSS(source);
16
+ }
17
+ function compileCSSSync(source, options = {}) {
18
+ using compiler = createCompilerSync();
19
+ return compiler.compileCSS(source, options);
20
+ }
21
+ function compileManifestSync(source, options) {
22
+ using compiler = createCompilerSync();
23
+ return compiler.compileManifest(source, options);
24
+ }
25
+ function compileManifestFileSync(file, options) {
26
+ assertValidationOptions(options);
27
+ if ("delivery" in options) {
28
+ const result = compileDeliveredFile(file, {
29
+ ...options,
30
+ projectDir: options.root,
31
+ preserveNativeCSS: options.preserveNativeCSS ?? true
32
+ });
33
+ return Object.freeze({
34
+ ...toMasterCSSCompileManifestResultInternal({
35
+ ...result.directives,
36
+ manifest: result.manifest,
37
+ directives: result.directives
38
+ }, options.onDiagnostic, options.validation),
39
+ diagnostics: validateCompiledCSS(result.stylesheets.map((asset) => stylesheetValidationSource(asset.css, asset.id, void 0, asset.outputMappings)), options),
40
+ entry: result.entry,
41
+ stylesheets: Object.freeze(result.stylesheets.map((asset) => Object.freeze({ ...asset }))),
42
+ resources: Object.freeze(result.resources.map((asset) => Object.freeze({ ...asset })))
43
+ });
44
+ }
45
+ return toMasterCSSCompileManifestResultInternal(compileCSSManifestFile(file, options), options.onDiagnostic, options.validation);
46
+ }
47
+ export { collectStylesheetDependenciesSync, compileCSSSync, compileManifestFileSync, compileManifestSync, composeStylesheetHostSync, createCompilerSync, inspectCSSSync, resolveStylesheetDependenciesSync, resolveStylesheetSync };
@@ -0,0 +1,5 @@
1
+ import { MasterCSSDiagnostic } from "@master/css-schema";
2
+ import { CSSDirectiveNotice } from "@master/css-schema/css-directives";
3
+ /** Adapt Rust source locations to the public, zero-based diagnostic envelope. */
4
+ declare function noticeDiagnostics(notices: readonly CSSDirectiveNotice[] | undefined, onDiagnostic?: (diagnostic: MasterCSSDiagnostic) => void): MasterCSSDiagnostic[];
5
+ export { noticeDiagnostics };
@@ -0,0 +1,29 @@
1
+ import { MASTER_CSS_DIAGNOSTIC_VERSION } from "@master/css-schema";
2
+ // src/notices.ts
3
+ /** Adapt Rust source locations to the public, zero-based diagnostic envelope. */
4
+ function noticeDiagnostics(notices, onDiagnostic) {
5
+ return (notices || []).map(({ code, message, source }) => {
6
+ const diagnostic = Object.freeze({
7
+ version: MASTER_CSS_DIAGNOSTIC_VERSION,
8
+ code,
9
+ message,
10
+ domain: "compiler",
11
+ phase: "compiler",
12
+ severity: "information",
13
+ ...source?.file ? { source: source.file } : {},
14
+ ...source?.loc ? { range: {
15
+ start: {
16
+ line: source.loc.start.line - 1,
17
+ character: source.loc.start.column - 1
18
+ },
19
+ end: {
20
+ line: source.loc.end.line - 1,
21
+ character: source.loc.end.column - 1
22
+ }
23
+ } } : {}
24
+ });
25
+ onDiagnostic?.(diagnostic);
26
+ return diagnostic;
27
+ });
28
+ }
29
+ export { noticeDiagnostics };
@@ -0,0 +1,5 @@
1
+ import { MasterCSSCompilerBindingSession } from "@master/css-binding/compiler";
2
+ type CompileGraph = MasterCSSCompilerBindingSession['compileCSSStylesheetGraph'];
3
+ /** Cache only the pure binding request, after resolving and observing all inputs. */
4
+ declare function compilePreparedGraph(binding: Pick<MasterCSSCompilerBindingSession, 'compileCSSStylesheetGraph'>, request: Parameters<CompileGraph>[0]): ReturnType<CompileGraph>;
5
+ export { compilePreparedGraph };
@@ -0,0 +1,31 @@
1
+ import { createHash } from "node:crypto";
2
+ // src/prepared-graph-cache.ts
3
+ const results = /* @__PURE__ */ new Map();
4
+ const budget = 16777216;
5
+ let bytes = 0;
6
+ /** Cache only the pure binding request, after resolving and observing all inputs. */
7
+ function compilePreparedGraph(binding, request) {
8
+ const key = createHash("sha256").update(JSON.stringify(request)).digest("hex");
9
+ const cached = results.get(key);
10
+ if (cached) {
11
+ results.delete(key);
12
+ results.set(key, cached);
13
+ return structuredClone(cached.result);
14
+ }
15
+ const result = binding.compileCSSStylesheetGraph(request);
16
+ const size = JSON.stringify(result).length * 2;
17
+ if (size <= budget) {
18
+ while (bytes + size > budget || results.size >= 64) {
19
+ const oldest = results.keys().next().value;
20
+ bytes -= results.get(oldest).bytes;
21
+ results.delete(oldest);
22
+ }
23
+ results.set(key, {
24
+ result: structuredClone(result),
25
+ bytes: size
26
+ });
27
+ bytes += size;
28
+ }
29
+ return result;
30
+ }
31
+ export { compilePreparedGraph };
@@ -0,0 +1,29 @@
1
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
2
+ import { CSSDirectiveExtractionPolicy } from "@master/css-schema/css-directives";
3
+ import { MasterCSSProjectSourceGraph } from "./options.js";
4
+ interface BindingProjectSourceEntryPlan {
5
+ entry: string;
6
+ include: string[];
7
+ exclude: string[];
8
+ files: string[];
9
+ }
10
+ interface BindingProjectManifestResult {
11
+ sourceGraph?: MasterCSSProjectSourceGraph;
12
+ entries: string[];
13
+ manifest: MasterCSSManifest;
14
+ dependencies: string[];
15
+ extractionPolicy: CSSDirectiveExtractionPolicy;
16
+ classNames: string[];
17
+ nativeClassNames: string[];
18
+ nativeCSS: string;
19
+ css: string;
20
+ generatedCSS: string;
21
+ warnings: string[];
22
+ sourcePlan: {
23
+ version: 1;
24
+ entries: BindingProjectSourceEntryPlan[];
25
+ files: string[];
26
+ };
27
+ }
28
+ declare function loadBindingProjectManifest(projectDir: string, baseManifest: MasterCSSManifest, entries?: readonly string[], onDependency?: (file: string) => void, includeSourceGraph?: boolean): BindingProjectManifestResult;
29
+ export { loadBindingProjectManifest };
@@ -0,0 +1,100 @@
1
+ import { prepareCSSImportGraph } from "../node-imports.js";
2
+ import { analyzeCSSDependencies, compileCSS, resolveCSSReferenceFile, stripWindowsExtendedPathPrefix } from "../node-compiler.js";
3
+ import { isAbsolute, join, relative, resolve, sep } from "node:path";
4
+ import { realpathSync } from "node:fs";
5
+ import { createCompilerBindingSessionSync } from "@master/css-binding/compiler/node";
6
+ // src/project/binding-project.ts
7
+ function prepareManifestGraph(entry, projectDir, onDependency) {
8
+ const graph = prepareCSSImportGraph(entry, void 0, {
9
+ projectDir,
10
+ onDependency
11
+ }, analyzeCSSDependencies);
12
+ const pending = Object.keys(graph.files);
13
+ const visited = /* @__PURE__ */ new Set();
14
+ while (pending.length) {
15
+ const file = pending.shift();
16
+ if (visited.has(file)) continue;
17
+ visited.add(file);
18
+ for (const reference of compileCSS(graph.files[file], { from: file }).references || []) {
19
+ const target = resolveCSSReferenceFile(reference, { root: projectDir });
20
+ const referenced = prepareCSSImportGraph(target, void 0, {
21
+ projectDir,
22
+ onDependency
23
+ }, analyzeCSSDependencies);
24
+ graph.edges.push({
25
+ from: file,
26
+ specifier: reference.source,
27
+ resolved: referenced.entry
28
+ }, ...referenced.edges);
29
+ Object.assign(graph.files, referenced.files);
30
+ Object.assign(graph.resourceOwners ??= {}, referenced.resourceOwners);
31
+ pending.push(...Object.keys(referenced.files).filter((id) => !visited.has(id)));
32
+ }
33
+ }
34
+ return graph;
35
+ }
36
+ function isProjectPath(root, file) {
37
+ const local = relative(root, file);
38
+ return local !== ".." && !local.startsWith(`..${sep}`) && !isAbsolute(local) && !local.split(sep).includes("node_modules");
39
+ }
40
+ function loadBindingProjectManifest(projectDir, baseManifest, entries, onDependency, includeSourceGraph = false) {
41
+ const compiler = createCompilerBindingSessionSync();
42
+ const root = resolve(projectDir);
43
+ let realRoot = root;
44
+ try {
45
+ realRoot = resolve(stripWindowsExtendedPathPrefix(realpathSync.native(root)));
46
+ } catch {}
47
+ const preservePath = (file) => {
48
+ const absoluteFile = resolve(stripWindowsExtendedPathPrefix(file));
49
+ return realRoot !== root && (absoluteFile === realRoot || absoluteFile.startsWith(`${realRoot}${sep}`)) ? join(root, relative(realRoot, absoluteFile)) : absoluteFile;
50
+ };
51
+ const resolvedEntries = (entries ?? compiler.findManifestEntries(projectDir)).map(preservePath);
52
+ const observed = /* @__PURE__ */ new Set();
53
+ const dependency = onDependency ? (file) => {
54
+ const path = preservePath(file);
55
+ if (observed.has(path)) return;
56
+ observed.add(path);
57
+ onDependency(path);
58
+ } : void 0;
59
+ const graphs = resolvedEntries.map((entry) => ({
60
+ entry,
61
+ source: "",
62
+ dependencies: [],
63
+ manifestGraph: prepareManifestGraph(entry, projectDir, dependency)
64
+ }));
65
+ const result = compiler.loadPreparedProjectManifest(projectDir, baseManifest, graphs);
66
+ if (includeSourceGraph) {
67
+ const files = /* @__PURE__ */ new Map();
68
+ const edges = /* @__PURE__ */ new Map();
69
+ for (const { manifestGraph } of graphs) {
70
+ for (const [source, content] of Object.entries(manifestGraph.files)) files.set(preservePath(source), content);
71
+ for (const edge of manifestGraph.edges) {
72
+ const value = {
73
+ from: preservePath(edge.from),
74
+ specifier: edge.specifier,
75
+ resolved: preservePath(edge.resolved)
76
+ };
77
+ edges.set(JSON.stringify(value), value);
78
+ }
79
+ }
80
+ result.sourceGraph = Object.freeze({
81
+ version: 1,
82
+ files: Object.freeze([...files].map(([source, content]) => Object.freeze({
83
+ source,
84
+ content,
85
+ projectOwned: isProjectPath(root, source) && isProjectPath(realRoot, stripWindowsExtendedPathPrefix(realpathSync.native(source)))
86
+ }))),
87
+ edges: Object.freeze([...edges.values()].map((edge) => Object.freeze(edge)))
88
+ });
89
+ }
90
+ result.entries = result.entries.map(preservePath);
91
+ result.dependencies = result.dependencies.map(preservePath);
92
+ result.sourcePlan.files = result.sourcePlan.files.map(preservePath);
93
+ result.sourcePlan.entries = result.sourcePlan.entries.map((entry) => ({
94
+ ...entry,
95
+ entry: preservePath(entry.entry),
96
+ files: entry.files.map(preservePath)
97
+ }));
98
+ return result;
99
+ }
100
+ export { loadBindingProjectManifest };
@@ -0,0 +1,7 @@
1
+ import { resolveMasterCSSPackageEntryFile } from "../node-compiler.js";
2
+ declare function cleanCSSManifestRequest(id: string): string;
3
+ declare function isCSSManifestRequest(id: string): boolean;
4
+ declare function hasMasterCSSManifestEntrypoint(source: string): boolean;
5
+ declare function findCSSManifestEntryFiles(projectDir?: string): Promise<string[]>;
6
+ declare function findCSSManifestEntryFilesSync(projectDir?: string): string[];
7
+ export { cleanCSSManifestRequest, findCSSManifestEntryFiles, findCSSManifestEntryFilesSync, hasMasterCSSManifestEntrypoint, isCSSManifestRequest, resolveMasterCSSPackageEntryFile };
@@ -0,0 +1,30 @@
1
+ import { resolveMasterCSSPackageEntryFile } from "../node-imports.js";
2
+ import { inspectCSS, stripRequestSuffix, stripWindowsExtendedPathPrefix } from "../node-compiler.js";
3
+ import { extname, join, relative, resolve, sep } from "node:path";
4
+ import { realpathSync } from "node:fs";
5
+ import { createCompilerBindingSessionSync } from "@master/css-binding/compiler/node";
6
+ // src/project/entries.ts
7
+ function cleanCSSManifestRequest(id) {
8
+ return stripRequestSuffix(id);
9
+ }
10
+ function isCSSManifestRequest(id) {
11
+ return extname(cleanCSSManifestRequest(id)) === ".css";
12
+ }
13
+ function hasMasterCSSManifestEntrypoint(source) {
14
+ return inspectCSS(source).hasMasterEntry;
15
+ }
16
+ async function findCSSManifestEntryFiles(projectDir = process.cwd()) {
17
+ return findCSSManifestEntryFilesSync(projectDir);
18
+ }
19
+ function findCSSManifestEntryFilesSync(projectDir = process.cwd()) {
20
+ const root = resolve(projectDir);
21
+ let realRoot = root;
22
+ try {
23
+ realRoot = resolve(stripWindowsExtendedPathPrefix(realpathSync.native(root)));
24
+ } catch {}
25
+ return createCompilerBindingSessionSync().findManifestEntries(root).map((entry) => {
26
+ const absoluteEntry = resolve(stripWindowsExtendedPathPrefix(entry));
27
+ return realRoot !== root && (absoluteEntry === realRoot || absoluteEntry.startsWith(`${realRoot}${sep}`)) ? join(root, relative(realRoot, absoluteEntry)) : absoluteEntry;
28
+ });
29
+ }
30
+ export { cleanCSSManifestRequest, findCSSManifestEntryFiles, findCSSManifestEntryFilesSync, hasMasterCSSManifestEntrypoint, isCSSManifestRequest, resolveMasterCSSPackageEntryFile };
@@ -0,0 +1,5 @@
1
+ import { MasterCSSProjectCompileOptions, MasterCSSProjectCompileOptions as MasterCSSProjectCompileOptions$1, MasterCSSProjectDiscoveryOptions, MasterCSSProjectDiscoveryOptions as MasterCSSProjectDiscoveryOptions$1, MasterCSSProjectLoadOptions, MasterCSSProjectLoadOptions as MasterCSSProjectLoadOptions$1, MasterCSSProjectResult, MasterCSSProjectResult as MasterCSSProjectResult$1, MasterCSSProjectSourceGraph } from "./options.js";
2
+ declare function discoverManifestEntriesSync(options?: Omit<MasterCSSProjectDiscoveryOptions$1, 'signal'>): readonly string[];
3
+ declare function loadProjectManifestSync(options: Omit<MasterCSSProjectLoadOptions$1, 'signal'>): MasterCSSProjectResult$1;
4
+ declare function compileProjectManifestSync(options: Omit<MasterCSSProjectCompileOptions$1, 'signal'>): MasterCSSProjectResult$1;
5
+ export { type MasterCSSProjectCompileOptions, type MasterCSSProjectDiscoveryOptions, type MasterCSSProjectLoadOptions, type MasterCSSProjectResult, type MasterCSSProjectSourceGraph, compileProjectManifestSync, discoverManifestEntriesSync, loadProjectManifestSync };
@@ -0,0 +1,40 @@
1
+ import { findCSSManifestEntryFilesSync, isCSSManifestRequest } from "./entries.js";
2
+ import { loadBindingProjectManifest } from "./binding-project.js";
3
+ import { resolve } from "node:path";
4
+ import { MASTER_CSS_DIAGNOSTIC_VERSION } from "@master/css-schema";
5
+ // src/project/manifest-sync.ts
6
+ function warningDiagnostic(message) {
7
+ return Object.freeze({
8
+ version: MASTER_CSS_DIAGNOSTIC_VERSION,
9
+ code: "PROJECT_WARNING",
10
+ domain: "project",
11
+ severity: "warning",
12
+ message
13
+ });
14
+ }
15
+ function assertStylesheetEntries(entries) {
16
+ for (const entry of entries ?? []) if (!isCSSManifestRequest(entry)) throw new TypeError("Master CSS project entries must be CSS files.");
17
+ }
18
+ function immutableProjectResult(result, onDiagnostic) {
19
+ const diagnostics = Object.freeze(result.warnings.map(warningDiagnostic));
20
+ for (const diagnostic of diagnostics) onDiagnostic?.(diagnostic);
21
+ return Object.freeze({
22
+ manifest: Object.freeze(result.manifest),
23
+ nativeClassNames: Object.freeze([...result.nativeClassNames]),
24
+ entries: Object.freeze([...result.entries]),
25
+ dependencies: Object.freeze([...result.dependencies]),
26
+ diagnostics,
27
+ ...result.sourceGraph ? { sourceGraph: result.sourceGraph } : {}
28
+ });
29
+ }
30
+ function discoverManifestEntriesSync(options = {}) {
31
+ return Object.freeze(findCSSManifestEntryFilesSync(resolve(options.root ?? process.cwd())));
32
+ }
33
+ function loadProjectManifestSync(options) {
34
+ assertStylesheetEntries(options.entries);
35
+ return immutableProjectResult(loadBindingProjectManifest(resolve(options.root ?? process.cwd()), options.baseManifest, options.entries, options.onDependency, options.includeSourceGraph), options.onDiagnostic);
36
+ }
37
+ function compileProjectManifestSync(options) {
38
+ return loadProjectManifestSync(options);
39
+ }
40
+ export { compileProjectManifestSync, discoverManifestEntriesSync, loadProjectManifestSync };
@@ -0,0 +1,5 @@
1
+ import { MasterCSSProjectCompileOptions, MasterCSSProjectCompileOptions as MasterCSSProjectCompileOptions$1, MasterCSSProjectDiscoveryOptions, MasterCSSProjectDiscoveryOptions as MasterCSSProjectDiscoveryOptions$1, MasterCSSProjectLoadOptions, MasterCSSProjectLoadOptions as MasterCSSProjectLoadOptions$1, MasterCSSProjectResult, MasterCSSProjectResult as MasterCSSProjectResult$1, MasterCSSProjectSourceGraph } from "./options.js";
2
+ declare function discoverManifestEntries(options?: MasterCSSProjectDiscoveryOptions$1): Promise<readonly string[]>;
3
+ declare function loadProjectManifest(options: MasterCSSProjectLoadOptions$1): Promise<MasterCSSProjectResult$1>;
4
+ declare function compileProjectManifest(options: MasterCSSProjectCompileOptions$1): Promise<MasterCSSProjectResult$1>;
5
+ export { type MasterCSSProjectCompileOptions, type MasterCSSProjectDiscoveryOptions, type MasterCSSProjectLoadOptions, type MasterCSSProjectResult, type MasterCSSProjectSourceGraph, compileProjectManifest, discoverManifestEntries, loadProjectManifest };