next-style 2.1.6 → 2.2.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/README.md +10 -43
- package/dist/index.cjs +24 -24
- package/dist/index.d.ts +2 -185
- package/dist/index.js +30 -30
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -246,7 +246,6 @@ All CSS properties and values are typed via [csstype](https://github.com/frenic/
|
|
|
246
246
|
```tsx
|
|
247
247
|
import { css, type CSSObject } from "next-style"
|
|
248
248
|
|
|
249
|
-
// Type a reusable style object before passing it to css()
|
|
250
249
|
const base: CSSObject = {
|
|
251
250
|
fontSize: "16px", // ✅
|
|
252
251
|
colour: "red", // ❌ TypeScript error: unknown property
|
|
@@ -263,48 +262,7 @@ const el = css(base)
|
|
|
263
262
|
| `CSSObject` | Full style object — properties, at-rules, and pseudos |
|
|
264
263
|
| `CSSProperties` | CSS properties only, no at-rules or pseudos |
|
|
265
264
|
|
|
266
|
-
##
|
|
267
|
-
|
|
268
|
-
### `createTransformer`
|
|
269
|
-
|
|
270
|
-
For build tooling, SWC/Babel plugins, and test harnesses that need an isolated style collector independent of the global runtime:
|
|
271
|
-
|
|
272
|
-
```ts
|
|
273
|
-
import { createTransformer } from "next-style"
|
|
274
|
-
|
|
275
|
-
const { collector, transformCssCall } = createTransformer()
|
|
276
|
-
|
|
277
|
-
const className = transformCssCall({ color: "red", fontSize: "16px" })
|
|
278
|
-
// → "ns-abc123"
|
|
279
|
-
|
|
280
|
-
const css = collector.getAllStyles()
|
|
281
|
-
// → ".ns-abc123 { color: red; font-size: 16px; }"
|
|
282
|
-
```
|
|
283
|
-
|
|
284
|
-
### `StyleCollector`
|
|
285
|
-
|
|
286
|
-
The class powering both the runtime and `createTransformer`. Exposed for custom integrations:
|
|
287
|
-
|
|
288
|
-
```ts
|
|
289
|
-
import { StyleCollector } from "next-style"
|
|
290
|
-
|
|
291
|
-
const collector = new StyleCollector()
|
|
292
|
-
collector.addStyle({ color: "red" }) // → "ns-abc123"
|
|
293
|
-
collector.addGlobalStyle("body", { margin: "0" })
|
|
294
|
-
collector.getAllStyles() // full CSS string
|
|
295
|
-
collector.flush("/custom/path/styles.css") // write to disk
|
|
296
|
-
```
|
|
297
|
-
|
|
298
|
-
### How the PostCSS bridge works
|
|
299
|
-
|
|
300
|
-
Because PostCSS runs in a separate process from the module graph, in-memory style collectors cannot be shared. next-style solves this with a file-based bridge:
|
|
301
|
-
|
|
302
|
-
1. Every `css()` / `global()` call writes compiled CSS to `node_modules/.cache/next-style.css`
|
|
303
|
-
2. The PostCSS plugin reads that file and replaces `@import "next-style"` with its contents
|
|
304
|
-
|
|
305
|
-
This is why `@import "next-style"` must appear in `globals.css` — it's the injection point.
|
|
306
|
-
|
|
307
|
-
### CSS Variables
|
|
265
|
+
## CSS Variables
|
|
308
266
|
|
|
309
267
|
next-style pairs naturally with CSS custom properties for design tokens:
|
|
310
268
|
|
|
@@ -328,6 +286,15 @@ const card = css({
|
|
|
328
286
|
})
|
|
329
287
|
```
|
|
330
288
|
|
|
289
|
+
## How it works
|
|
290
|
+
|
|
291
|
+
Because PostCSS runs in a separate process from the module graph, next-style uses a file-based bridge:
|
|
292
|
+
|
|
293
|
+
1. Every `css()` / `global()` call registers styles into an in-memory collector during module evaluation
|
|
294
|
+
2. The PostCSS plugin reads the collector and replaces `@import "next-style"` with the compiled CSS
|
|
295
|
+
|
|
296
|
+
This is why `@import "next-style"` must appear in `globals.css` — it's the injection point.
|
|
297
|
+
|
|
331
298
|
## CSS output order
|
|
332
299
|
|
|
333
300
|
Styles are emitted in this order to ensure correct cascade:
|
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${
|
|
3
|
-
${
|
|
1
|
+
"use strict";var $=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var K=Object.prototype.hasOwnProperty;var T=(n,s)=>{for(var e in s)$(n,e,{get:s[e],enumerable:!0})},z=(n,s,e,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let t of N(s))!K.call(n,t)&&t!==e&&$(n,t,{get:()=>s[t],enumerable:!(r=Q(s,t))||r.enumerable});return n};var I=n=>z($({},"__esModule",{value:!0}),n);var B={};T(B,{css:()=>w,global:()=>D});module.exports=I(B);function O(n){return n.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`)}function b(n){let s=typeof n=="string"?n:JSON.stringify(n),e=2166136261;for(let r=0;r<s.length;r++)e^=s.charCodeAt(r),e=e*16777619>>>0;return e.toString(36)}var R={"@sm":"@media (min-width: 640px)","@md":"@media (min-width: 768px)","@lg":"@media (min-width: 1024px)","@xl":"@media (min-width: 1280px)","@2xl":"@media (min-width: 1536px)"};function E(n){return R[n]??n}var u=class{constructor(){this.styles=new Map}addStyle(s){let r=`ns-${b(s)}`;if(this.styles.has(r))return r;let t=this.compileStyle(s);return this.styles.set(r,t),r}addGlobalStyle(s,e){let r=`global:${s}`;if(this.styles.has(r))return;let t=this.buildDeclarations(e);t&&this.styles.set(r,{className:r,css:`${s} {
|
|
2
|
+
${t}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(s){let{mediaQueries:e,pseudoClasses:r,normalStyles:t,keyframes:l,supports:g,container:y,layer:m}=this.parseStyles(s),o=`ns-${b(s)}`,S=this.buildDeclarations(t),A=`.${o} {
|
|
3
|
+
${S}}`,d={};Object.entries(e).forEach(([c,p])=>{let a=E(c),f=this.buildDeclarations(p," ");if(d[a]){let M=d[a].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);
|
|
5
|
+
`);d[a]=`${a} {
|
|
6
6
|
.${o} {
|
|
7
|
-
${
|
|
8
|
-
${
|
|
9
|
-
}`}else
|
|
7
|
+
${M}
|
|
8
|
+
${f} }
|
|
9
|
+
}`}else d[a]=`${a} {
|
|
10
10
|
.${o} {
|
|
11
|
-
${
|
|
12
|
-
}`}),Object.entries(
|
|
11
|
+
${f} }
|
|
12
|
+
}`}),Object.entries(y).forEach(([c,p])=>{let a=this.buildDeclarations(p," ");d[c]=`${c} {
|
|
13
13
|
.${o} {
|
|
14
14
|
${a} }
|
|
15
|
-
}`});let
|
|
16
|
-
${a}}`});let
|
|
17
|
-
`,Object.entries(p).forEach(([a,
|
|
18
|
-
${
|
|
19
|
-
`}),
|
|
20
|
-
`});let
|
|
15
|
+
}`});let C={};Object.entries(r).forEach(([c,p])=>{let a=this.buildDeclarations(p);C[c]=`.${o}${c} {
|
|
16
|
+
${a}}`});let h="";Object.entries(l).forEach(([c,p])=>{h+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(p).forEach(([a,f])=>{let j=this.buildDeclarations(f," ");h+=` ${a} {
|
|
18
|
+
${j} }
|
|
19
|
+
`}),h+=`}
|
|
20
|
+
`});let x={};Object.entries(g).forEach(([c,p])=>{let a=this.buildDeclarations(p," ");x[c]=`@supports ${c} {
|
|
21
21
|
.${o} {
|
|
22
22
|
${a} }
|
|
23
|
-
}`});let
|
|
24
|
-
${a}}`}),{className:o,css:
|
|
25
|
-
`)}),r}getAllStyles(){let
|
|
26
|
-
`),
|
|
27
|
-
`),Object.values(
|
|
28
|
-
`}),Object.values(
|
|
29
|
-
`}),Object.values(
|
|
30
|
-
`}),Object.entries(
|
|
31
|
-
`})}),
|
|
23
|
+
}`});let P={};return Object.entries(m).forEach(([c,p])=>{let a=this.buildDeclarations(p," ");P[c]=`@layer ${c} {
|
|
24
|
+
${a}}`}),{className:o,css:A,mediaQueries:d,pseudoClasses:C,keyframes:h,supports:x,layers:P}}parseStyles(s){let e={},r={},t={},l={},g={},y={},m={};return Object.entries(s).forEach(([i,o])=>{if(i.startsWith("@keyframes "))l[i.slice(11)]=o;else if(i==="@keyframes"&&typeof o=="object")Object.assign(l,o);else if(i.startsWith("@supports")){let S=i.slice(0,9)==="@supports"?i.slice(9).trim():i;g[S]=o}else i.startsWith("@container")?y[i]=o:i.startsWith("@layer")?m[i.slice(7)||"default"]=o:i in R||i.startsWith("@media")?r[i]=o:i.startsWith(":")||i.startsWith("::")?t[i]=o:e[i]=o}),{normalStyles:e,mediaQueries:r,pseudoClasses:t,keyframes:l,supports:g,container:y,layer:m}}buildDeclarations(s,e=" "){let r="";return Object.entries(s).forEach(([t,l])=>{(typeof l=="string"||typeof l=="number")&&(r+=`${e}${O(t)}: ${l};
|
|
25
|
+
`)}),r}getAllStyles(){let s="";return this.styles.forEach(e=>{e.keyframes&&(s+=`${e.keyframes}
|
|
26
|
+
`),e.css&&(s+=`${e.css}
|
|
27
|
+
`),Object.values(e.pseudoClasses).forEach(t=>{s+=`${t}
|
|
28
|
+
`}),Object.values(e.layers).forEach(t=>{s+=`${t}
|
|
29
|
+
`}),Object.values(e.supports).forEach(t=>{s+=`${t}
|
|
30
|
+
`}),Object.entries(e.mediaQueries).sort(([t],[l])=>this.extractMinWidth(t)-this.extractMinWidth(l)).forEach(([,t])=>{s+=`${t}
|
|
31
|
+
`})}),s}extractMinWidth(s){let e=s.match(/min-width:\s*(\d+)px/);return e?parseInt(e[1],10):0}getStyleMap(){return new Map(this.styles)}};function w(n){return W.addStyle(n)}function D(n){Object.entries(n).forEach(([s,e])=>{W.addGlobalStyle(s,e)})}var W=new u;0&&(module.exports={css,global});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,122 +1,11 @@
|
|
|
1
1
|
import { Properties, Pseudos } from 'csstype';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* The compiled representation of a single `css({})` call.
|
|
5
|
-
* Produced by `StyleCollector` and consumed by the PostCSS plugin.
|
|
6
|
-
*/
|
|
7
|
-
interface CompiledStyle {
|
|
8
|
-
/** Scoped class name, e.g. `"ns-1x2y3z"`. */
|
|
9
|
-
className: string;
|
|
10
|
-
/** Base CSS rule block for this class. */
|
|
11
|
-
css: string;
|
|
12
|
-
/** Map of normalized media query string → CSS rule block. */
|
|
13
|
-
mediaQueries: Record<string, string>;
|
|
14
|
-
/** Map of pseudo selector (e.g. `":hover"`) → CSS rule block. */
|
|
15
|
-
pseudoClasses: Record<string, string>;
|
|
16
|
-
/** Concatenated `@keyframes` blocks referenced by this style. */
|
|
17
|
-
keyframes: string;
|
|
18
|
-
/** Map of `@supports` condition → CSS rule block. */
|
|
19
|
-
supports: Record<string, string>;
|
|
20
|
-
/** Map of `@layer` name → CSS rule block. */
|
|
21
|
-
layers: Record<string, string>;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Collects, compiles, and deduplicates styles registered via `css()` and `global()`.
|
|
25
|
-
*
|
|
26
|
-
* A single shared instance is held by the runtime module. The PostCSS plugin
|
|
27
|
-
* calls `getAllStyles()` at build time to drain the collected CSS.
|
|
28
|
-
*
|
|
29
|
-
* @example
|
|
30
|
-
* const collector = new StyleCollector()
|
|
31
|
-
* const className = collector.addStyle({ color: 'red' }) // "ns-abc123"
|
|
32
|
-
* const css = collector.getAllStyles() // ".ns-abc123 { color: red; }"
|
|
33
|
-
*/
|
|
34
|
-
declare class StyleCollector {
|
|
35
|
-
private styles;
|
|
36
|
-
/**
|
|
37
|
-
* Compiles a style object and registers it in the collector.
|
|
38
|
-
* Returns the same class name for identical style objects (deduplication).
|
|
39
|
-
*
|
|
40
|
-
* @param styleObj - Raw style object from a `css({})` call.
|
|
41
|
-
* @returns Scoped class name string.
|
|
42
|
-
*/
|
|
43
|
-
addStyle(styleObj: any): string;
|
|
44
|
-
/**
|
|
45
|
-
* Registers a global style rule (no scoped class).
|
|
46
|
-
* Subsequent calls with the same selector are ignored (idempotent).
|
|
47
|
-
*
|
|
48
|
-
* @param selector - CSS selector string, e.g. `"body"` or `"h1, h2"`.
|
|
49
|
-
* @param styleObj - Style properties to apply to the selector.
|
|
50
|
-
*/
|
|
51
|
-
addGlobalStyle(selector: string, styleObj: any): void;
|
|
52
|
-
private compileStyle;
|
|
53
|
-
private parseStyles;
|
|
54
|
-
private buildDeclarations;
|
|
55
|
-
/**
|
|
56
|
-
* Serialises all collected styles into a single CSS string.
|
|
57
|
-
*
|
|
58
|
-
* Output order:
|
|
59
|
-
* 1. `@keyframes` blocks
|
|
60
|
-
* 2. Base class rules
|
|
61
|
-
* 3. Pseudo-class/element rules
|
|
62
|
-
* 4. `@layer` blocks
|
|
63
|
-
* 5. `@supports` blocks
|
|
64
|
-
* 6. Media queries (ascending `min-width`, mobile-first)
|
|
65
|
-
*
|
|
66
|
-
* @returns Full CSS string ready to be injected or written to a file.
|
|
67
|
-
*/
|
|
68
|
-
getAllStyles(): string;
|
|
69
|
-
private extractMinWidth;
|
|
70
|
-
/**
|
|
71
|
-
* Writes all collected styles to a temp file so the PostCSS plugin
|
|
72
|
-
* (which runs in a separate process) can read them.
|
|
73
|
-
*
|
|
74
|
-
* Call this after all `css()` / `global()` calls have been evaluated,
|
|
75
|
-
* e.g. at the end of a build-time entry point.
|
|
76
|
-
*
|
|
77
|
-
* @param filePath - Destination file path. Defaults to `os.tmpdir()/next-style.css`.
|
|
78
|
-
*/
|
|
79
|
-
flush(filePath?: string): void;
|
|
80
|
-
/**
|
|
81
|
-
* Returns the default cache file path, resolved at call-time from
|
|
82
|
-
* `process.cwd()` so it reflects the actual working directory of the
|
|
83
|
-
* running process rather than the directory at module-load time.
|
|
84
|
-
*/
|
|
85
|
-
static defaultCacheFile(): string;
|
|
86
|
-
/**
|
|
87
|
-
* Returns a snapshot of the internal style map.
|
|
88
|
-
* Intended for inspection and testing — not for direct mutation.
|
|
89
|
-
*/
|
|
90
|
-
getStyleMap(): Map<string, CompiledStyle>;
|
|
91
|
-
}
|
|
92
|
-
/**
|
|
93
|
-
* Creates an isolated `StyleCollector` paired with a transform helper.
|
|
94
|
-
*
|
|
95
|
-
* Primarily used by SWC/Babel transforms and test harnesses that need
|
|
96
|
-
* a fresh collector per file or per test, independent of the shared
|
|
97
|
-
* runtime instance.
|
|
98
|
-
*
|
|
99
|
-
* @example
|
|
100
|
-
* const { collector, transformCssCall } = createTransformer()
|
|
101
|
-
* const className = transformCssCall({ color: 'red' })
|
|
102
|
-
* const css = collector.getAllStyles()
|
|
103
|
-
*/
|
|
104
|
-
declare function createTransformer(): {
|
|
105
|
-
collector: StyleCollector;
|
|
106
|
-
/**
|
|
107
|
-
* Equivalent to calling `css()` against this transformer's isolated collector.
|
|
108
|
-
* @param styleObj - Raw style object.
|
|
109
|
-
* @returns Scoped class name string.
|
|
110
|
-
*/
|
|
111
|
-
transformCssCall(styleObj: any): string;
|
|
112
|
-
};
|
|
113
|
-
|
|
114
3
|
/**
|
|
115
4
|
* CSS properties with full type safety and autocomplete via csstype.
|
|
116
5
|
* Accepts both string and number values (e.g. `fontSize: 16` or `fontSize: '16px'`).
|
|
117
6
|
*/
|
|
118
7
|
type CSSProperties = Properties<string | number>;
|
|
119
|
-
/** @internal Mapped type for pseudo-classes/elements
|
|
8
|
+
/** @internal Mapped type for pseudo-classes/elements */
|
|
120
9
|
type PseudoStyles = {
|
|
121
10
|
[P in Pseudos]?: CSSProperties;
|
|
122
11
|
};
|
|
@@ -145,14 +34,6 @@ type AtRuleStyles = {
|
|
|
145
34
|
* - Feature queries: `'@supports (display: grid)'`
|
|
146
35
|
* - Keyframe animations: `'@keyframes fadeIn'`
|
|
147
36
|
* - Cascade layers: `'@layer utilities'`
|
|
148
|
-
*
|
|
149
|
-
* @example
|
|
150
|
-
* const style: CSSObject = {
|
|
151
|
-
* fontSize: '16px',
|
|
152
|
-
* '@md': { fontSize: '20px' },
|
|
153
|
-
* ':hover': { color: 'blue' },
|
|
154
|
-
* '@keyframes spin': { to: { transform: 'rotate(360deg)' } },
|
|
155
|
-
* }
|
|
156
37
|
*/
|
|
157
38
|
type CSSObject = CSSProperties & PseudoStyles & AtRuleStyles & {
|
|
158
39
|
[key: string]: any;
|
|
@@ -185,7 +66,6 @@ declare function css(styles: CSSObject): string;
|
|
|
185
66
|
* Registers global CSS styles applied directly to selectors (no scoped class).
|
|
186
67
|
*
|
|
187
68
|
* Useful for CSS resets, base typography, and third-party element overrides.
|
|
188
|
-
* Like `css()`, styles are extracted at build time — no runtime cost.
|
|
189
69
|
*
|
|
190
70
|
* @param styles - A record mapping CSS selectors to `CSSObject` style definitions.
|
|
191
71
|
*
|
|
@@ -193,71 +73,8 @@ declare function css(styles: CSSObject): string;
|
|
|
193
73
|
* global({
|
|
194
74
|
* '*': { boxSizing: 'border-box', margin: '0' },
|
|
195
75
|
* 'body': { fontFamily: 'Inter, sans-serif', lineHeight: '1.6' },
|
|
196
|
-
* 'h1, h2, h3': { fontWeight: 500 },
|
|
197
76
|
* })
|
|
198
77
|
*/
|
|
199
78
|
declare function global(styles: Record<string, CSSObject>): void;
|
|
200
79
|
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
/**
|
|
204
|
-
* Converts a camelCase CSS property name to kebab-case.
|
|
205
|
-
*
|
|
206
|
-
* @param str - camelCase string, e.g. `"backgroundColor"`.
|
|
207
|
-
* @returns kebab-case string, e.g. `"background-color"`.
|
|
208
|
-
*
|
|
209
|
-
* @example
|
|
210
|
-
* camelToKebab('fontSize') // "font-size"
|
|
211
|
-
* camelToKebab('borderTopWidth') // "border-top-width"
|
|
212
|
-
*/
|
|
213
|
-
declare function camelToKebab(str: string): string;
|
|
214
|
-
/**
|
|
215
|
-
* Generates a short, stable hash string from a style object or string.
|
|
216
|
-
* Used to produce unique class name suffixes (e.g. `"ns-1x2y3z"`).
|
|
217
|
-
*
|
|
218
|
-
* @param styles - Style object or pre-serialised string.
|
|
219
|
-
* @returns Base-36 hash string.
|
|
220
|
-
*/
|
|
221
|
-
declare function generateClassHash(styles: any): string;
|
|
222
|
-
/**
|
|
223
|
-
* Shorthand breakpoint aliases mapped to their full `@media` query strings.
|
|
224
|
-
*
|
|
225
|
-
* | Key | Expands to |
|
|
226
|
-
* |--------|-------------------------------------|
|
|
227
|
-
* | `@sm` | `@media (min-width: 640px)` |
|
|
228
|
-
* | `@md` | `@media (min-width: 768px)` |
|
|
229
|
-
* | `@lg` | `@media (min-width: 1024px)` |
|
|
230
|
-
* | `@xl` | `@media (min-width: 1280px)` |
|
|
231
|
-
* | `@2xl` | `@media (min-width: 1536px)` |
|
|
232
|
-
*/
|
|
233
|
-
declare const BREAKPOINTS: Record<string, string>;
|
|
234
|
-
/**
|
|
235
|
-
* Resolves a breakpoint shorthand to its full `@media` query string.
|
|
236
|
-
* Passes through unrecognised strings unchanged.
|
|
237
|
-
*
|
|
238
|
-
* @param query - Shorthand key (e.g. `"@md"`) or an arbitrary media query.
|
|
239
|
-
* @returns Full media query string (e.g. `"@media (min-width: 768px)"`).
|
|
240
|
-
*
|
|
241
|
-
* @example
|
|
242
|
-
* normalizeMediaQuery('@md') // "@media (min-width: 768px)"
|
|
243
|
-
* normalizeMediaQuery('@media (max-width: 600px)') // "@media (max-width: 600px)"
|
|
244
|
-
*/
|
|
245
|
-
declare function normalizeMediaQuery(query: string): string;
|
|
246
|
-
/**
|
|
247
|
-
* Returns `true` if the value is a valid CSS property value that can be
|
|
248
|
-
* serialised to a declaration (string, number, or nested object).
|
|
249
|
-
*
|
|
250
|
-
* @param _key - CSS property name (unused, reserved for future validation).
|
|
251
|
-
* @param value - Value to check.
|
|
252
|
-
*/
|
|
253
|
-
declare function validateCSSProperty(_key: string, value: any): boolean;
|
|
254
|
-
/**
|
|
255
|
-
* Removes duplicate entries from a style map, keeping the first occurrence.
|
|
256
|
-
* Two entries are considered duplicates when their serialised values are identical.
|
|
257
|
-
*
|
|
258
|
-
* @param styles - Map of class name → style data.
|
|
259
|
-
* @returns New map with duplicates removed.
|
|
260
|
-
*/
|
|
261
|
-
declare function deduplicateStyles(styles: Map<string, any>): Map<string, any>;
|
|
262
|
-
|
|
263
|
-
export { BREAKPOINTS, type CSSObject, type CSSProperties, type CompiledStyle, StyleCollector, camelToKebab, createTransformer, css, deduplicateStyles, generateClassHash, global, normalizeMediaQuery, collector as styleCollector, validateCSSProperty };
|
|
80
|
+
export { type CSSObject, css, global };
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
|
|
2
|
-
${r}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(
|
|
3
|
-
${
|
|
1
|
+
function j(c){return c.replace(/[A-Z]/g,s=>`-${s.toLowerCase()}`)}function $(c){let s=typeof c=="string"?c:JSON.stringify(c),e=2166136261;for(let t=0;t<s.length;t++)e^=s.charCodeAt(t),e=e*16777619>>>0;return e.toString(36)}var b={"@sm":"@media (min-width: 640px)","@md":"@media (min-width: 768px)","@lg":"@media (min-width: 1024px)","@xl":"@media (min-width: 1280px)","@2xl":"@media (min-width: 1536px)"};function O(c){return b[c]??c}var u=class{constructor(){this.styles=new Map}addStyle(s){let t=`ns-${$(s)}`;if(this.styles.has(t))return t;let r=this.compileStyle(s);return this.styles.set(t,r),t}addGlobalStyle(s,e){let t=`global:${s}`;if(this.styles.has(t))return;let r=this.buildDeclarations(e);r&&this.styles.set(t,{className:t,css:`${s} {
|
|
2
|
+
${r}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(s){let{mediaQueries:e,pseudoClasses:t,normalStyles:r,keyframes:l,supports:g,container:y,layer:m}=this.parseStyles(s),i=`ns-${$(s)}`,S=this.buildDeclarations(r),w=`.${i} {
|
|
3
|
+
${S}}`,d={};Object.entries(e).forEach(([a,p])=>{let o=O(a),f=this.buildDeclarations(p," ");if(d[o]){let D=d[o].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);d[
|
|
6
|
-
.${
|
|
7
|
-
${
|
|
8
|
-
${
|
|
9
|
-
}`}else d[
|
|
10
|
-
.${
|
|
11
|
-
${
|
|
12
|
-
}`}),Object.entries(
|
|
13
|
-
.${
|
|
14
|
-
${
|
|
15
|
-
}`});let
|
|
16
|
-
${
|
|
17
|
-
`,Object.entries(p).forEach(([
|
|
18
|
-
${
|
|
19
|
-
`}),
|
|
20
|
-
`});let
|
|
21
|
-
.${
|
|
22
|
-
${
|
|
23
|
-
}`});let
|
|
24
|
-
${
|
|
25
|
-
`)}),
|
|
26
|
-
`),
|
|
27
|
-
`),Object.values(
|
|
28
|
-
`}),Object.values(
|
|
29
|
-
`}),Object.values(
|
|
30
|
-
`}),Object.entries(
|
|
31
|
-
`})}),
|
|
5
|
+
`);d[o]=`${o} {
|
|
6
|
+
.${i} {
|
|
7
|
+
${D}
|
|
8
|
+
${f} }
|
|
9
|
+
}`}else d[o]=`${o} {
|
|
10
|
+
.${i} {
|
|
11
|
+
${f} }
|
|
12
|
+
}`}),Object.entries(y).forEach(([a,p])=>{let o=this.buildDeclarations(p," ");d[a]=`${a} {
|
|
13
|
+
.${i} {
|
|
14
|
+
${o} }
|
|
15
|
+
}`});let R={};Object.entries(t).forEach(([a,p])=>{let o=this.buildDeclarations(p);R[a]=`.${i}${a} {
|
|
16
|
+
${o}}`});let h="";Object.entries(l).forEach(([a,p])=>{h+=`@keyframes ${a} {
|
|
17
|
+
`,Object.entries(p).forEach(([o,f])=>{let P=this.buildDeclarations(f," ");h+=` ${o} {
|
|
18
|
+
${P} }
|
|
19
|
+
`}),h+=`}
|
|
20
|
+
`});let C={};Object.entries(g).forEach(([a,p])=>{let o=this.buildDeclarations(p," ");C[a]=`@supports ${a} {
|
|
21
|
+
.${i} {
|
|
22
|
+
${o} }
|
|
23
|
+
}`});let x={};return Object.entries(m).forEach(([a,p])=>{let o=this.buildDeclarations(p," ");x[a]=`@layer ${a} {
|
|
24
|
+
${o}}`}),{className:i,css:w,mediaQueries:d,pseudoClasses:R,keyframes:h,supports:C,layers:x}}parseStyles(s){let e={},t={},r={},l={},g={},y={},m={};return Object.entries(s).forEach(([n,i])=>{if(n.startsWith("@keyframes "))l[n.slice(11)]=i;else if(n==="@keyframes"&&typeof i=="object")Object.assign(l,i);else if(n.startsWith("@supports")){let S=n.slice(0,9)==="@supports"?n.slice(9).trim():n;g[S]=i}else n.startsWith("@container")?y[n]=i:n.startsWith("@layer")?m[n.slice(7)||"default"]=i:n in b||n.startsWith("@media")?t[n]=i:n.startsWith(":")||n.startsWith("::")?r[n]=i:e[n]=i}),{normalStyles:e,mediaQueries:t,pseudoClasses:r,keyframes:l,supports:g,container:y,layer:m}}buildDeclarations(s,e=" "){let t="";return Object.entries(s).forEach(([r,l])=>{(typeof l=="string"||typeof l=="number")&&(t+=`${e}${j(r)}: ${l};
|
|
25
|
+
`)}),t}getAllStyles(){let s="";return this.styles.forEach(e=>{e.keyframes&&(s+=`${e.keyframes}
|
|
26
|
+
`),e.css&&(s+=`${e.css}
|
|
27
|
+
`),Object.values(e.pseudoClasses).forEach(r=>{s+=`${r}
|
|
28
|
+
`}),Object.values(e.layers).forEach(r=>{s+=`${r}
|
|
29
|
+
`}),Object.values(e.supports).forEach(r=>{s+=`${r}
|
|
30
|
+
`}),Object.entries(e.mediaQueries).sort(([r],[l])=>this.extractMinWidth(r)-this.extractMinWidth(l)).forEach(([,r])=>{s+=`${r}
|
|
31
|
+
`})}),s}extractMinWidth(s){let e=s.match(/min-width:\s*(\d+)px/);return e?parseInt(e[1],10):0}getStyleMap(){return new Map(this.styles)}};function W(c){return E.addStyle(c)}function A(c){Object.entries(c).forEach(([s,e])=>{E.addGlobalStyle(s,e)})}var E=new u;export{W as css,A as global};
|