@gem-sdk/pages 2.0.0-dev.549 → 2.0.0-dev.570

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.
@@ -8,11 +8,12 @@ var core = require('@gem-sdk/core');
8
8
  var react = require('react');
9
9
  var getStorefrontApi = require('../../libs/get-storefront-api.js');
10
10
  var googleFonts = require('../../libs/google-fonts.js');
11
+ var checkOptionFont = require('../../libs/helpers/check-option-font.js');
11
12
  var genCss = require('../../libs/helpers/gen-css.js');
12
13
  var genFonts = require('../../libs/helpers/gen-fonts.js');
13
14
  var shopifyCdnWithGoogleFonts = require('../../libs/shopify-cdn-with-google-fonts.js');
14
15
  var libsStore = require('../../store/libs-store.js');
15
- var checkOptionFont = require('../../libs/helpers/check-option-font.js');
16
+ var getListFontWeightTypos = require('../composable/getListFontWeightTypos.js');
16
17
 
17
18
  const globalStyleId = 'global-style';
18
19
  const Toolbox = ()=>{
@@ -137,9 +138,11 @@ const Toolbox = ()=>{
137
138
  try {
138
139
  if (detail.data) {
139
140
  const themeStyle = genCss.genCSS(detail.data, detail.mobileOnly);
140
- const font = Object.entries(detail.data?.font).map(([, value])=>{
141
- return value;
142
- }).map((item)=>{
141
+ const fontWeights = getListFontWeightTypos.getListFontWeightTypos(detail.data?.typography);
142
+ const font = Object.entries(detail.data?.font).map(([, value])=>({
143
+ ...value,
144
+ variants: value.variants.filter((variant)=>fontWeights.includes(variant) || variant === 'regular' && fontWeights.includes('400')).map((variant)=>variant === 'regular' ? '400' : variant)
145
+ })).map((item)=>{
143
146
  if (item.type == 'custom') {
144
147
  const isGoogleFont = shopifyCdnWithGoogleFonts.shopifyCdnWithGoogleFonts.find((ggFont)=>ggFont.family == item.family);
145
148
  if (isGoogleFont) {
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ const getListFontWeightTypos = (font)=>{
4
+ const fontWeights = new Set();
5
+ Object.values(font).forEach((fontStyle)=>{
6
+ // Check desktop fontWeight
7
+ if (fontStyle.desktop?.fontWeight) {
8
+ fontWeights.add(fontStyle.desktop.fontWeight);
9
+ }
10
+ });
11
+ return Array.from(fontWeights);
12
+ };
13
+
14
+ exports.getListFontWeightTypos = getListFontWeightTypos;
@@ -36,7 +36,27 @@ const composeFonts = (fonts)=>{
36
36
  };
37
37
  });
38
38
  };
39
- const createFontUrl = (fonts, option, fontType)=>{
39
+ const handleGenerateFontParams = (variants, fontType = 'google')=>{
40
+ const regularWeights = [];
41
+ if (!variants.length) {
42
+ return fontType === 'bunny' ? '400' : 'wght@400';
43
+ }
44
+ // Get regular weights and remove italic variants
45
+ variants.forEach((variant)=>{
46
+ if (variant.includes('italic')) {
47
+ return;
48
+ }
49
+ const weight = variant === 'regular' ? '400' : variant;
50
+ regularWeights.push(weight);
51
+ });
52
+ // Sort weights numerically (ex: [900, 700, 400] -> [400, 700, 900])
53
+ const sortedRegularWeights = regularWeights.sort((a, b)=>Number(a) - Number(b));
54
+ // Build the variant string with only regular weights
55
+ const axisPrefix = 'wght@';
56
+ const listVariantsGoogleFonts = sortedRegularWeights.map((weight)=>weight);
57
+ return fontType === 'google' ? `${axisPrefix}${listVariantsGoogleFonts.join(';')}` : sortedRegularWeights.join(',');
58
+ };
59
+ const createFontUrl = (fonts, option, fontType = 'google')=>{
40
60
  const mainFonts = fonts.filter((font)=>{
41
61
  return !([
42
62
  'bunny',
@@ -50,8 +70,8 @@ const createFontUrl = (fonts, option, fontType)=>{
50
70
  return index === arr.findIndex((t)=>t.family === font.family);
51
71
  });
52
72
  const family = composeFonts(uniqFonts).map((font)=>{
53
- return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
54
- }).join('|');
73
+ return `${font.family.replace(/ /g, '+')}:${handleGenerateFontParams(font.variants, fontType)}`;
74
+ }).join(fontType === 'google' ? '&family=' : '|');
55
75
  params.append('family', family);
56
76
  params.append('display', display);
57
77
  if (option?.subset) {
@@ -61,7 +81,7 @@ const createFontUrl = (fonts, option, fontType)=>{
61
81
  params.append('effect', option.effect);
62
82
  }
63
83
  const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
64
- const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
84
+ const googleFontUrl = `https://fonts.googleapis.com/css2?${decodeURIComponent(params.toString())}`;
65
85
  return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
66
86
  };
67
87
  // eslint-disable-next-line max-params
@@ -4,11 +4,12 @@ import { useMatchMutate, useShopStore, usePageStore, useBuilderPreviewStore, use
4
4
  import { memo, useMemo, useCallback, useEffect } from 'react';
5
5
  import { getStorefrontApi } from '../../libs/get-storefront-api.js';
6
6
  import { createFontUrl } from '../../libs/google-fonts.js';
7
+ import { checkNotInOptionFont } from '../../libs/helpers/check-option-font.js';
7
8
  import { genCSS } from '../../libs/helpers/gen-css.js';
8
9
  import { getFontsFromDataBuilder } from '../../libs/helpers/gen-fonts.js';
9
10
  import { shopifyCdnWithGoogleFonts } from '../../libs/shopify-cdn-with-google-fonts.js';
10
11
  import { libsStore } from '../../store/libs-store.js';
11
- import { checkNotInOptionFont } from '../../libs/helpers/check-option-font.js';
12
+ import { getListFontWeightTypos } from '../composable/getListFontWeightTypos.js';
12
13
 
13
14
  const globalStyleId = 'global-style';
14
15
  const Toolbox = ()=>{
@@ -133,9 +134,11 @@ const Toolbox = ()=>{
133
134
  try {
134
135
  if (detail.data) {
135
136
  const themeStyle = genCSS(detail.data, detail.mobileOnly);
136
- const font = Object.entries(detail.data?.font).map(([, value])=>{
137
- return value;
138
- }).map((item)=>{
137
+ const fontWeights = getListFontWeightTypos(detail.data?.typography);
138
+ const font = Object.entries(detail.data?.font).map(([, value])=>({
139
+ ...value,
140
+ variants: value.variants.filter((variant)=>fontWeights.includes(variant) || variant === 'regular' && fontWeights.includes('400')).map((variant)=>variant === 'regular' ? '400' : variant)
141
+ })).map((item)=>{
139
142
  if (item.type == 'custom') {
140
143
  const isGoogleFont = shopifyCdnWithGoogleFonts.find((ggFont)=>ggFont.family == item.family);
141
144
  if (isGoogleFont) {
@@ -0,0 +1,12 @@
1
+ const getListFontWeightTypos = (font)=>{
2
+ const fontWeights = new Set();
3
+ Object.values(font).forEach((fontStyle)=>{
4
+ // Check desktop fontWeight
5
+ if (fontStyle.desktop?.fontWeight) {
6
+ fontWeights.add(fontStyle.desktop.fontWeight);
7
+ }
8
+ });
9
+ return Array.from(fontWeights);
10
+ };
11
+
12
+ export { getListFontWeightTypos };
@@ -34,7 +34,27 @@ const composeFonts = (fonts)=>{
34
34
  };
35
35
  });
36
36
  };
37
- const createFontUrl = (fonts, option, fontType)=>{
37
+ const handleGenerateFontParams = (variants, fontType = 'google')=>{
38
+ const regularWeights = [];
39
+ if (!variants.length) {
40
+ return fontType === 'bunny' ? '400' : 'wght@400';
41
+ }
42
+ // Get regular weights and remove italic variants
43
+ variants.forEach((variant)=>{
44
+ if (variant.includes('italic')) {
45
+ return;
46
+ }
47
+ const weight = variant === 'regular' ? '400' : variant;
48
+ regularWeights.push(weight);
49
+ });
50
+ // Sort weights numerically (ex: [900, 700, 400] -> [400, 700, 900])
51
+ const sortedRegularWeights = regularWeights.sort((a, b)=>Number(a) - Number(b));
52
+ // Build the variant string with only regular weights
53
+ const axisPrefix = 'wght@';
54
+ const listVariantsGoogleFonts = sortedRegularWeights.map((weight)=>weight);
55
+ return fontType === 'google' ? `${axisPrefix}${listVariantsGoogleFonts.join(';')}` : sortedRegularWeights.join(',');
56
+ };
57
+ const createFontUrl = (fonts, option, fontType = 'google')=>{
38
58
  const mainFonts = fonts.filter((font)=>{
39
59
  return !([
40
60
  'bunny',
@@ -48,8 +68,8 @@ const createFontUrl = (fonts, option, fontType)=>{
48
68
  return index === arr.findIndex((t)=>t.family === font.family);
49
69
  });
50
70
  const family = composeFonts(uniqFonts).map((font)=>{
51
- return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
52
- }).join('|');
71
+ return `${font.family.replace(/ /g, '+')}:${handleGenerateFontParams(font.variants, fontType)}`;
72
+ }).join(fontType === 'google' ? '&family=' : '|');
53
73
  params.append('family', family);
54
74
  params.append('display', display);
55
75
  if (option?.subset) {
@@ -59,7 +79,7 @@ const createFontUrl = (fonts, option, fontType)=>{
59
79
  params.append('effect', option.effect);
60
80
  }
61
81
  const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
62
- const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
82
+ const googleFontUrl = `https://fonts.googleapis.com/css2?${decodeURIComponent(params.toString())}`;
63
83
  return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
64
84
  };
65
85
  // eslint-disable-next-line max-params
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "2.0.0-dev.549",
3
+ "version": "2.0.0-dev.570",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -26,7 +26,7 @@
26
26
  "next": "14.2.20"
27
27
  },
28
28
  "devDependencies": {
29
- "@gem-sdk/core": "2.0.0-dev.540",
29
+ "@gem-sdk/core": "2.0.0-dev.569",
30
30
  "@gem-sdk/plugin-cookie-bar": "2.0.0-dev.348",
31
31
  "@gem-sdk/plugin-quick-view": "2.0.0-dev.348",
32
32
  "@gem-sdk/plugin-sticky-add-to-cart": "2.0.0-dev.348"