@typestyles/next 0.0.0-unstable.fb509f91ba06 → 0.0.0-unstable.ff74983e3aa5
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/README.md +19 -13
- package/dist/build.cjs +107 -141
- package/dist/build.js +74 -119
- package/dist/client.cjs +52 -57
- package/dist/client.js +25 -35
- package/dist/index.cjs +20 -98
- package/dist/index.js +3 -57
- package/dist/server.cjs +22 -50
- package/dist/server.js +7 -11
- package/package.json +11 -13
- package/src/build-route-css.test.ts +1 -1
- package/src/build-theme-extract.test.ts +1 -1
- package/src/build.test.ts +38 -1
- package/src/build.ts +10 -1
package/README.md
CHANGED
|
@@ -231,14 +231,17 @@ import { createTypeStyles } from 'typestyles';
|
|
|
231
231
|
|
|
232
232
|
const { recipe } = createTypeStyles({ scopeId: 'app' });
|
|
233
233
|
|
|
234
|
-
const button = recipe(
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
234
|
+
const button = recipe({
|
|
235
|
+
name: 'button',
|
|
236
|
+
styles: {
|
|
237
|
+
base: {
|
|
238
|
+
padding: '12px 24px',
|
|
239
|
+
backgroundColor: '#0066ff',
|
|
240
|
+
color: 'white',
|
|
241
|
+
border: 'none',
|
|
242
|
+
borderRadius: '6px',
|
|
243
|
+
cursor: 'pointer',
|
|
244
|
+
},
|
|
242
245
|
},
|
|
243
246
|
});
|
|
244
247
|
|
|
@@ -273,11 +276,14 @@ export const spacing = tokens.create('space', {
|
|
|
273
276
|
// app/page.tsx
|
|
274
277
|
import { recipe, colors, spacing } from './styles';
|
|
275
278
|
|
|
276
|
-
const card = recipe(
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
279
|
+
const card = recipe({
|
|
280
|
+
name: 'card',
|
|
281
|
+
styles: {
|
|
282
|
+
base: {
|
|
283
|
+
padding: spacing.md,
|
|
284
|
+
backgroundColor: colors.primary,
|
|
285
|
+
borderRadius: '8px',
|
|
286
|
+
},
|
|
281
287
|
},
|
|
282
288
|
});
|
|
283
289
|
|
package/dist/build.cjs
CHANGED
|
@@ -1,152 +1,118 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
-
for (let key of __getOwnPropNames(from))
|
|
13
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
-
}
|
|
16
|
-
return to;
|
|
17
|
-
};
|
|
18
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
-
|
|
20
|
-
// src/build.ts
|
|
21
|
-
var build_exports = {};
|
|
22
|
-
__export(build_exports, {
|
|
23
|
-
DEFAULT_EXTRACT_MODULE_CANDIDATES: () => import_build_runner2.DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
24
|
-
VerifyTypestylesBuildError: () => import_build_runner2.VerifyTypestylesBuildError,
|
|
25
|
-
buildTypestylesForNext: () => buildTypestylesForNext,
|
|
26
|
-
discoverDefaultExtractModules: () => import_build_runner2.discoverDefaultExtractModules,
|
|
27
|
-
getRouteCss: () => import_build_runner2.getRouteCss,
|
|
28
|
-
verifyTypestylesBuild: () => import_build_runner2.verifyTypestylesBuild,
|
|
29
|
-
withTypestyles: () => withTypestyles,
|
|
30
|
-
withTypestylesExtract: () => withTypestylesExtract
|
|
31
|
-
});
|
|
32
|
-
module.exports = __toCommonJS(build_exports);
|
|
33
|
-
var import_node_fs = require("fs");
|
|
34
|
-
var import_promises = require("fs/promises");
|
|
35
|
-
var import_node_module = require("module");
|
|
36
|
-
var import_node_path = require("path");
|
|
37
|
-
var import_node_url = require("url");
|
|
38
|
-
var import_build_runner = require("@typestyles/build-runner");
|
|
39
|
-
var import_build = require("typestyles/build");
|
|
40
|
-
var import_build_runner2 = require("@typestyles/build-runner");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let _typestyles_build_runner = require("@typestyles/build-runner");
|
|
3
|
+
let node_fs = require("node:fs");
|
|
4
|
+
let node_fs_promises = require("node:fs/promises");
|
|
5
|
+
let node_module = require("node:module");
|
|
6
|
+
let node_path = require("node:path");
|
|
7
|
+
let node_url = require("node:url");
|
|
8
|
+
let typestyles_build = require("typestyles/build");
|
|
9
|
+
//#region src/build.ts
|
|
41
10
|
function resolveExtractModulesForNext(root, modules) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (found.length === 0) {
|
|
47
|
-
throw new Error(
|
|
48
|
-
`[typestyles] No extraction entry found under ${root}. Add a convention file (see DEFAULT_EXTRACT_MODULE_CANDIDATES from @typestyles/build-runner) or pass modules to buildTypestylesForNext.`
|
|
49
|
-
);
|
|
50
|
-
}
|
|
51
|
-
return found;
|
|
11
|
+
if (modules !== void 0) return modules;
|
|
12
|
+
const found = (0, _typestyles_build_runner.discoverDefaultExtractModules)(root);
|
|
13
|
+
if (found.length === 0) throw new Error(`[typestyles] No extraction entry found under ${root}. Add a convention file (see DEFAULT_EXTRACT_MODULE_CANDIDATES from @typestyles/build-runner) or pass modules to buildTypestylesForNext.`);
|
|
14
|
+
return found;
|
|
52
15
|
}
|
|
53
16
|
async function buildTypestylesForNext(options) {
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
collectCss: import_build.collectStylesFromModules
|
|
89
|
-
});
|
|
90
|
-
manifest = (0, import_build_runner.buildManifestV2)(cssPath, routes);
|
|
91
|
-
}
|
|
92
|
-
const manAbs = (0, import_node_path.resolve)(root, manifestRel);
|
|
93
|
-
await (0, import_promises.mkdir)((0, import_node_path.dirname)(manAbs), { recursive: true });
|
|
94
|
-
await (0, import_promises.writeFile)(manAbs, `${JSON.stringify(manifest, null, 2)}
|
|
95
|
-
`, "utf8");
|
|
96
|
-
}
|
|
17
|
+
const { root, modules, cssOutFile = "app/typestyles.css", manifestOutFile, manifestCssPath, routeCssOutDir = "app/_typestyles/routes", appDir = "app" } = options;
|
|
18
|
+
const resolvedModules = resolveExtractModulesForNext(root, modules);
|
|
19
|
+
const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
|
|
20
|
+
let extractNonce = 0;
|
|
21
|
+
const loaders = resolvedModules.map((mod) => {
|
|
22
|
+
const abs = (0, node_path.resolve)(root, mod);
|
|
23
|
+
const href = (0, node_url.pathToFileURL)(abs).href;
|
|
24
|
+
return () => import(`${href}?typestyles-extract=${++extractNonce}`);
|
|
25
|
+
});
|
|
26
|
+
const css = await (0, typestyles_build.collectStylesFromModules)(loaders);
|
|
27
|
+
const outAbs = (0, node_path.resolve)(root, cssOutFile);
|
|
28
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(outAbs), { recursive: true });
|
|
29
|
+
await (0, node_fs_promises.writeFile)(outAbs, css, "utf8");
|
|
30
|
+
const manifestRel = manifestOutFile === false ? void 0 : manifestOutFile ?? "app/typestyles.manifest.json";
|
|
31
|
+
if (manifestRel) {
|
|
32
|
+
const cssPath = manifestCssPath ?? cssOutFile;
|
|
33
|
+
let manifest = {
|
|
34
|
+
version: 1,
|
|
35
|
+
css: cssPath
|
|
36
|
+
};
|
|
37
|
+
if (enableRouteCss) {
|
|
38
|
+
const { routes } = await (0, _typestyles_build_runner.collectAndWriteRouteCss)({
|
|
39
|
+
root,
|
|
40
|
+
sharedModules: resolvedModules,
|
|
41
|
+
appDir,
|
|
42
|
+
routeCssOutDir,
|
|
43
|
+
collectCss: typestyles_build.collectStylesFromModules
|
|
44
|
+
});
|
|
45
|
+
manifest = (0, _typestyles_build_runner.buildManifestV2)(cssPath, routes);
|
|
46
|
+
}
|
|
47
|
+
const manAbs = (0, node_path.resolve)(root, manifestRel);
|
|
48
|
+
await (0, node_fs_promises.mkdir)((0, node_path.dirname)(manAbs), { recursive: true });
|
|
49
|
+
await (0, node_fs_promises.writeFile)(manAbs, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
50
|
+
}
|
|
97
51
|
}
|
|
98
52
|
function discoverNextAppRoutesEnabled(root, appDir) {
|
|
99
|
-
|
|
53
|
+
return (0, node_fs.existsSync)((0, node_path.resolve)(root, appDir));
|
|
100
54
|
}
|
|
101
55
|
function withTypestyles(nextConfig = {}, options = {}) {
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
return nextConfig;
|
|
107
|
-
}
|
|
108
|
-
return withTypestylesExtract(nextConfig, options);
|
|
56
|
+
const projectRoot = options.root ?? process.cwd();
|
|
57
|
+
const hasConventionEntry = (0, _typestyles_build_runner.discoverDefaultExtractModules)(projectRoot).length > 0;
|
|
58
|
+
if (!(process.env.NODE_ENV === "production") || !hasConventionEntry) return nextConfig;
|
|
59
|
+
return withTypestylesExtract(nextConfig, options);
|
|
109
60
|
}
|
|
110
61
|
function withTypestylesExtract(nextConfig = {}, options = {}) {
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
console.warn(
|
|
134
|
-
"[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>."
|
|
135
|
-
);
|
|
136
|
-
}
|
|
137
|
-
}
|
|
138
|
-
return nextWebpack;
|
|
139
|
-
}
|
|
140
|
-
};
|
|
62
|
+
const disableClientRuntime = options.disableClientRuntime !== false;
|
|
63
|
+
const projectRoot = options.root ?? process.cwd();
|
|
64
|
+
return {
|
|
65
|
+
...nextConfig,
|
|
66
|
+
...disableClientRuntime ? { env: {
|
|
67
|
+
...typeof nextConfig.env === "object" && nextConfig.env !== null && !Array.isArray(nextConfig.env) ? nextConfig.env : {},
|
|
68
|
+
NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED: "true"
|
|
69
|
+
} } : {},
|
|
70
|
+
webpack(config, context) {
|
|
71
|
+
const nextWebpack = typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
72
|
+
if (disableClientRuntime && !context.isServer) {
|
|
73
|
+
try {
|
|
74
|
+
const webpackLib = (0, node_module.createRequire)((0, node_path.join)(projectRoot, "package.json"))("webpack");
|
|
75
|
+
nextWebpack.plugins.push(new webpackLib.DefinePlugin({ __TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true") }));
|
|
76
|
+
} catch {
|
|
77
|
+
console.warn("[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.");
|
|
78
|
+
}
|
|
79
|
+
nextWebpack.plugins.push(new _typestyles_build_runner.ZeroRuntimeSheetWebpackPlugin());
|
|
80
|
+
}
|
|
81
|
+
return nextWebpack;
|
|
82
|
+
}
|
|
83
|
+
};
|
|
141
84
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
85
|
+
//#endregion
|
|
86
|
+
Object.defineProperty(exports, "DEFAULT_EXTRACT_MODULE_CANDIDATES", {
|
|
87
|
+
enumerable: true,
|
|
88
|
+
get: function() {
|
|
89
|
+
return _typestyles_build_runner.DEFAULT_EXTRACT_MODULE_CANDIDATES;
|
|
90
|
+
}
|
|
91
|
+
});
|
|
92
|
+
Object.defineProperty(exports, "VerifyTypestylesBuildError", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function() {
|
|
95
|
+
return _typestyles_build_runner.VerifyTypestylesBuildError;
|
|
96
|
+
}
|
|
97
|
+
});
|
|
98
|
+
exports.buildTypestylesForNext = buildTypestylesForNext;
|
|
99
|
+
Object.defineProperty(exports, "discoverDefaultExtractModules", {
|
|
100
|
+
enumerable: true,
|
|
101
|
+
get: function() {
|
|
102
|
+
return _typestyles_build_runner.discoverDefaultExtractModules;
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
Object.defineProperty(exports, "getRouteCss", {
|
|
106
|
+
enumerable: true,
|
|
107
|
+
get: function() {
|
|
108
|
+
return _typestyles_build_runner.getRouteCss;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
Object.defineProperty(exports, "verifyTypestylesBuild", {
|
|
112
|
+
enumerable: true,
|
|
113
|
+
get: function() {
|
|
114
|
+
return _typestyles_build_runner.verifyTypestylesBuild;
|
|
115
|
+
}
|
|
152
116
|
});
|
|
117
|
+
exports.withTypestyles = withTypestyles;
|
|
118
|
+
exports.withTypestylesExtract = withTypestylesExtract;
|
package/dist/build.js
CHANGED
|
@@ -1,130 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { dirname, join, resolve } from "path";
|
|
6
|
-
import { pathToFileURL } from "url";
|
|
7
|
-
import {
|
|
8
|
-
buildManifestV2,
|
|
9
|
-
collectAndWriteRouteCss,
|
|
10
|
-
discoverDefaultExtractModules
|
|
11
|
-
} from "@typestyles/build-runner";
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
|
+
import { DEFAULT_EXTRACT_MODULE_CANDIDATES, VerifyTypestylesBuildError, ZeroRuntimeSheetWebpackPlugin, buildManifestV2, collectAndWriteRouteCss, discoverDefaultExtractModules, discoverDefaultExtractModules as discoverDefaultExtractModules$1, getRouteCss, verifyTypestylesBuild } from "@typestyles/build-runner";
|
|
3
|
+
import { existsSync } from "node:fs";
|
|
4
|
+
import { mkdir, writeFile } from "node:fs/promises";
|
|
5
|
+
import { dirname, join, resolve } from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
12
7
|
import { collectStylesFromModules } from "typestyles/build";
|
|
13
|
-
|
|
14
|
-
DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
15
|
-
discoverDefaultExtractModules as discoverDefaultExtractModules2,
|
|
16
|
-
verifyTypestylesBuild,
|
|
17
|
-
VerifyTypestylesBuildError,
|
|
18
|
-
getRouteCss
|
|
19
|
-
} from "@typestyles/build-runner";
|
|
8
|
+
//#region src/build.ts
|
|
20
9
|
function resolveExtractModulesForNext(root, modules) {
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
if (found.length === 0) {
|
|
26
|
-
throw new Error(
|
|
27
|
-
`[typestyles] No extraction entry found under ${root}. Add a convention file (see DEFAULT_EXTRACT_MODULE_CANDIDATES from @typestyles/build-runner) or pass modules to buildTypestylesForNext.`
|
|
28
|
-
);
|
|
29
|
-
}
|
|
30
|
-
return found;
|
|
10
|
+
if (modules !== void 0) return modules;
|
|
11
|
+
const found = discoverDefaultExtractModules$1(root);
|
|
12
|
+
if (found.length === 0) throw new Error(`[typestyles] No extraction entry found under ${root}. Add a convention file (see DEFAULT_EXTRACT_MODULE_CANDIDATES from @typestyles/build-runner) or pass modules to buildTypestylesForNext.`);
|
|
13
|
+
return found;
|
|
31
14
|
}
|
|
32
15
|
async function buildTypestylesForNext(options) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
collectCss: collectStylesFromModules
|
|
68
|
-
});
|
|
69
|
-
manifest = buildManifestV2(cssPath, routes);
|
|
70
|
-
}
|
|
71
|
-
const manAbs = resolve(root, manifestRel);
|
|
72
|
-
await mkdir(dirname(manAbs), { recursive: true });
|
|
73
|
-
await writeFile(manAbs, `${JSON.stringify(manifest, null, 2)}
|
|
74
|
-
`, "utf8");
|
|
75
|
-
}
|
|
16
|
+
const { root, modules, cssOutFile = "app/typestyles.css", manifestOutFile, manifestCssPath, routeCssOutDir = "app/_typestyles/routes", appDir = "app" } = options;
|
|
17
|
+
const resolvedModules = resolveExtractModulesForNext(root, modules);
|
|
18
|
+
const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
|
|
19
|
+
let extractNonce = 0;
|
|
20
|
+
const loaders = resolvedModules.map((mod) => {
|
|
21
|
+
const abs = resolve(root, mod);
|
|
22
|
+
const href = pathToFileURL(abs).href;
|
|
23
|
+
return () => import(`${href}?typestyles-extract=${++extractNonce}`);
|
|
24
|
+
});
|
|
25
|
+
const css = await collectStylesFromModules(loaders);
|
|
26
|
+
const outAbs = resolve(root, cssOutFile);
|
|
27
|
+
await mkdir(dirname(outAbs), { recursive: true });
|
|
28
|
+
await writeFile(outAbs, css, "utf8");
|
|
29
|
+
const manifestRel = manifestOutFile === false ? void 0 : manifestOutFile ?? "app/typestyles.manifest.json";
|
|
30
|
+
if (manifestRel) {
|
|
31
|
+
const cssPath = manifestCssPath ?? cssOutFile;
|
|
32
|
+
let manifest = {
|
|
33
|
+
version: 1,
|
|
34
|
+
css: cssPath
|
|
35
|
+
};
|
|
36
|
+
if (enableRouteCss) {
|
|
37
|
+
const { routes } = await collectAndWriteRouteCss({
|
|
38
|
+
root,
|
|
39
|
+
sharedModules: resolvedModules,
|
|
40
|
+
appDir,
|
|
41
|
+
routeCssOutDir,
|
|
42
|
+
collectCss: collectStylesFromModules
|
|
43
|
+
});
|
|
44
|
+
manifest = buildManifestV2(cssPath, routes);
|
|
45
|
+
}
|
|
46
|
+
const manAbs = resolve(root, manifestRel);
|
|
47
|
+
await mkdir(dirname(manAbs), { recursive: true });
|
|
48
|
+
await writeFile(manAbs, `${JSON.stringify(manifest, null, 2)}\n`, "utf8");
|
|
49
|
+
}
|
|
76
50
|
}
|
|
77
51
|
function discoverNextAppRoutesEnabled(root, appDir) {
|
|
78
|
-
|
|
52
|
+
return existsSync(resolve(root, appDir));
|
|
79
53
|
}
|
|
80
54
|
function withTypestyles(nextConfig = {}, options = {}) {
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return nextConfig;
|
|
86
|
-
}
|
|
87
|
-
return withTypestylesExtract(nextConfig, options);
|
|
55
|
+
const projectRoot = options.root ?? process.cwd();
|
|
56
|
+
const hasConventionEntry = discoverDefaultExtractModules$1(projectRoot).length > 0;
|
|
57
|
+
if (!(process.env.NODE_ENV === "production") || !hasConventionEntry) return nextConfig;
|
|
58
|
+
return withTypestylesExtract(nextConfig, options);
|
|
88
59
|
}
|
|
89
60
|
function withTypestylesExtract(nextConfig = {}, options = {}) {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
console.warn(
|
|
113
|
-
"[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>."
|
|
114
|
-
);
|
|
115
|
-
}
|
|
116
|
-
}
|
|
117
|
-
return nextWebpack;
|
|
118
|
-
}
|
|
119
|
-
};
|
|
61
|
+
const disableClientRuntime = options.disableClientRuntime !== false;
|
|
62
|
+
const projectRoot = options.root ?? process.cwd();
|
|
63
|
+
return {
|
|
64
|
+
...nextConfig,
|
|
65
|
+
...disableClientRuntime ? { env: {
|
|
66
|
+
...typeof nextConfig.env === "object" && nextConfig.env !== null && !Array.isArray(nextConfig.env) ? nextConfig.env : {},
|
|
67
|
+
NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED: "true"
|
|
68
|
+
} } : {},
|
|
69
|
+
webpack(config, context) {
|
|
70
|
+
const nextWebpack = typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
71
|
+
if (disableClientRuntime && !context.isServer) {
|
|
72
|
+
try {
|
|
73
|
+
const webpackLib = createRequire(join(projectRoot, "package.json"))("webpack");
|
|
74
|
+
nextWebpack.plugins.push(new webpackLib.DefinePlugin({ __TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true") }));
|
|
75
|
+
} catch {
|
|
76
|
+
console.warn("[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.");
|
|
77
|
+
}
|
|
78
|
+
nextWebpack.plugins.push(new ZeroRuntimeSheetWebpackPlugin());
|
|
79
|
+
}
|
|
80
|
+
return nextWebpack;
|
|
81
|
+
}
|
|
82
|
+
};
|
|
120
83
|
}
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
VerifyTypestylesBuildError,
|
|
124
|
-
buildTypestylesForNext,
|
|
125
|
-
discoverDefaultExtractModules2 as discoverDefaultExtractModules,
|
|
126
|
-
getRouteCss,
|
|
127
|
-
verifyTypestylesBuild,
|
|
128
|
-
withTypestyles,
|
|
129
|
-
withTypestylesExtract
|
|
130
|
-
};
|
|
84
|
+
//#endregion
|
|
85
|
+
export { DEFAULT_EXTRACT_MODULE_CANDIDATES, VerifyTypestylesBuildError, buildTypestylesForNext, discoverDefaultExtractModules, getRouteCss, verifyTypestylesBuild, withTypestyles, withTypestylesExtract };
|
package/dist/client.cjs
CHANGED
|
@@ -1,71 +1,66 @@
|
|
|
1
|
-
"use strict";
|
|
2
1
|
"use client";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
//#region \0rolldown/runtime.js
|
|
4
|
+
var __create = Object.create;
|
|
3
5
|
var __defProp = Object.defineProperty;
|
|
4
6
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
7
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
6
9
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __export = (target, all) => {
|
|
8
|
-
for (var name in all)
|
|
9
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
-
};
|
|
11
10
|
var __copyProps = (to, from, except, desc) => {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
12
|
+
key = keys[i];
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
14
|
+
get: ((k) => from[k]).bind(null, key),
|
|
15
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return to;
|
|
18
19
|
};
|
|
19
|
-
var
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
module.exports = __toCommonJS(client_exports);
|
|
30
|
-
var import_react = require("react");
|
|
31
|
-
var import_server = require("typestyles/server");
|
|
32
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
21
|
+
value: mod,
|
|
22
|
+
enumerable: true
|
|
23
|
+
}) : target, mod));
|
|
24
|
+
//#endregion
|
|
25
|
+
let typestyles_server = require("typestyles/server");
|
|
26
|
+
let react = require("react");
|
|
27
|
+
react = __toESM(react, 1);
|
|
28
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
29
|
+
//#region src/client.tsx
|
|
33
30
|
function useTypestyles() {
|
|
34
|
-
|
|
35
|
-
import_server.subscribeRegisteredCss,
|
|
36
|
-
() => (0, import_server.getRegisteredCss)(),
|
|
37
|
-
() => (0, import_server.getRegisteredCss)()
|
|
38
|
-
);
|
|
31
|
+
return (0, react.useSyncExternalStore)(typestyles_server.subscribeRegisteredCss, () => (0, typestyles_server.getRegisteredCss)(), () => (0, typestyles_server.getRegisteredCss)());
|
|
39
32
|
}
|
|
40
33
|
function TypestylesStylesheet({ children }) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
return null;
|
|
34
|
+
const [css, setCss] = (0, react.useState)("");
|
|
35
|
+
(0, react.useServerInsertedHTML)(() => {
|
|
36
|
+
const registeredCss = (0, typestyles_server.getRegisteredCss)();
|
|
37
|
+
if (registeredCss) return (0, react_jsx_runtime.jsx)("style", {
|
|
38
|
+
id: "typestyles",
|
|
39
|
+
dangerouslySetInnerHTML: { __html: registeredCss }
|
|
40
|
+
});
|
|
41
|
+
return null;
|
|
42
|
+
});
|
|
43
|
+
(0, react.useEffect)(() => {
|
|
44
|
+
setCss((0, typestyles_server.getRegisteredCss)());
|
|
45
|
+
}, []);
|
|
46
|
+
if (children) return (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [children, (0, react_jsx_runtime.jsx)("style", {
|
|
47
|
+
id: "typestyles-client",
|
|
48
|
+
dangerouslySetInnerHTML: { __html: css }
|
|
49
|
+
})] });
|
|
50
|
+
return null;
|
|
59
51
|
}
|
|
60
52
|
function createTypestylesLayout(layout) {
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
53
|
+
return function TypestylesLayout(props) {
|
|
54
|
+
return (0, react_jsx_runtime.jsx)(TypestylesStylesheet, { children: layout(props) });
|
|
55
|
+
};
|
|
64
56
|
}
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
57
|
+
//#endregion
|
|
58
|
+
exports.TypestylesStylesheet = TypestylesStylesheet;
|
|
59
|
+
exports.createTypestylesLayout = createTypestylesLayout;
|
|
60
|
+
Object.defineProperty(exports, "useServerInsertedHTML", {
|
|
61
|
+
enumerable: true,
|
|
62
|
+
get: function() {
|
|
63
|
+
return react.useServerInsertedHTML;
|
|
64
|
+
}
|
|
71
65
|
});
|
|
66
|
+
exports.useTypestyles = useTypestyles;
|
package/dist/client.js
CHANGED
|
@@ -1,44 +1,34 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
|
|
3
|
-
// src/client.tsx
|
|
4
|
-
import { useState, useEffect, useServerInsertedHTML, useSyncExternalStore } from "react";
|
|
5
2
|
import { getRegisteredCss, subscribeRegisteredCss } from "typestyles/server";
|
|
3
|
+
import { useEffect, useServerInsertedHTML, useState, useSyncExternalStore } from "react";
|
|
6
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/client.tsx
|
|
7
6
|
function useTypestyles() {
|
|
8
|
-
|
|
9
|
-
subscribeRegisteredCss,
|
|
10
|
-
() => getRegisteredCss(),
|
|
11
|
-
() => getRegisteredCss()
|
|
12
|
-
);
|
|
7
|
+
return useSyncExternalStore(subscribeRegisteredCss, () => getRegisteredCss(), () => getRegisteredCss());
|
|
13
8
|
}
|
|
14
9
|
function TypestylesStylesheet({ children }) {
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
return null;
|
|
10
|
+
const [css, setCss] = useState("");
|
|
11
|
+
useServerInsertedHTML(() => {
|
|
12
|
+
const registeredCss = getRegisteredCss();
|
|
13
|
+
if (registeredCss) return jsx("style", {
|
|
14
|
+
id: "typestyles",
|
|
15
|
+
dangerouslySetInnerHTML: { __html: registeredCss }
|
|
16
|
+
});
|
|
17
|
+
return null;
|
|
18
|
+
});
|
|
19
|
+
useEffect(() => {
|
|
20
|
+
setCss(getRegisteredCss());
|
|
21
|
+
}, []);
|
|
22
|
+
if (children) return jsxs(Fragment, { children: [children, jsx("style", {
|
|
23
|
+
id: "typestyles-client",
|
|
24
|
+
dangerouslySetInnerHTML: { __html: css }
|
|
25
|
+
})] });
|
|
26
|
+
return null;
|
|
33
27
|
}
|
|
34
28
|
function createTypestylesLayout(layout) {
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
29
|
+
return function TypestylesLayout(props) {
|
|
30
|
+
return jsx(TypestylesStylesheet, { children: layout(props) });
|
|
31
|
+
};
|
|
38
32
|
}
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
createTypestylesLayout,
|
|
42
|
-
useServerInsertedHTML,
|
|
43
|
-
useTypestyles
|
|
44
|
-
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { TypestylesStylesheet, createTypestylesLayout, useServerInsertedHTML, useTypestyles };
|
package/dist/index.cjs
CHANGED
|
@@ -1,100 +1,22 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/index.tsx
|
|
31
|
-
var index_exports = {};
|
|
32
|
-
__export(index_exports, {
|
|
33
|
-
TypestylesStylesheet: () => TypestylesStylesheet,
|
|
34
|
-
collectStylesFromComponent: () => collectStylesFromComponent,
|
|
35
|
-
createTypestylesLayout: () => createTypestylesLayout,
|
|
36
|
-
getRegisteredCss: () => import_server.getRegisteredCss,
|
|
37
|
-
getTypestylesMetadata: () => getTypestylesMetadata,
|
|
38
|
-
useServerInsertedHTML: () => import_react.useServerInsertedHTML,
|
|
39
|
-
useTypestyles: () => useTypestyles
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_server = require("./server.cjs");
|
|
3
|
+
const require_client = require("./client.cjs");
|
|
4
|
+
let typestyles_server = require("typestyles/server");
|
|
5
|
+
let react = require("react");
|
|
6
|
+
exports.TypestylesStylesheet = require_client.TypestylesStylesheet;
|
|
7
|
+
exports.collectStylesFromComponent = require_server.collectStylesFromComponent;
|
|
8
|
+
exports.createTypestylesLayout = require_client.createTypestylesLayout;
|
|
9
|
+
Object.defineProperty(exports, "getRegisteredCss", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function() {
|
|
12
|
+
return typestyles_server.getRegisteredCss;
|
|
13
|
+
}
|
|
40
14
|
});
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
const { renderToString } = await import("react-dom/server");
|
|
48
|
-
const { css } = (0, import_server.collectStyles)(() => renderToString(component));
|
|
49
|
-
return css;
|
|
50
|
-
}
|
|
51
|
-
async function getTypestylesMetadata(component) {
|
|
52
|
-
return collectStylesFromComponent(component);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
// src/client.tsx
|
|
56
|
-
var import_react = require("react");
|
|
57
|
-
var import_server2 = require("typestyles/server");
|
|
58
|
-
var import_jsx_runtime = require("react/jsx-runtime");
|
|
59
|
-
function useTypestyles() {
|
|
60
|
-
return (0, import_react.useSyncExternalStore)(
|
|
61
|
-
import_server2.subscribeRegisteredCss,
|
|
62
|
-
() => (0, import_server2.getRegisteredCss)(),
|
|
63
|
-
() => (0, import_server2.getRegisteredCss)()
|
|
64
|
-
);
|
|
65
|
-
}
|
|
66
|
-
function TypestylesStylesheet({ children }) {
|
|
67
|
-
const [css, setCss] = (0, import_react.useState)("");
|
|
68
|
-
(0, import_react.useServerInsertedHTML)(() => {
|
|
69
|
-
const registeredCss = (0, import_server2.getRegisteredCss)();
|
|
70
|
-
if (registeredCss) {
|
|
71
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { id: "typestyles", dangerouslySetInnerHTML: { __html: registeredCss } });
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
});
|
|
75
|
-
(0, import_react.useEffect)(() => {
|
|
76
|
-
setCss((0, import_server2.getRegisteredCss)());
|
|
77
|
-
}, []);
|
|
78
|
-
if (children) {
|
|
79
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
80
|
-
children,
|
|
81
|
-
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { id: "typestyles-client", dangerouslySetInnerHTML: { __html: css } })
|
|
82
|
-
] });
|
|
83
|
-
}
|
|
84
|
-
return null;
|
|
85
|
-
}
|
|
86
|
-
function createTypestylesLayout(layout) {
|
|
87
|
-
return function TypestylesLayout(props) {
|
|
88
|
-
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TypestylesStylesheet, { children: layout(props) });
|
|
89
|
-
};
|
|
90
|
-
}
|
|
91
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
92
|
-
0 && (module.exports = {
|
|
93
|
-
TypestylesStylesheet,
|
|
94
|
-
collectStylesFromComponent,
|
|
95
|
-
createTypestylesLayout,
|
|
96
|
-
getRegisteredCss,
|
|
97
|
-
getTypestylesMetadata,
|
|
98
|
-
useServerInsertedHTML,
|
|
99
|
-
useTypestyles
|
|
15
|
+
exports.getTypestylesMetadata = require_server.getTypestylesMetadata;
|
|
16
|
+
Object.defineProperty(exports, "useServerInsertedHTML", {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function() {
|
|
19
|
+
return react.useServerInsertedHTML;
|
|
20
|
+
}
|
|
100
21
|
});
|
|
22
|
+
exports.useTypestyles = require_client.useTypestyles;
|
package/dist/index.js
CHANGED
|
@@ -1,57 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
async function collectStylesFromComponent(component) {
|
|
5
|
-
const { renderToString } = await import("react-dom/server");
|
|
6
|
-
const { css } = collectStyles(() => renderToString(component));
|
|
7
|
-
return css;
|
|
8
|
-
}
|
|
9
|
-
async function getTypestylesMetadata(component) {
|
|
10
|
-
return collectStylesFromComponent(component);
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
// src/client.tsx
|
|
14
|
-
import { useState, useEffect, useServerInsertedHTML, useSyncExternalStore } from "react";
|
|
15
|
-
import { getRegisteredCss as getRegisteredCss2, subscribeRegisteredCss } from "typestyles/server";
|
|
16
|
-
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
17
|
-
function useTypestyles() {
|
|
18
|
-
return useSyncExternalStore(
|
|
19
|
-
subscribeRegisteredCss,
|
|
20
|
-
() => getRegisteredCss2(),
|
|
21
|
-
() => getRegisteredCss2()
|
|
22
|
-
);
|
|
23
|
-
}
|
|
24
|
-
function TypestylesStylesheet({ children }) {
|
|
25
|
-
const [css, setCss] = useState("");
|
|
26
|
-
useServerInsertedHTML(() => {
|
|
27
|
-
const registeredCss = getRegisteredCss2();
|
|
28
|
-
if (registeredCss) {
|
|
29
|
-
return /* @__PURE__ */ jsx("style", { id: "typestyles", dangerouslySetInnerHTML: { __html: registeredCss } });
|
|
30
|
-
}
|
|
31
|
-
return null;
|
|
32
|
-
});
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setCss(getRegisteredCss2());
|
|
35
|
-
}, []);
|
|
36
|
-
if (children) {
|
|
37
|
-
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
38
|
-
children,
|
|
39
|
-
/* @__PURE__ */ jsx("style", { id: "typestyles-client", dangerouslySetInnerHTML: { __html: css } })
|
|
40
|
-
] });
|
|
41
|
-
}
|
|
42
|
-
return null;
|
|
43
|
-
}
|
|
44
|
-
function createTypestylesLayout(layout) {
|
|
45
|
-
return function TypestylesLayout(props) {
|
|
46
|
-
return /* @__PURE__ */ jsx(TypestylesStylesheet, { children: layout(props) });
|
|
47
|
-
};
|
|
48
|
-
}
|
|
49
|
-
export {
|
|
50
|
-
TypestylesStylesheet,
|
|
51
|
-
collectStylesFromComponent,
|
|
52
|
-
createTypestylesLayout,
|
|
53
|
-
getRegisteredCss,
|
|
54
|
-
getTypestylesMetadata,
|
|
55
|
-
useServerInsertedHTML,
|
|
56
|
-
useTypestyles
|
|
57
|
-
};
|
|
1
|
+
import { collectStylesFromComponent, getRegisteredCss, getTypestylesMetadata } from "./server.js";
|
|
2
|
+
import { TypestylesStylesheet, createTypestylesLayout, useServerInsertedHTML, useTypestyles } from "./client.js";
|
|
3
|
+
export { TypestylesStylesheet, collectStylesFromComponent, createTypestylesLayout, getRegisteredCss, getTypestylesMetadata, useServerInsertedHTML, useTypestyles };
|
package/dist/server.cjs
CHANGED
|
@@ -1,55 +1,27 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
|
|
30
|
-
// src/server.ts
|
|
31
|
-
var server_exports = {};
|
|
32
|
-
__export(server_exports, {
|
|
33
|
-
collectStylesFromComponent: () => collectStylesFromComponent,
|
|
34
|
-
getRegisteredCss: () => import_server.getRegisteredCss,
|
|
35
|
-
getRouteCss: () => import_build_runner.getRouteCss,
|
|
36
|
-
getTypestylesMetadata: () => getTypestylesMetadata
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(server_exports);
|
|
39
|
-
var import_server = require("typestyles/server");
|
|
40
|
-
var import_build_runner = require("@typestyles/build-runner");
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
let typestyles_server = require("typestyles/server");
|
|
3
|
+
let _typestyles_build_runner = require("@typestyles/build-runner");
|
|
4
|
+
//#region src/server.ts
|
|
41
5
|
async function collectStylesFromComponent(component) {
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
6
|
+
const { renderToString } = await import("react-dom/server");
|
|
7
|
+
const { css } = (0, typestyles_server.collectStyles)(() => renderToString(component));
|
|
8
|
+
return css;
|
|
45
9
|
}
|
|
46
10
|
async function getTypestylesMetadata(component) {
|
|
47
|
-
|
|
11
|
+
return collectStylesFromComponent(component);
|
|
48
12
|
}
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
13
|
+
//#endregion
|
|
14
|
+
exports.collectStylesFromComponent = collectStylesFromComponent;
|
|
15
|
+
Object.defineProperty(exports, "getRegisteredCss", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function() {
|
|
18
|
+
return typestyles_server.getRegisteredCss;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "getRouteCss", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function() {
|
|
24
|
+
return _typestyles_build_runner.getRouteCss;
|
|
25
|
+
}
|
|
55
26
|
});
|
|
27
|
+
exports.getTypestylesMetadata = getTypestylesMetadata;
|
package/dist/server.js
CHANGED
|
@@ -1,17 +1,13 @@
|
|
|
1
|
-
// src/server.ts
|
|
2
1
|
import { collectStyles, getRegisteredCss } from "typestyles/server";
|
|
3
2
|
import { getRouteCss } from "@typestyles/build-runner";
|
|
3
|
+
//#region src/server.ts
|
|
4
4
|
async function collectStylesFromComponent(component) {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
5
|
+
const { renderToString } = await import("react-dom/server");
|
|
6
|
+
const { css } = collectStyles(() => renderToString(component));
|
|
7
|
+
return css;
|
|
8
8
|
}
|
|
9
9
|
async function getTypestylesMetadata(component) {
|
|
10
|
-
|
|
10
|
+
return collectStylesFromComponent(component);
|
|
11
11
|
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
getRegisteredCss,
|
|
15
|
-
getRouteCss,
|
|
16
|
-
getTypestylesMetadata
|
|
17
|
-
};
|
|
12
|
+
//#endregion
|
|
13
|
+
export { collectStylesFromComponent, getRegisteredCss, getRouteCss, getTypestylesMetadata };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@typestyles/next",
|
|
3
|
-
"version": "0.0.0-unstable.
|
|
3
|
+
"version": "0.0.0-unstable.ff74983e3aa5",
|
|
4
4
|
"description": "Next.js integration for typestyles SSR",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.cjs",
|
|
@@ -43,7 +43,7 @@
|
|
|
43
43
|
"license": "Apache-2.0",
|
|
44
44
|
"repository": {
|
|
45
45
|
"type": "git",
|
|
46
|
-
"url": "https://github.com/
|
|
46
|
+
"url": "https://github.com/phthalo-dev/typestyles",
|
|
47
47
|
"directory": "packages/next"
|
|
48
48
|
},
|
|
49
49
|
"peerDependencies": {
|
|
@@ -68,26 +68,24 @@
|
|
|
68
68
|
}
|
|
69
69
|
},
|
|
70
70
|
"dependencies": {
|
|
71
|
-
"@typestyles/build-runner": "0.0.0-unstable.
|
|
71
|
+
"@typestyles/build-runner": "0.0.0-unstable.ff74983e3aa5"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
|
-
"
|
|
75
|
-
"
|
|
76
|
-
"@types/node": "^25.2.1",
|
|
74
|
+
"vitest": "5.0.5",
|
|
75
|
+
"@types/node": "^24.13.0",
|
|
77
76
|
"@types/react": "^18.3.12",
|
|
78
77
|
"@types/react-dom": "^18.3.1",
|
|
79
78
|
"next": "^14.0.0",
|
|
80
79
|
"react": "^18.0.0",
|
|
81
80
|
"react-dom": "^18.0.0",
|
|
82
|
-
"
|
|
83
|
-
"
|
|
84
|
-
"
|
|
85
|
-
"
|
|
81
|
+
"typestyles": "0.0.0-unstable.ff74983e3aa5",
|
|
82
|
+
"typescript": "^6.0.0",
|
|
83
|
+
"webpack": "^5.97.1",
|
|
84
|
+
"vite-plus": "1.3.0"
|
|
86
85
|
},
|
|
87
86
|
"scripts": {
|
|
88
|
-
"build": "
|
|
89
|
-
"test": "
|
|
90
|
-
"lint": "eslint .",
|
|
87
|
+
"build": "vp pack",
|
|
88
|
+
"test": "vp test run",
|
|
91
89
|
"typecheck": "tsc --noEmit"
|
|
92
90
|
}
|
|
93
91
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
|
-
import { describe, expect, it } from '
|
|
4
|
+
import { describe, expect, it } from 'vite-plus/test';
|
|
5
5
|
import { buildTypestylesForNext } from './build';
|
|
6
6
|
|
|
7
7
|
describe('buildTypestylesForNext route CSS', () => {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { join } from 'node:path';
|
|
3
3
|
import { tmpdir } from 'node:os';
|
|
4
|
-
import { describe, expect, it } from '
|
|
4
|
+
import { describe, expect, it } from 'vite-plus/test';
|
|
5
5
|
import { buildTypestylesForNext, verifyTypestylesBuild } from './build';
|
|
6
6
|
|
|
7
7
|
describe('buildTypestylesForNext theme extraction', () => {
|
package/src/build.test.ts
CHANGED
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
2
|
import { tmpdir } from 'node:os';
|
|
3
3
|
import { join } from 'node:path';
|
|
4
|
-
import { describe, it, expect, vi } from '
|
|
4
|
+
import { describe, it, expect, vi } from 'vite-plus/test';
|
|
5
5
|
import type { NextConfig } from 'next';
|
|
6
6
|
import type { Configuration } from 'webpack';
|
|
7
|
+
import { ZeroRuntimeSheetWebpackPlugin } from '@typestyles/build-runner';
|
|
7
8
|
import { withTypestyles, withTypestylesExtract } from './build';
|
|
8
9
|
|
|
9
10
|
type WebpackContext = Parameters<NonNullable<NextConfig['webpack']>>[1];
|
|
@@ -47,6 +48,42 @@ describe('withTypestylesExtract', () => {
|
|
|
47
48
|
expect(hasDefine).toBe(true);
|
|
48
49
|
});
|
|
49
50
|
|
|
51
|
+
it('adds the zero-runtime sheet plugin only on client bundles', async () => {
|
|
52
|
+
const merged = withTypestylesExtract({});
|
|
53
|
+
const webpackHook = merged.webpack;
|
|
54
|
+
if (typeof webpackHook !== 'function') {
|
|
55
|
+
throw new Error('expected webpack hook');
|
|
56
|
+
}
|
|
57
|
+
const hasPlugin = (config: Configuration): boolean =>
|
|
58
|
+
(config.plugins ?? []).some((p) => p instanceof ZeroRuntimeSheetWebpackPlugin);
|
|
59
|
+
|
|
60
|
+
const client = webpackHook(
|
|
61
|
+
{ plugins: [] } as Configuration,
|
|
62
|
+
{ isServer: false } as WebpackContext,
|
|
63
|
+
);
|
|
64
|
+
expect(hasPlugin(client)).toBe(true);
|
|
65
|
+
expect(client.resolve?.alias).toBeUndefined();
|
|
66
|
+
|
|
67
|
+
const server = webpackHook(
|
|
68
|
+
{ plugins: [] } as Configuration,
|
|
69
|
+
{ isServer: true } as WebpackContext,
|
|
70
|
+
);
|
|
71
|
+
expect(hasPlugin(server)).toBe(false);
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('leaves existing resolve aliases untouched', () => {
|
|
75
|
+
const merged = withTypestylesExtract({});
|
|
76
|
+
const webpackHook = merged.webpack;
|
|
77
|
+
if (typeof webpackHook !== 'function') {
|
|
78
|
+
throw new Error('expected webpack hook');
|
|
79
|
+
}
|
|
80
|
+
const preserved = webpackHook(
|
|
81
|
+
{ plugins: [], resolve: { alias: { '@typestyles/vite': '/abs/vite.js' } } } as Configuration,
|
|
82
|
+
{ isServer: false } as WebpackContext,
|
|
83
|
+
);
|
|
84
|
+
expect(preserved.resolve?.alias).toEqual({ '@typestyles/vite': '/abs/vite.js' });
|
|
85
|
+
});
|
|
86
|
+
|
|
50
87
|
it('applies extract in production when a convention entry exists under root', () => {
|
|
51
88
|
const dir = mkdtempSync(join(tmpdir(), 'typestyles-next-cwd-'));
|
|
52
89
|
mkdirSync(join(dir, 'styles'), { recursive: true });
|
package/src/build.ts
CHANGED
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
buildManifestV2,
|
|
8
8
|
collectAndWriteRouteCss,
|
|
9
9
|
discoverDefaultExtractModules,
|
|
10
|
+
ZeroRuntimeSheetWebpackPlugin,
|
|
10
11
|
type TypestylesExtractManifestV1,
|
|
11
12
|
type TypestylesExtractManifestV2,
|
|
12
13
|
} from '@typestyles/build-runner';
|
|
@@ -184,7 +185,8 @@ export function withTypestyles(
|
|
|
184
185
|
/**
|
|
185
186
|
* Merge Next.js config so client bundles use pre-extracted CSS only (no runtime `<style>` injection).
|
|
186
187
|
*
|
|
187
|
-
* - **Webpack**: adds `DefinePlugin` for `__TYPESTYLES_RUNTIME_DISABLED__` on client bundles
|
|
188
|
+
* - **Webpack**: adds `DefinePlugin` for `__TYPESTYLES_RUNTIME_DISABLED__` on client bundles and
|
|
189
|
+
* resolves `typestyles` → `typestyles/core` (pure, name-only build — no CSS runtime in the client).
|
|
188
190
|
* - **Turbopack** (`next dev --turbo` / Turbopack production): webpack hooks do not run; the same
|
|
189
191
|
* `next.config` `env` entry `NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED` is merged so the client
|
|
190
192
|
* bundle still disables runtime insertion (see `typestyles` `sheet` implementation).
|
|
@@ -228,6 +230,13 @@ export function withTypestylesExtract(
|
|
|
228
230
|
'[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>.',
|
|
229
231
|
);
|
|
230
232
|
}
|
|
233
|
+
|
|
234
|
+
// Zero-runtime: redirect typestyles' `sheet` module to its no-op
|
|
235
|
+
// sibling. Class names / data attributes are computed identically; the
|
|
236
|
+
// CSS insertion runtime, stylesheet state, and DOM plumbing never enter
|
|
237
|
+
// the client graph. Server bundles keep the real runtime (SSR
|
|
238
|
+
// collection / route CSS depends on it).
|
|
239
|
+
nextWebpack.plugins.push(new ZeroRuntimeSheetWebpackPlugin() as never);
|
|
231
240
|
}
|
|
232
241
|
|
|
233
242
|
return nextWebpack;
|