@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
package/README.md ADDED
@@ -0,0 +1,466 @@
1
+ # @master/css-compiler
2
+
3
+ Rust-backed CSS directive and manifest compilation for Master CSS.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ npm install @master/css-compiler
9
+ ```
10
+
11
+ ## Responsibility
12
+
13
+ The Rust compiler and project crates own parsing, directive lowering, manifest
14
+ compilation, normalization, native CSS transformation, graph policy, and project
15
+ merge policy. TypeScript is limited to platform loading, filesystem/package
16
+ resolution, file IO, host CSS capability checks, and orchestration.
17
+
18
+ ## Universal session
19
+
20
+ ```ts
21
+ import { createCompiler } from '@master/css-compiler'
22
+
23
+ const compiler = await createCompiler()
24
+ const result = compiler.compileCSS(source, { from: 'src/app.css' })
25
+ compiler.dispose()
26
+ ```
27
+
28
+ The universal entry prefers the native binding in Node and falls back to
29
+ `binding-wasm-compiler`. It never runs a TypeScript parser, lowerer, or CSS transformer.
30
+ Session methods are synchronous after asynchronous initialization.
31
+
32
+ ## Compare project changes
33
+
34
+ `compiler.compareProjectSnapshots({ before, after })` compares two resolved
35
+ version 1 snapshots with independent Manifest v6 definitions. Each snapshot has
36
+ `manifest`, `sources: [{ path, classes }]`, `stylesheets: [{ path, css }]`,
37
+ `outputs: [{ path, css }]`, `excluded` and `unresolved`. Stylesheets contain
38
+ delivered native CSS after directive lowering. Asset arrays preserve delivery
39
+ order and require unique identities.
40
+
41
+ Node hosts can call `captureMasterCSSProject({ cwd, manifest, patterns })` from
42
+ `@master/css-compiler/diagnostics` to obtain `{ report, snapshot }` through the
43
+ existing scanner and stylesheet delivery pipeline. Capture rejects failed project
44
+ resolution, stylesheet compilation or extraction. Class validation diagnostics
45
+ remain in `report`, allowing comparison of consumers whose tokens were deleted.
46
+ `compareProjectSnapshots({ before, after })` on that same entrypoint is
47
+ an asynchronous convenience around the universal compiler method. Editors with
48
+ unsaved buffers can supply their own resolved snapshots to the universal method.
49
+
50
+ Reports include changed definitions, known consuming classes and files, rule
51
+ IR before/after (declarations, conditions and layers), transitive variable and
52
+ recipe dependencies, asset text and order changes, and explicit coverage limits.
53
+ A token edit can affect consumers even when class names and generated rules stay
54
+ unchanged. Native references are conservative at stylesheet granularity. The
55
+ report does not compute the DOM cascade, execute dynamic sources, compare binary
56
+ resource contents, fetch remote stylesheets, or verify visual/accessibility behavior.
57
+ Capture uses local file URLs as stable asset identities; compare deployment
58
+ outputs by supplying snapshots with the host's actual delivery URLs instead.
59
+
60
+ The session exposes batched Rust operations for CSS inspection, directive compilation,
61
+ theme compilation, dependency analysis, extraction-policy merging, manifest lowering
62
+ and normalization, default-preset compilation, and prepared import graphs.
63
+
64
+ ## Compile separate stylesheets
65
+
66
+ For a registered stylesheet collection, `collection.compose({ ...options, sourceIds })`
67
+ selects the source IDs owned by one host output. Omit `sourceIds` to compose all
68
+ registered sources; pass an empty array to emit only the generated CSS from the
69
+ supplied manifest and scanner classes. Selection leaves the collection intact.
70
+ Publish the selected result's stylesheet and resource assets together.
71
+
72
+ `compiler.compileStylesheets(request)` compiles prepared files with a shared
73
+ manifest while retaining each stylesheet's import order, conditions, and layers.
74
+ It is available with native and compiler-Wasm sessions.
75
+
76
+ ```ts
77
+ const result = compiler.compileStylesheets({
78
+ graph: {
79
+ entry: 'app',
80
+ files: {
81
+ app: '@import "./theme.css";',
82
+ theme: '@mixin --paint { color: red } @layer theme { .example { color: red; } }'
83
+ },
84
+ edges: [{ from: 'app', specifier: './theme.css', resolved: 'theme' }]
85
+ },
86
+ urls: { app: '/styles/app.css', theme: '/styles/theme.css' },
87
+ baseManifest: { version: 6, languageVersion: 18, mixins: [] }
88
+ })
89
+ ```
90
+
91
+ Deliver every item in `result.stylesheets` at its `href`, and load the entry's
92
+ stylesheet. `result.css` contains the entry CSS only. Imports without prepared
93
+ edges remain external CSS imports. Imported authoring definitions share the
94
+ manifest; native CSS and native `@apply` output retain their stylesheet scopes
95
+ and rule positions.
96
+
97
+ The host supplies file contents, import resolution, and delivery URLs. Use `resourceURLs` to map each source file ID and decoded resource URL to a
98
+ root-relative or absolute delivery URL before definitions are merged. For example,
99
+ `resourceURLs: { child: { "image.png": "/assets/image.png" } }` preserves a child
100
+ theme token's image when another file references it. With this option present, every
101
+ parsed relative `url()` or `image-set()` resource requires a mapping. Empty URLs,
102
+ fragment-only references, import edges, and namespace identifiers are preserved.
103
+ Root-relative replacements require assets to share an origin; use absolute URLs
104
+ when output stylesheets can be served from different origins. Without this option,
105
+ delivery must retain the original resource bases.
106
+ For `@reference`, supply the prepared reference context as `resolutionManifest`;
107
+ reference-only definitions are not added to the emitted manifest.
108
+
109
+ For standalone assets in one directory, `relativeResourceURLs: true` permits
110
+ mapped sibling URLs such as `./image.svg`. Every stylesheet URL must also be a
111
+ sibling `./name.css` URL. The resulting manifest's resource URLs are scoped to
112
+ those stylesheets; do not use it for inline CSS at a different document base.
113
+
114
+ The Node stylesheet collection accepts `delivery` on both `register` and
115
+ `compose`: supply `entryURL`, `stylesheetURL(file, variant)`, `resourceURL(file)`, and,
116
+ for sibling assets, `relativeResourceURLs: true`. Composition returns
117
+ `stylesheets`, `resources` (source file plus destination href), and dependencies
118
+ alongside the entry `css`. Delivery hosts can also supply `onDependency(file)` to observe
119
+ attempted stylesheet and resource paths, including missing files, before
120
+ registration or composition completes. Use the optional `variant` identity for
121
+ stylesheet URLs: shared files can need separate assets for different entry
122
+ pruning scopes. Each variant must have a distinct URL. Composition independently
123
+ supports `includeNativeCSS`, `includeMasterBaseCSS`, and `includeGeneratedCSS`.
124
+ Disabling native output suppresses that file's rules, native variant output and
125
+ external imports. Local links from suppressed files remain only when needed to
126
+ reach selected output, so empty imports cannot declare excluded cascade layers.
127
+ Unreachable stylesheet assets are omitted; authoring definitions and dependencies
128
+ still contribute to compilation. The low-level graph
129
+ request exposes the same native selection through `nativeStylesheets` (file IDs).
130
+ `preserveNativeCSS: false` omits raw native rules and unresolved external imports
131
+ while retaining compiled native `@apply` in otherwise included stylesheets;
132
+ `includeNativeCSS: false` excludes both kinds of project-native output.
133
+ Publish all returned assets together. References are
134
+ resolved without emitting their native CSS, while their used resources retain
135
+ the reference file's ownership.
136
+
137
+ `transformStylesheet(id, source, { baseManifest, delivery })` also supports
138
+ supplied local stylesheets. It compiles imported `@apply` rules and shared
139
+ authoring definitions through the Rust graph compiler, including roots whose
140
+ directives occur only in imported descendants. With `preserveImports: true`,
141
+ stylesheet resolution classifies these graphs as local while preserving the
142
+ original root source. A wholly native graph stays unchanged and its resources
143
+ remain owned by the host by default. Hosts that have already transformed a native
144
+ graph, such as scoped CSS Modules, can set `transformNativeStylesheets: true`
145
+ alongside `delivery` to publish that graph and its resources through the same
146
+ asset contract. This option has no effect without `delivery`. `code` is the entry CSS;
147
+ `stylesheets` contains retained children and `resources` identifies resource files
148
+ to publish. The host must publish the complete returned asset set at the supplied
149
+ URLs. `resolveImport` can supply host aliases, and `emittedGlobals` suppresses
150
+ variables and animations already provided by global stylesheets. Reference-only
151
+ native rules stay excluded. Omitting `delivery` keeps the existing single-source
152
+ transform contract. Vite consumes this asset result for local variant entries in
153
+ development and production, including inline requests. Further host input and
154
+ lifecycle combinations remain under integration validation.
155
+
156
+ Node hosts that enable `transformNativeStylesheets` with delivery can also set
157
+ `preserveUnchangedNativeCSS: true`. For a wholly native graph whose entry needs
158
+ no managed theme or keyframe expansion, the transform returns the original text
159
+ with `transformed: false`, leaving imports and assets with the host. The option defaults to `false`;
160
+ transformed graphs retain the complete delivery contract above.
161
+
162
+ Graph diagnostics retain original UTF-16 source spans after resource URL
163
+ relocation and consumption of entry, extraction, and reference directives.
164
+ The public binding converts ranges using the diagnostic's own source
165
+ file, and collection composition reports the original filename for entry variants.
166
+ Errors that do not provide a source range remain unlocated.
167
+
168
+ CLI `generate --output dist/output.css` publishes these sibling CSS/resource
169
+ assets automatically. Deploy the full output asset set, not only output.css.
170
+ The file/project/build APIs and `--no-export` still use their existing
171
+ single-string paths; their graph-delivery limitations remain independent of the standalone CLI export path.
172
+
173
+ ## Compose a stylesheet bundle
174
+
175
+ Use `prepareStylesheetBundle` to insert an existing `compileStylesheets` result
176
+ at a complete placeholder rule in a host stylesheet. Rust preserves ordinary
177
+ rules before and after each placeholder, shared layer scopes, import conditions,
178
+ and valid namespace declarations. Native and compiler-Wasm sessions expose the
179
+ same two-phase API:
180
+
181
+ ```ts
182
+ const bundle = compiler.prepareStylesheetBundle({
183
+ source: 'body{margin:0}#master-css-slot{--slot:0}body{color-green}',
184
+ from: 'bundle.css',
185
+ slotCSSRule: '#master-css-slot{--slot:0}',
186
+ managed: result // The complete compileStylesheets result above
187
+ })
188
+ const urls = Object.fromEntries(bundle.graph.stylesheets.map((sheet, index) => [
189
+ sheet.id, `/styles/bundle-${index}.css`
190
+ ]))
191
+ const assets = compiler.renderStylesheetBundle({ bundle, urls })
192
+ const entryURL = urls[bundle.graph.entry]
193
+ ```
194
+
195
+ Publish every returned asset at its `href` before loading `entryURL`. Assign
196
+ URLs after preparation, because the bundle can contain additional stylesheet
197
+ nodes. The bundle can be serialized as JSON between preparation and rendering.
198
+ The managed input must retain its compiler-issued import URLs and distinct,
199
+ nonempty asset `href` values so Rust can reconnect the graph after relocation.
200
+
201
+ For CSS string delivery, rendering accepts `inlineImports: true`. Rust expands
202
+ import-free local children when import order and namespace scope remain intact;
203
+ a wrapper containing only one unqualified import can also promote its child.
204
+ Select the returned asset whose ID is `bundle.graph.entry` for the CSS string.
205
+ Publish the remaining referenced assets and supply URLs valid at the insertion
206
+ site. Boundaries that protect external imports or separate namespaces remain
207
+ imports. The default rendering mode keeps separate stylesheet assets.
208
+
209
+ For ordinary bundle fragments, `bundle.sources` reports original UTF-16 ranges,
210
+ resource URLs, and imports. Supply `resourceURLs` to rendering as a map from each
211
+ decoded URL to an absolute or root-relative URL. Every ordinary relative resource
212
+ or CSS import requires a mapping; query strings and fragments belong in the
213
+ replacement. Namespace identifiers and fragment-only resource references are
214
+ preserved. Managed resources must already have suitable delivery URLs from
215
+ `compileStylesheets`; this step does not relocate them again.
216
+
217
+ Hosts that publish every fragment beside the original stylesheet can instead
218
+ set `preserveResourceBase: true`. This preserves ordinary URLs verbatim and cannot
219
+ be combined with `resourceURLs`. The host must guarantee the same resource base;
220
+ the compiler cannot infer a deployment directory from filesystem paths.
221
+
222
+ Node delivery hosts can use `resolveStylesheetSync(..., { preserveImports: true })`
223
+ for graph-based classification without flattening. `compilationSource` then stays
224
+ unexpanded. Set collection delivery's `resolveNodePackageImports: true` to resolve
225
+ CSS package exports with Node and preserve their native rules when project CSS is
226
+ pruned. Host-specific aliases and virtual CSS resolvers require separate integration.
227
+
228
+ Placeholders in comments, strings, and larger selectors are not insertion points.
229
+ Every matching rule is retained, including repeated occurrences. Supported wrapper
230
+ scopes are media, supports, and layers. Other wrapper scopes and invalid namespace
231
+ or import placement currently produce diagnostics. This API returns assets;
232
+ Vite production builds publish these assets automatically. Vite development CSS
233
+ entries serve retained graph assets through the development server; virtual/local
234
+ composition paths and graph lifecycle coverage remain incomplete. Webpack
235
+ asset publishing is not integrated with this delivery path.
236
+
237
+ `collectStylesheetEmittedGlobals()` compiles the managed import/reference graph
238
+ without flattening it. Qualified local imports may retain external imports in
239
+ their descendants. Metadata collection reports stylesheet/reference dependencies
240
+ and leaves resource-file reads and publication to the delivery host.
241
+
242
+ ## Native synchronous session
243
+
244
+ ```ts
245
+ import { createCompilerSync } from '@master/css-compiler/node'
246
+
247
+ const compiler = createCompilerSync()
248
+ ```
249
+
250
+ `createCompilerSync()` requires the native binding and throws
251
+ `NATIVE_UNAVAILABLE` when it cannot be loaded.
252
+
253
+ ## Node file helpers
254
+
255
+ The root entry also provides Node convenience functions such as `compileCSSFile`,
256
+ `compileCSSManifestFile`, `compileProjectManifest`, and `resolveCSSImportGraph`.
257
+ These functions supply files and Node package `exports` resolution to the Rust
258
+ compiler; they do not contain a TypeScript semantic fallback.
259
+
260
+ The native binding's filesystem project loader retains imported file boundaries
261
+ when collecting managed definitions, resolving references and planning source
262
+ scans. Native `@apply` output keeps import conditions and layer scopes, while
263
+ the separate `generatedCSS` field remains a definition metadata view. Ordinary
264
+ native CSS and asset publication belong to stylesheet delivery APIs. This does
265
+ not extend the raw `resolveCSSImportGraph().source` flattening contract.
266
+
267
+ Compiler binding sessions also expose `resolveCSSStylesheetGraph(request)` for
268
+ metadata consumers. It accepts prepared files and import edges, returns each
269
+ file with its ordered imports, and validates import syntax and cycles without
270
+ compiling native or managed CSS. References remain metadata and unresolved
271
+ external imports remain edges. Source directives are collected from their
272
+ owning files, so relative patterns retain the imported file's directory.
273
+
274
+ Default stylesheet collections retain the original import graph through
275
+ registration and composition. Imported scanning directives are consumed before
276
+ native import conditions are applied; source patterns and references retain
277
+ their owning files. Native, generated, and Master base output switches apply
278
+ across every registered graph. Unresolved entry imports remain the host source's
279
+ responsibility. Binding graph requests can identify those exact imports with
280
+ `hostImports`; Rust validates ownership and preserves output source anchors.
281
+ External imports inside child files still require explicit asset delivery when
282
+ they prevent safe inlining.
283
+
284
+ ## Publish a compiled file
285
+
286
+ `compileManifestFileSync(file, { baseManifest, delivery, preserveNativeCSS: true })`
287
+ can prepare a file and its imports for publication as separate stylesheets. The
288
+ Node host resolves local imports, package entries and references; the existing
289
+ Rust graph compiler retains external import order, conditions and native
290
+ `@apply` positions. `delivery` uses the same URL callbacks as standalone
291
+ stylesheet collections: `entryURL`, `stylesheetURL(file)` and `resourceURL(file)`.
292
+ Each stylesheet must have a distinct final URL.
293
+
294
+ The returned `stylesheets` include the entry and every required imported CSS
295
+ asset; copy each returned `resources` file to its `href` and publish each
296
+ stylesheet at its `href` before loading the entry. Compilation performs reads
297
+ and returns assets without writing output files. `css`, `nativeCSS` and
298
+ `generatedCSS` describe the entry only, so publishing only `css` is insufficient.
299
+ Relative resource URLs are rewritten for their original source owner and retain
300
+ query strings and fragments. Reference-only stylesheets are not published.
301
+ Omitting `preserveNativeCSS` retains the file API's existing default of removing
302
+ raw native CSS while preserving compiled native `@apply` and its conditions.
303
+ Omitting `delivery` continues to use the single-string file path, whose
304
+ external-import limitations remain; other build and `--no-export` consumers
305
+ still require their own asset publishing integration.
306
+
307
+ ## Browser entry
308
+
309
+ ```ts
310
+ import { createCompiler } from '@master/css-compiler/browser'
311
+
312
+ const compiler = await createCompiler()
313
+ const result = compiler.compileCSS(source)
314
+ compiler.dispose()
315
+ ```
316
+
317
+ The browser entry loads only `binding-wasm-compiler`. Browser compilation cannot resolve
318
+ filesystem `@reference` directives unless the host provides a prepared graph.
319
+
320
+
321
+ ## Project, stylesheet, and inspection APIs
322
+
323
+ Project entry discovery and manifest loading are available from
324
+ `@master/css-compiler/project` and its `sync`, `entries`, and `workspace` subpaths.
325
+ Managed stylesheet composition is available from
326
+ `@master/css-compiler/stylesheet`; browser-safe compilation and directive helpers use
327
+ its explicit subpaths. Complete project inspection reports are exposed from
328
+ `@master/css-compiler/diagnostics`.
329
+
330
+ Inspection reports associate each file's `discovered` classes with that file's
331
+ actual extracted candidates, including classes repeated across files. Class
332
+ classification still comes from the shared Rust scanner after all sources finish.
333
+ Invalid-class diagnostics point to the first containing file in report input
334
+ order. Safelisted classes absent from source do not create file occurrences.
335
+ The per-file `changed` flag reports scanner changes, so it can be false even when
336
+ that file contains classes already discovered in another file.
337
+
338
+
339
+ Node project manifest loading (`compileProjectManifest`, `loadProjectManifest`,
340
+ and their synchronous variants) preserves each imported stylesheet while
341
+ compiling shared definitions. A qualified local import containing an external
342
+ import can therefore supply definitions without fetching that external CSS.
343
+ `@reference` supplies definitions for composition and contributes dependencies;
344
+ its native rules, standalone utility classes, and source policies are not imported.
345
+ Relative `@source` and `@source not` patterns beginning with `./` or `../` resolve
346
+ from the file that declares them, including imported files. Bare patterns resolve
347
+ from the project root. Explicit project entries merge in the supplied order.
348
+ These APIs return a manifest and metadata; they do not publish native CSS assets.
349
+
350
+ These are cohesive compiler host responsibilities.
351
+
352
+
353
+ Build hosts can supply asynchronous CSS file resolution through
354
+ `resolveStylesheet(id, source, { preserveImports: true, resolveImport })` and
355
+ `collection.register(scanner, id, source, { delivery: { ...delivery, resolveImport } })`.
356
+ Use the same resolver for classification and registration. It receives the import
357
+ specifier and the importing source ID, and returns an absolute CSS file path,
358
+ a `{ id, source, baseFile? }` record from a host loader, `undefined` to use Node
359
+ resolution, or `null` to retain an external import. Supplied IDs are absolute file
360
+ paths or null-prefixed virtual IDs; virtual sources are not read as files. Query
361
+ suffixes remain part of a virtual source identity.
362
+ An absolute `baseFile` supplies the original filesystem owner for relative CSS
363
+ references as well as imports, resource URLs and source patterns. Reference
364
+ definitions retain their own resource bases; parser diagnostics retain the supplied
365
+ source identity. Attempted reference paths are reported even when the file is missing.
366
+ For CSS emitted from multiple original files, provide a serialized source-map v3
367
+ string as `sourceMap` on each supplied import record or entry delivery options.
368
+ Reference positions from the Rust compiler are mapped to their original files
369
+ before filesystem lookup. An explicitly supplied map must identify a filesystem
370
+ origin for every reference; unavailable origins produce an error instead of using
371
+ an unrelated directory. Without a map, references use that source's `baseFile`.
372
+ Registration stores the prepared graph, so composition does not resolve those
373
+ imports again. `onDependency` reports source IDs and attempted file reads; build
374
+ hosts should watch filesystem IDs and retain their loader dependencies separately;
375
+ aborting or disposing the collection during resolution prevents registration.
376
+
377
+ For a loader-supplied import, `baseFile` names its absolute source owner for
378
+ relative resource URLs and source patterns. Resource delivery preserves URL query
379
+ strings and fragments. A virtual source with relative resources and no owner
380
+ produces an error instead of inventing a filesystem path. Preprocessing and custom
381
+ resolution for `@reference` or resource URLs require further host integration.
382
+ Synchronous file compilation does not accept this asynchronous resolver.
383
+ For a preprocessed or virtual root, async resolution and delivery options also
384
+ accept `baseFile`. Relative Node fallback imports and resource URLs use that
385
+ absolute owner while the graph retains the root source identity.
386
+
387
+
388
+ For production graph delivery, an alias or custom resolver pointing to project
389
+ CSS follows the project's native CSS pruning policy. A bare-looking import name
390
+ alone does not make the file package CSS: the resolved file must belong to the
391
+ named package. Package export conditions may select another CSS file within that
392
+ package while retaining its native rules. `@preserve native;` explicitly keeps
393
+ project-native rules regardless of class usage.
394
+
395
+ Project loading and compilation options accept `onDependency(file)` in both async
396
+ and synchronous APIs. The callback observes each CSS file once per operation,
397
+ before reading it, including a missing import or `@reference` target. Hosts can
398
+ retain attempted dependencies when loading throws and retry after a file changes.
399
+ Manifest results and compiler diagnostics keep their existing semantics.
400
+
401
+ ### Stylesheet source maps
402
+
403
+ The direct Node stylesheet APIs return a serialized source map v3 in `sourceMap`:
404
+ `compileStylesheet()` and `compileRenderedStylesheet()` map their final `css`, and
405
+ `transformStylesheet()` maps its returned `code`. Pass a host-prepared input map
406
+ through the `sourceMap` option; Sass preparation also supplies its original map.
407
+ The compiler chains these inputs through directive removal, import expansion,
408
+ native printing and variant lowering, retaining original source contents.
409
+
410
+ Mappings are source anchors: printed native rules identify their originating rule,
411
+ and lowered declarations identify the authored declaration. An expanded interpolation retains the host map's segment anchor.
412
+ Generated wrappers, classes and resources without an authoring location are left
413
+ unmapped. Separate assets returned by the `delivery` path do not yet carry output
414
+ maps. For otherwise valid native CSS, malformed input maps label the successful
415
+ output with its prepared source rather than claiming an original Sass location.
416
+ Reference ownership validation still requires valid input context.
417
+
418
+ ### Graph output positions
419
+
420
+ Each stylesheet returned by `compileStylesheets()` includes `outputMappings` in
421
+ UTF-16 offsets relative to that stylesheet's final `css`. Source references address
422
+ the original input file, including after import URL changes, resource relocation
423
+ and native composition. These are compiler anchors, not a serialized source map;
424
+ hosts must chain them through their preprocessor maps and any later delivery edits.
425
+
426
+ ### Inlining compiled imports
427
+
428
+ `compileStylesheets({ ...request, inlineImports: true })` inlines compatible
429
+ local stylesheets after their managed definitions have been compiled. The returned
430
+ `stylesheets` array contains the entry and any assets still required by imports,
431
+ namespace boundaries or resource URL bases. Publish every returned asset at its
432
+ assigned URL. Relative resources can move only between the same delivery base;
433
+ provide explicit resource URL mappings when relocating them.
434
+
435
+ Each final stylesheet keeps `outputMappings` into the original input files through
436
+ inlining and qualifier wrappers. `nativeCSS` and `generatedCSS` remain metadata
437
+ views of the separately compiled files; use `css` for delivery.
438
+
439
+ The Node rendered stylesheet path uses this graph compilation for file imports.
440
+ Qualified imports may contain native rules, including native `@apply` calls, but
441
+ global definitions must come through unqualified imports or references. If
442
+ boundaries require multiple assets, use stylesheet delivery options;
443
+ the single-output path reports `CSS_IMPORT_ERROR` instead of losing those assets.
444
+
445
+ With `delivery` options, `compileRenderedStylesheet()` returns `entry`,
446
+ `stylesheets`, and `resources`. The stylesheet list includes the entry; publish
447
+ all assets at their assigned `href` values. Each stylesheet has a serialized
448
+ `sourceMap` for its final CSS. The entry's `css` equals the top-level result and
449
+ contains generated globals once, after its retained import rules. Sass dependencies
450
+ and original diagnostic locations remain attached to their source files.
451
+
452
+ ### Ordered native composition
453
+
454
+ Direct `compileManifest()`, stylesheet compilation and local transforms return
455
+ final `css` with native and lowered rules in their original positions. Repeated
456
+ selectors retain their cascade order; anonymous layers remain the same layer.
457
+ Do not reconstruct this output by concatenating `nativeCSS` and `generatedCSS`:
458
+ those fields are separate metadata views.
459
+
460
+ For raw compiler binding calls, forward the parser's `nativeOutput` together with
461
+ `manifestInput`, `styleDefinitions` and `warnings` to `lowerCSSDirectives()`.
462
+ Rust returns ordered `css` and its UTF-16 `outputMappings`; the Node stylesheet
463
+ host chains those mappings through import and Sass origins. Treat `nativeOutput`
464
+ as a compiler-produced plan and pass it unchanged. Invalid or overlapping slot
465
+ ranges are rejected. The plan stays in compiler data and is not part of a runtime
466
+ manifest or program.
@@ -0,0 +1,42 @@
1
+ import { MasterCSSDiagnostic } from "@master/css-schema";
2
+ import { ValidationSource } from "./value-validation.js";
3
+ import { MasterCSSManifest } from "@master/css-schema/manifest";
4
+ import { MasterCSSCompileManifestOptions, MasterCSSCompileManifestResult, MasterCSSCompileOptions, MasterCSSCompileResult, MasterCSSCompileStylesheetsRequest, MasterCSSCompileStylesheetsResult, MasterCSSCompilerInspection, MasterCSSPrepareStylesheetBundleRequest, MasterCSSRenderStylesheetBundleRequest, MasterCSSStylesheetAsset, MasterCSSStylesheetBundle } from "./index.js";
5
+ import { CompileCSSResult } from "./contracts.js";
6
+ import { BindingCompilerSession } from "./session.js";
7
+ /** @internal */
8
+ declare function toMasterCSSCompileResultInternal(result: CompileCSSResult, onDiagnostic?: (diagnostic: MasterCSSDiagnostic) => void, validation?: 'report' | 'error', origin?: Omit<ValidationSource, 'css'>): MasterCSSCompileResult;
9
+ interface InternalManifestCompileResult {
10
+ readonly notices?: CompileCSSResult['notices'];
11
+ readonly css: string;
12
+ readonly nativeCSS: string;
13
+ readonly generatedCSS: string;
14
+ readonly dependencies: readonly string[];
15
+ readonly classNames: readonly string[];
16
+ readonly nativeClassNames: readonly string[];
17
+ readonly warnings: readonly string[];
18
+ readonly manifest: MasterCSSManifest;
19
+ readonly directives: CompileCSSResult;
20
+ readonly outputMappings?: CompileCSSResult['outputMappings'];
21
+ readonly sourceTexts?: Record<string, string>;
22
+ }
23
+ /** @internal */
24
+ declare function toMasterCSSCompileManifestResultInternal(result: InternalManifestCompileResult, onDiagnostic?: (diagnostic: MasterCSSDiagnostic) => void, validation?: 'report' | 'error'): MasterCSSCompileManifestResult;
25
+ declare class MasterCSSCompiler implements Disposable {
26
+ #private;
27
+ private constructor();
28
+ get binding(): import("@master/css-binding").MasterCSSResolvedBinding;
29
+ inspectCSS(source: string): MasterCSSCompilerInspection;
30
+ compileCSS(source: string, options?: MasterCSSCompileOptions): MasterCSSCompileResult;
31
+ compileManifest(source: string, options: MasterCSSCompileManifestOptions): MasterCSSCompileManifestResult;
32
+ dispose(): void;
33
+ prepareStylesheetBundle(request: MasterCSSPrepareStylesheetBundleRequest): MasterCSSStylesheetBundle;
34
+ renderStylesheetBundle(request: MasterCSSRenderStylesheetBundleRequest): readonly MasterCSSStylesheetAsset[];
35
+ compareProjectSnapshots(request: import('./index.js').MasterCSSProjectComparisonRequest): import('./index.js').MasterCSSProjectComparison;
36
+ compileStylesheets(request: MasterCSSCompileStylesheetsRequest, options?: MasterCSSCompileOptions): MasterCSSCompileStylesheetsResult;
37
+ [Symbol.dispose](): void;
38
+ private assertActive;
39
+ }
40
+ /** @internal */
41
+ declare function bindCompilerSessionInternal(session: BindingCompilerSession): MasterCSSCompiler;
42
+ export { MasterCSSCompiler, bindCompilerSessionInternal, toMasterCSSCompileManifestResultInternal, toMasterCSSCompileResultInternal };