@openpkg-ts/ui 0.1.6 → 0.1.7

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/dist/api/index.js DELETED
@@ -1,435 +0,0 @@
1
- "use client";
2
- // src/api/CodeTabs.tsx
3
- import { Check, Copy } from "lucide-react";
4
- import { useState } from "react";
5
-
6
- // src/lib/utils.ts
7
- import { clsx } from "clsx";
8
- import { twMerge } from "tailwind-merge";
9
- function cn(...inputs) {
10
- return twMerge(clsx(inputs));
11
- }
12
-
13
- // src/api/CodeTabs.tsx
14
- import { jsx, jsxs } from "react/jsx-runtime";
15
-
16
- function CodeTabs({
17
- tabs,
18
- defaultIndex = 0,
19
- sticky = false,
20
- className
21
- }) {
22
- const [activeIndex, setActiveIndex] = useState(defaultIndex);
23
- const [copied, setCopied] = useState(false);
24
- const activeTab = tabs[activeIndex];
25
- const handleCopy = () => {
26
- if (!activeTab)
27
- return;
28
- navigator.clipboard.writeText(activeTab.code);
29
- setCopied(true);
30
- setTimeout(() => setCopied(false), 1200);
31
- };
32
- if (!tabs.length)
33
- return null;
34
- return /* @__PURE__ */ jsxs("div", {
35
- className: cn("group rounded-lg border border-dk-border bg-dk-background overflow-hidden", "selection:bg-dk-selection selection:text-current", className),
36
- children: [
37
- /* @__PURE__ */ jsxs("div", {
38
- className: cn("flex items-center border-b border-dk-border bg-dk-tabs-background", sticky && "sticky top-0 z-10"),
39
- children: [
40
- /* @__PURE__ */ jsx("div", {
41
- className: "flex-1 flex items-stretch",
42
- children: tabs.map((tab, index) => /* @__PURE__ */ jsx("button", {
43
- type: "button",
44
- onClick: () => setActiveIndex(index),
45
- className: cn("px-4 py-2 text-sm font-mono transition-colors duration-200", "border-r border-dk-border last:border-r-0", index === activeIndex ? "text-dk-tab-active-foreground bg-dk-background/50" : "text-dk-tab-inactive-foreground hover:text-dk-tab-active-foreground"),
46
- children: tab.label
47
- }, tab.label))
48
- }),
49
- /* @__PURE__ */ jsx("button", {
50
- type: "button",
51
- onClick: handleCopy,
52
- className: cn("p-2 mx-2", "text-dk-tab-inactive-foreground hover:text-dk-tab-active-foreground", "opacity-0 group-hover:opacity-100 transition-opacity", "cursor-pointer"),
53
- "aria-label": "Copy code",
54
- children: copied ? /* @__PURE__ */ jsx(Check, {
55
- size: 16
56
- }) : /* @__PURE__ */ jsx(Copy, {
57
- size: 16
58
- })
59
- })
60
- ]
61
- }),
62
- /* @__PURE__ */ jsx("div", {
63
- className: "bg-dk-background",
64
- children: activeTab?.content
65
- })
66
- ]
67
- });
68
- }
69
- // src/api/ExportCard.tsx
70
- import { cva } from "class-variance-authority";
71
- import * as React from "react";
72
- import { jsx as jsx2, jsxs as jsxs2 } from "react/jsx-runtime";
73
-
74
- var kindBadgeVariants = cva("inline-flex items-center justify-center font-mono font-medium rounded shrink-0 h-5 px-1.5 text-xs", {
75
- variants: {
76
- kind: {
77
- function: "bg-fuchsia-500/15 text-fuchsia-600 dark:text-fuchsia-400",
78
- class: "bg-amber-500/15 text-amber-600 dark:text-amber-400",
79
- interface: "bg-cyan-500/15 text-cyan-600 dark:text-cyan-400",
80
- type: "bg-purple-500/15 text-purple-600 dark:text-purple-400",
81
- enum: "bg-emerald-500/15 text-emerald-600 dark:text-emerald-400",
82
- variable: "bg-blue-500/15 text-blue-600 dark:text-blue-400"
83
- }
84
- },
85
- defaultVariants: {
86
- kind: "function"
87
- }
88
- });
89
- var kindLabels = {
90
- function: "fn",
91
- class: "cls",
92
- interface: "int",
93
- type: "type",
94
- enum: "enum",
95
- variable: "var"
96
- };
97
- var ExportCard = React.forwardRef(({ name, description, href, kind = "function", as: Component = "a", className, ...props }, ref) => {
98
- const isFunction = kind === "function";
99
- return /* @__PURE__ */ jsxs2(Component, {
100
- ref,
101
- href,
102
- className: cn("group block rounded-lg border border-border bg-card/50 p-4", "transition-all duration-200", "hover:border-border/80 hover:bg-card hover:shadow-md", "hover:-translate-y-0.5", className),
103
- ...props,
104
- children: [
105
- /* @__PURE__ */ jsxs2("div", {
106
- className: "flex items-center gap-2 mb-2",
107
- children: [
108
- /* @__PURE__ */ jsx2("span", {
109
- className: kindBadgeVariants({ kind }),
110
- children: kindLabels[kind]
111
- }),
112
- /* @__PURE__ */ jsx2("span", {
113
- className: "font-mono text-base font-medium text-foreground group-hover:text-primary transition-colors",
114
- children: name
115
- }),
116
- isFunction && /* @__PURE__ */ jsx2("span", {
117
- className: "font-mono text-base text-muted-foreground",
118
- children: "()"
119
- })
120
- ]
121
- }),
122
- description && /* @__PURE__ */ jsx2("p", {
123
- className: "text-sm text-muted-foreground line-clamp-2 leading-relaxed",
124
- children: description
125
- })
126
- ]
127
- });
128
- });
129
- ExportCard.displayName = "ExportCard";
130
- // src/api/ImportSection.tsx
131
- import { Check as Check2, Copy as Copy2 } from "lucide-react";
132
- import { useState as useState2 } from "react";
133
- import { jsx as jsx3, jsxs as jsxs3 } from "react/jsx-runtime";
134
-
135
- function ImportSection({ importStatement, className }) {
136
- const [copied, setCopied] = useState2(false);
137
- const handleCopy = () => {
138
- navigator.clipboard.writeText(importStatement);
139
- setCopied(true);
140
- setTimeout(() => setCopied(false), 1200);
141
- };
142
- return /* @__PURE__ */ jsxs3("div", {
143
- className: cn("group flex items-center justify-between gap-3", "rounded-lg border border-border bg-muted/30 px-4 py-3", className),
144
- children: [
145
- /* @__PURE__ */ jsx3("code", {
146
- className: "font-mono text-sm text-foreground overflow-x-auto",
147
- children: importStatement
148
- }),
149
- /* @__PURE__ */ jsx3("button", {
150
- type: "button",
151
- onClick: handleCopy,
152
- className: cn("shrink-0 p-1.5 rounded", "text-muted-foreground hover:text-foreground", "opacity-0 group-hover:opacity-100 transition-opacity duration-200", "cursor-pointer"),
153
- "aria-label": "Copy import statement",
154
- children: copied ? /* @__PURE__ */ jsx3(Check2, {
155
- size: 16
156
- }) : /* @__PURE__ */ jsx3(Copy2, {
157
- size: 16
158
- })
159
- })
160
- ]
161
- });
162
- }
163
- // src/api/ParameterItem.tsx
164
- import { ChevronRight } from "lucide-react";
165
- import { useState as useState3 } from "react";
166
- import { jsx as jsx4, jsxs as jsxs4 } from "react/jsx-runtime";
167
-
168
- function getNestedProperties(schema) {
169
- if (!schema || typeof schema !== "object")
170
- return null;
171
- if (schema.type === "object" && schema.properties) {
172
- return schema.properties;
173
- }
174
- return null;
175
- }
176
- function getRequiredFields(schema) {
177
- return schema.required ?? [];
178
- }
179
- function countProperties(schema) {
180
- const props = getNestedProperties(schema);
181
- return props ? Object.keys(props).length : 0;
182
- }
183
- function getTypeDisplay(schema) {
184
- if (schema.typeString)
185
- return schema.typeString;
186
- return schema.type ?? "unknown";
187
- }
188
- function NestedPropertyItem({
189
- name,
190
- schema,
191
- required = false,
192
- depth = 0
193
- }) {
194
- const [expanded, setExpanded] = useState3(false);
195
- const type = getTypeDisplay(schema);
196
- const nestedProps = getNestedProperties(schema);
197
- const nestedCount = countProperties(schema);
198
- const hasNested = nestedCount > 0;
199
- return /* @__PURE__ */ jsxs4("div", {
200
- className: cn("border-t border-border first:border-t-0", depth > 0 && "ml-4"),
201
- children: [
202
- /* @__PURE__ */ jsx4("div", {
203
- className: "py-3",
204
- children: /* @__PURE__ */ jsxs4("div", {
205
- className: "flex items-start gap-2",
206
- children: [
207
- hasNested && /* @__PURE__ */ jsx4("button", {
208
- type: "button",
209
- onClick: () => setExpanded(!expanded),
210
- className: "mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",
211
- "aria-label": expanded ? "Collapse" : "Expand",
212
- children: /* @__PURE__ */ jsx4(ChevronRight, {
213
- size: 14,
214
- className: cn("transition-transform duration-200", expanded && "rotate-90")
215
- })
216
- }),
217
- !hasNested && /* @__PURE__ */ jsx4("div", {
218
- className: "w-5"
219
- }),
220
- /* @__PURE__ */ jsxs4("div", {
221
- className: "flex-1 min-w-0",
222
- children: [
223
- /* @__PURE__ */ jsxs4("div", {
224
- className: "flex items-baseline gap-2 flex-wrap",
225
- children: [
226
- /* @__PURE__ */ jsxs4("span", {
227
- className: "font-mono text-sm text-foreground",
228
- children: [
229
- name,
230
- !required && /* @__PURE__ */ jsx4("span", {
231
- className: "text-muted-foreground",
232
- children: "?"
233
- })
234
- ]
235
- }),
236
- /* @__PURE__ */ jsx4("span", {
237
- className: "font-mono text-sm text-muted-foreground",
238
- children: hasNested ? "object" : type
239
- }),
240
- hasNested && /* @__PURE__ */ jsxs4("button", {
241
- type: "button",
242
- onClick: () => setExpanded(!expanded),
243
- className: "text-xs text-primary hover:underline cursor-pointer",
244
- children: [
245
- nestedCount,
246
- " ",
247
- nestedCount === 1 ? "property" : "properties"
248
- ]
249
- })
250
- ]
251
- }),
252
- schema.description && /* @__PURE__ */ jsx4("p", {
253
- className: "text-sm text-muted-foreground mt-1",
254
- children: schema.description
255
- })
256
- ]
257
- })
258
- ]
259
- })
260
- }),
261
- hasNested && expanded && nestedProps && /* @__PURE__ */ jsx4("div", {
262
- className: "border-l border-border ml-2",
263
- children: Object.entries(nestedProps).map(([propName, propSchema]) => /* @__PURE__ */ jsx4(NestedPropertyItem, {
264
- name: propName,
265
- schema: propSchema,
266
- required: getRequiredFields(schema).includes(propName),
267
- depth: depth + 1
268
- }, propName))
269
- })
270
- ]
271
- });
272
- }
273
- function ParameterItem({
274
- name,
275
- schema,
276
- required: isRequired = true,
277
- description,
278
- depth = 0,
279
- className
280
- }) {
281
- const [expanded, setExpanded] = useState3(false);
282
- const type = getTypeDisplay(schema);
283
- const nestedProps = getNestedProperties(schema);
284
- const nestedCount = countProperties(schema);
285
- const hasNested = nestedCount > 0;
286
- const displayDescription = description ?? schema.description;
287
- return /* @__PURE__ */ jsxs4("div", {
288
- className: cn("border-b border-border last:border-b-0", className),
289
- children: [
290
- /* @__PURE__ */ jsx4("div", {
291
- className: "py-3",
292
- children: /* @__PURE__ */ jsxs4("div", {
293
- className: "flex items-start gap-2",
294
- children: [
295
- hasNested && /* @__PURE__ */ jsx4("button", {
296
- type: "button",
297
- onClick: () => setExpanded(!expanded),
298
- className: "mt-0.5 p-0.5 text-muted-foreground hover:text-foreground transition-colors cursor-pointer",
299
- "aria-label": expanded ? "Collapse" : "Expand",
300
- children: /* @__PURE__ */ jsx4(ChevronRight, {
301
- size: 14,
302
- className: cn("transition-transform duration-200", expanded && "rotate-90")
303
- })
304
- }),
305
- !hasNested && /* @__PURE__ */ jsx4("div", {
306
- className: "w-5"
307
- }),
308
- /* @__PURE__ */ jsxs4("div", {
309
- className: "flex-1 min-w-0",
310
- children: [
311
- /* @__PURE__ */ jsxs4("div", {
312
- className: "flex items-baseline gap-2 flex-wrap",
313
- children: [
314
- /* @__PURE__ */ jsx4("span", {
315
- className: "font-mono text-sm font-medium text-foreground",
316
- children: name
317
- }),
318
- isRequired && /* @__PURE__ */ jsx4("span", {
319
- className: "text-[10px] font-semibold px-1.5 py-0.5 rounded border border-border bg-muted text-muted-foreground uppercase tracking-wide",
320
- children: "Required"
321
- }),
322
- /* @__PURE__ */ jsx4("span", {
323
- className: "font-mono text-sm text-muted-foreground",
324
- children: hasNested ? "object" : type
325
- }),
326
- hasNested && /* @__PURE__ */ jsxs4("button", {
327
- type: "button",
328
- onClick: () => setExpanded(!expanded),
329
- className: "text-xs text-primary hover:underline cursor-pointer",
330
- children: [
331
- nestedCount,
332
- " ",
333
- nestedCount === 1 ? "property" : "properties"
334
- ]
335
- })
336
- ]
337
- }),
338
- displayDescription && /* @__PURE__ */ jsx4("p", {
339
- className: "text-sm text-muted-foreground mt-1",
340
- children: displayDescription
341
- })
342
- ]
343
- })
344
- ]
345
- })
346
- }),
347
- hasNested && expanded && nestedProps && /* @__PURE__ */ jsx4("div", {
348
- className: "border-l border-border ml-2 mb-3",
349
- children: Object.entries(nestedProps).map(([propName, propSchema]) => /* @__PURE__ */ jsx4(NestedPropertyItem, {
350
- name: propName,
351
- schema: propSchema,
352
- required: getRequiredFields(schema).includes(propName),
353
- depth: depth + 1
354
- }, propName))
355
- })
356
- ]
357
- });
358
- }
359
- // src/api/TypeBadge.tsx
360
- import { cva as cva2 } from "class-variance-authority";
361
- import * as React2 from "react";
362
- import { jsx as jsx5 } from "react/jsx-runtime";
363
- var typeBadgeVariants = cva2("font-mono text-sm", {
364
- variants: {
365
- typeColor: {
366
- string: "text-emerald-600 dark:text-emerald-400",
367
- number: "text-blue-600 dark:text-blue-400",
368
- boolean: "text-amber-600 dark:text-amber-400",
369
- null: "text-gray-500 dark:text-gray-400",
370
- undefined: "text-gray-500 dark:text-gray-400",
371
- object: "text-purple-600 dark:text-purple-400",
372
- array: "text-cyan-600 dark:text-cyan-400",
373
- function: "text-fuchsia-600 dark:text-fuchsia-400",
374
- union: "text-orange-600 dark:text-orange-400",
375
- generic: "text-rose-600 dark:text-rose-400",
376
- default: "text-muted-foreground"
377
- }
378
- },
379
- defaultVariants: {
380
- typeColor: "default"
381
- }
382
- });
383
- function detectTypeColor(type) {
384
- const normalized = type.toLowerCase().trim();
385
- if (normalized === "string" || normalized.startsWith('"') || normalized.startsWith("'")) {
386
- return "string";
387
- }
388
- if (normalized === "number" || /^\d+$/.test(normalized)) {
389
- return "number";
390
- }
391
- if (normalized === "boolean" || normalized === "true" || normalized === "false") {
392
- return "boolean";
393
- }
394
- if (normalized === "null") {
395
- return "null";
396
- }
397
- if (normalized === "undefined" || normalized === "void") {
398
- return "undefined";
399
- }
400
- if (normalized === "object" || normalized.startsWith("{")) {
401
- return "object";
402
- }
403
- if (normalized.endsWith("[]") || normalized.startsWith("array")) {
404
- return "array";
405
- }
406
- if (normalized.startsWith("(") || normalized.includes("=>") || normalized.startsWith("function")) {
407
- return "function";
408
- }
409
- if (normalized.includes("|")) {
410
- return "union";
411
- }
412
- if (normalized.includes("<") && normalized.includes(">")) {
413
- return "generic";
414
- }
415
- return "default";
416
- }
417
- var TypeBadge = React2.forwardRef(({ className, type, typeColor, ...props }, ref) => {
418
- const color = typeColor ?? detectTypeColor(type);
419
- return /* @__PURE__ */ jsx5("span", {
420
- ref,
421
- className: cn(typeBadgeVariants({ typeColor: color }), className),
422
- ...props,
423
- children: type
424
- });
425
- });
426
- TypeBadge.displayName = "TypeBadge";
427
- export {
428
- typeBadgeVariants,
429
- kindBadgeVariants,
430
- TypeBadge,
431
- ParameterItem,
432
- ImportSection,
433
- ExportCard,
434
- CodeTabs
435
- };