@gem-sdk/core 1.5.17 → 1.5.22

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.
Files changed (206) hide show
  1. package/dist/cjs/components/AddOn.js +7 -7
  2. package/dist/cjs/components/ComponentWrapper.js +14 -8
  3. package/dist/cjs/components/ComponentWrapperPreview.js +55 -46
  4. package/dist/cjs/components/Empty.js +1 -1
  5. package/dist/cjs/components/Render.js +50 -13
  6. package/dist/cjs/components/Render.liquid.js +81 -57
  7. package/dist/cjs/components/RenderBlock.js +41 -8
  8. package/dist/cjs/components/RenderPreview.js +51 -13
  9. package/dist/cjs/components/RenderSection.js +11 -7
  10. package/dist/cjs/components/constant.js +24 -24
  11. package/dist/cjs/contexts/AddonContext.js +25 -14
  12. package/dist/cjs/contexts/BuilderComponent.js +23 -19
  13. package/dist/cjs/contexts/BuilderContext.js +25 -19
  14. package/dist/cjs/contexts/BuilderPreviewContext.js +349 -341
  15. package/dist/cjs/contexts/CartLineContext.js +19 -14
  16. package/dist/cjs/contexts/CollectionContext.js +21 -13
  17. package/dist/cjs/contexts/ProductContext.js +136 -115
  18. package/dist/cjs/contexts/ProductListContext.js +21 -13
  19. package/dist/cjs/contexts/SectionContext.js +41 -37
  20. package/dist/cjs/contexts/ShopContext.js +49 -31
  21. package/dist/cjs/graphql/fragments/analytic.generated.js +1 -1
  22. package/dist/cjs/graphql/fragments/collection-detail.generated.js +1 -1
  23. package/dist/cjs/graphql/fragments/collection-product.generated.js +1 -1
  24. package/dist/cjs/graphql/fragments/custom-code.generated.js +1 -1
  25. package/dist/cjs/graphql/fragments/data-seo.generated.js +1 -1
  26. package/dist/cjs/graphql/fragments/media.generated.js +1 -1
  27. package/dist/cjs/graphql/fragments/product-little.generated.js +1 -1
  28. package/dist/cjs/graphql/fragments/product-option-value.generated.js +1 -1
  29. package/dist/cjs/graphql/fragments/product-option.generated.js +1 -1
  30. package/dist/cjs/graphql/fragments/product.generated.js +1 -1
  31. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +1 -1
  32. package/dist/cjs/graphql/fragments/published-page-section.generated.js +1 -1
  33. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +1 -1
  34. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +1 -1
  35. package/dist/cjs/graphql/fragments/selected-option.generated.js +1 -1
  36. package/dist/cjs/graphql/fragments/variant.generated.js +1 -1
  37. package/dist/cjs/graphql/mutations/page-view-up.generated.js +1 -1
  38. package/dist/cjs/graphql/queries/products.generated.js +1 -1
  39. package/dist/cjs/graphql/queries/store-property.generated.js +1 -1
  40. package/dist/cjs/helpers/GlobalEvent.js +12 -10
  41. package/dist/cjs/helpers/background.js +96 -96
  42. package/dist/cjs/helpers/borders.js +123 -127
  43. package/dist/cjs/helpers/clone-deep.js +1 -1
  44. package/dist/cjs/helpers/cls.js +11 -15
  45. package/dist/cjs/helpers/colors.js +121 -156
  46. package/dist/cjs/helpers/compose-advance-style.js +115 -121
  47. package/dist/cjs/helpers/constant.js +16 -11
  48. package/dist/cjs/helpers/css-variable.js +2 -2
  49. package/dist/cjs/helpers/email.js +3 -3
  50. package/dist/cjs/helpers/flatten-connection.js +4 -5
  51. package/dist/cjs/helpers/get-resonsive-value.js +24 -25
  52. package/dist/cjs/helpers/get-shortname.js +87 -87
  53. package/dist/cjs/helpers/is-browser.js +2 -2
  54. package/dist/cjs/helpers/is-defined.js +2 -2
  55. package/dist/cjs/helpers/is-empty-children.js +2 -2
  56. package/dist/cjs/helpers/layout.js +9 -10
  57. package/dist/cjs/helpers/load-script.js +26 -27
  58. package/dist/cjs/helpers/make-style.js +77 -86
  59. package/dist/cjs/helpers/normalize-builder-data.js +18 -12
  60. package/dist/cjs/helpers/prefetch-queries.js +72 -52
  61. package/dist/cjs/helpers/product.js +25 -29
  62. package/dist/cjs/helpers/queries/get-collection.js +179 -167
  63. package/dist/cjs/helpers/queries/get-product-by-slug.js +103 -94
  64. package/dist/cjs/helpers/queries/get-product.js +121 -106
  65. package/dist/cjs/helpers/queries/get-products.js +137 -125
  66. package/dist/cjs/helpers/radius.js +78 -81
  67. package/dist/cjs/helpers/render.js +56 -56
  68. package/dist/cjs/helpers/shadow.js +38 -38
  69. package/dist/cjs/helpers/size.js +12 -13
  70. package/dist/cjs/helpers/spacing.js +35 -37
  71. package/dist/cjs/helpers/tracking/fpixel.js +21 -22
  72. package/dist/cjs/helpers/tracking/gtag.js +84 -90
  73. package/dist/cjs/helpers/tracking/tiktokpixel.js +12 -12
  74. package/dist/cjs/helpers/typography.js +2 -2
  75. package/dist/cjs/hooks/cart/use-add-to-cart.js +10 -10
  76. package/dist/cjs/hooks/cart/use-cart-data.js +18 -16
  77. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +10 -10
  78. package/dist/cjs/hooks/cart/use-cart-note-update.js +10 -10
  79. package/dist/cjs/hooks/cart/use-create-cart.js +12 -12
  80. package/dist/cjs/hooks/cart/use-remove-cart-item.js +10 -10
  81. package/dist/cjs/hooks/cart/use-update-cart-item.js +10 -10
  82. package/dist/cjs/hooks/shop/use-collection-query.js +12 -6
  83. package/dist/cjs/hooks/shop/use-product-query.js +12 -6
  84. package/dist/cjs/hooks/shop/use-products-query.js +14 -6
  85. package/dist/cjs/hooks/shop.js +86 -67
  86. package/dist/cjs/hooks/use-current-device.js +14 -16
  87. package/dist/cjs/hooks/use-lazy-video.js +7 -7
  88. package/dist/cjs/hooks/useCartId.js +35 -27
  89. package/dist/cjs/hooks/useCartLine.js +2 -2
  90. package/dist/cjs/hooks/useCartUI.js +37 -31
  91. package/dist/cjs/hooks/useCollection.js +2 -2
  92. package/dist/cjs/hooks/useFetchHandle.js +6 -6
  93. package/dist/cjs/hooks/useFormatMoney.js +11 -7
  94. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +1 -1
  95. package/dist/cjs/hooks/useLoadScript.js +22 -20
  96. package/dist/cjs/hooks/useMoney.js +59 -42
  97. package/dist/cjs/hooks/usePrevious.js +12 -10
  98. package/dist/cjs/hooks/useProduct.js +92 -69
  99. package/dist/cjs/hooks/useProductList.js +11 -11
  100. package/dist/cjs/hooks/useSuspenseFetch.js +20 -17
  101. package/dist/cjs/hooks/useSwatchesOptions.js +32 -30
  102. package/dist/cjs/types/global-style.js +9 -2
  103. package/dist/esm/components/AddOn.js +7 -7
  104. package/dist/esm/components/ComponentWrapper.js +14 -8
  105. package/dist/esm/components/ComponentWrapperPreview.js +55 -46
  106. package/dist/esm/components/Empty.js +1 -1
  107. package/dist/esm/components/Render.js +50 -13
  108. package/dist/esm/components/Render.liquid.js +81 -57
  109. package/dist/esm/components/RenderBlock.js +41 -8
  110. package/dist/esm/components/RenderPreview.js +51 -13
  111. package/dist/esm/components/RenderSection.js +11 -7
  112. package/dist/esm/components/constant.js +24 -24
  113. package/dist/esm/contexts/AddonContext.js +26 -15
  114. package/dist/esm/contexts/BuilderComponent.js +24 -20
  115. package/dist/esm/contexts/BuilderContext.js +26 -20
  116. package/dist/esm/contexts/BuilderPreviewContext.js +350 -342
  117. package/dist/esm/contexts/CartLineContext.js +20 -15
  118. package/dist/esm/contexts/CollectionContext.js +22 -14
  119. package/dist/esm/contexts/ProductContext.js +137 -116
  120. package/dist/esm/contexts/ProductListContext.js +22 -14
  121. package/dist/esm/contexts/SectionContext.js +42 -38
  122. package/dist/esm/contexts/ShopContext.js +50 -32
  123. package/dist/esm/graphql/fragments/analytic.generated.js +1 -1
  124. package/dist/esm/graphql/fragments/collection-detail.generated.js +1 -1
  125. package/dist/esm/graphql/fragments/collection-product.generated.js +1 -1
  126. package/dist/esm/graphql/fragments/custom-code.generated.js +1 -1
  127. package/dist/esm/graphql/fragments/data-seo.generated.js +1 -1
  128. package/dist/esm/graphql/fragments/media.generated.js +1 -1
  129. package/dist/esm/graphql/fragments/product-little.generated.js +1 -1
  130. package/dist/esm/graphql/fragments/product-option-value.generated.js +1 -1
  131. package/dist/esm/graphql/fragments/product-option.generated.js +1 -1
  132. package/dist/esm/graphql/fragments/product.generated.js +1 -1
  133. package/dist/esm/graphql/fragments/published-custom-section.generated.js +1 -1
  134. package/dist/esm/graphql/fragments/published-page-section.generated.js +1 -1
  135. package/dist/esm/graphql/fragments/published-theme-page.generated.js +1 -1
  136. package/dist/esm/graphql/fragments/published-theme-style.generated.js +1 -1
  137. package/dist/esm/graphql/fragments/selected-option.generated.js +1 -1
  138. package/dist/esm/graphql/fragments/variant.generated.js +1 -1
  139. package/dist/esm/graphql/mutations/page-view-up.generated.js +1 -1
  140. package/dist/esm/graphql/queries/products.generated.js +1 -1
  141. package/dist/esm/graphql/queries/store-property.generated.js +1 -1
  142. package/dist/esm/helpers/GlobalEvent.js +12 -10
  143. package/dist/esm/helpers/background.js +96 -96
  144. package/dist/esm/helpers/borders.js +123 -127
  145. package/dist/esm/helpers/clone-deep.js +1 -1
  146. package/dist/esm/helpers/cls.js +11 -15
  147. package/dist/esm/helpers/colors.js +121 -156
  148. package/dist/esm/helpers/compose-advance-style.js +115 -121
  149. package/dist/esm/helpers/constant.js +16 -11
  150. package/dist/esm/helpers/css-variable.js +2 -2
  151. package/dist/esm/helpers/email.js +3 -3
  152. package/dist/esm/helpers/flatten-connection.js +4 -5
  153. package/dist/esm/helpers/get-resonsive-value.js +24 -25
  154. package/dist/esm/helpers/get-shortname.js +87 -87
  155. package/dist/esm/helpers/is-browser.js +2 -2
  156. package/dist/esm/helpers/is-defined.js +2 -2
  157. package/dist/esm/helpers/is-empty-children.js +2 -2
  158. package/dist/esm/helpers/layout.js +9 -10
  159. package/dist/esm/helpers/load-script.js +26 -27
  160. package/dist/esm/helpers/make-style.js +77 -86
  161. package/dist/esm/helpers/normalize-builder-data.js +18 -12
  162. package/dist/esm/helpers/prefetch-queries.js +72 -52
  163. package/dist/esm/helpers/product.js +25 -29
  164. package/dist/esm/helpers/queries/get-collection.js +179 -167
  165. package/dist/esm/helpers/queries/get-product-by-slug.js +103 -94
  166. package/dist/esm/helpers/queries/get-product.js +121 -106
  167. package/dist/esm/helpers/queries/get-products.js +137 -125
  168. package/dist/esm/helpers/radius.js +78 -81
  169. package/dist/esm/helpers/render.js +56 -56
  170. package/dist/esm/helpers/shadow.js +38 -38
  171. package/dist/esm/helpers/size.js +12 -13
  172. package/dist/esm/helpers/spacing.js +35 -37
  173. package/dist/esm/helpers/tracking/fpixel.js +21 -22
  174. package/dist/esm/helpers/tracking/gtag.js +84 -90
  175. package/dist/esm/helpers/tracking/tiktokpixel.js +12 -12
  176. package/dist/esm/helpers/typography.js +2 -2
  177. package/dist/esm/hooks/cart/use-add-to-cart.js +10 -10
  178. package/dist/esm/hooks/cart/use-cart-data.js +18 -16
  179. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +10 -10
  180. package/dist/esm/hooks/cart/use-cart-note-update.js +10 -10
  181. package/dist/esm/hooks/cart/use-create-cart.js +12 -12
  182. package/dist/esm/hooks/cart/use-remove-cart-item.js +10 -10
  183. package/dist/esm/hooks/cart/use-update-cart-item.js +10 -10
  184. package/dist/esm/hooks/shop/use-collection-query.js +12 -6
  185. package/dist/esm/hooks/shop/use-product-query.js +12 -6
  186. package/dist/esm/hooks/shop/use-products-query.js +14 -6
  187. package/dist/esm/hooks/shop.js +86 -67
  188. package/dist/esm/hooks/use-current-device.js +14 -16
  189. package/dist/esm/hooks/use-lazy-video.js +7 -7
  190. package/dist/esm/hooks/useCartId.js +35 -27
  191. package/dist/esm/hooks/useCartLine.js +2 -2
  192. package/dist/esm/hooks/useCartUI.js +37 -31
  193. package/dist/esm/hooks/useCollection.js +2 -2
  194. package/dist/esm/hooks/useFetchHandle.js +6 -6
  195. package/dist/esm/hooks/useFormatMoney.js +11 -7
  196. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +1 -1
  197. package/dist/esm/hooks/useLoadScript.js +22 -20
  198. package/dist/esm/hooks/useMoney.js +59 -42
  199. package/dist/esm/hooks/usePrevious.js +12 -10
  200. package/dist/esm/hooks/useProduct.js +92 -69
  201. package/dist/esm/hooks/useProductList.js +11 -11
  202. package/dist/esm/hooks/useSuspenseFetch.js +20 -17
  203. package/dist/esm/hooks/useSwatchesOptions.js +32 -30
  204. package/dist/esm/types/global-style.js +9 -2
  205. package/dist/types/index.d.ts +24 -2
  206. 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, { 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 {
17
- ...products,
18
- products: {
19
- ...products.products,
20
- edges: products.products?.edges.map((edge) => {
21
- const medias = mergedMedias.find((item) => item.productId === edge.node?.baseID);
22
- const variants = mergedVariant.find((item) => item.productId === edge.node?.baseID);
23
- if (edge.node) {
24
- return {
25
- ...edge,
26
- node: {
27
- ...edge.node,
28
- variants: {
29
- ...edge.node?.variants,
30
- edges: variants?.items ?? [],
31
- },
32
- medias: {
33
- ...edge.node?.medias,
34
- edges: medias?.items ?? [],
35
- },
36
- },
37
- };
38
- }
39
- return edge;
40
- }) ?? [],
41
- },
42
- };
43
- };
44
- const fetchProducts = async (fetcher, variables) => {
45
- return fetcher([products_generated.ProductsDocument, variables]);
46
- };
47
- const loopFetchProducts = async (fetcher, { ids, isSample }) => {
48
- const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
49
- const productsPerPage = 8; // number of products per page
50
- let variables; // variables of collection query
51
- let productAfterFetcher; // product after of collection query
52
- let dataProducts; // data of collection query
53
- let hasNextPage; //
54
- let firstProducts;
55
- let currentPage = 1;
56
- // counter number of queries
57
- const pages = Math.ceil(numberOfProducts / productsPerPage);
58
- while (currentPage <= pages && hasNextPage !== false) {
59
- variables = {
60
- first: getCollection.calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
61
- firstMedia: 1,
62
- firstVariant: 1,
63
- orderBy: {
64
- direction: 'DESC',
65
- field: 'UPDATED_AT',
66
- },
67
- orderByMedia: {
68
- field: 'POSITION',
69
- direction: 'ASC',
70
- },
71
- where: {
72
- isStorefront: true,
73
- isSample: isSample,
74
- ...(ids?.length ? { baseIDIn: ids } : {}),
75
- },
76
- after: productAfterFetcher,
77
- };
78
- const pageData = await fetchProducts(fetcher, variables);
79
- productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
80
- if (currentPage === 1) {
81
- dataProducts = pageData; // set data of first page
82
- firstProducts = pageData;
83
- }
84
- else if (firstProducts?.products && pageData?.products?.edges.length) {
85
- // concat new values to the old ones
86
- firstProducts.products = {
87
- edges: firstProducts.products.edges.concat(pageData?.products?.edges),
88
- pageInfo: pageData?.products?.pageInfo,
89
- };
90
- }
91
- currentPage++;
92
- // hasNextPage = false if there is no more pages then break the loop
93
- if (!firstProducts) {
94
- hasNextPage = false;
95
- break;
96
- }
97
- }
98
- return dataProducts;
99
- };
100
- const mergeVariantsToProducts = async (fetcher, products, isSample) => {
101
- const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product) => {
102
- const variants = await getProduct.fetchVariants(fetcher, { id: product?.node?.baseID, isSample });
103
- return {
104
- productId: product?.node?.baseID,
105
- items: variants,
106
- };
107
- }) ?? []);
108
- return productsWithVariants;
109
- };
110
- const mergeMediasToProducts = async (fetcher, products, isSample) => {
111
- const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product) => {
112
- const medias = await getProduct.fetchMedias(fetcher, { id: product?.node?.baseID, isSample });
113
- return {
114
- productId: product?.node?.baseID,
115
- items: medias,
116
- };
117
- }) ?? []);
118
- return productsWithMedias;
119
- };
120
- // future can be used for fetching products with paging ids
121
- // const pagingQuery = (
122
- // data: string[],
123
- // currentPage: number,
124
- // productsPerPage: number,
125
- // first: number,
126
- // ): string[] => {
127
- // return data.slice(
128
- // (currentPage - 1) * productsPerPage,
129
- // (currentPage - 1) * productsPerPage + first,
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
- 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);
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) => (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 (!['symbol', 'object', 'function'].includes(typeof val)) {
17
- if (val) {
18
- propsArr.push(`${attr}="${val}"`);
19
- }
20
- else {
21
- propsArr.push(`${attr}`);
22
- }
23
- }
24
- }
25
- }
26
- return propsArr.join(' ');
27
- };
28
- const styles = (strings, ...keys) => {
29
- const styles = keys[0];
30
- const styleArr = [];
31
- for (const attr in styles) {
32
- if (Object.hasOwnProperty.call(styles, attr)) {
33
- const val = styles[attr];
34
- if (val !== undefined)
35
- styleArr.push(`${attr}:${val}`);
36
- }
37
- }
38
- return styleArr.join(';');
39
- };
40
- const template = (strings, ...keys) => {
41
- let str = '';
42
- strings.forEach((item, index) => {
43
- str += item;
44
- if (keys[index] !== undefined) {
45
- if (isObject(keys[index])) {
46
- if (/style=["|']/.test(item)) {
47
- str += styles `${keys[index]}`;
48
- }
49
- else {
50
- str += props `${keys[index]}`;
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 { 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;
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;