@stillwind/integration 0.8.0 → 0.9.0

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/CHANGELOG.md +180 -0
  2. package/dist/astro/development.d.ts +2 -0
  3. package/dist/astro/development.js +2 -0
  4. package/dist/astro/development.js.map +1 -1
  5. package/dist/astro/index.d.ts +1 -1
  6. package/dist/astro/index.js +8 -2
  7. package/dist/astro/index.js.map +1 -1
  8. package/dist/{emission-BVi5aRbb.js → emission-BpaN4Z4m.js} +212 -69
  9. package/dist/emission-BpaN4Z4m.js.map +1 -0
  10. package/dist/fresh/index.d.ts +1 -1
  11. package/dist/fresh/index.js +1 -1
  12. package/dist/{index-DFfbZxNT.d.ts → index-B6EtrWus.d.ts} +2 -2
  13. package/dist/loader-cache-DfOGY8AJ.js +231 -0
  14. package/dist/loader-cache-DfOGY8AJ.js.map +1 -0
  15. package/dist/next/css-loader.d.ts +5 -2
  16. package/dist/next/css-loader.js +7 -2
  17. package/dist/next/css-loader.js.map +1 -1
  18. package/dist/next/index.js +2 -0
  19. package/dist/next/index.js.map +1 -1
  20. package/dist/{node-loader-D-3Ynpy1.d.ts → node-loader-Bqg7E5zq.d.ts} +6 -3
  21. package/dist/nuxt/index.d.ts +2 -2
  22. package/dist/nuxt/index.js +2 -1
  23. package/dist/nuxt/index.js.map +1 -1
  24. package/dist/{plugin-aV0zIIAe.d.ts → plugin-BAG0ZI1X.d.ts} +58 -6
  25. package/dist/{plugin-mPiBLdqa.js → plugin-D-45o54j.js} +5 -2
  26. package/dist/plugin-D-45o54j.js.map +1 -0
  27. package/dist/{plugin-ByYcpBcE.js → plugin-DQH8QlYh.js} +331 -36
  28. package/dist/plugin-DQH8QlYh.js.map +1 -0
  29. package/dist/{project-DUGu8g_L.d.ts → project-B_KFQist.d.ts} +2 -2
  30. package/dist/project-egWF2vWJ.js +428 -0
  31. package/dist/project-egWF2vWJ.js.map +1 -0
  32. package/dist/{project-BNw0nZBE.d.ts → project-mB7CODIs.d.ts} +46 -7
  33. package/dist/rsbuild/index.d.ts +4 -1
  34. package/dist/rsbuild/index.js +2 -2
  35. package/dist/rsbuild/index.js.map +1 -1
  36. package/dist/rspack/index.d.ts +1 -1
  37. package/dist/rspack/index.js +1 -1
  38. package/dist/session-Cxf4D6oQ.d.ts +163 -0
  39. package/dist/source-entries-J5azZ_-z.js +350 -0
  40. package/dist/source-entries-J5azZ_-z.js.map +1 -0
  41. package/dist/turbopack/css-loader.d.ts +5 -2
  42. package/dist/turbopack/css-loader.js +53 -17
  43. package/dist/turbopack/css-loader.js.map +1 -1
  44. package/dist/turbopack/index.d.ts +2 -2
  45. package/dist/turbopack/loader.d.ts +3 -2
  46. package/dist/turbopack/loader.js +10 -4
  47. package/dist/turbopack/loader.js.map +1 -1
  48. package/dist/turbopack/node-loader.d.ts +1 -1
  49. package/dist/turbopack/node-loader.js +1 -0
  50. package/dist/turbopack/node-loader.js.map +1 -1
  51. package/dist/vite/index.d.ts +2 -2
  52. package/dist/vite/index.js +1 -1
  53. package/dist/vite/runtime.d.ts +10 -3
  54. package/dist/vite/runtime.js +8 -1
  55. package/dist/vite/runtime.js.map +1 -1
  56. package/dist/webpack/css-loader.js +1 -1
  57. package/dist/webpack/document-loader.d.ts +4 -1
  58. package/dist/webpack/document-loader.js +5 -2
  59. package/dist/webpack/document-loader.js.map +1 -1
  60. package/dist/webpack/fragment-loader.d.ts +1 -0
  61. package/dist/webpack/fragment-loader.js +1 -0
  62. package/dist/webpack/fragment-loader.js.map +1 -1
  63. package/dist/webpack/index.d.ts +1 -1
  64. package/dist/webpack/index.js +1 -1
  65. package/dist/webpack/loader.js +15 -21
  66. package/dist/webpack/loader.js.map +1 -1
  67. package/dist/webpack/source-loader.d.ts +1 -0
  68. package/dist/webpack/source-loader.js +1 -0
  69. package/dist/webpack/source-loader.js.map +1 -1
  70. package/package.json +19 -17
  71. package/dist/binding-files-Ds5NpyVV.js +0 -45
  72. package/dist/binding-files-Ds5NpyVV.js.map +0 -1
  73. package/dist/emission-BVi5aRbb.js.map +0 -1
  74. package/dist/plugin-ByYcpBcE.js.map +0 -1
  75. package/dist/plugin-mPiBLdqa.js.map +0 -1
  76. package/dist/project-C3IH7geC.js +0 -182
  77. package/dist/project-C3IH7geC.js.map +0 -1
  78. package/dist/session-B9_rp9TH.d.ts +0 -72
  79. package/dist/session-DHUCQMG5.js +0 -117
  80. package/dist/session-DHUCQMG5.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"loader.js","names":[],"sources":["../../src/webpack/css-value.ts","../../src/webpack/loader.ts"],"sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nimport type { NativeStylesheetPart } from \"@stillwind/native\";\n\n/** An asset referenced by CSS returned through an explicit module value. */\nexport interface CssValueResource {\n /** Token in the CSS text that the fragment loader replaces with an asset URL. */\n placeholder: string;\n /** Resolver identity of the asset, including any resource query. */\n id: string;\n /** Module request relative to the producer directory, stored in the fragment payload. */\n request: string;\n}\n\n/** CSS and asset references encoded in the query of an isolated fragment loader request. */\nexport interface CssFragment {\n /** CSS text for one stylesheet occurrence. */\n css: string;\n /** Resolved assets whose placeholders occur in this fragment. */\n resources: CssValueResource[];\n}\n\n/**\n * Generates a module that imports CSS fragments and exports their ordered values.\n *\n * Each fragment request encodes its CSS and referenced assets. Equal payloads produce equal\n * requests, while the value retains occurrence order.\n *\n * @param parts - Stylesheet occurrences in cascade order. Repeated occurrences keep their\n * positions.\n * @param resources - Resolved assets whose placeholders may occur in the parts.\n * @returns JavaScript exporting `parts`, the joined `css` string, and the same string as its\n * default export.\n */\nexport function cssValueModule(\n parts: readonly NativeStylesheetPart[],\n resources: readonly CssValueResource[],\n): string {\n const imports = parts.map((part, index) => {\n const payload = Buffer.from(\n JSON.stringify({\n css: part.css,\n resources: resources.filter((resource) => part.css.includes(resource.placeholder)),\n } satisfies CssFragment),\n ).toString(\"base64url\");\n const request = `!!${fileURLToPath(\n new URL(\"./fragment-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n )}!${fileURLToPath(\n new URL(\"./stillwind-fragment.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n )}?css=${payload}`;\n return `import { css as p${index} } from ${JSON.stringify(request)};\\n`;\n });\n const entries = parts.map(\n (part, index) =>\n ` { key: ${JSON.stringify(part.key)}, banners: ${JSON.stringify(part.banners)}, css: p${index} },\\n`,\n );\n return [\n \"// Stillwind CSS value (webpack)\\n\",\n 'import { cssText } from \"stillwind/css\";\\n',\n ...imports,\n \"\\n\",\n \"export const parts = [\\n\",\n ...entries,\n \"];\\n\",\n \"export const css = cssText(parts);\\n\",\n \"export default css;\\n\",\n ].join(\"\");\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport { resolveIntegrationConfig } from \"@stillwind/config/node\";\nimport {\n cleanModuleId,\n composeModuleSourceMap,\n cssEntrypoint,\n finalizeModuleWithMap,\n loadCssGraph,\n moduleSourceMap,\n nodePluginHost,\n warnRejectedNames,\n type UpstreamSourceMap,\n} from \"@stillwind/host\";\n\nimport { buildCompilerOptions, IntegrationSession } from \"../session.ts\";\nimport { cssValueModule, type CssValueResource } from \"./css-value.ts\";\nimport { recordProducer } from \"./emission.ts\";\nimport { createLoaderHost, watchCompilerFiles } from \"./host.ts\";\nimport {\n classifyRequest,\n relativeRequest,\n requestOptions,\n virtualRequest,\n type LoaderOptions,\n} from \"./requests.ts\";\nimport {\n loaderCompletion,\n type LoaderAdditionalData,\n type SourceTransformContext,\n} from \"./source-map-loader.ts\";\nimport { sourceDescriptor } from \"./sources.ts\";\n\n/**\n * Hashes transformed text to recognize a repeated pass through the same resource.\n *\n * @param source - Exact source text received or produced by the loader.\n * @returns A SHA-256 fingerprint encoded as hexadecimal.\n */\nconst fingerprint = (source: string) => createHash(\"sha256\").update(source).digest(\"hex\");\n\n/**\n * Compiles a producer, CSS projection, or explicit CSS value through the webpack loader protocol.\n *\n * The loader context supplies resolution, file dependencies, options, and an asynchronous callback.\n * Automatic document CSS and projections require `StillwindPlugin` to be installed before\n * compilation. Results and failures are delivered through the callback. SFC transforms also store\n * their code and map in `this.data` for framework map composition.\n *\n * @param this - Active loader context whose data and module metadata retain successful producer transforms.\n * @param source - Source supplied by the preceding loaders. CSS subrequests read the original\n * resource instead.\n * @param inputMap - Map from the supplied source to its original source, when available.\n * @param additionalData - Metadata from preceding loaders, including a prior Stillwind transform\n * fingerprint.\n * @returns No synchronous source. Pass-through and asynchronous results use the loader callback.\n */\nexport default function webpackLoader(\n this: SourceTransformContext<LoaderOptions>,\n source: string,\n inputMap: UpstreamSourceMap,\n additionalData?: LoaderAdditionalData,\n) {\n const callback = loaderCompletion(this);\n const text = String(source);\n const { projection, cssValue, sfc, id, passthrough } = classifyRequest(\n this.resourcePath,\n this.resourceQuery,\n );\n const prior = additionalData?.stillwind?.sourceTransform;\n // Framework loaders can clone the same rule into a subrequest's chain.\n // Skip only an identical output already produced for this resource.\n if (prior?.resource === id && prior.fingerprint === fingerprint(text)) {\n return callback(null, source, inputMap, additionalData);\n }\n if (passthrough) {\n return callback(null, source, inputMap);\n }\n if (\n !projection &&\n !cssValue &&\n !/stillwind\\/(?:alpine|astro|lit|preact|qwik|react|solid|svelte|vanilla|vue|module-css)/.test(\n text,\n )\n ) {\n return callback(null, source, inputMap);\n }\n const supplied = requestOptions(this.getOptions());\n let compiler: IntegrationSession | undefined;\n const {\n read,\n readDependency,\n dependencySources,\n resolveCss,\n resolveAsset,\n resolve,\n watch,\n warn,\n } = createLoaderHost(this, import.meta.filename);\n void (async () => {\n const configuration =\n this._compilation?.__stillwindConfiguration ??\n (await resolveIntegrationConfig(supplied, this.rootContext));\n for (const file of configuration.dependencies) {\n this.addDependency(file);\n }\n for (const file of configuration.missing) {\n this.addMissingDependency(file);\n }\n const { config } = configuration;\n if (config.naming) {\n this.cacheable(false);\n }\n /**\n * Creates a virtual module request using this source file's framework and compiler settings.\n * @param query - Stillwind virtual query selecting the requested CSS or value module.\n * @returns An inline loader request retaining the resource path and resolved configuration.\n */\n const request = (query: string) =>\n virtualRequest(this.resourcePath, sfc, config, import.meta.filename, query, supplied);\n watchCompilerFiles(watch);\n const root = path.resolve(this.rootContext, config.root ?? \".\");\n const css = path.resolve(root, cssEntrypoint(config));\n const loaded = await loadCssGraph(\n css,\n buildCompilerOptions(config),\n {\n resolve: resolveCss,\n read,\n documentUri: (id) => pathToFileURL(id).href,\n sourceMapSource: (id) => pathToFileURL(id).href,\n watch,\n watchDirectory: (id) => this.addContextDependency(id),\n plugins: nodePluginHost,\n },\n undefined,\n undefined,\n {\n plugins: config.plugins,\n tailwind: config.tailwind,\n important: config.important,\n root,\n },\n );\n compiler = new IntegrationSession(\n root,\n loaded.loader,\n config,\n false,\n this.mode === \"development\" ? \"development\" : \"release\",\n loaded.plugins,\n );\n const session = compiler.native;\n const output = await compiler.compile(\n projection || cssValue ? await read(this.resourcePath) : text,\n projection || cssValue ? this.resourcePath : id,\n {\n describe: (id) => sourceDescriptor(root, id),\n resolve,\n read: readDependency,\n watch,\n warn,\n },\n {\n stylesheetImports:\n sfc && !projection && !cssValue && config.automatic !== false\n ? [request(\"stillwind.css\")]\n : undefined,\n moduleCssImport: request(\"stillwind-module-css\"),\n },\n );\n if (!output?.code) {\n return callback(null, projection ? \"\" : source, projection ? null : inputMap);\n }\n const plan = session.planStylesheet({\n modules: [output.moduleId],\n coverage: { kind: \"observed\" },\n placement: \"document\",\n });\n warnRejectedNames(plan.rejectedNames, warn);\n\n const valueResources: CssValueResource[] = [];\n for (const resource of [...loaded.resources, ...plan.resources]) {\n const owner =\n \"moduleId\" in resource ? compiler.resolverId(resource.moduleId) : resource.sourceName;\n const resolved = await resolveAsset(resource.specifier, owner);\n if (!resolved) {\n throw new Error(`Cannot resolve Stillwind resource ${resource.specifier} from ${owner}`);\n }\n watch(cleanModuleId(resolved));\n if (plan.css.includes(resource.placeholder)) {\n valueResources.push({\n placeholder: resource.placeholder,\n id: resolved,\n request: relativeRequest(path.dirname(this.resourcePath), resolved),\n });\n }\n }\n const carrier = relativeRequest(\n path.dirname(this.resourcePath),\n fileURLToPath(\n new URL(\"./stillwind-webpack.css\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n );\n if (cssValue) {\n return callback(null, cssValueModule(plan.parts, valueResources), null);\n }\n const automatic = (!output.hasModuleCssImport && config.automatic !== false) || projection;\n if (automatic) {\n recordProducer(this, {\n source: text,\n id,\n root,\n config: config,\n manual: false,\n upstream: inputMap\n ? {\n id: this.resourcePath,\n sourceMapSource: sourceDescriptor(root, id).document.uri,\n map: typeof inputMap === \"string\" ? inputMap : JSON.stringify(inputMap),\n }\n : undefined,\n dependencies: await Promise.all(\n [...dependencySources].map(async ([id, pending]) => {\n const { source, map } = await pending;\n return {\n id,\n source,\n upstream: map\n ? {\n id: cleanModuleId(id),\n sourceMapSource: sourceDescriptor(root, id).document.uri,\n map: typeof map === \"string\" ? map : JSON.stringify(map),\n }\n : undefined,\n };\n }),\n ),\n });\n }\n const cssImport = `import ${JSON.stringify(carrier + \"?stillwind-document\")};\\n`;\n if (projection) {\n return callback(null, cssImport);\n }\n const finalized = finalizeModuleWithMap(output.code);\n // Append synthetic imports so RSC directives remain the first statements.\n const code =\n sfc || !automatic\n ? finalized.code\n : finalized.code.slice(finalized.prefix.length) + \"\\n\" + finalized.prefix + cssImport;\n const map = moduleSourceMap(\n text,\n output.code,\n this.resourcePath,\n output.mappings,\n finalized.removed,\n \"\",\n );\n const composedMap = composeModuleSourceMap(map, inputMap);\n if (sfc && this.data) {\n this.data.stillwindSourceTransform = {\n code,\n map: composedMap,\n resource: id,\n };\n }\n const metadata: LoaderAdditionalData = {\n ...additionalData,\n stillwind: {\n coverage: plan.coverage,\n designSystem: plan.designSystem,\n producers: plan.producers,\n sourceTransform: {\n resource: id,\n fingerprint: fingerprint(code),\n },\n },\n };\n callback(null, code, composedMap, metadata);\n })()\n .catch((error) => callback(error))\n .finally(() => compiler?.close());\n}\n\n/**\n * Keeps webpack pitch data available for sharing transformed SFC code and maps with framework\n * loaders.\n */\nexport function pitch() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,eACd,OACA,WACQ;CACR,MAAM,UAAU,MAAM,KAAK,MAAM,UAAU;EACzC,MAAM,UAAU,OAAO,KACrB,KAAK,UAAU;GACb,KAAK,KAAK;GACV,WAAW,UAAU,QAAQ,aAAa,KAAK,IAAI,SAAS,SAAS,WAAW,CAAC;EACnF,CAAuB,CACzB,CAAC,CAAC,SAAS,WAAW;EACtB,MAAM,UAAU,KAAK,cACnB,IAAI,IAAI,wBAAwB,YAAY,QAAQ,gCAAgC,CAAC,CACvF,EAAE,GAAG,cACH,IAAI,IAAI,2BAA2B,YAAY,QAAQ,gCAAgC,CAAC,CAC1F,EAAE,OAAO;EACT,OAAO,oBAAoB,MAAM,UAAU,KAAK,UAAU,OAAO,EAAE;CACrE,CAAC;CACD,MAAM,UAAU,MAAM,KACnB,MAAM,UACL,YAAY,KAAK,UAAU,KAAK,GAAG,EAAE,aAAa,KAAK,UAAU,KAAK,OAAO,EAAE,UAAU,MAAM,MACnG;CACA,OAAO;EACL;EACA;EACA,GAAG;EACH;EACA;EACA,GAAG;EACH;EACA;EACA;CACF,CAAC,CAAC,KAAK,EAAE;AACX;;;;;;;;AC1BA,MAAM,eAAe,WAAmB,WAAW,QAAQ,CAAC,CAAC,OAAO,MAAM,CAAC,CAAC,OAAO,KAAK;;;;;;;;;;;;;;;;;AAkBxF,SAAwB,cAEtB,QACA,UACA,gBACA;CACA,MAAM,WAAW,iBAAiB,IAAI;CACtC,MAAM,OAAO,OAAO,MAAM;CAC1B,MAAM,EAAE,YAAY,UAAU,KAAK,IAAI,gBAAgB,gBACrD,KAAK,cACL,KAAK,aACP;CACA,MAAM,QAAQ,gBAAgB,WAAW;CAGzC,IAAI,OAAO,aAAa,MAAM,MAAM,gBAAgB,YAAY,IAAI,GAClE,OAAO,SAAS,MAAM,QA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AAY,IAAI;IAC/B;GACF;EACF;EACA,SAAS,MAAM,MAAM,aAAa,QAAQ;CAC5C,EAAA,CAAG,CAAC,CACD,OAAO,UAAU,SAAS,KAAK,CAAC,CAAC,CACjC,cAAc,UAAU,MAAM,CAAC;AACpC;;;;;AAMA,SAAgB,QAAQ,CAAC"}
1
+ {"version":3,"file":"loader.js","names":[],"sources":["../../src/webpack/css-value.ts","../../src/webpack/loader.ts"],"sourcesContent":["import { fileURLToPath } from \"node:url\";\n\nimport type { NativeStylesheetPart } from \"@stillwind/native\";\n\n/** An asset referenced by CSS returned through an explicit module value. */\nexport interface CssValueResource {\n /** Token in the CSS text that the fragment loader replaces with an asset URL. */\n placeholder: string;\n /** Resolver identity of the asset, including any resource query. */\n id: string;\n /** Module request relative to the producer directory, stored in the fragment payload. */\n request: string;\n}\n\n/** CSS and asset references encoded in the query of an isolated fragment loader request. */\nexport interface CssFragment {\n /** CSS text for one stylesheet occurrence. */\n css: string;\n /** Resolved assets whose placeholders occur in this fragment. */\n resources: CssValueResource[];\n}\n\n/**\n * Generates a module that imports CSS fragments and exports their ordered values.\n *\n * Each fragment request encodes its CSS and referenced assets. Equal payloads produce equal\n * requests, while the value retains occurrence order.\n *\n * @param parts - Stylesheet occurrences in cascade order. Repeated occurrences keep their\n * positions.\n * @param resources - Resolved assets whose placeholders may occur in the parts.\n * @returns JavaScript exporting `parts`, the joined `css` string, and the same string as its\n * default export.\n */\nexport function cssValueModule(\n parts: readonly NativeStylesheetPart[],\n resources: readonly CssValueResource[],\n): string {\n const imports = parts.map((part, index) => {\n const payload = Buffer.from(\n JSON.stringify({\n css: part.css,\n resources: resources.filter((resource) => part.css.includes(resource.placeholder)),\n } satisfies CssFragment),\n ).toString(\"base64url\");\n const request = `!!${fileURLToPath(\n new URL(\"./fragment-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n )}!${fileURLToPath(\n new URL(\"./stillwind-fragment.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n )}?css=${payload}`;\n return `import { css as p${index} } from ${JSON.stringify(request)};\\n`;\n });\n const entries = parts.map(\n (part, index) =>\n ` { key: ${JSON.stringify(part.key)}, banners: ${JSON.stringify(part.banners)}, css: p${index} },\\n`,\n );\n return [\n \"// Stillwind CSS value (webpack)\\n\",\n 'import { cssText } from \"stillwind/css\";\\n',\n ...imports,\n \"\\n\",\n \"export const parts = [\\n\",\n ...entries,\n \"];\\n\",\n \"export const css = cssText(parts);\\n\",\n \"export default css;\\n\",\n ].join(\"\");\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { resolveIntegrationConfig } from \"@stillwind/config/node\";\nimport {\n cleanModuleId,\n composeModuleSourceMap,\n finalizeModuleWithMap,\n moduleSourceMap,\n warnRejectedNames,\n type UpstreamSourceMap,\n} from \"@stillwind/host\";\n\nimport { cssValueModule, type CssValueResource } from \"./css-value.ts\";\nimport { recordProducer } from \"./emission.ts\";\nimport { createLoaderHost, watchCompilerFiles } from \"./host.ts\";\nimport { useProject } from \"./project.ts\";\nimport {\n classifyRequest,\n relativeRequest,\n requestOptions,\n virtualRequest,\n type LoaderOptions,\n} from \"./requests.ts\";\nimport {\n loaderCompletion,\n type LoaderAdditionalData,\n type SourceTransformContext,\n} from \"./source-map-loader.ts\";\nimport { sourceDescriptor } from \"./sources.ts\";\n\n/**\n * Hashes transformed text to recognize a repeated pass through the same resource.\n *\n * @param source - Exact source text received or produced by the loader.\n * @returns A SHA-256 fingerprint encoded as hexadecimal.\n */\nconst fingerprint = (source: string) => createHash(\"sha256\").update(source).digest(\"hex\");\n\n/**\n * Compiles a producer, CSS projection, or explicit CSS value through the webpack loader protocol.\n *\n * The loader context supplies resolution, file dependencies, options, and an asynchronous callback.\n * Automatic document CSS and projections require `StillwindPlugin` to be installed before\n * compilation. Results and failures are delivered through the callback. SFC transforms also store\n * their code and map in `this.data` for framework map composition.\n *\n * @param this - Active loader context whose data and module metadata retain successful producer transforms.\n * @param source - Source supplied by the preceding loaders. CSS subrequests read the original\n * resource instead.\n * @param inputMap - Map from the supplied source to its original source, when available.\n * @param additionalData - Metadata from preceding loaders, including a prior Stillwind transform\n * fingerprint.\n * @returns No synchronous source. Pass-through and asynchronous results use the loader callback.\n */\nexport default function webpackLoader(\n this: SourceTransformContext<LoaderOptions>,\n source: string,\n inputMap: UpstreamSourceMap,\n additionalData?: LoaderAdditionalData,\n) {\n const callback = loaderCompletion(this);\n const text = String(source);\n const { projection, cssValue, sfc, id, passthrough } = classifyRequest(\n this.resourcePath,\n this.resourceQuery,\n );\n const prior = additionalData?.stillwind?.sourceTransform;\n // Framework loaders can clone the same rule into a subrequest's chain.\n // Skip only an identical output already produced for this resource.\n if (prior?.resource === id && prior.fingerprint === fingerprint(text)) {\n return callback(null, source, inputMap, additionalData);\n }\n if (passthrough) {\n return callback(null, source, inputMap);\n }\n if (\n !projection &&\n !cssValue &&\n !/stillwind\\/(?:alpine|astro|lit|preact|qwik|react|solid|svelte|vanilla|vue|module-css)/.test(\n text,\n )\n ) {\n return callback(null, source, inputMap);\n }\n const supplied = requestOptions(this.getOptions());\n let release: (() => void) | undefined;\n const {\n read,\n readDependency,\n dependencySources,\n resolveCss,\n resolveAsset,\n resolve,\n watch,\n warn,\n } = createLoaderHost(this, import.meta.filename);\n void (async () => {\n const configuration =\n this._compilation?.__stillwindConfiguration ??\n (await resolveIntegrationConfig(supplied, this.rootContext));\n for (const file of configuration.dependencies) {\n this.addDependency(file);\n }\n for (const file of configuration.missing) {\n this.addMissingDependency(file);\n }\n const { config } = configuration;\n if (config.naming) {\n this.cacheable(false);\n }\n /**\n * Creates a virtual module request using this source file's framework and compiler settings.\n *\n * @param query - Stillwind virtual query selecting the requested CSS or value module.\n * @returns An inline loader request retaining the resource path and resolved configuration.\n */\n const request = (query: string) =>\n virtualRequest(this.resourcePath, sfc, config, import.meta.filename, query, supplied);\n watchCompilerFiles(watch);\n const root = path.resolve(this.rootContext, config.root ?? \".\");\n const lease = await useProject(\n this,\n configuration.scope,\n config,\n root,\n this.mode === \"development\" ? \"development\" : \"release\",\n { read, resolveCss },\n );\n release = lease.done;\n const { loaded, compiler, outputs } = lease.value;\n const session = compiler.native;\n const output = await compiler.compile(\n projection || cssValue ? await read(this.resourcePath) : text,\n projection || cssValue ? this.resourcePath : id,\n {\n describe: (id) => sourceDescriptor(root, id),\n resolve,\n read: readDependency,\n watch,\n warn,\n },\n {\n stylesheetImports:\n sfc && !projection && !cssValue && config.automatic !== false\n ? [request(\"stillwind.css\")]\n : undefined,\n moduleCssImport: request(\"stillwind-module-css\"),\n },\n );\n if (!projection && !cssValue) {\n outputs.set(id, { source: text, moduleId: output?.moduleId });\n }\n if (!output?.code) {\n return callback(null, projection ? \"\" : source, projection ? null : inputMap);\n }\n const plan = session.planStylesheet({\n modules: [output.moduleId],\n coverage: { kind: \"observed\" },\n placement: \"document\",\n });\n warnRejectedNames(plan.rejectedNames, warn);\n\n const valueResources: CssValueResource[] = [];\n for (const resource of [...loaded.resources, ...plan.resources]) {\n const owner =\n \"moduleId\" in resource ? compiler.resolverId(resource.moduleId) : resource.sourceName;\n const resolved = await resolveAsset(resource.specifier, owner);\n if (!resolved) {\n throw new Error(`Cannot resolve Stillwind resource ${resource.specifier} from ${owner}`);\n }\n watch(cleanModuleId(resolved));\n if (plan.css.includes(resource.placeholder)) {\n valueResources.push({\n placeholder: resource.placeholder,\n id: resolved,\n request: relativeRequest(path.dirname(this.resourcePath), resolved),\n });\n }\n }\n const carrier = relativeRequest(\n path.dirname(this.resourcePath),\n fileURLToPath(\n new URL(\"./stillwind-webpack.css\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n );\n if (cssValue) {\n return callback(null, cssValueModule(plan.parts, valueResources), null);\n }\n const automatic = (!output.hasModuleCssImport && config.automatic !== false) || projection;\n if (automatic) {\n recordProducer(this, {\n source: text,\n id,\n root,\n config: config,\n manual: false,\n upstream: inputMap\n ? {\n id: this.resourcePath,\n sourceMapSource: sourceDescriptor(root, id).document.uri,\n map: typeof inputMap === \"string\" ? inputMap : JSON.stringify(inputMap),\n }\n : undefined,\n // The shared project can read the producer itself as a dependency. Its source and\n // upstream map are recorded above, and reconstruction composes each recorded upstream\n // map once, so a second copy would map the stylesheet's positions twice.\n dependencies: await Promise.all(\n [...dependencySources]\n .filter(([dependency]) => dependency !== id)\n .map(async ([id, pending]) => {\n const { source, map } = await pending;\n return {\n id,\n source,\n upstream: map\n ? {\n id: cleanModuleId(id),\n sourceMapSource: sourceDescriptor(root, id).document.uri,\n map: typeof map === \"string\" ? map : JSON.stringify(map),\n }\n : undefined,\n };\n }),\n ),\n });\n }\n const cssImport = `import ${JSON.stringify(carrier + \"?stillwind-document\")};\\n`;\n if (projection) {\n return callback(null, cssImport);\n }\n const finalized = finalizeModuleWithMap(output.code);\n // Append synthetic imports so RSC directives remain the first statements.\n const code =\n sfc || !automatic\n ? finalized.code\n : finalized.code.slice(finalized.prefix.length) + \"\\n\" + finalized.prefix + cssImport;\n const map = moduleSourceMap(\n text,\n output.code,\n this.resourcePath,\n output.mappings,\n finalized.removed,\n \"\",\n );\n const composedMap = composeModuleSourceMap(map, inputMap);\n if (sfc && this.data) {\n this.data.stillwindSourceTransform = {\n code,\n map: composedMap,\n resource: id,\n };\n }\n const metadata: LoaderAdditionalData = {\n ...additionalData,\n stillwind: {\n coverage: plan.coverage,\n designSystem: plan.designSystem,\n producers: plan.producers,\n sourceTransform: {\n resource: id,\n fingerprint: fingerprint(code),\n },\n },\n };\n callback(null, code, composedMap, metadata);\n })()\n .catch((error) => callback(error))\n .finally(() => release?.());\n}\n\n/**\n * Keeps webpack pitch data available for sharing transformed SFC code and maps with framework\n * loaders.\n */\nexport function pitch() {}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAkCA,SAAgB,eACd,OACA,WACQ;CACR,MAAM,UAAU,MAAM,KAAK,MAAM,UAAU;EACzC,MAAM,UAAU,OAAO,KACrB,KAAK,UAAU;GACb,KAAK,KAAK;GACV,WA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AAI,aAAa;IAC5B,MAAM,EAAE,QAAQ,QAAQ,MAAM;IAC9B,OAAO;KACL;KACA;KACA,UAAU,MACN;MACE,IAAI,cAAc,EAAE;MACpB,iBAAiB,iBAAiB,MAAM,EAAE,CAAC,CAAC,SAAS;MACrD,KAAK,OAAO,QAAQ,WAAW,MAAM,KAAK,UAAU,GAAG;KACzD,IACA,KAAA;IACN;GACF,CAAC,CACL;EACF,CAAC;EAEH,MAAM,YAAY,UAAU,KAAK,UAAU,UAAU,qBAAqB,EAAE;EAC5E,IAAI,YACF,OAAO,SAAS,MAAM,SAAS;EAEjC,MAAM,YAAY,sBAAsB,OAAO,IAAI;EAEnD,MAAM,OACJ,OAAO,CAAC,YACJ,UAAU,OACV,UAAU,KAAK,MAAM,UAAU,OAAO,MAAM,IAAI,OAAO,UAAU,SAAS;EAChF,MAAM,MAAM,gBACV,MACA,OAAO,MACP,KAAK,cACL,OAAO,UACP,UAAU,SACV,EACF;EACA,MAAM,cAAc,uBAAuB,KAAK,QAAQ;EACxD,IAAI,OAAO,KAAK,MACd,KAAK,KAAK,2BAA2B;GACnC;GACA,KAAK;GACL,UAAU;EACZ;EAEF,MAAM,WAAiC;GACrC,GAAG;GACH,WAAW;IACT,UAAU,KAAK;IACf,cAAc,KAAK;IACnB,WAAW,KAAK;IAChB,iBAAiB;KACf,UAAU;KACV,aAAa,YAAY,IAAI;IAC/B;GACF;EACF;EACA,SAAS,MAAM,MAAM,aAAa,QAAQ;CAC5C,EAAA,CAAG,CAAC,CACD,OAAO,UAAU,SAAS,KAAK,CAAC,CAAC,CACjC,cAAc,UAAU,CAAC;AAC9B;;;;;AAMA,SAAgB,QAAQ,CAAC"}
@@ -2,6 +2,7 @@ import { UpstreamSourceMap } from "@stillwind/host";
2
2
  import { LoaderContext } from "webpack";
3
3
  /**
4
4
  * Returns source text as a module value so importModule never executes application code.
5
+ *
5
6
  * @param this - Loader context retained for compatibility with the bundler loader protocol.
6
7
  * @param source - Source produced by preceding loaders, serialized as a string literal.
7
8
  * @param map - Optional upstream map serialized as a module export. Omission exports null.
@@ -1,6 +1,7 @@
1
1
  // src/webpack/source-loader.ts
2
2
  /**
3
3
  * Returns source text as a module value so importModule never executes application code.
4
+ *
4
5
  * @param this - Loader context retained for compatibility with the bundler loader protocol.
5
6
  * @param source - Source produced by preceding loaders, serialized as a string literal.
6
7
  * @param map - Optional upstream map serialized as a module export. Omission exports null.
@@ -1 +1 @@
1
- {"version":3,"file":"source-loader.js","names":[],"sources":["../../src/webpack/source-loader.ts"],"sourcesContent":["import type { UpstreamSourceMap } from \"@stillwind/host\";\nimport type { LoaderContext } from \"webpack\";\n\n/**\n * Returns source text as a module value so importModule never executes application code.\n * @param this - Loader context retained for compatibility with the bundler loader protocol.\n * @param source - Source produced by preceding loaders, serialized as a string literal.\n * @param map - Optional upstream map serialized as a module export. Omission exports null.\n * @returns JavaScript exporting captured source and its map without evaluating that source.\n */\nexport default function webpackSourceLoader(\n this: LoaderContext<unknown>,\n source: string,\n map: UpstreamSourceMap,\n) {\n return `// Stillwind source loader (webpack)\nexport const source = ${JSON.stringify(String(source))};\nexport const map = ${JSON.stringify(map ?? null)};\n`;\n}\n"],"mappings":";;;;;;;;AAUA,SAAwB,oBAEtB,QACA,KACA;CACA,OAAO;wBACe,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE;qBAClC,KAAK,UAAU,OAAO,IAAI,EAAE;;AAEjD"}
1
+ {"version":3,"file":"source-loader.js","names":[],"sources":["../../src/webpack/source-loader.ts"],"sourcesContent":["import type { UpstreamSourceMap } from \"@stillwind/host\";\nimport type { LoaderContext } from \"webpack\";\n\n/**\n * Returns source text as a module value so importModule never executes application code.\n *\n * @param this - Loader context retained for compatibility with the bundler loader protocol.\n * @param source - Source produced by preceding loaders, serialized as a string literal.\n * @param map - Optional upstream map serialized as a module export. Omission exports null.\n * @returns JavaScript exporting captured source and its map without evaluating that source.\n */\nexport default function webpackSourceLoader(\n this: LoaderContext<unknown>,\n source: string,\n map: UpstreamSourceMap,\n) {\n return `// Stillwind source loader (webpack)\nexport const source = ${JSON.stringify(String(source))};\nexport const map = ${JSON.stringify(map ?? null)};\n`;\n}\n"],"mappings":";;;;;;;;;AAWA,SAAwB,oBAEtB,QACA,KACA;CACA,OAAO;wBACe,KAAK,UAAU,OAAO,MAAM,CAAC,EAAE;qBAClC,KAAK,UAAU,OAAO,IAAI,EAAE;;AAEjD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@stillwind/integration",
3
- "version": "0.8.0",
3
+ "version": "0.9.0",
4
4
  "description": "Stillwind plugins for Vite, Astro, Next.js, Nuxt, SvelteKit, Fresh, webpack, Rspack, Rsbuild, and Turbopack",
5
5
  "keywords": [
6
6
  "astro",
@@ -37,7 +37,9 @@
37
37
  },
38
38
  "files": [
39
39
  "dist",
40
- "index.d.ts"
40
+ "index.d.ts",
41
+ "README.md",
42
+ "CHANGELOG.md"
41
43
  ],
42
44
  "type": "module",
43
45
  "types": "./index.d.ts",
@@ -100,33 +102,33 @@
100
102
  "@jridgewell/gen-mapping": "^0.3.13",
101
103
  "@jridgewell/remapping": "^2.3.5",
102
104
  "@jridgewell/trace-mapping": "^0.3.31",
103
- "@stillwind/config": "0.8.0",
104
- "@stillwind/host": "0.8.0",
105
- "@stillwind/native": "0.8.0",
106
- "rolldown": "^1.2.16"
105
+ "@stillwind/config": "0.9.0",
106
+ "@stillwind/host": "0.9.0",
107
+ "@stillwind/native": "0.9.0",
108
+ "rolldown": "^1.3.1"
107
109
  },
108
110
  "devDependencies": {
109
- "@rsbuild/core": "^2.3.0",
110
- "@rspack/core": "^2.3.0",
111
+ "@rsbuild/core": "^2.3.1",
112
+ "@rspack/core": "^2.3.1",
111
113
  "@stillwind-internal/tools-fixture-css": "0.0.0",
112
114
  "@stillwind-internal/tools-workspace": "0.0.0",
113
115
  "@sveltejs/kit": "^3.1.1",
114
116
  "@sveltejs/vite-plugin-svelte": "^7.3.1",
115
- "@swc/core": "^1.16.20",
117
+ "@swc/core": "^1.16.22",
116
118
  "@types/node": "^26.6.6",
117
119
  "@vitejs/plugin-vue": "^6.0.10",
118
- "astro": "^7.4.4",
120
+ "astro": "^7.4.8",
119
121
  "css-loader": "^7.1.5",
120
- "next": "^16.4.3",
121
- "nuxt": "^4.6.3",
122
- "stillwind": "0.8.0",
122
+ "next": "^16.4.5",
123
+ "nuxt": "^4.6.4",
124
+ "stillwind": "0.9.0",
123
125
  "svelte": "^5.57.3",
124
126
  "svelte-loader": "^3.2.4",
125
127
  "swc-loader": "^0.2.7",
126
128
  "typescript": "^6.0.3",
127
- "vite": "npm:@voidzero-dev/vite-plus-core@1.4.0",
128
- "vite-plus": "1.4.0",
129
- "vue": "^3.5.44",
129
+ "vite": "npm:@voidzero-dev/vite-plus-core@1.5.1",
130
+ "vite-plus": "1.5.1",
131
+ "vue": "^3.5.45",
130
132
  "vue-loader": "^17.4.2",
131
133
  "webpack": "^5.112.2"
132
134
  },
@@ -136,7 +138,7 @@
136
138
  "@sveltejs/kit": "^2.0.0 || ^3.0.0",
137
139
  "astro": "^6.0.0 || ^7.0.0",
138
140
  "nuxt": "^4.0.0",
139
- "stillwind": "0.8.0",
141
+ "stillwind": "0.9.0",
140
142
  "vite": "^7.0.0 || ^8.0.0"
141
143
  },
142
144
  "peerDependenciesMeta": {
@@ -1,45 +0,0 @@
1
- import { createRequire } from "node:module";
2
- import { fileURLToPath } from "node:url";
3
- import path from "node:path";
4
- import { existsSync, readFileSync, readdirSync } from "node:fs";
5
- // src/binding-files.ts
6
- /**
7
- * Returns existing runtime files from the generated loader and installed binding
8
- * packages. Watching both locations covers napi-rs's local and packaged loading.
9
- * Missing optional packages are skipped. Other filesystem and resolution errors
10
- * propagate to the caller.
11
- * @returns Distinct absolute runtime paths in discovery order, including the generated loader entry.
12
- * @throws If metadata, filesystem access, or resolution fails beyond a missing optional package.
13
- */
14
- function nativeBindingFiles() {
15
- const entry = fileURLToPath(import.meta.resolve("@stillwind/native"));
16
- const require = createRequire(entry);
17
- const files = /* @__PURE__ */ new Set([entry]);
18
- /**
19
- * Adds native and WASM runtime companions from an installed runtime directory.
20
- * @param directory - Existing directory to enumerate. Matching filenames are added to files.
21
- * @throws If enumeration fails.
22
- */
23
- const collect = (directory) => {
24
- for (const name of readdirSync(directory)) if ((name.startsWith("stillwind_native.") || name.startsWith("wasi-worker")) && /\.(node|wasm|cjs|mjs|js)$/.test(name)) files.add(path.join(directory, name));
25
- };
26
- collect(path.dirname(entry));
27
- const manifest = JSON.parse(readFileSync(new URL(import.meta.resolve("@stillwind/native/package.json")), "utf8"));
28
- for (const name of Object.keys(manifest.optionalDependencies)) {
29
- let runtime;
30
- try {
31
- runtime = require.resolve(name);
32
- } catch (error) {
33
- if (error.code === "MODULE_NOT_FOUND") continue;
34
- throw error;
35
- }
36
- if (existsSync(runtime)) {
37
- files.add(runtime);
38
- collect(path.dirname(runtime));
39
- }
40
- }
41
- return [...files];
42
- }
43
- export { nativeBindingFiles as t };
44
-
45
- //# sourceMappingURL=binding-files-Ds5NpyVV.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"binding-files-Ds5NpyVV.js","names":[],"sources":["../src/binding-files.ts"],"sourcesContent":["import { existsSync, readFileSync, readdirSync } from \"node:fs\";\nimport { createRequire } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\n/**\n * Returns existing runtime files from the generated loader and installed binding\n * packages. Watching both locations covers napi-rs's local and packaged loading.\n * Missing optional packages are skipped. Other filesystem and resolution errors\n * propagate to the caller.\n * @returns Distinct absolute runtime paths in discovery order, including the generated loader entry.\n * @throws If metadata, filesystem access, or resolution fails beyond a missing optional package.\n */\nexport function nativeBindingFiles(): string[] {\n const entry = fileURLToPath(import.meta.resolve(\"@stillwind/native\"));\n const require = createRequire(entry);\n const files = new Set([entry]);\n /**\n * Adds native and WASM runtime companions from an installed runtime directory.\n * @param directory - Existing directory to enumerate. Matching filenames are added to files.\n * @throws If enumeration fails.\n */\n const collect = (directory: string) => {\n for (const name of readdirSync(directory)) {\n if (\n (name.startsWith(\"stillwind_native.\") || name.startsWith(\"wasi-worker\")) &&\n /\\.(node|wasm|cjs|mjs|js)$/.test(name)\n ) {\n files.add(path.join(directory, name));\n }\n }\n };\n collect(path.dirname(entry));\n const manifest = JSON.parse(\n readFileSync(new URL(import.meta.resolve(\"@stillwind/native/package.json\")), \"utf8\"),\n ) as {\n /** Optional binding package names mapped to their version requirements in generated metadata. */\n optionalDependencies: Record<string, string>;\n };\n for (const name of Object.keys(manifest.optionalDependencies)) {\n let runtime: string;\n try {\n runtime = require.resolve(name);\n } catch (error) {\n if ((error as NodeJS.ErrnoException).code === \"MODULE_NOT_FOUND\") {\n continue;\n }\n throw error;\n }\n if (existsSync(runtime)) {\n files.add(runtime);\n collect(path.dirname(runtime));\n }\n }\n return [...files];\n}\n"],"mappings":";;;;;;;;;;;;;AAaA,SAAgB,qBAA+B;CAC7C,MAAM,QAAQ,cAAc,YAAY,QAAQ,mBAAmB,CAAC;CACpE,MAAM,UAAU,cAAc,KAAK;CACnC,MAAM,wBAAQ,IAAI,IAAI,CAAC,KAAK,CAAC;;;;;;CAM7B,MAAM,WAAW,cAAsB;EACrC,KAAK,MAAM,QAAQ,YAAY,SAAS,GACtC,KACG,KAAK,WAAW,mBAAmB,KAAK,KAAK,WAAW,aAAa,MACtE,4BAA4B,KAAK,IAAI,GAErC,MAAM,IAAI,KAAK,KAAK,WAAW,IAAI,CAAC;CAG1C;CACA,QAAQ,KAAK,QAAQ,KAAK,CAAC;CAC3B,MAAM,WAAW,KAAK,MACpB,aAAa,IAAI,IAAI,YAAY,QAAQ,gCAAgC,CAAC,GAAG,MAAM,CACrF;CAIA,KAAK,MAAM,QAAQ,OAAO,KAAK,SAAS,oBAAoB,GAAG;EAC7D,IAAI;EACJ,IAAI;GACF,UAAU,QAAQ,QAAQ,IAAI;EAChC,SAAS,OAAO;GACd,IAAK,MAAgC,SAAS,oBAC5C;GAEF,MAAM;EACR;EACA,IAAI,WAAW,OAAO,GAAG;GACvB,MAAM,IAAI,OAAO;GACjB,QAAQ,KAAK,QAAQ,OAAO,CAAC;EAC/B;CACF;CACA,OAAO,CAAC,GAAG,KAAK;AAClB"}
@@ -1 +0,0 @@
1
- {"version":3,"file":"emission-BVi5aRbb.js","names":[],"sources":["../src/webpack/rules.ts","../src/webpack/requests.ts","../src/webpack/sources.ts","../src/webpack/compilation-styles.ts","../src/webpack/host.ts","../src/webpack/emission.ts"],"sourcesContent":["import { createHash } from \"node:crypto\";\nimport { fileURLToPath } from \"node:url\";\n\nimport type { InlineConfig } from \"@stillwind/config\";\n\n/**\n * Derives the webpack rule identifier used by inline SFC loader requests.\n *\n * @param config - The same configuration values registered on the loader rule. JSON serialization\n * omits callbacks, so namingRevision must distinguish changed naming implementations.\n * @returns A stillwind-prefixed SHA-256 hash of the serialized configuration.\n * @throws If the configuration cannot be serialized as JSON.\n */\nexport function loaderOptionsId(config: InlineConfig): string {\n return \"stillwind-\" + createHash(\"sha256\").update(JSON.stringify(config)).digest(\"hex\");\n}\n\n/** webpack-compatible producer and source-map rules, also consumed by Rspack. */\nexport interface StillwindRule {\n /** Matches resource paths, including synthetic component script suffixes where required. */\n test: RegExp;\n /** Optional exclusion applied before the loader chain, normally for node_modules. */\n exclude?: RegExp;\n /** Placement relative to ordinary loaders. Omission uses the normal loader phase. */\n enforce?: \"pre\" | \"post\";\n /** Loader entries in webpack rule order, executed according to the bundler's loader phases. */\n use: (\n | string\n | {\n /** Absolute installed loader path. */\n loader: string;\n /** Discovery and inline settings retained by the rule and evaluated by its producer loader. */\n options: InlineConfig;\n /** Registered rule identity referenced by requests that retain naming callbacks. */\n ident: string;\n }\n )[];\n}\n\n/**\n * Builds producer, document CSS, and SFC source-map loader rules without evaluating configuration.\n *\n * @param config - Discovery and inline settings shared by producer rules. The object is retained.\n * @returns Rules using absolute paths in the installed integration package. The host provides its\n * CSS pipeline and registers StillwindPlugin when automatic document CSS is required.\n * @throws If loader resolution or configuration serialization fails.\n */\nexport function stillwindRules(config: InlineConfig): StillwindRule[] {\n return [\n {\n test: /\\.[cm]?[jt]sx?$/,\n exclude: /node_modules/,\n enforce: \"pre\",\n use: [\n {\n loader: fileURLToPath(\n new URL(\"./loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n options: config,\n ident: loaderOptionsId(config),\n },\n ],\n },\n {\n test: /\\.(?:astro|svelte|vue)$/,\n exclude: /node_modules/,\n enforce: \"pre\",\n use: [\n {\n loader: fileURLToPath(\n new URL(\"./loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n options: config,\n ident: loaderOptionsId(config),\n },\n ],\n },\n {\n test: /stillwind-webpack\\.css$/,\n enforce: \"post\",\n use: [\n fileURLToPath(\n new URL(\"./document-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n {\n test: /stillwind-webpack\\.css$/,\n enforce: \"pre\",\n use: [\n fileURLToPath(\n new URL(\"./css-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n {\n // Vue inline match resources select script rules with a synthetic .vue.ts suffix.\n test: /\\.(?:astro|svelte|vue)(?:\\.[cm]?[jt]sx?)?$/,\n exclude: /node_modules/,\n enforce: \"post\",\n use: [\n fileURLToPath(\n new URL(\"./source-map-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n ),\n ],\n },\n ];\n}\n","import path from \"node:path\";\n\nimport type { BuildConfig, InlineConfig } from \"@stillwind/config\";\n\nimport { loaderOptionsId } from \"./rules.ts\";\n\n/** Compiler options carried by a loader rule or an encoded SFC subrequest. */\nexport type LoaderOptions = InlineConfig & {\n /**\n * Base64url-encoded JSON configuration for an SFC subrequest. Omit when the rule supplies options\n * directly.\n */\n stillwindOptions?: string;\n};\n\n/** Producer identity and flags that select compilation behavior for one loader request. */\nexport interface ProducerRequest {\n /** Whether `stillwind.css` requests document CSS without importing application JavaScript. */\n projection: boolean;\n /** Whether `stillwind-module-css` requests an explicit CSS value module. */\n cssValue: boolean;\n /** Whether the resource is an Astro, Svelte, or Vue file, including its generated blocks. */\n sfc: boolean;\n /**\n * Full script identity. SFC blocks, projections, CSS values, and export selections share the\n * original producer identity.\n */\n id: string;\n /** Whether a `raw` or `url` query requires the loader to leave the input unchanged. */\n passthrough: boolean;\n}\n\n/**\n * Classifies a resource request and chooses the producer identity used for compilation.\n *\n * @param resourcePath - Absolute resource path without its query.\n * @param resourceQuery - Query including its leading `?`, or an empty string.\n * @returns Request flags and a producer ID. SFC blocks, CSS values, and projections share the\n * original file identity. Export-selection queries do not change the producer identity.\n */\nexport function classifyRequest(resourcePath: string, resourceQuery = \"\"): ProducerRequest {\n const projection = /[?&]stillwind\\.css(?:&|$)/.test(resourceQuery);\n const cssValue = /[?&]stillwind-module-css(?:&|$)/.test(resourceQuery);\n const sfc = /\\.(?:astro|svelte|vue)$/.test(resourcePath);\n const parameters = new URLSearchParams(resourceQuery);\n let sourceQuery = resourceQuery;\n if (parameters.has(\"export\")) {\n parameters.delete(\"export\");\n const query = parameters.toString();\n sourceQuery = query ? `?${query}` : \"\";\n }\n\n return {\n projection,\n cssValue,\n sfc,\n // SFC integrations re-enter the loader for blocks compiled from the original producer.\n id: resourcePath + (projection || cssValue || sfc ? \"\" : sourceQuery),\n passthrough: /[?&](?:raw|url)(?:[=&]|$)/.test(resourceQuery),\n };\n}\n\n/**\n * Reads compiler options from a rule or an encoded SFC subrequest.\n *\n * @param supplied - Rule options, optionally containing `stillwindOptions` encoded as base64url\n * JSON.\n * @returns Decoded options when `stillwindOptions` is present, otherwise the supplied object.\n * @throws If encoded configuration is not valid JSON.\n */\nexport function requestOptions(supplied: LoaderOptions): InlineConfig {\n return supplied.stillwindOptions\n ? JSON.parse(Buffer.from(supplied.stillwindOptions, \"base64url\").toString(\"utf8\"))\n : supplied;\n}\n\n/**\n * Creates a module request with forward slashes, relative to the importer when possible.\n *\n * @param from - Absolute directory containing the importing module.\n * @param to - Absolute path of the requested resource.\n * @returns A relative request with `./` when needed, or an absolute path across Windows volumes.\n */\nexport function relativeRequest(from: string, to: string): string {\n const value = path.relative(from, to).replaceAll(\"\\\\\", \"/\");\n return path.isAbsolute(value) || value.startsWith(\".\") ? value : `./${value}`;\n}\n\n/**\n * Creates a CSS projection or CSS value request that retains the producer configuration.\n *\n * SFC requests bypass other loaders. Naming callbacks use a registered rule identifier because JSON\n * cannot encode functions.\n *\n * @param resourcePath - Absolute path of the original producer.\n * @param sfc - Whether the producer is an Astro, Svelte, or Vue file.\n * @param config - Compiler config used for the original producer.\n * @param loaderPath - Absolute path of the producer loader.\n * @param query - Stillwind query text without a leading `?`.\n * @param identityConfig - Original inline settings registered on the loader rule. When evaluated\n * config contains naming callbacks, this selects that rule instead of serializing callbacks.\n * Defaults to config when file evaluation has not changed the registered settings.\n * @returns A relative resource request for scripts, or an inline loader request for SFCs.\n * @throws If SFC settings cannot be serialized for their inline request.\n */\nexport function virtualRequest(\n resourcePath: string,\n sfc: boolean,\n config: BuildConfig,\n loaderPath: string,\n query: string,\n identityConfig: InlineConfig = config,\n): string {\n if (!sfc) {\n return `${relativeRequest(path.dirname(resourcePath), resourcePath)}?${query}`;\n }\n\n const configuration = config.naming\n ? \"??\" + loaderOptionsId(identityConfig)\n : \"?stillwindOptions=\" + Buffer.from(JSON.stringify(config)).toString(\"base64url\");\n return `!!${loaderPath.replaceAll(\"\\\\\", \"/\")}${configuration}!${resourcePath.replaceAll(\"\\\\\", \"/\")}?${query}`;\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\n\nimport { cleanModuleId, fileModuleDescriptor } from \"@stillwind/host\";\n\n/**\n * Keeps each query-selected derivative's compiler, checker, and source-map identities distinct.\n * @param root - Absolute project root used to derive compiler identities.\n * @param id - Full source identity, including any query or fragment selecting transformed source.\n * @returns Ordinary file metadata without a suffix, or distinct module/document identities and a hashed checker filename.\n */\nexport function sourceDescriptor(root: string, id: string) {\n const descriptor = fileModuleDescriptor(root, id);\n const file = cleanModuleId(id);\n const suffix = id.slice(file.length);\n if (!suffix) {\n return descriptor;\n }\n const extension = path.extname(file);\n const key = createHash(\"sha256\").update(id).digest(\"hex\");\n const checkerFileName = path.join(\n path.dirname(file),\n `.${path.basename(file, extension)}.stillwind-${key}${extension}`,\n );\n return {\n ...descriptor,\n moduleId: descriptor.moduleId + suffix,\n document: {\n ...descriptor.document,\n uri: descriptor.document.uri + suffix,\n },\n checkerFileName,\n projectionFileName: checkerFileName.replaceAll(\"\\\\\", \"/\"),\n };\n}\n","import { createHash } from \"node:crypto\";\nimport path from \"node:path\";\nimport { fileURLToPath, pathToFileURL } from \"node:url\";\n\nimport {\n cleanModuleId,\n cssEntrypoint,\n cssWithSourceMap,\n loadCssGraph,\n nodePluginHost,\n warnRejectedNames,\n type CssUpstreamMap,\n} from \"@stillwind/host\";\n\nimport { buildCompilerOptions, IntegrationSession, warnSkippedCss } from \"../session.ts\";\nimport type { ProducerInput } from \"./emission.ts\";\nimport type { CompilationHost } from \"./host.ts\";\nimport { relativeRequest } from \"./requests.ts\";\nimport { sourceDescriptor } from \"./sources.ts\";\n\n/**\n * Recompiles recorded producers and renders document CSS for a completed compilation.\n *\n * Manual producers are compiled for dependency composition but are excluded from the document\n * selection. The temporary compiler closes after reconstruction.\n *\n * @param producers - Nonempty list of producers from the completed graph. Every producer must use\n * the same root and config.\n * @param io - Compilation host that reads captured dependency sources and resolves CSS, scripts,\n * and assets.\n * @param mode - Bundler mode. Only `development` selects development compilation.\n * @param watch - Registers a file as a compilation dependency.\n * @param watchDirectory - Registers a directory whose entry additions and removals invalidate the\n * compilation.\n * @param warn - Reports compiler warnings and the CSS statements that loading skipped through the\n * bundler.\n * @returns Document CSS with asset requests and an inline source map composed with recorded\n * upstream maps.\n * @throws If producers use different design systems, a dependency source is missing, or loading or\n * compilation fails.\n */\nexport async function compilationStyles(\n producers: readonly ProducerInput[],\n io: CompilationHost,\n mode: string | undefined,\n watch: (id: string) => void,\n watchDirectory: (id: string) => void,\n warn: (message: string) => void,\n): Promise<string> {\n const { config, root } = producers[0];\n const readDependency = io.dependencyReader(producers);\n const loaded = await loadCssGraph(\n path.resolve(root, cssEntrypoint(config)),\n buildCompilerOptions(config),\n {\n read: io.read,\n resolve: io.resolveCss,\n documentUri: (id) => pathToFileURL(id).href,\n sourceMapSource: (id) => pathToFileURL(id).href,\n watch,\n watchDirectory,\n plugins: nodePluginHost,\n },\n undefined,\n undefined,\n {\n plugins: config.plugins,\n tailwind: config.tailwind,\n important: config.important,\n root,\n },\n );\n warnSkippedCss(loaded.skipped, warn);\n const compiler = new IntegrationSession(\n root,\n loaded.loader,\n config,\n false,\n mode === \"development\" ? \"development\" : \"release\",\n loaded.plugins,\n );\n const selection: string[] = [];\n try {\n for (const input of producers) {\n if (input.root !== root || JSON.stringify(input.config) !== JSON.stringify(config)) {\n throw new Error(\"A compilation must use one Stillwind design system\");\n }\n const output = await compiler.compile(\n input.source,\n input.id,\n {\n describe: (id) => sourceDescriptor(root, id),\n resolve: async (specifier, importer) => ({\n id: await io.resolveJs(specifier, importer),\n }),\n read: readDependency,\n watch: (id) => {\n watch(cleanModuleId(id));\n },\n warn,\n },\n {\n moduleCssImport: \"stillwind/module-css\",\n },\n );\n if (output && !input.manual) {\n selection.push(output.moduleId);\n }\n }\n const revision = createHash(\"sha256\")\n .update(producers.map((input) => `${input.source}\\0`).join(\"\"))\n .digest(\"hex\");\n const plan = compiler.native.planStylesheet({\n modules: selection,\n coverage: {\n kind: \"complete\",\n target: \"compilation\",\n revision,\n },\n placement: \"document\",\n });\n warnRejectedNames(plan.rejectedNames, warn);\n const replacements = new Map<string, string>();\n for (const resource of [...loaded.resources, ...plan.resources]) {\n const owner =\n \"moduleId\" in resource ? compiler.resolverId(resource.moduleId) : resource.sourceName;\n const file = await io.resolveAsset(resource.specifier, owner);\n watch(file);\n const request = relativeRequest(\n path.dirname(fileURLToPath(import.meta.resolve(\"@stillwind/integration/webpack\"))),\n file,\n );\n replacements.set(resource.placeholder, JSON.stringify(request).slice(1, -1));\n }\n return cssWithSourceMap(\n plan,\n replacements,\n producers.flatMap((input) =>\n [\n input.upstream,\n ...(input.dependencies ?? []).map((dependency) => dependency.upstream),\n ].filter((upstream): upstream is CssUpstreamMap => Boolean(upstream)),\n ),\n );\n } finally {\n compiler.close();\n }\n}\n","import fs from \"node:fs\";\nimport { isBuiltin } from \"node:module\";\nimport path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { cleanModuleId, type UpstreamSourceMap } from \"@stillwind/host\";\n\nimport { nativeBindingFiles } from \"../binding-files.ts\";\nimport type { ProducerInput } from \"./emission.ts\";\n\n/** Resolver policies passed to webpack or Rspack for CSS, script, and asset imports. */\nexport interface ResolveSettings {\n /** Dependency category used to select bundler resolution behavior, such as `esm`. */\n dependencyType?: string;\n /** Package export conditions considered when resolving a request. */\n conditionNames?: string[];\n /** File extensions tested for extensionless requests, in resolution order. */\n extensions?: string[];\n /** Package metadata fields considered in resolution order. */\n mainFields?: string[];\n}\n\n/**\n * Completion handler for webpack or Rspack resolution.\n *\n * @param error - Resolution failure, or null or undefined when no error occurred.\n * @param id - Resolved resource identity. A missing or false ID declines the request.\n */\nexport type ResolveCallback = (error?: Error | null, id?: string | false) => void;\n\n/**\n * Resolver bound to the bundler's configured conditions, extensions, and package fields.\n *\n * @param directory - Absolute directory of the importing file.\n * @param specifier - Import or resource request text, including any query suffix.\n * @param callback - Receives the resolution failure or resulting resource identity.\n */\nexport type Resolver = (directory: string, specifier: string, callback: ResolveCallback) => void;\n\n/** Bundler filesystem and resolver operations shared by producer loaders and CSS reconstruction. */\nexport interface ResolverHost {\n /** Bundler input filesystem. Reads may return UTF-8 text or bytes through the callback. */\n fs: {\n /**\n * Reads through the bundler filesystem rather than bypassing its virtual files.\n * @param id - Filesystem identity without a resource query.\n * @param callback - Receives an error or file contents. Callers convert successful contents to text.\n */\n readFile(id: string, callback: (error?: Error | null, value?: string | Buffer) => void): void;\n };\n /**\n * Creates a callback resolver with the requested dependency policy.\n *\n * @param settings - Conditions, extensions, and package fields used for this resolver.\n * @returns A resolver accepting the importer directory, request text, and a completion callback.\n */\n getResolve(settings: ResolveSettings): Resolver;\n}\n\n/**\n * Loader operations required to resolve producers, capture transformed dependencies, and report\n * compilation inputs.\n */\ninterface LoaderHostContext extends ResolverHost {\n /**\n * Complete loader chain. Entries after `loaderIndex` run before Stillwind in the normal loader\n * phase.\n */\n loaders: readonly {\n /** Complete inline loader request, including its options, reused for dependency capture. */\n request: string;\n }[];\n /** Index of the currently executing Stillwind loader within `loaders`. */\n loaderIndex: number;\n /**\n * Evaluates a generated capture module through the specified loader chain.\n *\n * @param request - Inline request whose capture loader exports source and map instead of\n * executing application code.\n * @returns A promise for the generated capture module exports.\n */\n importModule(request: string): Promise<unknown>;\n /**\n * Registers a source or compiler file as a dependency of this loader result.\n *\n * @param id - Absolute filesystem path without a resource query.\n */\n addDependency(id: string): void;\n /**\n * Reports a compilation warning through the loader context.\n *\n * @param error - Warning represented as an Error instance.\n */\n emitWarning(error: Error): void;\n}\n\n/** Source and map exported by the capture loader after preceding framework transforms. */\nexport interface CapturedDependency {\n /** Transformed source text consumed by the compiler, without executing its application code. */\n source: string;\n /** Upstream map supplied by preceding loaders, or null when none was supplied. */\n map: UpstreamSourceMap;\n}\n\n/** Compiler operations and retained dependency captures for one producer loader invocation. */\nexport interface LoaderHost {\n /**\n * Reads a resource through the bundler input filesystem.\n *\n * @param id - Readable filesystem path without a query.\n * @returns A promise for the file contents converted to a string.\n */\n read: (id: string) => Promise<string>;\n /**\n * Reads ordinary files or captures query-qualified source through preceding loaders.\n *\n * @param dependency - Full resolver identity, including any query suffix.\n * @returns A promise for source text, rejecting if reading or capture fails.\n */\n readDependency: (dependency: string) => Promise<string>;\n /**\n * Pending transformed-source captures keyed by full resolver identity, retained for emission\n * metadata.\n */\n dependencySources: Map<string, Promise<CapturedDependency>>;\n /**\n * Resolves a CSS import using style export conditions and CSS extensions.\n *\n * @param specifier - CSS import text.\n * @param importer - Absolute path of the importing stylesheet.\n * @returns A promise for the resolved identity, or an empty string when the resolver declines it.\n */\n resolveCss: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves an asset using the bundler's default resolution policy.\n *\n * @param specifier - Asset request text.\n * @param importer - Absolute identity of the resource owner.\n * @returns A promise for the resolved identity, or an empty string when the resolver declines it.\n */\n resolveAsset: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a script dependency and marks Node builtins as external.\n *\n * @param specifier - Script import text, optionally naming a Node builtin.\n * @param importer - Absolute identity of the importing producer.\n * @returns A promise for the resolved identity and optional external status, or null when the\n * resolver declines the request. Other resolution errors reject the promise.\n */\n resolve: (\n specifier: string,\n importer: string,\n ) => Promise<{\n /** Full resolved source identity or Node builtin name. */\n id: string;\n /** Whether semantic traversal must skip loading the dependency as source. */\n external?: boolean;\n } | null>;\n /**\n * Registers the underlying file of a resolver identity as a loader dependency.\n *\n * @param id - File identity, optionally including a resource query that is removed before\n * registration.\n */\n watch: (id: string) => void;\n /**\n * Reports a compiler warning through the loader context.\n *\n * @param message - Warning text converted to an Error instance for the bundler.\n */\n warn: (message: string) => void;\n}\n\n/**\n * Creates compiler operations from a producer loader context and tracks the loader itself as a\n * dependency.\n *\n * Ordinary dependencies are read from the filesystem. Query-qualified dependencies pass through\n * preceding loaders and the capture loader. Pending captures are reused by their full resolver\n * identity.\n *\n * @param context - Active loader context with a complete loader chain and an `importModule`\n * implementation for query-qualified dependencies.\n * @param loaderPath - Absolute path of the Stillwind loader to register as a dependency.\n * @returns A host that resolves imports, reads files, captures transformed dependencies, and\n * forwards warnings.\n */\nexport function createLoaderHost(context: LoaderHostContext, loaderPath: string): LoaderHost {\n const read = createReadFile(context.fs);\n const dependencySources = new Map<string, Promise<CapturedDependency>>();\n /**\n * Reads an ordinary dependency or captures transformed text through preceding loaders.\n * @param dependency - Full resolver identity. A query or fragment requires a loader capture.\n * @returns File text or captured text. Capture promises, including failures, are retained by identity.\n * @throws If filesystem reading or the dependency's loader chain fails.\n */\n const readDependency = async (dependency: string) => {\n if (cleanModuleId(dependency) === dependency) {\n return read(dependency);\n }\n let pending = dependencySources.get(dependency);\n if (!pending) {\n const capture = fileURLToPath(\n new URL(\"./source-loader.js\", import.meta.resolve(\"@stillwind/integration/webpack\")),\n );\n const preceding = context.loaders\n .slice(context.loaderIndex + 1)\n .map((loader) => loader.request);\n pending = context.importModule(\n `!!${[capture, ...preceding, dependency].join(\"!\")}`,\n ) as Promise<CapturedDependency>;\n dependencySources.set(dependency, pending);\n }\n return (await pending).source;\n };\n /**\n * Adapts loader resolution to requests relative to a source file.\n * @param settings - Resolution policy passed to the loader's resolver factory.\n * @returns An asynchronous resolver accepting a specifier and full importer identity. Resolver\n * errors reject its promise, and a missing result becomes an empty string.\n */\n const resolver = (settings: ResolveSettings) => {\n const resolve = context.getResolve(settings);\n return (specifier: string, importer: string) =>\n new Promise<string>((done, reject) =>\n resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) =>\n error ? reject(error) : done(id || \"\"),\n ),\n );\n };\n const resolveCss = resolver(cssResolveOptions);\n const resolveJs = resolver({\n dependencyType: \"esm\",\n extensions: [\".tsx\", \".ts\", \".jsx\", \".js\", \".mjs\", \".cjs\", \".json\"],\n });\n const resolveAsset = resolver({});\n /**\n * Registers a filesystem dependency for loader invalidation.\n * @param id - Full resolver identity whose query and fragment are removed before registration.\n */\n const watch = (id: string) => context.addDependency(cleanModuleId(id));\n watch(loaderPath);\n return {\n read,\n readDependency,\n dependencySources,\n resolveCss,\n resolveAsset,\n resolve: async (specifier: string, importer: string) => {\n if (specifier.startsWith(\"node:\") && isBuiltin(specifier)) {\n return { id: specifier, external: true };\n }\n try {\n const id = await resolveJs(specifier, importer);\n return id ? { id } : null;\n } catch (error) {\n if (isBuiltin(specifier)) {\n return { id: specifier, external: true };\n }\n throw error;\n }\n },\n watch,\n warn: (message: string) => context.emitWarning(new Error(message)),\n };\n}\n\n/**\n * Registers compiler runtime files so changes invalidate cached loader results.\n *\n * The function includes native binding files and JavaScript files beside the published host\n * entrypoint.\n *\n * @param watch - Registers an absolute file path as a loader dependency.\n * @throws If the host runtime directory cannot be read.\n */\nexport function watchCompilerFiles(watch: (id: string) => void): void {\n for (const file of nativeBindingFiles()) {\n watch(file);\n }\n const directory = path.dirname(fileURLToPath(import.meta.resolve(\"@stillwind/host\")));\n for (const file of fs.readdirSync(directory)) {\n if (file.endsWith(\".js\")) {\n watch(path.join(directory, file));\n }\n }\n}\n\n/** File and resolver operations used after producer modules have completed compilation. */\nexport interface CompilationHost {\n /**\n * Reads the underlying file through the bundler input filesystem.\n *\n * @param id - Resolver identity whose query suffix is removed before reading.\n * @returns A promise for the file contents converted to a string.\n */\n read: (id: string) => Promise<string>;\n /**\n * Creates a reader that prefers captured producer and dependency sources over filesystem reads.\n *\n * @param producers - Producer metadata collected from the completed compilation graph.\n * @returns A reader keyed by full resolver identity. Missing query-qualified captures reject.\n * Ordinary uncaptured files are read through the filesystem.\n */\n dependencyReader: (producers: readonly ProducerInput[]) => (id: string) => Promise<string>;\n /**\n * Resolves an import from the design-system CSS graph.\n *\n * @param specifier - CSS import text.\n * @param importer - Absolute path of the importing stylesheet.\n * @returns A promise for the resolver's file identity, rejecting on resolution errors.\n */\n resolveCss: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a producer dependency, including supported framework source extensions.\n *\n * @param specifier - Script or framework import text.\n * @param importer - Absolute identity of the importing producer.\n * @returns A promise for the resolver's identity, retaining resource queries.\n */\n resolveJs: (specifier: string, importer: string) => Promise<string>;\n /**\n * Resolves a stylesheet asset using the bundler's default resolution policy.\n *\n * @param specifier - Asset request text.\n * @param importer - Absolute identity of the stylesheet or producer that owns the resource.\n * @returns A promise for the resolver's identity, rejecting on resolution errors.\n */\n resolveAsset: (specifier: string, importer: string) => Promise<string>;\n}\n\n/**\n * Creates filesystem and resolution operations for reconstructing a completed compilation.\n *\n * Reconstruction resolves framework source files as well as scripts. Query-qualified dependency\n * reads require captured source from producer metadata.\n *\n * @param context - Bundler input filesystem and resolver factory operations.\n * @returns A host that reads files and builds dependency readers from retained producer metadata.\n */\nexport function createCompilationHost(context: ResolverHost): CompilationHost {\n const read = createReadFile(context.fs, cleanModuleId);\n /**\n * Adapts compilation resolution to requests relative to a source file.\n * @param settings - Resolution policy passed to the bundler's resolver factory.\n * @returns An asynchronous resolver accepting a specifier and full importer identity. It forwards\n * successful resolver results without checking for an absent identity, and rejects resolver errors.\n */\n const resolver = (settings: ResolveSettings) => {\n const resolve = context.getResolve(settings);\n return (specifier: string, importer: string) =>\n new Promise<string>((done, reject) =>\n resolve(path.dirname(cleanModuleId(importer)), specifier, (error, id) =>\n error ? reject(error) : done(id as string),\n ),\n );\n };\n return {\n read,\n /**\n * Creates a reader using source captured by the completed module graph.\n * @param producers - Producer and dependency records. Later records replace earlier text for the same identity.\n * @returns A reader that uses exact captured identities before falling back to ordinary filesystem reads.\n */\n dependencyReader(producers: readonly ProducerInput[]) {\n const sources = new Map<string, string>();\n for (const input of producers) {\n sources.set(input.id, input.source);\n for (const dependency of input.dependencies ?? []) {\n sources.set(dependency.id, dependency.source);\n }\n }\n return (id: string) => {\n if (sources.has(id)) {\n return Promise.resolve(sources.get(id)!);\n }\n if (cleanModuleId(id) !== id) {\n return Promise.reject(new Error(`No transformed source captured for ${id}`));\n }\n return read(id);\n };\n },\n resolveCss: resolver(cssResolveOptions),\n resolveJs: resolver({\n dependencyType: \"esm\",\n extensions: [\".tsx\", \".ts\", \".jsx\", \".js\", \".mjs\", \".cjs\", \".vue\", \".svelte\", \".astro\"],\n }),\n resolveAsset: resolver({}),\n };\n}\n\n/**\n * CSS resolution policy that prefers style exports and metadata fields before ordinary package\n * entrypoints.\n */\nconst cssResolveOptions = {\n conditionNames: [\"style\", \"import\", \"default\"],\n extensions: [\".css\"],\n mainFields: [\"style\", \"main\"],\n};\n\n/**\n * Adapts the bundler filesystem to asynchronous string reads.\n *\n * @param filesystem - Input filesystem that completes reads through a callback.\n * @param fileId - Maps resolver identities to readable paths. Defaults to keeping the identity\n * unchanged.\n * @returns A reader that resolves to the filesystem value converted to a string, or rejects on read\n * failure.\n */\nfunction createReadFile(filesystem: ResolverHost[\"fs\"], fileId = (id: string) => id) {\n return (id: string) =>\n new Promise<string>((resolve, reject) =>\n filesystem.readFile(fileId(id), (error, value) =>\n error ? reject(error) : resolve(String(value)),\n ),\n );\n}\n","import type { BuildConfig } from \"@stillwind/config\";\nimport type { ResolvedIntegrationConfig } from \"@stillwind/config/node\";\nimport type { CssUpstreamMap } from \"@stillwind/host\";\n\nimport { compilationStyles } from \"./compilation-styles.ts\";\nimport { createCompilationHost, type ResolverHost } from \"./host.ts\";\n\n/**\n * A producer and its captured dependencies stored in bundler metadata for CSS reconstruction.\n */\nexport interface ProducerInput {\n /** Source text received by the producer loader, before Stillwind compilation. */\n source: string;\n /** Producer identity. Query-qualified script dependencies retain their query suffix. */\n id: string;\n /** Absolute project root against which compiler module identities are resolved. */\n root: string;\n /** Compiler configuration shared by every producer in this compilation. */\n config: BuildConfig;\n /**\n * Whether this producer is excluded from automatic document CSS and supplies explicit CSS values.\n */\n manual: boolean;\n /** Map from loader input back to the original source, used when composing final CSS maps. */\n upstream?: CssUpstreamMap;\n /**\n * Transformed dependencies captured through the loader chain. Cached metadata retains them for\n * reconstruction.\n */\n dependencies?: {\n /** Complete resolver identity, including the query that selected the transformed dependency. */\n id: string;\n /** Source produced by the loaders that ran before Stillwind. */\n source: string;\n /**\n * Map from the captured source back to its original source, when the preceding loaders supplied\n * one.\n */\n upstream?: CssUpstreamMap;\n }[];\n}\n\n/**\n * Stores a producer in module build metadata so cached modules can participate in CSS\n * reconstruction.\n *\n * @param context - Loader context for a module in a compilation registered by `StillwindPlugin`.\n * @param input - Producer source, compiler configuration, and captured dependency sources.\n * @throws If the compilation has no registered emission hook or the loader context has no module.\n */\nexport function recordProducer<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n input: ProducerInput,\n): void {\n requireEmission(context);\n if (!context._module) {\n throw new Error(incompleteGraphMessage);\n }\n context._module.buildInfo ??= {};\n context._module.buildInfo.stillwind = input;\n}\n\n/**\n * Bundler module metadata used to recover cached producer inputs and identify the shared document\n * CSS carrier.\n */\nexport interface EmissionModule {\n /** Resource path and query used to identify the shared document CSS carrier. */\n resource?: string;\n /** Build metadata retained by the bundler when a module is reused from cache. */\n buildInfo?: {\n /** Producer input reconstructed after the compilation graph is complete. */\n stillwind?: ProducerInput;\n /** Build fields owned by the bundler or other plugins, retained without interpretation. */\n [key: string]: unknown;\n };\n}\n\n/**\n * Compilation operations required to collect producers and rebuild document CSS carriers.\n */\nexport interface EmissionCompilation<Module extends EmissionModule = EmissionModule> {\n /** Parent compilation used by CSS extraction loaders that run a child compiler. */\n compiler?: {\n parentCompilation?: EmissionCompilation<Module>;\n };\n /** Settings evaluated by StillwindPlugin before the build run, reused by producer loaders. */\n __stillwindConfiguration?: ResolvedIntegrationConfig;\n /** Missing configuration candidates whose creation must trigger a watch rebuild. */\n missingDependencies: {\n /**\n * Registers a missing path so its creation invalidates this compilation.\n *\n * @param id - Absolute missing configuration candidate.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Compilation lifecycle operations used to wait for the completed producer graph. */\n hooks: {\n /** Runs after ordinary module builds, before document carriers are rebuilt. */\n finishModules: {\n /**\n * Registers asynchronous CSS reconstruction for the completed modules.\n *\n * @param name - Plugin registration name.\n * @param callback - Operation receiving cached and newly built modules. Rejections fail compilation.\n */\n tapPromise(name: string, callback: (modules: Iterable<Module>) => Promise<void>): void;\n };\n };\n /** Files whose changes invalidate reconstructed CSS. */\n fileDependencies: {\n /**\n * Adds a compiler or source file to watch tracking.\n *\n * @param id - Absolute dependency path.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Directories whose entry additions and removals invalidate reconstructed CSS. */\n contextDependencies: {\n /**\n * Adds a directory that a plugin lists to watch tracking.\n *\n * @param id - Absolute directory path.\n * @returns The bundler collection's insertion result, which Stillwind ignores.\n */\n add(id: string): unknown;\n };\n /** Bundler warning collection receiving compiler lint and rejected-name messages. */\n warnings: {\n /**\n * Appends a warning without failing reconstruction.\n *\n * @param error - Warning represented as an Error instance.\n * @returns The collection's append result, which Stillwind ignores.\n */\n push(error: Error): unknown;\n };\n /**\n * Reruns a document carrier after reconstructed CSS has been stored on the compilation.\n *\n * @param module - Carrier from the completed module graph.\n * @param callback - Completion handler receiving an error when rebuilding fails.\n */\n rebuildModule(module: Module, callback: (error?: Error | null) => void): void;\n /**\n * Reconstructed document CSS, optionally including an inline source map. Undefined before\n * reconstruction.\n */\n __stillwindCss?: string;\n}\n\n/**\n * Bundler context used to register emission and attach producer metadata to the current\n * compilation.\n */\nexport interface EmissionContext<\n Module extends EmissionModule = EmissionModule,\n> extends ResolverHost {\n /** Current compilation, required when recording producers or installing document CSS reconstruction. */\n _compilation?: EmissionCompilation<Module>;\n /** Current bundler module whose buildInfo retains producer metadata. */\n _module?: Module;\n /**\n * Bundler mode forwarded to CSS reconstruction. Only `development` selects development\n * compilation.\n */\n mode?: string;\n}\n\n/**\n * Registers CSS reconstruction after all modules in the compilation have finished.\n *\n * Registration is idempotent for a compilation. The hook collects cached and newly built producers,\n * stores document CSS, and rebuilds each carrier through the host CSS pipeline.\n *\n * @param context - Context with a compilation, filesystem, and resolver. Register it before\n * producer loaders run.\n * @throws If the context has no compilation with a `finishModules` hook.\n */\nexport function installEmission<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): void {\n const compilation = requireCompilation(context);\n if (installed.has(compilation)) {\n return;\n }\n installed.add(compilation);\n const io = createCompilationHost(context);\n compilation.hooks.finishModules.tapPromise(\"StillwindEmission\", async (modules) => {\n const completed = [...modules];\n const producers = completed\n .map((module) => module.buildInfo?.stillwind)\n .filter((input): input is ProducerInput => Boolean(input));\n const carriers = completed.filter((module) =>\n module.resource?.includes(\"stillwind-webpack.css?stillwind-document\"),\n );\n if (!carriers.length || !producers.length) {\n return;\n }\n compilation.__stillwindCss = await compilationStyles(\n producers,\n io,\n context.mode,\n (id) => {\n compilation.fileDependencies.add(id);\n },\n (id) => {\n compilation.contextDependencies.add(id);\n },\n (message) => {\n compilation.warnings.push(new Error(message));\n },\n );\n for (const carrier of carriers) {\n await new Promise<void>((resolve, reject) =>\n compilation.rebuildModule(carrier, (error) => (error ? reject(error) : resolve())),\n );\n }\n });\n}\n\n/**\n * Compilations whose emission hooks have been registered. Membership is required before automatic\n * loaders record producers.\n */\nconst installed = new WeakSet<object>();\n\nconst incompleteGraphMessage =\n \"Automatic Stillwind CSS requires new StillwindPlugin(config) before compilation begins\";\n\n/**\n * Obtains the compilation operations needed to reconstruct document CSS.\n *\n * @param context - Bundler context that must expose a `finishModules` compilation hook.\n * @returns The compilation attached to the context.\n * @throws If the context cannot supply a completed compilation graph.\n */\nfunction requireCompilation<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): EmissionCompilation<Module> {\n const compilation = context._compilation;\n if (!compilation?.hooks?.finishModules) {\n throw new Error(incompleteGraphMessage);\n }\n return compilation;\n}\n\n/**\n * Rejects automatic CSS requests when the compilation has no registered emission hook.\n *\n * @param context - Loader context associated with a compilation registered by `StillwindPlugin`.\n * @returns The nearest registered compilation holding reconstructed document CSS.\n * @throws If the compilation is missing or its emission hook has not been registered.\n */\nexport function requireEmission<Module extends EmissionModule>(\n context: EmissionContext<Module>,\n): EmissionCompilation<Module> {\n let compilation = requireCompilation(context);\n while (!installed.has(compilation)) {\n const parent = compilation.compiler?.parentCompilation;\n if (!parent) {\n throw new Error(incompleteGraphMessage);\n }\n compilation = parent;\n }\n return compilation;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AAaA,SAAgB,gBAAgB,QAA8B;CAC5D,OAAO,eAAe,WAAW,QAAQ,CAAC,CAAC,OAAO,KAAK,UAAU,MAAM,CAAC,CAAC,CAAC,OAAO,KAAK;AACxF;;;;;;;;;AAgCA,SAAgB,eAAe,QAAuC;CACpE,OAAO;EACL;GACE,MAAM;GACN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