next-style 2.0.8 → 2.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/dist/index.cjs +15 -15
- package/dist/index.js +15 -15
- package/dist/postcss-plugin/index.cjs +1 -1
- package/dist/postcss-plugin/index.js +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
${r}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:t,pseudoClasses:n,normalStyles:r,keyframes:l,supports:h,container:S,layer:u}=this.parseStyles(e),o=`ns-${m(e)}`,P=this.buildDeclarations(r),
|
|
3
|
-
${P}}`,
|
|
1
|
+
"use strict";var k=Object.create;var $=Object.defineProperty;var F=Object.getOwnPropertyDescriptor;var G=Object.getOwnPropertyNames;var J=Object.getPrototypeOf,L=Object.prototype.hasOwnProperty;var _=(s,e)=>{for(var t in e)$(s,t,{get:e[t],enumerable:!0})},N=(s,e,t,n)=>{if(e&&typeof e=="object"||typeof e=="function")for(let r of G(e))!L.call(s,r)&&r!==t&&$(s,r,{get:()=>e[r],enumerable:!(n=F(e,r))||n.enumerable});return s};var Q=(s,e,t)=>(t=s!=null?k(J(s)):{},N(e||!s||!s.__esModule?$(t,"default",{value:s,enumerable:!0}):t,s)),Z=s=>N($({},"__esModule",{value:!0}),s);var v={};_(v,{BREAKPOINTS:()=>f,StyleCollector:()=>p,camelToKebab:()=>R,createTransformer:()=>K,css:()=>z,deduplicateStyles:()=>T,generateClassHash:()=>m,global:()=>I,normalizeMediaQuery:()=>x,styleCollector:()=>g,validateCSSProperty:()=>W});module.exports=Z(v);var j=Q(require("fs"),1),E=Q(require("path"),1);function R(s){return s.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function m(s){let e=typeof s=="string"?s:JSON.stringify(s),t=0;for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);t=(t<<5)-t+r,t=t&t}return Math.abs(t).toString(36)}var f={"@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 x(s){return f[s]??s}function W(s,e){return typeof e=="string"||typeof e=="number"||typeof e=="object"&&!Array.isArray(e)}function T(s){let e=new Map,t=new Set;return s.forEach((n,r)=>{let l=JSON.stringify(n);t.has(l)||(t.add(l),e.set(r,n))}),e}var p=class{constructor(){this.styles=new Map}addStyle(e){let n=`ns-${m(e)}`;if(this.styles.has(n))return n;let r=this.compileStyle(e);return this.styles.set(n,r),n}addGlobalStyle(e,t){let n=`global:${e}`;if(this.styles.has(n))return;let r=this.buildDeclarations(t);r&&this.styles.set(n,{className:n,css:`${e} {
|
|
2
|
+
${r}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:t,pseudoClasses:n,normalStyles:r,keyframes:l,supports:h,container:S,layer:u}=this.parseStyles(e),o=`ns-${m(e)}`,P=this.buildDeclarations(r),B=`.${o} {
|
|
3
|
+
${P}}`,y={};Object.entries(t).forEach(([c,d])=>{let a=x(c),C=this.buildDeclarations(d," ");if(y[a]){let H=y[a].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);
|
|
5
|
+
`);y[a]=`${a} {
|
|
6
6
|
.${o} {
|
|
7
|
-
${
|
|
7
|
+
${H}
|
|
8
8
|
${C} }
|
|
9
|
-
}`}else
|
|
9
|
+
}`}else y[a]=`${a} {
|
|
10
10
|
.${o} {
|
|
11
11
|
${C} }
|
|
12
|
-
}`}),Object.entries(S).forEach(([c,
|
|
12
|
+
}`}),Object.entries(S).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");y[c]=`${c} {
|
|
13
13
|
.${o} {
|
|
14
14
|
${a} }
|
|
15
|
-
}`});let
|
|
16
|
-
${a}}`});let b="";Object.entries(l).forEach(([c,
|
|
17
|
-
`,Object.entries(
|
|
18
|
-
${
|
|
15
|
+
}`});let w={};Object.entries(n).forEach(([c,d])=>{let a=this.buildDeclarations(d);w[c]=`.${o}${c} {
|
|
16
|
+
${a}}`});let b="";Object.entries(l).forEach(([c,d])=>{b+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(d).forEach(([a,C])=>{let D=this.buildDeclarations(C," ");b+=` ${a} {
|
|
18
|
+
${D} }
|
|
19
19
|
`}),b+=`}
|
|
20
|
-
`});let M={};Object.entries(h).forEach(([c,
|
|
20
|
+
`});let M={};Object.entries(h).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");M[c]=`@supports ${c} {
|
|
21
21
|
.${o} {
|
|
22
22
|
${a} }
|
|
23
|
-
}`});let
|
|
24
|
-
${a}}`}),{className:o,css:
|
|
23
|
+
}`});let A={};return Object.entries(u).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");A[c]=`@layer ${c} {
|
|
24
|
+
${a}}`}),{className:o,css:B,mediaQueries:y,pseudoClasses:w,keyframes:b,supports:M,layers:A}}parseStyles(e){let t={},n={},r={},l={},h={},S={},u={};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 P=i.slice(0,9)==="@supports"?i.slice(9).trim():i;h[P]=o}else i.startsWith("@container")?S[i]=o:i.startsWith("@layer")?u[i.slice(7)||"default"]=o:i in f||i.startsWith("@media")?n[i]=o:i.startsWith(":")||i.startsWith("::")?r[i]=o:t[i]=o}),{normalStyles:t,mediaQueries:n,pseudoClasses:r,keyframes:l,supports:h,container:S,layer:u}}buildDeclarations(e,t=" "){let n="";return Object.entries(e).forEach(([r,l])=>{(typeof l=="string"||typeof l=="number")&&(n+=`${t}${R(r)}: ${l};
|
|
25
25
|
`)}),n}getAllStyles(){let e="";return this.styles.forEach(t=>{t.keyframes&&(e+=`${t.keyframes}
|
|
26
26
|
`),t.css&&(e+=`${t.css}
|
|
27
27
|
`),Object.values(t.pseudoClasses).forEach(r=>{e+=`${r}
|
|
28
28
|
`}),Object.values(t.layers).forEach(r=>{e+=`${r}
|
|
29
29
|
`}),Object.values(t.supports).forEach(r=>{e+=`${r}
|
|
30
30
|
`}),Object.entries(t.mediaQueries).sort(([r],[l])=>this.extractMinWidth(r)-this.extractMinWidth(l)).forEach(([,r])=>{e+=`${r}
|
|
31
|
-
`})}),e}extractMinWidth(e){let t=e.match(/min-width:\s*(\d+)px/);return t?parseInt(t[1],10):0}flush(e){try{let t=e??
|
|
31
|
+
`})}),e}extractMinWidth(e){let t=e.match(/min-width:\s*(\d+)px/);return t?parseInt(t[1],10):0}flush(e){try{let t=e??E.default.join(process.cwd(),"node_modules",".cache","next-style","styles.css");j.default.mkdirSync(E.default.dirname(t),{recursive:!0}),j.default.writeFileSync(t,this.getAllStyles(),"utf-8")}catch(t){console.error("Failed to flush styles to cache file:",t)}}getStyleMap(){return new Map(this.styles)}};function K(){let s=new p;return{collector:s,transformCssCall(e){return s.addStyle(e)}}}function z(s){let e=g.addStyle(s);return g.flush(),e}function I(s){Object.entries(s).forEach(([e,t])=>{g.addGlobalStyle(e,t)}),g.flush()}var g=new p;0&&(module.exports={BREAKPOINTS,StyleCollector,camelToKebab,createTransformer,css,deduplicateStyles,generateClassHash,global,normalizeMediaQuery,styleCollector,validateCSSProperty});
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
1
|
-
import
|
|
2
|
-
${s}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:t,pseudoClasses:r,normalStyles:s,keyframes:l,supports:m,container:f,layer:h}=this.parseStyles(e),o=`ns-${b(e)}`,$=this.buildDeclarations(s),
|
|
3
|
-
${$}}`,
|
|
1
|
+
import A from"fs";import D from"path";function P(n){return n.replace(/[A-Z]/g,e=>`-${e.toLowerCase()}`)}function b(n){let e=typeof n=="string"?n:JSON.stringify(n),t=0;for(let r=0;r<e.length;r++){let s=e.charCodeAt(r);t=(t<<5)-t+s,t=t&t}return Math.abs(t).toString(36)}var C={"@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(n){return C[n]??n}function W(n,e){return typeof e=="string"||typeof e=="number"||typeof e=="object"&&!Array.isArray(e)}function T(n){let e=new Map,t=new Set;return n.forEach((r,s)=>{let l=JSON.stringify(r);t.has(l)||(t.add(l),e.set(s,r))}),e}var y=class{constructor(){this.styles=new Map}addStyle(e){let r=`ns-${b(e)}`;if(this.styles.has(r))return r;let s=this.compileStyle(e);return this.styles.set(r,s),r}addGlobalStyle(e,t){let r=`global:${e}`;if(this.styles.has(r))return;let s=this.buildDeclarations(t);s&&this.styles.set(r,{className:r,css:`${e} {
|
|
2
|
+
${s}}`,mediaQueries:{},pseudoClasses:{},keyframes:"",supports:{},layers:{}})}compileStyle(e){let{mediaQueries:t,pseudoClasses:r,normalStyles:s,keyframes:l,supports:m,container:f,layer:h}=this.parseStyles(e),o=`ns-${b(e)}`,$=this.buildDeclarations(s),N=`.${o} {
|
|
3
|
+
${$}}`,p={};Object.entries(t).forEach(([c,d])=>{let a=O(c),u=this.buildDeclarations(d," ");if(p[a]){let Q=p[a].split(`
|
|
4
4
|
`).slice(2,-2).join(`
|
|
5
|
-
`);
|
|
5
|
+
`);p[a]=`${a} {
|
|
6
6
|
.${o} {
|
|
7
|
-
${
|
|
7
|
+
${Q}
|
|
8
8
|
${u} }
|
|
9
|
-
}`}else
|
|
9
|
+
}`}else p[a]=`${a} {
|
|
10
10
|
.${o} {
|
|
11
11
|
${u} }
|
|
12
|
-
}`}),Object.entries(f).forEach(([c,
|
|
12
|
+
}`}),Object.entries(f).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");p[c]=`${c} {
|
|
13
13
|
.${o} {
|
|
14
14
|
${a} }
|
|
15
|
-
}`});let j={};Object.entries(r).forEach(([c,
|
|
16
|
-
${a}}`});let S="";Object.entries(l).forEach(([c,
|
|
17
|
-
`,Object.entries(
|
|
18
|
-
${
|
|
15
|
+
}`});let j={};Object.entries(r).forEach(([c,d])=>{let a=this.buildDeclarations(d);j[c]=`.${o}${c} {
|
|
16
|
+
${a}}`});let S="";Object.entries(l).forEach(([c,d])=>{S+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(d).forEach(([a,u])=>{let M=this.buildDeclarations(u," ");S+=` ${a} {
|
|
18
|
+
${M} }
|
|
19
19
|
`}),S+=`}
|
|
20
|
-
`});let E={};Object.entries(m).forEach(([c,
|
|
20
|
+
`});let E={};Object.entries(m).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");E[c]=`@supports ${c} {
|
|
21
21
|
.${o} {
|
|
22
22
|
${a} }
|
|
23
|
-
}`});let
|
|
24
|
-
${a}}`}),{className:o,css:
|
|
23
|
+
}`});let w={};return Object.entries(h).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");w[c]=`@layer ${c} {
|
|
24
|
+
${a}}`}),{className:o,css:N,mediaQueries:p,pseudoClasses:j,keyframes:S,supports:E,layers:w}}parseStyles(e){let t={},r={},s={},l={},m={},f={},h={};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;m[$]=o}else i.startsWith("@container")?f[i]=o:i.startsWith("@layer")?h[i.slice(7)||"default"]=o:i in C||i.startsWith("@media")?r[i]=o:i.startsWith(":")||i.startsWith("::")?s[i]=o:t[i]=o}),{normalStyles:t,mediaQueries:r,pseudoClasses:s,keyframes:l,supports:m,container:f,layer:h}}buildDeclarations(e,t=" "){let r="";return Object.entries(e).forEach(([s,l])=>{(typeof l=="string"||typeof l=="number")&&(r+=`${t}${P(s)}: ${l};
|
|
25
25
|
`)}),r}getAllStyles(){let e="";return this.styles.forEach(t=>{t.keyframes&&(e+=`${t.keyframes}
|
|
26
26
|
`),t.css&&(e+=`${t.css}
|
|
27
27
|
`),Object.values(t.pseudoClasses).forEach(s=>{e+=`${s}
|
|
28
28
|
`}),Object.values(t.layers).forEach(s=>{e+=`${s}
|
|
29
29
|
`}),Object.values(t.supports).forEach(s=>{e+=`${s}
|
|
30
30
|
`}),Object.entries(t.mediaQueries).sort(([s],[l])=>this.extractMinWidth(s)-this.extractMinWidth(l)).forEach(([,s])=>{e+=`${s}
|
|
31
|
-
`})}),e}extractMinWidth(e){let t=e.match(/min-width:\s*(\d+)px/);return t?parseInt(t[1],10):0}flush(e){try{let t=e??
|
|
31
|
+
`})}),e}extractMinWidth(e){let t=e.match(/min-width:\s*(\d+)px/);return t?parseInt(t[1],10):0}flush(e){try{let t=e??D.join(process.cwd(),"node_modules",".cache","next-style","styles.css");A.mkdirSync(D.dirname(t),{recursive:!0}),A.writeFileSync(t,this.getAllStyles(),"utf-8")}catch(t){console.error("Failed to flush styles to cache file:",t)}}getStyleMap(){return new Map(this.styles)}};function K(){let n=new y;return{collector:n,transformCssCall(e){return n.addStyle(e)}}}function z(n){let e=g.addStyle(n);return g.flush(),e}function I(n){Object.entries(n).forEach(([e,t])=>{g.addGlobalStyle(e,t)}),g.flush()}var g=new y;export{C as BREAKPOINTS,y as StyleCollector,P as camelToKebab,K as createTransformer,z as css,T as deduplicateStyles,b as generateClassHash,I as global,O as normalizeMediaQuery,g as styleCollector,W as validateCSSProperty};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";var
|
|
1
|
+
"use strict";var x=Object.create;var i=Object.defineProperty;var h=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var E=Object.getPrototypeOf,P=Object.prototype.hasOwnProperty;var N=(e,t)=>{for(var s in t)i(e,s,{get:t[s],enumerable:!0})},d=(e,t,s,c)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of F(t))!P.call(e,n)&&n!==s&&i(e,n,{get:()=>t[n],enumerable:!(c=h(t,n))||c.enumerable});return e};var l=(e,t,s)=>(s=e!=null?x(E(e)):{},d(t||!e||!e.__esModule?i(s,"default",{value:e,enumerable:!0}):s,e)),O=e=>d(i({},"__esModule",{value:!0}),e);var _={};N(_,{CACHE_FILE:()=>y,default:()=>C,plugin:()=>S});module.exports=O(_);var m=l(require("fs"),1),g=l(require("path"),1),p=l(require("postcss"),1),w=/^next-style$/,y=g.default.join(process.cwd(),"node_modules",".cache","next-style","styles.css");function a(e={}){let t=e.cacheFile??y;return{postcssPlugin:"next-style",Once(c,{result:n}){n.messages.push({type:"dependency",plugin:"next-style",file:t,parent:n.opts.from??""});let r="";try{r=m.default.readFileSync(t,"utf-8")}catch(o){o.code==="ENOENT"||console.warn("[next-style] Failed to read cache file:",o)}let u=!1;c.walkAtRules("import",o=>{let f=o.params.replace(/['"]/g,"").trim();w.test(f)&&(r.trim()?o.replaceWith(p.default.parse(r)):o.remove(),u=!0)}),!u&&r.trim()&&c.prepend(p.default.parse(r))}}}a.postcss=!0;var C=a,S=a;0&&(module.exports={CACHE_FILE,plugin});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
import
|
|
1
|
+
import a from"fs";import u from"path";import l from"postcss";var f=/^next-style$/,d=u.join(process.cwd(),"node_modules",".cache","next-style","styles.css");function s(p={}){let n=p.cacheFile??d;return{postcssPlugin:"next-style",Once(o,{result:c}){c.messages.push({type:"dependency",plugin:"next-style",file:n,parent:c.opts.from??""});let t="";try{t=a.readFileSync(n,"utf-8")}catch(e){e.code==="ENOENT"||console.warn("[next-style] Failed to read cache file:",e)}let r=!1;o.walkAtRules("import",e=>{let i=e.params.replace(/['"]/g,"").trim();f.test(i)&&(t.trim()?e.replaceWith(l.parse(t)):e.remove(),r=!0)}),!r&&t.trim()&&o.prepend(l.parse(t))}}}s.postcss=!0;var E=s,P=s;export{d as CACHE_FILE,E as default,P as plugin};
|