@cssxio/unplugin 0.2.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/LICENSE +21 -0
- package/README.md +95 -0
- package/dist/chunk-NTRHNWKR.js +93 -0
- package/dist/esbuild.cjs +93 -0
- package/dist/esbuild.d.cts +15 -0
- package/dist/esbuild.d.ts +15 -0
- package/dist/esbuild.js +1 -0
- package/dist/index.cjs +93 -0
- package/dist/index.d.cts +149 -0
- package/dist/index.d.ts +149 -0
- package/dist/index.js +1 -0
- package/dist/options-CHY4_3I-.d.cts +23 -0
- package/dist/options-CHY4_3I-.d.ts +23 -0
- package/dist/rollup.cjs +92 -0
- package/dist/rollup.d.cts +13 -0
- package/dist/rollup.d.ts +13 -0
- package/dist/rollup.js +1 -0
- package/dist/rspack.cjs +92 -0
- package/dist/rspack.d.cts +13 -0
- package/dist/rspack.d.ts +13 -0
- package/dist/rspack.js +1 -0
- package/dist/vite.cjs +92 -0
- package/dist/vite.d.cts +13 -0
- package/dist/vite.d.ts +13 -0
- package/dist/vite.js +1 -0
- package/dist/webpack.cjs +92 -0
- package/dist/webpack.d.cts +13 -0
- package/dist/webpack.d.ts +13 -0
- package/dist/webpack.js +1 -0
- package/package.json +63 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 CSSX contributors
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
# @cssxio/unplugin
|
|
2
|
+
|
|
3
|
+
CSSX has build tool adapters at these entrypoints:
|
|
4
|
+
|
|
5
|
+
```ts
|
|
6
|
+
import cssxVite from '@cssxio/unplugin/vite';
|
|
7
|
+
import cssxRollup from '@cssxio/unplugin/rollup';
|
|
8
|
+
import cssxWebpack from '@cssxio/unplugin/webpack';
|
|
9
|
+
import cssxRspack from '@cssxio/unplugin/rspack';
|
|
10
|
+
import cssxEsbuild from '@cssxio/unplugin/esbuild';
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Add the selected adapter to your build tool `plugins` setting:
|
|
14
|
+
|
|
15
|
+
```ts
|
|
16
|
+
// vite.config.ts
|
|
17
|
+
import cssx from '@cssxio/unplugin/vite';
|
|
18
|
+
export default { plugins: [cssx()] };
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
```js
|
|
22
|
+
// rollup.config.js
|
|
23
|
+
import cssx from '@cssxio/unplugin/rollup';
|
|
24
|
+
export default { plugins: [cssx({ cssFileName: 'assets/cssx.css' })] };
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
```js
|
|
28
|
+
// webpack.config.js
|
|
29
|
+
import cssx from '@cssxio/unplugin/webpack';
|
|
30
|
+
export default { plugins: [cssx()] };
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
```js
|
|
34
|
+
// rspack.config.js
|
|
35
|
+
import cssx from '@cssxio/unplugin/rspack';
|
|
36
|
+
export default { plugins: [cssx()] };
|
|
37
|
+
```
|
|
38
|
+
|
|
39
|
+
```js
|
|
40
|
+
// build.mjs
|
|
41
|
+
import { build } from 'esbuild';
|
|
42
|
+
import cssx from '@cssxio/unplugin/esbuild';
|
|
43
|
+
|
|
44
|
+
await build({ entryPoints: ['src/main.ts'], bundle: true, plugins: [cssx()] });
|
|
45
|
+
```
|
|
46
|
+
|
|
47
|
+
## Programmatic API
|
|
48
|
+
|
|
49
|
+
The main entrypoint exports the low-level `unpluginFactory`, the universal `unplugin` adapter instance, and named callable factories for Vite, Rollup, webpack, Rspack, and esbuild. Most applications should import one platform entrypoint shown above.
|
|
50
|
+
|
|
51
|
+
```ts
|
|
52
|
+
import { transformCssxModule, compileCssxStylesheet } from '@cssxio/unplugin';
|
|
53
|
+
|
|
54
|
+
const transformed = await transformCssxModule(source, 'src/button.tsx');
|
|
55
|
+
const stylesheet = await compileCssxStylesheet([
|
|
56
|
+
{
|
|
57
|
+
id: 'src/button.tsx',
|
|
58
|
+
candidates: transformed?.candidates ?? {},
|
|
59
|
+
origins: transformed?.origins,
|
|
60
|
+
composites: transformed?.composites,
|
|
61
|
+
atomicClasses: transformed?.atomicClasses,
|
|
62
|
+
},
|
|
63
|
+
]);
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
`transformCssxModule` returns `null` unless the source module imports the configured CSSX runtime. Otherwise it returns transformed JavaScript, candidate metadata, composite-to-atomic selector metadata, source locations, and a JavaScript source map when the transform creates one. Pass an earlier compatible version 3 source map as its fourth argument to continue that map.
|
|
67
|
+
|
|
68
|
+
`compileCssxStylesheet` combines module metadata in stable module and utility order, removes duplicate utilities, aliases each winning atomic rule to the composite classes that use it, and returns generated CSS. It also returns a CSS source map when collected metadata includes source locations. `CssxPluginOptions`, `TransformResult`, `IncomingSourceMap`, `CssxSourceModule`, and stylesheet source-map types are exported from the main entrypoint.
|
|
69
|
+
|
|
70
|
+
## Options
|
|
71
|
+
|
|
72
|
+
| Option | Default | What it does |
|
|
73
|
+
| -------------- | -------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
74
|
+
| `importSource` | `@cssxio/cssx` | Module specifier that identifies source files to transform. A source file must contain this text and have a JavaScript or TypeScript extension. |
|
|
75
|
+
| `cssFileName` | `cssx.css` | Relative CSS output path. It must be non-empty, end in `.css`, and stay within the bundler output directory. `[hash]` is replaced with a stable hash of the generated CSS. |
|
|
76
|
+
| `sourceMap` | `true` | Whether to generate a separate CSS source map. Set it to `false` to omit both the `.css.map` file and source-map comment. |
|
|
77
|
+
| `layer` | — | CSS layer name that wraps generated CSS. It must be a single valid layer identifier, such as `cssx`. |
|
|
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
|
+
| `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
|
+
|
|
81
|
+
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
|
+
|
|
83
|
+
## Extracted CSS
|
|
84
|
+
|
|
85
|
+
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.
|
|
86
|
+
|
|
87
|
+
The Rollup-compatible adapters retain transformed module metadata until `generateBundle`, then emit CSS and its map as build assets. The webpack and Rspack adapters retain metadata on native modules and emit assets at the additions stage of `processAssets`. The direct esbuild adapter enables the metafile, removes data for source files absent from it, and generates CSS in `onEnd`.
|
|
88
|
+
|
|
89
|
+
When `sourceMap` is enabled and source locations are available, generated CSS has a separate `.css.map` file and a source-map comment. Each mapping points to the source module location of the static utility string that created the rule. `transformCssxModule` can accept and return JavaScript source maps for build tools that provide a compatible input map.
|
|
90
|
+
|
|
91
|
+
During local development, the Vite adapter serves the configured `cssFileName` path from memory, including a source map when one exists. Add a matching stylesheet link to your document. CSSX injects a small page script that refreshes matching stylesheet links after source changes or deletions. Production adapters create the same CSS file, and your app must include it.
|
|
92
|
+
|
|
93
|
+
With esbuild, `outdir` places CSS below that directory. `outfile` places it beside the output file. Without either option, it is placed below the working directory. With `write: false`, CSS and its map are appended to esbuild's in-memory `outputFiles`; otherwise they are written to disk. A later esbuild build removes CSS files that CSSX wrote when no utilities remain.
|
|
94
|
+
|
|
95
|
+
See the [workspace README](../../README.md) for CSSX syntax, supported utilities, and current exclusions.
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import{createClassNameAllocator as Ne}from"@cssxio/compiler";import{createUnplugin as Pe}from"unplugin";import{Buffer as $e}from"buffer";import{mkdir as Le,unlink as Fe,writeFile as Ie}from"fs/promises";import{basename as Ee,dirname as je,resolve as U}from"path";import{compileUtilities as Q,createSelectorAliases as Y}from"@cssxio/compiler";import{basename as ee}from"path";async function S(e,t,s,o=!0,n){let d=Object.create(null),c=Object.create(null),r=new Set,i=!0,l=new Map;for(let C of[...e].sort((p,m)=>p.id.localeCompare(m.id))){for(let[p,m]of Object.entries(C.candidates))if(p in d||(d[p]=m),C.id&&!l.has(p)){let g=C.origins?.[p];l.set(p,{id:C.id,line:g?.line??0,column:g?.column??0})}for(let[p,m]of Object.entries(C.composites??{})){let g=c[p];if(g&&g.join(" ")!==m.join(" "))throw new Error(`CSSX composite class collision for "${p}".`);c[p]=m}C.atomicClasses===void 0&&(i=!1);for(let p of C.atomicClasses??[])r.add(p)}let y=Object.keys(d).sort();if(y.length===0)return{css:""};let h=await Q(y,C=>d[C],t,Y(c),i?r:void 0,{darkMode:n}),a=h.css&&s?`@layer ${s}{`:"",f=`${a}${h.css}${a?"}":""}`,u=o?te(`${a}${h.prefixCss}`,h.entries,l):void 0;return{css:f,...u?{map:u}:{}}}function k(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${ee(t)}.map */`:e.css}function R(e,t){return JSON.stringify({...e,file:t})}function te(e,t,s){let o=[...new Set(t.map(r=>s.get(r.candidate)?.id).filter(r=>!!r))].sort();if(o.length===0)return;let n=new Map(o.map((r,i)=>[r,i])),d=[],c=D({line:0,column:0},e);for(let r of t){let i=s.get(r.candidate);i&&d.push({...c,source:n.get(i.id),originalLine:i.line,originalColumn:i.column}),c=D(c,r.css)}return{version:3,sources:o,names:[],mappings:se(d)}}function D(e,t){let s=t.split(`
|
|
3
|
+
`);return{line:e.line+s.length-1,column:s.at(-1).length+e.column*+(s.length===1)}}function se(e){let t=Array.from({length:Math.max(0,...e.map(r=>r.line))+1},()=>[]),s=0,o=0,n=0,d=0,c=0;for(let r of e)c*=+(r.line===d),d=r.line,t[r.line]?.push(`${P(r.column-c)}${P(r.source-s)}${P(r.originalLine-o)}${P(r.originalColumn-n)}`),c=r.column,s=r.source,o=r.originalLine,n=r.originalColumn;return t.map(r=>r.join(",")).join(";")}var ne="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function P(e){let t="",s=e<0?-e<<1|1:e<<1;do{let o=s&31;s>>>=5,s&&(o|=32),t+=ne[o]}while(s);return t}import{readFile as re}from"fs/promises";import{dirname as oe,isAbsolute as ae,normalize as ie,resolve as O,sep as B}from"path";async function M(e){return e.themeFile===void 0?e.theme:re(O(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.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 I(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 b(e,t){return E(e).replaceAll("[hash]",I(t))}function L(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${E(t).replaceAll(B,"/")}`}function F(e,t,s){return t.outdir?O(e,t.outdir,s):t.outfile?O(oe(O(e,t.outfile)),s):O(e,s)}function w(e){return e.split("?",1).join("")}function E(e){if(!e||ae(e))throw new Error("cssFileName must be a non-empty relative path.");let t=ie(e);if(t===".."||t.startsWith(`..${B}`))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 H(e,t,s){let o=e.getNativeBuildContext?.();if(!o||o.framework!=="webpack"&&o.framework!=="rspack")return;let n=o.loaderContext?._module;if(!n)return;let d=n.buildInfo??(n.buildInfo={});d[s]=t}function j(e,t,s,o,n,d,c,r){e.hooks.thisCompilation.tap("@cssxio/unplugin",i=>{i.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let l=[...i.modules].map(a=>le(a,d,c)),y=await S(l.some(a=>Object.keys(a.candidates).length>0)?l:[...c?.values()??[]],await s(),o,n,r);if(!y.css)return;let h=b(t,y.css);if(i.getAsset?.(h))throw new Error(`CSSX CSS asset collision at "${h}".`);if(i.emitAsset(h,new e.webpack.sources.RawSource(k(y,h))),y.map){let a=`${h}.map`;if(i.getAsset?.(a))throw new Error(`CSSX CSS map asset collision at "${a}".`);i.emitAsset(a,new e.webpack.sources.RawSource(R(y.map,h)))}})})}function le(e,t,s){let o=e.buildInfo?.[t];if(!o||typeof o!="object")return s?.get(e.resource?.split("?",1)[0]??"")??{id:"",candidates:{},composites:{},origins:{}};let{id:n,candidates:d,composites:c,atomicClasses:r,origins:i}=o;return{id:typeof n=="string"?n:"",candidates:d&&typeof d=="object"?d:{},composites:c&&typeof c=="object"?c:{},...Array.isArray(r)?{atomicClasses:r}:{},origins:i&&typeof i=="object"?i:{}}}import{transformAsync as de}from"@babel/core";import ce from"@cssxio/babel-plugin";import{compileUtilities as ue,createClassNameAllocator as me,createSelectorAliases as pe}from"@cssxio/compiler";var fe=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,ye=/\.astro(?:\?.*)?$/;async function v(e,t,s={},o){$(s);let n=s.importSource??"@cssxio/cssx";if(!fe.test(t)||!e.includes(n))return null;if(ye.test(t))return ge(e,t,s);let d=await M(s),c=await de(e,{babelrc:!1,configFile:!1,filename:t.split("?",1).join(""),parserOpts:{plugins:["jsx","typescript"]},plugins:[[ce,{importSource:n,classNameAllocator:s.classNameAllocator,theme:d,reusabilityBudget:s.reusabilityBudget,stableClassNames:s.stableClassNames,darkMode:s.darkMode}]],sourceMaps:!0,...o?{inputSourceMap:o}:{}}),r=c.metadata,{candidates:i,origins:l,composites:y,atomicClasses:h,cssOnlySignature:a}=r.cssx,f=Object.keys(i),u=f.length===0?"":(await ue(f,C=>i[C],d,pe(y),new Set(h),{darkMode:s.darkMode})).css;return{code:c.code,rules:u?[xe(Se(u,s.layer))]:[],candidates:i,composites:y,atomicClasses:h,origins:l,cssOnlySignature:a,map:c.map}}async function ge(e,t,s){let o=he(e);if(o.length===0)return null;let n=s.classNameAllocator??me(),d=s.importSource??"@cssxio/cssx",c={},r={},i=[],l=e;for(let y of[...o].reverse()){let h=await v(`import { sx } from ${JSON.stringify(d)};
|
|
4
|
+
const style = ${y.code};`,`${t}.ts`,{...s,classNameAllocator:n}),a=Ce(h.code);l=`${l.slice(0,y.start)}${a}${l.slice(y.end)}`,Object.assign(c,h.candidates),Object.assign(r,h.composites),i.push(...h.rules)}return{code:l,rules:i,candidates:c,composites:r,atomicClasses:[],origins:{},cssOnlySignature:l}}function he(e){let t=[],s=/\bsx\s*\(/g;for(let o of e.matchAll(s)){let n=o.index,d=e.indexOf("(",n),c=0,r="";for(let i=d;i<e.length;i+=1){let l=e[i];if(r){l==="\\"?i+=1:l===r&&(r="");continue}if(l==='"'||l==="'"||l==="`")r=l;else if(l==="(")c+=1;else if(l===")"&&--c===0){t.push({start:n,end:i+1,code:e.slice(n,i+1)}),s.lastIndex=i+1;break}}}return t}function Ce(e){let t="const style = ",s=e.indexOf(t)+t.length,o=e.indexOf(";",s);return e.slice(s,o)}function V(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 n=o;if(!(n.version!==3||!Array.isArray(n.sources)||typeof n.mappings!="string"))return{version:n.version,sources:[...n.sources],names:[...n.names??[]],mappings:n.mappings,file:n.file??t.split("?",1).join(""),...n.sourceRoot?{sourceRoot:n.sourceRoot}:{},...n.sourcesContent?{sourcesContent:[...n.sourcesContent]}:{}}}function xe(e){return{className:`cssx-${I(e)}`,css:e}}function Se(e,t){return e&&t?`@layer ${t}{${e}}`:e}function T(e,t,s=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:s}]})}import{Buffer as _}from"buffer";import{mkdir as we,readFile as be,realpath as ke,unlink as W,writeFile as X}from"fs/promises";import{basename as q,dirname as Me,resolve as G}from"path";import{createClassNameAllocator as ve}from"@cssxio/compiler";var Re=/\.[cm]?[jt]sx?$/;function J(e={}){let t=new Map,s=ve(),o,n;return{name:"@cssxio/unplugin",setup(d){let c=d.initialOptions.absWorkingDir??process.cwd();d.initialOptions.metafile=!0,d.onLoad({filter:Re},async({path:r})=>{let i=await be(r,"utf8"),l=await v(i,r,{...e,classNameAllocator:s});if(!l)return;let y=await z(r);return t.set(y,{id:y,candidates:l.candidates,composites:l.composites,atomicClasses:l.atomicClasses,origins:l.origins}),{contents:l.code,loader:Ae(r)}}),d.onEnd(async r=>{if(!r.metafile)return;let i=new Set(await Promise.all(Object.keys(r.metafile.inputs).map(u=>z(G(c,u)))));for(let u of t.keys())i.has(u)||t.delete(u);let l=await Oe([...t],e),y=F(c,d.initialOptions,b(e.cssFileName??"cssx.css",l.css));if(!l.css){o&&await W(o).catch(()=>{}),n&&await W(n).catch(()=>{}),o=void 0,n=void 0;return}let h=l.map?`${l.css}
|
|
5
|
+
/*# sourceMappingURL=${q(y)}.map */`:l.css,a=`${y}.map`,f=l.map?JSON.stringify({...l.map,file:q(y)}):void 0;if(d.initialOptions.write===!1){if(!r.outputFiles)return;if(r.outputFiles.some(u=>u.path===y))throw new Error(`CSSX CSS asset collision at "${y}".`);r.outputFiles.push({path:y,contents:_.from(h),hash:"",text:h}),f&&r.outputFiles.push({path:a,contents:_.from(f),hash:"",text:f});return}await we(Me(y),{recursive:!0}),await X(y,h),f&&await X(a,f),o=y,n=f?a:void 0})}}}async function Oe(e,t){let s=await M(t);return S(e.map(([,o])=>o),s,t.layer,t.sourceMap??!0,t.darkMode)}function Ae(e){return/\.tsx?$/.test(e)?"ts":"js"}async function z(e){return ke(e).catch(()=>G(e))}var A="@cssxio/unplugin/rules",Te=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/;function Ue(e,t,s){let o=new Set;for(let n of t)e.moduleGraph?.invalidateModule(n,o,s,!0);for(let n of o){if(!n.id)continue;let d=e.runner?.evaluatedModules?.getModuleById(n.id);d&&e.runner?.evaluatedModules?.invalidateModule(d)}}function De(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:Be(e[A])}function Be(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:s,candidates:o,composites:n,atomicClasses:d,origins:c,cssOnlySignature:r}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(s)?s:[],candidates:o&&typeof o=="object"?o:{},composites:n&&typeof n=="object"?n:{},...Array.isArray(d)?{atomicClasses:d}:{},origins:c&&typeof c=="object"?c:{},cssOnlySignature:typeof r=="string"?r:""}}var He=(e={},t)=>{$(e);let s=e.cssFileName??"cssx.css",o=e.sourceMap??!0,n=new Map,d=Ne(),c=new Map,r,i=process.cwd(),l,y=()=>M(e),h=async function(a,f){let u=new Set(Object.values(f).flatMap(g=>g.type==="chunk"?Object.keys(g.modules??{}):[]).map(w));if(t.framework!=="vite")for(let g of n.keys())u.has(g)||n.delete(g);let C=t.framework==="vite"?[...n.values()]:[...u].map(g=>{let x=De(this.getModuleInfo(g)?.meta);return Object.keys(x.candidates).length>0?x:n.get(g)??x}),p=await S(C,await y(),e.layer,o,e.darkMode);if(!p.css)return;let m=b(s,p.css);if(Object.hasOwn(f,m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(this.emitFile({type:"asset",fileName:m,source:k(p,m)}),p.map){let g=`${m}.map`;if(Object.hasOwn(f,g))throw new Error(`CSSX CSS map asset collision at "${g}".`);this.emitFile({type:"asset",fileName:g,source:R(p.map,m)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Te},async handler(a,f){e.themeFile&&this.addWatchFile?.(U(process.cwd(),e.themeFile));let u=await v(a,f,{...e,classNameAllocator:d},V(this,f)),C={id:w(f),rules:u?.rules??[],candidates:u?.candidates??{},composites:u?.composites??{},atomicClasses:u?.atomicClasses??[],origins:u?.origins??{},cssOnlySignature:u?.cssOnlySignature??""};H(this,C,A);let p=w(f);(u||p===f)&&(n.set(p,C),c.set(U(i,p),C)),t.framework==="vite"&&l&&T(l,L("/",s));let m=u?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&u?`${m}
|
|
6
|
+
${Ve(s)}`:m,meta:{[A]:C},...u?.map?{map:u.map}:{}}}},watchChange(a,f){f.event==="delete"&&n.delete(w(a))},rollup:{generateBundle:h},vite:{generateBundle:h,configureServer(a){l=a;let f=L(a.config.base,s),u=L("/",s);a.watcher?.on("unlink",C=>{n.delete(w(C)),T(a,u)}),a.middlewares.use((C,p,m)=>{let g=C.url?.split("?",1)[0];if(g!==f&&(g!==`${f}.map`||!o))return m();y().then(x=>S([...n.values()],x,e.layer,o,e.darkMode)).then(x=>{if(g===`${f}.map`){p.setHeader("Content-Type","application/json; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(x.map?R(x.map,s):"");return}p.setHeader("Content-Type","text/css; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(k(x,s))}).catch(x=>{p.setHeader("Content-Type","text/plain; charset=utf-8"),p.end(x instanceof Error?x.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let f=this.environment;if(!f||f.name==="client")return;let u=a.modules.filter(m=>{let g=n.get(w(m.id??""));return!!(g&&g.cssOnlySignature&&g.atomicClasses?.length===0)});if(u.length===0)return;let C=new Map(u.map(m=>[m,n.get(w(m.id)).cssOnlySignature]));for(let m of u)m.url&&await f.transformRequest(m.url);if(u.every(m=>{let g=n.get(w(m.id));return!!(g&&g.atomicClasses.length===0&&g.cssOnlySignature===C.get(m))}))return Ue(f,u,a.timestamp),a.modules.filter(m=>!u.includes(m))}}},...t.framework==="webpack"?{webpack(a){j(a,s,y,e.layer,o,A,n,e.darkMode)}}:{},...t.framework==="rspack"?{rspack(a){j(a,s,y,e.layer,o,A,n,e.darkMode)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let f=a.initialOptions.absWorkingDir??process.cwd();i=f,a.onEnd(async u=>{if(!u.metafile)return;let C=new Set(Object.keys(u.metafile.inputs).map(x=>U(f,x)));for(let x of c.keys())C.has(x)||c.delete(x);let p=await S([...c.values()],await y(),e.layer,o,e.darkMode),m=F(f,a.initialOptions,b(s,p.css));if(!p.css){r&&await Fe(r).catch(()=>{}),r=void 0;return}let g=k(p,Ee(m));if(a.initialOptions.write===!1){let x=u.outputFiles;if(!x)return;let K={path:m,contents:$e.from(g),hash:"",text:g};if(x.findIndex(Z=>Z.path===m)!==-1)throw new Error(`CSSX CSS asset collision at "${m}".`);x.push(K);return}await Le(je(m),{recursive:!0}),await Ie(m,g),r=m})}}}:{}}},N=Pe(He);function Ve(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 bt=N.vite,kt=N.rollup,Mt=N.webpack,vt=N.rspack,Rt=N;export{S as a,v as b,He as c,N as d,bt as e,kt as f,Mt as g,vt as h,Rt as i,J as j};
|
package/dist/esbuild.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";var le=Object.create;var I=Object.defineProperty;var de=Object.getOwnPropertyDescriptor;var ce=Object.getOwnPropertyNames;var ue=Object.getPrototypeOf,me=Object.prototype.hasOwnProperty;var pe=(e,t)=>{for(var s in t)I(e,s,{get:t[s],enumerable:!0})},q=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ce(t))!me.call(e,n)&&n!==s&&I(e,n,{get:()=>t[n],enumerable:!(o=de(t,n))||o.enumerable});return e};var fe=(e,t,s)=>(s=e!=null?le(ue(e)):{},q(t||!e||!e.__esModule?I(s,"default",{value:e,enumerable:!0}):s,e)),ye=e=>q(I({},"__esModule",{value:!0}),e);var je={};pe(je,{default:()=>oe});module.exports=ye(je);var X=require("buffer"),w=require("fs/promises"),v=require("path"),re=require("@cssxio/compiler");var ee=require("@cssxio/compiler"),te=require("unplugin"),se=require("buffer"),$=require("fs/promises"),M=require("path");var j=require("@cssxio/compiler"),G=require("path");async function b(e,t,s,o=!0,n){let d=Object.create(null),c=Object.create(null),r=new Set,i=!0,l=new Map;for(let C of[...e].sort((p,m)=>p.id.localeCompare(m.id))){for(let[p,m]of Object.entries(C.candidates))if(p in d||(d[p]=m),C.id&&!l.has(p)){let g=C.origins?.[p];l.set(p,{id:C.id,line:g?.line??0,column:g?.column??0})}for(let[p,m]of Object.entries(C.composites??{})){let g=c[p];if(g&&g.join(" ")!==m.join(" "))throw new Error(`CSSX composite class collision for "${p}".`);c[p]=m}C.atomicClasses===void 0&&(i=!1);for(let p of C.atomicClasses??[])r.add(p)}let y=Object.keys(d).sort();if(y.length===0)return{css:""};let h=await(0,j.compileUtilities)(y,C=>d[C],t,(0,j.createSelectorAliases)(c),i?r:void 0,{darkMode:n}),a=h.css&&s?`@layer ${s}{`:"",f=`${a}${h.css}${a?"}":""}`,u=o?ge(`${a}${h.prefixCss}`,h.entries,l):void 0;return{css:f,...u?{map:u}:{}}}function O(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${(0,G.basename)(t)}.map */`:e.css}function L(e,t){return JSON.stringify({...e,file:t})}function ge(e,t,s){let o=[...new Set(t.map(r=>s.get(r.candidate)?.id).filter(r=>!!r))].sort();if(o.length===0)return;let n=new Map(o.map((r,i)=>[r,i])),d=[],c=z({line:0,column:0},e);for(let r of t){let i=s.get(r.candidate);i&&d.push({...c,source:n.get(i.id),originalLine:i.line,originalColumn:i.column}),c=z(c,r.css)}return{version:3,sources:o,names:[],mappings:he(d)}}function z(e,t){let s=t.split(`
|
|
3
|
+
`);return{line:e.line+s.length-1,column:s.at(-1).length+e.column*+(s.length===1)}}function he(e){let t=Array.from({length:Math.max(0,...e.map(r=>r.line))+1},()=>[]),s=0,o=0,n=0,d=0,c=0;for(let r of e)c*=+(r.line===d),d=r.line,t[r.line]?.push(`${E(r.column-c)}${E(r.source-s)}${E(r.originalLine-o)}${E(r.originalColumn-n)}`),c=r.column,s=r.source,o=r.originalLine,n=r.originalColumn;return t.map(r=>r.join(",")).join(";")}var Ce="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function E(e){let t="",s=e<0?-e<<1|1:e<<1;do{let o=s&31;s>>>=5,s&&(o|=32),t+=Ce[o]}while(s);return t}var J=require("fs/promises"),S=require("path");async function A(e){return e.themeFile===void 0?e.theme:(0,J.readFile)((0,S.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.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.');V(e.cssFileName??"cssx.css")}function H(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 R(e,t){return V(e).replaceAll("[hash]",H(t))}function U(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${V(t).replaceAll(S.sep,"/")}`}function D(e,t,s){return t.outdir?(0,S.resolve)(e,t.outdir,s):t.outfile?(0,S.resolve)((0,S.dirname)((0,S.resolve)(e,t.outfile)),s):(0,S.resolve)(e,s)}function k(e){return e.split("?",1).join("")}function V(e){if(!e||(0,S.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let t=(0,S.normalize)(e);if(t===".."||t.startsWith(`..${S.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 K(e,t,s){let o=e.getNativeBuildContext?.();if(!o||o.framework!=="webpack"&&o.framework!=="rspack")return;let n=o.loaderContext?._module;if(!n)return;let d=n.buildInfo??(n.buildInfo={});d[s]=t}function _(e,t,s,o,n,d,c,r){e.hooks.thisCompilation.tap("@cssxio/unplugin",i=>{i.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let l=[...i.modules].map(a=>xe(a,d,c)),y=await b(l.some(a=>Object.keys(a.candidates).length>0)?l:[...c?.values()??[]],await s(),o,n,r);if(!y.css)return;let h=R(t,y.css);if(i.getAsset?.(h))throw new Error(`CSSX CSS asset collision at "${h}".`);if(i.emitAsset(h,new e.webpack.sources.RawSource(O(y,h))),y.map){let a=`${h}.map`;if(i.getAsset?.(a))throw new Error(`CSSX CSS map asset collision at "${a}".`);i.emitAsset(a,new e.webpack.sources.RawSource(L(y.map,h)))}})})}function xe(e,t,s){let o=e.buildInfo?.[t];if(!o||typeof o!="object")return s?.get(e.resource?.split("?",1)[0]??"")??{id:"",candidates:{},composites:{},origins:{}};let{id:n,candidates:d,composites:c,atomicClasses:r,origins:i}=o;return{id:typeof n=="string"?n:"",candidates:d&&typeof d=="object"?d:{},composites:c&&typeof c=="object"?c:{},...Array.isArray(r)?{atomicClasses:r}:{},origins:i&&typeof i=="object"?i:{}}}var Z=require("@babel/core"),Q=fe(require("@cssxio/babel-plugin"),1),N=require("@cssxio/compiler");var Se=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,we=/\.astro(?:\?.*)?$/;async function P(e,t,s={},o){T(s);let n=s.importSource??"@cssxio/cssx";if(!Se.test(t)||!e.includes(n))return null;if(we.test(t))return be(e,t,s);let d=await A(s),c=await(0,Z.transformAsync)(e,{babelrc:!1,configFile:!1,filename:t.split("?",1).join(""),parserOpts:{plugins:["jsx","typescript"]},plugins:[[Q.default,{importSource:n,classNameAllocator:s.classNameAllocator,theme:d,reusabilityBudget:s.reusabilityBudget,stableClassNames:s.stableClassNames,darkMode:s.darkMode}]],sourceMaps:!0,...o?{inputSourceMap:o}:{}}),r=c.metadata,{candidates:i,origins:l,composites:y,atomicClasses:h,cssOnlySignature:a}=r.cssx,f=Object.keys(i),u=f.length===0?"":(await(0,N.compileUtilities)(f,C=>i[C],d,(0,N.createSelectorAliases)(y),new Set(h),{darkMode:s.darkMode})).css;return{code:c.code,rules:u?[ve(Re(u,s.layer))]:[],candidates:i,composites:y,atomicClasses:h,origins:l,cssOnlySignature:a,map:c.map}}async function be(e,t,s){let o=ke(e);if(o.length===0)return null;let n=s.classNameAllocator??(0,N.createClassNameAllocator)(),d=s.importSource??"@cssxio/cssx",c={},r={},i=[],l=e;for(let y of[...o].reverse()){let h=await P(`import { sx } from ${JSON.stringify(d)};
|
|
4
|
+
const style = ${y.code};`,`${t}.ts`,{...s,classNameAllocator:n}),a=Me(h.code);l=`${l.slice(0,y.start)}${a}${l.slice(y.end)}`,Object.assign(c,h.candidates),Object.assign(r,h.composites),i.push(...h.rules)}return{code:l,rules:i,candidates:c,composites:r,atomicClasses:[],origins:{},cssOnlySignature:l}}function ke(e){let t=[],s=/\bsx\s*\(/g;for(let o of e.matchAll(s)){let n=o.index,d=e.indexOf("(",n),c=0,r="";for(let i=d;i<e.length;i+=1){let l=e[i];if(r){l==="\\"?i+=1:l===r&&(r="");continue}if(l==='"'||l==="'"||l==="`")r=l;else if(l==="(")c+=1;else if(l===")"&&--c===0){t.push({start:n,end:i+1,code:e.slice(n,i+1)}),s.lastIndex=i+1;break}}}return t}function Me(e){let t="const style = ",s=e.indexOf(t)+t.length,o=e.indexOf(";",s);return e.slice(s,o)}function Y(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 n=o;if(!(n.version!==3||!Array.isArray(n.sources)||typeof n.mappings!="string"))return{version:n.version,sources:[...n.sources],names:[...n.names??[]],mappings:n.mappings,file:n.file??t.split("?",1).join(""),...n.sourceRoot?{sourceRoot:n.sourceRoot}:{},...n.sourcesContent?{sourcesContent:[...n.sourcesContent]}:{}}}function ve(e){return{className:`cssx-${H(e)}`,css:e}}function Re(e,t){return e&&t?`@layer ${t}{${e}}`:e}function W(e,t,s=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:s}]})}var F="@cssxio/unplugin/rules",Oe=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/;function Ae(e,t,s){let o=new Set;for(let n of t)e.moduleGraph?.invalidateModule(n,o,s,!0);for(let n of o){if(!n.id)continue;let d=e.runner?.evaluatedModules?.getModuleById(n.id);d&&e.runner?.evaluatedModules?.invalidateModule(d)}}function Ne(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:Pe(e[F])}function Pe(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:s,candidates:o,composites:n,atomicClasses:d,origins:c,cssOnlySignature:r}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(s)?s:[],candidates:o&&typeof o=="object"?o:{},composites:n&&typeof n=="object"?n:{},...Array.isArray(d)?{atomicClasses:d}:{},origins:c&&typeof c=="object"?c:{},cssOnlySignature:typeof r=="string"?r:""}}var $e=(e={},t)=>{T(e);let s=e.cssFileName??"cssx.css",o=e.sourceMap??!0,n=new Map,d=(0,ee.createClassNameAllocator)(),c=new Map,r,i=process.cwd(),l,y=()=>A(e),h=async function(a,f){let u=new Set(Object.values(f).flatMap(g=>g.type==="chunk"?Object.keys(g.modules??{}):[]).map(k));if(t.framework!=="vite")for(let g of n.keys())u.has(g)||n.delete(g);let C=t.framework==="vite"?[...n.values()]:[...u].map(g=>{let x=Ne(this.getModuleInfo(g)?.meta);return Object.keys(x.candidates).length>0?x:n.get(g)??x}),p=await b(C,await y(),e.layer,o,e.darkMode);if(!p.css)return;let m=R(s,p.css);if(Object.hasOwn(f,m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(this.emitFile({type:"asset",fileName:m,source:O(p,m)}),p.map){let g=`${m}.map`;if(Object.hasOwn(f,g))throw new Error(`CSSX CSS map asset collision at "${g}".`);this.emitFile({type:"asset",fileName:g,source:L(p.map,m)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:Oe},async handler(a,f){e.themeFile&&this.addWatchFile?.((0,M.resolve)(process.cwd(),e.themeFile));let u=await P(a,f,{...e,classNameAllocator:d},Y(this,f)),C={id:k(f),rules:u?.rules??[],candidates:u?.candidates??{},composites:u?.composites??{},atomicClasses:u?.atomicClasses??[],origins:u?.origins??{},cssOnlySignature:u?.cssOnlySignature??""};K(this,C,F);let p=k(f);(u||p===f)&&(n.set(p,C),c.set((0,M.resolve)(i,p),C)),t.framework==="vite"&&l&&W(l,U("/",s));let m=u?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&u?`${m}
|
|
5
|
+
${Le(s)}`:m,meta:{[F]:C},...u?.map?{map:u.map}:{}}}},watchChange(a,f){f.event==="delete"&&n.delete(k(a))},rollup:{generateBundle:h},vite:{generateBundle:h,configureServer(a){l=a;let f=U(a.config.base,s),u=U("/",s);a.watcher?.on("unlink",C=>{n.delete(k(C)),W(a,u)}),a.middlewares.use((C,p,m)=>{let g=C.url?.split("?",1)[0];if(g!==f&&(g!==`${f}.map`||!o))return m();y().then(x=>b([...n.values()],x,e.layer,o,e.darkMode)).then(x=>{if(g===`${f}.map`){p.setHeader("Content-Type","application/json; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(x.map?L(x.map,s):"");return}p.setHeader("Content-Type","text/css; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(O(x,s))}).catch(x=>{p.setHeader("Content-Type","text/plain; charset=utf-8"),p.end(x instanceof Error?x.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let f=this.environment;if(!f||f.name==="client")return;let u=a.modules.filter(m=>{let g=n.get(k(m.id??""));return!!(g&&g.cssOnlySignature&&g.atomicClasses?.length===0)});if(u.length===0)return;let C=new Map(u.map(m=>[m,n.get(k(m.id)).cssOnlySignature]));for(let m of u)m.url&&await f.transformRequest(m.url);if(u.every(m=>{let g=n.get(k(m.id));return!!(g&&g.atomicClasses.length===0&&g.cssOnlySignature===C.get(m))}))return Ae(f,u,a.timestamp),a.modules.filter(m=>!u.includes(m))}}},...t.framework==="webpack"?{webpack(a){_(a,s,y,e.layer,o,F,n,e.darkMode)}}:{},...t.framework==="rspack"?{rspack(a){_(a,s,y,e.layer,o,F,n,e.darkMode)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let f=a.initialOptions.absWorkingDir??process.cwd();i=f,a.onEnd(async u=>{if(!u.metafile)return;let C=new Set(Object.keys(u.metafile.inputs).map(x=>(0,M.resolve)(f,x)));for(let x of c.keys())C.has(x)||c.delete(x);let p=await b([...c.values()],await y(),e.layer,o,e.darkMode),m=D(f,a.initialOptions,R(s,p.css));if(!p.css){r&&await(0,$.unlink)(r).catch(()=>{}),r=void 0;return}let g=O(p,(0,M.basename)(m));if(a.initialOptions.write===!1){let x=u.outputFiles;if(!x)return;let ae={path:m,contents:se.Buffer.from(g),hash:"",text:g};if(x.findIndex(ie=>ie.path===m)!==-1)throw new Error(`CSSX CSS asset collision at "${m}".`);x.push(ae);return}await(0,$.mkdir)((0,M.dirname)(m),{recursive:!0}),await(0,$.writeFile)(m,g),r=m})}}}:{}}},B=(0,te.createUnplugin)($e);function Le(e){return`if (typeof document !== "undefined" && typeof module !== "undefined" && module.hot) {
|
|
6
|
+
const key = "__cssxStylesheetHmr";
|
|
7
|
+
const state = globalThis[key] || (globalThis[key] = { revision: 0, staged: [], replacements: [] });
|
|
8
|
+
const stylesheetLink = [...document.querySelectorAll('link[rel="stylesheet"]')].find((link) =>
|
|
9
|
+
new URL(link.href, document.baseURI).pathname.endsWith(${JSON.stringify(`/${e}`)}),
|
|
10
|
+
);
|
|
11
|
+
const nextLink = stylesheetLink && (() => {
|
|
12
|
+
const path = new URL(stylesheetLink.href, document.baseURI).pathname;
|
|
13
|
+
return path.includes("/_next/");
|
|
14
|
+
})();
|
|
15
|
+
if (!state.installed) {
|
|
16
|
+
state.installed = true;
|
|
17
|
+
state.stage = () => {
|
|
18
|
+
const revision = ++state.revision;
|
|
19
|
+
state.staged = [];
|
|
20
|
+
state.replacements = [];
|
|
21
|
+
const links = [...document.querySelectorAll('link[rel="stylesheet"]')].filter((link) =>
|
|
22
|
+
new URL(link.href, document.baseURI).pathname.endsWith(${JSON.stringify(`/${e}`)}),
|
|
23
|
+
);
|
|
24
|
+
return Promise.all(
|
|
25
|
+
links.map(
|
|
26
|
+
(link) =>
|
|
27
|
+
new Promise((resolve) => {
|
|
28
|
+
const replacement = link.cloneNode();
|
|
29
|
+
const url = new URL(link.href, document.baseURI);
|
|
30
|
+
url.searchParams.set("cssx", String(revision));
|
|
31
|
+
replacement.href = url.href;
|
|
32
|
+
const finish = (loaded) => {
|
|
33
|
+
replacement.removeEventListener("load", onLoad);
|
|
34
|
+
replacement.removeEventListener("error", onError);
|
|
35
|
+
if (loaded) {
|
|
36
|
+
state.staged.push(link);
|
|
37
|
+
if (state.removeOnLoad) link.remove();
|
|
38
|
+
}
|
|
39
|
+
else replacement.remove();
|
|
40
|
+
resolve();
|
|
41
|
+
};
|
|
42
|
+
const onLoad = () => finish(true);
|
|
43
|
+
const onError = () => finish(false);
|
|
44
|
+
replacement.addEventListener("load", onLoad);
|
|
45
|
+
replacement.addEventListener("error", onError);
|
|
46
|
+
state.replacements.push(replacement);
|
|
47
|
+
link.after(replacement);
|
|
48
|
+
}),
|
|
49
|
+
),
|
|
50
|
+
);
|
|
51
|
+
};
|
|
52
|
+
module.hot.addStatusHandler((status) => {
|
|
53
|
+
if (status === "prepare" || status === "dispose") {
|
|
54
|
+
return state.stage();
|
|
55
|
+
}
|
|
56
|
+
if (status === "idle") {
|
|
57
|
+
for (const link of state.staged) link.remove();
|
|
58
|
+
state.staged = [];
|
|
59
|
+
state.replacements = [];
|
|
60
|
+
}
|
|
61
|
+
if (status === "abort" || status === "fail") {
|
|
62
|
+
for (const replacement of state.replacements) replacement.remove();
|
|
63
|
+
state.staged = [];
|
|
64
|
+
state.replacements = [];
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
if (nextLink) module.hot.accept(() => void state.stage());
|
|
68
|
+
for (const updateKey of Object.getOwnPropertyNames(globalThis).filter((name) => name.startsWith("webpackHotUpdate"))) {
|
|
69
|
+
const update = globalThis[updateKey];
|
|
70
|
+
if (typeof update !== "function") continue;
|
|
71
|
+
globalThis[updateKey] = function (...args) {
|
|
72
|
+
void state.stage();
|
|
73
|
+
return update.apply(this, args);
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
if (stylesheetLink) {
|
|
77
|
+
state.removeOnLoad = Boolean(nextLink);
|
|
78
|
+
const refresh = async () => {
|
|
79
|
+
try {
|
|
80
|
+
const url = new URL(stylesheetLink.href, document.baseURI);
|
|
81
|
+
url.searchParams.set("cssx-probe", String(Date.now()));
|
|
82
|
+
const css = await fetch(url.href, { cache: "no-store" }).then((response) => response.text());
|
|
83
|
+
if (state.css && state.css !== css) void state.stage();
|
|
84
|
+
state.css = css;
|
|
85
|
+
} catch {
|
|
86
|
+
}
|
|
87
|
+
};
|
|
88
|
+
void refresh();
|
|
89
|
+
state.poll = setInterval(() => void refresh(), 500);
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}`}var Qe=B.vite,Ye=B.rollup,et=B.webpack,tt=B.rspack;var Fe=/\.[cm]?[jt]sx?$/;function oe(e={}){let t=new Map,s=(0,re.createClassNameAllocator)(),o,n;return{name:"@cssxio/unplugin",setup(d){let c=d.initialOptions.absWorkingDir??process.cwd();d.initialOptions.metafile=!0,d.onLoad({filter:Fe},async({path:r})=>{let i=await(0,w.readFile)(r,"utf8"),l=await P(i,r,{...e,classNameAllocator:s});if(!l)return;let y=await ne(r);return t.set(y,{id:y,candidates:l.candidates,composites:l.composites,atomicClasses:l.atomicClasses,origins:l.origins}),{contents:l.code,loader:Ee(r)}}),d.onEnd(async r=>{if(!r.metafile)return;let i=new Set(await Promise.all(Object.keys(r.metafile.inputs).map(u=>ne((0,v.resolve)(c,u)))));for(let u of t.keys())i.has(u)||t.delete(u);let l=await Ie([...t],e),y=D(c,d.initialOptions,R(e.cssFileName??"cssx.css",l.css));if(!l.css){o&&await(0,w.unlink)(o).catch(()=>{}),n&&await(0,w.unlink)(n).catch(()=>{}),o=void 0,n=void 0;return}let h=l.map?`${l.css}
|
|
93
|
+
/*# sourceMappingURL=${(0,v.basename)(y)}.map */`:l.css,a=`${y}.map`,f=l.map?JSON.stringify({...l.map,file:(0,v.basename)(y)}):void 0;if(d.initialOptions.write===!1){if(!r.outputFiles)return;if(r.outputFiles.some(u=>u.path===y))throw new Error(`CSSX CSS asset collision at "${y}".`);r.outputFiles.push({path:y,contents:X.Buffer.from(h),hash:"",text:h}),f&&r.outputFiles.push({path:a,contents:X.Buffer.from(f),hash:"",text:f});return}await(0,w.mkdir)((0,v.dirname)(y),{recursive:!0}),await(0,w.writeFile)(y,h),f&&await(0,w.writeFile)(a,f),o=y,n=f?a:void 0})}}}async function Ie(e,t){let s=await A(t);return b(e.map(([,o])=>o),s,t.layer,t.sourceMap??!0,t.darkMode)}function Ee(e){return/\.tsx?$/.test(e)?"ts":"js"}async function ne(e){return(0,w.realpath)(e).catch(()=>(0,v.resolve)(e))}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild';
|
|
2
|
+
import { C as CssxPluginOptions } from './options-CHY4_3I-.cjs';
|
|
3
|
+
import '@cssxio/compiler';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates the CSSX adapter for esbuild. It enables the metafile, transforms matching source files,
|
|
7
|
+
* then emits CSS after esbuild finishes. With `write: false`, CSS and its source map are added to
|
|
8
|
+
* `outputFiles`; otherwise they are written beside esbuild's configured output.
|
|
9
|
+
*
|
|
10
|
+
* @param options Adapter options.
|
|
11
|
+
* @returns An esbuild plugin.
|
|
12
|
+
*/
|
|
13
|
+
declare function cssxEsbuild(options?: CssxPluginOptions): Plugin;
|
|
14
|
+
|
|
15
|
+
export { cssxEsbuild as default };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from 'esbuild';
|
|
2
|
+
import { C as CssxPluginOptions } from './options-CHY4_3I-.js';
|
|
3
|
+
import '@cssxio/compiler';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Creates the CSSX adapter for esbuild. It enables the metafile, transforms matching source files,
|
|
7
|
+
* then emits CSS after esbuild finishes. With `write: false`, CSS and its source map are added to
|
|
8
|
+
* `outputFiles`; otherwise they are written beside esbuild's configured output.
|
|
9
|
+
*
|
|
10
|
+
* @param options Adapter options.
|
|
11
|
+
* @returns An esbuild plugin.
|
|
12
|
+
*/
|
|
13
|
+
declare function cssxEsbuild(options?: CssxPluginOptions): Plugin;
|
|
14
|
+
|
|
15
|
+
export { cssxEsbuild as default };
|
package/dist/esbuild.js
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{j as a}from"./chunk-NTRHNWKR.js";export{a as default};
|
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
"use strict";var de=Object.create;var E=Object.defineProperty;var ce=Object.getOwnPropertyDescriptor;var ue=Object.getOwnPropertyNames;var me=Object.getPrototypeOf,pe=Object.prototype.hasOwnProperty;var fe=(e,t)=>{for(var s in t)E(e,s,{get:t[s],enumerable:!0})},z=(e,t,s,o)=>{if(t&&typeof t=="object"||typeof t=="function")for(let n of ue(t))!pe.call(e,n)&&n!==s&&E(e,n,{get:()=>t[n],enumerable:!(o=ce(t,n))||o.enumerable});return e};var ye=(e,t,s)=>(s=e!=null?de(me(e)):{},z(t||!e||!e.__esModule?E(s,"default",{value:e,enumerable:!0}):s,e)),ge=e=>z(E({},"__esModule",{value:!0}),e);var He={};fe(He,{compileCssxStylesheet:()=>b,default:()=>Be,esbuild:()=>q,rollup:()=>Te,rspack:()=>De,transformCssxModule:()=>O,unplugin:()=>L,unpluginFactory:()=>ae,vite:()=>je,webpack:()=>Ue});module.exports=ge(He);var ne=require("@cssxio/compiler"),re=require("unplugin"),oe=require("buffer"),$=require("fs/promises"),v=require("path");var T=require("@cssxio/compiler"),J=require("path");async function b(e,t,s,o=!0,n){let d=Object.create(null),c=Object.create(null),r=new Set,i=!0,l=new Map;for(let C of[...e].sort((p,m)=>p.id.localeCompare(m.id))){for(let[p,m]of Object.entries(C.candidates))if(p in d||(d[p]=m),C.id&&!l.has(p)){let g=C.origins?.[p];l.set(p,{id:C.id,line:g?.line??0,column:g?.column??0})}for(let[p,m]of Object.entries(C.composites??{})){let g=c[p];if(g&&g.join(" ")!==m.join(" "))throw new Error(`CSSX composite class collision for "${p}".`);c[p]=m}C.atomicClasses===void 0&&(i=!1);for(let p of C.atomicClasses??[])r.add(p)}let y=Object.keys(d).sort();if(y.length===0)return{css:""};let h=await(0,T.compileUtilities)(y,C=>d[C],t,(0,T.createSelectorAliases)(c),i?r:void 0,{darkMode:n}),a=h.css&&s?`@layer ${s}{`:"",f=`${a}${h.css}${a?"}":""}`,u=o?he(`${a}${h.prefixCss}`,h.entries,l):void 0;return{css:f,...u?{map:u}:{}}}function A(e,t){return e.map?`${e.css}
|
|
2
|
+
/*# sourceMappingURL=${(0,J.basename)(t)}.map */`:e.css}function F(e,t){return JSON.stringify({...e,file:t})}function he(e,t,s){let o=[...new Set(t.map(r=>s.get(r.candidate)?.id).filter(r=>!!r))].sort();if(o.length===0)return;let n=new Map(o.map((r,i)=>[r,i])),d=[],c=G({line:0,column:0},e);for(let r of t){let i=s.get(r.candidate);i&&d.push({...c,source:n.get(i.id),originalLine:i.line,originalColumn:i.column}),c=G(c,r.css)}return{version:3,sources:o,names:[],mappings:Ce(d)}}function G(e,t){let s=t.split(`
|
|
3
|
+
`);return{line:e.line+s.length-1,column:s.at(-1).length+e.column*+(s.length===1)}}function Ce(e){let t=Array.from({length:Math.max(0,...e.map(r=>r.line))+1},()=>[]),s=0,o=0,n=0,d=0,c=0;for(let r of e)c*=+(r.line===d),d=r.line,t[r.line]?.push(`${j(r.column-c)}${j(r.source-s)}${j(r.originalLine-o)}${j(r.originalColumn-n)}`),c=r.column,s=r.source,o=r.originalLine,n=r.originalColumn;return t.map(r=>r.join(",")).join(";")}var xe="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";function j(e){let t="",s=e<0?-e<<1|1:e<<1;do{let o=s&31;s>>>=5,s&&(o|=32),t+=xe[o]}while(s);return t}var K=require("fs/promises"),S=require("path");async function N(e){return e.themeFile===void 0?e.theme:(0,K.readFile)((0,S.resolve)(process.cwd(),e.themeFile),"utf8")}function U(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.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.');V(e.cssFileName??"cssx.css")}function H(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 R(e,t){return V(e).replaceAll("[hash]",H(t))}function D(e,t){return`${e&&e!=="/"?`/${e.replace(/^\/+|\/+$/g,"")}`:""}/${V(t).replaceAll(S.sep,"/")}`}function B(e,t,s){return t.outdir?(0,S.resolve)(e,t.outdir,s):t.outfile?(0,S.resolve)((0,S.dirname)((0,S.resolve)(e,t.outfile)),s):(0,S.resolve)(e,s)}function k(e){return e.split("?",1).join("")}function V(e){if(!e||(0,S.isAbsolute)(e))throw new Error("cssFileName must be a non-empty relative path.");let t=(0,S.normalize)(e);if(t===".."||t.startsWith(`..${S.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 Z(e,t,s){let o=e.getNativeBuildContext?.();if(!o||o.framework!=="webpack"&&o.framework!=="rspack")return;let n=o.loaderContext?._module;if(!n)return;let d=n.buildInfo??(n.buildInfo={});d[s]=t}function _(e,t,s,o,n,d,c,r){e.hooks.thisCompilation.tap("@cssxio/unplugin",i=>{i.hooks.processAssets.tapPromise({name:"@cssxio/unplugin",stage:e.webpack.Compilation.PROCESS_ASSETS_STAGE_ADDITIONS},async()=>{let l=[...i.modules].map(a=>Se(a,d,c)),y=await b(l.some(a=>Object.keys(a.candidates).length>0)?l:[...c?.values()??[]],await s(),o,n,r);if(!y.css)return;let h=R(t,y.css);if(i.getAsset?.(h))throw new Error(`CSSX CSS asset collision at "${h}".`);if(i.emitAsset(h,new e.webpack.sources.RawSource(A(y,h))),y.map){let a=`${h}.map`;if(i.getAsset?.(a))throw new Error(`CSSX CSS map asset collision at "${a}".`);i.emitAsset(a,new e.webpack.sources.RawSource(F(y.map,h)))}})})}function Se(e,t,s){let o=e.buildInfo?.[t];if(!o||typeof o!="object")return s?.get(e.resource?.split("?",1)[0]??"")??{id:"",candidates:{},composites:{},origins:{}};let{id:n,candidates:d,composites:c,atomicClasses:r,origins:i}=o;return{id:typeof n=="string"?n:"",candidates:d&&typeof d=="object"?d:{},composites:c&&typeof c=="object"?c:{},...Array.isArray(r)?{atomicClasses:r}:{},origins:i&&typeof i=="object"?i:{}}}var Q=require("@babel/core"),Y=ye(require("@cssxio/babel-plugin"),1),P=require("@cssxio/compiler");var we=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/,be=/\.astro(?:\?.*)?$/;async function O(e,t,s={},o){U(s);let n=s.importSource??"@cssxio/cssx";if(!we.test(t)||!e.includes(n))return null;if(be.test(t))return ke(e,t,s);let d=await N(s),c=await(0,Q.transformAsync)(e,{babelrc:!1,configFile:!1,filename:t.split("?",1).join(""),parserOpts:{plugins:["jsx","typescript"]},plugins:[[Y.default,{importSource:n,classNameAllocator:s.classNameAllocator,theme:d,reusabilityBudget:s.reusabilityBudget,stableClassNames:s.stableClassNames,darkMode:s.darkMode}]],sourceMaps:!0,...o?{inputSourceMap:o}:{}}),r=c.metadata,{candidates:i,origins:l,composites:y,atomicClasses:h,cssOnlySignature:a}=r.cssx,f=Object.keys(i),u=f.length===0?"":(await(0,P.compileUtilities)(f,C=>i[C],d,(0,P.createSelectorAliases)(y),new Set(h),{darkMode:s.darkMode})).css;return{code:c.code,rules:u?[Re(Oe(u,s.layer))]:[],candidates:i,composites:y,atomicClasses:h,origins:l,cssOnlySignature:a,map:c.map}}async function ke(e,t,s){let o=Me(e);if(o.length===0)return null;let n=s.classNameAllocator??(0,P.createClassNameAllocator)(),d=s.importSource??"@cssxio/cssx",c={},r={},i=[],l=e;for(let y of[...o].reverse()){let h=await O(`import { sx } from ${JSON.stringify(d)};
|
|
4
|
+
const style = ${y.code};`,`${t}.ts`,{...s,classNameAllocator:n}),a=ve(h.code);l=`${l.slice(0,y.start)}${a}${l.slice(y.end)}`,Object.assign(c,h.candidates),Object.assign(r,h.composites),i.push(...h.rules)}return{code:l,rules:i,candidates:c,composites:r,atomicClasses:[],origins:{},cssOnlySignature:l}}function Me(e){let t=[],s=/\bsx\s*\(/g;for(let o of e.matchAll(s)){let n=o.index,d=e.indexOf("(",n),c=0,r="";for(let i=d;i<e.length;i+=1){let l=e[i];if(r){l==="\\"?i+=1:l===r&&(r="");continue}if(l==='"'||l==="'"||l==="`")r=l;else if(l==="(")c+=1;else if(l===")"&&--c===0){t.push({start:n,end:i+1,code:e.slice(n,i+1)}),s.lastIndex=i+1;break}}}return t}function ve(e){let t="const style = ",s=e.indexOf(t)+t.length,o=e.indexOf(";",s);return e.slice(s,o)}function ee(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 n=o;if(!(n.version!==3||!Array.isArray(n.sources)||typeof n.mappings!="string"))return{version:n.version,sources:[...n.sources],names:[...n.names??[]],mappings:n.mappings,file:n.file??t.split("?",1).join(""),...n.sourceRoot?{sourceRoot:n.sourceRoot}:{},...n.sourcesContent?{sourcesContent:[...n.sourcesContent]}:{}}}function Re(e){return{className:`cssx-${H(e)}`,css:e}}function Oe(e,t){return e&&t?`@layer ${t}{${e}}`:e}function W(e,t,s=Date.now()){e.ws.send({type:"update",updates:[{type:"css-update",path:t,acceptedPath:t,timestamp:s}]})}var X=require("buffer"),w=require("fs/promises"),M=require("path"),se=require("@cssxio/compiler");var Ae=/\.[cm]?[jt]sx?$/;function q(e={}){let t=new Map,s=(0,se.createClassNameAllocator)(),o,n;return{name:"@cssxio/unplugin",setup(d){let c=d.initialOptions.absWorkingDir??process.cwd();d.initialOptions.metafile=!0,d.onLoad({filter:Ae},async({path:r})=>{let i=await(0,w.readFile)(r,"utf8"),l=await O(i,r,{...e,classNameAllocator:s});if(!l)return;let y=await te(r);return t.set(y,{id:y,candidates:l.candidates,composites:l.composites,atomicClasses:l.atomicClasses,origins:l.origins}),{contents:l.code,loader:Pe(r)}}),d.onEnd(async r=>{if(!r.metafile)return;let i=new Set(await Promise.all(Object.keys(r.metafile.inputs).map(u=>te((0,M.resolve)(c,u)))));for(let u of t.keys())i.has(u)||t.delete(u);let l=await Ne([...t],e),y=B(c,d.initialOptions,R(e.cssFileName??"cssx.css",l.css));if(!l.css){o&&await(0,w.unlink)(o).catch(()=>{}),n&&await(0,w.unlink)(n).catch(()=>{}),o=void 0,n=void 0;return}let h=l.map?`${l.css}
|
|
5
|
+
/*# sourceMappingURL=${(0,M.basename)(y)}.map */`:l.css,a=`${y}.map`,f=l.map?JSON.stringify({...l.map,file:(0,M.basename)(y)}):void 0;if(d.initialOptions.write===!1){if(!r.outputFiles)return;if(r.outputFiles.some(u=>u.path===y))throw new Error(`CSSX CSS asset collision at "${y}".`);r.outputFiles.push({path:y,contents:X.Buffer.from(h),hash:"",text:h}),f&&r.outputFiles.push({path:a,contents:X.Buffer.from(f),hash:"",text:f});return}await(0,w.mkdir)((0,M.dirname)(y),{recursive:!0}),await(0,w.writeFile)(y,h),f&&await(0,w.writeFile)(a,f),o=y,n=f?a:void 0})}}}async function Ne(e,t){let s=await N(t);return b(e.map(([,o])=>o),s,t.layer,t.sourceMap??!0,t.darkMode)}function Pe(e){return/\.tsx?$/.test(e)?"ts":"js"}async function te(e){return(0,w.realpath)(e).catch(()=>(0,M.resolve)(e))}var I="@cssxio/unplugin/rules",$e=/\.(?:[cm]?[jt]sx?|astro)(?:\?.*)?$/;function Le(e,t,s){let o=new Set;for(let n of t)e.moduleGraph?.invalidateModule(n,o,s,!0);for(let n of o){if(!n.id)continue;let d=e.runner?.evaluatedModules?.getModuleById(n.id);d&&e.runner?.evaluatedModules?.invalidateModule(d)}}function Fe(e){return!e||typeof e!="object"?{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""}:Ie(e[I])}function Ie(e){if(!e||typeof e!="object")return{id:"",rules:[],candidates:{},composites:{},origins:{},cssOnlySignature:""};let{id:t,rules:s,candidates:o,composites:n,atomicClasses:d,origins:c,cssOnlySignature:r}=e;return{id:typeof t=="string"?t:"",rules:Array.isArray(s)?s:[],candidates:o&&typeof o=="object"?o:{},composites:n&&typeof n=="object"?n:{},...Array.isArray(d)?{atomicClasses:d}:{},origins:c&&typeof c=="object"?c:{},cssOnlySignature:typeof r=="string"?r:""}}var ae=(e={},t)=>{U(e);let s=e.cssFileName??"cssx.css",o=e.sourceMap??!0,n=new Map,d=(0,ne.createClassNameAllocator)(),c=new Map,r,i=process.cwd(),l,y=()=>N(e),h=async function(a,f){let u=new Set(Object.values(f).flatMap(g=>g.type==="chunk"?Object.keys(g.modules??{}):[]).map(k));if(t.framework!=="vite")for(let g of n.keys())u.has(g)||n.delete(g);let C=t.framework==="vite"?[...n.values()]:[...u].map(g=>{let x=Fe(this.getModuleInfo(g)?.meta);return Object.keys(x.candidates).length>0?x:n.get(g)??x}),p=await b(C,await y(),e.layer,o,e.darkMode);if(!p.css)return;let m=R(s,p.css);if(Object.hasOwn(f,m))throw new Error(`CSSX CSS asset collision at "${m}".`);if(this.emitFile({type:"asset",fileName:m,source:A(p,m)}),p.map){let g=`${m}.map`;if(Object.hasOwn(f,g))throw new Error(`CSSX CSS map asset collision at "${g}".`);this.emitFile({type:"asset",fileName:g,source:F(p.map,m)})}};return{name:"@cssxio/unplugin",enforce:"pre",transform:{filter:{id:$e},async handler(a,f){e.themeFile&&this.addWatchFile?.((0,v.resolve)(process.cwd(),e.themeFile));let u=await O(a,f,{...e,classNameAllocator:d},ee(this,f)),C={id:k(f),rules:u?.rules??[],candidates:u?.candidates??{},composites:u?.composites??{},atomicClasses:u?.atomicClasses??[],origins:u?.origins??{},cssOnlySignature:u?.cssOnlySignature??""};Z(this,C,I);let p=k(f);(u||p===f)&&(n.set(p,C),c.set((0,v.resolve)(i,p),C)),t.framework==="vite"&&l&&W(l,D("/",s));let m=u?.code??a;return{code:(t.framework==="webpack"||t.framework==="rspack")&&u?`${m}
|
|
6
|
+
${Ee(s)}`:m,meta:{[I]:C},...u?.map?{map:u.map}:{}}}},watchChange(a,f){f.event==="delete"&&n.delete(k(a))},rollup:{generateBundle:h},vite:{generateBundle:h,configureServer(a){l=a;let f=D(a.config.base,s),u=D("/",s);a.watcher?.on("unlink",C=>{n.delete(k(C)),W(a,u)}),a.middlewares.use((C,p,m)=>{let g=C.url?.split("?",1)[0];if(g!==f&&(g!==`${f}.map`||!o))return m();y().then(x=>b([...n.values()],x,e.layer,o,e.darkMode)).then(x=>{if(g===`${f}.map`){p.setHeader("Content-Type","application/json; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(x.map?F(x.map,s):"");return}p.setHeader("Content-Type","text/css; charset=utf-8"),p.setHeader("Cache-Control","no-store"),p.end(A(x,s))}).catch(x=>{p.setHeader("Content-Type","text/plain; charset=utf-8"),p.end(x instanceof Error?x.message:"Unable to compile CSSX development stylesheet.")})})},hotUpdate:{order:"pre",async handler(a){let f=this.environment;if(!f||f.name==="client")return;let u=a.modules.filter(m=>{let g=n.get(k(m.id??""));return!!(g&&g.cssOnlySignature&&g.atomicClasses?.length===0)});if(u.length===0)return;let C=new Map(u.map(m=>[m,n.get(k(m.id)).cssOnlySignature]));for(let m of u)m.url&&await f.transformRequest(m.url);if(u.every(m=>{let g=n.get(k(m.id));return!!(g&&g.atomicClasses.length===0&&g.cssOnlySignature===C.get(m))}))return Le(f,u,a.timestamp),a.modules.filter(m=>!u.includes(m))}}},...t.framework==="webpack"?{webpack(a){_(a,s,y,e.layer,o,I,n,e.darkMode)}}:{},...t.framework==="rspack"?{rspack(a){_(a,s,y,e.layer,o,I,n,e.darkMode)}}:{},...t.framework==="esbuild"?{esbuild:{config(a){a.metafile=!0},setup(a){let f=a.initialOptions.absWorkingDir??process.cwd();i=f,a.onEnd(async u=>{if(!u.metafile)return;let C=new Set(Object.keys(u.metafile.inputs).map(x=>(0,v.resolve)(f,x)));for(let x of c.keys())C.has(x)||c.delete(x);let p=await b([...c.values()],await y(),e.layer,o,e.darkMode),m=B(f,a.initialOptions,R(s,p.css));if(!p.css){r&&await(0,$.unlink)(r).catch(()=>{}),r=void 0;return}let g=A(p,(0,v.basename)(m));if(a.initialOptions.write===!1){let x=u.outputFiles;if(!x)return;let ie={path:m,contents:oe.Buffer.from(g),hash:"",text:g};if(x.findIndex(le=>le.path===m)!==-1)throw new Error(`CSSX CSS asset collision at "${m}".`);x.push(ie);return}await(0,$.mkdir)((0,v.dirname)(m),{recursive:!0}),await(0,$.writeFile)(m,g),r=m})}}}:{}}},L=(0,re.createUnplugin)(ae);function Ee(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 je=L.vite,Te=L.rollup,Ue=L.webpack,De=L.rspack,Be=L;0&&(module.exports={compileCssxStylesheet,esbuild,rollup,rspack,transformCssxModule,unplugin,unpluginFactory,vite,webpack});
|