@gem-sdk/core 1.12.0-next.4 → 1.12.0-next.41

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.
@@ -5,182 +5,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var react = require('react');
6
6
  var shop = require('./shop.js');
7
7
 
8
- const NARROW_SYMBOL_MAP = {
9
- AED: 'د.إ',
10
- AFN: '؋',
11
- ALL: 'L',
12
- AMD: 'դր.',
13
- ANG: 'ƒ',
14
- AOA: 'Kz',
15
- ARS: '$',
16
- AUD: '$',
17
- AWG: 'ƒ',
18
- AZN: '₼',
19
- BAM: 'КМ',
20
- BBD: '$',
21
- BDT: '৳',
22
- BGN: 'лв.',
23
- BHD: 'ب.د',
24
- BIF: 'Fr',
25
- BMD: '$',
26
- BND: '$',
27
- BOB: 'Bs.',
28
- BRL: 'R$',
29
- BSD: '$',
30
- BTN: 'Nu.',
31
- BWP: 'P',
32
- BYN: 'Br',
33
- BYR: 'Br',
34
- BZD: '$',
35
- CAD: '$',
36
- CDF: 'Fr',
37
- CHF: 'CHF',
38
- CLF: 'UF',
39
- CLP: '$',
40
- CNY: '¥',
41
- COP: '$',
42
- CRC: '₡',
43
- CUC: '$',
44
- CUP: '$',
45
- CVE: '$',
46
- CZK: 'Kč',
47
- DJF: 'Fdj',
48
- DKK: 'kr.',
49
- DOP: '$',
50
- DZD: 'د.ج',
51
- EGP: 'ج.م',
52
- ERN: 'Nfk',
53
- ETB: 'Br',
54
- EUR: '€',
55
- FJD: '$',
56
- FKP: '£',
57
- GBP: '£',
58
- GEL: 'ლ',
59
- GHS: '₵',
60
- GIP: '£',
61
- GMD: 'D',
62
- GNF: 'Fr',
63
- GTQ: 'Q',
64
- GYD: '$',
65
- HKD: '$',
66
- HNL: 'L',
67
- HRK: 'kn',
68
- HTG: 'G',
69
- HUF: 'Ft',
70
- IDR: 'Rp',
71
- ILS: '₪',
72
- INR: '₹',
73
- IQD: 'ع.د',
74
- IRR: '﷼',
75
- ISK: 'kr',
76
- JMD: '$',
77
- JOD: 'د.ا',
78
- JPY: '¥',
79
- KES: 'KSh',
80
- KGS: 'som',
81
- KHR: '៛',
82
- KMF: 'Fr',
83
- KPW: '₩',
84
- KRW: '₩',
85
- KWD: 'د.ك',
86
- KYD: '$',
87
- KZT: '〒',
88
- LAK: '₭',
89
- LBP: 'ل.ل',
90
- LKR: '₨',
91
- LRD: '$',
92
- LSL: 'L',
93
- LTL: 'Lt',
94
- LVL: 'Ls',
95
- LYD: 'ل.د',
96
- MAD: 'د.م.',
97
- MDL: 'L',
98
- MGA: 'Ar',
99
- MKD: 'ден',
100
- MMK: 'K',
101
- MNT: '₮',
102
- MOP: 'P',
103
- MRU: 'UM',
104
- MUR: '₨',
105
- MVR: 'MVR',
106
- MWK: 'MK',
107
- MXN: '$',
108
- MYR: 'RM',
109
- MZN: 'MTn',
110
- NAD: '$',
111
- NGN: '₦',
112
- NIO: 'C$',
113
- NOK: 'kr',
114
- NPR: '₨',
115
- NZD: '$',
116
- OMR: 'ر.ع.',
117
- PAB: 'B/.',
118
- PEN: 'S/.',
119
- PGK: 'K',
120
- PHP: '₱',
121
- PKR: '₨',
122
- PLN: 'zł',
123
- PYG: '₲',
124
- QAR: 'ر.ق',
125
- RON: 'Lei',
126
- RSD: 'РСД',
127
- RUB: '₽',
128
- RWF: 'FRw',
129
- SAR: 'ر.س',
130
- SBD: '$',
131
- SCR: '₨',
132
- SDG: '£',
133
- SEK: 'kr',
134
- SGD: '$',
135
- SHP: '£',
136
- SKK: 'Sk',
137
- SLL: 'Le',
138
- SOS: 'Sh',
139
- SRD: '$',
140
- SSP: '£',
141
- STN: 'Db',
142
- SVC: '₡',
143
- SYP: '£S',
144
- SZL: 'E',
145
- THB: '฿',
146
- TJS: 'ЅМ',
147
- TMT: 'T',
148
- TND: 'د.ت',
149
- TOP: 'T$',
150
- TRY: '₺',
151
- TTD: '$',
152
- TWD: '$',
153
- TZS: 'Sh',
154
- UAH: '₴',
155
- UGX: 'USh',
156
- USD: '$',
157
- UYU: '$',
158
- UZS: '',
159
- VED: 'Bs.D.',
160
- VES: 'Bs.S.',
161
- VND: '₫',
162
- VUV: 'Vt',
163
- WST: 'T',
164
- XAF: 'Fr',
165
- XAG: 'oz t',
166
- XAU: 'oz t',
167
- XBA: '',
168
- XBB: '',
169
- XBC: '',
170
- XBD: '',
171
- XCD: '$',
172
- XDR: 'SDR',
173
- XOF: 'Fr',
174
- XPD: 'oz t',
175
- XPF: 'Fr',
176
- XPT: 'oz t',
177
- xts: '',
178
- YER: '﷼',
179
- ZAR: 'R',
180
- ZMK: 'ZK',
181
- ZMW: 'ZK'
182
- };
183
- const useMoney = (money)=>{
8
+ const useMoney = (amount)=>{
184
9
  const { locale } = shop.useLocale();
185
10
  const { currency } = shop.useCurrency();
186
11
  const options = react.useMemo(()=>({
@@ -189,43 +14,71 @@ const useMoney = (money)=>{
189
14
  }), [
190
15
  currency
191
16
  ]);
192
- const value = react.useMemo(()=>new Intl.NumberFormat(locale, options).format(money), [
193
- locale,
194
- options,
195
- money
196
- ]);
197
- const baseParts = new Intl.NumberFormat(locale, options).formatToParts(money);
198
- const nameParts = new Intl.NumberFormat(locale, {
17
+ const defaultFormatter = useLazyFormatter(locale, options);
18
+ const nameFormatter = useLazyFormatter(locale, {
199
19
  ...options,
200
20
  currencyDisplay: 'name'
201
- }).formatToParts(money);
202
- const narrowParts = new Intl.NumberFormat(locale, {
21
+ });
22
+ const narrowSymbolFormatter = useLazyFormatter(locale, {
203
23
  ...options,
204
24
  currencyDisplay: 'narrowSymbol'
205
- }).formatToParts(money);
206
- const moneyValue = react.useMemo(()=>({
207
- currencyCode: currency,
208
- currencyName: nameParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "US dollars"
209
- currency,
210
- currencyNarrowSymbol: narrowParts.find((part)=>part.type === 'currency')?.value ?? // e.g. "$"
211
- (currency ? NARROW_SYMBOL_MAP[currency] : '') ?? '',
212
- parts: baseParts,
213
- localizedString: value,
214
- amount: baseParts.filter((part)=>[
215
- 'decimal',
216
- 'fraction',
217
- 'group',
218
- 'integer',
219
- 'literal'
220
- ].includes(part.type)).map((part)=>part.value).join('')
25
+ });
26
+ const withoutTrailingZerosFormatter = useLazyFormatter(locale, {
27
+ ...options,
28
+ minimumFractionDigits: 0,
29
+ maximumFractionDigits: 0
30
+ });
31
+ const withoutCurrencyFormatter = useLazyFormatter(locale);
32
+ const withoutTrailingZerosOrCurrencyFormatter = useLazyFormatter(locale, {
33
+ minimumFractionDigits: 0,
34
+ maximumFractionDigits: 0
35
+ });
36
+ const isPartCurrency = (part)=>part.type === 'currency';
37
+ // By wrapping these properties in functions, we only
38
+ // create formatters if they are going to be used.
39
+ const lazyFormatters = react.useMemo(()=>({
40
+ currencyCode: ()=>currency,
41
+ localizedString: ()=>defaultFormatter().format(amount),
42
+ parts: ()=>defaultFormatter().formatToParts(amount),
43
+ withoutTrailingZeros: ()=>amount % 1 === 0 ? withoutTrailingZerosFormatter().format(amount) : defaultFormatter().format(amount),
44
+ withoutTrailingZerosAndCurrency: ()=>amount % 1 === 0 ? withoutTrailingZerosOrCurrencyFormatter().format(amount) : withoutCurrencyFormatter().format(amount),
45
+ currencyName: ()=>nameFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
46
+ currencySymbol: ()=>defaultFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? currency,
47
+ currencyNarrowSymbol: ()=>narrowSymbolFormatter().formatToParts(amount).find(isPartCurrency)?.value ?? '',
48
+ amount: ()=>defaultFormatter().formatToParts(amount).filter((part)=>[
49
+ 'decimal',
50
+ 'fraction',
51
+ 'group',
52
+ 'integer',
53
+ 'literal'
54
+ ].includes(part.type)).map((part)=>part.value).join('')
221
55
  }), [
222
- baseParts,
223
- nameParts,
224
- narrowParts,
225
- value,
226
- currency
56
+ currency,
57
+ amount,
58
+ nameFormatter,
59
+ defaultFormatter,
60
+ narrowSymbolFormatter,
61
+ withoutCurrencyFormatter,
62
+ withoutTrailingZerosFormatter,
63
+ withoutTrailingZerosOrCurrencyFormatter
64
+ ]);
65
+ // Call functions automatically when the properties are accessed
66
+ // to keep these functions as an implementation detail.
67
+ return react.useMemo(()=>new Proxy(lazyFormatters, {
68
+ // eslint-disable-next-line @typescript-eslint/no-unsafe-return, @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-call
69
+ get: (target, key)=>Reflect.get(target, key)?.call(null)
70
+ }), [
71
+ lazyFormatters
227
72
  ]);
228
- return moneyValue;
229
73
  };
74
+ function useLazyFormatter(locale, options) {
75
+ return react.useMemo(()=>{
76
+ let memoized;
77
+ return ()=>memoized ??= new Intl.NumberFormat(locale, options);
78
+ }, [
79
+ locale,
80
+ options
81
+ ]);
82
+ }
230
83
 
231
84
  exports.default = useMoney;
package/dist/cjs/index.js CHANGED
@@ -67,12 +67,12 @@ var useCollectionsQuery = require('./hooks/shop/use-collections-query.js');
67
67
  var useProductQuery = require('./hooks/shop/use-product-query.js');
68
68
  var useProductsQuery = require('./hooks/shop/use-products-query.js');
69
69
  var useCurrentDevice = require('./hooks/use-current-device.js');
70
+ var useFormatMoney = require('./hooks/useFormatMoney.js');
70
71
  var useLazyVideo = require('./hooks/use-lazy-video.js');
71
72
  var useCartId = require('./hooks/useCartId.js');
72
73
  var useCartLine = require('./hooks/useCartLine.js');
73
74
  var useCartUI = require('./hooks/useCartUI.js');
74
75
  var useCollection = require('./hooks/useCollection.js');
75
- var useFormatMoney = require('./hooks/useFormatMoney.js');
76
76
  var react = require('react');
77
77
  var useIsomorphicLayoutEffect = require('./hooks/useIsomorphicLayoutEffect.js');
78
78
  var useLoadScript = require('./hooks/useLoadScript.js');
@@ -93,6 +93,7 @@ var getProductBySlug = require('./helpers/queries/get-product-by-slug.js');
93
93
  exports.AddOn = AddOn.default;
94
94
  exports.Render = Render.default;
95
95
  exports.RenderPreview = RenderPreview.default;
96
+ exports.RenderChildren = Render_liquid.RenderChildren;
96
97
  exports.RenderLiquid = Render_liquid.default;
97
98
  exports.AddonProvider = AddonContext.AddonProvider;
98
99
  exports.useAddon = AddonContext.useAddon;
@@ -150,6 +151,7 @@ exports.makeStyleResponsive = makeStyle.makeStyleResponsive;
150
151
  exports.makeStyleResponsiveState = makeStyle.makeStyleResponsiveState;
151
152
  exports.makeStyleState = makeStyle.makeStyleState;
152
153
  exports.makeWidth = makeStyle.makeWidth;
154
+ exports.removeNullUndefined = makeStyle.removeNullUndefined;
153
155
  exports.normalizeBuilderData = normalizeBuilderData.normalizeBuilderData;
154
156
  exports.prefetchQueries = prefetchQueries.prefetchQueries;
155
157
  exports.composeSpacing = spacing.composeSpacing;
@@ -176,7 +178,12 @@ exports.getGlobalColorStateStyle = colors.getGlobalColorStateStyle;
176
178
  exports.getGlobalColorStyle = colors.getGlobalColorStyle;
177
179
  exports.getSingleColorVariable = colors.getSingleColorVariable;
178
180
  exports.isColor = colors.isColor;
181
+ exports.composeTypography = typography.composeTypography;
182
+ exports.composeTypographyAttr = typography.composeTypographyAttr;
183
+ exports.composeTypographyClassName = typography.composeTypographyClassName;
179
184
  exports.composeTypographyCss = typography.composeTypographyCss;
185
+ exports.composeTypographyStyle = typography.composeTypographyStyle;
186
+ exports.composeTypographyV2 = typography.composeTypographyV2;
180
187
  exports.genTypoClass = typography.genTypoClass;
181
188
  exports.composeCornerCss = radius.composeCornerCss;
182
189
  exports.composeRadius = radius.composeRadius;
@@ -190,6 +197,8 @@ exports.fpixel = fpixel;
190
197
  exports.gtag = gtag;
191
198
  exports.tiktokpixel = tiktokpixel;
192
199
  exports.RenderIf = render.RenderIf;
200
+ exports.composeMemo = render.composeMemo;
201
+ exports.dataStringify = render.dataStringify;
193
202
  exports.props = render.props;
194
203
  exports.styles = render.styles;
195
204
  exports.template = render.template;
@@ -225,6 +234,7 @@ exports.useIsStorefrontProduct = shop.useIsStorefrontProduct;
225
234
  exports.useLocale = shop.useLocale;
226
235
  exports.useMatchMutate = shop.useMatchMutate;
227
236
  exports.useMobileOnly = shop.useMobileOnly;
237
+ exports.useMoneyFormat = shop.useMoneyFormat;
228
238
  exports.usePageType = shop.usePageType;
229
239
  exports.usePluginEnable = shop.usePluginEnable;
230
240
  exports.useStoreFront = shop.useStoreFront;
@@ -234,12 +244,12 @@ exports.useCollectionsQuery = useCollectionsQuery.useCollectionsQuery;
234
244
  exports.useProductQuery = useProductQuery.useProductQuery;
235
245
  exports.useProductsQuery = useProductsQuery.useProductsQuery;
236
246
  exports.useCurrentDevice = useCurrentDevice.useCurrentDevice;
247
+ exports.useFormatMoney = useFormatMoney.useFormatMoney;
237
248
  exports.useLazyVideo = useLazyVideo.useLazyVideo;
238
249
  exports.useCartId = useCartId.default;
239
250
  exports.useCartLine = useCartLine.default;
240
251
  exports.useCartUI = useCartUI.default;
241
252
  exports.useCollection = useCollection.useCollection;
242
- exports.useFormatMoney = useFormatMoney.default;
243
253
  Object.defineProperty(exports, 'useId', {
244
254
  enumerable: true,
245
255
  get: function () { return react.useId; }
@@ -12,20 +12,35 @@ const componentTexts = [
12
12
  'Text',
13
13
  'Heading'
14
14
  ];
15
- const Render = ({ uid , builder , components , parentId , ...passProps })=>{
15
+ const Render = ({ uid , builder , components , parentId , extraFiles ={} , ...passProps })=>{
16
16
  const item = builder[uid];
17
17
  const Component = components[item?.tag];
18
18
  if (!Component) {
19
19
  console.log('Miss component: ', item);
20
- return '';
20
+ return {
21
+ liquid: '',
22
+ extraFiles
23
+ };
24
+ }
25
+ if (!item) {
26
+ return {
27
+ liquid: '',
28
+ extraFiles
29
+ };
21
30
  }
22
- if (!item) return null;
23
31
  if (item?.type === 'section') {
24
- return '';
32
+ return {
33
+ liquid: '',
34
+ extraFiles
35
+ };
25
36
  } else {
37
+ const customProps = {
38
+ extraFiles: {}
39
+ };
26
40
  const style = composeAdvanceStyle(item.advanced, item.tag);
41
+ let liquid = '';
27
42
  if (disableWrap.includes(item.tag)) {
28
- return RenderIf(item?.childrens?.length, ()=>{
43
+ liquid = RenderIf(item?.childrens?.length, ()=>{
29
44
  return Component({
30
45
  builderProps: {
31
46
  uid,
@@ -42,17 +57,19 @@ const Render = ({ uid , builder , components , parentId , ...passProps })=>{
42
57
  ...builder[id],
43
58
  uid: id,
44
59
  builder,
45
- components
60
+ components,
61
+ customProps
46
62
  };
47
63
  }),
48
- children: item.childrens.map((id)=>Render({
64
+ children: item.childrens.map((id)=>RenderChildren({
49
65
  uid: id,
50
66
  builder,
51
67
  components,
52
- parentId: uid
68
+ customProps
53
69
  })).join('')
54
70
  });
55
- }, ()=>Component({
71
+ }, ()=>{
72
+ return Component({
56
73
  builderProps: {
57
74
  uid,
58
75
  builderData: item
@@ -64,42 +81,73 @@ const Render = ({ uid , builder , components , parentId , ...passProps })=>{
64
81
  isText: componentTexts.includes(item.tag) ? true : null,
65
82
  parentId: componentsRenderWithParentId.includes(item.tag) ? parentId : null,
66
83
  ...passProps
67
- }));
84
+ });
85
+ });
86
+ } else {
87
+ liquid = template`<div style="${style}" class="${item.uid}">
88
+ ${RenderIf(item?.childrens?.length, ()=>{
89
+ return Component({
90
+ builderProps: {
91
+ uid,
92
+ builderData: item
93
+ },
94
+ styles: item.styles,
95
+ setting: item.settings,
96
+ ...passProps,
97
+ rawChildren: item.childrens.map((id)=>{
98
+ return {
99
+ ...builder[id],
100
+ uid: id,
101
+ builder,
102
+ components,
103
+ customProps
104
+ };
105
+ }),
106
+ children: item.childrens.map((id)=>RenderChildren({
107
+ uid: id,
108
+ builder,
109
+ components,
110
+ customProps
111
+ })).join('')
112
+ });
113
+ }, ()=>{
114
+ return Component({
115
+ builderProps: {
116
+ uid,
117
+ builderData: item
118
+ },
119
+ styles: item.styles,
120
+ setting: item.settings,
121
+ isText: componentTexts.includes(item.tag) ? true : null,
122
+ ...passProps
123
+ });
124
+ })}
125
+ </div>`;
68
126
  }
69
- return template`<div style="${style}" class="${item.uid}">
70
- ${RenderIf(item?.childrens?.length, ()=>Component({
71
- builderProps: {
72
- uid,
73
- builderData: item
74
- },
75
- styles: item.styles,
76
- setting: item.settings,
77
- ...passProps,
78
- rawChildren: item.childrens.map((id)=>{
79
- return {
80
- ...builder[id],
81
- uid: id,
82
- builder,
83
- components
84
- };
85
- }),
86
- children: item.childrens.map((id)=>Render({
87
- uid: id,
88
- builder,
89
- components
90
- })).join('')
91
- }), ()=>Component({
92
- builderProps: {
93
- uid,
94
- builderData: item
95
- },
96
- styles: item.styles,
97
- setting: item.settings,
98
- isText: componentTexts.includes(item.tag) ? true : null,
99
- ...passProps
100
- }))}
101
- </div>`;
127
+ return {
128
+ liquid,
129
+ extraFiles: customProps.extraFiles
130
+ };
131
+ }
132
+ };
133
+ const RenderChildren = (props)=>{
134
+ const data = Render(props);
135
+ // Append to prop parent
136
+ for(const key in data.extraFiles){
137
+ if (Object.prototype.hasOwnProperty.call(data.extraFiles, key)) {
138
+ const value = data.extraFiles[key];
139
+ props.customProps.extraFiles[key] = value;
140
+ }
141
+ }
142
+ // Fix limit 256kb
143
+ const textEncoder = new TextEncoder();
144
+ const size = data?.liquid ? textEncoder.encode(data.liquid).length : 0;
145
+ if (Math.ceil(size / 1024) >= 180) {
146
+ const fileName = `gp-section-snippet-${props.uid}`;
147
+ props.customProps.extraFiles[fileName] = data.liquid;
148
+ return `{% render '${fileName}', product: product, variant: variant, product_form_id: product_form_id %}`;
102
149
  }
150
+ return data.liquid;
103
151
  };
104
152
 
105
- export { Render as default };
153
+ export { RenderChildren, Render as default };
@@ -115,7 +115,15 @@ function composeAdvanceStyle(data, tag) {
115
115
  }
116
116
  } else {
117
117
  if (attr === 'border') {
118
- Object.assign(styles, getBorderStyle(value));
118
+ const borderStyle = value;
119
+ if (borderStyle.border === 'none') {
120
+ borderStyle.border = 'solid';
121
+ borderStyle.color = '#121212';
122
+ borderStyle.isCustom = true;
123
+ borderStyle.width = '0px';
124
+ borderStyle.position = 'all';
125
+ }
126
+ Object.assign(styles, getBorderStyle(borderStyle));
119
127
  }
120
128
  if (attr === 'rounded') {
121
129
  Object.assign(styles, getCornerCSSFromGlobal(value));
@@ -1,5 +1,12 @@
1
1
  import { getResponsiveValueByScreen } from './get-resonsive-value.js';
2
2
 
3
+ const removeNullUndefined = (obj)=>Object.entries(obj).reduce((a, [k, v])=>{
4
+ if (v === null || v === undefined) return a;
5
+ return {
6
+ ...a,
7
+ [k]: v
8
+ };
9
+ }, {});
3
10
  const makeStyleKey = (name)=>{
4
11
  return [
5
12
  name,
@@ -14,10 +21,10 @@ const makeStyleKey = (name)=>{
14
21
  ].map((key)=>`--${key}`);
15
22
  };
16
23
  const makeStyle = (style)=>{
17
- return Object.fromEntries(Object.entries(style).map(([key, value])=>[
24
+ return removeNullUndefined(Object.fromEntries(Object.entries(style).map(([key, value])=>[
18
25
  `--${key}`,
19
26
  value
20
- ]));
27
+ ])));
21
28
  };
22
29
  const makeStyleState = (name, value)=>{
23
30
  if (!value) return {};
@@ -107,4 +114,4 @@ const makeLineClamp = (lineClampValue, hasLineClampValue)=>{
107
114
  };
108
115
  };
109
116
 
110
- export { makeAspectRatio, makeHeight, makeLineClamp, makeStyle, makeStyleKey, makeStyleResponsive, makeStyleResponsiveState, makeStyleState, makeWidth };
117
+ export { makeAspectRatio, makeHeight, makeLineClamp, makeStyle, makeStyleKey, makeStyleResponsive, makeStyleResponsiveState, makeStyleState, makeWidth, removeNullUndefined };
@@ -37,6 +37,9 @@ const styles = (strings, ...keys)=>{
37
37
  }
38
38
  return styleArr.join(';');
39
39
  };
40
+ const dataStringify = (obj)=>{
41
+ return JSON.stringify(obj).replace(/\\"/g, '"');
42
+ };
40
43
  const template = (strings, ...keys)=>{
41
44
  let str = '';
42
45
  strings.forEach((item, index)=>{
@@ -55,5 +58,7 @@ const template = (strings, ...keys)=>{
55
58
  });
56
59
  return str;
57
60
  };
61
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
62
+ const composeMemo = (fn, _)=>fn();
58
63
 
59
- export { RenderIf, 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 };