@cssxio/unplugin 0.5.1 → 0.8.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 +73 -17
- package/dist/chunk-BPBCQNZV.js +91 -0
- package/dist/chunk-GGFXMP4P.js +13 -0
- package/dist/chunk-T2L6RO3O.js +1 -0
- package/dist/esbuild.cjs +17 -7
- package/dist/esbuild.d.cts +1 -1
- package/dist/esbuild.d.ts +1 -1
- package/dist/esbuild.js +1 -1
- package/dist/index.cjs +17 -7
- package/dist/index.d.cts +10 -24
- package/dist/index.d.ts +10 -24
- package/dist/index.js +1 -1
- package/dist/next-loader.cjs +16 -0
- package/dist/next-loader.d.cts +33 -0
- package/dist/next-loader.d.ts +33 -0
- package/dist/next-loader.js +4 -0
- package/dist/next.cjs +1 -0
- package/dist/next.d.cts +39 -0
- package/dist/next.d.ts +39 -0
- package/dist/next.js +1 -0
- package/dist/options-DkqShf7w.d.cts +56 -0
- package/dist/options-DkqShf7w.d.ts +56 -0
- package/dist/rollup.cjs +16 -6
- package/dist/rollup.d.cts +3 -3
- package/dist/rollup.d.ts +3 -3
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +16 -6
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.js +1 -1
- package/dist/source-map-from-context-B4SX_KAW.d.cts +19 -0
- package/dist/source-map-from-context-B4SX_KAW.d.ts +19 -0
- package/dist/vite.cjs +16 -6
- package/dist/vite.d.cts +1 -1
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +1 -1
- package/dist/webpack.cjs +16 -6
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +15 -4
- package/dist/chunk-KCX3ORPX.js +0 -93
- package/dist/options-kIzRyZSc.d.cts +0 -29
- package/dist/options-kIzRyZSc.d.ts +0 -29
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,17 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";var Mt=Object.create;var K=Object.defineProperty;var vt=Object.getOwnPropertyDescriptor;var Ot=Object.getOwnPropertyNames;var kt=Object.getPrototypeOf,Pt=Object.prototype.hasOwnProperty;var At=(e,t)=>{for(var s in t)K(e,s,{get:t[s],enumerable:!0})},Ce=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Ot(t))!Pt.call(e,r)&&r!==s&&K(e,r,{get:()=>t[r],enumerable:!(o=vt(t,r))||o.enumerable});return e};var Rt=(e,t,s)=>(s=e!=null?Mt(kt(e)):{},Ce(t||!e||!e.__esModule?K(s,"default",{value:e,enumerable:!0}):s,e)),Et=e=>Ce(K({},"__esModule",{value:!0}),e);var Wt={};At(Wt,{compileCssxStylesheet:()=>w,default:()=>Nt,esbuild:()=>xe,rollup:()=>Ht,rspack:()=>_t,transformCssxModule:()=>b,unplugin:()=>W,unpluginFactory:()=>bt,vite:()=>Ut,webpack:()=>Xt});module.exports=Et(Wt);var St=require("@cssxio/compiler"),wt=require("unplugin");var Y=require("fs/promises"),Z=require("path");function he(e,t,s){let o=s.naming??(s.stableClassNames?"source":s.className?.variant==="random"?"hash":s.className?.variant??"serial"),r=s.stableClassNames?"stableClassNames compatibility option selects source-addressed composites":s.naming?"explicit naming option":s.className?.variant?"className.variant option":"default serial naming",i=new Map,m=new Map;for(let c of[...e].sort((d,l)=>d.id.localeCompare(l.id))){let d=new Map;for(let[l,u]of Object.entries(c.candidates)){let p=m.get(l)??new Set;p.add(u),m.set(l,p);let g=i.get(u)??{module:c.id,utilities:new Set,line:c.origins?.[l]?.line??0,column:c.origins?.[l]?.column??0};g.utilities.add(l),i.set(u,g);let f=d.get(u)??[];f.push(l),d.set(u,f)}for(let[l,u]of Object.entries(c.composites??{})){let p=u.flatMap(y=>d.get(y)??[]),g=p[0],f=i.get(l)??{module:c.id,utilities:new Set,line:g?c.origins?.[g]?.line??0:0,column:g?c.origins?.[g]?.column??0:0};for(let y of p)f.utilities.add(y);i.set(l,f)}for(let l of c.atomicClasses??[])i.has(l)||i.set(l,{module:c.id,utilities:new Set,line:0,column:0})}let n=[...i].sort(([c],[d])=>c.localeCompare(d)).map(([c,d])=>({className:c,module:d.module,utilities:[...d.utilities].sort(),line:d.line+1,column:d.column+1,selectorFound:new RegExp(`\\.${Tt(c)}(?:[^A-Za-z0-9_-]|$)`).test(t)})),a=[...m].filter(([,c])=>c.size>1).map(([c])=>c).sort();return{version:1,naming:{mode:o,reason:r},coordination:{mode:s.coordination??"memory",...s.coordination==="manifest"&&s.manifestPath?{manifestPath:s.manifestPath}:{}},classes:n,serverClientMappings:{status:a.length>0?"mismatch":s.coordination==="manifest"?"manifest-shared":"consistent-in-process",conflicts:a}}}function Tt(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function Se(e,t){let s=new Map,o=[];for(let r of t)r.id?s.set(r.id,r):o.push(r);for(let r of e)r.id?s.set(r.id,r):o.push(r);return[...s.values(),...o]}var j=require("path");function B(e){if(!e||(0,j.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let t=(0,j.normalize)(e);if(t===".."||t.startsWith(`..${j.sep}`))throw new Error("cssFileName must not escape the bundler output directory.");if(!t.endsWith(".css"))throw new Error("cssFileName must end in .css.");return t}function E(e){if(e.sourceRoots&&e.sourceRoots.some(s=>typeof s!="string"||!s.trim()))throw new Error("CSSX sourceRoots must contain non-empty file-system paths.");let t=e.debug;if(t===null||t!==void 0&&typeof t!="boolean"&&(typeof t!="object"||typeof t.reportFile!="string"||!t.reportFile))throw new Error("CSSX debug must be a boolean or an object with a reportFile path.");if(e.naming!==void 0&&!["serial","hash","source"].includes(e.naming))throw new Error('CSSX naming must be "serial", "hash", or "source".');if(e.coordination!==void 0&&!["memory","manifest"].includes(e.coordination))throw new Error('CSSX coordination must be "memory" or "manifest".');if(e.stableClassNames&&e.naming&&e.naming!=="source")throw new Error('CSSX stableClassNames selects source naming and conflicts with naming. Use naming: "source".');if(e.stableClassNames&&e.coordination==="manifest")throw new Error("CSSX stableClassNames already selects source naming; remove it to use manifest coordination.");if(e.naming==="hash"&&e.className?.variant==="serial")throw new Error('CSSX naming: "hash" conflicts with className.variant: "serial".');if(e.naming==="serial"&&e.className?.variant==="random")throw new Error('CSSX naming: "serial" conflicts with className.variant: "random".');if(e.coordination==="manifest"&&!e.manifestPath)throw new Error('CSSX coordination: "manifest" requires manifestPath.');if(e.manifestPath&&e.coordination!=="manifest")throw new Error('CSSX manifestPath requires coordination: "manifest".');if(e.coordination==="manifest"&&e.classNameAllocator)throw new Error("CSSX manifest coordination cannot use a custom classNameAllocator.");if(e.theme!==void 0&&e.themeFile!==void 0)throw new Error("CSSX accepts either theme or themeFile, not both.");if(e.layer!==void 0&&!/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e.layer))throw new Error("CSSX layer must be a valid CSS layer identifier.");if(e.sourceMap!==void 0&&typeof e.sourceMap!="boolean")throw new Error("CSSX sourceMap must be a boolean.");if(e.darkMode!==void 0&&e.darkMode!=="media"&&e.darkMode!=="selector"&&e.darkMode!=="class")throw new Error('CSSX darkMode must be "media", "selector", or "class".');if(e.preflight!==void 0&&typeof e.preflight!="boolean")throw new Error("CSSX preflight must be a boolean.");if(e.reusabilityBudget!==void 0&&e.reusabilityBudget!=="auto"&&(!Number.isFinite(e.reusabilityBudget)||e.reusabilityBudget<0||e.reusabilityBudget>100))throw new Error('CSSX reusabilityBudget must be "auto" or a number from 0 through 100.');B(e.cssFileName??"cssx.css")}var we=require("fs/promises"),be=require("path");async function T(e){return e.themeFile===void 0?e.theme:(0,we.readFile)((0,be.resolve)(process.cwd(),e.themeFile),"utf8")}function S(e){return e.split("?",1).join("")}function z(e){let t=2166136261;for(let s=0;s<e.length;s++)t^=e.charCodeAt(s),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function k(e,t){return B(e).replaceAll("[hash]",z(t))}var F=require("path");function q(e,t,s){return t.outdir?(0,F.resolve)(e,t.outdir,s):t.outfile?(0,F.resolve)((0,F.dirname)((0,F.resolve)(e,t.outfile)),s):(0,F.resolve)(e,s)}var Ne=require("path");function L(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${B(t).replaceAll(Ne.sep,"/")}`}function M(e){let t=e.naming==="hash"?"random":e.naming==="serial"?"serial":void 0;if(t&&e.className?.variant&&e.className.variant!==t)throw new Error(`CSSX naming: "${e.naming}" conflicts with className.variant: "${e.className.variant}".`);return{...e.className,...t?{variant:t}:{}}}function Me(e,t){let s=e.buildInfo?.[t];if(!s||typeof s!="object")return;let{id:o,candidates:r,composites:i,atomicClasses:m,origins:n}=s;return{id:typeof o=="string"?o:"",candidates:r&&typeof r=="object"?r:{},composites:i&&typeof i=="object"?i:{},...Array.isArray(m)?{atomicClasses:m}:{},origins:n&&typeof n=="object"?n:{}}}var Q=require("@cssxio/compiler");function me(e,t){let s=t.split(`
|
|
2
|
+
`);return{line:e.line+s.length-1,column:s.at(-1).length+e.column*+(s.length===1)}}var Ft="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function G(e){let t="",s=e<0?-e<<1|1:e<<1;do{let o=s&31;s>>>=5,s&&(o|=32),t+=Ft[o]}while(s);return t}function ve(e){let t=Array.from({length:Math.max(0,...e.map(n=>n.line))+1},()=>[]),s=0,o=0,r=0,i=0,m=0;for(let n of e)m*=+(n.line===i),i=n.line,t[n.line]?.push(`${G(n.column-m)}${G(n.source-s)}${G(n.originalLine-o)}${G(n.originalColumn-r)}`),m=n.column,s=n.source,o=n.originalLine,r=n.originalColumn;return t.map(n=>n.join(",")).join(";")}function Oe(e,t,s){let o=[...new Set(t.map(n=>s.get(n.candidate)?.id).filter(n=>!!n))].sort();if(o.length===0)return;let r=new Map(o.map((n,a)=>[n,a])),i=[],m=me({line:0,column:0},e);for(let n of t){let a=s.get(n.candidate);a&&i.push({...m,source:r.get(a.id),originalLine:a.line,originalColumn:a.column}),m=me(m,n.css)}return{version:3,sources:o,names:[],mappings:ve(i)}}var ke='*,::before,::after,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-text-size-adjust:100%;tab-size:4;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea,::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;border-radius:0;background-color:transparent;opacity:1}button,select{text-transform:none}button,input:where([type="button"],[type="reset"],[type="submit"]),::file-selector-button{appearance:button}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit}textarea{resize:vertical}::placeholder{opacity:1}button,[role="button"]{cursor:pointer}:disabled{cursor:default}[hidden]:where(:not([hidden="until-found"])){display:none!important}';async function w(e,t,s,o=!0,r,i=!0){let m=Object.create(null),n=Object.create(null),a=new Set,c=!0,d=new Map;for(let x of[...e].sort((h,A)=>h.id.localeCompare(A.id))){for(let[h,A]of Object.entries(x.candidates))if(h in m||(m[h]=A),x.id&&!d.has(h)){let J=x.origins?.[h];d.set(h,{id:x.id,line:J?.line??0,column:J?.column??0})}for(let[h,A]of Object.entries(x.composites??{})){let J=n[h];if(J&&J.join(" ")!==A.join(" "))throw new Error(`CSSX composite class collision for "${h}".`);n[h]=A}x.atomicClasses===void 0&&(c=!1);for(let h of x.atomicClasses??[])a.add(h)}let l=Object.keys(m).sort(),u=i?ke:"";if(l.length===0)return{css:u&&s?`@layer ${s}{${u}}`:u};let p=await(0,Q.compileUtilities)(l,x=>m[x],t,(0,Q.createSelectorAliases)(n),c?a:void 0,{darkMode:r}),g=s?`@layer ${s}{`:"",f=`${g}${u}${p.css}${g?"}":""}`,y=o?Oe(`${g}${u}${p.prefixCss}`,p.entries,d):void 0;return{css:f,...y?{map:y}:{}}}function $(e,t){return JSON.stringify({...e,file:t})}var Pe=require("path");function P(e,t){return e.map?`${e.css}
|
|
3
|
+
/*# sourceMappingURL=${(0,Pe.basename)(t)}.map */`:e.css}function Ae(e,t,s,o,r,i,m,n,a=!0,c,d){let l=e.name??e.options?.name;l==="server"||l==="edge-server"||e.hooks.thisCompilation.tap("@cssxio/unplugin",u=>{u.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let p=c?await c():Se([...u.modules].map(y=>Me(y,i)).filter(y=>y!==void 0),m?.values()??[]),g=await w(p,await s(),o,r,n,a);if(d?.debug){let y=he(p,g.css,d);if(d.debug===!0)console.info(`CSSX: ${y.naming.mode} naming; ${y.classes.filter(x=>x.selectorFound).length}/${y.classes.length} generated classes have selectors; compiler mappings ${y.serverClientMappings.status}${y.serverClientMappings.conflicts.length?` (${y.serverClientMappings.conflicts.length} utility conflicts)`:""}.`);else{let x=(0,Z.resolve)(e.context,d.debug.reportFile);await(0,Y.mkdir)((0,Z.dirname)(x),{recursive:!0}),await(0,Y.writeFile)(x,`${JSON.stringify(y,null,2)}
|
|
4
|
+
`,"utf8")}}if(!g.css)return;let f=k(t,g.css);if(u.getAsset?.(f))throw new Error(`CSSX CSS asset collision at "${f}".`);if(u.emitAsset(f,new e.webpack.sources.RawSource(P(g,f))),g.map){let y=`${f}.map`;if(u.getAsset?.(y))throw new Error(`CSSX CSS map asset collision at "${y}".`);u.emitAsset(y,new e.webpack.sources.RawSource($(g.map,f)))}})})}var D="@cssxio/unplugin/rules";function ee(){return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}}var Te=require("@cssxio/compiler");function Re(e,t){return`${e}\0${JSON.stringify(t)}`}var Ee=new Map;function te(e,t){let s=Re(e,t),o=Ee.get(s);return o||(o={classNameAllocator:t.classNameAllocator??(0,Te.createClassNameAllocator)(M(t)),transformedDataById:new Map},Ee.set(s,o)),o}var tt=require("@cssxio/compiler"),st=require("fs/promises"),H=require("path");var Fe=require("fs/promises"),se=require("path"),$t=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro",".mdx",".md"]),Dt=new Set([".git",".next",".turbo","node_modules"]);async function $e(e,t=[]){let s=[],o=[e,...t],r=new Set;for(;o.length>0;){let i=o.pop(),m=(0,se.resolve)(i);if(!r.has(m)){r.add(m);for(let n of await(0,Fe.readdir)(i,{withFileTypes:!0})){let a=(0,se.join)(i,n.name);if(n.isDirectory()){Dt.has(n.name)||o.push(a);continue}n.isFile()&&$t.has(a.slice(a.lastIndexOf(".")))&&s.push(a)}}}return s.sort()}var De=require("module"),Ie=require("path"),de=require("url");async function je(e,t,s={}){let o=(0,De.createRequire)((0,Ie.resolve)(t,"package.json")),r;try{r=o.resolve("@mdx-js/mdx")}catch{throw new Error("CSSX Next MDX support requires @mdx-js/mdx to be installed in the Next.js project.")}let i=await import((0,de.pathToFileURL)(r).href),m=async n=>Promise.all((n??[]).map(async a=>{let[c,d]=typeof a=="string"?[a,void 0]:a,l=o.resolve(c),u=await import((0,de.pathToFileURL)(l).href),p=u.default??u;return d===void 0?p:[p,d]}));return String(await i.compile(e,{outputFormat:"program",development:s.development??!1,remarkPlugins:await m(s.remarkPlugins),rehypePlugins:await m(s.rehypePlugins),recmaPlugins:await m(s.recmaPlugins)}))}var Be=require("@cssxio/compiler");function re(e){let t=[],s=/\bsx\s*\(/g;for(let o of e.matchAll(s)){let r=o.index,i=e.indexOf("(",r),m=0,n="";for(let a=i;a<e.length;a+=1){let c=e[a];if(n){c==="\\"?a+=1:c===n&&(n="");continue}if(c==='"'||c==="'"||c==="`")n=c;else if(c==="(")m+=1;else if(c===")"&&--m===0){t.push({start:r,end:a+1,code:e.slice(r,a+1)}),s.lastIndex=a+1;break}}}return t}function V(e,t){return{code:e,rules:t.flatMap(s=>s.rules),candidates:Object.assign({},...t.map(s=>s.candidates)),composites:Object.assign({},...t.map(s=>s.composites)),atomicClasses:[...new Set(t.flatMap(s=>s.atomicClasses))],origins:Object.assign({},...t.map(s=>s.origins)),cssOnlySignature:e}}function oe(e){let t="const style = ",s=e.indexOf(t)+t.length,o=e.indexOf(";",s);return e.slice(s,o)}async function Le(e,t,s,o){let r=re(e);if(r.length===0)return null;let i=s.classNameAllocator??(0,Be.createClassNameAllocator)(),m=s.importSource??"@cssxio/cssx",n=[],a=e;for(let c of[...r].reverse()){let d=await o(`import { sx } from ${JSON.stringify(m)};
|
|
5
|
+
const style = ${c.code};`,`${t}.ts`,{...s,classNameAllocator:i}),l=oe(d.code);a=`${a.slice(0,c.start)}${l}${a.slice(c.end)}`,n.push({...d,atomicClasses:[],origins:{}})}return V(a,n)}var He=require("@babel/core"),Xe=Rt(require("@cssxio/babel-plugin"),1),ne=require("@cssxio/compiler");function Ve(e){return{className:`cssx-${z(e)}`,css:e}}function Ue(e,t){return e&&t?`@layer ${t}{${e}}`:e}async function _e(e,t,s,o){let r=s.importSource??"@cssxio/cssx",i=await T(s),m=await(0,He.transformAsync)(e,{babelrc:!1,configFile:!1,filename:t,parserOpts:{plugins:["jsx","typescript"]},plugins:[[Xe.default,{importSource:r,classNameAllocator:s.classNameAllocator,theme:i,reusabilityBudget:s.reusabilityBudget,stableClassNames:s.stableClassNames,stableClassNameFileName:s.stableClassNameFileName,darkMode:s.darkMode}]],sourceMaps:!0,...o?{inputSourceMap:o}:{}}),n=m.metadata,{candidates:a,origins:c,composites:d,atomicClasses:l,cssOnlySignature:u}=n.cssx,p=Object.keys(a),g=p.length===0?"":(await(0,ne.compileUtilities)(p,f=>a[f],i,(0,ne.createSelectorAliases)(d),new Set(l),{darkMode:s.darkMode})).css;return{code:m.code,rules:g?[Ve(Ue(g,s.layer))]:[],candidates:a,composites:d,atomicClasses:l,origins:c,cssOnlySignature:u,map:m.map}}var Ke=require("@cssxio/compiler"),Qe=require("@vue/compiler-sfc");function ie(e,t){let s=e.split(`
|
|
6
|
+
`).slice(0,t.line).reduce((o,r)=>o+r.length+1,0);return Math.min(e.length,s+t.column)}function ae(e,t){let s=Math.min(e.length,t),o=e.slice(0,s).split(`
|
|
7
|
+
`).length-1,r=e.lastIndexOf(`
|
|
8
|
+
`,s-1)+1;return{line:o,column:s-r}}function ue(e,t,s){let o={},r=e.slice(t);for(let[i,m]of Object.entries(s))o[i]=ae(e,t+ie(r,m));return o}function We(e){return e.slice(1,-1).replace(/\\(['"\\bnfrtv])/g,(t,s)=>({b:"\b",n:`
|
|
9
|
+
`,f:"\f",r:"\r",t:" ",v:"\v"})[s]??s)}function Je(e,t){if(!t)return e;let s=t==='"'?"'":'"';return e.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,o=>{let r=o[0]==='"'?JSON.parse(o):We(o),i=JSON.stringify(r);return s==='"'?i:`'${i.slice(1,-1).replaceAll("'","\\'")}'`})}function ze(e,t,s,o,r){let i={};for(let[m,n]of Object.entries(r)){let a=ie(s,n);i[m]=ae(e,t+Math.max(0,a-o))}return i}function qe(e,t){let s=-1,o;for(let r=0;r<t;r++){let i=e[r];if(o){i===o&&(o=void 0);continue}if(i==="<"&&/[A-Za-z]/.test(e[r+1])){s=r;continue}s!==-1&&(i===">"?s=-1:(i==='"'||i==="'")&&(o=i))}return o}async function Ge(e,t,s,o,r){let i=re(e);if(i.length===0)return null;let m=s.importSource??"@cssxio/cssx",n=[],a=e;for(let c of[...i].reverse()){let d=`import { sx } from ${JSON.stringify(m)};
|
|
10
|
+
const style = `,l=`${d}${c.code};`,u=await r(l,`${t}.cssx-vue-template.ts`,{...s,classNameAllocator:o}),p=Je(oe(u.code),qe(e,c.start));a=`${a.slice(0,c.start)}${p}${a.slice(c.end)}`,n.push({...u,origins:ze(e,c.start,l,d.length,u.origins)})}return V(a,n)}async function Ye(e,t,s,o){let r=t.split("?",1).join(""),i=(0,Qe.parse)(e,{filename:r});if(i.errors.length>0)throw new Error(i.errors[0].message);let m=s.classNameAllocator??(0,Ke.createClassNameAllocator)(),n=[],a=[];for(let l of[i.descriptor.script,i.descriptor.scriptSetup]){if(!l?.content.includes(s.importSource??"@cssxio/cssx"))continue;let u=l.lang==="js"||l.lang==="jsx"||l.lang==="tsx"?l.lang:"ts",p=await o(l.content,`${r}.cssx-vue-script.${u}`,{...s,classNameAllocator:m});n.push({start:l.loc.start.offset,end:l.loc.end.offset,code:p.code}),a.push({...p,origins:ue(e,l.loc.start.offset,p.origins)})}let c=i.descriptor.template;if(c?.content.includes("sx")){let l=await Ge(c.content,r,s,m,o);l&&(n.push({start:c.loc.start.offset,end:c.loc.end.offset,code:l.code}),a.push({...l,origins:ue(e,c.loc.start.offset,l.origins)}))}if(n.length===0)return null;let d=e;for(let l of n.sort((u,p)=>p.start-u.start))d=`${d.slice(0,l.start)}${l.code}${d.slice(l.end)}`;return V(d,a)}var It=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro",".vue"]);async function b(e,t,s={},o){E(s);let r=s.importSource??"@cssxio/cssx",i=t.split("?",1).join("");return!It.has(i.slice(i.lastIndexOf(".")))||!e.includes(r)?null:i.endsWith(".astro")?Le(e,t,s,b):i.endsWith(".vue")?Ye(e,t,s,b):_e(e,i,s,o)}function pe(e,t){if(!e||typeof e!="object")return;let s=e.getCombinedSourcemap;if(typeof s!="function")return;let o=s.call(e);if(!o||typeof o!="object")return;let r=o;if(!(r.version!==3||!Array.isArray(r.sources)||typeof r.mappings!="string"))return{version:r.version,sources:[...r.sources],names:[...r.names??[]],mappings:r.mappings,file:r.file??t.split("?",1).join(""),...r.sourceRoot?{sourceRoot:r.sourceRoot}:{},...r.sourcesContent?{sourcesContent:[...r.sourcesContent]}:{}}}var R=require("@cssxio/compiler"),C=require("fs/promises"),le=require("path"),Ze=20,et=5*6e4;async function U(e,t,s){let o=(0,le.resolve)(e),r=`${o}.lock`,i=Date.now(),m,n=0;for(;!m;){await(0,C.mkdir)((0,le.dirname)(o),{recursive:!0});let a;try{a=await(0,C.open)(r,"wx")}catch(c){let d=c.code;if(d!=="EEXIST"){if(d!=="EACCES"&&d!=="EPERM")throw c;try{await(0,C.stat)(r)}catch(l){if(l.code==="ENOENT"){if(n+=1,n>1)throw c;await new Promise(u=>setTimeout(u,Ze));continue}throw l}}if(n=0,await jt(r))continue;if(Date.now()-i>=et)throw new Error(`Timed out waiting for CSSX class-name manifest lock: ${r}`);await new Promise(l=>setTimeout(l,Ze));continue}try{await a.writeFile(`${process.pid}
|
|
11
|
+
${Date.now()}
|
|
12
|
+
`)}catch(c){throw await a.close().catch(()=>{}),await(0,C.rm)(r,{force:!0}).catch(()=>{}),c}m=a}try{let a=await Bt(o,t),c=await s(a),d=(0,R.snapshotClassNameAllocator)(a),l=`${o}.${process.pid}.${Date.now()}.tmp`;try{await(0,C.writeFile)(l,`${JSON.stringify(d,null,2)}
|
|
13
|
+
`,"utf8"),await(0,C.rename)(l,o)}catch(u){throw await(0,C.rm)(l,{force:!0}).catch(()=>{}),u}return c}finally{await m.close(),await(0,C.rm)(r,{force:!0})}}async function jt(e){try{let t=await(0,C.stat)(e),s;try{s=await(0,C.readFile)(e,"utf8")}catch(i){let m=i.code;if(m==="EACCES"||m==="EPERM")return!1;throw i}let[o]=s.split(`
|
|
14
|
+
`),r=Number(o);if(Number.isSafeInteger(r)&&r>0)try{return process.kill(r,0),!1}catch(i){return i.code!=="ESRCH"?!1:(await(0,C.rm)(e,{force:!0}),!0)}return Date.now()-t.mtimeMs<et?!1:(await(0,C.rm)(e,{force:!0}),!0)}catch(t){if(t.code==="ENOENT")return!1;throw t}}async function Bt(e,t){try{let s=JSON.parse(await(0,C.readFile)(e,"utf8")),o=(0,R.snapshotClassNameAllocator)((0,R.createClassNameAllocator)(t)).options;if(JSON.stringify(s.options)!==JSON.stringify(o))throw new Error("CSSX class-name manifest options do not match the active compiler options.");return(0,R.restoreClassNameAllocator)(s)}catch(s){if(s.code==="ENOENT")return(0,R.createClassNameAllocator)(t);throw s}}async function v(e,t){let s=await $e(e,t.sourceRoots?.map(i=>(0,H.resolve)(e,i))),o={...t};delete o.coordination,delete o.manifestPath,delete o.classNameAllocator;let r=async i=>{let m=[];for(let n of s){let a=await(0,st.readFile)(n,"utf8"),c=/\.(?:md|mdx)$/i.test(n);if(c&&!a.includes(t.importSource??"@cssxio/cssx"))continue;let d=c?await je(a,e,t.mdx):a,l=t.stableClassNames||t.naming==="source",u=await b(d,c?`${n}.tsx`:n,{...o,classNameAllocator:i,stableClassNames:l,...l?{stableClassNameFileName:(0,H.relative)(e,n).replaceAll(H.sep,"/")}:{}});u&&m.push({id:n,candidates:u.candidates,composites:u.composites,atomicClasses:u.atomicClasses,origins:u.origins})}return m};return t.coordination==="manifest"?U(t.manifestPath,M(t),r):r(t.classNameAllocator??(0,tt.createClassNameAllocator)(M(t)))}function fe({compiler:e,options:t,cssFileName:s,sourceMap:o,getTheme:r}){let i=te(e.context,t);Ae(e,s,r,t.layer,o,D,i.transformedDataById,t.darkMode,t.preflight,t.stableClassNames||t.naming==="source"||t.coordination==="manifest"?()=>v(e.context,t):void 0,t)}function ce(e,t,s=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:s}]})}function rt(e,t){let{cssFileName:s,sourceMap:o,options:r,rollupDataById:i,getTheme:m}=t,n=L(e.config.base,s),a=L("/",s);e.watcher?.on("unlink",c=>{i.delete(S(c)),ce(e,a)}),e.middlewares.use((c,d,l)=>{let u=c.url?.split("?",1)[0];if(u!==n&&(u!==`${n}.map`||!o))return l();m().then(async p=>{let g=r.coordination==="manifest"?await v(e.config.root??process.cwd(),r):[...i.values()];return w(g,p,r.layer,o,r.darkMode,r.preflight)}).then(p=>{if(u===`${n}.map`){d.setHeader("Content-Type","application/json; charset=utf-8"),d.setHeader("Cache-Control","no-store"),d.end(p.map?$(p.map,s):"");return}d.setHeader("Content-Type","text/css; charset=utf-8"),d.setHeader("Cache-Control","no-store"),d.end(P(p,s))}).catch(p=>{d.setHeader("Content-Type","text/plain; charset=utf-8"),d.end(p instanceof Error?p.message:"Unable to compile CSSX development stylesheet.")})})}function ot(e){if(!e||typeof e!="object")return ee();let{id:t,rules:s,candidates:o,composites:r,atomicClasses:i,origins:m,cssOnlySignature:n}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(s)?s:[],candidates:o&&typeof o=="object"?o:{},composites:r&&typeof r=="object"?r:{},...Array.isArray(i)?{atomicClasses:i}:{},origins:m&&typeof m=="object"?m:{},cssOnlySignature:typeof n=="string"?n:""}}function nt(e){return!e||typeof e!="object"?ee():ot(e[D])}function it(e){return async function(t,s){let{framework:o,options:r,cssFileName:i,sourceMap:m,rollupDataById:n,getTheme:a}=e,c=new Set(Object.values(s).flatMap(p=>p.type==="chunk"?Object.keys(p.modules??{}):[]).map(S));if(o!=="vite")for(let p of n.keys())c.has(p)||n.delete(p);let d=r.coordination==="manifest"?await v(process.cwd(),r):o==="vite"?[...n.values()]:[...c].map(p=>{let g=nt(this.getModuleInfo(p)?.meta);return Object.keys(g.candidates).length>0?g:n.get(p)??g}),l=await w(d,await a(),r.layer,m,r.darkMode,r.preflight);if(!l.css)return;let u=k(i,l.css);if(Object.hasOwn(s,u))throw new Error(`CSSX CSS asset collision at "${u}".`);if(this.emitFile({type:"asset",fileName:u,source:P(l,u)}),l.map){let p=`${u}.map`;if(Object.hasOwn(s,p))throw new Error(`CSSX CSS map asset collision at "${p}".`);this.emitFile({type:"asset",fileName:p,source:$(l.map,u)})}}}var I=require("path");function at(e){let t=e.getNativeBuildContext?.();return t&&(t.framework==="webpack"||t.framework==="rspack")?t.loaderContext?.rootContext??process.cwd():void 0}function lt(e){return`if (typeof document !== "undefined" && typeof module !== "undefined" && module.hot) {
|
|
7
15
|
const key = "__cssxStylesheetHmr";
|
|
8
16
|
const state = globalThis[key] || (globalThis[key] = { revision: 0, staged: [], replacements: [] });
|
|
9
17
|
const stylesheetLink = [...document.querySelectorAll('link[rel="stylesheet"]')].find((link) =>
|
|
@@ -90,4 +98,6 @@ ${Ge(s)}`:h,meta:{[L]:c},...p?.map?{map:p.map}:{}}}},watchChange(l,i){i.event===
|
|
|
90
98
|
state.poll = setInterval(() => void refresh(), 500);
|
|
91
99
|
}
|
|
92
100
|
}
|
|
93
|
-
}`}
|
|
101
|
+
}`}function ct(e,t,s){let o=e.getNativeBuildContext?.();if(!o||o.framework!=="webpack"&&o.framework!=="rspack")return;let r=o.loaderContext?._module;if(!r)return;let i=r.buildInfo??(r.buildInfo={});i[s]=t}function mt(e){return async function(t,s){let{framework:o,options:r,classNameAllocator:i,rollupDataById:m,esbuildDataById:n,cssFileName:a,getEsbuildWorkingDirectory:c,notifyViteStyles:d}=e;r.themeFile&&this.addWatchFile?.((0,I.resolve)(r.themeFile));let l=at(this),u=l?te(l,r):void 0,p={...r,className:{...r.className,...r.naming==="hash"?{variant:"random"}:{},...r.naming==="serial"?{variant:"serial"}:{}},stableClassNames:r.stableClassNames||r.naming==="source",classNameAllocator:u?.classNameAllocator??i,...r.stableClassNames||r.naming==="source"?{stableClassNameFileName:(0,I.relative)(l??process.cwd(),S(s)).replaceAll(I.sep,"/")}:{}},g={...p};delete g.coordination,delete g.manifestPath;let f=r.coordination==="manifest"?await U(r.manifestPath,g.className,A=>b(t,s,{...g,classNameAllocator:A},pe(this,s))):await b(t,s,p,pe(this,s)),y={id:S(s),rules:f?.rules??[],candidates:f?.candidates??{},composites:f?.composites??{},atomicClasses:f?.atomicClasses??[],origins:f?.origins??{},cssOnlySignature:f?.cssOnlySignature??""};ct(this,y,D);let x=S(s);(f||x===s)&&(m.set(x,y),n.set((0,I.resolve)(c(),x),y),u?.transformedDataById.set(x,y)),o==="vite"&&d(L("/",a));let h=f?.code??t;return{code:(o==="webpack"||o==="rspack")&&f?`${h}
|
|
102
|
+
${lt(a)}`:h,meta:{[D]:y},...f?.map?{map:f.map}:{}}}}var dt=require("buffer"),X=require("fs/promises"),_=require("path");function ut(e){let{options:t,cssFileName:s,sourceMap:o,dataById:r,getTheme:i}=e,m,n=process.cwd();return{config(a){a.metafile=!0},setup(a){n=a.initialOptions.absWorkingDir??process.cwd(),a.onEnd(async c=>{if(!c.metafile)return;let d=new Set(Object.keys(c.metafile.inputs).map(f=>(0,_.resolve)(n,f)));for(let f of r.keys())d.has(f)||r.delete(f);let l=t.coordination==="manifest"?await v(n,t):[...r.values()],u=await w(l,await i(),t.layer,o,t.darkMode,t.preflight),p=q(n,a.initialOptions,k(s,u.css));if(!u.css){m&&await(0,X.unlink)(m).catch(()=>{}),m=void 0;return}let g=P(u,(0,_.basename)(p));if(a.initialOptions.write===!1){let f=c.outputFiles;if(!f)return;let y={path:p,contents:dt.Buffer.from(g),hash:"",text:g};if(f.findIndex(h=>h.path===p)!==-1)throw new Error(`CSSX CSS asset collision at "${p}".`);f.push(y);return}await(0,X.mkdir)((0,_.dirname)(p),{recursive:!0}),await(0,X.writeFile)(p,g),m=p})},getWorkingDirectory:()=>n}}function pt(e,t,s){let o=new Set;for(let r of t)e.moduleGraph?.invalidateModule(r,o,s,!0);for(let r of o){if(!r.id)continue;let i=e.runner?.evaluatedModules?.getModuleById(r.id);i&&e.runner?.evaluatedModules?.invalidateModule(i)}}function ft(e){return async function(s){let o=this.environment;if(!o||o.name==="client")return;let r=s.modules,i=r.filter(a=>{let c=e.get(S(a.id??""));return!!(c&&c.cssOnlySignature&&c.atomicClasses?.length===0)});if(i.length===0)return;let m=new Map(i.map(a=>[a,e.get(S(a.id)).cssOnlySignature]));for(let a of i)a.url&&await o.transformRequest(a.url);if(i.every(a=>{let c=e.get(S(a.id));return!!(c&&c.atomicClasses.length===0&&c.cssOnlySignature===m.get(a))}))return pt(o,i,s.timestamp),r.filter(a=>!i.includes(a))}}var ht=require("@cssxio/compiler"),ye=require("buffer"),O=require("fs/promises"),N=require("path");var gt=require("fs/promises"),yt=require("path");async function ge(e){return(0,gt.realpath)(e).catch(()=>(0,yt.resolve)(e))}async function xt(e,t){let s=await T(t);return w(e.map(([,o])=>o),s,t.layer,t.sourceMap??!0,t.darkMode,t.preflight)}function Ct(e){return/\.tsx?$/.test(e)?"ts":"js"}var Lt=/\.[cm]?[jt]sx?$/;function xe(e={}){if(E(e),e.classNameAllocator&&e.className)throw new Error("CSSX classNameAllocator owns naming. Omit className when supplying a custom allocator.");let t=new Map,s=e.classNameAllocator??(0,ht.createClassNameAllocator)(M(e)),o,r;return{name:"@cssxio/unplugin",setup(i){let m=i.initialOptions.absWorkingDir??process.cwd();i.initialOptions.metafile=!0,i.onLoad({filter:Lt},async({path:n})=>{let a=await(0,O.readFile)(n,"utf8"),c=e.stableClassNames||e.naming==="source",d={...e,className:M(e),stableClassNames:c,...c?{stableClassNameFileName:(0,N.relative)(m,n).replaceAll(N.sep,"/")}:{},classNameAllocator:s},l={...d};delete l.coordination,delete l.manifestPath;let u=e.coordination==="manifest"?await U(e.manifestPath,l.className,g=>b(a,n,{...l,classNameAllocator:g})):await b(a,n,d);if(!u)return;let p=await ge(n);return t.set(p,{id:p,candidates:u.candidates,composites:u.composites,atomicClasses:u.atomicClasses,origins:u.origins}),{contents:u.code,loader:Ct(n)}}),i.onEnd(async n=>{if(!n.metafile)return;let a=new Set(await Promise.all(Object.keys(n.metafile.inputs).map(f=>ge((0,N.resolve)(m,f)))));for(let f of t.keys())a.has(f)||t.delete(f);let c=e.coordination==="manifest"?(await v(m,e)).map(f=>[f.id,f]):[...t],d=await xt(c,e),l=q(m,i.initialOptions,k(e.cssFileName??"cssx.css",d.css));if(!d.css){o&&await(0,O.unlink)(o).catch(()=>{}),r&&await(0,O.unlink)(r).catch(()=>{}),o=void 0,r=void 0;return}let u=d.map?`${d.css}
|
|
103
|
+
/*# sourceMappingURL=${(0,N.basename)(l)}.map */`:d.css,p=`${l}.map`,g=d.map?JSON.stringify({...d.map,file:(0,N.basename)(l)}):void 0;if(i.initialOptions.write===!1){if(!n.outputFiles)return;if(n.outputFiles.some(f=>f.path===l))throw new Error(`CSSX CSS asset collision at "${l}".`);n.outputFiles.push({path:l,contents:ye.Buffer.from(u),hash:"",text:u}),g&&n.outputFiles.push({path:p,contents:ye.Buffer.from(g),hash:"",text:g});return}await(0,O.mkdir)((0,N.dirname)(l),{recursive:!0}),await(0,O.writeFile)(l,u),g&&await(0,O.writeFile)(p,g),o=l,r=g?p:void 0})}}}var Vt=/\.(?:[cm]?[jt]sx?|astro|vue|md|mdx)(?:\?.*)?$/,bt=(e={},t)=>{if(E(e),e.classNameAllocator&&e.className)throw new Error("CSSX classNameAllocator owns naming. Omit className when supplying a custom allocator.");let s=e.cssFileName??"cssx.css",o=e.sourceMap??!0,r=new Map,i=e.classNameAllocator??(0,St.createClassNameAllocator)(M(e)),m=new Map,n,a=()=>T(e),c=ut({options:e,cssFileName:s,sourceMap:o,dataById:m,getTheme:a}),d=it({framework:t.framework,options:e,cssFileName:s,sourceMap:o,rollupDataById:r,getTheme:a});return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Vt},handler:mt({framework:t.framework,options:e,classNameAllocator:i,rollupDataById:r,esbuildDataById:m,cssFileName:s,getEsbuildWorkingDirectory:c.getWorkingDirectory,notifyViteStyles:l=>{n&&ce(n,l)}})},watchChange(l,u){u.event==="delete"&&r.delete(S(l))},rollup:{generateBundle:d},vite:{generateBundle:d,configureServer(l){n=l,rt(l,{cssFileName:s,sourceMap:o,options:e,rollupDataById:r,getTheme:a})},hotUpdate:{order:"pre",handler:ft(r)}},...t.framework==="webpack"?{webpack(l){fe({compiler:l,options:e,cssFileName:s,sourceMap:o,getTheme:a})}}:{},...t.framework==="rspack"?{rspack(l){fe({compiler:l,options:e,cssFileName:s,sourceMap:o,getTheme:a})}}:{},...t.framework==="esbuild"?{esbuild:{config:c.config,setup:c.setup}}:{}}},W=(0,wt.createUnplugin)(bt),Ut=W.vite,Ht=W.rollup,Xt=W.webpack,_t=W.rspack,Nt=W;0&&(module.exports={compileCssxStylesheet,esbuild,rollup,rspack,transformCssxModule,unplugin,unpluginFactory,vite,webpack});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as _webpack from 'webpack';
|
|
2
|
+
import * as _rollup from 'rollup';
|
|
2
3
|
import * as _unplugin from 'unplugin';
|
|
3
4
|
import { UnpluginFactory } from 'unplugin';
|
|
4
|
-
import { C as CssxPluginOptions } from './options-
|
|
5
|
-
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
6
|
-
import { transformAsync } from '@babel/core';
|
|
5
|
+
import { C as CssxPluginOptions } from './options-DkqShf7w.cjs';
|
|
7
6
|
export { default as esbuild } from './esbuild.cjs';
|
|
7
|
+
import { I as IncomingSourceMap } from './source-map-from-context-B4SX_KAW.cjs';
|
|
8
|
+
import { transformAsync } from '@babel/core';
|
|
9
|
+
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
8
10
|
import 'esbuild';
|
|
9
11
|
|
|
10
12
|
/** The source location of one utility string. */
|
|
@@ -45,6 +47,7 @@ interface CssxStylesheet {
|
|
|
45
47
|
/** Source map for generated CSS when source locations are available. */
|
|
46
48
|
readonly map?: CssxSourceMap;
|
|
47
49
|
}
|
|
50
|
+
|
|
48
51
|
/**
|
|
49
52
|
* Builds one stylesheet from source module data.
|
|
50
53
|
*
|
|
@@ -53,7 +56,7 @@ interface CssxStylesheet {
|
|
|
53
56
|
* @param layer Optional CSS layer for the output.
|
|
54
57
|
* @param sourceMap Whether to generate a CSS source map.
|
|
55
58
|
* @param darkMode Controls how the `dark` variant is activated.
|
|
56
|
-
* @param preflight Whether to add the
|
|
59
|
+
* @param preflight Whether to add the browser baseline before utility rules.
|
|
57
60
|
* @returns The generated CSS and its source map when source locations exist.
|
|
58
61
|
*/
|
|
59
62
|
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode, preflight?: boolean): Promise<CssxStylesheet>;
|
|
@@ -77,23 +80,6 @@ interface TransformResult {
|
|
|
77
80
|
/** Source map that continues a map supplied by an earlier transform. */
|
|
78
81
|
readonly map?: NonNullable<Awaited<ReturnType<typeof transformAsync>>>['map'];
|
|
79
82
|
}
|
|
80
|
-
/** A source map accepted from a build tool. */
|
|
81
|
-
interface IncomingSourceMap {
|
|
82
|
-
/** Source map format version. CSSX accepts version 3. */
|
|
83
|
-
readonly version: number;
|
|
84
|
-
/** Source file names referenced by the map. */
|
|
85
|
-
readonly sources: string[];
|
|
86
|
-
/** Original identifier names referenced by the map. */
|
|
87
|
-
readonly names: string[];
|
|
88
|
-
/** Optional prefix for source file names. */
|
|
89
|
-
readonly sourceRoot?: string;
|
|
90
|
-
/** Optional source file contents. */
|
|
91
|
-
readonly sourcesContent?: string[];
|
|
92
|
-
/** Encoded source map segments. */
|
|
93
|
-
readonly mappings: string;
|
|
94
|
-
/** Name of the generated file. */
|
|
95
|
-
readonly file: string;
|
|
96
|
-
}
|
|
97
83
|
/**
|
|
98
84
|
* Transforms one source module that imports CSSX.
|
|
99
85
|
*
|
|
@@ -110,7 +96,7 @@ declare function transformCssxModule(code: string, id: string, options?: CssxPlu
|
|
|
110
96
|
}, inputSourceMap?: IncomingSourceMap): Promise<TransformResult | null>;
|
|
111
97
|
|
|
112
98
|
/**
|
|
113
|
-
*
|
|
99
|
+
* Creates the CSSX adapter hooks consumed by Unplugin for one build tool.
|
|
114
100
|
*
|
|
115
101
|
* @param options CSSX adapter options.
|
|
116
102
|
* @param meta Unplugin metadata that identifies the active build tool.
|
|
@@ -132,7 +118,7 @@ declare const vite: (options?: CssxPluginOptions | undefined) => _unplugin.ViteP
|
|
|
132
118
|
* @param options CSSX adapter options.
|
|
133
119
|
* @returns The Rollup plugin.
|
|
134
120
|
*/
|
|
135
|
-
declare const rollup: (options?: CssxPluginOptions | undefined) =>
|
|
121
|
+
declare const rollup: (options?: CssxPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
136
122
|
/**
|
|
137
123
|
* Callable factory that creates the CSSX adapter for webpack.
|
|
138
124
|
*
|
|
@@ -148,4 +134,4 @@ declare const webpack: (options?: CssxPluginOptions | undefined) => _webpack.Web
|
|
|
148
134
|
*/
|
|
149
135
|
declare const rspack: (options?: CssxPluginOptions | undefined) => _unplugin.RspackPluginInstance;
|
|
150
136
|
|
|
151
|
-
export { type CssxCandidateOrigin, CssxPluginOptions, type CssxSourceMap, type CssxSourceModule, type CssxStylesheet,
|
|
137
|
+
export { type CssxCandidateOrigin, CssxPluginOptions, type CssxSourceMap, type CssxSourceModule, type CssxStylesheet, IncomingSourceMap, type TransformResult, compileCssxStylesheet, unplugin as default, rollup, rspack, transformCssxModule, unplugin, unpluginFactory, vite, webpack };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as _webpack from 'webpack';
|
|
2
|
+
import * as _rollup from 'rollup';
|
|
2
3
|
import * as _unplugin from 'unplugin';
|
|
3
4
|
import { UnpluginFactory } from 'unplugin';
|
|
4
|
-
import { C as CssxPluginOptions } from './options-
|
|
5
|
-
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
6
|
-
import { transformAsync } from '@babel/core';
|
|
5
|
+
import { C as CssxPluginOptions } from './options-DkqShf7w.js';
|
|
7
6
|
export { default as esbuild } from './esbuild.js';
|
|
7
|
+
import { I as IncomingSourceMap } from './source-map-from-context-B4SX_KAW.js';
|
|
8
|
+
import { transformAsync } from '@babel/core';
|
|
9
|
+
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
8
10
|
import 'esbuild';
|
|
9
11
|
|
|
10
12
|
/** The source location of one utility string. */
|
|
@@ -45,6 +47,7 @@ interface CssxStylesheet {
|
|
|
45
47
|
/** Source map for generated CSS when source locations are available. */
|
|
46
48
|
readonly map?: CssxSourceMap;
|
|
47
49
|
}
|
|
50
|
+
|
|
48
51
|
/**
|
|
49
52
|
* Builds one stylesheet from source module data.
|
|
50
53
|
*
|
|
@@ -53,7 +56,7 @@ interface CssxStylesheet {
|
|
|
53
56
|
* @param layer Optional CSS layer for the output.
|
|
54
57
|
* @param sourceMap Whether to generate a CSS source map.
|
|
55
58
|
* @param darkMode Controls how the `dark` variant is activated.
|
|
56
|
-
* @param preflight Whether to add the
|
|
59
|
+
* @param preflight Whether to add the browser baseline before utility rules.
|
|
57
60
|
* @returns The generated CSS and its source map when source locations exist.
|
|
58
61
|
*/
|
|
59
62
|
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode, preflight?: boolean): Promise<CssxStylesheet>;
|
|
@@ -77,23 +80,6 @@ interface TransformResult {
|
|
|
77
80
|
/** Source map that continues a map supplied by an earlier transform. */
|
|
78
81
|
readonly map?: NonNullable<Awaited<ReturnType<typeof transformAsync>>>['map'];
|
|
79
82
|
}
|
|
80
|
-
/** A source map accepted from a build tool. */
|
|
81
|
-
interface IncomingSourceMap {
|
|
82
|
-
/** Source map format version. CSSX accepts version 3. */
|
|
83
|
-
readonly version: number;
|
|
84
|
-
/** Source file names referenced by the map. */
|
|
85
|
-
readonly sources: string[];
|
|
86
|
-
/** Original identifier names referenced by the map. */
|
|
87
|
-
readonly names: string[];
|
|
88
|
-
/** Optional prefix for source file names. */
|
|
89
|
-
readonly sourceRoot?: string;
|
|
90
|
-
/** Optional source file contents. */
|
|
91
|
-
readonly sourcesContent?: string[];
|
|
92
|
-
/** Encoded source map segments. */
|
|
93
|
-
readonly mappings: string;
|
|
94
|
-
/** Name of the generated file. */
|
|
95
|
-
readonly file: string;
|
|
96
|
-
}
|
|
97
83
|
/**
|
|
98
84
|
* Transforms one source module that imports CSSX.
|
|
99
85
|
*
|
|
@@ -110,7 +96,7 @@ declare function transformCssxModule(code: string, id: string, options?: CssxPlu
|
|
|
110
96
|
}, inputSourceMap?: IncomingSourceMap): Promise<TransformResult | null>;
|
|
111
97
|
|
|
112
98
|
/**
|
|
113
|
-
*
|
|
99
|
+
* Creates the CSSX adapter hooks consumed by Unplugin for one build tool.
|
|
114
100
|
*
|
|
115
101
|
* @param options CSSX adapter options.
|
|
116
102
|
* @param meta Unplugin metadata that identifies the active build tool.
|
|
@@ -132,7 +118,7 @@ declare const vite: (options?: CssxPluginOptions | undefined) => _unplugin.ViteP
|
|
|
132
118
|
* @param options CSSX adapter options.
|
|
133
119
|
* @returns The Rollup plugin.
|
|
134
120
|
*/
|
|
135
|
-
declare const rollup: (options?: CssxPluginOptions | undefined) =>
|
|
121
|
+
declare const rollup: (options?: CssxPluginOptions | undefined) => _rollup.Plugin<any> | _rollup.Plugin<any>[];
|
|
136
122
|
/**
|
|
137
123
|
* Callable factory that creates the CSSX adapter for webpack.
|
|
138
124
|
*
|
|
@@ -148,4 +134,4 @@ declare const webpack: (options?: CssxPluginOptions | undefined) => _webpack.Web
|
|
|
148
134
|
*/
|
|
149
135
|
declare const rspack: (options?: CssxPluginOptions | undefined) => _unplugin.RspackPluginInstance;
|
|
150
136
|
|
|
151
|
-
export { type CssxCandidateOrigin, CssxPluginOptions, type CssxSourceMap, type CssxSourceModule, type CssxStylesheet,
|
|
137
|
+
export { type CssxCandidateOrigin, CssxPluginOptions, type CssxSourceMap, type CssxSourceModule, type CssxStylesheet, IncomingSourceMap, type TransformResult, compileCssxStylesheet, unplugin as default, rollup, rspack, transformCssxModule, unplugin, unpluginFactory, vite, webpack };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h
|
|
1
|
+
import{a as c,b as d,c as e,d as f,e as g,f as h,g as i,h as j}from"./chunk-BPBCQNZV.js";import{g as a,m as b}from"./chunk-GGFXMP4P.js";import"./chunk-T2L6RO3O.js";export{a as compileCssxStylesheet,i as default,j as esbuild,f as rollup,h as rspack,b as transformCssxModule,d as unplugin,c as unpluginFactory,e as vite,g as webpack};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";var Fe=Object.create;var T=Object.defineProperty;var je=Object.getOwnPropertyDescriptor;var ke=Object.getOwnPropertyNames;var Ie=Object.getPrototypeOf,Le=Object.prototype.hasOwnProperty;var Xe=(e,s)=>{for(var t in s)T(e,t,{get:s[t],enumerable:!0})},H=(e,s,t,r)=>{if(s&&typeof s=="object"||typeof s=="function")for(let o of ke(s))!Le.call(e,o)&&o!==t&&T(e,o,{get:()=>s[o],enumerable:!(r=je(s,o))||r.enumerable});return e};var De=(e,s,t)=>(t=e!=null?Fe(Ie(e)):{},H(s||!e||!e.__esModule?T(t,"default",{value:e,enumerable:!0}):t,e)),Je=e=>H(T({},"__esModule",{value:!0}),e);var He={};Xe(He,{default:()=>$e});module.exports=Je(He);var N=require("fs/promises"),x=require("path");var $=require("@cssxio/compiler");function z(e,s){let t=s.split(`
|
|
2
|
+
`);return{line:e.line+t.length-1,column:t.at(-1).length+e.column*+(t.length===1)}}var Ve="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function v(e){let s="",t=e<0?-e<<1|1:e<<1;do{let r=t&31;t>>>=5,t&&(r|=32),s+=Ve[r]}while(t);return s}function Z(e){let s=Array.from({length:Math.max(0,...e.map(i=>i.line))+1},()=>[]),t=0,r=0,o=0,n=0,m=0;for(let i of e)m*=+(i.line===n),n=i.line,s[i.line]?.push(`${v(i.column-m)}${v(i.source-t)}${v(i.originalLine-r)}${v(i.originalColumn-o)}`),m=i.column,t=i.source,r=i.originalLine,o=i.originalColumn;return s.map(i=>i.join(",")).join(";")}function K(e,s,t){let r=[...new Set(s.map(i=>t.get(i.candidate)?.id).filter(i=>!!i))].sort();if(r.length===0)return;let o=new Map(r.map((i,l)=>[i,l])),n=[],m=z({line:0,column:0},e);for(let i of s){let l=t.get(i.candidate);l&&n.push({...m,source:o.get(l.id),originalLine:l.line,originalColumn:l.column}),m=z(m,i.css)}return{version:3,sources:r,names:[],mappings:Z(n)}}var Y='*,::before,::after,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;font-family:ui-sans-serif,system-ui,sans-serif,"Apple Color Emoji","Segoe UI Emoji","Segoe UI Symbol","Noto Color Emoji";font-feature-settings:normal;font-variation-settings:normal;-webkit-text-size-adjust:100%;tab-size:4;-webkit-tap-highlight-color:transparent}body{margin:0;line-height:inherit}hr{height:0;color:inherit;border-top-width:1px}abbr:where([title]){text-decoration:underline dotted}h1,h2,h3,h4,h5,h6{font-size:inherit;font-weight:inherit}a{color:inherit;text-decoration:inherit}b,strong{font-weight:bolder}code,kbd,samp,pre{font-family:ui-monospace,SFMono-Regular,Menlo,Monaco,Consolas,"Liberation Mono","Courier New",monospace;font-size:1em}small{font-size:80%}sub,sup{position:relative;font-size:75%;line-height:0;vertical-align:baseline}sub{bottom:-.25em}sup{top:-.5em}table{text-indent:0;border-color:inherit;border-collapse:collapse}:-moz-focusring:where(:not(iframe)){outline:auto}progress{vertical-align:baseline}summary{display:list-item}ol,ul,menu{list-style:none}img,svg,video,canvas,audio,iframe,embed,object{display:block;vertical-align:middle}img,video{max-width:100%;height:auto}button,input,select,optgroup,textarea,::file-selector-button{font:inherit;font-feature-settings:inherit;font-variation-settings:inherit;letter-spacing:inherit;color:inherit;border-radius:0;background-color:transparent;opacity:1}button,select{text-transform:none}button,input:where([type="button"],[type="reset"],[type="submit"]),::file-selector-button{appearance:button}::-webkit-inner-spin-button,::-webkit-outer-spin-button{height:auto}[type="search"]{-webkit-appearance:textfield;outline-offset:-2px}::-webkit-search-decoration{-webkit-appearance:none}::-webkit-file-upload-button{font:inherit}textarea{resize:vertical}::placeholder{opacity:1}button,[role="button"]{cursor:pointer}:disabled{cursor:default}[hidden]:where(:not([hidden="until-found"])){display:none!important}';async function ee(e,s,t,r=!0,o,n=!0){let m=Object.create(null),i=Object.create(null),l=new Set,a=!0,d=new Map;for(let p of[...e].sort((C,b)=>C.id.localeCompare(b.id))){for(let[C,b]of Object.entries(p.candidates))if(C in m||(m[C]=b),p.id&&!d.has(C)){let w=p.origins?.[C];d.set(C,{id:p.id,line:w?.line??0,column:w?.column??0})}for(let[C,b]of Object.entries(p.composites??{})){let w=i[C];if(w&&w.join(" ")!==b.join(" "))throw new Error(`CSSX composite class collision for "${C}".`);i[C]=b}p.atomicClasses===void 0&&(a=!1);for(let C of p.atomicClasses??[])l.add(C)}let c=Object.keys(m).sort(),u=n?Y:"";if(c.length===0)return{css:u&&t?`@layer ${t}{${u}}`:u};let f=await(0,$.compileUtilities)(c,p=>m[p],s,(0,$.createSelectorAliases)(i),a?l:void 0,{darkMode:o}),h=t?`@layer ${t}{`:"",g=`${h}${u}${f.css}${h?"}":""}`,S=r?K(`${h}${u}${f.prefixCss}`,f.entries,d):void 0;return{css:g,...S?{map:S}:{}}}function te(e,s,t){let r=t.naming??(t.stableClassNames?"source":t.className?.variant==="random"?"hash":t.className?.variant??"serial"),o=t.stableClassNames?"stableClassNames compatibility option selects source-addressed composites":t.naming?"explicit naming option":t.className?.variant?"className.variant option":"default serial naming",n=new Map,m=new Map;for(let a of[...e].sort((d,c)=>d.id.localeCompare(c.id))){let d=new Map;for(let[c,u]of Object.entries(a.candidates)){let f=m.get(c)??new Set;f.add(u),m.set(c,f);let h=n.get(u)??{module:a.id,utilities:new Set,line:a.origins?.[c]?.line??0,column:a.origins?.[c]?.column??0};h.utilities.add(c),n.set(u,h);let g=d.get(u)??[];g.push(c),d.set(u,g)}for(let[c,u]of Object.entries(a.composites??{})){let f=u.flatMap(S=>d.get(S)??[]),h=f[0],g=n.get(c)??{module:a.id,utilities:new Set,line:h?a.origins?.[h]?.line??0:0,column:h?a.origins?.[h]?.column??0:0};for(let S of f)g.utilities.add(S);n.set(c,g)}for(let c of a.atomicClasses??[])n.has(c)||n.set(c,{module:a.id,utilities:new Set,line:0,column:0})}let i=[...n].sort(([a],[d])=>a.localeCompare(d)).map(([a,d])=>({className:a,module:d.module,utilities:[...d.utilities].sort(),line:d.line+1,column:d.column+1,selectorFound:new RegExp(`\\.${Be(a)}(?:[^A-Za-z0-9_-]|$)`).test(s)})),l=[...m].filter(([,a])=>a.size>1).map(([a])=>a).sort();return{version:1,naming:{mode:r,reason:o},coordination:{mode:t.coordination??"memory",...t.coordination==="manifest"&&t.manifestPath?{manifestPath:t.manifestPath}:{}},classes:i,serverClientMappings:{status:l.length>0?"mismatch":t.coordination==="manifest"?"manifest-shared":"consistent-in-process",conflicts:l}}}function Be(e){return e.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function se(e,s){return JSON.stringify({...e,file:s})}var re=require("path");function oe(e,s){return e.map?`${e.css}
|
|
3
|
+
/*# sourceMappingURL=${(0,re.basename)(s)}.map */`:e.css}var ne=require("fs/promises"),F=require("path"),ze=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro",".mdx",".md"]),_e=new Set([".git",".next",".turbo","node_modules"]);async function j(e,s=[]){let t=[],r=[e,...s],o=new Set;for(;r.length>0;){let n=r.pop(),m=(0,F.resolve)(n);if(!o.has(m)){o.add(m);for(let i of await(0,ne.readdir)(n,{withFileTypes:!0})){let l=(0,F.join)(n,i.name);if(i.isDirectory()){_e.has(i.name)||r.push(l);continue}i.isFile()&&ze.has(l.slice(l.lastIndexOf(".")))&&t.push(l)}}}return t.sort()}var ie=require("module"),ae=require("path"),_=require("url");async function k(e,s,t={}){let r=(0,ie.createRequire)((0,ae.resolve)(s,"package.json")),o;try{o=r.resolve("@mdx-js/mdx")}catch{throw new Error("CSSX Next MDX support requires @mdx-js/mdx to be installed in the Next.js project.")}let n=await import((0,_.pathToFileURL)(o).href),m=async i=>Promise.all((i??[]).map(async l=>{let[a,d]=typeof l=="string"?[l,void 0]:l,c=r.resolve(a),u=await import((0,_.pathToFileURL)(c).href),f=u.default??u;return d===void 0?f:[f,d]}));return String(await n.compile(e,{outputFormat:"program",development:t.development??!1,remarkPlugins:await m(t.remarkPlugins),rehypePlugins:await m(t.rehypePlugins),recmaPlugins:await m(t.recmaPlugins)}))}var P=require("path");function le(e){if(!e||(0,P.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let s=(0,P.normalize)(e);if(s===".."||s.startsWith(`..${P.sep}`))throw new Error("cssFileName must not escape the bundler output directory.");if(!s.endsWith(".css"))throw new Error("cssFileName must end in .css.");return s}function q(e){if(e.sourceRoots&&e.sourceRoots.some(t=>typeof t!="string"||!t.trim()))throw new Error("CSSX sourceRoots must contain non-empty file-system paths.");let s=e.debug;if(s===null||s!==void 0&&typeof s!="boolean"&&(typeof s!="object"||typeof s.reportFile!="string"||!s.reportFile))throw new Error("CSSX debug must be a boolean or an object with a reportFile path.");if(e.naming!==void 0&&!["serial","hash","source"].includes(e.naming))throw new Error('CSSX naming must be "serial", "hash", or "source".');if(e.coordination!==void 0&&!["memory","manifest"].includes(e.coordination))throw new Error('CSSX coordination must be "memory" or "manifest".');if(e.stableClassNames&&e.naming&&e.naming!=="source")throw new Error('CSSX stableClassNames selects source naming and conflicts with naming. Use naming: "source".');if(e.stableClassNames&&e.coordination==="manifest")throw new Error("CSSX stableClassNames already selects source naming; remove it to use manifest coordination.");if(e.naming==="hash"&&e.className?.variant==="serial")throw new Error('CSSX naming: "hash" conflicts with className.variant: "serial".');if(e.naming==="serial"&&e.className?.variant==="random")throw new Error('CSSX naming: "serial" conflicts with className.variant: "random".');if(e.coordination==="manifest"&&!e.manifestPath)throw new Error('CSSX coordination: "manifest" requires manifestPath.');if(e.manifestPath&&e.coordination!=="manifest")throw new Error('CSSX manifestPath requires coordination: "manifest".');if(e.coordination==="manifest"&&e.classNameAllocator)throw new Error("CSSX manifest coordination cannot use a custom classNameAllocator.");if(e.theme!==void 0&&e.themeFile!==void 0)throw new Error("CSSX accepts either theme or themeFile, not both.");if(e.layer!==void 0&&!/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e.layer))throw new Error("CSSX layer must be a valid CSS layer identifier.");if(e.sourceMap!==void 0&&typeof e.sourceMap!="boolean")throw new Error("CSSX sourceMap must be a boolean.");if(e.darkMode!==void 0&&e.darkMode!=="media"&&e.darkMode!=="selector"&&e.darkMode!=="class")throw new Error('CSSX darkMode must be "media", "selector", or "class".');if(e.preflight!==void 0&&typeof e.preflight!="boolean")throw new Error("CSSX preflight must be a boolean.");if(e.reusabilityBudget!==void 0&&e.reusabilityBudget!=="auto"&&(!Number.isFinite(e.reusabilityBudget)||e.reusabilityBudget<0||e.reusabilityBudget>100))throw new Error('CSSX reusabilityBudget must be "auto" or a number from 0 through 100.');le(e.cssFileName??"cssx.css")}var ce=require("fs/promises"),me=require("path");async function U(e){return e.themeFile===void 0?e.theme:(0,ce.readFile)((0,me.resolve)(process.cwd(),e.themeFile),"utf8")}function W(e){let s=2166136261;for(let t=0;t<e.length;t++)s^=e.charCodeAt(t),s=Math.imul(s,16777619);return(s>>>0).toString(36)}function A(e){let s=e.naming==="hash"?"random":e.naming==="serial"?"serial":void 0;if(s&&e.className?.variant&&e.className.variant!==s)throw new Error(`CSSX naming: "${e.naming}" conflicts with className.variant: "${e.className.variant}".`);return{...e.className,...s?{variant:s}:{}}}var Ee=require("@cssxio/compiler"),ve=require("fs/promises"),E=require("path");var de=require("@cssxio/compiler");function I(e){let s=[],t=/\bsx\s*\(/g;for(let r of e.matchAll(t)){let o=r.index,n=e.indexOf("(",o),m=0,i="";for(let l=n;l<e.length;l+=1){let a=e[l];if(i){a==="\\"?l+=1:a===i&&(i="");continue}if(a==='"'||a==="'"||a==="`")i=a;else if(a==="(")m+=1;else if(a===")"&&--m===0){s.push({start:o,end:l+1,code:e.slice(o,l+1)}),t.lastIndex=l+1;break}}}return s}function R(e,s){return{code:e,rules:s.flatMap(t=>t.rules),candidates:Object.assign({},...s.map(t=>t.candidates)),composites:Object.assign({},...s.map(t=>t.composites)),atomicClasses:[...new Set(s.flatMap(t=>t.atomicClasses))],origins:Object.assign({},...s.map(t=>t.origins)),cssOnlySignature:e}}function L(e){let s="const style = ",t=e.indexOf(s)+s.length,r=e.indexOf(";",t);return e.slice(t,r)}async function ue(e,s,t,r){let o=I(e);if(o.length===0)return null;let n=t.classNameAllocator??(0,de.createClassNameAllocator)(),m=t.importSource??"@cssxio/cssx",i=[],l=e;for(let a of[...o].reverse()){let d=await r(`import { sx } from ${JSON.stringify(m)};
|
|
4
|
+
const style = ${a.code};`,`${s}.ts`,{...t,classNameAllocator:n}),c=L(d.code);l=`${l.slice(0,a.start)}${c}${l.slice(a.end)}`,i.push({...d,atomicClasses:[],origins:{}})}return R(l,i)}var ge=require("@babel/core"),xe=De(require("@cssxio/babel-plugin"),1),X=require("@cssxio/compiler");function fe(e){return{className:`cssx-${W(e)}`,css:e}}function pe(e,s){return e&&s?`@layer ${s}{${e}}`:e}async function ye(e,s,t,r){let o=t.importSource??"@cssxio/cssx",n=await U(t),m=await(0,ge.transformAsync)(e,{babelrc:!1,configFile:!1,filename:s,parserOpts:{plugins:["jsx","typescript"]},plugins:[[xe.default,{importSource:o,classNameAllocator:t.classNameAllocator,theme:n,reusabilityBudget:t.reusabilityBudget,stableClassNames:t.stableClassNames,stableClassNameFileName:t.stableClassNameFileName,darkMode:t.darkMode}]],sourceMaps:!0,...r?{inputSourceMap:r}:{}}),i=m.metadata,{candidates:l,origins:a,composites:d,atomicClasses:c,cssOnlySignature:u}=i.cssx,f=Object.keys(l),h=f.length===0?"":(await(0,X.compileUtilities)(f,g=>l[g],n,(0,X.createSelectorAliases)(d),new Set(c),{darkMode:t.darkMode})).css;return{code:m.code,rules:h?[fe(pe(h,t.layer))]:[],candidates:l,composites:d,atomicClasses:c,origins:a,cssOnlySignature:u,map:m.map}}var Ne=require("@cssxio/compiler"),Oe=require("@vue/compiler-sfc");function D(e,s){let t=e.split(`
|
|
5
|
+
`).slice(0,s.line).reduce((r,o)=>r+o.length+1,0);return Math.min(e.length,t+s.column)}function J(e,s){let t=Math.min(e.length,s),r=e.slice(0,t).split(`
|
|
6
|
+
`).length-1,o=e.lastIndexOf(`
|
|
7
|
+
`,t-1)+1;return{line:r,column:t-o}}function G(e,s,t){let r={},o=e.slice(s);for(let[n,m]of Object.entries(t))r[n]=J(e,s+D(o,m));return r}function he(e){return e.slice(1,-1).replace(/\\(['"\\bnfrtv])/g,(s,t)=>({b:"\b",n:`
|
|
8
|
+
`,f:"\f",r:"\r",t:" ",v:"\v"})[t]??t)}function Ce(e,s){if(!s)return e;let t=s==='"'?"'":'"';return e.replace(/"(?:\\.|[^"\\])*"|'(?:\\.|[^'\\])*'/g,r=>{let o=r[0]==='"'?JSON.parse(r):he(r),n=JSON.stringify(o);return t==='"'?n:`'${n.slice(1,-1).replaceAll("'","\\'")}'`})}function be(e,s,t,r,o){let n={};for(let[m,i]of Object.entries(o)){let l=D(t,i);n[m]=J(e,s+Math.max(0,l-r))}return n}function Se(e,s){let t=-1,r;for(let o=0;o<s;o++){let n=e[o];if(r){n===r&&(r=void 0);continue}if(n==="<"&&/[A-Za-z]/.test(e[o+1])){t=o;continue}t!==-1&&(n===">"?t=-1:(n==='"'||n==="'")&&(r=n))}return r}async function we(e,s,t,r,o){let n=I(e);if(n.length===0)return null;let m=t.importSource??"@cssxio/cssx",i=[],l=e;for(let a of[...n].reverse()){let d=`import { sx } from ${JSON.stringify(m)};
|
|
9
|
+
const style = `,c=`${d}${a.code};`,u=await o(c,`${s}.cssx-vue-template.ts`,{...t,classNameAllocator:r}),f=Ce(L(u.code),Se(e,a.start));l=`${l.slice(0,a.start)}${f}${l.slice(a.end)}`,i.push({...u,origins:be(e,a.start,c,d.length,u.origins)})}return R(l,i)}async function Me(e,s,t,r){let o=s.split("?",1).join(""),n=(0,Oe.parse)(e,{filename:o});if(n.errors.length>0)throw new Error(n.errors[0].message);let m=t.classNameAllocator??(0,Ne.createClassNameAllocator)(),i=[],l=[];for(let c of[n.descriptor.script,n.descriptor.scriptSetup]){if(!c?.content.includes(t.importSource??"@cssxio/cssx"))continue;let u=c.lang==="js"||c.lang==="jsx"||c.lang==="tsx"?c.lang:"ts",f=await r(c.content,`${o}.cssx-vue-script.${u}`,{...t,classNameAllocator:m});i.push({start:c.loc.start.offset,end:c.loc.end.offset,code:f.code}),l.push({...f,origins:G(e,c.loc.start.offset,f.origins)})}let a=n.descriptor.template;if(a?.content.includes("sx")){let c=await we(a.content,o,t,m,r);c&&(i.push({start:a.loc.start.offset,end:a.loc.end.offset,code:c.code}),l.push({...c,origins:G(e,a.loc.start.offset,c.origins)}))}if(i.length===0)return null;let d=e;for(let c of i.sort((u,f)=>f.start-u.start))d=`${d.slice(0,c.start)}${c.code}${d.slice(c.end)}`;return R(d,l)}var qe=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro",".vue"]);async function M(e,s,t={},r){q(t);let o=t.importSource??"@cssxio/cssx",n=s.split("?",1).join("");return!qe.has(n.slice(n.lastIndexOf(".")))||!e.includes(o)?null:n.endsWith(".astro")?ue(e,s,t,M):n.endsWith(".vue")?Me(e,s,t,M):ye(e,n,t,r)}var O=require("@cssxio/compiler"),y=require("fs/promises"),V=require("path"),Pe=20,Re=5*6e4;async function B(e,s,t){let r=(0,V.resolve)(e),o=`${r}.lock`,n=Date.now(),m,i=0;for(;!m;){await(0,y.mkdir)((0,V.dirname)(r),{recursive:!0});let l;try{l=await(0,y.open)(o,"wx")}catch(a){let d=a.code;if(d!=="EEXIST"){if(d!=="EACCES"&&d!=="EPERM")throw a;try{await(0,y.stat)(o)}catch(c){if(c.code==="ENOENT"){if(i+=1,i>1)throw a;await new Promise(u=>setTimeout(u,Pe));continue}throw c}}if(i=0,await Ue(o))continue;if(Date.now()-n>=Re)throw new Error(`Timed out waiting for CSSX class-name manifest lock: ${o}`);await new Promise(c=>setTimeout(c,Pe));continue}try{await l.writeFile(`${process.pid}
|
|
10
|
+
${Date.now()}
|
|
11
|
+
`)}catch(a){throw await l.close().catch(()=>{}),await(0,y.rm)(o,{force:!0}).catch(()=>{}),a}m=l}try{let l=await We(r,s),a=await t(l),d=(0,O.snapshotClassNameAllocator)(l),c=`${r}.${process.pid}.${Date.now()}.tmp`;try{await(0,y.writeFile)(c,`${JSON.stringify(d,null,2)}
|
|
12
|
+
`,"utf8"),await(0,y.rename)(c,r)}catch(u){throw await(0,y.rm)(c,{force:!0}).catch(()=>{}),u}return a}finally{await m.close(),await(0,y.rm)(o,{force:!0})}}async function Ue(e){try{let s=await(0,y.stat)(e),t;try{t=await(0,y.readFile)(e,"utf8")}catch(n){let m=n.code;if(m==="EACCES"||m==="EPERM")return!1;throw n}let[r]=t.split(`
|
|
13
|
+
`),o=Number(r);if(Number.isSafeInteger(o)&&o>0)try{return process.kill(o,0),!1}catch(n){return n.code!=="ESRCH"?!1:(await(0,y.rm)(e,{force:!0}),!0)}return Date.now()-s.mtimeMs<Re?!1:(await(0,y.rm)(e,{force:!0}),!0)}catch(s){if(s.code==="ENOENT")return!1;throw s}}async function We(e,s){try{let t=JSON.parse(await(0,y.readFile)(e,"utf8")),r=(0,O.snapshotClassNameAllocator)((0,O.createClassNameAllocator)(s)).options;if(JSON.stringify(t.options)!==JSON.stringify(r))throw new Error("CSSX class-name manifest options do not match the active compiler options.");return(0,O.restoreClassNameAllocator)(t)}catch(t){if(t.code==="ENOENT")return(0,O.createClassNameAllocator)(s);throw t}}async function Ae(e,s){let t=await j(e,s.sourceRoots?.map(n=>(0,E.resolve)(e,n))),r={...s};delete r.coordination,delete r.manifestPath,delete r.classNameAllocator;let o=async n=>{let m=[];for(let i of t){let l=await(0,ve.readFile)(i,"utf8"),a=/\.(?:md|mdx)$/i.test(i);if(a&&!l.includes(s.importSource??"@cssxio/cssx"))continue;let d=a?await k(l,e,s.mdx):l,c=s.stableClassNames||s.naming==="source",u=await M(d,a?`${i}.tsx`:i,{...r,classNameAllocator:n,stableClassNames:c,...c?{stableClassNameFileName:(0,E.relative)(e,i).replaceAll(E.sep,"/")}:{}});u&&m.push({id:i,candidates:u.candidates,composites:u.composites,atomicClasses:u.atomicClasses,origins:u.origins})}return m};return s.coordination==="manifest"?B(s.manifestPath,A(s),o):o(s.classNameAllocator??(0,Ee.createClassNameAllocator)(A(s)))}var Te=new Set([".md",".mdx"]);function $e(e,s){let t=this.async();Ge(this,e,s).then(({code:r,map:o})=>t(null,r,o),r=>t(r instanceof Error?r:new Error(String(r))))}async function Ge(e,s,t){let r=e.getOptions(),o=(0,x.resolve)(r.projectRoot||e.rootContext||process.cwd()),n=(0,x.resolve)(e.resourcePath),m=n.slice(n.lastIndexOf(".")).toLowerCase(),i=s;Te.has(m)&&(i=await k(s,o,r.mdx));let l=(0,x.relative)(o,n).replaceAll(x.sep,"/"),a=r.cssx.naming==="source"||r.cssx.stableClassNames===!0,d={...r.cssx,className:A(r.cssx),stableClassNames:a,...a?{stableClassNameFileName:l}:{}},c=await B(r.manifestPath,d.className,async g=>{let S=Te.has(m)?`${n}.tsx`:n;return M(i,S,{...d,classNameAllocator:g},t)}),u=c?.code??i,f=c?.map??t,h=Qe(l);if(h){let g=r.cssx.sourceRoots?.map(p=>(0,x.resolve)(o,p))??[],S=await j(o,g);for(let p of S)e.addDependency(p);for(let p of[(0,x.resolve)(o,"app"),(0,x.resolve)(o,"src"),(0,x.resolve)(o,"pages"),(0,x.resolve)(o,"components"),...g])try{(await(0,N.stat)(p)).isDirectory()&&e.addContextDependency(p)}catch(C){if(C.code!=="ENOENT")throw C}}if(h){let g=await Ae(o,{...r.cssx,coordination:"manifest",manifestPath:r.manifestPath}),S=r.cssx.themeFile?await(0,N.readFile)((0,x.resolve)(o,r.cssx.themeFile),"utf8"):r.cssx.theme;r.cssx.themeFile&&e.addDependency((0,x.resolve)(o,r.cssx.themeFile));let p=await ee(g,S,r.cssx.layer,r.cssx.sourceMap,r.cssx.darkMode,r.cssx.preflight);if(r.cssx.debug){let b=te(g,p.css,{...r.cssx,coordination:"manifest",manifestPath:r.manifestPath});if(r.cssx.debug===!0)console.info(`CSSX: ${b.naming.mode} naming; ${b.classes.filter(w=>w.selectorFound).length}/${b.classes.length} generated classes have selectors; compiler mappings ${b.serverClientMappings.status}${b.serverClientMappings.conflicts.length?` (${b.serverClientMappings.conflicts.length} utility conflicts)`:""}.`);else{let w=(0,x.resolve)(o,r.cssx.debug.reportFile);await(0,N.mkdir)((0,x.dirname)(w),{recursive:!0}),await Q(w,`${JSON.stringify(b,null,2)}
|
|
14
|
+
`)}}await(0,N.mkdir)((0,x.dirname)(r.styleSheetFile),{recursive:!0});let C=oe(p,"generated.css");await Q(r.styleSheetFile,C),p.map&&await Q(`${r.styleSheetFile}.map`,se(p.map,"generated.css"))}if(h){let g=(0,x.relative)((0,x.dirname)(n),r.styleSheetFile).replaceAll(x.sep,"/");u+=`
|
|
15
|
+
import '${g.startsWith(".")?g:`./${g}`}';
|
|
16
|
+
`,f=void 0}return{code:u,...f?{map:f}:{}}}function Qe(e){return/^(?:src\/)?app\/layout\.[cm]?[jt]sx?$/.test(e)}async function Q(e,s){try{if(await(0,N.readFile)(e,"utf8")===s)return}catch(t){if(t.code!=="ENOENT")throw t}await(0,N.writeFile)(e,s,"utf8")}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { C as CssxPluginOptions, a as CssxNextMdxOptions } from './options-DkqShf7w.cjs';
|
|
2
|
+
import { I as IncomingSourceMap } from './source-map-from-context-B4SX_KAW.cjs';
|
|
3
|
+
import '@cssxio/compiler';
|
|
4
|
+
|
|
5
|
+
/** JSON-safe options passed by the Next.js config wrapper to this loader. */
|
|
6
|
+
interface CssxNextLoaderOptions {
|
|
7
|
+
readonly projectRoot: string;
|
|
8
|
+
readonly styleSheetFile: string;
|
|
9
|
+
readonly importSource: string;
|
|
10
|
+
readonly manifestPath: string;
|
|
11
|
+
readonly development: boolean;
|
|
12
|
+
readonly cssx: Omit<CssxPluginOptions, 'classNameAllocator' | 'coordination' | 'manifestPath'>;
|
|
13
|
+
readonly mdx?: CssxNextMdxOptions;
|
|
14
|
+
}
|
|
15
|
+
/** Minimal Webpack/Turbopack loader context used by the shared loader. */
|
|
16
|
+
interface CssxLoaderContext {
|
|
17
|
+
readonly resourcePath: string;
|
|
18
|
+
readonly rootContext?: string;
|
|
19
|
+
async(): (error: Error | null, source?: string, map?: IncomingSourceMap) => void;
|
|
20
|
+
getOptions(): CssxNextLoaderOptions;
|
|
21
|
+
addDependency(fileName: string): void;
|
|
22
|
+
addContextDependency(directory: string): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Next.js loader shared by Webpack and Turbopack.
|
|
26
|
+
*
|
|
27
|
+
* @param source Current source module.
|
|
28
|
+
* @param inputMap Existing source map from an earlier loader.
|
|
29
|
+
* @returns Nothing; follows the webpack loader callback contract.
|
|
30
|
+
*/
|
|
31
|
+
declare function cssxNextLoader(this: CssxLoaderContext, source: string, inputMap?: IncomingSourceMap): void;
|
|
32
|
+
|
|
33
|
+
export { type CssxNextLoaderOptions, cssxNextLoader as default };
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { C as CssxPluginOptions, a as CssxNextMdxOptions } from './options-DkqShf7w.js';
|
|
2
|
+
import { I as IncomingSourceMap } from './source-map-from-context-B4SX_KAW.js';
|
|
3
|
+
import '@cssxio/compiler';
|
|
4
|
+
|
|
5
|
+
/** JSON-safe options passed by the Next.js config wrapper to this loader. */
|
|
6
|
+
interface CssxNextLoaderOptions {
|
|
7
|
+
readonly projectRoot: string;
|
|
8
|
+
readonly styleSheetFile: string;
|
|
9
|
+
readonly importSource: string;
|
|
10
|
+
readonly manifestPath: string;
|
|
11
|
+
readonly development: boolean;
|
|
12
|
+
readonly cssx: Omit<CssxPluginOptions, 'classNameAllocator' | 'coordination' | 'manifestPath'>;
|
|
13
|
+
readonly mdx?: CssxNextMdxOptions;
|
|
14
|
+
}
|
|
15
|
+
/** Minimal Webpack/Turbopack loader context used by the shared loader. */
|
|
16
|
+
interface CssxLoaderContext {
|
|
17
|
+
readonly resourcePath: string;
|
|
18
|
+
readonly rootContext?: string;
|
|
19
|
+
async(): (error: Error | null, source?: string, map?: IncomingSourceMap) => void;
|
|
20
|
+
getOptions(): CssxNextLoaderOptions;
|
|
21
|
+
addDependency(fileName: string): void;
|
|
22
|
+
addContextDependency(directory: string): void;
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Next.js loader shared by Webpack and Turbopack.
|
|
26
|
+
*
|
|
27
|
+
* @param source Current source module.
|
|
28
|
+
* @param inputMap Existing source map from an earlier loader.
|
|
29
|
+
* @returns Nothing; follows the webpack loader callback contract.
|
|
30
|
+
*/
|
|
31
|
+
declare function cssxNextLoader(this: CssxLoaderContext, source: string, inputMap?: IncomingSourceMap): void;
|
|
32
|
+
|
|
33
|
+
export { type CssxNextLoaderOptions, cssxNextLoader as default };
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import{f as v,g as O,h as P,i as F,j as b,k as E,l as I,m as $,o as L,p as D}from"./chunk-GGFXMP4P.js";import"./chunk-T2L6RO3O.js";import{mkdir as R,readFile as J,stat as T,writeFile as X}from"fs/promises";import{dirname as g,relative as j,resolve as n,sep as A}from"path";var k=new Set([".md",".mdx"]);function W(s,i){let a=this.async();_(this,s,i).then(({code:e,map:t})=>a(null,e,t),e=>a(e instanceof Error?e:new Error(String(e))))}async function _(s,i,a){let e=s.getOptions(),t=n(e.projectRoot||s.rootContext||process.cwd()),l=n(s.resourcePath),y=l.slice(l.lastIndexOf(".")).toLowerCase(),f=i;k.has(y)&&(f=await I(i,t,e.mdx));let C=j(t,l).replaceAll(A,"/"),N=e.cssx.naming==="source"||e.cssx.stableClassNames===!0,S={...e.cssx,className:v(e.cssx),stableClassNames:N,...N?{stableClassNameFileName:C}:{}},w=await L(e.manifestPath,S.className,async o=>{let m=k.has(y)?`${l}.tsx`:l;return $(f,m,{...S,classNameAllocator:o},a)}),M=w?.code??f,u=w?.map??a,x=q(C);if(x){let o=e.cssx.sourceRoots?.map(r=>n(t,r))??[],m=await E(t,o);for(let r of m)s.addDependency(r);for(let r of[n(t,"app"),n(t,"src"),n(t,"pages"),n(t,"components"),...o])try{(await T(r)).isDirectory()&&s.addContextDependency(r)}catch(p){if(p.code!=="ENOENT")throw p}}if(x){let o=await D(t,{...e.cssx,coordination:"manifest",manifestPath:e.manifestPath}),m=e.cssx.themeFile?await J(n(t,e.cssx.themeFile),"utf8"):e.cssx.theme;e.cssx.themeFile&&s.addDependency(n(t,e.cssx.themeFile));let r=await O(o,m,e.cssx.layer,e.cssx.sourceMap,e.cssx.darkMode,e.cssx.preflight);if(e.cssx.debug){let c=b(o,r.css,{...e.cssx,coordination:"manifest",manifestPath:e.manifestPath});if(e.cssx.debug===!0)console.info(`CSSX: ${c.naming.mode} naming; ${c.classes.filter(d=>d.selectorFound).length}/${c.classes.length} generated classes have selectors; compiler mappings ${c.serverClientMappings.status}${c.serverClientMappings.conflicts.length?` (${c.serverClientMappings.conflicts.length} utility conflicts)`:""}.`);else{let d=n(t,e.cssx.debug.reportFile);await R(g(d),{recursive:!0}),await h(d,`${JSON.stringify(c,null,2)}
|
|
2
|
+
`)}}await R(g(e.styleSheetFile),{recursive:!0});let p=F(r,"generated.css");await h(e.styleSheetFile,p),r.map&&await h(`${e.styleSheetFile}.map`,P(r.map,"generated.css"))}if(x){let o=j(g(l),e.styleSheetFile).replaceAll(A,"/");M+=`
|
|
3
|
+
import '${o.startsWith(".")?o:`./${o}`}';
|
|
4
|
+
`,u=void 0}return{code:M,...u?{map:u}:{}}}function q(s){return/^(?:src\/)?app\/layout\.[cm]?[jt]sx?$/.test(s)}async function h(s,i){try{if(await J(s,"utf8")===i)return}catch(a){if(a.code!=="ENOENT")throw a}await X(s,i,"utf8")}export{W as default};
|
package/dist/next.cjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var p=Object.defineProperty;var v=Object.getOwnPropertyDescriptor;var F=Object.getOwnPropertyNames;var R=Object.prototype.hasOwnProperty;var A=(e,r)=>{for(var t in r)p(e,t,{get:r[t],enumerable:!0})},M=(e,r,t,a)=>{if(r&&typeof r=="object"||typeof r=="function")for(let o of F(r))!R.call(e,o)&&o!==t&&p(e,o,{get:()=>r[o],enumerable:!(a=v(r,o))||a.enumerable});return e};var $=e=>M(p({},"__esModule",{value:!0}),e);var D={};A(D,{default:()=>_,withCSSX:()=>X});module.exports=$(D);var E=require("fs"),u=require("path");var l=require("path");function y(e){if(!e||(0,l.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let r=(0,l.normalize)(e);if(r===".."||r.startsWith(`..${l.sep}`))throw new Error("cssFileName must not escape the bundler output directory.");if(!r.endsWith(".css"))throw new Error("cssFileName must end in .css.");return r}function b(e){if(e.sourceRoots&&e.sourceRoots.some(t=>typeof t!="string"||!t.trim()))throw new Error("CSSX sourceRoots must contain non-empty file-system paths.");let r=e.debug;if(r===null||r!==void 0&&typeof r!="boolean"&&(typeof r!="object"||typeof r.reportFile!="string"||!r.reportFile))throw new Error("CSSX debug must be a boolean or an object with a reportFile path.");if(e.naming!==void 0&&!["serial","hash","source"].includes(e.naming))throw new Error('CSSX naming must be "serial", "hash", or "source".');if(e.coordination!==void 0&&!["memory","manifest"].includes(e.coordination))throw new Error('CSSX coordination must be "memory" or "manifest".');if(e.stableClassNames&&e.naming&&e.naming!=="source")throw new Error('CSSX stableClassNames selects source naming and conflicts with naming. Use naming: "source".');if(e.stableClassNames&&e.coordination==="manifest")throw new Error("CSSX stableClassNames already selects source naming; remove it to use manifest coordination.");if(e.naming==="hash"&&e.className?.variant==="serial")throw new Error('CSSX naming: "hash" conflicts with className.variant: "serial".');if(e.naming==="serial"&&e.className?.variant==="random")throw new Error('CSSX naming: "serial" conflicts with className.variant: "random".');if(e.coordination==="manifest"&&!e.manifestPath)throw new Error('CSSX coordination: "manifest" requires manifestPath.');if(e.manifestPath&&e.coordination!=="manifest")throw new Error('CSSX manifestPath requires coordination: "manifest".');if(e.coordination==="manifest"&&e.classNameAllocator)throw new Error("CSSX manifest coordination cannot use a custom classNameAllocator.");if(e.theme!==void 0&&e.themeFile!==void 0)throw new Error("CSSX accepts either theme or themeFile, not both.");if(e.layer!==void 0&&!/^[A-Za-z_-][A-Za-z0-9_-]*$/.test(e.layer))throw new Error("CSSX layer must be a valid CSS layer identifier.");if(e.sourceMap!==void 0&&typeof e.sourceMap!="boolean")throw new Error("CSSX sourceMap must be a boolean.");if(e.darkMode!==void 0&&e.darkMode!=="media"&&e.darkMode!=="selector"&&e.darkMode!=="class")throw new Error('CSSX darkMode must be "media", "selector", or "class".');if(e.preflight!==void 0&&typeof e.preflight!="boolean")throw new Error("CSSX preflight must be a boolean.");if(e.reusabilityBudget!==void 0&&e.reusabilityBudget!=="auto"&&(!Number.isFinite(e.reusabilityBudget)||e.reusabilityBudget<0||e.reusabilityBudget>100))throw new Error('CSSX reusabilityBudget must be "auto" or a number from 0 through 100.');y(e.cssFileName??"cssx.css")}var f=require("path"),N=require("url");function k(e,r){let t=r??(0,f.dirname)((0,N.fileURLToPath)(e)),a=r?".cjs":e.endsWith(".ts")?".ts":".js";return(0,f.resolve)(t,`next-loader${a}`)}var O={},W=z(),h=k(O.url,W);function X(e,r={}){if(r.classNameAllocator)throw new Error("withCSSX cannot serialize classNameAllocator across Next.js compiler workers.");let t=process.cwd();if(!B(t))throw new Error("withCSSX requires an App Router root layout at app/layout.{js,jsx,ts,tsx} or src/app/layout.{js,jsx,ts,tsx}.");let a=(0,u.resolve)(t,r.manifestPath??".cssx/classnames.json"),o={...r,naming:r.naming??(r.stableClassNames?"source":"serial"),coordination:r.coordination??(r.stableClassNames?"memory":"manifest"),...!r.stableClassNames||r.coordination==="manifest"?{manifestPath:a}:{}};b(o);let x=n=>{let w=(0,u.resolve)(t,".cssx/next.css"),m={...o};delete m.classNameAllocator,delete m.coordination,delete m.manifestPath;let d={projectRoot:t,styleSheetFile:w,importSource:o.importSource??"@cssxio/cssx",manifestPath:a,development:process.env.NODE_ENV!=="production",cssx:m,...o.mdx?{mdx:o.mdx}:{}},C=n.webpack;n.webpack=(s,P)=>{let i=C?C(s,P):s;if(typeof i.then=="function")throw new Error("withCSSX requires a synchronous Next.js webpack callback; Next.js does not await webpack hooks.");return i.module??={rules:[]},i.module.rules??=[],i.module.rules.push({test:/\.(?:[cm]?[jt]sx?)$/,include:[t,...(r.sourceRoots??[]).map(g=>(0,u.resolve)(t,g))],enforce:"pre",use:[{loader:h,options:d}]}),i.module.rules.push({test:/\.(?:md|mdx)$/,include:[t,...(r.sourceRoots??[]).map(g=>(0,u.resolve)(t,g))],type:"javascript/auto",use:[{loader:h,options:d}]}),i};let S=n.turbopack??{},c={...S.rules??{}};for(let s of["*.js","*.jsx","*.ts","*.tsx"]){if(c[s])throw new Error(`withCSSX owns turbopack.rules["${s}"]; merge the CSSX loader into that rule explicitly.`);c[s]={loaders:[{loader:h,options:d}]}}for(let s of["*.md","*.mdx"]){if(c[s])throw new Error(`withCSSX owns turbopack.rules["${s}"]; configure MDX through the CSSX mdx option.`);c[s]={loaders:[{loader:h,options:d}],as:"*.js"}}n.turbopack={...S,rules:c};let j=Array.isArray(n.pageExtensions)?n.pageExtensions:["js","jsx","ts","tsx"];return n.pageExtensions=[...new Set([...j,"md","mdx"])],n};return typeof e=="function"?async(n,w)=>x(await e(n,w)):x(e)}var _=X;function B(e){let r=["js","jsx","ts","tsx"];return["app","src/app"].some(t=>r.some(a=>(0,E.existsSync)((0,u.resolve)(e,t,`layout.${a}`))))}function z(){return typeof __dirname=="string"?__dirname:void 0}0&&(module.exports={withCSSX});
|
package/dist/next.d.cts
ADDED
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { C as CssxPluginOptions } from './options-DkqShf7w.cjs';
|
|
2
|
+
import '@cssxio/compiler';
|
|
3
|
+
|
|
4
|
+
/** Subset of Next's Webpack configuration accessed by this adapter. */
|
|
5
|
+
type NextWebpackConfig = {
|
|
6
|
+
module?: {
|
|
7
|
+
rules?: unknown[];
|
|
8
|
+
[key: string]: unknown;
|
|
9
|
+
};
|
|
10
|
+
resolve?: {
|
|
11
|
+
alias?: Record<string, unknown>;
|
|
12
|
+
[key: string]: unknown;
|
|
13
|
+
};
|
|
14
|
+
[key: string]: unknown;
|
|
15
|
+
};
|
|
16
|
+
/** Subset of Next's config surface extended by withCSSX. */
|
|
17
|
+
type NextConfig = {
|
|
18
|
+
webpack?: (config: NextWebpackConfig, context: Record<string, unknown>) => NextWebpackConfig;
|
|
19
|
+
turbopack?: {
|
|
20
|
+
rules?: Record<string, unknown>;
|
|
21
|
+
resolveAlias?: Record<string, string>;
|
|
22
|
+
[key: string]: unknown;
|
|
23
|
+
};
|
|
24
|
+
distDir?: string;
|
|
25
|
+
[key: string]: unknown;
|
|
26
|
+
};
|
|
27
|
+
/** Async or sync Next configuration factory accepted by Next.js. */
|
|
28
|
+
type NextConfigFactory = (phase: string, context: Record<string, unknown>) => NextConfig | Promise<NextConfig>;
|
|
29
|
+
/**
|
|
30
|
+
* Adds CSSX compilation and stylesheet inclusion to a Next.js configuration.
|
|
31
|
+
*
|
|
32
|
+
* @param nextConfig Existing Next.js config object or config factory.
|
|
33
|
+
* @param cssxOptions CSSX compiler, naming, theme, and MDX options.
|
|
34
|
+
* @returns A Next.js config with Webpack and Turbopack CSSX loader rules.
|
|
35
|
+
*/
|
|
36
|
+
declare function withCSSX<T extends NextConfig>(nextConfig: T, cssxOptions?: CssxPluginOptions): T;
|
|
37
|
+
declare function withCSSX(nextConfig: NextConfigFactory, cssxOptions?: CssxPluginOptions): NextConfigFactory;
|
|
38
|
+
|
|
39
|
+
export { withCSSX as default, withCSSX };
|