1313import type { ShikiTransformer } from 'shiki'
1414
1515// Auto-generated whitelists from packages/0/src/
16- import { V0_COMPONENTS , V0_COMPOSABLES } from './generated/api-whitelist'
16+ import { V0_COMPONENTS , V0_COMPOSABLES , V0_COMPOSABLE_TO_DIR } from './generated/api-whitelist'
1717// Vue API content - import only keys for build-time detection
1818import { VUE_API_CONTENT } from './vue-api-content'
1919
@@ -34,15 +34,18 @@ const TRINITY_RETURNS: Record<string, string> = {
3434const VUE_API_NAMES = new Set ( Object . keys ( VUE_API_CONTENT ) )
3535
3636/**
37- * Maps composable names to their canonical API page.
37+ * Maps composable names to their canonical API page (directory name) .
3838 * Returns the API name if valid, null otherwise.
3939 *
40- * Patterns:
41- * - createX -> createX (the canonical API page)
42- * - useX -> createX (trinity return maps to factory)
43- * - createXContext -> createX (variant maps to base)
44- * - createXPlugin -> createX or useX (createStackPlugin -> createStack, createStoragePlugin -> useStorage)
45- * - useContext/provideContext -> createContext (special trinity returns)
40+ * Uses the V0_COMPOSABLE_TO_DIR mapping generated from source directories.
41+ * Each function name maps to its containing directory, which is the API cache key.
42+ *
43+ * Examples:
44+ * - createStackPlugin -> useStack (the directory containing it)
45+ * - createStackContext -> useStack
46+ * - useStack -> useStack
47+ * - createSelection -> createSelection
48+ * - useContext -> createContext (trinity return value)
4649 */
4750function resolveComposable ( name : string ) : { apiName : string } | null {
4851 // Check special trinity return values first (e.g., useContext -> createContext)
@@ -56,36 +59,13 @@ function resolveComposable (name: string): { apiName: string } | null {
5659 return null
5760 }
5861
59- // For useX, check if createX exists (trinity pattern)
60- // useStack -> createStack, useGroup -> createGroup
61- if ( name . startsWith ( 'use' ) ) {
62- const base = name . slice ( 3 ) // 'useStack' -> 'Stack'
63- const createVersion = `create${ base } `
64- if ( V0_COMPOSABLES . has ( createVersion ) ) {
65- return { apiName : createVersion }
66- }
67- }
68-
69- // For createXContext/createXPlugin, map to createX or useX
70- // createStackPlugin -> createStack, createStoragePlugin -> useStorage
71- if ( name . startsWith ( 'create' ) ) {
72- const withoutPrefix = name . slice ( 6 ) // 'createStackPlugin' -> 'StackPlugin'
73- const base = withoutPrefix . replace ( / ( P l u g i n | C o n t e x t ) $ / , '' )
74- if ( base && base !== withoutPrefix ) {
75- // Try createX first (trinity factories)
76- const createVersion = `create${ base } `
77- if ( V0_COMPOSABLES . has ( createVersion ) ) {
78- return { apiName : createVersion }
79- }
80- // Fall back to useX (plugin composables like useStorage, useTheme)
81- const useVersion = `use${ base } `
82- if ( V0_COMPOSABLES . has ( useVersion ) ) {
83- return { apiName : useVersion }
84- }
85- }
62+ // Use the mapping to get the directory name (API cache key)
63+ const dirName = V0_COMPOSABLE_TO_DIR [ name ]
64+ if ( dirName ) {
65+ return { apiName : dirName }
8666 }
8767
88- // Direct match - use as-is (createX, toX, etc. )
68+ // Fallback: use the name as-is (shouldn't happen if whitelist is in sync )
8969 return { apiName : name }
9070}
9171
0 commit comments