11const prefix = 'db' ;
22
33const fileHeader = `
4- @use "variables" as *;
5- @use "icon/icon-family-calc" as *;
6- // Do not edit directly
7- // Generated on
8- // ${ new Date ( ) . toString ( ) }
9- `;
4+ @use "variables" as *;
5+ @use "icon/icon-family-calc" as *;
6+ // Do not edit directly
7+ // Generated on
8+ // ${ new Date ( ) . toString ( ) }
9+ ` ;
1010
1111const getShortSize = ( size ) => {
1212 if ( size === '3xlarge' ) {
@@ -48,99 +48,44 @@ const getShortSize = (size) => {
4848 return size ;
4949} ;
5050
51- const getUtilityClass = ( utility , scale , textType , size ) => {
52- const isHeadline = textType === 'headline' ;
53-
54- let result = `
55- ${ utility ? '.' : '%' } ${ prefix } -${ scale } -${ textType } -${ getShortSize ( size ) } {
56- ` ;
57- result += `
58- line-height: $${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -line-height;
59- font-size: $${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -font-size;
60- ` ;
61-
62- if ( isHeadline ) {
63- result += `
64- font-weight: 700;
65-
66- &-light,
67- &[data-variant="light"] {
68- font-weight: 300;
69- }
51+ /**
52+ *
53+ * @param properties {{scale: string, textType:string, size:string, sSize:string, isHeadline:boolean, mQuery: string}}
54+ */
55+ const getMediaQueryProperties = ( properties ) => {
56+ const { textType, sSize, scale, size, isHeadline, mQuery } = properties ;
57+ let result = `--db-type-${ textType } -font-size-${ sSize } : #{$${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -font-size};
58+ --db-type-${ textType } -line-height-${ sSize } : #{$${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -line-height};
7059 ` ;
71- } else {
72- result += `
73- --db-base-icon-font-size: #{$${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -font-size};
74- --db-base-icon-font-family: #{get-icon-family($${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -font-size,
75- $${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -line-height)};
76- --db-base-icon-font-family-filled: #{get-icon-family($${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -font-size,
77- $${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -line-height,"filled")};
78- --db-type-body-font-size-${ getShortSize (
79- size
80- ) } : #{$${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -font-size};
81- --db-type-body-line-height-${ getShortSize (
82- size
83- ) } : #{$${ prefix } -typography-${ scale } -mobile-${ textType } -${ size } -line-height};
84- ` ;
85- }
86-
87- result += `
88- @media only screen and (min-width: $db-screens-md) {
89- line-height: $${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -line-height;
90- font-size: $${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -font-size;` ;
91- if ( ! isHeadline ) {
92- result += `
93- --db-base-icon-font-size: #{$${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -font-size};
94- --db-base-icon-font-family: #{get-icon-family($${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -font-size,
95- $${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -line-height)};
96- --db-base-icon-font-family-filled: #{get-icon-family($${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -font-size,
97- $${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -line-height,"filled")};
98- --db-type-body-font-size-${ getShortSize (
99- size
100- ) } : #{$${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -font-size};
101- --db-type-body-line-height-${ getShortSize (
102- size
103- ) } : #{$${ prefix } -typography-${ scale } -tablet-${ textType } -${ size } -line-height};
104- ` ;
105- }
106-
107- result += `}\n` ;
10860
109- result += `
110- @media only screen and (min-width: $db-screens-lg) {
111- line-height: $${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -line-height;
112- font-size: $${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -font-size;` ;
11361 if ( ! isHeadline ) {
11462 result += `
115- --db-base-icon-font-size: #{$${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -font-size};
116- --db-base-icon-font-family: #{get-icon-family($${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -font-size,
117- $${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -line-height)};
118- --db-base-icon-font-family-filled: #{get-icon-family($${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -font-size,
119- $${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -line-height,"filled")};
120- --db-type-body-font-size-${ getShortSize (
121- size
122- ) } : #{$${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -font-size};
123- --db-type-body-line-height-${ getShortSize (
124- size
125- ) } : #{$${ prefix } -typography-${ scale } -desktop-${ textType } -${ size } -line-height};
63+ --db-base-icon-font-size-${ sSize } : #{$${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -font-size};
64+ --db-base-icon-font-family-${ sSize } : #{get-icon-family($${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -font-size,
65+ $${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -line-height)};
66+ --db-base-icon-font-family-filled-${ sSize } : #{get-icon-family($${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -font-size,
67+ $${ prefix } -typography-${ scale } -${ mQuery } -${ textType } -${ size } -line-height,"filled")};
12668 ` ;
12769 }
12870
129- result += `}` ;
130-
131- result += `
132- }
133- ` ;
134-
13571 return result ;
13672} ;
13773
138- const generateClasses = ( typography , utility ) => {
139- let allClasses = fileHeader ;
74+ const getSizeProperties = ( scale , textType , size , mQuery ) => {
75+ const isHeadline = textType === 'headline' ;
76+ const sSize = getShortSize ( size ) ;
77+ return getMediaQueryProperties ( {
78+ scale,
79+ size,
80+ textType,
81+ sSize,
82+ isHeadline,
83+ mQuery
84+ } ) ;
85+ } ;
14086
141- if ( utility ) {
142- allClasses += `@use "variables" as *;\n@use "typography-placeholder" as *;\n` ;
143- }
87+ const generateTypography = ( typography ) => {
88+ let allClasses = fileHeader ;
14489
14590 // ScaleTypeKey = [regular, functional, expressive]
14691 for ( const scaleTypeKey of Object . keys ( typography ) ) {
@@ -154,19 +99,43 @@ const generateClasses = (typography, utility) => {
15499 for ( const textTypeKey of Object . keys ( firstMediaQueryObject ) ) {
155100 const textTypeObject = firstMediaQueryObject [ textTypeKey ] ;
156101 // SizeKey = [3xlarge - 3xsmall]
157- for ( const sizeKey of Object . keys ( textTypeObject ) ) {
158- allClasses += getUtilityClass (
159- utility ,
160- scaleTypeKey ,
161- textTypeKey ,
162- sizeKey
163- ) ;
102+ allClasses += `
103+ %${ prefix } -typography-${ textTypeKey } -${ scaleTypeKey } {
104+ ` ;
105+ for ( const mQuery of [ 'mobile' , 'tablet' , 'desktop' ] ) {
106+ if ( mQuery !== 'mobile' ) {
107+ allClasses += `@media only screen and (min-width: ${
108+ mQuery === 'tablet'
109+ ? '#{$db-screens-md}'
110+ : '#{$db-screens-lg}'
111+ } ) {
112+ ` ;
113+ }
114+
115+ for ( const sizeKey of Object . keys ( textTypeObject ) ) {
116+ allClasses += getSizeProperties (
117+ scaleTypeKey ,
118+ textTypeKey ,
119+ sizeKey ,
120+ mQuery
121+ ) ;
122+ }
123+
124+ if ( mQuery !== 'mobile' ) {
125+ allClasses += `}
126+
127+ ` ;
128+ }
164129 }
130+
131+ allClasses += `
132+ }
133+ ` ;
165134 }
166135 }
167136 }
168137
169138 return allClasses ;
170139} ;
171140
172- module . exports = generateClasses ;
141+ module . exports = generateTypography ;
0 commit comments