kira-kit 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,109 @@
1
+ import { existsSync, readFileSync, writeFileSync } from "fs";
2
+ import { join } from "path";
3
+ import type { ComponentsConfig } from "../types";
4
+
5
+ export const DEFAULT_REGISTRY_URL = "https://kira-kit.vercel.app/r";
6
+
7
+ const DEFAULT_CONFIG = {
8
+ $schema: "https://ui.shadcn.com/schema.json",
9
+ style: "base-nova",
10
+ rsc: false,
11
+ tsx: true,
12
+ registryUrl: DEFAULT_REGISTRY_URL,
13
+ tailwind: {
14
+ config: "",
15
+ css: "src/index.css",
16
+ baseColor: "neutral",
17
+ cssVariables: true,
18
+ prefix: "",
19
+ },
20
+ iconLibrary: "tabler",
21
+ aliases: {
22
+ components: "@/components",
23
+ utils: "@/lib/utils",
24
+ ui: "@/components/ui",
25
+ lib: "@/lib",
26
+ hooks: "@/hooks",
27
+ },
28
+ menuColor: "default",
29
+ menuAccent: "subtle",
30
+ registries: {},
31
+ } as const;
32
+
33
+ export function findConfigFile(cwd: string): string | null {
34
+ const paths = [join(cwd, "components.json"), join(cwd, "kira-kit.json")];
35
+
36
+ for (const path of paths) {
37
+ if (existsSync(path)) {
38
+ return path;
39
+ }
40
+ }
41
+
42
+ return null;
43
+ }
44
+
45
+ export function readConfig(cwd: string): ComponentsConfig | null {
46
+ const configPath = findConfigFile(cwd);
47
+
48
+ if (!configPath) {
49
+ return null;
50
+ }
51
+
52
+ try {
53
+ const content = readFileSync(configPath, "utf-8");
54
+ return JSON.parse(content) as ComponentsConfig;
55
+ } catch {
56
+ return null;
57
+ }
58
+ }
59
+
60
+ export function writeConfig(
61
+ cwd: string,
62
+ config: Partial<ComponentsConfig>,
63
+ ): void {
64
+ const existingConfig = readConfig(cwd);
65
+ const newConfig = { ...DEFAULT_CONFIG, ...existingConfig, ...config };
66
+
67
+ const configPath = join(cwd, "components.json");
68
+ writeFileSync(configPath, JSON.stringify(newConfig, null, 2) + "\n");
69
+ }
70
+
71
+ export function updateAliases(
72
+ cwd: string,
73
+ aliases: Partial<ComponentsConfig["aliases"]>,
74
+ ): void {
75
+ const config = readConfig(cwd);
76
+
77
+ if (!config) {
78
+ throw new Error("No components.json found. Run 'kira-kit init' first.");
79
+ }
80
+
81
+ config.aliases = { ...config.aliases, ...aliases };
82
+
83
+ const configPath = join(cwd, "components.json");
84
+ writeFileSync(configPath, JSON.stringify(config, null, 2) + "\n");
85
+ }
86
+
87
+ export function getAliases(cwd: string): ComponentsConfig["aliases"] {
88
+ const config = readConfig(cwd);
89
+
90
+ if (!config) {
91
+ return DEFAULT_CONFIG.aliases;
92
+ }
93
+
94
+ return config.aliases;
95
+ }
96
+
97
+ export function getRegistryUrl(cwd: string): string {
98
+ const config = readConfig(cwd);
99
+
100
+ if (!config) {
101
+ return "https://kira-kit.vercel.app/r";
102
+ }
103
+
104
+ if (config.registries && "@kira-kit" in config.registries) {
105
+ return config.registries["@kira-kit"];
106
+ }
107
+
108
+ return "https://kira-kit.vercel.app/r";
109
+ }
@@ -0,0 +1,135 @@
1
+ import { execSync } from "child_process";
2
+ import { existsSync } from "fs";
3
+ import { join } from "path";
4
+ import picocolors from "picocolors";
5
+
6
+ const PACKAGE_MANAGER = detectPackageManager();
7
+
8
+ function detectPackageManager(): "bun" | "pnpm" | "npm" | "yarn" {
9
+ const userAgent = process.env.npm_config_user_agent || "";
10
+
11
+ if (userAgent.startsWith("bun")) return "bun";
12
+ if (userAgent.startsWith("pnpm")) return "pnpm";
13
+ if (userAgent.startsWith("yarn")) return "yarn";
14
+ if (userAgent.startsWith("npm")) return "npm";
15
+
16
+ if (process.env.BUN_INSTALL) return "bun";
17
+ if (process.env.PNPM_HOME) return "pnpm";
18
+ if (process.env.YARN_ENABLE_IMMUTABLE_CACHE === "false") return "yarn";
19
+
20
+ return "bun";
21
+ }
22
+
23
+ function getInstallCmd(dependencies: string[]): string {
24
+ const pkgManager = PACKAGE_MANAGER;
25
+
26
+ switch (pkgManager) {
27
+ case "bun":
28
+ return `bun add ${dependencies.join(" ")}`;
29
+ case "pnpm":
30
+ return `pnpm add ${dependencies.join(" ")}`;
31
+ case "yarn":
32
+ return `yarn add ${dependencies.join(" ")}`;
33
+ default:
34
+ return `npm install ${dependencies.join(" ")}`;
35
+ }
36
+ }
37
+
38
+ function getDevInstallCmd(dependencies: string[]): string {
39
+ const pkgManager = PACKAGE_MANAGER;
40
+
41
+ switch (pkgManager) {
42
+ case "bun":
43
+ return `bun add -D ${dependencies.join(" ")}`;
44
+ case "pnpm":
45
+ return `pnpm add -D ${dependencies.join(" ")}`;
46
+ case "yarn":
47
+ return `yarn add -D ${dependencies.join(" ")}`;
48
+ default:
49
+ return `npm install -D ${dependencies.join(" ")}`;
50
+ }
51
+ }
52
+
53
+ export async function parseDependencies(
54
+ componentContent: string
55
+ ): Promise<string[]> {
56
+ const deps = new Set<string>();
57
+
58
+ const npmPackages = [
59
+ "clsx",
60
+ "tailwind-merge",
61
+ "class-variance-authority",
62
+ "@tabler/icons-react",
63
+ "date-fns",
64
+ "react-day-picker",
65
+ "react-resizable-panels",
66
+ "@tanstack/react-table",
67
+ "@tanstack/react-virtual",
68
+ "@uiw/color-convert",
69
+ "@uiw/react-color-hue",
70
+ "@uiw/react-color-saturation",
71
+ "@dnd-kit/core",
72
+ "@dnd-kit/sortable",
73
+ "@dnd-kit/utilities",
74
+ "cmdk",
75
+ "embla-carousel-react",
76
+ "sonner",
77
+ "animejs",
78
+ "gsap",
79
+ "@gsap/react",
80
+ ];
81
+
82
+ for (const pkg of npmPackages) {
83
+ const regex = new RegExp(
84
+ `from\\s+["']${pkg.replace("/", "\\/")}[@^~]?[\\d.]*["']`,
85
+ "g"
86
+ );
87
+ if (regex.test(componentContent)) {
88
+ deps.add(pkg);
89
+ }
90
+ }
91
+
92
+ if (
93
+ componentContent.includes('from "class-variance-authority"') ||
94
+ componentContent.includes("from 'class-variance-authority'")
95
+ ) {
96
+ deps.add("class-variance-authority");
97
+ }
98
+
99
+ return Array.from(deps).sort();
100
+ }
101
+
102
+ export async function installDependencies(
103
+ dependencies: string[],
104
+ isDev: boolean = false
105
+ ): Promise<void> {
106
+ if (dependencies.length === 0) return;
107
+
108
+ console.log(picocolors.cyan(`Installing dependencies...`));
109
+
110
+ const cmd = isDev
111
+ ? getDevInstallCmd(dependencies)
112
+ : getInstallCmd(dependencies);
113
+
114
+ try {
115
+ execSync(cmd, {
116
+ stdio: "inherit",
117
+ cwd: process.cwd(),
118
+ env: { ...process.env, ADBLOCK: "1", DISABLE_OPENCOLLECTIVE: "1" },
119
+ });
120
+ } catch (error) {
121
+ throw new Error(`Failed to install dependencies: ${error}`);
122
+ }
123
+ }
124
+
125
+ export function getPackageManager(): string {
126
+ return PACKAGE_MANAGER;
127
+ }
128
+
129
+ export async function initPackageJson(): Promise<void> {
130
+ const packageJsonPath = join(process.cwd(), "package.json");
131
+
132
+ if (!existsSync(packageJsonPath)) {
133
+ execSync('echo "{}" > package.json', { stdio: "inherit" });
134
+ }
135
+ }
@@ -0,0 +1,64 @@
1
+ import { existsSync, readFileSync, writeFileSync, mkdirSync, cpSync, rmSync } from "fs";
2
+ import { dirname, join, relative } from "path";
3
+
4
+ export async function readFile(filePath: string): Promise<string> {
5
+ return readFileSync(filePath, "utf-8");
6
+ }
7
+
8
+ export async function writeFile(
9
+ filePath: string,
10
+ content: string
11
+ ): Promise<void> {
12
+ const dir = dirname(filePath);
13
+ if (!existsSync(dir)) {
14
+ mkdirSync(dir, { recursive: true });
15
+ }
16
+ writeFileSync(filePath, content, "utf-8");
17
+ }
18
+
19
+ export async function copyFile(
20
+ source: string,
21
+ destination: string
22
+ ): Promise<void> {
23
+ const dir = dirname(destination);
24
+ if (!existsSync(dir)) {
25
+ mkdirSync(dir, { recursive: true });
26
+ }
27
+ cpSync(source, destination);
28
+ }
29
+
30
+ export async function copyDirectory(
31
+ source: string,
32
+ destination: string
33
+ ): Promise<void> {
34
+ if (!existsSync(destination)) {
35
+ mkdirSync(destination, { recursive: true });
36
+ }
37
+ cpSync(source, destination, { recursive: true });
38
+ }
39
+
40
+ export function fileExists(filePath: string): boolean {
41
+ return existsSync(filePath);
42
+ }
43
+
44
+ export async function removeFile(filePath: string): Promise<void> {
45
+ if (existsSync(filePath)) {
46
+ rmSync(filePath);
47
+ }
48
+ }
49
+
50
+ export async function removeDirectory(dirPath: string): Promise<void> {
51
+ if (existsSync(dirPath)) {
52
+ rmSync(dirPath, { recursive: true });
53
+ }
54
+ }
55
+
56
+ export function getRelativePath(from: string, to: string): string {
57
+ return relative(from, to);
58
+ }
59
+
60
+ export function ensureDir(dirPath: string): void {
61
+ if (!existsSync(dirPath)) {
62
+ mkdirSync(dirPath, { recursive: true });
63
+ }
64
+ }
@@ -0,0 +1,102 @@
1
+ import picocolors from "picocolors";
2
+
3
+ export const colors = {
4
+ primary: picocolors.cyan,
5
+ success: picocolors.green,
6
+ error: picocolors.red,
7
+ warning: picocolors.yellow,
8
+ dim: picocolors.dim,
9
+ bold: picocolors.bold,
10
+ italic: picocolors.italic,
11
+ };
12
+
13
+ export function log(message: string): void {
14
+ console.log(message);
15
+ }
16
+
17
+ export function info(message: string): void {
18
+ console.log(colors.primary("info") + " " + message);
19
+ }
20
+
21
+ export function success(message: string): void {
22
+ console.log(colors.success("success") + " " + message);
23
+ }
24
+
25
+ export function error(message: string): void {
26
+ console.error(colors.error("error") + " " + message);
27
+ }
28
+
29
+ export function warning(message: string): void {
30
+ console.warn(colors.warning("warning") + " " + message);
31
+ }
32
+
33
+ export function banner(text: string): void {
34
+ const line = "=".repeat(text.length + 4);
35
+ console.log(
36
+ picocolors.cyan(`
37
+ ${line}
38
+ ${text}
39
+ ${line}
40
+ `),
41
+ );
42
+ }
43
+
44
+ export function welcome(name: string): void {
45
+ console.log(
46
+ picocolors.cyan(`
47
+ ██╗ ██╗██╗██████╗ █████╗ ██╗ ██╗██╗████████╗
48
+ ██║ ██╔╝██║██╔══██╗██╔══██╗ ██║ ██╔╝██║╚══██╔══╝
49
+ █████╔╝ ██║██████╔╝███████║█████╗█████╔╝ ██║ ██║
50
+ ██╔═██╗ ██║██╔══██╗██╔══██║╚════╝██╔═██╗ ██║ ██║
51
+ ██║ ██╗██║██║ ██║██║ ██║ ██║ ██╗██║ ██║
52
+ ╚═╝ ╚═╝╚═╝╚═╝ ╚═╝╚═╝ ╚═╝ ╚═╝ ╚═╝╚═╝ ╚═╝
53
+
54
+ CLI v0.2.0. Welcome!
55
+ `),
56
+ );
57
+ }
58
+
59
+ export function spinner(message: string): {
60
+ start(): void;
61
+ stop(msg: string): void;
62
+ } {
63
+ const frames = ["⠋", "⠙", "⠹", "⠸", "⠼", "⠴", "⠦", "⠧", "⠇", "⠏"];
64
+ let interval: ReturnType<typeof setInterval>;
65
+ let i = 0;
66
+
67
+ return {
68
+ start() {
69
+ process.stdout.write(colors.dim(message) + " " + frames[0] + " \r");
70
+ interval = setInterval(() => {
71
+ process.stdout.write(
72
+ "\r" + colors.dim(message) + " " + frames[i] + " \r",
73
+ );
74
+ i = (i + 1) % frames.length;
75
+ }, 80);
76
+ },
77
+ stop(msg: string) {
78
+ clearInterval(interval);
79
+ process.stdout.write("\r" + " ".repeat(message.length + 5) + "\r");
80
+ success(msg);
81
+ },
82
+ };
83
+ }
84
+
85
+ export function table(rows: string[][]): void {
86
+ const maxLengths: number[] = [];
87
+
88
+ for (const row of rows) {
89
+ row.forEach((cell, i) => {
90
+ maxLengths[i] = Math.max(maxLengths[i] || 0, cell.length);
91
+ });
92
+ }
93
+
94
+ for (const row of rows) {
95
+ const line = row.map((cell, i) => cell.padEnd(maxLengths[i])).join(" ");
96
+ console.log(line);
97
+ }
98
+ }
99
+
100
+ export function dim(message: string): string {
101
+ return colors.dim(message);
102
+ }
@@ -0,0 +1,81 @@
1
+ import type { RegistryItem } from "../types";
2
+
3
+ import { getRegistryUrl } from "./config";
4
+
5
+ export async function fetchRegistryItem(
6
+ componentName: string,
7
+ cwd: string = process.cwd(),
8
+ ): Promise<RegistryItem | null> {
9
+ const registryUrl = getRegistryUrl(cwd);
10
+ const url = `${registryUrl}/${componentName}.json`;
11
+
12
+ try {
13
+ const response = await fetch(url);
14
+
15
+ if (!response.ok) {
16
+ if (response.status === 404) {
17
+ return null;
18
+ }
19
+ throw new Error(`Failed to fetch ${url}: ${response.statusText}`);
20
+ }
21
+
22
+ const data = await response.json();
23
+ return data as RegistryItem;
24
+ } catch (error) {
25
+ if (error instanceof TypeError && error.message.includes("fetch")) {
26
+ throw new Error(
27
+ `Unable to fetch from ${url}. Make sure you're connected to the internet.`,
28
+ );
29
+ }
30
+ throw error;
31
+ }
32
+ }
33
+
34
+ export async function fetchRegistryIndex(cwd: string = process.cwd()): Promise<{
35
+ name: string;
36
+ homepage: string;
37
+ components: Array<{
38
+ name: string;
39
+ title: string;
40
+ dependencies: string[];
41
+ registryDependencies: string[];
42
+ }>;
43
+ }> {
44
+ const registryUrl = getRegistryUrl(cwd);
45
+ const url = `${registryUrl}/index.json`;
46
+
47
+ const response = await fetch(url);
48
+
49
+ if (!response.ok) {
50
+ throw new Error(`Failed to fetch registry index: ${response.statusText}`);
51
+ }
52
+
53
+ const data = await response.json();
54
+ return data as {
55
+ name: string;
56
+ homepage: string;
57
+ components: Array<{
58
+ name: string;
59
+ title: string;
60
+ dependencies: string[];
61
+ registryDependencies: string[];
62
+ }>;
63
+ };
64
+ }
65
+
66
+ export async function fetchAllRegistries(
67
+ cwd: string = process.cwd(),
68
+ ): Promise<RegistryItem[]> {
69
+ const index = await fetchRegistryIndex(cwd);
70
+
71
+ const items: RegistryItem[] = [];
72
+
73
+ for (const component of index.components) {
74
+ const item = await fetchRegistryItem(component.name, cwd);
75
+ if (item) {
76
+ items.push(item);
77
+ }
78
+ }
79
+
80
+ return items;
81
+ }
@@ -0,0 +1,123 @@
1
+ export const STATIC_STYLES = `
2
+ /* Mac-like scrollbar styling with cross-browser support */
3
+ @layer base {
4
+ /* Standard scrollbar styling (Firefox) */
5
+ * {
6
+ scrollbar-width: thin;
7
+ scrollbar-color: var(--scrollbar-thumb) var(--scrollbar-track);
8
+ }
9
+
10
+ :root {
11
+ --scrollbar-thumb: oklch(0.7 0 0 / 40%);
12
+ --scrollbar-track: transparent;
13
+ --scrollbar-thumb-hover: oklch(0.6 0 0 / 60%);
14
+ }
15
+
16
+ .dark {
17
+ --scrollbar-thumb: oklch(0.5 0 0 / 40%);
18
+ --scrollbar-thumb-hover: oklch(0.6 0 0 / 60%);
19
+ }
20
+
21
+ /* Webkit scrollbar styling (Chrome, Safari, Edge) */
22
+ ::-webkit-scrollbar {
23
+ width: 8px;
24
+ height: 8px;
25
+ }
26
+
27
+ ::-webkit-scrollbar-track {
28
+ background: var(--scrollbar-track);
29
+ border-radius: 4px;
30
+ }
31
+
32
+ ::-webkit-scrollbar-thumb {
33
+ background: var(--scrollbar-thumb);
34
+ border-radius: 4px;
35
+ border: 2px solid transparent;
36
+ background-clip: content-box;
37
+ }
38
+
39
+ ::-webkit-scrollbar-thumb:hover {
40
+ background: var(--scrollbar-thumb-hover);
41
+ background-clip: content-box;
42
+ }
43
+
44
+ ::-webkit-scrollbar-corner {
45
+ background: transparent;
46
+ }
47
+
48
+ /* Accessibility: Respect user preferences for reduced motion */
49
+ @media (prefers-reduced-motion: reduce) {
50
+ ::-webkit-scrollbar-thumb {
51
+ transition: none;
52
+ }
53
+ }
54
+
55
+ /* Accessibility: High contrast mode support */
56
+ @media (forced-colors: active) {
57
+ ::-webkit-scrollbar-thumb {
58
+ background: CanvasText;
59
+ }
60
+ ::-webkit-scrollbar-track {
61
+ background: Canvas;
62
+ }
63
+ }
64
+ }
65
+
66
+ /* Shimmer animation for skeleton loading */
67
+ @keyframes shimmer {
68
+ 0% { transform: translateX(-100%); }
69
+ 100% { transform: translateX(100%); }
70
+ }
71
+
72
+ /* Wave animation for skeleton loading */
73
+ @keyframes skeleton-wave {
74
+ 0%, 100% { opacity: 1; }
75
+ 50% { opacity: 0.5; }
76
+ }
77
+
78
+ /* Progress bar animations */
79
+ @keyframes progress-stripes {
80
+ from { background-position: 1rem 0; }
81
+ to { background-position: 0 0; }
82
+ }
83
+
84
+ @keyframes progress-indeterminate {
85
+ 0% { transform: translateX(-100%); }
86
+ 100% { transform: translateX(400%); }
87
+ }
88
+
89
+ /* Date Picker Calendar Styles */
90
+ @layer components {
91
+ .rdp-nav, .rdp-button_previous, .rdp-button_next { display: none !important; }
92
+ .rdp-month_caption { margin-top: 0 !important; padding-top: 0 !important; }
93
+ .rdp-months { margin-top: 0 !important; padding-top: 0 !important; }
94
+ [data-picker-grid], [data-picker-container] { width: 100% !important; min-width: 0; }
95
+
96
+ .rdp-day_selected { @apply bg-primary text-primary-foreground rounded-md; }
97
+ .rdp-day_selected:hover { @apply bg-primary/90; }
98
+ .rdp-day_selected .rdp-day_button { @apply ring-0 outline-none; box-shadow: none !important; border: none !important; }
99
+
100
+ .rdp-day_today:not(.rdp-day_selected) { @apply bg-muted/30; }
101
+ .rdp-day_today:not(.rdp-day_selected) .rdp-day_button::after {
102
+ content: ""; position: absolute; bottom: 2px; left: 50%; transform: translateX(-50%);
103
+ width: 4px; height: 4px; border-radius: 50%; background-color: var(--primary);
104
+ }
105
+
106
+ .rdp-day_selected .rdp-day_button::after, .rdp-day_today.rdp-day_selected .rdp-day_button::after { display: none !important; }
107
+
108
+ .rdp-day_button { @apply rounded-md; }
109
+ .rdp-day_button:hover:not(.rdp-day_selected):not(.rdp-day_disabled) { @apply bg-muted/50; }
110
+ .rdp-day_button:focus-visible { @apply ring-2 ring-ring ring-offset-2 ring-offset-background; }
111
+
112
+ .rdp-day_range_start, .rdp-day_range_end { @apply bg-primary text-primary-foreground rounded-md; }
113
+ .rdp-day_range_middle { @apply bg-primary/10 rounded-none; }
114
+ .rdp-day_range_middle:hover { @apply bg-primary/15; }
115
+ .rdp-day_range_middle .rdp-day_button { @apply text-foreground font-medium; color: var(--foreground) !important; }
116
+
117
+ @media (forced-colors: active) {
118
+ .rdp-day_selected { @apply bg-[Highlight] text-[HighlightText]; }
119
+ .rdp-day_today:not(.rdp-day_selected) { @apply border-2 border-[Highlight]; }
120
+ .rdp-day_today .rdp-day_button::after { background-color: Highlight; }
121
+ }
122
+ }
123
+ `;