@supernova-studio/model 0.58.27 → 0.59.1
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/dist/index.d.mts +433 -351
- package/dist/index.d.ts +433 -351
- package/dist/index.js +57 -25
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +53 -21
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- package/src/dsm/elements/data/figma-node-reference.ts +45 -17
- package/src/dsm/elements/raw-element.ts +19 -1
- package/src/dsm/elements/tokens.ts +11 -5
- package/src/dsm/import/support/import-context.ts +1 -0
- package/src/feature-flags/feature-flags.ts +1 -0
package/package.json
CHANGED
|
@@ -1,27 +1,55 @@
|
|
|
1
1
|
import { z } from "zod";
|
|
2
|
+
import { nullishToOptional } from "../../../helpers/nullish-to-optional";
|
|
2
3
|
|
|
4
|
+
//
|
|
5
|
+
// Enums
|
|
6
|
+
//
|
|
7
|
+
|
|
8
|
+
export const FigmaNodeRenderState = z.enum(["InProgress", "Success", "Failed"]);
|
|
3
9
|
export const FigmaNodeRenderFormat = z.enum(["Png", "Svg"]);
|
|
10
|
+
export const FigmaNodeRenderErrorType = z.enum(["MissingIntegration", "NodeNotFound", "RenderError"]);
|
|
11
|
+
|
|
12
|
+
export type FigmaNodeRenderState = z.infer<typeof FigmaNodeRenderState>;
|
|
13
|
+
export type FigmaNodeRenderFormat = z.infer<typeof FigmaNodeRenderFormat>;
|
|
14
|
+
export type FigmaNodeRenderErrorType = z.infer<typeof FigmaNodeRenderErrorType>;
|
|
15
|
+
|
|
16
|
+
//
|
|
17
|
+
// Definition
|
|
18
|
+
//
|
|
19
|
+
|
|
20
|
+
export const FigmaNodeRelinkData = z.object({
|
|
21
|
+
fileId: z.string(),
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
export const FigmaNodeRenderedImage = z.object({
|
|
25
|
+
resourceId: z.string(),
|
|
26
|
+
format: FigmaNodeRenderFormat,
|
|
27
|
+
scale: nullishToOptional(z.number()),
|
|
28
|
+
|
|
29
|
+
width: nullishToOptional(z.number()),
|
|
30
|
+
height: nullishToOptional(z.number()),
|
|
31
|
+
url: nullishToOptional(z.string()),
|
|
32
|
+
originKey: nullishToOptional(z.string()),
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
export const FigmaNodeRenderError = z.object({
|
|
36
|
+
type: FigmaNodeRenderErrorType,
|
|
37
|
+
});
|
|
4
38
|
|
|
5
39
|
export const FigmaNodeReferenceData = z.object({
|
|
6
|
-
structureElementId: z.string(),
|
|
7
40
|
nodeId: z.string(),
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
assetScale: z.number().optional(),
|
|
15
|
-
assetWidth: z.number().optional(),
|
|
16
|
-
assetHeight: z.number().optional(),
|
|
17
|
-
assetUrl: z.string().optional(),
|
|
18
|
-
assetOriginKey: z.string().optional(),
|
|
19
|
-
});
|
|
41
|
+
format: FigmaNodeRenderFormat,
|
|
42
|
+
scale: nullishToOptional(z.number()),
|
|
43
|
+
|
|
44
|
+
renderState: FigmaNodeRenderState,
|
|
45
|
+
renderedImage: FigmaNodeRenderedImage.optional(),
|
|
46
|
+
renderError: FigmaNodeRenderError.optional(),
|
|
20
47
|
|
|
21
|
-
|
|
22
|
-
|
|
48
|
+
hasSource: z.boolean(),
|
|
49
|
+
relinkData: FigmaNodeRelinkData.optional(),
|
|
23
50
|
});
|
|
24
51
|
|
|
25
|
-
export type
|
|
52
|
+
export type FigmaNodeRelinkData = z.infer<typeof FigmaNodeRelinkData>;
|
|
53
|
+
export type FigmaNodeRenderedImage = z.infer<typeof FigmaNodeRenderedImage>;
|
|
54
|
+
export type FigmaNodeRenderError = z.infer<typeof FigmaNodeRenderError>;
|
|
26
55
|
export type FigmaNodeReferenceData = z.infer<typeof FigmaNodeReferenceData>;
|
|
27
|
-
export type FigmaNodeReferenceElementData = z.infer<typeof FigmaNodeReferenceElementData>;
|
|
@@ -93,14 +93,32 @@ const stringTokenTypes: Set<DesignTokenType> = new Set([
|
|
|
93
93
|
"FontWeight",
|
|
94
94
|
] satisfies DesignTokenType[]);
|
|
95
95
|
|
|
96
|
-
|
|
96
|
+
const fallbackNumberValue = 14;
|
|
97
|
+
|
|
98
|
+
export function areTokenTypesCompatible(
|
|
99
|
+
lhs: DesignTokenType,
|
|
100
|
+
rhs: DesignTokenType,
|
|
101
|
+
isNonCompatibleTypeChangesEnabled = false
|
|
102
|
+
): boolean {
|
|
97
103
|
if (lhs === rhs) return true;
|
|
98
104
|
if (numberTokenTypes.has(lhs) && numberTokenTypes.has(rhs)) return true;
|
|
99
105
|
if (stringTokenTypes.has(lhs) && stringTokenTypes.has(rhs)) return true;
|
|
100
106
|
|
|
107
|
+
if (isNonCompatibleTypeChangesEnabled && stringTokenTypes.has(lhs) && numberTokenTypes.has(rhs)) return true;
|
|
108
|
+
|
|
101
109
|
return false;
|
|
102
110
|
}
|
|
103
111
|
|
|
112
|
+
export function castStringToDimensionValue(lhs: DesignTokenType, rhs: DesignTokenType, value?: unknown) {
|
|
113
|
+
if (stringTokenTypes.has(lhs) && numberTokenTypes.has(rhs) && value) {
|
|
114
|
+
const newValue = Number.parseFloat(value?.toString() ?? "");
|
|
115
|
+
const measure = Number.isNaN(newValue) ? fallbackNumberValue : newValue;
|
|
116
|
+
return { unit: "Pixels", measure };
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
return value;
|
|
120
|
+
}
|
|
121
|
+
|
|
104
122
|
//
|
|
105
123
|
// Element category
|
|
106
124
|
//
|
|
@@ -35,7 +35,7 @@ import {
|
|
|
35
35
|
VisibilityTokenData,
|
|
36
36
|
ZIndexTokenData,
|
|
37
37
|
} from "./data";
|
|
38
|
-
import { areTokenTypesCompatible, DesignTokenType } from "./raw-element";
|
|
38
|
+
import { areTokenTypesCompatible, castStringToDimensionValue, DesignTokenType } from "./raw-element";
|
|
39
39
|
|
|
40
40
|
//
|
|
41
41
|
// Base
|
|
@@ -279,15 +279,21 @@ export function extractTokenTypedData<T extends DesignTokenType, I extends Desig
|
|
|
279
279
|
|
|
280
280
|
export function convertTokenTypedData<I extends DesignTokenType, O extends DesignTokenType>(
|
|
281
281
|
source: DesignTokenTypedDataOfType<I>,
|
|
282
|
-
type: O
|
|
282
|
+
type: O,
|
|
283
|
+
isNonCompatibleTypeChangesEnabled: boolean
|
|
283
284
|
): DesignTokenTypedDataOfType<O> {
|
|
284
|
-
if (!areTokenTypesCompatible(source.type, type)) {
|
|
285
|
+
if (!areTokenTypesCompatible(source.type, type, isNonCompatibleTypeChangesEnabled)) {
|
|
285
286
|
throw SupernovaException.invalidOperation(`Cannot convert token from ${source.type} to ${type}`);
|
|
286
287
|
}
|
|
287
288
|
|
|
289
|
+
const data = source.data;
|
|
290
|
+
if (isNonCompatibleTypeChangesEnabled) {
|
|
291
|
+
data.value = castStringToDimensionValue(source.type, type, source.data.value);
|
|
292
|
+
}
|
|
293
|
+
|
|
288
294
|
return {
|
|
289
|
-
type
|
|
290
|
-
data
|
|
295
|
+
type,
|
|
296
|
+
data,
|
|
291
297
|
} as DesignTokenTypedDataOfType<O>;
|
|
292
298
|
}
|
|
293
299
|
|
|
@@ -60,6 +60,7 @@ export const FeatureFlagsKeepAliases = z.object({
|
|
|
60
60
|
isTypographyPropsKeepAliasesEnabled: z.boolean().default(false),
|
|
61
61
|
isGradientPropsKeepAliasesEnabled: z.boolean().default(false),
|
|
62
62
|
isShadowPropsKeepAliasesEnabled: z.boolean().default(false),
|
|
63
|
+
isNonCompatibleTypeChangesEnabled: z.boolean().default(false),
|
|
63
64
|
});
|
|
64
65
|
export type FeatureFlagsKeepAliases = z.infer<typeof FeatureFlagsKeepAliases>;
|
|
65
66
|
|
|
@@ -8,6 +8,7 @@ export const FlaggedFeature = z.enum([
|
|
|
8
8
|
"TypographyPropsKeepAliases",
|
|
9
9
|
"GradientPropsKeepAliases",
|
|
10
10
|
"ShadowPropsKeepAliases",
|
|
11
|
+
"NonCompatibleTypeChanges",
|
|
11
12
|
]);
|
|
12
13
|
export const FeatureFlagMap = z.record(FlaggedFeature, z.boolean());
|
|
13
14
|
export const FeatureFlag = z.object({
|