@supernova-studio/model 0.58.27 → 0.59.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/dist/index.d.mts +28 -44
- package/dist/index.d.ts +28 -44
- package/dist/index.js +29 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +24 -6
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
- 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
|
@@ -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({
|