@slabui/cli 0.4.1 → 0.5.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/CHANGELOG.md +6 -0
- package/dist/cli.mjs +22 -22
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @slabui/cli
|
|
2
2
|
|
|
3
|
+
## 0.5.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#111](https://github.com/slabui/ui/pull/111) [`097b2f8`](https://github.com/slabui/ui/commit/097b2f893e32f97650a3f0e0348fb555ba8d7ea8) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - `slabui mcp init` asks whether the editor should run the MCP server locally (`npx -y @slabui/mcp@latest`, the default) or connect to the remote one, and takes `--transport local|http`. The local server reads the token saved by `slabui login`, so Pro items work without `SLABUI_TOKEN` in the environment. In the local server, the hint for Pro items asks for `slabui login`.
|
|
8
|
+
|
|
3
9
|
## 0.4.1
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cli.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import e from"node:path";import{Command as t,Option as n}from"commander";import r from"postcss";import{access as i,lstat as a,mkdir as o,readFile as s,realpath as c,rm as l,writeFile as u}from"node:fs/promises";import{createHash as d,randomBytes as f}from"node:crypto";import{z as p}from"zod";import{homedir as m,hostname as h}from"node:os";import{createPathsMatcher as g,parseTsconfig as _}from"get-tsconfig";import{applyEdits as v,modify as y,parse as b}from"jsonc-parser";import x from"semver";import{spawn as S}from"node:child_process";import*as C from"@clack/prompts";import{createTwoFilesPatch as w}from"diff";import ee from"minisearch";import{createServer as
|
|
2
|
+
import e from"node:path";import{Command as t,Option as n}from"commander";import r from"postcss";import{access as i,lstat as a,mkdir as o,readFile as s,realpath as c,rm as l,writeFile as u}from"node:fs/promises";import{createHash as d,randomBytes as f}from"node:crypto";import{z as p}from"zod";import{homedir as m,hostname as h}from"node:os";import{createPathsMatcher as g,parseTsconfig as _}from"get-tsconfig";import{applyEdits as v,modify as y,parse as b}from"jsonc-parser";import x from"semver";import{spawn as S}from"node:child_process";import*as C from"@clack/prompts";import{createTwoFilesPatch as w}from"diff";import ee from"minisearch";import{createServer as te}from"node:http";import{merge as ne}from"node-diff3";var T=`0.5.0`,re=`The SlabUI CLI: add, update and compare items from versioned component registries`;const E=/^[a-z0-9][a-z0-9-]*$/i;function ie(e){return E.test(e)}function ae(e,t=!1){if(!ie(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const oe=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function se(e,t,{base:n,overwrite:i=!1,shouldRemove:a,theme:o}={}){let s=r.parse(e),c=[],l=[],u=e=>o?e:ce(e),d=u(t),f=n?u(n):void 0;for(let e of[`theme`,`light`,`dark`]){let t=d[e]??{},n=f?.[e]??{},u=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);if(u.size===0)continue;let p=de(s,e,o);for(let d of u){let u=t[d],f=n[d],m=p?.nodes?.find(e=>e.type===`decl`&&e.prop===`--${d}`),h=m?.value,g=t=>c.push({group:e,name:d,action:t});if(u===void 0){if(h===void 0)continue;a&&await a(e,d)?(m?.remove(),g(`removed`)):(l.push(`--${d} (${e}) was removed in the new version; kept in the CSS.`),g(`kept`))}else if(h===void 0){if(f!==void 0){g(`kept`);continue}p??=fe(s,e,o),p.raws.semicolon=!0,p.raws.after=`
|
|
3
3
|
`,p.append(r.decl({prop:`--${d}`,value:u,raws:{before:`
|
|
4
4
|
`}})),g(`added`)}else me(h,u)?g(`unchanged`):i||f!==void 0&&me(h,f)?(m.value=u,g(`updated`)):(l.push(`--${d} (${e}) has a custom value in the CSS (${h}); kept instead of ${u}.`),g(`kept`))}}return!o&&Object.keys(d.dark??{}).length>0&&pe(s),{css:s.toString(),changes:c,warnings:l}}function ce(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))oe.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function le(e,t){return t?ae(t,e===`dark`):e===`light`?`:root`:`.dark`}const ue=e=>e.replace(/["'\s]/g,``);function de(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&ue(e.selector)===ue(le(t,n)))}function fe(e,t,n){let i=t===`theme`?r.atRule({name:`theme`,params:`inline`}):r.rule({selector:le(t,n)});return i.raws={before:e.nodes.length>0?`
|
|
5
5
|
|
|
@@ -142,12 +142,12 @@ button:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px;
|
|
|
142
142
|
<rect ${Ye} transform="translate(40 28) scale(1 0.5299193) rotate(45)" fill="url(#plate)"/>
|
|
143
143
|
<path class="ink" d="M122.72 63.52L122.72 63.52Q116.83 63.52 112.61 61.54Q108.38 59.56 106.02 55.97Q103.65 52.39 103.33 47.52L103.33 47.52L113.12 47.08Q113.50 49.76 114.69 51.65Q115.87 53.54 117.89 54.50Q119.90 55.46 122.85 55.46L122.85 55.46Q125.28 55.46 126.98 54.88Q128.67 54.31 129.57 53.12Q130.46 51.94 130.46 50.21L130.46 50.21Q130.46 48.61 129.70 47.43Q128.93 46.24 126.75 45.25Q124.58 44.26 120.35 43.30L120.35 43.30Q114.53 41.96 110.98 40.29Q107.42 38.63 105.82 36.10Q104.22 33.57 104.22 29.73L104.22 29.73Q104.22 25.64 106.24 22.56Q108.26 19.49 112.10 17.76Q115.94 16.04 121.25 16.04L121.25 16.04Q126.88 16.04 130.78 18.02Q134.69 20.00 136.90 23.46Q139.10 26.92 139.55 31.40L139.55 31.40L129.82 31.91Q129.63 29.54 128.54 27.78Q127.46 26.02 125.60 25.06Q123.74 24.10 121.12 24.10L121.12 24.10Q117.79 24.10 115.90 25.57Q114.02 27.04 114.02 29.41L114.02 29.41Q114.02 31.08 114.88 32.20Q115.74 33.32 117.76 34.15Q119.78 34.98 123.49 35.75L123.49 35.75Q129.82 37.03 133.50 38.98Q137.18 40.93 138.72 43.62Q140.26 46.31 140.26 49.76L140.26 49.76Q140.26 53.99 138.11 57.09Q135.97 60.20 132.03 61.86Q128.10 63.52 122.72 63.52ZM159.26 62.50L153.57 62.50Q149.34 62.50 146.98 60.39Q144.61 58.28 144.61 53.54L144.61 53.54L144.61 17.06L154.21 17.06L154.21 52.52Q154.21 54.05 154.91 54.69Q155.62 55.33 156.96 55.33L156.96 55.33L159.26 55.33L159.26 62.50ZM171.49 63.27L171.49 63.27Q166.18 63.27 162.82 60.80Q159.46 58.34 159.46 53.92L159.46 53.92Q159.46 49.38 162.30 46.92Q165.15 44.45 170.72 43.30L170.72 43.30L181.79 41.12Q181.79 37.80 180.29 36.10Q178.78 34.40 175.97 34.40L175.97 34.40Q173.22 34.40 171.68 35.65Q170.14 36.90 169.70 39.33L169.70 39.33L160.03 38.88Q160.99 33.25 165.12 30.34Q169.25 27.43 175.97 27.43L175.97 27.43Q183.65 27.43 187.52 31.08Q191.39 34.72 191.39 41.76L191.39 41.76L191.39 53.48Q191.39 54.95 191.87 55.43Q192.35 55.91 193.31 55.91L193.31 55.91L194.27 55.91L194.27 62.50Q193.82 62.63 192.83 62.76Q191.84 62.88 190.88 62.88L190.88 62.88Q188.83 62.88 187.07 62.18Q185.31 61.48 184.22 59.75L184.22 59.75Q183.58 58.79 183.33 57.32L183.33 57.32Q182.69 58.53 181.73 59.62L181.73 59.62Q180.06 61.35 177.47 62.31Q174.88 63.27 171.49 63.27ZM173.79 56.68L173.79 56.68Q176.16 56.68 177.95 55.75Q179.74 54.82 180.77 53.03Q181.79 51.24 181.79 48.80L181.79 48.80L181.79 47.14L173.98 48.80Q171.68 49.25 170.50 50.31Q169.31 51.36 169.31 53.03L169.31 53.03Q169.31 54.76 170.46 55.72Q171.62 56.68 173.79 56.68ZM215.33 63.27L215.33 63.27Q211.74 63.27 209.09 61.73Q206.43 60.20 204.96 57.44L204.96 57.44L204.77 62.50L195.62 62.50L195.62 17.06L205.22 17.06L205.22 33.06Q206.56 30.69 209.18 29.06Q211.81 27.43 215.33 27.43L215.33 27.43Q219.68 27.43 222.88 29.64Q226.08 31.84 227.84 35.88Q229.60 39.91 229.60 45.35L229.60 45.35Q229.60 50.79 227.84 54.82Q226.08 58.85 222.88 61.06Q219.68 63.27 215.33 63.27ZM212.64 55.91L212.64 55.91Q215.84 55.91 217.79 53.12Q219.74 50.34 219.74 45.35L219.74 45.35Q219.74 40.36 217.82 37.57Q215.90 34.79 212.70 34.79L212.70 34.79Q210.34 34.79 208.64 36.04Q206.94 37.28 206.08 39.65Q205.22 42.02 205.22 45.35L205.22 45.35Q205.22 48.61 206.08 50.98Q206.94 53.35 208.64 54.63Q210.34 55.91 212.64 55.91Z"/>
|
|
144
144
|
<path fill="url(#ui)" d="M251.30 63.52L251.30 63.52Q245.54 63.52 241.34 61.41Q237.15 59.30 234.85 55.36Q232.54 51.43 232.54 46.12L232.54 46.12L232.54 17.06L242.27 17.06L242.27 46.12Q242.27 50.53 244.61 52.93Q246.94 55.33 251.30 55.33L251.30 55.33Q255.65 55.33 257.95 52.93Q260.26 50.53 260.26 46.12L260.26 46.12L260.26 17.06L269.98 17.06L269.98 46.12Q269.98 51.43 267.71 55.36Q265.44 59.30 261.22 61.41Q256.99 63.52 251.30 63.52ZM285.98 62.50L276.26 62.50L276.26 17.06L285.98 17.06L285.98 62.50Z"/>
|
|
145
|
-
</svg>`;function Ze(t=process.env,n=process.platform,r=m()){let i=n===`win32`?e.join(t.APPDATA??e.join(r,`AppData/Roaming`),`slabui`):e.join(t.XDG_CONFIG_HOME||e.join(r,`.config`),`slabui`);return e.join(i,`credentials.json`)}async function Qe(e=Ze()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function $e(t,n=Ze()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function et(e=Ze()){let t=await Qe(e)!==void 0;return await l(e,{force:!0}),t}async function tt({registryUrl:e,token:t,fetch:n=globalThis.fetch,headers:r={}}){let i=`${e.replace(/\/+$/,``)}/whoami.json`,a=await n(i,{headers:{...r,authorization:`Bearer ${t.trim()}`},signal:AbortSignal.timeout(15e3)});if(a.status===401)return null;if(!a.ok)throw Error(`Error ${a.status} while fetching ${i}.`);let o=await a.json();return{...o,access:o.access??[]}}function nt(){return f(24).toString(`base64url`)}function rt({registryUrl:e,callback:t,state:n,client:r,host:i=h()}){let a=new URL(`/cli/authorize`,new URL(e).origin);return a.searchParams.set(`callback`,t),a.searchParams.set(`state`,n),a.searchParams.set(`client`,r),a.searchParams.set(`host`,i.replace(/\.local$/,``).slice(0,60)),a.toString()}var M=class extends Error{name=`SlabUIError`};const N=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),it=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),P=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),at=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),F=p.enum(Ve),ot=p.enum(He),st=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),ct=p.object({registry:p.array(st).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),lt=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],ut=[e=>e.files.length>0||e.cssVars!==void 0||e.css!==void 0||(e.utilities?.length??0)>0||(e.variants?.length??0)>0||e.base!==void 0,{message:`the item needs files, cssVars or CSS rules`,path:[`files`]}],dt=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional()}).refine(...lt),ft=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional(),content:p.string()}).refine(...lt),pt=p.record(p.string(),p.string()),mt=p.object({theme:pt.optional(),light:pt.optional(),dark:pt.optional()}),ht=p.record(p.string().min(1),p.record(p.string().min(1),p.string().min(1))),gt=p.string().regex(/^[a-z][\w-]*$/),_t=p.object({utilities:p.record(gt,p.string().min(1)).optional(),variants:p.record(gt,p.string().min(1)).optional(),base:ht.optional()}),vt={name:N,kind:F,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:ct.prefault({}),cssVars:mt.optional()},yt=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...vt,version:P,files:p.array(ft).default([]),css:_t.optional()}).refine(...ut);p.object({...vt,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:ot.optional(),inferDependencies:p.boolean().optional(),files:p.array(dt).default([]),utilities:p.array(gt).optional(),variants:p.array(gt).optional(),base:ht.optional()}).refine(...ut);const bt=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),xt=p.object({hash:at,path:bt}),St=p.object({kind:F,title:p.string().min(1).optional(),description:p.string().min(1),categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:ot.optional(),dependencies:ct.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:P,versions:p.record(P,xt)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Ct=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:it.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(N,St)});let wt;function Tt(e){wt=e}function Et(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Dt(e,t=wt){let n={"user-agent":`slabui/${ne}`};return Et(e)?n[Be.optOut]=`off`:t&&(n[Be.command]=t),n}const Ot=/* @__PURE__ */ new Map;function kt(e){return Ot.get(e)}function I(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>Qe()}={}){let a=e.url.replace(/\/+$/,``),o={...Dt(n,r),...jt(e.headers,n)},s;async function c(t){let r=Object.keys(o).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||r)return{};let a=(e.token===void 0?void 0:Mt(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new M(`"${t}" is a Pro item. Run "slabui login" or set ${A} to install it.`);return{authorization:`Bearer ${a}`}}async function l(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...o,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new M(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new M(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${A}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new M(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new M(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new M(`Not found: ${n}.`);if(!a.ok)throw new M(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function u(e,t,n,r){let i;try{i=JSON.parse(new TextDecoder().decode(t))}catch{throw new M(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new M(`${e} does not match the expected format:\n${p.prettifyError(a.error)}`);return a.data}async function d(){let t=`${a}/registry.json`,n=u(t,await l(t),Ct,At);return Ot.set(e.namespace,n),n}function f(){return s??=d().catch(e=>{throw s=void 0,e}),s}return{index:f,async item(t,n){let r=(await f()).items[t];if(r===void 0)throw new M(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new M(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let o=`${a}/${i.path}`,s=r.access===`pro`?await l(o,{extraHeaders:await c(t),pro:t}):await l(o);if(Nt(s)!==i.hash)throw new M(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,yt);if(d.name!==t||d.version!==n)throw new M(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function At(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new M(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new M(`${e} uses format ${r}, which is no longer supported. ${n}`)}function jt(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Mt(n,`the "${e}" header`,t)]))}function Mt(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new M(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function Nt(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function L(t,n){let r=e=>new M(`Path "${n}" refused: ${e}.`);if(n===``)throw r(`it is empty`);if(n.includes(`\0`))throw r(`it contains a null character`);if(n.includes(`\\`))throw r(`use / as the separator`);if(e.posix.isAbsolute(n)||e.win32.isAbsolute(n))throw r(`it is absolute`);let i=e.resolve(t),o=e.resolve(i,n);if(o===i)throw r(`it points to the project root`);if(!Pt(i,o))throw r(`it leaves the project root`);let s=await Ft(o);if(s===o&&(await a(o)).isSymbolicLink())throw r(`the target is a symbolic link`);let l=await c(i),u=await c(s).catch(()=>{throw r(`it goes through a broken symbolic link`)});if(!Pt(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function Pt(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function Ft(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const It=p.object({version:P,files:p.array(p.string().min(1))}),Lt=p.object({$schema:p.string().optional(),token:p.string().min(1).optional(),css:p.string().min(1).optional(),aliases:p.object({components:p.string().min(1),ui:p.string().min(1),lib:p.string().min(1),hooks:p.string().min(1),utils:p.string().min(1),styles:p.string().min(1)}),items:p.record(N,It).default({})}),Rt=[`tsconfig.json`,`jsconfig.json`],zt=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function R(e){return i(e).then(()=>!0,()=>!1)}async function z(t){for(let n of Rt){let r=e.join(t,n);if(await R(r))try{return{path:r,config:_(r)}}catch(e){throw new M(`Could not read ${n}: ${e.message}`)}}throw new M(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function B(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function V(t,n,r){if(r===void 0)return;let i=B(t),a=i!==void 0&&r.startsWith(i)?H(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function Bt(t,n,r){let i=Ut(r)?e.resolve(n,r):H(t,r);return i===void 0?void 0:e.relative(n,i).split(e.sep).join(`/`)}function H(e,t){return g(e)?.(t)[0]}async function Vt(t){for(let n of zt)if(await R(e.join(t,n)))return n}async function U(t){let n=e.join(t,O),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new M(`${O} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new M(`${O} is not valid JSON.`)}let a=Lt.safeParse(i);if(!a.success)throw new M(`${O} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function Ht(t,n){await u(e.join(t,O),`${JSON.stringify(n,null,2)}\n`)}function Ut(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Wt(t){return await R(e.join(t,`src`))?`src`:`.`}async function Gt(t,{folder:n}={}){let{path:r}=await z(t),i=e.resolve(t,n??await Wt(t)),a=[r],o=[],c=b(await s(r,`utf8`)).references??[];for(let t of c){let n=e.resolve(e.dirname(r),t.path),i=n.endsWith(`.json`)?n:e.join(n,`tsconfig.json`);/app/.test(e.basename(i))&&await R(i)&&a.push(i)}for(let t of a){let n=await s(t,`utf8`),r=b(n);if(r.compilerOptions?.paths)continue;let a=e.resolve(e.dirname(t),r.compilerOptions?.baseUrl??`.`),c=e.relative(a,i).split(e.sep).join(`/`),l=c?`./${c}/*`:`./*`,d=n.match(/\n( +|\t)"/)?.[1]??` `,f=y(n,[`compilerOptions`,`paths`,`@/*`],[l],{formattingOptions:{insertSpaces:!d.startsWith(` `),tabSize:d.startsWith(` `)?1:d.length}});await u(t,v(n,f)),o.push(t)}return o}const W=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],Kt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,qt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function Jt(t){return e.posix.extname(t)===`.css`}function Yt(e,t){return e.replace(qt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Xt(t){return W.includes(e.posix.extname(t))}function Zt(e,t){return e.replace(Kt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Qt(e,t){return[e,...W.map(t=>`${e}${t}`),...W.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function $t(t){let n=e.posix.extname(t);return W.includes(n)?t.slice(0,-n.length):t}function G(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new M(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==k.namespace)throw new M(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!N.safeParse(r).success)throw new M(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new M(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function K(e){return e.name}function q(e,t=process.env){return{namespace:k.namespace,url:t.SLABUI_REGISTRY_URL||k.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function en(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=x.maxSatisfying(n,e.range);if(r===null)throw new M(`No version of "${K(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const tn={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function nn(t,n){if(t.target!==void 0){let r=t.target;return an((r.startsWith(B(n.tsconfig)??`\0`)?H(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in tn))throw new M(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[tn[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=Ut(r)?e.resolve(n.root,r,i):H(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new M(`Alias "${r}" does not match any "paths" in the tsconfig.`);return an(a,n)}function rn(t,n,r){let i=B(r.tsconfig),a=i===void 0?void 0:H(r.tsconfig,`${i}__slabui__`)?.slice(0,-10),o=e.resolve(r.root,t);if(i!==void 0&&a!==void 0&&o.startsWith(a))return`${i}${$t(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),$t(s)}function an(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function on(e){return e.kind===`block`||e.kind===`example`}function sn(e,t,n){return on(e)?fn(e,n):new Map(e.files.map(e=>[e.path,nn(e,t)]))}function cn(e,t){return[e,...t.dependencies.registry.map(e=>K(G(e)))]}async function ln(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=G(e),o=K(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(q(t.token));r.set(o,sn(await c.item(a.name,s.version),n))}}function un(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=Jt(e.path);if(!Xt(e.path)&&!s)return e.content;let c=cn(t,n),l=e=>{if(e===`slabui:css`){if(a.css===void 0){o.push(`"${t}": ${r} uses the global CSS, but "css" is not set in slabui.json.`);return}return dn(a.css,r)}if(!e.startsWith(`@/registry/`))return;let n=e.slice(11);for(let e of c){let t=i.get(e),o=t&&Qt(n,new Set(t.keys()));if(o){let e=t.get(o);return s?dn(e,r):rn(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?Yt(e.content,l):Zt(e.content,l)}function dn(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function fn(t,n){let r=t.files.map(t=>e.posix.dirname(t.path).split(`/`)),i=[];for(let[e,t]of(r[0]??[]).entries())if(r.every(n=>n[e]===t))i.push(t);else break;let a=i.join(`/`),o=e.posix.normalize(n.split(e.sep).join(`/`));return new Map(t.files.map(t=>[t.path,e.posix.join(o,e.posix.relative(a,t.path))]))}const pn=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function mn(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function hn(t){let n=(await gn(t))?.packageManager?.split(`@`)[0];if(n&&[`pnpm`,`npm`,`yarn`,`bun`].includes(n))return n;let r=e.resolve(t);for(;;){for(let[t,n]of pn)if(await R(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function gn(t){let n=await s(e.join(t,`package.json`),`utf8`).catch(()=>void 0);return n===void 0?void 0:JSON.parse(n)}async function _n(e,{npm:t,npmDev:n}){let r=await gn(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=mn(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=x.minVersion(o);r&&s&&!x.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function vn(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function yn(e,t,n,r){if(n.length===0)return;let[i,a]=vn(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new M(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new M(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function bn(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await _n(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${mn(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await hn(e);return await yn(e,s,a.install,!1),await yn(e,s,a.installDev,!0),o}async function xn({refs:e,config:t,createClient:n=e=>I(e)}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=[],s=/* @__PURE__ */ new Set,c=[];function l(e){let t=r.get(e.namespace);return t===void 0&&(t=n(e),r.set(e.namespace,t)),t}async function u(e,n){let r=K(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!x.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>Sn(p,e)))return;let m=q(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new M(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let _=Object.keys(g.versions),v=d.flatMap(({range:e})=>e?[e]:[]),y=v.length===0?g.latest:x.rsort(_.filter(e=>v.every(t=>x.satisfies(e,t))))[0]??null;if(y===null)throw new M(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${x.sort(_).join(`, `)}.`);let b=await h.item(e.name,y);a.set(r,{key:r,registry:m,item:b});for(let e of b.dependencies.registry)await u(G(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(G(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function Sn(e,t){return t===void 0||x.satisfies(e.item.version,t)}const Cn=`fonts.css`,wn=`base.css`,Tn=`utilities.css`,En=On([`background`,`foreground`,`border`,`input`,`ring`,`brand`,`brand-foreground`,`primary`,`primary-foreground`,`secondary`,`secondary-foreground`,`danger`,`danger-foreground`,`success`,`success-foreground`,`warning`,`warning-foreground`,`inverted`,`inverted-foreground`,`radius`,`spacing`,`font-size`,`scrollbar-thumb`]);function Dn(e){let t={},n={};for(let[r,i]of Object.entries(e.theme??{}))(he(r)?t:n)[r]=i;let{theme:r,...i}=e;return{globals:{...i,...Object.keys(n).length>0&&{theme:n}},fonts:Object.keys(t).length>0?{theme:t}:{}}}function On(e,{theme:t=`all`}={}){let n=new Set(e),r=e=>Object.fromEntries(Object.entries(e).filter(([e])=>n.has(e))),i=/* @__PURE__ */ new Set([...Object.keys(D.light),...Object.keys(D.dark)]);return{theme:Object.fromEntries(Object.entries(D.theme).filter(([,e])=>{let r=[...e.matchAll(/var\(--([\w-]+)/g)].map(([,e])=>e).filter(e=>i.has(e));return r.every(e=>n.has(e))?t===`all`||r.length>0:!1})),light:r(D.light),dark:r(D.dark)}}async function kn(t,n,r,{replace:i=!1}={}){let a=await L(t,n),c=await s(a,`utf8`).catch(()=>void 0),l;i&&c!==void 0&&(l=await An(t,n,c));let d=i?void 0:c,f=await J(t,n,r,Cn),p=await L(t,f),m=await s(p,`utf8`).catch(()=>void 0),h=d===void 0||m!==void 0,{globals:g,fonts:_}=Dn(En),v=await Pe(d??`@import "tailwindcss";
|
|
146
|
-
`,h?g:
|
|
145
|
+
</svg>`;function Ze(t=process.env,n=process.platform,r=m()){let i=n===`win32`?e.join(t.APPDATA??e.join(r,`AppData/Roaming`),`slabui`):e.join(t.XDG_CONFIG_HOME||e.join(r,`.config`),`slabui`);return e.join(i,`credentials.json`)}async function Qe(e=Ze()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function $e(t,n=Ze()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function et(e=Ze()){let t=await Qe(e)!==void 0;return await l(e,{force:!0}),t}async function tt({registryUrl:e,token:t,fetch:n=globalThis.fetch,headers:r={}}){let i=`${e.replace(/\/+$/,``)}/whoami.json`,a=await n(i,{headers:{...r,authorization:`Bearer ${t.trim()}`},signal:AbortSignal.timeout(15e3)});if(a.status===401)return null;if(!a.ok)throw Error(`Error ${a.status} while fetching ${i}.`);let o=await a.json();return{...o,access:o.access??[]}}function nt(){return f(24).toString(`base64url`)}function rt({registryUrl:e,callback:t,state:n,client:r,host:i=h()}){let a=new URL(`/cli/authorize`,new URL(e).origin);return a.searchParams.set(`callback`,t),a.searchParams.set(`state`,n),a.searchParams.set(`client`,r),a.searchParams.set(`host`,i.replace(/\.local$/,``).slice(0,60)),a.toString()}var M=class extends Error{name=`SlabUIError`};const N=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),it=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),P=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),at=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),F=p.enum(Ve),ot=p.enum(He),st=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),ct=p.object({registry:p.array(st).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),lt=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],ut=[e=>e.files.length>0||e.cssVars!==void 0||e.css!==void 0||(e.utilities?.length??0)>0||(e.variants?.length??0)>0||e.base!==void 0,{message:`the item needs files, cssVars or CSS rules`,path:[`files`]}],dt=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional()}).refine(...lt),ft=p.object({path:p.string().min(1),kind:F,target:p.string().min(1).optional(),content:p.string()}).refine(...lt),pt=p.record(p.string(),p.string()),mt=p.object({theme:pt.optional(),light:pt.optional(),dark:pt.optional()}),ht=p.record(p.string().min(1),p.record(p.string().min(1),p.string().min(1))),gt=p.string().regex(/^[a-z][\w-]*$/),_t=p.object({utilities:p.record(gt,p.string().min(1)).optional(),variants:p.record(gt,p.string().min(1)).optional(),base:ht.optional()}),vt={name:N,kind:F,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:ct.prefault({}),cssVars:mt.optional()},yt=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...vt,version:P,files:p.array(ft).default([]),css:_t.optional()}).refine(...ut);p.object({...vt,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:ot.optional(),inferDependencies:p.boolean().optional(),files:p.array(dt).default([]),utilities:p.array(gt).optional(),variants:p.array(gt).optional(),base:ht.optional()}).refine(...ut);const bt=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),xt=p.object({hash:at,path:bt}),St=p.object({kind:F,title:p.string().min(1).optional(),description:p.string().min(1),categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:ot.optional(),dependencies:ct.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:P,versions:p.record(P,xt)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Ct=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:it.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(N,St)});let wt;function Tt(e){wt=e}function Et(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Dt(e,t=wt){let n={"user-agent":`slabui/${T}`};return Et(e)?n[Be.optOut]=`off`:t&&(n[Be.command]=t),n}const Ot=/* @__PURE__ */ new Map;function kt(e){return Ot.get(e)}function I(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>Qe()}={}){let a=e.url.replace(/\/+$/,``),o={...Dt(n,r),...jt(e.headers,n)},s;async function c(t){let r=Object.keys(o).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||r)return{};let a=(e.token===void 0?void 0:Mt(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new M(`"${t}" is a Pro item. Run "slabui login" or set ${A} to install it.`);return{authorization:`Bearer ${a}`}}async function l(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...o,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new M(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new M(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${A}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new M(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new M(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new M(`Not found: ${n}.`);if(!a.ok)throw new M(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function u(e,t,n,r){let i;try{i=JSON.parse(new TextDecoder().decode(t))}catch{throw new M(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new M(`${e} does not match the expected format:\n${p.prettifyError(a.error)}`);return a.data}async function d(){let t=`${a}/registry.json`,n=u(t,await l(t),Ct,At);return Ot.set(e.namespace,n),n}function f(){return s??=d().catch(e=>{throw s=void 0,e}),s}return{index:f,async item(t,n){let r=(await f()).items[t];if(r===void 0)throw new M(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new M(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let o=`${a}/${i.path}`,s=r.access===`pro`?await l(o,{extraHeaders:await c(t),pro:t}):await l(o);if(Nt(s)!==i.hash)throw new M(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,yt);if(d.name!==t||d.version!==n)throw new M(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function At(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new M(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new M(`${e} uses format ${r}, which is no longer supported. ${n}`)}function jt(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Mt(n,`the "${e}" header`,t)]))}function Mt(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new M(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function Nt(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function L(t,n){let r=e=>new M(`Path "${n}" refused: ${e}.`);if(n===``)throw r(`it is empty`);if(n.includes(`\0`))throw r(`it contains a null character`);if(n.includes(`\\`))throw r(`use / as the separator`);if(e.posix.isAbsolute(n)||e.win32.isAbsolute(n))throw r(`it is absolute`);let i=e.resolve(t),o=e.resolve(i,n);if(o===i)throw r(`it points to the project root`);if(!Pt(i,o))throw r(`it leaves the project root`);let s=await Ft(o);if(s===o&&(await a(o)).isSymbolicLink())throw r(`the target is a symbolic link`);let l=await c(i),u=await c(s).catch(()=>{throw r(`it goes through a broken symbolic link`)});if(!Pt(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function Pt(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function Ft(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const It=p.object({version:P,files:p.array(p.string().min(1))}),Lt=p.object({$schema:p.string().optional(),token:p.string().min(1).optional(),css:p.string().min(1).optional(),aliases:p.object({components:p.string().min(1),ui:p.string().min(1),lib:p.string().min(1),hooks:p.string().min(1),utils:p.string().min(1),styles:p.string().min(1)}),items:p.record(N,It).default({})}),Rt=[`tsconfig.json`,`jsconfig.json`],zt=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function R(e){return i(e).then(()=>!0,()=>!1)}async function z(t){for(let n of Rt){let r=e.join(t,n);if(await R(r))try{return{path:r,config:_(r)}}catch(e){throw new M(`Could not read ${n}: ${e.message}`)}}throw new M(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function B(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function Bt(t,n,r){if(r===void 0)return;let i=B(t),a=i!==void 0&&r.startsWith(i)?V(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function Vt(t,n,r){let i=Wt(r)?e.resolve(n,r):V(t,r);return i===void 0?void 0:e.relative(n,i).split(e.sep).join(`/`)}function V(e,t){return g(e)?.(t)[0]}async function Ht(t){for(let n of zt)if(await R(e.join(t,n)))return n}async function H(t){let n=e.join(t,O),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new M(`${O} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new M(`${O} is not valid JSON.`)}let a=Lt.safeParse(i);if(!a.success)throw new M(`${O} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function Ut(t,n){await u(e.join(t,O),`${JSON.stringify(n,null,2)}\n`)}function Wt(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Gt(t){return await R(e.join(t,`src`))?`src`:`.`}async function Kt(t,{folder:n}={}){let{path:r}=await z(t),i=e.resolve(t,n??await Gt(t)),a=[r],o=[],c=b(await s(r,`utf8`)).references??[];for(let t of c){let n=e.resolve(e.dirname(r),t.path),i=n.endsWith(`.json`)?n:e.join(n,`tsconfig.json`);/app/.test(e.basename(i))&&await R(i)&&a.push(i)}for(let t of a){let n=await s(t,`utf8`),r=b(n);if(r.compilerOptions?.paths)continue;let a=e.resolve(e.dirname(t),r.compilerOptions?.baseUrl??`.`),c=e.relative(a,i).split(e.sep).join(`/`),l=c?`./${c}/*`:`./*`,d=n.match(/\n( +|\t)"/)?.[1]??` `,f=y(n,[`compilerOptions`,`paths`,`@/*`],[l],{formattingOptions:{insertSpaces:!d.startsWith(` `),tabSize:d.startsWith(` `)?1:d.length}});await u(t,v(n,f)),o.push(t)}return o}const qt=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],Jt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,Yt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function Xt(t){return e.posix.extname(t)===`.css`}function Zt(e,t){return e.replace(Yt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Qt(t){return qt.includes(e.posix.extname(t))}function $t(e,t){return e.replace(Jt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function en(e,t){return[e,...qt.map(t=>`${e}${t}`),...qt.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function tn(t){let n=e.posix.extname(t);return qt.includes(n)?t.slice(0,-n.length):t}function U(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new M(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==k.namespace)throw new M(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!N.safeParse(r).success)throw new M(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new M(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function W(e){return e.name}function G(e,t=process.env){return{namespace:k.namespace,url:t.SLABUI_REGISTRY_URL||k.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function nn(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=x.maxSatisfying(n,e.range);if(r===null)throw new M(`No version of "${W(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const rn={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function an(t,n){if(t.target!==void 0){let r=t.target;return sn((r.startsWith(B(n.tsconfig)??`\0`)?V(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in rn))throw new M(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[rn[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=Wt(r)?e.resolve(n.root,r,i):V(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new M(`Alias "${r}" does not match any "paths" in the tsconfig.`);return sn(a,n)}function on(t,n,r){let i=B(r.tsconfig),a=i===void 0?void 0:V(r.tsconfig,`${i}__slabui__`)?.slice(0,-10),o=e.resolve(r.root,t);if(i!==void 0&&a!==void 0&&o.startsWith(a))return`${i}${tn(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),tn(s)}function sn(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function K(e){return e.kind===`block`||e.kind===`example`}function cn(e,t,n){return K(e)?pn(e,n):new Map(e.files.map(e=>[e.path,an(e,t)]))}function ln(e,t){return[e,...t.dependencies.registry.map(e=>W(U(e)))]}async function un(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=U(e),o=W(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(G(t.token));r.set(o,cn(await c.item(a.name,s.version),n))}}function dn(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=Xt(e.path);if(!Qt(e.path)&&!s)return e.content;let c=ln(t,n),l=e=>{if(e===`slabui:css`){if(a.css===void 0){o.push(`"${t}": ${r} uses the global CSS, but "css" is not set in slabui.json.`);return}return fn(a.css,r)}if(!e.startsWith(`@/registry/`))return;let n=e.slice(11);for(let e of c){let t=i.get(e),o=t&&en(n,new Set(t.keys()));if(o){let e=t.get(o);return s?fn(e,r):on(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?Zt(e.content,l):$t(e.content,l)}function fn(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function pn(t,n){let r=t.files.map(t=>e.posix.dirname(t.path).split(`/`)),i=[];for(let[e,t]of(r[0]??[]).entries())if(r.every(n=>n[e]===t))i.push(t);else break;let a=i.join(`/`),o=e.posix.normalize(n.split(e.sep).join(`/`));return new Map(t.files.map(t=>[t.path,e.posix.join(o,e.posix.relative(a,t.path))]))}const mn=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function hn(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function gn(t){let n=(await _n(t))?.packageManager?.split(`@`)[0];if(n&&[`pnpm`,`npm`,`yarn`,`bun`].includes(n))return n;let r=e.resolve(t);for(;;){for(let[t,n]of mn)if(await R(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function _n(t){let n=await s(e.join(t,`package.json`),`utf8`).catch(()=>void 0);return n===void 0?void 0:JSON.parse(n)}async function vn(e,{npm:t,npmDev:n}){let r=await _n(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=hn(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=x.minVersion(o);r&&s&&!x.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function yn(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function bn(e,t,n,r){if(n.length===0)return;let[i,a]=yn(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new M(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new M(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function xn(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await vn(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${hn(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await gn(e);return await bn(e,s,a.install,!1),await bn(e,s,a.installDev,!0),o}async function Sn({refs:e,config:t,createClient:n=e=>I(e)}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=[],s=/* @__PURE__ */ new Set,c=[];function l(e){let t=r.get(e.namespace);return t===void 0&&(t=n(e),r.set(e.namespace,t)),t}async function u(e,n){let r=W(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!x.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>Cn(p,e)))return;let m=G(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new M(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let _=Object.keys(g.versions),v=d.flatMap(({range:e})=>e?[e]:[]),y=v.length===0?g.latest:x.rsort(_.filter(e=>v.every(t=>x.satisfies(e,t))))[0]??null;if(y===null)throw new M(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${x.sort(_).join(`, `)}.`);let b=await h.item(e.name,y);a.set(r,{key:r,registry:m,item:b});for(let e of b.dependencies.registry)await u(U(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(U(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function Cn(e,t){return t===void 0||x.satisfies(e.item.version,t)}const wn=`fonts.css`,Tn=`base.css`,En=`utilities.css`,Dn=kn([`background`,`foreground`,`border`,`input`,`ring`,`brand`,`brand-foreground`,`primary`,`primary-foreground`,`secondary`,`secondary-foreground`,`danger`,`danger-foreground`,`success`,`success-foreground`,`warning`,`warning-foreground`,`inverted`,`inverted-foreground`,`radius`,`spacing`,`font-size`,`scrollbar-thumb`]);function On(e){let t={},n={};for(let[r,i]of Object.entries(e.theme??{}))(he(r)?t:n)[r]=i;let{theme:r,...i}=e;return{globals:{...i,...Object.keys(n).length>0&&{theme:n}},fonts:Object.keys(t).length>0?{theme:t}:{}}}function kn(e,{theme:t=`all`}={}){let n=new Set(e),r=e=>Object.fromEntries(Object.entries(e).filter(([e])=>n.has(e))),i=/* @__PURE__ */ new Set([...Object.keys(D.light),...Object.keys(D.dark)]);return{theme:Object.fromEntries(Object.entries(D.theme).filter(([,e])=>{let r=[...e.matchAll(/var\(--([\w-]+)/g)].map(([,e])=>e).filter(e=>i.has(e));return r.every(e=>n.has(e))?t===`all`||r.length>0:!1})),light:r(D.light),dark:r(D.dark)}}async function An(t,n,r,{replace:i=!1}={}){let a=await L(t,n),c=await s(a,`utf8`).catch(()=>void 0),l;i&&c!==void 0&&(l=await jn(t,n,c));let d=i?void 0:c,f=await q(t,n,r,wn),p=await L(t,f),m=await s(p,`utf8`).catch(()=>void 0),h=d===void 0||m!==void 0,{globals:g,fonts:_}=On(Dn),v=await Pe(d??`@import "tailwindcss";
|
|
146
|
+
`,h?g:Dn);(d===void 0||v.css!==d)&&(await o(e.dirname(a),{recursive:!0}),await u(a,v.css));let y=[...v.changes],b=[];if(h){let e=await Pe(m??`/* Typography: font families and the text-* scale, imported by the global CSS.
|
|
147
147
|
Every text-* class is proportional to --font-size (set in :root in the
|
|
148
148
|
global CSS): change it to make all text larger or smaller. Line heights are
|
|
149
149
|
unitless ratios, so they follow the font size on their own. */
|
|
150
|
-
`,_);y.push(...e.changes),m===void 0?(await
|
|
150
|
+
`,_);y.push(...e.changes),m===void 0?(await J(t,n,r,wn,e.css),b.push(f)):e.css!==m&&await u(p,e.css)}return d===void 0&&await J(t,n,r,`base.css`,`/* Element styles (*, html, body), imported by the global CSS. The theme
|
|
151
151
|
variables stay in the global CSS; components add here what they need in
|
|
152
152
|
the whole app. */
|
|
153
153
|
|
|
@@ -181,7 +181,7 @@ button:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px;
|
|
|
181
181
|
text-rendering: optimizeLegibility;
|
|
182
182
|
}
|
|
183
183
|
}
|
|
184
|
-
`)&&b.push(await
|
|
184
|
+
`)&&b.push(await q(t,n,r,Tn)),await J(t,n,r,`utilities.css`,`/* @utility and @custom-variant, imported by the global CSS. slabui add
|
|
185
185
|
adds the ones components use; the ones you change are kept as they are. */
|
|
186
186
|
|
|
187
187
|
@utility no-scrollbar {
|
|
@@ -192,30 +192,31 @@ button:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px;
|
|
|
192
192
|
display: none;
|
|
193
193
|
}
|
|
194
194
|
}
|
|
195
|
-
`)&&b.push(await
|
|
195
|
+
`)&&b.push(await q(t,n,r,En)),{created:c===void 0,...l&&{backup:l},changes:y,files:b}}async function jn(e,t,n){for(let r=0;;r++){let i=r===0?`${t}.bak`:`${t}.bak.${r}`,a=await L(e,i);if(!await s(a).then(()=>!0).catch(()=>!1))return await u(a,n),i}}async function Mn(e,t,n,r,{styles:i,...a}){if(t===void 0)return a.warnings.push(`"${n}": has CSS variables, but "css" is not set in slabui.json; add them to your CSS manually.`),[];await Fn(e,t,i,a.warnings);let o=await q(e,t,i,wn),c=await s(await L(e,o)).then(()=>!0).catch(()=>!1),l=e=>c?On(e):{globals:e,fonts:{}},d=l(r),f=a.base?l(a.base):void 0,p=[];for(let[r,i]of[[t,`globals`],[o,`fonts`]]){let t=d[i],o=f?.[i];if(i===`fonts`&&Object.keys(t).length===0&&Object.keys(o??{}).length===0)continue;let c=await L(e,r),l=await s(c,`utf8`),m=await Pe(l,t,{...a,base:o});a.warnings.push(...m.warnings.map(e=>`"${n}": ${e}`)),m.css!==l&&await u(c,m.css),p.push(...m.changes)}return p}async function Nn(e,t,n,r,i,a){if(t===void 0||r===void 0||r.length===0)return[];let o=kn(r,{theme:`aliases`}),s=[],c=await Mn(e,t,n,o,{overwrite:!1,warnings:s,styles:a});return i.push(...s.filter(e=>!e.includes(`custom value`))),c.filter(({action:e})=>e===`added`)}async function Pn(e,t,n,r,i){let{warnings:a,styles:o,...c}=i,l=e=>Object.keys(r[e]??{}).length>0||Object.keys(i.base?.[e]??{}).length>0,d=l(`utilities`)||l(`variants`),f=l(`base`);if(!d&&!f)return[];if(t===void 0)return a.push(`"${n}": has CSS rules (@utility, @custom-variant or base), but "css" is not set in slabui.json; add them to your CSS manually.`),[];await Fn(e,t,o,a);let p=[],m=async(r,i,c)=>{await J(e,t,o,r,i);let l=await L(e,await q(e,t,o,r)),d=await s(l,`utf8`),f=await c(d);a.push(...f.warnings.map(e=>`"${n}": ${e}`)),f.css!==d&&await u(l,f.css),p.push(...f.changes)};return d&&await m(En,`/* @utility and @custom-variant, imported by the global CSS. slabui add
|
|
196
196
|
adds the ones components use; the ones you change are kept as they are. */
|
|
197
|
-
`,e=>Fe(e,r,c)),f&&await m(
|
|
197
|
+
`,e=>Fe(e,r,c)),f&&await m(Tn,`/* Element styles (*, html, body), imported by the global CSS. The theme
|
|
198
198
|
variables stay in the global CSS; components add here what they need in
|
|
199
199
|
the whole app. */
|
|
200
|
-
`,e=>Ie(e,r.base,c)),p}async function
|
|
201
|
-
`);if(!(a&&await a(`These files already exist and will be overwritten:\n${e}\nContinue?`)))throw new M(`These files already exist in the project:\n${e}\nUse --overwrite to overwrite them.`)}let ee=[],
|
|
202
|
-
`)}async function Gn({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>I(e)}){let a=await
|
|
200
|
+
`,e=>Ie(e,r.base,c)),p}async function Fn(e,t,n,r){let i=await L(e,t),a=await s(i,`utf8`).catch(()=>void 0);return a===void 0?(await An(e,t,n),r.push(`${t} did not exist; it was created with the default template.`),s(i,`utf8`)):a}async function q(t,n,r,i){let a=e.posix.join(e.posix.dirname(Y(n)),i);if(r===void 0)return a;for(let n of[a,e.posix.join(Y(r),i)])if(await s(await L(t,n)).then(()=>!0).catch(()=>!1))return n;return e.posix.join(Y(r),`core`,i)}async function J(t,n,r,i,a){let c=await q(t,n,r,i),l=await L(t,c),d=await s(l,`utf8`).then(()=>!0).catch(()=>!1);d||(await o(e.dirname(l),{recursive:!0}),await u(l,a));let f=await L(t,n),p=await s(f,`utf8`),m=Le(p,In(n,c));return m!==p&&await u(f,m),!d}function In(t,n){let r=e.posix.relative(e.posix.dirname(Y(t)),Y(n));return r.startsWith(`.`)?r:`./${r}`}const Y=e=>e.replaceAll(`\\`,`/`);async function Ln({root:t,refs:n,overwrite:r=!1,skipInstall:i=!1,confirm:a,path:s,askPath:c,createClient:l=e=>I(e)}){let d=await H(t),f=await z(t),p={root:t,aliases:d.aliases,tsconfig:f,css:Bt(f,t,d.css)},m=Vt(f,t,d.aliases.styles),h=/* @__PURE__ */ new Map,g=e=>{let t=h.get(e.namespace);return t===void 0&&(t=l(e),h.set(e.namespace,t)),t},_=Object.keys(d.items).length===0,v=await Sn({refs:n,config:d,createClient:g}),y=[...v.warnings],b=v.items.filter(({item:e})=>K(e)),x=s;if(b.length>0&&x===void 0){let e=b.map(({key:e})=>e);if(c===void 0)throw new M(`${e.map(e=>`"${e}"`).join(`, `)} ${e.length>1?`are blocks or examples`:`is a block or example`}: pass the folder with --path.`);x=await c(e)}let S=/* @__PURE__ */ new Map;for(let{key:e,item:t}of v.items)S.set(e,cn(t,p,x));await un(v.items.map(({item:e})=>e),{config:d,context:p,destinations:S,clientFor:g});let C=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(d.items))for(let n of t.files)C.set(n,e);let w=[];for(let{key:n}of v.items)for(let r of S.get(n)?.values()??[])if(await L(t,r),await R(e.join(t,r))){let e=C.get(r);w.push(e?`${r} (from "${e}")`:r)}if(w.length>0&&!r){let e=w.map(e=>` ${e}`).join(`
|
|
201
|
+
`);if(!(a&&await a(`These files already exist and will be overwritten:\n${e}\nContinue?`)))throw new M(`These files already exist in the project:\n${e}\nUse --overwrite to overwrite them.`)}let ee=[],te=[],ne=[];for(let{key:n,item:i,registry:a}of v.items){let s=S.get(n);for(let r of i.files){let a=s.get(r.path),c=dn(r,{key:n,item:i,destination:a,destinations:S,context:p,warnings:y}),l=await L(t,a);await o(e.dirname(l),{recursive:!0}),await u(l,c)}if(a.namespace===k.namespace){let e=(await g(a).index()).items[i.name]?.tokens;te.push(...await Nn(t,p.css,n,e,y,m))}i.cssVars!==void 0&&te.push(...await Mn(t,p.css,n,i.cssVars,{overwrite:r,warnings:y,styles:m})),i.css!==void 0&&ne.push(...await Pn(t,p.css,n,i.css,{overwrite:r,warnings:y,styles:m}));let c=[...s.values()];K(i)||(d.items[n]={version:i.version,files:c}),ee.push({key:n,version:i.version,files:c,block:K(i)})}await Ut(t,d);let T=await xn(t,{npm:v.items.flatMap(({item:e})=>e.dependencies.npm),npmDev:v.items.flatMap(({item:e})=>e.dependencies.npmDev)},{confirm:a,skipInstall:i,warnings:y}),re=[],E=v.items[0]?.registry;if(_&&E!==void 0){let e=(await g(E).index()).license;e!==void 0&&re.push({namespace:E.namespace,url:e})}return{added:ee,installed:v.installed,packages:T,cssChanges:te,ruleChanges:ne,licenses:re,warnings:y}}function X(e){return!e&&!!(process.stdin.isTTY&&process.stdout.isTTY)}function Rn(e){if(C.isCancel(e))throw C.cancel(`Cancelled.`),new M(`Operation cancelled.`);return e}async function Z(e,t=``){return Rn(await C.text({message:e,initialValue:t}))}async function Q(e,t=!0){return Rn(await C.confirm({message:e,initialValue:t}))}async function zn(e,t){return Rn(await C.select({message:e,options:t}))}async function Bn(e,t,n=[]){return Rn(await C.multiselect({message:e,options:t,initialValues:n,required:!0}))}const Vn=new t(`add`).description(`Installs items and their dependencies (default: latest version)`).argument(`<items...>`,`e.g. button, button@1.1.0, @acme/table`).option(`-y, --yes`,`never prompt; fail instead of overwriting`).option(`-o, --overwrite`,`overwrite existing files`).option(`--skip-install`,`skip installing npm packages`).option(`--path <dir>`,`folder for blocks and examples`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=X(n.yes),i=await Ln({root:e.resolve(n.cwd),refs:t,overwrite:n.overwrite,skipInstall:n.skipInstall,path:n.path,confirm:r?Q:void 0,askPath:r?e=>Z(`Where should ${e.join(`, `)} be installed? (relative to the project root)`,`components`):void 0});for(let{key:e,version:t,files:n,block:r}of i.added){console.log(`+ ${e}@${t}${r?` (copied, not tracked in items)`:``}`);for(let e of n)console.log(` ${e}`)}for(let e of i.installed)console.log(`= ${e} (already installed)`);i.packages.length>0&&console.log(`Installed packages: ${i.packages.join(` `)}`);let a=ze(i.cssChanges);a&&console.log(a);let o=Re(i.ruleChanges);o&&console.log(o);for(let{namespace:e,url:t}of i.licenses)console.log(`Items from ${e} are licensed under ${t}`);for(let e of i.warnings)console.warn(`warning: ${e}`)});function Hn(e,t,n,r=!1){if(n.range!==void 0)return{version:nn(n,e)};if(r)return{version:e.latest};let i=nn({...n,range:`${x.major(t)}.x`},{...e,versions:{...e.versions,[t]:{hash:``,path:``}}}),a=x.gt(t,i)?t:i;return{version:a,newerMajor:x.major(e.latest)>x.major(a)?e.latest:void 0}}async function Un({key:t,version:n,major:r,config:i,context:a,clientFor:o}){let c=U(n?`${t}@${n}`:t),l=c.name,u=i.items[l];if(u===void 0)throw new M(`"${l}" is not installed. Blocks and examples are not updated; for other items, use "slabui add ${l}".`);let d=G(i.token),f=o(d),p=(await f.index()).items[c.name];if(p===void 0)throw new M(`Item "${c.name}" no longer exists in the "${d.namespace}" registry.`);let m=Hn(p,u.version,c,r),h=await f.item(c.name,u.version),g=m.version===u.version?h:await f.item(c.name,m.version),_=[],v=async e=>{let t=/* @__PURE__ */ new Map([[l,cn(e,a)]]);await un([e],{config:i,context:a,destinations:t,clientFor:o});let n=t.get(l);return new Map(e.files.map(r=>{let i=n.get(r.path);return[i,Wn(dn(r,{key:l,item:e,destination:i,destinations:t,context:a,warnings:_}))]}))},y=await v(h),b=await v(g),x=[.../* @__PURE__ */ new Set([...y.keys(),...b.keys()])];return{key:l,registry:d,base:h,remote:g,files:await Promise.all(x.map(async t=>{let n=await s(e.join(a.root,t),`utf8`).then(Wn).catch(()=>void 0);return{destination:t,base:y.get(t),remote:b.get(t),local:n}})),newerMajor:m.newerMajor,warnings:_}}function Wn(e){return e.replace(/\r\n/g,`
|
|
202
|
+
`)}async function Gn({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>I(e)}){let a=await H(e),o=await z(e),s={root:e,aliases:a.aliases,tsconfig:o,css:Bt(o,e,a.css)},[c,l]=Kn(t),u=await Un({key:c,version:l,major:r,config:a,context:s,clientFor:i}),d=n?`base`:`local`,f=n?`local`:`remote`,p=u.files.flatMap(e=>{let t=e[d]??``,r=e[f]??``;return t===r?[]:[w(`a/${e.destination}`,`b/${e.destination}`,t,r,n?u.base.version:`local`,n?`local`:u.remote.version)]});return{comparison:u,patches:p,changed:p.length>0}}function Kn(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}const qn=new t(`diff`).description(`Shows the difference between the local and the remote version`).argument(`<item>`,`installed item (optional version: button@2)`).option(`--local`,`show only what changed in the project (base → local)`).option(`--major`,`compare with the latest version, even in another major`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let{comparison:r,patches:i,changed:a}=await Gn({root:e.resolve(n.cwd),ref:t,local:n.local,major:n.major}),{key:o,base:s,remote:c,newerMajor:l}=r;for(let e of r.warnings)console.warn(`warning: ${e}`);a||console.log(n.local?`${o}: no local changes since ${s.version}.`:`${o}: local matches ${c.version}.`);for(let e of i)process.stdout.write(e);l&&!n.local&&console.log(`\n${o}@${l} is available (new major): slabui diff ${o} --major`),a&&(process.exitCode=1)});function Jn(e,t,{type:n}={}){let r=/* @__PURE__ */ new Map,i=new ee({fields:[`name`,`title`,`description`,`categories`,`keywords`,`kind`],searchOptions:{boost:{name:4,title:3,keywords:2,categories:1.5},fuzzy:.2,prefix:!0,combineWith:`AND`}});for(let{namespace:t,isDefault:a,index:o}of e)for(let[e,s]of Object.entries(o.items)){if(n!==void 0&&s.kind!==n)continue;let o=a?e:`${t}/${e}`;r.set(o,{key:o,name:e,namespace:t,entry:s}),i.add({id:o,name:`${e} ${e.replaceAll(`-`,` `)}`,title:s.title??``,description:s.description,categories:(s.categories??[]).join(` `),keywords:(s.keywords??[]).join(` `),kind:s.kind})}return i.search(t).map(({id:e,score:t})=>({...r.get(e),score:t}))}const Yn=e=>I(e);async function Xn(t){return await R(e.join(t,`slabui.json`))?H(t):void 0}async function Zn({root:e,term:t,type:n,createClient:r=Yn}){let i=G((await Xn(e))?.token);try{let e=await r(i).index();return{results:Jn([{namespace:i.namespace,isDefault:!0,index:e}],t,{type:n}),warnings:[]}}catch(e){return{results:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function Qn({root:e,ref:t,createClient:n=Yn}){let r=await Xn(e),i=U(t),a=G(r?.token),o=n(a),s=(await o.index()).items[i.name];if(s===void 0)throw new M(`Item "${i.name}" does not exist in the "${a.namespace}" registry.`);let c=await o.item(i.name,nn(i,s)),l=W(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await z(e)};u=c.files.map(e=>{try{return an(e,t)}catch{return e.path}})}return{key:l,registry:a,entry:s,item:c,installed:r?.items[l]?.version,destinations:u}}const $n=new t(`info`).description(`Shows versions, files and dependencies of an item`).argument(`<item>`,`item name, e.g. button, button@1.1.0, @acme/table`).option(`--json`,`print as JSON`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=await Qn({root:e.resolve(n.cwd),ref:t}),{item:i,entry:a}=r;if(n.json){console.log(JSON.stringify(r,null,2));return}let o=x.rsort(Object.keys(a.versions)).map(e=>[e,e===a.latest?`(latest)`:``,e===r.installed?`(installed)`:``].filter(Boolean).join(` `)),{registry:s,npm:c,npmDev:l}=i.dependencies;console.log(`${r.key}@${i.version} (${i.kind}${a.access===`pro`?`, pro`:``}, ${r.registry.namespace})`),i.title&&console.log(i.title),console.log(i.description),a.docs&&console.log(`Docs: ${a.docs}`),console.log(`\nVersions:\n${o.map(e=>` ${e}`).join(`
|
|
203
203
|
`)}`),r.installed||console.log(`
|
|
204
204
|
Not installed in this project.`),console.log(`
|
|
205
205
|
Files:`),i.files.forEach((e,t)=>{let n=r.destinations?.[t];console.log(` ${e.path}${n?` → ${n}`:``}`)});for(let[e,t]of[[`Registry dependencies`,s],[`npm packages`,c],[`npm dev packages`,l]])t.length>0&&console.log(`\n${e}:\n${t.map(e=>` ${e}`).join(`
|
|
206
|
-
`)}`)});async function er(e){let t=B(await z(e));if(t===void 0)throw new M(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await tr(e,`${t}styles`)}}async function tr(e,t){let n=await
|
|
207
|
-
`,c=[],l=b(a,c,{allowTrailingComma:!0});if(c.length>0||typeof l!=`object`||!l||Array.isArray(l))throw new M(`${r} is not valid JSON; fix it before running mcp init.`);let d=[];for(let e of n){let{name:t,url:n}=e,i=Object.fromEntries(Object.entries(e.headers).filter(([,e])=>e!==
|
|
208
|
-
`)?a:`${a}\n`),{file:r,warnings:d}}function
|
|
206
|
+
`)}`)});async function er(e){let t=B(await z(e));if(t===void 0)throw new M(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await tr(e,`${t}styles`)}}async function tr(e,t){let n=await Ht(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function nr({root:t,aliases:n,css:r,force:i=!1}){if(!i&&await R(e.join(t,`slabui.json`)))throw new M(`${O} already exists. Use --force to create it again.`);let a=await z(t);for(let[e,t]of Object.entries(n))if(!Wt(t)&&V(a,t)===void 0)throw new M(`Alias "${t}" (${e}) does not match any "paths" in the tsconfig.`);let o={$schema:`https://slabui.com/schema.json`,...r&&{css:r},aliases:n,items:{}};return await Ut(t,o),o}const rr=new t(`init`).description(`Creates ${O} at the project root`).option(`-y, --yes`,`use the detected values without prompting`).option(`-f, --force`,`overwrite an existing ${O}`).option(`--no-template`,`do not create or complete the global CSS with the default template`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd),r=X(t.yes);if(r&&C.intro(`slabui init`),B(await z(n))===void 0){if(r&&!await Q(`The tsconfig has no alias in "paths". Create "@/*" (used for file locations and imports)?`)){C.cancel(`Nothing was created. Add an alias to "paths" (e.g. "@/*": ["./src/*"]) and run init again.`);return}let t=await Gt(n),i=[{value:`src`,label:`./src (@/components → src/components)`},{value:`.`,label:`./ (@/components → components)`}],a=await Kt(n,{folder:r?await zn(`Where should "@/*" point?`,[...i.filter(({value:e})=>e===t),...i.filter(({value:e})=>e!==t)]):t});for(let t of a)console.log(`${e.relative(n,t)}: added "@/*" to "paths".`);await ir(n)&&console.log('Vite does not read "paths" by default: add `resolve: { tsconfigPaths: true }` to vite.config (or the vite-tsconfig-paths plugin).')}let i=await er(n),{aliases:a,css:o}=i,s=t.template;r&&(a={components:await Z(`Components alias`,a.components),ui:await Z(`UI components alias`,a.ui),lib:await Z(`Lib alias`,a.lib),hooks:await Z(`Hooks alias`,a.hooks),utils:await Z(`Utils alias`,a.utils),styles:await Z(`Styles alias`,a.styles)},o=await Z(`Global CSS file (empty if none)`,i.cssDetected?i.css:(await tr(n,a.styles)).css)||void 0,o&&s&&(s=await Q(`Add the default theme to ${o}? (creates the file if needed)`))),await nr({root:n,aliases:a,css:o,force:t.force}),console.log(`${O} created in ${n}.`);let c=await z(n),l=Bt(c,n,o);if(l&&s){let t=await R(e.join(n,l))&&(!r||await Q(`${l} already exists. Replace it with the SlabUI template? (the original is saved to ${l}.bak; No keeps it and only adds the missing variables)`)),{created:i,backup:o,changes:s,files:u}=await An(n,l,Vt(c,n,a.styles),{replace:t}),d=s.filter(({action:e})=>e===`added`).length;console.log(i?`${l}: created with the default template.`:o?`${l}: replaced with the default template (the original is in ${o}).`:`${l}: default template applied (${d} variables added).`);for(let e of u)console.log(`${e}: created (imported by ${l}).`)}});async function ir(t){for(let n of[`ts`,`mts`,`js`,`mjs`,`cjs`])if(await R(e.join(t,`vite.config.${n}`)))return!0;return!1}async function ar({token:e,fetch:t=globalThis.fetch,env:n=process.env,file:r=Ze(n)}){let i=G(void 0,n),a;try{a=await tt({registryUrl:i.url,token:e,fetch:t,headers:Dt(n,`login`)})}catch(e){throw e instanceof Error&&e.message.startsWith(`Error 404`)?new M(`${i.url} does not support login.`):new M(e instanceof Error&&e.message.startsWith(`Error `)?e.message:`Could not reach ${i.url}.`)}if(a===null)throw new M(`Invalid token. Check it and try again.`);return await $e(e.trim(),r),{account:a,url:i.url,file:r}}async function or({root:e,onUrl:t,timeout:n=3e5,...r}){let i=G(void 0,r.env),a=nt();return ar({root:e,token:await new Promise((e,r)=>{let o=te((t,n)=>{let i=new URL(t.url??`/`,`http://127.0.0.1`);if(i.pathname!==`/callback`||i.searchParams.get(`state`)!==a){n.writeHead(404).end();return}let o=i.searchParams.get(`token`);n.writeHead(200,{"content-type":`text/html; charset=utf-8`}),n.end(Ue(o?{status:`success`,title:`You're signed in`,message:`Go back to the terminal. You can close this tab.`}:{status:`error`,title:`Sign-in cancelled`,message:`You can close this tab.`})),c(()=>o?e(o):r(new M(`Sign-in was cancelled in the browser.`)))}),s=setTimeout(()=>c(()=>r(new M(`Timed out waiting for the browser sign-in.`))),n);function c(e){clearTimeout(s),o.close(),e()}o.once(`error`,r),o.listen(0,`127.0.0.1`,()=>{let{port:e}=o.address();t(rt({registryUrl:i.url,callback:`http://127.0.0.1:${e}/callback`,state:a,client:`SlabUI CLI`}))})}),...r})}function sr(e){let[t,n]=process.platform===`darwin`?[`open`,[e]]:process.platform===`win32`?[`cmd`,[`/c`,`start`,``,e]]:[`xdg-open`,[e]];try{S(t,n,{stdio:`ignore`,detached:!0}).on(`error`,()=>{}).unref()}catch{}}const cr=new t(`login`).description(`Signs in to your SlabUI account in the browser (or saves a --token)`).option(`--token <token>`,`save this token instead of using the browser`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd);if(t.token===void 0&&!process.stdout.isTTY)throw new M(`Pass the token with --token or set ${A}.`);let{account:r,url:i,file:a}=t.token===void 0?await or({root:n,onUrl:e=>{console.log(`Opening the browser to sign in. If it does not open, visit:\n ${e}\n`),sr(e)}}):await ar({root:n,token:t.token}),o=r.name?` as ${r.name}`:``,s=r.access.includes(`pro`)?`Pro`:`Free`;console.log(`Logged in to ${i}${o} (${r.plan??s}).`),s===`Free`&&console.log(`Pro items need a subscription: https://slabui.com/pricing`),console.log(`Token saved in ${a}`)}),lr=new t(`logout`).description(`Removes the token saved by slabui login`).action(async()=>{console.log(await et()?`Logged out.`:`No token was saved; nothing to do.`)}),ur=[`local`,`http`],dr={command:`npx`,args:[`-y`,`@slabui/mcp@latest`]},fr=`Bearer \${${A}}`;function pr(e){return Object.keys(e).some(e=>e.toLowerCase()===`authorization`)?e:{...e,Authorization:fr}}const mr={claude:`.mcp.json`,cursor:`.cursor/mcp.json`,vscode:`.vscode/mcp.json`,zed:`.zed/settings.json`},hr=[[`.mcp.json`,`claude`],[`.claude`,`claude`],[`.cursor`,`cursor`],[`.vscode`,`vscode`],[`.zed`,`zed`],[`.codex`,`codex`]];function gr(e){let t=[];for(let n of e.flatMap(e=>e.split(`,`))){let e=n.trim();if(e!==``){if(!j.includes(e))throw new M(`Unknown client "${e}" (${j.join(`, `)}).`);t.includes(e)||t.push(e)}}return t}async function _r(t){let n=[];for(let[r,i]of hr)!n.includes(i)&&await R(e.join(t,r))&&n.push(i);return n}async function vr({root:e,url:t,transport:n=t===void 0?`local`:`http`,createClient:r=e=>I(e)}){let i=G((await H(e)).token),a=i.namespace.slice(1);if(n===`local`){if(t!==void 0)throw new M(`--url is for the remote server; use it with --transport http.`);return{servers:[{name:a,...dr}],warnings:[]}}let o=pr(i.headers);if(t!==void 0)return{servers:[{name:a,url:t,headers:o}],warnings:[]};try{let e=(await r(i).index()).mcp;return e===void 0?{servers:[],warnings:[`The "${i.namespace}" registry has no MCP server.`]}:{servers:[{name:a,url:e,headers:o}],warnings:[]}}catch(e){return{servers:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function yr(t,n,r){if(n===`zed`)return Sr(t,r);if(n===`codex`)return{snippet:Cr(r)};let i=mr[n],a=e.join(t,i),c=await s(a,`utf8`).catch(()=>void 0),l={};if(c!==void 0&&c.trim()!==``)try{l=JSON.parse(c)}catch{throw new M(`${i} is not valid JSON; fix it before running mcp init.`)}let d=n===`vscode`?`servers`:`mcpServers`,f=l[d]??{};for(let e of r)f[e.name]=br(n,e);return l[d]=f,await o(e.dirname(a),{recursive:!0}),await u(a,`${JSON.stringify(l,null,2)}\n`),{file:i}}function br(e,t){if(t.command!==void 0){let{command:n,args:r}=t;return{...e===`vscode`&&{type:`stdio`},command:n,args:r}}let{url:n,headers:r}=t,i=xr(r,e===`claude`?"${$1}":"${env:$1}",e);return{...e!==`cursor`&&{type:`http`},url:n,...Object.keys(i).length>0&&{headers:i}}}function xr(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,r===fr&&n===`claude`?`Bearer \${${A}:-}`:r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,t)]))}async function Sr(t,n){let r=mr.zed,i=e.join(t,r),a=await s(i,`utf8`).catch(()=>``)||`{}
|
|
207
|
+
`,c=[],l=b(a,c,{allowTrailingComma:!0});if(c.length>0||typeof l!=`object`||!l||Array.isArray(l))throw new M(`${r} is not valid JSON; fix it before running mcp init.`);let d=[];for(let e of n){if(e.command!==void 0){let{name:t,command:n,args:r}=e;a=v(a,y(a,[`context_servers`,t],{command:n,args:r},{formattingOptions:{insertSpaces:!0,tabSize:2}}));continue}let{name:t,url:n}=e,i=Object.fromEntries(Object.entries(e.headers).filter(([,e])=>e!==fr));Object.keys(i).length<Object.keys(e.headers).length&&d.push(`${r}: to read Pro items in "${t}", add the header "Authorization": "Bearer <your token>".`);let o={url:n,...Object.keys(i).length>0&&{headers:i}};a=v(a,y(a,[`context_servers`,t],o,{formattingOptions:{insertSpaces:!0,tabSize:2}})),Object.values(i).some(e=>/\$\{\w+\}/.test(e))&&d.push(`${r}: replace the \${VAR} values in the headers of "${t}" with the real values.`)}return await o(e.dirname(i),{recursive:!0}),await u(i,a.endsWith(`
|
|
208
|
+
`)?a:`${a}\n`),{file:r,warnings:d}}function Cr(e){return e.map(e=>{if(e.command!==void 0)return[`[mcp_servers.${e.name}]`,`command = ${JSON.stringify(e.command)}`,`args = ${JSON.stringify(e.args).replaceAll(`,`,`, `)}`].join(`
|
|
209
|
+
`);let{name:t,url:n,headers:r}=e,i=[`[mcp_servers.${t}]`,`url = ${JSON.stringify(n)}`],a=[],o=[];for(let[e,t]of Object.entries(r)){let n=/^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t),r=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t);e.toLowerCase()===`authorization`&&n?i.push(`bearer_token_env_var = ${JSON.stringify(n[1])}`):r?o.push(`${JSON.stringify(e)} = ${JSON.stringify(r[1])}`):a.push(`${JSON.stringify(e)} = ${JSON.stringify(t)}`)}return a.length>0&&i.push(`http_headers = { ${a.join(`, `)} }`),o.length>0&&i.push(`env_http_headers = { ${o.join(`, `)} }`),i.join(`
|
|
209
210
|
`)}).join(`
|
|
210
211
|
|
|
211
212
|
`).replace(/^/,`# In ~/.codex/config.toml (or .codex/config.toml in a trusted project):
|
|
212
|
-
`)}const
|
|
213
|
+
`)}const wr={claude:`CLAUDE.md`,cursor:`.cursor/rules/slabui.mdc`,vscode:`.github/copilot-instructions.md`,zed:`AGENTS.md`,codex:`AGENTS.md`},Tr=`<!-- slabui:start -->`,Er=`<!-- slabui:end -->`;function Dr(e){return wr[e]}function Or(e){let t=/* @__PURE__ */ new Set;return e.filter(e=>!t.has(wr[e])&&(t.add(wr[e]),!0))}function kr(e){return`## UI registry (slabui)
|
|
213
214
|
|
|
214
215
|
UI components, blocks and examples in this project come from the versioned
|
|
215
216
|
SlabUI registry, managed by the \`slabui\` CLI. The installed items and their
|
|
216
217
|
versions are listed under \`items\` in \`slabui.json\`.
|
|
217
218
|
|
|
218
|
-
${e.map(({
|
|
219
|
+
${e.map(e=>e.command===void 0?`MCP server: \`${e.name}\` (${e.url}).`:`MCP server: \`${e.name}\` (local, \`${[e.command,...e.args].join(` `)}\`).`).join(`
|
|
219
220
|
`)}
|
|
220
221
|
|
|
221
222
|
- Before writing a component from scratch, search the registry with
|
|
@@ -230,17 +231,16 @@ ${e.map(({name:e,url:t})=>`MCP server: \`${e}\` (${t}).`).join(`
|
|
|
230
231
|
overwrite installed files with a newer version by hand.
|
|
231
232
|
- Use \`get_item\` and \`diff_versions\` from the MCP server to read an item's
|
|
232
233
|
code or compare versions without installing it.
|
|
233
|
-
- Items marked
|
|
234
|
-
CLI, and \`SLABUI_TOKEN\` in the environment for the MCP server.
|
|
234
|
+
${e.some(e=>e.command!==void 0)?"- Items marked `pro` need a SlabUI Pro subscription and `slabui login`\n (used by the CLI and the MCP server).":"- Items marked `pro` need a SlabUI Pro subscription: `slabui login` for the\n CLI, and `SLABUI_TOKEN` in the environment for the MCP server."}
|
|
235
235
|
- Claude Code: \`slabui add skill\` installs the SlabUI skill
|
|
236
236
|
(\`.claude/skills/slabui\`); \`slabui update skill\` keeps it current.
|
|
237
|
-
`}async function
|
|
238
|
-
`)}const
|
|
237
|
+
`}async function Ar(t,n,r){let i=wr[n],a=e.join(t,i),c=kr(r),l;if(n===`cursor`)l=`---\ndescription: Installing and updating UI components with the slabui CLI\nalwaysApply: true\n---\n\n${c}`;else{let e=`${Tr}\n${c}${Er}\n`,t=await s(a,`utf8`).catch(()=>void 0),n=t?.indexOf(Tr)??-1,r=t?.indexOf(Er,n)??-1;if(t===void 0||t.trim()===``)l=e;else if(n!==-1&&r!==-1){let i=t.slice(r+19).replace(/^\n/,``);l=`${t.slice(0,n)}${e}${i}`}else l=`${t.replace(/\n*$/,``)}\n\n${e}`}return await o(e.dirname(a),{recursive:!0}),await u(a,l),{file:i}}const jr={claude:`Claude Code (.mcp.json)`,cursor:`Cursor (.cursor/mcp.json)`,vscode:`VS Code (.vscode/mcp.json)`,zed:`Zed (.zed/settings.json)`,codex:`Codex (snippet for config.toml)`},Mr=new t(`init`).description(`Adds the SlabUI MCP server to an editor or agent`).option(`--client <clients>`,`editors or agents, repeated or comma-separated (${j.join(`, `)})`,(e,t=[])=>[...t,e]).option(`--transport <transport>`,`how the editor reaches the server (${ur.join(`, `)}): local runs @slabui/mcp and uses "slabui login"; http uses the remote server and SLABUI_TOKEN`).option(`--url <url>`,`MCP URL for the default registry with --transport http (e.g. a local server)`).option(`--instructions`,`write instructions for the agent (CLAUDE.md, AGENTS.md…)`).option(`--no-instructions`,`skip the instructions for the agent`).option(`-y, --yes`,`never prompt`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async t=>{let n=e.resolve(t.cwd),r=gr(t.client??[]);if(r.length===0){if(!X(t.yes))throw new M(`Pass the clients with --client (${j.join(`, `)}), e.g. --client claude,cursor.`);let e=await _r(n);r=await Bn(`Which editors or agents should get the MCP servers?`,[...e,...j.filter(t=>!e.includes(t))].map(t=>({value:t,label:`${jr[t]}${e.includes(t)?` (detected)`:``}`})),e)}let i=t.transport;if(i!==void 0&&!ur.includes(i))throw new M(`Unknown transport "${i}" (${ur.join(`, `)}).`);t.url===void 0?X(t.yes)?i===void 0&&(i=await zn(`How should the editor reach the SlabUI MCP server?`,[{value:`local`,label:`Local (recommended): runs on this computer and uses "slabui login"`},{value:`http`,label:`Remote (HTTP): no Node needed; Pro items need SLABUI_TOKEN in the environment`}])):i??=`local`:i??=`http`;let{servers:a,warnings:o}=await vr({root:n,url:t.url,transport:i});for(let e of o)console.warn(`warning: ${e}`);if(a.length===0)throw new M(`The SlabUI registry has no MCP server.`);for(let e of r){let t=await yr(n,e,a);for(let e of t.warnings??[])console.warn(`warning: ${e}`);t.file&&console.log(`${t.file}: ${a.map(Pr).join(`, `)}`),t.snippet&&console.log(t.snippet)}let s=Or(r);if(t.instructions??(!X(t.yes)||await Q(`Add instructions for the agent to ${s.map(Dr).join(`, `)}?`)))for(let e of s){let{file:t}=await Ar(n,e,a);console.log(`${t}: instructions for the agent`)}}),Nr=new t(`mcp`).description(`Integration with editors and agents through MCP`).addCommand(Mr);function Pr(e){return e.command===void 0?`${e.name} → ${e.url}`:`${e.name} → ${[e.command,...e.args].join(` `)}`}async function Fr({root:e,refs:t=[],createClient:n=e=>I(e)}){let r=await H(e),i=t.length>0?[...new Set(t.map(e=>W(U(e))))]:Object.keys(r.items);for(let e of i)if(r.items[e]===void 0)throw new M(`"${e}" is not installed. Blocks and examples are not tracked in ${O}.`);return i.length===0?[]:Ir(r,i,await n(G(r.token)).index())}function Ir(e,t,n){return t.flatMap(t=>{let r=U(t),i=e.items[t];if(i===void 0)return[];let a=i.version,o=n.items[r.name];if(o===void 0)return[{key:t,registry:n.namespace??k.namespace,current:a,status:`missing`}];let s=Hn(o,a,{...r,range:void 0}).version,c=o.latest,l=a in o.versions?x.gt(s,a)||x.gt(c,a)?`outdated`:`current`:`unknown-version`;return[{key:t,registry:n.namespace??k.namespace,current:a,wanted:s,latest:c,status:l}]})}const Lr=[`Item`,`Current`,`Wanted`,`Latest`,`Registry`],Rr=new t(`outdated`).description(`Lists installed items that have newer versions`).argument(`[items...]`,`items to check (default: all)`).option(`--all`,`also list items that are up to date`).option(`--json`,`print as JSON (all items, with their status)`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=await Fr({root:e.resolve(n.cwd),refs:t});if(r.some(e=>e.status!==`current`)&&(process.exitCode=1),n.json){console.log(JSON.stringify(r,null,2));return}for(let e of r)e.status===`missing`?console.warn(`warning: "${e.key}" no longer exists in the "${e.registry}" registry.`):e.status===`unknown-version`&&console.warn(`warning: ${e.key}@${e.current} is no longer in the "${e.registry}" registry index.`);let i=r.filter(e=>e.wanted!==void 0&&(n.all||e.status!==`current`));if(i.length>0&&console.log(zr(i)),!r.some(e=>e.status===`outdated`)){console.log(`Everything is up to date.`);return}console.log("\nRun `slabui update` to get the Wanted versions.");let a=r.filter(e=>e.latest!==void 0&&e.wanted!==void 0&&x.major(e.latest)>x.major(e.wanted));for(let{key:e}of a)console.log(`Run \`slabui update ${e} --major\` to get the Latest.`)});function zr(e){let t=[[...Lr],...e.map(({key:e,current:t,wanted:n,latest:r,registry:i})=>[e,t,n??``,r??``,i])],n=Lr.map((e,n)=>Math.max(...t.map(e=>e[n].length)));return t.map(e=>e.map((e,t)=>e.padEnd(n[t])).join(` `).trimEnd()).join(`
|
|
238
|
+
`)}const Br=new t(`search`).description(`Searches items in the SlabUI registry`).argument(`<termo>`,`text to search for`).addOption(new n(`--type <kind>`,`filter by item kind`).choices(Ve)).option(`-n, --limit <n>`,`maximum number of results`,`10`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let{results:r,warnings:i}=await Zn({root:e.resolve(n.cwd),term:t,type:n.type});for(let e of i)console.warn(`warning: ${e}`);if(r.length===0)console.log(`No items found for "${t}".`);else for(let{key:e,entry:t}of r.slice(0,Number(n.limit))){let n=t.access===`pro`?`, pro`:``;console.log(`${e}@${t.latest} (${t.kind}${n})`),console.log(` ${t.description}`)}}),Vr={a:`local`,o:`base`,b:`remote`};async function Hr({root:e,refs:t,major:n=!1,overwrite:r=!1,skipInstall:i=!1,confirm:a,resolveConflict:o,createClient:s=e=>I(e)}){let c=await H(e),l=await z(e),u={root:e,aliases:c.aliases,tsconfig:l,css:Bt(l,e,c.css)},d=Vt(l,e,c.aliases.styles),f=/* @__PURE__ */ new Map,p=e=>{let t=f.get(e.namespace);return t===void 0&&(t=s(e),f.set(e.namespace,t)),t},m={updated:[],upToDate:[],conflicts:[],added:[],packages:[],cssChanges:[],ruleChanges:[],warnings:[]},h=(t.length>0?t:Object.keys(c.items)).map(e=>Kn(e)),g=/* @__PURE__ */ new Set,_=/* @__PURE__ */ new Set,v=[],y=[];for(;h.length>0;){let[t,i]=h.shift();if(g.has(t))continue;g.add(t);let s=await Un({key:t,version:i,major:n,config:c,context:u,clientFor:p});m.warnings.push(...s.warnings),s.newerMajor&&m.warnings.push(`${s.key}@${s.newerMajor} is available (new major): slabui update ${s.key} --major`);let{base:l,remote:f}=s;if(f.version===l.version){m.upToDate.push(s.key);continue}let b=[];for(let t of s.files){let n=await Ur(t,{root:e,overwrite:r,confirm:a,resolveConflict:o,warnings:m.warnings});b.push({destination:t.destination,status:n}),n===`conflict`&&m.conflicts.push(t.destination)}if((f.cssVars!==void 0||l.cssVars!==void 0)&&m.cssChanges.push(...await Mn(e,u.css,s.key,f.cssVars??{},{base:l.cssVars??{},warnings:m.warnings,styles:d,shouldRemove:r?async()=>!0:a&&((e,t)=>a(`--${t} (${e}) was removed in the new version of "${s.key}". Remove it from the CSS?`))})),s.registry.namespace===k.namespace){let t=(await p(s.registry).index()).items[f.name]?.tokens;m.cssChanges.push(...await Nn(e,u.css,s.key,t,m.warnings,d))}(f.css!==void 0||l.css!==void 0)&&m.ruleChanges.push(...await Pn(e,u.css,s.key,f.css??{},{base:l.css??{},warnings:m.warnings,styles:d,shouldRemove:r?async()=>!0:a&&((e,t)=>a(`${e===`base`?t:`${e===`utility`?`@utility`:`@custom-variant`} ${t}`} was removed in the new version of "${s.key}". Remove it from the CSS?`))})),c.items[s.key]={version:f.version,files:s.files.filter(e=>e.remote!==void 0).map(e=>e.destination)},m.updated.push({key:s.key,from:l.version,to:f.version,files:b});for(let e of f.dependencies.registry){let t=U(e),n=W(t),r=c.items[n];r===void 0?_.add(e):t.range!==void 0&&!x.satisfies(r.version,t.range)&&h.push([n,t.range])}v.push(...f.dependencies.npm),y.push(...f.dependencies.npmDev)}if(await Ut(e,c),_.size>0){let t=await Ln({root:e,refs:[..._],overwrite:r,skipInstall:i,confirm:a,createClient:p});m.added=t.added.map(({key:e})=>e),m.cssChanges.push(...t.cssChanges),m.ruleChanges.push(...t.ruleChanges),m.packages.push(...t.packages),m.warnings.push(...t.warnings)}return m.packages.push(...await xn(e,{npm:v,npmDev:y},{confirm:a,skipInstall:i,warnings:m.warnings})),m}async function Ur({destination:t,base:n,remote:r,local:i},{root:a,overwrite:s,confirm:c,resolveConflict:d,warnings:f}){let p=await L(a,t),m=async t=>{await o(e.dirname(p),{recursive:!0}),await u(p,t)};if(r===void 0)return i===void 0?`removed`:i===n||s||c!==void 0&&await c(`${t} was removed in the new version, but has local changes. Delete it?`)?(await l(p),`removed`):(f.push(`${t} was removed in the new version; kept because it has local changes.`),`kept`);if(n===void 0)return i===r?`unchanged`:i!==void 0&&!(s||c!==void 0&&await c(`${t} is new in this version, but already exists in the project. Overwrite it?`))?(f.push(`${t} already exists in the project and was not overwritten (--overwrite).`),`kept`):(await m(r),`added`);if(i===r)return`unchanged`;if(i===void 0||i===n)return i===void 0&&f.push(`${t} was missing from the project and was recreated.`),await m(r),`updated`;let h=ne(i.split(`
|
|
239
239
|
`),n.split(`
|
|
240
240
|
`),r.split(`
|
|
241
|
-
`),{label:
|
|
241
|
+
`),{label:Vr});if(!h.conflict)return await m(h.result.join(`
|
|
242
242
|
`)),`merged`;let g=d?await d(t):`markers`;return g===`local`?`kept`:g===`remote`?(await m(r),`updated`):(await m(h.result.join(`
|
|
243
|
-
`)),`conflict`)}const
|
|
244
|
-
`)}`),process.exitCode=1)}),
|
|
243
|
+
`)),`conflict`)}const Wr={unchanged:`unchanged`,updated:`updated`,merged:`merged with local changes`,conflict:`CONFLICT (markers in the file)`,added:`created`,removed:`removed`,kept:`kept`},Gr=new t(`update`).description(`Updates items to a new version (3-way merge)`).argument(`[items...]`,`items to update (default: all); e.g. button@2`).option(`--major`,`allow updating to a new major`).option(`-y, --yes`,`never prompt; conflicts keep the markers`).option(`-o, --overwrite`,`overwrite and delete files without prompting`).option(`--skip-install`,`skip installing npm packages`).option(`--cwd <dir>`,`project root`,process.cwd()).action(async(t,n)=>{let r=X(n.yes),i=await Hr({root:e.resolve(n.cwd),refs:t,major:n.major,overwrite:n.overwrite,skipInstall:n.skipInstall,confirm:r?Q:void 0,resolveConflict:r?e=>zn(`Conflict in ${e}. What should be done?`,[{value:`markers`,label:`Keep the markers and resolve in the editor`},{value:`local`,label:`Keep the local version`},{value:`remote`,label:`Use the remote version (discards local changes)`}]):void 0});for(let{key:e,from:t,to:n,files:r}of i.updated){console.log(`↑ ${e}: ${t} → ${n}`);for(let{destination:e,status:t}of r)console.log(` ${e}: ${Wr[t]}`)}for(let e of i.added)console.log(`+ ${e} (new dependency)`);i.updated.length===0&&i.added.length===0&&console.log(`Everything is up to date.`),i.packages.length>0&&console.log(`Installed packages: ${i.packages.join(` `)}`);let a=ze(i.cssChanges);a&&console.log(a);let o=Re(i.ruleChanges);o&&console.log(o);for(let e of i.warnings)console.warn(`warning: ${e}`);i.conflicts.length>0&&(console.error(`\nResolve the conflicts (look for "<<<<<<< local"):\n${i.conflicts.map(e=>` ${e}`).join(`
|
|
244
|
+
`)}`),process.exitCode=1)}),Kr=`slabui`,qr=`https://registry.npmjs.org/-/package/${Kr}/dist-tags`,Jr=864e5,Yr={pnpm:`pnpm add -D`,npm:`npm install -D`,yarn:`yarn add -D`,bun:`bun add -d`};function Xr({env:e=process.env,argv:t=process.argv,tty:n=!!(process.stdout.isTTY&&process.stderr.isTTY)}={}){let r=e.CI!==void 0&&e.CI!==``&&e.CI!==`false`;return n&&!r&&e.SLABUI_NO_UPDATE_CHECK!==`1`&&!t.includes(`--json`)}function Zr(t=process.env,n=process.platform,r=m()){let i=n===`darwin`?e.join(r,`Library/Caches/slabui`):n===`win32`?e.join(t.LOCALAPPDATA??e.join(r,`AppData/Local`),`slabui/Cache`):e.join(t.XDG_CACHE_HOME||e.join(r,`.cache`),`slabui`);return e.join(i,`update-check.json`)}async function Qr(e){try{return JSON.parse(await s(e,`utf8`))}catch{return{}}}async function $r(t,n){try{let r=await Qr(t);n(r),await o(e.dirname(t),{recursive:!0}),await u(t,`${JSON.stringify(r)}\n`)}catch{}}async function ei({file:e,fetch:t=globalThis.fetch,now:n=Date.now(),signal:r}){let i=(await Qr(e)).cli;if(i&&n-i.checkedAt<Jr)return i.latest;let a;try{let e=await t(qr,{signal:r}),n=await e.json();e.ok&&typeof n.latest==`string`&&(a=x.valid(n.latest)??void 0)}catch{}if(!r?.aborted)return await $r(e,e=>{e.cli={checkedAt:n,latest:a}}),a}function ti(e,t,n){if(t!==void 0&&x.gt(t,e))return`Update available: slabui ${e} → ${t}\nRun: ${Yr[n]??Yr.npm} ${Kr}@latest`}async function ni({root:t,file:n,now:r=Date.now(),indexOf:i=kt}){if(!await R(e.join(t,`slabui.json`)))return;let a=(await Qr(n)).projects?.[t];if(a!==void 0&&r-a<Jr)return;let o=await H(t),s=i(G().namespace);if(s===void 0)return;let c=Ir(o,Object.keys(o.items),s).filter(e=>e.status===`outdated`).length;if(c!==0)return await $r(n,e=>{e.projects={...e.projects,[t]:r}}),c===1?"1 installed item has a newer version. Run `slabui outdated` to see it.":`${c} installed items have newer versions. Run \`slabui outdated\` to see them.`}const ri=/* @__PURE__ */ new Set([`add`,`info`,`search`]),ii=Date.now(),ai=Xr(),oi=Zr(),si=new AbortController,ci=ai?ei({file:oi,signal:si.signal}).catch(()=>void 0):void 0;let $;const li=new t(`slabui`).description(re).version(T,`-v, --version`).addCommand(rr).addCommand(Vn).addCommand(Gr).addCommand(Rr).addCommand(qn).addCommand(Br).addCommand($n).addCommand(cr).addCommand(lr).addCommand(Nr).hook(`preAction`,(e,t)=>{Tt(`${t.parent?.parent?`${t.parent.name()} `:``}${t.name()}`)}).hook(`postAction`,(t,n)=>{let{cwd:r}=n.opts();$={name:n.name(),root:e.resolve(r??`.`)}});try{await li.parseAsync()}catch(e){console.error(e instanceof M?e.message:e),process.exitCode=1}ai&&await ui().catch(()=>{});async function ui(){let e=[];if($&&ri.has($.name)){let t=await ni({root:$.root,file:oi});t&&e.push(t)}let t=Math.max(0,ii+1e3-Date.now()),n,r=await Promise.race([ci,new Promise(e=>{n=setTimeout(()=>e(void 0),t)})]);clearTimeout(n),si.abort();let i=ti(T,r,await gn($?.root??process.cwd()));i&&e.push(i),e.length>0&&console.error(`\n${e.join(`
|
|
245
245
|
|
|
246
246
|
`)}`)}export{};
|
package/dist/index.mjs
CHANGED
|
@@ -117,7 +117,7 @@ button:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px;
|
|
|
117
117
|
<rect ${se} transform="translate(40 28) scale(1 0.5299193) rotate(45)" fill="url(#plate)"/>
|
|
118
118
|
<path class="ink" d="M122.72 63.52L122.72 63.52Q116.83 63.52 112.61 61.54Q108.38 59.56 106.02 55.97Q103.65 52.39 103.33 47.52L103.33 47.52L113.12 47.08Q113.50 49.76 114.69 51.65Q115.87 53.54 117.89 54.50Q119.90 55.46 122.85 55.46L122.85 55.46Q125.28 55.46 126.98 54.88Q128.67 54.31 129.57 53.12Q130.46 51.94 130.46 50.21L130.46 50.21Q130.46 48.61 129.70 47.43Q128.93 46.24 126.75 45.25Q124.58 44.26 120.35 43.30L120.35 43.30Q114.53 41.96 110.98 40.29Q107.42 38.63 105.82 36.10Q104.22 33.57 104.22 29.73L104.22 29.73Q104.22 25.64 106.24 22.56Q108.26 19.49 112.10 17.76Q115.94 16.04 121.25 16.04L121.25 16.04Q126.88 16.04 130.78 18.02Q134.69 20.00 136.90 23.46Q139.10 26.92 139.55 31.40L139.55 31.40L129.82 31.91Q129.63 29.54 128.54 27.78Q127.46 26.02 125.60 25.06Q123.74 24.10 121.12 24.10L121.12 24.10Q117.79 24.10 115.90 25.57Q114.02 27.04 114.02 29.41L114.02 29.41Q114.02 31.08 114.88 32.20Q115.74 33.32 117.76 34.15Q119.78 34.98 123.49 35.75L123.49 35.75Q129.82 37.03 133.50 38.98Q137.18 40.93 138.72 43.62Q140.26 46.31 140.26 49.76L140.26 49.76Q140.26 53.99 138.11 57.09Q135.97 60.20 132.03 61.86Q128.10 63.52 122.72 63.52ZM159.26 62.50L153.57 62.50Q149.34 62.50 146.98 60.39Q144.61 58.28 144.61 53.54L144.61 53.54L144.61 17.06L154.21 17.06L154.21 52.52Q154.21 54.05 154.91 54.69Q155.62 55.33 156.96 55.33L156.96 55.33L159.26 55.33L159.26 62.50ZM171.49 63.27L171.49 63.27Q166.18 63.27 162.82 60.80Q159.46 58.34 159.46 53.92L159.46 53.92Q159.46 49.38 162.30 46.92Q165.15 44.45 170.72 43.30L170.72 43.30L181.79 41.12Q181.79 37.80 180.29 36.10Q178.78 34.40 175.97 34.40L175.97 34.40Q173.22 34.40 171.68 35.65Q170.14 36.90 169.70 39.33L169.70 39.33L160.03 38.88Q160.99 33.25 165.12 30.34Q169.25 27.43 175.97 27.43L175.97 27.43Q183.65 27.43 187.52 31.08Q191.39 34.72 191.39 41.76L191.39 41.76L191.39 53.48Q191.39 54.95 191.87 55.43Q192.35 55.91 193.31 55.91L193.31 55.91L194.27 55.91L194.27 62.50Q193.82 62.63 192.83 62.76Q191.84 62.88 190.88 62.88L190.88 62.88Q188.83 62.88 187.07 62.18Q185.31 61.48 184.22 59.75L184.22 59.75Q183.58 58.79 183.33 57.32L183.33 57.32Q182.69 58.53 181.73 59.62L181.73 59.62Q180.06 61.35 177.47 62.31Q174.88 63.27 171.49 63.27ZM173.79 56.68L173.79 56.68Q176.16 56.68 177.95 55.75Q179.74 54.82 180.77 53.03Q181.79 51.24 181.79 48.80L181.79 48.80L181.79 47.14L173.98 48.80Q171.68 49.25 170.50 50.31Q169.31 51.36 169.31 53.03L169.31 53.03Q169.31 54.76 170.46 55.72Q171.62 56.68 173.79 56.68ZM215.33 63.27L215.33 63.27Q211.74 63.27 209.09 61.73Q206.43 60.20 204.96 57.44L204.96 57.44L204.77 62.50L195.62 62.50L195.62 17.06L205.22 17.06L205.22 33.06Q206.56 30.69 209.18 29.06Q211.81 27.43 215.33 27.43L215.33 27.43Q219.68 27.43 222.88 29.64Q226.08 31.84 227.84 35.88Q229.60 39.91 229.60 45.35L229.60 45.35Q229.60 50.79 227.84 54.82Q226.08 58.85 222.88 61.06Q219.68 63.27 215.33 63.27ZM212.64 55.91L212.64 55.91Q215.84 55.91 217.79 53.12Q219.74 50.34 219.74 45.35L219.74 45.35Q219.74 40.36 217.82 37.57Q215.90 34.79 212.70 34.79L212.70 34.79Q210.34 34.79 208.64 36.04Q206.94 37.28 206.08 39.65Q205.22 42.02 205.22 45.35L205.22 45.35Q205.22 48.61 206.08 50.98Q206.94 53.35 208.64 54.63Q210.34 55.91 212.64 55.91Z"/>
|
|
119
119
|
<path fill="url(#ui)" d="M251.30 63.52L251.30 63.52Q245.54 63.52 241.34 61.41Q237.15 59.30 234.85 55.36Q232.54 51.43 232.54 46.12L232.54 46.12L232.54 17.06L242.27 17.06L242.27 46.12Q242.27 50.53 244.61 52.93Q246.94 55.33 251.30 55.33L251.30 55.33Q255.65 55.33 257.95 52.93Q260.26 50.53 260.26 46.12L260.26 46.12L260.26 17.06L269.98 17.06L269.98 46.12Q269.98 51.43 267.71 55.36Q265.44 59.30 261.22 61.41Q256.99 63.52 251.30 63.52ZM285.98 62.50L276.26 62.50L276.26 17.06L285.98 17.06L285.98 62.50Z"/>
|
|
120
|
-
</svg>`;function le(e=process.env,t=process.platform,n=r()){let i=t===`win32`?a.join(e.APPDATA??a.join(n,`AppData/Roaming`),`slabui`):a.join(e.XDG_CONFIG_HOME||a.join(n,`.config`),`slabui`);return a.join(i,`credentials.json`)}async function ue(e=le()){try{let{token:t}=JSON.parse(await l(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function de(e,t=le()){await c(a.dirname(t),{recursive:!0}),await f(t,`${JSON.stringify({token:e})}\n`,{mode:384})}async function fe({registryUrl:e,token:t,fetch:n=globalThis.fetch,headers:r={}}){let i=`${e.replace(/\/+$/,``)}/whoami.json`,a=await n(i,{headers:{...r,authorization:`Bearer ${t.trim()}`},signal:AbortSignal.timeout(15e3)});if(a.status===401)return null;if(!a.ok)throw Error(`Error ${a.status} while fetching ${i}.`);let o=await a.json();return{...o,access:o.access??[]}}function pe(){return t(24).toString(`base64url`)}function me({registryUrl:e,callback:t,state:n,client:r,host:a=i()}){let o=new URL(`/cli/authorize`,new URL(e).origin);return o.searchParams.set(`callback`,t),o.searchParams.set(`state`,n),o.searchParams.set(`client`,r),o.searchParams.set(`host`,a.replace(/\.local$/,``).slice(0,60)),o.toString()}var j=class extends Error{name=`SlabUIError`};const M=n.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),he=n.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),N=n.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),ge=n.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),P=n.enum(D),_e=n.enum(O),ve=n.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),ye=n.object({registry:n.array(ve).default([]),npm:n.array(n.string().min(1)).default([]),npmDev:n.array(n.string().min(1)).default([])}),be=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],xe=[e=>e.files.length>0||e.cssVars!==void 0||e.css!==void 0||(e.utilities?.length??0)>0||(e.variants?.length??0)>0||e.base!==void 0,{message:`the item needs files, cssVars or CSS rules`,path:[`files`]}],Se=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional()}).refine(...be),Ce=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional(),content:n.string()}).refine(...be),we=n.record(n.string(),n.string()),Te=n.object({theme:we.optional(),light:we.optional(),dark:we.optional()}),Ee=n.record(n.string().min(1),n.record(n.string().min(1),n.string().min(1))),F=n.string().regex(/^[a-z][\w-]*$/),De=n.object({utilities:n.record(F,n.string().min(1)).optional(),variants:n.record(F,n.string().min(1)).optional(),base:Ee.optional()}),Oe={name:M,kind:P,title:n.string().min(1).optional(),description:n.string().min(1),dependencies:ye.prefault({}),cssVars:Te.optional()},ke=n.object({$schema:n.string().optional(),schemaVersion:n.literal(1),...Oe,version:N,files:n.array(Ce).default([]),css:De.optional()}).refine(...xe);n.object({...Oe,categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:_e.optional(),inferDependencies:n.boolean().optional(),files:n.array(Se).default([]),utilities:n.array(F).optional(),variants:n.array(F).optional(),base:Ee.optional()}).refine(...xe);const Ae=n.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),je=n.object({hash:ge,path:Ae}),Me=n.object({kind:P,title:n.string().min(1).optional(),description:n.string().min(1),categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:_e.optional(),dependencies:ye.prefault({}),tokens:n.array(n.string().min(1)).optional(),latest:N,versions:n.record(N,je)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Ne=n.object({$schema:n.string().optional(),schemaVersion:n.literal(2),namespace:he.optional(),homepage:n.url().optional(),mcp:n.url().optional(),license:n.url().optional(),items:n.record(M,Me)});var Pe=`0.4.1`;let Fe;function Ie(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Le(e,t=Fe){let n={"user-agent":`slabui/${Pe}`};return Ie(e)?n[E.optOut]=`off`:t&&(n[E.command]=t),n}const Re=/* @__PURE__ */ new Map;function I(e,{fetch:t=globalThis.fetch,env:r=process.env,command:i,savedToken:a=()=>ue()}={}){let o=e.url.replace(/\/+$/,``),s={...Le(r,i),...Be(e.headers,r)},c;async function l(t){let n=Object.keys(s).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||n)return{};let i=(e.token===void 0?void 0:Ve(e.token,`"token" in slabui.json`,r))||r.SLABUI_TOKEN||await a();if(!i)throw new j(`"${t}" is a Pro item. Run "slabui login" or set ${k} to install it.`);return{authorization:`Bearer ${i}`}}async function u(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...s,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new j(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new j(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${k}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new j(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new j(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new j(`Not found: ${n}.`);if(!a.ok)throw new j(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function d(e,t,r,i){let a;try{a=JSON.parse(new TextDecoder().decode(t))}catch{throw new j(`${e} is not valid JSON.`)}i?.(e,a);let o=r.safeParse(a);if(!o.success)throw new j(`${e} does not match the expected format:\n${n.prettifyError(o.error)}`);return o.data}async function f(){let t=`${o}/registry.json`,n=d(t,await u(t),Ne,ze);return Re.set(e.namespace,n),n}function p(){return c??=f().catch(e=>{throw c=void 0,e}),c}return{index:p,async item(t,n){let r=(await p()).items[t];if(r===void 0)throw new j(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new j(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let a=`${o}/${i.path}`,s=r.access===`pro`?await u(a,{extraHeaders:await l(t),pro:t}):await u(a);if(He(s)!==i.hash)throw new j(`${a} does not match the hash in the index. The file may have been changed on the server.`);let c=d(a,s,ke);if(c.name!==t||c.version!==n)throw new j(`${a} contains ${c.name}@${c.version}, not ${t}@${n}.`);return c}}}function ze(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new j(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new j(`${e} uses format ${r}, which is no longer supported. ${n}`)}function Be(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ve(n,`the "${e}" header`,t)]))}function Ve(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new j(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function He(t){return`sha256-${e(`sha256`).update(t).digest(`base64`)}`}const Ue=n.object({version:N,files:n.array(n.string().min(1))}),We=n.object({$schema:n.string().optional(),token:n.string().min(1).optional(),css:n.string().min(1).optional(),aliases:n.object({components:n.string().min(1),ui:n.string().min(1),lib:n.string().min(1),hooks:n.string().min(1),utils:n.string().min(1),styles:n.string().min(1)}),items:n.record(M,Ue).default({})}),Ge=[`tsconfig.json`,`jsconfig.json`],Ke=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function L(e){return o(e).then(()=>!0,()=>!1)}async function R(e){for(let t of Ge){let n=a.join(e,t);if(await L(n))try{return{path:n,config:m(n)}}catch(e){throw new j(`Could not read ${t}: ${e.message}`)}}throw new j(`No tsconfig.json or jsconfig.json in ${e}. slabui uses its "paths" to resolve the aliases.`)}function z(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function qe(e,t,n){if(n===void 0)return;let r=z(e),i=r!==void 0&&n.startsWith(r)?B(e,n):void 0;return i===void 0?n:a.relative(t,i).split(a.sep).join(`/`)}function Je(e,t,n){let r=Ze(n)?a.resolve(t,n):B(e,n);return r===void 0?void 0:a.relative(t,r).split(a.sep).join(`/`)}function B(e,t){return p(e)?.(t)[0]}async function Ye(e){for(let t of Ke)if(await L(a.join(e,t)))return t}async function V(e){let t=a.join(e,S),r=await l(t,`utf8`).catch(()=>void 0);if(r===void 0)throw new j(`${S} not found in ${e}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new j(`${S} is not valid JSON.`)}let o=We.safeParse(i);if(!o.success)throw new j(`${S} has errors:\n${n.prettifyError(o.error)}`);return o.data}async function Xe(e,t){await f(a.join(e,S),`${JSON.stringify(t,null,2)}\n`)}function Ze(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Qe(e){let t=z(await R(e));if(t===void 0)throw new j(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await $e(e,`${t}styles`)}}async function $e(e,t){let n=await Ye(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function et({root:e,aliases:t,css:n,force:r=!1}){if(!r&&await L(a.join(e,`slabui.json`)))throw new j(`${S} already exists. Use --force to create it again.`);let i=await R(e);for(let[e,n]of Object.entries(t))if(!Ze(n)&&B(i,n)===void 0)throw new j(`Alias "${n}" (${e}) does not match any "paths" in the tsconfig.`);let o={$schema:T,...n&&{css:n},aliases:t,items:{}};return await Xe(e,o),o}async function H(e,t){let n=e=>new j(`Path "${t}" refused: ${e}.`);if(t===``)throw n(`it is empty`);if(t.includes(`\0`))throw n(`it contains a null character`);if(t.includes(`\\`))throw n(`use / as the separator`);if(a.posix.isAbsolute(t)||a.win32.isAbsolute(t))throw n(`it is absolute`);let r=a.resolve(e),i=a.resolve(r,t);if(i===r)throw n(`it points to the project root`);if(!tt(r,i))throw n(`it leaves the project root`);let o=await nt(i);if(o===i&&(await s(i)).isSymbolicLink())throw n(`the target is a symbolic link`);let c=await u(r),l=await u(o).catch(()=>{throw n(`it goes through a broken symbolic link`)});if(!tt(c,l))throw n(`it goes through a symbolic link outside the project`);return a.join(l,a.relative(o,i))}function tt(e,t){let n=a.relative(e,t);return n===``||n!==`..`&&!n.startsWith(`..${a.sep}`)&&!a.isAbsolute(n)}async function nt(e){let t=e;for(;;)try{return await s(t),t}catch(e){if(e.code!==`ENOENT`)throw e;t=a.dirname(t)}}const U=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],rt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,it=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function at(e){return a.posix.extname(e)===`.css`}function ot(e,t){return e.replace(it,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function st(e){return U.includes(a.posix.extname(e))}function ct(e,t){return e.replace(rt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function lt(e,t){return[e,...U.map(t=>`${e}${t}`),...U.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function ut(e){let t=a.posix.extname(e);return U.includes(t)?e.slice(0,-t.length):e}function W(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new j(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==C.namespace)throw new j(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!M.safeParse(r).success)throw new j(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||h.validRange(i)===null))throw new j(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function G(e){return e.name}function K(e,t=process.env){return{namespace:C.namespace,url:t.SLABUI_REGISTRY_URL||C.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function q(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=h.maxSatisfying(n,e.range);if(r===null)throw new j(`No version of "${G(e)}" satisfies "${e.range}". Available: ${h.sort(n).join(`, `)}.`);return r}const dt={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function ft(e,t){if(e.target!==void 0){let n=e.target;return mt((n.startsWith(z(t.tsconfig)??`\0`)?B(t.tsconfig,n):void 0)??a.resolve(t.root,n),t)}if(!(e.kind in dt))throw new j(`Files with kind "${e.kind}" cannot be installed by add yet (${e.path}).`);let n=t.aliases[dt[e.kind]],r=e.kind===`style`&&e.path.split(`/`).slice(1).join(`/`)||a.posix.basename(e.path),i=Ze(n)?a.resolve(t.root,n,r):B(t.tsconfig,`${n}/${r}`);if(i===void 0)throw new j(`Alias "${n}" does not match any "paths" in the tsconfig.`);return mt(i,t)}function pt(e,t,n){let r=z(n.tsconfig),i=r===void 0?void 0:B(n.tsconfig,`${r}__slabui__`)?.slice(0,-10),o=a.resolve(n.root,e);if(r!==void 0&&i!==void 0&&o.startsWith(i))return`${r}${ut(a.relative(i,o).split(a.sep).join(`/`))}`;let s=a.posix.relative(a.posix.dirname(t),e);return s.startsWith(`.`)||(s=`./${s}`),ut(s)}function mt(e,t){return a.relative(t.root,e).split(a.sep).join(`/`)}function J(e){return e.kind===`block`||e.kind===`example`}function ht(e,t,n){return J(e)?bt(e,n):new Map(e.files.map(e=>[e.path,ft(e,t)]))}function gt(e,t){return[e,...t.dependencies.registry.map(e=>G(W(e)))]}async function _t(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=W(e),o=G(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(K(t.token));r.set(o,ht(await c.item(a.name,s.version),n))}}function vt(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=at(e.path);if(!st(e.path)&&!s)return e.content;let c=gt(t,n),l=e=>{if(e===`slabui:css`){if(a.css===void 0){o.push(`"${t}": ${r} uses the global CSS, but "css" is not set in slabui.json.`);return}return yt(a.css,r)}if(!e.startsWith(`@/registry/`))return;let n=e.slice(11);for(let e of c){let t=i.get(e),o=t&<(n,new Set(t.keys()));if(o){let e=t.get(o);return s?yt(e,r):pt(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?ot(e.content,l):ct(e.content,l)}function yt(e,t){let n=a.posix.relative(a.posix.dirname(t),e);return n.startsWith(`.`)?n:`./${n}`}function bt(e,t){let n=e.files.map(e=>a.posix.dirname(e.path).split(`/`)),r=[];for(let[e,t]of(n[0]??[]).entries())if(n.every(n=>n[e]===t))r.push(t);else break;let i=r.join(`/`),o=a.posix.normalize(t.split(a.sep).join(`/`));return new Map(e.files.map(e=>[e.path,a.posix.join(o,a.posix.relative(i,e.path))]))}const xt=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function St(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function Ct(e){let t=(await wt(e))?.packageManager?.split(`@`)[0];if(t&&[`pnpm`,`npm`,`yarn`,`bun`].includes(t))return t;let n=a.resolve(e);for(;;){for(let[e,t]of xt)if(await L(a.join(n,e)))return t;let e=a.dirname(n);if(e===n)return`npm`;n=e}}async function wt(e){let t=await l(a.join(e,`package.json`),`utf8`).catch(()=>void 0);return t===void 0?void 0:JSON.parse(t)}async function Tt(e,{npm:t,npmDev:n}){let r=await wt(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=St(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=h.minVersion(o);r&&s&&!h.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function Et(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function Dt(e,t,n,r){if(n.length===0)return;let[i,a]=Et(t,n,r);await new Promise((t,n)=>{let r=g(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new j(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new j(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function Ot(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await Tt(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${St(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await Ct(e);return await Dt(e,s,a.install,!1),await Dt(e,s,a.installDev,!0),o}async function kt({refs:e,config:t,createClient:n=e=>I(e)}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=[],s=/* @__PURE__ */ new Set,c=[];function l(e){let t=r.get(e.namespace);return t===void 0&&(t=n(e),r.set(e.namespace,t)),t}async function u(e,n){let r=G(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!h.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>At(p,e)))return;let m=K(t.token),g=l(m),_=(await g.index()).items[e.name];if(_===void 0)throw new j(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let v=Object.keys(_.versions),y=d.flatMap(({range:e})=>e?[e]:[]),b=y.length===0?_.latest:h.rsort(v.filter(e=>y.every(t=>h.satisfies(e,t))))[0]??null;if(b===null)throw new j(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${h.sort(v).join(`, `)}.`);let x=await g.item(e.name,b);a.set(r,{key:r,registry:m,item:x});for(let e of x.dependencies.registry)await u(W(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(W(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function At(e,t){return t===void 0||h.satisfies(e.item.version,t)}const jt=/^[a-z0-9][a-z0-9-]*$/i;function Mt(e){return jt.test(e)}function Nt(e,t=!1){if(!Mt(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const Pt=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function Ft(e,t,{base:n,overwrite:r=!1,shouldRemove:i,theme:a}={}){let o=_.parse(e),s=[],c=[],l=e=>a?e:It(e),u=l(t),d=n?l(n):void 0;for(let e of[`theme`,`light`,`dark`]){let t=u[e]??{},n=d?.[e]??{},l=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);if(l.size===0)continue;let f=zt(o,e,a);for(let u of l){let l=t[u],d=n[u],p=f?.nodes?.find(e=>e.type===`decl`&&e.prop===`--${u}`),m=p?.value,h=t=>s.push({group:e,name:u,action:t});if(l===void 0){if(m===void 0)continue;i&&await i(e,u)?(p?.remove(),h(`removed`)):(c.push(`--${u} (${e}) was removed in the new version; kept in the CSS.`),h(`kept`))}else if(m===void 0){if(d!==void 0){h(`kept`);continue}f??=Bt(o,e,a),f.raws.semicolon=!0,f.raws.after=`
|
|
120
|
+
</svg>`;function le(e=process.env,t=process.platform,n=r()){let i=t===`win32`?a.join(e.APPDATA??a.join(n,`AppData/Roaming`),`slabui`):a.join(e.XDG_CONFIG_HOME||a.join(n,`.config`),`slabui`);return a.join(i,`credentials.json`)}async function ue(e=le()){try{let{token:t}=JSON.parse(await l(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function de(e,t=le()){await c(a.dirname(t),{recursive:!0}),await f(t,`${JSON.stringify({token:e})}\n`,{mode:384})}async function fe({registryUrl:e,token:t,fetch:n=globalThis.fetch,headers:r={}}){let i=`${e.replace(/\/+$/,``)}/whoami.json`,a=await n(i,{headers:{...r,authorization:`Bearer ${t.trim()}`},signal:AbortSignal.timeout(15e3)});if(a.status===401)return null;if(!a.ok)throw Error(`Error ${a.status} while fetching ${i}.`);let o=await a.json();return{...o,access:o.access??[]}}function pe(){return t(24).toString(`base64url`)}function me({registryUrl:e,callback:t,state:n,client:r,host:a=i()}){let o=new URL(`/cli/authorize`,new URL(e).origin);return o.searchParams.set(`callback`,t),o.searchParams.set(`state`,n),o.searchParams.set(`client`,r),o.searchParams.set(`host`,a.replace(/\.local$/,``).slice(0,60)),o.toString()}var j=class extends Error{name=`SlabUIError`};const M=n.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),he=n.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),N=n.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),ge=n.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),P=n.enum(D),_e=n.enum(O),ve=n.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),ye=n.object({registry:n.array(ve).default([]),npm:n.array(n.string().min(1)).default([]),npmDev:n.array(n.string().min(1)).default([])}),be=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],xe=[e=>e.files.length>0||e.cssVars!==void 0||e.css!==void 0||(e.utilities?.length??0)>0||(e.variants?.length??0)>0||e.base!==void 0,{message:`the item needs files, cssVars or CSS rules`,path:[`files`]}],Se=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional()}).refine(...be),Ce=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional(),content:n.string()}).refine(...be),we=n.record(n.string(),n.string()),Te=n.object({theme:we.optional(),light:we.optional(),dark:we.optional()}),Ee=n.record(n.string().min(1),n.record(n.string().min(1),n.string().min(1))),F=n.string().regex(/^[a-z][\w-]*$/),De=n.object({utilities:n.record(F,n.string().min(1)).optional(),variants:n.record(F,n.string().min(1)).optional(),base:Ee.optional()}),Oe={name:M,kind:P,title:n.string().min(1).optional(),description:n.string().min(1),dependencies:ye.prefault({}),cssVars:Te.optional()},ke=n.object({$schema:n.string().optional(),schemaVersion:n.literal(1),...Oe,version:N,files:n.array(Ce).default([]),css:De.optional()}).refine(...xe);n.object({...Oe,categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:_e.optional(),inferDependencies:n.boolean().optional(),files:n.array(Se).default([]),utilities:n.array(F).optional(),variants:n.array(F).optional(),base:Ee.optional()}).refine(...xe);const Ae=n.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),je=n.object({hash:ge,path:Ae}),Me=n.object({kind:P,title:n.string().min(1).optional(),description:n.string().min(1),categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:_e.optional(),dependencies:ye.prefault({}),tokens:n.array(n.string().min(1)).optional(),latest:N,versions:n.record(N,je)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Ne=n.object({$schema:n.string().optional(),schemaVersion:n.literal(2),namespace:he.optional(),homepage:n.url().optional(),mcp:n.url().optional(),license:n.url().optional(),items:n.record(M,Me)});var Pe=`0.5.0`;let Fe;function Ie(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Le(e,t=Fe){let n={"user-agent":`slabui/${Pe}`};return Ie(e)?n[E.optOut]=`off`:t&&(n[E.command]=t),n}const Re=/* @__PURE__ */ new Map;function I(e,{fetch:t=globalThis.fetch,env:r=process.env,command:i,savedToken:a=()=>ue()}={}){let o=e.url.replace(/\/+$/,``),s={...Le(r,i),...Be(e.headers,r)},c;async function l(t){let n=Object.keys(s).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||n)return{};let i=(e.token===void 0?void 0:Ve(e.token,`"token" in slabui.json`,r))||r.SLABUI_TOKEN||await a();if(!i)throw new j(`"${t}" is a Pro item. Run "slabui login" or set ${k} to install it.`);return{authorization:`Bearer ${i}`}}async function u(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...s,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new j(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new j(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${k}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new j(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new j(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new j(`Not found: ${n}.`);if(!a.ok)throw new j(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function d(e,t,r,i){let a;try{a=JSON.parse(new TextDecoder().decode(t))}catch{throw new j(`${e} is not valid JSON.`)}i?.(e,a);let o=r.safeParse(a);if(!o.success)throw new j(`${e} does not match the expected format:\n${n.prettifyError(o.error)}`);return o.data}async function f(){let t=`${o}/registry.json`,n=d(t,await u(t),Ne,ze);return Re.set(e.namespace,n),n}function p(){return c??=f().catch(e=>{throw c=void 0,e}),c}return{index:p,async item(t,n){let r=(await p()).items[t];if(r===void 0)throw new j(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new j(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let a=`${o}/${i.path}`,s=r.access===`pro`?await u(a,{extraHeaders:await l(t),pro:t}):await u(a);if(He(s)!==i.hash)throw new j(`${a} does not match the hash in the index. The file may have been changed on the server.`);let c=d(a,s,ke);if(c.name!==t||c.version!==n)throw new j(`${a} contains ${c.name}@${c.version}, not ${t}@${n}.`);return c}}}function ze(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new j(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new j(`${e} uses format ${r}, which is no longer supported. ${n}`)}function Be(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ve(n,`the "${e}" header`,t)]))}function Ve(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new j(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function He(t){return`sha256-${e(`sha256`).update(t).digest(`base64`)}`}const Ue=n.object({version:N,files:n.array(n.string().min(1))}),We=n.object({$schema:n.string().optional(),token:n.string().min(1).optional(),css:n.string().min(1).optional(),aliases:n.object({components:n.string().min(1),ui:n.string().min(1),lib:n.string().min(1),hooks:n.string().min(1),utils:n.string().min(1),styles:n.string().min(1)}),items:n.record(M,Ue).default({})}),Ge=[`tsconfig.json`,`jsconfig.json`],Ke=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function L(e){return o(e).then(()=>!0,()=>!1)}async function R(e){for(let t of Ge){let n=a.join(e,t);if(await L(n))try{return{path:n,config:m(n)}}catch(e){throw new j(`Could not read ${t}: ${e.message}`)}}throw new j(`No tsconfig.json or jsconfig.json in ${e}. slabui uses its "paths" to resolve the aliases.`)}function z(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function qe(e,t,n){if(n===void 0)return;let r=z(e),i=r!==void 0&&n.startsWith(r)?B(e,n):void 0;return i===void 0?n:a.relative(t,i).split(a.sep).join(`/`)}function Je(e,t,n){let r=Ze(n)?a.resolve(t,n):B(e,n);return r===void 0?void 0:a.relative(t,r).split(a.sep).join(`/`)}function B(e,t){return p(e)?.(t)[0]}async function Ye(e){for(let t of Ke)if(await L(a.join(e,t)))return t}async function V(e){let t=a.join(e,S),r=await l(t,`utf8`).catch(()=>void 0);if(r===void 0)throw new j(`${S} not found in ${e}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new j(`${S} is not valid JSON.`)}let o=We.safeParse(i);if(!o.success)throw new j(`${S} has errors:\n${n.prettifyError(o.error)}`);return o.data}async function Xe(e,t){await f(a.join(e,S),`${JSON.stringify(t,null,2)}\n`)}function Ze(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Qe(e){let t=z(await R(e));if(t===void 0)throw new j(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await $e(e,`${t}styles`)}}async function $e(e,t){let n=await Ye(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function et({root:e,aliases:t,css:n,force:r=!1}){if(!r&&await L(a.join(e,`slabui.json`)))throw new j(`${S} already exists. Use --force to create it again.`);let i=await R(e);for(let[e,n]of Object.entries(t))if(!Ze(n)&&B(i,n)===void 0)throw new j(`Alias "${n}" (${e}) does not match any "paths" in the tsconfig.`);let o={$schema:T,...n&&{css:n},aliases:t,items:{}};return await Xe(e,o),o}async function H(e,t){let n=e=>new j(`Path "${t}" refused: ${e}.`);if(t===``)throw n(`it is empty`);if(t.includes(`\0`))throw n(`it contains a null character`);if(t.includes(`\\`))throw n(`use / as the separator`);if(a.posix.isAbsolute(t)||a.win32.isAbsolute(t))throw n(`it is absolute`);let r=a.resolve(e),i=a.resolve(r,t);if(i===r)throw n(`it points to the project root`);if(!tt(r,i))throw n(`it leaves the project root`);let o=await nt(i);if(o===i&&(await s(i)).isSymbolicLink())throw n(`the target is a symbolic link`);let c=await u(r),l=await u(o).catch(()=>{throw n(`it goes through a broken symbolic link`)});if(!tt(c,l))throw n(`it goes through a symbolic link outside the project`);return a.join(l,a.relative(o,i))}function tt(e,t){let n=a.relative(e,t);return n===``||n!==`..`&&!n.startsWith(`..${a.sep}`)&&!a.isAbsolute(n)}async function nt(e){let t=e;for(;;)try{return await s(t),t}catch(e){if(e.code!==`ENOENT`)throw e;t=a.dirname(t)}}const U=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],rt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,it=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function at(e){return a.posix.extname(e)===`.css`}function ot(e,t){return e.replace(it,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function st(e){return U.includes(a.posix.extname(e))}function ct(e,t){return e.replace(rt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function lt(e,t){return[e,...U.map(t=>`${e}${t}`),...U.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function ut(e){let t=a.posix.extname(e);return U.includes(t)?e.slice(0,-t.length):e}function W(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new j(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==C.namespace)throw new j(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!M.safeParse(r).success)throw new j(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||h.validRange(i)===null))throw new j(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function G(e){return e.name}function K(e,t=process.env){return{namespace:C.namespace,url:t.SLABUI_REGISTRY_URL||C.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function q(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=h.maxSatisfying(n,e.range);if(r===null)throw new j(`No version of "${G(e)}" satisfies "${e.range}". Available: ${h.sort(n).join(`, `)}.`);return r}const dt={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function ft(e,t){if(e.target!==void 0){let n=e.target;return mt((n.startsWith(z(t.tsconfig)??`\0`)?B(t.tsconfig,n):void 0)??a.resolve(t.root,n),t)}if(!(e.kind in dt))throw new j(`Files with kind "${e.kind}" cannot be installed by add yet (${e.path}).`);let n=t.aliases[dt[e.kind]],r=e.kind===`style`&&e.path.split(`/`).slice(1).join(`/`)||a.posix.basename(e.path),i=Ze(n)?a.resolve(t.root,n,r):B(t.tsconfig,`${n}/${r}`);if(i===void 0)throw new j(`Alias "${n}" does not match any "paths" in the tsconfig.`);return mt(i,t)}function pt(e,t,n){let r=z(n.tsconfig),i=r===void 0?void 0:B(n.tsconfig,`${r}__slabui__`)?.slice(0,-10),o=a.resolve(n.root,e);if(r!==void 0&&i!==void 0&&o.startsWith(i))return`${r}${ut(a.relative(i,o).split(a.sep).join(`/`))}`;let s=a.posix.relative(a.posix.dirname(t),e);return s.startsWith(`.`)||(s=`./${s}`),ut(s)}function mt(e,t){return a.relative(t.root,e).split(a.sep).join(`/`)}function J(e){return e.kind===`block`||e.kind===`example`}function ht(e,t,n){return J(e)?bt(e,n):new Map(e.files.map(e=>[e.path,ft(e,t)]))}function gt(e,t){return[e,...t.dependencies.registry.map(e=>G(W(e)))]}async function _t(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=W(e),o=G(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(K(t.token));r.set(o,ht(await c.item(a.name,s.version),n))}}function vt(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=at(e.path);if(!st(e.path)&&!s)return e.content;let c=gt(t,n),l=e=>{if(e===`slabui:css`){if(a.css===void 0){o.push(`"${t}": ${r} uses the global CSS, but "css" is not set in slabui.json.`);return}return yt(a.css,r)}if(!e.startsWith(`@/registry/`))return;let n=e.slice(11);for(let e of c){let t=i.get(e),o=t&<(n,new Set(t.keys()));if(o){let e=t.get(o);return s?yt(e,r):pt(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?ot(e.content,l):ct(e.content,l)}function yt(e,t){let n=a.posix.relative(a.posix.dirname(t),e);return n.startsWith(`.`)?n:`./${n}`}function bt(e,t){let n=e.files.map(e=>a.posix.dirname(e.path).split(`/`)),r=[];for(let[e,t]of(n[0]??[]).entries())if(n.every(n=>n[e]===t))r.push(t);else break;let i=r.join(`/`),o=a.posix.normalize(t.split(a.sep).join(`/`));return new Map(e.files.map(e=>[e.path,a.posix.join(o,a.posix.relative(i,e.path))]))}const xt=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function St(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function Ct(e){let t=(await wt(e))?.packageManager?.split(`@`)[0];if(t&&[`pnpm`,`npm`,`yarn`,`bun`].includes(t))return t;let n=a.resolve(e);for(;;){for(let[e,t]of xt)if(await L(a.join(n,e)))return t;let e=a.dirname(n);if(e===n)return`npm`;n=e}}async function wt(e){let t=await l(a.join(e,`package.json`),`utf8`).catch(()=>void 0);return t===void 0?void 0:JSON.parse(t)}async function Tt(e,{npm:t,npmDev:n}){let r=await wt(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=St(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=h.minVersion(o);r&&s&&!h.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function Et(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function Dt(e,t,n,r){if(n.length===0)return;let[i,a]=Et(t,n,r);await new Promise((t,n)=>{let r=g(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new j(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new j(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function Ot(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await Tt(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${St(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await Ct(e);return await Dt(e,s,a.install,!1),await Dt(e,s,a.installDev,!0),o}async function kt({refs:e,config:t,createClient:n=e=>I(e)}){let r=/* @__PURE__ */ new Map,i=/* @__PURE__ */ new Map,a=/* @__PURE__ */ new Map,o=[],s=/* @__PURE__ */ new Set,c=[];function l(e){let t=r.get(e.namespace);return t===void 0&&(t=n(e),r.set(e.namespace,t)),t}async function u(e,n){let r=G(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!h.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>At(p,e)))return;let m=K(t.token),g=l(m),_=(await g.index()).items[e.name];if(_===void 0)throw new j(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let v=Object.keys(_.versions),y=d.flatMap(({range:e})=>e?[e]:[]),b=y.length===0?_.latest:h.rsort(v.filter(e=>y.every(t=>h.satisfies(e,t))))[0]??null;if(b===null)throw new j(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${h.sort(v).join(`, `)}.`);let x=await g.item(e.name,b);a.set(r,{key:r,registry:m,item:x});for(let e of x.dependencies.registry)await u(W(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(W(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function At(e,t){return t===void 0||h.satisfies(e.item.version,t)}const jt=/^[a-z0-9][a-z0-9-]*$/i;function Mt(e){return jt.test(e)}function Nt(e,t=!1){if(!Mt(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const Pt=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function Ft(e,t,{base:n,overwrite:r=!1,shouldRemove:i,theme:a}={}){let o=_.parse(e),s=[],c=[],l=e=>a?e:It(e),u=l(t),d=n?l(n):void 0;for(let e of[`theme`,`light`,`dark`]){let t=u[e]??{},n=d?.[e]??{},l=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);if(l.size===0)continue;let f=zt(o,e,a);for(let u of l){let l=t[u],d=n[u],p=f?.nodes?.find(e=>e.type===`decl`&&e.prop===`--${u}`),m=p?.value,h=t=>s.push({group:e,name:u,action:t});if(l===void 0){if(m===void 0)continue;i&&await i(e,u)?(p?.remove(),h(`removed`)):(c.push(`--${u} (${e}) was removed in the new version; kept in the CSS.`),h(`kept`))}else if(m===void 0){if(d!==void 0){h(`kept`);continue}f??=Bt(o,e,a),f.raws.semicolon=!0,f.raws.after=`
|
|
121
121
|
`,f.append(_.decl({prop:`--${u}`,value:l,raws:{before:`
|
|
122
122
|
`}})),h(`added`)}else Ht(m,l)?h(`unchanged`):r||d!==void 0&&Ht(m,d)?(p.value=l,h(`updated`)):(c.push(`--${u} (${e}) has a custom value in the CSS (${m}); kept instead of ${l}.`),h(`kept`))}}return!a&&Object.keys(u.dark??{}).length>0&&Vt(o),{css:o.toString(),changes:s,warnings:c}}function It(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))Pt.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function Lt(e,t){return t?Nt(t,e===`dark`):e===`light`?`:root`:`.dark`}const Rt=e=>e.replace(/["'\s]/g,``);function zt(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&Rt(e.selector)===Rt(Lt(t,n)))}function Bt(e,t,n){let r=t===`theme`?_.atRule({name:`theme`,params:`inline`}):_.rule({selector:Lt(t,n)});return r.raws={before:e.nodes.length>0?`
|
|
123
123
|
|