@gem-sdk/pages 1.36.20 → 2.0.0-dev.834
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.
- package/dist/cjs/components/ErrorBoundary.js +1 -40
- package/dist/cjs/components/ErrorFallback.js +1 -26
- package/dist/cjs/components/FacebookPixel.js +3 -36
- package/dist/cjs/components/Footer.js +1 -125
- package/dist/cjs/components/FooterForPostPurchase.js +1 -0
- package/dist/cjs/components/GoogleAnalytic.js +5 -67
- package/dist/cjs/components/Header.js +1 -96
- package/dist/cjs/components/TikTokPixel.js +3 -19
- package/dist/cjs/components/builder/PopupManager.js +1 -62
- package/dist/cjs/components/builder/Toolbar.js +1 -883
- package/dist/cjs/components/builder/Toolbox.js +1 -384
- package/dist/cjs/components/builder/toolbar/Onboarding.js +1 -110
- package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +1 -263
- package/dist/cjs/components/image-to-layout/DropElement.js +1 -164
- package/dist/cjs/components/image-to-layout/ImageToLayout.js +1 -41
- package/dist/cjs/index.js +1 -75
- package/dist/cjs/layouts/main.js +1 -30
- package/dist/cjs/libs/api/get-builder-props.js +1 -41
- package/dist/cjs/libs/api/get-collection-props.js +1 -68
- package/dist/cjs/libs/api/get-home-page-props-v2.js +1 -145
- package/dist/cjs/libs/api/get-home-page-props.js +1 -151
- package/dist/cjs/libs/api/get-post-purchase-props-preview.js +1 -0
- package/dist/cjs/libs/api/get-preview-props.js +1 -18
- package/dist/cjs/libs/api/get-product-props.js +1 -73
- package/dist/cjs/libs/api/get-static-page-props-preview.js +1 -150
- package/dist/cjs/libs/api/get-static-page-props-v2.js +1 -152
- package/dist/cjs/libs/api/get-static-page-props.js +1 -148
- package/dist/cjs/libs/custom-fonts.js +6 -60
- package/dist/cjs/libs/fetcher.js +1 -67
- package/dist/cjs/libs/get-layout.js +1 -13
- package/dist/cjs/libs/get-storefront-api.js +1 -12
- package/dist/cjs/libs/getStaticPaths.js +1 -10
- package/dist/cjs/libs/google-fonts.js +1 -81
- package/dist/cjs/libs/helpers/common.js +1 -27
- package/dist/cjs/libs/helpers/gen-css.js +1 -117
- package/dist/cjs/libs/helpers/gen-fonts.js +1 -68
- package/dist/cjs/libs/helpers/generate-manifres.js +1 -5
- package/dist/cjs/libs/helpers/get-fallback.js +1 -35
- package/dist/cjs/libs/helpers/normalize.js +1 -90
- package/dist/cjs/libs/helpers/parse-json.js +1 -16
- package/dist/cjs/libs/helpers/user-agent.js +1 -7
- package/dist/cjs/libs/hooks/use-tracking-view.js +1 -45
- package/dist/cjs/libs/hooks/usePagePreview.js +1 -0
- package/dist/cjs/libs/parse-html.js +1 -42
- package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1 -1845
- package/dist/cjs/pages/404.js +1 -43
- package/dist/cjs/pages/500.js +1 -74
- package/dist/cjs/pages/CollectionGlobalProvider.js +1 -59
- package/dist/cjs/pages/builder.js +1 -103
- package/dist/cjs/pages/collection-detail.js +1 -64
- package/dist/cjs/pages/preview.js +1 -26
- package/dist/cjs/pages/product-detail.js +1 -69
- package/dist/cjs/pages/static-v2.js +1 -91
- package/dist/cjs/pages/static.js +1 -75
- package/dist/esm/components/ErrorBoundary.js +1 -38
- package/dist/esm/components/ErrorFallback.js +1 -24
- package/dist/esm/components/FacebookPixel.js +3 -34
- package/dist/esm/components/Footer.js +1 -121
- package/dist/esm/components/FooterForPostPurchase.js +1 -0
- package/dist/esm/components/GoogleAnalytic.js +5 -65
- package/dist/esm/components/Header.js +1 -92
- package/dist/esm/components/TikTokPixel.js +3 -17
- package/dist/esm/components/builder/PopupManager.js +1 -58
- package/dist/esm/components/builder/Toolbar.js +1 -879
- package/dist/esm/components/builder/Toolbox.js +1 -380
- package/dist/esm/components/builder/toolbar/Onboarding.js +1 -106
- package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +1 -259
- package/dist/esm/components/image-to-layout/DropElement.js +1 -162
- package/dist/esm/components/image-to-layout/ImageToLayout.js +1 -37
- package/dist/esm/index.js +1 -33
- package/dist/esm/layouts/main.js +1 -26
- package/dist/esm/libs/api/get-builder-props.js +1 -39
- package/dist/esm/libs/api/get-collection-props.js +1 -66
- package/dist/esm/libs/api/get-home-page-props-v2.js +1 -143
- package/dist/esm/libs/api/get-home-page-props.js +1 -149
- package/dist/esm/libs/api/get-post-purchase-props-preview.js +1 -0
- package/dist/esm/libs/api/get-preview-props.js +1 -16
- package/dist/esm/libs/api/get-product-props.js +1 -71
- package/dist/esm/libs/api/get-static-page-props-preview.js +1 -148
- package/dist/esm/libs/api/get-static-page-props-v2.js +1 -150
- package/dist/esm/libs/api/get-static-page-props.js +1 -146
- package/dist/esm/libs/custom-fonts.js +6 -55
- package/dist/esm/libs/fetcher.js +1 -64
- package/dist/esm/libs/get-layout.js +1 -11
- package/dist/esm/libs/get-storefront-api.js +1 -10
- package/dist/esm/libs/getStaticPaths.js +1 -8
- package/dist/esm/libs/google-fonts.js +1 -75
- package/dist/esm/libs/helpers/common.js +1 -24
- package/dist/esm/libs/helpers/gen-css.js +1 -115
- package/dist/esm/libs/helpers/gen-fonts.js +1 -65
- package/dist/esm/libs/helpers/generate-manifres.js +1 -3
- package/dist/esm/libs/helpers/get-fallback.js +1 -33
- package/dist/esm/libs/helpers/normalize.js +1 -85
- package/dist/esm/libs/helpers/parse-json.js +1 -13
- package/dist/esm/libs/helpers/user-agent.js +1 -5
- package/dist/esm/libs/hooks/use-tracking-view.js +1 -43
- package/dist/esm/libs/hooks/usePagePreview.js +1 -0
- package/dist/esm/libs/parse-html.js +1 -40
- package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1 -1843
- package/dist/esm/pages/404.js +1 -41
- package/dist/esm/pages/500.js +1 -72
- package/dist/esm/pages/CollectionGlobalProvider.js +1 -55
- package/dist/esm/pages/builder.js +1 -101
- package/dist/esm/pages/collection-detail.js +1 -60
- package/dist/esm/pages/preview.js +1 -24
- package/dist/esm/pages/product-detail.js +1 -65
- package/dist/esm/pages/static-v2.js +1 -89
- package/dist/esm/pages/static.js +1 -71
- package/dist/types/index.d.ts +29 -6
- package/package.json +5 -5
|
@@ -1,81 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var genFonts = require('./helpers/gen-fonts.js');
|
|
4
|
-
|
|
5
|
-
const composeFonts = (fonts)=>{
|
|
6
|
-
const uniqFonts = fonts.filter((font, index, arr)=>{
|
|
7
|
-
return index === arr.findIndex((t)=>t.family === font.family);
|
|
8
|
-
});
|
|
9
|
-
return uniqFonts.map((font)=>{
|
|
10
|
-
const variants = fonts.filter((t)=>t.family === font.family).reduce((acc, t)=>{
|
|
11
|
-
return [
|
|
12
|
-
...acc,
|
|
13
|
-
...t.variants
|
|
14
|
-
];
|
|
15
|
-
}, []).filter((t, index, arr)=>{
|
|
16
|
-
return index === arr.findIndex((v)=>v === t);
|
|
17
|
-
});
|
|
18
|
-
return {
|
|
19
|
-
...font,
|
|
20
|
-
variants
|
|
21
|
-
};
|
|
22
|
-
});
|
|
23
|
-
};
|
|
24
|
-
const createFontUrl = (fonts, option)=>{
|
|
25
|
-
const googleFonts = fonts.filter((font)=>font.type === 'google' || !font.type);
|
|
26
|
-
if (!googleFonts.length) return;
|
|
27
|
-
const params = new URLSearchParams();
|
|
28
|
-
const display = option?.display || 'swap';
|
|
29
|
-
const uniqFonts = googleFonts.filter((font, index, arr)=>{
|
|
30
|
-
return index === arr.findIndex((t)=>t.family === font.family);
|
|
31
|
-
});
|
|
32
|
-
const family = composeFonts(uniqFonts).map((font)=>{
|
|
33
|
-
return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
|
|
34
|
-
}).join('|');
|
|
35
|
-
params.append('family', family);
|
|
36
|
-
params.append('display', display);
|
|
37
|
-
if (option?.subset) {
|
|
38
|
-
params.append('subset', option.subset);
|
|
39
|
-
}
|
|
40
|
-
if (option?.effect) {
|
|
41
|
-
params.append('effect', option.effect);
|
|
42
|
-
}
|
|
43
|
-
return `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
|
|
44
|
-
};
|
|
45
|
-
async function getFonts(fonts, option) {
|
|
46
|
-
/**
|
|
47
|
-
* The order of IE -> Chrome is important, other wise chrome starts loading woff1.
|
|
48
|
-
* CSS cascading 🤷♂️.
|
|
49
|
-
*/ const url = createFontUrl(fonts, option);
|
|
50
|
-
if (!url) return '';
|
|
51
|
-
try {
|
|
52
|
-
return `@import url('${url}');`;
|
|
53
|
-
} catch (e) {
|
|
54
|
-
return '';
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
const getFontFromGlobalStyle = (data)=>{
|
|
58
|
-
if (!data) return '';
|
|
59
|
-
try {
|
|
60
|
-
const globalStyle = JSON.parse(data);
|
|
61
|
-
const fontData = globalStyle?.font ?? {};
|
|
62
|
-
const fonts = Object.entries(fontData).map(([, value])=>{
|
|
63
|
-
return value;
|
|
64
|
-
});
|
|
65
|
-
return getFonts(fonts);
|
|
66
|
-
} catch {
|
|
67
|
-
return '';
|
|
68
|
-
}
|
|
69
|
-
};
|
|
70
|
-
async function getFontStyleFromPageTemplate(pageTemplate) {
|
|
71
|
-
const fontStyle = pageTemplate.map((sectionData)=>{
|
|
72
|
-
return getFonts(genFonts.getFontsFromDataBuilder(sectionData.data));
|
|
73
|
-
});
|
|
74
|
-
return await Promise.all(fontStyle);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
exports.composeFonts = composeFonts;
|
|
78
|
-
exports.createFontUrl = createFontUrl;
|
|
79
|
-
exports.getFontFromGlobalStyle = getFontFromGlobalStyle;
|
|
80
|
-
exports.getFontStyleFromPageTemplate = getFontStyleFromPageTemplate;
|
|
81
|
-
exports.getFonts = getFonts;
|
|
1
|
+
"use strict";var genFonts=require("./helpers/gen-fonts.js");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",IE_UA="Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko";async function getFontForUA(e,t){return fetch(e,{headers:{"User-Agent":t}}).then(e=>200===e.status?e.text():"")}const composeFonts=e=>{let t=e.filter((e,t,o)=>t===o.findIndex(t=>t.family===e.family));return t.map(t=>{let o=e.filter(e=>e.family===t.family).reduce((e,t)=>[...e,...t.variants],[]).filter((e,t,o)=>t===o.findIndex(t=>t===e));return{...t,variants:o}})},createFontUrl=(e,t)=>{let o=e.filter(e=>"google"===e.type||!e.type);if(!o.length)return;let n=new URLSearchParams,r=t?.display||"swap",a=o.filter((e,t,o)=>t===o.findIndex(t=>t.family===e.family)),l=composeFonts(a).map(e=>`${e.family.replace(/ /g,"+")}:${e.variants.join(",")}`).join("|");return n.append("family",l),n.append("display",r),t?.subset&&n.append("subset",t.subset),t?.effect&&n.append("effect",t.effect),`https://fonts.googleapis.com/css?${decodeURIComponent(n.toString())}`};async function getFonts(e,t,o=!0){let n=createFontUrl(e,t);if(!n)return"";try{if(o)return`@import url('${n}');`;let[e,t]=await Promise.all([getFontForUA(n,"Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko"),getFontForUA(n,"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")]);return e+t}catch(e){return""}}const getFontFromGlobalStyle=e=>{if(!e)return"";try{let t=JSON.parse(e),o=t?.font??{},n=Object.entries(o).map(([,e])=>e);return getFonts(n)}catch{return""}};async function getFontStyleFromPageTemplate(e){let t=e.map(e=>getFonts(genFonts.getFontsFromDataBuilder(e.data)));return await Promise.all(t)}exports.composeFonts=composeFonts,exports.createFontUrl=createFontUrl,exports.getFontFromGlobalStyle=getFontFromGlobalStyle,exports.getFontStyleFromPageTemplate=getFontStyleFromPageTemplate,exports.getFonts=getFonts;
|
|
@@ -1,27 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
async function wait(ms) {
|
|
4
|
-
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
5
|
-
}
|
|
6
|
-
const retryWithDelay = async (fn, config)=>{
|
|
7
|
-
const retries = config?.retries ?? 3;
|
|
8
|
-
const delay = config?.delay ?? 1000;
|
|
9
|
-
try {
|
|
10
|
-
return await fn();
|
|
11
|
-
} catch (err) {
|
|
12
|
-
if (retries <= 0 || config?.retryIf && !config.retryIf(err)) {
|
|
13
|
-
return Promise.reject(err);
|
|
14
|
-
}
|
|
15
|
-
//delay the next call
|
|
16
|
-
await wait(delay);
|
|
17
|
-
//recursively call the same func
|
|
18
|
-
return retryWithDelay(fn, {
|
|
19
|
-
...config,
|
|
20
|
-
retries: retries - 1,
|
|
21
|
-
delay
|
|
22
|
-
});
|
|
23
|
-
}
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
exports.retryWithDelay = retryWithDelay;
|
|
27
|
-
exports.wait = wait;
|
|
1
|
+
"use strict";async function wait(t){return new Promise(e=>setTimeout(e,t))}const retryWithDelay=async(t,e)=>{let r=e?.retries??3,i=e?.delay??1e3;try{return await t()}catch(a){if(r<=0||e?.retryIf&&!e.retryIf(a))return Promise.reject(a);return await wait(i),retryWithDelay(t,{...e,retries:r-1,delay:i})}};exports.retryWithDelay=retryWithDelay,exports.wait=wait;
|
|
@@ -1,117 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var core = require('@gem-sdk/core');
|
|
4
|
-
var merge = require('deepmerge');
|
|
5
|
-
|
|
6
|
-
const baseDevices = {
|
|
7
|
-
tablet: '1023px',
|
|
8
|
-
mobile: '767px'
|
|
9
|
-
};
|
|
10
|
-
const flattenObject = (obj, prefix)=>{
|
|
11
|
-
return Object.keys(obj).reduce((acc, k)=>{
|
|
12
|
-
const pre = prefix ? `${prefix}-` : '';
|
|
13
|
-
if (typeof obj[k] === 'object' && obj[k] !== null && Object.keys(obj[k]).length > 0) Object.assign(acc, flattenObject(obj[k], pre + k));
|
|
14
|
-
else acc[pre + k] = obj[k];
|
|
15
|
-
return acc;
|
|
16
|
-
}, {});
|
|
17
|
-
};
|
|
18
|
-
const devicesOrder = [
|
|
19
|
-
'desktop',
|
|
20
|
-
'tablet',
|
|
21
|
-
'mobile'
|
|
22
|
-
];
|
|
23
|
-
const mapObject = (obj)=>{
|
|
24
|
-
return Object.entries(obj ?? {}).reduce((acc, [k, v])=>{
|
|
25
|
-
return {
|
|
26
|
-
...acc,
|
|
27
|
-
[core.getShortName(k)]: typeof v === 'object' ? mapObject(v) : v
|
|
28
|
-
};
|
|
29
|
-
}, {});
|
|
30
|
-
};
|
|
31
|
-
const getValueByDevice = (data, device)=>{
|
|
32
|
-
const deviceData = {
|
|
33
|
-
typography: Object.fromEntries(Object.entries(data?.typography ?? {}).map(([key, value])=>{
|
|
34
|
-
const typo = {
|
|
35
|
-
...value?.[device]
|
|
36
|
-
};
|
|
37
|
-
if (!typo) return [
|
|
38
|
-
key,
|
|
39
|
-
undefined
|
|
40
|
-
];
|
|
41
|
-
if (typo.fontFamily) {
|
|
42
|
-
typo.fontFamily = `var(--g-font-${typo.fontFamily}, ${typo.fontFamily})`;
|
|
43
|
-
}
|
|
44
|
-
return [
|
|
45
|
-
key,
|
|
46
|
-
typo
|
|
47
|
-
];
|
|
48
|
-
})),
|
|
49
|
-
spacing: Object.fromEntries(Object.entries(data?.spacing ?? {}).map(([key, value])=>{
|
|
50
|
-
return [
|
|
51
|
-
key,
|
|
52
|
-
value?.[device]
|
|
53
|
-
];
|
|
54
|
-
})),
|
|
55
|
-
container: Object.fromEntries(Object.entries(data?.container ?? {}).map(([key, value])=>{
|
|
56
|
-
return [
|
|
57
|
-
key,
|
|
58
|
-
value?.[device]
|
|
59
|
-
];
|
|
60
|
-
})),
|
|
61
|
-
font: Object.fromEntries(Object.entries(data?.font ?? {}).map(([key, value])=>{
|
|
62
|
-
return [
|
|
63
|
-
key,
|
|
64
|
-
value?.family
|
|
65
|
-
];
|
|
66
|
-
}))
|
|
67
|
-
};
|
|
68
|
-
return deviceData;
|
|
69
|
-
};
|
|
70
|
-
const genCSSVariable = (deviceData)=>{
|
|
71
|
-
return Object.entries(mapObject(flattenObject(deviceData))).map(([key, value])=>{
|
|
72
|
-
if (value === undefined) return undefined;
|
|
73
|
-
if ([
|
|
74
|
-
'font-heading',
|
|
75
|
-
'font-body'
|
|
76
|
-
].includes(key)) {
|
|
77
|
-
return `--g-${key}: '${value}'`;
|
|
78
|
-
}
|
|
79
|
-
return `--g-${key}:${value}`;
|
|
80
|
-
}).filter((v)=>v !== undefined).join(';');
|
|
81
|
-
};
|
|
82
|
-
const genCSS = (input, mobileOnly)=>{
|
|
83
|
-
if (!input) return '';
|
|
84
|
-
let data = {};
|
|
85
|
-
try {
|
|
86
|
-
if (typeof input === 'string') {
|
|
87
|
-
data = JSON.parse(input);
|
|
88
|
-
} else {
|
|
89
|
-
data = input;
|
|
90
|
-
}
|
|
91
|
-
if (mobileOnly) {
|
|
92
|
-
const desktop = getValueByDevice(data, 'desktop');
|
|
93
|
-
const mobile = getValueByDevice(data, 'mobile');
|
|
94
|
-
const deviceData = merge(desktop, mobile);
|
|
95
|
-
deviceData.color = data.color;
|
|
96
|
-
deviceData.radius = data.radius;
|
|
97
|
-
const cssData = genCSSVariable(deviceData);
|
|
98
|
-
return `:root{${cssData}}`;
|
|
99
|
-
}
|
|
100
|
-
return devicesOrder.map((device)=>{
|
|
101
|
-
const deviceData = getValueByDevice(data, device);
|
|
102
|
-
if (device === 'desktop') {
|
|
103
|
-
deviceData.color = data.color;
|
|
104
|
-
deviceData.radius = data.radius;
|
|
105
|
-
}
|
|
106
|
-
const cssData = genCSSVariable(deviceData);
|
|
107
|
-
if (device === 'desktop') {
|
|
108
|
-
return `:root{${cssData}}`;
|
|
109
|
-
}
|
|
110
|
-
return `@media (max-width: ${baseDevices[device]}) {:root{${cssData}}}`;
|
|
111
|
-
}).join('\n');
|
|
112
|
-
} catch {
|
|
113
|
-
return '';
|
|
114
|
-
}
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
exports.genCSS = genCSS;
|
|
1
|
+
"use strict";var core=require("@gem-sdk/core"),merge=require("deepmerge");const baseDevices={tablet:"1023px",mobile:"767px"},flattenObject=(e,t)=>Object.keys(e).reduce((r,i)=>{let o=t?`${t}-`:"";return"object"==typeof e[i]&&null!==e[i]&&Object.keys(e[i]).length>0?Object.assign(r,flattenObject(e[i],o+i)):r[o+i]=e[i],r},{}),devicesOrder=["desktop","tablet","mobile"],mapObject=e=>Object.entries(e??{}).reduce((e,[t,r])=>({...e,[core.getShortName(t)]:"object"==typeof r?mapObject(r):r}),{}),getValueByDevice=(e,t)=>{let r={typography:Object.fromEntries(Object.entries(e?.typography??{}).map(([e,r])=>{let i={...r?.[t]};return i?(i.fontFamily&&(i.fontFamily=`var(--g-font-${i.fontFamily}, ${i.fontFamily})`),[e,i]):[e,void 0]})),spacing:Object.fromEntries(Object.entries(e?.spacing??{}).map(([e,r])=>[e,r?.[t]])),container:Object.fromEntries(Object.entries(e?.container??{}).map(([e,r])=>[e,r?.[t]])),font:Object.fromEntries(Object.entries(e?.font??{}).map(([e,t])=>[e,t?.family]))};return r},genCSSVariable=e=>Object.entries(mapObject(flattenObject(e))).map(([e,t])=>{if(void 0!==t)return["font-heading","font-body"].includes(e)?`--g-${e}: '${t}'`:`--g-${e}:${t}`}).filter(e=>void 0!==e).join(";"),genCSS=(e,t)=>{if(!e)return"";let r={};try{if(r="string"==typeof e?JSON.parse(e):e,t){let e=getValueByDevice(r,"desktop"),t=getValueByDevice(r,"mobile"),i=merge(e,t);i.color=r.color,i.radius=r.radius;let o=genCSSVariable(i);return`:root{${o}}`}return devicesOrder.map(e=>{let t=getValueByDevice(r,e);"desktop"===e&&(t.color=r.color,t.radius=r.radius);let i=genCSSVariable(t);return"desktop"===e?`:root{${i}}`:`@media (max-width: ${baseDevices[e]}) {:root{${i}}}`}).join("\n")}catch{return""}};exports.genCSS=genCSS;
|
|
@@ -1,68 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const getFontsFromDataBuilder = (dataBuilder)=>{
|
|
4
|
-
const fonts = [];
|
|
5
|
-
for(const uid in dataBuilder){
|
|
6
|
-
if (Object.prototype.hasOwnProperty.call(dataBuilder, uid)) {
|
|
7
|
-
const data = dataBuilder[uid];
|
|
8
|
-
const styles = data.styles;
|
|
9
|
-
const settings = data.settings;
|
|
10
|
-
getFontFromGroupSetting(fonts, styles);
|
|
11
|
-
getFontFromGroupSetting(fonts, settings);
|
|
12
|
-
}
|
|
13
|
-
}
|
|
14
|
-
return fonts;
|
|
15
|
-
};
|
|
16
|
-
const getFontFromGroupSetting = (fonts, groupSetting)=>{
|
|
17
|
-
for(const attr in groupSetting){
|
|
18
|
-
if (Object.prototype.hasOwnProperty.call(groupSetting, attr)) {
|
|
19
|
-
const value = groupSetting[attr];
|
|
20
|
-
if (value) {
|
|
21
|
-
const customFontFamily = value.custom?.fontFamily;
|
|
22
|
-
let customFontVariants = value.custom?.fontVariants;
|
|
23
|
-
if (!customFontVariants?.length) {
|
|
24
|
-
customFontVariants = [
|
|
25
|
-
value.custom?.fontWeight
|
|
26
|
-
];
|
|
27
|
-
}
|
|
28
|
-
if (customFontFamily && customFontVariants?.length) {
|
|
29
|
-
const variants = customFontVariants.map((item)=>{
|
|
30
|
-
switch(item){
|
|
31
|
-
case 'regular':
|
|
32
|
-
return '400';
|
|
33
|
-
}
|
|
34
|
-
return item;
|
|
35
|
-
});
|
|
36
|
-
const customFontWeight = value.custom?.fontWeight && variants.includes(value.custom?.fontWeight) ? value.custom?.fontWeight : variants[0];
|
|
37
|
-
if (customFontWeight) {
|
|
38
|
-
const isExist = fonts.find((item)=>item.family == customFontFamily && item.variants.includes(customFontWeight));
|
|
39
|
-
if (!isExist) {
|
|
40
|
-
const isFontFamily = fonts.find((item)=>item.family == customFontFamily);
|
|
41
|
-
if (isFontFamily) {
|
|
42
|
-
isFontFamily.variants.push(customFontWeight);
|
|
43
|
-
} else {
|
|
44
|
-
const fontVariants = [
|
|
45
|
-
customFontWeight
|
|
46
|
-
];
|
|
47
|
-
if (customFontWeight !== '700') {
|
|
48
|
-
if (variants.includes('700')) {
|
|
49
|
-
fontVariants.push('700'); // Auto add 700 for bold in editor inline
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
fonts.push({
|
|
53
|
-
family: customFontFamily,
|
|
54
|
-
variants: fontVariants,
|
|
55
|
-
subsets: [],
|
|
56
|
-
type: 'google'
|
|
57
|
-
});
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
}
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
exports.getFontFromGroupSetting = getFontFromGroupSetting;
|
|
68
|
-
exports.getFontsFromDataBuilder = getFontsFromDataBuilder;
|
|
1
|
+
"use strict";const getFontsFromDataBuilder=t=>{let e=[];for(let o in t)if(Object.prototype.hasOwnProperty.call(t,o)){let n=t[o],i=n.styles,r=n.settings;getFontFromGroupSetting(e,i),getFontFromGroupSetting(e,r)}return e},getFontFromGroupSetting=(t,e)=>{for(let o in e)if(Object.prototype.hasOwnProperty.call(e,o)){let n=e[o];if(n){let e=n.custom?.fontFamily,o=n.custom?.fontVariants;if(o?.length||(o=[n.custom?.fontWeight]),e&&o?.length){let i=o.map(t=>"regular"===t?"400":t),r=n.custom?.fontWeight&&i.includes(n.custom?.fontWeight)?n.custom?.fontWeight:i[0];if(r){let o=t.find(t=>t.family==e&&t.variants.includes(r));if(!o){let o=t.find(t=>t.family==e);if(o)o.variants.push(r);else{let o=[r];"700"!==r&&i.includes("700")&&o.push("700"),t.push({family:e,variants:o,subsets:[],type:"google"})}}}}}}};exports.getFontFromGroupSetting=getFontFromGroupSetting,exports.getFontsFromDataBuilder=getFontsFromDataBuilder;
|
|
@@ -1,5 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const generateManifest = (data)=>`data:application/manifest+json,${encodeURIComponent(JSON.stringify(data))}`;
|
|
4
|
-
|
|
5
|
-
exports.generateManifest = generateManifest;
|
|
1
|
+
"use strict";const generateManifest=e=>`data:application/manifest+json,${encodeURIComponent(JSON.stringify(e))}`;exports.generateManifest=generateManifest;
|
|
@@ -1,35 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var core = require('@gem-sdk/core');
|
|
4
|
-
|
|
5
|
-
const isStorefront = true;
|
|
6
|
-
const getFallbackV2 = async (fetcher, data)=>{
|
|
7
|
-
const isSample = !process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
|
|
8
|
-
const queries = data.map((v)=>core.prefetchQueries(v.data, {
|
|
9
|
-
isSample,
|
|
10
|
-
isStorefront
|
|
11
|
-
})).flat();
|
|
12
|
-
const datas = await Promise.allSettled(queries.map(({ query, variables, func })=>{
|
|
13
|
-
if (func) {
|
|
14
|
-
return func(fetcher, variables);
|
|
15
|
-
}
|
|
16
|
-
if (query) return fetcher([
|
|
17
|
-
query,
|
|
18
|
-
variables
|
|
19
|
-
]);
|
|
20
|
-
return {};
|
|
21
|
-
}));
|
|
22
|
-
const fallback = queries.reduce((acc, { key }, index)=>{
|
|
23
|
-
const res = datas[index];
|
|
24
|
-
if (res?.status === 'fulfilled') {
|
|
25
|
-
return {
|
|
26
|
-
...acc,
|
|
27
|
-
[key]: res.value
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
return acc;
|
|
31
|
-
}, {});
|
|
32
|
-
return fallback;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
exports.getFallbackV2 = getFallbackV2;
|
|
1
|
+
"use strict";var core=require("@gem-sdk/core");const isStorefront=!0,getFallbackV2=async(e,t)=>{let r=!process.env.NEXT_PUBLIC_STOREFRONT_TOKEN,a=t.map(e=>core.prefetchQueries(e.data,{isSample:r,isStorefront:!0})).flat(),l=await Promise.allSettled(a.map(({query:t,variables:r,func:a})=>a?a(e,r):t?e([t,r]):{})),s=a.reduce((e,{key:t},r)=>{let a=l[r];return a?.status==="fulfilled"?{...e,[t]:a.value}:e},{});return s};exports.getFallbackV2=getFallbackV2;
|
|
@@ -1,90 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const normalizeBuilderData = (data)=>{
|
|
4
|
-
const result = {};
|
|
5
|
-
function compose(cData, currData = {}) {
|
|
6
|
-
if (cData) {
|
|
7
|
-
const { childrens, dateModified, editorConfigs, ...rest } = cData;
|
|
8
|
-
if (rest.type === 'section') {
|
|
9
|
-
currData[rest.uid] = rest;
|
|
10
|
-
} else {
|
|
11
|
-
const items = childrens?.map((child)=>child?.uid) ?? [];
|
|
12
|
-
currData[rest.uid] = {
|
|
13
|
-
...rest,
|
|
14
|
-
childrens: items
|
|
15
|
-
};
|
|
16
|
-
if (childrens) {
|
|
17
|
-
childrens.map((child)=>compose(child, currData));
|
|
18
|
-
}
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
compose(data, result);
|
|
23
|
-
return {
|
|
24
|
-
...result
|
|
25
|
-
};
|
|
26
|
-
};
|
|
27
|
-
const orderSection = (sections, orders)=>{
|
|
28
|
-
// Filter out sections that are not in the order list
|
|
29
|
-
const ids = orders?.filter((id)=>sections?.some((v)=>v?.id === id));
|
|
30
|
-
// Return the ordered sections
|
|
31
|
-
const orderedSections = ids?.map((id)=>sections?.find((v)=>v?.id === id)) ?? [];
|
|
32
|
-
// Return the sections that are not in the order list
|
|
33
|
-
const sectionsNotInOrder = sections?.filter((v)=>!v?.id || !ids?.includes(v.id)) ?? [];
|
|
34
|
-
// Return the ordered sections + the sections that are not in the order list
|
|
35
|
-
return orderedSections.concat(sectionsNotInOrder);
|
|
36
|
-
};
|
|
37
|
-
function normalizePageSectionResponse(sections, orders) {
|
|
38
|
-
const sortedSections = orderSection(sections, orders);
|
|
39
|
-
const childrens = sortedSections.map((item)=>{
|
|
40
|
-
if (!item?.component) return false;
|
|
41
|
-
try {
|
|
42
|
-
const data = JSON.parse(item.component);
|
|
43
|
-
return data;
|
|
44
|
-
} catch {
|
|
45
|
-
return false;
|
|
46
|
-
}
|
|
47
|
-
}).filter(Boolean);
|
|
48
|
-
return normalizeBuilderData({
|
|
49
|
-
uid: 'ROOT',
|
|
50
|
-
tag: 'Root',
|
|
51
|
-
childrens
|
|
52
|
-
});
|
|
53
|
-
}
|
|
54
|
-
function normalizePageSectionResponseV2(sections, orders) {
|
|
55
|
-
const sortedSections = orderSection(sections, orders);
|
|
56
|
-
const childrens = sortedSections.map((item)=>{
|
|
57
|
-
if (!item?.component) return false;
|
|
58
|
-
try {
|
|
59
|
-
const data = JSON.parse(item.component);
|
|
60
|
-
return data;
|
|
61
|
-
} catch {
|
|
62
|
-
return false;
|
|
63
|
-
}
|
|
64
|
-
}).filter(Boolean);
|
|
65
|
-
return childrens.map((v)=>{
|
|
66
|
-
return {
|
|
67
|
-
uid: v.uid,
|
|
68
|
-
lazy: Boolean(v.settings?.lazy),
|
|
69
|
-
priority: Boolean(v.settings?.priority),
|
|
70
|
-
data: normalizeBuilderData(v)
|
|
71
|
-
};
|
|
72
|
-
});
|
|
73
|
-
}
|
|
74
|
-
const parseBuilderTemplateV2 = (data)=>{
|
|
75
|
-
return normalizePageSectionResponseV2([
|
|
76
|
-
...data?.pageSections ?? [],
|
|
77
|
-
...data?.themePageCustomSections ?? []
|
|
78
|
-
], data?.sectionPosition);
|
|
79
|
-
};
|
|
80
|
-
const parseBuilderTemplate = (data)=>{
|
|
81
|
-
return normalizePageSectionResponse([
|
|
82
|
-
...data?.pageSections ?? [],
|
|
83
|
-
...data?.themePageCustomSections ?? []
|
|
84
|
-
], data?.sectionPosition);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
exports.normalizeBuilderData = normalizeBuilderData;
|
|
88
|
-
exports.normalizePageSectionResponseV2 = normalizePageSectionResponseV2;
|
|
89
|
-
exports.parseBuilderTemplate = parseBuilderTemplate;
|
|
90
|
-
exports.parseBuilderTemplateV2 = parseBuilderTemplateV2;
|
|
1
|
+
"use strict";const normalizeBuilderData=e=>{let t={};function r(e,t={}){if(e){let{childrens:i,dateModified:o,editorConfigs:n,...a}=e;if("section"===a.type)t[a.uid]=a;else{let e=i?.map(e=>e?.uid)??[];t[a.uid]={...a,childrens:e},i&&i.map(e=>r(e,t))}}}return r(e,t),{...t}},orderSection=(e,t)=>{let r=t?.filter(t=>e?.some(e=>e?.id===t)),i=r?.map(t=>e?.find(e=>e?.id===t))??[],o=e?.filter(e=>(!e?.id||!r?.includes(e.id))&&!e?.deletedAt)??[];return i.concat(o)};function normalizePageSectionResponse(e,t){let r=orderSection(e,t),i=r.map(e=>{if(!e?.component)return!1;try{let t=JSON.parse(e.component);return t}catch{return!1}}).filter(Boolean);return normalizeBuilderData({uid:"ROOT",tag:"Root",childrens:i})}function normalizePageSectionResponseV2(e,t){let r=orderSection(e,t),i=r.map(e=>{if(!e?.component)return!1;try{let t=JSON.parse(e.component);return t}catch{return!1}}).filter(Boolean);return i.map(e=>({uid:e.uid,lazy:!!e.settings?.lazy,priority:!!e.settings?.priority,data:normalizeBuilderData(e)}))}const parseBuilderTemplateV2=e=>normalizePageSectionResponseV2([...e?.pageSections??[],...e?.themePageCustomSections??[]],e?.sectionPosition),parseBuilderTemplate=e=>normalizePageSectionResponse([...e?.pageSections??[],...e?.themePageCustomSections??[]],e?.sectionPosition),parseBuilderLibraryTemplate=e=>normalizePageSectionResponseV2([...e?.sections??[]],e?.sectionPosition);exports.normalizeBuilderData=normalizeBuilderData,exports.normalizePageSectionResponseV2=normalizePageSectionResponseV2,exports.parseBuilderLibraryTemplate=parseBuilderLibraryTemplate,exports.parseBuilderTemplate=parseBuilderTemplate,exports.parseBuilderTemplateV2=parseBuilderTemplateV2;
|
|
@@ -1,16 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
const parseJson = (json)=>{
|
|
4
|
-
if (!json) return null;
|
|
5
|
-
try {
|
|
6
|
-
return JSON.parse(json);
|
|
7
|
-
} catch (e) {
|
|
8
|
-
return null;
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
const serializableJson = (props)=>{
|
|
12
|
-
return JSON.parse(JSON.stringify(props));
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
exports.parseJson = parseJson;
|
|
16
|
-
exports.serializableJson = serializableJson;
|
|
1
|
+
"use strict";const parseJson=s=>{if(!s)return null;try{return JSON.parse(s)}catch(s){return null}},serializableJson=s=>JSON.parse(JSON.stringify(s));exports.parseJson=parseJson,exports.serializableJson=serializableJson;
|
|
@@ -1,7 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
function isBot(input) {
|
|
4
|
-
return /Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Chrome-Lighthouse|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(input);
|
|
5
|
-
}
|
|
6
|
-
|
|
7
|
-
exports.isBot = isBot;
|
|
1
|
+
"use strict";function isBot(o){return/Googlebot|Mediapartners-Google|AdsBot-Google|googleweblight|Storebot-Google|Google-PageRenderer|Chrome-Lighthouse|Bingbot|BingPreview|Slurp|DuckDuckBot|baiduspider|yandex|sogou|LinkedInBot|bitlybot|tumblr|vkShare|quora link preview|facebookexternalhit|facebookcatalog|Twitterbot|applebot|redditbot|Slackbot|Discordbot|WhatsApp|SkypeUriPreview|ia_archiver/i.test(o)}exports.isBot=isBot;
|
|
@@ -1,45 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var core = require('@gem-sdk/core');
|
|
4
|
-
var react = require('react');
|
|
5
|
-
var userAgent = require('../helpers/user-agent.js');
|
|
6
|
-
|
|
7
|
-
const useTrackingView = (token, handle, isFallback)=>{
|
|
8
|
-
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
9
|
-
const apiURL = process.env.NEXT_PUBLIC_API_URL;
|
|
10
|
-
const sendTracking = react.useCallback((handle)=>{
|
|
11
|
-
if (!apiURL || !shopToken) return;
|
|
12
|
-
const bot = userAgent.isBot(navigator.userAgent);
|
|
13
|
-
const variables = {
|
|
14
|
-
pageHandle: handle,
|
|
15
|
-
userAgent: bot ? 'BOT' : 'BROWSER'
|
|
16
|
-
};
|
|
17
|
-
const headers = {
|
|
18
|
-
'Content-Type': 'application/json',
|
|
19
|
-
'X-GemX-Shop-Token': shopToken
|
|
20
|
-
};
|
|
21
|
-
fetch(apiURL, {
|
|
22
|
-
method: 'POST',
|
|
23
|
-
headers,
|
|
24
|
-
body: JSON.stringify({
|
|
25
|
-
query: core.PageViewUpDocument,
|
|
26
|
-
variables
|
|
27
|
-
})
|
|
28
|
-
}).finally(()=>{
|
|
29
|
-
//
|
|
30
|
-
});
|
|
31
|
-
}, [
|
|
32
|
-
apiURL,
|
|
33
|
-
shopToken
|
|
34
|
-
]);
|
|
35
|
-
react.useEffect(()=>{
|
|
36
|
-
if (!handle || isFallback) return;
|
|
37
|
-
sendTracking(handle);
|
|
38
|
-
}, [
|
|
39
|
-
handle,
|
|
40
|
-
sendTracking,
|
|
41
|
-
isFallback
|
|
42
|
-
]);
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
exports.useTrackingView = useTrackingView;
|
|
1
|
+
"use strict";var core=require("@gem-sdk/core"),react=require("react");const useTrackingView=(e,r,c)=>{let t=e||process.env.NEXT_PUBLIC_SHOP_TOKEN,a=process.env.NEXT_PUBLIC_API_URL,i=react.useCallback(e=>{if(!a||!t)return;let r={pageHandle:e},c={"Content-Type":"application/json","X-GemX-Shop-Token":t};fetch(a,{method:"POST",headers:c,body:JSON.stringify({query:core.PageViewUpDocument,variables:r})}).finally(()=>{})},[a,t]);react.useEffect(()=>{r&&!c&&i(r)},[r,i,c])};exports.useTrackingView=useTrackingView;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";var generateManifres=require("../helpers/generate-manifres.js"),parseJson=require("../helpers/parse-json.js");const usePagePreview=(e,o,r)=>{let s=e?.isMobile??!1,a="fulfilled"===r.status?r.value:void 0,n="fulfilled"===o.status?o.value:void 0,i=n?.storeProperty?.favicon??"/favicon/favicon-32x32.png",t=a?.localization.language.isoCode??null,l=a?.localization.country.isoCode??null,c=a?.shop.moneyFormat??null,p=a?.localization.country.currency.isoCode??null,u=parseJson.parseJson(n?.storeProperty?.swatchesConfig),f=t&&l?`${t}-${l}`:null,m={defaultTitle:a?.shop.name,title:e?.name,openGraph:{site_name:a?.shop.name,locale:a?.localization.country.isoCode,title:e?.name??a?.shop.name},nofollow:!0,noindex:!0,canonical:`/preview/${e?.id}`,additionalMetaTags:[{name:"theme-color",content:"#000000"}],additionalLinkTags:[{rel:"icon",sizes:"32x32",href:`${i}-/crop/1:1/center/-/smart_resize/32x32/`},{rel:"icon",sizes:"16x16",href:`${i}-/crop/1:1/center/-/smart_resize/16x16/`},{rel:"apple-touch-icon",sizes:"180x180",href:`${i}-/crop/1:1/center/-/smart_resize/180x180/`},{rel:"manifest",href:generateManifres.generateManifest({theme_color:"#000000",background_color:"#ffffff",display:"standalone",scope:"/",start_url:"/",name:a?.shop.name,short_name:a?.shop.name,description:a?.shop.description,icons:[{src:`${i}-/crop/1:1/center/-/smart_resize/192x192/`,sizes:"192x192",type:"image/png",purpose:"any maskable"},{src:`${i}-/crop/1:1/center/-/smart_resize/512x512/`,sizes:"512x512",type:"image/png"}]})}]};return{seo:m,pageConfig:{mobileOnly:s,locale:f,languageIsoCode:t,countryIsoCode:l,moneyFormat:c,currency:p,swatches:u}}};exports.usePagePreview=usePagePreview;
|
|
@@ -1,42 +1 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
-
var parse = require('html-react-parser');
|
|
5
|
-
var Script = require('next/script');
|
|
6
|
-
|
|
7
|
-
const parseHtml = (html, isHead)=>{
|
|
8
|
-
if (!html) return undefined;
|
|
9
|
-
try {
|
|
10
|
-
return parse(html, {
|
|
11
|
-
replace: (node)=>{
|
|
12
|
-
if (node.type === 'script' && node instanceof parse.Element) {
|
|
13
|
-
const child = node.children?.[0];
|
|
14
|
-
if (child instanceof parse.Text) {
|
|
15
|
-
if (isHead) return /*#__PURE__*/ jsxRuntime.jsx("script", {
|
|
16
|
-
...node.attribs,
|
|
17
|
-
dangerouslySetInnerHTML: {
|
|
18
|
-
__html: child.data
|
|
19
|
-
}
|
|
20
|
-
});
|
|
21
|
-
else return /*#__PURE__*/ jsxRuntime.jsx(Script, {
|
|
22
|
-
...node.attribs,
|
|
23
|
-
dangerouslySetInnerHTML: {
|
|
24
|
-
__html: child.data
|
|
25
|
-
}
|
|
26
|
-
});
|
|
27
|
-
} else {
|
|
28
|
-
if (!isHead) {
|
|
29
|
-
return /*#__PURE__*/ jsxRuntime.jsx(Script, {
|
|
30
|
-
...node.attribs
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
});
|
|
37
|
-
} catch {
|
|
38
|
-
return undefined;
|
|
39
|
-
}
|
|
40
|
-
};
|
|
41
|
-
|
|
42
|
-
exports.parseHtml = parseHtml;
|
|
1
|
+
"use strict";var jsxRuntime=require("react/jsx-runtime"),parse=require("html-react-parser"),Script=require("next/script");const parseHtml=(t,r)=>{if(t)try{return parse(t,{replace:t=>{if("script"===t.type&&t instanceof parse.Element){let e=t.children?.[0];if(e instanceof parse.Text)return r?jsxRuntime.jsx("script",{...t.attribs,dangerouslySetInnerHTML:{__html:e.data}}):jsxRuntime.jsx(Script,{...t.attribs,dangerouslySetInnerHTML:{__html:e.data}});if(!r)return jsxRuntime.jsx(Script,{...t.attribs})}}})}catch{return}};exports.parseHtml=parseHtml;
|