@stacksjs/ts-css 0.1.3 → 0.3.1

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.
Files changed (57) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/ENGINE.md +677 -0
  3. package/PLUGIN.md +217 -0
  4. package/dist/bin/cli.js +33 -0
  5. package/dist/bin/cssx.js +405 -0
  6. package/dist/chunk-0h48763m.js +2 -0
  7. package/dist/chunk-br9jax0b.js +2 -0
  8. package/dist/chunk-f9gzb0a5.js +3 -0
  9. package/dist/chunk-genwkevp.js +3 -0
  10. package/dist/chunk-jj3s4ctf.js +62 -0
  11. package/dist/chunk-mz87cw2e.js +2 -0
  12. package/dist/engine/build.d.ts +26 -0
  13. package/dist/engine/color-modifier.d.ts +8 -0
  14. package/dist/engine/config.d.ts +5 -0
  15. package/dist/engine/format.d.ts +20 -0
  16. package/dist/engine/generator.d.ts +14 -0
  17. package/dist/engine/index.d.ts +13 -0
  18. package/dist/engine/index.js +653 -0
  19. package/dist/engine/parser.d.ts +68 -0
  20. package/dist/engine/plugin.d.ts +22 -0
  21. package/dist/engine/preflight-forms.d.ts +6 -0
  22. package/dist/engine/preflight.d.ts +3 -0
  23. package/dist/engine/rules-advanced.d.ts +27 -0
  24. package/dist/engine/rules-effects.d.ts +35 -0
  25. package/dist/engine/rules-forms.d.ts +8 -0
  26. package/dist/engine/rules-grid.d.ts +13 -0
  27. package/dist/engine/rules-icons.d.ts +2 -0
  28. package/dist/engine/rules-interactivity.d.ts +41 -0
  29. package/dist/engine/rules-layout.d.ts +28 -0
  30. package/dist/engine/rules-transforms.d.ts +35 -0
  31. package/dist/engine/rules-typography.d.ts +47 -0
  32. package/dist/engine/rules.d.ts +56 -0
  33. package/dist/engine/scanner.d.ts +16 -0
  34. package/dist/engine/style/api.d.ts +95 -0
  35. package/dist/engine/style/collect.d.ts +10 -0
  36. package/dist/engine/style/evaluate.d.ts +11 -0
  37. package/dist/engine/style/hash.d.ts +15 -0
  38. package/dist/engine/style/index.d.ts +56 -0
  39. package/dist/engine/style/plugin.d.ts +27 -0
  40. package/dist/engine/style/priority.d.ts +12 -0
  41. package/dist/engine/style/registry.d.ts +56 -0
  42. package/dist/engine/style/types.d.ts +54 -0
  43. package/dist/engine/style/value.d.ts +15 -0
  44. package/dist/engine/transformer-compile-class.d.ts +34 -0
  45. package/dist/engine/types.d.ts +156 -0
  46. package/dist/index.js +1 -60
  47. package/dist/optimize/index.js +1 -1
  48. package/dist/parse/index.js +1 -1
  49. package/dist/parse/list.d.ts +1 -1
  50. package/dist/select/index.js +1 -1
  51. package/dist/what/index.js +1 -1
  52. package/package.json +35 -19
  53. package/dist/chunk-1kmkypmr.js +0 -3
  54. package/dist/chunk-2wsah70r.js +0 -2
  55. package/dist/chunk-9ep6bwwb.js +0 -2
  56. package/dist/chunk-edwg811g.js +0 -2
  57. package/dist/chunk-thy3p95k.js +0 -3
package/PLUGIN.md ADDED
@@ -0,0 +1,217 @@
1
+ # Crosswind Bun Plugin
2
+
3
+ A Bun plugin that automatically generates and injects Crosswind CSS into your HTML files during the build process.
4
+
5
+ ## Installation
6
+
7
+ ```bash
8
+ bun add @ts-css/core
9
+ ```
10
+
11
+ ## Quick Start**1. Create your HTML file**(`src/template.html`)
12
+
13
+ ```html
14
+ <!DOCTYPE html>
15
+ <html>
16
+ <head>
17
+ <title>My App</title>
18
+ </head>
19
+ <body>
20
+ <div class="flex items-center p-4 bg-blue-500 text-white rounded-lg">
21
+ <h1 class="text-2xl font-bold">Hello Crosswind!</h1>
22
+ </div>
23
+ </body>
24
+ </html>
25
+ ```**2. Import it in your TypeScript**(`src/index.ts`):
26
+
27
+ ```typescript
28
+ import template from './template.html'
29
+
30
+ // The HTML now has Crosswind CSS injected
31
+ document.body.innerHTML = template
32
+ ```**3. Build with the plugin**:
33
+
34
+ ```typescript
35
+ import { plugin } from '@ts-css/core'
36
+
37
+ await Bun.build({
38
+ entrypoints: ['./src/index.ts'],
39
+ outdir: './dist',
40
+ plugins: [plugin()],
41
+ })
42
+ ```The plugin will automatically:
43
+
44
+ - Scan the HTML for utility classes
45
+ - Generate CSS for those classes
46
+ - Inject the CSS into the`<head>`section
47
+
48
+ ## Configuration
49
+
50
+ ### Basic Configuration```typescript
51
+
52
+ import { plugin } from '@ts-css/core'
53
+
54
+ await Bun.build({
55
+ entrypoints: ['./src/index.ts'],
56
+ outdir: './dist',
57
+ plugins: [
58
+ plugin({
59
+ includePreflight: true, // Include CSS reset (default: true)
60
+ }),
61
+ ],
62
+ })
63
+
64
+ ```### Custom Theme```typescript
65
+ import { plugin } from '@ts-css/core'
66
+
67
+ await Bun.build({
68
+ entrypoints: ['./src/index.ts'],
69
+ outdir: './dist',
70
+ plugins: [
71
+ plugin({
72
+ config: {
73
+ minify: true,
74
+ theme: {
75
+ colors: {
76
+ primary: '#3b82f6',
77
+ secondary: '#10b981',
78
+ danger: '#ef4444',
79
+ },
80
+ spacing: {
81
+ 18: '4.5rem',
82
+ 88: '22rem',
83
+ },
84
+ },
85
+ shortcuts: {
86
+ btn: 'px-4 py-2 rounded bg-primary text-white hover:bg-blue-600',
87
+ card: 'p-6 bg-white rounded-lg shadow-md',
88
+ },
89
+ },
90
+ }),
91
+ ],
92
+ })
93
+ ```### Advanced Configuration```typescript
94
+
95
+ import { plugin } from '@ts-css/core'
96
+
97
+ await Bun.build({
98
+ entrypoints: ['./src/index.ts'],
99
+ outdir: './dist',
100
+ plugins: [
101
+ plugin({
102
+ config: {
103
+ minify: true,
104
+ safelist: ['bg-red-500', 'text-green-500'], // Always include these
105
+ blocklist: ['debug-*'], // Never include these
106
+ theme: {
107
+ colors: {
108
+ brand: {
109
+ 50: '#f0f9ff',
110
+ 100: '#e0f2fe',
111
+ 500: '#0ea5e9',
112
+ 900: '#0c4a6e',
113
+ },
114
+ },
115
+ },
116
+ shortcuts: {
117
+ 'btn-primary': 'px-4 py-2 rounded bg-brand-500 text-white hover:bg-brand-600',
118
+ },
119
+ },
120
+ includePreflight: true,
121
+ }),
122
+ ],
123
+ })
124
+
125
+ ```## API Reference
126
+
127
+ ### `plugin(options?)`
128
+
129
+ Creates a Crosswind Bun plugin instance.
130
+
131
+ #### Options
132
+
133
+ -**`config`**(`Partial<TsCssConfig>`) - Custom Crosswind configuration
134
+
135
+ - `minify`- Minify the generated CSS
136
+
137
+ -`theme`- Custom theme (colors, spacing, fonts, etc.)
138
+ -`shortcuts`- Utility class shortcuts
139
+ -`safelist`- Classes to always include
140
+ -`blocklist`- Classes to never include
141
+ -`variants` - Enable/disable variants
142
+
143
+ - And more...
144
+
145
+ -**`includePreflight`**(`boolean`) - Include preflight CSS (default: `true`)
146
+
147
+ ## How It Works
148
+
149
+ 1. The plugin registers an `onLoad`handler for`.html`files
150
+ 2. When Bun encounters an HTML import, the plugin intercepts it
151
+ 3. It extracts all utility classes from the HTML using Crosswind's parser
152
+ 4. It generates CSS for those classes using Crosswind's generator
153
+ 5. The CSS is injected into the`<head>`section
154
+ 6. The processed HTML is returned to the bundle
155
+
156
+ ## Use Cases
157
+
158
+ -**SPAs**: Import HTML templates with automatic CSS generation
159
+ -**Web Components**: Load component templates with scoped styles
160
+ -**Static Sites**: Process HTML pages during build
161
+ -**Email Templates**: Generate inline CSS for email HTML
162
+
163
+ ## Examples
164
+
165
+ See the [examples/plugin](./examples/plugin) directory for a complete working example.
166
+
167
+ ## Comparison with CLI
168
+
169
+ | Feature | Plugin | CLI |
170
+ |---------|--------|-----|
171
+ | Automatic CSS generation | ✅ | ✅ |
172
+ | Watches files | ✅ (via Bun) | ✅ |
173
+ | Injects CSS | ✅ | ❌ |
174
+ | Separate CSS file | ❌ | ✅ |
175
+ | Build integration | ✅ | ❌ |
176
+ | Standalone usage | ❌ | ✅ |
177
+
178
+ ## Performance
179
+
180
+ The plugin is highly performant:
181
+
182
+ - Processes 1000 utilities in ~7ms
183
+ - Minimal overhead in build process
184
+ - Lazy loading - only processes imported HTML files
185
+
186
+ ## TypeScript Support
187
+
188
+ The plugin is fully typed. Import the types:```typescript
189
+ import type { TsCssPluginOptions } from '@ts-css/core'
190
+
191
+ const options: TsCssPluginOptions = {
192
+ config: {
193
+ minify: true,
194
+ },
195
+ }
196
+ ```## Configuration File
197
+
198
+ The plugin also respects`crosswind.config.ts`in your project root:```typescript
199
+ // crosswind.config.ts
200
+ import type { TsCssOptions } from '@ts-css/core'
201
+
202
+ export default {
203
+ minify: true,
204
+ theme: {
205
+ colors: {
206
+ primary: '#3b82f6',
207
+ },
208
+ },
209
+ } satisfies TsCssOptions
210
+
211
+ ```
212
+
213
+ The plugin will merge this config with any options passed to it.
214
+
215
+ ## License
216
+
217
+ MIT
@@ -0,0 +1,33 @@
1
+ #!/usr/bin/env bun
2
+ // @bun
3
+ import{existsSync as wt}from"fs";import de from"fs/promises";import We from"os";import me from"path";import j from"process";import{EventEmitter as xt}from"events";import V from"process";import je from"process";import ge from"process";import re from"process";import X from"process";import He from"tty";import hn,{stdin as wr,stdout as xr}from"process";class qe{configPath;config=null;events=[];retryCount=0;maxRetries=3;retryDelayMs=1000;constructor(){let e=We.homedir(),t=me.join(e,".config","clapp");this.configPath=me.join(t,"telemetry.json")}async isEnabled(){if(j.env.DO_NOT_TRACK==="1"||j.env.DO_NOT_TRACK==="true")return!1;if(j.env.NO_TELEMETRY==="1"||j.env.NO_TELEMETRY==="true")return!1;return(await this.loadConfig()).enabled}async enable(){let e=await this.loadConfig();if(e.enabled=!0,!e.userId)e.userId=this.generateUserId();await this.saveConfig(e)}async disable(){let e=await this.loadConfig();e.enabled=!1,await this.saveConfig(e)}async track(e,t){if(!await this.isEnabled())return;let r={event:e,...t,timestamp:Date.now(),platform:We.platform(),nodeVersion:j.version};if(this.events.push(r),this.events.length>=10)await this.send()}async trackCommand(e,t){await this.track("command",{command:e,duration:t})}async trackError(e,t){await this.track("error",{error:e,command:t})}async send(){if(!await this.isEnabled()||this.events.length===0)return!0;try{this.events=[],this.retryCount=0;let t=await this.loadConfig();return t.lastSent=Date.now(),await this.saveConfig(t),!0}catch{if(this.retryCount<this.maxRetries){this.retryCount++;let t=this.retryDelayMs*2**(this.retryCount-1);return await this.sleep(t),this.send()}return this.events=[],this.retryCount=0,!1}}async flush(){if(this.events.length===0)return!0;return this.send()}sleep(e){return new Promise((t)=>setTimeout(t,e))}async status(){let e=await this.loadConfig();return{enabled:e.enabled,doNotTrack:j.env.DO_NOT_TRACK==="1"||j.env.DO_NOT_TRACK==="true",eventsQueued:this.events.length,lastSent:e.lastSent}}async loadConfig(){if(this.config)return this.config;try{if(wt(this.configPath)){let e=await de.readFile(this.configPath,"utf-8");return this.config=JSON.parse(e),this.config}}catch{}return this.config={enabled:!1},this.config}async saveConfig(e){this.config=e;try{let t=me.dirname(this.configPath);await de.mkdir(t,{recursive:!0}),await de.writeFile(this.configPath,JSON.stringify(e,null,2),"utf-8")}catch{}}generateUserId(){let e=Math.random().toString(36).substring(2,15),t=Date.now().toString(36);return`${e}-${t}`}}var lr=new qe;function fe(e){return e.replace(/[<[].+/,"").trim()}function $t(e){let t=/<([^>]+)>/g,n=/\[([^\]]+)\]/g,r=[],s=(a)=>{let o=!1,c=a[1];if(c.startsWith("..."))c=c.slice(3),o=!0;else if(c.endsWith("..."))c=c.slice(0,-3),o=!0;return{required:a[0].startsWith("<"),value:c.trim(),variadic:o}},i;while(i=t.exec(e))r.push(s(i));let l;while(l=n.exec(e))r.push(s(l));return r}function St(e){let t={alias:{},boolean:[]};for(let[n,r]of e.entries()){if(r.names.length>1)t.alias[r.names[0]]=r.names.slice(1);if(r.isBoolean)if(r.negated){if(!e.some((i,l)=>l!==n&&i.names.some((a)=>r.names.includes(a))&&typeof i.required==="boolean"))t.boolean.push(r.names[0])}else t.boolean.push(r.names[0])}return t}function Fe(e){return e.reduce((t,n)=>t.length>=n.length?t:n,"")}function pe(e,t){return e.length>=t?e:`${e}${" ".repeat(t-e.length)}`}function ne(e){return e.replace(/([a-z])-([a-z])/g,(t,n,r)=>n+r.toUpperCase())}function kt(e,t,n){let r=0,s=t.length,i=e,l;for(;r<s;++r)l=i[t[r]],i=i[t[r]]=r===s-1?n:l!=null?l:!!~t[r+1].indexOf(".")||!(+t[r+1]>-1)?{}:[]}function Tt(e,t){for(let n of Object.keys(t)){let r=t[n];if(r.shouldTransform){if(e[n]=Array.prototype.concat.call([],e[n]),typeof r.transformFunction==="function")e[n]=e[n].map(r.transformFunction)}}}function At(e){let t=/([^\\/]+)$/.exec(e);return t?t[1]:""}function Z(e){return e.split(".").map((t,n)=>n===0?ne(t):t).join(".")}class ee extends Error{exitCode=2;isUsageError=!0;usage;constructor(e,t){super(e);if(this.name=this.constructor.name,t!==void 0)this.usage=t;if(typeof Error.captureStackTrace==="function")Error.captureStackTrace(this,this.constructor);else this.stack=Error(e).stack}format(e=!1){if(e&&this.stack)return`${this.message}
4
+
5
+ Stack trace:
6
+ ${this.stack}`;return this.message}}function Nt(e){if(e instanceof ee)return!0;return!!e&&typeof e==="object"&&e.name==="ClappError"&&typeof e.message==="string"}function It(){let{env:e}=je,{TERM:t,TERM_PROGRAM:n}=e;if(je.platform!=="win32")return t!=="linux";return Boolean(e.WT_SESSION)||Boolean(e.TERMINUS_SUBLIME)||e.ConEmuTask==="{cmd::Cmder}"||n==="Terminus-Sublime"||n==="vscode"||t==="xterm-256color"||t==="alacritty"||t==="rxvt-unicode"||t==="rxvt-unicode-256color"||e.TERMINAL_EMULATOR==="JetBrains-JediTerm"}var se="\x1B",w=`${se}[`;var Ue={to(e,t){if(!t)return`${w}${e+1}G`;return`${w}${t+1};${e+1}H`},move(e,t){let n="";if(e<0)n+=`${w}${-e}D`;else if(e>0)n+=`${w}${e}C`;if(t<0)n+=`${w}${-t}A`;else if(t>0)n+=`${w}${t}B`;return n},up:(e=1)=>`${w}${e}A`,down:(e=1)=>`${w}${e}B`,forward:(e=1)=>`${w}${e}C`,backward:(e=1)=>`${w}${e}D`,nextLine:(e=1)=>`${w}E`.repeat(e),prevLine:(e=1)=>`${w}F`.repeat(e),left:`${w}G`,hide:`${w}?25l`,show:`${w}?25h`,save:`${se}7`,restore:`${se}8`};var dr={screen:`${w}2J`,up:(e=1)=>`${w}1J`.repeat(e),down:(e=1)=>`${w}J`.repeat(e),line:`${w}2K`,lineEnd:`${w}K`,lineStart:`${w}1K`,lines(e){let t="";for(let n=0;n<e;n++)t+=this.line+(n<e-1?Ue.up():"");if(e)t+=Ue.left;return t}},mr={screen:`${se}c`};function Et(e,t){let n=[];for(let r=0;r<=t.length;r++)n[r]=[r];for(let r=0;r<=e.length;r++)n[0][r]=r;for(let r=1;r<=t.length;r++)for(let s=1;s<=e.length;s++)if(t.charAt(r-1)===e.charAt(s-1))n[r][s]=n[r-1][s-1];else n[r][s]=Math.min(n[r-1][s-1]+1,n[r][s-1]+1,n[r-1][s]+1);return n[t.length][e.length]}function Ge(e,t,n=2,r=3){return t.map((s)=>({cmd:s,distance:Et(e,s)})).filter(({distance:s})=>s<=n).sort((s,i)=>s.distance-i.distance).slice(0,r).map(({cmd:s})=>s)}function Ot(e,t={}){let n={_:[]},r=t.alias||{},s=new Set(t.boolean||[]),i={};for(let o of Object.keys(r))for(let c of r[o])i[c]=o;for(let o of s)if(r[o])for(let c of r[o])s.add(c);function l(o,c){if(o===void 0)return c;if(typeof c==="boolean")return c;return Array.isArray(o)?[...o,c]:[o,c]}function a(o,c){let h=i[o]||o,u=l(n[h],c);if(n[h]=u,r[h])for(let d of r[h])n[d]=u;if(i[o]&&r[i[o]])for(let d of r[i[o]])n[d]=u;n[o]=u}for(let o=0;o<e.length;o++){let c=e[o];if(c==="--"){n._.push(...e.slice(o+1));break}if(c.startsWith("--")){let h=c.indexOf("=");if(h!==-1){let u=ne(c.slice(2,h)),d=c.slice(h+1);a(u,d)}else{let u=c.slice(2);if(u.startsWith("no-")){let f=ne(u.slice(3));a(f,!1);continue}let d=ne(u),b=i[d]||d;if(s.has(b)||s.has(d))a(d,!0);else{let f=e[o+1];if(f!==void 0&&!f.startsWith("-"))a(d,f),o++;else a(d,!0)}}}else if(c.startsWith("-")&&c.length>1){let h=c.slice(1);for(let u=0;u<h.length;u++){let d=h[u],b=i[d]||d;if(u===h.length-1&&!s.has(b)&&!s.has(d)){let f=e[o+1];if(f!==void 0&&!f.startsWith("-"))a(d,f),o++;else a(d,!0)}else a(d,!0)}}else n._.push(c)}return n}class Ke{rawName;description;name;names;isBoolean;required;config;negated;variadic;constructor(e,t,n){if(this.rawName=e,this.description=t,this.config=Object.assign({},n),e=e.replace(/\.\*/g,""),this.negated=!1,this.variadic=/[<[](?:\.\.\.[^\]>]+|[^\]>]+\.\.\.)[\]>]/.test(e),this.names=fe(e).split(",").map((r)=>{let s=r.trim().replace(/^-{1,2}/,"");if(s.startsWith("no-"))this.negated=!0,s=s.replace(/^no-/,"");return Z(s)}).sort((r,s)=>r.length>s.length?1:-1),this.name=this.names[this.names.length-1],this.negated&&this.config.default==null)this.config.default=!0;if(e.includes("<"))this.required=!0;else if(e.includes("["))this.required=!1;else this.isBoolean=!0}}var fr=ge.argv,Lt=`${ge.platform}-${ge.arch} bun-v${typeof Bun<"u"?Bun.version:"unknown"}`,ze=re.argv,Pt=`${re.platform}-${re.arch} node-${re.version}`;class ye{rawName;description;config;cli;options;aliasNames;name;namespace;args;commandAction;usageText;versionNumber;examples;helpCallback;globalCommand;beforeHooks;afterHooks;middleware;constructor(e,t,n,r){this.rawName=e,this.description=t,this.config=n,this.cli=r,this.options=[],this.aliasNames=[],this.name=fe(e);let s=fe(e),i=s.indexOf(":");if(i>0)this.namespace=s.substring(0,i),this.name=s.substring(i+1);if(this.args=$t(e),this.examples=[],this.beforeHooks=[],this.afterHooks=[],this.middleware=[],!n)this.config={}}usage(e){return this.usageText=e,this}allowUnknownOptions(){return this.config.allowUnknownOptions=!0,this}ignoreOptionDefaultValue(){return this.config.ignoreOptionDefaultValue=!0,this}version(e,t="-v, --version"){return this.versionNumber=e,this.option(t,"Display version number"),this}example(e){return this.examples.push(e),this}option(e,t,n){let r=new Ke(e,t,n);return this.options.push(r),this}alias(e){return this.aliasNames.push(e),this}action(e){return this.commandAction=e,this}before(e){return this.beforeHooks.push(e),this}after(e){return this.afterHooks.push(e),this}use(e){return this.middleware.push(e),this}isMatched(e){if(this.aliasNames.includes(e))return!0;if(this.namespace)return`${this.namespace}:${this.name}`===e;return this.name===e}get isDefaultCommand(){return this.name===""||this.aliasNames.includes("!")}get isGlobalCommand(){return this instanceof be}get displayName(){return this.namespace?`${this.namespace}:${this.name}`:this.name}hasOption(e){let t=Z(e.split(".")[0]);return!!this.options.find((n)=>n.names.some((r)=>Z(r)===t))}outputHelp(){let{name:e,commands:t}=this.cli,{versionNumber:n,options:r,helpCallback:s}=this.cli.globalCommand,i=[{body:`${e}${n?`/${n}`:""}`}];if(i.push({title:"Usage",body:` $ ${e} ${this.usageText||this.rawName}`}),(this.isGlobalCommand||this.isDefaultCommand)&&t.length>0){let c=Fe(t.map((f)=>f.rawName)),h=new Map,u=[];for(let f of t)if(f.namespace){if(!h.has(f.namespace))h.set(f.namespace,[]);h.get(f.namespace).push(f)}else u.push(f);let d="";if(u.sort((f,_)=>f.rawName<_.rawName?-1:f.rawName>_.rawName?1:0),u.length>0)d+=u.map((f)=>` ${pe(f.rawName,c.length)} ${f.description}`).join(`
7
+ `);let b=Array.from(h.keys()).sort();for(let f of b){let _=h.get(f);if(d.length>0)d+=`
8
+
9
+ `;d+=` ${f}:
10
+ `,d+=_.map((T)=>` ${pe(T.rawName,c.length-2)} ${T.description}`).join(`
11
+ `)}i.push({title:"Commands",body:d}),i.push({body:`Run \`${e} <command> --help\` for command details.`})}let a=new Set(this.options.flatMap((c)=>c.names)),o=this.isGlobalCommand?r:[...this.options,...(r||[]).filter((c)=>!c.names.some((h)=>a.has(h)))];if(!this.isGlobalCommand&&!this.isDefaultCommand)o=o.filter((c)=>c.name!=="version");if(o.length>0){let c=Fe(o.map((h)=>h.rawName));i.push({title:"Options",body:o.map((h)=>` ${pe(h.rawName,c.length)} ${h.description} ${h.config.default===void 0?"":`(default: ${h.config.default})`}`).join(`
12
+ `)})}if(this.examples.length>0)i.push({title:"Examples",body:this.examples.map((c)=>{if(typeof c==="function")return c(e);return c}).join(`
13
+ `)});if(s)i=s(i)||i;console.log(i.map((c)=>c.title?`${c.title}:
14
+ ${c.body}`:c.body).join(`
15
+
16
+ `))}outputVersion(){let{name:e}=this.cli,{versionNumber:t}=this.cli.globalCommand;if(t)console.log(`${e}/${t} ${typeof Bun<"u"?Lt:Pt}`)}get usageLine(){return`$ ${this.cli.name} ${this.usageText||this.rawName}`}checkRequiredArgs(){let e=this.args.filter((t)=>t.required).length;if(this.cli.args.length<e){let n=this.args.filter((s)=>s.required).slice(this.cli.args.length),r=n.map((s)=>`<${s.value}>`).join(" ");throw new ee(`Missing required argument${n.length>1?"s":""}: ${r}
17
+
18
+ Run \`${this.cli.name} ${this.rawName} --help\` for usage information.`,this.usageLine)}}checkUnknownOptions(){let{options:e,globalCommand:t}=this.cli;if(!this.config.allowUnknownOptions){for(let n of Object.keys(e))if(n!=="--"&&!this.hasOption(n)&&!t.hasOption(n)){let s=[...t.options,...this.options].flatMap((c)=>c.names),i=Z(n.split(".")[0]),l=n.length>1?`--${n}`:`-${n}`,a=Ge(i,s),o=`Unknown option \`${l}\``;if(a.length>0)o+=`
19
+
20
+ Did you mean one of these?`,a.forEach((c)=>{let h=c.length>1?`--${c}`:`-${c}`;o+=`
21
+ \u2022 ${h}`});throw o+=`
22
+
23
+ Run \`${this.cli.name} ${this.rawName} --help\` to see available options.`,new ee(o,this.usageLine)}}}checkOptionValue(){let{options:e,globalCommand:t}=this.cli,n=[...t.options,...this.options];for(let r of n){let s=e[r.name.split(".")[0]];if(r.required){let i=n.some((l)=>l.negated&&l.names.includes(r.name));if(s===!0||s===!1&&!i)throw new ee(`Option \`${r.rawName}\` requires a value.
24
+
25
+ Example: ${this.cli.name} ${this.rawName} ${r.rawName} <value>`,this.usageLine)}}}}class be extends ye{constructor(e){super("@@global@@","",{},e)}}var Rt=ye,W={red:["\x1B[31m","\x1B[39m"],green:["\x1B[32m","\x1B[39m"],blue:["\x1B[34m","\x1B[39m"],yellow:["\x1B[33m","\x1B[39m"],cyan:["\x1B[36m","\x1B[39m"],magenta:["\x1B[35m","\x1B[39m"],white:["\x1B[37m","\x1B[39m"],gray:["\x1B[90m","\x1B[39m"],bgRed:["\x1B[41m","\x1B[49m"],bgGreen:["\x1B[42m","\x1B[49m"],bgBlue:["\x1B[44m","\x1B[49m"],bgYellow:["\x1B[43m","\x1B[49m"],bgCyan:["\x1B[46m","\x1B[49m"],bgMagenta:["\x1B[45m","\x1B[49m"],bold:["\x1B[1m","\x1B[22m"],italic:["\x1B[3m","\x1B[23m"],underline:["\x1B[4m","\x1B[24m"],dim:["\x1B[2m","\x1B[22m"],inverse:["\x1B[7m","\x1B[27m"],hidden:["\x1B[8m","\x1B[28m"],strikethrough:["\x1B[9m","\x1B[29m"]};var Q={primary:"blue",secondary:"cyan",success:"green",warning:"yellow",error:"red",info:"magenta",muted:"gray"};function _t(){return!0}function Bt(){let e={};e.supportsColor=_t();function t(r,s=[]){let i=r===""?[]:[...s,r],l=function(o){if(!e.supportsColor)return o;let c="",h="";for(let u of i)if(u in Q&&Q[u]in W){let d=Q[u];c+=W[d][0],h=W[d][1]+h}else if(u in W)c+=W[u][0],h=W[u][1]+h;return c+o+h},a=[...Object.keys(W),...Object.keys(Q)];for(let o of a)if(!(o in l))Object.defineProperty(l,o,{get(){return t(o,i)}});return l}let n=[...Object.keys(W),...Object.keys(Q)];for(let r of n)if(!(r in e))Object.defineProperty(e,r,{get(){return t(r)}});return e}var J=Bt();class Ce extends xt{name;commands;globalCommand;matchedCommand;matchedCommandName;rawArgs;args;options;showHelpOnExit;showVersionOnExit;enableDidYouMean=!0;signalHandlersSet=!1;isVerbose=!1;isQuiet=!1;isDebug=!1;isNoInteraction=!1;environment;isDryRun=!1;isForce=!1;useEmoji=!0;theme;isNoCache=!1;constructor(e=""){super();this.name=e,this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.globalCommand=new be(this),this.globalCommand.usage("<command> [options]")}handleSignals(e){if(this.signalHandlersSet)return this;let t=async(n)=>{if(console.log(`
26
+
27
+ Received ${n}, cleaning up...`),e)try{await e()}catch(r){console.error("Error during cleanup:",r)}V.exit(0)};return V.on("SIGINT",()=>t("SIGINT")),V.on("SIGTERM",()=>t("SIGTERM")),this.signalHandlersSet=!0,this}didYouMean(e=!0){return this.enableDidYouMean=e,this}verbose(){return this.globalCommand.option("-v, --verbose","Enable verbose output"),this}quiet(){return this.globalCommand.option("-q, --quiet","Suppress non-essential output"),this}debug(){return this.globalCommand.option("--debug","Enable debug mode with detailed error information"),this}noInteraction(){return this.globalCommand.option("-n, --no-interaction","Do not ask any interactive questions (for CI/CD)"),this}env(){return this.globalCommand.option("--env <environment>","Target environment (e.g., production, staging, local)"),this}dryRun(){return this.globalCommand.option("--dry-run","Preview actions without executing them"),this}force(){return this.globalCommand.option("-f, --force","Skip confirmation prompts"),this}emoji(){return this.globalCommand.option("--no-emoji","Disable emoji in output"),this}themes(){return this.globalCommand.option("--theme <theme>","Color theme (default, dracula, nord, solarized, monokai)"),this}cache(){return this.globalCommand.option("--no-cache","Disable caching"),this}usage(e){return this.globalCommand.usage(e),this}command(e,t,n){if(!n)n={};let r=new Rt(e,t||"",n,this);return r.globalCommand=this.globalCommand,this.commands.push(r),r}option(e,t,n){return this.globalCommand.option(e,t,n),this}help(e){return this.globalCommand.option("-h, --help","Display this message"),this.globalCommand.helpCallback=e,this.showHelpOnExit=!0,this}version(e,t="-v, --version"){return this.globalCommand.version(e,t),this.showVersionOnExit=!0,this}example(e){return this.globalCommand.example(e),this}outputHelp(){if(this.matchedCommand)this.matchedCommand.outputHelp();else this.globalCommand.outputHelp()}outputVersion(){this.globalCommand.outputVersion()}setParsedInfo({args:e,options:t},n,r){if(this.args=e,this.options=t,n)this.matchedCommand=n;if(r)this.matchedCommandName=r;return this}unsetMatchedCommand(){this.matchedCommand=void 0,this.matchedCommandName=void 0}showCommandNotFound(e){if(console.log(J.red(`
28
+ \u2717 Command "${e}" not found.
29
+ `)),this.enableDidYouMean){let t=[];for(let r of this.commands){if(r.displayName)t.push(r.displayName);if(r.aliasNames)t.push(...r.aliasNames)}let n=Ge(e,t);if(n.length>0)console.log(J.yellow("Did you mean one of these?")),n.forEach((r)=>console.log(` ${J.dim("\u2022")} ${this.name} ${r}`)),console.log("")}console.log(J.dim("Run"),`${this.name} --help`,J.dim("to see all available commands")),V.exit(1)}async parse(e=ze,t={}){let{run:n=!0,exitOnError:r=!1}=t;if(r)try{return await this.parse(e,{run:n})}catch(o){throw this.handleUsageError(o),o}if(this.rawArgs=e,!this.name)this.name=e[1]?At(e[1]):"cli";let s=!0,i=e.slice(2),l=i[0];if(l&&!l.startsWith("-")){for(let o of this.commands)if(o.isMatched(l)){let c=this.mri(i,o);s=!1;let h={...c,args:c.args.slice(1)};this.setParsedInfo(h,o,l),this.emit(`command:${l}`,o);break}if(s){let o=i[1];if(o&&!o.startsWith("-")){let c=`${l}:${o}`;for(let h of this.commands)if(h.isMatched(c)){let u=this.mri(i,h);s=!1;let d={...u,args:u.args.slice(2)};this.setParsedInfo(d,h,c),this.emit(`command:${c}`,h);break}}}}if(s){for(let o of this.commands)if(o.name===""){s=!1;let c=this.mri(i,o);this.setParsedInfo(c,o),this.emit("command:!",o);break}}if(s){let o=this.mri(e.slice(2));this.setParsedInfo(o)}if(this.options.verbose)this.isVerbose=!0;if(this.options.quiet)this.isQuiet=!0;if(this.options.debug)this.isDebug=!0;if(this.options.noInteraction||this.options.interaction===!1)this.isNoInteraction=!0;if(this.options.env)this.environment=String(this.options.env);if(this.options.dryRun)this.isDryRun=!0;if(this.options.force)this.isForce=!0;if(this.options.noEmoji||this.options.emoji===!1)this.useEmoji=!1;if(this.options.theme)this.theme=String(this.options.theme);if(this.options.noCache||this.options.cache===!1)this.isNoCache=!0;if(this.options.help&&this.showHelpOnExit)this.outputHelp(),n=!1,this.unsetMatchedCommand();if(this.options.version&&this.showVersionOnExit&&this.matchedCommandName==null)this.outputVersion(),n=!1,this.unsetMatchedCommand();let a={args:this.args,options:this.options};if(n)await this.runMatchedCommand();if(!this.matchedCommand&&this.args[0]){if(this.emit("command:*"),!(this.listenerCount("command:*")>0))this.showCommandNotFound(this.args[0])}return a}mri(e,t){let n=[...this.globalCommand.options,...t?t.options:[]],r=St(n),s=[],i=e.indexOf("--");if(i>-1)s=e.slice(i+1),e=e.slice(0,i);let l=Ot(e,r),a={_:l._};for(let d of Object.keys(l))if(d!=="_")a[Z(d)]=l[d];let o=a._,c={"--":s},h=t&&t.config.ignoreOptionDefaultValue?t.config.ignoreOptionDefaultValue:this.globalCommand.config.ignoreOptionDefaultValue,u=Object.create(null);for(let d of n){if(!h&&d.config.default!==void 0)for(let b of d.names)c[b]=d.config.default;if(Array.isArray(d.config.type)){if(u[d.name]===void 0)u[d.name]={shouldTransform:!0,transformFunction:d.config.type[0]}}}for(let d of Object.keys(a))if(d!=="_"){let b=d.split(".");kt(c,b,a[d]),Tt(c,u)}for(let d of n){if(!d.variadic)continue;for(let b of d.names){let f=c[b];if(f===void 0||Array.isArray(f))continue;if(d.config.default!==void 0&&f===d.config.default)continue;c[b]=[f]}}return{args:o,options:c}}async run(e=ze){return this.parse(e,{run:!0,exitOnError:!0})}handleUsageError(e){if(!Nt(e)||e.isUsageError===!1)return;let t=e.message||"command-line error",n=this.name?`${this.name}: `:"",r=/--help/.test(t)?"":e.usage?`
30
+ Usage: ${e.usage}`:`
31
+ Run \`${this.name??"cli"} --help\` for usage.`;V.stderr.write(`${n}${t}${r}
32
+ `),V.exit(e.exitCode??2)}async runMatchedCommand(){let{args:e,options:t,matchedCommand:n}=this;if(!n||!n.commandAction)return;n.checkUnknownOptions(),n.checkOptionValue(),n.checkRequiredArgs();let r=[];n.args.forEach((a,o)=>{if(a.variadic)r.push(e.slice(o));else r.push(e[o])}),r.push(t);let s={command:n,args:r,options:t};for(let a of n.beforeHooks)await a(s);let i,l=async()=>{let a=n.commandAction.apply(this,r);if(a instanceof Promise)i=await a;else i=a;return i};if(n.middleware.length>0){let a=0,o=async()=>{if(a<n.middleware.length){let c=n.middleware[a++];await c({...s,next:o})}else await l()};await o()}else await l();for(let a of n.afterHooks)await a(s);return i}removeSignalHandlers(){if(!this.signalHandlersSet)return this;return V.removeAllListeners("SIGINT"),V.removeAllListeners("SIGTERM"),this.signalHandlersSet=!1,this}destroy(){this.removeSignalHandlers(),this.commands=[],this.rawArgs=[],this.args=[],this.options={},this.matchedCommand=void 0,this.matchedCommandName=void 0,this.removeAllListeners()}}class Ye{cache;enabled;cleanupInterval=null;hits=0;misses=0;constructor(){this.cache=new Map,this.enabled=!0,this.startCleanupInterval()}startCleanupInterval(){if(this.cleanupInterval)return;this.cleanupInterval=setInterval(()=>{this.cleanup()},30000),this.cleanupInterval.unref()}stopCleanup(){if(this.cleanupInterval)clearInterval(this.cleanupInterval),this.cleanupInterval=null}isEnabled(){return this.enabled}get(e){if(!this.enabled){this.misses++;return}let t=this.cache.get(e);if(!t){this.misses++;return}if(Date.now()-t.timestamp>t.ttl){this.cache.delete(e),this.misses++;return}return this.hits++,t.value}set(e,t,n=5000){if(!this.enabled)return;this.cache.set(e,{value:t,timestamp:Date.now(),ttl:n})}has(e){if(!this.enabled)return!1;let t=this.cache.get(e);if(!t)return!1;if(Date.now()-t.timestamp>t.ttl)return this.cache.delete(e),!1;return!0}delete(e){this.cache.delete(e)}clear(){this.cache.clear()}disable(){this.enabled=!1,this.clear()}enable(){this.enabled=!0}stats(){return{size:this.cache.size,enabled:this.enabled,hits:this.hits,misses:this.misses}}resetStats(){this.hits=0,this.misses=0}keys(){return Array.from(this.cache.keys())}cleanup(){let e=Date.now();for(let[t,n]of this.cache.entries())if(e-n.timestamp>n.ttl)this.cache.delete(t)}destroy(){this.stopCleanup(),this.clear(),this.resetStats()}}var yr=new Ye;function Dt(){if("FORCE_COLOR"in X.env)return X.env.FORCE_COLOR!=="0";if("NO_COLOR"in X.env||X.env.TERM==="dumb")return!1;if(X.platform==="win32")return!0;return He.isatty(1)&&He.isatty(2)}var Qe=Dt();function v(e,t){if(!Qe)return(n)=>n;return(n)=>e+n+t}var Mt=v("\x1B[0m","\x1B[0m"),Vt=v("\x1B[31m","\x1B[39m"),Wt=v("\x1B[32m","\x1B[39m"),jt=v("\x1B[33m","\x1B[39m"),Ft=v("\x1B[34m","\x1B[39m"),Ut=v("\x1B[35m","\x1B[39m"),zt=v("\x1B[36m","\x1B[39m"),Ht=v("\x1B[37m","\x1B[39m"),qt=v("\x1B[90m","\x1B[39m"),Gt=v("\x1B[1m","\x1B[22m"),Kt=v("\x1B[3m","\x1B[23m"),Yt=v("\x1B[4m","\x1B[24m"),Qt=v("\x1B[2m","\x1B[22m"),Jt=v("\x1B[7m","\x1B[27m"),Xt=v("\x1B[8m","\x1B[28m"),Zt=v("\x1B[9m","\x1B[29m"),en=v("\x1B[41m","\x1B[49m"),tn=v("\x1B[42m","\x1B[49m"),nn=v("\x1B[43m","\x1B[49m"),rn=v("\x1B[44m","\x1B[49m"),sn=v("\x1B[45m","\x1B[49m"),on=v("\x1B[46m","\x1B[49m"),an=v("\x1B[47m","\x1B[49m"),ln=Qe,cn={reset:Mt,red:Vt,green:Wt,yellow:jt,blue:Ft,magenta:Ut,cyan:zt,white:Ht,gray:qt,bold:Gt,italic:Kt,underline:Yt,dim:Qt,inverse:Jt,hidden:Xt,strikethrough:Zt,bgRed:en,bgGreen:tn,bgYellow:nn,bgBlue:rn,bgMagenta:sn,bgCyan:on,bgWhite:an,isColorSupported:ln},un=cn,dn=["up","down","left","right","space","enter","cancel"],$r={actions:new Set(dn),aliases:new Map([["k","up"],["j","down"],["h","left"],["l","right"],["\x03","cancel"],["escape","cancel"]]),messages:{cancel:"Canceled",error:"Something went wrong"}};var Sr=hn.platform.startsWith("win"),kr=Symbol("clapp:cancel");var mn=It();var C=(e,t)=>mn?e:t,Tr=C("\u25C6","*"),Ar=C("\u25A0","x"),Nr=C("\u25B2","x"),Ir=C("\u25C7","o"),Er=C("\u250C","T"),pn=C("\u2502","|"),Or=C("\u2514","\u2014"),Lr=C("\u25CF",">"),Pr=C("\u25CB"," "),Rr=C("\u25FB","[\u2022]"),_r=C("\u25FC","[+]"),Br=C("\u25FB","[ ]"),Dr=C("\u25AA","\u2022"),Mr=C("\u2500","-"),Vr=C("\u256E","+"),Wr=C("\u251C","+"),jr=C("\u256F","+"),Fr=C("\u25CF","\u2022"),Ur=C("\u25C6","*"),zr=C("\u25B2","!"),Hr=C("\u25A0","x");var qr={light:C("\u2500","-"),heavy:C("\u2501","="),block:C("\u2588","#")};function fn(){return`${un.gray(pn)} `}var Gr=fn();import{existsSync as er,readFileSync as tr}from"fs";function B(e){return{prev:null,next:null,data:e}}class L{head=null;tail=null;cursors=[];allocateCursor(e,t){let n={prev:e,next:t};return this.cursors.push(n),n}releaseCursor(){this.cursors.pop()}updateCursors(e,t,n,r){for(let s of this.cursors){if(s.prev===e)s.prev=t;if(s.next===n)s.next=r}}static createItem(e){return B(e)}createItem(e){return B(e)}get isEmpty(){return this.head===null}get first(){return this.head?.data??null}get last(){return this.tail?.data??null}*[Symbol.iterator](){for(let e=this.head;e!=null;e=e.next)yield e.data}fromArray(e){let t=null;this.head=null;for(let n of e){let r=B(n);if(r.prev=t,t)t.next=r;else this.head=r;t=r}return this.tail=t,this}toArray(){let e=[];for(let t=this.head;t!=null;t=t.next)e.push(t.data);return e}toJSON(){return this.toArray()}forEach(e,t){let n=this.allocateCursor(null,this.head);while(n.next!==null){let r=n.next;n.prev=r,n.next=r.next,e.call(t,r.data,r,this)}this.releaseCursor()}forEachRight(e,t){let n=this.allocateCursor(this.tail,null);while(n.prev!==null){let r=n.prev;n.next=r,n.prev=r.prev,e.call(t,r.data,r,this)}this.releaseCursor()}reduce(e,t){let n=t,r=0;for(let s=this.head;s!=null;s=s.next)n=e(n,s.data,r++,this);return n}some(e){let t=0;for(let n=this.head;n!=null;n=n.next)if(e(n.data,t++,this))return!0;return!1}map(e){let t=new L,n=null,r=0;for(let s=this.head;s!=null;s=s.next){let i=B(e(s.data,r++,this));if(i.prev=n,n)n.next=i;else t.head=i;n=i}return t.tail=n,t}filter(e){let t=new L,n=null,r=0;for(let s=this.head;s!=null;s=s.next)if(e(s.data,r++,this)){let i=B(s.data);if(i.prev=n,n)n.next=i;else t.head=i;n=i}return t.tail=n,t}clear(){let e=this.head;while(e){let t=e.next;e.prev=null,e.next=null,e=t}this.head=null,this.tail=null}copy(){let e=new L,t=null;for(let n=this.head;n!=null;n=n.next){let r=B(n.data);if(r.prev=t,t)t.next=r;else e.head=r;t=r}return e.tail=t,e}prepend(e){return this.insert(e,this.head)}prependData(e){return this.insert(B(e),this.head)}append(e){return this.insert(e,null)}appendData(e){return this.insert(B(e),null)}insert(e,t=null){if(t!=null)if(this.updateCursors(t.prev,e,t,e),t.prev===null){if(this.head!==t)throw Error("before doesn't belong to list");this.head=e,t.prev=e,e.next=t,this.updateCursors(null,e,null,null)}else t.prev.next=e,e.prev=t.prev,t.prev=e,e.next=t;else if(this.updateCursors(this.tail,e,null,e),this.tail!==null)this.tail.next=e,e.prev=this.tail,this.tail=e;else this.head=e,this.tail=e;return this}insertData(e,t=null){return this.insert(B(e),t)}remove(e){if(this.updateCursors(e,e.prev,e,e.next),e.prev!==null)e.prev.next=e.next;else if(this.head===e)this.head=e.next;else throw Error("item doesn't belong to list");if(e.next!==null)e.next.prev=e.prev;else if(this.tail===e)this.tail=e.prev;else throw Error("item doesn't belong to list");return e.prev=null,e.next=null,e}push(e){this.insert(B(e),null)}pop(){if(this.tail===null)return null;return this.remove(this.tail)}unshift(e){this.prependData(e)}shift(){if(this.head===null)return null;return this.remove(this.head)}prependList(e){return this.insertList(e,this.head)}appendList(e){return this.insertList(e,null)}insertList(e,t=null){if(e.head===null)return this;if(t!==null){if(this.updateCursors(t.prev,e.tail,t,e.head),t.prev!==null)t.prev.next=e.head,e.head.prev=t.prev;else this.head=e.head;t.prev=e.tail,e.tail.next=t}else{if(this.updateCursors(this.tail,e.tail,null,e.head),this.tail!==null)this.tail.next=e.head,e.head.prev=this.tail;else this.head=e.head;this.tail=e.tail}return e.head=null,e.tail=null,this}replace(e,t){if(t instanceof L)this.insertList(t,e),this.remove(e);else this.insert(t,e),this.remove(e)}}function k(e){switch(e.type){case"StyleSheet":return O(e.children,"");case"Rule":return`${k(e.prelude)}{${k(e.block)}}`;case"Block":return gn(e.children);case"Atrule":{let t=`@${e.name}`;if(e.prelude){let n=k(e.prelude);if(n)t+=` ${n}`}if(e.block)t+=`{${k(e.block)}}`;else t+=";";return t}case"AtrulePrelude":return O(e.children,"");case"SelectorList":return O(e.children,",");case"Selector":return O(e.children,"");case"TypeSelector":return e.name;case"IdSelector":return`#${e.name}`;case"ClassSelector":return`.${e.name}`;case"NestingSelector":return"&";case"AttributeSelector":{let t=`[${e.name.name}`;if(e.matcher&&e.value)if(t+=e.matcher,e.value.type==="String")t+=`"${ve(e.value.value)}"`;else t+=e.value.name;if(e.flags)t+=` ${e.flags}`;return t+="]",t}case"PseudoClassSelector":return e.children?`:${e.name}(${O(e.children,"")})`:`:${e.name}`;case"PseudoElementSelector":return e.children?`::${e.name}(${O(e.children,"")})`:`::${e.name}`;case"Combinator":return e.name===" "?" ":e.name;case"Declaration":return`${e.property}:${k(e.value)}${e.important?"!important":""}`;case"DeclarationList":return O(e.children,";");case"Value":return O(e.children,"");case"Identifier":return e.name;case"Number":return e.value;case"Percentage":return`${e.value}%`;case"Dimension":return e.value+e.unit;case"String":return`"${ve(e.value)}"`;case"Url":return/[\s"'()\\\u0000-\u001F\u007F]/.test(e.value)?`url("${ve(e.value)}")`:`url(${e.value})`;case"Hash":return`#${e.name}`;case"Operator":return e.value;case"Function":return`${e.name}(${O(e.children,"")})`;case"Parentheses":return`(${O(e.children,"")})`;case"Brackets":return`[${O(e.children,"")}]`;case"Raw":return e.value;case"Comment":return e.value.startsWith("!")?`/*${e.value}*/`:"";case"WhiteSpace":return" ";case"CDO":return"<!--";case"CDC":return"-->";case"AnPlusB":{let t=e.a??"",n=e.b??"";if(t&&n){let r=Number(n);return`${t==="1"?"":t==="-1"?"-":t}n${r>=0?`+${n}`:n}`}if(t)return`${t==="1"?"":t==="-1"?"-":t}n`;return n}case"Ratio":return`${e.left.value}/${e.right.value}`;case"UnicodeRange":return e.value;case"Nth":return e.selector?`${k(e.nth)} of ${k(e.selector)}`:k(e.nth);case"MediaQueryList":return O(e.children,",");case"MediaQuery":return O(e.children,"");case"MediaFeature":{let t=`(${e.name}`;if(e.value)t+=`:${k(e.value)}`;return t+=")",t}}return""}function O(e,t){let n="",r=!0,s=null,i=e.head;while(i!=null){let l=i.data;if(l.type==="WhiteSpace"){let o=i.next?i.next.data:null;if(Je(s)||Je(o)){i=i.next;continue}}let a=k(l);if(!a){i=i.next;continue}if(!r&&t&&!bn(s))n+=t;r=!1,n+=a,s=l,i=i.next}return n}function gn(e){let t="",n=null,r=e.head;while(r!=null){let s=r.data,i=k(s);if(!i){r=r.next;continue}if(n&&yn(n,s))t+=";";t+=i,n=s,r=r.next}return t}function yn(e,t){return e.type==="Declaration"&&t.type!=="Comment"}function Je(e){if(!e||e.type!=="Operator")return!1;let t=e.value;return t===":"||t===","||t==="/"}function bn(e){if(!e)return!1;return e.type==="Operator"||e.type==="Combinator"}function ve(e){let t="";for(let n=0;n<e.length;n++){let r=e.charCodeAt(n);if(r===92)t+="\\\\";else if(r===34)t+="\\\"";else if(r<32||r===127){let s=r.toString(16),i=n+1<e.length?e.charCodeAt(n+1):-1,l=i===32||i===9||i===10||i===12||i===13||i>=48&&i<=57||i>=65&&i<=70||i>=97&&i<=102;t+=`\\${s}${l?" ":""}`}else t+=e[n]}return t}var U=(()=>{let e=new Uint8Array(128);for(let t=0;t<128;t++){let n=0;if(t===32||t===9||t===10||t===12||t===13)n|=1;if(t>=48&&t<=57)n|=2;if(t>=48&&t<=57||t>=65&&t<=70||t>=97&&t<=102)n|=4;if(t>=65&&t<=90||t>=97&&t<=122||t===95)n|=8;if(t===10||t===12||t===13)n|=16;e[t]=n}return e})();function P(e){return e<128&&(U[e]&2)!==0}function te(e){return e<128&&(U[e]&4)!==0}function Xe(e){return e>=128||e<128&&(U[e]&8)!==0}function Cn(e){return e===45||e>=128||e<128&&(U[e]&10)!==0}function vn(e){return e>=0&&e<=8||e===11||e>=14&&e<=31||e===127}function xe(e){return e<128&&(U[e]&16)!==0}function M(e){return e<128&&(U[e]&1)!==0}function F(e,t){if(e!==92)return!1;if(xe(t))return!1;return!0}function we(e,t,n){if(e===45)return Xe(t)||t===45||F(t,n);if(Xe(e))return!0;if(e===92)return F(e,t);return!1}function wn(e,t,n){if(e===43||e===45){if(P(t))return!0;if(t===46&&P(n))return!0;return!1}if(e===46)return P(t);return P(e)}class ie{source;offset=0;types;starts;ends;count=0;_tokens=null;_lineStarts=null;constructor(e){this.source=e;let t=Math.max(64,Math.ceil(e.length/3));this.types=new Uint8Array(t),this.starts=new Uint32Array(t),this.ends=new Uint32Array(t),this.tokenize()}get lineStarts(){if(this._lineStarts==null)this._lineStarts=xn(this.source);return this._lineStarts}get tokens(){if(this._tokens!=null)return this._tokens;let e=Array.from({length:this.count});for(let t=0;t<this.count;t++)e[t]={type:this.types[t],start:this.starts[t],end:this.ends[t]};return this._tokens=e,e}addToken(e,t,n){if(this.count>=this.types.length)this.grow();this.types[this.count]=e,this.starts[this.count]=t,this.ends[this.count]=n,this.count++}grow(){let t=this.types.length*2,n=new Uint8Array(t);n.set(this.types),this.types=n;let r=new Uint32Array(t);r.set(this.starts),this.starts=r;let s=new Uint32Array(t);s.set(this.ends),this.ends=s}tokenize(){let e=this.source,t=0,n=e.length;while(t<n){let r=e.charCodeAt(t);if(r===47&&e.charCodeAt(t+1)===42){let l=t;t+=2;while(t<n&&!(e.charCodeAt(t)===42&&e.charCodeAt(t+1)===47))t++;t=t<n?t+2:n,this.addToken(25,l,t);continue}if(M(r)){let l=t;while(t<n&&M(e.charCodeAt(t)))t++;this.addToken(13,l,t);continue}if(r===34||r===39){t=this.consumeString(r,t);continue}if(r===35){if(t+1<n&&(Cn(e.charCodeAt(t+1))||F(e.charCodeAt(t+1),e.charCodeAt(t+2)))){let l=t;t++,t=this.consumeName(t),this.addToken(4,l,t);continue}this.addToken(9,t,t+1),t++;continue}switch(r){case 40:this.addToken(21,t,t+1),t++;continue;case 41:this.addToken(22,t,t+1),t++;continue;case 91:this.addToken(19,t,t+1),t++;continue;case 93:this.addToken(20,t,t+1),t++;continue;case 123:this.addToken(23,t,t+1),t++;continue;case 125:this.addToken(24,t,t+1),t++;continue;case 44:this.addToken(18,t,t+1),t++;continue;case 58:this.addToken(16,t,t+1),t++;continue;case 59:this.addToken(17,t,t+1),t++;continue}if(r===60&&e.startsWith("!--",t+1)){this.addToken(14,t,t+4),t+=4;continue}if(r===45&&e.startsWith("->",t+1)){this.addToken(15,t,t+3),t+=3;continue}if(r===64){let l=e.charCodeAt(t+1),a=e.charCodeAt(t+2),o=e.charCodeAt(t+3);if(we(l,a,o)){let c=t;t++,t=this.consumeName(t),this.addToken(3,c,t);continue}this.addToken(9,t,t+1),t++;continue}let s=e.charCodeAt(t+1),i=e.charCodeAt(t+2);if(wn(r,s,i)){t=this.consumeNumeric(t);continue}if(we(r,s,i)){t=this.consumeIdentLike(t);continue}if(r===92){if(F(r,s)){t=this.consumeIdentLike(t);continue}this.addToken(9,t,t+1),t++;continue}this.addToken(9,t,t+1),t++}this.addToken(0,n,n)}consumeString(e,t){let n=this.source,r=n.length,s=t+1;while(s<r){let i=n.charCodeAt(s);if(i===e)return s++,this.addToken(5,t,s),s;if(xe(i))return this.addToken(6,t,s),s;if(i===92){let l=n.charCodeAt(s+1);if(xe(l)){s+=2;continue}if(s+1<r){s=this.consumeEscapeSkip(s+1);continue}}s++}return this.addToken(5,t,s),s}consumeEscapeSkip(e){let t=this.source;if(e>=t.length)return e;let n=t.charCodeAt(e);if(te(n)){let r=1;e++;while(r<6&&e<t.length&&te(t.charCodeAt(e)))e++,r++;if(e<t.length&&M(t.charCodeAt(e)))e++;return e}return e+1}consumeName(e){let t=this.source,n=t.length,r=e;while(r<n){let s=t.charCodeAt(r);if(s<128&&(U[s]&10)!==0){r++;continue}if(s===45){r++;continue}if(s>=128){r++;continue}if(s===92&&F(s,t.charCodeAt(r+1))){r=this.consumeEscapeSkip(r+1);continue}break}return r}consumeNumber(e){let t=this.source,n=e;if(t.charCodeAt(n)===43||t.charCodeAt(n)===45)n++;while(n<t.length&&P(t.charCodeAt(n)))n++;if(t.charCodeAt(n)===46&&P(t.charCodeAt(n+1))){n+=2;while(n<t.length&&P(t.charCodeAt(n)))n++}let r=t.charCodeAt(n);if(r===69||r===101){let s=t.charCodeAt(n+1),i=t.charCodeAt(n+2);if(P(s)){n+=2;while(n<t.length&&P(t.charCodeAt(n)))n++}else if((s===43||s===45)&&P(i)){n+=3;while(n<t.length&&P(t.charCodeAt(n)))n++}}return n}consumeNumeric(e){let t=this.source,n=this.consumeNumber(e),r=t.charCodeAt(n),s=t.charCodeAt(n+1),i=t.charCodeAt(n+2);if(we(r,s,i)){let l=this.consumeName(n);return this.addToken(12,e,l),l}if(r===37)return this.addToken(11,e,n+1),n+1;return this.addToken(10,e,n),n}consumeIdentLike(e){let t=this.source,n=this.consumeName(e),r=t.charCodeAt(n);if(r===40&&n-e===3){let s=t.charCodeAt(e)|32,i=t.charCodeAt(e+1)|32,l=t.charCodeAt(e+2)|32;if(s===117&&i===114&&l===108){let a=n+1;while(a<t.length&&M(t.charCodeAt(a)))a++;let o=t.charCodeAt(a);if(o===34||o===39)return this.addToken(2,e,n+1),n+1;return this.consumeUrl(e,n)}}if(r===40)return this.addToken(2,e,n+1),n+1;return this.addToken(1,e,n),n}consumeUrl(e,t){let n=this.source,r=n.length,s=t+1;while(s<r&&M(n.charCodeAt(s)))s++;while(s<r){let i=n.charCodeAt(s);if(i===41)return s++,this.addToken(7,e,s),s;if(M(i)){let l=s;while(s<r&&M(n.charCodeAt(s)))s++;if(s>=r)return this.addToken(7,e,s),s;if(n.charCodeAt(s)===41)return s++,this.addToken(7,e,s),s;return this.consumeBadUrl(e,l)}if(i===34||i===39||i===40||vn(i))return this.consumeBadUrl(e,s);if(i===92){if(F(i,n.charCodeAt(s+1))){s=this.consumeEscapeSkip(s+1);continue}return this.consumeBadUrl(e,s)}s++}return this.addToken(7,e,s),s}consumeBadUrl(e,t){let n=this.source,r=t;while(r<n.length){let s=n.charCodeAt(r);if(s===41){r++;break}if(s===92&&F(s,n.charCodeAt(r+1))){r=this.consumeEscapeSkip(r+1);continue}r++}return this.addToken(8,e,r),r}locate(e){let t=this.lineStarts,n=0,r=t.length-1;while(n<r){let i=n+r+1>>1;if(t[i]<=e)n=i;else r=i-1}let s=t[n];return{line:n+1,column:e-s+1}}}function xn(e){let t=[0],n=e.length;for(let r=0;r<n;r++){let s=e.charCodeAt(r);if(s===10)t.push(r+1);else if(s===13){if(e.charCodeAt(r+1)!==10)t.push(r+1)}}return t}function $e(e,t,n){for(let r=t;r<n;r++)if(e.charCodeAt(r)===92)return $n(e,t,n,r);return e.slice(t,n)}function $n(e,t,n,r){let s=e.slice(t,r),i=r;while(i<n){if(e.charCodeAt(i)!==92){s+=e[i],i++;continue}if(i+1>=n){i++;continue}let a=e.charCodeAt(i+1);if(a===10){i+=2;continue}if(a===13){i+=e.charCodeAt(i+2)===10?3:2;continue}if(te(a)){let o=i+1,c="";while(c.length<6&&o<n&&te(e.charCodeAt(o)))c+=e[o],o++;let h=Number.parseInt(c,16);if(o<n&&M(e.charCodeAt(o)))o++;s+=h===0||h>=55296&&h<=57343||h>1114111?String.fromCodePoint(65533):String.fromCodePoint(h),i=o;continue}s+=e[i+1],i+=2}return s}function Se(e,t,n){for(let r=t;r<n;r++)if(e.charCodeAt(r)===92)return Sn(e,t,n,r);return e.slice(t,n)}function Sn(e,t,n,r){let s=e.slice(t,r),i=r;while(i<n){if(e.charCodeAt(i)!==92){s+=e[i],i++;continue}let a=i+1,o="";while(o.length<6&&a<n&&te(e.charCodeAt(a)))o+=e[a],a++;if(o.length>0){let c=Number.parseInt(o,16);if(a<n&&M(e.charCodeAt(a)))a++;s+=c===0||c>=55296&&c<=57343||c>1114111?String.fromCodePoint(65533):String.fromCodePoint(c),i=a;continue}if(a<n){s+=e[a],i=a+1;continue}s+=String.fromCodePoint(65533),i=a}return s}function it(e,t){let n=new ie(e);return{source:e,types:n.types,starts:n.starts,ends:n.ends,count:n.count,end:n.count,pos:0,positions:t.positions??!1,filename:t.filename,parseValue:t.parseValue??!0,parseAtrulePrelude:t.parseAtrulePrelude??!0,parseCustomProperty:t.parseCustomProperty??!1,parseRulePrelude:t.parseRulePrelude??!0,onParseError:t.onParseError,tokenizer:n}}function m(e){return e.pos<e.end?e.types[e.pos]:0}function p(e){let t=e.pos;if(t>=e.end)return{type:0,start:e.starts[t]??e.source.length,end:e.ends[t]??e.source.length};return{type:e.types[t],start:e.starts[t],end:e.ends[t]}}function g(e){let t=e.pos++;if(t>=e.end)return{type:0,start:e.starts[t]??e.source.length,end:e.ends[t]??e.source.length};return{type:e.types[t],start:e.starts[t],end:e.ends[t]}}function D(e,t){return e.source.slice(t.start,t.end)}function R(e){let{types:t,end:n}=e;while(e.pos<n){let r=t[e.pos];if(r===13||r===25)e.pos++;else break}}function Ze(e){let{types:t,end:n}=e;while(e.pos<n&&t[e.pos]===13)e.pos++}function y(e,t,n){if(!e.positions)return null;let r=e.tokenizer.locate(t.start),s=e.tokenizer.locate(n.end);return{source:e.filename??"<unknown>",start:{offset:t.start,line:r.line,column:r.column},end:{offset:n.end,line:s.line,column:s.column}}}function ot(e){if(!e.positions)return null;let t=p(e),n=e.tokenizer.locate(t.start);return{source:e.filename??"<unknown>",start:{offset:t.start,line:n.line,column:n.column},end:{offset:t.start,line:n.line,column:n.column}}}function oe(e,t,n,r){return{type:"Raw",value:e,loc:y(r,t,n)}}function N(){return new L}function ke(e,t,n,r){if(e.onParseError){let{line:s,column:i}=e.tokenizer.locate(n.start),l=SyntaxError(`${e.filename??"<input>"}:${s}:${i}: ${t}`);l.line=s,l.column=i,l.offset=n.start,e.onParseError(l,r)}return r}function z(e,t={}){let n=it(e,t);switch(t.context??"stylesheet"){case"stylesheet":return nt(n);case"atrule":return le(n)??et(n);case"atrulePrelude":return Nn(n);case"mediaQuery":case"mediaQueryList":return tt(n);case"rule":return Ae(n);case"selectorList":return Ee(n);case"selector":return ut(n);case"block":return Ne(n);case"declarationList":return On(n);case"declaration":return Ie(n)??et(n);case"value":return Ln(n);case"raw":return tt(n);default:return nt(n)}}function et(e){return{type:"StyleSheet",children:N(),loc:ot(e)}}function tt(e){let t=p(e),n=t;while(m(e)!==0)n=g(e);return{type:"Raw",value:e.source.slice(t.start,n.end),loc:y(e,t,n)}}function nt(e){let t=p(e),n=N(),{types:r,end:s}=e;while(e.pos<s){let a=r[e.pos];if(a===13){e.pos++;continue}if(a===25){let h={type:25,start:e.starts[e.pos],end:e.ends[e.pos]},u=Te(e,h);e.pos++,n.appendData(u);continue}if(a===0)break;if(a===14||a===15){e.pos++;continue}if(a===3){let h=le(e);if(h)n.appendData(h);continue}if(a===24){e.pos++;continue}let o=e.pos,c=Ae(e);if(n.appendData(c),e.pos===o)e.pos++}let i=e.end-1,l=i>=0?{type:e.types[i],start:e.starts[i],end:e.ends[i]}:{type:0,start:0,end:0};return{type:"StyleSheet",children:n,loc:y(e,t,l)}}function Te(e,t){return{type:"Comment",value:e.source.slice(t.start+2,t.end-2),loc:y(e,t,t)}}function le(e){let t=p(e);if(t.type!==3)return null;e.pos++;let n=ae(e.source,t.start+1,t.end);R(e);let r=e.pos,s=p(e),{types:i,end:l}=e,a=r,o=r;while(a<l){let u=i[a];if(u===0||u===17||u===23)break;if(u!==13&&u!==25)o=a+1;a++}let c=null;if(o>r){let u=e.starts[r],d=e.ends[o-1],b={type:i[o-1],start:e.starts[o-1],end:d},f=e.source.slice(u,d).trim();if(f.length>0)if(e.parseAtrulePrelude)try{let _=e.end;e.end=o,e.pos=r;let T=N();while(m(e)!==0){let K=H(e);if(K)T.appendData(K)}if(lt(T),e.end=_,e.pos=a,T.isEmpty)c=oe(f,s,b,e);else c={type:"AtrulePrelude",children:T,loc:null}}catch(_){let T=oe(f,s,b,e);ke(e,`Failed to parse @${n} prelude: ${_.message}`,s,T),c=T,e.pos=a}else c=oe(f,s,b,e),e.pos=a;else e.pos=a}else e.pos=a;let h=null;if(m(e)===17)g(e);else if(m(e)===23)h=Ne(e,An.has(n));return{type:"Atrule",name:n,prelude:c,block:h,loc:y(e,t,p(e))}}var Tn=new Set(["is","not","where","has","matches","-moz-any","-webkit-any"]),An=new Set(["media","supports","document","layer","container","scope","starting-style","-moz-document","keyframes","-webkit-keyframes","-moz-keyframes","-o-keyframes"]);function Nn(e){let t=p(e),n=N();while(m(e)!==0){if(p(e).type===13){e.pos++;continue}let s=H(e);if(s)n.appendData(s)}return{type:"AtrulePrelude",children:n,loc:y(e,t,p(e))}}function Ae(e){let t=p(e),n;if(e.parseRulePrelude)n=Ee(e);else{let s=p(e),i=s;while(m(e)!==0&&m(e)!==23)i=g(e);let l=e.source.slice(s.start,i.end).trim();n=oe(l,s,i,e)}let r=Ne(e,!0);return{type:"Rule",prelude:n,block:r,loc:y(e,t,p(e))}}function Ne(e,t=!1){let n=p(e);if(m(e)!==23)return{type:"Block",children:N(),loc:ot(e)};e.pos++;let r=N(),{types:s,end:i}=e;while(e.pos<i){let l=s[e.pos];if(l===24||l===0)break;if(l===13){e.pos++;continue}if(l===25){let o={type:25,start:e.starts[e.pos],end:e.ends[e.pos]};e.pos++,r.appendData(Te(e,o));continue}if(l===3){let o=le(e);if(o)r.appendData(o);continue}if(t&&In(e,En)){let o=Ae(e);r.appendData(o);continue}let a=Ie(e);if(a)r.appendData(a);if(e.pos<i&&s[e.pos]===17)e.pos++}if(m(e)===24)e.pos++;return{type:"Block",children:r,loc:y(e,n,p(e))}}function In(e,t){let n=e.pos,r=t(e);return e.pos=n,r}function En(e){let{types:t,end:n}=e;while(e.pos<n){let r=t[e.pos];if(r===23)return!0;if(r===17||r===24||r===0)return!1;e.pos++}return!1}function On(e){let t=p(e),n=N();while(m(e)!==0&&m(e)!==24){let r=p(e);if(r.type===13){e.pos++;continue}if(r.type===25){n.appendData(Te(e,g(e)));continue}if(r.type===17){e.pos++;continue}if(r.type===3){let i=le(e);if(i)n.appendData(i);continue}let s=Ie(e);if(s)n.appendData(s);if(m(e)===17)g(e)}return{type:"DeclarationList",children:n,loc:y(e,t,p(e))}}function Ie(e){R(e);let t=p(e);if(t.type!==1&&t.type!==4&&!(t.type===9&&e.source[t.start]==="*"&&e.source[t.start+1]===" "))if(t.type===9&&e.source[t.start]==="*")e.pos++;else{ke(e,"Expected property name",t,{type:"Raw",value:"",loc:null});let{types:I,end:E}=e;while(e.pos<E){let S=I[e.pos];if(S===0||S===17||S===24)break;e.pos++}return null}let n=e.starts[e.pos],r=e.ends[e.pos];e.pos++;let s=e.source.slice(n,r);if(Ze(e),m(e)!==16){ke(e,`Expected ':' after property "${s}"`,p(e),{type:"Raw",value:"",loc:null});let{types:I,end:E}=e;while(e.pos<E){let S=I[e.pos];if(S===0||S===17||S===24)break;e.pos++}return null}e.pos++,Ze(e);let{types:i,starts:l,end:a,pos:o}=e,c=o,h=o,u=-1,d=-1;while(c<a){let I=i[c];if(I===0||I===17||I===24)break;if(I===9&&e.source.charCodeAt(l[c])===33){let E=c+1;while(E<a&&i[E]===13)E++;if(E<a&&i[E]===1){let S=l[E];if(e.ends[E]-S===9&&(e.source.charCodeAt(S)|32)===105&&(e.source.charCodeAt(S+1)|32)===109&&(e.source.charCodeAt(S+2)|32)===112&&(e.source.charCodeAt(S+3)|32)===111&&(e.source.charCodeAt(S+4)|32)===114&&(e.source.charCodeAt(S+5)|32)===116&&(e.source.charCodeAt(S+6)|32)===97&&(e.source.charCodeAt(S+7)|32)===110&&(e.source.charCodeAt(S+8)|32)===116){d=c,u=E,c=E+1;continue}}}if(I!==13&&I!==25)h=c+1;c++}let b=h,f=u>=0?{type:1,start:l[u],end:e.ends[u]}:null,_=s.startsWith("--"),T,K=l[o],Me=b>o?e.ends[b-1]:K,he={type:i[o],start:K,end:e.ends[o]},Ve=b>o?{type:i[b-1],start:l[b-1],end:Me}:he;if(_&&!e.parseCustomProperty||!e.parseValue)T={type:"Raw",value:e.source.slice(K,Me).trim(),loc:y(e,he,Ve)};else if(b===o)T={type:"Value",children:N(),loc:y(e,he,Ve)};else{let I=e.end;e.end=b,e.pos=o,T=at(e),e.end=I}return e.pos=c,{type:"Declaration",property:s,important:f?!0:!1,value:T,loc:y(e,t,p(e))}}function Ln(e){return at(e)}function at(e){let t=p(e),n=N();while(m(e)!==0&&m(e)!==17&&m(e)!==24&&m(e)!==22&&m(e)!==20){let r=H(e);if(r)n.appendData(r)}return ct(n),{type:"Value",children:n,loc:y(e,t,p(e))}}function lt(e){for(let t of e)if("children"in t&&t.children instanceof L)lt(t.children);ct(e)}function ct(e){let t=e.head;while(t){if(t.data.type==="Number"){let n=t.next;while(n&&n.data.type==="WhiteSpace")n=n.next;if(n&&n.data.type==="Operator"&&n.data.value==="/"){let r=n.next;while(r&&r.data.type==="WhiteSpace")r=r.next;if(r&&r.data.type==="Number"){let s={type:"Ratio",left:t.data,right:r.data,loc:null},i=t.next;while(i&&i!==r.next){let l=i.next;e.remove(i),i=l}e.replace(t,e.createItem(s)),t=e.head;continue}}}t=t.next}}function H(e){let t=e.pos;if(t>=e.end)return null;let n=e.types[t],r=e.starts[t],s=e.ends[t],i=e.source;switch(n){case 13:return e.pos++,e.positions?{type:"WhiteSpace",value:" ",loc:A(e,r,s)}:{type:"WhiteSpace",value:" ",loc:null};case 25:return e.pos++,{type:"Comment",value:i.slice(r+2,s-2),loc:e.positions?A(e,r,s):null};case 10:return e.pos++,{type:"Number",value:i.slice(r,s),loc:e.positions?A(e,r,s):null};case 11:return e.pos++,{type:"Percentage",value:i.slice(r,s-1),loc:e.positions?A(e,r,s):null};case 12:{e.pos++;let l=r,a=i.charCodeAt(l);if(a===43||a===45)l++;let o=!1;while(l<s){let h=i.charCodeAt(l);if(h>=48&&h<=57){l++;continue}if(h===46&&!o){o=!0,l++;continue}break}let c=i.charCodeAt(l);if(c===69||c===101){let h=l+1,u=i.charCodeAt(h);if(u===43||u===45)h++;let d=!1;while(h<s){let b=i.charCodeAt(h);if(b>=48&&b<=57){h++,d=!0;continue}break}if(d)l=h}return{type:"Dimension",value:i.slice(r,l),unit:i.slice(l,s),loc:e.positions?A(e,r,s):null}}case 1:return e.pos++,{type:"Identifier",name:Se(i,r,s),loc:e.positions?A(e,r,s):null};case 5:{e.pos++;let l=r+1,o=s-r>=2&&i.charCodeAt(s-1)===i.charCodeAt(r)?s-1:s;return{type:"String",value:$e(i,l,o),loc:e.positions?A(e,r,s):null}}case 7:{e.pos++;let l=r+4;while(l<s&&rt(i.charCodeAt(l)))l++;let a=s;if(a>l&&i.charCodeAt(a-1)===41)a--;while(a>l&&rt(i.charCodeAt(a-1)))a--;let o;if(a-l>=2){let c=i.charCodeAt(l),h=i.charCodeAt(a-1);if((c===34||c===39)&&c===h)o=i.slice(l+1,a-1);else o=i.slice(l,a)}else o=i.slice(l,a);return{type:"Url",value:o,loc:e.positions?A(e,r,s):null}}case 4:return e.pos++,{type:"Hash",name:i.slice(r+1,s),loc:e.positions?A(e,r,s):null};case 2:return Rn(e);case 21:return _n(e);case 18:return e.pos++,{type:"Operator",value:",",loc:e.positions?A(e,r,s):null};case 16:return e.pos++,{type:"Operator",value:":",loc:e.positions?A(e,r,s):null};case 9:{e.pos++;let l=i.charCodeAt(r),a=i[r];if(Pn(l))return{type:"Operator",value:a,loc:e.positions?A(e,r,s):null};return{type:"Identifier",name:a,loc:e.positions?A(e,r,s):null}}case 19:{e.pos++;let l=N();while(m(e)!==0&&m(e)!==20){let o=H(e);if(o)l.appendData(o)}let a=e.pos<e.end?e.ends[e.pos]:s;if(m(e)===20)e.pos++;return{type:"Brackets",children:l,loc:e.positions?A(e,r,a):null}}case 3:case 23:case 24:case 22:case 20:case 17:case 0:case 14:case 15:case 6:case 8:return e.pos++,{type:"Raw",value:i.slice(r,s),loc:e.positions?A(e,r,s):null}}return e.pos++,null}function rt(e){return e===32||e===9||e===10||e===12||e===13}function Pn(e){return e===47||e===43||e===45||e===42||e===61||e===62||e===60||e===126||e===124||e===36||e===94||e===33||e===38}function ae(e,t,n){for(let r=t;r<n;r++){let s=e.charCodeAt(r);if(s>=65&&s<=90)return e.slice(t,n).toLowerCase()}return e.slice(t,n)}function A(e,t,n){let r=e.tokenizer.locate(t),s=e.tokenizer.locate(n);return{source:e.filename??"<unknown>",start:{offset:t,line:r.line,column:r.column},end:{offset:n,line:s.line,column:s.column}}}function Rn(e){let t=g(e),n=ae(e.source,t.start,t.end-1),r=N();while(m(e)!==0&&m(e)!==22){let s=H(e);if(s)r.appendData(s)}if(m(e)===22)g(e);if(n==="url"){for(let s=r.head;s!=null;s=s.next)if(s.data.type==="String")return{type:"Url",value:s.data.value,loc:y(e,t,p(e))}}return{type:"Function",name:n,children:r,loc:y(e,t,p(e))}}function _n(e){let t=g(e),n=N();while(m(e)!==0&&m(e)!==22){let r=H(e);if(r)n.appendData(r)}if(m(e)===22)g(e);return{type:"Parentheses",children:n,loc:y(e,t,p(e))}}function Ee(e){let t=p(e),n=N();while(m(e)!==0){if(R(e),m(e)===0||m(e)===23)break;let r=ut(e);if(r.children.head!==null)n.appendData(r);if(R(e),m(e)===18){g(e);continue}break}return{type:"SelectorList",children:n,loc:y(e,t,p(e))}}function ut(e){let t=p(e),n=N(),r=!0;while(m(e)!==0&&m(e)!==18&&m(e)!==23){let s=p(e);if(s.type===13){if(g(e),!r&&m(e)!==0&&m(e)!==18&&m(e)!==23&&!st(e)&&!Bn(e)){let l={type:"Combinator",name:" ",loc:y(e,s,s)};n.appendData(l),r=!0}continue}if(s.type===9&&e.source.charCodeAt(s.start)===124&&e.types[e.pos+1]===9&&e.source.charCodeAt(e.starts[e.pos+1])===124){let l=p(e);g(e);let a=g(e),o={type:"Combinator",name:"||",loc:y(e,l,a)};n.appendData(o),r=!0,R(e);continue}if(st(e)){let l=g(e),o={type:"Combinator",name:e.source[l.start],loc:y(e,l,l)};n.appendData(o),r=!0,R(e);continue}let i=Dn(e);if(!i)break;n.appendData(i),r=!1}while(n.tail&&n.tail.data.type==="Combinator")n.remove(n.tail);return{type:"Selector",children:n,loc:y(e,t,p(e))}}function st(e){let t=p(e);if(t.type!==9)return!1;let n=e.source[t.start];return n===">"||n==="+"||n==="~"}function Bn(e){if(e.types[e.pos]!==9)return!1;if(e.source.charCodeAt(e.starts[e.pos])!==124)return!1;if(e.types[e.pos+1]!==9)return!1;return e.source.charCodeAt(e.starts[e.pos+1])===124}function Dn(e){let t=p(e);switch(t.type){case 1:{if(g(e),m(e)===9&&e.source[p(e).start]==="|"&&e.source[p(e).start+1]!=="="&&!(e.types[e.pos+1]===9&&e.source.charCodeAt(e.starts[e.pos+1])===124)){if(g(e),m(e)===1){let r=g(e);return{type:"TypeSelector",name:`${D(e,t)}|${D(e,r)}`,loc:y(e,t,r)}}if(m(e)===9&&e.source[p(e).start]==="*"){let r=g(e);return{type:"TypeSelector",name:`${D(e,t)}|*`,loc:y(e,t,r)}}}return{type:"TypeSelector",name:D(e,t),loc:y(e,t,t)}}case 11:return g(e),{type:"TypeSelector",name:D(e,t),loc:y(e,t,t)};case 10:return g(e),{type:"TypeSelector",name:D(e,t),loc:y(e,t,t)};case 9:{let n=e.source[t.start];if(n==="*")return g(e),{type:"TypeSelector",name:"*",loc:y(e,t,t)};if(n==="."){if(g(e),m(e)===1){let r=g(e);return{type:"ClassSelector",name:D(e,r),loc:y(e,t,r)}}return null}if(n==="&")return g(e),{type:"NestingSelector",loc:y(e,t,t)};return g(e),null}case 4:return g(e),{type:"IdSelector",name:e.source.slice(t.start+1,t.end),loc:y(e,t,t)};case 16:{g(e);let n=m(e)===16;if(n)g(e);return Mn(e,n,t)}case 19:return Vn(e)}return null}function Mn(e,t,n){let r=p(e);if(r.type===1){g(e);let s=ae(e.source,r.start,r.end);return t?{type:"PseudoElementSelector",name:s,children:null,loc:y(e,n,r)}:{type:"PseudoClassSelector",name:s,children:null,loc:y(e,n,r)}}if(r.type===2){g(e);let s=ae(e.source,r.start,r.end-1),i=N();if(!t&&Tn.has(s)){let o=p(e),c=o,h=1;while(m(e)!==0&&h>0){if(m(e)===21||m(e)===2)h++;else if(m(e)===22){if(h--,h===0)break}c=g(e)}if(m(e)===22)g(e);let u=e.source.slice(o.start,c.end).trim();if(u.length>0){let d=it(u,{positions:!1}),b=Ee(d);i.appendData(b)}}else{while(m(e)!==0&&m(e)!==22){let o=H(e);if(o)i.appendData(o)}if(m(e)===22)g(e)}if(t)return{type:"PseudoElementSelector",name:s,children:i,loc:y(e,n,p(e))};return{type:"PseudoClassSelector",name:s,children:i,loc:y(e,n,p(e))}}return null}function Vn(e){let t=g(e);R(e);let n=p(e);if(n.type!==1)return null;g(e);let r={type:"Identifier",name:D(e,n),loc:y(e,n,n)};R(e);let s=null,i=null,l=null,a=p(e);if(a.type===9){let c=e.source[a.start],h=e.source[a.start+1];if(c==="=")s="=",g(e);else if((c==="~"||c==="|"||c==="^"||c==="$"||c==="*")&&h==="="){g(e);let b=p(e);if(b.type===9&&e.source[b.start]==="=")g(e),s=`${c}=`}R(e);let u=p(e);if(u.type===5){g(e);let b=u.end-u.start>=2&&e.source.charCodeAt(u.end-1)===e.source.charCodeAt(u.start);i={type:"String",value:$e(e.source,u.start+1,b?u.end-1:u.end),loc:y(e,u,u)}}else if(u.type===1)g(e),i={type:"Identifier",name:D(e,u),loc:y(e,u,u)};R(e);let d=p(e);if(d.type===1)g(e),l=D(e,d)}R(e);let o=p(e);if(m(e)===20)o=g(e);return{type:"AttributeSelector",name:r,matcher:s,value:i,flags:l,loc:y(e,t,o)}}var ht=Symbol("walkSkip"),x=Symbol("walkStop");function Wn(e){return{root:e,stylesheet:null,atrule:null,atrulePrelude:null,rule:null,selector:null,block:null,declaration:null,function:null}}function jn(e,t){let n=Wn(e),r=typeof t==="function"?t:t.enter,s=typeof t==="function"?null:t.leave??null,i=typeof t==="function"?null:t.visit??null,l=typeof t==="function"?!1:t.reverse??!1;function a(o,c,h){let u=null,d;switch(o.type){case"StyleSheet":u="stylesheet",d=n.stylesheet,n.stylesheet=o;break;case"Atrule":u="atrule",d=n.atrule,n.atrule=o;break;case"AtrulePrelude":u="atrulePrelude",d=n.atrulePrelude,n.atrulePrelude=o;break;case"Rule":u="rule",d=n.rule,n.rule=o;break;case"Selector":u="selector",d=n.selector,n.selector=o;break;case"Block":u="block",d=n.block,n.block=o;break;case"Declaration":u="declaration",d=n.declaration,n.declaration=o;break;case"Function":u="function",d=n.function,n.function=o;break}let b;if((i===null||i===o.type)&&r){let f=r.call(n,o,c,h);if(f===ht){if(u)n[u]=d;return}if(f===x){if(u)n[u]=d;return x}}if(b=Fn(o,l,a),b===x){if(u)n[u]=d;return x}if((i===null||i===o.type)&&s){if(s.call(n,o,c,h)===x){if(u)n[u]=d;return x}}if(u)n[u]=d;return}return a(e,null,null)}var q=Object.assign(jn,{skip:ht,stop:x});function Fn(e,t,n){if("children"in e&&e.children instanceof L)return Un(e.children,t,n);if(e.type==="Rule"){if(n(e.prelude,null,null)===x)return x;if(n(e.block,null,null)===x)return x;return}if(e.type==="Atrule"){if(e.prelude){if(n(e.prelude,null,null)===x)return x}if(e.block){if(n(e.block,null,null)===x)return x}return}if(e.type==="Declaration")return n(e.value,null,null);if(e.type==="AttributeSelector"){if(n(e.name,null,null)===x)return x;if(e.value)return n(e.value,null,null);return}return}function Un(e,t,n){let r;if(t)e.forEachRight((s,i,l)=>{if(r)return;if(n(s,i,l)===x)r=x});else e.forEach((s,i,l)=>{if(r)return;if(n(s,i,l)===x)r=x});return r}function Y(e,t={}){let n=t.exclamation??!1,r=!1;q(e,(s,i,l)=>{if(s.type!=="Comment")return;let a=s.value.startsWith("!");if(n===!0&&a)return;if(n==="first-exclamation"&&a&&!r){r=!0;return}if(i&&l)l.remove(i)})}function ce(e){q(e,(t)=>{if(t.type!=="Block"&&t.type!=="DeclarationList")return;if(!("children"in t)||!t.children)return;let n=t.children,r=n.head;if(r==null||r.next==null)return;let s=0;for(let a=r;a!=null;a=a.next)if(a.data.type==="Declaration"){if(s++,s>=2)break}if(s<2)return;let i=new Map,l=[];for(let a=r;a!=null;a=a.next){let o=a.data;if(o.type!=="Declaration")continue;let c=o.property,h=i.get(c);if(h){let u=!!h.decl.important,d=!!o.important;if(d||u===d)l.push(h.item),i.set(c,{item:a,decl:o});else l.push(a)}else i.set(c,{item:a,decl:o})}for(let a of l)n.remove(a)})}var zn={black:"#000",fuchsia:"#f0f",white:"#fff",red:"#f00",cyan:"#0ff",blue:"#00f",yellow:"#ff0",magenta:"#f0f",lime:"#0f0",silver:"#c0c0c0",gray:"#808080",maroon:"#800000",olive:"#808000",green:"#008000",purple:"#800080",teal:"#008080",navy:"#000080"},Hn={"#f00":"red","#ff0000":"red","#000080":"navy","#008080":"teal"};function Le(e){if(!e.startsWith("#"))return e;let t=e.slice(1);if(t.length===6){if(t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5])return`#${t[0]}${t[2]}${t[4]}`}if(t.length===8){if(t[0]===t[1]&&t[2]===t[3]&&t[4]===t[5]&&t[6]===t[7])return`#${t[0]}${t[2]}${t[4]}${t[6]}`}return e}function dt(e){let t=e.toLowerCase();return zn[t]??null}function mt(e){let t=e.toLowerCase();return Hn[t]??null}function qn(e,t,n){let r=(e<<16|t<<8|n).toString(16).padStart(6,"0");return Le(`#${r}`)}var Gn=/^rgba?\(\s*([+-]?\d*\.?\d+%?)\s*[,\s]\s*([+-]?\d*\.?\d+%?)\s*[,\s]\s*([+-]?\d*\.?\d+%?)\s*(?:[,/]\s*([+-]?\d*\.?\d+%?)\s*)?\)$/;function pt(e){let t=Gn.exec(e.trim());if(!t)return e;let n=Oe(t[1]),r=Oe(t[2]),s=Oe(t[3]);if(t[4]!==void 0&&!Kn(t[4]))return e;return qn(n,r,s)}function Kn(e){if(e.endsWith("%"))return Number.parseFloat(e)>=100;return Number.parseFloat(e)>=1}function Oe(e){if(e.endsWith("%"))return Math.max(0,Math.min(255,Math.round(Number.parseFloat(e)*2.55)));return Math.max(0,Math.min(255,Math.round(Number.parseFloat(e))))}var Yn=new Set(["px","pt","pc","in","cm","mm","q","em","rem","ex","ch","cap","ic","lh","rlh","vw","vh","vi","vb","vmin","vmax","svw","svh","svi","svb","svmin","svmax","lvw","lvh","lvi","lvb","lvmin","lvmax","dvw","dvh","dvi","dvb","dvmin","dvmax","cqw","cqh","cqi","cqb","cqmin","cqmax"]);function ue(e){if(e.charCodeAt(0)===43)e=e.slice(1);if(e.includes(".")){let t=e.replace(/(\.\d*?)0+($|[eE])/,"$1$2");t=t.replace(/\.($|[eE])/,"$1"),e=t}if(e.startsWith("0.")&&e.length>2)e=e.slice(1);else if(e.startsWith("-0.")&&e.length>3)e=`-${e.slice(2)}`;if(e==="-0"||e==="-.0"||e==="-0.0")e="0";return e}function ft(e,t){let n=ue(e);if((n==="0"||n==="-0")&&Yn.has(t.toLowerCase()))return{value:"0",unit:""};return{value:n,unit:t}}function gt(e){return ue(e)}function yt(e,t){let n=Number.parseFloat(e);if(!Number.isFinite(n))return e;let r=t<0?0:t;return n.toFixed(r)}var bt=new Set(["color","background","background-color","border","border-color","border-top","border-top-color","border-right","border-right-color","border-bottom","border-bottom-color","border-left","border-left-color","border-block","border-block-color","border-block-start-color","border-block-end-color","border-inline","border-inline-color","border-inline-start-color","border-inline-end-color","outline","outline-color","caret-color","fill","stroke","flood-color","lighting-color","stop-color","column-rule","column-rule-color","text-decoration","text-decoration-color","text-emphasis","text-emphasis-color","text-shadow","box-shadow","accent-color","scrollbar-color"]);function Ct(e){if(!e||e.type!=="Operator")return!1;let t=e.value;return t===":"||t===","||t==="/"}function Qn(e){let t=e.children;if(!t)return;while(t.head&&t.head.data.type==="WhiteSpace")t.remove(t.head);while(t.tail&&t.tail.data.type==="WhiteSpace")t.remove(t.tail);let n=t.head;while(n){let r=n.next;if(n.data.type==="WhiteSpace"){let s=n.prev&&Ct(n.prev.data),i=r&&Ct(r.data);if(s||i)t.remove(n)}n=r}}function Pe(e,t={}){let n=t.floatPrecision??null,r=n===null?null:(s)=>yt(s,n);q(e,{enter(s,i,l){switch(s.type){case"Number":{let a=r?r(s.value):s.value;s.value=ue(a);return}case"Percentage":{let a=r?r(s.value):s.value;s.value=gt(a);return}case"Dimension":{let a=r?r(s.value):s.value,o=ft(a,s.unit);s.value=o.value,s.unit=o.unit;return}case"Hash":{let a=Le(`#${s.name}`).slice(1);if(s.name=a,i&&l&&this.declaration&&bt.has(this.declaration.property.toLowerCase())){let o=mt(`#${a}`);if(o&&o.length<a.length+1){let c={type:"Identifier",name:o,loc:s.loc};l.replace(i,l.createItem(c))}}return}case"Identifier":{if(!i||!l||!this.declaration)return;if(!bt.has(this.declaration.property.toLowerCase()))return;let a=dt(s.name);if(a&&a.length<s.name.length){let o={type:"Hash",name:a.slice(1),loc:s.loc};l.replace(i,l.createItem(o))}return}case"Url":return;case"Function":{let a=s.name.toLowerCase();if((a==="rgb"||a==="rgba")&&i&&l)s.__rgbReplaceCandidate=!0}}},leave(s,i,l){if(s.type==="Parentheses"||s.type==="Function"||s.type==="Value")Qn(s);if(s.type==="Function"&&s.__rgbReplaceCandidate&&i&&l){let a=k(s),o=pt(a);if(o!==a&&o.startsWith("#")){let c={type:"Hash",name:o.slice(1),loc:s.loc};l.replace(i,l.createItem(c))}}}})}function Re(e,t={}){let n=z(e,{context:"stylesheet"});return vt(n,t)}function _e(e,t={}){let n=z(e,{context:"declarationList"});return vt(n,t)}function vt(e,t){if(t.comments===!1)Y(e,{exclamation:!1});else if(t.comments==="first-exclamation")Y(e,{exclamation:"first-exclamation"});else Y(e,{exclamation:!0});return Pe(e,{floatPrecision:t.floatPrecision??null}),ce(e),{css:k(e),ast:e}}var Be="0.3.1";function De(e){if(!er(e))process.stderr.write(`ts-css: file not found: ${e}
33
+ `),process.exit(1);return tr(e,"utf8")}var G=new Ce("ts-css");G.command("minify <file>","Minify a CSS file").option("--no-comments","Strip /*!*/ comments too").option("--block",'Treat input as a declarationList (style="\u2026" body)').action(async(e,t)=>{let n=De(e),r={comments:t.comments===!1?!1:"exclamation"},s=t.block?_e(n,r):Re(n,r);process.stdout.write(s.css)});G.command("parse <file>","Parse a CSS file and print its AST as JSON").option("--positions","Include source locations on every node").action(async(e,t)=>{let n=De(e),r=z(n,{positions:t.positions});process.stdout.write(JSON.stringify(r,null,2))});G.command("format <file>","Round-trip CSS through parser/generator (deterministic single-line output)").action(async(e)=>{let t=De(e),n=z(t);process.stdout.write(k(n))});G.command("version","Show the version of the CLI").action(()=>{console.log(Be)});G.version(Be);G.help();G.parse();