@dsai-io/tools 1.0.7 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1002,20 +1002,6 @@ var init_line_height = __esm({
1002
1002
  }
1003
1003
  });
1004
1004
 
1005
- // src/tokens/style-dictionary/transforms/name.ts
1006
- exports.nameKebab = void 0;
1007
- var init_name = __esm({
1008
- "src/tokens/style-dictionary/transforms/name.ts"() {
1009
- exports.nameKebab = {
1010
- name: "name/kebab",
1011
- type: "name",
1012
- transform: (token) => {
1013
- return token.path.join("-").replace(/_/g, "-").toLowerCase();
1014
- }
1015
- };
1016
- }
1017
- });
1018
-
1019
1005
  // src/tokens/style-dictionary/transforms/name-js-identifier.ts
1020
1006
  function toPascalCaseSegment3(segment) {
1021
1007
  const needsNumericPrefix = /^\d/.test(segment);
@@ -1035,6 +1021,20 @@ var init_name_js_identifier = __esm({
1035
1021
  }
1036
1022
  });
1037
1023
 
1024
+ // src/tokens/style-dictionary/transforms/name.ts
1025
+ exports.nameKebab = void 0;
1026
+ var init_name = __esm({
1027
+ "src/tokens/style-dictionary/transforms/name.ts"() {
1028
+ exports.nameKebab = {
1029
+ name: "name/kebab",
1030
+ type: "name",
1031
+ transform: (token) => {
1032
+ return token.path.join("-").replace(/_/g, "-").toLowerCase();
1033
+ }
1034
+ };
1035
+ }
1036
+ });
1037
+
1038
1038
  // src/tokens/style-dictionary/transforms/index.ts
1039
1039
  var transforms_exports = {};
1040
1040
  __export(transforms_exports, {
@@ -1063,8 +1063,8 @@ var init_transforms = __esm({
1063
1063
  init_dimension();
1064
1064
  init_font_weight();
1065
1065
  init_line_height();
1066
- init_name();
1067
1066
  init_name_js_identifier();
1067
+ init_name();
1068
1068
  init_font_weight();
1069
1069
  init_line_height();
1070
1070
  init_dimension();
@@ -1760,13 +1760,29 @@ var globalConfigSchema = zod.z.object({
1760
1760
  framework: frameworkSchema.optional(),
1761
1761
  build: buildConfigSchema.optional()
1762
1762
  });
1763
+ var aliasesConfigSchema = zod.z.object({
1764
+ importAlias: zod.z.string().optional().default("@/"),
1765
+ ui: zod.z.string().optional().default("src/components/ui"),
1766
+ hooks: zod.z.string().optional().default("src/hooks"),
1767
+ utils: zod.z.string().optional().default("src/lib/utils"),
1768
+ components: zod.z.string().optional().default("src/components"),
1769
+ lib: zod.z.string().optional().default("src/lib")
1770
+ });
1771
+ var componentsConfigSchema = zod.z.object({
1772
+ enabled: zod.z.boolean().optional().default(true),
1773
+ registryUrl: zod.z.string().optional().default("https://registry.dsai.dev"),
1774
+ tsx: zod.z.boolean().optional().default(true),
1775
+ overwrite: zod.z.boolean().optional().default(false)
1776
+ });
1763
1777
  var dsaiConfigSchema = zod.z.object({
1764
1778
  $schema: zod.z.string().optional(),
1765
1779
  extends: zod.z.union([zod.z.string(), zod.z.array(zod.z.string())]).optional(),
1766
1780
  global: globalConfigSchema.optional(),
1767
1781
  tokens: tokensConfigSchema.optional(),
1768
1782
  themes: themesConfigSchema.optional(),
1769
- icons: iconsConfigSchema.optional()
1783
+ icons: iconsConfigSchema.optional(),
1784
+ aliases: aliasesConfigSchema.optional(),
1785
+ components: componentsConfigSchema.optional()
1770
1786
  });
1771
1787
  function formatValidationErrors(zodError) {
1772
1788
  return zodError.issues.map((err) => ({
@@ -1804,7 +1820,9 @@ function validateConfigSection(section, config) {
1804
1820
  global: globalConfigSchema,
1805
1821
  tokens: tokensConfigSchema,
1806
1822
  themes: themesConfigSchema,
1807
- icons: iconsConfigSchema
1823
+ icons: iconsConfigSchema,
1824
+ aliases: aliasesConfigSchema,
1825
+ components: componentsConfigSchema
1808
1826
  };
1809
1827
  const schema = sectionSchemas[section];
1810
1828
  if (!schema) {
@@ -1916,6 +1934,20 @@ var defaultIconsConfig = {
1916
1934
  optimize: true,
1917
1935
  prefix: "Icon"
1918
1936
  };
1937
+ var defaultAliasesConfig = {
1938
+ importAlias: "@/",
1939
+ ui: "src/components/ui",
1940
+ hooks: "src/hooks",
1941
+ utils: "src/lib/utils",
1942
+ components: "src/components",
1943
+ lib: "src/lib"
1944
+ };
1945
+ var defaultComponentsConfig = {
1946
+ enabled: true,
1947
+ registryUrl: "https://registry.dsai.dev",
1948
+ tsx: true,
1949
+ overwrite: false
1950
+ };
1919
1951
  var defaultTokensConfig = {
1920
1952
  source: "theme",
1921
1953
  sourceDir: DEFAULT_SOURCE_DIR,
@@ -1950,6 +1982,8 @@ var defaultGlobalConfig = {
1950
1982
  var defaultConfig = {
1951
1983
  tokens: defaultTokensConfig,
1952
1984
  icons: defaultIconsConfig,
1985
+ aliases: defaultAliasesConfig,
1986
+ components: defaultComponentsConfig,
1953
1987
  global: defaultGlobalConfig,
1954
1988
  configDir: process.cwd()
1955
1989
  };
@@ -2213,10 +2247,32 @@ function resolveTokensConfig(config, options) {
2213
2247
  postprocess: config?.postprocess
2214
2248
  };
2215
2249
  }
2250
+ function resolveAliasesConfig(config) {
2251
+ const base = defaultAliasesConfig;
2252
+ return {
2253
+ importAlias: config?.importAlias ?? base.importAlias,
2254
+ ui: config?.ui ?? base.ui,
2255
+ hooks: config?.hooks ?? base.hooks,
2256
+ utils: config?.utils ?? base.utils,
2257
+ components: config?.components ?? base.components,
2258
+ lib: config?.lib ?? base.lib
2259
+ };
2260
+ }
2261
+ function resolveComponentsConfig(config) {
2262
+ const base = defaultComponentsConfig;
2263
+ return {
2264
+ enabled: config?.enabled ?? base.enabled,
2265
+ registryUrl: config?.registryUrl ?? base.registryUrl,
2266
+ tsx: config?.tsx ?? base.tsx,
2267
+ overwrite: config?.overwrite ?? base.overwrite
2268
+ };
2269
+ }
2216
2270
  function applyOverrides(config, overrides) {
2217
2271
  return {
2218
2272
  tokens: overrides.tokens ? { ...config.tokens, ...overrides.tokens } : config.tokens,
2219
2273
  icons: overrides.icons ? { ...config.icons, ...overrides.icons } : config.icons,
2274
+ aliases: overrides.aliases ? { ...config.aliases, ...overrides.aliases } : config.aliases,
2275
+ components: overrides.components ? { ...config.components, ...overrides.components } : config.components,
2220
2276
  global: overrides.global ? { ...config.global, ...overrides.global } : config.global
2221
2277
  };
2222
2278
  }
@@ -2227,6 +2283,8 @@ function resolveConfig(config = {}, options = {}) {
2227
2283
  global: resolveGlobalConfig(mergedConfig.global, options),
2228
2284
  tokens: resolveTokensConfig(mergedConfig.tokens, options),
2229
2285
  icons: resolveIconsConfig(mergedConfig.icons, options),
2286
+ aliases: resolveAliasesConfig(mergedConfig.aliases),
2287
+ components: resolveComponentsConfig(mergedConfig.components),
2230
2288
  configDir
2231
2289
  };
2232
2290
  }
@@ -2242,6 +2300,8 @@ function createResolvedConfig(partial = {}) {
2242
2300
  global: partial.global ?? defaultConfig.global,
2243
2301
  tokens: partial.tokens ?? defaultConfig.tokens,
2244
2302
  icons: partial.icons ?? defaultConfig.icons,
2303
+ aliases: partial.aliases ?? defaultConfig.aliases,
2304
+ components: partial.components ?? defaultConfig.components,
2245
2305
  configDir: partial.configDir ?? process.cwd(),
2246
2306
  configPath: partial.configPath
2247
2307
  };
@@ -9098,6 +9158,1156 @@ async function buildIcons(config, options = {}) {
9098
9158
  result.duration = Date.now() - startTime;
9099
9159
  return result;
9100
9160
  }
9161
+ var registryItemTypeSchema = zod.z.enum([
9162
+ "registry:ui",
9163
+ "registry:hook",
9164
+ "registry:util",
9165
+ "registry:lib",
9166
+ "registry:component",
9167
+ "registry:style",
9168
+ "registry:type"
9169
+ ]);
9170
+ var registryFileSchema = zod.z.object({
9171
+ path: zod.z.string().min(1, "File path is required"),
9172
+ type: registryItemTypeSchema,
9173
+ content: zod.z.string(),
9174
+ target: zod.z.string().optional()
9175
+ });
9176
+ var registryItemSchema = zod.z.object({
9177
+ name: zod.z.string().min(1, "Registry item name is required"),
9178
+ type: registryItemTypeSchema,
9179
+ title: zod.z.string().min(1, "Title is required"),
9180
+ description: zod.z.string().default(""),
9181
+ dependencies: zod.z.array(zod.z.string()).default([]),
9182
+ devDependencies: zod.z.array(zod.z.string()).default([]),
9183
+ registryDependencies: zod.z.array(zod.z.string()).default([]),
9184
+ files: zod.z.array(registryFileSchema).min(1, "At least one file is required"),
9185
+ cssVars: zod.z.object({
9186
+ light: zod.z.record(zod.z.string(), zod.z.string()).optional(),
9187
+ dark: zod.z.record(zod.z.string(), zod.z.string()).optional()
9188
+ }).optional(),
9189
+ categories: zod.z.array(zod.z.string()).optional()
9190
+ });
9191
+ var registryIndexEntrySchema = zod.z.object({
9192
+ name: zod.z.string(),
9193
+ type: registryItemTypeSchema,
9194
+ title: zod.z.string(),
9195
+ description: zod.z.string(),
9196
+ dependencies: zod.z.array(zod.z.string()),
9197
+ registryDependencies: zod.z.array(zod.z.string()),
9198
+ categories: zod.z.array(zod.z.string()).optional()
9199
+ });
9200
+ var registryIndexSchema = zod.z.object({
9201
+ version: zod.z.string(),
9202
+ count: zod.z.number(),
9203
+ items: zod.z.array(registryIndexEntrySchema)
9204
+ });
9205
+
9206
+ // src/registry/component-map.ts
9207
+ var componentMap = {
9208
+ accordion: {
9209
+ type: "registry:ui",
9210
+ title: "Accordion",
9211
+ description: "Collapsible content panels for presenting information in a limited space.",
9212
+ categories: ["disclosure", "layout"]
9213
+ },
9214
+ alert: {
9215
+ type: "registry:ui",
9216
+ title: "Alert",
9217
+ description: "Contextual feedback messages for user actions.",
9218
+ categories: ["feedback"]
9219
+ },
9220
+ avatar: {
9221
+ type: "registry:ui",
9222
+ title: "Avatar",
9223
+ description: "Graphical representation of a user or entity.",
9224
+ categories: ["data-display"]
9225
+ },
9226
+ badge: {
9227
+ type: "registry:ui",
9228
+ title: "Badge",
9229
+ description: "Small count or status indicator, typically displayed on other elements.",
9230
+ categories: ["data-display"]
9231
+ },
9232
+ breadcrumb: {
9233
+ type: "registry:ui",
9234
+ title: "Breadcrumb",
9235
+ description: "Navigation aid showing the current page location within a hierarchy.",
9236
+ categories: ["navigation"]
9237
+ },
9238
+ button: {
9239
+ type: "registry:ui",
9240
+ title: "Button",
9241
+ description: "Trigger for actions and events.",
9242
+ categories: ["actions"]
9243
+ },
9244
+ card: {
9245
+ type: "registry:ui",
9246
+ title: "Card",
9247
+ description: "Flexible container for grouping related content and actions.",
9248
+ categories: ["layout", "data-display"]
9249
+ },
9250
+ "card-list": {
9251
+ type: "registry:ui",
9252
+ title: "CardList",
9253
+ description: "Responsive list of selectable cards with keyboard navigation.",
9254
+ categories: ["layout", "data-display"]
9255
+ },
9256
+ carousel: {
9257
+ type: "registry:ui",
9258
+ title: "Carousel",
9259
+ description: "Slideshow component for cycling through content.",
9260
+ categories: ["data-display"]
9261
+ },
9262
+ checkbox: {
9263
+ type: "registry:ui",
9264
+ title: "Checkbox",
9265
+ description: "Toggle control for boolean selections.",
9266
+ categories: ["forms"]
9267
+ },
9268
+ "checkbox-group": {
9269
+ type: "registry:ui",
9270
+ title: "CheckboxGroup",
9271
+ description: "Managed group of checkboxes with shared state.",
9272
+ categories: ["forms"]
9273
+ },
9274
+ dropdown: {
9275
+ type: "registry:ui",
9276
+ title: "Dropdown",
9277
+ description: "Toggleable overlay menu for displaying a list of actions.",
9278
+ categories: ["navigation", "actions"],
9279
+ npmDependencies: ["@floating-ui/react"]
9280
+ },
9281
+ icon: {
9282
+ type: "registry:ui",
9283
+ title: "Icon",
9284
+ description: "Scalable vector icon component with accessibility support.",
9285
+ categories: ["data-display"]
9286
+ },
9287
+ input: {
9288
+ type: "registry:ui",
9289
+ title: "Input",
9290
+ description: "Text input field with validation and formatting support.",
9291
+ categories: ["forms"]
9292
+ },
9293
+ "list-group": {
9294
+ type: "registry:ui",
9295
+ title: "ListGroup",
9296
+ description: "Flexible component for displaying a series of items.",
9297
+ categories: ["data-display", "navigation"]
9298
+ },
9299
+ modal: {
9300
+ type: "registry:ui",
9301
+ title: "Modal",
9302
+ description: "Dialog overlay for focused content and user interactions.",
9303
+ categories: ["feedback", "disclosure"]
9304
+ },
9305
+ navbar: {
9306
+ type: "registry:ui",
9307
+ title: "Navbar",
9308
+ description: "Responsive navigation header with branding and links.",
9309
+ categories: ["navigation"]
9310
+ },
9311
+ pagination: {
9312
+ type: "registry:ui",
9313
+ title: "Pagination",
9314
+ description: "Navigation controls for paged content.",
9315
+ categories: ["navigation"]
9316
+ },
9317
+ popover: {
9318
+ type: "registry:ui",
9319
+ title: "Popover",
9320
+ description: "Floating content panel anchored to a trigger element.",
9321
+ categories: ["disclosure"],
9322
+ npmDependencies: ["@floating-ui/react"]
9323
+ },
9324
+ progress: {
9325
+ type: "registry:ui",
9326
+ title: "Progress",
9327
+ description: "Visual indicator of task completion.",
9328
+ categories: ["feedback"]
9329
+ },
9330
+ radio: {
9331
+ type: "registry:ui",
9332
+ title: "Radio",
9333
+ description: "Single-select control within a group of options.",
9334
+ categories: ["forms"]
9335
+ },
9336
+ scrollspy: {
9337
+ type: "registry:ui",
9338
+ title: "Scrollspy",
9339
+ description: "Automatically highlights navigation links based on scroll position.",
9340
+ categories: ["navigation"]
9341
+ },
9342
+ select: {
9343
+ type: "registry:ui",
9344
+ title: "Select",
9345
+ description: "Dropdown selector for choosing from a list of options.",
9346
+ categories: ["forms"],
9347
+ npmDependencies: ["@floating-ui/react"]
9348
+ },
9349
+ "selectable-card": {
9350
+ type: "registry:ui",
9351
+ title: "SelectableCard",
9352
+ description: "Card variant that acts as a selectable option.",
9353
+ categories: ["forms", "data-display"]
9354
+ },
9355
+ sheet: {
9356
+ type: "registry:ui",
9357
+ title: "Sheet",
9358
+ description: "Sliding panel overlay from screen edges.",
9359
+ categories: ["disclosure", "layout"]
9360
+ },
9361
+ spinner: {
9362
+ type: "registry:ui",
9363
+ title: "Spinner",
9364
+ description: "Loading indicator for asynchronous operations.",
9365
+ categories: ["feedback"]
9366
+ },
9367
+ switch: {
9368
+ type: "registry:ui",
9369
+ title: "Switch",
9370
+ description: "Toggle control for binary on/off states.",
9371
+ categories: ["forms"]
9372
+ },
9373
+ table: {
9374
+ type: "registry:ui",
9375
+ title: "Table",
9376
+ description: "Data table with sorting, selection, and responsive layout.",
9377
+ categories: ["data-display"]
9378
+ },
9379
+ tabs: {
9380
+ type: "registry:ui",
9381
+ title: "Tabs",
9382
+ description: "Tabbed interface for switching between content panels.",
9383
+ categories: ["navigation", "layout"]
9384
+ },
9385
+ "tabs-pro": {
9386
+ type: "registry:ui",
9387
+ title: "TabsPro",
9388
+ description: "Advanced tabbed interface with closable, sortable, and overflow support.",
9389
+ categories: ["navigation", "layout"]
9390
+ },
9391
+ toast: {
9392
+ type: "registry:ui",
9393
+ title: "Toast",
9394
+ description: "Brief notification messages that auto-dismiss.",
9395
+ categories: ["feedback"]
9396
+ },
9397
+ tooltip: {
9398
+ type: "registry:ui",
9399
+ title: "Tooltip",
9400
+ description: "Informational popup displayed on hover or focus.",
9401
+ categories: ["data-display"],
9402
+ npmDependencies: ["@floating-ui/react"]
9403
+ },
9404
+ typography: {
9405
+ type: "registry:ui",
9406
+ title: "Typography",
9407
+ description: "Text rendering primitives with semantic variants.",
9408
+ categories: ["data-display"]
9409
+ }
9410
+ };
9411
+ var hookMap = {
9412
+ "use-async": {
9413
+ type: "registry:hook",
9414
+ title: "useAsync",
9415
+ description: "Manages async operation lifecycle (loading, error, data states).",
9416
+ categories: ["state"]
9417
+ },
9418
+ "use-callback-ref": {
9419
+ type: "registry:hook",
9420
+ title: "useCallbackRef",
9421
+ description: "Stable callback reference that always points to the latest function.",
9422
+ categories: ["refs"]
9423
+ },
9424
+ "use-click-outside": {
9425
+ type: "registry:hook",
9426
+ title: "useClickOutside",
9427
+ description: "Detects clicks outside of a target element.",
9428
+ categories: ["dom"]
9429
+ },
9430
+ "use-controllable-state": {
9431
+ type: "registry:hook",
9432
+ title: "useControllableState",
9433
+ description: "Manages state that can be either controlled or uncontrolled.",
9434
+ categories: ["state"]
9435
+ },
9436
+ "use-dark-mode": {
9437
+ type: "registry:hook",
9438
+ title: "useDarkMode",
9439
+ description: "Detects and toggles dark mode preference.",
9440
+ categories: ["theme"]
9441
+ },
9442
+ "use-debounce": {
9443
+ type: "registry:hook",
9444
+ title: "useDebounce",
9445
+ description: "Debounces a value or callback over a specified delay.",
9446
+ categories: ["timing"]
9447
+ },
9448
+ "use-field": {
9449
+ type: "registry:hook",
9450
+ title: "useField",
9451
+ description: "Form field state management with validation.",
9452
+ categories: ["forms"]
9453
+ },
9454
+ "use-focus-trap": {
9455
+ type: "registry:hook",
9456
+ title: "useFocusTrap",
9457
+ description: "Traps keyboard focus within a container for modal-like experiences.",
9458
+ categories: ["a11y"]
9459
+ },
9460
+ "use-form": {
9461
+ type: "registry:hook",
9462
+ title: "useForm",
9463
+ description: "Comprehensive form state management with validation.",
9464
+ categories: ["forms"]
9465
+ },
9466
+ "use-hover": {
9467
+ type: "registry:hook",
9468
+ title: "useHover",
9469
+ description: "Tracks hover state of an element with enter/leave delays.",
9470
+ categories: ["dom"]
9471
+ },
9472
+ "use-id": {
9473
+ type: "registry:hook",
9474
+ title: "useId",
9475
+ description: "Generates stable unique identifiers for accessibility attributes.",
9476
+ categories: ["a11y"]
9477
+ },
9478
+ "use-intersection-observer": {
9479
+ type: "registry:hook",
9480
+ title: "useIntersectionObserver",
9481
+ description: "Observes element visibility within the viewport.",
9482
+ categories: ["dom"]
9483
+ },
9484
+ "use-key-press": {
9485
+ type: "registry:hook",
9486
+ title: "useKeyPress",
9487
+ description: "Listens for specific keyboard key presses.",
9488
+ categories: ["dom"]
9489
+ },
9490
+ "use-local-storage": {
9491
+ type: "registry:hook",
9492
+ title: "useLocalStorage",
9493
+ description: "Persists state to localStorage with serialization.",
9494
+ categories: ["state", "storage"]
9495
+ },
9496
+ "use-media-query": {
9497
+ type: "registry:hook",
9498
+ title: "useMediaQuery",
9499
+ description: "Matches CSS media queries and provides responsive breakpoint helpers.",
9500
+ categories: ["responsive"]
9501
+ },
9502
+ "use-mounted": {
9503
+ type: "registry:hook",
9504
+ title: "useMounted",
9505
+ description: "Tracks whether the component is currently mounted.",
9506
+ categories: ["lifecycle"]
9507
+ },
9508
+ "use-previous": {
9509
+ type: "registry:hook",
9510
+ title: "usePrevious",
9511
+ description: "Returns the previous value of a variable across renders.",
9512
+ categories: ["state"]
9513
+ },
9514
+ "use-reduced-motion": {
9515
+ type: "registry:hook",
9516
+ title: "useReducedMotion",
9517
+ description: "Detects user preference for reduced motion.",
9518
+ categories: ["a11y"]
9519
+ },
9520
+ "use-resize-observer": {
9521
+ type: "registry:hook",
9522
+ title: "useResizeObserver",
9523
+ description: "Observes element size changes via ResizeObserver.",
9524
+ categories: ["dom"]
9525
+ },
9526
+ "use-roving-focus": {
9527
+ type: "registry:hook",
9528
+ title: "useRovingFocus",
9529
+ description: "Implements roving tabindex pattern for composite widgets.",
9530
+ categories: ["a11y"]
9531
+ },
9532
+ "use-scroll-lock": {
9533
+ type: "registry:hook",
9534
+ title: "useScrollLock",
9535
+ description: "Prevents body scrolling while active (for modals/overlays).",
9536
+ categories: ["dom"]
9537
+ },
9538
+ "use-session-storage": {
9539
+ type: "registry:hook",
9540
+ title: "useSessionStorage",
9541
+ description: "Persists state to sessionStorage with serialization.",
9542
+ categories: ["state", "storage"]
9543
+ },
9544
+ "use-throttle": {
9545
+ type: "registry:hook",
9546
+ title: "useThrottle",
9547
+ description: "Throttles a value or callback to fire at most once per interval.",
9548
+ categories: ["timing"]
9549
+ }
9550
+ };
9551
+ var utilMap = {
9552
+ cn: {
9553
+ type: "registry:util",
9554
+ title: "cn",
9555
+ description: "Conditional class name composition utility.",
9556
+ categories: ["styling"]
9557
+ },
9558
+ a11y: {
9559
+ type: "registry:util",
9560
+ title: "a11y",
9561
+ description: "Accessibility utilities including screen reader announcements and ARIA helpers.",
9562
+ categories: ["a11y"]
9563
+ },
9564
+ async: {
9565
+ type: "registry:util",
9566
+ title: "async",
9567
+ description: "Async operation utilities: abortable tasks, queues, exponential backoff.",
9568
+ categories: ["async"]
9569
+ },
9570
+ browser: {
9571
+ type: "registry:util",
9572
+ title: "browser",
9573
+ description: "Browser environment detection and feature checks.",
9574
+ categories: ["platform"]
9575
+ },
9576
+ collections: {
9577
+ type: "registry:util",
9578
+ title: "collections",
9579
+ description: "Collection utilities: chunk, paginate, memoize, selectors.",
9580
+ categories: ["data"]
9581
+ },
9582
+ color: {
9583
+ type: "registry:util",
9584
+ title: "color",
9585
+ description: "Color manipulation utilities: contrast, luminance, hex/rgb conversion.",
9586
+ categories: ["styling"]
9587
+ },
9588
+ date: {
9589
+ type: "registry:util",
9590
+ title: "date",
9591
+ description: "Date formatting and relative time utilities.",
9592
+ categories: ["formatting"]
9593
+ },
9594
+ "merge-refs": {
9595
+ type: "registry:util",
9596
+ title: "mergeRefs",
9597
+ description: "Merges multiple React refs into a single callback ref.",
9598
+ categories: ["refs"]
9599
+ },
9600
+ dx: {
9601
+ type: "registry:util",
9602
+ title: "dx",
9603
+ description: "Developer experience helpers: component creation, context factories, polymorphic patterns.",
9604
+ categories: ["dx"]
9605
+ },
9606
+ forms: {
9607
+ type: "registry:util",
9608
+ title: "forms",
9609
+ description: "Form utilities: validators, field error extraction, dirty checking.",
9610
+ categories: ["forms"]
9611
+ },
9612
+ keyboard: {
9613
+ type: "registry:util",
9614
+ title: "keyboard",
9615
+ description: "Keyboard event helpers for detecting specific keys.",
9616
+ categories: ["dom"]
9617
+ },
9618
+ layout: {
9619
+ type: "registry:util",
9620
+ title: "layout",
9621
+ description: "Layout measurement utilities: element bounds, viewport size, resize observation.",
9622
+ categories: ["dom"]
9623
+ },
9624
+ misc: {
9625
+ type: "registry:util",
9626
+ title: "misc",
9627
+ description: "Miscellaneous utilities: clear icon, safe input props, event helpers.",
9628
+ categories: ["misc"]
9629
+ },
9630
+ motion: {
9631
+ type: "registry:util",
9632
+ title: "motion",
9633
+ description: "Animation utilities: spring physics, easing functions, distance calculations.",
9634
+ categories: ["animation"]
9635
+ },
9636
+ number: {
9637
+ type: "registry:util",
9638
+ title: "number",
9639
+ description: "Number formatting and clamping utilities.",
9640
+ categories: ["formatting"]
9641
+ },
9642
+ object: {
9643
+ type: "registry:util",
9644
+ title: "object",
9645
+ description: "Object manipulation utilities: deep merge, pick, omit.",
9646
+ categories: ["data"]
9647
+ },
9648
+ platform: {
9649
+ type: "registry:util",
9650
+ title: "platform",
9651
+ description: "Platform detection utilities: browser, OS, device pixel ratio, text direction.",
9652
+ categories: ["platform"]
9653
+ },
9654
+ responsive: {
9655
+ type: "registry:util",
9656
+ title: "responsive",
9657
+ description: "Responsive design utilities.",
9658
+ categories: ["responsive"]
9659
+ },
9660
+ safety: {
9661
+ type: "registry:util",
9662
+ title: "safety",
9663
+ description: "Security utilities: clipboard access, crypto ID generation, token generation.",
9664
+ categories: ["security"]
9665
+ },
9666
+ string: {
9667
+ type: "registry:util",
9668
+ title: "string",
9669
+ description: "String manipulation utilities: capitalize, slugify, variant classes.",
9670
+ categories: ["formatting"]
9671
+ },
9672
+ telemetry: {
9673
+ type: "registry:util",
9674
+ title: "telemetry",
9675
+ description: "Telemetry utilities: error catching, performance measurement, timing.",
9676
+ categories: ["observability"]
9677
+ },
9678
+ timing: {
9679
+ type: "registry:util",
9680
+ title: "timing",
9681
+ description: "Timing utilities: debounce and throttle functions.",
9682
+ categories: ["timing"]
9683
+ },
9684
+ types: {
9685
+ type: "registry:util",
9686
+ title: "types",
9687
+ description: "Shared type guards and type utilities.",
9688
+ categories: ["types"]
9689
+ },
9690
+ validation: {
9691
+ type: "registry:util",
9692
+ title: "validation",
9693
+ description: "Input validation utilities: email, URL, href safety checks.",
9694
+ categories: ["validation"]
9695
+ }
9696
+ };
9697
+ var directoryToRegistryName = {
9698
+ Accordion: "accordion",
9699
+ Alert: "alert",
9700
+ Avatar: "avatar",
9701
+ Badge: "badge",
9702
+ Breadcrumb: "breadcrumb",
9703
+ Button: "button",
9704
+ Card: "card",
9705
+ CardList: "card-list",
9706
+ Carousel: "carousel",
9707
+ Checkbox: "checkbox",
9708
+ CheckboxGroup: "checkbox-group",
9709
+ Dropdown: "dropdown",
9710
+ Icon: "icon",
9711
+ Input: "input",
9712
+ ListGroup: "list-group",
9713
+ Modal: "modal",
9714
+ Navbar: "navbar",
9715
+ Pagination: "pagination",
9716
+ Popover: "popover",
9717
+ Progress: "progress",
9718
+ Radio: "radio",
9719
+ Scrollspy: "scrollspy",
9720
+ Select: "select",
9721
+ SelectableCard: "selectable-card",
9722
+ Sheet: "sheet",
9723
+ Spinner: "spinner",
9724
+ Switch: "switch",
9725
+ Table: "table",
9726
+ Tabs: "tabs",
9727
+ TabsPro: "tabs-pro",
9728
+ Toast: "toast",
9729
+ Tooltip: "tooltip",
9730
+ Typography: "typography"
9731
+ };
9732
+ var hookDirectoryToRegistryName = {
9733
+ useAsync: "use-async",
9734
+ useCallbackRef: "use-callback-ref",
9735
+ useClickOutside: "use-click-outside",
9736
+ useControllableState: "use-controllable-state",
9737
+ useDarkMode: "use-dark-mode",
9738
+ useDebounce: "use-debounce",
9739
+ useField: "use-field",
9740
+ useFocusTrap: "use-focus-trap",
9741
+ useForm: "use-form",
9742
+ useHover: "use-hover",
9743
+ useId: "use-id",
9744
+ useIntersectionObserver: "use-intersection-observer",
9745
+ useKeyPress: "use-key-press",
9746
+ useLocalStorage: "use-local-storage",
9747
+ useMediaQuery: "use-media-query",
9748
+ useMounted: "use-mounted",
9749
+ usePrevious: "use-previous",
9750
+ useReducedMotion: "use-reduced-motion",
9751
+ useResizeObserver: "use-resize-observer",
9752
+ useRovingFocus: "use-roving-focus",
9753
+ useScrollLock: "use-scroll-lock",
9754
+ useSessionStorage: "use-session-storage",
9755
+ useThrottle: "use-throttle"
9756
+ };
9757
+
9758
+ // src/registry/builder.ts
9759
+ var EXCLUDE_PATTERNS = [
9760
+ /\.test\.(tsx?|jsx?)$/,
9761
+ /\.spec\.(tsx?|jsx?)$/,
9762
+ /\.stories\.(tsx?|jsx?)$/,
9763
+ /\.figma\.(tsx?|jsx?)$/,
9764
+ /\.a11y\.test\./,
9765
+ /\.security\.test\./,
9766
+ /\.integration\.test\./,
9767
+ /README\.md$/
9768
+ ];
9769
+ var REACT_BUILTINS = /* @__PURE__ */ new Set(["react", "react-dom", "react/jsx-runtime", "react-dom/client"]);
9770
+ var UTIL_SUBPATH_TO_REGISTRY = {
9771
+ index: "cn",
9772
+ keyboard: "keyboard",
9773
+ dom: "merge-refs",
9774
+ "dom/mergeRefs": "merge-refs",
9775
+ browser: "browser",
9776
+ validation: "validation",
9777
+ string: "string",
9778
+ misc: "misc",
9779
+ a11y: "a11y",
9780
+ types: "types",
9781
+ async: "async",
9782
+ collections: "collections",
9783
+ color: "color",
9784
+ date: "date",
9785
+ dx: "dx",
9786
+ forms: "forms",
9787
+ layout: "layout",
9788
+ motion: "motion",
9789
+ number: "number",
9790
+ object: "object",
9791
+ platform: "platform",
9792
+ responsive: "responsive",
9793
+ safety: "safety",
9794
+ telemetry: "telemetry",
9795
+ timing: "timing"
9796
+ };
9797
+ function shouldIncludeFile(filePath) {
9798
+ const ext = path2.extname(filePath);
9799
+ if (![".ts", ".tsx", ".css"].includes(ext)) return false;
9800
+ return !EXCLUDE_PATTERNS.some((pattern) => pattern.test(filePath));
9801
+ }
9802
+ function readSourceFiles(dirPath) {
9803
+ if (!fs3.existsSync(dirPath) || !fs3.statSync(dirPath).isDirectory()) return [];
9804
+ const results = [];
9805
+ for (const entry of fs3.readdirSync(dirPath, { withFileTypes: true })) {
9806
+ const fullPath = path2.join(dirPath, entry.name);
9807
+ if (entry.isDirectory()) {
9808
+ for (const sub of fs3.readdirSync(fullPath, { withFileTypes: true })) {
9809
+ if (sub.isFile()) {
9810
+ const subPath = path2.join(fullPath, sub.name);
9811
+ if (shouldIncludeFile(subPath)) {
9812
+ results.push({ path: path2.relative(dirPath, subPath), content: fs3.readFileSync(subPath, "utf-8") });
9813
+ }
9814
+ }
9815
+ }
9816
+ } else if (entry.isFile() && shouldIncludeFile(fullPath)) {
9817
+ results.push({ path: entry.name, content: fs3.readFileSync(fullPath, "utf-8") });
9818
+ }
9819
+ }
9820
+ return results;
9821
+ }
9822
+ function extractCnSource(utilsIndexPath) {
9823
+ const content = fs3.readFileSync(utilsIndexPath, "utf-8");
9824
+ const cnPattern = /(\/\*\*[\s\S]*?\*\/\s*)?export function cn\b[\s\S]*?\n\}/;
9825
+ const match = cnPattern.exec(content);
9826
+ return match ? match[0] : "export function cn(...classes: (string | boolean | undefined | null)[]): string {\n return classes.filter(Boolean).join(' ');\n}";
9827
+ }
9828
+ function analyzeImports(files, knownNpmDeps) {
9829
+ const registryDeps = /* @__PURE__ */ new Set();
9830
+ const npmDeps = new Set(knownNpmDeps);
9831
+ const importPattern = /(?:import|export)\s+(?:[\s\S]*?)\s+from\s+['"]([^'"]+)['"]/g;
9832
+ for (const file of files) {
9833
+ let m;
9834
+ importPattern.lastIndex = 0;
9835
+ while ((m = importPattern.exec(file.content)) !== null) {
9836
+ const specifier = m[1] ?? "";
9837
+ const typesPattern = /\.\.\/(?:\.\.\/)?types(?:\/.*)?$/;
9838
+ if (typesPattern.test(specifier)) {
9839
+ registryDeps.add("dsai-types");
9840
+ continue;
9841
+ }
9842
+ const hookPattern = /\.\.\/(?:\.\.\/)?hooks\/(\w+)/;
9843
+ const hookMatch = hookPattern.exec(specifier);
9844
+ if (hookMatch && hookMatch[1]) {
9845
+ const regName = hookDirectoryToRegistryName[hookMatch[1]];
9846
+ if (regName) registryDeps.add(regName);
9847
+ continue;
9848
+ }
9849
+ const utilPattern = /\.\.\/(?:\.\.\/)?utils(?:\/(.+))?$/;
9850
+ const utilMatch = utilPattern.exec(specifier);
9851
+ if (utilMatch) {
9852
+ const subpath = utilMatch[1] ?? "index";
9853
+ const regName = UTIL_SUBPATH_TO_REGISTRY[subpath];
9854
+ if (regName) registryDeps.add(regName);
9855
+ continue;
9856
+ }
9857
+ const compPattern = /^\.\.\/(\.\.\/)?(?:components\/)?([A-Z]\w+)(?:\/.*)?$/;
9858
+ const compMatch = compPattern.exec(specifier);
9859
+ if (compMatch && compMatch[2]) {
9860
+ const compDir = compMatch[2];
9861
+ const regName = directoryToRegistryName[compDir];
9862
+ if (regName) registryDeps.add(regName);
9863
+ continue;
9864
+ }
9865
+ if (!specifier.startsWith(".") && !specifier.startsWith("/")) {
9866
+ const parts = specifier.split("/");
9867
+ const pkgName = specifier.startsWith("@") && parts.length >= 2 ? `${parts[0]}/${parts[1]}` : parts[0] ?? specifier;
9868
+ if (pkgName && !REACT_BUILTINS.has(pkgName) && !pkgName.startsWith("@dsai-io/")) {
9869
+ npmDeps.add(pkgName);
9870
+ }
9871
+ }
9872
+ }
9873
+ }
9874
+ return { registryDeps, npmDeps };
9875
+ }
9876
+ function buildComponentItem(name, dirPath, log) {
9877
+ const meta = componentMap[name];
9878
+ if (!meta) {
9879
+ log(` [WARN] No metadata for component "${name}", skipping`);
9880
+ return null;
9881
+ }
9882
+ const sourceFiles = readSourceFiles(dirPath);
9883
+ if (sourceFiles.length === 0) {
9884
+ log(` [WARN] No source files found in ${dirPath}`);
9885
+ return null;
9886
+ }
9887
+ const { registryDeps, npmDeps } = analyzeImports(sourceFiles, meta.npmDependencies ?? []);
9888
+ const files = sourceFiles.map((f) => ({
9889
+ path: f.path,
9890
+ type: path2.extname(f.path) === ".css" ? "registry:style" : meta.type,
9891
+ content: f.content
9892
+ }));
9893
+ return {
9894
+ name,
9895
+ type: meta.type,
9896
+ title: meta.title,
9897
+ description: meta.description,
9898
+ dependencies: [...npmDeps].sort(),
9899
+ devDependencies: [],
9900
+ registryDependencies: [...registryDeps].sort(),
9901
+ files,
9902
+ categories: meta.categories
9903
+ };
9904
+ }
9905
+ function buildHookItem(name, dirPath, log) {
9906
+ const meta = hookMap[name];
9907
+ if (!meta) {
9908
+ log(` [WARN] No metadata for hook "${name}", skipping`);
9909
+ return null;
9910
+ }
9911
+ const sourceFiles = readSourceFiles(dirPath);
9912
+ if (sourceFiles.length === 0) {
9913
+ log(` [WARN] No source files found in ${dirPath}`);
9914
+ return null;
9915
+ }
9916
+ const { registryDeps, npmDeps } = analyzeImports(sourceFiles, meta.npmDependencies ?? []);
9917
+ const files = sourceFiles.map((f) => ({
9918
+ path: f.path,
9919
+ type: path2.extname(f.path) === ".css" ? "registry:style" : meta.type,
9920
+ content: f.content
9921
+ }));
9922
+ return {
9923
+ name,
9924
+ type: meta.type,
9925
+ title: meta.title,
9926
+ description: meta.description,
9927
+ dependencies: [...npmDeps].sort(),
9928
+ devDependencies: [],
9929
+ registryDependencies: [...registryDeps].sort(),
9930
+ files,
9931
+ categories: meta.categories
9932
+ };
9933
+ }
9934
+ function buildUtilItem(name, reactSrcDir, log) {
9935
+ const meta = utilMap[name];
9936
+ if (!meta) {
9937
+ log(` [WARN] No metadata for util "${name}", skipping`);
9938
+ return null;
9939
+ }
9940
+ let files;
9941
+ let registryDeps = /* @__PURE__ */ new Set();
9942
+ let npmDeps = /* @__PURE__ */ new Set();
9943
+ if (name === "cn") {
9944
+ const indexPath = path2.join(reactSrcDir, "utils", "index.ts");
9945
+ const cnSource = extractCnSource(indexPath);
9946
+ files = [{ path: "cn.ts", type: "registry:util", content: cnSource }];
9947
+ } else if (name === "merge-refs") {
9948
+ const dirPath = path2.join(reactSrcDir, "utils", "dom");
9949
+ const sourceFiles = readSourceFiles(dirPath);
9950
+ const analyzed = analyzeImports(sourceFiles, []);
9951
+ registryDeps = analyzed.registryDeps;
9952
+ npmDeps = analyzed.npmDeps;
9953
+ files = sourceFiles.map((f) => ({
9954
+ path: `dom/${f.path}`,
9955
+ type: path2.extname(f.path) === ".css" ? "registry:style" : "registry:util",
9956
+ content: f.content
9957
+ }));
9958
+ } else {
9959
+ const dirPath = path2.join(reactSrcDir, "utils", name);
9960
+ if (!fs3.existsSync(dirPath) || !fs3.statSync(dirPath).isDirectory()) {
9961
+ log(` [WARN] Util directory not found: ${dirPath}`);
9962
+ return null;
9963
+ }
9964
+ const sourceFiles = readSourceFiles(dirPath);
9965
+ if (sourceFiles.length === 0) {
9966
+ log(` [WARN] No source files found in ${dirPath}`);
9967
+ return null;
9968
+ }
9969
+ const analyzed = analyzeImports(sourceFiles, []);
9970
+ registryDeps = analyzed.registryDeps;
9971
+ npmDeps = analyzed.npmDeps;
9972
+ files = sourceFiles.map((f) => ({
9973
+ path: `${name}/${f.path}`,
9974
+ type: path2.extname(f.path) === ".css" ? "registry:style" : "registry:util",
9975
+ content: f.content
9976
+ }));
9977
+ }
9978
+ return {
9979
+ name,
9980
+ type: meta.type,
9981
+ title: meta.title,
9982
+ description: meta.description,
9983
+ dependencies: [...npmDeps].sort(),
9984
+ devDependencies: [],
9985
+ registryDependencies: [...registryDeps].sort(),
9986
+ files,
9987
+ categories: meta.categories
9988
+ };
9989
+ }
9990
+ function buildTypesItem(reactSrcDir, log) {
9991
+ const typesDir = path2.join(reactSrcDir, "types");
9992
+ const sourceFiles = readSourceFiles(typesDir);
9993
+ if (sourceFiles.length === 0) {
9994
+ log(" [WARN] No type files found");
9995
+ return null;
9996
+ }
9997
+ const files = sourceFiles.map((f) => {
9998
+ let content = f.content;
9999
+ content = content.replace(/export \{[^}]*\} from ['"]\.\.\/utils\/[^'"]+['"];?\n?/g, "");
10000
+ return {
10001
+ path: `types/${f.path}`,
10002
+ type: "registry:type",
10003
+ content
10004
+ };
10005
+ });
10006
+ return {
10007
+ name: "dsai-types",
10008
+ type: "registry:type",
10009
+ title: "Shared Types",
10010
+ description: "Shared type definitions (SafeHTMLAttributes, ComponentSize, PolymorphicComponentProps, etc.)",
10011
+ dependencies: [],
10012
+ devDependencies: [],
10013
+ registryDependencies: [],
10014
+ files,
10015
+ categories: ["types"]
10016
+ };
10017
+ }
10018
+ function buildRegistry(options) {
10019
+ const { reactSrcDir, outputDir, verbose = false } = options;
10020
+ const log = verbose ? (msg) => console.log(msg) : (_msg) => {
10021
+ };
10022
+ const componentsDir = path2.join(reactSrcDir, "components");
10023
+ const hooksDir = path2.join(reactSrcDir, "hooks");
10024
+ const allItems = [];
10025
+ log("[registry] Scanning components...");
10026
+ if (fs3.existsSync(componentsDir)) {
10027
+ for (const entry of fs3.readdirSync(componentsDir, { withFileTypes: true })) {
10028
+ if (!entry.isDirectory()) continue;
10029
+ const dirName = entry.name;
10030
+ const registryName = directoryToRegistryName[dirName];
10031
+ if (!registryName) {
10032
+ log(` [SKIP] Unknown component directory: ${dirName}`);
10033
+ continue;
10034
+ }
10035
+ log(` Building ${registryName}...`);
10036
+ const item = buildComponentItem(registryName, path2.join(componentsDir, dirName), log);
10037
+ if (item) allItems.push(item);
10038
+ }
10039
+ }
10040
+ log("[registry] Scanning hooks...");
10041
+ if (fs3.existsSync(hooksDir)) {
10042
+ for (const entry of fs3.readdirSync(hooksDir, { withFileTypes: true })) {
10043
+ if (!entry.isDirectory()) continue;
10044
+ const dirName = entry.name;
10045
+ const registryName = hookDirectoryToRegistryName[dirName];
10046
+ if (!registryName) {
10047
+ log(` [SKIP] Unknown hook directory: ${dirName}`);
10048
+ continue;
10049
+ }
10050
+ log(` Building ${registryName}...`);
10051
+ const item = buildHookItem(registryName, path2.join(hooksDir, dirName), log);
10052
+ if (item) allItems.push(item);
10053
+ }
10054
+ }
10055
+ log("[registry] Scanning utils...");
10056
+ for (const name of Object.keys(utilMap)) {
10057
+ log(` Building ${name}...`);
10058
+ const item = buildUtilItem(name, reactSrcDir, log);
10059
+ if (item) allItems.push(item);
10060
+ }
10061
+ log("[registry] Building shared types...");
10062
+ const typesItem = buildTypesItem(reactSrcDir, log);
10063
+ if (typesItem) {
10064
+ allItems.push(typesItem);
10065
+ log(` Built dsai-types (${typesItem.files.length} files)`);
10066
+ }
10067
+ log(`[registry] Writing ${allItems.length} items to ${outputDir}...`);
10068
+ for (const sub of ["components", "hooks", "utils", "types"]) {
10069
+ const dir = path2.join(outputDir, sub);
10070
+ if (!fs3.existsSync(dir)) fs3.mkdirSync(dir, { recursive: true });
10071
+ }
10072
+ const typeToSubdir = {
10073
+ "registry:ui": "components",
10074
+ "registry:component": "components",
10075
+ "registry:hook": "hooks",
10076
+ "registry:util": "utils",
10077
+ "registry:lib": "utils",
10078
+ "registry:type": "types"
10079
+ };
10080
+ for (const item of allItems) {
10081
+ const subdir = typeToSubdir[item.type] ?? "utils";
10082
+ const filePath = path2.join(outputDir, subdir, `${item.name}.json`);
10083
+ fs3.writeFileSync(filePath, JSON.stringify(item, null, 2) + "\n", "utf-8");
10084
+ log(` Wrote ${path2.relative(outputDir, filePath)}`);
10085
+ }
10086
+ const indexEntries = allItems.map((item) => ({
10087
+ name: item.name,
10088
+ type: item.type,
10089
+ title: item.title,
10090
+ description: item.description,
10091
+ dependencies: item.dependencies,
10092
+ registryDependencies: item.registryDependencies,
10093
+ categories: item.categories
10094
+ }));
10095
+ const registryIndex = {
10096
+ version: "0.1.0",
10097
+ count: indexEntries.length,
10098
+ items: indexEntries
10099
+ };
10100
+ fs3.writeFileSync(path2.join(outputDir, "index.json"), JSON.stringify(registryIndex, null, 2) + "\n", "utf-8");
10101
+ log(`[registry] Wrote index.json (${registryIndex.count} items)`);
10102
+ return registryIndex;
10103
+ }
10104
+ function loadItem(name, registryDir) {
10105
+ const subdirs = ["components", "hooks", "utils", "lib", "styles", "types"];
10106
+ for (const sub of subdirs) {
10107
+ const filePath = path2.join(registryDir, sub, `${name}.json`);
10108
+ if (fs3.existsSync(filePath)) {
10109
+ return JSON.parse(fs3.readFileSync(filePath, "utf-8"));
10110
+ }
10111
+ }
10112
+ return null;
10113
+ }
10114
+ function resolveTree(names, registryDir) {
10115
+ const visited = /* @__PURE__ */ new Map();
10116
+ const queue = [...names];
10117
+ while (queue.length > 0) {
10118
+ const name = queue.shift();
10119
+ if (visited.has(name)) continue;
10120
+ const item = loadItem(name, registryDir);
10121
+ if (!item) {
10122
+ throw new Error(`Registry item "${name}" not found. Run \`dsai registry build\` or check the name.`);
10123
+ }
10124
+ visited.set(name, item);
10125
+ for (const dep of item.registryDependencies) {
10126
+ if (!visited.has(dep)) queue.push(dep);
10127
+ }
10128
+ }
10129
+ const inDeg = /* @__PURE__ */ new Map();
10130
+ for (const [name, item] of visited) {
10131
+ inDeg.set(name, item.registryDependencies.filter((d) => visited.has(d)).length);
10132
+ }
10133
+ const sorted = [];
10134
+ const ready = [];
10135
+ for (const [name, deg] of inDeg) {
10136
+ if (deg === 0) ready.push(name);
10137
+ }
10138
+ while (ready.length > 0) {
10139
+ const name = ready.shift();
10140
+ sorted.push(visited.get(name));
10141
+ for (const [otherName, otherItem] of visited) {
10142
+ if (otherItem.registryDependencies.includes(name)) {
10143
+ const newDeg = (inDeg.get(otherName) ?? 1) - 1;
10144
+ inDeg.set(otherName, newDeg);
10145
+ if (newDeg === 0) ready.push(otherName);
10146
+ }
10147
+ }
10148
+ }
10149
+ if (sorted.length !== visited.size) {
10150
+ const missing = [...visited.keys()].filter((n) => !sorted.some((s) => s.name === n));
10151
+ throw new Error(`Circular dependency detected involving: ${missing.join(", ")}`);
10152
+ }
10153
+ const allDeps = /* @__PURE__ */ new Set();
10154
+ const allDevDeps = /* @__PURE__ */ new Set();
10155
+ const lightVars = {};
10156
+ const darkVars = {};
10157
+ for (const item of sorted) {
10158
+ for (const dep of item.dependencies) allDeps.add(dep);
10159
+ for (const dep of item.devDependencies) allDevDeps.add(dep);
10160
+ if (item.cssVars?.light) Object.assign(lightVars, item.cssVars.light);
10161
+ if (item.cssVars?.dark) Object.assign(darkVars, item.cssVars.dark);
10162
+ }
10163
+ return {
10164
+ items: sorted,
10165
+ dependencies: [...allDeps],
10166
+ devDependencies: [...allDevDeps],
10167
+ cssVars: { light: lightVars, dark: darkVars }
10168
+ };
10169
+ }
10170
+
10171
+ // src/registry/transformer.ts
10172
+ function transformImports(content, options) {
10173
+ const { aliases } = options;
10174
+ let result = content;
10175
+ result = result.replace(
10176
+ /(from\s+['"])(?:\.\.\/)+types(?:\/([^'"]+))?(['"])/g,
10177
+ (_match, prefix, subpath, suffix) => {
10178
+ if (subpath) {
10179
+ return `${prefix}${aliases.importAlias}${aliases.components}/types/${subpath}${suffix}`;
10180
+ }
10181
+ return `${prefix}${aliases.importAlias}${aliases.components}/types${suffix}`;
10182
+ }
10183
+ );
10184
+ result = result.replace(
10185
+ /(from\s+['"])\.\.\/(([A-Z]\w+)(\/[^'"]+)?)(['"])/g,
10186
+ (_match, prefix, _fullPath, dirName, subPath, suffix) => {
10187
+ const kebab = dirName.replace(/([a-z0-9])([A-Z])/g, "$1-$2").toLowerCase();
10188
+ if (subPath) {
10189
+ return `${prefix}${aliases.importAlias}${aliases.ui}/${kebab}${subPath}${suffix}`;
10190
+ }
10191
+ return `${prefix}${aliases.importAlias}${aliases.ui}/${kebab}${suffix}`;
10192
+ }
10193
+ );
10194
+ result = result.replace(
10195
+ /(from\s+['"])(?:\.\.\/)+hooks\/(\w+)(['"])/g,
10196
+ `$1${aliases.importAlias}${aliases.hooks}/$2$3`
10197
+ );
10198
+ result = result.replace(
10199
+ /(from\s+['"])(?:\.\.\/)+utils\/(\w+(?:\/\w+)?)(['"])/g,
10200
+ `$1${aliases.importAlias}${aliases.utils}/$2$3`
10201
+ );
10202
+ result = result.replace(
10203
+ /(from\s+['"])(?:\.\.\/)+utils(['"])/g,
10204
+ `$1${aliases.importAlias}${aliases.utils}$2`
10205
+ );
10206
+ return result;
10207
+ }
10208
+ function normalizeExtensions(content, tsx) {
10209
+ if (!tsx) {
10210
+ return content.replace(/(from\s+['"][^'"]+)\.tsx(['"])/g, "$1.jsx$2").replace(/(from\s+['"][^'"]+)\.ts(['"])/g, "$1.js$2");
10211
+ }
10212
+ return content;
10213
+ }
10214
+ function getTargetDir(type, aliases) {
10215
+ switch (type) {
10216
+ case "registry:ui":
10217
+ return aliases.ui;
10218
+ case "registry:hook":
10219
+ return aliases.hooks;
10220
+ case "registry:util":
10221
+ return aliases.utils;
10222
+ case "registry:lib":
10223
+ return aliases.lib;
10224
+ case "registry:component":
10225
+ return aliases.components;
10226
+ case "registry:type":
10227
+ return aliases.components;
10228
+ case "registry:style":
10229
+ return aliases.ui;
10230
+ default:
10231
+ return aliases.lib;
10232
+ }
10233
+ }
10234
+ function detectPackageManager(projectDir) {
10235
+ if (fs3.existsSync(path2.join(projectDir, "pnpm-lock.yaml"))) return "pnpm";
10236
+ if (fs3.existsSync(path2.join(projectDir, "bun.lockb")) || fs3.existsSync(path2.join(projectDir, "bun.lock"))) return "bun";
10237
+ if (fs3.existsSync(path2.join(projectDir, "yarn.lock"))) return "yarn";
10238
+ return "npm";
10239
+ }
10240
+ function getInstallArgs(pm, packages, dev) {
10241
+ switch (pm) {
10242
+ case "pnpm":
10243
+ return ["pnpm", ["add", ...[], ...packages]];
10244
+ case "yarn":
10245
+ return ["yarn", ["add", ...[], ...packages]];
10246
+ case "bun":
10247
+ return ["bun", ["add", ...[], ...packages]];
10248
+ default:
10249
+ return ["npm", ["install", ...[], ...packages]];
10250
+ }
10251
+ }
10252
+ function writeRegistryItems(tree, options) {
10253
+ const { projectDir, aliases, components, overwrite, dryRun, log } = options;
10254
+ const result = { written: [], skipped: [], installedDeps: [] };
10255
+ const shouldOverwrite = overwrite ?? components.overwrite;
10256
+ for (const item of tree.items) {
10257
+ const targetBaseDir = getTargetDir(item.type, aliases);
10258
+ for (const file of item.files) {
10259
+ const fileName = path2.basename(file.path);
10260
+ let targetPath;
10261
+ if (file.target) {
10262
+ targetPath = path2.join(projectDir, file.target);
10263
+ } else if (item.type === "registry:ui" || item.type === "registry:component") {
10264
+ targetPath = path2.join(projectDir, targetBaseDir, item.name, fileName);
10265
+ } else if (item.type === "registry:type") {
10266
+ targetPath = path2.join(projectDir, targetBaseDir, file.path);
10267
+ } else {
10268
+ targetPath = path2.join(projectDir, targetBaseDir, fileName);
10269
+ }
10270
+ if (fs3.existsSync(targetPath) && !shouldOverwrite) {
10271
+ if (log) log(` Skipped (exists): ${targetPath}`);
10272
+ result.skipped.push(targetPath);
10273
+ continue;
10274
+ }
10275
+ let content = file.content;
10276
+ content = transformImports(content, { aliases, tsx: components.tsx });
10277
+ content = normalizeExtensions(content, components.tsx);
10278
+ if (dryRun) {
10279
+ if (log) log(` Would write: ${targetPath}`);
10280
+ result.written.push(targetPath);
10281
+ continue;
10282
+ }
10283
+ const dir = path2.dirname(targetPath);
10284
+ if (!fs3.existsSync(dir)) fs3.mkdirSync(dir, { recursive: true });
10285
+ fs3.writeFileSync(targetPath, content, "utf-8");
10286
+ if (log) log(` Written: ${targetPath}`);
10287
+ result.written.push(targetPath);
10288
+ }
10289
+ }
10290
+ const depsToInstall = tree.dependencies.filter((dep) => {
10291
+ const pkgJsonPath = path2.join(projectDir, "package.json");
10292
+ if (fs3.existsSync(pkgJsonPath)) {
10293
+ const pkgJson = JSON.parse(fs3.readFileSync(pkgJsonPath, "utf-8"));
10294
+ const allDeps = { ...pkgJson.dependencies, ...pkgJson.devDependencies };
10295
+ return !Reflect.get(allDeps, dep);
10296
+ }
10297
+ return true;
10298
+ });
10299
+ if (depsToInstall.length > 0 && !dryRun) {
10300
+ const pm = detectPackageManager(projectDir);
10301
+ const [cmd, args] = getInstallArgs(pm, depsToInstall);
10302
+ if (log) log(` Installing: ${cmd} ${args.join(" ")}`);
10303
+ child_process.execFileSync(cmd, args, { cwd: projectDir, stdio: "inherit" });
10304
+ result.installedDeps = depsToInstall;
10305
+ } else if (depsToInstall.length > 0 && dryRun) {
10306
+ if (log) log(` Would install: ${depsToInstall.join(", ")}`);
10307
+ result.installedDeps = depsToInstall;
10308
+ }
10309
+ return result;
10310
+ }
9101
10311
  function getPackageRoot() {
9102
10312
  const currentFile = url.fileURLToPath((typeof document === 'undefined' ? require('u' + 'rl').pathToFileURL(__filename).href : (_documentCurrentScript && _documentCurrentScript.tagName.toUpperCase() === 'SCRIPT' && _documentCurrentScript.src || new URL('index.cjs', document.baseURI).href)));
9103
10313
  return path2.resolve(path2.dirname(currentFile), "..");
@@ -9219,11 +10429,13 @@ exports.DEFAULT_PREFIX = DEFAULT_PREFIX;
9219
10429
  exports.DEFAULT_SOURCE_DIR = DEFAULT_SOURCE_DIR;
9220
10430
  exports.VALID_TOKEN_TYPES = VALID_TOKEN_TYPES;
9221
10431
  exports.addScssImportHeader = addScssImportHeader;
10432
+ exports.aliasesConfigSchema = aliasesConfigSchema;
9222
10433
  exports.applyNameMapping = applyNameMapping;
9223
10434
  exports.autoDetectThemes = autoDetectThemes;
9224
10435
  exports.buildAllThemes = buildAllThemes;
9225
10436
  exports.buildConfigSchema = buildConfigSchema;
9226
10437
  exports.buildIcons = buildIcons;
10438
+ exports.buildRegistry = buildRegistry;
9227
10439
  exports.buildTheme = buildTheme;
9228
10440
  exports.buildTokens = buildTokens;
9229
10441
  exports.buildTokensCLI = buildTokensCLI;
@@ -9234,6 +10446,7 @@ exports.cleanSVGForReact = cleanSVGForReact;
9234
10446
  exports.cleanTokenOutputs = cleanTokenOutputs;
9235
10447
  exports.cleanTokensCLI = cleanTokensCLI;
9236
10448
  exports.clearConfigCache = clearConfigCache;
10449
+ exports.componentsConfigSchema = componentsConfigSchema;
9237
10450
  exports.createBundle = createBundle;
9238
10451
  exports.createBundleFromFiles = createBundleFromFiles;
9239
10452
  exports.createBundles = createBundles;
@@ -9245,6 +10458,8 @@ exports.createStyleDictionaryConfig = createStyleDictionaryConfig;
9245
10458
  exports.customFormatSchema = customFormatSchema;
9246
10459
  exports.customTransformSchema = customTransformSchema;
9247
10460
  exports.deepMerge = deepMerge2;
10461
+ exports.defaultAliasesConfig = defaultAliasesConfig;
10462
+ exports.defaultComponentsConfig = defaultComponentsConfig;
9248
10463
  exports.defaultConfig = defaultConfig;
9249
10464
  exports.defaultFormats = defaultFormats;
9250
10465
  exports.defaultGlobalConfig = defaultGlobalConfig;
@@ -9351,6 +10566,7 @@ exports.mergeConfigs = mergeConfigs;
9351
10566
  exports.mergeContent = mergeContent;
9352
10567
  exports.migrateConfig = migrateConfig;
9353
10568
  exports.migrateLegacyTokensConfig = migrateLegacyTokensConfig;
10569
+ exports.normalizeExtensions = normalizeExtensions;
9354
10570
  exports.normalizeIconName = normalizeIconName;
9355
10571
  exports.optimizeSVG = optimizeSVG;
9356
10572
  exports.optimizeSVGFiles = optimizeSVGFiles;
@@ -9370,11 +10586,17 @@ exports.registerFormats = registerFormats;
9370
10586
  exports.registerPreprocessors = registerPreprocessors;
9371
10587
  exports.registerTransformGroups = registerTransformGroups;
9372
10588
  exports.registerTransforms = registerTransforms;
10589
+ exports.registryFileSchema = registryFileSchema;
10590
+ exports.registryIndexEntrySchema = registryIndexEntrySchema;
10591
+ exports.registryIndexSchema = registryIndexSchema;
10592
+ exports.registryItemSchema = registryItemSchema;
10593
+ exports.registryItemTypeSchema = registryItemTypeSchema;
9373
10594
  exports.replacePlaceholders = replacePlaceholders;
9374
10595
  exports.resolveAllOutputPaths = resolveAllOutputPaths;
9375
10596
  exports.resolveConfig = resolveConfig;
9376
10597
  exports.resolveOutputPath = resolveOutputPath;
9377
10598
  exports.resolvePath = resolvePath;
10599
+ exports.resolveTree = resolveTree;
9378
10600
  exports.runBuildCLI = runBuildCLI;
9379
10601
  exports.scanDirectories = scanDirectories;
9380
10602
  exports.scanSVGFiles = scanSVGFiles;
@@ -9399,6 +10621,7 @@ exports.tokenCacheConfigSchema = tokenCacheConfigSchema;
9399
10621
  exports.tokenWatchConfigSchema = tokenWatchConfigSchema;
9400
10622
  exports.tokensConfigSchema = tokensConfigSchema;
9401
10623
  exports.tokensHooksSchema = tokensHooksSchema;
10624
+ exports.transformImports = transformImports;
9402
10625
  exports.transformToken = transformToken;
9403
10626
  exports.transformTokenTree = transformTokenTree;
9404
10627
  exports.transformTokens = transformTokens;
@@ -9425,5 +10648,6 @@ exports.validateTokensCLI = validateTokensCLI;
9425
10648
  exports.version = version;
9426
10649
  exports.versionSchema = versionSchema;
9427
10650
  exports.writeChangelog = writeChangelog;
10651
+ exports.writeRegistryItems = writeRegistryItems;
9428
10652
  //# sourceMappingURL=index.cjs.map
9429
10653
  //# sourceMappingURL=index.cjs.map