@gem-sdk/core 1.5.17 → 1.5.23
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 +7 -7
- package/dist/cjs/components/ComponentWrapper.js +14 -8
- package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
- package/dist/cjs/components/Empty.js +1 -1
- package/dist/cjs/components/Render.js +50 -13
- package/dist/cjs/components/Render.liquid.js +81 -57
- package/dist/cjs/components/RenderBlock.js +41 -8
- package/dist/cjs/components/RenderPreview.js +51 -13
- package/dist/cjs/components/RenderSection.js +11 -7
- package/dist/cjs/components/constant.js +24 -24
- package/dist/cjs/contexts/AddonContext.js +25 -14
- package/dist/cjs/contexts/BuilderComponent.js +23 -19
- package/dist/cjs/contexts/BuilderContext.js +25 -19
- package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
- package/dist/cjs/contexts/CartLineContext.js +19 -14
- package/dist/cjs/contexts/CollectionContext.js +21 -13
- package/dist/cjs/contexts/ProductContext.js +136 -115
- package/dist/cjs/contexts/ProductListContext.js +21 -13
- package/dist/cjs/contexts/SectionContext.js +41 -37
- package/dist/cjs/contexts/ShopContext.js +54 -31
- package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/cjs/graphql/fragments/media.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/product.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
- package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/cjs/graphql/queries/products.generated.js +1 -1
- package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
- package/dist/cjs/helpers/GlobalEvent.js +12 -10
- package/dist/cjs/helpers/background.js +96 -96
- package/dist/cjs/helpers/borders.js +123 -127
- package/dist/cjs/helpers/clone-deep.js +1 -1
- package/dist/cjs/helpers/cls.js +11 -15
- package/dist/cjs/helpers/colors.js +121 -156
- package/dist/cjs/helpers/compose-advance-style.js +115 -121
- package/dist/cjs/helpers/constant.js +16 -11
- package/dist/cjs/helpers/css-variable.js +2 -2
- package/dist/cjs/helpers/email.js +3 -3
- package/dist/cjs/helpers/flatten-connection.js +4 -5
- package/dist/cjs/helpers/get-resonsive-value.js +24 -25
- package/dist/cjs/helpers/get-shortname.js +87 -87
- package/dist/cjs/helpers/is-browser.js +2 -2
- package/dist/cjs/helpers/is-defined.js +2 -2
- package/dist/cjs/helpers/is-empty-children.js +2 -2
- package/dist/cjs/helpers/layout.js +9 -10
- package/dist/cjs/helpers/load-script.js +26 -27
- package/dist/cjs/helpers/make-style.js +77 -86
- package/dist/cjs/helpers/normalize-builder-data.js +18 -12
- package/dist/cjs/helpers/prefetch-queries.js +72 -52
- package/dist/cjs/helpers/product.js +25 -29
- package/dist/cjs/helpers/queries/get-collection.js +179 -167
- package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/cjs/helpers/queries/get-product.js +121 -106
- package/dist/cjs/helpers/queries/get-products.js +137 -125
- package/dist/cjs/helpers/radius.js +78 -81
- package/dist/cjs/helpers/render.js +56 -56
- package/dist/cjs/helpers/shadow.js +38 -38
- package/dist/cjs/helpers/size.js +12 -13
- package/dist/cjs/helpers/spacing.js +35 -37
- package/dist/cjs/helpers/tracking/fpixel.js +21 -22
- package/dist/cjs/helpers/tracking/gtag.js +84 -90
- package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/cjs/helpers/typography.js +2 -2
- package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
- package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
- package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
- package/dist/cjs/hooks/shop/use-product-query.js +12 -6
- package/dist/cjs/hooks/shop/use-products-query.js +14 -6
- package/dist/cjs/hooks/shop.js +86 -67
- package/dist/cjs/hooks/use-current-device.js +14 -16
- package/dist/cjs/hooks/use-lazy-video.js +7 -7
- package/dist/cjs/hooks/useCartId.js +35 -27
- package/dist/cjs/hooks/useCartLine.js +2 -2
- package/dist/cjs/hooks/useCartUI.js +37 -31
- package/dist/cjs/hooks/useCollection.js +2 -2
- package/dist/cjs/hooks/useFetchHandle.js +6 -6
- package/dist/cjs/hooks/useFormatMoney.js +11 -7
- package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/cjs/hooks/useLoadScript.js +22 -20
- package/dist/cjs/hooks/useMoney.js +59 -42
- package/dist/cjs/hooks/usePrevious.js +12 -10
- package/dist/cjs/hooks/useProduct.js +92 -69
- package/dist/cjs/hooks/useProductList.js +11 -11
- package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
- package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
- package/dist/cjs/types/global-style.js +9 -2
- package/dist/esm/components/AddOn.js +7 -7
- package/dist/esm/components/ComponentWrapper.js +14 -8
- package/dist/esm/components/ComponentWrapperPreview.js +55 -46
- package/dist/esm/components/Empty.js +1 -1
- package/dist/esm/components/Render.js +50 -13
- package/dist/esm/components/Render.liquid.js +81 -57
- package/dist/esm/components/RenderBlock.js +41 -8
- package/dist/esm/components/RenderPreview.js +51 -13
- package/dist/esm/components/RenderSection.js +11 -7
- package/dist/esm/components/constant.js +24 -24
- package/dist/esm/contexts/AddonContext.js +26 -15
- package/dist/esm/contexts/BuilderComponent.js +24 -20
- package/dist/esm/contexts/BuilderContext.js +26 -20
- package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
- package/dist/esm/contexts/CartLineContext.js +20 -15
- package/dist/esm/contexts/CollectionContext.js +22 -14
- package/dist/esm/contexts/ProductContext.js +137 -116
- package/dist/esm/contexts/ProductListContext.js +22 -14
- package/dist/esm/contexts/SectionContext.js +42 -38
- package/dist/esm/contexts/ShopContext.js +55 -32
- package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
- package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
- package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
- package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
- package/dist/esm/graphql/fragments/media.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
- package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/product.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
- package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
- package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
- package/dist/esm/graphql/fragments/variant.generated.js +1 -1
- package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
- package/dist/esm/graphql/queries/products.generated.js +1 -1
- package/dist/esm/graphql/queries/store-property.generated.js +1 -1
- package/dist/esm/helpers/GlobalEvent.js +12 -10
- package/dist/esm/helpers/background.js +96 -96
- package/dist/esm/helpers/borders.js +123 -127
- package/dist/esm/helpers/clone-deep.js +1 -1
- package/dist/esm/helpers/cls.js +11 -15
- package/dist/esm/helpers/colors.js +121 -156
- package/dist/esm/helpers/compose-advance-style.js +115 -121
- package/dist/esm/helpers/constant.js +16 -11
- package/dist/esm/helpers/css-variable.js +2 -2
- package/dist/esm/helpers/email.js +3 -3
- package/dist/esm/helpers/flatten-connection.js +4 -5
- package/dist/esm/helpers/get-resonsive-value.js +24 -25
- package/dist/esm/helpers/get-shortname.js +87 -87
- package/dist/esm/helpers/is-browser.js +2 -2
- package/dist/esm/helpers/is-defined.js +2 -2
- package/dist/esm/helpers/is-empty-children.js +2 -2
- package/dist/esm/helpers/layout.js +9 -10
- package/dist/esm/helpers/load-script.js +26 -27
- package/dist/esm/helpers/make-style.js +77 -86
- package/dist/esm/helpers/normalize-builder-data.js +18 -12
- package/dist/esm/helpers/prefetch-queries.js +72 -52
- package/dist/esm/helpers/product.js +25 -29
- package/dist/esm/helpers/queries/get-collection.js +179 -167
- package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
- package/dist/esm/helpers/queries/get-product.js +121 -106
- package/dist/esm/helpers/queries/get-products.js +137 -125
- package/dist/esm/helpers/radius.js +78 -81
- package/dist/esm/helpers/render.js +56 -56
- package/dist/esm/helpers/shadow.js +38 -38
- package/dist/esm/helpers/size.js +12 -13
- package/dist/esm/helpers/spacing.js +35 -37
- package/dist/esm/helpers/tracking/fpixel.js +21 -22
- package/dist/esm/helpers/tracking/gtag.js +84 -90
- package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
- package/dist/esm/helpers/typography.js +2 -2
- package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
- package/dist/esm/hooks/cart/use-cart-data.js +18 -16
- package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
- package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
- package/dist/esm/hooks/cart/use-create-cart.js +12 -12
- package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
- package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
- package/dist/esm/hooks/shop/use-collection-query.js +12 -6
- package/dist/esm/hooks/shop/use-product-query.js +12 -6
- package/dist/esm/hooks/shop/use-products-query.js +14 -6
- package/dist/esm/hooks/shop.js +86 -67
- package/dist/esm/hooks/use-current-device.js +14 -16
- package/dist/esm/hooks/use-lazy-video.js +7 -7
- package/dist/esm/hooks/useCartId.js +35 -27
- package/dist/esm/hooks/useCartLine.js +2 -2
- package/dist/esm/hooks/useCartUI.js +37 -31
- package/dist/esm/hooks/useCollection.js +2 -2
- package/dist/esm/hooks/useFetchHandle.js +6 -6
- package/dist/esm/hooks/useFormatMoney.js +11 -7
- package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
- package/dist/esm/hooks/useLoadScript.js +22 -20
- package/dist/esm/hooks/useMoney.js +59 -42
- package/dist/esm/hooks/usePrevious.js +12 -10
- package/dist/esm/hooks/useProduct.js +92 -69
- package/dist/esm/hooks/useProductList.js +11 -11
- package/dist/esm/hooks/useSuspenseFetch.js +20 -17
- package/dist/esm/hooks/useSwatchesOptions.js +32 -30
- package/dist/esm/types/global-style.js +9 -2
- package/dist/types/index.d.ts +30 -2
- package/package.json +1 -1
|
@@ -4,130 +4,142 @@ var products_generated = require('../../graphql/queries/products.generated.js');
|
|
|
4
4
|
var getCollection = require('./get-collection.js');
|
|
5
5
|
var getProduct = require('./get-product.js');
|
|
6
6
|
|
|
7
|
-
const getProducts = async (fetcher, { ids, isSample
|
|
8
|
-
const products = await loopFetchProducts(fetcher, {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
]
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
};
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
//
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
return {
|
|
114
|
-
productId: product?.node?.baseID,
|
|
115
|
-
items:
|
|
116
|
-
};
|
|
117
|
-
}) ?? []);
|
|
118
|
-
return
|
|
119
|
-
};
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
7
|
+
const getProducts = async (fetcher, { ids , isSample })=>{
|
|
8
|
+
const products = await loopFetchProducts(fetcher, {
|
|
9
|
+
ids,
|
|
10
|
+
isSample
|
|
11
|
+
});
|
|
12
|
+
if (!products) {
|
|
13
|
+
throw new Error('Product not found');
|
|
14
|
+
}
|
|
15
|
+
const [mergedVariant, mergedMedias] = await Promise.all([
|
|
16
|
+
mergeVariantsToProducts(fetcher, products, isSample),
|
|
17
|
+
mergeMediasToProducts(fetcher, products, isSample)
|
|
18
|
+
]);
|
|
19
|
+
return {
|
|
20
|
+
...products,
|
|
21
|
+
products: {
|
|
22
|
+
...products.products,
|
|
23
|
+
edges: products.products?.edges.map((edge)=>{
|
|
24
|
+
const medias = mergedMedias.find((item)=>item.productId === edge.node?.baseID);
|
|
25
|
+
const variants = mergedVariant.find((item)=>item.productId === edge.node?.baseID);
|
|
26
|
+
if (edge.node) {
|
|
27
|
+
return {
|
|
28
|
+
...edge,
|
|
29
|
+
node: {
|
|
30
|
+
...edge.node,
|
|
31
|
+
variants: {
|
|
32
|
+
...edge.node?.variants,
|
|
33
|
+
edges: variants?.items ?? []
|
|
34
|
+
},
|
|
35
|
+
medias: {
|
|
36
|
+
...edge.node?.medias,
|
|
37
|
+
edges: medias?.items ?? []
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
return edge;
|
|
43
|
+
}) ?? []
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
};
|
|
47
|
+
const fetchProducts = async (fetcher, variables)=>{
|
|
48
|
+
return fetcher([
|
|
49
|
+
products_generated.ProductsDocument,
|
|
50
|
+
variables
|
|
51
|
+
]);
|
|
52
|
+
};
|
|
53
|
+
const loopFetchProducts = async (fetcher, { ids , isSample })=>{
|
|
54
|
+
const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
|
|
55
|
+
const productsPerPage = 8; // number of products per page
|
|
56
|
+
let variables; // variables of collection query
|
|
57
|
+
let productAfterFetcher; // product after of collection query
|
|
58
|
+
let dataProducts; // data of collection query
|
|
59
|
+
let hasNextPage; //
|
|
60
|
+
let firstProducts;
|
|
61
|
+
let currentPage = 1;
|
|
62
|
+
// counter number of queries
|
|
63
|
+
const pages = Math.ceil(numberOfProducts / productsPerPage);
|
|
64
|
+
while(currentPage <= pages && hasNextPage !== false){
|
|
65
|
+
variables = {
|
|
66
|
+
first: getCollection.calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
|
|
67
|
+
firstMedia: 1,
|
|
68
|
+
firstVariant: 1,
|
|
69
|
+
orderBy: {
|
|
70
|
+
direction: 'DESC',
|
|
71
|
+
field: 'UPDATED_AT'
|
|
72
|
+
},
|
|
73
|
+
orderByMedia: {
|
|
74
|
+
field: 'POSITION',
|
|
75
|
+
direction: 'ASC'
|
|
76
|
+
},
|
|
77
|
+
where: {
|
|
78
|
+
isStorefront: true,
|
|
79
|
+
isSample: isSample,
|
|
80
|
+
...ids?.length ? {
|
|
81
|
+
baseIDIn: ids
|
|
82
|
+
} : {}
|
|
83
|
+
},
|
|
84
|
+
after: productAfterFetcher
|
|
85
|
+
};
|
|
86
|
+
const pageData = await fetchProducts(fetcher, variables);
|
|
87
|
+
productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
|
|
88
|
+
if (currentPage === 1) {
|
|
89
|
+
dataProducts = pageData; // set data of first page
|
|
90
|
+
firstProducts = pageData;
|
|
91
|
+
} else if (firstProducts?.products && pageData?.products?.edges.length) {
|
|
92
|
+
// concat new values to the old ones
|
|
93
|
+
firstProducts.products = {
|
|
94
|
+
edges: firstProducts.products.edges.concat(pageData?.products?.edges),
|
|
95
|
+
pageInfo: pageData?.products?.pageInfo
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
currentPage++;
|
|
99
|
+
// hasNextPage = false if there is no more pages then break the loop
|
|
100
|
+
if (!firstProducts) {
|
|
101
|
+
hasNextPage = false;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return dataProducts;
|
|
106
|
+
};
|
|
107
|
+
const mergeVariantsToProducts = async (fetcher, products, isSample)=>{
|
|
108
|
+
const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product)=>{
|
|
109
|
+
const variants = await getProduct.fetchVariants(fetcher, {
|
|
110
|
+
id: product?.node?.baseID,
|
|
111
|
+
isSample
|
|
112
|
+
});
|
|
113
|
+
return {
|
|
114
|
+
productId: product?.node?.baseID,
|
|
115
|
+
items: variants
|
|
116
|
+
};
|
|
117
|
+
}) ?? []);
|
|
118
|
+
return productsWithVariants;
|
|
119
|
+
};
|
|
120
|
+
const mergeMediasToProducts = async (fetcher, products, isSample)=>{
|
|
121
|
+
const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product)=>{
|
|
122
|
+
const medias = await getProduct.fetchMedias(fetcher, {
|
|
123
|
+
id: product?.node?.baseID,
|
|
124
|
+
isSample
|
|
125
|
+
});
|
|
126
|
+
return {
|
|
127
|
+
productId: product?.node?.baseID,
|
|
128
|
+
items: medias
|
|
129
|
+
};
|
|
130
|
+
}) ?? []);
|
|
131
|
+
return productsWithMedias;
|
|
132
|
+
}; // future can be used for fetching products with paging ids
|
|
133
|
+
// const pagingQuery = (
|
|
134
|
+
// data: string[],
|
|
135
|
+
// currentPage: number,
|
|
136
|
+
// productsPerPage: number,
|
|
137
|
+
// first: number,
|
|
138
|
+
// ): string[] => {
|
|
139
|
+
// return data.slice(
|
|
140
|
+
// (currentPage - 1) * productsPerPage,
|
|
141
|
+
// (currentPage - 1) * productsPerPage + first,
|
|
142
|
+
// );
|
|
143
|
+
// };
|
|
132
144
|
|
|
133
145
|
exports.getProducts = getProducts;
|
|
@@ -2,87 +2,84 @@
|
|
|
2
2
|
|
|
3
3
|
var constant = require('./constant.js');
|
|
4
4
|
|
|
5
|
-
const getRadiusCSSFromGlobal = (state, key, device)
|
|
6
|
-
if (!key || !state)
|
|
7
|
-
|
|
8
|
-
const
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
[`-${mState}-
|
|
21
|
-
[`-${mState}-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
};
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
case '
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
case '
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
case '
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
return getCustomRadius('normal', radiusValue?.active);
|
|
84
|
-
}
|
|
85
|
-
return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
|
|
5
|
+
const getRadiusCSSFromGlobal = (state, key, device)=>{
|
|
6
|
+
if (!key || !state) return {};
|
|
7
|
+
const suffix = device && device !== 'desktop' ? constant.devicesMapping?.[device] : '';
|
|
8
|
+
const mState = constant.stateMapping?.[state];
|
|
9
|
+
return {
|
|
10
|
+
[`-${mState}-radius${suffix}`]: `var(--g-radius-${key})`
|
|
11
|
+
};
|
|
12
|
+
};
|
|
13
|
+
const getCustomRadius = (state, radius, device)=>{
|
|
14
|
+
if (!radius || !state) return {};
|
|
15
|
+
const suffix = device && device !== 'desktop' ? constant.devicesMapping?.[device] : '';
|
|
16
|
+
const mState = constant.stateMapping?.[state];
|
|
17
|
+
return {
|
|
18
|
+
[`-${mState}-bblr${suffix}`]: radius.bblr,
|
|
19
|
+
[`-${mState}-bbrr${suffix}`]: radius.bbrr,
|
|
20
|
+
[`-${mState}-btlr${suffix}`]: radius.btlr,
|
|
21
|
+
[`-${mState}-btrr${suffix}`]: radius.btrr
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
const composeRadius = (value)=>{
|
|
25
|
+
if (!value) return {};
|
|
26
|
+
if ('desktop' in value || 'tablet' in value || 'mobile' in value) {
|
|
27
|
+
return composeRadiusResponsiveState(value);
|
|
28
|
+
}
|
|
29
|
+
return composeRadiusState(value);
|
|
30
|
+
};
|
|
31
|
+
const composeRadiusState = (radiusValue, device)=>{
|
|
32
|
+
const style = {};
|
|
33
|
+
switch(radiusValue?.normal?.radiusType){
|
|
34
|
+
case 'medium':
|
|
35
|
+
case 'large':
|
|
36
|
+
case 'small':
|
|
37
|
+
Object.assign(style, getRadiusCSSFromGlobal('normal', radiusValue?.normal?.radiusType, device));
|
|
38
|
+
break;
|
|
39
|
+
case 'circle':
|
|
40
|
+
case 'none':
|
|
41
|
+
case 'custom':
|
|
42
|
+
Object.assign(style, getCustomRadius('normal', radiusValue.normal, device));
|
|
43
|
+
break;
|
|
44
|
+
}
|
|
45
|
+
switch(radiusValue?.hover?.radiusType){
|
|
46
|
+
case 'medium':
|
|
47
|
+
case 'large':
|
|
48
|
+
case 'small':
|
|
49
|
+
Object.assign(style, getRadiusCSSFromGlobal('hover', radiusValue?.hover?.radiusType, device));
|
|
50
|
+
break;
|
|
51
|
+
case 'circle':
|
|
52
|
+
case 'none':
|
|
53
|
+
case 'custom':
|
|
54
|
+
Object.assign(style, getCustomRadius('hover', radiusValue.hover, device));
|
|
55
|
+
break;
|
|
56
|
+
}
|
|
57
|
+
switch(radiusValue?.focus?.radiusType){
|
|
58
|
+
case 'medium':
|
|
59
|
+
case 'large':
|
|
60
|
+
case 'small':
|
|
61
|
+
Object.assign(style, getRadiusCSSFromGlobal('focus', radiusValue?.focus?.radiusType, device));
|
|
62
|
+
break;
|
|
63
|
+
case 'circle':
|
|
64
|
+
case 'none':
|
|
65
|
+
case 'custom':
|
|
66
|
+
Object.assign(style, getCustomRadius('focus', radiusValue.focus, device));
|
|
67
|
+
break;
|
|
68
|
+
}
|
|
69
|
+
return style;
|
|
70
|
+
};
|
|
71
|
+
const composeRadiusResponsiveState = (radiusValue)=>{
|
|
72
|
+
const style = {};
|
|
73
|
+
Object.assign(style, composeRadiusState(radiusValue?.desktop, 'desktop'));
|
|
74
|
+
Object.assign(style, composeRadiusState(radiusValue?.tablet, 'tablet'));
|
|
75
|
+
Object.assign(style, composeRadiusState(radiusValue?.mobile, 'mobile'));
|
|
76
|
+
return style;
|
|
77
|
+
};
|
|
78
|
+
const getRadiusStyleActiveState = (radiusValue)=>{
|
|
79
|
+
if (radiusValue?.active?.radiusType === 'custom') {
|
|
80
|
+
return getCustomRadius('normal', radiusValue?.active);
|
|
81
|
+
}
|
|
82
|
+
return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
|
|
86
83
|
};
|
|
87
84
|
|
|
88
85
|
exports.composeRadius = composeRadius;
|
|
@@ -1,61 +1,61 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
const RenderIf = (c, t, f)
|
|
4
|
-
const isObject = (obj)
|
|
5
|
-
if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) {
|
|
6
|
-
return true;
|
|
7
|
-
}
|
|
8
|
-
return false;
|
|
9
|
-
};
|
|
10
|
-
const props = (strings, ...keys)
|
|
11
|
-
const props = keys[0];
|
|
12
|
-
const propsArr = [];
|
|
13
|
-
for
|
|
14
|
-
if (Object.hasOwnProperty.call(props, attr)) {
|
|
15
|
-
const val = props[attr];
|
|
16
|
-
if (![
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else {
|
|
54
|
-
str += keys[index];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
});
|
|
58
|
-
return str;
|
|
3
|
+
const RenderIf = (c, t, f)=>c ? typeof t === 'string' ? t : t() : (typeof f === 'string' ? f : f?.()) ?? '';
|
|
4
|
+
const isObject = (obj)=>{
|
|
5
|
+
if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) {
|
|
6
|
+
return true;
|
|
7
|
+
}
|
|
8
|
+
return false;
|
|
9
|
+
};
|
|
10
|
+
const props = (strings, ...keys)=>{
|
|
11
|
+
const props = keys[0];
|
|
12
|
+
const propsArr = [];
|
|
13
|
+
for(const attr in props){
|
|
14
|
+
if (Object.hasOwnProperty.call(props, attr)) {
|
|
15
|
+
const val = props[attr];
|
|
16
|
+
if (![
|
|
17
|
+
'symbol',
|
|
18
|
+
'object',
|
|
19
|
+
'function'
|
|
20
|
+
].includes(typeof val)) {
|
|
21
|
+
if (val) {
|
|
22
|
+
propsArr.push(`${attr}="${val}"`);
|
|
23
|
+
} else {
|
|
24
|
+
propsArr.push(`${attr}`);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return propsArr.join(' ');
|
|
30
|
+
};
|
|
31
|
+
const styles = (strings, ...keys)=>{
|
|
32
|
+
const styles = keys[0];
|
|
33
|
+
const styleArr = [];
|
|
34
|
+
for(const attr in styles){
|
|
35
|
+
if (Object.hasOwnProperty.call(styles, attr)) {
|
|
36
|
+
const val = styles[attr];
|
|
37
|
+
if (val !== undefined) styleArr.push(`${attr}:${val}`);
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
return styleArr.join(';');
|
|
41
|
+
};
|
|
42
|
+
const template = (strings, ...keys)=>{
|
|
43
|
+
let str = '';
|
|
44
|
+
strings.forEach((item, index)=>{
|
|
45
|
+
str += item;
|
|
46
|
+
if (keys[index] !== undefined) {
|
|
47
|
+
if (isObject(keys[index])) {
|
|
48
|
+
if (/style=["|']/.test(item)) {
|
|
49
|
+
str += styles`${keys[index]}`;
|
|
50
|
+
} else {
|
|
51
|
+
str += props`${keys[index]}`;
|
|
52
|
+
}
|
|
53
|
+
} else {
|
|
54
|
+
str += keys[index];
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return str;
|
|
59
59
|
};
|
|
60
60
|
|
|
61
61
|
exports.RenderIf = RenderIf;
|
|
@@ -4,44 +4,44 @@ var colors = require('./colors.js');
|
|
|
4
4
|
var constant = require('./constant.js');
|
|
5
5
|
var getShortname = require('./get-shortname.js');
|
|
6
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 {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return {
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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;
|
|
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 {
|
|
13
|
+
value,
|
|
14
|
+
unit: unit ?? 'px'
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
value: 0,
|
|
19
|
+
unit: 'px'
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const getStyleShadow = (shadowStyle, isActiveState = false)=>{
|
|
23
|
+
const { styleAppliedFor , value , isEnableShadow } = shadowStyle || {};
|
|
24
|
+
let { state } = shadowStyle || {};
|
|
25
|
+
if (!state) state = 'normal';
|
|
26
|
+
if (!styleAppliedFor || !value) return {};
|
|
27
|
+
if (typeof value.distance == 'undefined') return {};
|
|
28
|
+
const { value: distance , unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
|
|
29
|
+
return {
|
|
30
|
+
[`-${!isActiveState ? constant.stateMapping?.[state] : ''}-${getShortname.getShortName(styleAppliedFor)}`]: isEnableShadow ? `${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)}` : 'none'
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow)=>{
|
|
34
|
+
if (!shadow || !styleAppliedFor) 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
45
|
};
|
|
46
46
|
|
|
47
47
|
exports.getStyleShadow = getStyleShadow;
|