@cssxio/unplugin 0.3.0 → 0.4.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 +6 -0
- package/dist/chunk-VCJX4HRK.js +93 -0
- package/dist/esbuild.cjs +7 -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 +7 -7
- package/dist/index.d.cts +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.js +1 -1
- package/dist/{options-CHY4_3I-.d.cts → options-Cx1s2I5t.d.cts} +2 -0
- package/dist/{options-CHY4_3I-.d.ts → options-Cx1s2I5t.d.ts} +2 -0
- package/dist/rollup.cjs +6 -6
- package/dist/rollup.d.cts +1 -1
- package/dist/rollup.d.ts +1 -1
- package/dist/rollup.js +1 -1
- package/dist/rspack.cjs +6 -6
- package/dist/rspack.d.cts +1 -1
- package/dist/rspack.d.ts +1 -1
- package/dist/rspack.js +1 -1
- package/dist/vite.cjs +6 -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 +6 -6
- package/dist/webpack.d.cts +1 -1
- package/dist/webpack.d.ts +1 -1
- package/dist/webpack.js +1 -1
- package/package.json +3 -3
- package/dist/chunk-BYZGCOHM.js +0 -93
package/README.md
CHANGED
|
@@ -77,9 +77,15 @@ const stylesheet = await compileCssxStylesheet([
|
|
|
77
77
|
| `layer` | — | CSS layer name that wraps generated CSS. It must be a single valid layer identifier, such as `cssx`. |
|
|
78
78
|
| `theme` | — | Inline CSSX `@theme` source used while transforming and compiling CSS. The theme is compiled into generated rules; it does not add a global stylesheet. |
|
|
79
79
|
| `themeFile` | — | Path, relative to the current working directory, to a CSSX `@theme` file. It is reread when CSS is generated; Rollup-compatible adapters register it as a watched dependency. Do not use it with `theme`. |
|
|
80
|
+
| `darkMode` | `media` | Activates `dark:` utilities with the system color-scheme media query (`media`) or with `[data-theme=dark]` (`selector`). Use `selector` for an application-controlled `data-theme` switcher. |
|
|
81
|
+
| `preflight` | `false` | Adds CSSX's opt-in browser baseline before utilities. It resets common element, link, form-control, button, and box-model defaults for utility-framework migrations. |
|
|
80
82
|
|
|
81
83
|
The universal adapter validates options when it is created. `theme` and `themeFile` cannot be used together. Invalid CSS paths and layer names fail the build before CSS is emitted.
|
|
82
84
|
|
|
85
|
+
CSSX generates utility CSS only by default. Set `preflight: true` to add its
|
|
86
|
+
opt-in browser baseline; leave it disabled when an existing app stylesheet
|
|
87
|
+
already owns global element styles.
|
|
88
|
+
|
|
83
89
|
## Extracted CSS
|
|
84
90
|
|
|
85
91
|
Each production adapter collects CSS from the source files used by the final build. It does not create a CSS file when no used file has CSSX utilities. The default file is `cssx.css`. Set `cssFileName` to use another relative path. CSSX emits one composite class in markup for each static style composition while sharing declarations across composite selectors in the stylesheet.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import{createClassNameAllocator as ee}from"@cssxio/compiler";import{createUnplugin as Le}from"unplugin";import{Buffer as Fe}from"buffer";import{mkdir as je,unlink as Ee,writeFile as Be}from"fs/promises";import{basename as De,dirname as Te,resolve as T}from"path";import{compileUtilities as ne,createSelectorAliases as se}from"@cssxio/compiler";import{basename as re}from"path";var H='*,::before,::after,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;-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 b(e,t,n,o=!0,s,u=!1){let p=Object.create(null),r=Object.create(null),y=new Set,c=!0,g=new Map;for(let d of[...e].sort((l,h)=>l.id.localeCompare(h.id))){for(let[l,h]of Object.entries(d.candidates))if(l in p||(p[l]=h),d.id&&!g.has(l)){let S=d.origins?.[l];g.set(l,{id:d.id,line:S?.line??0,column:S?.column??0})}for(let[l,h]of Object.entries(d.composites??{})){let S=r[l];if(S&&S.join(" ")!==h.join(" "))throw new Error(`CSSX composite class collision for "${l}".`);r[l]=h}d.atomicClasses===void 0&&(c=!1);for(let l of d.atomicClasses??[])y.add(l)}let x=Object.keys(p).sort(),a=u?H:"";if(x.length===0)return{css:a&&n?`@layer ${n}{${a}}`:a};let i=await ne(x,d=>p[d],t,se(r),c?y:void 0,{darkMode:s}),m=n?`@layer ${n}{`:"",C=`${m}${a}${i.css}${m?"}":""}`,f=o?oe(`${m}${a}${i.prefixCss}`,i.entries,g):void 0;return{css:C,...f?{map:f}:{}}}function v(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${re(t)}.map */`:e.css}function O(e,t){return JSON.stringify({...e,file:t})}function oe(e,t,n){let o=[...new Set(t.map(r=>n.get(r.candidate)?.id).filter(r=>!!r))].sort();if(o.length===0)return;let s=new Map(o.map((r,y)=>[r,y])),u=[],p=V({line:0,column:0},e);for(let r of t){let y=n.get(r.candidate);y&&u.push({...p,source:s.get(y.id),originalLine:y.line,originalColumn:y.column}),p=V(p,r.css)}return{version:3,sources:o,names:[],mappings:ae(u)}}function V(e,t){let n=t.split(`
|
|
3
|
+
`);return{line:e.line+n.length-1,column:n.at(-1).length+e.column*+(n.length===1)}}function ae(e){let t=Array.from({length:Math.max(0,...e.map(r=>r.line))+1},()=>[]),n=0,o=0,s=0,u=0,p=0;for(let r of e)p*=+(r.line===u),u=r.line,t[r.line]?.push(`${I(r.column-p)}${I(r.source-n)}${I(r.originalLine-o)}${I(r.originalColumn-s)}`),p=r.column,n=r.source,o=r.originalLine,s=r.originalColumn;return t.map(r=>r.join(",")).join(";")}var ie="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function I(e){let t="",n=e<0?-e<<1|1:e<<1;do{let o=n&31;n>>>=5,n&&(o|=32),t+=ie[o]}while(n);return t}import{readFile as le}from"fs/promises";import{dirname as de,isAbsolute as ce,normalize as ue,resolve as N,sep as _}from"path";async function M(e){return e.themeFile===void 0?e.theme:le(N(process.cwd(),e.themeFile),"utf8")}function $(e){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")throw new Error('CSSX darkMode must be "media" or "selector".');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.');E(e.cssFileName??"cssx.css")}function j(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function k(e,t){return E(e).replaceAll("[hash]",j(t))}function L(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${E(t).replaceAll(_,"/")}`}function F(e,t,n){return t.outdir?N(e,t.outdir,n):t.outfile?N(de(N(e,t.outfile)),n):N(e,n)}function w(e){return e.split("?",1).join("")}function E(e){if(!e||ce(e))throw new Error("cssFileName must be a non-empty relative path.");let t=ue(e);if(t===".."||t.startsWith(`..${_}`))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 W(e,t,n){let o=e.getNativeBuildContext?.();if(!o||o.framework!=="webpack"&&o.framework!=="rspack")return;let s=o.loaderContext?._module;if(!s)return;let u=s.buildInfo??(s.buildInfo={});u[n]=t}function B(e,t,n,o,s,u,p,r,y=!1){let c=e.name??e.options?.name;c==="server"||c==="edge-server"||e.hooks.thisCompilation.tap("@cssxio/unplugin",g=>{g.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let x=[...g.modules].map(C=>pe(C,u)).filter(C=>C!==void 0),a=me(x,p?.values()??[]),i=await b(a,await n(),o,s,r,y);if(!i.css)return;let m=k(t,i.css);if(g.getAsset?.(m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(g.emitAsset(m,new e.webpack.sources.RawSource(v(i,m))),i.map){let C=`${m}.map`;if(g.getAsset?.(C))throw new Error(`CSSX CSS map asset collision at "${C}".`);g.emitAsset(C,new e.webpack.sources.RawSource(O(i.map,m)))}})})}function me(e,t){let n=new Map,o=[];for(let s of t)s.id?n.set(s.id,s):o.push(s);for(let s of e)s.id?n.set(s.id,s):o.push(s);return[...n.values(),...o]}function pe(e,t){let n=e.buildInfo?.[t];if(!n||typeof n!="object")return;let{id:o,candidates:s,composites:u,atomicClasses:p,origins:r}=n;return{id:typeof o=="string"?o:"",candidates:s&&typeof s=="object"?s:{},composites:u&&typeof u=="object"?u:{},...Array.isArray(p)?{atomicClasses:p}:{},origins:r&&typeof r=="object"?r:{}}}import{transformAsync as fe}from"@babel/core";import ge from"@cssxio/babel-plugin";import{compileUtilities as ye,createClassNameAllocator as he,createSelectorAliases as Ce}from"@cssxio/compiler";var xe=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro"]);async function R(e,t,n={},o){$(n);let s=n.importSource??"@cssxio/cssx",u=t.split("?",1).join("");if(!xe.has(u.slice(u.lastIndexOf(".")))||!e.includes(s))return null;if(u.endsWith(".astro"))return be(e,t,n);let p=await M(n),r=await fe(e,{babelrc:!1,configFile:!1,filename:u,parserOpts:{plugins:["jsx","typescript"]},plugins:[[ge,{importSource:s,classNameAllocator:n.classNameAllocator,theme:p,reusabilityBudget:n.reusabilityBudget,stableClassNames:n.stableClassNames,darkMode:n.darkMode}]],sourceMaps:!0,...o?{inputSourceMap:o}:{}}),y=r.metadata,{candidates:c,origins:g,composites:x,atomicClasses:a,cssOnlySignature:i}=y.cssx,m=Object.keys(c),C=m.length===0?"":(await ye(m,f=>c[f],p,Ce(x),new Set(a),{darkMode:n.darkMode})).css;return{code:r.code,rules:C?[ke(ve(C,n.layer))]:[],candidates:c,composites:x,atomicClasses:a,origins:g,cssOnlySignature:i,map:r.map}}async function be(e,t,n){let o=we(e);if(o.length===0)return null;let s=n.classNameAllocator??he(),u=n.importSource??"@cssxio/cssx",p={},r={},y=[],c=e;for(let g of[...o].reverse()){let x=await R(`import { sx } from ${JSON.stringify(u)};
|
|
4
|
+
const style = ${g.code};`,`${t}.ts`,{...n,classNameAllocator:s}),a=Se(x.code);c=`${c.slice(0,g.start)}${a}${c.slice(g.end)}`,Object.assign(p,x.candidates),Object.assign(r,x.composites),y.push(...x.rules)}return{code:c,rules:y,candidates:p,composites:r,atomicClasses:[],origins:{},cssOnlySignature:c}}function we(e){let t=[],n=/\bsx\s*\(/g;for(let o of e.matchAll(n)){let s=o.index,u=e.indexOf("(",s),p=0,r="";for(let y=u;y<e.length;y+=1){let c=e[y];if(r){c==="\\"?y+=1:c===r&&(r="");continue}if(c==='"'||c==="'"||c==="`")r=c;else if(c==="(")p+=1;else if(c===")"&&--p===0){t.push({start:s,end:y+1,code:e.slice(s,y+1)}),n.lastIndex=y+1;break}}}return t}function Se(e){let t="const style = ",n=e.indexOf(t)+t.length,o=e.indexOf(";",n);return e.slice(n,o)}function X(e,t){if(!e||typeof e!="object")return;let n=e.getCombinedSourcemap;if(typeof n!="function")return;let o=n.call(e);if(!o||typeof o!="object")return;let s=o;if(!(s.version!==3||!Array.isArray(s.sources)||typeof s.mappings!="string"))return{version:s.version,sources:[...s.sources],names:[...s.names??[]],mappings:s.mappings,file:s.file??t.split("?",1).join(""),...s.sourceRoot?{sourceRoot:s.sourceRoot}:{},...s.sourcesContent?{sourcesContent:[...s.sourcesContent]}:{}}}function ke(e){return{className:`cssx-${j(e)}`,css:e}}function ve(e,t){return e&&t?`@layer ${t}{${e}}`:e}function D(e,t,n=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:n}]})}import{Buffer as z}from"buffer";import{mkdir as Me,readFile as Re,realpath as Oe,unlink as G,writeFile as q}from"fs/promises";import{basename as J,dirname as Ne,resolve as Z}from"path";import{createClassNameAllocator as Ae}from"@cssxio/compiler";var Pe=/\.[cm]?[jt]sx?$/;function Q(e={}){let t=new Map,n=Ae(),o,s;return{name:"@cssxio/unplugin",setup(u){let p=u.initialOptions.absWorkingDir??process.cwd();u.initialOptions.metafile=!0,u.onLoad({filter:Pe},async({path:r})=>{let y=await Re(r,"utf8"),c=await R(y,r,{...e,classNameAllocator:n});if(!c)return;let g=await K(r);return t.set(g,{id:g,candidates:c.candidates,composites:c.composites,atomicClasses:c.atomicClasses,origins:c.origins}),{contents:c.code,loader:$e(r)}}),u.onEnd(async r=>{if(!r.metafile)return;let y=new Set(await Promise.all(Object.keys(r.metafile.inputs).map(m=>K(Z(p,m)))));for(let m of t.keys())y.has(m)||t.delete(m);let c=await Ie([...t],e),g=F(p,u.initialOptions,k(e.cssFileName??"cssx.css",c.css));if(!c.css){o&&await G(o).catch(()=>{}),s&&await G(s).catch(()=>{}),o=void 0,s=void 0;return}let x=c.map?`${c.css}
|
|
5
|
+
/*# sourceMappingURL=${J(g)}.map */`:c.css,a=`${g}.map`,i=c.map?JSON.stringify({...c.map,file:J(g)}):void 0;if(u.initialOptions.write===!1){if(!r.outputFiles)return;if(r.outputFiles.some(m=>m.path===g))throw new Error(`CSSX CSS asset collision at "${g}".`);r.outputFiles.push({path:g,contents:z.from(x),hash:"",text:x}),i&&r.outputFiles.push({path:a,contents:z.from(i),hash:"",text:i});return}await Me(Ne(g),{recursive:!0}),await q(g,x),i&&await q(a,i),o=g,s=i?a:void 0})}}}async function Ie(e,t){let n=await M(t);return b(e.map(([,o])=>o),n,t.layer,t.sourceMap??!0,t.darkMode,t.preflight)}function $e(e){return/\.tsx?$/.test(e)?"ts":"js"}async function K(e){return Oe(e).catch(()=>Z(e))}var A="@cssxio/unplugin/rules",Ue=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,Y=new Map;function He(e,t){return`${e}\0${JSON.stringify(t)}`}function U(e,t){let n=He(e,t),o=Y.get(n);return o||(o={classNameAllocator:ee(),transformedDataById:new Map},Y.set(n,o)),o}function Ve(e){let t=e.getNativeBuildContext?.();return t&&(t.framework==="webpack"||t.framework==="rspack")?t.loaderContext?.rootContext??process.cwd():void 0}function _e(e,t,n){let o=new Set;for(let s of t)e.moduleGraph?.invalidateModule(s,o,n,!0);for(let s of o){if(!s.id)continue;let u=e.runner?.evaluatedModules?.getModuleById(s.id);u&&e.runner?.evaluatedModules?.invalidateModule(u)}}function We(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:Xe(e[A])}function Xe(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:n,candidates:o,composites:s,atomicClasses:u,origins:p,cssOnlySignature:r}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(n)?n:[],candidates:o&&typeof o=="object"?o:{},composites:s&&typeof s=="object"?s:{},...Array.isArray(u)?{atomicClasses:u}:{},origins:p&&typeof p=="object"?p:{},cssOnlySignature:typeof r=="string"?r:""}}var ze=(e={},t)=>{$(e);let n=e.cssFileName??"cssx.css",o=e.sourceMap??!0,s=new Map,u=ee(),p=new Map,r,y=process.cwd(),c,g=()=>M(e),x=async function(a,i){let m=new Set(Object.values(i).flatMap(l=>l.type==="chunk"?Object.keys(l.modules??{}):[]).map(w));if(t.framework!=="vite")for(let l of s.keys())m.has(l)||s.delete(l);let C=t.framework==="vite"?[...s.values()]:[...m].map(l=>{let h=We(this.getModuleInfo(l)?.meta);return Object.keys(h.candidates).length>0?h:s.get(l)??h}),f=await b(C,await g(),e.layer,o,e.darkMode,e.preflight);if(!f.css)return;let d=k(n,f.css);if(Object.hasOwn(i,d))throw new Error(`CSSX CSS asset collision at "${d}".`);if(this.emitFile({type:"asset",fileName:d,source:v(f,d)}),f.map){let l=`${d}.map`;if(Object.hasOwn(i,l))throw new Error(`CSSX CSS map asset collision at "${l}".`);this.emitFile({type:"asset",fileName:l,source:O(f.map,d)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Ue},async handler(a,i){e.themeFile&&this.addWatchFile?.(T(process.cwd(),e.themeFile));let m=Ve(this),C=m?U(m,e):void 0,f=await R(a,i,{...e,classNameAllocator:C?.classNameAllocator??u},X(this,i)),d={id:w(i),rules:f?.rules??[],candidates:f?.candidates??{},composites:f?.composites??{},atomicClasses:f?.atomicClasses??[],origins:f?.origins??{},cssOnlySignature:f?.cssOnlySignature??""};W(this,d,A);let l=w(i);(f||l===i)&&(s.set(l,d),p.set(T(y,l),d),C?.transformedDataById.set(l,d)),t.framework==="vite"&&c&&D(c,L("/",n));let h=f?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&f?`${h}
|
|
6
|
+
${Ge(n)}`:h,meta:{[A]:d},...f?.map?{map:f.map}:{}}}},watchChange(a,i){i.event==="delete"&&s.delete(w(a))},rollup:{generateBundle:x},vite:{generateBundle:x,configureServer(a){c=a;let i=L(a.config.base,n),m=L("/",n);a.watcher?.on("unlink",C=>{s.delete(w(C)),D(a,m)}),a.middlewares.use((C,f,d)=>{let l=C.url?.split("?",1)[0];if(l!==i&&(l!==`${i}.map`||!o))return d();g().then(h=>b([...s.values()],h,e.layer,o,e.darkMode,e.preflight)).then(h=>{if(l===`${i}.map`){f.setHeader("Content-Type","application/json; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(h.map?O(h.map,n):"");return}f.setHeader("Content-Type","text/css; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(v(h,n))}).catch(h=>{f.setHeader("Content-Type","text/plain; charset=utf-8"),f.end(h instanceof Error?h.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let i=this.environment;if(!i||i.name==="client")return;let m=a.modules.filter(d=>{let l=s.get(w(d.id??""));return!!(l&&l.cssOnlySignature&&l.atomicClasses?.length===0)});if(m.length===0)return;let C=new Map(m.map(d=>[d,s.get(w(d.id)).cssOnlySignature]));for(let d of m)d.url&&await i.transformRequest(d.url);if(m.every(d=>{let l=s.get(w(d.id));return!!(l&&l.atomicClasses.length===0&&l.cssOnlySignature===C.get(d))}))return _e(i,m,a.timestamp),a.modules.filter(d=>!m.includes(d))}}},...t.framework==="webpack"?{webpack(a){let i=U(a.context??a.options?.context??process.cwd(),e);B(a,n,g,e.layer,o,A,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="rspack"?{rspack(a){let i=U(a.context??a.options?.context??process.cwd(),e);B(a,n,g,e.layer,o,A,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let i=a.initialOptions.absWorkingDir??process.cwd();y=i,a.onEnd(async m=>{if(!m.metafile)return;let C=new Set(Object.keys(m.metafile.inputs).map(h=>T(i,h)));for(let h of p.keys())C.has(h)||p.delete(h);let f=await b([...p.values()],await g(),e.layer,o,e.darkMode,e.preflight),d=F(i,a.initialOptions,k(n,f.css));if(!f.css){r&&await Ee(r).catch(()=>{}),r=void 0;return}let l=v(f,De(d));if(a.initialOptions.write===!1){let h=m.outputFiles;if(!h)return;let S={path:d,contents:Fe.from(l),hash:"",text:l};if(h.findIndex(te=>te.path===d)!==-1)throw new Error(`CSSX CSS asset collision at "${d}".`);h.push(S);return}await je(Te(d),{recursive:!0}),await Be(d,l),r=d})}}}:{}}},P=Le(ze);function Ge(e){return`if (typeof document !== "undefined" && typeof module !== "undefined" && module.hot) {
|
|
7
|
+
const key = "__cssxStylesheetHmr";
|
|
8
|
+
const state = globalThis[key] || (globalThis[key] = { revision: 0, staged: [], replacements: [] });
|
|
9
|
+
const stylesheetLink = [...document.querySelectorAll('link[rel="stylesheet"]')].find((link) =>
|
|
10
|
+
new URL(link.href, document.baseURI).pathname.endsWith(${JSON.stringify(`/${e}`)}),
|
|
11
|
+
);
|
|
12
|
+
const nextLink = stylesheetLink && (() => {
|
|
13
|
+
const path = new URL(stylesheetLink.href, document.baseURI).pathname;
|
|
14
|
+
return path.includes("/_next/");
|
|
15
|
+
})();
|
|
16
|
+
if (!state.installed) {
|
|
17
|
+
state.installed = true;
|
|
18
|
+
state.stage = () => {
|
|
19
|
+
const revision = ++state.revision;
|
|
20
|
+
state.staged = [];
|
|
21
|
+
state.replacements = [];
|
|
22
|
+
const links = [...document.querySelectorAll('link[rel="stylesheet"]')].filter((link) =>
|
|
23
|
+
new URL(link.href, document.baseURI).pathname.endsWith(${JSON.stringify(`/${e}`)}),
|
|
24
|
+
);
|
|
25
|
+
return Promise.all(
|
|
26
|
+
links.map(
|
|
27
|
+
(link) =>
|
|
28
|
+
new Promise((resolve) => {
|
|
29
|
+
const replacement = link.cloneNode();
|
|
30
|
+
const url = new URL(link.href, document.baseURI);
|
|
31
|
+
url.searchParams.set("cssx", String(revision));
|
|
32
|
+
replacement.href = url.href;
|
|
33
|
+
const finish = (loaded) => {
|
|
34
|
+
replacement.removeEventListener("load", onLoad);
|
|
35
|
+
replacement.removeEventListener("error", onError);
|
|
36
|
+
if (loaded) {
|
|
37
|
+
state.staged.push(link);
|
|
38
|
+
if (state.removeOnLoad) link.remove();
|
|
39
|
+
}
|
|
40
|
+
else replacement.remove();
|
|
41
|
+
resolve();
|
|
42
|
+
};
|
|
43
|
+
const onLoad = () => finish(true);
|
|
44
|
+
const onError = () => finish(false);
|
|
45
|
+
replacement.addEventListener("load", onLoad);
|
|
46
|
+
replacement.addEventListener("error", onError);
|
|
47
|
+
state.replacements.push(replacement);
|
|
48
|
+
link.after(replacement);
|
|
49
|
+
}),
|
|
50
|
+
),
|
|
51
|
+
);
|
|
52
|
+
};
|
|
53
|
+
module.hot.addStatusHandler((status) => {
|
|
54
|
+
if (status === "prepare" || status === "dispose") {
|
|
55
|
+
return state.stage();
|
|
56
|
+
}
|
|
57
|
+
if (status === "idle") {
|
|
58
|
+
for (const link of state.staged) link.remove();
|
|
59
|
+
state.staged = [];
|
|
60
|
+
state.replacements = [];
|
|
61
|
+
}
|
|
62
|
+
if (status === "abort" || status === "fail") {
|
|
63
|
+
for (const replacement of state.replacements) replacement.remove();
|
|
64
|
+
state.staged = [];
|
|
65
|
+
state.replacements = [];
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
if (nextLink) module.hot.accept(() => void state.stage());
|
|
69
|
+
for (const updateKey of Object.getOwnPropertyNames(globalThis).filter((name) => name.startsWith("webpackHotUpdate"))) {
|
|
70
|
+
const update = globalThis[updateKey];
|
|
71
|
+
if (typeof update !== "function") continue;
|
|
72
|
+
globalThis[updateKey] = function (...args) {
|
|
73
|
+
void state.stage();
|
|
74
|
+
return update.apply(this, args);
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
if (stylesheetLink) {
|
|
78
|
+
state.removeOnLoad = Boolean(nextLink);
|
|
79
|
+
const refresh = async () => {
|
|
80
|
+
try {
|
|
81
|
+
const url = new URL(stylesheetLink.href, document.baseURI);
|
|
82
|
+
url.searchParams.set("cssx-probe", String(Date.now()));
|
|
83
|
+
const css = await fetch(url.href, { cache: "no-store" }).then((response) => response.text());
|
|
84
|
+
if (state.css && state.css !== css) void state.stage();
|
|
85
|
+
state.css = css;
|
|
86
|
+
} catch {
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
void refresh();
|
|
90
|
+
state.poll = setInterval(() => void refresh(), 500);
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}`}var At=P.vite,Pt=P.rollup,It=P.webpack,$t=P.rspack,Lt=P;export{b as a,R as b,ze as c,P as d,At as e,Pt as f,It as g,$t as h,Lt as i,Q as j};
|
package/dist/esbuild.cjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
/*# sourceMappingURL=${(0,
|
|
3
|
-
`);return{line:e.line+
|
|
4
|
-
const style = ${g.code};`,`${t}.ts`,{...
|
|
5
|
-
${
|
|
1
|
+
"use strict";var ue=Object.create;var j=Object.defineProperty;var me=Object.getOwnPropertyDescriptor;var pe=Object.getOwnPropertyNames;var fe=Object.getPrototypeOf,ge=Object.prototype.hasOwnProperty;var ye=(e,t)=>{for(var n in t)j(e,n,{get:t[n],enumerable:!0})},J=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of pe(t))!ge.call(e,s)&&s!==n&&j(e,s,{get:()=>t[s],enumerable:!(r=me(t,s))||r.enumerable});return e};var he=(e,t,n)=>(n=e!=null?ue(fe(e)):{},J(t||!e||!e.__esModule?j(n,"default",{value:e,enumerable:!0}):n,e)),Ce=e=>J(j({},"__esModule",{value:!0}),e);var He={};ye(He,{default:()=>de});module.exports=Ce(He);var q=require("buffer"),w=require("fs/promises"),M=require("path"),le=require("@cssxio/compiler");var G=require("@cssxio/compiler"),oe=require("unplugin"),ae=require("buffer"),$=require("fs/promises"),v=require("path");var B=require("@cssxio/compiler"),Q=require("path");var K='*,::before,::after,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;-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 S(e,t,n,r=!0,s,u=!1){let p=Object.create(null),o=Object.create(null),y=new Set,c=!0,g=new Map;for(let d of[...e].sort((l,h)=>l.id.localeCompare(h.id))){for(let[l,h]of Object.entries(d.candidates))if(l in p||(p[l]=h),d.id&&!g.has(l)){let R=d.origins?.[l];g.set(l,{id:d.id,line:R?.line??0,column:R?.column??0})}for(let[l,h]of Object.entries(d.composites??{})){let R=o[l];if(R&&R.join(" ")!==h.join(" "))throw new Error(`CSSX composite class collision for "${l}".`);o[l]=h}d.atomicClasses===void 0&&(c=!1);for(let l of d.atomicClasses??[])y.add(l)}let x=Object.keys(p).sort(),a=u?K:"";if(x.length===0)return{css:a&&n?`@layer ${n}{${a}}`:a};let i=await(0,B.compileUtilities)(x,d=>p[d],t,(0,B.createSelectorAliases)(o),c?y:void 0,{darkMode:s}),m=n?`@layer ${n}{`:"",C=`${m}${a}${i.css}${m?"}":""}`,f=r?xe(`${m}${a}${i.prefixCss}`,i.entries,g):void 0;return{css:C,...f?{map:f}:{}}}function N(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${(0,Q.basename)(t)}.map */`:e.css}function L(e,t){return JSON.stringify({...e,file:t})}function xe(e,t,n){let r=[...new Set(t.map(o=>n.get(o.candidate)?.id).filter(o=>!!o))].sort();if(r.length===0)return;let s=new Map(r.map((o,y)=>[o,y])),u=[],p=Z({line:0,column:0},e);for(let o of t){let y=n.get(o.candidate);y&&u.push({...p,source:s.get(y.id),originalLine:y.line,originalColumn:y.column}),p=Z(p,o.css)}return{version:3,sources:r,names:[],mappings:be(u)}}function Z(e,t){let n=t.split(`
|
|
3
|
+
`);return{line:e.line+n.length-1,column:n.at(-1).length+e.column*+(n.length===1)}}function be(e){let t=Array.from({length:Math.max(0,...e.map(o=>o.line))+1},()=>[]),n=0,r=0,s=0,u=0,p=0;for(let o of e)p*=+(o.line===u),u=o.line,t[o.line]?.push(`${E(o.column-p)}${E(o.source-n)}${E(o.originalLine-r)}${E(o.originalColumn-s)}`),p=o.column,n=o.source,r=o.originalLine,s=o.originalColumn;return t.map(o=>o.join(",")).join(";")}var we="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function E(e){let t="",n=e<0?-e<<1|1:e<<1;do{let r=n&31;n>>>=5,n&&(r|=32),t+=we[r]}while(n);return t}var Y=require("fs/promises"),b=require("path");async function A(e){return e.themeFile===void 0?e.theme:(0,Y.readFile)((0,b.resolve)(process.cwd(),e.themeFile),"utf8")}function D(e){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")throw new Error('CSSX darkMode must be "media" or "selector".');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.');_(e.cssFileName??"cssx.css")}function V(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function O(e,t){return _(e).replaceAll("[hash]",V(t))}function T(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${_(t).replaceAll(b.sep,"/")}`}function U(e,t,n){return t.outdir?(0,b.resolve)(e,t.outdir,n):t.outfile?(0,b.resolve)((0,b.dirname)((0,b.resolve)(e,t.outfile)),n):(0,b.resolve)(e,n)}function k(e){return e.split("?",1).join("")}function _(e){if(!e||(0,b.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let t=(0,b.normalize)(e);if(t===".."||t.startsWith(`..${b.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 ee(e,t,n){let r=e.getNativeBuildContext?.();if(!r||r.framework!=="webpack"&&r.framework!=="rspack")return;let s=r.loaderContext?._module;if(!s)return;let u=s.buildInfo??(s.buildInfo={});u[n]=t}function W(e,t,n,r,s,u,p,o,y=!1){let c=e.name??e.options?.name;c==="server"||c==="edge-server"||e.hooks.thisCompilation.tap("@cssxio/unplugin",g=>{g.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let x=[...g.modules].map(C=>ke(C,u)).filter(C=>C!==void 0),a=Se(x,p?.values()??[]),i=await S(a,await n(),r,s,o,y);if(!i.css)return;let m=O(t,i.css);if(g.getAsset?.(m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(g.emitAsset(m,new e.webpack.sources.RawSource(N(i,m))),i.map){let C=`${m}.map`;if(g.getAsset?.(C))throw new Error(`CSSX CSS map asset collision at "${C}".`);g.emitAsset(C,new e.webpack.sources.RawSource(L(i.map,m)))}})})}function Se(e,t){let n=new Map,r=[];for(let s of t)s.id?n.set(s.id,s):r.push(s);for(let s of e)s.id?n.set(s.id,s):r.push(s);return[...n.values(),...r]}function ke(e,t){let n=e.buildInfo?.[t];if(!n||typeof n!="object")return;let{id:r,candidates:s,composites:u,atomicClasses:p,origins:o}=n;return{id:typeof r=="string"?r:"",candidates:s&&typeof s=="object"?s:{},composites:u&&typeof u=="object"?u:{},...Array.isArray(p)?{atomicClasses:p}:{},origins:o&&typeof o=="object"?o:{}}}var te=require("@babel/core"),ne=he(require("@cssxio/babel-plugin"),1),P=require("@cssxio/compiler");var ve=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro"]);async function I(e,t,n={},r){D(n);let s=n.importSource??"@cssxio/cssx",u=t.split("?",1).join("");if(!ve.has(u.slice(u.lastIndexOf(".")))||!e.includes(s))return null;if(u.endsWith(".astro"))return Me(e,t,n);let p=await A(n),o=await(0,te.transformAsync)(e,{babelrc:!1,configFile:!1,filename:u,parserOpts:{plugins:["jsx","typescript"]},plugins:[[ne.default,{importSource:s,classNameAllocator:n.classNameAllocator,theme:p,reusabilityBudget:n.reusabilityBudget,stableClassNames:n.stableClassNames,darkMode:n.darkMode}]],sourceMaps:!0,...r?{inputSourceMap:r}:{}}),y=o.metadata,{candidates:c,origins:g,composites:x,atomicClasses:a,cssOnlySignature:i}=y.cssx,m=Object.keys(c),C=m.length===0?"":(await(0,P.compileUtilities)(m,f=>c[f],p,(0,P.createSelectorAliases)(x),new Set(a),{darkMode:n.darkMode})).css;return{code:o.code,rules:C?[Ne(Ae(C,n.layer))]:[],candidates:c,composites:x,atomicClasses:a,origins:g,cssOnlySignature:i,map:o.map}}async function Me(e,t,n){let r=Re(e);if(r.length===0)return null;let s=n.classNameAllocator??(0,P.createClassNameAllocator)(),u=n.importSource??"@cssxio/cssx",p={},o={},y=[],c=e;for(let g of[...r].reverse()){let x=await I(`import { sx } from ${JSON.stringify(u)};
|
|
4
|
+
const style = ${g.code};`,`${t}.ts`,{...n,classNameAllocator:s}),a=Oe(x.code);c=`${c.slice(0,g.start)}${a}${c.slice(g.end)}`,Object.assign(p,x.candidates),Object.assign(o,x.composites),y.push(...x.rules)}return{code:c,rules:y,candidates:p,composites:o,atomicClasses:[],origins:{},cssOnlySignature:c}}function Re(e){let t=[],n=/\bsx\s*\(/g;for(let r of e.matchAll(n)){let s=r.index,u=e.indexOf("(",s),p=0,o="";for(let y=u;y<e.length;y+=1){let c=e[y];if(o){c==="\\"?y+=1:c===o&&(o="");continue}if(c==='"'||c==="'"||c==="`")o=c;else if(c==="(")p+=1;else if(c===")"&&--p===0){t.push({start:s,end:y+1,code:e.slice(s,y+1)}),n.lastIndex=y+1;break}}}return t}function Oe(e){let t="const style = ",n=e.indexOf(t)+t.length,r=e.indexOf(";",n);return e.slice(n,r)}function se(e,t){if(!e||typeof e!="object")return;let n=e.getCombinedSourcemap;if(typeof n!="function")return;let r=n.call(e);if(!r||typeof r!="object")return;let s=r;if(!(s.version!==3||!Array.isArray(s.sources)||typeof s.mappings!="string"))return{version:s.version,sources:[...s.sources],names:[...s.names??[]],mappings:s.mappings,file:s.file??t.split("?",1).join(""),...s.sourceRoot?{sourceRoot:s.sourceRoot}:{},...s.sourcesContent?{sourcesContent:[...s.sourcesContent]}:{}}}function Ne(e){return{className:`cssx-${V(e)}`,css:e}}function Ae(e,t){return e&&t?`@layer ${t}{${e}}`:e}function X(e,t,n=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:n}]})}var F="@cssxio/unplugin/rules",Pe=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,re=new Map;function Ie(e,t){return`${e}\0${JSON.stringify(t)}`}function z(e,t){let n=Ie(e,t),r=re.get(n);return r||(r={classNameAllocator:(0,G.createClassNameAllocator)(),transformedDataById:new Map},re.set(n,r)),r}function $e(e){let t=e.getNativeBuildContext?.();return t&&(t.framework==="webpack"||t.framework==="rspack")?t.loaderContext?.rootContext??process.cwd():void 0}function Le(e,t,n){let r=new Set;for(let s of t)e.moduleGraph?.invalidateModule(s,r,n,!0);for(let s of r){if(!s.id)continue;let u=e.runner?.evaluatedModules?.getModuleById(s.id);u&&e.runner?.evaluatedModules?.invalidateModule(u)}}function Fe(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:je(e[F])}function je(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:n,candidates:r,composites:s,atomicClasses:u,origins:p,cssOnlySignature:o}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(n)?n:[],candidates:r&&typeof r=="object"?r:{},composites:s&&typeof s=="object"?s:{},...Array.isArray(u)?{atomicClasses:u}:{},origins:p&&typeof p=="object"?p:{},cssOnlySignature:typeof o=="string"?o:""}}var Ee=(e={},t)=>{D(e);let n=e.cssFileName??"cssx.css",r=e.sourceMap??!0,s=new Map,u=(0,G.createClassNameAllocator)(),p=new Map,o,y=process.cwd(),c,g=()=>A(e),x=async function(a,i){let m=new Set(Object.values(i).flatMap(l=>l.type==="chunk"?Object.keys(l.modules??{}):[]).map(k));if(t.framework!=="vite")for(let l of s.keys())m.has(l)||s.delete(l);let C=t.framework==="vite"?[...s.values()]:[...m].map(l=>{let h=Fe(this.getModuleInfo(l)?.meta);return Object.keys(h.candidates).length>0?h:s.get(l)??h}),f=await S(C,await g(),e.layer,r,e.darkMode,e.preflight);if(!f.css)return;let d=O(n,f.css);if(Object.hasOwn(i,d))throw new Error(`CSSX CSS asset collision at "${d}".`);if(this.emitFile({type:"asset",fileName:d,source:N(f,d)}),f.map){let l=`${d}.map`;if(Object.hasOwn(i,l))throw new Error(`CSSX CSS map asset collision at "${l}".`);this.emitFile({type:"asset",fileName:l,source:L(f.map,d)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Pe},async handler(a,i){e.themeFile&&this.addWatchFile?.((0,v.resolve)(process.cwd(),e.themeFile));let m=$e(this),C=m?z(m,e):void 0,f=await I(a,i,{...e,classNameAllocator:C?.classNameAllocator??u},se(this,i)),d={id:k(i),rules:f?.rules??[],candidates:f?.candidates??{},composites:f?.composites??{},atomicClasses:f?.atomicClasses??[],origins:f?.origins??{},cssOnlySignature:f?.cssOnlySignature??""};ee(this,d,F);let l=k(i);(f||l===i)&&(s.set(l,d),p.set((0,v.resolve)(y,l),d),C?.transformedDataById.set(l,d)),t.framework==="vite"&&c&&X(c,T("/",n));let h=f?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&f?`${h}
|
|
5
|
+
${Be(n)}`:h,meta:{[F]:d},...f?.map?{map:f.map}:{}}}},watchChange(a,i){i.event==="delete"&&s.delete(k(a))},rollup:{generateBundle:x},vite:{generateBundle:x,configureServer(a){c=a;let i=T(a.config.base,n),m=T("/",n);a.watcher?.on("unlink",C=>{s.delete(k(C)),X(a,m)}),a.middlewares.use((C,f,d)=>{let l=C.url?.split("?",1)[0];if(l!==i&&(l!==`${i}.map`||!r))return d();g().then(h=>S([...s.values()],h,e.layer,r,e.darkMode,e.preflight)).then(h=>{if(l===`${i}.map`){f.setHeader("Content-Type","application/json; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(h.map?L(h.map,n):"");return}f.setHeader("Content-Type","text/css; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(N(h,n))}).catch(h=>{f.setHeader("Content-Type","text/plain; charset=utf-8"),f.end(h instanceof Error?h.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let i=this.environment;if(!i||i.name==="client")return;let m=a.modules.filter(d=>{let l=s.get(k(d.id??""));return!!(l&&l.cssOnlySignature&&l.atomicClasses?.length===0)});if(m.length===0)return;let C=new Map(m.map(d=>[d,s.get(k(d.id)).cssOnlySignature]));for(let d of m)d.url&&await i.transformRequest(d.url);if(m.every(d=>{let l=s.get(k(d.id));return!!(l&&l.atomicClasses.length===0&&l.cssOnlySignature===C.get(d))}))return Le(i,m,a.timestamp),a.modules.filter(d=>!m.includes(d))}}},...t.framework==="webpack"?{webpack(a){let i=z(a.context??a.options?.context??process.cwd(),e);W(a,n,g,e.layer,r,F,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="rspack"?{rspack(a){let i=z(a.context??a.options?.context??process.cwd(),e);W(a,n,g,e.layer,r,F,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let i=a.initialOptions.absWorkingDir??process.cwd();y=i,a.onEnd(async m=>{if(!m.metafile)return;let C=new Set(Object.keys(m.metafile.inputs).map(h=>(0,v.resolve)(i,h)));for(let h of p.keys())C.has(h)||p.delete(h);let f=await S([...p.values()],await g(),e.layer,r,e.darkMode,e.preflight),d=U(i,a.initialOptions,O(n,f.css));if(!f.css){o&&await(0,$.unlink)(o).catch(()=>{}),o=void 0;return}let l=N(f,(0,v.basename)(d));if(a.initialOptions.write===!1){let h=m.outputFiles;if(!h)return;let R={path:d,contents:ae.Buffer.from(l),hash:"",text:l};if(h.findIndex(ce=>ce.path===d)!==-1)throw new Error(`CSSX CSS asset collision at "${d}".`);h.push(R);return}await(0,$.mkdir)((0,v.dirname)(d),{recursive:!0}),await(0,$.writeFile)(d,l),o=d})}}}:{}}},H=(0,oe.createUnplugin)(Ee);function Be(e){return`if (typeof document !== "undefined" && typeof module !== "undefined" && module.hot) {
|
|
6
6
|
const key = "__cssxStylesheetHmr";
|
|
7
7
|
const state = globalThis[key] || (globalThis[key] = { revision: 0, staged: [], replacements: [] });
|
|
8
8
|
const stylesheetLink = [...document.querySelectorAll('link[rel="stylesheet"]')].find((link) =>
|
|
@@ -89,5 +89,5 @@ ${Le(s)}`:p,meta:{[F]:h},...c?.map?{map:c.map}:{}}}},watchChange(a,f){f.event===
|
|
|
89
89
|
state.poll = setInterval(() => void refresh(), 500);
|
|
90
90
|
}
|
|
91
91
|
}
|
|
92
|
-
}`}var
|
|
93
|
-
/*# sourceMappingURL=${(0,
|
|
92
|
+
}`}var ot=H.vite,at=H.rollup,it=H.webpack,lt=H.rspack;var De=/\.[cm]?[jt]sx?$/;function de(e={}){let t=new Map,n=(0,le.createClassNameAllocator)(),r,s;return{name:"@cssxio/unplugin",setup(u){let p=u.initialOptions.absWorkingDir??process.cwd();u.initialOptions.metafile=!0,u.onLoad({filter:De},async({path:o})=>{let y=await(0,w.readFile)(o,"utf8"),c=await I(y,o,{...e,classNameAllocator:n});if(!c)return;let g=await ie(o);return t.set(g,{id:g,candidates:c.candidates,composites:c.composites,atomicClasses:c.atomicClasses,origins:c.origins}),{contents:c.code,loader:Ue(o)}}),u.onEnd(async o=>{if(!o.metafile)return;let y=new Set(await Promise.all(Object.keys(o.metafile.inputs).map(m=>ie((0,M.resolve)(p,m)))));for(let m of t.keys())y.has(m)||t.delete(m);let c=await Te([...t],e),g=U(p,u.initialOptions,O(e.cssFileName??"cssx.css",c.css));if(!c.css){r&&await(0,w.unlink)(r).catch(()=>{}),s&&await(0,w.unlink)(s).catch(()=>{}),r=void 0,s=void 0;return}let x=c.map?`${c.css}
|
|
93
|
+
/*# sourceMappingURL=${(0,M.basename)(g)}.map */`:c.css,a=`${g}.map`,i=c.map?JSON.stringify({...c.map,file:(0,M.basename)(g)}):void 0;if(u.initialOptions.write===!1){if(!o.outputFiles)return;if(o.outputFiles.some(m=>m.path===g))throw new Error(`CSSX CSS asset collision at "${g}".`);o.outputFiles.push({path:g,contents:q.Buffer.from(x),hash:"",text:x}),i&&o.outputFiles.push({path:a,contents:q.Buffer.from(i),hash:"",text:i});return}await(0,w.mkdir)((0,M.dirname)(g),{recursive:!0}),await(0,w.writeFile)(g,x),i&&await(0,w.writeFile)(a,i),r=g,s=i?a:void 0})}}}async function Te(e,t){let n=await A(t);return S(e.map(([,r])=>r),n,t.layer,t.sourceMap??!0,t.darkMode,t.preflight)}function Ue(e){return/\.tsx?$/.test(e)?"ts":"js"}async function ie(e){return(0,w.realpath)(e).catch(()=>(0,M.resolve)(e))}
|
package/dist/esbuild.d.cts
CHANGED
package/dist/esbuild.d.ts
CHANGED
package/dist/esbuild.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{j as a}from"./chunk-
|
|
1
|
+
import{j as a}from"./chunk-VCJX4HRK.js";export{a as default};
|
package/dist/index.cjs
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
"use strict";var
|
|
2
|
-
/*# sourceMappingURL=${(0,
|
|
3
|
-
`);return{line:e.line+
|
|
4
|
-
const style = ${g.code};`,`${t}.ts`,{...
|
|
5
|
-
/*# sourceMappingURL=${(0,
|
|
6
|
-
${
|
|
1
|
+
"use strict";var me=Object.create;var E=Object.defineProperty;var pe=Object.getOwnPropertyDescriptor;var fe=Object.getOwnPropertyNames;var ge=Object.getPrototypeOf,ye=Object.prototype.hasOwnProperty;var he=(e,t)=>{for(var n in t)E(e,n,{get:t[n],enumerable:!0})},K=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let s of fe(t))!ye.call(e,s)&&s!==n&&E(e,s,{get:()=>t[s],enumerable:!(r=pe(t,s))||r.enumerable});return e};var Ce=(e,t,n)=>(n=e!=null?me(ge(e)):{},K(t||!e||!e.__esModule?E(n,"default",{value:e,enumerable:!0}):n,e)),xe=e=>K(E({},"__esModule",{value:!0}),e);var ze={};he(ze,{compileCssxStylesheet:()=>S,default:()=>Xe,esbuild:()=>G,rollup:()=>Ve,rspack:()=>We,transformCssxModule:()=>N,unplugin:()=>L,unpluginFactory:()=>ce,vite:()=>He,webpack:()=>_e});module.exports=xe(ze);var J=require("@cssxio/compiler"),le=require("unplugin"),de=require("buffer"),$=require("fs/promises"),M=require("path");var D=require("@cssxio/compiler"),Y=require("path");var Z='*,::before,::after,::backdrop,::file-selector-button{box-sizing:border-box;margin:0;padding:0;border:0 solid}html,:host{line-height:1.5;-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 S(e,t,n,r=!0,s,u=!1){let p=Object.create(null),o=Object.create(null),y=new Set,c=!0,g=new Map;for(let d of[...e].sort((l,h)=>l.id.localeCompare(h.id))){for(let[l,h]of Object.entries(d.candidates))if(l in p||(p[l]=h),d.id&&!g.has(l)){let R=d.origins?.[l];g.set(l,{id:d.id,line:R?.line??0,column:R?.column??0})}for(let[l,h]of Object.entries(d.composites??{})){let R=o[l];if(R&&R.join(" ")!==h.join(" "))throw new Error(`CSSX composite class collision for "${l}".`);o[l]=h}d.atomicClasses===void 0&&(c=!1);for(let l of d.atomicClasses??[])y.add(l)}let x=Object.keys(p).sort(),a=u?Z:"";if(x.length===0)return{css:a&&n?`@layer ${n}{${a}}`:a};let i=await(0,D.compileUtilities)(x,d=>p[d],t,(0,D.createSelectorAliases)(o),c?y:void 0,{darkMode:s}),m=n?`@layer ${n}{`:"",C=`${m}${a}${i.css}${m?"}":""}`,f=r?be(`${m}${a}${i.prefixCss}`,i.entries,g):void 0;return{css:C,...f?{map:f}:{}}}function A(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${(0,Y.basename)(t)}.map */`:e.css}function F(e,t){return JSON.stringify({...e,file:t})}function be(e,t,n){let r=[...new Set(t.map(o=>n.get(o.candidate)?.id).filter(o=>!!o))].sort();if(r.length===0)return;let s=new Map(r.map((o,y)=>[o,y])),u=[],p=Q({line:0,column:0},e);for(let o of t){let y=n.get(o.candidate);y&&u.push({...p,source:s.get(y.id),originalLine:y.line,originalColumn:y.column}),p=Q(p,o.css)}return{version:3,sources:r,names:[],mappings:we(u)}}function Q(e,t){let n=t.split(`
|
|
3
|
+
`);return{line:e.line+n.length-1,column:n.at(-1).length+e.column*+(n.length===1)}}function we(e){let t=Array.from({length:Math.max(0,...e.map(o=>o.line))+1},()=>[]),n=0,r=0,s=0,u=0,p=0;for(let o of e)p*=+(o.line===u),u=o.line,t[o.line]?.push(`${B(o.column-p)}${B(o.source-n)}${B(o.originalLine-r)}${B(o.originalColumn-s)}`),p=o.column,n=o.source,r=o.originalLine,s=o.originalColumn;return t.map(o=>o.join(",")).join(";")}var Se="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function B(e){let t="",n=e<0?-e<<1|1:e<<1;do{let r=n&31;n>>>=5,n&&(r|=32),t+=Se[r]}while(n);return t}var ee=require("fs/promises"),b=require("path");async function P(e){return e.themeFile===void 0?e.theme:(0,ee.readFile)((0,b.resolve)(process.cwd(),e.themeFile),"utf8")}function T(e){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")throw new Error('CSSX darkMode must be "media" or "selector".');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.');_(e.cssFileName??"cssx.css")}function V(e){let t=2166136261;for(let n=0;n<e.length;n++)t^=e.charCodeAt(n),t=Math.imul(t,16777619);return(t>>>0).toString(36)}function O(e,t){return _(e).replaceAll("[hash]",V(t))}function U(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${_(t).replaceAll(b.sep,"/")}`}function H(e,t,n){return t.outdir?(0,b.resolve)(e,t.outdir,n):t.outfile?(0,b.resolve)((0,b.dirname)((0,b.resolve)(e,t.outfile)),n):(0,b.resolve)(e,n)}function k(e){return e.split("?",1).join("")}function _(e){if(!e||(0,b.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let t=(0,b.normalize)(e);if(t===".."||t.startsWith(`..${b.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 te(e,t,n){let r=e.getNativeBuildContext?.();if(!r||r.framework!=="webpack"&&r.framework!=="rspack")return;let s=r.loaderContext?._module;if(!s)return;let u=s.buildInfo??(s.buildInfo={});u[n]=t}function W(e,t,n,r,s,u,p,o,y=!1){let c=e.name??e.options?.name;c==="server"||c==="edge-server"||e.hooks.thisCompilation.tap("@cssxio/unplugin",g=>{g.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let x=[...g.modules].map(C=>ve(C,u)).filter(C=>C!==void 0),a=ke(x,p?.values()??[]),i=await S(a,await n(),r,s,o,y);if(!i.css)return;let m=O(t,i.css);if(g.getAsset?.(m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(g.emitAsset(m,new e.webpack.sources.RawSource(A(i,m))),i.map){let C=`${m}.map`;if(g.getAsset?.(C))throw new Error(`CSSX CSS map asset collision at "${C}".`);g.emitAsset(C,new e.webpack.sources.RawSource(F(i.map,m)))}})})}function ke(e,t){let n=new Map,r=[];for(let s of t)s.id?n.set(s.id,s):r.push(s);for(let s of e)s.id?n.set(s.id,s):r.push(s);return[...n.values(),...r]}function ve(e,t){let n=e.buildInfo?.[t];if(!n||typeof n!="object")return;let{id:r,candidates:s,composites:u,atomicClasses:p,origins:o}=n;return{id:typeof r=="string"?r:"",candidates:s&&typeof s=="object"?s:{},composites:u&&typeof u=="object"?u:{},...Array.isArray(p)?{atomicClasses:p}:{},origins:o&&typeof o=="object"?o:{}}}var ne=require("@babel/core"),se=Ce(require("@cssxio/babel-plugin"),1),I=require("@cssxio/compiler");var Me=new Set([".js",".jsx",".ts",".tsx",".cjs",".cjsx",".cts",".ctsx",".mjs",".mjsx",".mts",".mtsx",".astro"]);async function N(e,t,n={},r){T(n);let s=n.importSource??"@cssxio/cssx",u=t.split("?",1).join("");if(!Me.has(u.slice(u.lastIndexOf(".")))||!e.includes(s))return null;if(u.endsWith(".astro"))return Re(e,t,n);let p=await P(n),o=await(0,ne.transformAsync)(e,{babelrc:!1,configFile:!1,filename:u,parserOpts:{plugins:["jsx","typescript"]},plugins:[[se.default,{importSource:s,classNameAllocator:n.classNameAllocator,theme:p,reusabilityBudget:n.reusabilityBudget,stableClassNames:n.stableClassNames,darkMode:n.darkMode}]],sourceMaps:!0,...r?{inputSourceMap:r}:{}}),y=o.metadata,{candidates:c,origins:g,composites:x,atomicClasses:a,cssOnlySignature:i}=y.cssx,m=Object.keys(c),C=m.length===0?"":(await(0,I.compileUtilities)(m,f=>c[f],p,(0,I.createSelectorAliases)(x),new Set(a),{darkMode:n.darkMode})).css;return{code:o.code,rules:C?[Ae(Pe(C,n.layer))]:[],candidates:c,composites:x,atomicClasses:a,origins:g,cssOnlySignature:i,map:o.map}}async function Re(e,t,n){let r=Oe(e);if(r.length===0)return null;let s=n.classNameAllocator??(0,I.createClassNameAllocator)(),u=n.importSource??"@cssxio/cssx",p={},o={},y=[],c=e;for(let g of[...r].reverse()){let x=await N(`import { sx } from ${JSON.stringify(u)};
|
|
4
|
+
const style = ${g.code};`,`${t}.ts`,{...n,classNameAllocator:s}),a=Ne(x.code);c=`${c.slice(0,g.start)}${a}${c.slice(g.end)}`,Object.assign(p,x.candidates),Object.assign(o,x.composites),y.push(...x.rules)}return{code:c,rules:y,candidates:p,composites:o,atomicClasses:[],origins:{},cssOnlySignature:c}}function Oe(e){let t=[],n=/\bsx\s*\(/g;for(let r of e.matchAll(n)){let s=r.index,u=e.indexOf("(",s),p=0,o="";for(let y=u;y<e.length;y+=1){let c=e[y];if(o){c==="\\"?y+=1:c===o&&(o="");continue}if(c==='"'||c==="'"||c==="`")o=c;else if(c==="(")p+=1;else if(c===")"&&--p===0){t.push({start:s,end:y+1,code:e.slice(s,y+1)}),n.lastIndex=y+1;break}}}return t}function Ne(e){let t="const style = ",n=e.indexOf(t)+t.length,r=e.indexOf(";",n);return e.slice(n,r)}function re(e,t){if(!e||typeof e!="object")return;let n=e.getCombinedSourcemap;if(typeof n!="function")return;let r=n.call(e);if(!r||typeof r!="object")return;let s=r;if(!(s.version!==3||!Array.isArray(s.sources)||typeof s.mappings!="string"))return{version:s.version,sources:[...s.sources],names:[...s.names??[]],mappings:s.mappings,file:s.file??t.split("?",1).join(""),...s.sourceRoot?{sourceRoot:s.sourceRoot}:{},...s.sourcesContent?{sourcesContent:[...s.sourcesContent]}:{}}}function Ae(e){return{className:`cssx-${V(e)}`,css:e}}function Pe(e,t){return e&&t?`@layer ${t}{${e}}`:e}function X(e,t,n=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:n}]})}var z=require("buffer"),w=require("fs/promises"),v=require("path"),ae=require("@cssxio/compiler");var Ie=/\.[cm]?[jt]sx?$/;function G(e={}){let t=new Map,n=(0,ae.createClassNameAllocator)(),r,s;return{name:"@cssxio/unplugin",setup(u){let p=u.initialOptions.absWorkingDir??process.cwd();u.initialOptions.metafile=!0,u.onLoad({filter:Ie},async({path:o})=>{let y=await(0,w.readFile)(o,"utf8"),c=await N(y,o,{...e,classNameAllocator:n});if(!c)return;let g=await oe(o);return t.set(g,{id:g,candidates:c.candidates,composites:c.composites,atomicClasses:c.atomicClasses,origins:c.origins}),{contents:c.code,loader:Le(o)}}),u.onEnd(async o=>{if(!o.metafile)return;let y=new Set(await Promise.all(Object.keys(o.metafile.inputs).map(m=>oe((0,v.resolve)(p,m)))));for(let m of t.keys())y.has(m)||t.delete(m);let c=await $e([...t],e),g=H(p,u.initialOptions,O(e.cssFileName??"cssx.css",c.css));if(!c.css){r&&await(0,w.unlink)(r).catch(()=>{}),s&&await(0,w.unlink)(s).catch(()=>{}),r=void 0,s=void 0;return}let x=c.map?`${c.css}
|
|
5
|
+
/*# sourceMappingURL=${(0,v.basename)(g)}.map */`:c.css,a=`${g}.map`,i=c.map?JSON.stringify({...c.map,file:(0,v.basename)(g)}):void 0;if(u.initialOptions.write===!1){if(!o.outputFiles)return;if(o.outputFiles.some(m=>m.path===g))throw new Error(`CSSX CSS asset collision at "${g}".`);o.outputFiles.push({path:g,contents:z.Buffer.from(x),hash:"",text:x}),i&&o.outputFiles.push({path:a,contents:z.Buffer.from(i),hash:"",text:i});return}await(0,w.mkdir)((0,v.dirname)(g),{recursive:!0}),await(0,w.writeFile)(g,x),i&&await(0,w.writeFile)(a,i),r=g,s=i?a:void 0})}}}async function $e(e,t){let n=await P(t);return S(e.map(([,r])=>r),n,t.layer,t.sourceMap??!0,t.darkMode,t.preflight)}function Le(e){return/\.tsx?$/.test(e)?"ts":"js"}async function oe(e){return(0,w.realpath)(e).catch(()=>(0,v.resolve)(e))}var j="@cssxio/unplugin/rules",Fe=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,ie=new Map;function je(e,t){return`${e}\0${JSON.stringify(t)}`}function q(e,t){let n=je(e,t),r=ie.get(n);return r||(r={classNameAllocator:(0,J.createClassNameAllocator)(),transformedDataById:new Map},ie.set(n,r)),r}function Ee(e){let t=e.getNativeBuildContext?.();return t&&(t.framework==="webpack"||t.framework==="rspack")?t.loaderContext?.rootContext??process.cwd():void 0}function Be(e,t,n){let r=new Set;for(let s of t)e.moduleGraph?.invalidateModule(s,r,n,!0);for(let s of r){if(!s.id)continue;let u=e.runner?.evaluatedModules?.getModuleById(s.id);u&&e.runner?.evaluatedModules?.invalidateModule(u)}}function De(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:Te(e[j])}function Te(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:n,candidates:r,composites:s,atomicClasses:u,origins:p,cssOnlySignature:o}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(n)?n:[],candidates:r&&typeof r=="object"?r:{},composites:s&&typeof s=="object"?s:{},...Array.isArray(u)?{atomicClasses:u}:{},origins:p&&typeof p=="object"?p:{},cssOnlySignature:typeof o=="string"?o:""}}var ce=(e={},t)=>{T(e);let n=e.cssFileName??"cssx.css",r=e.sourceMap??!0,s=new Map,u=(0,J.createClassNameAllocator)(),p=new Map,o,y=process.cwd(),c,g=()=>P(e),x=async function(a,i){let m=new Set(Object.values(i).flatMap(l=>l.type==="chunk"?Object.keys(l.modules??{}):[]).map(k));if(t.framework!=="vite")for(let l of s.keys())m.has(l)||s.delete(l);let C=t.framework==="vite"?[...s.values()]:[...m].map(l=>{let h=De(this.getModuleInfo(l)?.meta);return Object.keys(h.candidates).length>0?h:s.get(l)??h}),f=await S(C,await g(),e.layer,r,e.darkMode,e.preflight);if(!f.css)return;let d=O(n,f.css);if(Object.hasOwn(i,d))throw new Error(`CSSX CSS asset collision at "${d}".`);if(this.emitFile({type:"asset",fileName:d,source:A(f,d)}),f.map){let l=`${d}.map`;if(Object.hasOwn(i,l))throw new Error(`CSSX CSS map asset collision at "${l}".`);this.emitFile({type:"asset",fileName:l,source:F(f.map,d)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Fe},async handler(a,i){e.themeFile&&this.addWatchFile?.((0,M.resolve)(process.cwd(),e.themeFile));let m=Ee(this),C=m?q(m,e):void 0,f=await N(a,i,{...e,classNameAllocator:C?.classNameAllocator??u},re(this,i)),d={id:k(i),rules:f?.rules??[],candidates:f?.candidates??{},composites:f?.composites??{},atomicClasses:f?.atomicClasses??[],origins:f?.origins??{},cssOnlySignature:f?.cssOnlySignature??""};te(this,d,j);let l=k(i);(f||l===i)&&(s.set(l,d),p.set((0,M.resolve)(y,l),d),C?.transformedDataById.set(l,d)),t.framework==="vite"&&c&&X(c,U("/",n));let h=f?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&f?`${h}
|
|
6
|
+
${Ue(n)}`:h,meta:{[j]:d},...f?.map?{map:f.map}:{}}}},watchChange(a,i){i.event==="delete"&&s.delete(k(a))},rollup:{generateBundle:x},vite:{generateBundle:x,configureServer(a){c=a;let i=U(a.config.base,n),m=U("/",n);a.watcher?.on("unlink",C=>{s.delete(k(C)),X(a,m)}),a.middlewares.use((C,f,d)=>{let l=C.url?.split("?",1)[0];if(l!==i&&(l!==`${i}.map`||!r))return d();g().then(h=>S([...s.values()],h,e.layer,r,e.darkMode,e.preflight)).then(h=>{if(l===`${i}.map`){f.setHeader("Content-Type","application/json; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(h.map?F(h.map,n):"");return}f.setHeader("Content-Type","text/css; charset=utf-8"),f.setHeader("Cache-Control","no-store"),f.end(A(h,n))}).catch(h=>{f.setHeader("Content-Type","text/plain; charset=utf-8"),f.end(h instanceof Error?h.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let i=this.environment;if(!i||i.name==="client")return;let m=a.modules.filter(d=>{let l=s.get(k(d.id??""));return!!(l&&l.cssOnlySignature&&l.atomicClasses?.length===0)});if(m.length===0)return;let C=new Map(m.map(d=>[d,s.get(k(d.id)).cssOnlySignature]));for(let d of m)d.url&&await i.transformRequest(d.url);if(m.every(d=>{let l=s.get(k(d.id));return!!(l&&l.atomicClasses.length===0&&l.cssOnlySignature===C.get(d))}))return Be(i,m,a.timestamp),a.modules.filter(d=>!m.includes(d))}}},...t.framework==="webpack"?{webpack(a){let i=q(a.context??a.options?.context??process.cwd(),e);W(a,n,g,e.layer,r,j,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="rspack"?{rspack(a){let i=q(a.context??a.options?.context??process.cwd(),e);W(a,n,g,e.layer,r,j,i.transformedDataById,e.darkMode,e.preflight)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let i=a.initialOptions.absWorkingDir??process.cwd();y=i,a.onEnd(async m=>{if(!m.metafile)return;let C=new Set(Object.keys(m.metafile.inputs).map(h=>(0,M.resolve)(i,h)));for(let h of p.keys())C.has(h)||p.delete(h);let f=await S([...p.values()],await g(),e.layer,r,e.darkMode,e.preflight),d=H(i,a.initialOptions,O(n,f.css));if(!f.css){o&&await(0,$.unlink)(o).catch(()=>{}),o=void 0;return}let l=A(f,(0,M.basename)(d));if(a.initialOptions.write===!1){let h=m.outputFiles;if(!h)return;let R={path:d,contents:de.Buffer.from(l),hash:"",text:l};if(h.findIndex(ue=>ue.path===d)!==-1)throw new Error(`CSSX CSS asset collision at "${d}".`);h.push(R);return}await(0,$.mkdir)((0,M.dirname)(d),{recursive:!0}),await(0,$.writeFile)(d,l),o=d})}}}:{}}},L=(0,le.createUnplugin)(ce);function Ue(e){return`if (typeof document !== "undefined" && typeof module !== "undefined" && module.hot) {
|
|
7
7
|
const key = "__cssxStylesheetHmr";
|
|
8
8
|
const state = globalThis[key] || (globalThis[key] = { revision: 0, staged: [], replacements: [] });
|
|
9
9
|
const stylesheetLink = [...document.querySelectorAll('link[rel="stylesheet"]')].find((link) =>
|
|
@@ -90,4 +90,4 @@ ${je(s)}`:p,meta:{[j]:h},...c?.map?{map:c.map}:{}}}},watchChange(a,f){f.event===
|
|
|
90
90
|
state.poll = setInterval(() => void refresh(), 500);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
|
-
}`}var
|
|
93
|
+
}`}var He=L.vite,Ve=L.rollup,_e=L.webpack,We=L.rspack,Xe=L;0&&(module.exports={compileCssxStylesheet,esbuild,rollup,rspack,transformCssxModule,unplugin,unpluginFactory,vite,webpack});
|
package/dist/index.d.cts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _webpack from 'webpack';
|
|
2
2
|
import * as _unplugin from 'unplugin';
|
|
3
3
|
import { UnpluginFactory } from 'unplugin';
|
|
4
|
-
import { C as CssxPluginOptions } from './options-
|
|
4
|
+
import { C as CssxPluginOptions } from './options-Cx1s2I5t.cjs';
|
|
5
5
|
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
6
6
|
import { transformAsync } from '@babel/core';
|
|
7
7
|
export { default as esbuild } from './esbuild.cjs';
|
|
@@ -53,9 +53,10 @@ interface CssxStylesheet {
|
|
|
53
53
|
* @param layer Optional CSS layer for the output.
|
|
54
54
|
* @param sourceMap Whether to generate a CSS source map.
|
|
55
55
|
* @param darkMode Controls how the `dark` variant is activated.
|
|
56
|
+
* @param preflight Whether to add the optional browser baseline before utility rules.
|
|
56
57
|
* @returns The generated CSS and its source map when source locations exist.
|
|
57
58
|
*/
|
|
58
|
-
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode): Promise<CssxStylesheet>;
|
|
59
|
+
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode, preflight?: boolean): Promise<CssxStylesheet>;
|
|
59
60
|
|
|
60
61
|
/** The result of transforming one source module. */
|
|
61
62
|
interface TransformResult {
|
package/dist/index.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as _webpack from 'webpack';
|
|
2
2
|
import * as _unplugin from 'unplugin';
|
|
3
3
|
import { UnpluginFactory } from 'unplugin';
|
|
4
|
-
import { C as CssxPluginOptions } from './options-
|
|
4
|
+
import { C as CssxPluginOptions } from './options-Cx1s2I5t.js';
|
|
5
5
|
import { DarkMode, CssxRule, ClassNameAllocator } from '@cssxio/compiler';
|
|
6
6
|
import { transformAsync } from '@babel/core';
|
|
7
7
|
export { default as esbuild } from './esbuild.js';
|
|
@@ -53,9 +53,10 @@ interface CssxStylesheet {
|
|
|
53
53
|
* @param layer Optional CSS layer for the output.
|
|
54
54
|
* @param sourceMap Whether to generate a CSS source map.
|
|
55
55
|
* @param darkMode Controls how the `dark` variant is activated.
|
|
56
|
+
* @param preflight Whether to add the optional browser baseline before utility rules.
|
|
56
57
|
* @returns The generated CSS and its source map when source locations exist.
|
|
57
58
|
*/
|
|
58
|
-
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode): Promise<CssxStylesheet>;
|
|
59
|
+
declare function compileCssxStylesheet(data: readonly CssxSourceModule[], theme?: string, layer?: string, sourceMap?: boolean, darkMode?: DarkMode, preflight?: boolean): Promise<CssxStylesheet>;
|
|
59
60
|
|
|
60
61
|
/** The result of transforming one source module. */
|
|
61
62
|
interface TransformResult {
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
import{a,b,c,d,e,f,g,h,i,j}from"./chunk-
|
|
1
|
+
import{a,b,c,d,e,f,g,h,i,j}from"./chunk-VCJX4HRK.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};
|
|
@@ -18,6 +18,8 @@ interface CssxPluginOptions {
|
|
|
18
18
|
readonly reusabilityBudget?: ReusabilityBudget;
|
|
19
19
|
/** Activates `dark` variants with a media query or a `[data-theme=dark]` selector. */
|
|
20
20
|
readonly darkMode?: DarkMode;
|
|
21
|
+
/** Adds CSSX's optional browser reset before generated utility rules. */
|
|
22
|
+
readonly preflight?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type { CssxPluginOptions as C };
|
|
@@ -18,6 +18,8 @@ interface CssxPluginOptions {
|
|
|
18
18
|
readonly reusabilityBudget?: ReusabilityBudget;
|
|
19
19
|
/** Activates `dark` variants with a media query or a `[data-theme=dark]` selector. */
|
|
20
20
|
readonly darkMode?: DarkMode;
|
|
21
|
+
/** Adds CSSX's optional browser reset before generated utility rules. */
|
|
22
|
+
readonly preflight?: boolean;
|
|
21
23
|
}
|
|
22
24
|
|
|
23
25
|
export type { CssxPluginOptions as C };
|