next-style 2.1.0 → 2.1.2
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 +1 -24
- package/dist/index.d.ts +6 -0
- package/dist/index.js +9 -9
- package/dist/postcss-plugin/index.d.ts +8 -4
- package/dist/postcss-plugin/index.js +296 -1
- package/package.json +18 -9
- package/dist/index.cjs +0 -31
- package/dist/index.d.cts +0 -257
- package/dist/postcss-plugin/index.cjs +0 -1
- package/dist/postcss-plugin/index.d.cts +0 -19
package/README.md
CHANGED
|
@@ -367,29 +367,6 @@ On the very first build, no `css()` calls have been evaluated yet so the cache f
|
|
|
367
367
|
|
|
368
368
|
Ensure next-style is listed **first** in the plugins object — it must run before any other transformations.
|
|
369
369
|
|
|
370
|
-
## Contributing
|
|
371
|
-
|
|
372
|
-
```bash
|
|
373
|
-
bun install # install dependencies
|
|
374
|
-
bun run export # production build (note: script is "export", not "build")
|
|
375
|
-
bun run dev # watch mode
|
|
376
|
-
bun test # run tests
|
|
377
|
-
bun run lint # lint with Biome
|
|
378
|
-
bun run format # format with Biome
|
|
379
|
-
bunx tsc --noEmit # type-check only
|
|
380
|
-
```
|
|
381
|
-
|
|
382
|
-
**Project structure**
|
|
383
|
-
|
|
384
|
-
```
|
|
385
|
-
src/
|
|
386
|
-
├── index.ts # public exports
|
|
387
|
-
├── runtime/ # css() · global() · CSSObject type
|
|
388
|
-
├── postcss-plugin/ # @import "next-style" → compiled CSS
|
|
389
|
-
├── compiler/ # StyleCollector · createTransformer · CompiledStyle
|
|
390
|
-
└── utils/ # camelToKebab · generateClassHash · BREAKPOINTS · normalizeMediaQuery
|
|
391
|
-
```
|
|
392
|
-
|
|
393
370
|
## License
|
|
394
371
|
|
|
395
|
-
MIT © [
|
|
372
|
+
MIT © [Tiwz](https://github.com/TiwPhiraphan)
|
package/dist/index.d.ts
CHANGED
|
@@ -77,6 +77,12 @@ declare class StyleCollector {
|
|
|
77
77
|
* @param filePath - Destination file path. Defaults to `os.tmpdir()/next-style.css`.
|
|
78
78
|
*/
|
|
79
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;
|
|
80
86
|
/**
|
|
81
87
|
* Returns a snapshot of the internal style map.
|
|
82
88
|
* Intended for inspection and testing — not for direct mutation.
|
package/dist/index.js
CHANGED
|
@@ -1,31 +1,31 @@
|
|
|
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} {
|
|
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 n{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
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),
|
|
3
|
+
${$}}`,p={};Object.entries(t).forEach(([c,d])=>{let a=O(c),S=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
|
+
${S} }
|
|
9
9
|
}`}else p[a]=`${a} {
|
|
10
10
|
.${o} {
|
|
11
|
-
${
|
|
11
|
+
${S} }
|
|
12
12
|
}`}),Object.entries(f).forEach(([c,d])=>{let a=this.buildDeclarations(d," ");p[c]=`${c} {
|
|
13
13
|
.${o} {
|
|
14
14
|
${a} }
|
|
15
15
|
}`});let j={};Object.entries(r).forEach(([c,d])=>{let a=this.buildDeclarations(d);j[c]=`.${o}${c} {
|
|
16
|
-
${a}}`});let
|
|
17
|
-
`,Object.entries(d).forEach(([a,
|
|
16
|
+
${a}}`});let u="";Object.entries(l).forEach(([c,d])=>{u+=`@keyframes ${c} {
|
|
17
|
+
`,Object.entries(d).forEach(([a,S])=>{let M=this.buildDeclarations(S," ");u+=` ${a} {
|
|
18
18
|
${M} }
|
|
19
|
-
`}),
|
|
19
|
+
`}),u+=`}
|
|
20
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
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:
|
|
24
|
+
${a}}`}),{className:o,css:N,mediaQueries:p,pseudoClasses:j,keyframes:u,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??n.defaultCacheFile();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)}}static defaultCacheFile(){return D.join(process.cwd(),"node_modules",".cache","next-style","styles.css")}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 F(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,F as global,O as normalizeMediaQuery,g as styleCollector,W as validateCSSProperty};
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import postcss from 'postcss';
|
|
2
2
|
|
|
3
|
-
/**
|
|
4
|
-
|
|
3
|
+
/**
|
|
4
|
+
* Resolves the cache file path from the PostCSS `result.opts.from` field.
|
|
5
|
+
* Falls back to `process.cwd()` when `from` is absent (e.g. standalone runs).
|
|
6
|
+
*/
|
|
7
|
+
declare function resolveCacheFile(from: string | undefined): string;
|
|
5
8
|
interface PluginOptions {
|
|
6
9
|
/**
|
|
7
10
|
* Override the cache file path.
|
|
8
|
-
*
|
|
11
|
+
* When omitted, the path is derived from the CSS file being processed
|
|
12
|
+
* (`result.opts.from`) by walking up to the nearest `package.json`.
|
|
9
13
|
*/
|
|
10
14
|
cacheFile?: string;
|
|
11
15
|
}
|
|
@@ -16,4 +20,4 @@ declare namespace nextStylePlugin {
|
|
|
16
20
|
|
|
17
21
|
declare const plugin: typeof nextStylePlugin;
|
|
18
22
|
|
|
19
|
-
export {
|
|
23
|
+
export { nextStylePlugin as default, plugin, resolveCacheFile };
|