Skip to content

Commit 4f830ef

Browse files
committed
wip fix font style add preprocess
1 parent 01b5df5 commit 4f830ef

File tree

5 files changed

+43
-24
lines changed

5 files changed

+43
-24
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/preprocessors/add-font-styles.ts

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -66,29 +66,37 @@ function recurse(
6666
if (tokenType === 'typography') {
6767
const tokenTypographyValue = tokenValue as TokenTypographyValue & { fontStyle: string };
6868
if (tokenTypographyValue.fontWeight === undefined) return;
69+
70+
console.log(123, tokenTypographyValue);
6971
const fontWeight = resolveFontWeight(
7072
`${tokenTypographyValue.fontWeight}`,
7173
refCopy,
7274
usesDtcg,
7375
);
7476
const { weight, style } = splitWeightStyle(fontWeight, alwaysAddFontStyle);
75-
76-
tokenTypographyValue.fontWeight = weight;
7777
if (style) {
78+
tokenTypographyValue.fontWeight = weight;
7879
tokenTypographyValue.fontStyle = style;
7980
}
8081
} else if (tokenType === 'fontWeight') {
8182
const tokenFontWeightsValue = tokenValue as SingleFontWeightsToken['value'];
8283
const fontWeight = resolveFontWeight(`${tokenFontWeightsValue}`, refCopy, usesDtcg);
8384
const { weight, style } = splitWeightStyle(fontWeight, alwaysAddFontStyle);
8485

85-
// since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly
86-
token[`${usesDtcg ? '$' : ''}value`] = weight;
8786
if (style) {
88-
(slice as DeepKeyTokenMap<false>)[`fontStyle`] = {
89-
...token,
90-
[`${usesDtcg ? '$' : ''}type`]: 'fontStyle',
91-
[`${usesDtcg ? '$' : ''}value`]: style,
87+
// since tokenFontWeightsValue is a primitive (string), we have to permutate the change directly
88+
// token[`${usesDtcg ? '$' : ''}value`] = weight;
89+
(slice[key] as DeepKeyTokenMap<false>) = {
90+
weight: {
91+
...token,
92+
[`${usesDtcg ? '$' : ''}type`]: 'fontWeight',
93+
[`${usesDtcg ? '$' : ''}value`]: weight,
94+
},
95+
style: {
96+
...token,
97+
[`${usesDtcg ? '$' : ''}type`]: 'fontStyle',
98+
[`${usesDtcg ? '$' : ''}value`]: style,
99+
},
92100
};
93101
}
94102
}

test/integration/cross-file-refs.test.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ describe('cross file references', () => {
4242
it('supports cross file references e.g. expanding typography', async () => {
4343
const file = await promises.readFile(outputFilePath, 'utf-8');
4444
expect(file).to.include(`
45-
--sdTypoFontWeight: 400;
46-
--sdTypoFontStyle: italic;
45+
--sdTypoFontWeightWeight: 400;
46+
--sdTypoFontWeightStyle: italic;
4747
--sdPrimaryFont: Inter;
4848
--sdFontWeight: 800;
4949
--sdLineHeight: 1.5;
@@ -67,14 +67,14 @@ describe('cross file references', () => {
6767
--sdTestTypographyTextFontSize: 25px;
6868
--sdTestTypographyTextLineHeight: 32px;
6969
--sdTestTypographyTextFontWeight: 700;
70-
--sdWeight: 400;
71-
--sdTypoAliasFontWeight: 400;
72-
--sdTypoAliasFontStyle: italic;
70+
--sdWeightWeight: 400;
71+
--sdWeightStyle: italic;
72+
--sdTypoAliasFontWeightWeight: 400;
73+
--sdTypoAliasFontWeightStyle: italic;
7374
--sdTypo3FontFamily: Inter;
7475
--sdTypo3FontWeight: 800;
7576
--sdTypo3LineHeight: 1.5;
7677
--sdTypo3FontSize: 8px;
77-
--sdFontStyle: italic;
7878
`);
7979
});
8080
});

test/integration/expand-composition.test.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,16 +74,18 @@ describe('expand composition tokens', () => {
7474
--sdCompositionHeaderFontSizes: 96px;
7575
--sdCompositionHeaderFontWeights: 700;
7676
--sdTypography: italic 800 26px/1.25 Arial;
77-
--sdFontWeightRef: 800;
77+
--sdFontWeightRefWeight: 800;
78+
--sdFontWeightRefStyle: italic;
7879
--sdBorder: 4px solid #FFFF00;
7980
--sdShadowSingle: inset 0 4px 10px 0 rgba(0,0,0,0.4);
8081
--sdShadowDouble: inset 0 4px 10px 0 rgba(0,0,0,0.4), 0 8px 12px 5px rgba(0,0,0,0.4);
8182
--sdRef: italic 800 26px/1.25 Arial;`,
8283
);
8384
});
8485

85-
it('optionally can transform typography, border and shadow tokens', async () => {
86+
it.only('optionally can transform typography, border and shadow tokens', async () => {
8687
const file = await promises.readFile(outputFilePath, 'utf-8');
88+
console.log(file);
8789
expect(file).to.include(
8890
`
8991
--sdCompositionSize: 24px;
@@ -95,7 +97,8 @@ describe('expand composition tokens', () => {
9597
--sdCompositionHeaderFontSizes: 96px;
9698
--sdCompositionHeaderFontWeights: 700;
9799
--sdTypographyFontFamily: Arial;
98-
--sdTypographyFontWeight: 800;
100+
--sdTypographyFontWeightWeight: 800;
101+
--sdTypographyFontWeightStyle: italic;
99102
--sdTypographyLineHeight: 1.25;
100103
--sdTypographyFontSize: 26px;
101104
--sdTypographyLetterSpacing: 0rem;
@@ -104,7 +107,8 @@ describe('expand composition tokens', () => {
104107
--sdTypographyTextDecoration: none;
105108
--sdTypographyTextCase: none;
106109
--sdTypographyFontStyle: italic;
107-
--sdFontWeightRef: 800;
110+
--sdFontWeightRefWeight: 800;
111+
--sdFontWeightRefStyle: italic;
108112
--sdBorderColor: #ffff00;
109113
--sdBorderWidth: 4px;
110114
--sdBorderStyle: solid;

test/spec/preprocessors/add-font-styles.spec.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -106,8 +106,13 @@ describe('add font style', () => {
106106
fw: { value: 'SemiBold Italic', type: 'fontWeight' },
107107
}),
108108
).to.eql({
109-
fw: { value: 'SemiBold', type: 'fontWeight' },
110-
fontStyle: { value: 'italic', type: 'fontStyle' },
109+
fw: {
110+
weight: {
111+
value: 'SemiBold',
112+
type: 'fontWeight',
113+
},
114+
style: { value: 'italic', type: 'fontStyle' },
115+
},
111116
});
112117
});
113118

@@ -122,8 +127,10 @@ describe('add font style', () => {
122127
}),
123128
).to.eql({
124129
fw: {
125-
weight: { $value: 'SemiBold', $type: 'fontWeight' },
126-
fontStyle: { $value: 'italic', $type: 'fontStyle' },
130+
weight: {
131+
weight: { $value: 'SemiBold', $type: 'fontWeight' },
132+
style: { $value: 'italic', $type: 'fontStyle' },
133+
},
127134
},
128135
});
129136
});

0 commit comments

Comments
 (0)