@slabui/cli 0.0.0-stage → 0.0.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 +14 -0
- package/LICENSE +59 -0
- package/README.md +14 -2
- package/dist/cli.mjs +65 -0
- package/dist/index.d.mts +449 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.mjs +26 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +61 -3
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,449 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { TsConfigResult } from "get-tsconfig";
|
|
3
|
+
declare const itemFileSchema: z.ZodObject<{
|
|
4
|
+
path: z.ZodString;
|
|
5
|
+
kind: z.ZodEnum<{
|
|
6
|
+
block: "block";
|
|
7
|
+
component: "component";
|
|
8
|
+
example: "example";
|
|
9
|
+
file: "file";
|
|
10
|
+
hook: "hook";
|
|
11
|
+
lib: "lib";
|
|
12
|
+
style: "style";
|
|
13
|
+
theme: "theme";
|
|
14
|
+
ui: "ui";
|
|
15
|
+
util: "util";
|
|
16
|
+
}>;
|
|
17
|
+
target: z.ZodOptional<z.ZodString>;
|
|
18
|
+
content: z.ZodString;
|
|
19
|
+
}, z.core.$strip>;
|
|
20
|
+
declare const cssVarsSchema: z.ZodObject<{
|
|
21
|
+
theme: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
22
|
+
light: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
23
|
+
dark: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
24
|
+
}, z.core.$strip>;
|
|
25
|
+
declare const itemSchema: z.ZodObject<{
|
|
26
|
+
name: z.ZodString;
|
|
27
|
+
kind: z.ZodEnum<{
|
|
28
|
+
block: "block";
|
|
29
|
+
component: "component";
|
|
30
|
+
example: "example";
|
|
31
|
+
file: "file";
|
|
32
|
+
hook: "hook";
|
|
33
|
+
lib: "lib";
|
|
34
|
+
style: "style";
|
|
35
|
+
theme: "theme";
|
|
36
|
+
ui: "ui";
|
|
37
|
+
util: "util";
|
|
38
|
+
}>;
|
|
39
|
+
title: z.ZodOptional<z.ZodString>;
|
|
40
|
+
description: z.ZodString;
|
|
41
|
+
dependencies: z.ZodPrefault<z.ZodObject<{
|
|
42
|
+
registry: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
43
|
+
npm: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
44
|
+
npmDev: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
45
|
+
}, z.core.$strip>>;
|
|
46
|
+
cssVars: z.ZodOptional<z.ZodObject<{
|
|
47
|
+
theme: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
48
|
+
light: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
49
|
+
dark: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodString>>;
|
|
50
|
+
}, z.core.$strip>>;
|
|
51
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
52
|
+
schemaVersion: z.ZodLiteral<1>;
|
|
53
|
+
version: z.ZodString;
|
|
54
|
+
files: z.ZodDefault<z.ZodArray<z.ZodObject<{
|
|
55
|
+
path: z.ZodString;
|
|
56
|
+
kind: z.ZodEnum<{
|
|
57
|
+
block: "block";
|
|
58
|
+
component: "component";
|
|
59
|
+
example: "example";
|
|
60
|
+
file: "file";
|
|
61
|
+
hook: "hook";
|
|
62
|
+
lib: "lib";
|
|
63
|
+
style: "style";
|
|
64
|
+
theme: "theme";
|
|
65
|
+
ui: "ui";
|
|
66
|
+
util: "util";
|
|
67
|
+
}>;
|
|
68
|
+
target: z.ZodOptional<z.ZodString>;
|
|
69
|
+
content: z.ZodString;
|
|
70
|
+
}, z.core.$strip>>>;
|
|
71
|
+
}, z.core.$strip>;
|
|
72
|
+
type ItemFile = z.infer<typeof itemFileSchema>;
|
|
73
|
+
type Item = z.infer<typeof itemSchema>;
|
|
74
|
+
type CssVars = z.infer<typeof cssVarsSchema>;
|
|
75
|
+
declare const registryEntrySchema: z.ZodObject<{
|
|
76
|
+
kind: z.ZodEnum<{
|
|
77
|
+
block: "block";
|
|
78
|
+
component: "component";
|
|
79
|
+
example: "example";
|
|
80
|
+
file: "file";
|
|
81
|
+
hook: "hook";
|
|
82
|
+
lib: "lib";
|
|
83
|
+
style: "style";
|
|
84
|
+
theme: "theme";
|
|
85
|
+
ui: "ui";
|
|
86
|
+
util: "util";
|
|
87
|
+
}>;
|
|
88
|
+
title: z.ZodOptional<z.ZodString>;
|
|
89
|
+
description: z.ZodString;
|
|
90
|
+
categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
91
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
92
|
+
docs: z.ZodOptional<z.ZodURL>;
|
|
93
|
+
access: z.ZodOptional<z.ZodEnum<{
|
|
94
|
+
free: "free";
|
|
95
|
+
pro: "pro";
|
|
96
|
+
}>>;
|
|
97
|
+
dependencies: z.ZodPrefault<z.ZodObject<{
|
|
98
|
+
registry: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
99
|
+
npm: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
100
|
+
npmDev: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
101
|
+
}, z.core.$strip>>;
|
|
102
|
+
tokens: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
103
|
+
latest: z.ZodString;
|
|
104
|
+
versions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
105
|
+
hash: z.ZodString;
|
|
106
|
+
path: z.ZodString;
|
|
107
|
+
}, z.core.$strip>>;
|
|
108
|
+
}, z.core.$strip>;
|
|
109
|
+
declare const registrySchema: z.ZodObject<{
|
|
110
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
111
|
+
schemaVersion: z.ZodLiteral<2>;
|
|
112
|
+
namespace: z.ZodOptional<z.ZodString>;
|
|
113
|
+
homepage: z.ZodOptional<z.ZodURL>;
|
|
114
|
+
mcp: z.ZodOptional<z.ZodURL>;
|
|
115
|
+
license: z.ZodOptional<z.ZodURL>;
|
|
116
|
+
items: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
117
|
+
kind: z.ZodEnum<{
|
|
118
|
+
block: "block";
|
|
119
|
+
component: "component";
|
|
120
|
+
example: "example";
|
|
121
|
+
file: "file";
|
|
122
|
+
hook: "hook";
|
|
123
|
+
lib: "lib";
|
|
124
|
+
style: "style";
|
|
125
|
+
theme: "theme";
|
|
126
|
+
ui: "ui";
|
|
127
|
+
util: "util";
|
|
128
|
+
}>;
|
|
129
|
+
title: z.ZodOptional<z.ZodString>;
|
|
130
|
+
description: z.ZodString;
|
|
131
|
+
categories: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
132
|
+
keywords: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
133
|
+
docs: z.ZodOptional<z.ZodURL>;
|
|
134
|
+
access: z.ZodOptional<z.ZodEnum<{
|
|
135
|
+
free: "free";
|
|
136
|
+
pro: "pro";
|
|
137
|
+
}>>;
|
|
138
|
+
dependencies: z.ZodPrefault<z.ZodObject<{
|
|
139
|
+
registry: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
140
|
+
npm: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
141
|
+
npmDev: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
142
|
+
}, z.core.$strip>>;
|
|
143
|
+
tokens: z.ZodOptional<z.ZodArray<z.ZodString>>;
|
|
144
|
+
latest: z.ZodString;
|
|
145
|
+
versions: z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
146
|
+
hash: z.ZodString;
|
|
147
|
+
path: z.ZodString;
|
|
148
|
+
}, z.core.$strip>>;
|
|
149
|
+
}, z.core.$strip>>;
|
|
150
|
+
}, z.core.$strip>;
|
|
151
|
+
type RegistryEntry = z.infer<typeof registryEntrySchema>;
|
|
152
|
+
type Registry = z.infer<typeof registrySchema>;
|
|
153
|
+
declare const dependenciesSchema: z.ZodObject<{
|
|
154
|
+
registry: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
155
|
+
npm: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
156
|
+
npmDev: z.ZodDefault<z.ZodArray<z.ZodString>>;
|
|
157
|
+
}, z.core.$strip>;
|
|
158
|
+
type Dependencies = z.infer<typeof dependenciesSchema>;
|
|
159
|
+
export declare const installedItemSchema: z.ZodObject<{
|
|
160
|
+
version: z.ZodString;
|
|
161
|
+
files: z.ZodArray<z.ZodString>;
|
|
162
|
+
}, z.core.$strip>;
|
|
163
|
+
export declare const configSchema: z.ZodObject<{
|
|
164
|
+
$schema: z.ZodOptional<z.ZodString>;
|
|
165
|
+
token: z.ZodOptional<z.ZodString>;
|
|
166
|
+
css: z.ZodOptional<z.ZodString>;
|
|
167
|
+
aliases: z.ZodObject<{
|
|
168
|
+
components: z.ZodString;
|
|
169
|
+
ui: z.ZodString;
|
|
170
|
+
lib: z.ZodString;
|
|
171
|
+
hooks: z.ZodString;
|
|
172
|
+
utils: z.ZodString;
|
|
173
|
+
styles: z.ZodString;
|
|
174
|
+
}, z.core.$strip>;
|
|
175
|
+
items: z.ZodDefault<z.ZodRecord<z.ZodString, z.ZodObject<{
|
|
176
|
+
version: z.ZodString;
|
|
177
|
+
files: z.ZodArray<z.ZodString>;
|
|
178
|
+
}, z.core.$strip>>>;
|
|
179
|
+
}, z.core.$strip>;
|
|
180
|
+
type InstalledItem = z.infer<typeof installedItemSchema>;
|
|
181
|
+
type Config = z.infer<typeof configSchema>;
|
|
182
|
+
type ItemRef = {
|
|
183
|
+
name: string;
|
|
184
|
+
range?: string;
|
|
185
|
+
};
|
|
186
|
+
type ResolvedRegistry = {
|
|
187
|
+
namespace: string;
|
|
188
|
+
url: string;
|
|
189
|
+
headers: Record<string, string>;
|
|
190
|
+
isDefault: boolean;
|
|
191
|
+
token?: string;
|
|
192
|
+
};
|
|
193
|
+
export declare function parseItemRef(ref: string): ItemRef;
|
|
194
|
+
export declare function itemKey(ref: ItemRef): string;
|
|
195
|
+
export declare function resolveRegistry(token?: Config["token"], env?: Record<string, string | undefined>): ResolvedRegistry;
|
|
196
|
+
export declare function resolveVersion(ref: ItemRef, entry: Pick<RegistryEntry, "latest" | "versions">): string;
|
|
197
|
+
type RegistryClientOptions = {
|
|
198
|
+
fetch?: typeof fetch;
|
|
199
|
+
env?: Record<string, string | undefined>;
|
|
200
|
+
command?: string;
|
|
201
|
+
savedToken?: () => Promise<string | undefined>;
|
|
202
|
+
};
|
|
203
|
+
type RegistryClient = {
|
|
204
|
+
index(): Promise<Registry>;
|
|
205
|
+
item(name: string, version: string): Promise<Item>;
|
|
206
|
+
};
|
|
207
|
+
export declare function createRegistryClient(registry: ResolvedRegistry, { fetch, env, command, savedToken }?: RegistryClientOptions): RegistryClient;
|
|
208
|
+
export declare function expandHeaders(headers: Record<string, string>, env?: Record<string, string | undefined>): Record<string, string>;
|
|
209
|
+
export declare function hash(body: Uint8Array): string;
|
|
210
|
+
export declare const CONFIG_FILE = "slabui.json";
|
|
211
|
+
export declare const DEFAULT_REGISTRY: {
|
|
212
|
+
readonly namespace: "@slabui";
|
|
213
|
+
readonly url: "https://slabui.com/r";
|
|
214
|
+
};
|
|
215
|
+
export declare const SITE_URL = "https://slabui.com";
|
|
216
|
+
export declare const CONFIG_SCHEMA_URL = "https://slabui.com/schema.json";
|
|
217
|
+
export declare const TELEMETRY_HEADERS: {
|
|
218
|
+
readonly command: "x-slabui-command";
|
|
219
|
+
readonly optOut: "x-slabui-telemetry";
|
|
220
|
+
};
|
|
221
|
+
export declare const ITEM_KINDS: readonly ["ui", "component", "lib", "hook", "util", "style", "file", "theme", "block", "example"];
|
|
222
|
+
type ItemKind = (typeof ITEM_KINDS)[number];
|
|
223
|
+
export declare const ITEM_ACCESS: readonly ["free", "pro"];
|
|
224
|
+
type ItemAccess = (typeof ITEM_ACCESS)[number];
|
|
225
|
+
export declare const TOKEN_ENV = "SLABUI_TOKEN";
|
|
226
|
+
export declare const WHOAMI_PATH = "whoami.json";
|
|
227
|
+
export declare const MCP_CLIENTS: readonly ["claude", "cursor", "vscode", "zed", "codex"];
|
|
228
|
+
type McpClient = (typeof MCP_CLIENTS)[number];
|
|
229
|
+
export declare class SlabUIError extends Error {
|
|
230
|
+
name: string;
|
|
231
|
+
}
|
|
232
|
+
type Aliases = Config["aliases"];
|
|
233
|
+
export declare function detectDefaults(root: string): Promise<{
|
|
234
|
+
aliases: Aliases;
|
|
235
|
+
css: string;
|
|
236
|
+
cssDetected: boolean;
|
|
237
|
+
}>;
|
|
238
|
+
export declare function initProject({ root, aliases, css, force }: {
|
|
239
|
+
root: string;
|
|
240
|
+
aliases: Aliases;
|
|
241
|
+
css?: string;
|
|
242
|
+
force?: boolean;
|
|
243
|
+
}): Promise<Config>;
|
|
244
|
+
type Group = "theme" | "light" | "dark";
|
|
245
|
+
type CssVarChange = {
|
|
246
|
+
group: Group;
|
|
247
|
+
name: string;
|
|
248
|
+
action: "added" | "updated" | "kept" | "removed" | "unchanged";
|
|
249
|
+
};
|
|
250
|
+
type AddOptions = {
|
|
251
|
+
root: string;
|
|
252
|
+
refs: string[];
|
|
253
|
+
overwrite?: boolean;
|
|
254
|
+
skipInstall?: boolean;
|
|
255
|
+
confirm?: (message: string) => Promise<boolean>;
|
|
256
|
+
path?: string;
|
|
257
|
+
askPath?: (items: string[]) => Promise<string>;
|
|
258
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
259
|
+
};
|
|
260
|
+
type AddResult = {
|
|
261
|
+
added: {
|
|
262
|
+
key: string;
|
|
263
|
+
version: string;
|
|
264
|
+
files: string[];
|
|
265
|
+
block: boolean;
|
|
266
|
+
}[];
|
|
267
|
+
installed: string[];
|
|
268
|
+
packages: string[];
|
|
269
|
+
cssChanges: CssVarChange[];
|
|
270
|
+
licenses: {
|
|
271
|
+
namespace: string;
|
|
272
|
+
url: string;
|
|
273
|
+
}[];
|
|
274
|
+
warnings: string[];
|
|
275
|
+
};
|
|
276
|
+
export declare function addItems({ root, refs, overwrite, skipInstall, confirm, path: blockPath, askPath, createClient }: AddOptions): Promise<AddResult>;
|
|
277
|
+
type MaterializeContext = {
|
|
278
|
+
root: string;
|
|
279
|
+
aliases: Config["aliases"];
|
|
280
|
+
tsconfig: TsConfigResult;
|
|
281
|
+
css?: string;
|
|
282
|
+
};
|
|
283
|
+
type FileComparison = {
|
|
284
|
+
destination: string;
|
|
285
|
+
base?: string;
|
|
286
|
+
remote?: string;
|
|
287
|
+
local?: string;
|
|
288
|
+
};
|
|
289
|
+
type ItemComparison = {
|
|
290
|
+
key: string;
|
|
291
|
+
registry: ResolvedRegistry;
|
|
292
|
+
base: Item;
|
|
293
|
+
remote: Item;
|
|
294
|
+
files: FileComparison[];
|
|
295
|
+
newerMajor?: string;
|
|
296
|
+
warnings: string[];
|
|
297
|
+
};
|
|
298
|
+
export declare function compareItem({ key, version, major, config, context, clientFor }: {
|
|
299
|
+
key: string;
|
|
300
|
+
version?: string;
|
|
301
|
+
major?: boolean;
|
|
302
|
+
config: Pick<Config, "items" | "token">;
|
|
303
|
+
context: MaterializeContext;
|
|
304
|
+
clientFor: (registry: ResolvedRegistry) => RegistryClient;
|
|
305
|
+
}): Promise<ItemComparison>;
|
|
306
|
+
type DiffResult = {
|
|
307
|
+
comparison: ItemComparison;
|
|
308
|
+
patches: string[];
|
|
309
|
+
changed: boolean;
|
|
310
|
+
};
|
|
311
|
+
export declare function diffItem({ root, ref, local, major, createClient }: {
|
|
312
|
+
root: string;
|
|
313
|
+
ref: string;
|
|
314
|
+
local?: boolean;
|
|
315
|
+
major?: boolean;
|
|
316
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
317
|
+
}): Promise<DiffResult>;
|
|
318
|
+
type OutdatedStatus = "outdated" | "current" | "missing" | "unknown-version";
|
|
319
|
+
type OutdatedItem = {
|
|
320
|
+
key: string;
|
|
321
|
+
registry: string;
|
|
322
|
+
current: string;
|
|
323
|
+
wanted?: string;
|
|
324
|
+
latest?: string;
|
|
325
|
+
status: OutdatedStatus;
|
|
326
|
+
};
|
|
327
|
+
type OutdatedOptions = {
|
|
328
|
+
root: string;
|
|
329
|
+
refs?: string[];
|
|
330
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
331
|
+
};
|
|
332
|
+
export declare function outdatedItems({ root, refs, createClient }: OutdatedOptions): Promise<OutdatedItem[]>;
|
|
333
|
+
type PlannedItem = {
|
|
334
|
+
key: string;
|
|
335
|
+
registry: ResolvedRegistry;
|
|
336
|
+
item: Item;
|
|
337
|
+
};
|
|
338
|
+
type InstallPlan = {
|
|
339
|
+
items: PlannedItem[];
|
|
340
|
+
installed: string[];
|
|
341
|
+
warnings: string[];
|
|
342
|
+
};
|
|
343
|
+
type Options$2 = {
|
|
344
|
+
refs: string[];
|
|
345
|
+
config: Pick<Config, "items" | "token">;
|
|
346
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
347
|
+
};
|
|
348
|
+
export declare function planInstall({ refs, config, createClient }: Options$2): Promise<InstallPlan>;
|
|
349
|
+
export declare function applyCssTemplate(root: string, file: string): Promise<{
|
|
350
|
+
created: boolean;
|
|
351
|
+
changes: CssVarChange[];
|
|
352
|
+
}>;
|
|
353
|
+
type ConflictResolution = "markers" | "local" | "remote";
|
|
354
|
+
type FileStatus = "unchanged" | "updated" | "merged" | "conflict" | "added" | "removed" | "kept";
|
|
355
|
+
type UpdateOptions = {
|
|
356
|
+
root: string;
|
|
357
|
+
refs: string[];
|
|
358
|
+
major?: boolean;
|
|
359
|
+
overwrite?: boolean;
|
|
360
|
+
skipInstall?: boolean;
|
|
361
|
+
confirm?: (message: string) => Promise<boolean>;
|
|
362
|
+
resolveConflict?: (destination: string) => Promise<ConflictResolution>;
|
|
363
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
364
|
+
};
|
|
365
|
+
type UpdateResult = {
|
|
366
|
+
updated: {
|
|
367
|
+
key: string;
|
|
368
|
+
from: string;
|
|
369
|
+
to: string;
|
|
370
|
+
files: {
|
|
371
|
+
destination: string;
|
|
372
|
+
status: FileStatus;
|
|
373
|
+
}[];
|
|
374
|
+
}[];
|
|
375
|
+
upToDate: string[];
|
|
376
|
+
conflicts: string[];
|
|
377
|
+
added: string[];
|
|
378
|
+
packages: string[];
|
|
379
|
+
cssChanges: CssVarChange[];
|
|
380
|
+
warnings: string[];
|
|
381
|
+
};
|
|
382
|
+
export declare function updateItems({ root, refs, major, overwrite, skipInstall, confirm, resolveConflict, createClient }: UpdateOptions): Promise<UpdateResult>;
|
|
383
|
+
type Account = {
|
|
384
|
+
name?: string;
|
|
385
|
+
image?: string;
|
|
386
|
+
plan?: string;
|
|
387
|
+
access: string[];
|
|
388
|
+
};
|
|
389
|
+
type Options$1 = {
|
|
390
|
+
root: string;
|
|
391
|
+
fetch?: typeof fetch;
|
|
392
|
+
env?: Record<string, string | undefined>;
|
|
393
|
+
file?: string;
|
|
394
|
+
};
|
|
395
|
+
export declare function login({ token, fetch, env, file }: Options$1 & {
|
|
396
|
+
token: string;
|
|
397
|
+
}): Promise<{
|
|
398
|
+
account: Account;
|
|
399
|
+
url: string;
|
|
400
|
+
file: string;
|
|
401
|
+
}>;
|
|
402
|
+
export declare function loginWithBrowser({ root, onUrl, timeout, ...options }: Options$1 & {
|
|
403
|
+
onUrl: (url: string) => void;
|
|
404
|
+
timeout?: number;
|
|
405
|
+
}): Promise<{
|
|
406
|
+
account: Account;
|
|
407
|
+
url: string;
|
|
408
|
+
file: string;
|
|
409
|
+
}>;
|
|
410
|
+
export declare function resolveProjectPath(root: string, relativePath: string): Promise<string>;
|
|
411
|
+
type SearchResult = {
|
|
412
|
+
key: string;
|
|
413
|
+
name: string;
|
|
414
|
+
namespace: string;
|
|
415
|
+
entry: RegistryEntry;
|
|
416
|
+
score: number;
|
|
417
|
+
};
|
|
418
|
+
type SearchSource = {
|
|
419
|
+
namespace: string;
|
|
420
|
+
isDefault: boolean;
|
|
421
|
+
index: Registry;
|
|
422
|
+
};
|
|
423
|
+
export declare function searchRegistries(sources: SearchSource[], term: string, { type }?: {
|
|
424
|
+
type?: ItemKind;
|
|
425
|
+
}): SearchResult[];
|
|
426
|
+
type Options = {
|
|
427
|
+
root: string;
|
|
428
|
+
createClient?: (registry: ResolvedRegistry) => RegistryClient;
|
|
429
|
+
};
|
|
430
|
+
export declare function searchItems({ root, term, type, createClient }: Options & {
|
|
431
|
+
term: string;
|
|
432
|
+
type?: ItemKind;
|
|
433
|
+
}): Promise<{
|
|
434
|
+
results: SearchResult[];
|
|
435
|
+
warnings: string[];
|
|
436
|
+
}>;
|
|
437
|
+
type ItemInfo = {
|
|
438
|
+
key: string;
|
|
439
|
+
registry: ResolvedRegistry;
|
|
440
|
+
entry: RegistryEntry;
|
|
441
|
+
item: Item;
|
|
442
|
+
installed?: string;
|
|
443
|
+
destinations?: string[];
|
|
444
|
+
};
|
|
445
|
+
export declare function itemInfo({ root, ref: raw, createClient }: Options & {
|
|
446
|
+
ref: string;
|
|
447
|
+
}): Promise<ItemInfo>;
|
|
448
|
+
export type { Account, AddOptions, AddResult, Config, ConflictResolution, CssVars, Dependencies, DiffResult, InstallPlan, InstalledItem, Item, ItemAccess, ItemComparison, ItemFile, ItemInfo, ItemKind, ItemRef, McpClient, OutdatedItem, OutdatedOptions, OutdatedStatus, PlannedItem, Registry, RegistryClient, RegistryClientOptions, RegistryEntry, ResolvedRegistry, SearchResult, SearchSource, UpdateOptions, UpdateResult };
|
|
449
|
+
//# sourceMappingURL=index.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":["Options","Options"],"sources":["../src/schemas/item.ts","../src/schemas/registry.ts","../src/schemas/shared.ts","../src/schemas/config.ts","../src/resolve.ts","../src/client.ts","../src/constants.ts","../src/errors.ts","../src/init.ts","../src/css.ts","../src/install/add.ts","../src/install/materialize.ts","../src/install/compare.ts","../src/install/diff.ts","../src/install/outdated.ts","../src/install/plan.ts","../src/install/styles.ts","../src/install/update.ts","../src/login.ts","../src/paths.ts","../src/search.ts","../src/query.ts"],"mappings":"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"}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import{createHash as e,randomBytes as t}from"node:crypto";import{z as n}from"zod";import{homedir as r,hostname as i}from"node:os";import a from"node:path";import{access as o,lstat as s,mkdir as c,readFile as l,realpath as u,rm as d,writeFile as f}from"node:fs/promises";import{createPathsMatcher as p,parseTsconfig as m}from"get-tsconfig";import"jsonc-parser";import h from"semver";import{spawn as g}from"node:child_process";import _ from"postcss";import{createTwoFilesPatch as v}from"diff";import{merge as y}from"node-diff3";import{createServer as b}from"node:http";import x from"minisearch";const S=`slabui.json`,C={namespace:`@slabui`,url:`https://slabui.com/r`},w=`https://slabui.com`,T=`${w}/schema.json`,E={command:`x-slabui-command`,optOut:`x-slabui-telemetry`},D=[`ui`,`component`,`lib`,`hook`,`util`,`style`,`file`,`theme`,`block`,`example`],O=[`free`,`pro`],k=`SLABUI_TOKEN`,ee=`whoami.json`,te=[`claude`,`cursor`,`vscode`,`zed`,`codex`];function A(e=process.env,t=process.platform,n=r()){let i=t===`win32`?a.join(e.APPDATA??a.join(n,`AppData/Roaming`),`slabui`):a.join(e.XDG_CONFIG_HOME||a.join(n,`.config`),`slabui`);return a.join(i,`credentials.json`)}async function ne(e=A()){try{let{token:t}=JSON.parse(await l(e,`utf8`));return typeof t==`string`&&t?t:void 0}catch{return}}async function re(e,t=A()){await c(a.dirname(t),{recursive:!0}),await f(t,`${JSON.stringify({token:e})}\n`,{mode:384})}async function ie({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 ae(){return t(24).toString(`base64url`)}function oe({registryUrl:e,callback:t,state:n,client:r,host:a=i()}){let o=new URL(`/cli/authorize`,new URL(e).origin);return o.searchParams.set(`callback`,t),o.searchParams.set(`state`,n),o.searchParams.set(`client`,r),o.searchParams.set(`host`,a.replace(/\.local$/,``).slice(0,60)),o.toString()}var j=class extends Error{name=`SlabUIError`};const M=n.string().regex(/^[a-z0-9]+(-[a-z0-9]+)*$/,`name must be kebab-case`),se=n.string().regex(/^@[a-z0-9-]+$/,`namespace must look like @name`),N=n.string().regex(/^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)$/,`version must be X.Y.Z`),ce=n.string().regex(/^sha256-[A-Za-z0-9+/]+={0,2}$/,`hash must be sha256-<base64>`),P=n.enum(D),le=n.enum(O),ue=n.string().regex(/^(@[a-z0-9-]+\/)?[a-z0-9]+(-[a-z0-9]+)*(@\S+)?$/,`dependency must look like [@ns/]name[@version]`),de=n.object({registry:n.array(ue).default([]),npm:n.array(n.string().min(1)).default([]),npmDev:n.array(n.string().min(1)).default([])}),fe=[e=>e.kind!==`file`||e.target!==void 0,{message:`a file with kind "file" needs a target`,path:[`target`]}],pe=[e=>e.files.length>0||e.cssVars!==void 0,{message:`the item needs files or cssVars`,path:[`files`]}],me=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional()}).refine(...fe),he=n.object({path:n.string().min(1),kind:P,target:n.string().min(1).optional(),content:n.string()}).refine(...fe),F=n.record(n.string(),n.string()),ge=n.object({theme:F.optional(),light:F.optional(),dark:F.optional()}),_e={name:M,kind:P,title:n.string().min(1).optional(),description:n.string().min(1),dependencies:de.prefault({}),cssVars:ge.optional()},ve=n.object({$schema:n.string().optional(),schemaVersion:n.literal(1),..._e,version:N,files:n.array(he).default([])}).refine(...pe);n.object({..._e,categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:le.optional(),inferDependencies:n.boolean().optional(),files:n.array(me).default([])}).refine(...pe);const ye=n.string().regex(/^(?!.*(^|\/)\.\.?(\/|$))[A-Za-z0-9._-]+(\/[A-Za-z0-9._-]+)*\.json$/,`path must be a relative path to a .json file`),be=n.object({hash:ce,path:ye}),xe=n.object({kind:P,title:n.string().min(1).optional(),description:n.string().min(1),categories:n.array(n.string().min(1)).optional(),keywords:n.array(n.string().min(1)).optional(),docs:n.url().optional(),access:le.optional(),dependencies:de.prefault({}),tokens:n.array(n.string().min(1)).optional(),latest:N,versions:n.record(N,be)}).refine(e=>e.latest in e.versions,{message:`latest must exist in versions`,path:[`latest`]}),Se=n.object({$schema:n.string().optional(),schemaVersion:n.literal(2),namespace:se.optional(),homepage:n.url().optional(),mcp:n.url().optional(),license:n.url().optional(),items:n.record(M,xe)});var Ce=`0.0.1`;let we;function Te(e){return e.SLABUI_TELEMETRY_DISABLED===`1`||e.DO_NOT_TRACK===`1`}function Ee(e,t=we){let n={"user-agent":`slabui/${Ce}`};return Te(e)?n[E.optOut]=`off`:t&&(n[E.command]=t),n}const De=/* @__PURE__ */ new Map;function I(e,{fetch:t=globalThis.fetch,env:r=process.env,command:i,savedToken:a=()=>ne()}={}){let o=e.url.replace(/\/+$/,``),s={...Ee(r,i),...ke(e.headers,r)},c;async function l(t){let n=Object.keys(s).some(e=>e.toLowerCase()===`authorization`);if(!e.isDefault||n)return{};let i=(e.token===void 0?void 0:Ae(e.token,`"token" in slabui.json`,r))||r.SLABUI_TOKEN||await a();if(!i)throw new j(`"${t}" is a Pro item. Run "slabui login" or set ${k} to install it.`);return{authorization:`Bearer ${i}`}}async function u(n,{extraHeaders:r={},pro:i}={}){let a;try{a=await t(n,{headers:{...s,...r},signal:AbortSignal.timeout(3e4)})}catch{throw new j(`Could not reach ${n}.`)}if(i!==void 0&&e.isDefault&&a.status===401)throw new j(`The token was refused while fetching the Pro item "${i}". Run "slabui login" again or check ${k}.`);if(i!==void 0&&e.isDefault&&a.status===403)throw new j(`Your token does not give access to the Pro item "${i}". Check your SlabUI Pro subscription.`);if(a.status===401||a.status===403)throw new j(`Access denied to ${n} (${a.status}).`);if(a.status===404)throw new j(`Not found: ${n}.`);if(!a.ok)throw new j(`Error ${a.status} while fetching ${n}.`);return new Uint8Array(await a.arrayBuffer())}function d(e,t,r,i){let a;try{a=JSON.parse(new TextDecoder().decode(t))}catch{throw new j(`${e} is not valid JSON.`)}i?.(e,a);let o=r.safeParse(a);if(!o.success)throw new j(`${e} does not match the expected format:\n${n.prettifyError(o.error)}`);return o.data}async function f(){let t=`${o}/registry.json`,n=d(t,await u(t),Se,Oe);return De.set(e.namespace,n),n}function p(){return c??=f().catch(e=>{throw c=void 0,e}),c}return{index:p,async item(t,n){let r=(await p()).items[t];if(r===void 0)throw new j(`Item "${t}" does not exist in the "${e.namespace}" registry.`);let i=r.versions[n];if(i===void 0)throw new j(`Version ${n} of "${t}" does not exist in the "${e.namespace}" registry.`);let a=`${o}/${i.path}`,s=r.access===`pro`?await u(a,{extraHeaders:await l(t),pro:t}):await u(a);if(je(s)!==i.hash)throw new j(`${a} does not match the hash in the index. The file may have been changed on the server.`);let c=d(a,s,ve);if(c.name!==t||c.version!==n)throw new j(`${a} contains ${c.name}@${c.version}, not ${t}@${n}.`);return c}}}function Oe(e,t,n=`The registry needs to be published again in the current format.`){let r=t&&typeof t==`object`&&`schemaVersion`in t?t.schemaVersion:void 0;if(typeof r==`number`&&r!==2)throw r>2?new j(`${e} uses format ${r}, which this version of slabui does not support. Update it with \`pnpm add -D slabui@latest\`.`):new j(`${e} uses format ${r}, which is no longer supported. ${n}`)}function ke(e,t=process.env){return Object.fromEntries(Object.entries(e).map(([e,n])=>[e,Ae(n,`the "${e}" header`,t)]))}function Ae(e,t,n){return e.replace(/\$\{([A-Za-z_][A-Za-z0-9_]*)\}/g,(e,r)=>{let i=n[r];if(i===void 0)throw new j(`Environment variable ${r}, used in ${t}, is not set.`);return i})}function je(t){return`sha256-${e(`sha256`).update(t).digest(`base64`)}`}const Me=n.object({version:N,files:n.array(n.string().min(1))}),Ne=n.object({$schema:n.string().optional(),token:n.string().min(1).optional(),css:n.string().min(1).optional(),aliases:n.object({components:n.string().min(1),ui:n.string().min(1),lib:n.string().min(1),hooks:n.string().min(1),utils:n.string().min(1),styles:n.string().min(1)}),items:n.record(M,Me).default({})}),Pe=[`tsconfig.json`,`jsconfig.json`],Fe=[`app/globals.css`,`src/app/globals.css`,`styles/globals.css`,`src/styles/globals.css`,`app/global.css`,`src/index.css`,`src/styles.css`];async function L(e){return o(e).then(()=>!0,()=>!1)}async function R(e){for(let t of Pe){let n=a.join(e,t);if(await L(n))try{return{path:n,config:m(n)}}catch(e){throw new j(`Could not read ${t}: ${e.message}`)}}throw new j(`No tsconfig.json or jsconfig.json in ${e}. slabui uses its "paths" to resolve the aliases.`)}function z(e){let t=Object.keys(e.config.compilerOptions?.paths??{}).filter(e=>e.endsWith(`/*`));return(t.find(e=>e===`@/*`)??t.find(e=>e===`~/*`)??t[0])?.slice(0,-1)}function B(e,t,n){if(n===void 0)return;let r=z(e),i=r!==void 0&&n.startsWith(r)?V(e,n):void 0;return i===void 0?n:a.relative(t,i).split(a.sep).join(`/`)}function V(e,t){return p(e)?.(t)[0]}async function Ie(e){for(let t of Fe)if(await L(a.join(e,t)))return t}async function H(e){let t=a.join(e,S),r=await l(t,`utf8`).catch(()=>void 0);if(r===void 0)throw new j(`${S} not found in ${e}. Run "slabui init" first.`);let i;try{i=JSON.parse(r)}catch{throw new j(`${S} is not valid JSON.`)}let o=Ne.safeParse(i);if(!o.success)throw new j(`${S} has errors:\n${n.prettifyError(o.error)}`);return o.data}async function U(e,t){await f(a.join(e,S),`${JSON.stringify(t,null,2)}\n`)}function Le(e){return e.startsWith(`./`)||e.startsWith(`../`)}async function Re(e){let t=z(await R(e));if(t===void 0)throw new j(`The tsconfig has no alias in "paths" (e.g. "@/*": ["./*"]). slabui uses it to place files and write imports.`);return{aliases:{components:`${t}components`,ui:`${t}components/ui`,lib:`${t}lib`,hooks:`${t}hooks`,utils:`${t}utils`,styles:`${t}styles`},...await ze(e,`${t}styles`)}}async function ze(e,t){let n=await Ie(e);return n===void 0?{css:`${t}/globals.css`,cssDetected:!1}:{css:n,cssDetected:!0}}async function Be({root:e,aliases:t,css:n,force:r=!1}){if(!r&&await L(a.join(e,`slabui.json`)))throw new j(`${S} already exists. Use --force to create it again.`);let i=await R(e);for(let[e,n]of Object.entries(t))if(!Le(n)&&V(i,n)===void 0)throw new j(`Alias "${n}" (${e}) does not match any "paths" in the tsconfig.`);let o={$schema:T,...n&&{css:n},aliases:t,items:{}};return await U(e,o),o}async function W(e,t){let n=e=>new j(`Path "${t}" refused: ${e}.`);if(t===``)throw n(`it is empty`);if(t.includes(`\0`))throw n(`it contains a null character`);if(t.includes(`\\`))throw n(`use / as the separator`);if(a.posix.isAbsolute(t)||a.win32.isAbsolute(t))throw n(`it is absolute`);let r=a.resolve(e),i=a.resolve(r,t);if(i===r)throw n(`it points to the project root`);if(!Ve(r,i))throw n(`it leaves the project root`);let o=await He(i);if(o===i&&(await s(i)).isSymbolicLink())throw n(`the target is a symbolic link`);let c=await u(r),l=await u(o).catch(()=>{throw n(`it goes through a broken symbolic link`)});if(!Ve(c,l))throw n(`it goes through a symbolic link outside the project`);return a.join(l,a.relative(o,i))}function Ve(e,t){let n=a.relative(e,t);return n===``||n!==`..`&&!n.startsWith(`..${a.sep}`)&&!a.isAbsolute(n)}async function He(e){let t=e;for(;;)try{return await s(t),t}catch(e){if(e.code!==`ENOENT`)throw e;t=a.dirname(t)}}const G=[`.ts`,`.tsx`,`.js`,`.jsx`,`.mts`,`.cts`,`.mjs`],Ue=/(\bfrom\s+|\bimport\s+|\bimport\s*\(\s*)(["'])([^"'\n]+)\2/g,We=/(@(?:import|reference)\s+)(["'])([^"'\n]+)\2/g;function Ge(e){return a.posix.extname(e)===`.css`}function Ke(e,t){return e.replace(We,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function qe(e){return G.includes(a.posix.extname(e))}function Je(e,t){return e.replace(Ue,(e,n,r,i)=>{let a=t(i);return a===void 0?e:`${n}${r}${a}${r}`})}function Ye(e,t){return[e,...G.map(t=>`${e}${t}`),...G.map(t=>`${e}/index${t}`)].find(e=>t.has(e))}function Xe(e){let t=a.posix.extname(e);return G.includes(t)?e.slice(0,-t.length):e}function K(e){let t=e;if(t.startsWith(`@`)){let n=t.indexOf(`/`);if(n===-1)throw new j(`"${e}" has no item name after the namespace.`);if(t.slice(0,n)!==C.namespace)throw new j(`"${e}" is not from the SlabUI registry. Only SlabUI items can be installed.`);t=t.slice(n+1)}let n=t.indexOf(`@`),r=n===-1?t:t.slice(0,n),i=n===-1?void 0:t.slice(n+1);if(!M.safeParse(r).success)throw new j(`"${r}" is not a valid item name (kebab-case).`);if(i!==void 0&&(!i||h.validRange(i)===null))throw new j(`"${i}" is not a valid version or range.`);return{name:r,...i!==void 0&&{range:i}}}function q(e){return e.name}function J(e,t=process.env){return{namespace:C.namespace,url:t.SLABUI_REGISTRY_URL||C.url,headers:{},isDefault:!0,...e!==void 0&&{token:e}}}function Y(e,t){if(e.range===void 0)return t.latest;let n=Object.keys(t.versions),r=h.maxSatisfying(n,e.range);if(r===null)throw new j(`No version of "${q(e)}" satisfies "${e.range}". Available: ${h.sort(n).join(`, `)}.`);return r}const Ze={ui:`ui`,component:`components`,lib:`lib`,hook:`hooks`,util:`utils`,style:`styles`};function Qe(e,t){if(e.target!==void 0){let n=e.target;return et((n.startsWith(z(t.tsconfig)??`\0`)?V(t.tsconfig,n):void 0)??a.resolve(t.root,n),t)}if(!(e.kind in Ze))throw new j(`Files with kind "${e.kind}" cannot be installed by add yet (${e.path}).`);let n=t.aliases[Ze[e.kind]],r=e.kind===`style`&&e.path.split(`/`).slice(1).join(`/`)||a.posix.basename(e.path),i=Le(n)?a.resolve(t.root,n,r):V(t.tsconfig,`${n}/${r}`);if(i===void 0)throw new j(`Alias "${n}" does not match any "paths" in the tsconfig.`);return et(i,t)}function $e(e,t,n){let r=z(n.tsconfig),i=r===void 0?void 0:V(n.tsconfig,`${r}__slabui__`)?.slice(0,-10),o=a.resolve(n.root,e);if(r!==void 0&&i!==void 0&&o.startsWith(i))return`${r}${Xe(a.relative(i,o).split(a.sep).join(`/`))}`;let s=a.posix.relative(a.posix.dirname(t),e);return s.startsWith(`.`)||(s=`./${s}`),Xe(s)}function et(e,t){return a.relative(t.root,e).split(a.sep).join(`/`)}function X(e){return e.kind===`block`||e.kind===`example`}function Z(e,t,n){return X(e)?at(e,n):new Map(e.files.map(e=>[e.path,Qe(e,t)]))}function tt(e,t){return[e,...t.dependencies.registry.map(e=>q(K(e)))]}async function nt(e,{config:t,context:n,destinations:r,clientFor:i}){for(let a of e)for(let e of a.dependencies.registry){let a=K(e),o=q(a),s=t.items[o];if(r.has(o)||s===void 0)continue;let c=i(J(t.token));r.set(o,Z(await c.item(a.name,s.version),n))}}function rt(e,{key:t,item:n,destination:r,destinations:i,context:a,warnings:o}){let s=Ge(e.path);if(!qe(e.path)&&!s)return e.content;let c=tt(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 it(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&&Ye(n,new Set(t.keys()));if(o){let e=t.get(o);return s?it(e,r):$e(e,r,a)}}o.push(`"${t}": could not rewrite the import ${e} in ${r}.`)};return s?Ke(e.content,l):Je(e.content,l)}function it(e,t){let n=a.posix.relative(a.posix.dirname(t),e);return n.startsWith(`.`)?n:`./${n}`}function at(e,t){let n=e.files.map(e=>a.posix.dirname(e.path).split(`/`)),r=[];for(let[e,t]of(n[0]??[]).entries())if(n.every(n=>n[e]===t))r.push(t);else break;let i=r.join(`/`),o=a.posix.normalize(t.split(a.sep).join(`/`));return new Map(e.files.map(e=>[e.path,a.posix.join(o,a.posix.relative(i,e.path))]))}const ot=[[`pnpm-lock.yaml`,`pnpm`],[`bun.lock`,`bun`],[`bun.lockb`,`bun`],[`yarn.lock`,`yarn`],[`package-lock.json`,`npm`]];function st(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?{name:e}:{name:e.slice(0,t),range:e.slice(t+1)||void 0}}async function ct(e){let t=(await lt(e))?.packageManager?.split(`@`)[0];if(t&&[`pnpm`,`npm`,`yarn`,`bun`].includes(t))return t;let n=a.resolve(e);for(;;){for(let[e,t]of ot)if(await L(a.join(n,e)))return t;let e=a.dirname(n);if(e===n)return`npm`;n=e}}async function lt(e){let t=await l(a.join(e,`package.json`),`utf8`).catch(()=>void 0);return t===void 0?void 0:JSON.parse(t)}async function ut(e,{npm:t,npmDev:n}){let r=await lt(e)??{},i={...r.devDependencies,...r.dependencies},a={install:[],installDev:[],conflicts:[]},o=(e,t)=>{let{name:n,range:r}=st(e),o=i[n];if(o===void 0){t.includes(e)||t.push(e);return}let s=h.minVersion(o);r&&s&&!h.satisfies(s,r)&&a.conflicts.push({spec:e,installed:o})};for(let e of new Set(t))o(e,a.install);for(let e of new Set(n))o(e,a.installDev);return a}function dt(e,t,n){return[e,[e===`npm`?`install`:`add`,...n?[e===`bun`?`--dev`:`-D`]:[],...t]]}async function ft(e,t,n,r){if(n.length===0)return;let[i,a]=dt(t,n,r);await new Promise((t,n)=>{let r=g(i,a,{cwd:e,stdio:`inherit`});r.on(`error`,e=>n(new j(`Could not run ${i}: ${e.message}`))),r.on(`exit`,e=>e===0?t():n(new j(`${i} ${a.join(` `)} exited with code ${e}.`)))})}async function pt(e,t,{confirm:n,skipInstall:r=!1,warnings:i}){let a=await ut(e,t);for(let{spec:e,installed:t}of a.conflicts)n&&await n(`The project has ${t}, but ${e} is required. Update it?`)?a.install.push(e):i.push(`Kept ${st(e).name}@${t}; the item requires ${e}.`);let o=[...a.install,...a.installDev];if(o.length===0)return[];if(r)return i.push(`Packages not installed (--skip-install): ${o.join(` `)}`),[];let s=await ct(e);return await ft(e,s,a.install,!1),await ft(e,s,a.installDev,!0),o}async function mt({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=q(e),d=i.get(r)??[];d.push({range:e.range,by:n}),i.set(r,d);let f=t.items[r];if(f!==void 0){let e=d.filter(({range:e})=>e&&!h.satisfies(f.version,e));if(e.length===0)s.add(r);else for(let{range:t,by:n}of e)c.push(`"${r}" is installed at ${f.version}, but ${n?`"${n}"`:`the request`} requires ${t}. Run "slabui update ${r}".`);return}let p=a.get(r);if(p&&d.every(({range:e})=>ht(p,e)))return;let m=J(t.token),g=l(m),_=(await g.index()).items[e.name];if(_===void 0)throw new j(`Item "${e.name}" does not exist in the "${m.namespace}" registry.`);let v=Object.keys(_.versions),y=d.flatMap(({range:e})=>e?[e]:[]),b=y.length===0?_.latest:h.rsort(v.filter(e=>y.every(t=>h.satisfies(e,t))))[0]??null;if(b===null)throw new j(`No version of "${r}" satisfies every request: ${d.map(({range:e,by:t})=>`${e??`latest`} (${t??`requested`})`).join(`, `)}. Available: ${h.sort(v).join(`, `)}.`);let x=await g.item(e.name,b);a.set(r,{key:r,registry:m,item:x});for(let e of x.dependencies.registry)await u(K(e),r);o.includes(r)||o.push(r)}for(let t of e)await u(K(t));return{items:o.map(e=>a.get(e)),installed:[...s],warnings:c}}function ht(e,t){return t===void 0||h.satisfies(e.item.version,t)}const gt=/^[a-z0-9][a-z0-9-]*$/i;function _t(e){return gt.test(e)}function vt(e,t=!1){if(!_t(e))throw Error(`Invalid theme name: "${e}"`);return`:root[data-slabui-theme="${e}"]${t?`.dark`:``}`}const yt=/^\s*(oklch|oklab|lch|lab|hsla?|rgba?|hwb|color)\(|^\s*#[0-9a-f]{3,8}\s*$/i;async function bt(e,t,{base:n,overwrite:r=!1,shouldRemove:i,theme:a}={}){let o=_.parse(e),s=[],c=[],l=e=>a?e:xt(e),u=l(t),d=n?l(n):void 0;for(let e of[`theme`,`light`,`dark`]){let t=u[e]??{},n=d?.[e]??{},l=/* @__PURE__ */ new Set([...Object.keys(t),...Object.keys(n)]);if(l.size===0)continue;let f=wt(o,e,a);for(let u of l){let l=t[u],d=n[u],p=f?.nodes?.find(e=>e.type===`decl`&&e.prop===`--${u}`),m=p?.value,h=t=>s.push({group:e,name:u,action:t});if(l===void 0){if(m===void 0)continue;i&&await i(e,u)?(p?.remove(),h(`removed`)):(c.push(`--${u} (${e}) was removed in the new version; kept in the CSS.`),h(`kept`))}else if(m===void 0){if(d!==void 0){h(`kept`);continue}f??=Tt(o,e,a),f.raws.semicolon=!0,f.raws.after=`
|
|
2
|
+
`,f.append(_.decl({prop:`--${u}`,value:l,raws:{before:`
|
|
3
|
+
`}})),h(`added`)}else Q(m,l)?h(`unchanged`):r||d!==void 0&&Q(m,d)?(p.value=l,h(`updated`)):(c.push(`--${u} (${e}) has a custom value in the CSS (${m}); kept instead of ${l}.`),h(`kept`))}}return!a&&Object.keys(u.dark??{}).length>0&&Et(o),{css:o.toString(),changes:s,warnings:c}}function xt(e){let t={...e.theme};for(let n of[e.light,e.dark])for(let[e,r]of Object.entries(n??{}))yt.test(r)&&t[`color-${e}`]===void 0&&(t[`color-${e}`]=`var(--${e})`);return{...e,...Object.keys(t).length>0&&{theme:t}}}function St(e,t){return t?vt(t,e===`dark`):e===`light`?`:root`:`.dark`}const Ct=e=>e.replace(/["'\s]/g,``);function wt(e,t,n){return e.nodes.find(e=>t===`theme`?e.type===`atrule`&&e.name===`theme`&&e.params.trim()===`inline`:e.type===`rule`&&Ct(e.selector)===Ct(St(t,n)))}function Tt(e,t,n){let r=t===`theme`?_.atRule({name:`theme`,params:`inline`}):_.rule({selector:St(t,n)});return r.raws={before:e.nodes.length>0?`
|
|
4
|
+
|
|
5
|
+
`:``,between:` `,after:`
|
|
6
|
+
`,semicolon:!0},e.append(r),r}function Et(e){if(e.nodes.some(e=>e.type===`atrule`&&e.name===`custom-variant`&&e.params.trim().startsWith(`dark`)))return;let t=_.atRule({name:`custom-variant`,params:`dark (&:is(.dark *))`}),n=e.nodes.filter(e=>e.type===`atrule`&&e.name===`import`).at(-1);n?(t.raws={before:`
|
|
7
|
+
|
|
8
|
+
`},n.after(t)):(t.raws={before:``},e.prepend(t))}function Q(e,t){return e.replace(/\s+/g,` `).trim()===t.replace(/\s+/g,` `).trim()}const Dt={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":`0.625rem`,"text-2xxs":`0.688rem`,"text-2xs":`0.813rem`,"text-2xs--line-height":`calc(1.125 / 0.813)`,"text-2sm":`0.938rem`,"text-2sm--line-height":`calc(1.625 / 0.938)`,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`,background:`oklch(1 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)`,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)`}},Ot=bt,kt=Dt;async function At(e,t){let n=await W(e,t),r=await l(n,`utf8`).catch(()=>void 0),i=await Ot(r??`@import "tailwindcss";
|
|
9
|
+
|
|
10
|
+
@layer base {
|
|
11
|
+
* {
|
|
12
|
+
@apply border-border outline-ring/50;
|
|
13
|
+
}
|
|
14
|
+
body {
|
|
15
|
+
@apply bg-background text-foreground;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
`,kt);return(r===void 0||i.css!==r)&&(await c(a.dirname(n),{recursive:!0}),await f(n,i.css)),{created:r===void 0,changes:i.changes}}async function jt(e,t,n,r,i){if(t===void 0)return i.warnings.push(`"${n}": has CSS variables, but "css" is not set in slabui.json; add them to your CSS manually.`),[];let a=await W(e,t),o=await l(a,`utf8`).catch(()=>void 0);o===void 0&&(await At(e,t),i.warnings.push(`${t} did not exist; it was created with the default template.`),o=await l(a,`utf8`));let s=await Ot(o,r,i);return i.warnings.push(...s.warnings.map(e=>`"${n}": ${e}`)),s.css!==o&&await f(a,s.css),s.changes}async function Mt({root:e,refs:t,overwrite:n=!1,skipInstall:r=!1,confirm:i,path:o,askPath:s,createClient:l=e=>I(e)}){let u=await H(e),d=await R(e),p={root:e,aliases:u.aliases,tsconfig:d,css:B(d,e,u.css)},m=/* @__PURE__ */ new Map,h=e=>{let t=m.get(e.namespace);return t===void 0&&(t=l(e),m.set(e.namespace,t)),t},g=Object.keys(u.items).length===0,_=await mt({refs:t,config:u,createClient:h}),v=[..._.warnings],y=_.items.filter(({item:e})=>X(e)),b=o;if(y.length>0&&b===void 0){let e=y.map(({key:e})=>e);if(s===void 0)throw new j(`${e.map(e=>`"${e}"`).join(`, `)} ${e.length>1?`are blocks or examples`:`is a block or example`}: pass the folder with --path.`);b=await s(e)}let x=/* @__PURE__ */ new Map;for(let{key:e,item:t}of _.items)x.set(e,Z(t,p,b));await nt(_.items.map(({item:e})=>e),{config:u,context:p,destinations:x,clientFor:h});let S=/* @__PURE__ */ new Map;for(let[e,t]of Object.entries(u.items))for(let n of t.files)S.set(n,e);let C=[];for(let{key:t}of _.items)for(let n of x.get(t)?.values()??[])if(await W(e,n),await L(a.join(e,n))){let e=S.get(n);C.push(e?`${n} (from "${e}")`:n)}if(C.length>0&&!n){let e=C.map(e=>` ${e}`).join(`
|
|
19
|
+
`);if(!(i&&await i(`These files already exist and will be overwritten:\n${e}\nContinue?`)))throw new j(`These files already exist in the project:\n${e}\nUse --overwrite to overwrite them.`)}let w=[],T=[];for(let{key:t,item:r}of _.items){let i=x.get(t);for(let n of r.files){let o=i.get(n.path),s=rt(n,{key:t,item:r,destination:o,destinations:x,context:p,warnings:v}),l=await W(e,o);await c(a.dirname(l),{recursive:!0}),await f(l,s)}r.cssVars!==void 0&&T.push(...await jt(e,p.css,t,r.cssVars,{overwrite:n,warnings:v}));let o=[...i.values()];X(r)||(u.items[t]={version:r.version,files:o}),w.push({key:t,version:r.version,files:o,block:X(r)})}await U(e,u);let E=await pt(e,{npm:_.items.flatMap(({item:e})=>e.dependencies.npm),npmDev:_.items.flatMap(({item:e})=>e.dependencies.npmDev)},{confirm:i,skipInstall:r,warnings:v}),D=[],O=_.items[0]?.registry;if(g&&O!==void 0){let e=(await h(O).index()).license;e!==void 0&&D.push({namespace:O.namespace,url:e})}return{added:w,installed:_.installed,packages:E,cssChanges:T,licenses:D,warnings:v}}function Nt(e,t,n,r=!1){if(n.range!==void 0)return{version:Y(n,e)};if(r)return{version:e.latest};let i=Y({...n,range:`${h.major(t)}.x`},{...e,versions:{...e.versions,[t]:{hash:``,path:``}}}),a=h.gt(t,i)?t:i;return{version:a,newerMajor:h.major(e.latest)>h.major(a)?e.latest:void 0}}async function $({key:e,version:t,major:n,config:r,context:i,clientFor:o}){let s=K(t?`${e}@${t}`:e),c=s.name,u=r.items[c];if(u===void 0)throw new j(`"${c}" is not installed. Blocks and examples are not updated; for other items, use "slabui add ${c}".`);let d=J(r.token),f=o(d),p=(await f.index()).items[s.name];if(p===void 0)throw new j(`Item "${s.name}" no longer exists in the "${d.namespace}" registry.`);let m=Nt(p,u.version,s,n),h=await f.item(s.name,u.version),g=m.version===u.version?h:await f.item(s.name,m.version),_=[],v=async e=>{let t=/* @__PURE__ */ new Map([[c,Z(e,i)]]);await nt([e],{config:r,context:i,destinations:t,clientFor:o});let n=t.get(c);return new Map(e.files.map(r=>{let a=n.get(r.path);return[a,Pt(rt(r,{key:c,item:e,destination:a,destinations:t,context:i,warnings:_}))]}))},y=await v(h),b=await v(g),x=[.../* @__PURE__ */ new Set([...y.keys(),...b.keys()])];return{key:c,registry:d,base:h,remote:g,files:await Promise.all(x.map(async e=>{let t=await l(a.join(i.root,e),`utf8`).then(Pt).catch(()=>void 0);return{destination:e,base:y.get(e),remote:b.get(e),local:t}})),newerMajor:m.newerMajor,warnings:_}}function Pt(e){return e.replace(/\r\n/g,`
|
|
20
|
+
`)}async function Ft({root:e,ref:t,local:n=!1,major:r,createClient:i=e=>I(e)}){let a=await H(e),o=await R(e),s={root:e,aliases:a.aliases,tsconfig:o,css:B(o,e,a.css)},[c,l]=It(t),u=await $({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?[]:[v(`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 It(e){let t=e.indexOf(`@`,+!!e.startsWith(`@`));return t===-1?[e,void 0]:[e.slice(0,t),e.slice(t+1)]}async function Lt({root:e,refs:t=[],createClient:n=e=>I(e)}){let r=await H(e),i=t.length>0?[...new Set(t.map(e=>q(K(e))))]:Object.keys(r.items);for(let e of i)if(r.items[e]===void 0)throw new j(`"${e}" is not installed. Blocks and examples are not tracked in ${S}.`);return i.length===0?[]:Rt(r,i,await n(J(r.token)).index())}function Rt(e,t,n){return t.flatMap(t=>{let r=K(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??C.namespace,current:a,status:`missing`}];let s=Nt(o,a,{...r,range:void 0}).version,c=o.latest,l=a in o.versions?h.gt(s,a)||h.gt(c,a)?`outdated`:`current`:`unknown-version`;return[{key:t,registry:n.namespace??C.namespace,current:a,wanted:s,latest:c,status:l}]})}const zt={a:`local`,o:`base`,b:`remote`};async function Bt({root:e,refs:t,major:n=!1,overwrite:r=!1,skipInstall:i=!1,confirm:a,resolveConflict:o,createClient:s=e=>I(e)}){let c=await H(e),l=await R(e),u={root:e,aliases:c.aliases,tsconfig:l,css:B(l,e,c.css)},d=/* @__PURE__ */ new Map,f=e=>{let t=d.get(e.namespace);return t===void 0&&(t=s(e),d.set(e.namespace,t)),t},p={updated:[],upToDate:[],conflicts:[],added:[],packages:[],cssChanges:[],warnings:[]},m=(t.length>0?t:Object.keys(c.items)).map(e=>It(e)),g=/* @__PURE__ */ new Set,_=/* @__PURE__ */ new Set,v=[],y=[];for(;m.length>0;){let[t,i]=m.shift();if(g.has(t))continue;g.add(t);let s=await $({key:t,version:i,major:n,config:c,context:u,clientFor:f});p.warnings.push(...s.warnings),s.newerMajor&&p.warnings.push(`${s.key}@${s.newerMajor} is available (new major): slabui update ${s.key} --major`);let{base:l,remote:d}=s;if(d.version===l.version){p.upToDate.push(s.key);continue}let b=[];for(let t of s.files){let n=await Vt(t,{root:e,overwrite:r,confirm:a,resolveConflict:o,warnings:p.warnings});b.push({destination:t.destination,status:n}),n===`conflict`&&p.conflicts.push(t.destination)}(d.cssVars!==void 0||l.cssVars!==void 0)&&p.cssChanges.push(...await jt(e,u.css,s.key,d.cssVars??{},{base:l.cssVars??{},warnings:p.warnings,shouldRemove:r?async()=>!0:a&&((e,t)=>a(`--${t} (${e}) was removed in the new version of "${s.key}". Remove it from the CSS?`))})),c.items[s.key]={version:d.version,files:s.files.filter(e=>e.remote!==void 0).map(e=>e.destination)},p.updated.push({key:s.key,from:l.version,to:d.version,files:b});for(let e of d.dependencies.registry){let t=K(e),n=q(t),r=c.items[n];r===void 0?_.add(e):t.range!==void 0&&!h.satisfies(r.version,t.range)&&m.push([n,t.range])}v.push(...d.dependencies.npm),y.push(...d.dependencies.npmDev)}if(await U(e,c),_.size>0){let t=await Mt({root:e,refs:[..._],overwrite:r,skipInstall:i,confirm:a,createClient:f});p.added=t.added.map(({key:e})=>e),p.packages.push(...t.packages),p.warnings.push(...t.warnings)}return p.packages.push(...await pt(e,{npm:v,npmDev:y},{confirm:a,skipInstall:i,warnings:p.warnings})),p}async function Vt({destination:e,base:t,remote:n,local:r},{root:i,overwrite:o,confirm:s,resolveConflict:l,warnings:u}){let p=await W(i,e),m=async e=>{await c(a.dirname(p),{recursive:!0}),await f(p,e)};if(n===void 0)return r===void 0?`removed`:r===t||o||s!==void 0&&await s(`${e} was removed in the new version, but has local changes. Delete it?`)?(await d(p),`removed`):(u.push(`${e} was removed in the new version; kept because it has local changes.`),`kept`);if(t===void 0)return r===n?`unchanged`:r!==void 0&&!(o||s!==void 0&&await s(`${e} is new in this version, but already exists in the project. Overwrite it?`))?(u.push(`${e} already exists in the project and was not overwritten (--overwrite).`),`kept`):(await m(n),`added`);if(r===n)return`unchanged`;if(r===void 0||r===t)return r===void 0&&u.push(`${e} was missing from the project and was recreated.`),await m(n),`updated`;let h=y(r.split(`
|
|
21
|
+
`),t.split(`
|
|
22
|
+
`),n.split(`
|
|
23
|
+
`),{label:zt});if(!h.conflict)return await m(h.result.join(`
|
|
24
|
+
`)),`merged`;let g=l?await l(e):`markers`;return g===`local`?`kept`:g===`remote`?(await m(n),`updated`):(await m(h.result.join(`
|
|
25
|
+
`)),`conflict`)}async function Ht({token:e,fetch:t=globalThis.fetch,env:n=process.env,file:r=A(n)}){let i=J(void 0,n),a;try{a=await ie({registryUrl:i.url,token:e,fetch:t,headers:Ee(n,`login`)})}catch(e){throw e instanceof Error&&e.message.startsWith(`Error 404`)?new j(`${i.url} does not support login.`):new j(e instanceof Error&&e.message.startsWith(`Error `)?e.message:`Could not reach ${i.url}.`)}if(a===null)throw new j(`Invalid token. Check it and try again.`);return await re(e.trim(),r),{account:a,url:i.url,file:r}}async function Ut({root:e,onUrl:t,timeout:n=3e5,...r}){let i=J(void 0,r.env),a=ae();return Ht({root:e,token:await new Promise((e,r)=>{let o=b((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(Wt(o?`Signed in. You can close this tab and go back to the terminal.`:`Sign-in cancelled. You can close this tab.`)),c(()=>o?e(o):r(new j(`Sign-in was cancelled in the browser.`)))}),s=setTimeout(()=>c(()=>r(new j(`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(oe({registryUrl:i.url,callback:`http://127.0.0.1:${e}/callback`,state:a,client:`SlabUI CLI`}))})}),...r})}function Wt(e){return`<!doctype html><meta charset="utf-8"><title>SlabUI</title><body style="font:16px system-ui;display:grid;place-items:center;height:100vh;margin:0"><p>${e}</p></body>`}function Gt(e,t,{type:n}={}){let r=/* @__PURE__ */ new Map,i=new x({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 Kt=e=>I(e);async function qt(e){return await L(a.join(e,`slabui.json`))?H(e):void 0}async function Jt({root:e,term:t,type:n,createClient:r=Kt}){let i=J((await qt(e))?.token);try{let e=await r(i).index();return{results:Gt([{namespace:i.namespace,isDefault:!0,index:e}],t,{type:n}),warnings:[]}}catch(e){return{results:[],warnings:[`"${i.namespace}": ${e.message}`]}}}async function Yt({root:e,ref:t,createClient:n=Kt}){let r=await qt(e),i=K(t),a=J(r?.token),o=n(a),s=(await o.index()).items[i.name];if(s===void 0)throw new j(`Item "${i.name}" does not exist in the "${a.namespace}" registry.`);let c=await o.item(i.name,Y(i,s)),l=q(i),u;if(r!==void 0){let t={root:e,aliases:r.aliases,tsconfig:await R(e)};u=c.files.map(e=>{try{return Qe(e,t)}catch{return e.path}})}return{key:l,registry:a,entry:s,item:c,installed:r?.items[l]?.version,destinations:u}}export{S as CONFIG_FILE,T as CONFIG_SCHEMA_URL,C as DEFAULT_REGISTRY,O as ITEM_ACCESS,D as ITEM_KINDS,te as MCP_CLIENTS,w as SITE_URL,j as SlabUIError,E as TELEMETRY_HEADERS,k as TOKEN_ENV,ee as WHOAMI_PATH,Mt as addItems,At as applyCssTemplate,$ as compareItem,Ne as configSchema,I as createRegistryClient,Re as detectDefaults,Ft as diffItem,ke as expandHeaders,je as hash,Be as initProject,Me as installedItemSchema,Yt as itemInfo,q as itemKey,Ht as login,Ut as loginWithBrowser,Lt as outdatedItems,K as parseItemRef,mt as planInstall,W as resolveProjectPath,J as resolveRegistry,Y as resolveVersion,Jt as searchItems,Gt as searchRegistries,Bt as updateItems};
|
|
26
|
+
//# sourceMappingURL=index.mjs.map
|