kern-lang 1.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.
Files changed (67) hide show
  1. package/LICENSE +661 -0
  2. package/README.md +304 -0
  3. package/dist/cli.d.ts +2 -0
  4. package/dist/cli.js +244 -0
  5. package/dist/cli.js.map +1 -0
  6. package/dist/config.d.ts +46 -0
  7. package/dist/config.js +54 -0
  8. package/dist/config.js.map +1 -0
  9. package/dist/context-export.d.ts +11 -0
  10. package/dist/context-export.js +121 -0
  11. package/dist/context-export.js.map +1 -0
  12. package/dist/decompiler.d.ts +2 -0
  13. package/dist/decompiler.js +44 -0
  14. package/dist/decompiler.js.map +1 -0
  15. package/dist/draft-protocol.d.ts +27 -0
  16. package/dist/draft-protocol.js +135 -0
  17. package/dist/draft-protocol.js.map +1 -0
  18. package/dist/errors.d.ts +12 -0
  19. package/dist/errors.js +40 -0
  20. package/dist/errors.js.map +1 -0
  21. package/dist/index.d.ts +28 -0
  22. package/dist/index.js +33 -0
  23. package/dist/index.js.map +1 -0
  24. package/dist/metrics.d.ts +30 -0
  25. package/dist/metrics.js +182 -0
  26. package/dist/metrics.js.map +1 -0
  27. package/dist/parser.d.ts +4 -0
  28. package/dist/parser.js +361 -0
  29. package/dist/parser.js.map +1 -0
  30. package/dist/spec.d.ts +17 -0
  31. package/dist/spec.js +86 -0
  32. package/dist/spec.js.map +1 -0
  33. package/dist/styles-react.d.ts +3 -0
  34. package/dist/styles-react.js +20 -0
  35. package/dist/styles-react.js.map +1 -0
  36. package/dist/styles-tailwind.d.ts +8 -0
  37. package/dist/styles-tailwind.js +197 -0
  38. package/dist/styles-tailwind.js.map +1 -0
  39. package/dist/transpiler-cli.d.ts +3 -0
  40. package/dist/transpiler-cli.js +279 -0
  41. package/dist/transpiler-cli.js.map +1 -0
  42. package/dist/transpiler-express.d.ts +3 -0
  43. package/dist/transpiler-express.js +612 -0
  44. package/dist/transpiler-express.js.map +1 -0
  45. package/dist/transpiler-nextjs.d.ts +21 -0
  46. package/dist/transpiler-nextjs.js +400 -0
  47. package/dist/transpiler-nextjs.js.map +1 -0
  48. package/dist/transpiler-tailwind.d.ts +3 -0
  49. package/dist/transpiler-tailwind.js +594 -0
  50. package/dist/transpiler-tailwind.js.map +1 -0
  51. package/dist/transpiler-terminal.d.ts +3 -0
  52. package/dist/transpiler-terminal.js +522 -0
  53. package/dist/transpiler-terminal.js.map +1 -0
  54. package/dist/transpiler-web.d.ts +3 -0
  55. package/dist/transpiler-web.js +218 -0
  56. package/dist/transpiler-web.js.map +1 -0
  57. package/dist/transpiler.d.ts +3 -0
  58. package/dist/transpiler.js +218 -0
  59. package/dist/transpiler.js.map +1 -0
  60. package/dist/types.d.ts +76 -0
  61. package/dist/types.js +11 -0
  62. package/dist/types.js.map +1 -0
  63. package/dist/utils.d.ts +5 -0
  64. package/dist/utils.js +36 -0
  65. package/dist/utils.js.map +1 -0
  66. package/kern.config.ts +61 -0
  67. package/package.json +64 -0
@@ -0,0 +1,218 @@
1
+ import { expandStyles } from './styles-react.js';
2
+ import { countTokens, serializeIR } from './utils.js';
3
+ const NODE_TO_ELEMENT = {
4
+ screen: 'div',
5
+ row: 'div',
6
+ col: 'div',
7
+ card: 'div',
8
+ scroll: 'div',
9
+ text: 'span',
10
+ image: 'img',
11
+ progress: 'div',
12
+ divider: 'hr',
13
+ button: 'button',
14
+ input: 'input',
15
+ modal: 'dialog',
16
+ list: 'ul',
17
+ item: 'li',
18
+ tabs: 'nav',
19
+ tab: 'button',
20
+ header: 'header',
21
+ };
22
+ function cssPropertyName(camel) {
23
+ return camel.replace(/([A-Z])/g, '-$1').toLowerCase();
24
+ }
25
+ function cssValue(key, value) {
26
+ if (typeof value === 'number') {
27
+ const unitless = ['flex', 'fontWeight', 'opacity', 'zIndex', 'lineHeight'];
28
+ if (unitless.some(u => key.toLowerCase().includes(u.toLowerCase())))
29
+ return String(value);
30
+ return `${value}px`;
31
+ }
32
+ return String(value);
33
+ }
34
+ export function transpileWeb(root, _config) {
35
+ const sourceMap = [];
36
+ const cssClasses = {};
37
+ let classIdx = 0;
38
+ const jsxLines = [];
39
+ // Collect themes
40
+ const themes = {};
41
+ function collectThemes(node) {
42
+ if (node.type === 'theme' && node.props) {
43
+ const props = node.props;
44
+ if (props.styles) {
45
+ const keys = Object.keys(props).filter(k => k !== 'styles' && k !== 'pseudoStyles' && k !== 'themeRefs');
46
+ const name = keys[0] || `theme_${classIdx++}`;
47
+ themes[name] = props.styles;
48
+ }
49
+ }
50
+ if (node.children)
51
+ node.children.forEach(collectThemes);
52
+ }
53
+ collectThemes(root);
54
+ function getClassName(nodeType) {
55
+ return `${nodeType}_${classIdx++}`;
56
+ }
57
+ function renderNode(node, indent) {
58
+ if (node.type === 'theme')
59
+ return;
60
+ const el = NODE_TO_ELEMENT[node.type] || 'div';
61
+ const irLine = node.loc?.line || 0;
62
+ const outLine = jsxLines.length + 1;
63
+ sourceMap.push({ irLine, irCol: node.loc?.col || 1, outLine, outCol: 1 });
64
+ const props = node.props || {};
65
+ const attrs = [];
66
+ // Merge styles: theme refs + inline
67
+ let mergedStyles = {};
68
+ const themeRefs = props.themeRefs || [];
69
+ for (const ref of themeRefs) {
70
+ if (themes[ref]) {
71
+ mergedStyles = { ...mergedStyles, ...expandStyles(themes[ref]) };
72
+ }
73
+ }
74
+ if (props.styles) {
75
+ mergedStyles = { ...mergedStyles, ...expandStyles(props.styles) };
76
+ }
77
+ // Add layout defaults
78
+ if (node.type === 'screen') {
79
+ if (!mergedStyles.display)
80
+ mergedStyles.display = 'flex';
81
+ if (!mergedStyles.flexDirection)
82
+ mergedStyles.flexDirection = 'column';
83
+ if (!mergedStyles.minHeight)
84
+ mergedStyles.minHeight = '100vh';
85
+ }
86
+ if (node.type === 'row') {
87
+ if (!mergedStyles.display)
88
+ mergedStyles.display = 'flex';
89
+ if (!mergedStyles.flexDirection)
90
+ mergedStyles.flexDirection = 'row';
91
+ }
92
+ if (node.type === 'col') {
93
+ if (!mergedStyles.display)
94
+ mergedStyles.display = 'flex';
95
+ if (!mergedStyles.flexDirection)
96
+ mergedStyles.flexDirection = 'column';
97
+ }
98
+ if (node.type === 'card') {
99
+ if (!mergedStyles.boxShadow)
100
+ mergedStyles.boxShadow = '0 2px 8px rgba(0,0,0,0.1)';
101
+ }
102
+ let className = '';
103
+ if (Object.keys(mergedStyles).length > 0) {
104
+ className = getClassName(node.type);
105
+ cssClasses[className] = mergedStyles;
106
+ attrs.push(`className={styles.${className}}`);
107
+ }
108
+ // Pseudo-styles as CSS hover/active
109
+ const pseudoStyles = props.pseudoStyles;
110
+ // Props as attributes
111
+ for (const [k, v] of Object.entries(props)) {
112
+ if (['styles', 'pseudoStyles', 'themeRefs', 'value', 'text', 'src'].includes(k))
113
+ continue;
114
+ if (k === 'to' && node.type === 'button') {
115
+ attrs.push(`onClick={() => router.push('/${v}')}`);
116
+ continue;
117
+ }
118
+ attrs.push(`${k === 'active' ? 'data-active' : k}="${v}"`);
119
+ }
120
+ // Image src
121
+ if (node.type === 'image' && props.src) {
122
+ attrs.push(`src="/${props.src}.png"`);
123
+ attrs.push(`alt="${props.src}"`);
124
+ }
125
+ const attrStr = attrs.length > 0 ? ' ' + attrs.join(' ') : '';
126
+ const hasChildren = (node.children && node.children.length > 0) ||
127
+ (node.type === 'text' && props.value) ||
128
+ (node.type === 'button' && props.text) ||
129
+ (node.type === 'progress');
130
+ if (hasChildren) {
131
+ jsxLines.push(`${indent}<${el}${attrStr}>`);
132
+ if (node.type === 'text' && props.value) {
133
+ jsxLines.push(`${indent} {${JSON.stringify(props.value)}}`);
134
+ }
135
+ if (node.type === 'button' && props.text) {
136
+ jsxLines.push(`${indent} ${props.text}`);
137
+ }
138
+ if (node.type === 'progress') {
139
+ const label = props.label || '';
140
+ const current = Number(props.current || 0);
141
+ const target = Number(props.target || 100);
142
+ const unit = props.unit || '';
143
+ const color = props.color || '#007AFF';
144
+ const pct = Math.round((current / target) * 100);
145
+ const barClass = getClassName('progressBar');
146
+ const fillClass = getClassName('progressFill');
147
+ cssClasses[barClass] = { height: 8, borderRadius: 4, backgroundColor: '#E0E0E0', overflow: 'hidden', width: '100%' };
148
+ cssClasses[fillClass] = { height: 8, borderRadius: 4, backgroundColor: color, width: `${pct}%` };
149
+ jsxLines.push(`${indent} <span className={styles.progressLabel}>${label}: ${current}/${target} ${unit}</span>`);
150
+ jsxLines.push(`${indent} <div className={styles.${barClass}}>`);
151
+ jsxLines.push(`${indent} <div className={styles.${fillClass}} />`);
152
+ jsxLines.push(`${indent} </div>`);
153
+ }
154
+ if (node.children) {
155
+ for (const child of node.children) {
156
+ renderNode(child, indent + ' ');
157
+ }
158
+ }
159
+ jsxLines.push(`${indent}</${el}>`);
160
+ }
161
+ else if (node.type === 'image') {
162
+ jsxLines.push(`${indent}<${el}${attrStr} />`);
163
+ }
164
+ else if (node.type === 'divider') {
165
+ jsxLines.push(`${indent}<${el}${attrStr} />`);
166
+ }
167
+ else if (node.type === 'input') {
168
+ jsxLines.push(`${indent}<${el}${attrStr} />`);
169
+ }
170
+ else {
171
+ jsxLines.push(`${indent}<${el}${attrStr} />`);
172
+ }
173
+ }
174
+ renderNode(root, ' ');
175
+ const name = root.props?.name || 'Component';
176
+ const code = [];
177
+ // React + Next.js compatible
178
+ code.push(`'use client';`);
179
+ code.push('');
180
+ code.push(`import React from 'react';`);
181
+ code.push('');
182
+ // CSS Module styles
183
+ code.push(`const styles: Record<string, React.CSSProperties> = {`);
184
+ for (const [cname, cval] of Object.entries(cssClasses)) {
185
+ const entries = Object.entries(cval)
186
+ .map(([k, v]) => ` ${k}: ${typeof v === 'number' ? v : `'${v}'`}`)
187
+ .join(',\n');
188
+ code.push(` ${cname}: {`);
189
+ code.push(entries + ',');
190
+ code.push(` },`);
191
+ }
192
+ if (!cssClasses['progressLabel']) {
193
+ code.push(` progressLabel: {`);
194
+ code.push(` fontSize: 14,`);
195
+ code.push(` marginBottom: 4,`);
196
+ code.push(` },`);
197
+ }
198
+ code.push(`};`);
199
+ code.push('');
200
+ code.push(`export default function ${name}() {`);
201
+ code.push(' return (');
202
+ code.push(...jsxLines);
203
+ code.push(' );');
204
+ code.push('}');
205
+ const output = code.join('\n');
206
+ const irText = serializeIR(root);
207
+ const irTokenCount = countTokens(irText);
208
+ const tsTokenCount = countTokens(output);
209
+ const tokenReduction = Math.round((1 - irTokenCount / tsTokenCount) * 100);
210
+ return {
211
+ code: output,
212
+ sourceMap,
213
+ irTokenCount,
214
+ tsTokenCount,
215
+ tokenReduction,
216
+ };
217
+ }
218
+ //# sourceMappingURL=transpiler-web.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpiler-web.js","sourceRoot":"","sources":["../src/transpiler-web.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEtD,MAAM,eAAe,GAA2B;IAC9C,MAAM,EAAE,KAAK;IACb,GAAG,EAAE,KAAK;IACV,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,KAAK;IACX,MAAM,EAAE,KAAK;IACb,IAAI,EAAE,MAAM;IACZ,KAAK,EAAE,KAAK;IACZ,QAAQ,EAAE,KAAK;IACf,OAAO,EAAE,IAAI;IACb,MAAM,EAAE,QAAQ;IAChB,KAAK,EAAE,OAAO;IACd,KAAK,EAAE,QAAQ;IACf,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,IAAI;IACV,IAAI,EAAE,KAAK;IACX,GAAG,EAAE,QAAQ;IACb,MAAM,EAAE,QAAQ;CACjB,CAAC;AAEF,SAAS,eAAe,CAAC,KAAa;IACpC,OAAO,KAAK,CAAC,OAAO,CAAC,UAAU,EAAE,KAAK,CAAC,CAAC,WAAW,EAAE,CAAC;AACxD,CAAC;AAED,SAAS,QAAQ,CAAC,GAAW,EAAE,KAAsB;IACnD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;QAC9B,MAAM,QAA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AAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,CAAC,UAAU,CAAC,eAAe,CAAC,EAAE,CAAC;QACjC,IAAI,CAAC,IAAI,CAAC,oBAAoB,CAAC,CAAC;QAChC,IAAI,CAAC,IAAI,CAAC,mBAAmB,CAAC,CAAC;QAC/B,IAAI,CAAC,IAAI,CAAC,sBAAsB,CAAC,CAAC;QAClC,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IACpB,CAAC;IACD,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAChB,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;IACd,IAAI,CAAC,IAAI,CAAC,2BAA2B,IAAI,MAAM,CAAC,CAAC;IACjD,IAAI,CAAC,IAAI,CAAC,YAAY,CAAC,CAAC;IACxB,IAAI,CAAC,IAAI,CAAC,GAAG,QAAQ,CAAC,CAAC;IACvB,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;IAClB,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAEf,MAAM,MAAM,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IAE/B,MAAM,MAAM,GAAG,WAAW,CAAC,IAAI,CAAC,CAAC;IACjC,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,YAAY,GAAG,WAAW,CAAC,MAAM,CAAC,CAAC;IACzC,MAAM,cAAc,GAAG,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,YAAY,GAAG,YAAY,CAAC,GAAG,GAAG,CAAC,CAAC;IAE3E,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,SAAS;QACT,YAAY;QACZ,YAAY;QACZ,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,3 @@
1
+ import type { IRNode, TranspileResult } from './types.js';
2
+ import type { ResolvedKernConfig } from './config.js';
3
+ export declare function transpile(root: IRNode, _config?: ResolvedKernConfig): TranspileResult;
@@ -0,0 +1,218 @@
1
+ import { expandStyles } from './styles-react.js';
2
+ import { countTokens, serializeIR } from './utils.js';
3
+ const NODE_TO_COMPONENT = {
4
+ screen: 'View',
5
+ row: 'View',
6
+ col: 'View',
7
+ card: 'View',
8
+ scroll: 'ScrollView',
9
+ text: 'Text',
10
+ image: 'Image',
11
+ progress: 'View',
12
+ divider: 'View',
13
+ button: 'TouchableOpacity',
14
+ input: 'TextInput',
15
+ modal: 'Modal',
16
+ list: 'View',
17
+ item: 'View',
18
+ tabs: 'View',
19
+ tab: 'TouchableOpacity',
20
+ header: 'View',
21
+ };
22
+ function styleToString(styles, indent) {
23
+ const entries = Object.entries(styles);
24
+ if (entries.length === 0)
25
+ return '{}';
26
+ const lines = entries.map(([k, v]) => {
27
+ const val = typeof v === 'number' ? String(v) : `'${v}'`;
28
+ return `${indent} ${k}: ${val},`;
29
+ });
30
+ return `{\n${lines.join('\n')}\n${indent}}`;
31
+ }
32
+ export function transpile(root, _config) {
33
+ const sourceMap = [];
34
+ const styleEntries = {};
35
+ let styleIdx = 0;
36
+ const lines = [];
37
+ const imports = new Set();
38
+ // Collect theme definitions
39
+ const themes = {};
40
+ function collectThemes(node) {
41
+ if (node.type === 'theme' && node.props) {
42
+ const name = Object.values(node.props).find(v => typeof v === 'string');
43
+ const themeName = node.props['name'];
44
+ // theme nodes: type=theme, first prop value or the styles
45
+ if (node.props.styles) {
46
+ const key = themeName || name || `theme_${styleIdx++}`;
47
+ themes[key] = node.props.styles;
48
+ }
49
+ }
50
+ if (node.children)
51
+ node.children.forEach(collectThemes);
52
+ }
53
+ collectThemes(root);
54
+ // For theme nodes like "theme bar {h:8,br:4}", the type name follows "theme"
55
+ // Re-collect from raw structure
56
+ function collectThemeNodes(node) {
57
+ if (node.children) {
58
+ for (const child of node.children) {
59
+ if (child.type === 'theme') {
60
+ // The name is the first string prop value or from props
61
+ const props = child.props || {};
62
+ // In our parser, "theme bar {h:8,br:4}" parses as type=theme with
63
+ // remaining "bar" not matching a prop pattern. Let me handle this in a different way.
64
+ // Actually looking at the parser, "bar" after "theme" would not be parsed as a prop.
65
+ // Let me check: "theme bar {h:8,br:4}" - type="theme", then "bar" tries to match as prop (no =), fails.
66
+ // So we need to handle theme name specially. For now, get it from the parser result.
67
+ if (props.styles) {
68
+ // Use first non-style, non-pseudoStyles key as name, or generate one
69
+ const keys = Object.keys(props).filter(k => k !== 'styles' && k !== 'pseudoStyles' && k !== 'themeRefs');
70
+ const name = keys[0] || `theme_${styleIdx++}`;
71
+ themes[name] = props.styles;
72
+ }
73
+ }
74
+ collectThemeNodes(child);
75
+ }
76
+ }
77
+ }
78
+ collectThemeNodes(root);
79
+ function getStyleName(nodeType) {
80
+ return `${nodeType}_${styleIdx++}`;
81
+ }
82
+ function renderNode(node, indent) {
83
+ if (node.type === 'theme')
84
+ return; // Don't render theme definitions
85
+ const comp = NODE_TO_COMPONENT[node.type] || 'View';
86
+ imports.add(comp);
87
+ const irLine = node.loc?.line || 0;
88
+ const outLine = lines.length + 1;
89
+ sourceMap.push({ irLine, irCol: node.loc?.col || 1, outLine, outCol: 1 });
90
+ const props = node.props || {};
91
+ const attrs = [];
92
+ // Compute merged styles: theme refs + inline
93
+ let mergedStyles = {};
94
+ // Apply theme refs first
95
+ const themeRefs = props.themeRefs || [];
96
+ for (const ref of themeRefs) {
97
+ if (themes[ref]) {
98
+ mergedStyles = { ...mergedStyles, ...expandStyles(themes[ref]) };
99
+ }
100
+ }
101
+ // Apply inline styles on top
102
+ if (props.styles) {
103
+ mergedStyles = { ...mergedStyles, ...expandStyles(props.styles) };
104
+ }
105
+ // Add default flexDirection for row
106
+ if (node.type === 'row' && !mergedStyles.flexDirection) {
107
+ mergedStyles.flexDirection = 'row';
108
+ }
109
+ let styleName = '';
110
+ if (Object.keys(mergedStyles).length > 0) {
111
+ styleName = getStyleName(node.type);
112
+ styleEntries[styleName] = mergedStyles;
113
+ attrs.push(`style={styles.${styleName}}`);
114
+ }
115
+ // Handle pseudo-styles (simplified: just store as comment)
116
+ const pseudoStyles = props.pseudoStyles;
117
+ // Add meaningful props as JSX attributes
118
+ for (const [k, v] of Object.entries(props)) {
119
+ if (k === 'styles' || k === 'pseudoStyles' || k === 'themeRefs')
120
+ continue;
121
+ if (k === 'value' && node.type === 'text')
122
+ continue; // handled as children
123
+ if (k === 'text' && node.type === 'button')
124
+ continue; // handled as children
125
+ if (k === 'src' && node.type === 'image') {
126
+ attrs.push(`source={require('./${v}')}`);
127
+ continue;
128
+ }
129
+ attrs.push(`${k}="${v}"`);
130
+ }
131
+ const attrStr = attrs.length > 0 ? ' ' + attrs.join(' ') : '';
132
+ const hasChildren = (node.children && node.children.length > 0) ||
133
+ (node.type === 'text' && props.value) ||
134
+ (node.type === 'button' && props.text) ||
135
+ (node.type === 'progress');
136
+ if (hasChildren) {
137
+ lines.push(`${indent}<${comp}${attrStr}>`);
138
+ // Text content
139
+ if (node.type === 'text' && props.value) {
140
+ lines.push(`${indent} {${JSON.stringify(props.value)}}`);
141
+ }
142
+ // Button text
143
+ if (node.type === 'button' && props.text) {
144
+ imports.add('Text');
145
+ lines.push(`${indent} <Text style={styles.buttonText}>${props.text}</Text>`);
146
+ if (!styleEntries.buttonText) {
147
+ styleEntries.buttonText = { color: '#FFFFFF', textAlign: 'center', fontWeight: 'bold' };
148
+ }
149
+ }
150
+ // Progress bar rendering
151
+ if (node.type === 'progress') {
152
+ imports.add('Text');
153
+ const label = props.label || '';
154
+ const current = props.current || 0;
155
+ const target = props.target || 100;
156
+ const unit = props.unit || '';
157
+ lines.push(`${indent} <Text>${label}: ${current}/${target} ${unit}</Text>`);
158
+ const barStyle = getStyleName('progressBar');
159
+ const fillStyle = getStyleName('progressFill');
160
+ styleEntries[barStyle] = { height: 8, borderRadius: 4, backgroundColor: '#E0E0E0', overflow: 'hidden' };
161
+ const color = props.color || '#007AFF';
162
+ const pct = Number(current) / Number(target);
163
+ styleEntries[fillStyle] = { height: 8, borderRadius: 4, backgroundColor: color, width: `${Math.round(pct * 100)}%` };
164
+ lines.push(`${indent} <View style={styles.${barStyle}}>`);
165
+ lines.push(`${indent} <View style={styles.${fillStyle}} />`);
166
+ lines.push(`${indent} </View>`);
167
+ }
168
+ // Child nodes
169
+ if (node.children) {
170
+ for (const child of node.children) {
171
+ renderNode(child, indent + ' ');
172
+ }
173
+ }
174
+ lines.push(`${indent}</${comp}>`);
175
+ }
176
+ else {
177
+ lines.push(`${indent}<${comp}${attrStr} />`);
178
+ }
179
+ }
180
+ // Render
181
+ renderNode(root, ' ');
182
+ // Build component name
183
+ const name = root.props?.name || 'Component';
184
+ // Build imports
185
+ const importList = Array.from(imports).sort();
186
+ const code = [];
187
+ code.push(`import React from 'react';`);
188
+ code.push(`import { ${importList.join(', ')}, StyleSheet } from 'react-native';`);
189
+ code.push('');
190
+ code.push(`const ${name}: React.FC = () => {`);
191
+ code.push(' return (');
192
+ code.push(...lines);
193
+ code.push(' );');
194
+ code.push('};');
195
+ code.push('');
196
+ // Build StyleSheet
197
+ code.push('const styles = StyleSheet.create({');
198
+ for (const [sname, sval] of Object.entries(styleEntries)) {
199
+ code.push(` ${sname}: ${styleToString(sval, ' ')},`);
200
+ }
201
+ code.push('});');
202
+ code.push('');
203
+ code.push(`export default ${name};`);
204
+ const output = code.join('\n');
205
+ // Serialize IR back for token counting
206
+ const irText = serializeIR(root);
207
+ const irTokenCount = countTokens(irText);
208
+ const tsTokenCount = countTokens(output);
209
+ const tokenReduction = Math.round((1 - irTokenCount / tsTokenCount) * 100);
210
+ return {
211
+ code: output,
212
+ sourceMap,
213
+ irTokenCount,
214
+ tsTokenCount,
215
+ tokenReduction,
216
+ };
217
+ }
218
+ //# sourceMappingURL=transpiler.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transpiler.js","sourceRoot":"","sources":["../src/transpiler.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,YAAY,EAAE,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,WAAW,EAAE,W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C,CAAC,GAAG,YAAY,GAAG,YAAY,CAAC,GAAG,GAAG,CAAC,CAAC;IAE3E,OAAO;QACL,IAAI,EAAE,MAAM;QACZ,SAAS;QACT,YAAY;QACZ,YAAY;QACZ,cAAc;KACf,CAAC;AACJ,CAAC"}
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Kern IR Type System
3
+ *
4
+ * This is the contract. Each forge engine must implement:
5
+ * 1. A parser that reads IR → IRNode tree
6
+ * 2. A transpiler that converts IRNode tree → React Native TypeScript
7
+ * 3. A decompiler that converts IRNode tree → human-readable TypeScript
8
+ * 4. Source map generation for debugging
9
+ */
10
+ /** Base node in the IR tree */
11
+ export interface IRNode {
12
+ /** Node type identifier */
13
+ type: string;
14
+ /** Source location for source maps */
15
+ loc?: IRSourceLocation;
16
+ /** Child nodes */
17
+ children?: IRNode[];
18
+ /** Node-specific properties */
19
+ props?: Record<string, unknown>;
20
+ }
21
+ /** Source location tracking */
22
+ export interface IRSourceLocation {
23
+ line: number;
24
+ col: number;
25
+ endLine?: number;
26
+ endCol?: number;
27
+ }
28
+ /** Source map entry */
29
+ export interface SourceMapEntry {
30
+ /** Position in IR source */
31
+ irLine: number;
32
+ irCol: number;
33
+ /** Position in generated output */
34
+ outLine: number;
35
+ outCol: number;
36
+ }
37
+ /** Generated output artifact (for multi-file targets like Next.js, Express) */
38
+ export interface GeneratedArtifact {
39
+ /** Relative output path */
40
+ path: string;
41
+ /** Generated code */
42
+ content: string;
43
+ /** Artifact type */
44
+ type: 'page' | 'layout' | 'route' | 'middleware' | 'component' | 'config' | 'entry' | 'command';
45
+ }
46
+ /** Result of transpilation */
47
+ export interface TranspileResult {
48
+ /** Generated React Native TypeScript code */
49
+ code: string;
50
+ /** Source map entries */
51
+ sourceMap: SourceMapEntry[];
52
+ /** Token count of the IR input */
53
+ irTokenCount: number;
54
+ /** Token count of the generated TypeScript output */
55
+ tsTokenCount: number;
56
+ /** Token reduction percentage */
57
+ tokenReduction: number;
58
+ /** Multi-file output artifacts */
59
+ artifacts?: GeneratedArtifact[];
60
+ }
61
+ /** Result of decompilation (IR → human-readable) */
62
+ export interface DecompileResult {
63
+ /** Human-readable TypeScript representation */
64
+ code: string;
65
+ }
66
+ /** The main engine interface each implementation must satisfy */
67
+ export interface KernEngine {
68
+ /** Parse IR source text into an IR node tree */
69
+ parse(source: string): IRNode;
70
+ /** Transpile IR node tree to React Native TypeScript */
71
+ transpile(root: IRNode): TranspileResult;
72
+ /** Decompile IR node tree to human-readable TypeScript */
73
+ decompile(root: IRNode): DecompileResult;
74
+ /** Get the IR representation of a component (for token comparison) */
75
+ serialize(root: IRNode): string;
76
+ }
package/dist/types.js ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Kern IR Type System
3
+ *
4
+ * This is the contract. Each forge engine must implement:
5
+ * 1. A parser that reads IR → IRNode tree
6
+ * 2. A transpiler that converts IRNode tree → React Native TypeScript
7
+ * 3. A decompiler that converts IRNode tree → human-readable TypeScript
8
+ * 4. Source map generation for debugging
9
+ */
10
+ export {};
11
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;GAQG"}
@@ -0,0 +1,5 @@
1
+ import type { IRNode } from './types.js';
2
+ export declare function countTokens(text: string): number;
3
+ export declare function serializeIR(node: IRNode, indent?: string): string;
4
+ export declare function camelKey(text: string): string;
5
+ export declare function escapeJsx(s: string): string;
package/dist/utils.js ADDED
@@ -0,0 +1,36 @@
1
+ export function countTokens(text) {
2
+ return text.split(/[\s{}()\[\];,.<>:='"]+/).filter(Boolean).length;
3
+ }
4
+ export function serializeIR(node, indent = '') {
5
+ let line = `${indent}${node.type}`;
6
+ const props = node.props || {};
7
+ for (const [k, v] of Object.entries(props)) {
8
+ if (k === 'styles' || k === 'pseudoStyles' || k === 'themeRefs')
9
+ continue;
10
+ line += ` ${k}=${typeof v === 'string' && v.includes(' ') ? `"${v}"` : v}`;
11
+ }
12
+ if (props.styles) {
13
+ const pairs = Object.entries(props.styles)
14
+ .map(([k, v]) => `${k}:${v}`).join(',');
15
+ line += ` {${pairs}}`;
16
+ }
17
+ if (props.themeRefs) {
18
+ for (const ref of props.themeRefs) {
19
+ line += ` $${ref}`;
20
+ }
21
+ }
22
+ let result = line + '\n';
23
+ if (node.children) {
24
+ for (const child of node.children) {
25
+ result += serializeIR(child, indent + ' ');
26
+ }
27
+ }
28
+ return result;
29
+ }
30
+ export function camelKey(text) {
31
+ return text.toLowerCase().replace(/[^a-z0-9]+(.)/g, (_, c) => c.toUpperCase()).replace(/[^a-zA-Z0-9]/g, '');
32
+ }
33
+ export function escapeJsx(s) {
34
+ return s.replace(/'/g, "\\'");
35
+ }
36
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sourceRoot":"","sources":["../src/utils.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,WAAW,CAAC,IAAY;IACtC,OAAO,IAAI,CAAC,KAAK,CAAC,wBAAwB,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,MAAM,CAAC;AACrE,CAAC;AAED,MAAM,UAAU,WAAW,CAAC,IAAY,EAAE,MAAM,GAAG,EAAE;IACnD,IAAI,IAAI,GAAG,GAAG,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,CAAC;IACnC,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,IAAI,EAAE,CAAC;IAC/B,KAAK,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QAC3C,IAAI,CAAC,KAAK,QAAQ,IAAI,CAAC,KAAK,cAAc,IAAI,CAAC,KAAK,WAAW;YAAE,SAAS;QAC1E,IAAI,IAAI,IAAI,CAAC,IAAI,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IA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