@gem-sdk/pages 1.10.18 → 1.10.37

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.
@@ -29,7 +29,7 @@ const createFontUrl = (fonts, option)=>{
29
29
  }
30
30
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
31
31
  };
32
- async function getFonts(fonts, option) {
32
+ async function getFonts(fonts, option, maxSize) {
33
33
  /**
34
34
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
35
35
  * CSS cascading 🤷‍♂️.
@@ -40,12 +40,20 @@ async function getFonts(fonts, option) {
40
40
  getFontForUA(url, IE_UA),
41
41
  getFontForUA(url, CHROME_UA)
42
42
  ]);
43
- return ie + chrome;
43
+ const value = ie + chrome;
44
+ if (maxSize) {
45
+ const textEncoder = new TextEncoder();
46
+ const size = value ? textEncoder.encode(value).length : 0;
47
+ if (Math.ceil(size / 1024) >= maxSize) {
48
+ return `@import url('${url}');`;
49
+ }
50
+ }
51
+ return value;
44
52
  } catch (e) {
45
53
  return '';
46
54
  }
47
55
  }
48
- const getFontFromGlobalStyle = (data)=>{
56
+ const getFontFromGlobalStyle = (data, maxSize)=>{
49
57
  if (!data) return '';
50
58
  try {
51
59
  const globalStyle = JSON.parse(data);
@@ -53,7 +61,7 @@ const getFontFromGlobalStyle = (data)=>{
53
61
  const fonts = Object.entries(fontData).map(([, value])=>{
54
62
  return value;
55
63
  });
56
- return getFonts(fonts);
64
+ return getFonts(fonts, undefined, maxSize);
57
65
  } catch {
58
66
  return '';
59
67
  }
@@ -27,7 +27,7 @@ const createFontUrl = (fonts, option)=>{
27
27
  }
28
28
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
29
29
  };
30
- async function getFonts(fonts, option) {
30
+ async function getFonts(fonts, option, maxSize) {
31
31
  /**
32
32
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
33
33
  * CSS cascading 🤷‍♂️.
@@ -38,12 +38,20 @@ async function getFonts(fonts, option) {
38
38
  getFontForUA(url, IE_UA),
39
39
  getFontForUA(url, CHROME_UA)
40
40
  ]);
41
- return ie + chrome;
41
+ const value = ie + chrome;
42
+ if (maxSize) {
43
+ const textEncoder = new TextEncoder();
44
+ const size = value ? textEncoder.encode(value).length : 0;
45
+ if (Math.ceil(size / 1024) >= maxSize) {
46
+ return `@import url('${url}');`;
47
+ }
48
+ }
49
+ return value;
42
50
  } catch (e) {
43
51
  return '';
44
52
  }
45
53
  }
46
- const getFontFromGlobalStyle = (data)=>{
54
+ const getFontFromGlobalStyle = (data, maxSize)=>{
47
55
  if (!data) return '';
48
56
  try {
49
57
  const globalStyle = JSON.parse(data);
@@ -51,7 +59,7 @@ const getFontFromGlobalStyle = (data)=>{
51
59
  const fonts = Object.entries(fontData).map(([, value])=>{
52
60
  return value;
53
61
  });
54
- return getFonts(fonts);
62
+ return getFonts(fonts, undefined, maxSize);
55
63
  } catch {
56
64
  return '';
57
65
  }
@@ -155,8 +155,8 @@ type FontOption = {
155
155
  subset?: string;
156
156
  effect?: string;
157
157
  };
158
- declare function getFonts(fonts: FontItem[], option?: FontOption): Promise<string>;
159
- declare const getFontFromGlobalStyle: (data?: string) => Promise<string> | "";
158
+ declare function getFonts(fonts: FontItem[], option?: FontOption, maxSize?: number): Promise<string>;
159
+ declare const getFontFromGlobalStyle: (data?: string, maxSize?: number) => Promise<string> | "";
160
160
 
161
161
  declare const getStorefrontApi: (handle: string, provider?: 'BIGCOMMERCE' | 'SHOPIFY') => string;
162
162
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.10.18",
3
+ "version": "1.10.37",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",