@gem-sdk/pages 2.0.0-dev.884 → 2.0.0-staging.118
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 +41 -1
- package/dist/cjs/components/ErrorFallback.js +27 -1
- package/dist/cjs/components/FacebookPixel.js +34 -3
- package/dist/cjs/components/FooterForPostPurchase.js +35 -1
- package/dist/cjs/components/GoogleAnalytic.js +66 -5
- package/dist/cjs/components/TikTokPixel.js +20 -3
- package/dist/cjs/components/builder/Body.js +37 -0
- package/dist/cjs/components/builder/Footer.js +155 -0
- package/dist/cjs/components/builder/Header.js +188 -0
- package/dist/cjs/components/builder/PopupManager.js +64 -1
- package/dist/cjs/components/builder/SwitchView.js +185 -0
- package/dist/cjs/components/builder/Toolbar.js +701 -1
- package/dist/cjs/components/builder/Toolbox.js +485 -1
- package/dist/cjs/components/builder/const.js +56 -0
- package/dist/cjs/components/builder/toolbar/const.js +7 -0
- package/dist/cjs/components/builder/toolbar/utils/findDOMClosest.js +41 -0
- package/dist/cjs/components/builder/toolbar/utils/findOverflowParent.js +20 -0
- package/dist/cjs/components/builder/toolbar/utils/getChildrenByAttrSelector.js +18 -0
- package/dist/cjs/components/builder/toolbar/utils/getDOMElementParents.js +32 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverParent.js +16 -0
- package/dist/cjs/components/builder/toolbar/utils/isOverToolbarPosition.js +12 -0
- package/dist/cjs/components/builder/toolbar/utils/isSection.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/notVisible.js +8 -0
- package/dist/cjs/components/builder/toolbar/utils/waitForElementToExist.js +27 -0
- package/dist/cjs/components/image-to-layout/AddSectionImageToLayout.js +151 -1
- package/dist/cjs/components/image-to-layout/DropElement.js +167 -1
- package/dist/cjs/components/image-to-layout/ImageToLayout.js +42 -1
- package/dist/cjs/index.js +80 -1
- package/dist/cjs/layouts/main.js +31 -1
- package/dist/cjs/libs/api/get-builder-props.js +46 -1
- package/dist/cjs/libs/api/get-collection-props.js +68 -1
- package/dist/cjs/libs/api/get-home-page-props-v2.js +145 -1
- package/dist/cjs/libs/api/get-home-page-props.js +151 -1
- package/dist/cjs/libs/api/get-post-purchase-props-preview.js +268 -1
- package/dist/cjs/libs/api/get-preview-props.js +18 -1
- package/dist/cjs/libs/api/get-product-props.js +73 -1
- package/dist/cjs/libs/api/get-static-page-props-preview.js +155 -1
- package/dist/cjs/libs/api/get-static-page-props-v2.js +164 -1
- package/dist/cjs/libs/api/get-static-page-props.js +148 -1
- package/dist/cjs/libs/custom-fonts.js +60 -6
- package/dist/cjs/libs/fetcher.js +100 -1
- package/dist/cjs/libs/get-layout.js +13 -1
- package/dist/cjs/libs/get-storefront-api.js +12 -1
- package/dist/cjs/libs/getStaticPaths.js +10 -1
- package/dist/cjs/libs/google-fonts.js +118 -1
- package/dist/cjs/libs/helpers/check-option-font.js +65 -0
- package/dist/cjs/libs/helpers/common.js +27 -1
- package/dist/cjs/libs/helpers/gen-css.js +135 -1
- package/dist/cjs/libs/helpers/gen-fonts.js +90 -1
- package/dist/cjs/libs/helpers/generate-manifres.js +5 -1
- package/dist/cjs/libs/helpers/get-fallback.js +34 -1
- package/dist/cjs/libs/helpers/normalize.js +111 -1
- package/dist/cjs/libs/helpers/parse-json.js +16 -1
- package/dist/cjs/libs/helpers/user-agent.js +7 -1
- package/dist/cjs/libs/hooks/use-tracking-view.js +43 -1
- package/dist/cjs/libs/hooks/usePagePreview.js +92 -1
- package/dist/cjs/libs/parse-html.js +34 -1
- package/dist/cjs/libs/shopify-cdn-with-google-fonts.js +1845 -1
- package/dist/cjs/pages/404.js +43 -1
- package/dist/cjs/pages/500.js +74 -1
- package/dist/cjs/pages/CollectionGlobalProvider.js +59 -1
- package/dist/cjs/pages/builder.js +115 -1
- package/dist/cjs/pages/collection-detail.js +64 -1
- package/dist/cjs/pages/preview.js +26 -1
- package/dist/cjs/pages/product-detail.js +69 -1
- package/dist/cjs/pages/static-v2.js +139 -1
- package/dist/cjs/pages/static.js +75 -1
- package/dist/cjs/store/libs-store.js +14 -0
- package/dist/esm/components/ErrorBoundary.js +39 -1
- package/dist/esm/components/ErrorFallback.js +25 -1
- package/dist/esm/components/FacebookPixel.js +32 -3
- package/dist/esm/components/FooterForPostPurchase.js +31 -1
- package/dist/esm/components/GoogleAnalytic.js +64 -5
- package/dist/esm/components/TikTokPixel.js +18 -3
- package/dist/esm/components/builder/Body.js +33 -0
- package/dist/esm/components/builder/Footer.js +151 -0
- package/dist/esm/components/builder/Header.js +184 -0
- package/dist/esm/components/builder/PopupManager.js +60 -1
- package/dist/esm/components/builder/SwitchView.js +181 -0
- package/dist/esm/components/builder/Toolbar.js +697 -1
- package/dist/esm/components/builder/Toolbox.js +481 -1
- package/dist/esm/components/builder/const.js +54 -0
- package/dist/esm/components/builder/toolbar/const.js +4 -0
- package/dist/esm/components/builder/toolbar/utils/findDOMClosest.js +39 -0
- package/dist/esm/components/builder/toolbar/utils/findOverflowParent.js +18 -0
- package/dist/esm/components/builder/toolbar/utils/getChildrenByAttrSelector.js +16 -0
- package/dist/esm/components/builder/toolbar/utils/getDOMElementParents.js +30 -0
- package/dist/esm/components/builder/toolbar/utils/isOverParent.js +14 -0
- package/dist/esm/components/builder/toolbar/utils/isOverToolbarPosition.js +10 -0
- package/dist/esm/components/builder/toolbar/utils/isSection.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/notVisible.js +6 -0
- package/dist/esm/components/builder/toolbar/utils/waitForElementToExist.js +25 -0
- package/dist/esm/components/image-to-layout/AddSectionImageToLayout.js +147 -1
- package/dist/esm/components/image-to-layout/DropElement.js +165 -1
- package/dist/esm/components/image-to-layout/ImageToLayout.js +38 -1
- package/dist/esm/index.js +35 -1
- package/dist/esm/layouts/main.js +27 -1
- package/dist/esm/libs/api/get-builder-props.js +44 -1
- package/dist/esm/libs/api/get-collection-props.js +66 -1
- package/dist/esm/libs/api/get-home-page-props-v2.js +143 -1
- package/dist/esm/libs/api/get-home-page-props.js +149 -1
- package/dist/esm/libs/api/get-post-purchase-props-preview.js +260 -1
- package/dist/esm/libs/api/get-preview-props.js +16 -1
- package/dist/esm/libs/api/get-product-props.js +71 -1
- package/dist/esm/libs/api/get-static-page-props-preview.js +153 -1
- package/dist/esm/libs/api/get-static-page-props-v2.js +162 -1
- package/dist/esm/libs/api/get-static-page-props.js +146 -1
- package/dist/esm/libs/custom-fonts.js +55 -6
- package/dist/esm/libs/fetcher.js +96 -1
- package/dist/esm/libs/get-layout.js +11 -1
- package/dist/esm/libs/get-storefront-api.js +10 -1
- package/dist/esm/libs/getStaticPaths.js +8 -1
- package/dist/esm/libs/google-fonts.js +112 -1
- package/dist/esm/libs/helpers/check-option-font.js +63 -0
- package/dist/esm/libs/helpers/common.js +24 -1
- package/dist/esm/libs/helpers/gen-css.js +133 -1
- package/dist/esm/libs/helpers/gen-fonts.js +87 -1
- package/dist/esm/libs/helpers/generate-manifres.js +3 -1
- package/dist/esm/libs/helpers/get-fallback.js +32 -1
- package/dist/esm/libs/helpers/normalize.js +103 -1
- package/dist/esm/libs/helpers/parse-json.js +13 -1
- package/dist/esm/libs/helpers/user-agent.js +5 -1
- package/dist/esm/libs/hooks/use-tracking-view.js +41 -1
- package/dist/esm/libs/hooks/usePagePreview.js +90 -1
- package/dist/esm/libs/parse-html.js +32 -1
- package/dist/esm/libs/shopify-cdn-with-google-fonts.js +1843 -1
- package/dist/esm/pages/404.js +41 -1
- package/dist/esm/pages/500.js +72 -1
- package/dist/esm/pages/CollectionGlobalProvider.js +55 -1
- package/dist/esm/pages/builder.js +113 -1
- package/dist/esm/pages/collection-detail.js +60 -1
- package/dist/esm/pages/preview.js +24 -1
- package/dist/esm/pages/product-detail.js +65 -1
- package/dist/esm/pages/static-v2.js +137 -1
- package/dist/esm/pages/static.js +71 -1
- package/dist/esm/store/libs-store.js +12 -0
- package/dist/types/index.d.ts +50 -34
- package/package.json +8 -5
- package/dist/cjs/components/Footer.js +0 -1
- package/dist/cjs/components/Header.js +0 -1
- package/dist/cjs/components/builder/toolbar/Onboarding.js +0 -1
- package/dist/esm/components/Footer.js +0 -1
- package/dist/esm/components/Header.js +0 -1
- package/dist/esm/components/builder/toolbar/Onboarding.js +0 -1
|
@@ -1 +1,164 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var adapterShopify = require('@gem-sdk/adapter-shopify');
|
|
5
|
+
var googleFonts = require('../google-fonts.js');
|
|
6
|
+
var genCss = require('../helpers/gen-css.js');
|
|
7
|
+
var generateManifres = require('../helpers/generate-manifres.js');
|
|
8
|
+
var getFallback = require('../helpers/get-fallback.js');
|
|
9
|
+
var normalize = require('../helpers/normalize.js');
|
|
10
|
+
var parseJson = require('../helpers/parse-json.js');
|
|
11
|
+
var nextjs = require('@sentry/nextjs');
|
|
12
|
+
var customFonts = require('../custom-fonts.js');
|
|
13
|
+
|
|
14
|
+
const getStaticPagePropsV2 = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
15
|
+
try {
|
|
16
|
+
const pageType = 'STATIC';
|
|
17
|
+
const variables = {
|
|
18
|
+
slug,
|
|
19
|
+
slugType: pageType
|
|
20
|
+
};
|
|
21
|
+
const [theme, storeProperty, shopifyMeta, publishedShopMetas] = await Promise.allSettled([
|
|
22
|
+
fetcher([
|
|
23
|
+
core.PublishedThemePagesDocument,
|
|
24
|
+
variables
|
|
25
|
+
]),
|
|
26
|
+
fetcher([
|
|
27
|
+
core.StorePropertyDocument
|
|
28
|
+
]),
|
|
29
|
+
shopifyFetcher([
|
|
30
|
+
adapterShopify.ShopMetaDocument
|
|
31
|
+
]),
|
|
32
|
+
fetcher([
|
|
33
|
+
core.PublishedShopMetasDocument,
|
|
34
|
+
{
|
|
35
|
+
keys: [
|
|
36
|
+
'source_font'
|
|
37
|
+
]
|
|
38
|
+
}
|
|
39
|
+
])
|
|
40
|
+
]);
|
|
41
|
+
if (theme.status === 'rejected') {
|
|
42
|
+
throw new Error(theme.reason?.[0]);
|
|
43
|
+
}
|
|
44
|
+
const publishedShopMetaValue = publishedShopMetas.status === 'fulfilled' ? publishedShopMetas.value : undefined;
|
|
45
|
+
const sourceFont = publishedShopMetaValue?.publishedShopMetas?.find((item)=>item?.key === 'source_font');
|
|
46
|
+
const dataBuilder = theme.value.publishedThemePages?.[0];
|
|
47
|
+
const themePageCustomFonts = theme.value?.publishedThemePages?.[0]?.themePageCustomFonts;
|
|
48
|
+
if (!dataBuilder) {
|
|
49
|
+
throw new Error(`No data builder found for slug: /${slug}`);
|
|
50
|
+
}
|
|
51
|
+
const pageTemplate = normalize.parseBuilderTemplateV2(dataBuilder);
|
|
52
|
+
const [elementFontStyle, fontStyle, fallback, customFonts$1] = await Promise.all([
|
|
53
|
+
googleFonts.getFontStyleFromPageTemplate(pageTemplate, sourceFont?.value),
|
|
54
|
+
googleFonts.getFontFromGlobalStyle(dataBuilder?.pageStyle?.data, sourceFont?.value),
|
|
55
|
+
getFallback.getFallbackV2(fetcher, pageTemplate),
|
|
56
|
+
customFonts.getCustomFonts(themePageCustomFonts)
|
|
57
|
+
]);
|
|
58
|
+
const mobileOnly = dataBuilder.isMobile ?? false;
|
|
59
|
+
const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
|
|
60
|
+
const thumbnail = parseJson.parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
|
|
61
|
+
const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
|
|
62
|
+
const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
|
|
63
|
+
const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
|
|
64
|
+
const seo = {
|
|
65
|
+
defaultTitle: shopMeta?.shop.name,
|
|
66
|
+
title: dataBuilder?.name,
|
|
67
|
+
description: description ?? shopMeta?.shop.description,
|
|
68
|
+
openGraph: {
|
|
69
|
+
site_name: shopMeta?.shop.name,
|
|
70
|
+
locale: shopMeta?.localization.country.isoCode,
|
|
71
|
+
title: dataBuilder?.name ?? shopMeta?.shop.name,
|
|
72
|
+
description: description ?? shopMeta?.shop.description,
|
|
73
|
+
images: thumbnail ? [
|
|
74
|
+
thumbnail
|
|
75
|
+
] : []
|
|
76
|
+
},
|
|
77
|
+
canonical: `https://${shopData?.storeProperty?.primaryDomain}/${slug}`,
|
|
78
|
+
additionalMetaTags: [
|
|
79
|
+
{
|
|
80
|
+
name: 'theme-color',
|
|
81
|
+
content: '#000000'
|
|
82
|
+
}
|
|
83
|
+
],
|
|
84
|
+
additionalLinkTags: [
|
|
85
|
+
{
|
|
86
|
+
rel: 'icon',
|
|
87
|
+
sizes: '32x32',
|
|
88
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/32x32/`
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
rel: 'icon',
|
|
92
|
+
sizes: '16x16',
|
|
93
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/16x16/`
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
rel: 'apple-touch-icon',
|
|
97
|
+
sizes: '180x180',
|
|
98
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/180x180/`
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
rel: 'manifest',
|
|
102
|
+
href: generateManifres.generateManifest({
|
|
103
|
+
theme_color: '#000000',
|
|
104
|
+
background_color: '#ffffff',
|
|
105
|
+
display: 'standalone',
|
|
106
|
+
scope: '/',
|
|
107
|
+
start_url: '/',
|
|
108
|
+
name: shopMeta?.shop.name,
|
|
109
|
+
short_name: shopMeta?.shop.name,
|
|
110
|
+
description: shopMeta?.shop.description,
|
|
111
|
+
icons: [
|
|
112
|
+
{
|
|
113
|
+
src: `${favicon}-/crop/1:1/center/-/smart_resize/192x192/`,
|
|
114
|
+
sizes: '192x192',
|
|
115
|
+
type: 'image/png',
|
|
116
|
+
purpose: 'any maskable'
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
src: `${favicon}-/crop/1:1/center/-/smart_resize/512x512/`,
|
|
120
|
+
sizes: '512x512',
|
|
121
|
+
type: 'image/png'
|
|
122
|
+
}
|
|
123
|
+
]
|
|
124
|
+
})
|
|
125
|
+
}
|
|
126
|
+
]
|
|
127
|
+
};
|
|
128
|
+
const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
|
|
129
|
+
const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
|
|
130
|
+
const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
|
|
131
|
+
return parseJson.serializableJson({
|
|
132
|
+
themeStyle: genCss.genCSS(dataBuilder?.pageStyle?.data, mobileOnly),
|
|
133
|
+
fontStyle,
|
|
134
|
+
elementFontStyle,
|
|
135
|
+
builderData: pageTemplate,
|
|
136
|
+
pageType,
|
|
137
|
+
moneyFormat: shopMeta?.shop.moneyFormat ?? null,
|
|
138
|
+
currency: shopMeta?.localization.country.currency.isoCode ?? null,
|
|
139
|
+
languageIsoCode,
|
|
140
|
+
countryIsoCode,
|
|
141
|
+
locale,
|
|
142
|
+
swr: {
|
|
143
|
+
fallback
|
|
144
|
+
},
|
|
145
|
+
swatches: parseJson.parseJson(shopData?.storeProperty?.swatchesConfig),
|
|
146
|
+
seo,
|
|
147
|
+
mobileOnly,
|
|
148
|
+
gaTrackingId: dataBuilder.themePageAnalytic?.gaTrackingID ?? null,
|
|
149
|
+
facebookPixelId: dataBuilder.themePageAnalytic?.fbPixelID ?? null,
|
|
150
|
+
tiktokPixelId: dataBuilder.themePageAnalytic?.tiktokPixelID ?? null,
|
|
151
|
+
customCodeHeader: dataBuilder.themePageCustomCode?.header ?? null,
|
|
152
|
+
customCodeBody: dataBuilder.themePageCustomCode?.body ?? null,
|
|
153
|
+
pageHandle: dataBuilder.handle ?? null,
|
|
154
|
+
customFonts: customFonts$1,
|
|
155
|
+
interaction: dataBuilder?.interaction,
|
|
156
|
+
pageBackground: normalize.extractPageBackground(dataBuilder)
|
|
157
|
+
});
|
|
158
|
+
} catch (err) {
|
|
159
|
+
nextjs.captureException(err);
|
|
160
|
+
throw err;
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
exports.getStaticPagePropsV2 = getStaticPagePropsV2;
|
|
@@ -1 +1,148 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var core = require('@gem-sdk/core');
|
|
4
|
+
var adapterShopify = require('@gem-sdk/adapter-shopify');
|
|
5
|
+
var googleFonts = require('../google-fonts.js');
|
|
6
|
+
var genCss = require('../helpers/gen-css.js');
|
|
7
|
+
var generateManifres = require('../helpers/generate-manifres.js');
|
|
8
|
+
var normalize = require('../helpers/normalize.js');
|
|
9
|
+
var parseJson = require('../helpers/parse-json.js');
|
|
10
|
+
|
|
11
|
+
const getStaticPageProps = (fetcher, shopifyFetcher)=>async (slug)=>{
|
|
12
|
+
const pageType = 'STATIC';
|
|
13
|
+
const variables = {
|
|
14
|
+
slug,
|
|
15
|
+
slugType: pageType
|
|
16
|
+
};
|
|
17
|
+
const [theme, storeProperty, shopifyMeta] = await Promise.allSettled([
|
|
18
|
+
fetcher([
|
|
19
|
+
core.PublishedThemePagesDocument,
|
|
20
|
+
variables
|
|
21
|
+
]),
|
|
22
|
+
fetcher([
|
|
23
|
+
core.StorePropertyDocument
|
|
24
|
+
]),
|
|
25
|
+
shopifyFetcher([
|
|
26
|
+
adapterShopify.ShopMetaDocument
|
|
27
|
+
])
|
|
28
|
+
]);
|
|
29
|
+
if (theme.status === 'rejected') {
|
|
30
|
+
return {
|
|
31
|
+
pageType
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
const dataBuilder = theme.value.publishedThemePages?.[0];
|
|
35
|
+
const pageTemplate = normalize.parseBuilderTemplate(dataBuilder);
|
|
36
|
+
const fontStyle = await googleFonts.getFontFromGlobalStyle(dataBuilder?.pageStyle?.data);
|
|
37
|
+
const queries = core.prefetchQueries(pageTemplate);
|
|
38
|
+
const datas = await Promise.allSettled(queries.map(({ query, variables, func })=>{
|
|
39
|
+
if (func) {
|
|
40
|
+
return func(fetcher, variables);
|
|
41
|
+
}
|
|
42
|
+
if (query) return fetcher([
|
|
43
|
+
query,
|
|
44
|
+
variables
|
|
45
|
+
]);
|
|
46
|
+
return {};
|
|
47
|
+
}));
|
|
48
|
+
const fallback = queries.reduce((acc, { key }, index)=>{
|
|
49
|
+
const res = datas[index];
|
|
50
|
+
if (res?.status === 'fulfilled') {
|
|
51
|
+
return {
|
|
52
|
+
...acc,
|
|
53
|
+
[key]: res.value
|
|
54
|
+
};
|
|
55
|
+
}
|
|
56
|
+
return acc;
|
|
57
|
+
}, {});
|
|
58
|
+
const description = dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-description')?.value;
|
|
59
|
+
const thumbnail = parseJson.parseJson(dataBuilder?.themePageDataSEO?.find((item)=>item?.key === 'global-meta-thumbnail')?.value);
|
|
60
|
+
const shopMeta = shopifyMeta.status === 'fulfilled' ? shopifyMeta.value : undefined;
|
|
61
|
+
const shopData = storeProperty.status === 'fulfilled' ? storeProperty.value : undefined;
|
|
62
|
+
const favicon = shopData?.storeProperty?.favicon ?? '/favicon/favicon-32x32.png';
|
|
63
|
+
const seo = {
|
|
64
|
+
defaultTitle: shopMeta?.shop.name ?? '',
|
|
65
|
+
title: dataBuilder?.name ?? '',
|
|
66
|
+
description: description ?? shopMeta?.shop.description ?? '',
|
|
67
|
+
openGraph: {
|
|
68
|
+
site_name: shopMeta?.shop.name ?? '',
|
|
69
|
+
locale: shopMeta?.localization.country.isoCode ?? '',
|
|
70
|
+
title: dataBuilder?.name ?? shopMeta?.shop.name ?? '',
|
|
71
|
+
description: description ?? shopMeta?.shop.description ?? '',
|
|
72
|
+
images: thumbnail ? [
|
|
73
|
+
thumbnail
|
|
74
|
+
] : []
|
|
75
|
+
},
|
|
76
|
+
additionalMetaTags: [
|
|
77
|
+
{
|
|
78
|
+
name: 'theme-color',
|
|
79
|
+
content: '#000000'
|
|
80
|
+
}
|
|
81
|
+
],
|
|
82
|
+
canonical: `/${slug}`,
|
|
83
|
+
additionalLinkTags: [
|
|
84
|
+
{
|
|
85
|
+
rel: 'icon',
|
|
86
|
+
sizes: '32x32',
|
|
87
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/32x32/`
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
rel: 'icon',
|
|
91
|
+
sizes: '16x16',
|
|
92
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/16x16/`
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
rel: 'apple-touch-icon',
|
|
96
|
+
sizes: '180x180',
|
|
97
|
+
href: `${favicon}-/crop/1:1/center/-/smart_resize/180x180/`
|
|
98
|
+
},
|
|
99
|
+
{
|
|
100
|
+
rel: 'manifest',
|
|
101
|
+
href: generateManifres.generateManifest({
|
|
102
|
+
theme_color: '#000000',
|
|
103
|
+
background_color: '#ffffff',
|
|
104
|
+
display: 'standalone',
|
|
105
|
+
scope: '/',
|
|
106
|
+
start_url: '/',
|
|
107
|
+
name: shopMeta?.shop.name,
|
|
108
|
+
short_name: shopMeta?.shop.name,
|
|
109
|
+
description: shopMeta?.shop.description,
|
|
110
|
+
icons: [
|
|
111
|
+
{
|
|
112
|
+
src: `${favicon}-/crop/1:1/center/-/smart_resize/192x192/`,
|
|
113
|
+
sizes: '192x192',
|
|
114
|
+
type: 'image/png',
|
|
115
|
+
purpose: 'any maskable'
|
|
116
|
+
},
|
|
117
|
+
{
|
|
118
|
+
src: `${favicon}-/crop/1:1/center/-/smart_resize/512x512/`,
|
|
119
|
+
sizes: '512x512',
|
|
120
|
+
type: 'image/png'
|
|
121
|
+
}
|
|
122
|
+
]
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
};
|
|
127
|
+
const languageIsoCode = shopMeta?.localization.language.isoCode ?? null;
|
|
128
|
+
const countryIsoCode = shopMeta?.localization.country.isoCode ?? null;
|
|
129
|
+
const locale = !languageIsoCode || !countryIsoCode ? null : `${languageIsoCode}-${countryIsoCode}`;
|
|
130
|
+
return parseJson.serializableJson({
|
|
131
|
+
themeStyle: genCss.genCSS(dataBuilder?.pageStyle?.data),
|
|
132
|
+
fontStyle,
|
|
133
|
+
builderData: pageTemplate,
|
|
134
|
+
pageType,
|
|
135
|
+
moneyFormat: shopMeta?.shop.moneyFormat ?? null,
|
|
136
|
+
currency: shopMeta?.localization.country.currency.isoCode ?? null,
|
|
137
|
+
languageIsoCode,
|
|
138
|
+
countryIsoCode,
|
|
139
|
+
locale,
|
|
140
|
+
swr: {
|
|
141
|
+
fallback
|
|
142
|
+
},
|
|
143
|
+
swatches: parseJson.parseJson(shopData?.storeProperty?.swatchesConfig),
|
|
144
|
+
seo
|
|
145
|
+
});
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
exports.getStaticPageProps = getStaticPageProps;
|
|
@@ -1,8 +1,62 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const composeFontMimeType = (fonts)=>{
|
|
4
|
+
const result = {};
|
|
5
|
+
fonts?.forEach((font)=>{
|
|
6
|
+
if (!font) return;
|
|
7
|
+
const fontKey = `${font.fontFamily}_${font.fontStyle}_${font.fontWeight}`;
|
|
8
|
+
const fontData = {
|
|
9
|
+
font: {
|
|
10
|
+
fontFamily: font.fontFamily,
|
|
11
|
+
fontStyle: font.fontStyle,
|
|
12
|
+
fontWeight: font.fontWeight
|
|
13
|
+
},
|
|
14
|
+
urls: [
|
|
15
|
+
{
|
|
16
|
+
url: font.backupFilePath || font.filePath,
|
|
17
|
+
mimeType: font.mimeType
|
|
18
|
+
}
|
|
19
|
+
]
|
|
20
|
+
};
|
|
21
|
+
if (!result[fontKey]) {
|
|
22
|
+
result[fontKey] = fontData;
|
|
23
|
+
} else {
|
|
24
|
+
result[fontKey]?.urls.push(fontData?.urls?.[0]);
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return result;
|
|
28
|
+
};
|
|
29
|
+
// Currently support only ttf, otf, woff, woff2
|
|
30
|
+
const formatName = (mimeType)=>{
|
|
31
|
+
const fontMimeTypes = {
|
|
32
|
+
'font/ttf': 'truetype',
|
|
33
|
+
'application/x-font-opentype': 'opentype',
|
|
34
|
+
'application/font-woff': 'woff',
|
|
35
|
+
'application/font-woff2': 'woff2'
|
|
36
|
+
};
|
|
37
|
+
return fontMimeTypes[mimeType];
|
|
38
|
+
};
|
|
39
|
+
const composeFontFaces = (fontsMimeType)=>{
|
|
40
|
+
const fontFaces = [];
|
|
41
|
+
for (const [, value] of Object.entries(fontsMimeType)){
|
|
42
|
+
fontFaces.push(`
|
|
2
43
|
@font-face {
|
|
3
|
-
font-family: '${
|
|
4
|
-
src: ${
|
|
5
|
-
font-style: ${
|
|
6
|
-
font-weight: ${
|
|
44
|
+
font-family: '${value.font.fontFamily}';
|
|
45
|
+
src: ${value.urls.map((item)=>`url('${item.url}') format('${formatName(item.mimeType)}')`).join('\n')};
|
|
46
|
+
font-style: ${value?.font?.fontStyle ?? 'normal'};
|
|
47
|
+
font-weight: ${value?.font?.fontWeight ?? 'normal'};
|
|
7
48
|
}
|
|
8
|
-
`);
|
|
49
|
+
`);
|
|
50
|
+
}
|
|
51
|
+
return fontFaces.map((fontFace)=>fontFace).join('\n');
|
|
52
|
+
};
|
|
53
|
+
const getCustomFonts = (fonts)=>{
|
|
54
|
+
if (!fonts) return null;
|
|
55
|
+
const fontsMimeType = composeFontMimeType(fonts);
|
|
56
|
+
return composeFontFaces(fontsMimeType);
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.composeFontFaces = composeFontFaces;
|
|
60
|
+
exports.composeFontMimeType = composeFontMimeType;
|
|
61
|
+
exports.formatName = formatName;
|
|
62
|
+
exports.getCustomFonts = getCustomFonts;
|
package/dist/cjs/libs/fetcher.js
CHANGED
|
@@ -1 +1,100 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var getStorefrontApi = require('./get-storefront-api.js');
|
|
4
|
+
|
|
5
|
+
const createFetcher = (token)=>{
|
|
6
|
+
const shopToken = token || process.env.NEXT_PUBLIC_SHOP_TOKEN;
|
|
7
|
+
return async (args)=>{
|
|
8
|
+
const [query, variables, operationName] = args;
|
|
9
|
+
if (!shopToken) {
|
|
10
|
+
throw new Error('shopToken is not defined');
|
|
11
|
+
}
|
|
12
|
+
if (!process.env.NEXT_PUBLIC_API_URL) {
|
|
13
|
+
throw new Error('NEXT_PUBLIC_API_URL is not defined');
|
|
14
|
+
}
|
|
15
|
+
const headers = {
|
|
16
|
+
'Content-Type': 'application/json',
|
|
17
|
+
'X-GemX-Shop-Token': shopToken
|
|
18
|
+
};
|
|
19
|
+
return fetch(process.env.NEXT_PUBLIC_API_URL, {
|
|
20
|
+
method: 'POST',
|
|
21
|
+
headers,
|
|
22
|
+
body: JSON.stringify({
|
|
23
|
+
query,
|
|
24
|
+
variables,
|
|
25
|
+
operationName
|
|
26
|
+
})
|
|
27
|
+
}).then((res)=>res.json()).then((res)=>{
|
|
28
|
+
if (res.errors) {
|
|
29
|
+
return Promise.reject(res.errors);
|
|
30
|
+
}
|
|
31
|
+
return res.data;
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
const createAppAPIFetcher = (token, shopID)=>{
|
|
36
|
+
const shopToken = token;
|
|
37
|
+
const endPoint = process.env.NEXT_APP_API_URL;
|
|
38
|
+
return async (args)=>{
|
|
39
|
+
const [query, variables, operationName] = args;
|
|
40
|
+
if (!shopToken) {
|
|
41
|
+
throw new Error('shopToken is not defined');
|
|
42
|
+
}
|
|
43
|
+
if (!endPoint) {
|
|
44
|
+
throw new Error('NEXT_APP_API_URL is not defined');
|
|
45
|
+
}
|
|
46
|
+
const headers = {
|
|
47
|
+
'Content-Type': 'application/json',
|
|
48
|
+
Authorization: `Token ${shopToken}`,
|
|
49
|
+
'X-GemX-Shop-ID': shopID || ''
|
|
50
|
+
};
|
|
51
|
+
return fetch(endPoint, {
|
|
52
|
+
method: 'POST',
|
|
53
|
+
headers,
|
|
54
|
+
body: JSON.stringify({
|
|
55
|
+
query,
|
|
56
|
+
variables,
|
|
57
|
+
operationName
|
|
58
|
+
})
|
|
59
|
+
}).then((res)=>res.json()).then((res)=>{
|
|
60
|
+
if (res.errors) {
|
|
61
|
+
return Promise.reject(res.errors);
|
|
62
|
+
}
|
|
63
|
+
return res.data;
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
};
|
|
67
|
+
const createShopifyFetcher = (storefrontToken, handle)=>{
|
|
68
|
+
const token = storefrontToken ?? process.env.NEXT_PUBLIC_STOREFRONT_TOKEN;
|
|
69
|
+
const storefrontHandle = handle ?? process.env.NEXT_PUBLIC_STOREFRONT_HANDLE;
|
|
70
|
+
return async (args)=>{
|
|
71
|
+
if (!token) {
|
|
72
|
+
throw new Error('NEXT_PUBLIC_STOREFRONT_TOKEN is not defined');
|
|
73
|
+
}
|
|
74
|
+
if (!storefrontHandle) {
|
|
75
|
+
throw new Error('NEXT_PUBLIC_STOREFRONT_HANDLE is not defined');
|
|
76
|
+
}
|
|
77
|
+
const headers = {
|
|
78
|
+
'Content-Type': 'application/json',
|
|
79
|
+
'X-Shopify-Storefront-Access-Token': token
|
|
80
|
+
};
|
|
81
|
+
const [query, variables] = args;
|
|
82
|
+
return fetch(getStorefrontApi.getStorefrontApi(storefrontHandle), {
|
|
83
|
+
method: 'POST',
|
|
84
|
+
headers,
|
|
85
|
+
body: JSON.stringify({
|
|
86
|
+
query,
|
|
87
|
+
variables
|
|
88
|
+
})
|
|
89
|
+
}).then((res)=>res.json()).then((res)=>{
|
|
90
|
+
if (res.errors) {
|
|
91
|
+
return Promise.reject(res.errors);
|
|
92
|
+
}
|
|
93
|
+
return res.data;
|
|
94
|
+
});
|
|
95
|
+
};
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
exports.createAppAPIFetcher = createAppAPIFetcher;
|
|
99
|
+
exports.createFetcher = createFetcher;
|
|
100
|
+
exports.createShopifyFetcher = createShopifyFetcher;
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
4
|
+
var main = require('../layouts/main.js');
|
|
5
|
+
|
|
6
|
+
const getLayout = (page, pageProps)=>{
|
|
7
|
+
return /*#__PURE__*/ jsxRuntime.jsx(main.default, {
|
|
8
|
+
...pageProps,
|
|
9
|
+
children: page
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.getLayout = getLayout;
|
|
@@ -1 +1,12 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const getStorefrontApi = (handle, provider)=>{
|
|
4
|
+
switch(provider){
|
|
5
|
+
case 'BIGCOMMERCE':
|
|
6
|
+
return `https://${handle}.bigcommerce.com`;
|
|
7
|
+
default:
|
|
8
|
+
return `https://${handle}.myshopify.com/api/2022-07/graphql.json`;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
exports.getStorefrontApi = getStorefrontApi;
|
|
@@ -1 +1,118 @@
|
|
|
1
|
-
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var checkOptionFont = require('./helpers/check-option-font.js');
|
|
4
|
+
var genFonts = require('./helpers/gen-fonts.js');
|
|
5
|
+
|
|
6
|
+
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';
|
|
7
|
+
const IE_UA = 'Mozilla/5.0 (Windows NT 10.0; Trident/7.0; rv:11.0) like Gecko';
|
|
8
|
+
async function getFontForUA(url, UA) {
|
|
9
|
+
return fetch(url, {
|
|
10
|
+
headers: {
|
|
11
|
+
'User-Agent': UA
|
|
12
|
+
}
|
|
13
|
+
}).then((res)=>{
|
|
14
|
+
if (res.status === 200) {
|
|
15
|
+
return res.text();
|
|
16
|
+
}
|
|
17
|
+
return '';
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
const composeFonts = (fonts)=>{
|
|
21
|
+
const uniqFonts = fonts.filter((font, index, arr)=>{
|
|
22
|
+
return index === arr.findIndex((t)=>t.family === font.family);
|
|
23
|
+
});
|
|
24
|
+
return uniqFonts.map((font)=>{
|
|
25
|
+
const variants = fonts.filter((t)=>t.family === font.family).reduce((acc, t)=>{
|
|
26
|
+
return [
|
|
27
|
+
...acc,
|
|
28
|
+
...t.variants
|
|
29
|
+
];
|
|
30
|
+
}, []).filter((t, index, arr)=>{
|
|
31
|
+
return index === arr.findIndex((v)=>v === t);
|
|
32
|
+
});
|
|
33
|
+
return {
|
|
34
|
+
...font,
|
|
35
|
+
variants
|
|
36
|
+
};
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
const createFontUrl = (fonts, option, fontType)=>{
|
|
40
|
+
const mainFonts = fonts.filter((font)=>{
|
|
41
|
+
return !([
|
|
42
|
+
'bunny',
|
|
43
|
+
'google'
|
|
44
|
+
].includes(font.type) && checkOptionFont.checkNotInOptionFont(font.family, fontType || 'google')) && (font.type === 'google' || font.type === 'bunny' || !font.type);
|
|
45
|
+
});
|
|
46
|
+
if (!mainFonts.length) return;
|
|
47
|
+
const params = new URLSearchParams();
|
|
48
|
+
const display = option?.display || 'swap';
|
|
49
|
+
const uniqFonts = mainFonts.filter((font, index, arr)=>{
|
|
50
|
+
return index === arr.findIndex((t)=>t.family === font.family);
|
|
51
|
+
});
|
|
52
|
+
const family = composeFonts(uniqFonts).map((font)=>{
|
|
53
|
+
return `${font.family.replace(/ /g, '+')}:${font.variants.join(',')}`;
|
|
54
|
+
}).join('|');
|
|
55
|
+
params.append('family', family);
|
|
56
|
+
params.append('display', display);
|
|
57
|
+
if (option?.subset) {
|
|
58
|
+
params.append('subset', option.subset);
|
|
59
|
+
}
|
|
60
|
+
if (option?.effect) {
|
|
61
|
+
params.append('effect', option.effect);
|
|
62
|
+
}
|
|
63
|
+
const bunnyFontUrl = `https://fonts.bunny.net/css?family=${family}`;
|
|
64
|
+
const googleFontUrl = `https://fonts.googleapis.com/css?${decodeURIComponent(params.toString())}`;
|
|
65
|
+
return fontType === 'bunny' ? bunnyFontUrl : googleFontUrl;
|
|
66
|
+
};
|
|
67
|
+
// eslint-disable-next-line max-params
|
|
68
|
+
async function getFonts(fonts, option, isImportFontByUrl = true, fontType) {
|
|
69
|
+
/**
|
|
70
|
+
* The order of IE -> Chrome is important, other wise chrome starts loading woff1.
|
|
71
|
+
* CSS cascading 🤷♂️.
|
|
72
|
+
*/ const url = createFontUrl(fonts, option, fontType);
|
|
73
|
+
if (!url) return '';
|
|
74
|
+
try {
|
|
75
|
+
if (isImportFontByUrl) return `@import url('${url}');`;
|
|
76
|
+
const [ie, chrome] = await Promise.all([
|
|
77
|
+
getFontForUA(url, IE_UA),
|
|
78
|
+
getFontForUA(url, CHROME_UA)
|
|
79
|
+
]);
|
|
80
|
+
const maxSize = 50; // 50KB
|
|
81
|
+
const value = ie + chrome;
|
|
82
|
+
if (maxSize) {
|
|
83
|
+
const textEncoder = new TextEncoder();
|
|
84
|
+
const size = value ? textEncoder.encode(value).length : 0;
|
|
85
|
+
if (Math.ceil(size / 1024) >= maxSize) {
|
|
86
|
+
return `@import url('${url}');`;
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
return value;
|
|
90
|
+
} catch (e) {
|
|
91
|
+
return '';
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
const getFontFromGlobalStyle = (data, sourceFont)=>{
|
|
95
|
+
if (!data) return '';
|
|
96
|
+
try {
|
|
97
|
+
const globalStyle = JSON.parse(data);
|
|
98
|
+
const fontData = globalStyle?.font ?? {};
|
|
99
|
+
const fonts = Object.entries(fontData).map(([, value])=>{
|
|
100
|
+
return value;
|
|
101
|
+
});
|
|
102
|
+
return getFonts(fonts, undefined, undefined, sourceFont);
|
|
103
|
+
} catch {
|
|
104
|
+
return '';
|
|
105
|
+
}
|
|
106
|
+
};
|
|
107
|
+
async function getFontStyleFromPageTemplate(pageTemplate, sourceFont) {
|
|
108
|
+
const fontStyle = pageTemplate.map((sectionData)=>{
|
|
109
|
+
return getFonts(genFonts.getFontsFromDataBuilder(sectionData.data), undefined, undefined, sourceFont);
|
|
110
|
+
});
|
|
111
|
+
return await Promise.all(fontStyle);
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
exports.composeFonts = composeFonts;
|
|
115
|
+
exports.createFontUrl = createFontUrl;
|
|
116
|
+
exports.getFontFromGlobalStyle = getFontFromGlobalStyle;
|
|
117
|
+
exports.getFontStyleFromPageTemplate = getFontStyleFromPageTemplate;
|
|
118
|
+
exports.getFonts = getFonts;
|