@gem-sdk/pages 1.53.0-dev.82 → 1.53.0-dev.89

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.
@@ -10,6 +10,7 @@ var googleFonts = require('../../libs/google-fonts.js');
10
10
  var genCss = require('../../libs/helpers/gen-css.js');
11
11
  var genFonts = require('../../libs/helpers/gen-fonts.js');
12
12
  var shopifyCdnWithGoogleFonts = require('../../libs/shopify-cdn-with-google-fonts.js');
13
+ var libsStore = require('../../store/libs-store.js');
13
14
 
14
15
  const globalStyleId = 'global-style';
15
16
  const Toolbox = ()=>{
@@ -35,6 +36,8 @@ const Toolbox = ()=>{
35
36
  const changeLayoutSettings = core.useShopStore((s)=>s.changeLayoutSettings);
36
37
  const changeCreateThemeSectionCount = core.useShopStore((s)=>s.changeCreateThemeSectionCount);
37
38
  const changeShopPlan = core.useShopStore((s)=>s.changeShopPlan);
39
+ const changeFontType = libsStore.libsStore((s)=>s.changeFontType);
40
+ const fontType = libsStore.libsStore((s)=>s.fontType);
38
41
  const clearModal = core.useModalStore((s)=>s.clearModal);
39
42
  const setInteractionIsSelectOnPage = core.usePageStore((s)=>s.setInteractionIsSelectOnPage);
40
43
  const setInteractionItem = core.usePageStore((s)=>s.setInteractionItem);
@@ -79,7 +82,7 @@ const Toolbox = ()=>{
79
82
  const variantName = variant;
80
83
  const url = googleFonts.createFontUrl([
81
84
  cloneFont
82
- ]);
85
+ ], undefined, fontType);
83
86
  if (url) {
84
87
  const googleFont = document.querySelector(`.${className}[data-font="${fontName}"][data-font-variant="${variantName}"]`);
85
88
  if (googleFont) {
@@ -282,6 +285,13 @@ const Toolbox = ()=>{
282
285
  }, [
283
286
  changeShopPlan
284
287
  ]);
288
+ const onUpdateFontType = react.useCallback((e)=>{
289
+ const fontType = e.detail;
290
+ if (!fontType) return;
291
+ changeFontType(fontType);
292
+ }, [
293
+ changeFontType
294
+ ]);
285
295
  const onUpdateDynamicProduct = react.useCallback((e)=>{
286
296
  const product = e.detail;
287
297
  if (!product) return;
@@ -387,6 +397,7 @@ const Toolbox = ()=>{
387
397
  window.addEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
388
398
  window.addEventListener('update-interaction-item', onUpdateInteractionItem);
389
399
  window.addEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
400
+ window.addEventListener('update-font-type', onUpdateFontType);
390
401
  return ()=>{
391
402
  window.removeEventListener('update-shop-info', onChangeShopInfo);
392
403
  window.removeEventListener('revalidate-query', onRevalidateQuery);
@@ -409,6 +420,7 @@ const Toolbox = ()=>{
409
420
  window.removeEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
410
421
  window.removeEventListener('update-interaction-item', onUpdateInteractionItem);
411
422
  window.removeEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
423
+ window.removeEventListener('update-font-type', onUpdateFontType);
412
424
  };
413
425
  }, [
414
426
  onAddEntity,
@@ -432,7 +444,8 @@ const Toolbox = ()=>{
432
444
  onUpdateSalePageProductId,
433
445
  onUpdateInteractionItem,
434
446
  onUpdateInteractionIsSelectOnPage,
435
- onUpdateInteractionSettingType
447
+ onUpdateInteractionSettingType,
448
+ onUpdateFontType
436
449
  ]);
437
450
  return /*#__PURE__*/ jsxRuntime.jsx("div", {
438
451
  className: "toolbox"
@@ -35,12 +35,12 @@ const composeFonts = (fonts)=>{
35
35
  };
36
36
  });
37
37
  };
38
- const createFontUrl = (fonts, option)=>{
39
- const googleFonts = fonts.filter((font)=>font.type === 'google' || !font.type);
40
- if (!googleFonts.length) return;
38
+ const createFontUrl = (fonts, option, fontType)=>{
39
+ const mainFonts = fonts.filter((font)=>font.type === 'google' || !font.type || font.type === 'bunny');
40
+ if (!mainFonts.length) return;
41
41
  const params = new URLSearchParams();
42
42
  const display = option?.display || 'swap';
43
- const uniqFonts = googleFonts.filter((font, index, arr)=>{
43
+ const uniqFonts = mainFonts.filter((font, index, arr)=>{
44
44
  return index === arr.findIndex((t)=>t.family === font.family);
45
45
  });
46
46
  const family = composeFonts(uniqFonts).map((font)=>{
@@ -54,13 +54,16 @@ const createFontUrl = (fonts, option)=>{
54
54
  if (option?.effect) {
55
55
  params.append('effect', option.effect);
56
56
  }
57
- return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
57
+ const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
58
+ const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
59
+ return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
58
60
  };
59
- async function getFonts(fonts, option, isImportFontByUrl = true) {
61
+ // eslint-disable-next-line max-params
62
+ async function getFonts(fonts, option, isImportFontByUrl = true, fontType) {
60
63
  /**
61
64
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
62
65
  * CSS cascading 🤷‍♂️.
63
- */ const url = createFontUrl(fonts, option);
66
+ */ const url = createFontUrl(fonts, option, fontType);
64
67
  if (!url) return '';
65
68
  try {
66
69
  if (isImportFontByUrl) return `@import url('${url}');`;
@@ -0,0 +1,14 @@
1
+ 'use strict';
2
+
3
+ var zustand = require('zustand');
4
+
5
+ const libsStore = zustand.create((set)=>({
6
+ fontType: 'google',
7
+ changeFontType: (fontType)=>{
8
+ set({
9
+ fontType
10
+ });
11
+ }
12
+ }));
13
+
14
+ exports.libsStore = libsStore;
@@ -6,6 +6,7 @@ import { createFontUrl } from '../../libs/google-fonts.js';
6
6
  import { genCSS } from '../../libs/helpers/gen-css.js';
7
7
  import { getFontsFromDataBuilder } from '../../libs/helpers/gen-fonts.js';
8
8
  import { shopifyCdnWithGoogleFonts } from '../../libs/shopify-cdn-with-google-fonts.js';
9
+ import { libsStore } from '../../store/libs-store.js';
9
10
 
10
11
  const globalStyleId = 'global-style';
11
12
  const Toolbox = ()=>{
@@ -31,6 +32,8 @@ const Toolbox = ()=>{
31
32
  const changeLayoutSettings = useShopStore((s)=>s.changeLayoutSettings);
32
33
  const changeCreateThemeSectionCount = useShopStore((s)=>s.changeCreateThemeSectionCount);
33
34
  const changeShopPlan = useShopStore((s)=>s.changeShopPlan);
35
+ const changeFontType = libsStore((s)=>s.changeFontType);
36
+ const fontType = libsStore((s)=>s.fontType);
34
37
  const clearModal = useModalStore((s)=>s.clearModal);
35
38
  const setInteractionIsSelectOnPage = usePageStore((s)=>s.setInteractionIsSelectOnPage);
36
39
  const setInteractionItem = usePageStore((s)=>s.setInteractionItem);
@@ -75,7 +78,7 @@ const Toolbox = ()=>{
75
78
  const variantName = variant;
76
79
  const url = createFontUrl([
77
80
  cloneFont
78
- ]);
81
+ ], undefined, fontType);
79
82
  if (url) {
80
83
  const googleFont = document.querySelector(`.${className}[data-font="${fontName}"][data-font-variant="${variantName}"]`);
81
84
  if (googleFont) {
@@ -278,6 +281,13 @@ const Toolbox = ()=>{
278
281
  }, [
279
282
  changeShopPlan
280
283
  ]);
284
+ const onUpdateFontType = useCallback((e)=>{
285
+ const fontType = e.detail;
286
+ if (!fontType) return;
287
+ changeFontType(fontType);
288
+ }, [
289
+ changeFontType
290
+ ]);
281
291
  const onUpdateDynamicProduct = useCallback((e)=>{
282
292
  const product = e.detail;
283
293
  if (!product) return;
@@ -383,6 +393,7 @@ const Toolbox = ()=>{
383
393
  window.addEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
384
394
  window.addEventListener('update-interaction-item', onUpdateInteractionItem);
385
395
  window.addEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
396
+ window.addEventListener('update-font-type', onUpdateFontType);
386
397
  return ()=>{
387
398
  window.removeEventListener('update-shop-info', onChangeShopInfo);
388
399
  window.removeEventListener('revalidate-query', onRevalidateQuery);
@@ -405,6 +416,7 @@ const Toolbox = ()=>{
405
416
  window.removeEventListener('update-interaction-is-select-on-page', onUpdateInteractionIsSelectOnPage);
406
417
  window.removeEventListener('update-interaction-item', onUpdateInteractionItem);
407
418
  window.removeEventListener('update-interaction-setting-type', onUpdateInteractionSettingType);
419
+ window.removeEventListener('update-font-type', onUpdateFontType);
408
420
  };
409
421
  }, [
410
422
  onAddEntity,
@@ -428,7 +440,8 @@ const Toolbox = ()=>{
428
440
  onUpdateSalePageProductId,
429
441
  onUpdateInteractionItem,
430
442
  onUpdateInteractionIsSelectOnPage,
431
- onUpdateInteractionSettingType
443
+ onUpdateInteractionSettingType,
444
+ onUpdateFontType
432
445
  ]);
433
446
  return /*#__PURE__*/ jsx("div", {
434
447
  className: "toolbox"
@@ -33,12 +33,12 @@ const composeFonts = (fonts)=>{
33
33
  };
34
34
  });
35
35
  };
36
- const createFontUrl = (fonts, option)=>{
37
- const googleFonts = fonts.filter((font)=>font.type === 'google' || !font.type);
38
- if (!googleFonts.length) return;
36
+ const createFontUrl = (fonts, option, fontType)=>{
37
+ const mainFonts = fonts.filter((font)=>font.type === 'google' || !font.type || font.type === 'bunny');
38
+ if (!mainFonts.length) return;
39
39
  const params = new URLSearchParams();
40
40
  const display = option?.display || 'swap';
41
- const uniqFonts = googleFonts.filter((font, index, arr)=>{
41
+ const uniqFonts = mainFonts.filter((font, index, arr)=>{
42
42
  return index === arr.findIndex((t)=>t.family === font.family);
43
43
  });
44
44
  const family = composeFonts(uniqFonts).map((font)=>{
@@ -52,13 +52,16 @@ const createFontUrl = (fonts, option)=>{
52
52
  if (option?.effect) {
53
53
  params.append('effect', option.effect);
54
54
  }
55
- return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
55
+ const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
56
+ const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
57
+ return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
56
58
  };
57
- async function getFonts(fonts, option, isImportFontByUrl = true) {
59
+ // eslint-disable-next-line max-params
60
+ async function getFonts(fonts, option, isImportFontByUrl = true, fontType) {
58
61
  /**
59
62
  * The order of IE -> Chrome is important, other wise chrome starts loading woff1.
60
63
  * CSS cascading 🤷‍♂️.
61
- */ const url = createFontUrl(fonts, option);
64
+ */ const url = createFontUrl(fonts, option, fontType);
62
65
  if (!url) return '';
63
66
  try {
64
67
  if (isImportFontByUrl) return `@import url('${url}');`;
@@ -0,0 +1,12 @@
1
+ import { create } from 'zustand';
2
+
3
+ const libsStore = create((set)=>({
4
+ fontType: 'google',
5
+ changeFontType: (fontType)=>{
6
+ set({
7
+ fontType
8
+ });
9
+ }
10
+ }));
11
+
12
+ export { libsStore };
@@ -189,7 +189,7 @@ declare const BuilderPage: React.FC<BuilderPageProps>;
189
189
 
190
190
  declare const getStaticPaths: GetStaticPaths;
191
191
 
192
- type TypographyV2FontFamilyType = 'google' | 'custom' | 'theme';
192
+ type TypographyV2FontFamilyType = 'google' | 'custom' | 'theme' | 'bunny';
193
193
 
194
194
  type FontItem = {
195
195
  type: TypographyV2FontFamilyType;
@@ -202,7 +202,7 @@ type FontOption = {
202
202
  subset?: string;
203
203
  effect?: string;
204
204
  };
205
- declare function getFonts(fonts: FontItem[], option?: FontOption, isImportFontByUrl?: boolean): Promise<string>;
205
+ declare function getFonts(fonts: FontItem[], option?: FontOption, isImportFontByUrl?: boolean, fontType?: string): Promise<string>;
206
206
  declare const getFontFromGlobalStyle: (data?: string) => "" | Promise<string>;
207
207
 
208
208
  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.53.0-dev.82",
3
+ "version": "1.53.0-dev.89",
4
4
  "license": "MIT",
5
5
  "sideEffects": false,
6
6
  "main": "dist/cjs/index.js",