@seed-design/figma 0.0.20 → 0.0.22
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/lib/codegen/index.cjs +8019 -0
- package/lib/codegen/index.d.ts +1827 -0
- package/lib/codegen/index.js +7989 -0
- package/lib/codegen/targets/react/index.cjs +12205 -0
- package/lib/codegen/targets/react/index.d.ts +270 -0
- package/lib/codegen/targets/react/index.js +12187 -0
- package/lib/index.cjs +86 -2741
- package/lib/index.d.ts +18 -1933
- package/lib/index.js +68 -2715
- package/package.json +18 -9
- package/src/codegen/{targets/react/component/properties.type.ts → component-properties.ts} +43 -43
- package/src/codegen/core/codegen.ts +24 -9
- package/src/codegen/core/{component.ts → component-handler.ts} +3 -3
- package/src/codegen/core/component-type-helper.ts +35 -0
- package/src/codegen/core/context.ts +20 -0
- package/src/codegen/core/index.ts +16 -14
- package/src/codegen/core/infer-layout.test.ts +17 -16
- package/src/codegen/core/infer-layout.ts +1 -1
- package/src/codegen/core/{props.ts → props-converter.ts} +10 -13
- package/src/codegen/core/{value.ts → value-resolver.ts} +90 -52
- package/src/codegen/default-services.ts +44 -0
- package/src/codegen/index.ts +1 -44
- package/src/codegen/targets/figma/frame.ts +8 -8
- package/src/codegen/targets/figma/index.ts +1 -1
- package/src/codegen/targets/figma/pipeline.ts +71 -0
- package/src/codegen/targets/figma/props.ts +59 -70
- package/src/codegen/targets/figma/shape.ts +18 -18
- package/src/codegen/targets/figma/text.ts +6 -6
- package/src/codegen/targets/figma/value-resolver.ts +22 -0
- package/src/codegen/targets/react/component/deps.interface.ts +5 -4
- package/src/codegen/targets/react/component/{transformers → handlers}/action-button.ts +8 -14
- package/src/codegen/targets/react/component/{transformers → handlers}/action-chip.ts +10 -20
- package/src/codegen/targets/react/component/{transformers → handlers}/action-sheet.ts +13 -10
- package/src/codegen/targets/react/component/{transformers → handlers}/app-bar.ts +28 -36
- package/src/codegen/targets/react/component/handlers/avatar-stack.ts +29 -0
- package/src/codegen/targets/react/component/{transformers → handlers}/avatar.ts +12 -9
- package/src/codegen/targets/react/component/handlers/badge.ts +18 -0
- package/src/codegen/targets/react/component/{transformers → handlers}/callout.ts +6 -8
- package/src/codegen/targets/react/component/{transformers → handlers}/checkbox.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/chip-tabs.ts +10 -10
- package/src/codegen/targets/react/component/{transformers → handlers}/control-chip.ts +10 -20
- package/src/codegen/targets/react/component/{transformers → handlers}/error-state.ts +9 -9
- package/src/codegen/targets/react/component/{transformers → handlers}/extended-action-sheet.ts +16 -18
- package/src/codegen/targets/react/component/{transformers → handlers}/extended-fab.ts +6 -6
- package/src/codegen/targets/react/component/handlers/fab.ts +18 -0
- package/src/codegen/targets/react/component/{transformers → handlers}/help-bubble.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/identity-placeholder.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/inline-banner.ts +7 -10
- package/src/codegen/targets/react/component/{transformers → handlers}/manner-temp-badge.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/multiline-text-field.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/progress-circle.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/reaction-button.ts +6 -6
- package/src/codegen/targets/react/component/{transformers → handlers}/segmented-control.ts +10 -10
- package/src/codegen/targets/react/component/{transformers → handlers}/select-box.ts +10 -10
- package/src/codegen/targets/react/component/handlers/skeleton.ts +25 -0
- package/src/codegen/targets/react/component/{transformers → handlers}/snackbar.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/switch.ts +5 -5
- package/src/codegen/targets/react/component/{transformers → handlers}/tabs.ts +15 -15
- package/src/codegen/targets/react/component/{transformers → handlers}/text-button.ts +7 -13
- package/src/codegen/targets/react/component/{transformers → handlers}/text-field.ts +9 -9
- package/src/codegen/targets/react/component/{transformers → handlers}/toggle-button.ts +7 -11
- package/src/codegen/targets/react/component/index.ts +79 -75
- package/src/codegen/targets/react/frame.ts +8 -8
- package/src/codegen/targets/react/icon.ts +50 -0
- package/src/codegen/targets/react/index.ts +1 -1
- package/src/codegen/targets/react/instance.ts +19 -50
- package/src/codegen/targets/react/pipeline.ts +108 -0
- package/src/codegen/targets/react/props.ts +95 -73
- package/src/codegen/targets/react/shape.ts +5 -5
- package/src/codegen/targets/react/text.ts +6 -6
- package/src/codegen/targets/react/value-resolver.ts +35 -0
- package/src/entities/icon.repository.ts +2 -2
- package/src/entities/icon.service.ts +9 -20
- package/src/entities/style.service.ts +5 -17
- package/src/entities/variable.service.ts +36 -68
- package/src/normalizer/from-plugin.ts +3 -0
- package/src/normalizer/from-rest.ts +6 -0
- package/src/normalizer/types.ts +4 -1
- package/src/utils/figma-variable.ts +39 -3
- package/src/codegen/core/component.types.ts +0 -29
- package/src/codegen/targets/figma/context.ts +0 -139
- package/src/codegen/targets/react/component/transformers/avatar-stack.ts +0 -29
- package/src/codegen/targets/react/component/transformers/badge.ts +0 -21
- package/src/codegen/targets/react/component/transformers/fab.ts +0 -18
- package/src/codegen/targets/react/component/transformers/skeleton.ts +0 -51
- package/src/codegen/targets/react/context.ts +0 -176
- /package/src/codegen/core/{element.ts → element-transformer.ts} +0 -0
|
@@ -1,18 +1,15 @@
|
|
|
1
1
|
import type { VariableValueResolved } from "@/entities";
|
|
2
|
-
import type { NormalizedSceneNode } from "@/normalizer";
|
|
3
2
|
import { objectEntries } from "@/utils/common";
|
|
4
|
-
import type { ElementNode } from "./jsx";
|
|
5
3
|
|
|
6
|
-
export type
|
|
4
|
+
export type PropsConverter<
|
|
7
5
|
T extends Record<string, any> = Record<string, any>,
|
|
8
6
|
R extends Record<string, any> = Record<string, any>,
|
|
9
|
-
> = (node: T
|
|
7
|
+
> = (node: T) => R;
|
|
10
8
|
|
|
11
|
-
export function
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
return transformer;
|
|
9
|
+
export function definePropsConverter<T extends Record<string, any>, R extends Record<string, any>>(
|
|
10
|
+
converter: PropsConverter<T, R>,
|
|
11
|
+
) {
|
|
12
|
+
return converter;
|
|
16
13
|
}
|
|
17
14
|
|
|
18
15
|
type Handlers<
|
|
@@ -28,7 +25,7 @@ type Shorthands<TProps extends Record<string, any>, HandlerKeys extends keyof TP
|
|
|
28
25
|
HandlerKeys[]
|
|
29
26
|
>;
|
|
30
27
|
|
|
31
|
-
export interface
|
|
28
|
+
export interface CreatePropsConverterConfig<
|
|
32
29
|
TTrait extends Record<string, any>,
|
|
33
30
|
TProps extends Record<string, any>,
|
|
34
31
|
HandlerKeys extends keyof TProps,
|
|
@@ -42,7 +39,7 @@ export interface PropsTransformerConfig<
|
|
|
42
39
|
defaults?: Partial<TProps>;
|
|
43
40
|
}
|
|
44
41
|
|
|
45
|
-
export function
|
|
42
|
+
export function createPropsConverter<
|
|
46
43
|
TTrait extends Record<string, any>,
|
|
47
44
|
TProps extends Record<string, any>,
|
|
48
45
|
HandlerKeys extends keyof TProps,
|
|
@@ -50,8 +47,8 @@ export function createPropsTransformer<
|
|
|
50
47
|
handlers,
|
|
51
48
|
shorthands,
|
|
52
49
|
defaults,
|
|
53
|
-
}:
|
|
54
|
-
return
|
|
50
|
+
}: CreatePropsConverterConfig<TTrait, TProps, HandlerKeys>): PropsConverter<TTrait, TProps> {
|
|
51
|
+
return definePropsConverter((node: TTrait) => {
|
|
55
52
|
const result = {} as TProps;
|
|
56
53
|
|
|
57
54
|
for (const [prop, handler] of objectEntries(handlers)) {
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { StyleService, VariableValueResolved } from "@/entities";
|
|
1
2
|
import type {
|
|
2
3
|
NormalizedCornerTrait,
|
|
3
4
|
NormalizedHasFramePropertiesTrait,
|
|
@@ -14,8 +15,9 @@ import {
|
|
|
14
15
|
} from "@/utils/figma-node";
|
|
15
16
|
import type { RGBA } from "@figma/rest-api-spec";
|
|
16
17
|
import type { VariableService } from "../../entities/variable.service";
|
|
18
|
+
import { useCodegenOptions } from "./context";
|
|
17
19
|
|
|
18
|
-
export interface
|
|
20
|
+
export interface ValueResolver<TColor, TDimension, TFontDimension, TFontWeight> {
|
|
19
21
|
getFormattedValue: {
|
|
20
22
|
frameFill: (
|
|
21
23
|
node: NormalizedHasGeometryTrait & NormalizedIsLayerTrait,
|
|
@@ -84,44 +86,83 @@ export interface ValueTransformer<TColor, TDimension, TFontDimension, TFontWeigh
|
|
|
84
86
|
node: NormalizedTypePropertiesTrait & NormalizedIsLayerTrait,
|
|
85
87
|
) => string | TFontDimension | undefined;
|
|
86
88
|
};
|
|
89
|
+
getTextStyleValue: (
|
|
90
|
+
node: NormalizedTypePropertiesTrait & NormalizedIsLayerTrait,
|
|
91
|
+
) => string | undefined; // TODO: we might turn this into a generic; not sure yet
|
|
87
92
|
}
|
|
88
93
|
|
|
89
|
-
export interface
|
|
94
|
+
export interface ValueResolverDeps<TColor, TDimension, TFontDimension, TFontWeight> {
|
|
90
95
|
variableService: VariableService;
|
|
91
|
-
|
|
96
|
+
variableNameFormatter: (props: { slug: string[] }) => string;
|
|
97
|
+
styleService: StyleService;
|
|
98
|
+
styleNameFormatter: (props: { slug: string[] }) => string;
|
|
99
|
+
rawValueFormatters: {
|
|
92
100
|
color: (value: RGBA) => string | TColor;
|
|
93
101
|
dimension: (value: number) => string | TDimension;
|
|
94
102
|
fontDimension: (value: number) => string | TFontDimension;
|
|
95
103
|
fontWeight: (value: number) => string | TFontWeight;
|
|
96
104
|
};
|
|
97
|
-
shouldInferVariableName: boolean;
|
|
98
105
|
}
|
|
99
106
|
|
|
100
|
-
export function
|
|
107
|
+
export function createValueResolver<TColor, TDimension, TFontDimension, TFontWeight>({
|
|
101
108
|
variableService,
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
109
|
+
variableNameFormatter,
|
|
110
|
+
styleService,
|
|
111
|
+
styleNameFormatter,
|
|
112
|
+
rawValueFormatters,
|
|
113
|
+
}: ValueResolverDeps<TColor, TDimension, TFontDimension, TFontWeight>): ValueResolver<
|
|
105
114
|
TColor,
|
|
106
115
|
TDimension,
|
|
107
116
|
TFontDimension,
|
|
108
117
|
TFontWeight
|
|
109
118
|
> {
|
|
119
|
+
function getVariableName(key: string) {
|
|
120
|
+
const slug = variableService.getSlug(key);
|
|
121
|
+
|
|
122
|
+
if (!slug) {
|
|
123
|
+
return undefined;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return variableNameFormatter({ slug });
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
function inferVariableName(value: VariableValueResolved, scope: VariableScope) {
|
|
130
|
+
const { shouldInferVariableName } = useCodegenOptions();
|
|
131
|
+
|
|
132
|
+
if (!shouldInferVariableName) {
|
|
133
|
+
return undefined;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
const inferred = variableService.infer(value, scope);
|
|
137
|
+
|
|
138
|
+
if (!inferred) {
|
|
139
|
+
return undefined;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return getVariableName(inferred.key);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
function getStyleName(key: string) {
|
|
146
|
+
const slug = styleService.getSlug(key);
|
|
147
|
+
|
|
148
|
+
if (!slug) {
|
|
149
|
+
return undefined;
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
return styleNameFormatter({ slug });
|
|
153
|
+
}
|
|
154
|
+
|
|
110
155
|
function processColor(
|
|
111
156
|
key: string | undefined,
|
|
112
157
|
value: RGBA | undefined,
|
|
113
158
|
scope: "FRAME_FILL" | "SHAPE_FILL" | "STROKE_COLOR" | "TEXT_FILL",
|
|
114
159
|
) {
|
|
115
160
|
if (key) {
|
|
116
|
-
return
|
|
161
|
+
return getVariableName(key);
|
|
117
162
|
}
|
|
118
163
|
|
|
119
|
-
if (value) {
|
|
120
|
-
|
|
121
|
-
return variableService.inferVariableName(value, scope) ?? formatters.color(value);
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return formatters.color(value);
|
|
164
|
+
if (value !== undefined) {
|
|
165
|
+
return inferVariableName(value, scope) ?? rawValueFormatters.color(value);
|
|
125
166
|
}
|
|
126
167
|
|
|
127
168
|
return undefined;
|
|
@@ -133,15 +174,11 @@ export function createValueTransformer<TColor, TDimension, TFontDimension, TFont
|
|
|
133
174
|
scope: "WIDTH_HEIGHT" | "GAP" | "CORNER_RADIUS",
|
|
134
175
|
) {
|
|
135
176
|
if (key) {
|
|
136
|
-
return
|
|
177
|
+
return getVariableName(key);
|
|
137
178
|
}
|
|
138
179
|
|
|
139
|
-
if (value) {
|
|
140
|
-
|
|
141
|
-
return variableService.inferVariableName(value, scope) ?? formatters.dimension(value);
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
return formatters.dimension(value);
|
|
180
|
+
if (value !== undefined) {
|
|
181
|
+
return inferVariableName(value, scope) ?? rawValueFormatters.dimension(value);
|
|
145
182
|
}
|
|
146
183
|
|
|
147
184
|
return undefined;
|
|
@@ -153,15 +190,11 @@ export function createValueTransformer<TColor, TDimension, TFontDimension, TFont
|
|
|
153
190
|
scope: "FONT_SIZE" | "LINE_HEIGHT",
|
|
154
191
|
) {
|
|
155
192
|
if (key) {
|
|
156
|
-
return
|
|
193
|
+
return getVariableName(key);
|
|
157
194
|
}
|
|
158
195
|
|
|
159
|
-
if (value) {
|
|
160
|
-
|
|
161
|
-
return variableService.inferVariableName(value, scope) ?? formatters.fontDimension(value);
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
return formatters.fontDimension(value);
|
|
196
|
+
if (value !== undefined) {
|
|
197
|
+
return inferVariableName(value, scope) ?? rawValueFormatters.fontDimension(value);
|
|
165
198
|
}
|
|
166
199
|
|
|
167
200
|
return undefined;
|
|
@@ -169,37 +202,33 @@ export function createValueTransformer<TColor, TDimension, TFontDimension, TFont
|
|
|
169
202
|
|
|
170
203
|
function processFontWeight(key: string | undefined, value: number | undefined) {
|
|
171
204
|
if (key) {
|
|
172
|
-
return
|
|
205
|
+
return getVariableName(key);
|
|
173
206
|
}
|
|
174
207
|
|
|
175
|
-
if (value) {
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
};
|
|
208
|
+
if (value !== undefined) {
|
|
209
|
+
const fontWeightToString: Record<number, string> = {
|
|
210
|
+
100: "thin",
|
|
211
|
+
200: "extra-light",
|
|
212
|
+
300: "light",
|
|
213
|
+
400: "regular",
|
|
214
|
+
500: "medium",
|
|
215
|
+
600: "semi-bold",
|
|
216
|
+
700: "bold",
|
|
217
|
+
800: "extra-bold",
|
|
218
|
+
900: "black",
|
|
219
|
+
};
|
|
188
220
|
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
return formatters.fontWeight(value);
|
|
221
|
+
return (
|
|
222
|
+
inferVariableName(value, "FONT_WEIGHT") ??
|
|
223
|
+
inferVariableName(fontWeightToString[value], "FONT_STYLE") ??
|
|
224
|
+
rawValueFormatters.fontWeight(value)
|
|
225
|
+
);
|
|
197
226
|
}
|
|
198
227
|
|
|
199
228
|
return undefined;
|
|
200
229
|
}
|
|
201
230
|
|
|
202
|
-
const getFormattedValue:
|
|
231
|
+
const getFormattedValue: ValueResolver<
|
|
203
232
|
TColor,
|
|
204
233
|
TDimension,
|
|
205
234
|
TFontDimension,
|
|
@@ -283,7 +312,16 @@ export function createValueTransformer<TColor, TDimension, TFontDimension, TFont
|
|
|
283
312
|
),
|
|
284
313
|
};
|
|
285
314
|
|
|
315
|
+
function getTextStyleValue(node: NormalizedTypePropertiesTrait & NormalizedIsLayerTrait) {
|
|
316
|
+
if (node.textStyleKey) {
|
|
317
|
+
return getStyleName(node.textStyleKey);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
return undefined;
|
|
321
|
+
}
|
|
322
|
+
|
|
286
323
|
return {
|
|
287
324
|
getFormattedValue,
|
|
325
|
+
getTextStyleValue,
|
|
288
326
|
};
|
|
289
327
|
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import {
|
|
2
|
+
createIconService,
|
|
3
|
+
createStyleService,
|
|
4
|
+
createVariableService,
|
|
5
|
+
iconRepository,
|
|
6
|
+
styleRepository,
|
|
7
|
+
variableRepository,
|
|
8
|
+
} from "@/entities";
|
|
9
|
+
|
|
10
|
+
export const styleService = createStyleService({
|
|
11
|
+
styleRepository,
|
|
12
|
+
});
|
|
13
|
+
export const variableService = createVariableService({
|
|
14
|
+
variableRepository,
|
|
15
|
+
inferCompareFunction: (a, b) => {
|
|
16
|
+
const scoreFn = (name: string) => {
|
|
17
|
+
let score = 0;
|
|
18
|
+
if (name.includes("bg")) {
|
|
19
|
+
score += 100;
|
|
20
|
+
}
|
|
21
|
+
if (name.includes("fg")) {
|
|
22
|
+
score += 100;
|
|
23
|
+
}
|
|
24
|
+
if (name.includes("stroke")) {
|
|
25
|
+
score += 100;
|
|
26
|
+
}
|
|
27
|
+
if (name.includes("spacing-x")) {
|
|
28
|
+
score -= 100;
|
|
29
|
+
}
|
|
30
|
+
if (name.includes("spacing-y")) {
|
|
31
|
+
score -= 100;
|
|
32
|
+
}
|
|
33
|
+
if (name.endsWith("pressed")) {
|
|
34
|
+
score -= 100;
|
|
35
|
+
}
|
|
36
|
+
return score;
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
return scoreFn(b.name) - scoreFn(a.name);
|
|
40
|
+
},
|
|
41
|
+
});
|
|
42
|
+
export const iconService = createIconService({
|
|
43
|
+
iconRepository,
|
|
44
|
+
});
|
package/src/codegen/index.ts
CHANGED
|
@@ -1,46 +1,3 @@
|
|
|
1
|
+
export * from "./component-properties";
|
|
1
2
|
export * from "./core";
|
|
2
3
|
export * from "./targets";
|
|
3
|
-
|
|
4
|
-
import type { NormalizedSceneNode } from "@/normalizer";
|
|
5
|
-
import { stringifyElement } from "./core/jsx";
|
|
6
|
-
import { figma, react } from "./targets";
|
|
7
|
-
|
|
8
|
-
export function generateJsxTree(
|
|
9
|
-
node: NormalizedSceneNode,
|
|
10
|
-
options: Partial<react.CreateContextOptions> = {},
|
|
11
|
-
) {
|
|
12
|
-
const { shouldInferVariableName = true, shouldInferAutoLayout = true } = options;
|
|
13
|
-
const codegen = react.createContext({
|
|
14
|
-
shouldInferVariableName,
|
|
15
|
-
shouldInferAutoLayout,
|
|
16
|
-
});
|
|
17
|
-
|
|
18
|
-
return codegen(node);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export function generateCode(
|
|
22
|
-
node: NormalizedSceneNode,
|
|
23
|
-
options: Partial<react.CreateContextOptions> & { shouldPrintSource?: boolean } = {},
|
|
24
|
-
) {
|
|
25
|
-
const result = generateJsxTree(node, options);
|
|
26
|
-
return result ? stringifyElement(result, { printSource: options.shouldPrintSource }) : undefined;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export function generateFigmaSummary(
|
|
30
|
-
node: NormalizedSceneNode,
|
|
31
|
-
options: Partial<figma.CreateContextOptions> & { shouldPrintSource?: boolean } = {},
|
|
32
|
-
) {
|
|
33
|
-
const {
|
|
34
|
-
shouldInferVariableName = false,
|
|
35
|
-
shouldPrintSource = false,
|
|
36
|
-
shouldInferAutoLayout = false,
|
|
37
|
-
} = options;
|
|
38
|
-
const codegen = figma.createContext({
|
|
39
|
-
shouldInferVariableName,
|
|
40
|
-
shouldInferAutoLayout,
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
const result = codegen(node);
|
|
44
|
-
|
|
45
|
-
return result ? stringifyElement(result, { printSource: shouldPrintSource }) : undefined;
|
|
46
|
-
}
|
|
@@ -4,14 +4,14 @@ import type {
|
|
|
4
4
|
NormalizedInstanceNode,
|
|
5
5
|
} from "@/normalizer";
|
|
6
6
|
import { createElement, defineElementTransformer, type ElementTransformer } from "../../core";
|
|
7
|
-
import type {
|
|
7
|
+
import type { PropsConverters } from "./props";
|
|
8
8
|
|
|
9
9
|
export interface FrameTransformerDeps {
|
|
10
|
-
|
|
10
|
+
propsConverters: PropsConverters;
|
|
11
11
|
}
|
|
12
12
|
|
|
13
13
|
export function createFrameTransformer({
|
|
14
|
-
|
|
14
|
+
propsConverters,
|
|
15
15
|
}: FrameTransformerDeps): ElementTransformer<
|
|
16
16
|
NormalizedFrameNode | NormalizedInstanceNode | NormalizedComponentNode
|
|
17
17
|
> {
|
|
@@ -20,11 +20,11 @@ export function createFrameTransformer({
|
|
|
20
20
|
const children = node.children;
|
|
21
21
|
|
|
22
22
|
const props = {
|
|
23
|
-
...
|
|
24
|
-
...
|
|
25
|
-
...
|
|
26
|
-
...
|
|
27
|
-
...
|
|
23
|
+
...propsConverters.radius(node),
|
|
24
|
+
...propsConverters.containerLayout(node),
|
|
25
|
+
...propsConverters.selfLayout(node),
|
|
26
|
+
...propsConverters.frameFill(node),
|
|
27
|
+
...propsConverters.stroke(node),
|
|
28
28
|
};
|
|
29
29
|
|
|
30
30
|
return createElement(
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { createCodeGenerator } from "@/codegen/core";
|
|
2
|
+
import { createFrameTransformer } from "./frame";
|
|
3
|
+
import { createInstanceTransformer } from "./instance";
|
|
4
|
+
import {
|
|
5
|
+
createContainerLayoutPropsConverter,
|
|
6
|
+
createFrameFillPropsConverter,
|
|
7
|
+
createRadiusPropsConverter,
|
|
8
|
+
createSelfLayoutPropsConverter,
|
|
9
|
+
createShapeFillPropsConverter,
|
|
10
|
+
createStrokePropsConverter,
|
|
11
|
+
createTextFillPropsConverter,
|
|
12
|
+
createTypeStylePropsConverter,
|
|
13
|
+
} from "./props";
|
|
14
|
+
import {
|
|
15
|
+
createBooleanOperationTransformer,
|
|
16
|
+
createRectangleTransformer,
|
|
17
|
+
createVectorTransformer,
|
|
18
|
+
} from "./shape";
|
|
19
|
+
import { createTextTransformer } from "./text";
|
|
20
|
+
import { valueResolver } from "./value-resolver";
|
|
21
|
+
|
|
22
|
+
export function createPipeline() {
|
|
23
|
+
const containerLayoutPropsConverter = createContainerLayoutPropsConverter(valueResolver);
|
|
24
|
+
const selfLayoutPropsConverter = createSelfLayoutPropsConverter(valueResolver);
|
|
25
|
+
const frameFillPropsConverter = createFrameFillPropsConverter(valueResolver);
|
|
26
|
+
const shapeFillPropsConverter = createShapeFillPropsConverter(valueResolver);
|
|
27
|
+
const textFillPropsConverter = createTextFillPropsConverter(valueResolver);
|
|
28
|
+
const radiusPropsConverter = createRadiusPropsConverter(valueResolver);
|
|
29
|
+
const strokePropsConverter = createStrokePropsConverter(valueResolver);
|
|
30
|
+
const typeStylePropsConverter = createTypeStylePropsConverter(valueResolver);
|
|
31
|
+
const propsConverters = {
|
|
32
|
+
containerLayout: containerLayoutPropsConverter,
|
|
33
|
+
selfLayout: selfLayoutPropsConverter,
|
|
34
|
+
frameFill: frameFillPropsConverter,
|
|
35
|
+
shapeFill: shapeFillPropsConverter,
|
|
36
|
+
textFill: textFillPropsConverter,
|
|
37
|
+
radius: radiusPropsConverter,
|
|
38
|
+
stroke: strokePropsConverter,
|
|
39
|
+
typeStyle: typeStylePropsConverter,
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const frameTransformer = createFrameTransformer({
|
|
43
|
+
propsConverters,
|
|
44
|
+
});
|
|
45
|
+
const instanceTransformer = createInstanceTransformer({
|
|
46
|
+
frameTransformer,
|
|
47
|
+
});
|
|
48
|
+
const textTransformer = createTextTransformer({
|
|
49
|
+
propsConverters,
|
|
50
|
+
});
|
|
51
|
+
const rectangleTransformer = createRectangleTransformer({
|
|
52
|
+
propsConverters,
|
|
53
|
+
});
|
|
54
|
+
const vectorTransformer = createVectorTransformer({
|
|
55
|
+
propsConverters,
|
|
56
|
+
});
|
|
57
|
+
const booleanOperationTransformer = createBooleanOperationTransformer({
|
|
58
|
+
propsConverters,
|
|
59
|
+
});
|
|
60
|
+
|
|
61
|
+
const codegenTransformer = createCodeGenerator({
|
|
62
|
+
frameTransformer,
|
|
63
|
+
textTransformer,
|
|
64
|
+
rectangleTransformer,
|
|
65
|
+
instanceTransformer,
|
|
66
|
+
vectorTransformer,
|
|
67
|
+
booleanOperationTransformer,
|
|
68
|
+
});
|
|
69
|
+
|
|
70
|
+
return codegenTransformer;
|
|
71
|
+
}
|