@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,367 @@
1
+ import { stylesheetOutputMap } from "./output-map.js";
2
+ import { normalizeStylesheetGraphID, prepareCSSImportGraph, prepareCSSImportGraphWithResolver } from "../node-imports.js";
3
+ import { compilePreparedGraph } from "../prepared-graph-cache.js";
4
+ import { analyzeCSSDependencies, compileCSS, inspectCSS, mergeCSSDirectiveExtractionPolicy, resolveCSSReferenceFile } from "../node-compiler.js";
5
+ import { collectStylesheetDirectives, hasLocalStyleDirectives, hasStylesheetSourceDirectives, mergeStylesheetDirectives, mergeStylesheetSourceOptions, resolveStylesheetSourcePaths } from "./directives.js";
6
+ import { hasStylesheetResourceReferences, renderCompiledManifestCSS } from "./render.js";
7
+ import { resolveReferenceOrigins } from "./reference-origins.js";
8
+ import { referenceFileInputs } from "./reference-files.js";
9
+ import { fileURLToPath, pathToFileURL } from "node:url";
10
+ import { isAbsolute, resolve } from "node:path";
11
+ import { MasterCSSError } from "@master/css-schema";
12
+ import { existsSync, readFileSync, realpathSync } from "node:fs";
13
+ import { createCompilerBindingSessionSync } from "@master/css-binding/compiler/node";
14
+ // src/stylesheet/delivery.ts
15
+ /** @internal Filesystem preparation and standalone stylesheet asset composition. */
16
+ function prepareDelivery(graph, delivery, owners, metadataOnly = false) {
17
+ const urls = {};
18
+ const resourceURLs = {};
19
+ const resources = /* @__PURE__ */ new Map();
20
+ for (const [file, source] of Object.entries(graph.files)) {
21
+ const owner = owners[file] ?? file;
22
+ if (!owner.startsWith("\0")) delivery.onDependency?.(owner);
23
+ urls[file] = delivery.stylesheetURL(owner, owners[file] ? file : void 0);
24
+ resourceURLs[file] = {};
25
+ for (const { url } of analyzeCSSDependencies(source).resources) {
26
+ if (url.startsWith("/") || /^[a-z][a-z\d+.-]*:/i.test(url)) continue;
27
+ const baseFile = graph.baseFiles?.[file] ?? (isAbsolute(owner) ? owner : void 0);
28
+ if (!baseFile) throw new TypeError(`Relative resource URL requires a source baseFile: ${owner}`);
29
+ const original = new URL(url, pathToFileURL(baseFile));
30
+ const resourceFile = fileURLToPath(original);
31
+ if (!metadataOnly) {
32
+ delivery.onDependency?.(resourceFile);
33
+ readFileSync(resourceFile);
34
+ }
35
+ const href = delivery.resourceURL(resourceFile);
36
+ if (!metadataOnly) resources.set(resourceFile, {
37
+ file: resourceFile,
38
+ href
39
+ });
40
+ resourceURLs[file][url] = `${href}${original.search}${original.hash}`;
41
+ }
42
+ }
43
+ return {
44
+ urls,
45
+ resourceURLs,
46
+ resources: [...resources.values()]
47
+ };
48
+ }
49
+ function prepareGraphReferences(graph, options, referenceStack = [], owners = {}, metadataOnly = false) {
50
+ const delivery = options.delivery;
51
+ const references = [...referenceFileInputs(options.referenceFiles), ...Object.entries(graph.files).flatMap(([file, source]) => {
52
+ const parsed = compileCSS(source, {
53
+ from: owners[file] ?? file,
54
+ preserveNativeCSS: false
55
+ });
56
+ if (file === graph.entry && options.references) return options.references;
57
+ const references = parsed.references || [];
58
+ const owner = graph.baseFiles?.[file] ?? owners[file] ?? file;
59
+ return resolveReferenceOrigins(source, references.map((reference) => ({
60
+ ...reference,
61
+ file: owner
62
+ })), owner, graph.sourceMaps?.[file]);
63
+ })];
64
+ const entryFile = graph.baseFiles?.[graph.entry] ?? owners[graph.entry] ?? graph.entry;
65
+ const stack = [...referenceStack, ...entryFile.startsWith("\0") ? [] : [existsSync(entryFile) ? realpathSync(entryFile) : resolve(entryFile)]];
66
+ const reference = {
67
+ dependencies: [],
68
+ warnings: [],
69
+ resources: []
70
+ };
71
+ for (const item of references) {
72
+ const file = resolveCSSReferenceFile(item, { root: options.projectDir });
73
+ delivery.onDependency?.(file);
74
+ const chain = [...stack, ...item.file && !item.file.startsWith("\0") ? [existsSync(item.file) ? realpathSync(item.file) : resolve(item.file)] : []];
75
+ if (chain.includes(realpathSync(file))) throw new Error(`Circular CSS reference: ${[...stack, file].join(" -> ")}`);
76
+ const compiled = compileGraph(prepareCSSImportGraph(file, void 0, {
77
+ projectDir: options.projectDir,
78
+ onDependency: delivery.onDependency,
79
+ resolveNodePackageImports: delivery.resolveNodePackageImports
80
+ }, analyzeCSSDependencies), {
81
+ ...options,
82
+ referenceFiles: void 0,
83
+ references: void 0,
84
+ baseManifest: reference.manifest ?? options.baseManifest
85
+ }, void 0, chain, {}, {}, [], metadataOnly);
86
+ reference.manifest = compiled.manifest;
87
+ reference.dependencies.push(...compiled.directives.dependencies);
88
+ reference.warnings.push(...compiled.directives.warnings);
89
+ reference.resources.push(...compiled.resources);
90
+ }
91
+ return reference;
92
+ }
93
+ function compileGraph(graph, options, classes, referenceStack = [], owners = {}, classesByStylesheet = {}, nativeStylesheets, metadataOnly = false, inlineImports = false, hostImports = {}, preparedReference) {
94
+ const delivery = options.delivery;
95
+ const prepared = prepareDelivery(graph, delivery, owners, metadataOnly);
96
+ if (new Set(Object.values(prepared.urls)).size !== Object.keys(prepared.urls).length) throw new TypeError("Each stylesheet variant requires a distinct delivery URL.");
97
+ const reference = preparedReference ?? prepareGraphReferences(graph, options, referenceStack, owners, metadataOnly);
98
+ prepared.resources.push(...reference.resources);
99
+ const binding = createCompilerBindingSessionSync();
100
+ try {
101
+ const result = compilePreparedGraph(binding, {
102
+ graph,
103
+ pruneNativeStylesheets: Object.keys(graph.files).filter((file) => {
104
+ const policy = collectStylesheetDirectives(graph.files[file], owners[file] ?? file, options.projectDir);
105
+ return !policy.preserveNative && (policy.pruneNative || options.pruneNativeCSS === true && !graph.packageFiles?.includes(file));
106
+ }),
107
+ urls: prepared.urls,
108
+ resourceURLs: inlineImports ? void 0 : prepared.resourceURLs,
109
+ inlineImports,
110
+ hostImports,
111
+ relativeResourceURLs: delivery.relativeResourceURLs,
112
+ classesByStylesheet,
113
+ nativeStylesheets,
114
+ baseManifest: options.baseManifest,
115
+ resolutionManifest: reference.manifest,
116
+ options: {
117
+ preserveNativeCSS: options.preserveNativeCSS ?? true,
118
+ ...options.preserveNativeSource === void 0 ? {} : { preserveNativeSource: options.preserveNativeSource },
119
+ ...classes ? { classes: [...classes] } : {}
120
+ }
121
+ });
122
+ const directives = result.directives;
123
+ directives.extractionPolicy = mergeCSSDirectiveExtractionPolicy(directives.extractionPolicy);
124
+ directives.dependencies = [.../* @__PURE__ */ new Set([
125
+ ...directives.dependencies.map((file) => owners[file] ?? file),
126
+ ...reference.dependencies,
127
+ ...prepared.resources.map(({ file }) => file)
128
+ ])];
129
+ directives.warnings = [.../* @__PURE__ */ new Set([...directives.warnings, ...reference.warnings])];
130
+ return {
131
+ ...result,
132
+ manifest: result.manifest,
133
+ directives,
134
+ resources: [...new Map(prepared.resources.map((asset) => [asset.file, asset])).values()]
135
+ };
136
+ } catch (error) {
137
+ if (error instanceof MasterCSSError && error.diagnostics.some((diagnostic) => diagnostic.source && owners[diagnostic.source])) throw new MasterCSSError({
138
+ ...error.payload,
139
+ diagnostics: error.diagnostics.map((diagnostic) => ({
140
+ ...diagnostic,
141
+ ...diagnostic.source ? { source: owners[diagnostic.source] ?? diagnostic.source } : {}
142
+ }))
143
+ }, { cause: error });
144
+ throw error;
145
+ } finally {
146
+ binding.dispose();
147
+ }
148
+ }
149
+ /** Compile native resource usage without flattening imports or reading host-owned assets. */
150
+ function compileStylesheetMetadata(file, source, options) {
151
+ const graph = prepareCSSImportGraph(file, source, { projectDir: options.projectDir }, analyzeCSSDependencies);
152
+ if (!Object.values(graph.files).some((text) => inspectCSS(text).hasMasterEntry)) return;
153
+ return compileGraph(graph, {
154
+ ...options,
155
+ delivery: {
156
+ entryURL: pathToFileURL(file).href,
157
+ stylesheetURL: (id) => pathToFileURL(id).href,
158
+ resourceURL: (id) => pathToFileURL(id).href
159
+ }
160
+ }, void 0, [], {}, {}, void 0, true);
161
+ }
162
+ /** Compile one file and its dependencies for a host that publishes every asset. */
163
+ function compileDeliveredFile(file, options) {
164
+ const filename = resolve(options.projectDir ?? "", file);
165
+ const delivery = options.delivery;
166
+ if (delivery.resolveImport) throw new TypeError("Custom import resolution requires asynchronous stylesheet registration.");
167
+ const graph = prepareCSSImportGraph(filename, void 0, {
168
+ projectDir: options.projectDir,
169
+ onDependency: delivery.onDependency,
170
+ resolveNodePackageImports: delivery.resolveNodePackageImports
171
+ }, analyzeCSSDependencies);
172
+ return {
173
+ ...compileGraph(graph, {
174
+ ...options,
175
+ delivery: {
176
+ ...delivery,
177
+ stylesheetURL: (id, variant) => id === filename ? delivery.entryURL : delivery.stylesheetURL(id, variant)
178
+ }
179
+ }, options.classes),
180
+ entry: graph.entry
181
+ };
182
+ }
183
+ /** Compile supplied local CSS and its imports without flattening their boundaries. */
184
+ async function compileDeliveredSource(id, source, options, nativeClasses) {
185
+ const filename = normalizeStylesheetGraphID(id), delivery = options.delivery;
186
+ const graphOptions = {
187
+ baseFile: delivery.baseFile ?? options.baseFile,
188
+ sourceMap: delivery.sourceMap ?? options.sourceMap,
189
+ projectDir: options.projectDir,
190
+ onDependency: delivery.onDependency,
191
+ resolveNodePackageImports: delivery.resolveNodePackageImports
192
+ };
193
+ const graph = delivery.resolveImport || graphOptions.baseFile || graphOptions.sourceMap ? await prepareCSSImportGraphWithResolver(filename, source, graphOptions, analyzeCSSDependencies, delivery.resolveImport ?? (() => void 0)) : prepareCSSImportGraph(filename, source, graphOptions, analyzeCSSDependencies);
194
+ const nativeGraph = (!options.transformNativeStylesheets || options.preserveUnchangedNativeCSS) && !Object.entries(graph.files).some(([file, source]) => hasLocalStyleDirectives(source, file));
195
+ let reference;
196
+ if (nativeGraph) {
197
+ if (!options.transformNativeStylesheets) return;
198
+ reference = prepareGraphReferences(graph, options);
199
+ if (!hasStylesheetResourceReferences(reference.manifest ?? options.baseManifest, graph.files[graph.entry])) return;
200
+ }
201
+ const result = compileGraph(graph, {
202
+ ...options,
203
+ delivery: {
204
+ ...delivery,
205
+ stylesheetURL: (file, variant) => file === graph.entry ? delivery.entryURL : delivery.stylesheetURL(file, variant)
206
+ }
207
+ }, nativeClasses, [], {}, {}, void 0, false, false, {}, reference);
208
+ const stylesheets = result.stylesheets.map((asset) => ({
209
+ ...asset,
210
+ sourceMap: stylesheetOutputMap(asset.css, asset.outputMappings, {
211
+ file: asset.id,
212
+ compilationFile: asset.id,
213
+ source: graph.files[asset.id],
214
+ sourceMap: graph.sourceMaps?.[asset.id],
215
+ graph: { sources: graph.files }
216
+ })
217
+ }));
218
+ return {
219
+ ...result,
220
+ stylesheets,
221
+ entry: graph.entry,
222
+ outputMap: (css, mappings, file = graph.entry) => stylesheetOutputMap(css, mappings, {
223
+ file,
224
+ compilationFile: file,
225
+ source: graph.files[file],
226
+ sourceMap: graph.sourceMaps?.[file],
227
+ graph: { sources: graph.files }
228
+ })
229
+ };
230
+ }
231
+ async function registerDeliveredStylesheet(scanner, sources, id, source, options, inlineImports = false) {
232
+ const filename = normalizeStylesheetGraphID(id);
233
+ const graphOptions = {
234
+ baseFile: options.delivery?.baseFile,
235
+ sourceMap: options.delivery?.sourceMap,
236
+ projectDir: options.projectDir ?? scanner.cwd,
237
+ onDependency: options.delivery?.onDependency,
238
+ resolveNodePackageImports: options.delivery?.resolveNodePackageImports
239
+ };
240
+ const graph = options.delivery?.resolveImport || options.delivery?.baseFile || options.delivery?.sourceMap ? await prepareCSSImportGraphWithResolver(filename, source, graphOptions, analyzeCSSDependencies, options.delivery.resolveImport ?? (() => void 0)) : prepareCSSImportGraph(filename, source, graphOptions, analyzeCSSDependencies);
241
+ const directives = mergeStylesheetDirectives(...Object.entries(graph.files).map(([file, text]) => collectStylesheetDirectives(text, graph.baseFiles?.[file] ?? file, scanner.cwd)));
242
+ const result = compileGraph(graph, options, void 0, [], {}, {}, void 0, inlineImports, inlineImports, inlineImports ? collectionHostImports(graph) : {});
243
+ const scoped = mergeStylesheetSourceOptions({
244
+ ...scanner.options,
245
+ exclude: scanner.customOptions ? scanner.customOptions.exclude : scanner.options.exclude
246
+ }, directives);
247
+ const sourceDependencies = hasStylesheetSourceDirectives(directives) ? resolveStylesheetSourcePaths(scoped, scanner.cwd).map((file) => resolve(scanner.cwd, file)) : [];
248
+ const dependencies = [.../* @__PURE__ */ new Set([...result.directives.dependencies, ...sourceDependencies])];
249
+ const rootPolicy = collectStylesheetDirectives(graph.files[graph.entry]);
250
+ const pruneNativeCSS = !rootPolicy.preserveNative && (options.pruneNativeCSS === true || rootPolicy.pruneNative);
251
+ const hasPruning = pruneNativeCSS || Object.values(graph.files).some((text) => {
252
+ const policy = collectStylesheetDirectives(text);
253
+ return !policy.preserveNative && policy.pruneNative;
254
+ });
255
+ if (inlineImports && hasPruning && result.directives.nativeClassNames.length && !scanner.registerNativeClasses) throw new TypeError("Stylesheet scanner integrations require registerNativeClasses().");
256
+ const masterCSS = inlineImports && Object.values(graph.files).some((text) => inspectCSS(text).hasMasterCSSImport);
257
+ sources.set(filename, {
258
+ source,
259
+ graph,
260
+ pruneNativeCSS,
261
+ masterCSS,
262
+ directives,
263
+ dependencies,
264
+ sourceDependencies,
265
+ classIndependent: !hasPruning && !hasStylesheetSourceDirectives(directives)
266
+ });
267
+ scanner.registerNativeClasses?.(filename, result.directives.nativeClassNames);
268
+ return {
269
+ ...result.directives,
270
+ dependencies
271
+ };
272
+ }
273
+ function composeDeliveredStylesheets(sources, options, classes, styleClasses, inlineImports = false) {
274
+ const entry = "\0master-css-output";
275
+ const graph = {
276
+ entry,
277
+ files: { [entry]: "" },
278
+ edges: []
279
+ };
280
+ const generatedClasses = new Set(classes);
281
+ const owners = {};
282
+ const classesByStylesheet = {};
283
+ const nativeStylesheets = [];
284
+ const hostImports = {};
285
+ for (const [id, source] of sources) {
286
+ if (!source.graph) throw new TypeError("Standalone delivery requires graph registration for every stylesheet.");
287
+ const specifier = `sheet-${graph.edges.length}`;
288
+ graph.files[entry] += `@import "${specifier}";\n`;
289
+ const masterFiles = /* @__PURE__ */ new Set();
290
+ const pending = source.graph.edges.filter((edge) => edge.specifier === "@master/css" || edge.specifier === "@master/css-preset").map((edge) => edge.resolved);
291
+ while (pending.length) {
292
+ const file = pending.pop();
293
+ if (masterFiles.has(file)) continue;
294
+ masterFiles.add(file);
295
+ pending.push(...source.graph.edges.filter((edge) => edge.from === file).map((edge) => edge.resolved));
296
+ }
297
+ const scopedClasses = [...styleClasses(source)];
298
+ const variant = (file) => `${file}\0${specifier}`;
299
+ for (const [file, text] of Object.entries(source.graph.files)) {
300
+ const key = variant(file);
301
+ graph.files[key] = text;
302
+ (graph.resourceOwners ??= {})[key] = source.graph.resourceOwners?.[file] ?? file;
303
+ if (source.graph.baseFiles?.[file]) (graph.baseFiles ??= {})[key] = source.graph.baseFiles[file];
304
+ if (source.graph.sourceMaps?.[file]) (graph.sourceMaps ??= {})[key] = source.graph.sourceMaps[file];
305
+ owners[key] = file;
306
+ const filePolicy = collectStylesheetDirectives(text, file, options.projectDir);
307
+ classesByStylesheet[key] = !filePolicy.preserveNative && (filePolicy.pruneNative || options.pruneNativeCSS === true && !source.graph.packageFiles?.includes(file)) ? scopedClasses : null;
308
+ if (masterFiles.has(file) ? options.includeMasterBaseCSS !== false : options.includeNativeCSS !== false) nativeStylesheets.push(key);
309
+ }
310
+ if (inlineImports) hostImports[variant(id)] = collectionHostImports(source.graph)[id];
311
+ graph.edges.push({
312
+ from: entry,
313
+ specifier,
314
+ resolved: variant(id)
315
+ }, ...source.graph.edges.map((edge) => ({
316
+ ...edge,
317
+ from: variant(edge.from),
318
+ resolved: variant(edge.resolved)
319
+ })));
320
+ for (const className of scopedClasses) generatedClasses.add(className);
321
+ }
322
+ const delivery = options.delivery;
323
+ const result = compileGraph(graph, {
324
+ ...options,
325
+ baseManifest: options.manifest ?? options.baseManifest,
326
+ delivery: {
327
+ ...delivery,
328
+ stylesheetURL: (file, variant) => file === entry ? delivery.entryURL : delivery.stylesheetURL(file, variant)
329
+ }
330
+ }, [...generatedClasses], [], owners, classesByStylesheet, nativeStylesheets, inlineImports, inlineImports, hostImports);
331
+ if (inlineImports && result.stylesheets.length > 1) throw new MasterCSSError({
332
+ code: "CSS_IMPORT_ERROR",
333
+ domain: "compiler",
334
+ message: "This stylesheet retains import or resource boundaries and requires stylesheet asset delivery."
335
+ });
336
+ const rendered = renderCompiledManifestCSS({
337
+ manifest: result.manifest,
338
+ nativeCSS: result.stylesheets.map((asset) => asset.css),
339
+ classNames: generatedClasses,
340
+ includeGeneratedCSS: options.includeGeneratedCSS
341
+ });
342
+ const referenced = renderCompiledManifestCSS({
343
+ manifest: result.resolutionManifest,
344
+ nativeCSS: result.stylesheets.map((asset) => asset.css),
345
+ includeGeneratedCSS: false,
346
+ emittedGlobals: rendered.emittedGlobals
347
+ });
348
+ return {
349
+ css: [
350
+ result.stylesheets.find((asset) => asset.id === entry)?.css,
351
+ rendered.generatedCSS,
352
+ referenced.generatedCSS
353
+ ].filter(Boolean).join("\n"),
354
+ emittedGlobals: referenced.emittedGlobals,
355
+ stylesheets: result.stylesheets.filter((asset) => asset.id !== entry),
356
+ resources: result.resources,
357
+ dependencies: result.directives.dependencies.filter((file) => file !== entry)
358
+ };
359
+ }
360
+ /** Only the registered entry's unresolved imports are emitted by its host source.
361
+ * Imported children's external boundaries still require explicit asset delivery.
362
+ */
363
+ function collectionHostImports(graph) {
364
+ const local = new Set(graph.edges.filter((edge) => edge.from === graph.entry).map((edge) => edge.specifier));
365
+ return { [graph.entry]: analyzeCSSDependencies(graph.files[graph.entry]).imports.map((imported) => imported.source).filter((specifier) => !local.has(specifier)) };
366
+ }
367
+ export { compileDeliveredFile, compileDeliveredSource, compileStylesheetMetadata, composeDeliveredStylesheets, registerDeliveredStylesheet };
@@ -0,0 +1,31 @@
1
+ import { CSSDirectiveExtractionPolicy } from "@master/css-schema/css-directives";
2
+ import { PrepareCSSImportGraphOptions } from "../node-imports.js";
3
+ import { StandaloneCSSDirectiveStatement } from "../node-compiler.js";
4
+ type StylesheetDirectives = CSSDirectiveExtractionPolicy;
5
+ type StylesheetDirectiveStatement = StandaloneCSSDirectiveStatement;
6
+ declare function hasLocalStyleDirectives(source: string, from?: string): boolean;
7
+ interface StylesheetSourceOptions {
8
+ outputDirectories?: readonly string[];
9
+ include?: readonly string[];
10
+ exclude?: readonly string[];
11
+ safelist?: readonly string[];
12
+ blocklist?: readonly (string | RegExp)[];
13
+ }
14
+ interface CollectedStylesheetDirectives {
15
+ directives: StylesheetDirectives;
16
+ dependencies: string[];
17
+ }
18
+ declare function createStylesheetDirectives(): StylesheetDirectives;
19
+ declare function hasStylesheetDirectives(directives?: StylesheetDirectives): boolean;
20
+ declare function hasStylesheetSourceDirectives(directives?: StylesheetDirectives): boolean;
21
+ declare function mergeStylesheetDirectives(...directives: (Partial<StylesheetDirectives> | undefined)[]): CSSDirectiveExtractionPolicy;
22
+ declare function mergeStylesheetSourceOptions<T extends StylesheetSourceOptions>(options: T, directives?: StylesheetDirectives): T;
23
+ declare function findStylesheetDirectiveStatements(source: string): StylesheetDirectiveStatement[];
24
+ declare function removeStylesheetDirectiveStatements(source: string): {
25
+ code: string;
26
+ removed: boolean;
27
+ };
28
+ declare function collectStylesheetDirectives(source: string, file?: string, cwd?: string): StylesheetDirectives;
29
+ declare function collectStylesheetDirectivesFromCSSGraph(file: string, source?: string, cwd?: string, graphOptions?: Pick<PrepareCSSImportGraphOptions, 'projectDir' | 'expandPackageImports'>): CollectedStylesheetDirectives;
30
+ declare function resolveStylesheetSourcePaths(options: StylesheetSourceOptions, cwd?: string): string[];
31
+ export { CollectedStylesheetDirectives, StylesheetDirectiveStatement, StylesheetDirectives, StylesheetSourceOptions, collectStylesheetDirectives, collectStylesheetDirectivesFromCSSGraph, createStylesheetDirectives, findStylesheetDirectiveStatements, hasLocalStyleDirectives, hasStylesheetDirectives, hasStylesheetSourceDirectives, mergeStylesheetDirectives, mergeStylesheetSourceOptions, removeStylesheetDirectiveStatements, resolveStylesheetSourcePaths };
@@ -0,0 +1,105 @@
1
+ import { prepareCSSImportGraph } from "../node-imports.js";
2
+ import { analyzeCSSDependencies, collectStandaloneCSSDirectiveExtractionPolicy, compileCSS, createCSSDirectiveExtractionPolicy, findStandaloneCSSDirectiveStatements, mergeCSSDirectiveExtractionPolicy, removeStandaloneCSSDirectives } from "../node-compiler.js";
3
+ import { dirname, isAbsolute, relative, resolve } from "node:path";
4
+ import { createCompilerBindingSessionSync } from "@master/css-binding/compiler/node";
5
+ import { SourcePolicy } from "@master/css-tooling/scanner/node";
6
+ import fg from "fast-glob";
7
+ // src/stylesheet/directives.ts
8
+ function hasLocalStyleDirectives(source, from) {
9
+ const result = compileCSS(source, {
10
+ preserveNativeCSS: false,
11
+ from
12
+ });
13
+ return Boolean(result.generatedCSS || result.styleDefinitions?.length || result.references?.length || analyzeCSSDependencies(source).usesCustomMedia);
14
+ }
15
+ function createStylesheetDirectives() {
16
+ return createCSSDirectiveExtractionPolicy();
17
+ }
18
+ function hasStylesheetDirectives(directives) {
19
+ return Boolean(directives && (directives.include.length || directives.exclude.length || directives.safelist.length || directives.safelistKeyframes.length || directives.blocklist.length || directives.preserveNative || directives.pruneNative));
20
+ }
21
+ function hasStylesheetSourceDirectives(directives) {
22
+ return Boolean(directives && (directives.include.length || directives.exclude.length));
23
+ }
24
+ function normalizePath(source) {
25
+ return source.replace(/\\/g, "/");
26
+ }
27
+ function normalizeSourcePattern(pattern, file, cwd = process.cwd()) {
28
+ if (isAbsolute(pattern)) return normalizePath(relative(cwd, pattern) || ".");
29
+ if (!file || file.includes("\0") || /^[a-z][a-z\d+.-]*:/i.test(file) && !/^[a-z]:[\\/]/i.test(file)) throw new Error("Resolving @source requires the declaring stylesheet file or baseFile");
30
+ return normalizePath(relative(cwd, resolve(cwd, dirname(file), pattern)) || ".");
31
+ }
32
+ function mergeStylesheetDirectives(...directives) {
33
+ return mergeCSSDirectiveExtractionPolicy(...directives);
34
+ }
35
+ function mergeStylesheetSourceOptions(options, directives) {
36
+ if (!directives) return options;
37
+ return {
38
+ ...options,
39
+ include: [.../* @__PURE__ */ new Set([...options.include || [], ...directives.include])],
40
+ exclude: [.../* @__PURE__ */ new Set([...options.exclude || [], ...directives.exclude])],
41
+ safelist: [.../* @__PURE__ */ new Set([...options.safelist || [], ...directives.safelist])],
42
+ blocklist: [...options.blocklist || [], ...directives.blocklist]
43
+ };
44
+ }
45
+ function findStylesheetDirectiveStatements(source) {
46
+ return findStandaloneCSSDirectiveStatements(source);
47
+ }
48
+ function removeStylesheetDirectiveStatements(source) {
49
+ const code = removeStandaloneCSSDirectives(source);
50
+ return {
51
+ code,
52
+ removed: code !== source
53
+ };
54
+ }
55
+ function collectStylesheetDirectives(source, file, cwd = process.cwd()) {
56
+ const directives = collectStandaloneCSSDirectiveExtractionPolicy(source);
57
+ if (!file) return directives;
58
+ directives.include = directives.include.map((pattern) => normalizeSourcePattern(pattern, file, cwd));
59
+ directives.exclude = directives.exclude.map((pattern) => normalizeSourcePattern(pattern, file, cwd));
60
+ return directives;
61
+ }
62
+ function collectStylesheetDirectivesFromCSSGraph(file, source, cwd = process.cwd(), graphOptions = {}) {
63
+ const filename = resolve(file);
64
+ const request = prepareCSSImportGraph(filename, source, {
65
+ projectDir: cwd,
66
+ expandPackageImports: false,
67
+ ...graphOptions
68
+ }, analyzeCSSDependencies);
69
+ const compiler = createCompilerBindingSessionSync();
70
+ try {
71
+ const graph = compiler.resolveCSSStylesheetGraph(request);
72
+ const nodes = new Map(graph.stylesheets.map((node) => [node.id, node]));
73
+ const visited = /* @__PURE__ */ new Set();
74
+ const policies = [];
75
+ const work = [[graph.entry, false]];
76
+ while (work.length) {
77
+ const [id, exit] = work.pop();
78
+ const node = nodes.get(id);
79
+ if (exit) policies.push(collectStylesheetDirectives(node.source, id, cwd));
80
+ else if (!visited.has(id)) {
81
+ visited.add(id);
82
+ work.push([id, true]);
83
+ for (const edge of [...node.imports].reverse()) if (edge.resolved) work.push([edge.resolved, false]);
84
+ }
85
+ }
86
+ return {
87
+ directives: mergeStylesheetDirectives(...policies),
88
+ dependencies: graph.stylesheets.map((node) => node.id)
89
+ };
90
+ } finally {
91
+ compiler.dispose();
92
+ }
93
+ }
94
+ function resolveStylesheetSourcePaths(options, cwd = process.cwd()) {
95
+ const paths = /* @__PURE__ */ new Set();
96
+ const policy = new SourcePolicy(cwd, options);
97
+ if (options.include?.length) {
98
+ for (const sourcePath of fg.sync([...options.include], {
99
+ cwd,
100
+ ignore: options.exclude ? [...options.exclude] : void 0
101
+ })) if (sourcePath && policy.accepts(sourcePath, true)) paths.add(sourcePath);
102
+ }
103
+ return [...paths];
104
+ }
105
+ export { collectStylesheetDirectives, collectStylesheetDirectivesFromCSSGraph, createStylesheetDirectives, findStylesheetDirectiveStatements, hasLocalStyleDirectives, hasStylesheetDirectives, hasStylesheetSourceDirectives, mergeStylesheetDirectives, mergeStylesheetSourceOptions, removeStylesheetDirectiveStatements, resolveStylesheetSourcePaths };
@@ -0,0 +1,3 @@
1
+ import { MasterCSSCompiledStylesheet, MasterCSSPreparedStylesheet, MasterCSSRenderedStylesheetCompileOptions, MasterCSSSassCompiler, MasterCSSStylesheetAsyncResolutionOptions, MasterCSSStylesheetCollection, MasterCSSStylesheetCollectionSnapshot, MasterCSSStylesheetCompileOptions, MasterCSSStylesheetComposition, MasterCSSStylesheetCompositionOptions, MasterCSSStylesheetDeliveryOptions, MasterCSSStylesheetDependencyOptions, MasterCSSStylesheetHostOptions, MasterCSSStylesheetImportResolver, MasterCSSStylesheetImportSource, MasterCSSStylesheetKind, MasterCSSStylesheetPreparationOptions, MasterCSSStylesheetResolution, MasterCSSStylesheetResolutionOptions, MasterCSSStylesheetResourceAsset, MasterCSSStylesheetSourceSnapshot, MasterCSSStylesheetTransformOptions, MasterCSSStylesheetTransformResult, collectStylesheetDependencies, collectStylesheetEmittedGlobals, compileRenderedStylesheet, compileStylesheet, composeStylesheetHost, createStylesheetCollection, prepareStylesheet, resolveStylesheet, transformStylesheet } from "./public.js";
2
+ import { MasterCSSLinkedStylesheet, describeLinkedStylesheet } from "./linked-stylesheet.js";
3
+ export { type MasterCSSCompiledStylesheet, type MasterCSSLinkedStylesheet, type MasterCSSPreparedStylesheet, type MasterCSSRenderedStylesheetCompileOptions, type MasterCSSSassCompiler, type MasterCSSStylesheetAsyncResolutionOptions, MasterCSSStylesheetCollection, type MasterCSSStylesheetCollectionSnapshot, type MasterCSSStylesheetCompileOptions, type MasterCSSStylesheetComposition, type MasterCSSStylesheetCompositionOptions, type MasterCSSStylesheetDeliveryOptions, type MasterCSSStylesheetDependencyOptions, type MasterCSSStylesheetHostOptions, type MasterCSSStylesheetImportResolver, type MasterCSSStylesheetImportSource, type MasterCSSStylesheetKind, type MasterCSSStylesheetPreparationOptions, type MasterCSSStylesheetResolution, type MasterCSSStylesheetResolutionOptions, type MasterCSSStylesheetResourceAsset, type MasterCSSStylesheetSourceSnapshot, type MasterCSSStylesheetTransformOptions, type MasterCSSStylesheetTransformResult, collectStylesheetDependencies, collectStylesheetEmittedGlobals, compileRenderedStylesheet, compileStylesheet, composeStylesheetHost, createStylesheetCollection, describeLinkedStylesheet, prepareStylesheet, resolveStylesheet, transformStylesheet };
@@ -0,0 +1,4 @@
1
+ import { prepareStylesheetSource } from "./index.js";
2
+ import { MasterCSSStylesheetCollection, collectStylesheetDependencies, collectStylesheetEmittedGlobals, compileRenderedStylesheet, compileStylesheet, composeStylesheetHost, createStylesheetCollection, resolveStylesheet, transformStylesheet } from "./public.js";
3
+ import { describeLinkedStylesheet } from "./linked-stylesheet.js";
4
+ export { MasterCSSStylesheetCollection, collectStylesheetDependencies, collectStylesheetEmittedGlobals, compileRenderedStylesheet, compileStylesheet, composeStylesheetHost, createStylesheetCollection, describeLinkedStylesheet, prepareStylesheetSource as prepareStylesheet, resolveStylesheet, transformStylesheet };
@@ -0,0 +1,39 @@
1
+ import { CompileCSSResult } from "../node-compiler.js";
2
+ import { CompileRenderedStylesheetOptions, CompileRenderedStylesheetOptions as CompileRenderedStylesheetOptions$1, CompileRenderedStylesheetResult, CompileRenderedStylesheetResult as CompileRenderedStylesheetResult$1, CompileStylesheetOptions, CompileStylesheetOptions as CompileStylesheetOptions$1, CreateExtractedCSSOptions, CreateExtractedCSSOptions as CreateExtractedCSSOptions$1, CreateExtractedCSSResult, CreateExtractedCSSResult as CreateExtractedCSSResult$1, CreateStyleEntryEmittedGlobalsOptions, CreateStyleEntryEmittedGlobalsOptions as CreateStyleEntryEmittedGlobalsOptions$1, CreateStyleEntryEmittedGlobalsResult, CreateStyleEntryEmittedGlobalsResult as CreateStyleEntryEmittedGlobalsResult$1, CreateStylesheetHostSourceOptions, CreateStylesheetHostSourceOptions as CreateStylesheetHostSourceOptions$1, RegisterStylesheetSourceOptions, RegisterStylesheetSourceOptions as RegisterStylesheetSourceOptions$1, ResolveStylesheetImportGraphOptions, ResolveStylesheetImportGraphOptions as ResolveStylesheetImportGraphOptions$1, ResolvedStylesheetSource, ResolvedStylesheetSource as ResolvedStylesheetSource$1, SassModule, ScannerCSSState, ScannerClassState, ScannerState, ScannerState as ScannerState$1, StylesheetPreparationOptions, StylesheetSource, StylesheetSources, StylesheetSources as StylesheetSources$1, TransformLocalStylesheetOptions, TransformLocalStylesheetOptions as TransformLocalStylesheetOptions$1, TransformLocalStylesheetResult, TransformLocalStylesheetResult as TransformLocalStylesheetResult$1 } from "./types.js";
3
+ import { CollectedStylesheetDirectives, StylesheetDirectiveStatement, StylesheetDirectives, StylesheetSourceOptions, collectStylesheetDirectives, collectStylesheetDirectivesFromCSSGraph, createStylesheetDirectives, findStylesheetDirectiveStatements, hasLocalStyleDirectives, hasStylesheetDirectives, hasStylesheetSourceDirectives, mergeStylesheetDirectives, mergeStylesheetSourceOptions, removeStylesheetDirectiveStatements, resolveStylesheetSourcePaths } from "./directives.js";
4
+ declare function cleanStyleRequest(id: string): string;
5
+ declare function isStylesheetRequest(id: string): boolean;
6
+ declare function replaceStylesheetImports(source: string, replacement: string): {
7
+ code: string;
8
+ replaced: boolean;
9
+ };
10
+ declare function resolveStylesheetImportGraph(file: string, source: string, projectDir?: string, options?: ResolveStylesheetImportGraphOptions$1): ResolvedStylesheetSource$1;
11
+ declare function collectStylesheetDependencies(file: string, source?: string, projectDir?: string): string[];
12
+ declare function removeStylesheetImports(source: string): {
13
+ code: string;
14
+ replaced: boolean;
15
+ };
16
+ declare function hasMasterStyleEntrypoint(source: string): boolean;
17
+ declare function resolveMasterStyleSource(file: string, source: string, projectDir?: string): ResolvedStylesheetSource$1 | undefined;
18
+ declare function isMasterCSSPackageStyleFile(id: string, projectDir?: string): boolean;
19
+ declare function removeMasterStyleDirectives(source: string): {
20
+ code: string;
21
+ removed: boolean;
22
+ };
23
+ declare function createStylesheetHostSource(source: string, options?: CreateStylesheetHostSourceOptions$1): string;
24
+ declare function isMasterStyleSource(source: string): boolean;
25
+ declare function prepareStylesheetSource(id: string, source: string, options?: StylesheetPreparationOptions): Promise<import("./types.js").PreparedStylesheetSource>;
26
+ declare function compileStylesheet(id: string, source: string, options: CompileStylesheetOptions$1): Promise<CompileCSSResult>;
27
+ declare function compileRenderedStylesheet(id: string, source: string, options: CompileRenderedStylesheetOptions$1): Promise<CompileRenderedStylesheetResult$1>;
28
+ declare function createStyleEntryEmittedGlobals(entries: string[], options: CreateStyleEntryEmittedGlobalsOptions$1): Promise<CreateStyleEntryEmittedGlobalsResult$1>;
29
+ declare function transformLocalStylesheet(id: string, source: string, options: TransformLocalStylesheetOptions$1): Promise<TransformLocalStylesheetResult$1>;
30
+ declare function getNativeCSS(result: {
31
+ css?: string;
32
+ generatedCSS?: string;
33
+ nativeCSS?: string;
34
+ }): string;
35
+ declare function getScannerClasses(scanner: ScannerState$1): string[];
36
+ declare function registerStylesheetSource(scanner: ScannerState$1, stylesheetSources: StylesheetSources$1, id: string, source: string, options: RegisterStylesheetSourceOptions$1): Promise<CompileCSSResult>;
37
+ declare function createExtractedCSSResult(options: CreateExtractedCSSOptions$1): Promise<CreateExtractedCSSResult$1>;
38
+ declare function createExtractedCSS(options: CreateExtractedCSSOptions$1): Promise<string>;
39
+ export { type CollectedStylesheetDirectives, type CompileRenderedStylesheetOptions, type CompileRenderedStylesheetResult, type CompileStylesheetOptions, type CreateExtractedCSSOptions, type CreateExtractedCSSResult, type CreateStyleEntryEmittedGlobalsOptions, type CreateStyleEntryEmittedGlobalsResult, type CreateStylesheetHostSourceOptions, type RegisterStylesheetSourceOptions, type ResolveStylesheetImportGraphOptions, type ResolvedStylesheetSource, type SassModule, type ScannerCSSState, type ScannerClassState, type ScannerState, type StylesheetDirectiveStatement, type StylesheetDirectives, type StylesheetSource, type StylesheetSourceOptions, type StylesheetSources, type TransformLocalStylesheetOptions, type TransformLocalStylesheetResult, cleanStyleRequest, collectStylesheetDependencies, collectStylesheetDirectives, collectStylesheetDirectivesFromCSSGraph, compileRenderedStylesheet, compileStylesheet, createExtractedCSS, createExtractedCSSResult, createStyleEntryEmittedGlobals, createStylesheetDirectives, createStylesheetHostSource, findStylesheetDirectiveStatements, getNativeCSS, getScannerClasses, hasLocalStyleDirectives, hasMasterStyleEntrypoint, hasStylesheetDirectives, hasStylesheetSourceDirectives, isMasterCSSPackageStyleFile, isMasterStyleSource, isStylesheetRequest, mergeStylesheetDirectives, mergeStylesheetSourceOptions, prepareStylesheetSource, registerStylesheetSource, removeMasterStyleDirectives, removeStylesheetDirectiveStatements, removeStylesheetImports, replaceStylesheetImports, resolveMasterStyleSource, resolveStylesheetImportGraph, resolveStylesheetSourcePaths, transformLocalStylesheet };