inkbridge 0.1.0-beta.2 → 0.1.0-beta.21

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 (178) hide show
  1. package/README.md +108 -25
  2. package/bin/inkbridge.mjs +354 -83
  3. package/code.js +40 -11802
  4. package/manifest.json +1 -0
  5. package/package.json +74 -23
  6. package/scanner/adapter-utils-regression.ts +159 -0
  7. package/scanner/aspect-percent-position-regression.ts +237 -0
  8. package/scanner/aspect-ratio-regression.ts +90 -0
  9. package/scanner/blob-placement-regression.ts +2 -2
  10. package/scanner/block-cache-regression.ts +195 -0
  11. package/scanner/bundle-size-regression.ts +50 -0
  12. package/scanner/child-sizing-matrix-regression.ts +303 -0
  13. package/scanner/cli.ts +342 -13
  14. package/scanner/component-scanner.ts +2108 -174
  15. package/scanner/component-sections-regression.ts +198 -0
  16. package/scanner/compound-classes-lookup-regression.ts +163 -0
  17. package/scanner/css-token-reader-regression.ts +7 -6
  18. package/scanner/css-token-reader.ts +152 -31
  19. package/scanner/cva-jsx-child-fallback-regression.ts +98 -0
  20. package/scanner/cva-master-icon-regression.ts +315 -0
  21. package/scanner/data-attr-prop-alias-regression.ts +129 -0
  22. package/scanner/explicit-size-root-regression.ts +102 -0
  23. package/scanner/font-family-extract-regression.ts +113 -0
  24. package/scanner/font-style-resolver-regression.ts +1 -1
  25. package/scanner/framework-adapter-shadcn-regression.ts +480 -0
  26. package/scanner/full-width-matrix-regression.ts +338 -0
  27. package/scanner/grid-cols-extraction-regression.ts +110 -0
  28. package/scanner/image-src-collector-regression.ts +204 -0
  29. package/scanner/inline-flex-regression.ts +235 -0
  30. package/scanner/input-range-regression.ts +217 -0
  31. package/scanner/instance-rendering-regression.ts +224 -0
  32. package/scanner/jsx-prop-unresolved-regression.ts +178 -0
  33. package/scanner/jsx-text-regression.ts +178 -0
  34. package/scanner/layout-alignment-regression.ts +108 -0
  35. package/scanner/layout-flex-regression.ts +90 -0
  36. package/scanner/layout-mode-regression.ts +71 -0
  37. package/scanner/layout-sizing-regression.ts +227 -0
  38. package/scanner/layout-spacing-regression.ts +135 -0
  39. package/scanner/local-const-className-regression.ts +331 -0
  40. package/scanner/percent-position-regression.ts +105 -0
  41. package/scanner/provider-cascade-regression.ts +224 -0
  42. package/scanner/provider-flatten-regression.ts +235 -0
  43. package/scanner/radial-gradient-regression.ts +1 -1
  44. package/scanner/render-prop-parser-regression.ts +161 -0
  45. package/scanner/ring-utility-regression.ts +153 -0
  46. package/scanner/sandbox-spread-regression.ts +125 -0
  47. package/scanner/selection-pressed-regression.ts +241 -0
  48. package/scanner/size-full-normalization-regression.ts +127 -0
  49. package/scanner/state-classification-regression.ts +175 -0
  50. package/scanner/story-diagnostics-regression.ts +216 -0
  51. package/scanner/story-dimensioning-regression.ts +298 -0
  52. package/scanner/story-render-strategy-regression.ts +205 -0
  53. package/scanner/stretch-to-parent-width-regression.ts +147 -0
  54. package/scanner/svg-fill-parent-regression.ts +98 -0
  55. package/scanner/svg-group-inheritance-regression.ts +166 -0
  56. package/scanner/svg-marker-inline-regression.ts +211 -0
  57. package/scanner/svg-marker-regression.ts +116 -0
  58. package/scanner/tailwind-parser.ts +46 -4
  59. package/scanner/text-resize-matrix-regression.ts +173 -0
  60. package/scanner/transform-math-regression.ts +1 -1
  61. package/scanner/types.ts +26 -2
  62. package/src/cache/frame-cache.ts +150 -0
  63. package/src/cache/index.ts +2 -0
  64. package/src/{component-defs.ts → components/component-defs.ts} +25 -10
  65. package/src/{component-gen.ts → components/component-gen.ts} +43 -116
  66. package/src/components/component-instance.ts +386 -0
  67. package/src/components/component-library.ts +44 -0
  68. package/src/components/component-lookup.ts +161 -0
  69. package/src/components/index.ts +7 -0
  70. package/src/components/scanner-types.ts +39 -0
  71. package/src/components/symbol-instance-policy.ts +312 -0
  72. package/src/design-system/block-cache.ts +130 -0
  73. package/src/design-system/component-sections.ts +107 -0
  74. package/src/design-system/cva-inference.ts +187 -0
  75. package/src/design-system/cva-master.ts +427 -0
  76. package/src/design-system/cva-utils.ts +29 -0
  77. package/src/design-system/design-system.ts +334 -0
  78. package/src/design-system/frame-stabilizers.ts +191 -0
  79. package/src/design-system/frame-utils.ts +46 -0
  80. package/src/design-system/generated-node.ts +84 -0
  81. package/src/design-system/icon-rendering.ts +229 -0
  82. package/src/design-system/index.ts +13 -0
  83. package/src/design-system/instance-rendering.ts +307 -0
  84. package/src/design-system/master-shared.ts +133 -0
  85. package/src/design-system/node-helpers.ts +237 -0
  86. package/src/design-system/node-variants.ts +196 -0
  87. package/src/design-system/non-cva-master.ts +104 -0
  88. package/src/design-system/portal-handling.ts +138 -0
  89. package/src/design-system/preview-builder.ts +738 -0
  90. package/src/{render-context.ts → design-system/render-context.ts} +32 -6
  91. package/src/design-system/render-prop-parser.ts +50 -0
  92. package/src/design-system/responsive-resolver.ts +180 -0
  93. package/src/design-system/selectable-state.ts +157 -0
  94. package/src/design-system/state-master.ts +267 -0
  95. package/src/design-system/state-utils.ts +15 -0
  96. package/src/design-system/story-builder-context.ts +40 -0
  97. package/src/design-system/story-builder.ts +1322 -0
  98. package/src/design-system/story-diagnostics.ts +80 -0
  99. package/src/design-system/story-dimensioning.ts +272 -0
  100. package/src/design-system/story-frames.ts +400 -0
  101. package/src/design-system/story-instance.ts +333 -0
  102. package/src/{story-layout.ts → design-system/story-layout.ts} +2 -2
  103. package/src/design-system/story-render-strategy.ts +150 -0
  104. package/src/design-system/story-tree-search.ts +110 -0
  105. package/src/design-system/symbol-fallback.ts +89 -0
  106. package/src/design-system/symbol-source.ts +172 -0
  107. package/src/design-system/table-helpers.ts +56 -0
  108. package/src/design-system/tag-predicates.ts +99 -0
  109. package/src/design-system/theme-context.ts +52 -0
  110. package/src/design-system/typography.ts +100 -0
  111. package/src/design-system/ui-builder.ts +2676 -0
  112. package/src/{clip-path-decorative.ts → effects/clip-path-decorative.ts} +11 -11
  113. package/src/effects/icon-builder.ts +1074 -0
  114. package/src/effects/index.ts +5 -0
  115. package/src/effects/portal-panel.ts +369 -0
  116. package/src/{radial-gradient.ts → effects/radial-gradient.ts} +1 -1
  117. package/src/framework-adapters/index.ts +47 -0
  118. package/src/framework-adapters/shadcn.ts +541 -0
  119. package/src/{github.ts → github/github.ts} +46 -21
  120. package/src/github/index.ts +1 -0
  121. package/src/layout/deferred-layout.ts +1556 -0
  122. package/src/layout/index.ts +24 -0
  123. package/src/layout/layout-parser.ts +375 -0
  124. package/src/{layout-utils.ts → layout/layout-utils.ts} +23 -17
  125. package/src/layout/parser/alignment.ts +54 -0
  126. package/src/layout/parser/flex.ts +59 -0
  127. package/src/layout/parser/index.ts +65 -0
  128. package/src/layout/parser/ir.ts +80 -0
  129. package/src/layout/parser/layout-mode.ts +57 -0
  130. package/src/layout/parser/sizing.ts +241 -0
  131. package/src/layout/parser/spacing-scale.ts +78 -0
  132. package/src/layout/parser/spacing.ts +134 -0
  133. package/src/layout/ring-utils.ts +120 -0
  134. package/src/layout/size-utils.ts +143 -0
  135. package/src/layout/text-resize-decision.ts +51 -0
  136. package/src/{width-solver.ts → layout/width-solver.ts} +168 -37
  137. package/src/main.ts +444 -162
  138. package/src/{config.ts → plugin/config.ts} +12 -12
  139. package/src/{dev-server.ts → plugin/dev-server.ts} +3 -3
  140. package/src/plugin/image-src-collector.ts +52 -0
  141. package/src/plugin/index.ts +3 -0
  142. package/src/plugin/packs/index.ts +2 -0
  143. package/src/{pack-provider.ts → plugin/packs/pack-provider.ts} +12 -12
  144. package/src/{packs.ts → plugin/packs/packs.ts} +22 -17
  145. package/src/render-engine-version.ts +2 -0
  146. package/src/tailwind/adapter-utils.ts +137 -0
  147. package/src/{class-utils.ts → tailwind/class-utils.ts} +33 -6
  148. package/src/tailwind/index.ts +8 -0
  149. package/src/tailwind/jsx-utils.ts +319 -0
  150. package/src/{node-ir.ts → tailwind/node-ir.ts} +208 -19
  151. package/src/{responsive-analyzer.ts → tailwind/responsive-analyzer.ts} +32 -2
  152. package/src/{state-analyzer.ts → tailwind/state-analyzer.ts} +71 -5
  153. package/src/{tailwind.ts → tailwind/tailwind.ts} +423 -674
  154. package/src/{utility-resolver.ts → tailwind/utility-resolver.ts} +27 -6
  155. package/src/{font-style-resolver.ts → text/font-style-resolver.ts} +0 -2
  156. package/src/text/index.ts +4 -0
  157. package/src/{inline-text.ts → text/inline-text.ts} +13 -13
  158. package/src/{text-builder.ts → text/text-builder.ts} +24 -7
  159. package/src/{text-line.ts → text/text-line.ts} +2 -2
  160. package/src/{change-detection.ts → tokens/change-detection.ts} +12 -12
  161. package/src/{color-resolver.ts → tokens/color-resolver.ts} +1 -6
  162. package/src/{colors.ts → tokens/colors.ts} +13 -6
  163. package/src/tokens/index.ts +6 -0
  164. package/src/{token-source.ts → tokens/token-source.ts} +4 -1
  165. package/src/{tokens.ts → tokens/tokens.ts} +116 -20
  166. package/src/{variables.ts → tokens/variables.ts} +447 -102
  167. package/templates/patch-tokens-route.ts +25 -6
  168. package/templates/scan-components-route.ts +26 -5
  169. package/ui.html +485 -37
  170. package/src/component-lookup.ts +0 -82
  171. package/src/design-system.ts +0 -59
  172. package/src/icon-builder.ts +0 -607
  173. package/src/layout-parser.ts +0 -667
  174. package/src/story-builder.ts +0 -1706
  175. package/src/ui-builder.ts +0 -1996
  176. /package/src/{image-cache.ts → cache/image-cache.ts} +0 -0
  177. /package/src/{blob-placement.ts → effects/blob-placement.ts} +0 -0
  178. /package/src/{transform-math.ts → tailwind/transform-math.ts} +0 -0
@@ -0,0 +1,107 @@
1
+ import type { ComponentDef } from '../components';
2
+
3
+ export type ComponentSectionConfig = {
4
+ key: string;
5
+ title: string;
6
+ description: string;
7
+ };
8
+
9
+ export const COMPONENT_SECTION_ORDER: ComponentSectionConfig[] = [
10
+ {
11
+ key: 'atoms',
12
+ title: 'Atoms',
13
+ description: 'Reusable primitives and controls.',
14
+ },
15
+ {
16
+ key: 'molecules',
17
+ title: 'Molecules',
18
+ description: 'Composed blocks built from atoms.',
19
+ },
20
+ {
21
+ key: 'organisms',
22
+ title: 'Organisms',
23
+ description: 'Feature and section-level compositions.',
24
+ },
25
+ {
26
+ key: 'utilities',
27
+ title: 'Utilities',
28
+ description: 'Utility and helper components.',
29
+ },
30
+ {
31
+ key: 'other',
32
+ title: 'Other',
33
+ description: 'Components that do not fit current atomic buckets.',
34
+ },
35
+ ];
36
+
37
+ const COMPONENT_SECTION_BY_KEY: Record<string, ComponentSectionConfig> = COMPONENT_SECTION_ORDER.reduce(function(map, section) {
38
+ map[section.key] = section;
39
+ return map;
40
+ }, {} as Record<string, ComponentSectionConfig>);
41
+
42
+ export function getComponentSectionName(section: ComponentSectionConfig): string {
43
+ return 'Section / ' + section.title;
44
+ }
45
+
46
+ export function inferComponentSection(def: ComponentDef): ComponentSectionConfig {
47
+ const kind = String(def && def.kind ? def.kind : '').toLowerCase();
48
+ const type = String(def && def.type ? def.type : '').toLowerCase();
49
+ const usesCount = Number(def && typeof def.usesCount === 'number' ? def.usesCount : 0);
50
+ const usedByCount = Number(def && typeof def.usedByCount === 'number' ? def.usedByCount : 0);
51
+ const isLeaf = typeof def?.isLeaf === 'boolean' ? def.isLeaf : (usesCount === 0);
52
+ const hasStory = typeof def?.hasStory === 'boolean' ? def.hasStory : true;
53
+
54
+ if (kind === 'atom') return COMPONENT_SECTION_BY_KEY.atoms;
55
+ if (kind === 'molecule') return COMPONENT_SECTION_BY_KEY.molecules;
56
+ if (kind === 'organism') return COMPONENT_SECTION_BY_KEY.organisms;
57
+ if (kind === 'utility') return COMPONENT_SECTION_BY_KEY.utilities;
58
+ if (kind === 'other') return COMPONENT_SECTION_BY_KEY.other;
59
+
60
+ if (!hasStory && usedByCount === 0 && isLeaf) {
61
+ return COMPONENT_SECTION_BY_KEY.utilities;
62
+ }
63
+
64
+ if (type === 'cva' || type === 'state') {
65
+ return COMPONENT_SECTION_BY_KEY.atoms;
66
+ }
67
+
68
+ if (isLeaf && usedByCount > 0) {
69
+ return COMPONENT_SECTION_BY_KEY.atoms;
70
+ }
71
+
72
+ if (usesCount >= 2) {
73
+ return COMPONENT_SECTION_BY_KEY.organisms;
74
+ }
75
+
76
+ if (type === 'compound' || usesCount === 1 || usedByCount > 0) {
77
+ return COMPONENT_SECTION_BY_KEY.molecules;
78
+ }
79
+
80
+ if (isLeaf) {
81
+ return COMPONENT_SECTION_BY_KEY.atoms;
82
+ }
83
+
84
+ return COMPONENT_SECTION_BY_KEY.other;
85
+ }
86
+
87
+ export function groupComponentDefs(defs: ComponentDef[]): { section: ComponentSectionConfig; defs: ComponentDef[] }[] {
88
+ const grouped: Record<string, ComponentDef[]> = {};
89
+ for (let i = 0; i < defs.length; i++) {
90
+ const def = defs[i];
91
+ const section = inferComponentSection(def);
92
+ if (!grouped[section.key]) grouped[section.key] = [];
93
+ grouped[section.key].push(def);
94
+ }
95
+
96
+ const out: { section: ComponentSectionConfig; defs: ComponentDef[] }[] = [];
97
+ for (let i = 0; i < COMPONENT_SECTION_ORDER.length; i++) {
98
+ const section = COMPONENT_SECTION_ORDER[i];
99
+ const entries = grouped[section.key];
100
+ if (!entries || entries.length === 0) continue;
101
+ out.push({
102
+ section,
103
+ defs: entries.sort(function(a: ComponentDef, b: ComponentDef) { return a.name.localeCompare(b.name); }),
104
+ });
105
+ }
106
+ return out;
107
+ }
@@ -0,0 +1,187 @@
1
+ import { COMPONENT_DEFS } from '../tokens';
2
+ import { splitClassName } from '../tailwind';
3
+ import { normalizeComponentDef } from './node-helpers';
4
+
5
+ /**
6
+ * Reverse-engineering CVA component identity + variant props from a flat
7
+ * Tailwind class list. Used by ui-builder when an `asChild` Radix wrapper
8
+ * (e.g. `<Button asChild><Link/></Button>`) appears as anonymous "Comp"
9
+ * in the scanned JSX — we still want to render it as the original CVA
10
+ * symbol with its variants.
11
+ *
12
+ * `inferCvaDefFromClasses` finds the best-matching CVA def by base-class
13
+ * overlap. `buildCvaInstanceProps` then resolves the variant props that
14
+ * best explain the remaining classes, optionally preserving any leftover
15
+ * "extra" className the caller wants to keep.
16
+ */
17
+
18
+ function toClassSet(classes: string[]): Set<string> {
19
+ const out = new Set<string>();
20
+ for (let i = 0; i < classes.length; i++) {
21
+ const token = String(classes[i] || '').trim();
22
+ if (!token) continue;
23
+ out.add(token);
24
+ }
25
+ return out;
26
+ }
27
+
28
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
29
+ function getAllNormalizedDefs(): any[] {
30
+ const defs = (COMPONENT_DEFS && Array.isArray(COMPONENT_DEFS.components))
31
+ ? COMPONENT_DEFS.components
32
+ : [];
33
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
34
+ const out: any[] = [];
35
+ for (let i = 0; i < defs.length; i++) {
36
+ const normalized = normalizeComponentDef(defs[i]);
37
+ if (normalized) out.push(normalized);
38
+ }
39
+ return out;
40
+ }
41
+
42
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
43
+ export function inferCvaDefFromClasses(classes: string[]): any | null {
44
+ if (classes.length === 0) return null;
45
+ const classSet = toClassSet(classes);
46
+ const defs = getAllNormalizedDefs();
47
+
48
+ // Common asChild pattern from shadcn Button:
49
+ // <Button asChild><Link .../></Button> often appears as anonymous "Comp" in scanned JSX.
50
+ // Match stable button signature classes first to avoid generic score misses.
51
+ const hasButtonSignature =
52
+ classSet.has('inline-flex')
53
+ && classSet.has('items-center')
54
+ && classSet.has('justify-center')
55
+ && classSet.has('whitespace-nowrap')
56
+ && classSet.has('rounded-md')
57
+ && classSet.has('font-medium');
58
+ if (hasButtonSignature) {
59
+ for (let i = 0; i < defs.length; i++) {
60
+ const def = defs[i];
61
+ if (def && def.type === 'cva' && def.name === 'Button') {
62
+ return def;
63
+ }
64
+ }
65
+ }
66
+
67
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
68
+ let best: any | null = null;
69
+ let bestScore = 0;
70
+ for (let i = 0; i < defs.length; i++) {
71
+ const def = defs[i];
72
+ if (!def || def.type !== 'cva') continue;
73
+ const baseClasses = Array.isArray(def.baseClasses) ? def.baseClasses : [];
74
+ if (baseClasses.length === 0) continue;
75
+ let matched = 0;
76
+ for (let j = 0; j < baseClasses.length; j++) {
77
+ if (classSet.has(baseClasses[j])) matched++;
78
+ }
79
+ const score = matched / baseClasses.length;
80
+ if (matched >= 4 && score > bestScore) {
81
+ best = def;
82
+ bestScore = score;
83
+ }
84
+ }
85
+ if (bestScore < 0.65) return null;
86
+ return best;
87
+ }
88
+
89
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
90
+ function inferCvaVariantPropsFromClasses(def: any, classes: string[]): Record<string, string> {
91
+ const out: Record<string, string> = {};
92
+ if (!def || def.type !== 'cva') return out;
93
+
94
+ const classSet = toClassSet(classes);
95
+ const variants = def.variants || {};
96
+ const variantClasses = def.variantClasses || {};
97
+ const defaultVariants = def.defaultVariants || {};
98
+ const variantKeys = Object.keys(variants);
99
+
100
+ for (let i = 0; i < variantKeys.length; i++) {
101
+ const key = variantKeys[i];
102
+ const values = Array.isArray(variants[key]) ? variants[key] : [];
103
+ if (values.length === 0) continue;
104
+ let bestValue: string | null = null;
105
+ let bestScore = -1;
106
+ for (let j = 0; j < values.length; j++) {
107
+ const value = String(values[j]);
108
+ const valueClasses = variantClasses && variantClasses[key] && Array.isArray(variantClasses[key][value])
109
+ ? variantClasses[key][value]
110
+ : [];
111
+ if (valueClasses.length === 0) continue;
112
+ let matched = 0;
113
+ for (let k = 0; k < valueClasses.length; k++) {
114
+ if (classSet.has(valueClasses[k])) matched++;
115
+ }
116
+ if (matched > bestScore) {
117
+ bestScore = matched;
118
+ bestValue = value;
119
+ }
120
+ }
121
+ if (bestValue) {
122
+ out[key] = bestValue;
123
+ continue;
124
+ }
125
+ const defaultValue = defaultVariants[key];
126
+ if (defaultValue != null) {
127
+ out[key] = String(defaultValue);
128
+ }
129
+ }
130
+ return out;
131
+ }
132
+
133
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
134
+ function getKnownCvaClassSet(def: any, variants: Record<string, string>): Set<string> {
135
+ const known = new Set<string>();
136
+ const baseClasses = Array.isArray(def && def.baseClasses) ? def.baseClasses : [];
137
+ for (let i = 0; i < baseClasses.length; i++) {
138
+ known.add(baseClasses[i]);
139
+ }
140
+ const variantClasses = def && def.variantClasses ? def.variantClasses : {};
141
+ const variantKeys = Object.keys((def && def.variants) || {});
142
+ for (let i = 0; i < variantKeys.length; i++) {
143
+ const key = variantKeys[i];
144
+ const value = variants[key];
145
+ if (!value) continue;
146
+ const classesForValue = variantClasses && variantClasses[key] && Array.isArray(variantClasses[key][value])
147
+ ? variantClasses[key][value]
148
+ : [];
149
+ for (let j = 0; j < classesForValue.length; j++) {
150
+ known.add(classesForValue[j]);
151
+ }
152
+ }
153
+ return known;
154
+ }
155
+
156
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
157
+ export function buildCvaInstanceProps(def: any, nodeProps: Record<string, any>, classes: string[], keepExtraClassName: boolean): Record<string, any> {
158
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
159
+ const props: Record<string, any> = Object.assign({}, nodeProps || {});
160
+ const inferredVariants = inferCvaVariantPropsFromClasses(def, classes);
161
+ const variantKeys = Object.keys((def && def.variants) || {});
162
+ for (let i = 0; i < variantKeys.length; i++) {
163
+ const key = variantKeys[i];
164
+ const inferred = inferredVariants[key];
165
+ if (inferred != null) {
166
+ props[key] = inferred;
167
+ }
168
+ }
169
+ if (keepExtraClassName) {
170
+ const classTokens = splitClassName(props.className);
171
+ if (classTokens.length > 0) {
172
+ const known = getKnownCvaClassSet(def, inferredVariants);
173
+ const extra = classTokens.filter(token => !known.has(token));
174
+ if (extra.length > 0) {
175
+ props.className = extra.join(' ');
176
+ } else {
177
+ delete props.className;
178
+ }
179
+ } else {
180
+ delete props.className;
181
+ }
182
+ } else {
183
+ delete props.className;
184
+ }
185
+ delete props.ref;
186
+ return props;
187
+ }