next-style 2.2.0 → 2.2.1
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/dist/index.cjs +22 -22
- package/dist/index.d.ts +0 -20
- package/dist/index.js +28 -28
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${t}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(
|
|
3
|
-
${
|
|
1
|
+
"use strict";var b=Object.defineProperty;var Q=Object.getOwnPropertyDescriptor;var N=Object.getOwnPropertyNames;var F=Object.prototype.hasOwnProperty;var K=(n,e)=>{for(var s in e)b(n,s,{get:e[s],enumerable:!0})},T=(n,e,s,r)=>{if(e&&typeof e=="object"||typeof e=="function")for(let t of N(e))!F.call(n,t)&&t!==s&&b(n,t,{get:()=>e[t],enumerable:!(r=Q(e,t))||r.enumerable});return n};var z=n=>T(b({},"__esModule",{value:!0}),n);var I={};K(I,{css:()=>A,global:()=>D});module.exports=z(I);function E(n){return n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function C(n){let e=typeof n=="string"?n:JSON.stringify(n),s=2166136261;for(let r=0;r<e.length;r++)s^=e.charCodeAt(r),s=s*16777619>>>0;return s.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 w(n){return R[n]??n}var u=class n{constructor(){this.styles=new Map}addStyle(e){let r=`ns-${C(e)}`;if(this.styles.has(r))return r;let t=this.compileStyle(e);return this.styles.set(r,t),r}addGlobalStyle(e,s){let r=`global:${e}`;if(this.styles.has(r))return;let t=this.buildDeclarations(s);t&&this.styles.set(r,{className:r,css:`${e} {
|
|
2
|
+
${t}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:s,pseudoClasses:r,normalStyles:t,keyframes:l,supports:y,container:f,layer:g}=this.parseStyles(e),o=`ns-${C(e)}`,$=this.buildDeclarations(t),W=`.${o} {
|
|
3
|
+
${$}}`,p={};Object.entries(s).forEach(([c,d])=>{let a=w(c),m=this.buildDeclarations(d," ");if(p[a]){let M=p[a].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);
|
|
5
|
+
`);p[a]=`${a} {
|
|
6
6
|
.${o} {
|
|
7
7
|
${M}
|
|
8
|
-
${
|
|
9
|
-
}`}else
|
|
8
|
+
${m} }
|
|
9
|
+
}`}else p[a]=`${a} {
|
|
10
10
|
.${o} {
|
|
11
|
-
${
|
|
12
|
-
}`}),Object.entries(
|
|
11
|
+
${m} }
|
|
12
|
+
}`}),Object.entries(f).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");p[c]=`${c} {
|
|
13
13
|
.${o} {
|
|
14
14
|
${a} }
|
|
15
|
-
}`});let
|
|
16
|
-
${a}}`});let h="";Object.entries(l).forEach(([c,
|
|
17
|
-
`,Object.entries(
|
|
18
|
-
${
|
|
15
|
+
}`});let x={};Object.entries(r).forEach(([c,d])=>{let a=this.buildDeclarations(d);x[c]=`.${o}${c} {
|
|
16
|
+
${a}}`});let h="";Object.entries(l).forEach(([c,d])=>{h+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(d).forEach(([a,m])=>{let O=this.buildDeclarations(m," ");h+=` ${a} {
|
|
18
|
+
${O} }
|
|
19
19
|
`}),h+=`}
|
|
20
|
-
`});let
|
|
20
|
+
`});let P={};Object.entries(y).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");P[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 j={};return Object.entries(g).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");j[c]=`@layer ${c} {
|
|
24
|
+
${a}}`}),{className:o,css:W,mediaQueries:p,pseudoClasses:x,keyframes:h,supports:P,layers:j}}parseStyles(e){let s={},r={},t={},l={},y={},f={},g={};return Object.entries(e).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 $=i.slice(0,9)==="@supports"?i.slice(9).trim():i;y[$]=o}else i.startsWith("@container")?f[i]=o:i.startsWith("@layer")?g[i.slice(7)||"default"]=o:i in R||i.startsWith("@media")?r[i]=o:i.startsWith(":")||i.startsWith("::")?t[i]=o:s[i]=o}),{normalStyles:s,mediaQueries:r,pseudoClasses:t,keyframes:l,supports:y,container:f,layer:g}}buildDeclarations(e,s=" "){let r="";return Object.entries(e).forEach(([t,l])=>{(typeof l=="string"||typeof l=="number")&&(r+=`${s}${E(t)}: ${l};
|
|
25
|
+
`)}),r}getAllStyles(){let e="";return this.styles.forEach(s=>{s.keyframes&&(e+=`${s.keyframes}
|
|
26
|
+
`),s.css&&(e+=`${s.css}
|
|
27
|
+
`),Object.values(s.pseudoClasses).forEach(t=>{e+=`${t}
|
|
28
|
+
`}),Object.values(s.layers).forEach(t=>{e+=`${t}
|
|
29
|
+
`}),Object.values(s.supports).forEach(t=>{e+=`${t}
|
|
30
|
+
`}),Object.entries(s.mediaQueries).sort(([t],[l])=>this.extractMinWidth(t)-this.extractMinWidth(l)).forEach(([,t])=>{e+=`${t}
|
|
31
|
+
`})}),e}extractMinWidth(e){let s=e.match(/min-width:\s*(\d+)px/);return s?parseInt(s[1],10):0}flush(e){if(!(typeof window<"u"))try{let s=require("fs"),r=require("path"),t=e??n.defaultCacheFile();s.mkdirSync(r.dirname(t),{recursive:!0}),s.writeFileSync(t,this.getAllStyles(),"utf-8")}catch(s){console.error("[next-style] Failed to flush styles to cache file:",s)}}static defaultCacheFile(){return require("path").join(process.cwd(),"node_modules",".cache","next-style","styles.css")}getStyleMap(){return new Map(this.styles)}};function A(n){let e=S.addStyle(n);return typeof window>"u"&&S.flush(),e}function D(n){Object.entries(n).forEach(([e,s])=>{S.addGlobalStyle(e,s)}),typeof window>"u"&&S.flush()}var S=new u;0&&(module.exports={css,global});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,9 @@
|
|
|
1
1
|
import { Properties, Pseudos } from 'csstype';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
* CSS properties with full type safety and autocomplete via csstype.
|
|
5
|
-
* Accepts both string and number values (e.g. `fontSize: 16` or `fontSize: '16px'`).
|
|
6
|
-
*/
|
|
7
3
|
type CSSProperties = Properties<string | number>;
|
|
8
|
-
/** @internal Mapped type for pseudo-classes/elements */
|
|
9
4
|
type PseudoStyles = {
|
|
10
5
|
[P in Pseudos]?: CSSProperties;
|
|
11
6
|
};
|
|
12
|
-
/** @internal At-rule keys (@media, @container, @supports, @layer, @keyframes) */
|
|
13
7
|
type AtRuleStyles = {
|
|
14
8
|
'@sm'?: CSSProperties;
|
|
15
9
|
'@md'?: CSSProperties;
|
|
@@ -40,35 +34,21 @@ type CSSObject = CSSProperties & PseudoStyles & AtRuleStyles & {
|
|
|
40
34
|
};
|
|
41
35
|
/**
|
|
42
36
|
* Converts a style object into a unique CSS class name.
|
|
43
|
-
*
|
|
44
37
|
* Styles are collected at build time by the PostCSS plugin and emitted as
|
|
45
38
|
* a single static CSS file — there is zero runtime overhead in production.
|
|
46
|
-
* Identical style objects always return the same class name (deduplication).
|
|
47
|
-
*
|
|
48
|
-
* @param styles - A `CSSObject` describing the styles for this element.
|
|
49
|
-
* @returns A stable class name string (e.g. `"ns-1x2y3z"`).
|
|
50
39
|
*
|
|
51
40
|
* @example
|
|
52
41
|
* const button = css({
|
|
53
42
|
* padding: '8px 16px',
|
|
54
|
-
* borderRadius: '6px',
|
|
55
43
|
* backgroundColor: '#7F77DD',
|
|
56
44
|
* ':hover': { backgroundColor: '#534AB7' },
|
|
57
45
|
* '@md': { padding: '10px 20px' },
|
|
58
46
|
* })
|
|
59
|
-
*
|
|
60
|
-
* export function Button() {
|
|
61
|
-
* return <button className={button}>Click me</button>
|
|
62
|
-
* }
|
|
63
47
|
*/
|
|
64
48
|
declare function css(styles: CSSObject): string;
|
|
65
49
|
/**
|
|
66
50
|
* Registers global CSS styles applied directly to selectors (no scoped class).
|
|
67
51
|
*
|
|
68
|
-
* Useful for CSS resets, base typography, and third-party element overrides.
|
|
69
|
-
*
|
|
70
|
-
* @param styles - A record mapping CSS selectors to `CSSObject` style definitions.
|
|
71
|
-
*
|
|
72
52
|
* @example
|
|
73
53
|
* global({
|
|
74
54
|
* '*': { boxSizing: 'border-box', margin: '0' },
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
function
|
|
2
|
-
${
|
|
3
|
-
${
|
|
1
|
+
var b=(n=>typeof require<"u"?require:typeof Proxy<"u"?new Proxy(n,{get:(e,s)=>(typeof require<"u"?require:e)[s]}):n)(function(n){if(typeof require<"u")return require.apply(this,arguments);throw Error('Dynamic require of "'+n+'" is not supported')});function E(n){return n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function C(n){let e=typeof n=="string"?n:JSON.stringify(n),s=2166136261;for(let r=0;r<e.length;r++)s^=e.charCodeAt(r),s=s*16777619>>>0;return s.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 w(n){return R[n]??n}var u=class n{constructor(){this.styles=new Map}addStyle(e){let r=`ns-${C(e)}`;if(this.styles.has(r))return r;let t=this.compileStyle(e);return this.styles.set(r,t),r}addGlobalStyle(e,s){let r=`global:${e}`;if(this.styles.has(r))return;let t=this.buildDeclarations(s);t&&this.styles.set(r,{className:r,css:`${e} {
|
|
2
|
+
${t}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:s,pseudoClasses:r,normalStyles:t,keyframes:l,supports:y,container:f,layer:g}=this.parseStyles(e),o=`ns-${C(e)}`,$=this.buildDeclarations(t),A=`.${o} {
|
|
3
|
+
${$}}`,p={};Object.entries(s).forEach(([c,d])=>{let a=w(c),m=this.buildDeclarations(d," ");if(p[a]){let D=p[a].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);
|
|
6
|
-
.${
|
|
5
|
+
`);p[a]=`${a} {
|
|
6
|
+
.${o} {
|
|
7
7
|
${D}
|
|
8
|
-
${
|
|
9
|
-
}`}else
|
|
10
|
-
.${
|
|
11
|
-
${
|
|
12
|
-
}`}),Object.entries(
|
|
13
|
-
.${
|
|
14
|
-
${
|
|
15
|
-
}`});let
|
|
16
|
-
${
|
|
17
|
-
`,Object.entries(
|
|
18
|
-
${
|
|
8
|
+
${m} }
|
|
9
|
+
}`}else p[a]=`${a} {
|
|
10
|
+
.${o} {
|
|
11
|
+
${m} }
|
|
12
|
+
}`}),Object.entries(f).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");p[c]=`${c} {
|
|
13
|
+
.${o} {
|
|
14
|
+
${a} }
|
|
15
|
+
}`});let x={};Object.entries(r).forEach(([c,d])=>{let a=this.buildDeclarations(d);x[c]=`.${o}${c} {
|
|
16
|
+
${a}}`});let h="";Object.entries(l).forEach(([c,d])=>{h+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(d).forEach(([a,m])=>{let O=this.buildDeclarations(m," ");h+=` ${a} {
|
|
18
|
+
${O} }
|
|
19
19
|
`}),h+=`}
|
|
20
|
-
`});let
|
|
21
|
-
.${
|
|
22
|
-
${
|
|
23
|
-
}`});let
|
|
24
|
-
${
|
|
25
|
-
`)}),
|
|
26
|
-
`),
|
|
27
|
-
`),Object.values(
|
|
28
|
-
`}),Object.values(
|
|
29
|
-
`}),Object.values(
|
|
30
|
-
`}),Object.entries(
|
|
31
|
-
`})}),
|
|
20
|
+
`});let P={};Object.entries(y).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");P[c]=`@supports ${c} {
|
|
21
|
+
.${o} {
|
|
22
|
+
${a} }
|
|
23
|
+
}`});let j={};return Object.entries(g).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");j[c]=`@layer ${c} {
|
|
24
|
+
${a}}`}),{className:o,css:A,mediaQueries:p,pseudoClasses:x,keyframes:h,supports:P,layers:j}}parseStyles(e){let s={},r={},t={},l={},y={},f={},g={};return Object.entries(e).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 $=i.slice(0,9)==="@supports"?i.slice(9).trim():i;y[$]=o}else i.startsWith("@container")?f[i]=o:i.startsWith("@layer")?g[i.slice(7)||"default"]=o:i in R||i.startsWith("@media")?r[i]=o:i.startsWith(":")||i.startsWith("::")?t[i]=o:s[i]=o}),{normalStyles:s,mediaQueries:r,pseudoClasses:t,keyframes:l,supports:y,container:f,layer:g}}buildDeclarations(e,s=" "){let r="";return Object.entries(e).forEach(([t,l])=>{(typeof l=="string"||typeof l=="number")&&(r+=`${s}${E(t)}: ${l};
|
|
25
|
+
`)}),r}getAllStyles(){let e="";return this.styles.forEach(s=>{s.keyframes&&(e+=`${s.keyframes}
|
|
26
|
+
`),s.css&&(e+=`${s.css}
|
|
27
|
+
`),Object.values(s.pseudoClasses).forEach(t=>{e+=`${t}
|
|
28
|
+
`}),Object.values(s.layers).forEach(t=>{e+=`${t}
|
|
29
|
+
`}),Object.values(s.supports).forEach(t=>{e+=`${t}
|
|
30
|
+
`}),Object.entries(s.mediaQueries).sort(([t],[l])=>this.extractMinWidth(t)-this.extractMinWidth(l)).forEach(([,t])=>{e+=`${t}
|
|
31
|
+
`})}),e}extractMinWidth(e){let s=e.match(/min-width:\s*(\d+)px/);return s?parseInt(s[1],10):0}flush(e){if(!(typeof window<"u"))try{let s=b("fs"),r=b("path"),t=e??n.defaultCacheFile();s.mkdirSync(r.dirname(t),{recursive:!0}),s.writeFileSync(t,this.getAllStyles(),"utf-8")}catch(s){console.error("[next-style] Failed to flush styles to cache file:",s)}}static defaultCacheFile(){return b("path").join(process.cwd(),"node_modules",".cache","next-style","styles.css")}getStyleMap(){return new Map(this.styles)}};function W(n){let e=S.addStyle(n);return typeof window>"u"&&S.flush(),e}function M(n){Object.entries(n).forEach(([e,s])=>{S.addGlobalStyle(e,s)}),typeof window>"u"&&S.flush()}var S=new u;export{W as css,M as global};
|