@slabui/cli 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +24 -0
- package/dist/cli.mjs +139 -20
- package/dist/index.d.mts +4 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +137 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,29 @@
|
|
|
1
1
|
# @slabui/cli
|
|
2
2
|
|
|
3
|
+
## 0.4.1
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#109](https://github.com/slabui/ui/pull/109) [`60cabf6`](https://github.com/slabui/ui/commit/60cabf68bbc878617a8e3bd2474de57f535e55ad) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - The page shown after signing in from the theme editor or `slabui login` now uses the SlabUI look (logo, theme colors, light and dark), in English.
|
|
8
|
+
|
|
9
|
+
## 0.4.0
|
|
10
|
+
|
|
11
|
+
### Minor Changes
|
|
12
|
+
|
|
13
|
+
- [#94](https://github.com/slabui/ui/pull/94) [`6e1efeb`](https://github.com/slabui/ui/commit/6e1efebceae84a8aef0387a8507fdf00c93dcacb) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - `slabui init` organiza o CSS assim:
|
|
14
|
+
|
|
15
|
+
- O `fonts.css`, o `base.css` e o `utilities.css` vão para `core/`, na pasta do alias `styles` (`styles/core/utilities.css`). O CSS global importa cada um pelo caminho relativo (`./core/utilities.css` ou, com o `app/globals.css` do Next, `../styles/core/utilities.css`).
|
|
16
|
+
- Um CSS global que já existe (o `app/globals.css` do Next, o `src/index.css` do Vite) é substituído pelo template da SlabUI, e o original fica numa cópia `<arquivo>.bak` ao lado dele. No modo interativo, o `init` pergunta antes; respondendo não, ele só acrescenta as variáveis que faltam, como antes. Com `--yes`, substitui.
|
|
17
|
+
- Sem CSS global, ele é criado em `styles/globals.css`, como antes.
|
|
18
|
+
|
|
19
|
+
Projetos de antes, com esses arquivos ao lado do CSS global ou direto em `styles/`, continuam usando os que já existem.
|
|
20
|
+
|
|
21
|
+
- [#95](https://github.com/slabui/ui/pull/95) [`d099c46`](https://github.com/slabui/ui/commit/d099c4656eb551a3b51c75034adb05873533ce93) Thanks [@andrefelipeschulle](https://github.com/andrefelipeschulle)! - O tema padrão ganha a cor da marca, `brand` e `brand-foreground`, com os mesmos valores iniciais do `primary`. A `brand` é a identidade (logo, destaques); o `primary` é a cor das ações dos componentes.
|
|
22
|
+
|
|
23
|
+
O `slabui init` passa a gravar, além das cores do `base.css`, as que quase todo componente usa, cada uma com o `-foreground`: `brand`, `primary`, `secondary`, `danger`, `success`, `warning` e `inverted`. Com o `danger`, vem também o apelido `--color-destructive`.
|
|
24
|
+
|
|
25
|
+
No editor de tema, a lista de cores ganha o grupo "Brand", antes de "Actions".
|
|
26
|
+
|
|
3
27
|
## 0.3.1
|
|
4
28
|
|
|
5
29
|
### Patch Changes
|
package/dist/cli.mjs
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
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
|
|
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=`
|
|
3
3
|
`,p.append(r.decl({prop:`--${d}`,value:u,raws:{before:`
|
|
4
4
|
`}})),g(`added`)}else me(h,u)?g(`unchanged`):i||f!==void 0&&me(h,f)?(m.value=u,g(`updated`)):(l.push(`--${d} (${e}) has a custom value in the CSS (${h}); kept instead of ${u}.`),g(`kept`))}}return!o&&Object.keys(d.dark??{}).length>0&&pe(s),{css:s.toString(),changes:c,warnings:l}}function ce(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))oe.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function le(e,t){return t?ae(t,e===`dark`):e===`light`?`:root`:`.dark`}const ue=e=>e.replace(/["'\s]/g,``);function de(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&ue(e.selector)===ue(le(t,n)))}function fe(e,t,n){let i=t===`theme`?r.atRule({name:`theme`,params:`inline`}):r.rule({selector:le(t,n)});return i.raws={before:e.nodes.length>0?`
|
|
5
5
|
|
|
6
6
|
`:``,between:` `,after:`
|
|
7
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:`
|
|
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)`,"color-destructive":`var(--danger)`},light:{spacing:`0.25rem`,radius:`0.65rem`,"font-size":`1rem`,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)`,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)`,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:`
|
|
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
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=`
|
|
11
11
|
`,i.after(r);return}if(t){r.raws.before=t.raws.before??``,t.raws.before=`
|
|
12
12
|
|
|
@@ -23,12 +23,131 @@ import e from"node:path";import{Command as t,Option as n}from"commander";import
|
|
|
23
23
|
`,between:` `,after:`
|
|
24
24
|
`,semicolon:!0},n.append(i),n.raws.after=`
|
|
25
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 M(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 Ue(e=M()){try{let{token:t}=JSON.parse(await s(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function We(t,n=M()){await o(e.dirname(n),{recursive:!0}),await u(n,`${JSON.stringify({token:t})}\n`,{mode:384})}async function Ge(e=M()){let t=await Ue(e)!==void 0;return await l(e,{force:!0}),t}async function Ke({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 qe(){return f(24).toString(`base64url`)}function Je({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 N=class extends Error{name=`SlabUIError`};const P=p.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),Ye=p.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),Xe=p.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),Ze=p.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),Qe=p.enum(Ve),$e=p.enum(He),et=p.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),tt=p.object({registry:p.array(et).default([]),npm:p.array(p.string().min(1)).default([]),npmDev:p.array(p.string().min(1)).default([])}),nt=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],rt=[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`]}],it=p.object({path:p.string().min(1),kind:Qe,target:p.string().min(1).optional()}).refine(...nt),at=p.object({path:p.string().min(1),kind:Qe,target:p.string().min(1).optional(),content:p.string()}).refine(...nt),ot=p.record(p.string(),p.string()),st=p.object({theme:ot.optional(),light:ot.optional(),dark:ot.optional()}),ct=p.record(p.string().min(1),p.record(p.string().min(1),p.string().min(1))),lt=p.string().regex(/^[a-z][\w-]*$/),ut=p.object({utilities:p.record(lt,p.string().min(1)).optional(),variants:p.record(lt,p.string().min(1)).optional(),base:ct.optional()}),dt={name:P,kind:Qe,title:p.string().min(1).optional(),description:p.string().min(1),dependencies:tt.prefault({}),cssVars:st.optional()},ft=p.object({$schema:p.string().optional(),schemaVersion:p.literal(1),...dt,version:Xe,files:p.array(at).default([]),css:ut.optional()}).refine(...rt);p.object({...dt,categories:p.array(p.string().min(1)).optional(),keywords:p.array(p.string().min(1)).optional(),docs:p.url().optional(),access:$e.optional(),inferDependencies:p.boolean().optional(),files:p.array(it).default([]),utilities:p.array(lt).optional(),variants:p.array(lt).optional(),base:ct.optional()}).refine(...rt);const pt=p.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),mt=p.object({hash:Ze,path:pt}),ht=p.object({kind:Qe,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:$e.optional(),dependencies:tt.prefault({}),tokens:p.array(p.string().min(1)).optional(),latest:Xe,versions:p.record(Xe,mt)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),gt=p.object({$schema:p.string().optional(),schemaVersion:p.literal(2),namespace:Ye.optional(),homepage:p.url().optional(),mcp:p.url().optional(),license:p.url().optional(),items:p.record(P,ht)});let _t;function vt(e){_t=e}function yt(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function bt(e,t=_t){let n={"user-agent":`slabui/${E}`};return yt(e)?n[Be.optOut]=`off`:t&&(n[Be.command]=t),n}const xt=/* @__PURE__ */ new Map;function St(e){return xt.get(e)}function F(e,{fetch:t=globalThis.fetch,env:n=process.env,command:r,savedToken:i=()=>Ue()}={}){let a=e.url.replace(/\/+$/,``),o={...bt(n,r),...wt(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:Tt(e.token,`"token" in slabui.json`,n))||n.SLABUI_TOKEN||await i();if(!a)throw new N(`"${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 N(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new N(`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 N(`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 N(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new N(`Not found: ${n}.`);if(!a.ok)throw new N(`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 N(`${e} is not valid JSON.`)}r?.(e,i);let a=n.safeParse(i);if(!a.success)throw new N(`${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),gt,Ct);return xt.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 N(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new N(`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(Et(s)!==i.hash)throw new N(`${o} does not match the hash in the index. The file may have been changed on the server.`);let d=u(o,s,ft);if(d.name!==t||d.version!==n)throw new N(`${o} contains ${d.name}@${d.version}, not ${t}@${n}.`);return d}}}function Ct(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 N(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new N(`${e} uses format ${r}, which is no longer supported. ${n}`)}function wt(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Tt(n,`the "${e}" header`,t)]))}function Tt(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 N(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function Et(e){return`sha256-${d(`sha256`).update(e).digest(`base64`)}`}async function I(t,n){let r=e=>new N(`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(!Dt(i,o))throw r(`it leaves the project root`);let s=await Ot(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(!Dt(l,u))throw r(`it goes through a symbolic link outside the project`);return e.join(u,e.relative(s,o))}function Dt(t,n){let r=e.relative(t,n);return r===``||r!==`..`&&!r.startsWith(`..${e.sep}`)&&!e.isAbsolute(r)}async function Ot(t){let n=t;for(;;)try{return await a(n),n}catch(t){if(t.code!==`ENOENT`)throw t;n=e.dirname(n)}}const kt=p.object({version:Xe,files:p.array(p.string().min(1))}),At=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(P,kt).default({})}),jt=[`tsconfig.json`,`jsconfig.json`],Mt=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function L(e){return i(e).then(()=>!0,()=>!1)}async function R(t){for(let n of jt){let r=e.join(t,n);if(await L(r))try{return{path:r,config:_(r)}}catch(e){throw new N(`Could not read ${n}: ${e.message}`)}}throw new N(`No tsconfig.json or jsconfig.json in ${t}. slabui uses its "paths" to resolve the aliases.`)}function z(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function Nt(t,n,r){if(r===void 0)return;let i=z(t),a=i!==void 0&&r.startsWith(i)?B(t,r):void 0;return a===void 0?r:e.relative(n,a).split(e.sep).join(`/`)}function Pt(t,n,r){let i=Lt(r)?e.resolve(n,r):B(t,r);return i===void 0?void 0:e.relative(n,i).split(e.sep).join(`/`)}function B(e,t){return g(e)?.(t)[0]}async function Ft(t){for(let n of Mt)if(await L(e.join(t,n)))return n}async function V(t){let n=e.join(t,O),r=await s(n,`utf8`).catch(()=>void 0);if(r===void 0)throw new N(`${O} not found in ${t}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new N(`${O} is not valid JSON.`)}let a=At.safeParse(i);if(!a.success)throw new N(`${O} has errors:\n${p.prettifyError(a.error)}`);return a.data}async function It(t,n){await u(e.join(t,O),`${JSON.stringify(n,null,2)}\n`)}function Lt(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Rt(t){return await L(e.join(t,`src`))?`src`:`.`}async function zt(t,{folder:n}={}){let{path:r}=await R(t),i=e.resolve(t,n??await Rt(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 L(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`],Bt=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,Vt=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function Ht(t){return e.posix.extname(t)===`.css`}function Ut(e,t){return e.replace(Vt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Wt(t){return H.includes(e.posix.extname(t))}function Gt(e,t){return e.replace(Bt,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Kt(e,t){return[e,...H.map(t=>`${e}${t}`),...H.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function qt(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 N(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==k.namespace)throw new N(`"${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(!P.safeParse(r).success)throw new N(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||x.validRange(i)===null))throw new N(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function W(e){return e.name}function G(e,t=process.env){return{namespace:k.namespace,url:t.SLABUI_REGISTRY_URL||k.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function Jt(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 N(`No version of "${W(e)}" satisfies "${e.range}". Available: ${x.sort(n).join(`, `)}.`);return r}const Yt={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function Xt(t,n){if(t.target!==void 0){let r=t.target;return Qt((r.startsWith(z(n.tsconfig)??`\0`)?B(n.tsconfig,r):void 0)??e.resolve(n.root,r),n)}if(!(t.kind in Yt))throw new N(`Files with kind "${t.kind}" cannot be installed by add yet (${t.path}).`);let r=n.aliases[Yt[t.kind]],i=t.kind===`style`&&t.path.split(`/`).slice(1).join(`/`)||e.posix.basename(t.path),a=Lt(r)?e.resolve(n.root,r,i):B(n.tsconfig,`${r}/${i}`);if(a===void 0)throw new N(`Alias "${r}" does not match any "paths" in the tsconfig.`);return Qt(a,n)}function Zt(t,n,r){let i=z(r.tsconfig),a=i===void 0?void 0:B(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}${qt(e.relative(a,o).split(e.sep).join(`/`))}`;let s=e.posix.relative(e.posix.dirname(n),t);return s.startsWith(`.`)||(s=`./${s}`),qt(s)}function Qt(t,n){return e.relative(n.root,t).split(e.sep).join(`/`)}function K(e){return e.kind===`block`||e.kind===`example`}function $t(e,t,n){return K(e)?an(e,n):new Map(e.files.map(e=>[e.path,Xt(e,t)]))}function en(e,t){return[e,...t.dependencies.registry.map(e=>W(U(e)))]}async function tn(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,$t(await c.item(a.name,s.version),n))}}function nn(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=Ht(e.path);if(!Wt(e.path)&&!s)return e.content;let c=en(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 rn(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&&Kt(n,new Set(t.keys()));if(o){let e=t.get(o);return s?rn(e,r):Zt(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?Ut(e.content,l):Gt(e.content,l)}function rn(t,n){let r=e.posix.relative(e.posix.dirname(n),t);return r.startsWith(`.`)?r:`./${r}`}function an(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 on=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function sn(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 cn(t){let n=(await ln(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 on)if(await L(e.join(r,t)))return n;let t=e.dirname(r);if(t===r)return`npm`;r=t}}async function ln(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 un(e,{npm:t,npmDev:n}){let r=await ln(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=sn(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 dn(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function fn(e,t,n,r){if(n.length===0)return;let[i,a]=dn(t,n,r);await new Promise((t,n)=>{let r=S(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new N(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new N(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function pn(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await un(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 ${sn(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 cn(e);return await fn(e,s,a.install,!1),await fn(e,s,a.installDev,!0),o}async function mn({refs:e,config:t,createClient:n=e=>F(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})=>hn(p,e)))return;let m=G(t.token),h=l(m),g=(await h.index()).items[e.name];if(g===void 0)throw new N(`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 N(`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 hn(e,t){return t===void 0||x.satisfies(e.item.version,t)}const gn=`fonts.css`,_n=`base.css`,vn=`utilities.css`,yn=xn([`background`,`foreground`,`border`,`input`,`ring`,`radius`,`spacing`,`font-size`,`scrollbar-thumb`]);function bn(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 xn(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 Sn(t,n,r){let i=await I(t,n),a=await s(i,`utf8`).catch(()=>void 0),c=await q(t,n,r,gn),l=await I(t,c),d=await s(l,`utf8`).catch(()=>void 0),f=a===void 0||d!==void 0,{globals:p,fonts:m}=bn(yn),h=await Pe(a??`@import "tailwindcss";
|
|
27
|
-
|
|
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>
|
|
27
|
+
<html lang="en">
|
|
28
|
+
<head>
|
|
29
|
+
<meta charset="utf-8">
|
|
30
|
+
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
31
|
+
<meta name="color-scheme" content="light dark">
|
|
32
|
+
<title>${We(t)} · SlabUI</title>
|
|
33
|
+
<style>${Ge}</style>
|
|
34
|
+
</head>
|
|
35
|
+
<body>
|
|
36
|
+
<main>
|
|
37
|
+
${Xe}
|
|
38
|
+
<section class="card" data-status="${e}">
|
|
39
|
+
<span class="icon">${i}</span>
|
|
40
|
+
<h1>${We(t)}</h1>
|
|
41
|
+
<p>${We(n)}</p>
|
|
42
|
+
${r?`<button type="button" onclick="window.close()">Close tab</button>`:``}
|
|
43
|
+
</section>
|
|
44
|
+
</main>
|
|
45
|
+
</body>
|
|
46
|
+
</html>`}function We(e){return e.replace(/[&<>"']/g,e=>({"&":`&`,"<":`<`,">":`>`,'"':`"`,"'":`'`})[e]??e)}const Ge=`
|
|
47
|
+
:root {
|
|
48
|
+
--background: oklch(0.985 0 0);
|
|
49
|
+
--foreground: oklch(0.145 0 0);
|
|
50
|
+
--card: oklch(1 0 0);
|
|
51
|
+
--muted-foreground: oklch(0.556 0 0);
|
|
52
|
+
--border: oklch(0.922 0 0);
|
|
53
|
+
--primary: oklch(70% 0.1435 227.76);
|
|
54
|
+
--primary-foreground: oklch(0.985 0 0);
|
|
55
|
+
--success: oklch(0.728 0.125 139.6);
|
|
56
|
+
--danger: oklch(0.577 0.245 27.325);
|
|
57
|
+
--logo: #0b0c0e;
|
|
58
|
+
--radius: 0.65rem;
|
|
59
|
+
}
|
|
60
|
+
@media (prefers-color-scheme: dark) {
|
|
61
|
+
:root {
|
|
62
|
+
--background: oklch(0.145 0 0);
|
|
63
|
+
--foreground: oklch(0.985 0 0);
|
|
64
|
+
--card: oklch(0.205 0 0);
|
|
65
|
+
--muted-foreground: oklch(0.708 0 0);
|
|
66
|
+
--border: oklch(1 0 0 / 10%);
|
|
67
|
+
--primary: oklch(66% 0.1435 227.76);
|
|
68
|
+
--danger: oklch(0.704 0.191 22.216);
|
|
69
|
+
--logo: #f4f4f2;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
* { box-sizing: border-box; }
|
|
73
|
+
body {
|
|
74
|
+
margin: 0;
|
|
75
|
+
min-height: 100vh;
|
|
76
|
+
display: grid;
|
|
77
|
+
place-items: center;
|
|
78
|
+
padding: 1.5rem 1rem;
|
|
79
|
+
background: var(--background);
|
|
80
|
+
color: var(--foreground);
|
|
81
|
+
font: 16px/1.5 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif;
|
|
82
|
+
-webkit-font-smoothing: antialiased;
|
|
83
|
+
}
|
|
84
|
+
main {
|
|
85
|
+
width: 100%;
|
|
86
|
+
max-width: 24rem;
|
|
87
|
+
display: grid;
|
|
88
|
+
justify-items: center;
|
|
89
|
+
gap: 1.5rem;
|
|
90
|
+
}
|
|
91
|
+
.logo { height: 1.75rem; width: auto; }
|
|
92
|
+
.logo .ink { fill: var(--logo); }
|
|
93
|
+
.card {
|
|
94
|
+
width: 100%;
|
|
95
|
+
display: grid;
|
|
96
|
+
justify-items: center;
|
|
97
|
+
gap: 0.5rem;
|
|
98
|
+
padding: 2rem 1.5rem;
|
|
99
|
+
text-align: center;
|
|
100
|
+
background: var(--card);
|
|
101
|
+
border: 1px solid var(--border);
|
|
102
|
+
border-radius: calc(var(--radius) * 1.4);
|
|
103
|
+
box-shadow: 0 1px 2px oklch(0 0 0 / 5%);
|
|
104
|
+
}
|
|
105
|
+
.icon {
|
|
106
|
+
--tone: var(--success);
|
|
107
|
+
display: grid;
|
|
108
|
+
place-items: center;
|
|
109
|
+
width: 3rem;
|
|
110
|
+
height: 3rem;
|
|
111
|
+
margin-bottom: 0.5rem;
|
|
112
|
+
border-radius: 999px;
|
|
113
|
+
color: var(--tone);
|
|
114
|
+
background: color-mix(in oklch, var(--tone) 15%, transparent);
|
|
115
|
+
}
|
|
116
|
+
.card[data-status="error"] .icon { --tone: var(--danger); }
|
|
117
|
+
.icon svg { width: 1.5rem; height: 1.5rem; }
|
|
118
|
+
h1 { margin: 0; font-size: 1.25rem; line-height: 1.4; font-weight: 600; }
|
|
119
|
+
p { margin: 0; color: var(--muted-foreground); font-size: 0.875rem; }
|
|
120
|
+
button {
|
|
121
|
+
margin-top: 1rem;
|
|
122
|
+
height: 2.25rem;
|
|
123
|
+
padding: 0 1rem;
|
|
124
|
+
border: 0;
|
|
125
|
+
border-radius: var(--radius);
|
|
126
|
+
background: var(--primary);
|
|
127
|
+
color: var(--primary-foreground);
|
|
128
|
+
font: inherit;
|
|
129
|
+
font-size: 0.875rem;
|
|
130
|
+
font-weight: 500;
|
|
131
|
+
cursor: pointer;
|
|
132
|
+
}
|
|
133
|
+
button:hover { opacity: 0.9; }
|
|
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">
|
|
136
|
+
<defs>
|
|
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
|
+
<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
|
+
</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)"/>
|
|
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
|
+
<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.
|
|
28
147
|
Every text-* class is proportional to --font-size (set in :root in the
|
|
29
148
|
global CSS): change it to make all text larger or smaller. Line heights are
|
|
30
149
|
unitless ratios, so they follow the font size on their own. */
|
|
31
|
-
`,
|
|
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
|
|
32
151
|
variables stay in the global CSS; components add here what they need in
|
|
33
152
|
the whole app. */
|
|
34
153
|
|
|
@@ -62,7 +181,7 @@ import e from"node:path";import{Command as t,Option as n}from"commander";import
|
|
|
62
181
|
text-rendering: optimizeLegibility;
|
|
63
182
|
}
|
|
64
183
|
}
|
|
65
|
-
`)&&
|
|
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
|
|
66
185
|
adds the ones components use; the ones you change are kept as they are. */
|
|
67
186
|
|
|
68
187
|
@utility no-scrollbar {
|
|
@@ -73,24 +192,24 @@ import e from"node:path";import{Command as t,Option as n}from"commander";import
|
|
|
73
192
|
display: none;
|
|
74
193
|
}
|
|
75
194
|
}
|
|
76
|
-
`)&&
|
|
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
|
|
77
196
|
adds the ones components use; the ones you change are kept as they are. */
|
|
78
|
-
`,e=>Fe(e,r,c)),f&&await m(
|
|
197
|
+
`,e=>Fe(e,r,c)),f&&await m(wn,`/* Element styles (*, html, body), imported by the global CSS. The theme
|
|
79
198
|
variables stay in the global CSS; components add here what they need in
|
|
80
199
|
the whole app. */
|
|
81
|
-
`,e=>Ie(e,r.base,c)),p}async function
|
|
82
|
-
`);if(!(a&&await a(`These files already exist and will be overwritten:\n${e}\nContinue?`)))throw new
|
|
83
|
-
`)}async function
|
|
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(`
|
|
84
203
|
`)}`),r.installed||console.log(`
|
|
85
204
|
Not installed in this project.`),console.log(`
|
|
86
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(`
|
|
87
|
-
`)}`)});async function
|
|
88
|
-
`,c=[],l=b(a,c,{allowTrailingComma:!0});if(c.length>0||typeof l!=`object`||!l||Array.isArray(l))throw new
|
|
89
|
-
`)?a:`${a}\n`),{file:r,warnings:d}}function
|
|
206
|
+
`)}`)});async function er(e){let t=B(await z(e));if(t===void 0)throw new M(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await tr(e,`${t}styles`)}}async function tr(e,t){let n=await 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(`
|
|
90
209
|
`)}).join(`
|
|
91
210
|
|
|
92
211
|
`).replace(/^/,`# In ~/.codex/config.toml (or .codex/config.toml in a trusted project):
|
|
93
|
-
`)}const
|
|
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)
|
|
94
213
|
|
|
95
214
|
UI components, blocks and examples in this project come from the versioned
|
|
96
215
|
SlabUI registry, managed by the \`slabui\` CLI. The installed items and their
|
|
@@ -115,13 +234,13 @@ ${e.map(({name:e,url:t})=>`MCP server: \`${e}\` (${t}).`).join(`
|
|
|
115
234
|
CLI, and \`SLABUI_TOKEN\` in the environment for the MCP server.
|
|
116
235
|
- Claude Code: \`slabui add skill\` installs the SlabUI skill
|
|
117
236
|
(\`.claude/skills/slabui\`); \`slabui update skill\` keeps it current.
|
|
118
|
-
`}async function
|
|
119
|
-
`)}const
|
|
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(`
|
|
120
239
|
`),n.split(`
|
|
121
240
|
`),r.split(`
|
|
122
|
-
`),{label:
|
|
241
|
+
`),{label:Rr});if(!h.conflict)return await m(h.result.join(`
|
|
123
242
|
`)),`merged`;let g=d?await d(t):`markers`;return g===`local`?`kept`:g===`remote`?(await m(r),`updated`):(await m(h.result.join(`
|
|
124
|
-
`)),`conflict`)}const
|
|
125
|
-
`)}`),process.exitCode=1)}),
|
|
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(`
|
|
126
245
|
|
|
127
246
|
`)}`)}export{};
|
package/dist/index.d.mts
CHANGED
|
@@ -360,10 +360,13 @@ type Options$2 = {
|
|
|
360
360
|
export declare function planInstall({ refs, config, createClient }: Options$2): Promise<InstallPlan>;
|
|
361
361
|
type TemplateResult = {
|
|
362
362
|
created: boolean;
|
|
363
|
+
backup?: string;
|
|
363
364
|
changes: CssVarChange[];
|
|
364
365
|
files: string[];
|
|
365
366
|
};
|
|
366
|
-
export declare function applyCssTemplate(root: string, file: string, styles?: string
|
|
367
|
+
export declare function applyCssTemplate(root: string, file: string, styles?: string, { replace }?: {
|
|
368
|
+
replace?: boolean;
|
|
369
|
+
}): Promise<TemplateResult>;
|
|
367
370
|
type ConflictResolution = "markers" | "local" | "remote";
|
|
368
371
|
type FileStatus = "unchanged" | "updated" | "merged" | "conflict" | "added" | "removed" | "kept";
|
|
369
372
|
type UpdateOptions = {
|