@stillwind/integration 0.5.0 → 0.7.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/dist/astro/index.js +1 -1
- package/dist/fresh/index.js +1 -1
- package/dist/nuxt/index.js +1 -1
- package/dist/{plugin-B2UvdR4C.js → plugin-DOKl8qk3.js} +77 -6
- package/dist/plugin-DOKl8qk3.js.map +1 -0
- package/dist/vite/index.js +1 -1
- package/index.d.ts +2 -0
- package/package.json +34 -8
- package/dist/plugin-B2UvdR4C.js.map +0 -1
package/dist/astro/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { i as renderChunkStyles, r as createViteProject, t as createVitePlugins } from "../plugin-
|
|
1
|
+
import { i as renderChunkStyles, r as createViteProject, t as createVitePlugins } from "../plugin-DOKl8qk3.js";
|
|
2
2
|
import { registerDevelopmentCss } from "./development.js";
|
|
3
3
|
import { randomUUID } from "node:crypto";
|
|
4
4
|
import { fileURLToPath } from "node:url";
|
package/dist/fresh/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as createViteProject, t as createVitePlugins } from "../plugin-
|
|
1
|
+
import { r as createViteProject, t as createVitePlugins } from "../plugin-DOKl8qk3.js";
|
|
2
2
|
// src/fresh/manifest.ts
|
|
3
3
|
/** Filters repeated static files for Fresh's move operation without changing the emitted manifest. */
|
|
4
4
|
function registrationManifest(source) {
|
package/dist/nuxt/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { r as createViteProject, t as createVitePlugins } from "../plugin-
|
|
1
|
+
import { r as createViteProject, t as createVitePlugins } from "../plugin-DOKl8qk3.js";
|
|
2
2
|
import { addPluginTemplate, defineNuxtModule } from "nuxt/kit";
|
|
3
3
|
// src/nuxt/index.ts
|
|
4
4
|
/**
|
|
@@ -3,7 +3,7 @@ import { n as buildCompilerOptions, r as warnSkippedCss, t as IntegrationSession
|
|
|
3
3
|
import { createHash } from "node:crypto";
|
|
4
4
|
import { fileURLToPath, pathToFileURL } from "node:url";
|
|
5
5
|
import { attachPlugins, cleanModuleId, compilerModuleId, composeFrameworkSourceMap, createStylesheetResolver, cssEntrypoint, cssWithSourceMap, decodeCssSourceMap, fileSourceKind, finalizeCss, finalizeModuleWithMap, isStylesheet, loadCssGraph, moduleSourceMap, nodePluginHost, warnRejectedNames } from "@stillwind/host";
|
|
6
|
-
import { dirname, isAbsolute, posix, resolve } from "node:path";
|
|
6
|
+
import { dirname, isAbsolute, posix, relative, resolve } from "node:path";
|
|
7
7
|
import { readFile, readdir, realpath } from "node:fs/promises";
|
|
8
8
|
import { minifyCss } from "@stillwind/native";
|
|
9
9
|
import { isFileServingAllowed } from "vite";
|
|
@@ -31,6 +31,31 @@ function sourceModuleId(root, id) {
|
|
|
31
31
|
}
|
|
32
32
|
// src/vite/chunk-styles.ts
|
|
33
33
|
/**
|
|
34
|
+
* Browser code that keeps loader links across Astro ClientRouter navigations.
|
|
35
|
+
*
|
|
36
|
+
* Astro removes each head element that the incoming document does not contain, and the chunk that
|
|
37
|
+
* added a link does not run again, so the link would stay missing. Astro keeps an old stylesheet
|
|
38
|
+
* link when the incoming head has a link with the same `href`, and each incoming link matches one
|
|
39
|
+
* old link. The listener therefore copies each loader link while the incoming head has fewer links
|
|
40
|
+
* with its `href` than the current head, which also keeps repeated split occurrences. One listener
|
|
41
|
+
* serves all chunks in a document.
|
|
42
|
+
*/
|
|
43
|
+
const persistAcrossSwaps = `const key = Symbol.for("stillwind.persistLinks");
|
|
44
|
+
if (!globalThis[key]) {
|
|
45
|
+
globalThis[key] = true;
|
|
46
|
+
document.addEventListener("astro:before-swap", (event) => {
|
|
47
|
+
const head = event.newDocument.head;
|
|
48
|
+
const count = (parent, href) =>
|
|
49
|
+
[...parent.querySelectorAll('link[rel="stylesheet"]')].filter((l) => l.getAttribute("href") === href).length;
|
|
50
|
+
for (const link of document.head.querySelectorAll("link[data-stillwind-loader]")) {
|
|
51
|
+
const href = link.getAttribute("href");
|
|
52
|
+
if (count(head, href) < count(document.head, href)) {
|
|
53
|
+
head.append(link.cloneNode());
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
}`;
|
|
58
|
+
/**
|
|
34
59
|
* Associates emitted CSS with a chunk and loads its stylesheets in the browser.
|
|
35
60
|
*
|
|
36
61
|
* Split parts retain manifest order and relative-base URLs resolve against the chunk. Hosts can
|
|
@@ -93,8 +118,10 @@ if (typeof document !== "undefined") {
|
|
|
93
118
|
l.href = p.relative ? new URL(p.href, import.meta.url).href : p.href;
|
|
94
119
|
l.dataset.stillwindPart = p.id;
|
|
95
120
|
l.dataset.stillwindOrder = String(p.order);
|
|
121
|
+
l.dataset.stillwindLoader = "";
|
|
96
122
|
document.head.insertBefore(l, links.find((e) => Number(e.dataset.stillwindOrder) > p.order) ?? null);
|
|
97
123
|
}
|
|
124
|
+
${persistAcrossSwaps}
|
|
98
125
|
}
|
|
99
126
|
`,
|
|
100
127
|
map: null
|
|
@@ -117,8 +144,10 @@ if (typeof document !== "undefined") {
|
|
|
117
144
|
const link = document.createElement("link");
|
|
118
145
|
link.rel = "stylesheet";
|
|
119
146
|
link.href = href;
|
|
147
|
+
link.dataset.stillwindLoader = "";
|
|
120
148
|
document.head.append(link);
|
|
121
149
|
}
|
|
150
|
+
${persistAcrossSwaps}
|
|
122
151
|
}
|
|
123
152
|
`,
|
|
124
153
|
map: null
|
|
@@ -513,8 +542,9 @@ function developmentHooks(project) {
|
|
|
513
542
|
/**
|
|
514
543
|
* Registers routes that serve document CSS and revisioned stylesheet snapshots.
|
|
515
544
|
*
|
|
516
|
-
* The document route supports repeated `module` selections and defaults to `ssr`.
|
|
517
|
-
*
|
|
545
|
+
* The document route supports repeated `module` selections and defaults to `ssr`. It records each
|
|
546
|
+
* served URL so that later CSS changes in that environment reload the document's link. The
|
|
547
|
+
* snapshot route defaults to `client`. Unknown environments return 404 and stylesheet failures return
|
|
518
548
|
* 500.
|
|
519
549
|
*
|
|
520
550
|
* @param server - Active server with the project's initialized Vite environments.
|
|
@@ -526,6 +556,9 @@ function developmentHooks(project) {
|
|
|
526
556
|
const selection = params.getAll("module");
|
|
527
557
|
const environment = server.environments[name];
|
|
528
558
|
if (!environment) return sendJson(response, { error: "Unknown environment" }, 404);
|
|
559
|
+
const link = new URL(request.originalUrl ?? request.url ?? "", "http://stillwind.local");
|
|
560
|
+
link.searchParams.delete("t");
|
|
561
|
+
project.observeDocumentStylesheet(name, link.pathname + link.search);
|
|
529
562
|
documentPlan(name, {
|
|
530
563
|
resolve: (specifier, importer, options) => environment.pluginContainer.resolveId(specifier, importer, options),
|
|
531
564
|
addWatchFile: (id) => {
|
|
@@ -1788,6 +1821,10 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1788
1821
|
let configurationDependencies = [];
|
|
1789
1822
|
let missingConfigurations = [];
|
|
1790
1823
|
const environments = /* @__PURE__ */ new Map();
|
|
1824
|
+
/** Document stylesheet URLs served in development, keyed by environment name. */
|
|
1825
|
+
const documentStylesheets = /* @__PURE__ */ new Map();
|
|
1826
|
+
/** CSS of the latest publication that refreshed document stylesheets, keyed by environment name. */
|
|
1827
|
+
const publishedDocumentCss = /* @__PURE__ */ new Map();
|
|
1791
1828
|
let bindings = /* @__PURE__ */ new WeakMap();
|
|
1792
1829
|
/**
|
|
1793
1830
|
* Gets or creates the compiler state owned by one Vite environment.
|
|
@@ -1896,6 +1933,8 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1896
1933
|
/** Detaches server listeners, closes discovery watchers, and closes every retained compiler environment. */
|
|
1897
1934
|
const close = () => {
|
|
1898
1935
|
stopCssWatching();
|
|
1936
|
+
documentStylesheets.clear();
|
|
1937
|
+
publishedDocumentCss.clear();
|
|
1899
1938
|
for (const state of environments.values()) state.close();
|
|
1900
1939
|
};
|
|
1901
1940
|
/**
|
|
@@ -1907,12 +1946,29 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1907
1946
|
*/
|
|
1908
1947
|
const publish = (name, context) => {
|
|
1909
1948
|
if (!settings.watching || !settings.devServerRef) return Promise.resolve();
|
|
1949
|
+
const environmentName = name ?? "client";
|
|
1910
1950
|
return environment(name).publish(context, (snapshot) => {
|
|
1911
|
-
settings.devServerRef?.environments
|
|
1951
|
+
const environments = settings.devServerRef?.environments;
|
|
1952
|
+
environments?.[environmentName]?.hot.send({
|
|
1912
1953
|
type: "custom",
|
|
1913
1954
|
event: "stillwind:css",
|
|
1914
1955
|
data: snapshot
|
|
1915
1956
|
});
|
|
1957
|
+
const urls = documentStylesheets.get(environmentName);
|
|
1958
|
+
if (!urls) return;
|
|
1959
|
+
const css = snapshot.parts.map((part) => part.css).join("\n");
|
|
1960
|
+
if (publishedDocumentCss.get(environmentName) === css) return;
|
|
1961
|
+
publishedDocumentCss.set(environmentName, css);
|
|
1962
|
+
const timestamp = Date.now();
|
|
1963
|
+
environments?.client?.hot.send({
|
|
1964
|
+
type: "update",
|
|
1965
|
+
updates: [...urls].sort((left, right) => right.length - left.length).map((path) => ({
|
|
1966
|
+
type: "css-update",
|
|
1967
|
+
path,
|
|
1968
|
+
acceptedPath: path,
|
|
1969
|
+
timestamp
|
|
1970
|
+
}))
|
|
1971
|
+
});
|
|
1916
1972
|
});
|
|
1917
1973
|
};
|
|
1918
1974
|
const project = {
|
|
@@ -1950,6 +2006,14 @@ function createViteProject(supplied = {}, applicationRoot = () => void 0) {
|
|
|
1950
2006
|
documentPlan: (name, context, complete = false, selection) => environment(name).documentPlan(context, complete, selection),
|
|
1951
2007
|
snapshot: (name, context) => environment(name).snapshot(context),
|
|
1952
2008
|
publish,
|
|
2009
|
+
observeDocumentStylesheet: (name, url) => {
|
|
2010
|
+
let urls = documentStylesheets.get(name);
|
|
2011
|
+
if (!urls) {
|
|
2012
|
+
urls = /* @__PURE__ */ new Set();
|
|
2013
|
+
documentStylesheets.set(name, urls);
|
|
2014
|
+
}
|
|
2015
|
+
urls.add(url);
|
|
2016
|
+
},
|
|
1953
2017
|
publicSourceMap: (name, map) => publicCssSourceMap(environment(name).browserSources, map),
|
|
1954
2018
|
cssForBrowser: (name, output, replacements) => cssForBrowser(environment(name).browserSources, output, replacements),
|
|
1955
2019
|
buildOutput: (name) => environment(name).buildOutput ?? {},
|
|
@@ -2010,6 +2074,8 @@ async function projectionImports(code, id) {
|
|
|
2010
2074
|
return [...imports];
|
|
2011
2075
|
}
|
|
2012
2076
|
// src/vite/transform.ts
|
|
2077
|
+
/** Project settings whose configured CSS entrypoint has already produced an import warning. */
|
|
2078
|
+
const warnedEntrypointImports = /* @__PURE__ */ new WeakSet();
|
|
2013
2079
|
/**
|
|
2014
2080
|
* Creates source transform and watch hooks for the project compiler plugin.
|
|
2015
2081
|
*
|
|
@@ -2021,7 +2087,8 @@ async function projectionImports(code, id) {
|
|
|
2021
2087
|
* generated modules.
|
|
2022
2088
|
* @param options - Source selection and ordering required by the framework integration.
|
|
2023
2089
|
* @returns Hooks that recompile cached producers, register stylesheet projections, reserve authored
|
|
2024
|
-
* CSS identifiers, and remove deleted inputs.
|
|
2090
|
+
* CSS identifiers, and remove deleted inputs. The transform warns once per project when the
|
|
2091
|
+
* configured CSS entrypoint is imported as an ordinary stylesheet.
|
|
2025
2092
|
*/
|
|
2026
2093
|
function transformHooks(project, virtualModules, options = {}) {
|
|
2027
2094
|
const { settings, publish, compile } = project;
|
|
@@ -2074,6 +2141,10 @@ function transformHooks(project, virtualModules, options = {}) {
|
|
|
2074
2141
|
if (typeof load === "function") return load.call(this, id);
|
|
2075
2142
|
}
|
|
2076
2143
|
if (isAuthoredStylesheet(id)) {
|
|
2144
|
+
if (project.config.css && !warnedEntrypointImports.has(settings) && relative(resolve(settings.projectRoot, project.config.css), cleanModuleId(id)) === "") {
|
|
2145
|
+
warnedEntrypointImports.add(settings);
|
|
2146
|
+
this.warn(`The Stillwind CSS entrypoint ${project.config.css} is imported as an ordinary stylesheet. The integration already delivers its compiled CSS. Remove the import so that Vite does not also emit the uncompiled Stillwind rules.`);
|
|
2147
|
+
}
|
|
2077
2148
|
await project.environment(name).reserveAuthoredCss(id, code, this);
|
|
2078
2149
|
return;
|
|
2079
2150
|
}
|
|
@@ -2571,4 +2642,4 @@ function compilerPlugin(project, transform, closed) {
|
|
|
2571
2642
|
}
|
|
2572
2643
|
export { renderChunkStyles as i, stillwind as n, createViteProject as r, createVitePlugins as t };
|
|
2573
2644
|
|
|
2574
|
-
//# sourceMappingURL=plugin-
|
|
2645
|
+
//# sourceMappingURL=plugin-DOKl8qk3.js.map
|