inkhouse 0.1.0-beta.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/README.md +201 -0
- package/bin/inkhouse.mjs +171 -0
- package/code.js +11802 -0
- package/manifest.json +30 -0
- package/package.json +45 -0
- package/scanner/blob-placement-regression.ts +132 -0
- package/scanner/class-collector.ts +69 -0
- package/scanner/cli.ts +336 -0
- package/scanner/component-scanner.ts +2876 -0
- package/scanner/css-patch-regression.ts +112 -0
- package/scanner/css-token-reader-regression.ts +92 -0
- package/scanner/css-token-reader.ts +477 -0
- package/scanner/font-style-resolver-regression.ts +32 -0
- package/scanner/index.ts +9 -0
- package/scanner/radial-gradient-regression.ts +53 -0
- package/scanner/style-map.ts +145 -0
- package/scanner/tailwind-parser.ts +644 -0
- package/scanner/transform-math-regression.ts +42 -0
- package/scanner/types.ts +298 -0
- package/src/blob-placement.ts +111 -0
- package/src/change-detection.ts +204 -0
- package/src/class-utils.ts +105 -0
- package/src/clip-path-decorative.ts +194 -0
- package/src/color-resolver.ts +98 -0
- package/src/colors.ts +196 -0
- package/src/component-defs.ts +54 -0
- package/src/component-gen.ts +561 -0
- package/src/component-lookup.ts +82 -0
- package/src/config.ts +115 -0
- package/src/design-system.ts +59 -0
- package/src/dev-server.ts +173 -0
- package/src/figma-globals.d.ts +3 -0
- package/src/font-style-resolver.ts +171 -0
- package/src/github.ts +1465 -0
- package/src/icon-builder.ts +607 -0
- package/src/image-cache.ts +22 -0
- package/src/inline-text.ts +271 -0
- package/src/layout-parser.ts +667 -0
- package/src/layout-utils.ts +155 -0
- package/src/main.ts +687 -0
- package/src/node-ir.ts +595 -0
- package/src/pack-provider.ts +148 -0
- package/src/packs.ts +126 -0
- package/src/radial-gradient.ts +84 -0
- package/src/render-context.ts +138 -0
- package/src/responsive-analyzer.ts +139 -0
- package/src/state-analyzer.ts +143 -0
- package/src/story-builder.ts +1706 -0
- package/src/story-layout.ts +38 -0
- package/src/tailwind.ts +2379 -0
- package/src/text-builder.ts +116 -0
- package/src/text-line.ts +42 -0
- package/src/token-source.ts +43 -0
- package/src/tokens.ts +717 -0
- package/src/transform-math.ts +44 -0
- package/src/ui-builder.ts +1996 -0
- package/src/utility-resolver.ts +125 -0
- package/src/variables.ts +1042 -0
- package/src/width-solver.ts +466 -0
- package/templates/patch-tokens-route.ts +165 -0
- package/templates/scan-components-route.ts +57 -0
- package/ui.html +1222 -0
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { parseUtilityClass, variantState } from './utility-resolver';
|
|
2
|
+
import { tailwindClassesToStyle } from './tailwind';
|
|
3
|
+
|
|
4
|
+
export type StateEffect = {
|
|
5
|
+
property: 'background' | 'border' | 'text' | 'opacity' | 'underline';
|
|
6
|
+
value: string;
|
|
7
|
+
token?: string | null;
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
export type StateInfo = {
|
|
11
|
+
name: string;
|
|
12
|
+
trigger: string;
|
|
13
|
+
classes: string[];
|
|
14
|
+
effects?: StateEffect[];
|
|
15
|
+
};
|
|
16
|
+
|
|
17
|
+
const RESPONSIVE_VARIANTS = new Set(['sm', 'md', 'lg', 'xl', '2xl']);
|
|
18
|
+
|
|
19
|
+
function extractStateVariant(variants: string[]): { state: string; variant: string } | null {
|
|
20
|
+
const filtered: string[] = [];
|
|
21
|
+
for (const v of variants) {
|
|
22
|
+
if (RESPONSIVE_VARIANTS.has(v)) continue;
|
|
23
|
+
filtered.push(v);
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const state = variantState(filtered);
|
|
27
|
+
if (state) {
|
|
28
|
+
const match = filtered.find(v => v === state) || state;
|
|
29
|
+
return { state: state, variant: match };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
for (const v of filtered) {
|
|
33
|
+
if (v.startsWith('group-') || v.startsWith('peer-')) {
|
|
34
|
+
return { state: v, variant: v };
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return null;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function stripStateVariant(input: string, variant: string): string | null {
|
|
42
|
+
const parsed = parseUtilityClass(input);
|
|
43
|
+
const nextVariants: string[] = [];
|
|
44
|
+
for (const v of parsed.variants) {
|
|
45
|
+
if (v === variant) continue;
|
|
46
|
+
nextVariants.push(v);
|
|
47
|
+
}
|
|
48
|
+
if (!parsed.utility) return null;
|
|
49
|
+
let rebuilt = parsed.utility;
|
|
50
|
+
if (nextVariants.length > 0) {
|
|
51
|
+
rebuilt = nextVariants.join(':') + ':' + parsed.utility;
|
|
52
|
+
}
|
|
53
|
+
if (parsed.important) rebuilt = '!' + rebuilt;
|
|
54
|
+
return rebuilt;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export function extractStatesFromClasses(classes: string[]): StateInfo[] {
|
|
58
|
+
const stateMap: Record<string, StateInfo> = {};
|
|
59
|
+
const ensure = (name: string, trigger: string): StateInfo => {
|
|
60
|
+
if (!stateMap[name]) {
|
|
61
|
+
stateMap[name] = { name: name, trigger: trigger, classes: [] };
|
|
62
|
+
}
|
|
63
|
+
return stateMap[name];
|
|
64
|
+
};
|
|
65
|
+
|
|
66
|
+
ensure('default', '');
|
|
67
|
+
|
|
68
|
+
for (const cls of classes) {
|
|
69
|
+
const parsed = parseUtilityClass(cls);
|
|
70
|
+
const stateInfo = extractStateVariant(parsed.variants);
|
|
71
|
+
if (!stateInfo) {
|
|
72
|
+
stateMap['default'].classes.push(cls);
|
|
73
|
+
continue;
|
|
74
|
+
}
|
|
75
|
+
const stripped = stripStateVariant(cls, stateInfo.variant);
|
|
76
|
+
if (!stripped) continue;
|
|
77
|
+
const entry = ensure(stateInfo.state, stateInfo.variant + ':');
|
|
78
|
+
entry.classes.push(stripped);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return Object.keys(stateMap).map(key => stateMap[key]);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
export function getStateClasses(classes: string[], state: string): string[] {
|
|
85
|
+
const extracted = extractStatesFromClasses(classes);
|
|
86
|
+
for (const entry of extracted) {
|
|
87
|
+
if (entry.name === state) return entry.classes.slice();
|
|
88
|
+
}
|
|
89
|
+
return [];
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export function analyzeStateEffects(classes: string[], colorGroup: Record<string, string>): StateEffect[] {
|
|
93
|
+
const effects: StateEffect[] = [];
|
|
94
|
+
const style = tailwindClassesToStyle(classes, 'default', colorGroup);
|
|
95
|
+
if (style.bg) {
|
|
96
|
+
effects.push({ property: 'background', value: style.bg, token: style.bgToken });
|
|
97
|
+
}
|
|
98
|
+
if (style.border) {
|
|
99
|
+
effects.push({ property: 'border', value: style.border, token: style.borderToken });
|
|
100
|
+
}
|
|
101
|
+
if (style.text) {
|
|
102
|
+
effects.push({ property: 'text', value: style.text, token: style.textToken });
|
|
103
|
+
}
|
|
104
|
+
if (style.opacity != null) {
|
|
105
|
+
effects.push({ property: 'opacity', value: String(style.opacity) });
|
|
106
|
+
}
|
|
107
|
+
if (style.underline) {
|
|
108
|
+
effects.push({ property: 'underline', value: 'true' });
|
|
109
|
+
}
|
|
110
|
+
return effects;
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
export function mergeStatesWithDefinition(extracted: StateInfo[], defined: any): StateInfo[] {
|
|
114
|
+
if (!defined || !defined.states) return extracted;
|
|
115
|
+
const map: Record<string, StateInfo> = {};
|
|
116
|
+
for (const entry of extracted) {
|
|
117
|
+
map[entry.name] = {
|
|
118
|
+
name: entry.name,
|
|
119
|
+
trigger: entry.trigger,
|
|
120
|
+
classes: entry.classes.slice(),
|
|
121
|
+
effects: entry.effects,
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const definedStates = defined.states || {};
|
|
126
|
+
for (const stateName in definedStates) {
|
|
127
|
+
const defEntry = definedStates[stateName];
|
|
128
|
+
const defClasses = defEntry && defEntry.classes ? defEntry.classes : [];
|
|
129
|
+
if (!map[stateName]) {
|
|
130
|
+
map[stateName] = {
|
|
131
|
+
name: stateName,
|
|
132
|
+
trigger: stateName + ':',
|
|
133
|
+
classes: defClasses.slice(),
|
|
134
|
+
};
|
|
135
|
+
continue;
|
|
136
|
+
}
|
|
137
|
+
if (defClasses.length > 0) {
|
|
138
|
+
map[stateName].classes = map[stateName].classes.concat(defClasses);
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return Object.keys(map).map(key => map[key]);
|
|
143
|
+
}
|