next-style 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 kingslimes
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,230 @@
1
+ # NextStyle
2
+
3
+ A lightweight runtime CSS-in-JS engine designed for React and Next.js.
4
+ It supports nested pseudo selectors, responsive media queries, and automatic vendor prefixing via PostCSS — all at runtime with zero build-time CSS extraction.
5
+
6
+ NextStyle focuses on **runtime flexibility**, **type safety**, and **minimal abstraction**, making it suitable for design systems, theming, and dynamic UI styling.
7
+
8
+ ---
9
+
10
+ ## Features
11
+
12
+ - Runtime CSS generation
13
+ - Strongly typed style objects (powered by `csstype`)
14
+ - Nested pseudo selectors (`_hover`, `_focus`, `_active`)
15
+ - Responsive media queries (`_sm`, `_md`, `_lg`, `_xl`, `_xxl`)
16
+ - Automatic vendor prefixing (PostCSS + Autoprefixer)
17
+ - Deterministic hashed class names
18
+ - React `<style>` provider component
19
+ - No bundler or build-step CSS required
20
+
21
+ ---
22
+
23
+ ## Installation
24
+
25
+ Install the package along with its peer dependencies:
26
+
27
+ ```bash
28
+ npm install zed-style postcss autoprefixer react
29
+ ```
30
+
31
+ or with Bun:
32
+
33
+ ```bash
34
+ bun add zed-style postcss autoprefixer react
35
+ ```
36
+
37
+ ---
38
+
39
+ ## Basic Usage
40
+
41
+ ```tsx
42
+ import { NextStyle } from "zed-style"
43
+
44
+ const style = new NextStyle()
45
+
46
+ const className = style.css({
47
+ display: "flex",
48
+ alignItems: "center",
49
+ padding: "12px",
50
+ backgroundColor: "#111",
51
+ color: "white",
52
+
53
+ _hover: {
54
+ backgroundColor: "#222"
55
+ },
56
+
57
+ _md: {
58
+ padding: "16px"
59
+ }
60
+ })
61
+ ```
62
+
63
+ Apply the generated class name to your component:
64
+
65
+ ```tsx
66
+ export default function App() {
67
+ return (
68
+ <>
69
+ <div className={className}>
70
+ Hello NextStyle
71
+ </div>
72
+
73
+ <style.Provider />
74
+ </>
75
+ )
76
+ }
77
+ ```
78
+
79
+ ---
80
+
81
+ ## Style Object API
82
+
83
+ ### Base Properties
84
+
85
+ All standard CSS properties are supported and fully typed:
86
+
87
+ ```ts
88
+ {
89
+ margin: "8px",
90
+ fontSize: "14px",
91
+ backgroundColor: "#000"
92
+ }
93
+ ```
94
+
95
+ Types are derived from `csstype`, ensuring correctness and editor autocomplete.
96
+
97
+ ---
98
+
99
+ ### Pseudo Selectors
100
+
101
+ Use underscored keys for pseudo selectors:
102
+
103
+ ```ts
104
+ {
105
+ _hover: {
106
+ opacity: 0.8
107
+ },
108
+ _focus: {
109
+ outline: "2px solid blue"
110
+ },
111
+ _active: {
112
+ transform: "scale(0.98)"
113
+ }
114
+ }
115
+ ```
116
+
117
+ Supported pseudos:
118
+ - `_hover`
119
+ - `_focus`
120
+ - `_active`
121
+
122
+ ---
123
+
124
+ ### Responsive Media Queries
125
+
126
+ NextStyle provides built-in responsive keys:
127
+
128
+ | Key | Media Query |
129
+ |------|-------------|
130
+ | `_sm` | `(min-width: 640px)` |
131
+ | `_md` | `(min-width: 768px)` |
132
+ | `_lg` | `(min-width: 1024px)` |
133
+ | `_xl` | `(min-width: 1280px)` |
134
+ | `_xxl` | `(min-width: 1536px)` |
135
+
136
+ Example:
137
+
138
+ ```ts
139
+ {
140
+ fontSize: "14px",
141
+ _lg: {
142
+ fontSize: "18px"
143
+ }
144
+ }
145
+ ```
146
+
147
+ ---
148
+
149
+ ## `<style.Provider />`
150
+
151
+ The `Provider` component injects all generated CSS rules into a `<style>` tag.
152
+
153
+ Important notes:
154
+
155
+ - It must be rendered **once per style instance**
156
+ - It should be rendered **after** calling `css(...)`
157
+ - It performs no side effects if no styles were generated
158
+
159
+ ```tsx
160
+ <style.Provider />
161
+ ```
162
+
163
+ ---
164
+
165
+ ## Hashing Strategy
166
+
167
+ Class names are generated using a deterministic hash based on the style object:
168
+
169
+ ```text
170
+ zed_x9k3a2m1
171
+ ```
172
+
173
+ This ensures:
174
+ - Stable class names
175
+ - No duplicates
176
+ - Automatic caching of generated rules
177
+
178
+ ---
179
+
180
+ ## Runtime Behavior
181
+
182
+ - CSS is generated lazily on first usage
183
+ - Rules are cached in memory
184
+ - PostCSS transformation runs only once per unique rule
185
+ - No DOM mutation outside React rendering
186
+
187
+ ---
188
+
189
+ ## Type Safety
190
+
191
+ NextStyle provides full TypeScript support:
192
+
193
+ - All CSS properties are typed
194
+ - Invalid properties are caught at compile time
195
+ - Media and pseudo keys are strictly controlled
196
+
197
+ Types are generated via `.d.ts` and require no runtime dependency on `csstype`.
198
+
199
+ ---
200
+
201
+ ## Requirements
202
+
203
+ ### Peer Dependencies
204
+
205
+ - React >= 18
206
+ - PostCSS >= 8
207
+ - Autoprefixer >= 10
208
+
209
+ ### Runtime Environment
210
+
211
+ - Node.js >= 18
212
+ - Bun >= 1.0.0
213
+
214
+ ---
215
+
216
+ ## License
217
+
218
+ MIT © kingslimes
219
+
220
+ ---
221
+
222
+ ## Philosophy
223
+
224
+ NextStyle is intentionally minimal.
225
+
226
+ - No build-time CSS extraction
227
+ - No global runtime side effects
228
+ - No magic conventions
229
+
230
+ Just predictable runtime styling with strong types and explicit behavior.
@@ -0,0 +1,22 @@
1
+ import type { Properties } from "csstype";
2
+ export type NextStyleProperties = {
3
+ [K in keyof Properties<string | number>]?: Properties<string | number>[K];
4
+ } & {
5
+ _hover?: NextStyleObject;
6
+ _focus?: NextStyleObject;
7
+ _active?: NextStyleObject;
8
+ _sm?: NextStyleObject;
9
+ _md?: NextStyleObject;
10
+ _lg?: NextStyleObject;
11
+ _xl?: NextStyleObject;
12
+ _xxl?: NextStyleObject;
13
+ };
14
+ type NextStyleObject = Omit<NextStyleProperties, "_sm" | "_md" | "_lg" | "_xl" | "_xxl">;
15
+ export declare class NextStyle {
16
+ private prefix;
17
+ private rules;
18
+ constructor(prefix?: string);
19
+ css: (style: NextStyleProperties) => string;
20
+ Provider: () => import("react").JSX.Element | null;
21
+ }
22
+ export {};
package/dist/index.jsx ADDED
@@ -0,0 +1,92 @@
1
+ import postcss from "postcss";
2
+ import autoprefixer from "autoprefixer";
3
+ const processor = postcss([autoprefixer({
4
+ overrideBrowserslist: [">0.2%", "not dead", "not op_mini all"]
5
+ })]);
6
+ const postcssCache = new Map();
7
+ function postcssTransform(cssText) {
8
+ const cached = postcssCache.get(cssText);
9
+ if (cached) return cached;
10
+ const result = processor.process(cssText, {
11
+ from: undefined
12
+ }).css;
13
+ postcssCache.set(cssText, result);
14
+ return result;
15
+ }
16
+ function createHashName(seed) {
17
+ let hash = BigInt("0xcbf29ce484222325");
18
+ const prime = BigInt("0x100000001b3");
19
+ for (let i = 0; i < seed.length; i++) {
20
+ hash ^= BigInt(seed.charCodeAt(i));
21
+ hash *= prime;
22
+ hash &= BigInt("0xffffffffffffffff");
23
+ }
24
+ return hash.toString(36).slice(0, 9);
25
+ }
26
+ function toKebabCase(prop) {
27
+ return prop.replace(/[A-Z]/g, m => `-${m.toLowerCase()}`);
28
+ }
29
+ const MEDIA_MAP = {
30
+ _sm: "( min-width: 640px )",
31
+ _md: "( min-width: 768px )",
32
+ _lg: "( min-width: 1024px )",
33
+ _xl: "( min-width: 1280px )",
34
+ _xxl: "( min-width: 1536px )"
35
+ };
36
+ function serializeNested(style, ctx) {
37
+ let css = "";
38
+ let base = "";
39
+ for (const key in style) {
40
+ const value = style[key];
41
+ if (value == null || typeof value === "object" || key.startsWith("_")) continue;
42
+ base += `${toKebabCase(key)}:${value};`;
43
+ }
44
+ if (base) {
45
+ const rule = `${ctx.selector}{${base}}`;
46
+ css += ctx.media ? `${ctx.media}{${rule}}` : rule;
47
+ }
48
+ for (const pseudo of ["_hover", "_focus", "_active"]) {
49
+ const value = style[pseudo];
50
+ if (!value) continue;
51
+ css += serializeNested(value, {
52
+ ...ctx,
53
+ selector: `${ctx.selector}:${pseudo.slice(1)}`
54
+ });
55
+ }
56
+ for (const key in MEDIA_MAP) {
57
+ const mediaKey = key;
58
+ const value = style[mediaKey];
59
+ if (!value) continue;
60
+ css += serializeNested(value, {
61
+ ...ctx,
62
+ media: `@media ${MEDIA_MAP[mediaKey]}`
63
+ });
64
+ }
65
+ return css;
66
+ }
67
+ export class NextStyle {
68
+ rules = new Map();
69
+ constructor(prefix = "zed") {
70
+ this.prefix = prefix;
71
+ }
72
+ css = style => {
73
+ const hash = createHashName(JSON.stringify(style));
74
+ const className = `${this.prefix}_${hash}`;
75
+ if (!this.rules.has(className)) {
76
+ const raw = serializeNested(style, {
77
+ selector: `.${className}`
78
+ });
79
+ const cssText = postcssTransform(raw);
80
+ this.rules.set(className, cssText);
81
+ }
82
+ return className;
83
+ };
84
+ Provider = () => {
85
+ if (this.rules.size === 0) return null;
86
+ let cssText = "";
87
+ for (const rule of this.rules.values()) {
88
+ cssText += rule + "\n";
89
+ }
90
+ return <style>{cssText}</style>;
91
+ };
92
+ }
package/package.json ADDED
@@ -0,0 +1,66 @@
1
+ {
2
+ "name": "next-style",
3
+ "version": "1.1.0",
4
+ "description": "Lightweight runtime CSS-in-JS engine with nested pseudo selectors, media queries, global styles, keyframes, and font-face support.",
5
+ "author": {
6
+ "name": "kingslimes",
7
+ "email": "natontmp123@gmail.com",
8
+ "url": "https://github.com/kingslimes"
9
+ },
10
+ "license": "MIT",
11
+ "private": false,
12
+ "sideEffects": false,
13
+ "type": "module",
14
+ "files": [
15
+ "dist",
16
+ "LICENSE",
17
+ "README.md"
18
+ ],
19
+ "main": "./dist/index.jsx",
20
+ "types": "./dist/index.d.ts",
21
+ "exports": {
22
+ ".": {
23
+ "import": "./dist/index.jsx",
24
+ "types": "./dist/index.d.ts"
25
+ }
26
+ },
27
+ "repository": {
28
+ "type": "git",
29
+ "url": "https://github.com/kingslimes/zed-style.git"
30
+ },
31
+ "bugs": {
32
+ "url": "https://github.com/kingslimes/zed-style/issues"
33
+ },
34
+ "homepage": "https://github.com/kingslimes/zed-style#readme",
35
+ "keywords": [
36
+ "css",
37
+ "css-in-js",
38
+ "runtime-css",
39
+ "styled",
40
+ "style-engine",
41
+ "atomic-css",
42
+ "postcss",
43
+ "autoprefixer",
44
+ "nextjs",
45
+ "react",
46
+ "bun",
47
+ "typescript",
48
+ "design-system",
49
+ "theming",
50
+ "media-queries",
51
+ "keyframes",
52
+ "font-face"
53
+ ],
54
+ "peerDependencies": {
55
+ "react": ">=18",
56
+ "postcss": "^8",
57
+ "autoprefixer": "^10"
58
+ },
59
+ "devDependencies": {
60
+ "csstype": "^3"
61
+ },
62
+ "engines": {
63
+ "bun": ">=1.0.0",
64
+ "node": ">=18"
65
+ }
66
+ }