@slabui/cli 0.4.1 → 0.6.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 CHANGED
@@ -1,5 +1,25 @@
1
1
  # @slabui/cli
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#124](https://github.com/slabui/ui/pull/124) [`f4cedc6`](https://github.com/slabui/ui/commit/f4cedc621262225dabd07e06f7cc80806bb7cc00) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - `slabui init` now writes the control size variables (`--control-size`, `--control-padding` and `--control-text`) with the default theme, and `slabui add` brings them, with the `h-control`, `px-control-x` and `text-control` entries of `@theme inline`, to projects that install a component that uses them.
8
+
9
+ `slabui init` and `slabui add` also write `--primary-soft`. In a project whose `--primary` is not the default one, it is written as `var(--primary)`, so the two never drift apart.
10
+
11
+ `slabui init` and `slabui add` also write `--panel-spacing` and its `@theme inline` entries for the components that use them.
12
+
13
+ They also write `--panel-footer`.
14
+
15
+ - [#124](https://github.com/slabui/ui/pull/124) [`177e0a8`](https://github.com/slabui/ui/commit/177e0a8887baa5b960840a6ccf3efe2d2bd83070) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - `slabui init` now records the default theme in `slabui.json` as `theme-default`, so `slabui outdated` and `slabui update` also cover the theme. The CSS template follows the new theme tokens (`ring-size` and `ring-offset` instead of `focus-size` and `focus-offset`, no `brand`).
16
+
17
+ ## 0.5.0
18
+
19
+ ### Minor Changes
20
+
21
+ - [#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`.
22
+
3
23
  ## 0.4.1
4
24
 
5
25
  ### Patch Changes
package/dist/cli.mjs CHANGED
@@ -1,19 +1,19 @@
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 T}from"node:http";import{merge as te}from"node-diff3";var ne=`0.4.1`,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=`
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 re=`0.6.0`,ie=`The SlabUI CLI: add, update and compare items from versioned component registries`;const ae=/^[a-z0-9][a-z0-9-]*$/i;function oe(e){return ae.test(e)}function se(e,t=!1){if(!oe(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const ce=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function le(e,t,{base:n,overwrite:i=!1,shouldRemove:a,theme:o}={}){let s=r.parse(e),c=[],l=[],u=e=>o?e:ue(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=pe(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??=me(s,e,o),p.raws.semicolon=!0,p.raws.after=`
3
3
  `,p.append(r.decl({prop:`--${d}`,value:u,raws:{before:`
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?`
4
+ `}})),g(`added`)}else ge(h,u)?g(`unchanged`):i||f!==void 0&&ge(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&&he(s),{css:s.toString(),changes:c,warnings:l}}function ue(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))ce.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function de(e,t){return t?se(t,e===`dark`):e===`light`?`:root`:`.dark`}const fe=e=>e.replace(/["'\s]/g,``);function pe(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&fe(e.selector)===fe(de(t,n)))}function me(e,t,n){let i=t===`theme`?r.atRule({name:`theme`,params:`inline`}):r.rule({selector:de(t,n)});return i.raws={before:e.nodes.length>0?`
5
5
 
6
6
  `:``,between:` `,after:`
7
- `,semicolon:!0},e.append(i),i}function pe(e){if(e.nodes.some(e=>e.type===`atrule`&&e.name===`custom-variant`&&e.params.trim().startsWith(`dark`)))return;let t=r.atRule({name:`custom-variant`,params:`dark (&:is(.dark *))`}),n=e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`).at(-1);n?(t.raws={before:`
7
+ `,semicolon:!0},e.append(i),i}function he(e){if(e.nodes.some(e=>e.type===`atrule`&&e.name===`custom-variant`&&e.params.trim().startsWith(`dark`)))return;let t=r.atRule({name:`custom-variant`,params:`dark (&:is(.dark *))`}),n=e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`).at(-1);n?(t.raws={before:`
8
8
 
9
- `},n.after(t)):(t.raws={before:``},e.prepend(t))}function me(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}const D={theme:{"font-sans":`var(--font-sans)`,"font-heading":`var(--font-heading)`,"font-mono":`var(--font-mono)`,"radius-sm":`calc(var(--radius) * 0.6)`,"radius-md":`calc(var(--radius) * 0.8)`,"radius-lg":`var(--radius)`,"radius-xl":`calc(var(--radius) * 1.4)`,"radius-2xl":`calc(var(--radius) * 1.8)`,"radius-3xl":`calc(var(--radius) * 2.2)`,"radius-4xl":`calc(var(--radius) * 2.6)`,"breakpoint-3xl":`1600px`,"breakpoint-4xl":`2000px`,"text-xxs":`calc(var(--font-size) * 0.625)`,"text-2xxs":`calc(var(--font-size) * 0.688)`,"text-xs":`calc(var(--font-size) * 0.75)`,"text-xs--line-height":`calc(1 / 0.75)`,"text-2xs":`calc(var(--font-size) * 0.813)`,"text-2xs--line-height":`calc(1.125 / 0.813)`,"text-sm":`calc(var(--font-size) * 0.875)`,"text-sm--line-height":`calc(1.25 / 0.875)`,"text-2sm":`calc(var(--font-size) * 0.938)`,"text-2sm--line-height":`calc(1.625 / 0.938)`,"text-base":`var(--font-size)`,"text-base--line-height":`calc(1.5 / 1)`,"text-lg":`calc(var(--font-size) * 1.125)`,"text-lg--line-height":`calc(1.75 / 1.125)`,"text-xl":`calc(var(--font-size) * 1.25)`,"text-xl--line-height":`calc(1.75 / 1.25)`,"text-2xl":`calc(var(--font-size) * 1.5)`,"text-2xl--line-height":`calc(2 / 1.5)`,"text-3xl":`calc(var(--font-size) * 1.875)`,"text-3xl--line-height":`calc(2.25 / 1.875)`,"text-4xl":`calc(var(--font-size) * 2.25)`,"text-4xl--line-height":`calc(2.5 / 2.25)`,"text-5xl":`calc(var(--font-size) * 3)`,"text-5xl--line-height":`1`,"text-6xl":`calc(var(--font-size) * 3.75)`,"text-6xl--line-height":`1`,"text-7xl":`calc(var(--font-size) * 4.5)`,"text-7xl--line-height":`1`,"text-8xl":`calc(var(--font-size) * 6)`,"text-8xl--line-height":`1`,"text-9xl":`calc(var(--font-size) * 8)`,"text-9xl--line-height":`1`,spacing:`var(--spacing)`,"focus-size":`calc(var(--focus-size))`,"focus-offset":`var(--focus-offset)`,"container-page-sm":`var(--page-sm)`,"container-page":`var(--page)`,"container-page-lg":`var(--page-lg)`,"color-destructive":`var(--danger)`},light:{spacing:`0.25rem`,radius:`0.65rem`,"font-size":`1rem`,"page-sm":`768px`,page:`1200px`,"page-lg":`1440px`,background:`oklch(1 0 0)`,"scrollbar-thumb":`oklch(0.922 0 0)`,foreground:`oklch(0.145 0 0)`,card:`oklch(1 0 0)`,"card-foreground":`oklch(0.145 0 0)`,popover:`oklch(1 0 0)`,"popover-foreground":`oklch(0.145 0 0)`,muted:`oklch(0.97 0 0)`,"muted-foreground":`oklch(0.556 0 0)`,accent:`oklch(0.97 0 0)`,"accent-foreground":`oklch(0.205 0 0)`,border:`oklch(0.922 0 0)`,input:`oklch(0.922 0 0)`,ring:`oklch(0.708 0 0)`,"chart-1":`oklch(0.646 0.222 41.116)`,"chart-2":`oklch(0.6 0.118 184.704)`,"chart-3":`oklch(0.398 0.07 227.392)`,"chart-4":`oklch(0.828 0.189 84.429)`,"chart-5":`oklch(0.769 0.188 70.08)`,sidebar:`oklch(0.985 0 0)`,"sidebar-foreground":`oklch(0.145 0 0)`,"sidebar-primary":`oklch(0.205 0 0)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.97 0 0)`,"sidebar-accent-foreground":`oklch(0.205 0 0)`,"sidebar-border":`oklch(0.922 0 0)`,"sidebar-ring":`oklch(0.708 0 0)`,brand:`oklch(70% 0.1435 227.76)`,"brand-foreground":`oklch(0.985 0 0)`,primary:`oklch(70% 0.1435 227.76)`,"primary-foreground":`oklch(0.985 0 0)`,secondary:`oklch(0.97 0 0)`,"secondary-foreground":`oklch(0.205 0 0)`,danger:`oklch(0.577 0.245 27.325)`,"danger-foreground":`oklch(0.985 0 0)`,success:`oklch(0.728 0.125 139.6)`,"success-foreground":`oklch(0.985 0 0)`,warning:`oklch(0.784 0.181 44.7)`,"warning-foreground":`oklch(0.985 0 0)`,inverted:`oklch(0.205 0 0)`,"inverted-foreground":`oklch(0.97 0 0)`,focus:`oklch(0.7 0.181 44.7)`,"focus-size":`2.5px`,"focus-offset":`2px`,table:`oklch(0.94 0 0 / 65%)`,"table-content":`oklch(1 0 0)`,"table-hover":`oklch(0.98 0 0 / 10%)`},dark:{background:`oklch(0.145 0 0)`,"scrollbar-thumb":`oklch(0.269 0 0)`,foreground:`oklch(0.985 0 0)`,card:`oklch(0.205 0 0)`,"card-foreground":`oklch(0.985 0 0)`,popover:`oklch(0.205 0 0)`,"popover-foreground":`oklch(0.985 0 0)`,secondary:`oklch(0.269 0 0)`,"secondary-foreground":`oklch(0.985 0 0)`,muted:`oklch(0.269 0 0)`,"muted-foreground":`oklch(0.708 0 0)`,accent:`oklch(0.269 0 0)`,"accent-foreground":`oklch(0.985 0 0)`,border:`oklch(1 0 0 / 10%)`,input:`oklch(1 0 0 / 15%)`,ring:`oklch(0.556 0 0)`,"chart-1":`oklch(0.488 0.243 264.376)`,"chart-2":`oklch(0.696 0.17 162.48)`,"chart-3":`oklch(0.769 0.188 70.08)`,"chart-4":`oklch(0.627 0.265 303.9)`,"chart-5":`oklch(0.645 0.246 16.439)`,sidebar:`oklch(0.205 0 0)`,"sidebar-foreground":`oklch(0.985 0 0)`,"sidebar-primary":`oklch(0.488 0.243 264.376)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.269 0 0)`,"sidebar-accent-foreground":`oklch(0.985 0 0)`,"sidebar-border":`oklch(1 0 0 / 10%)`,"sidebar-ring":`oklch(0.556 0 0)`,brand:`oklch(66% 0.1435 227.76)`,"brand-foreground":`oklch(0.985 0 0)`,primary:`oklch(66% 0.1435 227.76)`,"primary-foreground":`oklch(0.985 0 0)`,danger:`oklch(0.704 0.191 22.216)`,"danger-foreground":`oklch(0.985 0 0)`,success:`oklch(0.728 0.125 139.6)`,"success-foreground":`oklch(0.985 0 0)`,warning:`oklch(0.784 0.181 44.7)`,"warning-foreground":`oklch(0.985 0 0)`,inverted:`oklch(0.922 0 0)`,"inverted-foreground":`oklch(0.205 0 0)`,focus:`oklch(0.7 0.181 44.7)`,table:`oklch(0.265 0 0)`,"table-content":`oklch(0.205 0 0)`,"table-hover":`oklch(0.22 0 0)`}};function he(e){return/^(?:font|text)-/.test(e)}const ge={utility:`utility`,variant:`custom-variant`};function _e(e){return e.params.trim().split(/[\s({]/)[0]??``}async function ve(e,t,n={}){let i=r.parse(e),a=[],o=[];for(let e of[`variant`,`utility`]){let r=e===`utility`?`utilities`:`variants`,s=t[r]??{},c=n.base?.[r]??{},l=/* @__PURE__ */ new Set([...Object.keys(s),...Object.keys(c)]);for(let t of l){let l=s[t],u=c[t],d=xe(i,e,t),f=`${r===`utilities`?`@utility`:`@custom-variant`} ${t}`,p=await be({local:d&&we(d),remote:l,base:u,options:n,kind:e,name:t,label:f,warnings:o,add:t=>Se(i,e,t),replace:e=>{let t=Ce(e);t.raws.before=d?.raws.before??``,d?.replaceWith(t)},remove:()=>d?.remove()});p&&a.push({kind:e,name:t,action:p})}}return{css:i.toString(),changes:a,warnings:o}}async function ye(e,t={},n={}){let i=r.parse(e),a=[],o=[],s=n.base?.base??{},c=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(s)]);for(let e of c){let c=t[e]??{},l=s[e]??{},u=/* @__PURE__ */ new Set([...Object.keys(c),...Object.keys(l)]);for(let t of u){let s=Te(i),u=s&&Ee(s,e),d=u?.nodes.find(e=>e.type===`decl`&&e.prop===t),f=`${e} { ${t} }`,p=await be({local:d?.value,remote:c[t],base:l[t],options:n,kind:`base`,name:f,label:`${t} in ${e}`,warnings:o,add:n=>{u??=De(i,e),u.append(r.decl({prop:t,value:n,raws:{before:`
10
- `}}))},replace:e=>{d&&(d.value=e)},remove:()=>{d?.remove(),u?.nodes.length===0&&u.remove()}});p&&a.push({kind:`base`,name:f,action:p})}}return{css:i.toString(),changes:a,warnings:o}}async function be({local:e,remote:t,base:n,options:r,kind:i,name:a,label:o,warnings:s,add:c,replace:l,remove:u}){return t===void 0?e===void 0?void 0:r.shouldRemove&&await r.shouldRemove(i,a)?(u(),`removed`):(s.push(`${o} was removed in the new version; kept in the CSS.`),`kept`):e===void 0?n===void 0?(c(t),`added`):`kept`:ke(e,t)?`unchanged`:r.overwrite||n!==void 0&&ke(e,n)?(l(t),`updated`):(s.push(`${o} was changed in the CSS; kept instead of the new one.`),`kept`)}function xe(e,t,n){return e.nodes.find(e=>e.type===`atrule`&&e.name===ge[t]&&_e(e)===n)}function Se(e,t,n){let r=Ce(n),i=e.nodes.findLast(e=>e.type===`atrule`&&e.name===ge.variant);if(t===`variant`){let t=e.nodes.find(e=>e.type===`atrule`&&e.name===ge.utility);if(i){r.raws.before=`
9
+ `},n.after(t)):(t.raws={before:``},e.prepend(t))}function ge(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}const T={theme:{"font-sans":`var(--font-sans)`,"font-heading":`var(--font-heading)`,"font-mono":`var(--font-mono)`,"radius-sm":`calc(var(--radius) * 0.6)`,"radius-md":`calc(var(--radius) * 0.8)`,"radius-lg":`var(--radius)`,"radius-xl":`calc(var(--radius) * 1.4)`,"radius-2xl":`calc(var(--radius) * 1.8)`,"radius-3xl":`calc(var(--radius) * 2.2)`,"radius-4xl":`calc(var(--radius) * 2.6)`,"breakpoint-3xl":`1600px`,"breakpoint-4xl":`2000px`,"text-xxs":`calc(var(--font-size) * 0.625)`,"text-2xxs":`calc(var(--font-size) * 0.688)`,"text-xs":`calc(var(--font-size) * 0.75)`,"text-xs--line-height":`calc(1 / 0.75)`,"text-2xs":`calc(var(--font-size) * 0.813)`,"text-2xs--line-height":`calc(1.125 / 0.813)`,"text-sm":`calc(var(--font-size) * 0.875)`,"text-sm--line-height":`calc(1.25 / 0.875)`,"text-2sm":`calc(var(--font-size) * 0.938)`,"text-2sm--line-height":`calc(1.625 / 0.938)`,"text-base":`var(--font-size)`,"text-base--line-height":`calc(1.5 / 1)`,"text-lg":`calc(var(--font-size) * 1.125)`,"text-lg--line-height":`calc(1.75 / 1.125)`,"text-xl":`calc(var(--font-size) * 1.25)`,"text-xl--line-height":`calc(1.75 / 1.25)`,"text-2xl":`calc(var(--font-size) * 1.5)`,"text-2xl--line-height":`calc(2 / 1.5)`,"text-3xl":`calc(var(--font-size) * 1.875)`,"text-3xl--line-height":`calc(2.25 / 1.875)`,"text-4xl":`calc(var(--font-size) * 2.25)`,"text-4xl--line-height":`calc(2.5 / 2.25)`,"text-5xl":`calc(var(--font-size) * 3)`,"text-5xl--line-height":`1`,"text-6xl":`calc(var(--font-size) * 3.75)`,"text-6xl--line-height":`1`,"text-7xl":`calc(var(--font-size) * 4.5)`,"text-7xl--line-height":`1`,"text-8xl":`calc(var(--font-size) * 6)`,"text-8xl--line-height":`1`,"text-9xl":`calc(var(--font-size) * 8)`,"text-9xl--line-height":`1`,spacing:`var(--spacing)`,"spacing-control-xs":`calc(0.25rem * var(--control-size) * 5.5 / 7.5)`,"spacing-control-sm":`calc(0.25rem * var(--control-size) * 6.5 / 7.5)`,"spacing-control":`calc(0.25rem * var(--control-size))`,"spacing-control-lg":`calc(0.25rem * var(--control-size) * 8.5 / 7.5)`,"spacing-control-icon-xs":`calc(0.25rem * var(--control-size) / 3)`,"spacing-control-icon-sm":`calc(0.25rem * var(--control-size) * 0.4)`,"spacing-control-icon":`calc(0.25rem * var(--control-size) * 0.4667)`,"spacing-control-icon-lg":`calc(0.25rem * var(--control-size) * 0.533)`,"spacing-control-x-sm":`calc(0.25rem * var(--control-padding) * 0.8)`,"spacing-control-x":`calc(0.25rem * var(--control-padding))`,"spacing-control-x-lg":`calc(0.25rem * var(--control-padding) * 1.2)`,"spacing-panel":`calc(var(--spacing) * var(--panel-spacing))`,"spacing-panel-sm":`calc(var(--spacing) * var(--panel-spacing) * 0.75)`,"text-control-xs":`calc(var(--font-size) * var(--control-text) * 0.7688)`,"text-control-sm":`calc(var(--font-size) * var(--control-text) * 0.9225)`,"text-control-sm--line-height":`calc(1.084 / var(--control-text))`,"text-control":`calc(var(--font-size) * var(--control-text))`,"text-control--line-height":`calc(1.125 / var(--control-text))`,"text-control-lg":`calc(var(--font-size) * var(--control-text) * 1.0763)`,"text-control-lg--line-height":`calc(1.161 / var(--control-text))`,"ring-size":`calc(var(--ring-size))`,"ring-offset":`var(--ring-offset)`,"container-page-sm":`var(--page-sm)`,"container-page":`var(--page)`,"container-page-lg":`var(--page-lg)`},light:{spacing:`0.25rem`,radius:`0.65rem`,"font-size":`1rem`,"control-size":`7.5`,"control-padding":`2.5`,"control-text":`0.813`,"panel-spacing":`4`,"panel-footer":`0`,"page-sm":`768px`,page:`1200px`,"page-lg":`1440px`,primary:`oklch(0.47 0.0867 221.72)`,"primary-foreground":`oklch(0.985 0 0)`,"primary-soft":`oklch(0.47 0.0867 221.72)`,secondary:`oklch(0.97 0 0)`,"secondary-foreground":`oklch(0.205 0 0)`,accent:`oklch(0.97 0 0)`,"accent-foreground":`oklch(0.205 0 0)`,muted:`oklch(0.97 0 0)`,"muted-foreground":`oklch(0.439 0 0)`,success:`oklch(0.47 0.0795 161.48)`,"success-foreground":`oklch(0.985 0 0)`,warning:`oklch(0.47 0.0689 84.4)`,"warning-foreground":`oklch(0.985 0 0)`,danger:`oklch(0.47 0.1113 12.6)`,"danger-foreground":`oklch(0.985 0 0)`,background:`oklch(0.985 0 0)`,foreground:`oklch(0.145 0 0)`,card:`oklch(1 0 0)`,"card-foreground":`oklch(0.145 0 0)`,popover:`oklch(1 0 0)`,"popover-foreground":`oklch(0.145 0 0)`,border:`oklch(0.922 0 0)`,input:`oklch(0.922 0 0)`,ring:`oklch(0.705 0.1867 47.6)`,"ring-size":`2.5px`,"ring-offset":`2px`,"scrollbar-thumb":`oklch(0.87 0 0)`,"chart-1":`oklch(0.555 0.0998 221.72)`,"chart-2":`oklch(0.735 0.0879 221.72)`,"chart-3":`oklch(0.39 0.072 221.72)`,"chart-4":`oklch(0.825 0.0649 221.72)`,"chart-5":`oklch(0.609 0.0998 221.72)`,sidebar:`oklch(0.97 0 0)`,"sidebar-foreground":`oklch(0.145 0 0)`,"sidebar-primary":`oklch(0.47 0.0867 221.72)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.922 0 0)`,"sidebar-accent-foreground":`oklch(0.205 0 0)`,"sidebar-border":`oklch(0.922 0 0)`,"sidebar-ring":`oklch(0.708 0 0)`},dark:{primary:`oklch(0.39 0.072 221.72)`,"primary-foreground":`oklch(0.985 0 0)`,"primary-soft":`oklch(0.735 0.0879 221.72)`,secondary:`oklch(0.269 0 0)`,"secondary-foreground":`oklch(0.985 0 0)`,accent:`oklch(0.269 0 0)`,"accent-foreground":`oklch(0.985 0 0)`,muted:`oklch(0.269 0 0)`,"muted-foreground":`oklch(0.708 0 0)`,success:`oklch(0.735 0.076 161.48)`,"success-foreground":`oklch(0.205 0 0)`,warning:`oklch(0.735 0.0659 84.4)`,"warning-foreground":`oklch(0.205 0 0)`,danger:`oklch(0.735 0.1064 12.6)`,"danger-foreground":`oklch(0.205 0 0)`,background:`oklch(0.145 0 0)`,foreground:`oklch(0.985 0 0)`,card:`oklch(0.205 0 0)`,"card-foreground":`oklch(0.985 0 0)`,popover:`oklch(0.205 0 0)`,"popover-foreground":`oklch(0.985 0 0)`,border:`oklch(1 0 0 / 10%)`,input:`oklch(1 0 0 / 15%)`,ring:`oklch(0.705 0.1867 47.6)`,"scrollbar-thumb":`oklch(0.371 0 0)`,"chart-1":`oklch(0.609 0.0998 221.72)`,"chart-2":`oklch(0.825 0.0649 221.72)`,"chart-3":`oklch(0.47 0.0867 221.72)`,"chart-4":`oklch(0.895 0.0399 221.72)`,"chart-5":`oklch(0.735 0.0879 221.72)`,sidebar:`oklch(0.205 0 0)`,"sidebar-foreground":`oklch(0.985 0 0)`,"sidebar-primary":`oklch(0.39 0.072 221.72)`,"sidebar-primary-foreground":`oklch(0.985 0 0)`,"sidebar-accent":`oklch(0.269 0 0)`,"sidebar-accent-foreground":`oklch(0.985 0 0)`,"sidebar-border":`oklch(1 0 0 / 10%)`,"sidebar-ring":`oklch(0.556 0 0)`}};function _e(e){return/^(?:font|text)-/.test(e)}const ve={utility:`utility`,variant:`custom-variant`};function ye(e){return e.params.trim().split(/[\s({]/)[0]??``}async function be(e,t,n={}){let i=r.parse(e),a=[],o=[];for(let e of[`variant`,`utility`]){let r=e===`utility`?`utilities`:`variants`,s=t[r]??{},c=n.base?.[r]??{},l=/* @__PURE__ */ new Set([...Object.keys(s),...Object.keys(c)]);for(let t of l){let l=s[t],u=c[t],d=Ce(i,e,t),f=`${r===`utilities`?`@utility`:`@custom-variant`} ${t}`,p=await Se({local:d&&Ee(d),remote:l,base:u,options:n,kind:e,name:t,label:f,warnings:o,add:t=>we(i,e,t),replace:e=>{let t=Te(e);t.raws.before=d?.raws.before??``,d?.replaceWith(t)},remove:()=>d?.remove()});p&&a.push({kind:e,name:t,action:p})}}return{css:i.toString(),changes:a,warnings:o}}async function xe(e,t={},n={}){let i=r.parse(e),a=[],o=[],s=n.base?.base??{},c=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(s)]);for(let e of c){let c=t[e]??{},l=s[e]??{},u=/* @__PURE__ */ new Set([...Object.keys(c),...Object.keys(l)]);for(let t of u){let s=De(i),u=s&&Oe(s,e),d=u?.nodes.find(e=>e.type===`decl`&&e.prop===t),f=`${e} { ${t} }`,p=await Se({local:d?.value,remote:c[t],base:l[t],options:n,kind:`base`,name:f,label:`${t} in ${e}`,warnings:o,add:n=>{u??=ke(i,e),u.append(r.decl({prop:t,value:n,raws:{before:`
10
+ `}}))},replace:e=>{d&&(d.value=e)},remove:()=>{d?.remove(),u?.nodes.length===0&&u.remove()}});p&&a.push({kind:`base`,name:f,action:p})}}return{css:i.toString(),changes:a,warnings:o}}async function Se({local:e,remote:t,base:n,options:r,kind:i,name:a,label:o,warnings:s,add:c,replace:l,remove:u}){return t===void 0?e===void 0?void 0:r.shouldRemove&&await r.shouldRemove(i,a)?(u(),`removed`):(s.push(`${o} was removed in the new version; kept in the CSS.`),`kept`):e===void 0?n===void 0?(c(t),`added`):`kept`:je(e,t)?`unchanged`:r.overwrite||n!==void 0&&je(e,n)?(l(t),`updated`):(s.push(`${o} was changed in the CSS; kept instead of the new one.`),`kept`)}function Ce(e,t,n){return e.nodes.find(e=>e.type===`atrule`&&e.name===ve[t]&&ye(e)===n)}function we(e,t,n){let r=Te(n),i=e.nodes.findLast(e=>e.type===`atrule`&&e.name===ve.variant);if(t===`variant`){let t=e.nodes.find(e=>e.type===`atrule`&&e.name===ve.utility);if(i){r.raws.before=`
11
11
  `,i.after(r);return}if(t){r.raws.before=t.raws.before??``,t.raws.before=`
12
12
 
13
13
  `,t.before(r);return}}r.raws.before=e.nodes.length>0?`
14
14
 
15
15
  `:``,e.append(r),e.raws.after=`
16
- `}function Ce(e){let t=r.parse(e.trim()).first;if(t?.type!==`atrule`)throw Error(`Not a CSS at-rule: ${e}`);return t}function we(e){let t=e.clone();return t.raws.before=``,t.nodes===void 0?`${t.toString()};`:t.toString()}function Te(e){return e.nodes.find(e=>e.type===`atrule`&&e.name===`layer`&&e.params.trim()===`base`)}function Ee(e,t){return e.nodes?.find(e=>e.type===`rule`&&Oe(e.selector)===Oe(t))}function De(e,t){let n=Te(e);n===void 0&&(n=r.atRule({name:`layer`,params:`base`}),n.raws={before:e.nodes.length>0?`
16
+ `}function Te(e){let t=r.parse(e.trim()).first;if(t?.type!==`atrule`)throw Error(`Not a CSS at-rule: ${e}`);return t}function Ee(e){let t=e.clone();return t.raws.before=``,t.nodes===void 0?`${t.toString()};`:t.toString()}function De(e){return e.nodes.find(e=>e.type===`atrule`&&e.name===`layer`&&e.params.trim()===`base`)}function Oe(e,t){return e.nodes?.find(e=>e.type===`rule`&&Ae(e.selector)===Ae(t))}function ke(e,t){let n=De(e);n===void 0&&(n=r.atRule({name:`layer`,params:`base`}),n.raws={before:e.nodes.length>0?`
17
17
 
18
18
  `:``,between:` `,after:`
19
19
  `},e.append(n),e.raws.after=`
@@ -22,28 +22,28 @@ import e from"node:path";import{Command as t,Option as n}from"commander";import
22
22
  `:`
23
23
  `,between:` `,after:`
24
24
  `,semicolon:!0},n.append(i),n.raws.after=`
25
- `,i}const Oe=e=>e.replace(/["'\s]/g,``);function ke(e,t){let n=e=>e.replace(/\s+/g,` `).replace(/\s*([{};:,])\s*/g,`$1`).replace(/;}/g,`}`).replace(/;$/,``).trim();return n(e)===n(t)}function Ae(e){return e.params.trim().replace(/^url\((.*)\)/,`$1`).split(/\s/)[0]?.replace(/^["']|["']$/g,``)}const je=(e,t)=>e!==void 0&&e.replace(/^\.\//,``)===t.replace(/^\.\//,``);function Me(e){return e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`)}function Ne(e,t){let n=r.parse(e),i=Me(n);if(i.some(e=>je(Ae(e),t)))return e;let a=r.atRule({name:`import`,params:`"${t}"`}),o=i.at(-1);return o?(a.raws={before:`
26
- `},o.after(a)):(a.raws={before:``},n.prepend(a)),n.toString()}const Pe=se,Fe=ve,Ie=ye,Le=Ne;function Re(e){let t=[`added`,`updated`,`kept`,`removed`].flatMap(t=>{let n=e.filter(e=>e.action===t).length;return n===0?[]:[`${n} ${t}`]});return t.length===0?void 0:`CSS rules: ${t.join(`, `)}.`}function ze(e){let t=[[`added`,`added`,`added`],[`updated`,`updated`,`updated`],[`kept`,`kept`,`kept`],[`removed`,`removed`,`removed`]].flatMap(([t,n,r])=>{let i=e.filter(e=>e.action===t).length;return i===0?[]:[`${i} ${i===1?n:r}`]});return t.length===0?void 0:`CSS variables: ${t.join(`, `)}.`}const O=`slabui.json`,k={namespace:`@slabui`,url:`https://slabui.com/r`},Be={command:`x-slabui-command`,optOut:`x-slabui-telemetry`},Ve=[`ui`,`component`,`lib`,`hook`,`util`,`style`,`file`,`theme`,`block`,`example`],He=[`free`,`pro`],A=`SLABUI_TOKEN`,j=[`claude`,`cursor`,`vscode`,`zed`,`codex`];function Ue({status:e,title:t,message:n,close:r=!1}){let i=e===`success`?qe:Je;return`<!doctype html>
25
+ `,i}const Ae=e=>e.replace(/["'\s]/g,``);function je(e,t){let n=e=>e.replace(/\s+/g,` `).replace(/\s*([{};:,])\s*/g,`$1`).replace(/;}/g,`}`).replace(/;$/,``).trim();return n(e)===n(t)}const Me=[`theme`,`light`,`dark`];function Ne(e,{theme:t}={}){let n=r.parse(e),i={};for(let e of Me){let r={};pe(n,e,t)?.each(e=>{e.type===`decl`&&e.prop.startsWith(`--`)&&(r[e.prop.slice(2)]=e.value)}),Object.keys(r).length>0&&(i[e]=r)}if(i.theme){let{theme:e={}}=ue({light:i.light,dark:i.dark});for(let[t,n]of Object.entries(e))i.theme[t]===n&&delete i.theme[t];Object.keys(i.theme).length===0&&delete i.theme}return i}function Pe(e){return e.params.trim().replace(/^url\((.*)\)/,`$1`).split(/\s/)[0]?.replace(/^["']|["']$/g,``)}const Fe=(e,t)=>e!==void 0&&e.replace(/^\.\//,``)===t.replace(/^\.\//,``);function Ie(e){return e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`)}function Le(e,t){let n=r.parse(e),i=Ie(n);if(i.some(e=>Fe(Pe(e),t)))return e;let a=r.atRule({name:`import`,params:`"${t}"`}),o=i.at(-1);return o?(a.raws={before:`
26
+ `},o.after(a)):(a.raws={before:``},n.prepend(a)),n.toString()}const Re=le,ze=be,Be=xe,Ve=Le;function He(e){let t=[`added`,`updated`,`kept`,`removed`].flatMap(t=>{let n=e.filter(e=>e.action===t).length;return n===0?[]:[`${n} ${t}`]});return t.length===0?void 0:`CSS rules: ${t.join(`, `)}.`}function Ue(e){let t=[[`added`,`added`,`added`],[`updated`,`updated`,`updated`],[`kept`,`kept`,`kept`],[`removed`,`removed`,`removed`]].flatMap(([t,n,r])=>{let i=e.filter(e=>e.action===t).length;return i===0?[]:[`${i} ${i===1?n:r}`]});return t.length===0?void 0:`CSS variables: ${t.join(`, `)}.`}const E=`slabui.json`,D={namespace:`@slabui`,url:`https://slabui.com/r`},We={command:`x-slabui-command`,optOut:`x-slabui-telemetry`},Ge=[`ui`,`component`,`lib`,`hook`,`util`,`style`,`file`,`theme`,`block`,`example`],Ke=[`free`,`pro`],O=`SLABUI_TOKEN`,k=[`claude`,`cursor`,`vscode`,`zed`,`codex`];function qe({status:e,title:t,message:n,close:r=!1}){let i=e===`success`?Ze:Qe;return`<!doctype html>
27
27
  <html lang="en">
28
28
  <head>
29
29
  <meta charset="utf-8">
30
30
  <meta name="viewport" content="width=device-width, initial-scale=1">
31
31
  <meta name="color-scheme" content="light dark">
32
- <title>${We(t)} · SlabUI</title>
33
- <style>${Ge}</style>
32
+ <title>${Je(t)} · SlabUI</title>
33
+ <style>${Ye}</style>
34
34
  </head>
35
35
  <body>
36
36
  <main>
37
- ${Xe}
37
+ ${et}
38
38
  <section class="card" data-status="${e}">
39
39
  <span class="icon">${i}</span>
40
- <h1>${We(t)}</h1>
41
- <p>${We(n)}</p>
40
+ <h1>${Je(t)}</h1>
41
+ <p>${Je(n)}</p>
42
42
  ${r?`<button type="button" onclick="window.close()">Close tab</button>`:``}
43
43
  </section>
44
44
  </main>
45
45
  </body>
46
- </html>`}function We(e){return e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e]??e)}const Ge=`
46
+ </html>`}function Je(e){return e.replace(/[&<>"']/g,e=>({"&":`&amp;`,"<":`&lt;`,">":`&gt;`,'"':`&quot;`,"'":`&#39;`})[e]??e)}const Ye=`
47
47
  :root {
48
48
  --background: oklch(0.985 0 0);
49
49
  --foreground: oklch(0.145 0 0);
@@ -132,22 +132,22 @@ button {
132
132
  }
133
133
  button:hover { opacity: 0.9; }
134
134
  button:focus-visible { outline: 2.5px solid var(--primary); outline-offset: 2px; }
135
- `,Ke=e=>`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,qe=Ke(`<path d="M20 6 9 17l-5-5"/>`),Je=Ke(`<path d="M18 6 6 18M6 6l12 12"/>`),Ye=`x="-30" y="-30" width="60" height="60" rx="12"`,Xe=`<svg class="logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 288 80" fill="none" role="img" aria-label="SlabUI">
135
+ `,Xe=e=>`<svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.5" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true">${e}</svg>`,Ze=Xe(`<path d="M20 6 9 17l-5-5"/>`),Qe=Xe(`<path d="M18 6 6 18M6 6l12 12"/>`),$e=`x="-30" y="-30" width="60" height="60" rx="12"`,et=`<svg class="logo" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 288 80" fill="none" role="img" aria-label="SlabUI">
136
136
  <defs>
137
137
  <linearGradient id="plate" x1="0" y1="0" x2="1" y2="1"><stop offset="0" stop-color="#00c1cc"/><stop offset="1" stop-color="#9296ff"/></linearGradient>
138
138
  <linearGradient id="ui" gradientUnits="userSpaceOnUse" x1="228.77" y1="0" x2="287.52" y2="0"><stop offset="0" stop-color="#00c1cc"/><stop offset="1" stop-color="#9296ff"/></linearGradient>
139
139
  </defs>
140
- <rect ${Ye} transform="translate(40 52) scale(1 0.5299193) rotate(45)" class="ink" fill-opacity=".25"/>
141
- <rect ${Ye} transform="translate(40 40) scale(1 0.5299193) rotate(45)" class="ink" fill-opacity=".6"/>
142
- <rect ${Ye} transform="translate(40 28) scale(1 0.5299193) rotate(45)" fill="url(#plate)"/>
140
+ <rect ${$e} transform="translate(40 52) scale(1 0.5299193) rotate(45)" class="ink" fill-opacity=".25"/>
141
+ <rect ${$e} transform="translate(40 40) scale(1 0.5299193) rotate(45)" class="ink" fill-opacity=".6"/>
142
+ <rect ${$e} 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:En);(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.
145
+ </svg>`;function tt(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 nt(e=tt()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function rt(t,n=tt()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function it(e=tt()){let t=await nt(e)!==void 0;return await l(e,{force:!0}),t}async function at({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 ot(){return f(24).toString(`base64url`)}function st({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 A=class extends Error{name=`SlabUIError`};const j=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),ct=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),M=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),lt=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),ut=p.enum(Ge),dt=p.enum(Ke),ft=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),pt=p.object({registry:p.array(ft).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),mt=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],ht=[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`]}],gt=p.object({path:p.string().min(1),kind:ut,target:p.string().min(1).optional()}).refine(...mt),_t=p.object({path:p.string().min(1),kind:ut,target:p.string().min(1).optional(),content:p.string()}).refine(...mt),vt=p.record(p.string(),p.string()),yt=p.object({theme:vt.optional(),light:vt.optional(),dark:vt.optional()}),bt=p.record(p.string().min(1),p.record(p.string().min(1),p.string().min(1))),xt=p.string().regex(/^[a-z][\w-]*$/),St=p.object({utilities:p.record(xt,p.string().min(1)).optional(),variants:p.record(xt,p.string().min(1)).optional(),base:bt.optional()}),Ct={name:j,kind:ut,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:pt.prefault({}),cssVars:yt.optional()},wt=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...Ct,version:M,files:p.array(_t).default([]),css:St.optional()}).refine(...ht);p.object({...Ct,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:dt.optional(),inferDependencies:p.boolean().optional(),files:p.array(gt).default([]),utilities:p.array(xt).optional(),variants:p.array(xt).optional(),base:bt.optional()}).refine(...ht);const Tt=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),Et=p.object({hash:lt,path:Tt}),Dt=p.object({kind:ut,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:dt.optional(),dependencies:pt.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:M,versions:p.record(M,Et)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Ot=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:ct.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(j,Dt)});let kt;function At(e){kt=e}function jt(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Mt(e,t=kt){let n={"user-agent":`slabui/${re}`};return jt(e)?n[We.optOut]=`off`:t&&(n[We.command]=t),n}const Nt=/* @__PURE__ */ new Map;function Pt(e){return Nt.get(e)}function N(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>nt()}={}){let a=e.url.replace(/\/+$/,``),o={...Mt(n,r),...It(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:Lt(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new A(`"${t}" is a Pro item. Run "slabui login" or set ${O} 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 A(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new A(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${O}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new A(`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 A(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new A(`Not found: ${n}.`);if(!a.ok)throw new A(`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 A(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new A(`${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),Ot,Ft);return Nt.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 A(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new A(`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(Rt(s)!==i.hash)throw new A(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,wt);if(d.name!==t||d.version!==n)throw new A(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function Ft(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 A(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new A(`${e} uses format ${r}, which is no longer supported. ${n}`)}function It(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Lt(n,`the "${e}" header`,t)]))}function Lt(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 A(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function Rt(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function P(t,n){let r=e=>new A(`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(!zt(i,o))throw r(`it leaves the project root`);let s=await Bt(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(!zt(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function zt(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function Bt(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const Vt=p.object({version:M,files:p.array(p.string().min(1))}),Ht=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(j,Vt).default({})}),Ut=[`tsconfig.json`,`jsconfig.json`],Wt=[`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 F(e){return i(e).then(()=>!0,()=>!1)}async function I(t){for(let n of Ut){let r=e.join(t,n);if(await F(r))try{return{path:r,config:_(r)}}catch(e){throw new A(`Could not read ${n}: ${e.message}`)}}throw new A(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function L(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 R(t,n,r){if(r===void 0)return;let i=L(t),a=i!==void 0&&r.startsWith(i)?z(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function Gt(t,n,r){let i=qt(r)?e.resolve(n,r):z(t,r);return i===void 0?void 0:e.relative(n,i).split(e.sep).join(`/`)}function z(e,t){return g(e)?.(t)[0]}async function Kt(t){for(let n of Wt)if(await F(e.join(t,n)))return n}async function B(t){let n=e.join(t,E),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new A(`${E} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new A(`${E} is not valid JSON.`)}let a=Ht.safeParse(i);if(!a.success)throw new A(`${E} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function V(t,n){await u(e.join(t,E),`${JSON.stringify(n,null,2)}\n`)}function qt(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Jt(t){return await F(e.join(t,`src`))?`src`:`.`}async function Yt(t,{folder:n}={}){let{path:r}=await I(t),i=e.resolve(t,n??await Jt(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 F(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 H=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],Xt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,Zt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function Qt(t){return e.posix.extname(t)===`.css`}function $t(e,t){return e.replace(Zt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function en(t){return H.includes(e.posix.extname(t))}function tn(e,t){return e.replace(Xt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function nn(e,t){return[e,...H.map(t=>`${e}${t}`),...H.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function rn(t){let n=e.posix.extname(t);return H.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 A(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==D.namespace)throw new A(`"${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(!j.safeParse(r).success)throw new A(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new A(`"${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:D.namespace,url:t.SLABUI_REGISTRY_URL||D.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function an(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 A(`No version of "${W(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const on={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function sn(t,n){if(t.target!==void 0){let r=t.target;return ln((r.startsWith(L(n.tsconfig)??`\0`)?z(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in on))throw new A(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[on[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=qt(r)?e.resolve(n.root,r,i):z(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new A(`Alias "${r}" does not match any "paths" in the tsconfig.`);return ln(a,n)}function cn(t,n,r){let i=L(r.tsconfig),a=i===void 0?void 0:z(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}${rn(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),rn(s)}function ln(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function un(e){return e.kind===`block`||e.kind===`example`}function dn(e,t,n){return un(e)?gn(e,n):new Map(e.files.map(e=>[e.path,sn(e,t)]))}function fn(e,t){return[e,...t.dependencies.registry.map(e=>W(U(e)))]}async function pn(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,dn(await c.item(a.name,s.version),n))}}function mn(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=Qt(e.path);if(!en(e.path)&&!s)return e.content;let c=fn(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 hn(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&&nn(n,new Set(t.keys()));if(o){let e=t.get(o);return s?hn(e,r):cn(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?$t(e.content,l):tn(e.content,l)}function hn(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function gn(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 _n=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function vn(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 yn(t){let n=(await bn(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 _n)if(await F(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function bn(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 xn(e,{npm:t,npmDev:n}){let r=await bn(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=vn(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 Sn(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function Cn(e,t,n,r){if(n.length===0)return;let[i,a]=Sn(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new A(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new A(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function wn(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await xn(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 ${vn(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 yn(e);return await Cn(e,s,a.install,!1),await Cn(e,s,a.installDev,!0),o}async function Tn({refs:e,config:t,createClient:n=e=>N(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})=>En(p,e)))return;let m=G(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new A(`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 A(`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 En(e,t){return t===void 0||x.satisfies(e.item.version,t)}const Dn=`fonts.css`,On=`base.css`,kn=`utilities.css`,An=Mn([`background`,`foreground`,`border`,`input`,`ring`,`primary`,`primary-foreground`,`primary-soft`,`secondary`,`secondary-foreground`,`danger`,`danger-foreground`,`success`,`success-foreground`,`warning`,`warning-foreground`,`radius`,`spacing`,`font-size`,`control-size`,`control-padding`,`control-text`,`panel-spacing`,`panel-footer`,`scrollbar-thumb`]);function jn(e){let t={},n={};for(let[r,i]of Object.entries(e.theme??{}))(_e(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 Mn(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(T.light),...Object.keys(T.dark)]);return{theme:Object.fromEntries(Object.entries(T.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(T.light),dark:r(T.dark)}}const Nn={"primary-soft":`primary`},Pn=(e,t)=>e.replace(/\s+/g,` `).trim()===t?.replace(/\s+/g,` `).trim();function Fn(e,t){if(t===void 0)return e;let n=Ne(t),r=[`light`,`dark`],i={theme:{...e.theme},light:{...e.light},dark:{...e.dark}},a=!1;for(let[e,t]of Object.entries(Nn)){if(!r.some(t=>e in i[t]))continue;let o=T;if(r.some(e=>{let r=n[e]?.[t];return r!==void 0&&!Pn(r,o[e]?.[t])})){for(let n of r)e in i[n]&&(i[n][e]=`var(--${t})`);i.theme[`color-${e}`]=`var(--${e})`,a=!0}}return a?i:e}async function In(t,n,r,{replace:i=!1}={}){let a=await P(t,n),c=await s(a,`utf8`).catch(()=>void 0),l;i&&c!==void 0&&(l=await Ln(t,n,c));let d=i?void 0:c,f=await K(t,n,r,Dn),p=await P(t,f),m=await s(p,`utf8`).catch(()=>void 0),h=d===void 0||m!==void 0,g=Fn(An,d),{globals:_,fonts:v}=jn(g),y=await Re(d??`@import "tailwindcss";
146
+ `,h?_:g);(d===void 0||y.css!==d)&&(await o(e.dirname(a),{recursive:!0}),await u(a,y.css));let b=[...y.changes],x=[];if(h){let e=await Re(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 Fn(t,n,r,Cn,e.css),b.push(f)):e.css!==m&&await u(p,e.css)}return d===void 0&&await Fn(t,n,r,`base.css`,`/* Element styles (*, html, body), imported by the global CSS. The theme
150
+ `,v);b.push(...e.changes),m===void 0?(await Hn(t,n,r,Dn,e.css),x.push(f)):e.css!==m&&await u(p,e.css)}return d===void 0&&await Hn(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 J(t,n,r,wn)),await Fn(t,n,r,`utilities.css`,`/* @utility and @custom-variant, imported by the global CSS. slabui add
184
+ `)&&x.push(await K(t,n,r,On)),await Hn(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 J(t,n,r,Tn)),{created:c===void 0,...l&&{backup:l},changes:y,files:b}}async function An(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 jn(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 Pn(e,t,i,a.warnings);let o=await J(e,t,i,Cn),c=await s(await L(e,o)).then(()=>!0).catch(()=>!1),l=e=>c?Dn(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 Mn(e,t,n,r,i,a){if(t===void 0||r===void 0||r.length===0)return[];let o=On(r,{theme:`aliases`}),s=[],c=await jn(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 Nn(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 Pn(e,t,o,a);let p=[],m=async(r,i,c)=>{await Fn(e,t,o,r,i);let l=await L(e,await J(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(Tn,`/* @utility and @custom-variant, imported by the global CSS. slabui add
195
+ `)&&x.push(await K(t,n,r,kn)),{created:c===void 0,...l&&{backup:l},changes:b,files:x}}async function Ln(e,t,n){for(let r=0;;r++){let i=r===0?`${t}.bak`:`${t}.bak.${r}`,a=await P(e,i);if(!await s(a).then(()=>!0).catch(()=>!1))return await u(a,n),i}}async function Rn(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 Vn(e,t,i,a.warnings);let o=await K(e,t,i,Dn),c=await s(await P(e,o)).then(()=>!0).catch(()=>!1),l=e=>c?jn(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 P(e,r),l=await s(c,`utf8`),m=await Re(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 zn(e,t,n,r,i,a){if(t===void 0||r===void 0||r.length===0)return[];let o=await P(e,t).then(e=>s(e,`utf8`)).catch(()=>void 0),c=Fn(Mn(r,{theme:`aliases`}),o),l=[],u=await Rn(e,t,n,c,{overwrite:!1,warnings:l,styles:a});return i.push(...l.filter(e=>!e.includes(`custom value`))),u.filter(({action:e})=>e===`added`)}async function Bn(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 Vn(e,t,o,a);let p=[],m=async(r,i,c)=>{await Hn(e,t,o,r,i);let l=await P(e,await K(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(kn,`/* @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(wn,`/* Element styles (*, html, body), imported by the global CSS. The theme
197
+ `,e=>ze(e,r,c)),f&&await m(On,`/* 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 Pn(e,t,n,r){let i=await L(e,t),a=await s(i,`utf8`).catch(()=>void 0);return a===void 0?(await kn(e,t,n),r.push(`${t} did not exist; it was created with the default template.`),s(i,`utf8`)):a}async function J(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 Fn(t,n,r,i,a){let c=await J(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 U(t),f=await z(t),p={root:t,aliases:d.aliases,tsconfig:f,css:V(f,t,d.css)},m=Bt(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 xn({refs:n,config:d,createClient:g}),y=[...v.warnings],b=v.items.filter(({item:e})=>on(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,sn(t,p,x));await ln(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=[],T=[],te=[];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=un(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;T.push(...await Mn(t,p.css,n,e,y,m))}i.cssVars!==void 0&&T.push(...await jn(t,p.css,n,i.cssVars,{overwrite:r,warnings:y,styles:m})),i.css!==void 0&&te.push(...await Nn(t,p.css,n,i.css,{overwrite:r,warnings:y,styles:m}));let c=[...s.values()];on(i)||(d.items[n]={version:i.version,files:c}),ee.push({key:n,version:i.version,files:c,block:on(i)})}await Ht(t,d);let ne=await bn(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:ne,cssChanges:T,ruleChanges:te,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:en(n,e)};if(r)return{version:e.latest};let i=en({...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=G(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=q(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,sn(e,a)]]);await ln([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(un(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 U(e),o=await z(e),s={root:e,aliases:a.aliases,tsconfig:o,css:V(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`))?U(t):void 0}async function Zn({root:e,term:t,type:n,createClient:r=Yn}){let i=q((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=G(t),a=q(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,en(i,s)),l=K(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await z(e)};u=c.files.map(e=>{try{return nn(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(`
200
+ `,e=>Be(e,r.base,c)),p}async function Vn(e,t,n,r){let i=await P(e,t),a=await s(i,`utf8`).catch(()=>void 0);return a===void 0?(await In(e,t,n),r.push(`${t} did not exist; it was created with the default template.`),s(i,`utf8`)):a}async function K(t,n,r,i){let a=e.posix.join(e.posix.dirname(q(n)),i);if(r===void 0)return a;for(let n of[a,e.posix.join(q(r),i)])if(await s(await P(t,n)).then(()=>!0).catch(()=>!1))return n;return e.posix.join(q(r),`core`,i)}async function Hn(t,n,r,i,a){let c=await K(t,n,r,i),l=await P(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 P(t,n),p=await s(f,`utf8`),m=Ve(p,Un(n,c));return m!==p&&await u(f,m),!d}function Un(t,n){let r=e.posix.relative(e.posix.dirname(q(t)),q(n));return r.startsWith(`.`)?r:`./${r}`}const q=e=>e.replaceAll(`\\`,`/`),J=`theme-default`;async function Wn({root:e,createClient:t=e=>N(e)}){let n=await B(e),r=n.items[J];if(r!==void 0)return{status:`installed`,version:r.version};let i,a;try{let e=t(G(n.token)),r=(await e.index()).items[J];if(r===void 0)return{status:`missing`};i=r.latest,a=(await e.item(J,i)).cssVars}catch{return{status:`offline`}}return Gn(a,T)?(n.items[J]={version:i,files:[]},await V(e,n),{status:`registered`,version:i}):{status:`different`,latest:i}}function Gn(e,t){return[`theme`,`light`,`dark`].every(n=>{let r=e?.[n]??{},i=t[n]??{},a=Object.keys(r);return a.length===Object.keys(i).length&&a.every(e=>r[e]===i[e])})}async function Kn({root:t,refs:n,overwrite:r=!1,skipInstall:i=!1,confirm:a,path:s,askPath:c,createClient:l=e=>N(e)}){let d=await B(t),f=await I(t),p={root:t,aliases:d.aliases,tsconfig:f,css:R(f,t,d.css)},m=Gt(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).every(e=>e===J),v=await Tn({refs:n,config:d,createClient:g}),y=[...v.warnings],b=v.items.filter(({item:e})=>un(e)),x=s;if(b.length>0&&x===void 0){let e=b.map(({key:e})=>e);if(c===void 0)throw new A(`${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,dn(t,p,x));await pn(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 P(t,r),await F(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 A(`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=mn(r,{key:n,item:i,destination:a,destinations:S,context:p,warnings:y}),l=await P(t,a);await o(e.dirname(l),{recursive:!0}),await u(l,c)}if(a.namespace===D.namespace){let e=(await g(a).index()).items[i.name]?.tokens;te.push(...await zn(t,p.css,n,e,y,m))}i.cssVars!==void 0&&te.push(...await Rn(t,p.css,n,i.cssVars,{overwrite:r,warnings:y,styles:m})),i.css!==void 0&&ne.push(...await Bn(t,p.css,n,i.css,{overwrite:r,warnings:y,styles:m}));let c=[...s.values()];un(i)||(d.items[n]={version:i.version,files:c}),ee.push({key:n,version:i.version,files:c,block:un(i)})}await V(t,d);let re=await wn(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}),ie=[],ae=v.items[0]?.registry;if(_&&ae!==void 0){let e=(await g(ae).index()).license;e!==void 0&&ie.push({namespace:ae.namespace,url:e})}return{added:ee,installed:v.installed,packages:re,cssChanges:te,ruleChanges:ne,licenses:ie,warnings:y}}function Y(e){return!e&&!!(process.stdin.isTTY&&process.stdout.isTTY)}function qn(e){if(C.isCancel(e))throw C.cancel(`Cancelled.`),new A(`Operation cancelled.`);return e}async function X(e,t=``){return qn(await C.text({message:e,initialValue:t}))}async function Z(e,t=!0){return qn(await C.confirm({message:e,initialValue:t}))}async function Jn(e,t){return qn(await C.select({message:e,options:t}))}async function Yn(e,t,n=[]){return qn(await C.multiselect({message:e,options:t,initialValues:n,required:!0}))}const Xn=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=Y(n.yes),i=await Kn({root:e.resolve(n.cwd),refs:t,overwrite:n.overwrite,skipInstall:n.skipInstall,path:n.path,confirm:r?Z:void 0,askPath:r?e=>X(`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=Ue(i.cssChanges);a&&console.log(a);let o=He(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 Zn(e,t,n,r=!1){if(n.range!==void 0)return{version:an(n,e)};if(r)return{version:e.latest};let i=an({...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 Qn({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 A(`"${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 A(`Item "${c.name}" no longer exists in the "${d.namespace}" registry.`);let m=Zn(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,dn(e,a)]]);await pn([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,$n(mn(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($n).catch(()=>void 0);return{destination:t,base:y.get(t),remote:b.get(t),local:n}})),newerMajor:m.newerMajor,warnings:_}}function $n(e){return e.replace(/\r\n/g,`
202
+ `)}async function er({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>N(e)}){let a=await B(e),o=await I(e),s={root:e,aliases:a.aliases,tsconfig:o,css:R(o,e,a.css)},[c,l]=tr(t),u=await Qn({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 tr(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}const nr=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 er({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 rr(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 ir=e=>N(e);async function ar(t){return await F(e.join(t,`slabui.json`))?B(t):void 0}async function or({root:e,term:t,type:n,createClient:r=ir}){let i=G((await ar(e))?.token);try{let e=await r(i).index();return{results:rr([{namespace:i.namespace,isDefault:!0,index:e}],t,{type:n}),warnings:[]}}catch(e){return{results:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function sr({root:e,ref:t,createClient:n=ir}){let r=await ar(e),i=U(t),a=G(r?.token),o=n(a),s=(await o.index()).items[i.name];if(s===void 0)throw new A(`Item "${i.name}" does not exist in the "${a.namespace}" registry.`);let c=await o.item(i.name,an(i,s)),l=W(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await I(e)};u=c.files.map(e=>{try{return sn(e,t)}catch{return e.path}})}return{key:l,registry:a,entry:s,item:c,installed:r?.items[l]?.version,destinations:u}}const cr=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 sr({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 Vt(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(!Ut(t)&&H(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 Ht(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 Wt(n),i=[{value:`src`,label:`./src (@/components → src/components)`},{value:`.`,label:`./ (@/components → components)`}],a=await Gt(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=V(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 kn(n,l,Bt(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=q(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=q(void 0,r.env),a=nt();return ar({root:e,token:await new Promise((e,r)=>{let o=T((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=`Bearer \${${A}}`;function dr(e){return Object.keys(e).some(e=>e.toLowerCase()===`authorization`)?e:{...e,Authorization:ur}}const fr={claude:`.mcp.json`,cursor:`.cursor/mcp.json`,vscode:`.vscode/mcp.json`,zed:`.zed/settings.json`},pr=[[`.mcp.json`,`claude`],[`.claude`,`claude`],[`.cursor`,`cursor`],[`.vscode`,`vscode`],[`.zed`,`zed`],[`.codex`,`codex`]];function mr(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 hr(t){let n=[];for(let[r,i]of pr)!n.includes(i)&&await R(e.join(t,r))&&n.push(i);return n}async function gr({root:e,url:t,createClient:n=e=>I(e)}){let r=q((await U(e)).token),i=r.namespace.slice(1),a=dr(r.headers);if(t!==void 0)return{servers:[{name:i,url:t,headers:a}],warnings:[]};try{let e=(await n(r).index()).mcp;return e===void 0?{servers:[],warnings:[`The "${r.namespace}" registry has no MCP server.`]}:{servers:[{name:i,url:e,headers:a}],warnings:[]}}catch(e){return{servers:[],warnings:[`"${r.namespace}": ${e.message}`]}}}async function _r(t,n,r){if(n===`zed`)return br(t,r);if(n===`codex`)return{snippet:xr(r)};let i=fr[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]=vr(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 vr(e,{url:t,headers:n}){let r=yr(n,e===`claude`?"${$1}":"${env:$1}",e);return{...e!==`cursor`&&{type:`http`},url:t,...Object.keys(r).length>0&&{headers:r}}}function yr(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,r===ur&&n===`claude`?`Bearer \${${A}:-}`:r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,t)]))}async function br(t,n){let r=fr.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){let{name:t,url:n}=e,i=Object.fromEntries(Object.entries(e.headers).filter(([,e])=>e!==ur));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 xr(e){return e.map(({name:e,url:t,headers:n})=>{let r=[`[mcp_servers.${e}]`,`url = ${JSON.stringify(t)}`],i=[],a=[];for(let[e,t]of Object.entries(n)){let n=/^Bearer \$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t),o=/^\$\{([A-Za-z_][A-Za-z0-9_]*)\}$/.exec(t);e.toLowerCase()===`authorization`&&n?r.push(`bearer_token_env_var = ${JSON.stringify(n[1])}`):o?a.push(`${JSON.stringify(e)} = ${JSON.stringify(o[1])}`):i.push(`${JSON.stringify(e)} = ${JSON.stringify(t)}`)}return i.length>0&&r.push(`http_headers = { ${i.join(`, `)} }`),a.length>0&&r.push(`env_http_headers = { ${a.join(`, `)} }`),r.join(`
206
+ `)}`)});async function lr(e){let t=L(await I(e));if(t===void 0)throw new A(`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 ur(e,`${t}styles`)}}async function ur(e,t){let n=await Kt(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function dr({root:t,aliases:n,css:r,force:i=!1}){if(!i&&await F(e.join(t,`slabui.json`)))throw new A(`${E} already exists. Use --force to create it again.`);let a=await I(t);for(let[e,t]of Object.entries(n))if(!qt(t)&&z(a,t)===void 0)throw new A(`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 V(t,o),o}const fr=new t(`init`).description(`Creates ${E} at the project root`).option(`-y, --yes`,`use the detected values without prompting`).option(`-f, --force`,`overwrite an existing ${E}`).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=Y(t.yes);if(r&&C.intro(`slabui init`),L(await I(n))===void 0){if(r&&!await Z(`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 Jt(n),i=[{value:`src`,label:`./src (@/components → src/components)`},{value:`.`,label:`./ (@/components → components)`}],a=await Yt(n,{folder:r?await Jn(`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 pr(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 lr(n),{aliases:a,css:o}=i,s=t.template;r&&(a={components:await X(`Components alias`,a.components),ui:await X(`UI components alias`,a.ui),lib:await X(`Lib alias`,a.lib),hooks:await X(`Hooks alias`,a.hooks),utils:await X(`Utils alias`,a.utils),styles:await X(`Styles alias`,a.styles)},o=await X(`Global CSS file (empty if none)`,i.cssDetected?i.css:(await ur(n,a.styles)).css)||void 0,o&&s&&(s=await Z(`Add the default theme to ${o}? (creates the file if needed)`))),await dr({root:n,aliases:a,css:o,force:t.force}),console.log(`${E} created in ${n}.`);let c=await I(n),l=R(c,n,o);if(l&&s){let t=await F(e.join(n,l))&&(!r||await Z(`${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 In(n,l,Gt(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}).`);let f=await Wn({root:n});f.status===`registered`?console.log(`${J}@${f.version}: registered in ${E} (slabui update keeps the theme up to date).`):(f.status===`different`||f.status===`offline`)&&console.log(`${J}: not registered in ${E} (${f.status===`offline`?`the registry could not be reached`:`this CLI and ${J}@${f.latest} have different themes; update slabui`}). Run "slabui add ${J}" later to let slabui update it.`)}});async function pr(t){for(let n of[`ts`,`mts`,`js`,`mjs`,`cjs`])if(await F(e.join(t,`vite.config.${n}`)))return!0;return!1}async function mr({token:e,fetch:t=globalThis.fetch,env:n=process.env,file:r=tt(n)}){let i=G(void 0,n),a;try{a=await at({registryUrl:i.url,token:e,fetch:t,headers:Mt(n,`login`)})}catch(e){throw e instanceof Error&&e.message.startsWith(`Error 404`)?new A(`${i.url} does not support login.`):new A(e instanceof Error&&e.message.startsWith(`Error `)?e.message:`Could not reach ${i.url}.`)}if(a===null)throw new A(`Invalid token. Check it and try again.`);return await rt(e.trim(),r),{account:a,url:i.url,file:r}}async function hr({root:e,onUrl:t,timeout:n=3e5,...r}){let i=G(void 0,r.env),a=ot();return mr({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(qe(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 A(`Sign-in was cancelled in the browser.`)))}),s=setTimeout(()=>c(()=>r(new A(`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(st({registryUrl:i.url,callback:`http://127.0.0.1:${e}/callback`,state:a,client:`SlabUI CLI`}))})}),...r})}function gr(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 _r=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 A(`Pass the token with --token or set ${O}.`);let{account:r,url:i,file:a}=t.token===void 0?await hr({root:n,onUrl:e=>{console.log(`Opening the browser to sign in. If it does not open, visit:\n ${e}\n`),gr(e)}}):await mr({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}`)}),vr=new t(`logout`).description(`Removes the token saved by slabui login`).action(async()=>{console.log(await it()?`Logged out.`:`No token was saved; nothing to do.`)}),yr=[`local`,`http`],br={command:`npx`,args:[`-y`,`@slabui/mcp@latest`]},xr=`Bearer \${${O}}`;function Sr(e){return Object.keys(e).some(e=>e.toLowerCase()===`authorization`)?e:{...e,Authorization:xr}}const Cr={claude:`.mcp.json`,cursor:`.cursor/mcp.json`,vscode:`.vscode/mcp.json`,zed:`.zed/settings.json`},wr=[[`.mcp.json`,`claude`],[`.claude`,`claude`],[`.cursor`,`cursor`],[`.vscode`,`vscode`],[`.zed`,`zed`],[`.codex`,`codex`]];function Tr(e){let t=[];for(let n of e.flatMap(e=>e.split(`,`))){let e=n.trim();if(e!==``){if(!k.includes(e))throw new A(`Unknown client "${e}" (${k.join(`, `)}).`);t.includes(e)||t.push(e)}}return t}async function Er(t){let n=[];for(let[r,i]of wr)!n.includes(i)&&await F(e.join(t,r))&&n.push(i);return n}async function Dr({root:e,url:t,transport:n=t===void 0?`local`:`http`,createClient:r=e=>N(e)}){let i=G((await B(e)).token),a=i.namespace.slice(1);if(n===`local`){if(t!==void 0)throw new A(`--url is for the remote server; use it with --transport http.`);return{servers:[{name:a,...br}],warnings:[]}}let o=Sr(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 Or(t,n,r){if(n===`zed`)return jr(t,r);if(n===`codex`)return{snippet:Mr(r)};let i=Cr[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 A(`${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]=kr(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 kr(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=Ar(r,e===`claude`?"${$1}":"${env:$1}",e);return{...e!==`cursor`&&{type:`http`},url:n,...Object.keys(i).length>0&&{headers:i}}}function Ar(e,t,n){return Object.fromEntries(Object.entries(e).map(([e,r])=>[e,r===xr&&n===`claude`?`Bearer \${${O}:-}`:r.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,t)]))}async function jr(t,n){let r=Cr.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 A(`${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!==xr));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 Mr(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 Sr={claude:`CLAUDE.md`,cursor:`.cursor/rules/slabui.mdc`,vscode:`.github/copilot-instructions.md`,zed:`AGENTS.md`,codex:`AGENTS.md`},Cr=`<!-- slabui:start -->`,wr=`<!-- slabui:end -->`;function Tr(e){return Sr[e]}function Er(e){let t=/* @__PURE__ */ new Set;return e.filter(e=>!t.has(Sr[e])&&(t.add(Sr[e]),!0))}function Dr(e){return`## UI registry (slabui)
213
+ `)}const Q={claude:`CLAUDE.md`,cursor:`.cursor/rules/slabui.mdc`,vscode:`.github/copilot-instructions.md`,zed:`AGENTS.md`,codex:`AGENTS.md`},Nr=`<!-- slabui:start -->`,Pr=`<!-- slabui:end -->`;function Fr(e){return Q[e]}function Ir(e){let t=/* @__PURE__ */ new Set;return e.filter(e=>!t.has(Q[e])&&(t.add(Q[e]),!0))}function Lr(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(({name:e,url:t})=>`MCP server: \`${e}\` (${t}).`).join(`
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 \`pro\` need a SlabUI Pro subscription: \`slabui login\` for the
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 Or(t,n,r){let i=Sr[n],a=e.join(t,i),c=Dr(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=`${Cr}\n${c}${wr}\n`,t=await s(a,`utf8`).catch(()=>void 0),n=t?.indexOf(Cr)??-1,r=t?.indexOf(wr,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 kr={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)`},Ar=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(`--url <url>`,`MCP URL for the default registry (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=mr(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 hr(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:`${kr[t]}${e.includes(t)?` (detected)`:``}`})),e)}let{servers:i,warnings:a}=await gr({root:n,url:t.url});for(let e of a)console.warn(`warning: ${e}`);if(i.length===0)throw new M(`The SlabUI registry has no MCP server.`);for(let e of r){let t=await _r(n,e,i);for(let e of t.warnings??[])console.warn(`warning: ${e}`);t.file&&console.log(`${t.file}: ${i.map(({name:e,url:t})=>`${e} → ${t}`).join(`, `)}`),t.snippet&&console.log(t.snippet)}let o=Er(r);if(t.instructions??(!X(t.yes)||await Q(`Add instructions for the agent to ${o.map(Tr).join(`, `)}?`)))for(let e of o){let{file:t}=await Or(n,e,i);console.log(`${t}: instructions for the agent`)}}),jr=new t(`mcp`).description(`Integration with editors and agents through MCP`).addCommand(Ar);async function Mr({root:e,refs:t=[],createClient:n=e=>I(e)}){let r=await U(e),i=t.length>0?[...new Set(t.map(e=>K(G(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?[]:Nr(r,i,await n(q(r.token)).index())}function Nr(e,t,n){return t.flatMap(t=>{let r=G(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 Pr=[`Item`,`Current`,`Wanted`,`Latest`,`Registry`],Fr=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 Mr({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(Ir(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 Ir(e){let t=[[...Pr],...e.map(({key:e,current:t,wanted:n,latest:r,registry:i})=>[e,t,n??``,r??``,i])],n=Pr.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 Lr=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}`)}}),Rr={a:`local`,o:`base`,b:`remote`};async function zr({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 U(e),l=await z(e),u={root:e,aliases:c.aliases,tsconfig:l,css:V(l,e,c.css)},d=Bt(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 Br(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 jn(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 Mn(e,u.css,s.key,t,m.warnings,d))}(f.css!==void 0||l.css!==void 0)&&m.ruleChanges.push(...await Nn(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=G(e),n=K(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 Ht(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 bn(e,{npm:v,npmDev:y},{confirm:a,skipInstall:i,warnings:m.warnings})),m}async function Br({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=te(i.split(`
237
+ `}async function Rr(t,n,r){let i=Q[n],a=e.join(t,i),c=Lr(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=`${Nr}\n${c}${Pr}\n`,t=await s(a,`utf8`).catch(()=>void 0),n=t?.indexOf(Nr)??-1,r=t?.indexOf(Pr,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 zr={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)`},Br=new t(`init`).description(`Adds the SlabUI MCP server to an editor or agent`).option(`--client <clients>`,`editors or agents, repeated or comma-separated (${k.join(`, `)})`,(e,t=[])=>[...t,e]).option(`--transport <transport>`,`how the editor reaches the server (${yr.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=Tr(t.client??[]);if(r.length===0){if(!Y(t.yes))throw new A(`Pass the clients with --client (${k.join(`, `)}), e.g. --client claude,cursor.`);let e=await Er(n);r=await Yn(`Which editors or agents should get the MCP servers?`,[...e,...k.filter(t=>!e.includes(t))].map(t=>({value:t,label:`${zr[t]}${e.includes(t)?` (detected)`:``}`})),e)}let i=t.transport;if(i!==void 0&&!yr.includes(i))throw new A(`Unknown transport "${i}" (${yr.join(`, `)}).`);t.url===void 0?Y(t.yes)?i===void 0&&(i=await Jn(`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 Dr({root:n,url:t.url,transport:i});for(let e of o)console.warn(`warning: ${e}`);if(a.length===0)throw new A(`The SlabUI registry has no MCP server.`);for(let e of r){let t=await Or(n,e,a);for(let e of t.warnings??[])console.warn(`warning: ${e}`);t.file&&console.log(`${t.file}: ${a.map(Hr).join(`, `)}`),t.snippet&&console.log(t.snippet)}let s=Ir(r);if(t.instructions??(!Y(t.yes)||await Z(`Add instructions for the agent to ${s.map(Fr).join(`, `)}?`)))for(let e of s){let{file:t}=await Rr(n,e,a);console.log(`${t}: instructions for the agent`)}}),Vr=new t(`mcp`).description(`Integration with editors and agents through MCP`).addCommand(Br);function Hr(e){return e.command===void 0?`${e.name} → ${e.url}`:`${e.name} → ${[e.command,...e.args].join(` `)}`}async function Ur({root:e,refs:t=[],createClient:n=e=>N(e)}){let r=await B(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 A(`"${e}" is not installed. Blocks and examples are not tracked in ${E}.`);return i.length===0?[]:Wr(r,i,await n(G(r.token)).index())}function Wr(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??D.namespace,current:a,status:`missing`}];let s=Zn(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??D.namespace,current:a,wanted:s,latest:c,status:l}]})}const Gr=[`Item`,`Current`,`Wanted`,`Latest`,`Registry`],Kr=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 Ur({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(qr(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 qr(e){let t=[[...Gr],...e.map(({key:e,current:t,wanted:n,latest:r,registry:i})=>[e,t,n??``,r??``,i])],n=Gr.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 Jr=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(Ge)).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 or({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}`)}}),Yr={a:`local`,o:`base`,b:`remote`};async function Xr({root:e,refs:t,major:n=!1,overwrite:r=!1,skipInstall:i=!1,confirm:a,resolveConflict:o,createClient:s=e=>N(e)}){let c=await B(e),l=await I(e),u={root:e,aliases:c.aliases,tsconfig:l,css:R(l,e,c.css)},d=Gt(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=>tr(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 Qn({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 Zr(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 Rn(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===D.namespace){let t=(await p(s.registry).index()).items[f.name]?.tokens;m.cssChanges.push(...await zn(e,u.css,s.key,t,m.warnings,d))}(f.css!==void 0||l.css!==void 0)&&m.ruleChanges.push(...await Bn(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 V(e,c),_.size>0){let t=await Kn({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 wn(e,{npm:v,npmDev:y},{confirm:a,skipInstall:i,warnings:m.warnings})),m}async function Zr({destination:t,base:n,remote:r,local:i},{root:a,overwrite:s,confirm:c,resolveConflict:d,warnings:f}){let p=await P(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:Rr});if(!h.conflict)return await m(h.result.join(`
241
+ `),{label:Yr});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 Vr={unchanged:`unchanged`,updated:`updated`,merged:`merged with local changes`,conflict:`CONFLICT (markers in the file)`,added:`created`,removed:`removed`,kept:`kept`},Hr=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 zr({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}: ${Vr[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)}),Ur=`slabui`,Wr=`https://registry.npmjs.org/-/package/${Ur}/dist-tags`,Gr=864e5,Kr={pnpm:`pnpm add -D`,npm:`npm install -D`,yarn:`yarn add -D`,bun:`bun add -d`};function qr({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 Jr(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 Yr(e){try{return JSON.parse(await s(e,`utf8`))}catch{return{}}}async function Xr(t,n){try{let r=await Yr(t);n(r),await o(e.dirname(t),{recursive:!0}),await u(t,`${JSON.stringify(r)}\n`)}catch{}}async function Zr({file:e,fetch:t=globalThis.fetch,now:n=Date.now(),signal:r}){let i=(await Yr(e)).cli;if(i&&n-i.checkedAt<Gr)return i.latest;let a;try{let e=await t(Wr,{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 Xr(e,e=>{e.cli={checkedAt:n,latest:a}}),a}function Qr(e,t,n){if(t!==void 0&&x.gt(t,e))return`Update available: slabui ${e} → ${t}\nRun: ${Kr[n]??Kr.npm} ${Ur}@latest`}async function $r({root:t,file:n,now:r=Date.now(),indexOf:i=kt}){if(!await R(e.join(t,`slabui.json`)))return;let a=(await Yr(n)).projects?.[t];if(a!==void 0&&r-a<Gr)return;let o=await U(t),s=i(q().namespace);if(s===void 0)return;let c=Nr(o,Object.keys(o.items),s).filter(e=>e.status===`outdated`).length;if(c!==0)return await Xr(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 ei=/* @__PURE__ */ new Set([`add`,`info`,`search`]),ti=Date.now(),ni=qr(),ri=Jr(),ii=new AbortController,ai=ni?Zr({file:ri,signal:ii.signal}).catch(()=>void 0):void 0;let $;const oi=new t(`slabui`).description(re).version(ne,`-v, --version`).addCommand(rr).addCommand(Vn).addCommand(Hr).addCommand(Fr).addCommand(qn).addCommand(Lr).addCommand($n).addCommand(cr).addCommand(lr).addCommand(jr).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 oi.parseAsync()}catch(e){console.error(e instanceof M?e.message:e),process.exitCode=1}ni&&await si().catch(()=>{});async function si(){let e=[];if($&&ei.has($.name)){let t=await $r({root:$.root,file:ri});t&&e.push(t)}let t=Math.max(0,ti+1e3-Date.now()),n,r=await Promise.race([ai,new Promise(e=>{n=setTimeout(()=>e(void 0),t)})]);clearTimeout(n),ii.abort();let i=Qr(ne,r,await hn($?.root??process.cwd()));i&&e.push(i),e.length>0&&console.error(`\n${e.join(`
243
+ `)),`conflict`)}const Qr={unchanged:`unchanged`,updated:`updated`,merged:`merged with local changes`,conflict:`CONFLICT (markers in the file)`,added:`created`,removed:`removed`,kept:`kept`},$r=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=Y(n.yes),i=await Xr({root:e.resolve(n.cwd),refs:t,major:n.major,overwrite:n.overwrite,skipInstall:n.skipInstall,confirm:r?Z:void 0,resolveConflict:r?e=>Jn(`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}: ${Qr[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=Ue(i.cssChanges);a&&console.log(a);let o=He(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)}),ei=`slabui`,ti=`https://registry.npmjs.org/-/package/${ei}/dist-tags`,ni=864e5,ri={pnpm:`pnpm add -D`,npm:`npm install -D`,yarn:`yarn add -D`,bun:`bun add -d`};function ii({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 ai(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 oi(e){try{return JSON.parse(await s(e,`utf8`))}catch{return{}}}async function si(t,n){try{let r=await oi(t);n(r),await o(e.dirname(t),{recursive:!0}),await u(t,`${JSON.stringify(r)}\n`)}catch{}}async function ci({file:e,fetch:t=globalThis.fetch,now:n=Date.now(),signal:r}){let i=(await oi(e)).cli;if(i&&n-i.checkedAt<ni)return i.latest;let a;try{let e=await t(ti,{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 si(e,e=>{e.cli={checkedAt:n,latest:a}}),a}function li(e,t,n){if(t!==void 0&&x.gt(t,e))return`Update available: slabui ${e} → ${t}\nRun: ${ri[n]??ri.npm} ${ei}@latest`}async function ui({root:t,file:n,now:r=Date.now(),indexOf:i=Pt}){if(!await F(e.join(t,`slabui.json`)))return;let a=(await oi(n)).projects?.[t];if(a!==void 0&&r-a<ni)return;let o=await B(t),s=i(G().namespace);if(s===void 0)return;let c=Wr(o,Object.keys(o.items),s).filter(e=>e.status===`outdated`).length;if(c!==0)return await si(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 di=/* @__PURE__ */ new Set([`add`,`info`,`search`]),fi=Date.now(),pi=ii(),mi=ai(),hi=new AbortController,gi=pi?ci({file:mi,signal:hi.signal}).catch(()=>void 0):void 0;let $;const _i=new t(`slabui`).description(ie).version(re,`-v, --version`).addCommand(fr).addCommand(Xn).addCommand($r).addCommand(Kr).addCommand(nr).addCommand(Jr).addCommand(cr).addCommand(_r).addCommand(vr).addCommand(Vr).hook(`preAction`,(e,t)=>{At(`${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 _i.parseAsync()}catch(e){console.error(e instanceof A?e.message:e),process.exitCode=1}pi&&await vi().catch(()=>{});async function vi(){let e=[];if($&&di.has($.name)){let t=await ui({root:$.root,file:mi});t&&e.push(t)}let t=Math.max(0,fi+1e3-Date.now()),n,r=await Promise.race([gi,new Promise(e=>{n=setTimeout(()=>e(void 0),t)})]);clearTimeout(n),hi.abort();let i=li(re,r,await yn($?.root??process.cwd()));i&&e.push(i),e.length>0&&console.error(`\n${e.join(`
245
245
 
246
246
  `)}`)}export{};