@kernlang/core 2.0.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/LICENSE +661 -0
- package/dist/codegen-core.d.ts +30 -0
- package/dist/codegen-core.js +751 -0
- package/dist/codegen-core.js.map +1 -0
- package/dist/config.d.ts +69 -0
- package/dist/config.js +78 -0
- package/dist/config.js.map +1 -0
- package/dist/decompiler.d.ts +2 -0
- package/dist/decompiler.js +44 -0
- package/dist/decompiler.js.map +1 -0
- package/dist/errors.d.ts +12 -0
- package/dist/errors.js +40 -0
- package/dist/errors.js.map +1 -0
- package/dist/index.d.ts +23 -0
- package/dist/index.js +28 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.d.ts +4 -0
- package/dist/parser.js +380 -0
- package/dist/parser.js.map +1 -0
- package/dist/scanner.d.ts +40 -0
- package/dist/scanner.js +380 -0
- package/dist/scanner.js.map +1 -0
- package/dist/spec.d.ts +17 -0
- package/dist/spec.js +101 -0
- package/dist/spec.js.map +1 -0
- package/dist/styles-react.d.ts +3 -0
- package/dist/styles-react.js +20 -0
- package/dist/styles-react.js.map +1 -0
- package/dist/styles-tailwind.d.ts +8 -0
- package/dist/styles-tailwind.js +197 -0
- package/dist/styles-tailwind.js.map +1 -0
- package/dist/template-catalog.d.ts +26 -0
- package/dist/template-catalog.js +228 -0
- package/dist/template-catalog.js.map +1 -0
- package/dist/template-engine.d.ts +33 -0
- package/dist/template-engine.js +196 -0
- package/dist/template-engine.js.map +1 -0
- package/dist/types.d.ts +94 -0
- package/dist/types.js +11 -0
- package/dist/types.js.map +1 -0
- package/dist/utils.d.ts +12 -0
- package/dist/utils.js +62 -0
- package/dist/utils.js.map +1 -0
- package/dist/version-adapters.d.ts +76 -0
- package/dist/version-adapters.js +172 -0
- package/dist/version-adapters.js.map +1 -0
- package/dist/version-detect.d.ts +30 -0
- package/dist/version-detect.js +63 -0
- package/dist/version-detect.js.map +1 -0
- package/package.json +20 -0
|
@@ -0,0 +1,197 @@
|
|
|
1
|
+
import { STYLE_SHORTHANDS, VALUE_SHORTHANDS } from './spec.js';
|
|
2
|
+
// ── Default color palette (canonical source of truth) ────────────────────
|
|
3
|
+
export const DEFAULT_COLORS = {
|
|
4
|
+
'#18181b': 'zinc-900',
|
|
5
|
+
'#27272a': 'zinc-800',
|
|
6
|
+
'#3f3f46': 'zinc-700',
|
|
7
|
+
'#52525b': 'zinc-600',
|
|
8
|
+
'#71717a': 'zinc-500',
|
|
9
|
+
'#a1a1aa': 'zinc-400',
|
|
10
|
+
'#d4d4d8': 'zinc-300',
|
|
11
|
+
'#e4e4e7': 'zinc-200',
|
|
12
|
+
'#f4f4f5': 'zinc-100',
|
|
13
|
+
'#fafafa': 'zinc-50',
|
|
14
|
+
'#09090b': 'zinc-950',
|
|
15
|
+
'#ffffff': 'white',
|
|
16
|
+
'#fff': 'white',
|
|
17
|
+
'#FFF': 'white',
|
|
18
|
+
'#f97316': 'orange-500',
|
|
19
|
+
'#ea580c': 'orange-600',
|
|
20
|
+
'#F8F9FA': 'gray-50',
|
|
21
|
+
};
|
|
22
|
+
// ── Style-to-Tailwind mapping ───────────────────────────────────────────
|
|
23
|
+
export function stylesToTailwind(styles, colors) {
|
|
24
|
+
const classes = [];
|
|
25
|
+
for (const [key, val] of Object.entries(styles)) {
|
|
26
|
+
const expanded = STYLE_SHORTHANDS[key] || key;
|
|
27
|
+
const v = VALUE_SHORTHANDS[val] || val;
|
|
28
|
+
switch (expanded) {
|
|
29
|
+
case 'padding':
|
|
30
|
+
classes.push(pxToTw('p', v));
|
|
31
|
+
break;
|
|
32
|
+
case 'paddingTop':
|
|
33
|
+
classes.push(pxToTw('pt', v));
|
|
34
|
+
break;
|
|
35
|
+
case 'paddingBottom':
|
|
36
|
+
classes.push(pxToTw('pb', v));
|
|
37
|
+
break;
|
|
38
|
+
case 'paddingLeft':
|
|
39
|
+
classes.push(pxToTw('pl', v));
|
|
40
|
+
break;
|
|
41
|
+
case 'paddingRight':
|
|
42
|
+
classes.push(pxToTw('pr', v));
|
|
43
|
+
break;
|
|
44
|
+
case 'margin':
|
|
45
|
+
classes.push(pxToTw('m', v));
|
|
46
|
+
break;
|
|
47
|
+
case 'marginTop':
|
|
48
|
+
classes.push(pxToTw('mt', v));
|
|
49
|
+
break;
|
|
50
|
+
case 'marginBottom':
|
|
51
|
+
classes.push(pxToTw('mb', v));
|
|
52
|
+
break;
|
|
53
|
+
case 'marginLeft':
|
|
54
|
+
classes.push(pxToTw('ml', v));
|
|
55
|
+
break;
|
|
56
|
+
case 'marginRight':
|
|
57
|
+
classes.push(pxToTw('mr', v));
|
|
58
|
+
break;
|
|
59
|
+
case 'backgroundColor':
|
|
60
|
+
classes.push(colorToTw('bg', v, colors));
|
|
61
|
+
break;
|
|
62
|
+
case 'color':
|
|
63
|
+
classes.push(colorToTw('text', v, colors));
|
|
64
|
+
break;
|
|
65
|
+
case 'fontSize':
|
|
66
|
+
classes.push(fsTw(v));
|
|
67
|
+
break;
|
|
68
|
+
case 'fontWeight':
|
|
69
|
+
classes.push(fwTw(v));
|
|
70
|
+
break;
|
|
71
|
+
case 'borderRadius':
|
|
72
|
+
classes.push(pxToTw('rounded', v));
|
|
73
|
+
break;
|
|
74
|
+
case 'width':
|
|
75
|
+
v === '100%' ? classes.push('w-full') : classes.push(`w-[${addPx(v)}]`);
|
|
76
|
+
break;
|
|
77
|
+
case 'height':
|
|
78
|
+
v === '100%' ? classes.push('h-full') : classes.push(`h-[${addPx(v)}]`);
|
|
79
|
+
break;
|
|
80
|
+
case 'justifyContent':
|
|
81
|
+
if (v === 'space-between')
|
|
82
|
+
classes.push('justify-between');
|
|
83
|
+
else if (v === 'space-around')
|
|
84
|
+
classes.push('justify-around');
|
|
85
|
+
else if (v === 'center')
|
|
86
|
+
classes.push('justify-center');
|
|
87
|
+
else if (v === 'flex-end')
|
|
88
|
+
classes.push('justify-end');
|
|
89
|
+
else
|
|
90
|
+
classes.push('justify-start');
|
|
91
|
+
break;
|
|
92
|
+
case 'alignItems':
|
|
93
|
+
if (v === 'center')
|
|
94
|
+
classes.push('items-center');
|
|
95
|
+
else if (v === 'flex-start')
|
|
96
|
+
classes.push('items-start');
|
|
97
|
+
else if (v === 'flex-end')
|
|
98
|
+
classes.push('items-end');
|
|
99
|
+
else if (v === 'stretch')
|
|
100
|
+
classes.push('items-stretch');
|
|
101
|
+
break;
|
|
102
|
+
case 'flexDirection':
|
|
103
|
+
if (v === 'row')
|
|
104
|
+
classes.push('flex-row');
|
|
105
|
+
break;
|
|
106
|
+
case 'flex':
|
|
107
|
+
classes.push(`flex-${v}`);
|
|
108
|
+
break;
|
|
109
|
+
case 'gap':
|
|
110
|
+
classes.push(pxToTw('gap', v));
|
|
111
|
+
break;
|
|
112
|
+
case 'borderColor':
|
|
113
|
+
classes.push(colorToTw('border', v, colors));
|
|
114
|
+
break;
|
|
115
|
+
case 'borderWidth':
|
|
116
|
+
classes.push('border');
|
|
117
|
+
break;
|
|
118
|
+
case 'overflow':
|
|
119
|
+
classes.push(`overflow-${v}`);
|
|
120
|
+
break;
|
|
121
|
+
case 'textAlign':
|
|
122
|
+
classes.push(`text-${v}`);
|
|
123
|
+
break;
|
|
124
|
+
case 'elevation':
|
|
125
|
+
classes.push(`shadow-${v === '0' ? 'none' : v}`);
|
|
126
|
+
break;
|
|
127
|
+
case 'opacity':
|
|
128
|
+
classes.push(`opacity-${Math.round(Number(v) * 100) || v}`);
|
|
129
|
+
break;
|
|
130
|
+
case 'position':
|
|
131
|
+
classes.push(v);
|
|
132
|
+
break;
|
|
133
|
+
case 'display':
|
|
134
|
+
classes.push(v === 'none' ? 'hidden' : v);
|
|
135
|
+
break;
|
|
136
|
+
case 'zIndex':
|
|
137
|
+
classes.push(`z-${v}`);
|
|
138
|
+
break;
|
|
139
|
+
default:
|
|
140
|
+
// Pass through as arbitrary Tailwind property
|
|
141
|
+
const twVal = v.replace(/ /g, '_');
|
|
142
|
+
classes.push(`[${cssKebab(expanded)}:${twVal}]`);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
return classes.join(' ');
|
|
146
|
+
}
|
|
147
|
+
export function pxToTw(prefix, v) {
|
|
148
|
+
const n = Number(v);
|
|
149
|
+
if (isNaN(n))
|
|
150
|
+
return `${prefix}-[${v}]`;
|
|
151
|
+
// Special handling for border-radius → Tailwind rounded classes
|
|
152
|
+
if (prefix === 'rounded') {
|
|
153
|
+
const roundedMap = {
|
|
154
|
+
0: 'rounded-none', 2: 'rounded-sm', 4: 'rounded', 6: 'rounded-md',
|
|
155
|
+
8: 'rounded-lg', 12: 'rounded-xl', 16: 'rounded-2xl', 20: 'rounded-[20px]',
|
|
156
|
+
9999: 'rounded-full',
|
|
157
|
+
};
|
|
158
|
+
return roundedMap[n] || `rounded-[${n}px]`;
|
|
159
|
+
}
|
|
160
|
+
// Tailwind spacing scale: 1=4px, 2=8px, 3=12px, 4=16px, 5=20px, 6=24px, 8=32px
|
|
161
|
+
const twMap = {
|
|
162
|
+
0: '0', 1: 'px', 2: '0.5', 4: '1', 6: '1.5', 8: '2', 10: '2.5',
|
|
163
|
+
12: '3', 14: '3.5', 16: '4', 20: '5', 24: '6', 28: '7', 32: '8',
|
|
164
|
+
36: '9', 40: '10', 44: '11', 48: '12',
|
|
165
|
+
};
|
|
166
|
+
return twMap[n] !== undefined ? `${prefix}-${twMap[n]}` : `${prefix}-[${n}px]`;
|
|
167
|
+
}
|
|
168
|
+
export function colorToTw(prefix, v, colors) {
|
|
169
|
+
const colorMap = colors ?? DEFAULT_COLORS;
|
|
170
|
+
const mapped = colorMap[v];
|
|
171
|
+
return mapped ? `${prefix}-${mapped}` : `${prefix}-[${v}]`;
|
|
172
|
+
}
|
|
173
|
+
export function fsTw(v) {
|
|
174
|
+
const map = {
|
|
175
|
+
'10': 'text-[10px]', '11': 'text-[11px]', '12': 'text-xs', '13': 'text-[13px]',
|
|
176
|
+
'14': 'text-sm', '16': 'text-base', '18': 'text-lg', '20': 'text-xl',
|
|
177
|
+
'24': 'text-2xl', '28': 'text-[28px]', '30': 'text-3xl',
|
|
178
|
+
};
|
|
179
|
+
return map[v] || `text-[${v}px]`;
|
|
180
|
+
}
|
|
181
|
+
export function fwTw(v) {
|
|
182
|
+
const map = {
|
|
183
|
+
'300': 'font-light', '400': 'font-normal', '500': 'font-medium',
|
|
184
|
+
'600': 'font-semibold', '700': 'font-bold', '800': 'font-extrabold',
|
|
185
|
+
'900': 'font-black', 'bold': 'font-bold', 'normal': 'font-normal',
|
|
186
|
+
'medium': 'font-medium', 'semibold': 'font-semibold',
|
|
187
|
+
};
|
|
188
|
+
return map[v] || `font-[${v}]`;
|
|
189
|
+
}
|
|
190
|
+
export function addPx(v) {
|
|
191
|
+
const n = Number(v);
|
|
192
|
+
return isNaN(n) ? v : `${n}px`;
|
|
193
|
+
}
|
|
194
|
+
export function cssKebab(s) {
|
|
195
|
+
return s.replace(/([A-Z])/g, '-$1').toLowerCase();
|
|
196
|
+
}
|
|
197
|
+
//# sourceMappingURL=styles-tailwind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"styles-tailwind.js","sourceRoot":"","sources":["../src/styles-tailwind.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAE/D,4EAA4E;AAE5E,MAAM,CAAC,MAAM,cAAc,GAA2B;IACpD,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,SAAS;IACpB,SAAS,EAAE,UAAU;IACrB,SAAS,EAAE,OAAO;IAClB,MAAM,EAAE,OAAO;IACf,MAAM,EAAE,OAAO;IACf,SAAS,EAAE,YAAY;IACvB,SAAS,EAAE,YAAY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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC;AACjC,CAAC;AAED,MAAM,UAAU,QAAQ,CAAC,CAAS;IAChC,OAAO,CAAC,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACpD,CAAC"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Template Catalog — built-in templates for popular libraries
|
|
3
|
+
*
|
|
4
|
+
* `kern init-templates` reads package.json, matches against this catalog,
|
|
5
|
+
* and scaffolds template .kern files for detected libraries.
|
|
6
|
+
*
|
|
7
|
+
* Any AI assistant just runs `kern init-templates` and the project is ready.
|
|
8
|
+
*/
|
|
9
|
+
export interface CatalogEntry {
|
|
10
|
+
/** npm package name that triggers this template */
|
|
11
|
+
packageName: string;
|
|
12
|
+
/** Human-friendly library name */
|
|
13
|
+
libraryName: string;
|
|
14
|
+
/** Template files to scaffold: filename → content */
|
|
15
|
+
templates: Record<string, string>;
|
|
16
|
+
}
|
|
17
|
+
export declare const TEMPLATE_CATALOG: CatalogEntry[];
|
|
18
|
+
/** Always-included templates (framework-agnostic patterns) */
|
|
19
|
+
export declare const COMMON_TEMPLATES: Record<string, string>;
|
|
20
|
+
/**
|
|
21
|
+
* Detect which catalog entries match a project's package.json.
|
|
22
|
+
*/
|
|
23
|
+
export declare function detectTemplates(packageJson: {
|
|
24
|
+
dependencies?: Record<string, string>;
|
|
25
|
+
devDependencies?: Record<string, string>;
|
|
26
|
+
}): CatalogEntry[];
|
|
@@ -0,0 +1,228 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Template Catalog — built-in templates for popular libraries
|
|
3
|
+
*
|
|
4
|
+
* `kern init-templates` reads package.json, matches against this catalog,
|
|
5
|
+
* and scaffolds template .kern files for detected libraries.
|
|
6
|
+
*
|
|
7
|
+
* Any AI assistant just runs `kern init-templates` and the project is ready.
|
|
8
|
+
*/
|
|
9
|
+
// ── Zustand ─────────────────────────────────────────────────────────────
|
|
10
|
+
const ZUSTAND_STORE = `template name=zustand-store
|
|
11
|
+
slot name=storeName type=identifier
|
|
12
|
+
slot name=stateType type=identifier
|
|
13
|
+
import from=zustand names=create
|
|
14
|
+
body <<<
|
|
15
|
+
export const use{{storeName}}Store = create<{{stateType}}>((set, get) => ({
|
|
16
|
+
{{CHILDREN}}
|
|
17
|
+
}));
|
|
18
|
+
>>>
|
|
19
|
+
`;
|
|
20
|
+
const ZUSTAND_SELECTOR = `template name=zustand-selector
|
|
21
|
+
slot name=selectorName type=identifier
|
|
22
|
+
slot name=stateType type=identifier
|
|
23
|
+
slot name=field type=expr
|
|
24
|
+
body <<<
|
|
25
|
+
export const select{{selectorName}} = (s: {{stateType}}) => s.{{field}};
|
|
26
|
+
>>>
|
|
27
|
+
`;
|
|
28
|
+
// ── SWR ─────────────────────────────────────────────────────────────────
|
|
29
|
+
const SWR_HOOK = `template name=swr-hook
|
|
30
|
+
slot name=hookName type=identifier
|
|
31
|
+
slot name=cacheKey type=expr
|
|
32
|
+
slot name=fetcher type=expr optional=true default=defaultFetcher
|
|
33
|
+
import from=swr names=useSWR
|
|
34
|
+
body <<<
|
|
35
|
+
export function {{hookName}}() {
|
|
36
|
+
const { data, error, isLoading } = useSWR(
|
|
37
|
+
{{cacheKey}},
|
|
38
|
+
{{fetcher}}
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
{{CHILDREN}}
|
|
42
|
+
|
|
43
|
+
return { data, error, isLoading };
|
|
44
|
+
}
|
|
45
|
+
>>>
|
|
46
|
+
`;
|
|
47
|
+
// ── React Query / TanStack Query ────────────────────────────────────────
|
|
48
|
+
const REACT_QUERY_HOOK = `template name=query-hook
|
|
49
|
+
slot name=hookName type=identifier
|
|
50
|
+
slot name=queryKey type=expr
|
|
51
|
+
slot name=queryFn type=expr
|
|
52
|
+
import from=@tanstack/react-query names=useQuery
|
|
53
|
+
body <<<
|
|
54
|
+
export function {{hookName}}() {
|
|
55
|
+
const { data, error, isLoading, refetch } = useQuery({
|
|
56
|
+
queryKey: [{{queryKey}}],
|
|
57
|
+
queryFn: {{queryFn}},
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
{{CHILDREN}}
|
|
61
|
+
|
|
62
|
+
return { data, error, isLoading, refetch };
|
|
63
|
+
}
|
|
64
|
+
>>>
|
|
65
|
+
`;
|
|
66
|
+
const REACT_MUTATION = `template name=mutation-hook
|
|
67
|
+
slot name=hookName type=identifier
|
|
68
|
+
slot name=mutationFn type=expr
|
|
69
|
+
import from=@tanstack/react-query names=useMutation
|
|
70
|
+
body <<<
|
|
71
|
+
export function {{hookName}}() {
|
|
72
|
+
const mutation = useMutation({
|
|
73
|
+
mutationFn: {{mutationFn}},
|
|
74
|
+
{{CHILDREN}}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
return mutation;
|
|
78
|
+
}
|
|
79
|
+
>>>
|
|
80
|
+
`;
|
|
81
|
+
// ── tRPC ────────────────────────────────────────────────────────────────
|
|
82
|
+
const TRPC_QUERY = `template name=trpc-query
|
|
83
|
+
slot name=hookName type=identifier
|
|
84
|
+
slot name=route type=expr
|
|
85
|
+
slot name=input type=expr optional=true
|
|
86
|
+
body <<<
|
|
87
|
+
export function {{hookName}}({{input}}) {
|
|
88
|
+
const query = api.{{route}}.useQuery({{input}});
|
|
89
|
+
|
|
90
|
+
{{CHILDREN}}
|
|
91
|
+
|
|
92
|
+
return query;
|
|
93
|
+
}
|
|
94
|
+
>>>
|
|
95
|
+
`;
|
|
96
|
+
// ── XState ──────────────────────────────────────────────────────────────
|
|
97
|
+
const XSTATE_MACHINE = `template name=xstate-machine
|
|
98
|
+
slot name=machineName type=identifier
|
|
99
|
+
slot name=contextType type=identifier optional=true
|
|
100
|
+
import from=xstate names="setup,assign"
|
|
101
|
+
body <<<
|
|
102
|
+
export const {{machineName}}Machine = setup({
|
|
103
|
+
types: {
|
|
104
|
+
context: {} as {{contextType}},
|
|
105
|
+
},
|
|
106
|
+
guards: {
|
|
107
|
+
{{CHILDREN}}
|
|
108
|
+
},
|
|
109
|
+
}).createMachine({
|
|
110
|
+
id: '{{machineName}}',
|
|
111
|
+
context: ({input}) => input,
|
|
112
|
+
});
|
|
113
|
+
>>>
|
|
114
|
+
`;
|
|
115
|
+
// ── Jotai ───────────────────────────────────────────────────────────────
|
|
116
|
+
const JOTAI_ATOM = `template name=jotai-atom
|
|
117
|
+
slot name=atomName type=identifier
|
|
118
|
+
slot name=atomType type=type
|
|
119
|
+
slot name=initialValue type=expr
|
|
120
|
+
import from=jotai names=atom
|
|
121
|
+
body <<<
|
|
122
|
+
export const {{atomName}}Atom = atom<{{atomType}}>({{initialValue}});
|
|
123
|
+
>>>
|
|
124
|
+
`;
|
|
125
|
+
const JOTAI_DERIVED = `template name=jotai-derived
|
|
126
|
+
slot name=atomName type=identifier
|
|
127
|
+
slot name=sourceAtom type=identifier
|
|
128
|
+
import from=jotai names="atom,useAtomValue"
|
|
129
|
+
body <<<
|
|
130
|
+
export const {{atomName}}Atom = atom((get) => {
|
|
131
|
+
const source = get({{sourceAtom}}Atom);
|
|
132
|
+
{{CHILDREN}}
|
|
133
|
+
});
|
|
134
|
+
>>>
|
|
135
|
+
`;
|
|
136
|
+
// ── Arrow Function Export ───────────────────────────────────────────────
|
|
137
|
+
const ARROW_FN = `template name=arrow-fn
|
|
138
|
+
slot name=name type=identifier
|
|
139
|
+
slot name=params type=expr optional=true
|
|
140
|
+
slot name=returnType type=type optional=true
|
|
141
|
+
body <<<
|
|
142
|
+
export const {{name}} = ({{params}}){{returnType}} => {
|
|
143
|
+
{{CHILDREN}}
|
|
144
|
+
};
|
|
145
|
+
>>>
|
|
146
|
+
`;
|
|
147
|
+
// ── Window Event Hook ───────────────────────────────────────────────────
|
|
148
|
+
const WINDOW_EVENT = `template name=window-event
|
|
149
|
+
slot name=hookName type=identifier
|
|
150
|
+
slot name=eventName type=expr
|
|
151
|
+
import from=react names="useEffect,useCallback"
|
|
152
|
+
body <<<
|
|
153
|
+
export function {{hookName}}() {
|
|
154
|
+
const handleEvent = useCallback((e: Event) => {
|
|
155
|
+
{{CHILDREN}}
|
|
156
|
+
}, []);
|
|
157
|
+
|
|
158
|
+
useEffect(() => {
|
|
159
|
+
window.addEventListener({{eventName}}, handleEvent);
|
|
160
|
+
return () => window.removeEventListener({{eventName}}, handleEvent);
|
|
161
|
+
}, [handleEvent]);
|
|
162
|
+
}
|
|
163
|
+
>>>
|
|
164
|
+
`;
|
|
165
|
+
// ── Catalog ─────────────────────────────────────────────────────────────
|
|
166
|
+
export const TEMPLATE_CATALOG = [
|
|
167
|
+
{
|
|
168
|
+
packageName: 'zustand',
|
|
169
|
+
libraryName: 'Zustand',
|
|
170
|
+
templates: {
|
|
171
|
+
'zustand-store.kern': ZUSTAND_STORE,
|
|
172
|
+
'zustand-selector.kern': ZUSTAND_SELECTOR,
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
{
|
|
176
|
+
packageName: 'swr',
|
|
177
|
+
libraryName: 'SWR',
|
|
178
|
+
templates: {
|
|
179
|
+
'swr-hook.kern': SWR_HOOK,
|
|
180
|
+
},
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
packageName: '@tanstack/react-query',
|
|
184
|
+
libraryName: 'TanStack Query',
|
|
185
|
+
templates: {
|
|
186
|
+
'query-hook.kern': REACT_QUERY_HOOK,
|
|
187
|
+
'mutation-hook.kern': REACT_MUTATION,
|
|
188
|
+
},
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
packageName: '@trpc/react-query',
|
|
192
|
+
libraryName: 'tRPC',
|
|
193
|
+
templates: {
|
|
194
|
+
'trpc-query.kern': TRPC_QUERY,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
{
|
|
198
|
+
packageName: 'xstate',
|
|
199
|
+
libraryName: 'XState',
|
|
200
|
+
templates: {
|
|
201
|
+
'xstate-machine.kern': XSTATE_MACHINE,
|
|
202
|
+
},
|
|
203
|
+
},
|
|
204
|
+
{
|
|
205
|
+
packageName: 'jotai',
|
|
206
|
+
libraryName: 'Jotai',
|
|
207
|
+
templates: {
|
|
208
|
+
'jotai-atom.kern': JOTAI_ATOM,
|
|
209
|
+
'jotai-derived.kern': JOTAI_DERIVED,
|
|
210
|
+
},
|
|
211
|
+
},
|
|
212
|
+
];
|
|
213
|
+
/** Always-included templates (framework-agnostic patterns) */
|
|
214
|
+
export const COMMON_TEMPLATES = {
|
|
215
|
+
'arrow-fn.kern': ARROW_FN,
|
|
216
|
+
'window-event.kern': WINDOW_EVENT,
|
|
217
|
+
};
|
|
218
|
+
/**
|
|
219
|
+
* Detect which catalog entries match a project's package.json.
|
|
220
|
+
*/
|
|
221
|
+
export function detectTemplates(packageJson) {
|
|
222
|
+
const allDeps = {
|
|
223
|
+
...packageJson.dependencies,
|
|
224
|
+
...packageJson.devDependencies,
|
|
225
|
+
};
|
|
226
|
+
return TEMPLATE_CATALOG.filter(entry => entry.packageName in allDeps);
|
|
227
|
+
}
|
|
228
|
+
//# sourceMappingURL=template-catalog.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"template-catalog.js","sourceRoot":"","sources":["../src/template-catalog.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAWH,2EAA2E;AAE3E,MAAM,aAAa,GAAG;;;;;;;;;CASrB,CAAC;AAEF,MAAM,gBAAgB,GAAG;;;;;;;CAOxB,CAAC;AAEF,2EAA2E;AAE3E,MAAM,QAAQ,GAAG;;;;;;;;;;;;;;;;;CAiBhB,CAAC;AAEF,2EAA2E;AAE3E,MAAM,gBAAgB,GAAG;;;;;;;;;;;;;;;;;CAiBxB,CAAC;AAEF,MAAM,cAAc,GAAG;;;;;;;;;;;;;;CActB,CAAC;AAEF,2EAA2E;AAE3E,MAAM,UAAU,GAAG;;;;;;;;;;;;;CAalB,CAAC;AAEF,2EAA2E;AAE3E,MAAM,cAAc,GAAG;;;;;;;;;;;;;;;;;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C,MAAM,OAAO,GAAG;QACd,GAAG,WAAW,CAAC,YAAY;QAC3B,GAAG,WAAW,CAAC,eAAe;KAC/B,CAAC;IAEF,OAAO,gBAAgB,CAAC,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,WAAW,IAAI,OAAO,CAAC,CAAC;AACxE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Kern Template Engine — dynamic pattern support
|
|
3
|
+
*
|
|
4
|
+
* Users define reusable code patterns in .kern files with typed slots.
|
|
5
|
+
* Templates are registered at config/CLI time, then expanded during codegen.
|
|
6
|
+
*/
|
|
7
|
+
import type { IRNode, TemplateDefinition } from './types.js';
|
|
8
|
+
export declare class KernTemplateError extends Error {
|
|
9
|
+
constructor(message: string);
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Register a template from a parsed 'template' IRNode.
|
|
13
|
+
* Extracts slot definitions, import declarations, and body from children.
|
|
14
|
+
*/
|
|
15
|
+
export declare function registerTemplate(node: IRNode, sourceFile?: string): void;
|
|
16
|
+
/** Check if a node type matches a registered template. */
|
|
17
|
+
export declare function isTemplateNode(type: string): boolean;
|
|
18
|
+
/** Clear all registered templates (for test isolation). */
|
|
19
|
+
export declare function clearTemplates(): void;
|
|
20
|
+
/** Get a registered template definition by name. */
|
|
21
|
+
export declare function getTemplate(name: string): TemplateDefinition | undefined;
|
|
22
|
+
/** Get count of registered templates. */
|
|
23
|
+
export declare function templateCount(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Expand a template instance node into TypeScript lines.
|
|
26
|
+
*
|
|
27
|
+
* 1. Look up template definition
|
|
28
|
+
* 2. Validate required slots against node.props
|
|
29
|
+
* 3. Replace {{slotName}} placeholders in body
|
|
30
|
+
* 4. Handle {{CHILDREN}}: iterate child nodes through codegen
|
|
31
|
+
* 5. Prepend import lines
|
|
32
|
+
*/
|
|
33
|
+
export declare function expandTemplateNode(node: IRNode, _depth?: number): string[];
|