@gem-sdk/pages 1.35.0 → 1.36.0

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.
@@ -2,20 +2,6 @@
2
2
 
3
3
  var genFonts = require('./helpers/gen-fonts.js');
4
4
 
5
- const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
6
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
7
- async function getFontForUA(url, UA) {
8
- return fetch(url, {
9
- headers: {
10
- 'User-Agent': UA
11
- }
12
- }).then((res)=>{
13
- if (res.status === 200) {
14
- return res.text();
15
- }
16
- return '';
17
- });
18
- }
19
5
  const composeFonts = (fonts)=>{
20
6
  const uniqFonts = fonts.filter((font, index, arr)=>{
21
7
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -56,31 +42,19 @@ const createFontUrl = (fonts, option)=>{
56
42
  }
57
43
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
58
44
  };
59
- async function getFonts(fonts, option, maxSize) {
45
+ async function getFonts(fonts, option) {
60
46
  /**
61
47
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
62
48
  * CSS cascading 🤷‍♂️.
63
49
  */ const url = createFontUrl(fonts, option);
64
50
  if (!url) return '';
65
51
  try {
66
- const [ie, chrome] = await Promise.all([
67
- getFontForUA(url, IE_UA),
68
- getFontForUA(url, CHROME_UA)
69
- ]);
70
- const value = ie + chrome;
71
- if (maxSize) {
72
- const textEncoder = new TextEncoder();
73
- const size = value ? textEncoder.encode(value).length : 0;
74
- if (Math.ceil(size / 1024) >= maxSize) {
75
- return `@import url('${url}');`;
76
- }
77
- }
78
- return value;
52
+ return `@import url('${url}');`;
79
53
  } catch (e) {
80
54
  return '';
81
55
  }
82
56
  }
83
- const getFontFromGlobalStyle = (data, maxSize)=>{
57
+ const getFontFromGlobalStyle = (data)=>{
84
58
  if (!data) return '';
85
59
  try {
86
60
  const globalStyle = JSON.parse(data);
@@ -88,7 +62,7 @@ const getFontFromGlobalStyle = (data, maxSize)=>{
88
62
  const fonts = Object.entries(fontData).map(([, value])=>{
89
63
  return value;
90
64
  });
91
- return getFonts(fonts, undefined, maxSize);
65
+ return getFonts(fonts);
92
66
  } catch {
93
67
  return '';
94
68
  }
@@ -1,19 +1,5 @@
1
1
  import { getFontsFromDataBuilder } from './helpers/gen-fonts.js';
2
2
 
3
- const CHROME_UA = 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/83.0.4103.61 Safari/537.36';
4
- const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
5
- async function getFontForUA(url, UA) {
6
- return fetch(url, {
7
- headers: {
8
- 'User-Agent': UA
9
- }
10
- }).then((res)=>{
11
- if (res.status === 200) {
12
- return res.text();
13
- }
14
- return '';
15
- });
16
- }
17
3
  const composeFonts = (fonts)=>{
18
4
  const uniqFonts = fonts.filter((font, index, arr)=>{
19
5
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -54,31 +40,19 @@ const createFontUrl = (fonts, option)=>{
54
40
  }
55
41
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
56
42
  };
57
- async function getFonts(fonts, option, maxSize) {
43
+ async function getFonts(fonts, option) {
58
44
  /**
59
45
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
60
46
  * CSS cascading 🤷‍♂️.
61
47
  */ const url = createFontUrl(fonts, option);
62
48
  if (!url) return '';
63
49
  try {
64
- const [ie, chrome] = await Promise.all([
65
- getFontForUA(url, IE_UA),
66
- getFontForUA(url, CHROME_UA)
67
- ]);
68
- const value = ie + chrome;
69
- if (maxSize) {
70
- const textEncoder = new TextEncoder();
71
- const size = value ? textEncoder.encode(value).length : 0;
72
- if (Math.ceil(size / 1024) >= maxSize) {
73
- return `@import url('${url}');`;
74
- }
75
- }
76
- return value;
50
+ return `@import url('${url}');`;
77
51
  } catch (e) {
78
52
  return '';
79
53
  }
80
54
  }
81
- const getFontFromGlobalStyle = (data, maxSize)=>{
55
+ const getFontFromGlobalStyle = (data)=>{
82
56
  if (!data) return '';
83
57
  try {
84
58
  const globalStyle = JSON.parse(data);
@@ -86,7 +60,7 @@ const getFontFromGlobalStyle = (data, maxSize)=>{
86
60
  const fonts = Object.entries(fontData).map(([, value])=>{
87
61
  return value;
88
62
  });
89
- return getFonts(fonts, undefined, maxSize);
63
+ return getFonts(fonts);
90
64
  } catch {
91
65
  return '';
92
66
  }
@@ -167,8 +167,8 @@ type FontOption = {
167
167
  subset?: string;
168
168
  effect?: string;
169
169
  };
170
- declare function getFonts(fonts: FontItem[], option?: FontOption, maxSize?: number): Promise<string>;
171
- declare const getFontFromGlobalStyle: (data?: string, maxSize?: number) => Promise<string> | "";
170
+ declare function getFonts(fonts: FontItem[], option?: FontOption): Promise<string>;
171
+ declare const getFontFromGlobalStyle: (data?: string) => Promise<string> | "";
172
172
 
173
173
  declare const getFontsFromDataBuilder: (dataBuilder: Record<string, any>) => FontItem[];
174
174
  declare const getFontFromGroupSetting: (fonts: FontItem[], groupSetting: Record<string, any>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.35.0",
3
+ "version": "1.36.0",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -25,7 +25,7 @@
25
25
  "next-seo": "^6.0.0"
26
26
  },
27
27
  "devDependencies": {
28
- "@gem-sdk/core": "1.35.0",
28
+ "@gem-sdk/core": "1.36.0",
29
29
  "@gem-sdk/plugin-cookie-bar": "1.35.0",
30
30
  "@gem-sdk/plugin-quick-view": "1.35.0",
31
31
  "@gem-sdk/plugin-sticky-add-to-cart": "1.35.0"