@typestyles/next 0.0.0-unstable.00cf16386ea7
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 +204 -0
- package/README.md +342 -0
- package/dist/build.cjs +151 -0
- package/dist/build.js +129 -0
- package/dist/client.cjs +71 -0
- package/dist/client.js +44 -0
- package/dist/index.cjs +100 -0
- package/dist/index.js +57 -0
- package/dist/server.cjs +55 -0
- package/dist/server.js +17 -0
- package/package.json +93 -0
- package/src/build-route-css.test.ts +48 -0
- package/src/build-theme-extract.test.ts +40 -0
- package/src/build.d.ts +70 -0
- package/src/build.test.ts +104 -0
- package/src/build.ts +233 -0
- package/src/client.d.ts +33 -0
- package/src/client.tsx +144 -0
- package/src/index.d.ts +15 -0
- package/src/index.tsx +27 -0
- package/src/react-augmentation.d.ts +13 -0
- package/src/server.d.ts +9 -0
- package/src/server.ts +56 -0
package/dist/build.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// src/build.ts
|
|
2
|
+
import { existsSync } from "fs";
|
|
3
|
+
import { mkdir, writeFile } from "fs/promises";
|
|
4
|
+
import { createRequire } from "module";
|
|
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";
|
|
12
|
+
import { collectStylesFromModules } from "typestyles/build";
|
|
13
|
+
import {
|
|
14
|
+
DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
15
|
+
discoverDefaultExtractModules as discoverDefaultExtractModules2,
|
|
16
|
+
verifyTypestylesBuild,
|
|
17
|
+
VerifyTypestylesBuildError,
|
|
18
|
+
getRouteCss
|
|
19
|
+
} from "@typestyles/build-runner";
|
|
20
|
+
function resolveExtractModulesForNext(root, modules) {
|
|
21
|
+
if (modules !== void 0) {
|
|
22
|
+
return modules;
|
|
23
|
+
}
|
|
24
|
+
const found = discoverDefaultExtractModules(root);
|
|
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;
|
|
31
|
+
}
|
|
32
|
+
async function buildTypestylesForNext(options) {
|
|
33
|
+
const {
|
|
34
|
+
root,
|
|
35
|
+
modules,
|
|
36
|
+
cssOutFile = "app/typestyles.css",
|
|
37
|
+
manifestOutFile,
|
|
38
|
+
manifestCssPath,
|
|
39
|
+
routeCssOutDir = "app/_typestyles/routes",
|
|
40
|
+
appDir = "app"
|
|
41
|
+
} = options;
|
|
42
|
+
const resolvedModules = resolveExtractModulesForNext(root, modules);
|
|
43
|
+
const enableRouteCss = options.routeCss ?? discoverNextAppRoutesEnabled(root, appDir);
|
|
44
|
+
const loaders = resolvedModules.map((mod) => {
|
|
45
|
+
const abs = resolve(root, mod);
|
|
46
|
+
const href = pathToFileURL(abs).href;
|
|
47
|
+
return () => import(href);
|
|
48
|
+
});
|
|
49
|
+
const css = await collectStylesFromModules(loaders);
|
|
50
|
+
const outAbs = resolve(root, cssOutFile);
|
|
51
|
+
await mkdir(dirname(outAbs), { recursive: true });
|
|
52
|
+
await writeFile(outAbs, css, "utf8");
|
|
53
|
+
const manifestRel = manifestOutFile === false ? void 0 : manifestOutFile ?? "app/typestyles.manifest.json";
|
|
54
|
+
if (manifestRel) {
|
|
55
|
+
const cssPath = manifestCssPath ?? cssOutFile;
|
|
56
|
+
let manifest = {
|
|
57
|
+
version: 1,
|
|
58
|
+
css: cssPath
|
|
59
|
+
};
|
|
60
|
+
if (enableRouteCss) {
|
|
61
|
+
const { routes } = await collectAndWriteRouteCss({
|
|
62
|
+
root,
|
|
63
|
+
sharedModules: resolvedModules,
|
|
64
|
+
appDir,
|
|
65
|
+
routeCssOutDir,
|
|
66
|
+
collectCss: collectStylesFromModules
|
|
67
|
+
});
|
|
68
|
+
manifest = buildManifestV2(cssPath, routes);
|
|
69
|
+
}
|
|
70
|
+
const manAbs = resolve(root, manifestRel);
|
|
71
|
+
await mkdir(dirname(manAbs), { recursive: true });
|
|
72
|
+
await writeFile(manAbs, `${JSON.stringify(manifest, null, 2)}
|
|
73
|
+
`, "utf8");
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
function discoverNextAppRoutesEnabled(root, appDir) {
|
|
77
|
+
return existsSync(resolve(root, appDir));
|
|
78
|
+
}
|
|
79
|
+
function withTypestyles(nextConfig = {}, options = {}) {
|
|
80
|
+
const projectRoot = options.root ?? process.cwd();
|
|
81
|
+
const hasConventionEntry = discoverDefaultExtractModules(projectRoot).length > 0;
|
|
82
|
+
const prod = process.env.NODE_ENV === "production";
|
|
83
|
+
if (!prod || !hasConventionEntry) {
|
|
84
|
+
return nextConfig;
|
|
85
|
+
}
|
|
86
|
+
return withTypestylesExtract(nextConfig, options);
|
|
87
|
+
}
|
|
88
|
+
function withTypestylesExtract(nextConfig = {}, options = {}) {
|
|
89
|
+
const disableClientRuntime = options.disableClientRuntime !== false;
|
|
90
|
+
const projectRoot = options.root ?? process.cwd();
|
|
91
|
+
return {
|
|
92
|
+
...nextConfig,
|
|
93
|
+
...disableClientRuntime ? {
|
|
94
|
+
env: {
|
|
95
|
+
...typeof nextConfig.env === "object" && nextConfig.env !== null && !Array.isArray(nextConfig.env) ? nextConfig.env : {},
|
|
96
|
+
NEXT_PUBLIC_TYPESTYLES_RUNTIME_DISABLED: "true"
|
|
97
|
+
}
|
|
98
|
+
} : {},
|
|
99
|
+
webpack(config, context) {
|
|
100
|
+
const nextWebpack = typeof nextConfig.webpack === "function" ? nextConfig.webpack(config, context) : config;
|
|
101
|
+
if (disableClientRuntime && !context.isServer) {
|
|
102
|
+
try {
|
|
103
|
+
const require2 = createRequire(join(projectRoot, "package.json"));
|
|
104
|
+
const webpackLib = require2("webpack");
|
|
105
|
+
nextWebpack.plugins.push(
|
|
106
|
+
new webpackLib.DefinePlugin({
|
|
107
|
+
__TYPESTYLES_RUNTIME_DISABLED__: JSON.stringify("true")
|
|
108
|
+
})
|
|
109
|
+
);
|
|
110
|
+
} catch {
|
|
111
|
+
console.warn(
|
|
112
|
+
"[@typestyles/next/build] Could not load webpack; client bundles may still inject <style>."
|
|
113
|
+
);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return nextWebpack;
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
export {
|
|
121
|
+
DEFAULT_EXTRACT_MODULE_CANDIDATES,
|
|
122
|
+
VerifyTypestylesBuildError,
|
|
123
|
+
buildTypestylesForNext,
|
|
124
|
+
discoverDefaultExtractModules2 as discoverDefaultExtractModules,
|
|
125
|
+
getRouteCss,
|
|
126
|
+
verifyTypestylesBuild,
|
|
127
|
+
withTypestyles,
|
|
128
|
+
withTypestylesExtract
|
|
129
|
+
};
|
package/dist/client.cjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
"use client";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
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
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/client.tsx
|
|
22
|
+
var client_exports = {};
|
|
23
|
+
__export(client_exports, {
|
|
24
|
+
TypestylesStylesheet: () => TypestylesStylesheet,
|
|
25
|
+
createTypestylesLayout: () => createTypestylesLayout,
|
|
26
|
+
useServerInsertedHTML: () => import_react.useServerInsertedHTML,
|
|
27
|
+
useTypestyles: () => useTypestyles
|
|
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");
|
|
33
|
+
function useTypestyles() {
|
|
34
|
+
return (0, import_react.useSyncExternalStore)(
|
|
35
|
+
import_server.subscribeRegisteredCss,
|
|
36
|
+
() => (0, import_server.getRegisteredCss)(),
|
|
37
|
+
() => (0, import_server.getRegisteredCss)()
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
function TypestylesStylesheet({ children }) {
|
|
41
|
+
const [css, setCss] = (0, import_react.useState)("");
|
|
42
|
+
(0, import_react.useServerInsertedHTML)(() => {
|
|
43
|
+
const registeredCss = (0, import_server.getRegisteredCss)();
|
|
44
|
+
if (registeredCss) {
|
|
45
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { id: "typestyles", dangerouslySetInnerHTML: { __html: registeredCss } });
|
|
46
|
+
}
|
|
47
|
+
return null;
|
|
48
|
+
});
|
|
49
|
+
(0, import_react.useEffect)(() => {
|
|
50
|
+
setCss((0, import_server.getRegisteredCss)());
|
|
51
|
+
}, []);
|
|
52
|
+
if (children) {
|
|
53
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsxs)(import_jsx_runtime.Fragment, { children: [
|
|
54
|
+
children,
|
|
55
|
+
/* @__PURE__ */ (0, import_jsx_runtime.jsx)("style", { id: "typestyles-client", dangerouslySetInnerHTML: { __html: css } })
|
|
56
|
+
] });
|
|
57
|
+
}
|
|
58
|
+
return null;
|
|
59
|
+
}
|
|
60
|
+
function createTypestylesLayout(layout) {
|
|
61
|
+
return function TypestylesLayout(props) {
|
|
62
|
+
return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(TypestylesStylesheet, { children: layout(props) });
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
66
|
+
0 && (module.exports = {
|
|
67
|
+
TypestylesStylesheet,
|
|
68
|
+
createTypestylesLayout,
|
|
69
|
+
useServerInsertedHTML,
|
|
70
|
+
useTypestyles
|
|
71
|
+
});
|
package/dist/client.js
ADDED
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
// src/client.tsx
|
|
4
|
+
import { useState, useEffect, useServerInsertedHTML, useSyncExternalStore } from "react";
|
|
5
|
+
import { getRegisteredCss, subscribeRegisteredCss } from "typestyles/server";
|
|
6
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
7
|
+
function useTypestyles() {
|
|
8
|
+
return useSyncExternalStore(
|
|
9
|
+
subscribeRegisteredCss,
|
|
10
|
+
() => getRegisteredCss(),
|
|
11
|
+
() => getRegisteredCss()
|
|
12
|
+
);
|
|
13
|
+
}
|
|
14
|
+
function TypestylesStylesheet({ children }) {
|
|
15
|
+
const [css, setCss] = useState("");
|
|
16
|
+
useServerInsertedHTML(() => {
|
|
17
|
+
const registeredCss = getRegisteredCss();
|
|
18
|
+
if (registeredCss) {
|
|
19
|
+
return /* @__PURE__ */ jsx("style", { id: "typestyles", dangerouslySetInnerHTML: { __html: registeredCss } });
|
|
20
|
+
}
|
|
21
|
+
return null;
|
|
22
|
+
});
|
|
23
|
+
useEffect(() => {
|
|
24
|
+
setCss(getRegisteredCss());
|
|
25
|
+
}, []);
|
|
26
|
+
if (children) {
|
|
27
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
28
|
+
children,
|
|
29
|
+
/* @__PURE__ */ jsx("style", { id: "typestyles-client", dangerouslySetInnerHTML: { __html: css } })
|
|
30
|
+
] });
|
|
31
|
+
}
|
|
32
|
+
return null;
|
|
33
|
+
}
|
|
34
|
+
function createTypestylesLayout(layout) {
|
|
35
|
+
return function TypestylesLayout(props) {
|
|
36
|
+
return /* @__PURE__ */ jsx(TypestylesStylesheet, { children: layout(props) });
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
export {
|
|
40
|
+
TypestylesStylesheet,
|
|
41
|
+
createTypestylesLayout,
|
|
42
|
+
useServerInsertedHTML,
|
|
43
|
+
useTypestyles
|
|
44
|
+
};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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/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
|
|
40
|
+
});
|
|
41
|
+
module.exports = __toCommonJS(index_exports);
|
|
42
|
+
|
|
43
|
+
// src/server.ts
|
|
44
|
+
var import_server = require("typestyles/server");
|
|
45
|
+
var import_build_runner = require("@typestyles/build-runner");
|
|
46
|
+
async function collectStylesFromComponent(component) {
|
|
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
|
|
100
|
+
});
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { collectStyles, getRegisteredCss } from "typestyles/server";
|
|
3
|
+
import { getRouteCss } from "@typestyles/build-runner";
|
|
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
|
+
};
|
package/dist/server.cjs
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
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");
|
|
41
|
+
async function collectStylesFromComponent(component) {
|
|
42
|
+
const { renderToString } = await import("react-dom/server");
|
|
43
|
+
const { css } = (0, import_server.collectStyles)(() => renderToString(component));
|
|
44
|
+
return css;
|
|
45
|
+
}
|
|
46
|
+
async function getTypestylesMetadata(component) {
|
|
47
|
+
return collectStylesFromComponent(component);
|
|
48
|
+
}
|
|
49
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
50
|
+
0 && (module.exports = {
|
|
51
|
+
collectStylesFromComponent,
|
|
52
|
+
getRegisteredCss,
|
|
53
|
+
getRouteCss,
|
|
54
|
+
getTypestylesMetadata
|
|
55
|
+
});
|
package/dist/server.js
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/server.ts
|
|
2
|
+
import { collectStyles, getRegisteredCss } from "typestyles/server";
|
|
3
|
+
import { getRouteCss } from "@typestyles/build-runner";
|
|
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
|
+
export {
|
|
13
|
+
collectStylesFromComponent,
|
|
14
|
+
getRegisteredCss,
|
|
15
|
+
getRouteCss,
|
|
16
|
+
getTypestylesMetadata
|
|
17
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@typestyles/next",
|
|
3
|
+
"version": "0.0.0-unstable.00cf16386ea7",
|
|
4
|
+
"description": "Next.js integration for typestyles SSR",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.js",
|
|
8
|
+
"types": "./src/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./src/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./server": {
|
|
16
|
+
"types": "./src/server.d.ts",
|
|
17
|
+
"import": "./dist/server.js",
|
|
18
|
+
"require": "./dist/server.cjs"
|
|
19
|
+
},
|
|
20
|
+
"./client": {
|
|
21
|
+
"types": "./src/client.d.ts",
|
|
22
|
+
"import": "./dist/client.js",
|
|
23
|
+
"require": "./dist/client.cjs",
|
|
24
|
+
"default": "./dist/client.js"
|
|
25
|
+
},
|
|
26
|
+
"./build": {
|
|
27
|
+
"types": "./src/build.d.ts",
|
|
28
|
+
"import": "./dist/build.js",
|
|
29
|
+
"require": "./dist/build.cjs"
|
|
30
|
+
}
|
|
31
|
+
},
|
|
32
|
+
"files": [
|
|
33
|
+
"dist",
|
|
34
|
+
"src"
|
|
35
|
+
],
|
|
36
|
+
"keywords": [
|
|
37
|
+
"next",
|
|
38
|
+
"nextjs",
|
|
39
|
+
"typestyles",
|
|
40
|
+
"ssr",
|
|
41
|
+
"react"
|
|
42
|
+
],
|
|
43
|
+
"license": "Apache-2.0",
|
|
44
|
+
"repository": {
|
|
45
|
+
"type": "git",
|
|
46
|
+
"url": "https://github.com/type-styles/typestyles",
|
|
47
|
+
"directory": "packages/next"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"next": ">=13.0.0",
|
|
51
|
+
"react": ">=18.0.0",
|
|
52
|
+
"react-dom": ">=18.0.0",
|
|
53
|
+
"typestyles": ">=0.1.0",
|
|
54
|
+
"webpack": ">=5.0.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"next": {
|
|
58
|
+
"optional": false
|
|
59
|
+
},
|
|
60
|
+
"react": {
|
|
61
|
+
"optional": false
|
|
62
|
+
},
|
|
63
|
+
"react-dom": {
|
|
64
|
+
"optional": false
|
|
65
|
+
},
|
|
66
|
+
"webpack": {
|
|
67
|
+
"optional": true
|
|
68
|
+
}
|
|
69
|
+
},
|
|
70
|
+
"dependencies": {
|
|
71
|
+
"@typestyles/build-runner": "0.0.0-unstable.00cf16386ea7"
|
|
72
|
+
},
|
|
73
|
+
"devDependencies": {
|
|
74
|
+
"eslint": "^9.39.2",
|
|
75
|
+
"vitest": "^3.0.0",
|
|
76
|
+
"@types/node": "^25.2.1",
|
|
77
|
+
"@types/react": "^18.3.12",
|
|
78
|
+
"@types/react-dom": "^18.3.1",
|
|
79
|
+
"next": "^14.0.0",
|
|
80
|
+
"react": "^18.0.0",
|
|
81
|
+
"react-dom": "^18.0.0",
|
|
82
|
+
"tsup": "^8.0.0",
|
|
83
|
+
"typestyles": "0.0.0-unstable.00cf16386ea7",
|
|
84
|
+
"typescript": "^5.4.0",
|
|
85
|
+
"webpack": "^5.97.1"
|
|
86
|
+
},
|
|
87
|
+
"scripts": {
|
|
88
|
+
"build": "tsup",
|
|
89
|
+
"test": "vitest run",
|
|
90
|
+
"lint": "eslint .",
|
|
91
|
+
"typecheck": "tsc --noEmit"
|
|
92
|
+
}
|
|
93
|
+
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { existsSync, mkdirSync, mkdtempSync, readFileSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { buildTypestylesForNext } from './build';
|
|
6
|
+
|
|
7
|
+
describe('buildTypestylesForNext route CSS', () => {
|
|
8
|
+
it('emits manifest v2 with per-route CSS files', async () => {
|
|
9
|
+
const root = mkdtempSync(join(tmpdir(), 'typestyles-next-build-routes-'));
|
|
10
|
+
mkdirSync(join(root, 'styles'), { recursive: true });
|
|
11
|
+
mkdirSync(join(root, 'app/about'), { recursive: true });
|
|
12
|
+
|
|
13
|
+
writeFileSync(
|
|
14
|
+
join(root, 'styles/typestyles-entry.ts'),
|
|
15
|
+
`import { styles } from 'typestyles';\nstyles.class('shared', { margin: '0' });\n`,
|
|
16
|
+
);
|
|
17
|
+
writeFileSync(
|
|
18
|
+
join(root, 'app/layout.tsx'),
|
|
19
|
+
`export default function Layout() { return null; }\n`,
|
|
20
|
+
);
|
|
21
|
+
writeFileSync(
|
|
22
|
+
join(root, 'app/page.tsx'),
|
|
23
|
+
`import { styles } from 'typestyles';\nstyles.class('home', { color: 'red' });\nexport default function Home() { return null; }\n`,
|
|
24
|
+
);
|
|
25
|
+
writeFileSync(
|
|
26
|
+
join(root, 'app/about/page.tsx'),
|
|
27
|
+
`import { styles } from 'typestyles';\nstyles.class('about', { color: 'blue' });\nexport default function About() { return null; }\n`,
|
|
28
|
+
);
|
|
29
|
+
|
|
30
|
+
try {
|
|
31
|
+
await buildTypestylesForNext({ root });
|
|
32
|
+
|
|
33
|
+
const manifest = JSON.parse(readFileSync(join(root, 'app/typestyles.manifest.json'), 'utf8'));
|
|
34
|
+
expect(manifest.version).toBe(2);
|
|
35
|
+
expect(manifest.routes['/']).toBeDefined();
|
|
36
|
+
expect(manifest.routes['/about']).toBeDefined();
|
|
37
|
+
expect(existsSync(join(root, manifest.routes['/'].css))).toBe(true);
|
|
38
|
+
expect(existsSync(join(root, manifest.routes['/about'].css))).toBe(true);
|
|
39
|
+
|
|
40
|
+
const homeCss = readFileSync(join(root, manifest.routes['/'].css), 'utf8');
|
|
41
|
+
const aboutCss = readFileSync(join(root, manifest.routes['/about'].css), 'utf8');
|
|
42
|
+
expect(homeCss).toContain('.home {');
|
|
43
|
+
expect(aboutCss).toContain('.about {');
|
|
44
|
+
} finally {
|
|
45
|
+
rmSync(root, { recursive: true, force: true });
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs';
|
|
2
|
+
import { join } from 'node:path';
|
|
3
|
+
import { tmpdir } from 'node:os';
|
|
4
|
+
import { describe, expect, it } from 'vitest';
|
|
5
|
+
import { buildTypestylesForNext, verifyTypestylesBuild } from './build';
|
|
6
|
+
|
|
7
|
+
describe('buildTypestylesForNext theme extraction', () => {
|
|
8
|
+
it('extracts tokens.create and createTheme CSS into the global stylesheet', async () => {
|
|
9
|
+
const root = mkdtempSync(join(tmpdir(), 'typestyles-next-theme-'));
|
|
10
|
+
mkdirSync(join(root, 'styles'), { recursive: true });
|
|
11
|
+
|
|
12
|
+
writeFileSync(
|
|
13
|
+
join(root, 'styles/typestyles-entry.ts'),
|
|
14
|
+
`import { tokens, createTheme } from 'typestyles';
|
|
15
|
+
const color = tokens.create('next-color', { primary: '#0066ff' });
|
|
16
|
+
createTheme('next-dark', { base: { 'next-color': { primary: '#66aaff' } } });
|
|
17
|
+
`,
|
|
18
|
+
);
|
|
19
|
+
|
|
20
|
+
try {
|
|
21
|
+
await buildTypestylesForNext({ root });
|
|
22
|
+
|
|
23
|
+
// Theme/token CSS is a byproduct of normal extraction — verify with the P1.7 build verifier.
|
|
24
|
+
const result = verifyTypestylesBuild({
|
|
25
|
+
root,
|
|
26
|
+
cssFile: 'app/typestyles.css',
|
|
27
|
+
manifestFile: 'app/typestyles.manifest.json',
|
|
28
|
+
requiredCssSubstrings: [
|
|
29
|
+
'--next-color-primary: #0066ff',
|
|
30
|
+
'.theme-next-dark',
|
|
31
|
+
'--next-color-primary: #66aaff',
|
|
32
|
+
],
|
|
33
|
+
});
|
|
34
|
+
expect(result.cssBytes).toBeGreaterThan(0);
|
|
35
|
+
expect(result.manifestVersion).toBe(1);
|
|
36
|
+
} finally {
|
|
37
|
+
rmSync(root, { recursive: true, force: true });
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
});
|