@gem-sdk/pages 1.40.0 → 1.40.2-staging.5

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,6 +2,20 @@
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
+ }
5
19
  const composeFonts = (fonts)=>{
6
20
  const uniqFonts = fonts.filter((font, index, arr)=>{
7
21
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -42,14 +56,19 @@ const createFontUrl = (fonts, option)=>{
42
56
  }
43
57
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
44
58
  };
45
- async function getFonts(fonts, option) {
59
+ async function getFonts(fonts, option, isImportFontByUrl = true) {
46
60
  /**
47
61
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
48
62
  * CSS cascading 🤷‍♂️.
49
63
  */ const url = createFontUrl(fonts, option);
50
64
  if (!url) return '';
51
65
  try {
52
- return `@import url('${url}');`;
66
+ if (isImportFontByUrl) return `@import url('${url}');`;
67
+ const [ie, chrome] = await Promise.all([
68
+ getFontForUA(url, IE_UA),
69
+ getFontForUA(url, CHROME_UA)
70
+ ]);
71
+ return ie + chrome;
53
72
  } catch (e) {
54
73
  return '';
55
74
  }
@@ -1,5 +1,19 @@
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
+ }
3
17
  const composeFonts = (fonts)=>{
4
18
  const uniqFonts = fonts.filter((font, index, arr)=>{
5
19
  return index === arr.findIndex((t)=>t.family === font.family);
@@ -40,14 +54,19 @@ const createFontUrl = (fonts, option)=>{
40
54
  }
41
55
  return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
42
56
  };
43
- async function getFonts(fonts, option) {
57
+ async function getFonts(fonts, option, isImportFontByUrl = true) {
44
58
  /**
45
59
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
46
60
  * CSS cascading 🤷‍♂️.
47
61
  */ const url = createFontUrl(fonts, option);
48
62
  if (!url) return '';
49
63
  try {
50
- return `@import url('${url}');`;
64
+ if (isImportFontByUrl) return `@import url('${url}');`;
65
+ const [ie, chrome] = await Promise.all([
66
+ getFontForUA(url, IE_UA),
67
+ getFontForUA(url, CHROME_UA)
68
+ ]);
69
+ return ie + chrome;
51
70
  } catch (e) {
52
71
  return '';
53
72
  }
@@ -192,7 +192,7 @@ type FontOption = {
192
192
  subset?: string;
193
193
  effect?: string;
194
194
  };
195
- declare function getFonts(fonts: FontItem[], option?: FontOption): Promise<string>;
195
+ declare function getFonts(fonts: FontItem[], option?: FontOption, isImportFontByUrl?: boolean): Promise<string>;
196
196
  declare const getFontFromGlobalStyle: (data?: string) => Promise<string> | "";
197
197
 
198
198
  declare const getFontsFromDataBuilder: (dataBuilder: Record<string, any>) => FontItem[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gem-sdk/pages",
3
- "version": "1.40.0",
3
+ "version": "1.40.2-staging.5",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",
@@ -26,10 +26,10 @@
26
26
  "next": "latest"
27
27
  },
28
28
  "devDependencies": {
29
- "@gem-sdk/core": "1.40.0",
30
- "@gem-sdk/plugin-cookie-bar": "1.40.0",
31
- "@gem-sdk/plugin-quick-view": "1.40.0",
32
- "@gem-sdk/plugin-sticky-add-to-cart": "1.40.0"
29
+ "@gem-sdk/core": "1.40.2-staging.5",
30
+ "@gem-sdk/plugin-cookie-bar": "1.40.2-staging.4",
31
+ "@gem-sdk/plugin-quick-view": "1.40.2-staging.4",
32
+ "@gem-sdk/plugin-sticky-add-to-cart": "1.40.2-staging.4"
33
33
  },
34
34
  "peerDependencies": {
35
35
  "next": ">=13"