@gem-sdk/core 1.0.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.
- package/dist/cjs/components/AddOn.js +18 -0
- package/dist/cjs/components/ComponentWrapper.js +45 -0
- package/dist/cjs/components/ComponentWrapperPreview.js +58 -0
- package/dist/cjs/components/Empty.js +7 -0
- package/dist/cjs/components/Render.js +28 -0
- package/dist/cjs/components/RenderBlock.js +21 -0
- package/dist/cjs/components/RenderPreview.js +28 -0
- package/dist/cjs/components/RenderSection.js +19 -0
- package/dist/cjs/contexts/AddonContext.js +25 -0
- package/dist/cjs/contexts/BuilderComponent.js +30 -0
- package/dist/cjs/contexts/BuilderContext.js +29 -0
- package/dist/cjs/contexts/BuilderPreviewContext.js +353 -0
- package/dist/cjs/contexts/CartLineContext.js +24 -0
- package/dist/cjs/contexts/CollectionContext.js +24 -0
- package/dist/cjs/contexts/ProductContext.js +126 -0
- package/dist/cjs/contexts/ProductListContext.js +24 -0
- package/dist/cjs/contexts/SectionContext.js +49 -0
- package/dist/cjs/contexts/ShopContext.js +43 -0
- package/dist/cjs/graphql/fragments/analytic.generated.js +11 -0
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +13 -0
- package/dist/cjs/graphql/fragments/collection-product.generated.js +26 -0
- package/dist/cjs/graphql/fragments/data-seo.generated.js +11 -0
- package/dist/cjs/graphql/fragments/media.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product-little.generated.js +25 -0
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +13 -0
- package/dist/cjs/graphql/fragments/product-option.generated.js +14 -0
- package/dist/cjs/graphql/fragments/product.generated.js +33 -0
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +12 -0
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +11 -0
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +27 -0
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +11 -0
- package/dist/cjs/graphql/fragments/selected-option.generated.js +11 -0
- package/dist/cjs/graphql/fragments/variant.generated.js +35 -0
- package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +34 -0
- package/dist/cjs/graphql/queries/collection.generated.js +52 -0
- package/dist/cjs/graphql/queries/preview-page.generated.js +23 -0
- package/dist/cjs/graphql/queries/product-little-detail.generated.js +24 -0
- package/dist/cjs/graphql/queries/product-medias.generated.js +29 -0
- package/dist/cjs/graphql/queries/product-variants.generated.js +33 -0
- package/dist/cjs/graphql/queries/products.generated.js +41 -0
- package/dist/cjs/graphql/queries/published-theme-pages.generated.js +23 -0
- package/dist/cjs/graphql/queries/storeProperty.generated.js +12 -0
- package/dist/cjs/helpers/GlobalEvent.js +17 -0
- package/dist/cjs/helpers/background.js +104 -0
- package/dist/cjs/helpers/borders.js +138 -0
- package/dist/cjs/helpers/clone-deep.js +5 -0
- package/dist/cjs/helpers/cls.js +20 -0
- package/dist/cjs/helpers/colors.js +157 -0
- package/dist/cjs/helpers/compose-advance-style.js +132 -0
- package/dist/cjs/helpers/constant.js +17 -0
- package/dist/cjs/helpers/css-variable.js +7 -0
- package/dist/cjs/helpers/email.js +11 -0
- package/dist/cjs/helpers/flatten-connection.js +10 -0
- package/dist/cjs/helpers/fpixel.js +29 -0
- package/dist/cjs/helpers/get-resonsive-value.js +32 -0
- package/dist/cjs/helpers/get-shortname.js +92 -0
- package/dist/cjs/helpers/gtag.js +48 -0
- package/dist/cjs/helpers/is-browser.js +9 -0
- package/dist/cjs/helpers/is-defined.js +7 -0
- package/dist/cjs/helpers/is-empty-children.js +12 -0
- package/dist/cjs/helpers/layout.js +17 -0
- package/dist/cjs/helpers/load-script.js +32 -0
- package/dist/cjs/helpers/make-style.js +99 -0
- package/dist/cjs/helpers/normalize-builder-data.js +17 -0
- package/dist/cjs/helpers/prefetch-queries.js +68 -0
- package/dist/cjs/helpers/product.js +35 -0
- package/dist/cjs/helpers/queries/get-collection.js +173 -0
- package/dist/cjs/helpers/queries/get-product-by-slug.js +99 -0
- package/dist/cjs/helpers/queries/get-product.js +113 -0
- package/dist/cjs/helpers/queries/get-products.js +135 -0
- package/dist/cjs/helpers/radius.js +91 -0
- package/dist/cjs/helpers/shadow.js +48 -0
- package/dist/cjs/helpers/size.js +20 -0
- package/dist/cjs/helpers/spacing.js +45 -0
- package/dist/cjs/helpers/tiktokpixel.js +17 -0
- package/dist/cjs/helpers/typography.js +7 -0
- package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-data.js +26 -0
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -0
- package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -0
- package/dist/cjs/hooks/cart/use-create-cart.js +22 -0
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -0
- package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -0
- package/dist/cjs/hooks/shop/use-collection-query.js +16 -0
- package/dist/cjs/hooks/shop/use-product-query.js +16 -0
- package/dist/cjs/hooks/shop/use-products-query.js +16 -0
- package/dist/cjs/hooks/shop.js +80 -0
- package/dist/cjs/hooks/use-current-device.js +23 -0
- package/dist/cjs/hooks/use-lazy-video.js +15 -0
- package/dist/cjs/hooks/useCartId.js +36 -0
- package/dist/cjs/hooks/useCartLine.js +11 -0
- package/dist/cjs/hooks/useCartUI.js +42 -0
- package/dist/cjs/hooks/useCollection.js +9 -0
- package/dist/cjs/hooks/useFetchHandle.js +13 -0
- package/dist/cjs/hooks/useFormatMoney.js +17 -0
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -0
- package/dist/cjs/hooks/useLoadScript.js +30 -0
- package/dist/cjs/hooks/useMoney.js +52 -0
- package/dist/cjs/hooks/usePrevious.js +17 -0
- package/dist/cjs/hooks/useProduct.js +90 -0
- package/dist/cjs/hooks/useProductList.js +21 -0
- package/dist/cjs/hooks/useSuspenseFetch.js +24 -0
- package/dist/cjs/hooks/useSwatchesOptions.js +39 -0
- package/dist/cjs/index.js +229 -0
- package/dist/cjs/types/global-style.js +7 -0
- package/dist/cjs/types/shop.js +2 -0
- package/dist/esm/components/AddOn.js +14 -0
- package/dist/esm/components/ComponentWrapper.js +40 -0
- package/dist/esm/components/ComponentWrapperPreview.js +54 -0
- package/dist/esm/components/Empty.js +3 -0
- package/dist/esm/components/Render.js +24 -0
- package/dist/esm/components/RenderBlock.js +17 -0
- package/dist/esm/components/RenderPreview.js +24 -0
- package/dist/esm/components/RenderSection.js +15 -0
- package/dist/esm/contexts/AddonContext.js +21 -0
- package/dist/esm/contexts/BuilderComponent.js +27 -0
- package/dist/esm/contexts/BuilderContext.js +26 -0
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -0
- package/dist/esm/contexts/CartLineContext.js +21 -0
- package/dist/esm/contexts/CollectionContext.js +20 -0
- package/dist/esm/contexts/ProductContext.js +123 -0
- package/dist/esm/contexts/ProductListContext.js +20 -0
- package/dist/esm/contexts/SectionContext.js +45 -0
- package/dist/esm/contexts/ShopContext.js +40 -0
- package/dist/esm/graphql/fragments/analytic.generated.js +9 -0
- package/dist/esm/graphql/fragments/collection-detail.generated.js +11 -0
- package/dist/esm/graphql/fragments/collection-product.generated.js +24 -0
- package/dist/esm/graphql/fragments/data-seo.generated.js +9 -0
- package/dist/esm/graphql/fragments/media.generated.js +12 -0
- package/dist/esm/graphql/fragments/product-little.generated.js +23 -0
- package/dist/esm/graphql/fragments/product-option-value.generated.js +11 -0
- package/dist/esm/graphql/fragments/product-option.generated.js +12 -0
- package/dist/esm/graphql/fragments/product.generated.js +31 -0
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +10 -0
- package/dist/esm/graphql/fragments/published-page-section.generated.js +9 -0
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +25 -0
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +9 -0
- package/dist/esm/graphql/fragments/selected-option.generated.js +9 -0
- package/dist/esm/graphql/fragments/variant.generated.js +33 -0
- package/dist/esm/graphql/queries/collection-detail-filter.generated.js +32 -0
- package/dist/esm/graphql/queries/collection.generated.js +50 -0
- package/dist/esm/graphql/queries/preview-page.generated.js +21 -0
- package/dist/esm/graphql/queries/product-little-detail.generated.js +22 -0
- package/dist/esm/graphql/queries/product-medias.generated.js +27 -0
- package/dist/esm/graphql/queries/product-variants.generated.js +31 -0
- package/dist/esm/graphql/queries/products.generated.js +38 -0
- package/dist/esm/graphql/queries/published-theme-pages.generated.js +21 -0
- package/dist/esm/graphql/queries/storeProperty.generated.js +10 -0
- package/dist/esm/helpers/GlobalEvent.js +13 -0
- package/dist/esm/helpers/background.js +102 -0
- package/dist/esm/helpers/borders.js +133 -0
- package/dist/esm/helpers/clone-deep.js +3 -0
- package/dist/esm/helpers/cls.js +18 -0
- package/dist/esm/helpers/colors.js +145 -0
- package/dist/esm/helpers/compose-advance-style.js +130 -0
- package/dist/esm/helpers/constant.js +13 -0
- package/dist/esm/helpers/css-variable.js +5 -0
- package/dist/esm/helpers/email.js +6 -0
- package/dist/esm/helpers/flatten-connection.js +8 -0
- package/dist/esm/helpers/fpixel.js +25 -0
- package/dist/esm/helpers/get-resonsive-value.js +28 -0
- package/dist/esm/helpers/get-shortname.js +90 -0
- package/dist/esm/helpers/gtag.js +45 -0
- package/dist/esm/helpers/is-browser.js +5 -0
- package/dist/esm/helpers/is-defined.js +5 -0
- package/dist/esm/helpers/is-empty-children.js +7 -0
- package/dist/esm/helpers/layout.js +15 -0
- package/dist/esm/helpers/load-script.js +30 -0
- package/dist/esm/helpers/make-style.js +91 -0
- package/dist/esm/helpers/normalize-builder-data.js +15 -0
- package/dist/esm/helpers/prefetch-queries.js +66 -0
- package/dist/esm/helpers/product.js +32 -0
- package/dist/esm/helpers/queries/get-collection.js +170 -0
- package/dist/esm/helpers/queries/get-product-by-slug.js +97 -0
- package/dist/esm/helpers/queries/get-product.js +109 -0
- package/dist/esm/helpers/queries/get-products.js +133 -0
- package/dist/esm/helpers/radius.js +86 -0
- package/dist/esm/helpers/shadow.js +45 -0
- package/dist/esm/helpers/size.js +18 -0
- package/dist/esm/helpers/spacing.js +42 -0
- package/dist/esm/helpers/tiktokpixel.js +15 -0
- package/dist/esm/helpers/typography.js +5 -0
- package/dist/esm/hooks/cart/use-add-to-cart.js +18 -0
- package/dist/esm/hooks/cart/use-cart-data.js +24 -0
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -0
- package/dist/esm/hooks/cart/use-cart-note-update.js +18 -0
- package/dist/esm/hooks/cart/use-create-cart.js +20 -0
- package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -0
- package/dist/esm/hooks/cart/use-update-cart-item.js +18 -0
- package/dist/esm/hooks/shop/use-collection-query.js +14 -0
- package/dist/esm/hooks/shop/use-product-query.js +14 -0
- package/dist/esm/hooks/shop/use-products-query.js +14 -0
- package/dist/esm/hooks/shop.js +68 -0
- package/dist/esm/hooks/use-current-device.js +21 -0
- package/dist/esm/hooks/use-lazy-video.js +13 -0
- package/dist/esm/hooks/useCartId.js +32 -0
- package/dist/esm/hooks/useCartLine.js +7 -0
- package/dist/esm/hooks/useCartUI.js +38 -0
- package/dist/esm/hooks/useCollection.js +7 -0
- package/dist/esm/hooks/useFetchHandle.js +11 -0
- package/dist/esm/hooks/useFormatMoney.js +13 -0
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -0
- package/dist/esm/hooks/useLoadScript.js +26 -0
- package/dist/esm/hooks/useMoney.js +48 -0
- package/dist/esm/hooks/usePrevious.js +15 -0
- package/dist/esm/hooks/useProduct.js +78 -0
- package/dist/esm/hooks/useProductList.js +16 -0
- package/dist/esm/hooks/useSuspenseFetch.js +20 -0
- package/dist/esm/hooks/useSwatchesOptions.js +35 -0
- package/dist/esm/index.js +82 -0
- package/dist/esm/types/global-style.js +4 -0
- package/dist/esm/types/shop.js +1 -0
- package/dist/types/index.d.ts +7393 -0
- package/package.json +50 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
function getSelectedVariant(variants, choices) {
|
|
4
|
+
/**
|
|
5
|
+
* Ensure the user has selected all the required options, not just some.
|
|
6
|
+
*/
|
|
7
|
+
if (!variants ||
|
|
8
|
+
!variants.length ||
|
|
9
|
+
!choices ||
|
|
10
|
+
variants[0]?.selectedOptions.length !== Object.keys(choices).length) {
|
|
11
|
+
return;
|
|
12
|
+
}
|
|
13
|
+
return variants.find((variant) => {
|
|
14
|
+
return Object.entries(choices).every(([name, value]) => {
|
|
15
|
+
return variant?.selectedOptions.some((option) => option.name === name && option.value === value);
|
|
16
|
+
});
|
|
17
|
+
});
|
|
18
|
+
}
|
|
19
|
+
function parseSelectedOption(options) {
|
|
20
|
+
if (!options || (options && options.length === 0)) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
return options.reduce((acc, { name, value }) => {
|
|
24
|
+
if (name && value) {
|
|
25
|
+
return {
|
|
26
|
+
...acc,
|
|
27
|
+
[name]: value,
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
return acc;
|
|
31
|
+
}, {});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
exports.getSelectedVariant = getSelectedVariant;
|
|
35
|
+
exports.parseSelectedOption = parseSelectedOption;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var collectionDetailFilter_generated = require('../../graphql/queries/collection-detail-filter.generated.js');
|
|
4
|
+
var productVariants_generated = require('../../graphql/queries/product-variants.generated.js');
|
|
5
|
+
var isDefined = require('../is-defined.js');
|
|
6
|
+
|
|
7
|
+
function productSortedByOrder(key) {
|
|
8
|
+
switch (key) {
|
|
9
|
+
case 'TITLE_ASC':
|
|
10
|
+
return { direction: 'ASC', field: 'TITLE' };
|
|
11
|
+
case 'TITLE_DESC':
|
|
12
|
+
return { direction: 'DESC', field: 'TITLE' };
|
|
13
|
+
case 'CREATED_AT_ASC':
|
|
14
|
+
return { direction: 'ASC', field: 'CREATED_AT' };
|
|
15
|
+
case 'CREATED_AT_DESC':
|
|
16
|
+
return { direction: 'DESC', field: 'CREATED_AT' };
|
|
17
|
+
case 'none':
|
|
18
|
+
return undefined;
|
|
19
|
+
default:
|
|
20
|
+
return undefined;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
const getCollection = async (fetcher, arg) => {
|
|
24
|
+
const collections = await loopFetchCollection(fetcher, arg);
|
|
25
|
+
if (!collections) {
|
|
26
|
+
throw new Error('collections not found');
|
|
27
|
+
}
|
|
28
|
+
// merge product collection variant
|
|
29
|
+
const mergeProducts = await mergeProductCollectionVariant(fetcher, collections, arg.isSample);
|
|
30
|
+
return mergeProducts;
|
|
31
|
+
};
|
|
32
|
+
const fetchCollection = async (fetcher, variables) => {
|
|
33
|
+
return fetcher([
|
|
34
|
+
collectionDetailFilter_generated.CollectionDetailFilterDocument,
|
|
35
|
+
variables,
|
|
36
|
+
]);
|
|
37
|
+
};
|
|
38
|
+
const calculateFirstProduct = (numberOfProducts, currentPage, productsPerPage) => {
|
|
39
|
+
const remainingProducts = numberOfProducts - productsPerPage * currentPage;
|
|
40
|
+
if (numberOfProducts < productsPerPage)
|
|
41
|
+
return numberOfProducts;
|
|
42
|
+
return remainingProducts > 0 ? productsPerPage : productsPerPage + remainingProducts;
|
|
43
|
+
};
|
|
44
|
+
const loopFetchCollection = async (fetcher, arg) => {
|
|
45
|
+
const productsPerPage = 8; // number of products per page
|
|
46
|
+
let variables; // variables of collection query
|
|
47
|
+
let productAfterFetcher; // product after of collection query
|
|
48
|
+
let dataCollection; // data of collection query
|
|
49
|
+
let hasNextPage; //
|
|
50
|
+
let firstCollection;
|
|
51
|
+
let currentPage = 1;
|
|
52
|
+
if (arg.numberOfProducts) {
|
|
53
|
+
const pages = Math.ceil(arg.numberOfProducts / productsPerPage);
|
|
54
|
+
while (currentPage <= pages && hasNextPage !== false) {
|
|
55
|
+
variables = {
|
|
56
|
+
firstVariant: 1,
|
|
57
|
+
firstMedia: 30,
|
|
58
|
+
orderBy: {
|
|
59
|
+
field: 'UPDATED_AT',
|
|
60
|
+
direction: 'DESC',
|
|
61
|
+
},
|
|
62
|
+
firstProduct: calculateFirstProduct(arg.numberOfProducts, currentPage, productsPerPage),
|
|
63
|
+
...(!arg.id || arg.id.toLowerCase() === 'latest'
|
|
64
|
+
? { where: { hasCollectionProducts: true } }
|
|
65
|
+
: { where: { baseID: arg.id } }),
|
|
66
|
+
orderByProduct: productSortedByOrder(arg.orderBy),
|
|
67
|
+
whereProduct: {
|
|
68
|
+
isStorefront: true,
|
|
69
|
+
isSample: arg.isSample,
|
|
70
|
+
},
|
|
71
|
+
productsAfter: productAfterFetcher,
|
|
72
|
+
};
|
|
73
|
+
const pageData = await fetchCollection(fetcher, variables);
|
|
74
|
+
productAfterFetcher = pageData?.collections?.edges?.[0]?.node?.products?.pageInfo?.endCursor;
|
|
75
|
+
if (currentPage === 1) {
|
|
76
|
+
dataCollection = pageData; // set data of first page
|
|
77
|
+
firstCollection = dataCollection?.collections?.edges?.[0];
|
|
78
|
+
}
|
|
79
|
+
else if (firstCollection?.node?.products &&
|
|
80
|
+
pageData?.collections?.edges?.[0]?.node?.products?.edges) {
|
|
81
|
+
// concat new values to the old ones
|
|
82
|
+
firstCollection.node.products = {
|
|
83
|
+
pageInfo: pageData?.collections?.edges?.[0]?.node?.products?.pageInfo,
|
|
84
|
+
edges: firstCollection.node?.products?.edges.concat(pageData?.collections?.edges?.[0]?.node?.products?.edges),
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
currentPage++;
|
|
88
|
+
// hasNextPage = false if there is no more pages then break the loop
|
|
89
|
+
if (!firstCollection?.node?.products?.pageInfo?.hasNextPage) {
|
|
90
|
+
hasNextPage = false;
|
|
91
|
+
break;
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
return dataCollection;
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
const mergeProductCollectionVariant = async (fetcher, collection, isSample) => {
|
|
98
|
+
const node = collection?.collections?.edges?.[0]?.node;
|
|
99
|
+
if (!node)
|
|
100
|
+
return collection;
|
|
101
|
+
const productList = node?.products?.edges;
|
|
102
|
+
const listBaseId = productList?.map((product) => product?.node?.baseID).filter(isDefined.isDefined);
|
|
103
|
+
const ProductListWithVariants = await fetchVariantsByBaseIds(fetcher, {
|
|
104
|
+
ids: listBaseId,
|
|
105
|
+
isSample,
|
|
106
|
+
});
|
|
107
|
+
// mapping variant to product list in collections
|
|
108
|
+
const newProductList = productList?.map((product) => {
|
|
109
|
+
const productVariants = ProductListWithVariants?.variants?.edges?.filter((productV) => productV?.node?.id === product?.node?.id);
|
|
110
|
+
return {
|
|
111
|
+
...product,
|
|
112
|
+
node: product.node
|
|
113
|
+
? {
|
|
114
|
+
...product.node,
|
|
115
|
+
variants: product.node?.variants
|
|
116
|
+
? {
|
|
117
|
+
...product.node?.variants,
|
|
118
|
+
edges: productVariants?.[0]?.node?.variants?.edges ?? [],
|
|
119
|
+
}
|
|
120
|
+
: undefined,
|
|
121
|
+
}
|
|
122
|
+
: undefined,
|
|
123
|
+
};
|
|
124
|
+
}) ?? [];
|
|
125
|
+
const newCollection = {
|
|
126
|
+
...collection,
|
|
127
|
+
collections: {
|
|
128
|
+
edges: [
|
|
129
|
+
{
|
|
130
|
+
node: {
|
|
131
|
+
...node,
|
|
132
|
+
products: {
|
|
133
|
+
edges: newProductList,
|
|
134
|
+
},
|
|
135
|
+
},
|
|
136
|
+
cursor: undefined,
|
|
137
|
+
},
|
|
138
|
+
],
|
|
139
|
+
},
|
|
140
|
+
};
|
|
141
|
+
return newCollection;
|
|
142
|
+
};
|
|
143
|
+
const fetchVariantsByBaseIds = async (fetcher, { ids, isSample }) => {
|
|
144
|
+
const initVariables = {
|
|
145
|
+
firstVariant: 100,
|
|
146
|
+
first: ids?.length || 1,
|
|
147
|
+
orderBy: {
|
|
148
|
+
field: 'UPDATED_AT',
|
|
149
|
+
direction: 'DESC',
|
|
150
|
+
},
|
|
151
|
+
where: {
|
|
152
|
+
isStorefront: true,
|
|
153
|
+
isSample,
|
|
154
|
+
...(ids?.length && { baseIDIn: ids.sort() }),
|
|
155
|
+
},
|
|
156
|
+
};
|
|
157
|
+
const query = async (variables) => {
|
|
158
|
+
try {
|
|
159
|
+
const response = await fetcher([
|
|
160
|
+
productVariants_generated.ProductVariantsDocument,
|
|
161
|
+
variables,
|
|
162
|
+
]);
|
|
163
|
+
return response;
|
|
164
|
+
}
|
|
165
|
+
catch {
|
|
166
|
+
return {};
|
|
167
|
+
}
|
|
168
|
+
};
|
|
169
|
+
return query(initVariables);
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
exports.calculateFirstProduct = calculateFirstProduct;
|
|
173
|
+
exports.getCollection = getCollection;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var productLittleDetail_generated = require('../../graphql/queries/product-little-detail.generated.js');
|
|
4
|
+
var productMedias_generated = require('../../graphql/queries/product-medias.generated.js');
|
|
5
|
+
var productVariants_generated = require('../../graphql/queries/product-variants.generated.js');
|
|
6
|
+
|
|
7
|
+
const getProductBySlug = async (fetcher, slug) => {
|
|
8
|
+
const [product, variants, medias] = await Promise.all([
|
|
9
|
+
fetchProduct(fetcher, slug),
|
|
10
|
+
fetchVariants(fetcher, slug),
|
|
11
|
+
fetchMedias(fetcher, slug),
|
|
12
|
+
]);
|
|
13
|
+
if (!product) {
|
|
14
|
+
throw new Error('Product not found');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...product,
|
|
18
|
+
variants: {
|
|
19
|
+
edges: variants,
|
|
20
|
+
},
|
|
21
|
+
medias: {
|
|
22
|
+
edges: medias,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const orderBy = {
|
|
27
|
+
field: 'UPDATED_AT',
|
|
28
|
+
direction: 'DESC',
|
|
29
|
+
};
|
|
30
|
+
const fetchProduct = async (fetcher, handle) => {
|
|
31
|
+
const variables = {
|
|
32
|
+
orderBy,
|
|
33
|
+
where: { handle, isStorefront: true },
|
|
34
|
+
};
|
|
35
|
+
const response = await fetcher([productLittleDetail_generated.ProductLittleDetailDocument, variables]);
|
|
36
|
+
return response.product?.edges?.[0]?.node;
|
|
37
|
+
};
|
|
38
|
+
const fetchVariants = async (fetcher, handle) => {
|
|
39
|
+
const initVariables = {
|
|
40
|
+
orderBy,
|
|
41
|
+
where: { handle, isStorefront: true },
|
|
42
|
+
};
|
|
43
|
+
const query = async (variables, olds) => {
|
|
44
|
+
try {
|
|
45
|
+
const response = await fetcher([
|
|
46
|
+
productVariants_generated.ProductVariantsDocument,
|
|
47
|
+
variables,
|
|
48
|
+
]);
|
|
49
|
+
const product = response.variants?.edges?.[0];
|
|
50
|
+
const items = olds?.concat(product?.node?.variants?.edges ?? []);
|
|
51
|
+
if (product?.node?.variants?.pageInfo?.hasNextPage) {
|
|
52
|
+
return query({
|
|
53
|
+
...variables,
|
|
54
|
+
afterVariant: product?.node?.variants?.pageInfo.endCursor,
|
|
55
|
+
}, items);
|
|
56
|
+
}
|
|
57
|
+
return items ?? [];
|
|
58
|
+
}
|
|
59
|
+
catch {
|
|
60
|
+
return olds ?? [];
|
|
61
|
+
}
|
|
62
|
+
};
|
|
63
|
+
return query(initVariables, []);
|
|
64
|
+
};
|
|
65
|
+
const fetchMedias = async (fetcher, handle) => {
|
|
66
|
+
const initVariables = {
|
|
67
|
+
orderBy,
|
|
68
|
+
where: { handle, isStorefront: true },
|
|
69
|
+
};
|
|
70
|
+
const query = async (variables) => {
|
|
71
|
+
try {
|
|
72
|
+
const response = await fetcher([
|
|
73
|
+
productMedias_generated.ProductMediasDocument,
|
|
74
|
+
variables,
|
|
75
|
+
]);
|
|
76
|
+
const product = response.medias?.edges?.[0];
|
|
77
|
+
const items = product?.node?.medias?.edges ?? [];
|
|
78
|
+
if (product?.node?.medias?.pageInfo?.hasNextPage) {
|
|
79
|
+
try {
|
|
80
|
+
const newData = await query({
|
|
81
|
+
...variables,
|
|
82
|
+
afterMedia: product?.node?.medias?.pageInfo.endCursor,
|
|
83
|
+
});
|
|
84
|
+
return items.concat(newData);
|
|
85
|
+
}
|
|
86
|
+
catch {
|
|
87
|
+
return items;
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
return items;
|
|
91
|
+
}
|
|
92
|
+
catch {
|
|
93
|
+
return [];
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
return query(initVariables);
|
|
97
|
+
};
|
|
98
|
+
|
|
99
|
+
exports.getProductBySlug = getProductBySlug;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var productLittleDetail_generated = require('../../graphql/queries/product-little-detail.generated.js');
|
|
4
|
+
var productMedias_generated = require('../../graphql/queries/product-medias.generated.js');
|
|
5
|
+
var productVariants_generated = require('../../graphql/queries/product-variants.generated.js');
|
|
6
|
+
|
|
7
|
+
const getProduct = async (fetcher, { id, isSample }) => {
|
|
8
|
+
const [product, variants, medias] = await Promise.all([
|
|
9
|
+
fetchProduct(fetcher, { id, isSample }),
|
|
10
|
+
fetchVariants(fetcher, { id, isSample }),
|
|
11
|
+
fetchMedias(fetcher, { id, isSample }),
|
|
12
|
+
]);
|
|
13
|
+
if (!product) {
|
|
14
|
+
throw new Error('Product not found');
|
|
15
|
+
}
|
|
16
|
+
return {
|
|
17
|
+
...product,
|
|
18
|
+
variants: {
|
|
19
|
+
edges: variants,
|
|
20
|
+
},
|
|
21
|
+
medias: {
|
|
22
|
+
edges: medias,
|
|
23
|
+
},
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const orderBy = {
|
|
27
|
+
field: 'UPDATED_AT',
|
|
28
|
+
direction: 'DESC',
|
|
29
|
+
};
|
|
30
|
+
const fetchProduct = async (fetcher, { id, isSample }) => {
|
|
31
|
+
const variables = {
|
|
32
|
+
orderBy,
|
|
33
|
+
where: {
|
|
34
|
+
isStorefront: true,
|
|
35
|
+
isSample,
|
|
36
|
+
...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
|
|
37
|
+
},
|
|
38
|
+
};
|
|
39
|
+
const response = await fetcher([productLittleDetail_generated.ProductLittleDetailDocument, variables]);
|
|
40
|
+
return response.product?.edges?.[0]?.node;
|
|
41
|
+
};
|
|
42
|
+
const fetchVariants = async (fetcher, { id, isSample }) => {
|
|
43
|
+
const initVariables = {
|
|
44
|
+
orderBy,
|
|
45
|
+
where: {
|
|
46
|
+
isStorefront: true,
|
|
47
|
+
isSample,
|
|
48
|
+
...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
const query = async (variables, olds) => {
|
|
52
|
+
try {
|
|
53
|
+
const response = await fetcher([
|
|
54
|
+
productVariants_generated.ProductVariantsDocument,
|
|
55
|
+
variables,
|
|
56
|
+
]);
|
|
57
|
+
const product = response.variants?.edges?.[0];
|
|
58
|
+
const items = olds?.concat(product?.node?.variants?.edges ?? []);
|
|
59
|
+
if (product?.node?.variants?.pageInfo?.hasNextPage) {
|
|
60
|
+
return query({
|
|
61
|
+
...variables,
|
|
62
|
+
afterVariant: product?.node?.variants?.pageInfo.endCursor,
|
|
63
|
+
}, items);
|
|
64
|
+
}
|
|
65
|
+
return items ?? [];
|
|
66
|
+
}
|
|
67
|
+
catch {
|
|
68
|
+
return olds ?? [];
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
return query(initVariables, []);
|
|
72
|
+
};
|
|
73
|
+
const fetchMedias = async (fetcher, { id, isSample }) => {
|
|
74
|
+
const initVariables = {
|
|
75
|
+
orderBy,
|
|
76
|
+
where: {
|
|
77
|
+
isStorefront: true,
|
|
78
|
+
isSample,
|
|
79
|
+
...(id && id.toLowerCase() !== 'latest' && { baseID: id }),
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
const query = async (variables) => {
|
|
83
|
+
try {
|
|
84
|
+
const response = await fetcher([
|
|
85
|
+
productMedias_generated.ProductMediasDocument,
|
|
86
|
+
variables,
|
|
87
|
+
]);
|
|
88
|
+
const product = response.medias?.edges?.[0];
|
|
89
|
+
const items = product?.node?.medias?.edges ?? [];
|
|
90
|
+
if (product?.node?.medias?.pageInfo?.hasNextPage) {
|
|
91
|
+
try {
|
|
92
|
+
const newData = await query({
|
|
93
|
+
...variables,
|
|
94
|
+
afterMedia: product?.node?.medias?.pageInfo.endCursor,
|
|
95
|
+
});
|
|
96
|
+
return items.concat(newData);
|
|
97
|
+
}
|
|
98
|
+
catch {
|
|
99
|
+
return items;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
return items;
|
|
103
|
+
}
|
|
104
|
+
catch {
|
|
105
|
+
return [];
|
|
106
|
+
}
|
|
107
|
+
};
|
|
108
|
+
return query(initVariables);
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
exports.fetchMedias = fetchMedias;
|
|
112
|
+
exports.fetchVariants = fetchVariants;
|
|
113
|
+
exports.getProduct = getProduct;
|
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var products_generated = require('../../graphql/queries/products.generated.js');
|
|
4
|
+
var getCollection = require('./get-collection.js');
|
|
5
|
+
var getProduct = require('./get-product.js');
|
|
6
|
+
|
|
7
|
+
const getProducts = async (fetcher, { ids, isSample }) => {
|
|
8
|
+
const products = await loopFetchProducts(fetcher, { ids, isSample });
|
|
9
|
+
if (!products) {
|
|
10
|
+
throw new Error('Product not found');
|
|
11
|
+
}
|
|
12
|
+
const [mergedVariant, mergedMedias] = await Promise.all([
|
|
13
|
+
mergeVariantsToProducts(fetcher, products, isSample),
|
|
14
|
+
mergeMediasToProducts(fetcher, products, isSample),
|
|
15
|
+
]);
|
|
16
|
+
return { ...mergedMedias, ...mergedVariant };
|
|
17
|
+
};
|
|
18
|
+
const fetchProducts = async (fetcher, variables) => {
|
|
19
|
+
return fetcher([products_generated.ProductsDocument, variables]);
|
|
20
|
+
};
|
|
21
|
+
const loopFetchProducts = async (fetcher, { ids, isSample }) => {
|
|
22
|
+
const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
|
|
23
|
+
const productsPerPage = 8; // number of products per page
|
|
24
|
+
let variables; // variables of collection query
|
|
25
|
+
let productAfterFetcher; // product after of collection query
|
|
26
|
+
let dataProducts; // data of collection query
|
|
27
|
+
let hasNextPage; //
|
|
28
|
+
let firstProducts;
|
|
29
|
+
let currentPage = 1;
|
|
30
|
+
// counter number of queries
|
|
31
|
+
const pages = Math.ceil(numberOfProducts / productsPerPage);
|
|
32
|
+
while (currentPage <= pages && hasNextPage !== false) {
|
|
33
|
+
variables = {
|
|
34
|
+
first: getCollection.calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
|
|
35
|
+
firstMedia: 1,
|
|
36
|
+
firstVariant: 1,
|
|
37
|
+
orderBy: {
|
|
38
|
+
direction: 'DESC',
|
|
39
|
+
field: 'UPDATED_AT',
|
|
40
|
+
},
|
|
41
|
+
where: {
|
|
42
|
+
isStorefront: true,
|
|
43
|
+
isSample: isSample,
|
|
44
|
+
...(ids?.length ? { baseIDIn: ids.sort() } : {}),
|
|
45
|
+
},
|
|
46
|
+
after: productAfterFetcher,
|
|
47
|
+
};
|
|
48
|
+
const pageData = await fetchProducts(fetcher, variables);
|
|
49
|
+
productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
|
|
50
|
+
if (currentPage === 1) {
|
|
51
|
+
dataProducts = pageData; // set data of first page
|
|
52
|
+
firstProducts = pageData;
|
|
53
|
+
}
|
|
54
|
+
else if (firstProducts?.products && pageData?.products?.edges.length) {
|
|
55
|
+
// concat new values to the old ones
|
|
56
|
+
firstProducts.products = {
|
|
57
|
+
edges: firstProducts.products.edges.concat(pageData?.products?.edges),
|
|
58
|
+
pageInfo: pageData?.products?.pageInfo,
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
currentPage++;
|
|
62
|
+
// hasNextPage = false if there is no more pages then break the loop
|
|
63
|
+
if (!firstProducts) {
|
|
64
|
+
hasNextPage = false;
|
|
65
|
+
break;
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
return dataProducts;
|
|
69
|
+
};
|
|
70
|
+
const mergeVariantsToProducts = async (fetcher, products, isSample) => {
|
|
71
|
+
const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product) => {
|
|
72
|
+
return getProduct.fetchVariants(fetcher, { id: product?.node?.baseID, isSample }).then((variants) => {
|
|
73
|
+
const res = {
|
|
74
|
+
...product,
|
|
75
|
+
...(product.node
|
|
76
|
+
? {
|
|
77
|
+
node: {
|
|
78
|
+
...product.node,
|
|
79
|
+
variants: variants.length ? { edges: variants } : undefined,
|
|
80
|
+
},
|
|
81
|
+
}
|
|
82
|
+
: {}),
|
|
83
|
+
};
|
|
84
|
+
return res;
|
|
85
|
+
});
|
|
86
|
+
}) ?? []).then((res) => {
|
|
87
|
+
return {
|
|
88
|
+
products: {
|
|
89
|
+
edges: res,
|
|
90
|
+
pageInfo: products?.products?.pageInfo,
|
|
91
|
+
},
|
|
92
|
+
};
|
|
93
|
+
});
|
|
94
|
+
return productsWithVariants;
|
|
95
|
+
};
|
|
96
|
+
const mergeMediasToProducts = async (fetcher, products, isSample) => {
|
|
97
|
+
const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product) => {
|
|
98
|
+
return getProduct.fetchMedias(fetcher, { id: product?.node?.baseID, isSample }).then((media) => {
|
|
99
|
+
const res = {
|
|
100
|
+
...product,
|
|
101
|
+
...(product.node
|
|
102
|
+
? {
|
|
103
|
+
node: {
|
|
104
|
+
...product.node,
|
|
105
|
+
medias: media.length ? { edges: media } : undefined,
|
|
106
|
+
},
|
|
107
|
+
}
|
|
108
|
+
: {}),
|
|
109
|
+
};
|
|
110
|
+
return res;
|
|
111
|
+
});
|
|
112
|
+
}) ?? []).then((res) => {
|
|
113
|
+
return {
|
|
114
|
+
products: {
|
|
115
|
+
edges: res,
|
|
116
|
+
pageInfo: products?.products?.pageInfo,
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
});
|
|
120
|
+
return productsWithMedias;
|
|
121
|
+
};
|
|
122
|
+
// future can be used for fetching products with paging ids
|
|
123
|
+
// const pagingQuery = (
|
|
124
|
+
// data: string[],
|
|
125
|
+
// currentPage: number,
|
|
126
|
+
// productsPerPage: number,
|
|
127
|
+
// first: number,
|
|
128
|
+
// ): string[] => {
|
|
129
|
+
// return data.slice(
|
|
130
|
+
// (currentPage - 1) * productsPerPage,
|
|
131
|
+
// (currentPage - 1) * productsPerPage + first,
|
|
132
|
+
// );
|
|
133
|
+
// };
|
|
134
|
+
|
|
135
|
+
exports.getProducts = getProducts;
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var constant = require('./constant.js');
|
|
4
|
+
|
|
5
|
+
const getRadiusCSSFromGlobal = (state, key, device) => {
|
|
6
|
+
if (!key || !state)
|
|
7
|
+
return {};
|
|
8
|
+
const suffix = device && device !== 'desktop' ? constant.devicesMapping?.[device] : '';
|
|
9
|
+
const mState = constant.stateMapping?.[state];
|
|
10
|
+
return {
|
|
11
|
+
[`-${mState}-radius${suffix}`]: `var(--g-radius-${key})`,
|
|
12
|
+
};
|
|
13
|
+
};
|
|
14
|
+
const getCustomRadius = (state, radius, device) => {
|
|
15
|
+
if (!radius || !state)
|
|
16
|
+
return {};
|
|
17
|
+
const suffix = device && device !== 'desktop' ? constant.devicesMapping?.[device] : '';
|
|
18
|
+
const mState = constant.stateMapping?.[state];
|
|
19
|
+
return {
|
|
20
|
+
[`-${mState}-bblr${suffix}`]: radius.bblr,
|
|
21
|
+
[`-${mState}-bbrr${suffix}`]: radius.bbrr,
|
|
22
|
+
[`-${mState}-btlr${suffix}`]: radius.btlr,
|
|
23
|
+
[`-${mState}-btrr${suffix}`]: radius.btrr,
|
|
24
|
+
};
|
|
25
|
+
};
|
|
26
|
+
const composeRadius = (value) => {
|
|
27
|
+
if (!value)
|
|
28
|
+
return {};
|
|
29
|
+
if ('desktop' in value || 'tablet' in value || 'mobile' in value) {
|
|
30
|
+
return composeRadiusResponsiveState(value);
|
|
31
|
+
}
|
|
32
|
+
return composeRadiusState(value);
|
|
33
|
+
};
|
|
34
|
+
const composeRadiusState = (radiusValue, device) => {
|
|
35
|
+
const style = {};
|
|
36
|
+
switch (radiusValue?.normal?.radiusType) {
|
|
37
|
+
case 'medium':
|
|
38
|
+
case 'large':
|
|
39
|
+
case 'small':
|
|
40
|
+
Object.assign(style, getRadiusCSSFromGlobal('normal', radiusValue?.normal?.radiusType, device));
|
|
41
|
+
break;
|
|
42
|
+
case 'circle':
|
|
43
|
+
case 'none':
|
|
44
|
+
case 'custom':
|
|
45
|
+
Object.assign(style, getCustomRadius('normal', radiusValue.normal, device));
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
switch (radiusValue?.hover?.radiusType) {
|
|
49
|
+
case 'medium':
|
|
50
|
+
case 'large':
|
|
51
|
+
case 'small':
|
|
52
|
+
Object.assign(style, getRadiusCSSFromGlobal('hover', radiusValue?.hover?.radiusType, device));
|
|
53
|
+
break;
|
|
54
|
+
case 'circle':
|
|
55
|
+
case 'none':
|
|
56
|
+
case 'custom':
|
|
57
|
+
Object.assign(style, getCustomRadius('hover', radiusValue.hover, device));
|
|
58
|
+
break;
|
|
59
|
+
}
|
|
60
|
+
switch (radiusValue?.focus?.radiusType) {
|
|
61
|
+
case 'medium':
|
|
62
|
+
case 'large':
|
|
63
|
+
case 'small':
|
|
64
|
+
Object.assign(style, getRadiusCSSFromGlobal('focus', radiusValue?.focus?.radiusType, device));
|
|
65
|
+
break;
|
|
66
|
+
case 'circle':
|
|
67
|
+
case 'none':
|
|
68
|
+
case 'custom':
|
|
69
|
+
Object.assign(style, getCustomRadius('focus', radiusValue.focus, device));
|
|
70
|
+
break;
|
|
71
|
+
}
|
|
72
|
+
return style;
|
|
73
|
+
};
|
|
74
|
+
const composeRadiusResponsiveState = (radiusValue) => {
|
|
75
|
+
const style = {};
|
|
76
|
+
Object.assign(style, composeRadiusState(radiusValue?.desktop, 'desktop'));
|
|
77
|
+
Object.assign(style, composeRadiusState(radiusValue?.tablet, 'tablet'));
|
|
78
|
+
Object.assign(style, composeRadiusState(radiusValue?.mobile, 'mobile'));
|
|
79
|
+
return style;
|
|
80
|
+
};
|
|
81
|
+
const getRadiusStyleActiveState = (radiusValue) => {
|
|
82
|
+
if (radiusValue?.active?.radiusType === 'custom') {
|
|
83
|
+
return getCustomRadius('normal', radiusValue?.active);
|
|
84
|
+
}
|
|
85
|
+
return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
exports.composeRadius = composeRadius;
|
|
89
|
+
exports.getCustomRadius = getCustomRadius;
|
|
90
|
+
exports.getRadiusCSSFromGlobal = getRadiusCSSFromGlobal;
|
|
91
|
+
exports.getRadiusStyleActiveState = getRadiusStyleActiveState;
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var colors = require('./colors.js');
|
|
4
|
+
var constant = require('./constant.js');
|
|
5
|
+
var getShortname = require('./get-shortname.js');
|
|
6
|
+
|
|
7
|
+
const parseValueWithUnit = (valueWithUnit) => {
|
|
8
|
+
const matches = valueWithUnit.match(/(\d+)(.+)/);
|
|
9
|
+
if (matches && matches.length === 3) {
|
|
10
|
+
const value = Number(matches[1] ?? 0);
|
|
11
|
+
const unit = matches[2];
|
|
12
|
+
return { value, unit: unit ?? 'px' };
|
|
13
|
+
}
|
|
14
|
+
return { value: 0, unit: 'px' };
|
|
15
|
+
};
|
|
16
|
+
const getStyleShadow = (shadowStyle, isActiveState = false) => {
|
|
17
|
+
const { styleAppliedFor, value, isEnableShadow } = shadowStyle || {};
|
|
18
|
+
let { state } = shadowStyle || {};
|
|
19
|
+
if (!state)
|
|
20
|
+
state = 'normal';
|
|
21
|
+
if (!styleAppliedFor || !value)
|
|
22
|
+
return {};
|
|
23
|
+
if (typeof value.distance == 'undefined')
|
|
24
|
+
return {};
|
|
25
|
+
const { value: distance, unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
|
|
26
|
+
return {
|
|
27
|
+
[`-${!isActiveState ? constant.stateMapping?.[state] : ''}-${getShortname.getShortName(styleAppliedFor)}`]: isEnableShadow
|
|
28
|
+
? `${Math.cos((parseFloat(`${value?.angle}`) * Math.PI) / 180) * parseFloat(`${distance}`)}${unitDistance} ${Math.sin((parseFloat(`${value?.angle}`) * Math.PI) / 180) * parseFloat(`${distance}`)}${unitDistance} ${value?.blur} ${styleAppliedFor === 'box-shadow' ? value?.spread + ' ' : ''}${colors.getSingleColorVariable(value?.color)}`
|
|
29
|
+
: 'none',
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow) => {
|
|
33
|
+
if (!shadow || !styleAppliedFor)
|
|
34
|
+
return {};
|
|
35
|
+
const style = {};
|
|
36
|
+
for (const [key, value] of Object.entries(shadow)) {
|
|
37
|
+
Object.assign(style, getStyleShadow({
|
|
38
|
+
value: value,
|
|
39
|
+
state: key,
|
|
40
|
+
styleAppliedFor,
|
|
41
|
+
isEnableShadow: isEnableShadow?.[key],
|
|
42
|
+
}));
|
|
43
|
+
}
|
|
44
|
+
return style;
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
exports.getStyleShadow = getStyleShadow;
|
|
48
|
+
exports.getStyleShadowState = getStyleShadowState;
|