@stillwind/integration 0.0.0-stage → 0.1.0-rc.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.
- package/LICENSE +21 -0
- package/README.md +67 -2
- package/dist/NPM-THIRD-PARTY-LICENSES +52 -0
- package/dist/astro/development.d.ts +15 -0
- package/dist/astro/development.js +34 -0
- package/dist/astro/development.js.map +1 -0
- package/dist/astro/index.d.ts +17 -0
- package/dist/astro/index.js +194 -0
- package/dist/astro/index.js.map +1 -0
- package/dist/astro/middleware.d.ts +2 -0
- package/dist/astro/middleware.js +64 -0
- package/dist/astro/middleware.js.map +1 -0
- package/dist/binding-files-Ds5NpyVV.js +45 -0
- package/dist/binding-files-Ds5NpyVV.js.map +1 -0
- package/dist/emission-BVi5aRbb.js +520 -0
- package/dist/emission-BVi5aRbb.js.map +1 -0
- package/dist/fresh/index.d.ts +10 -0
- package/dist/fresh/index.js +55 -0
- package/dist/fresh/index.js.map +1 -0
- package/dist/gen-mapping-D7jFzOEh.js +559 -0
- package/dist/gen-mapping-D7jFzOEh.js.map +1 -0
- package/dist/index-DFfbZxNT.d.ts +12 -0
- package/dist/next/css-loader.d.ts +14 -0
- package/dist/next/css-loader.js +58 -0
- package/dist/next/css-loader.js.map +1 -0
- package/dist/next/index.d.ts +15 -0
- package/dist/next/index.js +66 -0
- package/dist/next/index.js.map +1 -0
- package/dist/node-loader-D-3Ynpy1.d.ts +19 -0
- package/dist/nuxt/index.d.ts +13 -0
- package/dist/nuxt/index.js +64 -0
- package/dist/nuxt/index.js.map +1 -0
- package/dist/plugin-C_ZFfzo2.js +2572 -0
- package/dist/plugin-C_ZFfzo2.js.map +1 -0
- package/dist/plugin-aV0zIIAe.d.ts +278 -0
- package/dist/plugin-mPiBLdqa.js +79 -0
- package/dist/plugin-mPiBLdqa.js.map +1 -0
- package/dist/project-BNw0nZBE.d.ts +58 -0
- package/dist/project-C3IH7geC.js +182 -0
- package/dist/project-C3IH7geC.js.map +1 -0
- package/dist/project-DUGu8g_L.d.ts +15 -0
- package/dist/rsbuild/index.d.ts +28 -0
- package/dist/rsbuild/index.js +77 -0
- package/dist/rsbuild/index.js.map +1 -0
- package/dist/rspack/index.d.ts +3 -0
- package/dist/rspack/index.js +1 -0
- package/dist/rules-BvKsL2at.js +91 -0
- package/dist/rules-BvKsL2at.js.map +1 -0
- package/dist/session-B9_rp9TH.d.ts +72 -0
- package/dist/session-DHUCQMG5.js +117 -0
- package/dist/session-DHUCQMG5.js.map +1 -0
- package/dist/source-map-loader-CBLiYaBI.d.ts +128 -0
- package/dist/sveltekit/handle.d.ts +13 -0
- package/dist/sveltekit/handle.js +16 -0
- package/dist/sveltekit/handle.js.map +1 -0
- package/dist/trace-mapping-DV_eP3r7.d.ts +58 -0
- package/dist/turbopack/css-loader.d.ts +15 -0
- package/dist/turbopack/css-loader.js +44 -0
- package/dist/turbopack/css-loader.js.map +1 -0
- package/dist/turbopack/index.d.ts +54 -0
- package/dist/turbopack/index.js +1 -0
- package/dist/turbopack/loader.d.ts +13 -0
- package/dist/turbopack/loader.js +70 -0
- package/dist/turbopack/loader.js.map +1 -0
- package/dist/turbopack/node-loader.d.ts +2 -0
- package/dist/turbopack/node-loader.js +20 -0
- package/dist/turbopack/node-loader.js.map +1 -0
- package/dist/turbopack/stillwind-turbopack.css +0 -0
- package/dist/vite/index.d.ts +3 -0
- package/dist/vite/index.js +1 -0
- package/dist/vite/runtime-source-map.d.ts +19 -0
- package/dist/vite/runtime-source-map.js +106 -0
- package/dist/vite/runtime-source-map.js.map +1 -0
- package/dist/vite/runtime.d.ts +58 -0
- package/dist/vite/runtime.js +90 -0
- package/dist/vite/runtime.js.map +1 -0
- package/dist/webpack/css-loader.d.ts +17 -0
- package/dist/webpack/css-loader.js +36 -0
- package/dist/webpack/css-loader.js.map +1 -0
- package/dist/webpack/css-map-loader.d.ts +24 -0
- package/dist/webpack/css-map-loader.js +43 -0
- package/dist/webpack/css-map-loader.js.map +1 -0
- package/dist/webpack/document-loader.d.ts +12 -0
- package/dist/webpack/document-loader.js +19 -0
- package/dist/webpack/document-loader.js.map +1 -0
- package/dist/webpack/fragment-loader.d.ts +9 -0
- package/dist/webpack/fragment-loader.js +23 -0
- package/dist/webpack/fragment-loader.js.map +1 -0
- package/dist/webpack/index.d.ts +3 -0
- package/dist/webpack/index.js +1 -0
- package/dist/webpack/loader.d.ts +35 -0
- package/dist/webpack/loader.js +199 -0
- package/dist/webpack/loader.js.map +1 -0
- package/dist/webpack/source-loader.d.ts +11 -0
- package/dist/webpack/source-loader.js +17 -0
- package/dist/webpack/source-loader.js.map +1 -0
- package/dist/webpack/source-map-loader.d.ts +2 -0
- package/dist/webpack/source-map-loader.js +35 -0
- package/dist/webpack/source-map-loader.js.map +1 -0
- package/dist/webpack/stillwind-fragment.d.ts +1 -0
- package/dist/webpack/stillwind-fragment.js +1 -0
- package/dist/webpack/stillwind-webpack.css +1 -0
- package/package.json +133 -3
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
type GeneratedColumn = number;
|
|
2
|
+
type SourcesIndex = number;
|
|
3
|
+
type SourceLine = number;
|
|
4
|
+
type SourceColumn = number;
|
|
5
|
+
type NamesIndex = number;
|
|
6
|
+
type SourceMapSegment = [GeneratedColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn] | [GeneratedColumn, SourcesIndex, SourceLine, SourceColumn, NamesIndex];
|
|
7
|
+
interface SourceMapV3 {
|
|
8
|
+
file?: string | null;
|
|
9
|
+
names: string[];
|
|
10
|
+
sourceRoot?: string;
|
|
11
|
+
sources: (string | null)[];
|
|
12
|
+
sourcesContent?: (string | null)[];
|
|
13
|
+
version: 3;
|
|
14
|
+
ignoreList?: number[];
|
|
15
|
+
}
|
|
16
|
+
interface EncodedSourceMap extends SourceMapV3 {
|
|
17
|
+
mappings: string;
|
|
18
|
+
}
|
|
19
|
+
interface DecodedSourceMap extends SourceMapV3 {
|
|
20
|
+
mappings: SourceMapSegment[][];
|
|
21
|
+
}
|
|
22
|
+
type XInput = {
|
|
23
|
+
x_google_ignoreList?: SourceMapV3['ignoreList'];
|
|
24
|
+
};
|
|
25
|
+
type EncodedSourceMapXInput = EncodedSourceMap & XInput;
|
|
26
|
+
type DecodedSourceMapXInput = DecodedSourceMap & XInput;
|
|
27
|
+
type SourceMapInput = string | EncodedSourceMapXInput | DecodedSourceMapXInput | TraceMap;
|
|
28
|
+
declare abstract class SourceMap {
|
|
29
|
+
version: SourceMapV3['version'];
|
|
30
|
+
file: SourceMapV3['file'];
|
|
31
|
+
names: SourceMapV3['names'];
|
|
32
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
33
|
+
sources: SourceMapV3['sources'];
|
|
34
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
35
|
+
resolvedSources: SourceMapV3['sources'];
|
|
36
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
37
|
+
}
|
|
38
|
+
type Ro<T> = T extends Array<infer V> ? V[] | Readonly<V[]> | RoArray<V> | Readonly<RoArray<V>> : T extends object ? T | Readonly<T> | RoObject<T> | Readonly<RoObject<T>> : T;
|
|
39
|
+
type RoArray<T> = Ro<T>[];
|
|
40
|
+
type RoObject<T> = { [K in keyof T]: T[K] | Ro<T[K]>; };
|
|
41
|
+
declare class TraceMap implements SourceMap {
|
|
42
|
+
version: SourceMapV3['version'];
|
|
43
|
+
file: SourceMapV3['file'];
|
|
44
|
+
names: SourceMapV3['names'];
|
|
45
|
+
sourceRoot: SourceMapV3['sourceRoot'];
|
|
46
|
+
sources: SourceMapV3['sources'];
|
|
47
|
+
sourcesContent: SourceMapV3['sourcesContent'];
|
|
48
|
+
ignoreList: SourceMapV3['ignoreList'];
|
|
49
|
+
resolvedSources: string[];
|
|
50
|
+
private _encoded;
|
|
51
|
+
private _decoded;
|
|
52
|
+
private _decodedMemo;
|
|
53
|
+
private _bySources;
|
|
54
|
+
private _bySourceMemos;
|
|
55
|
+
constructor(map: Ro<SourceMapInput>, mapUrl?: string | null);
|
|
56
|
+
}
|
|
57
|
+
export { EncodedSourceMap as n, SourceMapInput as r, DecodedSourceMap as t };
|
|
58
|
+
//# sourceMappingURL=trace-mapping-DV_eP3r7.d.ts.map
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { n as TurbopackProject, t as TurbopackLoaderOptions } from "../project-BNw0nZBE.js";
|
|
2
|
+
import { LoaderContext } from "webpack";
|
|
3
|
+
/**
|
|
4
|
+
* Starts document CSS reconstruction from entries captured in standalone Turbopack loader options.
|
|
5
|
+
* @param this - Loader context that receives asynchronous CSS and source-map completion or an error.
|
|
6
|
+
*/
|
|
7
|
+
export default function turbopackCssLoader(this: LoaderContext<TurbopackLoaderOptions>): void;
|
|
8
|
+
/**
|
|
9
|
+
* Reconstructs a document stylesheet and resolves its local resources through the bundler.
|
|
10
|
+
* @param context - Loader context whose callback receives CSS and a decoded map, or the operation error.
|
|
11
|
+
* @param entries - Callback that selects absolute or project-relative entries after configuration is evaluated.
|
|
12
|
+
* Dependency watches are registered during traversal, and the compiler's checker is closed after planning.
|
|
13
|
+
*/
|
|
14
|
+
export declare function emitStylesheet(context: LoaderContext<TurbopackLoaderOptions>, entries: (options: TurbopackProject["options"]) => Promise<string[]>): void;
|
|
15
|
+
//# sourceMappingURL=css-loader.d.ts.map
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import { loaderCompletion } from "../webpack/source-map-loader.js";
|
|
2
|
+
import { n as createProject, t as compileGraph } from "../project-C3IH7geC.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { cssWithSourceMap, decodeCssSourceMap } from "@stillwind/host";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
// src/turbopack/css-loader.ts
|
|
7
|
+
/**
|
|
8
|
+
* Starts document CSS reconstruction from entries captured in standalone Turbopack loader options.
|
|
9
|
+
* @param this - Loader context that receives asynchronous CSS and source-map completion or an error.
|
|
10
|
+
*/
|
|
11
|
+
function turbopackCssLoader() {
|
|
12
|
+
emitStylesheet(this, async (options) => options.entries);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Reconstructs a document stylesheet and resolves its local resources through the bundler.
|
|
16
|
+
* @param context - Loader context whose callback receives CSS and a decoded map, or the operation error.
|
|
17
|
+
* @param entries - Callback that selects absolute or project-relative entries after configuration is evaluated.
|
|
18
|
+
* Dependency watches are registered during traversal, and the compiler's checker is closed after planning.
|
|
19
|
+
*/
|
|
20
|
+
function emitStylesheet(context, entries) {
|
|
21
|
+
const callback = loaderCompletion(context);
|
|
22
|
+
(async () => {
|
|
23
|
+
const project = await createProject(context);
|
|
24
|
+
try {
|
|
25
|
+
const plan = await compileGraph(await entries(project.options), project);
|
|
26
|
+
const replacements = /* @__PURE__ */ new Map();
|
|
27
|
+
for (const resource of [...project.loaded.resources, ...plan.resources]) {
|
|
28
|
+
const file = await project.resolveAsset(resource.specifier, "moduleId" in resource ? project.compiler.resolverId(resource.moduleId) : resource.sourceName);
|
|
29
|
+
project.host.watch(file);
|
|
30
|
+
let request = path.relative(path.dirname(context.resourcePath), file).replaceAll("\\", "/");
|
|
31
|
+
if (!request.startsWith(".")) request = `./${request}`;
|
|
32
|
+
replacements.set(resource.placeholder, JSON.stringify(request).slice(1, -1));
|
|
33
|
+
}
|
|
34
|
+
const output = decodeCssSourceMap(cssWithSourceMap(plan, replacements));
|
|
35
|
+
if (output.map) output.map.sources = output.map.sources.map((source) => source.startsWith("file:") ? fileURLToPath(source).replaceAll("\\", "/") : source);
|
|
36
|
+
callback(null, output.code, output.map);
|
|
37
|
+
} finally {
|
|
38
|
+
project.compiler.close();
|
|
39
|
+
}
|
|
40
|
+
})().catch(callback);
|
|
41
|
+
}
|
|
42
|
+
export { turbopackCssLoader as default, emitStylesheet };
|
|
43
|
+
|
|
44
|
+
//# sourceMappingURL=css-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css-loader.js","names":[],"sources":["../../src/turbopack/css-loader.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport { cssWithSourceMap, decodeCssSourceMap } from \"@stillwind/host\";\nimport type { LoaderContext } from \"webpack\";\n\nimport { loaderCompletion } from \"../webpack/source-map-loader.ts\";\nimport {\n compileGraph,\n createProject,\n type TurbopackLoaderOptions,\n type TurbopackProject,\n} from \"./project.ts\";\n\n/**\n * Starts document CSS reconstruction from entries captured in standalone Turbopack loader options.\n * @param this - Loader context that receives asynchronous CSS and source-map completion or an error.\n */\nexport default function turbopackCssLoader(this: LoaderContext<TurbopackLoaderOptions>) {\n emitStylesheet(this, async (options) => options.entries);\n}\n\n/**\n * Reconstructs a document stylesheet and resolves its local resources through the bundler.\n * @param context - Loader context whose callback receives CSS and a decoded map, or the operation error.\n * @param entries - Callback that selects absolute or project-relative entries after configuration is evaluated.\n * Dependency watches are registered during traversal, and the compiler's checker is closed after planning.\n */\nexport function emitStylesheet(\n context: LoaderContext<TurbopackLoaderOptions>,\n entries: (options: TurbopackProject[\"options\"]) => Promise<string[]>,\n): void {\n const callback = loaderCompletion(context);\n void (async () => {\n const project = await createProject(context);\n try {\n const plan = await compileGraph(await entries(project.options), project);\n const replacements = new Map<string, string>();\n for (const resource of [...project.loaded.resources, ...plan.resources]) {\n const file = await project.resolveAsset(\n resource.specifier,\n \"moduleId\" in resource\n ? project.compiler.resolverId(resource.moduleId)\n : resource.sourceName,\n );\n project.host.watch(file);\n let request = path.relative(path.dirname(context.resourcePath), file).replaceAll(\"\\\\\", \"/\");\n if (!request.startsWith(\".\")) {\n request = `./${request}`;\n }\n replacements.set(resource.placeholder, JSON.stringify(request).slice(1, -1));\n }\n const output = decodeCssSourceMap(cssWithSourceMap(plan, replacements));\n if (output.map) {\n output.map.sources = output.map.sources.map((source: string) =>\n source.startsWith(\"file:\") ? fileURLToPath(source).replaceAll(\"\\\\\", \"/\") : source,\n );\n }\n callback(null, output.code, output.map);\n } finally {\n project.compiler.close();\n }\n })().catch(callback);\n}\n"],"mappings":";;;;;;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|
|
3
|
+
import { SerializableInlineConfig } from "@stillwind/config";
|
|
4
|
+
/**
|
|
5
|
+
* Serializable inline settings and entry selection for standalone Turbopack rules.
|
|
6
|
+
* Naming callbacks can be supplied by stillwind.config.*, which each loader evaluates.
|
|
7
|
+
*/
|
|
8
|
+
interface IntegrationConfig extends SerializableInlineConfig {
|
|
9
|
+
/**
|
|
10
|
+
* Nonempty list of entry paths, absolute or relative to the resolved project root.
|
|
11
|
+
* Globs are not expanded.
|
|
12
|
+
*/
|
|
13
|
+
entries: string[];
|
|
14
|
+
/** Defaults to development when NODE_ENV is development, otherwise release. */
|
|
15
|
+
mode?: "development" | "release";
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Host rule that maps source files or the shared stylesheet carrier to Stillwind
|
|
19
|
+
* loaders.
|
|
20
|
+
*/
|
|
21
|
+
interface TurbopackRule {
|
|
22
|
+
/**
|
|
23
|
+
* Limits the producer rule to application modules rather than foreign package
|
|
24
|
+
* modules.
|
|
25
|
+
*/
|
|
26
|
+
condition?: {
|
|
27
|
+
/** Turbopack condition excluding modules classified as foreign packages. */
|
|
28
|
+
not: "foreign";
|
|
29
|
+
};
|
|
30
|
+
/** Loader chain in bundler rule order, using shared captured options. */
|
|
31
|
+
loaders: {
|
|
32
|
+
/** Absolute path to an installed Stillwind loader. */
|
|
33
|
+
loader: string;
|
|
34
|
+
/** Serializable settings forwarded to the isolated loader invocation. */
|
|
35
|
+
options: NodeLoaderOptions;
|
|
36
|
+
}[];
|
|
37
|
+
/** Forces the stylesheet carrier's output to be processed as CSS. */
|
|
38
|
+
as?: string;
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* Creates producer and shared stylesheet rules for a host's turbopack.rules
|
|
42
|
+
* configuration.
|
|
43
|
+
*
|
|
44
|
+
* @param config - Entry paths, optional mode, configuration file selection, and
|
|
45
|
+
* serializable compiler overrides. File evaluation occurs in loaders after the bundler
|
|
46
|
+
* starts.
|
|
47
|
+
* @returns Rules with independent Stillwind loaders. The host supplies its CSS output
|
|
48
|
+
* pipeline.
|
|
49
|
+
* @throws If entries is empty or contains blank paths, inline naming callbacks are
|
|
50
|
+
* supplied, or installed loader paths cannot be resolved.
|
|
51
|
+
*/
|
|
52
|
+
export declare function stillwindRules(config: IntegrationConfig): Record<string, TurbopackRule>;
|
|
53
|
+
export type { IntegrationConfig, TurbopackRule };
|
|
54
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { i as stillwindRules } from "../rules-BvKsL2at.js";
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { t as TurbopackLoaderOptions } from "../project-BNw0nZBE.js";
|
|
2
|
+
import { UpstreamSourceMap } from "@stillwind/host";
|
|
3
|
+
import { LoaderContext } from "webpack";
|
|
4
|
+
/**
|
|
5
|
+
* Compiles producer source or emits a JavaScript CSS value for its module-css query.
|
|
6
|
+
* @param this - Bundler loader context that supplies options, source identity, resolution, and async completion.
|
|
7
|
+
* @param source - Original module text. Sources without recognized Stillwind imports pass through unchanged.
|
|
8
|
+
* @param inputMap - Optional upstream map composed with compiler replacements for producer output.
|
|
9
|
+
* @returns The immediate callback result for pass-through source, or undefined while asynchronous compilation runs.
|
|
10
|
+
* Compilation registers dependencies, may add an automatic document carrier import, and closes its checker afterward.
|
|
11
|
+
*/
|
|
12
|
+
export default function turbopackLoader(this: LoaderContext<TurbopackLoaderOptions>, source: string, inputMap: UpstreamSourceMap): void;
|
|
13
|
+
//# sourceMappingURL=loader.d.ts.map
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { loaderCompletion } from "../webpack/source-map-loader.js";
|
|
2
|
+
import { n as createProject } from "../project-C3IH7geC.js";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import { composeModuleSourceMap, moduleSourceMap, warnRejectedNames } from "@stillwind/host";
|
|
5
|
+
import path from "node:path";
|
|
6
|
+
// src/turbopack/loader.ts
|
|
7
|
+
/**
|
|
8
|
+
* Compiles producer source or emits a JavaScript CSS value for its module-css query.
|
|
9
|
+
* @param this - Bundler loader context that supplies options, source identity, resolution, and async completion.
|
|
10
|
+
* @param source - Original module text. Sources without recognized Stillwind imports pass through unchanged.
|
|
11
|
+
* @param inputMap - Optional upstream map composed with compiler replacements for producer output.
|
|
12
|
+
* @returns The immediate callback result for pass-through source, or undefined while asynchronous compilation runs.
|
|
13
|
+
* Compilation registers dependencies, may add an automatic document carrier import, and closes its checker afterward.
|
|
14
|
+
*/
|
|
15
|
+
function turbopackLoader(source, inputMap) {
|
|
16
|
+
const callback = loaderCompletion(this);
|
|
17
|
+
if (!/stillwind\/(?:alpine|astro|lit|preact|qwik|react|solid|svelte|vanilla|vue|module-css)/.test(source)) return callback(null, source, inputMap);
|
|
18
|
+
(async () => {
|
|
19
|
+
const project = await createProject(this);
|
|
20
|
+
try {
|
|
21
|
+
const request = `./${path.basename(this.resourcePath)}?stillwind-module-css`;
|
|
22
|
+
const output = await project.compiler.compile(source, this.resourcePath, project.host, { moduleCssImport: request });
|
|
23
|
+
if (!output?.code) return callback(null, source, inputMap);
|
|
24
|
+
if (new URLSearchParams(this.resourceQuery).has("stillwind-module-css")) {
|
|
25
|
+
const plan = project.compiler.native.planStylesheet({
|
|
26
|
+
modules: [output.moduleId],
|
|
27
|
+
coverage: { kind: "observed" },
|
|
28
|
+
placement: "document"
|
|
29
|
+
});
|
|
30
|
+
warnRejectedNames(plan.rejectedNames, (message) => project.host.warn(message));
|
|
31
|
+
const imports = [];
|
|
32
|
+
const replacements = [];
|
|
33
|
+
for (const resource of [...project.loaded.resources, ...plan.resources]) {
|
|
34
|
+
const file = await project.resolveAsset(resource.specifier, "moduleId" in resource ? project.compiler.resolverId(resource.moduleId) : resource.sourceName);
|
|
35
|
+
project.host.watch(file);
|
|
36
|
+
let request = path.relative(path.dirname(this.resourcePath), file).replaceAll("\\", "/");
|
|
37
|
+
if (!request.startsWith(".")) request = `./${request}`;
|
|
38
|
+
const binding = `asset${imports.length}`;
|
|
39
|
+
imports.push(`import ${binding} from ${JSON.stringify(request)};\n`);
|
|
40
|
+
replacements.push(`.replaceAll(${JSON.stringify(resource.placeholder)}, JSON.stringify(typeof ${binding} === "string" ? ${binding} : ${binding}.src).slice(1, -1))`);
|
|
41
|
+
}
|
|
42
|
+
return callback(null, [
|
|
43
|
+
"// Stillwind CSS value (turbopack)\n",
|
|
44
|
+
"import { cssText } from \"stillwind/css\";\n",
|
|
45
|
+
...imports,
|
|
46
|
+
"\n",
|
|
47
|
+
`export const parts = ${JSON.stringify(plan.parts.map(({ key, css, banners }) => ({
|
|
48
|
+
key,
|
|
49
|
+
css,
|
|
50
|
+
banners
|
|
51
|
+
})))}.map((part) => ({ ...part, css: part.css${replacements.join("")} }));\n`,
|
|
52
|
+
"export const css = cssText(parts);\n",
|
|
53
|
+
"export default css;\n"
|
|
54
|
+
].join(""));
|
|
55
|
+
}
|
|
56
|
+
let code = output.code;
|
|
57
|
+
if (!output.hasModuleCssImport && project.options.compiler.automatic !== false) {
|
|
58
|
+
let carrier = path.relative(path.dirname(this.resourcePath), fileURLToPath(new URL("./stillwind-turbopack.css", import.meta.resolve("@stillwind/integration/turbopack")))).replaceAll("\\", "/");
|
|
59
|
+
if (!carrier.startsWith(".")) carrier = `./${carrier}`;
|
|
60
|
+
code += `\nimport ${JSON.stringify(carrier)};\n`;
|
|
61
|
+
}
|
|
62
|
+
callback(null, code, composeModuleSourceMap(moduleSourceMap(source, output.code, this.resourcePath, output.mappings, [], ""), inputMap));
|
|
63
|
+
} finally {
|
|
64
|
+
project.compiler.close();
|
|
65
|
+
}
|
|
66
|
+
})().catch(callback);
|
|
67
|
+
}
|
|
68
|
+
export { turbopackLoader as default };
|
|
69
|
+
|
|
70
|
+
//# sourceMappingURL=loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"loader.js","names":[],"sources":["../../src/turbopack/loader.ts"],"sourcesContent":["import path from \"node:path\";\nimport { fileURLToPath } from \"node:url\";\n\nimport {\n composeModuleSourceMap,\n moduleSourceMap,\n warnRejectedNames,\n type UpstreamSourceMap,\n} from \"@stillwind/host\";\nimport type { LoaderContext } from \"webpack\";\n\nimport { loaderCompletion } from \"../webpack/source-map-loader.ts\";\nimport { createProject, type TurbopackLoaderOptions } from \"./project.ts\";\n\n/**\n * Compiles producer source or emits a JavaScript CSS value for its module-css query.\n * @param this - Bundler loader context that supplies options, source identity, resolution, and async completion.\n * @param source - Original module text. Sources without recognized Stillwind imports pass through unchanged.\n * @param inputMap - Optional upstream map composed with compiler replacements for producer output.\n * @returns The immediate callback result for pass-through source, or undefined while asynchronous compilation runs.\n * Compilation registers dependencies, may add an automatic document carrier import, and closes its checker afterward.\n */\nexport default function turbopackLoader(\n this: LoaderContext<TurbopackLoaderOptions>,\n source: string,\n inputMap: UpstreamSourceMap,\n) {\n const callback = loaderCompletion(this);\n if (\n !/stillwind\\/(?:alpine|astro|lit|preact|qwik|react|solid|svelte|vanilla|vue|module-css)/.test(\n source,\n )\n ) {\n return callback(null, source, inputMap);\n }\n void (async () => {\n const project = await createProject(this);\n try {\n const request = `./${path.basename(this.resourcePath)}?stillwind-module-css`;\n const output = await project.compiler.compile(source, this.resourcePath, project.host, {\n moduleCssImport: request,\n });\n if (!output?.code) {\n return callback(null, source, inputMap);\n }\n if (new URLSearchParams(this.resourceQuery).has(\"stillwind-module-css\")) {\n const plan = project.compiler.native.planStylesheet({\n modules: [output.moduleId],\n coverage: { kind: \"observed\" },\n placement: \"document\",\n });\n warnRejectedNames(plan.rejectedNames, (message) => project.host.warn(message));\n const imports: string[] = [];\n const replacements: string[] = [];\n for (const resource of [...project.loaded.resources, ...plan.resources]) {\n const file = await project.resolveAsset(\n resource.specifier,\n \"moduleId\" in resource\n ? project.compiler.resolverId(resource.moduleId)\n : resource.sourceName,\n );\n project.host.watch(file);\n let request = path.relative(path.dirname(this.resourcePath), file).replaceAll(\"\\\\\", \"/\");\n if (!request.startsWith(\".\")) {\n request = `./${request}`;\n }\n const binding = `asset${imports.length}`;\n imports.push(`import ${binding} from ${JSON.stringify(request)};\\n`);\n replacements.push(\n `.replaceAll(${JSON.stringify(resource.placeholder)}, JSON.stringify(typeof ${binding} === \"string\" ? ${binding} : ${binding}.src).slice(1, -1))`,\n );\n }\n return callback(\n null,\n [\n \"// Stillwind CSS value (turbopack)\\n\",\n 'import { cssText } from \"stillwind/css\";\\n',\n ...imports,\n \"\\n\",\n `export const parts = ${JSON.stringify(plan.parts.map(({ key, css, banners }) => ({ key, css, banners })))}.map((part) => ({ ...part, css: part.css${replacements.join(\"\")} }));\\n`,\n \"export const css = cssText(parts);\\n\",\n \"export default css;\\n\",\n ].join(\"\"),\n );\n }\n let code = output.code;\n if (!output.hasModuleCssImport && project.options.compiler.automatic !== false) {\n let carrier = path\n .relative(\n path.dirname(this.resourcePath),\n fileURLToPath(\n new URL(\n \"./stillwind-turbopack.css\",\n import.meta.resolve(\"@stillwind/integration/turbopack\"),\n ),\n ),\n )\n .replaceAll(\"\\\\\", \"/\");\n if (!carrier.startsWith(\".\")) {\n carrier = `./${carrier}`;\n }\n code += `\\nimport ${JSON.stringify(carrier)};\\n`;\n }\n callback(\n null,\n code,\n composeModuleSourceMap(\n moduleSourceMap(source, output.code, this.resourcePath, output.mappings, [], \"\"),\n inputMap,\n ),\n );\n } finally {\n project.compiler.close();\n }\n })().catch(callback);\n}\n"],"mappings":";;;;;;;;;;;;;;AAsBA,SAAwB,gBAEtB,QACA,UACA;CACA,MAAM,WAAW,iBAAiB,IAAI;CACtC,IACE,CAAC,wFAAwF,KACvF,MACF,GAEA,OAAO,SAAS,MAAM,QAAQ,QAAQ;CAExC,CAAM,YAAY;EAChB,MAAM,UAAU,MAAM,cAAc,IAAI;EACxC,IAAI;GACF,MAAM,UAAU,KAAK,KAAK,SAAS,KAAK,YAAY,EAAE;GACtD,MAAM,SAAS,MAAM,QAAQ,SAAS,QAAQ,QAAQ,KAAK,cAAc,QAAQ,MAAM,EACrF,iBAAiB,QAC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AAO;GAClB,IAAI,CAAC,OAAO,sBAAsB,QAAQ,QAAQ,SAAS,cAAc,OAAO;IAC9E,IAAI,UAAU,KACX,SACC,KAAK,QAAQ,KAAK,YAAY,GAC9B,cACE,IAAI,IACF,6BACA,YAAY,QAAQ,kCAAkC,CACxD,CACF,CACF,CAAC,CACA,WAAW,MAAM,GAAG;IACvB,IAAI,CAAC,QAAQ,WAAW,GAAG,GACzB,UAAU,KAAK;IAEjB,QAAQ,YAAY,KAAK,UAAU,OAAO,EAAE;GAC9C;GACA,SACE,MACA,MACA,uBACE,gBAAgB,QAAQ,OAAO,MAAM,KAAK,cAAc,OAAO,UAAU,CAAC,GAAG,EAAE,GAC/E,QACF,CACF;EACF,UAAU;GACR,QAAQ,SAAS,MAAM;EACzB;CACF,EAAA,CAAG,CAAC,CAAC,MAAM,QAAQ;AACrB"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { pathToFileURL } from "node:url";
|
|
2
|
+
// src/turbopack/node-loader.ts
|
|
3
|
+
/**
|
|
4
|
+
* Loads the compiler in Node without exposing its dependencies to Turbopack's loader tracing.
|
|
5
|
+
* @param this - Loader context with an absolute implementation path and asynchronous completion.
|
|
6
|
+
* @param source - Original source text forwarded to the implementation.
|
|
7
|
+
* @param inputMap - Upstream source map forwarded unchanged.
|
|
8
|
+
* @returns Undefined. The implementation completes the loader callback and registers its dependencies.
|
|
9
|
+
* Import and synchronous invocation errors complete the callback with an error.
|
|
10
|
+
*/
|
|
11
|
+
function nodeLoader(source, inputMap) {
|
|
12
|
+
const callback = this.async();
|
|
13
|
+
import(
|
|
14
|
+
/* webpackIgnore: true */
|
|
15
|
+
pathToFileURL(this.getOptions().implementation).href
|
|
16
|
+
).then((module) => module.default.call(this, source, inputMap)).catch(callback);
|
|
17
|
+
}
|
|
18
|
+
export { nodeLoader as default };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=node-loader.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node-loader.js","names":[],"sources":["../../src/turbopack/node-loader.ts"],"sourcesContent":["import { pathToFileURL } from \"node:url\";\n\nimport type { UpstreamSourceMap } from \"@stillwind/host\";\nimport type { LoaderContext } from \"webpack\";\n\nimport type producerLoader from \"./loader.ts\";\nimport type { TurbopackLoaderOptions } from \"./project.ts\";\n\n/** Settings for a compiler loader that executes in Node. */\nexport type NodeLoaderOptions = TurbopackLoaderOptions & {\n /** Absolute path to the compiled loader implementation. */\n implementation: string;\n};\n\n/**\n * Loads the compiler in Node without exposing its dependencies to Turbopack's loader tracing.\n * @param this - Loader context with an absolute implementation path and asynchronous completion.\n * @param source - Original source text forwarded to the implementation.\n * @param inputMap - Upstream source map forwarded unchanged.\n * @returns Undefined. The implementation completes the loader callback and registers its dependencies.\n * Import and synchronous invocation errors complete the callback with an error.\n */\nexport default function nodeLoader(\n this: LoaderContext<NodeLoaderOptions>,\n source: string,\n inputMap: UpstreamSourceMap,\n) {\n const callback = this.async();\n const implementation = pathToFileURL(this.getOptions().implementation).href;\n void import(/* webpackIgnore: true */ implementation)\n .then((module: { default: typeof producerLoader }) =>\n module.default.call(this, source, inputMap),\n )\n .catch(callback);\n}\n"],"mappings":";;;;;;;;;;AAsBA,SAAwB,WAEtB,QACA,UACA;CACA,MAAM,WAAW,KAAK,MAAM;CAE5B;;EADuB,cAAc,KAAK,WAAW,CAAC,CAAC,cAAc,CAAC,CAAC;CAClB,CAClD,MAAM,WACL,OAAO,QAAQ,KAAK,MAAM,QAAQ,QAAQ,CAC5C,CAAC,CACA,MAAM,QAAQ;AACnB"}
|
|
File without changes
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { n as stillwind } from "../plugin-C_ZFfzo2.js";
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { StylesheetPart } from "./runtime.js";
|
|
2
|
+
/**
|
|
3
|
+
* Concatenates ordered CSS parts and combines their mappings without embedding original sources.
|
|
4
|
+
*
|
|
5
|
+
* @param parts - Partitions in stylesheet order, each with an optional map for its own CSS text.
|
|
6
|
+
* @returns Combined CSS followed by a UTF-8, base64-encoded inline version 3 map.
|
|
7
|
+
* @throws If a supplied source map cannot be decoded.
|
|
8
|
+
*/
|
|
9
|
+
export declare function renderCssWithSourceMap(parts: readonly StylesheetPart[]): string;
|
|
10
|
+
/**
|
|
11
|
+
* Replaces recorded placeholders and shifts an inline map to the resulting CSS positions.
|
|
12
|
+
*
|
|
13
|
+
* @param css - Generated CSS with an optional trailing inline map in the format emitted by this module.
|
|
14
|
+
* @param replacements - Placeholder/replacement pairs. First matching pair wins at each original position.
|
|
15
|
+
* @returns Replaced CSS with adjusted mappings when an inline map was present. Replacement text is not rescanned.
|
|
16
|
+
* @throws If a recognized inline map contains invalid base64, JSON, or source-map data.
|
|
17
|
+
*/
|
|
18
|
+
export declare function replaceCssResources(css: string, replacements: [string, string][]): string;
|
|
19
|
+
//# sourceMappingURL=runtime-source-map.d.ts.map
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
import { a as eachMapping, i as TraceMap, n as addSegment, r as toEncodedMap, t as GenMapping } from "../gen-mapping-D7jFzOEh.js";
|
|
2
|
+
import { cssBannerPrefix, cssText } from "stillwind/css";
|
|
3
|
+
// src/vite/runtime-source-map.ts
|
|
4
|
+
/**
|
|
5
|
+
* Concatenates ordered CSS parts and combines their mappings without embedding original sources.
|
|
6
|
+
*
|
|
7
|
+
* @param parts - Partitions in stylesheet order, each with an optional map for its own CSS text.
|
|
8
|
+
* @returns Combined CSS followed by a UTF-8, base64-encoded inline version 3 map.
|
|
9
|
+
* @throws If a supplied source map cannot be decoded.
|
|
10
|
+
*/
|
|
11
|
+
function renderCssWithSourceMap(parts) {
|
|
12
|
+
const map = new GenMapping();
|
|
13
|
+
const prefix = cssBannerPrefix(parts.flatMap((part) => part.banners ?? []));
|
|
14
|
+
let line = prefix.match(/\r\n|\r|\n/g)?.length ?? 0;
|
|
15
|
+
let column = prefix.split("\n").at(-1).length;
|
|
16
|
+
for (const part of parts) {
|
|
17
|
+
if (part.map) {
|
|
18
|
+
const trace = new TraceMap(part.map);
|
|
19
|
+
eachMapping(trace, (entry) => {
|
|
20
|
+
const generatedLine = line + entry.generatedLine - 1;
|
|
21
|
+
const generatedColumn = (entry.generatedLine === 1 ? column : 0) + entry.generatedColumn;
|
|
22
|
+
if (entry.source !== null && entry.originalLine !== null) addSegment(map, generatedLine, generatedColumn, entry.source, entry.originalLine - 1, entry.originalColumn);
|
|
23
|
+
else addSegment(map, generatedLine, generatedColumn);
|
|
24
|
+
});
|
|
25
|
+
}
|
|
26
|
+
const lines = part.css.split("\n");
|
|
27
|
+
if (lines.length > 1) {
|
|
28
|
+
line += lines.length - 1;
|
|
29
|
+
column = lines.at(-1).length;
|
|
30
|
+
} else column += part.css.length;
|
|
31
|
+
}
|
|
32
|
+
const encodedMap = toEncodedMap(map);
|
|
33
|
+
delete encodedMap.sourcesContent;
|
|
34
|
+
const bytes = new TextEncoder().encode(JSON.stringify(encodedMap));
|
|
35
|
+
const encoded = btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(""));
|
|
36
|
+
return `${cssText(parts)}\n/*# sourceMappingURL=data:application/json;base64,${encoded} */`;
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Replaces recorded placeholders and shifts an inline map to the resulting CSS positions.
|
|
40
|
+
*
|
|
41
|
+
* @param css - Generated CSS with an optional trailing inline map in the format emitted by this module.
|
|
42
|
+
* @param replacements - Placeholder/replacement pairs. First matching pair wins at each original position.
|
|
43
|
+
* @returns Replaced CSS with adjusted mappings when an inline map was present. Replacement text is not rescanned.
|
|
44
|
+
* @throws If a recognized inline map contains invalid base64, JSON, or source-map data.
|
|
45
|
+
*/
|
|
46
|
+
function replaceCssResources(css, replacements) {
|
|
47
|
+
const match = /\n\/\*# sourceMappingURL=data:application\/json;base64,([A-Za-z0-9+/=]+) \*\/$/.exec(css);
|
|
48
|
+
const text = match ? css.slice(0, match.index) : css;
|
|
49
|
+
const edits = [];
|
|
50
|
+
let result = "";
|
|
51
|
+
for (let offset = 0; offset < text.length;) {
|
|
52
|
+
const replacement = replacements.find(([placeholder]) => text.startsWith(placeholder, offset));
|
|
53
|
+
if (replacement?.[0].length) {
|
|
54
|
+
edits.push({
|
|
55
|
+
from: offset,
|
|
56
|
+
to: offset + replacement[0].length,
|
|
57
|
+
text: replacement[1],
|
|
58
|
+
start: result.length
|
|
59
|
+
});
|
|
60
|
+
result += replacement[1];
|
|
61
|
+
offset += replacement[0].length;
|
|
62
|
+
} else result += text[offset++];
|
|
63
|
+
}
|
|
64
|
+
if (!match) return result;
|
|
65
|
+
const bytes = Uint8Array.from(atob(match[1]), (character) => character.charCodeAt(0));
|
|
66
|
+
const original = new TraceMap(JSON.parse(new TextDecoder().decode(bytes)));
|
|
67
|
+
const starts = [0];
|
|
68
|
+
for (const found of text.matchAll(/\n/g)) starts.push(found.index + 1);
|
|
69
|
+
const map = new GenMapping();
|
|
70
|
+
const resultStarts = [0];
|
|
71
|
+
for (const found of result.matchAll(/\n/g)) resultStarts.push(found.index + 1);
|
|
72
|
+
eachMapping(original, (entry) => {
|
|
73
|
+
const offset = starts[entry.generatedLine - 1] + entry.generatedColumn;
|
|
74
|
+
let transformed = offset;
|
|
75
|
+
for (const edit of edits) if (offset >= edit.to) transformed += edit.text.length - (edit.to - edit.from);
|
|
76
|
+
else if (offset >= edit.from) {
|
|
77
|
+
transformed = edit.start;
|
|
78
|
+
break;
|
|
79
|
+
} else break;
|
|
80
|
+
let left = 0;
|
|
81
|
+
let right = resultStarts.length;
|
|
82
|
+
while (left + 1 < right) {
|
|
83
|
+
const middle = Math.floor((left + right) / 2);
|
|
84
|
+
if (resultStarts[middle] <= transformed) left = middle;
|
|
85
|
+
else right = middle;
|
|
86
|
+
}
|
|
87
|
+
const line = left;
|
|
88
|
+
const column = transformed - resultStarts[line];
|
|
89
|
+
if (entry.source !== null && entry.originalLine !== null) addSegment(map, line, column, entry.source, entry.originalLine - 1, entry.originalColumn);
|
|
90
|
+
else addSegment(map, line, column);
|
|
91
|
+
});
|
|
92
|
+
const encoded = toEncodedMap(map);
|
|
93
|
+
return renderCssWithSourceMap([{
|
|
94
|
+
producers: [],
|
|
95
|
+
css: result,
|
|
96
|
+
map: {
|
|
97
|
+
version: 3,
|
|
98
|
+
names: [],
|
|
99
|
+
sources: [...encoded.sources],
|
|
100
|
+
mappings: encoded.mappings
|
|
101
|
+
}
|
|
102
|
+
}]);
|
|
103
|
+
}
|
|
104
|
+
export { renderCssWithSourceMap, replaceCssResources };
|
|
105
|
+
|
|
106
|
+
//# sourceMappingURL=runtime-source-map.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"runtime-source-map.js","names":[],"sources":["../../src/vite/runtime-source-map.ts"],"sourcesContent":["import { GenMapping, addSegment, toEncodedMap } from \"@jridgewell/gen-mapping\";\nimport { TraceMap, eachMapping } from \"@jridgewell/trace-mapping\";\nimport { cssBannerPrefix, cssText } from \"stillwind/css\";\n\nimport type { StylesheetPart } from \"./runtime.ts\";\n\n/**\n * Concatenates ordered CSS parts and combines their mappings without embedding original sources.\n *\n * @param parts - Partitions in stylesheet order, each with an optional map for its own CSS text.\n * @returns Combined CSS followed by a UTF-8, base64-encoded inline version 3 map.\n * @throws If a supplied source map cannot be decoded.\n */\nexport function renderCssWithSourceMap(parts: readonly StylesheetPart[]): string {\n const map = new GenMapping();\n const prefix = cssBannerPrefix(parts.flatMap((part) => part.banners ?? []));\n let line = prefix.match(/\\r\\n|\\r|\\n/g)?.length ?? 0;\n let column = prefix.split(\"\\n\").at(-1)!.length;\n for (const part of parts) {\n if (part.map) {\n const trace = new TraceMap(part.map);\n eachMapping(trace, (entry) => {\n const generatedLine = line + entry.generatedLine - 1;\n const generatedColumn = (entry.generatedLine === 1 ? column : 0) + entry.generatedColumn;\n if (entry.source !== null && entry.originalLine !== null) {\n addSegment(\n map,\n generatedLine,\n generatedColumn,\n entry.source,\n entry.originalLine - 1,\n entry.originalColumn,\n );\n } else {\n addSegment(map, generatedLine, generatedColumn);\n }\n });\n }\n const lines = part.css.split(\"\\n\");\n if (lines.length > 1) {\n line += lines.length - 1;\n column = lines.at(-1)!.length;\n } else {\n column += part.css.length;\n }\n }\n const encodedMap = toEncodedMap(map);\n delete encodedMap.sourcesContent;\n const bytes = new TextEncoder().encode(JSON.stringify(encodedMap));\n const encoded = btoa(Array.from(bytes, (byte) => String.fromCharCode(byte)).join(\"\"));\n return `${cssText(parts)}\\n/*# sourceMappingURL=data:application/json;base64,${encoded} */`;\n}\n\n/**\n * Replaces recorded placeholders and shifts an inline map to the resulting CSS positions.\n *\n * @param css - Generated CSS with an optional trailing inline map in the format emitted by this module.\n * @param replacements - Placeholder/replacement pairs. First matching pair wins at each original position.\n * @returns Replaced CSS with adjusted mappings when an inline map was present. Replacement text is not rescanned.\n * @throws If a recognized inline map contains invalid base64, JSON, or source-map data.\n */\nexport function replaceCssResources(css: string, replacements: [string, string][]): string {\n const match =\n /\\n\\/\\*# sourceMappingURL=data:application\\/json;base64,([A-Za-z0-9+/=]+) \\*\\/$/.exec(css);\n const text = match ? css.slice(0, match.index) : css;\n const edits: {\n /** Inclusive UTF-16 placeholder offset in CSS before replacement. */\n from: number;\n /** Exclusive UTF-16 placeholder offset in that original CSS. */\n to: number;\n /** Replacement contents whose UTF-16 length shifts subsequent mappings. */\n text: string;\n /** Inclusive UTF-16 replacement offset in the resulting CSS. */\n start: number;\n }[] = [];\n let result = \"\";\n for (let offset = 0; offset < text.length;) {\n const replacement = replacements.find(([placeholder]) => text.startsWith(placeholder, offset));\n if (replacement?.[0].length) {\n edits.push({\n from: offset,\n to: offset + replacement[0].length,\n text: replacement[1],\n start: result.length,\n });\n result += replacement[1];\n offset += replacement[0].length;\n } else {\n result += text[offset++];\n }\n }\n if (!match) {\n return result;\n }\n const bytes = Uint8Array.from(atob(match[1]), (character) => character.charCodeAt(0));\n const original = new TraceMap(JSON.parse(new TextDecoder().decode(bytes)));\n const starts = [0];\n for (const found of text.matchAll(/\\n/g)) {\n starts.push(found.index + 1);\n }\n const map = new GenMapping();\n const resultStarts = [0];\n for (const found of result.matchAll(/\\n/g)) {\n resultStarts.push(found.index + 1);\n }\n eachMapping(original, (entry) => {\n const offset = starts[entry.generatedLine - 1] + entry.generatedColumn;\n let transformed = offset;\n for (const edit of edits) {\n if (offset >= edit.to) {\n transformed += edit.text.length - (edit.to - edit.from);\n } else if (offset >= edit.from) {\n transformed = edit.start;\n break;\n } else {\n break;\n }\n }\n let left = 0;\n let right = resultStarts.length;\n while (left + 1 < right) {\n const middle = Math.floor((left + right) / 2);\n if (resultStarts[middle] <= transformed) {\n left = middle;\n } else {\n right = middle;\n }\n }\n const line = left;\n const column = transformed - resultStarts[line];\n if (entry.source !== null && entry.originalLine !== null) {\n addSegment(map, line, column, entry.source, entry.originalLine - 1, entry.originalColumn);\n } else {\n addSegment(map, line, column);\n }\n });\n const encoded = toEncodedMap(map);\n return renderCssWithSourceMap([\n {\n producers: [],\n css: result,\n map: {\n version: 3,\n names: [],\n sources: [...encoded.sources],\n mappings: encoded.mappings,\n },\n },\n ]);\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,uBAAuB,OAA0C;CAC/E,MAAM,MAAM,IAAI,WAAW;CAC3B,MAAM,SAAS,gBAAgB,MAAM,SAAS,SAAS,KAAK,WAAW,CAAC,CAAC,CAAC;CAC1E,IAAI,OAAO,OAAO,MAAM,aAAa,CAAC,EAAE,UAAU;CAClD,IAAI,SAAS,OAAO,MAAM,IAAI,CAAC,CAAC,GAAG,EAAE,CAAC,CAAE;CACxC,KAAK,MAAM,QAAQ,OAAO;EACxB,IAAI,KAAK,KAAK;GACZ,MAAM,QAAQ,IAAI,SAAS,KAAK,GAAG;GACnC,YAAY,QAAQ,UAAU;IAC5B,MAAM,gBAAgB,OAAO,MAAM,gBAAgB;IACnD,MAAM,mBAAmB,MAAM,kBAAkB,IAAI,SAAS,KAAK,MAAM;IACzE,IAAI,MAAM,WAAW,QAAQ,MAAM,iBA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+
import { n as EncodedSourceMap } from "../trace-mapping-DV_eP3r7.js";
|
|
2
|
+
type StylesheetSourceMap = Readonly<Omit<EncodedSourceMap, "names" | "sources" | "sourcesContent" | "ignoreList">> & {
|
|
3
|
+
readonly names: readonly string[];
|
|
4
|
+
readonly sources: readonly (string | null)[];
|
|
5
|
+
readonly sourcesContent?: readonly (string | null)[];
|
|
6
|
+
readonly ignoreList?: readonly number[];
|
|
7
|
+
};
|
|
8
|
+
/** Ordered CSS partition activated by its producers or included unconditionally. */
|
|
9
|
+
export interface StylesheetPart {
|
|
10
|
+
/** Preserved notices required by this part. */
|
|
11
|
+
readonly banners?: readonly string[];
|
|
12
|
+
/** CSS with resources already resolved for the browser. */
|
|
13
|
+
readonly css: string;
|
|
14
|
+
/** Compiler module ids that need this part; an empty list keeps it active unconditionally. */
|
|
15
|
+
readonly producers: readonly string[];
|
|
16
|
+
/** Map for this part. Null or omission means that no map is available. */
|
|
17
|
+
readonly map?: StylesheetSourceMap | null;
|
|
18
|
+
}
|
|
19
|
+
/** Complete stylesheet and composition state published for one adapter revision. */
|
|
20
|
+
export interface StylesheetSnapshot {
|
|
21
|
+
/** Monotonic revision within the adapter environment. */
|
|
22
|
+
readonly revision: number;
|
|
23
|
+
/** Partitions in stylesheet order, retained when filtering for active producers. */
|
|
24
|
+
readonly parts: readonly StylesheetPart[];
|
|
25
|
+
/** Composition dependencies keyed by compiler module id. */
|
|
26
|
+
readonly dependencies: Readonly<Record<string, readonly string[]>>;
|
|
27
|
+
}
|
|
28
|
+
declare module "vite" {
|
|
29
|
+
/** Extends Vite's typed HMR events with complete Stillwind stylesheet snapshots. */
|
|
30
|
+
interface CustomEventMap {
|
|
31
|
+
/** Stylesheet revision, ordered parts, and composition dependencies published by Stillwind. */
|
|
32
|
+
"stillwind:css": StylesheetSnapshot;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* Reuses document state across runtime instances and applies the initial snapshot.
|
|
37
|
+
* `endpoint` supplies snapshots for this environment. `renderCss`, when supplied,
|
|
38
|
+
* must return CSS for the selected parts in their existing order.
|
|
39
|
+
* Returns operations for producer registration, snapshot updates and synchronization.
|
|
40
|
+
* Snapshots older than the shared document revision are ignored.
|
|
41
|
+
* @param options - Initial snapshot, snapshot endpoint, and optional renderer. Accepted snapshots are captured.
|
|
42
|
+
* @returns Operations that update shared producer state and the owned style element.
|
|
43
|
+
*/
|
|
44
|
+
export declare function createDevelopmentRuntime(options: {
|
|
45
|
+
/** Initial complete snapshot applied unless its revision is older than shared document state. */
|
|
46
|
+
snapshot: StylesheetSnapshot;
|
|
47
|
+
/** URL returning a JSON snapshot for this compiler environment. */
|
|
48
|
+
endpoint: string;
|
|
49
|
+
/** Optional renderer receiving selected parts in stylesheet order and returning their combined CSS. */
|
|
50
|
+
renderCss?: (parts: readonly StylesheetPart[]) => string;
|
|
51
|
+
}): {
|
|
52
|
+
register: (id: string) => void;
|
|
53
|
+
unregister: (id: string) => void;
|
|
54
|
+
synchronize: (revision: number) => Promise<void>;
|
|
55
|
+
apply: (update: StylesheetSnapshot) => void;
|
|
56
|
+
};
|
|
57
|
+
export {};
|
|
58
|
+
//# sourceMappingURL=runtime.d.ts.map
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { cssText } from "stillwind/css";
|
|
2
|
+
// src/vite/runtime.ts
|
|
3
|
+
const documentKey = Symbol.for("stillwind.document");
|
|
4
|
+
/**
|
|
5
|
+
* Reuses document state across runtime instances and applies the initial snapshot.
|
|
6
|
+
* `endpoint` supplies snapshots for this environment. `renderCss`, when supplied,
|
|
7
|
+
* must return CSS for the selected parts in their existing order.
|
|
8
|
+
* Returns operations for producer registration, snapshot updates and synchronization.
|
|
9
|
+
* Snapshots older than the shared document revision are ignored.
|
|
10
|
+
* @param options - Initial snapshot, snapshot endpoint, and optional renderer. Accepted snapshots are captured.
|
|
11
|
+
* @returns Operations that update shared producer state and the owned style element.
|
|
12
|
+
*/
|
|
13
|
+
function createDevelopmentRuntime(options) {
|
|
14
|
+
const endpoint = options.endpoint;
|
|
15
|
+
const renderCss = options.renderCss?.bind(options);
|
|
16
|
+
const globals = globalThis;
|
|
17
|
+
const state = globals[documentKey] ??= {
|
|
18
|
+
revision: -1,
|
|
19
|
+
active: /* @__PURE__ */ new Set()
|
|
20
|
+
};
|
|
21
|
+
/** Expands composition dependencies and writes active partitions into the shared style element. */
|
|
22
|
+
function render() {
|
|
23
|
+
if (!state.snapshot || typeof document === "undefined") return;
|
|
24
|
+
const active = new Set(state.active);
|
|
25
|
+
for (const module of active) for (const dependency of state.snapshot.dependencies[module] ?? []) active.add(dependency);
|
|
26
|
+
const parts = state.snapshot.parts.filter((part) => !part.producers.length || part.producers.some((producer) => active.has(producer)));
|
|
27
|
+
if (!state.style?.isConnected) {
|
|
28
|
+
state.style = document.createElement("style");
|
|
29
|
+
state.style.dataset.stillwind = "";
|
|
30
|
+
document.head.append(state.style);
|
|
31
|
+
}
|
|
32
|
+
state.style.textContent = renderCss ? renderCss(parts) : cssText(parts);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Activates a producer and rerenders its CSS and composition dependencies.
|
|
36
|
+
* @param id - Compiler module identity. Repeated registration has no additional ownership count.
|
|
37
|
+
*/
|
|
38
|
+
function register(id) {
|
|
39
|
+
state.active.add(id);
|
|
40
|
+
render();
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Removes a producer registration and rerenders the remaining active CSS.
|
|
44
|
+
* @param id - Compiler module identity. Unknown identities have no effect on the set.
|
|
45
|
+
*/
|
|
46
|
+
function unregister(id) {
|
|
47
|
+
state.active.delete(id);
|
|
48
|
+
render();
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* Fetches the current snapshot, sharing pending requests between producers.
|
|
52
|
+
* Resolves after the document reaches `revision`; rejects on fetch or response
|
|
53
|
+
* failures. Does not fetch when no document exists.
|
|
54
|
+
* @param revision - Minimum adapter revision required before completion.
|
|
55
|
+
* @returns Completion after a fetched snapshot reaches the requested revision, or immediately without a document.
|
|
56
|
+
* @throws If fetching, decoding, or applying a snapshot fails.
|
|
57
|
+
*/
|
|
58
|
+
async function synchronize(revision) {
|
|
59
|
+
if (typeof document === "undefined") return;
|
|
60
|
+
do {
|
|
61
|
+
state.pending ??= fetch(endpoint).then((response) => {
|
|
62
|
+
if (!response.ok) throw new Error("Stillwind stylesheet synchronization failed");
|
|
63
|
+
return response.json();
|
|
64
|
+
}).then(apply).finally(() => {
|
|
65
|
+
state.pending = void 0;
|
|
66
|
+
});
|
|
67
|
+
await state.pending;
|
|
68
|
+
} while (state.revision < revision);
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Accepts a current or newer snapshot and rerenders shared document styles.
|
|
72
|
+
* @param update - Complete snapshot to capture. Older revisions are ignored, and equal revisions are accepted.
|
|
73
|
+
*/
|
|
74
|
+
function apply(update) {
|
|
75
|
+
if (update.revision < state.revision) return;
|
|
76
|
+
state.snapshot = structuredClone(update);
|
|
77
|
+
state.revision = state.snapshot.revision;
|
|
78
|
+
render();
|
|
79
|
+
}
|
|
80
|
+
apply(options.snapshot);
|
|
81
|
+
return {
|
|
82
|
+
register,
|
|
83
|
+
unregister,
|
|
84
|
+
synchronize,
|
|
85
|
+
apply
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
export { createDevelopmentRuntime };
|
|
89
|
+
|
|
90
|
+
//# sourceMappingURL=runtime.js.map
|