@gem-sdk/core 1.12.0-next.31 → 1.12.0-next.36

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.
@@ -23,10 +23,10 @@ const makeStyleKey = (name)=>{
23
23
  ].map((key)=>`--${key}`);
24
24
  };
25
25
  const makeStyle = (style)=>{
26
- return Object.fromEntries(Object.entries(style).map(([key, value])=>[
26
+ return removeNullUndefined(Object.fromEntries(Object.entries(style).map(([key, value])=>[
27
27
  `--${key}`,
28
28
  value
29
- ]));
29
+ ])));
30
30
  };
31
31
  const makeStyleState = (name, value)=>{
32
32
  if (!value) return {};
@@ -60,8 +60,11 @@ const template = (strings, ...keys)=>{
60
60
  });
61
61
  return str;
62
62
  };
63
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
64
+ const composeMemo = (fn, _)=>fn();
63
65
 
64
66
  exports.RenderIf = RenderIf;
67
+ exports.composeMemo = composeMemo;
65
68
  exports.dataStringify = dataStringify;
66
69
  exports.props = props;
67
70
  exports.styles = styles;
@@ -1,5 +1,8 @@
1
1
  'use strict';
2
2
 
3
+ var colors = require('./colors.js');
4
+ var makeStyle = require('./make-style.js');
5
+
3
6
  const genTypoClass = (name)=>{
4
7
  return `g-${name}`;
5
8
  };
@@ -15,6 +18,71 @@ const composeTypographyCss = (typography)=>{
15
18
  ${lineHeight ? `line-height: ${lineHeight};` : ''}
16
19
  `;
17
20
  };
21
+ function getCustomCSSByDevice(typography, device) {
22
+ if (!typography || !device) return {};
23
+ const suffix = device === 'desktop' || !device ? '' : `-${device}`;
24
+ const { fontFamily } = typography?.[device] ?? {};
25
+ return {
26
+ [`--size${suffix}`]: typography?.[device]?.fontSize,
27
+ [`--lh${suffix}`]: typography?.[device]?.lineHeight,
28
+ [`--fs${suffix}`]: typography?.[device]?.fontStyle,
29
+ [`--ff${suffix}`]: fontFamily ? `var(--g-font-${fontFamily}, ${fontFamily})` : undefined,
30
+ [`--weight${suffix}`]: typography?.[device]?.fontWeight,
31
+ [`--ls${suffix}`]: typography?.[device]?.letterSpacing
32
+ };
33
+ }
34
+ const composeTypography = (typography)=>{
35
+ if (!typography) return {};
36
+ return makeStyle.removeNullUndefined({
37
+ ...getCustomCSSByDevice(typography, 'desktop'),
38
+ ...getCustomCSSByDevice(typography, 'tablet'),
39
+ ...getCustomCSSByDevice(typography, 'mobile')
40
+ });
41
+ };
42
+ const composeTypographyV2 = (value, attrs)=>{
43
+ if (!value) return {};
44
+ return makeStyle.removeNullUndefined({
45
+ ...makeStyle.makeStyle({
46
+ fs: !attrs?.italic && value?.fontStyle,
47
+ ff: value?.fontFamily ? `var(--g-font-${value.fontFamily}, ${value.fontFamily})` : undefined,
48
+ weight: !attrs?.bold && value?.fontWeight,
49
+ ls: value?.letterSpacing,
50
+ lh: value?.lineHeight
51
+ }),
52
+ ...makeStyle.makeStyleResponsive('size', value?.fontSize)
53
+ });
54
+ };
55
+ const composeTypographyAttr = (attrs)=>{
56
+ if (!attrs) return {};
57
+ return makeStyle.removeNullUndefined({
58
+ ...makeStyle.makeStyle({
59
+ fs: attrs?.italic && 'italic',
60
+ weight: attrs?.bold && 'bold',
61
+ c: colors.getSingleColorVariable(attrs?.color),
62
+ tt: attrs?.transform,
63
+ tdl: attrs?.underline ? 'underline' : undefined
64
+ })
65
+ });
66
+ };
67
+ const composeTypographyClassName = (typo, typography)=>{
68
+ return typo ? typo?.type && !typo.custom ? genTypoClass(typo.type) : '' : typography?.type && genTypoClass(typography?.type);
69
+ };
70
+ const composeTypographyStyle = (typo, typography, disableAttr)=>{
71
+ if (typo) {
72
+ return {
73
+ ...composeTypographyV2(typo.custom),
74
+ ...!disableAttr && composeTypographyAttr(typo.attrs)
75
+ };
76
+ }
77
+ return {
78
+ ...!typography?.type ? composeTypography(typography?.custom) : {}
79
+ };
80
+ };
18
81
 
82
+ exports.composeTypography = composeTypography;
83
+ exports.composeTypographyAttr = composeTypographyAttr;
84
+ exports.composeTypographyClassName = composeTypographyClassName;
19
85
  exports.composeTypographyCss = composeTypographyCss;
86
+ exports.composeTypographyStyle = composeTypographyStyle;
87
+ exports.composeTypographyV2 = composeTypographyV2;
20
88
  exports.genTypoClass = genTypoClass;
package/dist/cjs/index.js CHANGED
@@ -178,7 +178,12 @@ exports.getGlobalColorStateStyle = colors.getGlobalColorStateStyle;
178
178
  exports.getGlobalColorStyle = colors.getGlobalColorStyle;
179
179
  exports.getSingleColorVariable = colors.getSingleColorVariable;
180
180
  exports.isColor = colors.isColor;
181
+ exports.composeTypography = typography.composeTypography;
182
+ exports.composeTypographyAttr = typography.composeTypographyAttr;
183
+ exports.composeTypographyClassName = typography.composeTypographyClassName;
181
184
  exports.composeTypographyCss = typography.composeTypographyCss;
185
+ exports.composeTypographyStyle = typography.composeTypographyStyle;
186
+ exports.composeTypographyV2 = typography.composeTypographyV2;
182
187
  exports.genTypoClass = typography.genTypoClass;
183
188
  exports.composeCornerCss = radius.composeCornerCss;
184
189
  exports.composeRadius = radius.composeRadius;
@@ -192,6 +197,7 @@ exports.fpixel = fpixel;
192
197
  exports.gtag = gtag;
193
198
  exports.tiktokpixel = tiktokpixel;
194
199
  exports.RenderIf = render.RenderIf;
200
+ exports.composeMemo = render.composeMemo;
195
201
  exports.dataStringify = render.dataStringify;
196
202
  exports.props = render.props;
197
203
  exports.styles = render.styles;
@@ -21,10 +21,10 @@ const makeStyleKey = (name)=>{
21
21
  ].map((key)=>`--${key}`);
22
22
  };
23
23
  const makeStyle = (style)=>{
24
- return Object.fromEntries(Object.entries(style).map(([key, value])=>[
24
+ return removeNullUndefined(Object.fromEntries(Object.entries(style).map(([key, value])=>[
25
25
  `--${key}`,
26
26
  value
27
- ]));
27
+ ])));
28
28
  };
29
29
  const makeStyleState = (name, value)=>{
30
30
  if (!value) return {};
@@ -58,5 +58,7 @@ const template = (strings, ...keys)=>{
58
58
  });
59
59
  return str;
60
60
  };
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
+ const composeMemo = (fn, _)=>fn();
61
63
 
62
- export { RenderIf, dataStringify, props, styles, template };
64
+ export { RenderIf, composeMemo, dataStringify, props, styles, template };
@@ -1,3 +1,6 @@
1
+ import { getSingleColorVariable } from './colors.js';
2
+ import { removeNullUndefined, makeStyle, makeStyleResponsive } from './make-style.js';
3
+
1
4
  const genTypoClass = (name)=>{
2
5
  return `g-${name}`;
3
6
  };
@@ -13,5 +16,65 @@ const composeTypographyCss = (typography)=>{
13
16
  ${lineHeight ? `line-height: ${lineHeight};` : ''}
14
17
  `;
15
18
  };
19
+ function getCustomCSSByDevice(typography, device) {
20
+ if (!typography || !device) return {};
21
+ const suffix = device === 'desktop' || !device ? '' : `-${device}`;
22
+ const { fontFamily } = typography?.[device] ?? {};
23
+ return {
24
+ [`--size${suffix}`]: typography?.[device]?.fontSize,
25
+ [`--lh${suffix}`]: typography?.[device]?.lineHeight,
26
+ [`--fs${suffix}`]: typography?.[device]?.fontStyle,
27
+ [`--ff${suffix}`]: fontFamily ? `var(--g-font-${fontFamily}, ${fontFamily})` : undefined,
28
+ [`--weight${suffix}`]: typography?.[device]?.fontWeight,
29
+ [`--ls${suffix}`]: typography?.[device]?.letterSpacing
30
+ };
31
+ }
32
+ const composeTypography = (typography)=>{
33
+ if (!typography) return {};
34
+ return removeNullUndefined({
35
+ ...getCustomCSSByDevice(typography, 'desktop'),
36
+ ...getCustomCSSByDevice(typography, 'tablet'),
37
+ ...getCustomCSSByDevice(typography, 'mobile')
38
+ });
39
+ };
40
+ const composeTypographyV2 = (value, attrs)=>{
41
+ if (!value) return {};
42
+ return removeNullUndefined({
43
+ ...makeStyle({
44
+ fs: !attrs?.italic && value?.fontStyle,
45
+ ff: value?.fontFamily ? `var(--g-font-${value.fontFamily}, ${value.fontFamily})` : undefined,
46
+ weight: !attrs?.bold && value?.fontWeight,
47
+ ls: value?.letterSpacing,
48
+ lh: value?.lineHeight
49
+ }),
50
+ ...makeStyleResponsive('size', value?.fontSize)
51
+ });
52
+ };
53
+ const composeTypographyAttr = (attrs)=>{
54
+ if (!attrs) return {};
55
+ return removeNullUndefined({
56
+ ...makeStyle({
57
+ fs: attrs?.italic && 'italic',
58
+ weight: attrs?.bold && 'bold',
59
+ c: getSingleColorVariable(attrs?.color),
60
+ tt: attrs?.transform,
61
+ tdl: attrs?.underline ? 'underline' : undefined
62
+ })
63
+ });
64
+ };
65
+ const composeTypographyClassName = (typo, typography)=>{
66
+ return typo ? typo?.type && !typo.custom ? genTypoClass(typo.type) : '' : typography?.type && genTypoClass(typography?.type);
67
+ };
68
+ const composeTypographyStyle = (typo, typography, disableAttr)=>{
69
+ if (typo) {
70
+ return {
71
+ ...composeTypographyV2(typo.custom),
72
+ ...!disableAttr && composeTypographyAttr(typo.attrs)
73
+ };
74
+ }
75
+ return {
76
+ ...!typography?.type ? composeTypography(typography?.custom) : {}
77
+ };
78
+ };
16
79
 
17
- export { composeTypographyCss, genTypoClass };
80
+ export { composeTypography, composeTypographyAttr, composeTypographyClassName, composeTypographyCss, composeTypographyStyle, composeTypographyV2, genTypoClass };
package/dist/esm/index.js CHANGED
@@ -39,7 +39,7 @@ export { genVariable } from './helpers/css-variable.js';
39
39
  export { composeGridLayout, convertOldLayout, gridToArrayRegex, optionLayoutStyle } from './helpers/layout.js';
40
40
  export { isDefined } from './helpers/is-defined.js';
41
41
  export { composeTextColorCss, getGlobalColorCSSProp, getGlobalColorClass, getGlobalColorResponsiveClass, getGlobalColorResponsiveStyle, getGlobalColorStateClass, getGlobalColorStateClassDynamicBtn, getGlobalColorStateResponsiveClass, getGlobalColorStateResponsiveClassDynamicBtn, getGlobalColorStateResponsiveStyle, getGlobalColorStateStyle, getGlobalColorStyle, getSingleColorVariable, isColor } from './helpers/colors.js';
42
- export { composeTypographyCss, genTypoClass } from './helpers/typography.js';
42
+ export { composeTypography, composeTypographyAttr, composeTypographyClassName, composeTypographyCss, composeTypographyStyle, composeTypographyV2, genTypoClass } from './helpers/typography.js';
43
43
  export { composeCornerCss, composeRadius, getCornerCSSFromGlobal, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState } from './helpers/radius.js';
44
44
  export { getSelectedVariant, parseSelectedOption } from './helpers/product.js';
45
45
  import * as fpixel from './helpers/tracking/fpixel.js';
@@ -48,7 +48,7 @@ import * as gtag from './helpers/tracking/gtag.js';
48
48
  export { gtag };
49
49
  import * as tiktokpixel from './helpers/tracking/tiktokpixel.js';
50
50
  export { tiktokpixel };
51
- export { RenderIf, dataStringify, props, styles, template } from './helpers/render.js';
51
+ export { RenderIf, composeMemo, dataStringify, props, styles, template } from './helpers/render.js';
52
52
  export { baseAssetURL, isLocalEnv } from './helpers/convert.js';
53
53
  export { composeSize, composeSizeCss, genSizeClass } from './helpers/size.js';
54
54
  export { composeShadowCss, getStyleShadow, getStyleShadowState, parseValueWithUnit } from './helpers/shadow.js';