next-style 1.2.1 → 2.0.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 +1 -1
- package/README.md +220 -452
- package/dist/compiler/index.d.ts +95 -0
- package/dist/compiler/index.d.ts.map +1 -0
- package/dist/compiler/index.js +229 -0
- package/dist/index.d.ts +5 -317
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +4 -3
- package/dist/postcss-plugin/index.d.ts +28 -0
- package/dist/postcss-plugin/index.d.ts.map +1 -0
- package/dist/postcss-plugin/index.js +48 -0
- package/dist/runtime/index.d.ts +104 -0
- package/dist/runtime/index.d.ts.map +1 -0
- package/dist/runtime/index.js +62 -0
- package/dist/utils/index.d.ts +60 -0
- package/dist/utils/index.d.ts.map +1 -0
- package/dist/utils/index.js +97 -0
- package/package.json +37 -49
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The compiled representation of a single `css({})` call.
|
|
3
|
+
* Produced by `StyleCollector` and consumed by the PostCSS plugin.
|
|
4
|
+
*/
|
|
5
|
+
export interface CompiledStyle {
|
|
6
|
+
/** Scoped class name, e.g. `"ns-1x2y3z"`. */
|
|
7
|
+
className: string;
|
|
8
|
+
/** Base CSS rule block for this class. */
|
|
9
|
+
css: string;
|
|
10
|
+
/** Map of normalized media query string → CSS rule block. */
|
|
11
|
+
mediaQueries: Record<string, string>;
|
|
12
|
+
/** Map of pseudo selector (e.g. `":hover"`) → CSS rule block. */
|
|
13
|
+
pseudoClasses: Record<string, string>;
|
|
14
|
+
/** Concatenated `@keyframes` blocks referenced by this style. */
|
|
15
|
+
keyframes: string;
|
|
16
|
+
/** Map of `@supports` condition → CSS rule block. */
|
|
17
|
+
supports: Record<string, string>;
|
|
18
|
+
/** Map of `@layer` name → CSS rule block. */
|
|
19
|
+
layers: Record<string, string>;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Collects, compiles, and deduplicates styles registered via `css()` and `global()`.
|
|
23
|
+
*
|
|
24
|
+
* A single shared instance is held by the runtime module. The PostCSS plugin
|
|
25
|
+
* calls `getAllStyles()` at build time to drain the collected CSS.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* const collector = new StyleCollector()
|
|
29
|
+
* const className = collector.addStyle({ color: 'red' }) // "ns-abc123"
|
|
30
|
+
* const css = collector.getAllStyles() // ".ns-abc123 { color: red; }"
|
|
31
|
+
*/
|
|
32
|
+
export declare class StyleCollector {
|
|
33
|
+
private styles;
|
|
34
|
+
/**
|
|
35
|
+
* Compiles a style object and registers it in the collector.
|
|
36
|
+
* Returns the same class name for identical style objects (deduplication).
|
|
37
|
+
*
|
|
38
|
+
* @param styleObj - Raw style object from a `css({})` call.
|
|
39
|
+
* @returns Scoped class name string.
|
|
40
|
+
*/
|
|
41
|
+
addStyle(styleObj: any): string;
|
|
42
|
+
/**
|
|
43
|
+
* Registers a global style rule (no scoped class).
|
|
44
|
+
* Subsequent calls with the same selector are ignored (idempotent).
|
|
45
|
+
*
|
|
46
|
+
* @param selector - CSS selector string, e.g. `"body"` or `"h1, h2"`.
|
|
47
|
+
* @param styleObj - Style properties to apply to the selector.
|
|
48
|
+
*/
|
|
49
|
+
addGlobalStyle(selector: string, styleObj: any): void;
|
|
50
|
+
private compileStyle;
|
|
51
|
+
private parseStyles;
|
|
52
|
+
private buildDeclarations;
|
|
53
|
+
/**
|
|
54
|
+
* Serialises all collected styles into a single CSS string.
|
|
55
|
+
*
|
|
56
|
+
* Output order:
|
|
57
|
+
* 1. `@keyframes` blocks
|
|
58
|
+
* 2. Base class rules
|
|
59
|
+
* 3. Pseudo-class/element rules
|
|
60
|
+
* 4. `@layer` blocks
|
|
61
|
+
* 5. `@supports` blocks
|
|
62
|
+
* 6. Media queries (ascending `min-width`, mobile-first)
|
|
63
|
+
*
|
|
64
|
+
* @returns Full CSS string ready to be injected or written to a file.
|
|
65
|
+
*/
|
|
66
|
+
getAllStyles(): string;
|
|
67
|
+
private extractMinWidth;
|
|
68
|
+
/**
|
|
69
|
+
* Returns a snapshot of the internal style map.
|
|
70
|
+
* Intended for inspection and testing — not for direct mutation.
|
|
71
|
+
*/
|
|
72
|
+
getStyleMap(): Map<string, CompiledStyle>;
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Creates an isolated `StyleCollector` paired with a transform helper.
|
|
76
|
+
*
|
|
77
|
+
* Primarily used by SWC/Babel transforms and test harnesses that need
|
|
78
|
+
* a fresh collector per file or per test, independent of the shared
|
|
79
|
+
* runtime instance.
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* const { collector, transformCssCall } = createTransformer()
|
|
83
|
+
* const className = transformCssCall({ color: 'red' })
|
|
84
|
+
* const css = collector.getAllStyles()
|
|
85
|
+
*/
|
|
86
|
+
export declare function createTransformer(): {
|
|
87
|
+
collector: StyleCollector;
|
|
88
|
+
/**
|
|
89
|
+
* Equivalent to calling `css()` against this transformer's isolated collector.
|
|
90
|
+
* @param styleObj - Raw style object.
|
|
91
|
+
* @returns Scoped class name string.
|
|
92
|
+
*/
|
|
93
|
+
transformCssCall(styleObj: any): string;
|
|
94
|
+
};
|
|
95
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/compiler/index.ts"],"names":[],"mappings":"AAEA;;;GAGG;AACH,MAAM,WAAW,aAAa;IAC7B,6CAA6C;IAC7C,SAAS,EAAE,MAAM,CAAA;IACjB,0CAA0C;IAC1C,GAAG,EAAE,MAAM,CAAA;IACX,6DAA6D;IAC7D,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACpC,iEAAiE;IACjE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IACrC,iEAAiE;IACjE,SAAS,EAAE,MAAM,CAAA;IACjB,qDAAqD;IACrD,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAChC,6CAA6C;IAC7C,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;CAC9B;AAED;;;;;;;;;;GAUG;AACH,qBAAa,cAAc;IAC1B,OAAO,CAAC,MAAM,CAAmC;IAEjD;;;;;;OAMG;IACH,QAAQ,CAAC,QAAQ,EAAE,GAAG,GAAG,MAAM;IAW/B;;;;;;OAMG;IACH,cAAc,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,GAAG,GAAG,IAAI;IAgBrD,OAAO,CAAC,YAAY;IA+DpB,OAAO,CAAC,WAAW;IAwCnB,OAAO,CAAC,iBAAiB;IAUzB;;;;;;;;;;;;OAYG;IACH,YAAY,IAAI,MAAM;IAwBtB,OAAO,CAAC,eAAe;IAKvB;;;OAGG;IACH,WAAW;CAGX;AAED;;;;;;;;;;;GAWG;AACH,wBAAgB,iBAAiB;;IAI/B;;;;OAIG;+BACwB,GAAG,GAAG,MAAM;EAIxC"}
|
|
@@ -0,0 +1,229 @@
|
|
|
1
|
+
import { BREAKPOINTS, camelToKebab, generateClassHash, normalizeMediaQuery } from '../utils';
|
|
2
|
+
/**
|
|
3
|
+
* Collects, compiles, and deduplicates styles registered via `css()` and `global()`.
|
|
4
|
+
*
|
|
5
|
+
* A single shared instance is held by the runtime module. The PostCSS plugin
|
|
6
|
+
* calls `getAllStyles()` at build time to drain the collected CSS.
|
|
7
|
+
*
|
|
8
|
+
* @example
|
|
9
|
+
* const collector = new StyleCollector()
|
|
10
|
+
* const className = collector.addStyle({ color: 'red' }) // "ns-abc123"
|
|
11
|
+
* const css = collector.getAllStyles() // ".ns-abc123 { color: red; }"
|
|
12
|
+
*/
|
|
13
|
+
export class StyleCollector {
|
|
14
|
+
constructor() {
|
|
15
|
+
this.styles = new Map();
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Compiles a style object and registers it in the collector.
|
|
19
|
+
* Returns the same class name for identical style objects (deduplication).
|
|
20
|
+
*
|
|
21
|
+
* @param styleObj - Raw style object from a `css({})` call.
|
|
22
|
+
* @returns Scoped class name string.
|
|
23
|
+
*/
|
|
24
|
+
addStyle(styleObj) {
|
|
25
|
+
const hash = generateClassHash(styleObj);
|
|
26
|
+
const className = `ns-${hash}`;
|
|
27
|
+
if (this.styles.has(className)) {
|
|
28
|
+
return className;
|
|
29
|
+
}
|
|
30
|
+
const compiled = this.compileStyle(styleObj);
|
|
31
|
+
this.styles.set(className, compiled);
|
|
32
|
+
return className;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Registers a global style rule (no scoped class).
|
|
36
|
+
* Subsequent calls with the same selector are ignored (idempotent).
|
|
37
|
+
*
|
|
38
|
+
* @param selector - CSS selector string, e.g. `"body"` or `"h1, h2"`.
|
|
39
|
+
* @param styleObj - Style properties to apply to the selector.
|
|
40
|
+
*/
|
|
41
|
+
addGlobalStyle(selector, styleObj) {
|
|
42
|
+
const key = `global:${selector}`;
|
|
43
|
+
if (this.styles.has(key))
|
|
44
|
+
return;
|
|
45
|
+
const props = this.buildDeclarations(styleObj);
|
|
46
|
+
if (!props)
|
|
47
|
+
return;
|
|
48
|
+
this.styles.set(key, {
|
|
49
|
+
className: key,
|
|
50
|
+
css: `${selector} {\n${props}}`,
|
|
51
|
+
mediaQueries: {},
|
|
52
|
+
pseudoClasses: {},
|
|
53
|
+
keyframes: '',
|
|
54
|
+
supports: {},
|
|
55
|
+
layers: {}
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
compileStyle(styleObj) {
|
|
59
|
+
const { mediaQueries, pseudoClasses, normalStyles, keyframes, supports, container, layer } = this.parseStyles(styleObj);
|
|
60
|
+
const hash = generateClassHash(styleObj);
|
|
61
|
+
const className = `ns-${hash}`;
|
|
62
|
+
const declarations = this.buildDeclarations(normalStyles);
|
|
63
|
+
const css = `.${className} {\n${declarations}}`;
|
|
64
|
+
const compiledMedia = {};
|
|
65
|
+
Object.entries(mediaQueries).forEach(([query, styles]) => {
|
|
66
|
+
const normalized = normalizeMediaQuery(query);
|
|
67
|
+
const inner = this.buildDeclarations(styles, ' ');
|
|
68
|
+
const existing = compiledMedia[normalized];
|
|
69
|
+
compiledMedia[normalized] = existing
|
|
70
|
+
? `${normalized} {\n .${className} {\n${existing.split('\n').slice(2, -1).join('\n')}\n${inner} }\n}`
|
|
71
|
+
: `${normalized} {\n .${className} {\n${inner} }\n}`;
|
|
72
|
+
});
|
|
73
|
+
Object.entries(container).forEach(([query, styles]) => {
|
|
74
|
+
const inner = this.buildDeclarations(styles, ' ');
|
|
75
|
+
compiledMedia[query] = `${query} {\n .${className} {\n${inner} }\n}`;
|
|
76
|
+
});
|
|
77
|
+
const compiledPseudos = {};
|
|
78
|
+
Object.entries(pseudoClasses).forEach(([pseudo, styles]) => {
|
|
79
|
+
const inner = this.buildDeclarations(styles);
|
|
80
|
+
compiledPseudos[pseudo] = `.${className}${pseudo} {\n${inner}}`;
|
|
81
|
+
});
|
|
82
|
+
let keyframesCss = '';
|
|
83
|
+
Object.entries(keyframes).forEach(([name, frames]) => {
|
|
84
|
+
keyframesCss += `@keyframes ${name} {\n`;
|
|
85
|
+
Object.entries(frames).forEach(([stop, props]) => {
|
|
86
|
+
const inner = this.buildDeclarations(props, ' ');
|
|
87
|
+
keyframesCss += ` ${stop} {\n${inner} }\n`;
|
|
88
|
+
});
|
|
89
|
+
keyframesCss += '}\n';
|
|
90
|
+
});
|
|
91
|
+
const compiledSupports = {};
|
|
92
|
+
Object.entries(supports).forEach(([condition, styles]) => {
|
|
93
|
+
const inner = this.buildDeclarations(styles, ' ');
|
|
94
|
+
compiledSupports[condition] = `@supports ${condition} {\n .${className} {\n${inner} }\n}`;
|
|
95
|
+
});
|
|
96
|
+
const compiledLayers = {};
|
|
97
|
+
Object.entries(layer).forEach(([name, styles]) => {
|
|
98
|
+
const inner = this.buildDeclarations(styles, ' ');
|
|
99
|
+
compiledLayers[name] = `@layer ${name} {\n${inner}}`;
|
|
100
|
+
});
|
|
101
|
+
return {
|
|
102
|
+
className,
|
|
103
|
+
css,
|
|
104
|
+
mediaQueries: compiledMedia,
|
|
105
|
+
pseudoClasses: compiledPseudos,
|
|
106
|
+
keyframes: keyframesCss,
|
|
107
|
+
supports: compiledSupports,
|
|
108
|
+
layers: compiledLayers
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
parseStyles(styleObj) {
|
|
112
|
+
const normalStyles = {};
|
|
113
|
+
const mediaQueries = {};
|
|
114
|
+
const pseudoClasses = {};
|
|
115
|
+
const keyframes = {};
|
|
116
|
+
const supports = {};
|
|
117
|
+
const container = {};
|
|
118
|
+
const layer = {};
|
|
119
|
+
Object.entries(styleObj).forEach(([key, value]) => {
|
|
120
|
+
if (key.startsWith('@keyframes ')) {
|
|
121
|
+
keyframes[key.slice('@keyframes '.length)] = value;
|
|
122
|
+
}
|
|
123
|
+
else if (key === '@keyframes' && typeof value === 'object') {
|
|
124
|
+
Object.assign(keyframes, value);
|
|
125
|
+
}
|
|
126
|
+
else if (key.startsWith('@supports')) {
|
|
127
|
+
supports[key.slice('@supports '.length)] = value;
|
|
128
|
+
}
|
|
129
|
+
else if (key.startsWith('@container')) {
|
|
130
|
+
container[key] = value;
|
|
131
|
+
}
|
|
132
|
+
else if (key.startsWith('@layer')) {
|
|
133
|
+
layer[key.slice('@layer '.length) || 'default'] = value;
|
|
134
|
+
}
|
|
135
|
+
else if (key in BREAKPOINTS || key.startsWith('@media')) {
|
|
136
|
+
mediaQueries[key] = value;
|
|
137
|
+
}
|
|
138
|
+
else if (key.startsWith(':') || key.startsWith('::')) {
|
|
139
|
+
pseudoClasses[key] = value;
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
normalStyles[key] = value;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
return { normalStyles, mediaQueries, pseudoClasses, keyframes, supports, container, layer };
|
|
146
|
+
}
|
|
147
|
+
buildDeclarations(styles, indent = ' ') {
|
|
148
|
+
let css = '';
|
|
149
|
+
Object.entries(styles).forEach(([key, value]) => {
|
|
150
|
+
if (typeof value === 'string' || typeof value === 'number') {
|
|
151
|
+
css += `${indent}${camelToKebab(key)}: ${value};\n`;
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
return css;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Serialises all collected styles into a single CSS string.
|
|
158
|
+
*
|
|
159
|
+
* Output order:
|
|
160
|
+
* 1. `@keyframes` blocks
|
|
161
|
+
* 2. Base class rules
|
|
162
|
+
* 3. Pseudo-class/element rules
|
|
163
|
+
* 4. `@layer` blocks
|
|
164
|
+
* 5. `@supports` blocks
|
|
165
|
+
* 6. Media queries (ascending `min-width`, mobile-first)
|
|
166
|
+
*
|
|
167
|
+
* @returns Full CSS string ready to be injected or written to a file.
|
|
168
|
+
*/
|
|
169
|
+
getAllStyles() {
|
|
170
|
+
let allCss = '';
|
|
171
|
+
this.styles.forEach(style => {
|
|
172
|
+
if (style.keyframes)
|
|
173
|
+
allCss += `${style.keyframes}\n`;
|
|
174
|
+
if (style.css)
|
|
175
|
+
allCss += `${style.css}\n`;
|
|
176
|
+
Object.values(style.pseudoClasses).forEach(css => {
|
|
177
|
+
allCss += `${css}\n`;
|
|
178
|
+
});
|
|
179
|
+
Object.values(style.layers).forEach(css => {
|
|
180
|
+
allCss += `${css}\n`;
|
|
181
|
+
});
|
|
182
|
+
Object.values(style.supports).forEach(css => {
|
|
183
|
+
allCss += `${css}\n`;
|
|
184
|
+
});
|
|
185
|
+
const mediaEntries = Object.entries(style.mediaQueries).sort(([a], [b]) => this.extractMinWidth(a) - this.extractMinWidth(b));
|
|
186
|
+
mediaEntries.forEach(([, css]) => {
|
|
187
|
+
allCss += `${css}\n`;
|
|
188
|
+
});
|
|
189
|
+
});
|
|
190
|
+
return allCss;
|
|
191
|
+
}
|
|
192
|
+
extractMinWidth(query) {
|
|
193
|
+
const match = query.match(/min-width:\s*(\d+)px/);
|
|
194
|
+
return match ? parseInt(match[1], 10) : 0;
|
|
195
|
+
}
|
|
196
|
+
/**
|
|
197
|
+
* Returns a snapshot of the internal style map.
|
|
198
|
+
* Intended for inspection and testing — not for direct mutation.
|
|
199
|
+
*/
|
|
200
|
+
getStyleMap() {
|
|
201
|
+
return new Map(this.styles);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
/**
|
|
205
|
+
* Creates an isolated `StyleCollector` paired with a transform helper.
|
|
206
|
+
*
|
|
207
|
+
* Primarily used by SWC/Babel transforms and test harnesses that need
|
|
208
|
+
* a fresh collector per file or per test, independent of the shared
|
|
209
|
+
* runtime instance.
|
|
210
|
+
*
|
|
211
|
+
* @example
|
|
212
|
+
* const { collector, transformCssCall } = createTransformer()
|
|
213
|
+
* const className = transformCssCall({ color: 'red' })
|
|
214
|
+
* const css = collector.getAllStyles()
|
|
215
|
+
*/
|
|
216
|
+
export function createTransformer() {
|
|
217
|
+
const collector = new StyleCollector();
|
|
218
|
+
return {
|
|
219
|
+
collector,
|
|
220
|
+
/**
|
|
221
|
+
* Equivalent to calling `css()` against this transformer's isolated collector.
|
|
222
|
+
* @param styleObj - Raw style object.
|
|
223
|
+
* @returns Scoped class name string.
|
|
224
|
+
*/
|
|
225
|
+
transformCssCall(styleObj) {
|
|
226
|
+
return collector.addStyle(styleObj);
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,317 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
* Supports:
|
|
7
|
-
* - Standard CSS properties (camelCase)
|
|
8
|
-
* - Pseudo states via `_hover`, `_focus`, `_active`
|
|
9
|
-
* - Responsive media queries via `_sm` ~ `_xxl`
|
|
10
|
-
*
|
|
11
|
-
* Example:
|
|
12
|
-
* ```ts
|
|
13
|
-
* const button = css({
|
|
14
|
-
* padding: "8px 16px",
|
|
15
|
-
* backgroundColor: "black",
|
|
16
|
-
* color: "white",
|
|
17
|
-
* _hover: { opacity: 0.8 },
|
|
18
|
-
* _md: { padding: "12px 20px" }
|
|
19
|
-
* })
|
|
20
|
-
* ```
|
|
21
|
-
*/
|
|
22
|
-
export type NextStyleProperties = {
|
|
23
|
-
[K in keyof Properties<string | number>]?: Properties<string | number>[K];
|
|
24
|
-
} & {
|
|
25
|
-
[customProperty: `--${string}`]: string | number;
|
|
26
|
-
} & {
|
|
27
|
-
_hover?: NextStyleObject;
|
|
28
|
-
_focus?: NextStyleObject;
|
|
29
|
-
_active?: NextStyleObject;
|
|
30
|
-
_sm?: NextStyleObject;
|
|
31
|
-
_md?: NextStyleObject;
|
|
32
|
-
_lg?: NextStyleObject;
|
|
33
|
-
_xl?: NextStyleObject;
|
|
34
|
-
_xxl?: NextStyleObject;
|
|
35
|
-
};
|
|
36
|
-
type NextStyleObject = Omit<NextStyleProperties, "_sm" | "_md" | "_lg" | "_xl" | "_xxl">;
|
|
37
|
-
type KeyframesObject = {
|
|
38
|
-
[step: string]: Properties<string | number>;
|
|
39
|
-
};
|
|
40
|
-
type FontFaceObject = {
|
|
41
|
-
fontFamily: string;
|
|
42
|
-
src: string;
|
|
43
|
-
fontWeight?: string | number;
|
|
44
|
-
fontStyle?: string;
|
|
45
|
-
fontDisplay?: string;
|
|
46
|
-
unicodeRange?: string;
|
|
47
|
-
};
|
|
48
|
-
type PseudoState = "hover" | "focus" | "active";
|
|
49
|
-
/**
|
|
50
|
-
* Builder for defining relations starting from a generated class name.
|
|
51
|
-
*
|
|
52
|
-
* This builder should only be created via `NextStyle.when(...)`.
|
|
53
|
-
*/
|
|
54
|
-
declare class RelationBuilder {
|
|
55
|
-
private ns;
|
|
56
|
-
private source;
|
|
57
|
-
private pseudo?;
|
|
58
|
-
/**
|
|
59
|
-
* @internal
|
|
60
|
-
* @param ns NextStyle instance
|
|
61
|
-
* @param source Source class name generated by `css()`
|
|
62
|
-
* @param pseudo Optional pseudo state applied to the source
|
|
63
|
-
*/
|
|
64
|
-
constructor(ns: NextStyle, source: string, pseudo?: PseudoState | undefined);
|
|
65
|
-
/**
|
|
66
|
-
* Apply `:hover` pseudo state to the source selector.
|
|
67
|
-
*
|
|
68
|
-
* All subsequent relations will be scoped under `:hover`.
|
|
69
|
-
*
|
|
70
|
-
* @returns RelationBuilder
|
|
71
|
-
*
|
|
72
|
-
* Example:
|
|
73
|
-
* ```ts
|
|
74
|
-
* when(card)
|
|
75
|
-
* .hover()
|
|
76
|
-
* .child(icon, { opacity: 1 })
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
hover(): RelationBuilder;
|
|
80
|
-
/**
|
|
81
|
-
* Apply `:focus` pseudo state to the source selector.
|
|
82
|
-
*
|
|
83
|
-
* @returns RelationBuilder
|
|
84
|
-
*/
|
|
85
|
-
focus(): RelationBuilder;
|
|
86
|
-
/**
|
|
87
|
-
* Apply `:active` pseudo state to the source selector.
|
|
88
|
-
*
|
|
89
|
-
* @returns RelationBuilder
|
|
90
|
-
*/
|
|
91
|
-
active(): RelationBuilder;
|
|
92
|
-
/**
|
|
93
|
-
* Define styles for an adjacent sibling selector.
|
|
94
|
-
*
|
|
95
|
-
* CSS equivalent:
|
|
96
|
-
* `.source + .target`
|
|
97
|
-
*
|
|
98
|
-
* @param target Target class name generated by `css()`
|
|
99
|
-
* @param style Style applied to the target element
|
|
100
|
-
*
|
|
101
|
-
* Example:
|
|
102
|
-
* ```ts
|
|
103
|
-
* when(input)
|
|
104
|
-
* .focus()
|
|
105
|
-
* .adjacent(label, { color: "red" })
|
|
106
|
-
* ```
|
|
107
|
-
*/
|
|
108
|
-
adjacent(target: string, style: NextStyleProperties): void;
|
|
109
|
-
/**
|
|
110
|
-
* Define styles for a direct child selector.
|
|
111
|
-
*
|
|
112
|
-
* CSS equivalent:
|
|
113
|
-
* `.source > .target`
|
|
114
|
-
*
|
|
115
|
-
* @param target Target class name generated by `css()`
|
|
116
|
-
* @param style Style applied to the target element
|
|
117
|
-
*/
|
|
118
|
-
child(target: string, style: NextStyleProperties): void;
|
|
119
|
-
/**
|
|
120
|
-
* Define styles for a general sibling selector.
|
|
121
|
-
*
|
|
122
|
-
* CSS equivalent:
|
|
123
|
-
* `.source ~ .target`
|
|
124
|
-
*
|
|
125
|
-
* @param target Target class name generated by `css()`
|
|
126
|
-
* @param style Style applied to the target element
|
|
127
|
-
*/
|
|
128
|
-
sibling(target: string, style: NextStyleProperties): void;
|
|
129
|
-
/**
|
|
130
|
-
* Define styles for a descendant selector.
|
|
131
|
-
*
|
|
132
|
-
* CSS equivalent:
|
|
133
|
-
* `.source .target`
|
|
134
|
-
*
|
|
135
|
-
* @param target Target class name generated by `css()`
|
|
136
|
-
* @param style Style applied to the target element
|
|
137
|
-
*/
|
|
138
|
-
descendant(target: string, style: NextStyleProperties): void;
|
|
139
|
-
/**
|
|
140
|
-
* @internal
|
|
141
|
-
* Emit a global relational rule.
|
|
142
|
-
*/
|
|
143
|
-
private emit;
|
|
144
|
-
}
|
|
145
|
-
/**
|
|
146
|
-
* NextStyle
|
|
147
|
-
*
|
|
148
|
-
* Lightweight runtime CSS-in-JS engine with deterministic class names.
|
|
149
|
-
*
|
|
150
|
-
* Features:
|
|
151
|
-
* - Scoped class generation
|
|
152
|
-
* - Nested pseudo selectors
|
|
153
|
-
* - Responsive media queries
|
|
154
|
-
* - Global styles
|
|
155
|
-
* - Keyframes and font-face support
|
|
156
|
-
*
|
|
157
|
-
* Example:
|
|
158
|
-
* ```ts
|
|
159
|
-
* const ns = new NextStyle("app")
|
|
160
|
-
* ```
|
|
161
|
-
*/
|
|
162
|
-
export declare class NextStyle {
|
|
163
|
-
private prefix;
|
|
164
|
-
private rules;
|
|
165
|
-
private globalStore;
|
|
166
|
-
constructor(prefix?: string);
|
|
167
|
-
/**
|
|
168
|
-
* Generate a scoped class name from a style object.
|
|
169
|
-
*
|
|
170
|
-
* The returned value is a branded class name and is intended
|
|
171
|
-
* to be used with `when(...)` and relational APIs.
|
|
172
|
-
*
|
|
173
|
-
* @param style Style definition object
|
|
174
|
-
* @returns Scoped class name
|
|
175
|
-
*
|
|
176
|
-
* Example:
|
|
177
|
-
* ```ts
|
|
178
|
-
* const button = css({ padding: 8 })
|
|
179
|
-
* ```
|
|
180
|
-
*/
|
|
181
|
-
css: (style: NextStyleProperties) => string;
|
|
182
|
-
/**
|
|
183
|
-
* Define a global CSS selector.
|
|
184
|
-
*
|
|
185
|
-
* Styles are merged at property level instead of overwritten.
|
|
186
|
-
*
|
|
187
|
-
* @param selector CSS selector
|
|
188
|
-
* @param style Style definition
|
|
189
|
-
*
|
|
190
|
-
* Example:
|
|
191
|
-
* ```ts
|
|
192
|
-
* global("body", {
|
|
193
|
-
* fontFamily: "Kanit, sans-serif"
|
|
194
|
-
* })
|
|
195
|
-
* ```
|
|
196
|
-
*/
|
|
197
|
-
global: (selector: string, style: NextStyleProperties) => void;
|
|
198
|
-
/**
|
|
199
|
-
* Define styles on `:root`.
|
|
200
|
-
*
|
|
201
|
-
* Intended for:
|
|
202
|
-
* - CSS variables
|
|
203
|
-
* - Global theme tokens
|
|
204
|
-
*
|
|
205
|
-
* Styles are merged at property level.
|
|
206
|
-
*
|
|
207
|
-
* Example:
|
|
208
|
-
* ```ts
|
|
209
|
-
* root({
|
|
210
|
-
* "--color-primary": "#4f46e5",
|
|
211
|
-
* "--radius": "12px"
|
|
212
|
-
* })
|
|
213
|
-
* ```
|
|
214
|
-
*/
|
|
215
|
-
root: (style: NextStyleProperties) => void;
|
|
216
|
-
/**
|
|
217
|
-
* Apply default browser reset styles
|
|
218
|
-
* ```css
|
|
219
|
-
* html, body {
|
|
220
|
-
* max-width: 100vw;
|
|
221
|
-
* overflow-x: hidden;
|
|
222
|
-
* }
|
|
223
|
-
* body {
|
|
224
|
-
* color: "black";
|
|
225
|
-
* background: "white";
|
|
226
|
-
* -moz-osx-font-smoothing: grayscale;
|
|
227
|
-
* -webkit-font-smoothing: antialiased;
|
|
228
|
-
* font-family: "Arial, Helvetica, sans-serif"
|
|
229
|
-
* }
|
|
230
|
-
* *,
|
|
231
|
-
* *::before,
|
|
232
|
-
* *::after {
|
|
233
|
-
* margin: 0;
|
|
234
|
-
* padding: 0;
|
|
235
|
-
* box-sizing: border-box;
|
|
236
|
-
* }
|
|
237
|
-
* a {
|
|
238
|
-
* color: inherit;
|
|
239
|
-
* text-decoration: none
|
|
240
|
-
* }
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
resetStyle: () => this;
|
|
244
|
-
/**
|
|
245
|
-
* Create relational selectors based on a class generated by `css(...)`.
|
|
246
|
-
*
|
|
247
|
-
* ⚠️ This method only accepts class names returned from `css`.
|
|
248
|
-
*
|
|
249
|
-
* @param source Class name generated by `css`
|
|
250
|
-
*
|
|
251
|
-
* Example:
|
|
252
|
-
* ```ts
|
|
253
|
-
* const card = css({ ... })
|
|
254
|
-
*
|
|
255
|
-
* when(card)
|
|
256
|
-
* .hover()
|
|
257
|
-
* .child("icon", { opacity: 1 })
|
|
258
|
-
* ```
|
|
259
|
-
*/
|
|
260
|
-
when: (source: string) => RelationBuilder;
|
|
261
|
-
/**
|
|
262
|
-
* Register keyframes animation.
|
|
263
|
-
*
|
|
264
|
-
* @param frames Keyframes definition
|
|
265
|
-
* @returns Generated animation name
|
|
266
|
-
*
|
|
267
|
-
* Example:
|
|
268
|
-
* ```ts
|
|
269
|
-
* const fadeIn = keyframes({
|
|
270
|
-
* from: { opacity: 0 },
|
|
271
|
-
* to: { opacity: 1 }
|
|
272
|
-
* })
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
keyframes: (frames: KeyframesObject) => string;
|
|
276
|
-
/**
|
|
277
|
-
* Register a `@font-face` rule.
|
|
278
|
-
*
|
|
279
|
-
* Each unique definition is injected only once.
|
|
280
|
-
*
|
|
281
|
-
* @param font Font-face definition
|
|
282
|
-
*
|
|
283
|
-
* Example:
|
|
284
|
-
* ```ts
|
|
285
|
-
* fontFace({
|
|
286
|
-
* fontFamily: "Kanit",
|
|
287
|
-
* src: "url(/kanit.woff2) format('woff2')",
|
|
288
|
-
* fontWeight: 400
|
|
289
|
-
* })
|
|
290
|
-
* ```
|
|
291
|
-
*/
|
|
292
|
-
fontFace: (font: FontFaceObject) => void;
|
|
293
|
-
/**
|
|
294
|
-
* Serialize all generated CSS into a single string.
|
|
295
|
-
*
|
|
296
|
-
* Intended for:
|
|
297
|
-
* - Manual `<style>` injection
|
|
298
|
-
* - SSR environments
|
|
299
|
-
*
|
|
300
|
-
* @returns CSS text or `null` if no styles exist
|
|
301
|
-
*/
|
|
302
|
-
toTextCss: () => string | null;
|
|
303
|
-
/**
|
|
304
|
-
* React component that injects generated CSS into a `<style>` tag.
|
|
305
|
-
*
|
|
306
|
-
* Returns `null` if no styles are registered.
|
|
307
|
-
*
|
|
308
|
-
* Example:
|
|
309
|
-
* ```tsx
|
|
310
|
-
* <StyleProvider />
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
|
-
StyleProvider: () => DetailedReactHTMLElement<{
|
|
314
|
-
children: string;
|
|
315
|
-
}, HTMLStyleElement> | null;
|
|
316
|
-
}
|
|
317
|
-
export {};
|
|
1
|
+
export { type CompiledStyle, createTransformer, StyleCollector } from './compiler';
|
|
2
|
+
export { default as postcssPlugin, plugin } from './postcss-plugin';
|
|
3
|
+
export { type CSSObject, type CSSProperties, css, global, styleCollector } from './runtime';
|
|
4
|
+
export { BREAKPOINTS, camelToKebab, deduplicateStyles, generateClassHash, normalizeMediaQuery, validateCSSProperty } from './utils';
|
|
5
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,aAAa,EAAE,iBAAiB,EAAE,cAAc,EAAE,MAAM,YAAY,CAAA;AAClF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,EAAE,MAAM,kBAAkB,CAAA;AACnE,OAAO,EAAE,KAAK,SAAS,EAAE,KAAK,aAAa,EAAE,GAAG,EAAE,MAAM,EAAE,cAAc,EAAE,MAAM,WAAW,CAAA;AAC3F,OAAO,EACN,WAAW,EACX,YAAY,EACZ,iBAAiB,EACjB,iBAAiB,EACjB,mBAAmB,EACnB,mBAAmB,EACnB,MAAM,SAAS,CAAA"}
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
export { createTransformer, StyleCollector } from './compiler';
|
|
2
|
+
export { default as postcssPlugin, plugin } from './postcss-plugin';
|
|
3
|
+
export { css, global, styleCollector } from './runtime';
|
|
4
|
+
export { BREAKPOINTS, camelToKebab, deduplicateStyles, generateClassHash, normalizeMediaQuery, validateCSSProperty } from './utils';
|