@typestyles/rollup 0.0.0-unstable.5b7138167233

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 ADDED
@@ -0,0 +1,85 @@
1
+ # @typestyles/rollup
2
+
3
+ Rollup and Rolldown plugin for `typestyles`.
4
+
5
+ Supports:
6
+
7
+ - Runtime mode (default): normal typestyles runtime behavior.
8
+ - Build mode: emit static CSS and disable runtime style insertion in bundle.
9
+ - Hybrid mode: emit static CSS for production while keeping runtime-friendly behavior in development.
10
+
11
+ ## Installation
12
+
13
+ ```bash
14
+ pnpm add typestyles
15
+ pnpm add -D @typestyles/rollup rollup
16
+ ```
17
+
18
+ ## Rollup usage
19
+
20
+ ```js
21
+ // rollup.config.mjs
22
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
23
+ import typestylesRollupPlugin from '@typestyles/rollup';
24
+
25
+ export default {
26
+ input: 'src/main.js',
27
+ output: {
28
+ dir: 'dist',
29
+ format: 'es',
30
+ },
31
+ plugins: [
32
+ nodeResolve(),
33
+ typestylesRollupPlugin({
34
+ mode: 'build',
35
+ extract: {
36
+ modules: ['src/styles.ts', 'src/tokens.ts', 'src/animations.ts'],
37
+ fileName: 'typestyles.css',
38
+ },
39
+ }),
40
+ ],
41
+ };
42
+ ```
43
+
44
+ Then link the emitted CSS in your HTML:
45
+
46
+ ```html
47
+ <link rel="stylesheet" href="/typestyles.css" />
48
+ ```
49
+
50
+ ## Rolldown usage
51
+
52
+ Rolldown supports Rollup-compatible plugins, so you can use the same plugin:
53
+
54
+ ```js
55
+ // rolldown.config.mjs
56
+ import typestylesRollupPlugin from '@typestyles/rollup';
57
+
58
+ export default {
59
+ input: 'src/main.ts',
60
+ output: {
61
+ dir: 'dist',
62
+ format: 'esm',
63
+ },
64
+ plugins: [
65
+ typestylesRollupPlugin({
66
+ mode: 'build',
67
+ extract: {
68
+ modules: ['src/styles.ts', 'src/tokens.ts'],
69
+ },
70
+ }),
71
+ ],
72
+ };
73
+ ```
74
+
75
+ ## Options
76
+
77
+ - `mode?: 'runtime' | 'build' | 'hybrid'`
78
+ - Default: `'runtime'`
79
+ - `extract?: { modules: string[]; fileName?: string }`
80
+ - Required for `build` and `hybrid` if you want CSS extraction
81
+ - `warnDuplicates?: boolean`
82
+ - Default: `true`
83
+ - `root?: string`
84
+ - Project root for resolving `extract.modules`
85
+ - Default: `process.cwd()`
package/dist/index.cjs ADDED
@@ -0,0 +1,119 @@
1
+ "use strict";
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
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/index.ts
21
+ var index_exports = {};
22
+ __export(index_exports, {
23
+ default: () => typestylesRollupPlugin,
24
+ extractNamespaces: () => extractNamespaces
25
+ });
26
+ module.exports = __toCommonJS(index_exports);
27
+ var import_build_runner = require("@typestyles/build-runner");
28
+ var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
29
+ var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
30
+ var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
31
+ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
32
+ var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
33
+ var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
34
+ var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
35
+ var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
36
+ function extractNamespaces(code) {
37
+ const keys = [];
38
+ const prefixes = [];
39
+ for (const match of code.matchAll(STYLES_CREATE_RE)) {
40
+ prefixes.push(`.${match[1]}-`);
41
+ }
42
+ for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
43
+ prefixes.push(`.${match[1]}-`);
44
+ }
45
+ for (const match of code.matchAll(TOKENS_CREATE_RE)) {
46
+ keys.push(`tokens:${match[1]}`);
47
+ }
48
+ for (const match of code.matchAll(CREATE_THEME_RE)) {
49
+ keys.push(`theme:${match[1]}`);
50
+ }
51
+ for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
52
+ keys.push(`keyframes:${match[1]}`);
53
+ }
54
+ for (const match of code.matchAll(GLOBAL_STYLE_RE)) {
55
+ prefixes.push(match[1]);
56
+ }
57
+ for (const match of code.matchAll(GLOBAL_FONT_FACE_RE)) {
58
+ prefixes.push(`font-face:${match[1]}`);
59
+ }
60
+ return { keys, prefixes };
61
+ }
62
+ function typestylesRollupPlugin(options = {}) {
63
+ const { warnDuplicates = true, mode = "runtime", extract, root = process.cwd() } = options;
64
+ const moduleNamespaces = /* @__PURE__ */ new Map();
65
+ return {
66
+ name: "typestyles-rollup",
67
+ transform(code, id) {
68
+ if ((mode === "build" || mode === "hybrid") && code.includes("__TYPESTYLES_RUNTIME_DISABLED__")) {
69
+ return {
70
+ code: code.replace(/__TYPESTYLES_RUNTIME_DISABLED__/g, '"true"'),
71
+ map: null
72
+ };
73
+ }
74
+ if (!/\.[jt]sx?$/.test(id)) return null;
75
+ if (id.includes("node_modules")) return null;
76
+ if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
77
+ const { keys, prefixes } = extractNamespaces(code);
78
+ if (keys.length === 0 && prefixes.length === 0) return null;
79
+ if (warnDuplicates) {
80
+ for (const [otherId, other] of moduleNamespaces) {
81
+ if (otherId === id) continue;
82
+ for (const prefix of prefixes) {
83
+ if (other.prefixes.includes(prefix)) {
84
+ const ns = prefix.slice(1, -1);
85
+ this.warn(
86
+ `Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions.`
87
+ );
88
+ }
89
+ }
90
+ }
91
+ }
92
+ moduleNamespaces.set(id, { keys, prefixes });
93
+ return null;
94
+ },
95
+ async generateBundle() {
96
+ if (mode === "runtime") return;
97
+ if (!extract || !extract.modules.length) return;
98
+ try {
99
+ const css = await (0, import_build_runner.runTypestylesBuild)({
100
+ root,
101
+ modules: extract.modules
102
+ });
103
+ this.emitFile({
104
+ type: "asset",
105
+ fileName: extract.fileName ?? "typestyles.css",
106
+ source: css
107
+ });
108
+ } catch (error) {
109
+ this.error(
110
+ `[typestyles] Failed to extract CSS: ${error instanceof Error ? error.message : String(error)}`
111
+ );
112
+ }
113
+ }
114
+ };
115
+ }
116
+ // Annotate the CommonJS export names for ESM import in node:
117
+ 0 && (module.exports = {
118
+ extractNamespaces
119
+ });
@@ -0,0 +1,46 @@
1
+ import { Plugin } from 'rollup';
2
+
3
+ interface TypestylesExtractOptions {
4
+ /**
5
+ * Modules that should be imported during build to register styles.
6
+ * Paths are resolved relative to `root`.
7
+ */
8
+ modules: string[];
9
+ /**
10
+ * Output CSS filename (emitted build asset). Defaults to "typestyles.css".
11
+ */
12
+ fileName?: string;
13
+ }
14
+ interface TypestylesRollupPluginOptions {
15
+ /** Warn about duplicate namespaces across modules. Defaults to true. */
16
+ warnDuplicates?: boolean;
17
+ /**
18
+ * Integration mode:
19
+ * - "runtime" (default): no static extraction.
20
+ * - "build": emit static CSS and disable runtime insertion.
21
+ * - "hybrid": emit static CSS and keep runtime-compatible dev behavior.
22
+ */
23
+ mode?: 'runtime' | 'build' | 'hybrid';
24
+ /**
25
+ * Build-time extraction options for "build" and "hybrid" modes.
26
+ */
27
+ extract?: TypestylesExtractOptions;
28
+ /**
29
+ * Project root used to resolve `extract.modules`.
30
+ * Defaults to process.cwd().
31
+ */
32
+ root?: string;
33
+ }
34
+ declare function extractNamespaces(code: string): {
35
+ keys: string[];
36
+ prefixes: string[];
37
+ };
38
+ /**
39
+ * Rollup plugin for typestyles runtime + optional static extraction.
40
+ *
41
+ * Rolldown supports Rollup-compatible plugins, so this plugin also works
42
+ * as a starting integration there.
43
+ */
44
+ declare function typestylesRollupPlugin(options?: TypestylesRollupPluginOptions): Plugin;
45
+
46
+ export { type TypestylesExtractOptions, type TypestylesRollupPluginOptions, typestylesRollupPlugin as default, extractNamespaces };
@@ -0,0 +1,46 @@
1
+ import { Plugin } from 'rollup';
2
+
3
+ interface TypestylesExtractOptions {
4
+ /**
5
+ * Modules that should be imported during build to register styles.
6
+ * Paths are resolved relative to `root`.
7
+ */
8
+ modules: string[];
9
+ /**
10
+ * Output CSS filename (emitted build asset). Defaults to "typestyles.css".
11
+ */
12
+ fileName?: string;
13
+ }
14
+ interface TypestylesRollupPluginOptions {
15
+ /** Warn about duplicate namespaces across modules. Defaults to true. */
16
+ warnDuplicates?: boolean;
17
+ /**
18
+ * Integration mode:
19
+ * - "runtime" (default): no static extraction.
20
+ * - "build": emit static CSS and disable runtime insertion.
21
+ * - "hybrid": emit static CSS and keep runtime-compatible dev behavior.
22
+ */
23
+ mode?: 'runtime' | 'build' | 'hybrid';
24
+ /**
25
+ * Build-time extraction options for "build" and "hybrid" modes.
26
+ */
27
+ extract?: TypestylesExtractOptions;
28
+ /**
29
+ * Project root used to resolve `extract.modules`.
30
+ * Defaults to process.cwd().
31
+ */
32
+ root?: string;
33
+ }
34
+ declare function extractNamespaces(code: string): {
35
+ keys: string[];
36
+ prefixes: string[];
37
+ };
38
+ /**
39
+ * Rollup plugin for typestyles runtime + optional static extraction.
40
+ *
41
+ * Rolldown supports Rollup-compatible plugins, so this plugin also works
42
+ * as a starting integration there.
43
+ */
44
+ declare function typestylesRollupPlugin(options?: TypestylesRollupPluginOptions): Plugin;
45
+
46
+ export { type TypestylesExtractOptions, type TypestylesRollupPluginOptions, typestylesRollupPlugin as default, extractNamespaces };
package/dist/index.js ADDED
@@ -0,0 +1,94 @@
1
+ // src/index.ts
2
+ import { runTypestylesBuild } from "@typestyles/build-runner";
3
+ var STYLES_CREATE_RE = /styles\.create\(\s*['"]([^'"]+)['"]/g;
4
+ var STYLES_COMPONENT_RE = /styles\.component\(\s*['"]([^'"]+)['"]/g;
5
+ var TOKENS_CREATE_RE = /tokens\.create\(\s*['"]([^'"]+)['"]/g;
6
+ var CREATE_THEME_RE = /(?:tokens\.)?createTheme\(\s*['"]([^'"]+)['"]/g;
7
+ var KEYFRAMES_CREATE_RE = /keyframes\.create\(\s*['"]([^'"]+)['"]/g;
8
+ var GLOBAL_STYLE_RE = /global\.style\(\s*['"]([^'"]+)['"]/g;
9
+ var GLOBAL_FONT_FACE_RE = /global\.fontFace\(\s*['"]([^'"]+)['"]/g;
10
+ var TYPESTYLES_IMPORT_RE = /(?:from\s+|import\s+|require\s*\(\s*)['"]typestyles['"]/;
11
+ function extractNamespaces(code) {
12
+ const keys = [];
13
+ const prefixes = [];
14
+ for (const match of code.matchAll(STYLES_CREATE_RE)) {
15
+ prefixes.push(`.${match[1]}-`);
16
+ }
17
+ for (const match of code.matchAll(STYLES_COMPONENT_RE)) {
18
+ prefixes.push(`.${match[1]}-`);
19
+ }
20
+ for (const match of code.matchAll(TOKENS_CREATE_RE)) {
21
+ keys.push(`tokens:${match[1]}`);
22
+ }
23
+ for (const match of code.matchAll(CREATE_THEME_RE)) {
24
+ keys.push(`theme:${match[1]}`);
25
+ }
26
+ for (const match of code.matchAll(KEYFRAMES_CREATE_RE)) {
27
+ keys.push(`keyframes:${match[1]}`);
28
+ }
29
+ for (const match of code.matchAll(GLOBAL_STYLE_RE)) {
30
+ prefixes.push(match[1]);
31
+ }
32
+ for (const match of code.matchAll(GLOBAL_FONT_FACE_RE)) {
33
+ prefixes.push(`font-face:${match[1]}`);
34
+ }
35
+ return { keys, prefixes };
36
+ }
37
+ function typestylesRollupPlugin(options = {}) {
38
+ const { warnDuplicates = true, mode = "runtime", extract, root = process.cwd() } = options;
39
+ const moduleNamespaces = /* @__PURE__ */ new Map();
40
+ return {
41
+ name: "typestyles-rollup",
42
+ transform(code, id) {
43
+ if ((mode === "build" || mode === "hybrid") && code.includes("__TYPESTYLES_RUNTIME_DISABLED__")) {
44
+ return {
45
+ code: code.replace(/__TYPESTYLES_RUNTIME_DISABLED__/g, '"true"'),
46
+ map: null
47
+ };
48
+ }
49
+ if (!/\.[jt]sx?$/.test(id)) return null;
50
+ if (id.includes("node_modules")) return null;
51
+ if (!TYPESTYLES_IMPORT_RE.test(code)) return null;
52
+ const { keys, prefixes } = extractNamespaces(code);
53
+ if (keys.length === 0 && prefixes.length === 0) return null;
54
+ if (warnDuplicates) {
55
+ for (const [otherId, other] of moduleNamespaces) {
56
+ if (otherId === id) continue;
57
+ for (const prefix of prefixes) {
58
+ if (other.prefixes.includes(prefix)) {
59
+ const ns = prefix.slice(1, -1);
60
+ this.warn(
61
+ `Style namespace "${ns}" is also used in ${otherId}. Duplicate namespaces cause class name collisions.`
62
+ );
63
+ }
64
+ }
65
+ }
66
+ }
67
+ moduleNamespaces.set(id, { keys, prefixes });
68
+ return null;
69
+ },
70
+ async generateBundle() {
71
+ if (mode === "runtime") return;
72
+ if (!extract || !extract.modules.length) return;
73
+ try {
74
+ const css = await runTypestylesBuild({
75
+ root,
76
+ modules: extract.modules
77
+ });
78
+ this.emitFile({
79
+ type: "asset",
80
+ fileName: extract.fileName ?? "typestyles.css",
81
+ source: css
82
+ });
83
+ } catch (error) {
84
+ this.error(
85
+ `[typestyles] Failed to extract CSS: ${error instanceof Error ? error.message : String(error)}`
86
+ );
87
+ }
88
+ }
89
+ };
90
+ }
91
+ export {
92
+ typestylesRollupPlugin as default,
93
+ extractNamespaces
94
+ };
package/package.json ADDED
@@ -0,0 +1,55 @@
1
+ {
2
+ "name": "@typestyles/rollup",
3
+ "version": "0.0.0-unstable.5b7138167233",
4
+ "description": "Rollup and Rolldown plugin for typestyles",
5
+ "type": "module",
6
+ "main": "./dist/index.cjs",
7
+ "module": "./dist/index.js",
8
+ "types": "./dist/index.d.ts",
9
+ "exports": {
10
+ ".": {
11
+ "import": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ },
15
+ "require": {
16
+ "types": "./dist/index.d.cts",
17
+ "default": "./dist/index.cjs"
18
+ }
19
+ }
20
+ },
21
+ "files": [
22
+ "dist"
23
+ ],
24
+ "keywords": [
25
+ "rollup",
26
+ "rolldown",
27
+ "typestyles",
28
+ "plugin",
29
+ "css-in-js"
30
+ ],
31
+ "license": "Apache-2.0",
32
+ "repository": {
33
+ "type": "git",
34
+ "url": "https://github.com/dbanksdesign/typestyles",
35
+ "directory": "packages/rollup"
36
+ },
37
+ "peerDependencies": {
38
+ "rollup": ">=4.0.0"
39
+ },
40
+ "dependencies": {
41
+ "@typestyles/build-runner": "0.0.0-unstable.5b7138167233"
42
+ },
43
+ "devDependencies": {
44
+ "@types/node": "^25.2.1",
45
+ "tsup": "^8.0.0",
46
+ "typescript": "^5.4.0",
47
+ "vitest": "^3.0.0",
48
+ "rollup": "^4.0.0"
49
+ },
50
+ "scripts": {
51
+ "build": "tsup src/index.ts --format esm,cjs --dts --clean --external typestyles,@typestyles/build-runner",
52
+ "test": "vitest run",
53
+ "typecheck": "tsc --noEmit"
54
+ }
55
+ }