@gem-sdk/core 1.5.15 → 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 +93 -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 +93 -70
  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
@@ -2,130 +2,142 @@ import { ProductsDocument } from '../../graphql/queries/products.generated.js';
2
2
  import { calculateFirstProduct } from './get-collection.js';
3
3
  import { fetchVariants, fetchMedias } from './get-product.js';
4
4
 
5
- const getProducts = async (fetcher, { ids, isSample }) => {
6
- const products = await loopFetchProducts(fetcher, { ids, isSample });
7
- if (!products) {
8
- throw new Error('Product not found');
9
- }
10
- const [mergedVariant, mergedMedias] = await Promise.all([
11
- mergeVariantsToProducts(fetcher, products, isSample),
12
- mergeMediasToProducts(fetcher, products, isSample),
13
- ]);
14
- return {
15
- ...products,
16
- products: {
17
- ...products.products,
18
- edges: products.products?.edges.map((edge) => {
19
- const medias = mergedMedias.find((item) => item.productId === edge.node?.baseID);
20
- const variants = mergedVariant.find((item) => item.productId === edge.node?.baseID);
21
- if (edge.node) {
22
- return {
23
- ...edge,
24
- node: {
25
- ...edge.node,
26
- variants: {
27
- ...edge.node?.variants,
28
- edges: variants?.items ?? [],
29
- },
30
- medias: {
31
- ...edge.node?.medias,
32
- edges: medias?.items ?? [],
33
- },
34
- },
35
- };
36
- }
37
- return edge;
38
- }) ?? [],
39
- },
40
- };
41
- };
42
- const fetchProducts = async (fetcher, variables) => {
43
- return fetcher([ProductsDocument, variables]);
44
- };
45
- const loopFetchProducts = async (fetcher, { ids, isSample }) => {
46
- const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
47
- const productsPerPage = 8; // number of products per page
48
- let variables; // variables of collection query
49
- let productAfterFetcher; // product after of collection query
50
- let dataProducts; // data of collection query
51
- let hasNextPage; //
52
- let firstProducts;
53
- let currentPage = 1;
54
- // counter number of queries
55
- const pages = Math.ceil(numberOfProducts / productsPerPage);
56
- while (currentPage <= pages && hasNextPage !== false) {
57
- variables = {
58
- first: calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
59
- firstMedia: 1,
60
- firstVariant: 1,
61
- orderBy: {
62
- direction: 'DESC',
63
- field: 'UPDATED_AT',
64
- },
65
- orderByMedia: {
66
- field: 'POSITION',
67
- direction: 'ASC',
68
- },
69
- where: {
70
- isStorefront: true,
71
- isSample: isSample,
72
- ...(ids?.length ? { baseIDIn: ids } : {}),
73
- },
74
- after: productAfterFetcher,
75
- };
76
- const pageData = await fetchProducts(fetcher, variables);
77
- productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
78
- if (currentPage === 1) {
79
- dataProducts = pageData; // set data of first page
80
- firstProducts = pageData;
81
- }
82
- else if (firstProducts?.products && pageData?.products?.edges.length) {
83
- // concat new values to the old ones
84
- firstProducts.products = {
85
- edges: firstProducts.products.edges.concat(pageData?.products?.edges),
86
- pageInfo: pageData?.products?.pageInfo,
87
- };
88
- }
89
- currentPage++;
90
- // hasNextPage = false if there is no more pages then break the loop
91
- if (!firstProducts) {
92
- hasNextPage = false;
93
- break;
94
- }
95
- }
96
- return dataProducts;
97
- };
98
- const mergeVariantsToProducts = async (fetcher, products, isSample) => {
99
- const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product) => {
100
- const variants = await fetchVariants(fetcher, { id: product?.node?.baseID, isSample });
101
- return {
102
- productId: product?.node?.baseID,
103
- items: variants,
104
- };
105
- }) ?? []);
106
- return productsWithVariants;
107
- };
108
- const mergeMediasToProducts = async (fetcher, products, isSample) => {
109
- const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product) => {
110
- const medias = await fetchMedias(fetcher, { id: product?.node?.baseID, isSample });
111
- return {
112
- productId: product?.node?.baseID,
113
- items: medias,
114
- };
115
- }) ?? []);
116
- return productsWithMedias;
117
- };
118
- // future can be used for fetching products with paging ids
119
- // const pagingQuery = (
120
- // data: string[],
121
- // currentPage: number,
122
- // productsPerPage: number,
123
- // first: number,
124
- // ): string[] => {
125
- // return data.slice(
126
- // (currentPage - 1) * productsPerPage,
127
- // (currentPage - 1) * productsPerPage + first,
128
- // );
129
- // };
5
+ const getProducts = async (fetcher, { ids , isSample })=>{
6
+ const products = await loopFetchProducts(fetcher, {
7
+ ids,
8
+ isSample
9
+ });
10
+ if (!products) {
11
+ throw new Error('Product not found');
12
+ }
13
+ const [mergedVariant, mergedMedias] = await Promise.all([
14
+ mergeVariantsToProducts(fetcher, products, isSample),
15
+ mergeMediasToProducts(fetcher, products, isSample)
16
+ ]);
17
+ return {
18
+ ...products,
19
+ products: {
20
+ ...products.products,
21
+ edges: products.products?.edges.map((edge)=>{
22
+ const medias = mergedMedias.find((item)=>item.productId === edge.node?.baseID);
23
+ const variants = mergedVariant.find((item)=>item.productId === edge.node?.baseID);
24
+ if (edge.node) {
25
+ return {
26
+ ...edge,
27
+ node: {
28
+ ...edge.node,
29
+ variants: {
30
+ ...edge.node?.variants,
31
+ edges: variants?.items ?? []
32
+ },
33
+ medias: {
34
+ ...edge.node?.medias,
35
+ edges: medias?.items ?? []
36
+ }
37
+ }
38
+ };
39
+ }
40
+ return edge;
41
+ }) ?? []
42
+ }
43
+ };
44
+ };
45
+ const fetchProducts = async (fetcher, variables)=>{
46
+ return fetcher([
47
+ ProductsDocument,
48
+ variables
49
+ ]);
50
+ };
51
+ const loopFetchProducts = async (fetcher, { ids , isSample })=>{
52
+ const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
53
+ const productsPerPage = 8; // number of products per page
54
+ let variables; // variables of collection query
55
+ let productAfterFetcher; // product after of collection query
56
+ let dataProducts; // data of collection query
57
+ let hasNextPage; //
58
+ let firstProducts;
59
+ let currentPage = 1;
60
+ // counter number of queries
61
+ const pages = Math.ceil(numberOfProducts / productsPerPage);
62
+ while(currentPage <= pages && hasNextPage !== false){
63
+ variables = {
64
+ first: calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
65
+ firstMedia: 1,
66
+ firstVariant: 1,
67
+ orderBy: {
68
+ direction: 'DESC',
69
+ field: 'UPDATED_AT'
70
+ },
71
+ orderByMedia: {
72
+ field: 'POSITION',
73
+ direction: 'ASC'
74
+ },
75
+ where: {
76
+ isStorefront: true,
77
+ isSample: isSample,
78
+ ...ids?.length ? {
79
+ baseIDIn: ids
80
+ } : {}
81
+ },
82
+ after: productAfterFetcher
83
+ };
84
+ const pageData = await fetchProducts(fetcher, variables);
85
+ productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
86
+ if (currentPage === 1) {
87
+ dataProducts = pageData; // set data of first page
88
+ firstProducts = pageData;
89
+ } else if (firstProducts?.products && pageData?.products?.edges.length) {
90
+ // concat new values to the old ones
91
+ firstProducts.products = {
92
+ edges: firstProducts.products.edges.concat(pageData?.products?.edges),
93
+ pageInfo: pageData?.products?.pageInfo
94
+ };
95
+ }
96
+ currentPage++;
97
+ // hasNextPage = false if there is no more pages then break the loop
98
+ if (!firstProducts) {
99
+ hasNextPage = false;
100
+ break;
101
+ }
102
+ }
103
+ return dataProducts;
104
+ };
105
+ const mergeVariantsToProducts = async (fetcher, products, isSample)=>{
106
+ const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product)=>{
107
+ const variants = await fetchVariants(fetcher, {
108
+ id: product?.node?.baseID,
109
+ isSample
110
+ });
111
+ return {
112
+ productId: product?.node?.baseID,
113
+ items: variants
114
+ };
115
+ }) ?? []);
116
+ return productsWithVariants;
117
+ };
118
+ const mergeMediasToProducts = async (fetcher, products, isSample)=>{
119
+ const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product)=>{
120
+ const medias = await fetchMedias(fetcher, {
121
+ id: product?.node?.baseID,
122
+ isSample
123
+ });
124
+ return {
125
+ productId: product?.node?.baseID,
126
+ items: medias
127
+ };
128
+ }) ?? []);
129
+ return productsWithMedias;
130
+ }; // future can be used for fetching products with paging ids
131
+ // const pagingQuery = (
132
+ // data: string[],
133
+ // currentPage: number,
134
+ // productsPerPage: number,
135
+ // first: number,
136
+ // ): string[] => {
137
+ // return data.slice(
138
+ // (currentPage - 1) * productsPerPage,
139
+ // (currentPage - 1) * productsPerPage + first,
140
+ // );
141
+ // };
130
142
 
131
143
  export { getProducts };
@@ -1,86 +1,83 @@
1
1
  import { devicesMapping, stateMapping } from './constant.js';
2
2
 
3
- const getRadiusCSSFromGlobal = (state, key, device) => {
4
- if (!key || !state)
5
- return {};
6
- const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
7
- const mState = stateMapping?.[state];
8
- return {
9
- [`-${mState}-radius${suffix}`]: `var(--g-radius-${key})`,
10
- };
11
- };
12
- const getCustomRadius = (state, radius, device) => {
13
- if (!radius || !state)
14
- return {};
15
- const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
16
- const mState = 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)
26
- return {};
27
- if ('desktop' in value || 'tablet' in value || 'mobile' in value) {
28
- return composeRadiusResponsiveState(value);
29
- }
30
- return composeRadiusState(value);
31
- };
32
- const composeRadiusState = (radiusValue, device) => {
33
- const style = {};
34
- switch (radiusValue?.normal?.radiusType) {
35
- case 'medium':
36
- case 'large':
37
- case 'small':
38
- Object.assign(style, getRadiusCSSFromGlobal('normal', radiusValue?.normal?.radiusType, device));
39
- break;
40
- case 'circle':
41
- case 'none':
42
- case 'custom':
43
- Object.assign(style, getCustomRadius('normal', radiusValue.normal, device));
44
- break;
45
- }
46
- switch (radiusValue?.hover?.radiusType) {
47
- case 'medium':
48
- case 'large':
49
- case 'small':
50
- Object.assign(style, getRadiusCSSFromGlobal('hover', radiusValue?.hover?.radiusType, device));
51
- break;
52
- case 'circle':
53
- case 'none':
54
- case 'custom':
55
- Object.assign(style, getCustomRadius('hover', radiusValue.hover, device));
56
- break;
57
- }
58
- switch (radiusValue?.focus?.radiusType) {
59
- case 'medium':
60
- case 'large':
61
- case 'small':
62
- Object.assign(style, getRadiusCSSFromGlobal('focus', radiusValue?.focus?.radiusType, device));
63
- break;
64
- case 'circle':
65
- case 'none':
66
- case 'custom':
67
- Object.assign(style, getCustomRadius('focus', radiusValue.focus, device));
68
- break;
69
- }
70
- return style;
71
- };
72
- const composeRadiusResponsiveState = (radiusValue) => {
73
- const style = {};
74
- Object.assign(style, composeRadiusState(radiusValue?.desktop, 'desktop'));
75
- Object.assign(style, composeRadiusState(radiusValue?.tablet, 'tablet'));
76
- Object.assign(style, composeRadiusState(radiusValue?.mobile, 'mobile'));
77
- return style;
78
- };
79
- const getRadiusStyleActiveState = (radiusValue) => {
80
- if (radiusValue?.active?.radiusType === 'custom') {
81
- return getCustomRadius('normal', radiusValue?.active);
82
- }
83
- return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
3
+ const getRadiusCSSFromGlobal = (state, key, device)=>{
4
+ if (!key || !state) return {};
5
+ const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
6
+ const mState = stateMapping?.[state];
7
+ return {
8
+ [`-${mState}-radius${suffix}`]: `var(--g-radius-${key})`
9
+ };
10
+ };
11
+ const getCustomRadius = (state, radius, device)=>{
12
+ if (!radius || !state) return {};
13
+ const suffix = device && device !== 'desktop' ? devicesMapping?.[device] : '';
14
+ const mState = stateMapping?.[state];
15
+ return {
16
+ [`-${mState}-bblr${suffix}`]: radius.bblr,
17
+ [`-${mState}-bbrr${suffix}`]: radius.bbrr,
18
+ [`-${mState}-btlr${suffix}`]: radius.btlr,
19
+ [`-${mState}-btrr${suffix}`]: radius.btrr
20
+ };
21
+ };
22
+ const composeRadius = (value)=>{
23
+ if (!value) return {};
24
+ if ('desktop' in value || 'tablet' in value || 'mobile' in value) {
25
+ return composeRadiusResponsiveState(value);
26
+ }
27
+ return composeRadiusState(value);
28
+ };
29
+ const composeRadiusState = (radiusValue, device)=>{
30
+ const style = {};
31
+ switch(radiusValue?.normal?.radiusType){
32
+ case 'medium':
33
+ case 'large':
34
+ case 'small':
35
+ Object.assign(style, getRadiusCSSFromGlobal('normal', radiusValue?.normal?.radiusType, device));
36
+ break;
37
+ case 'circle':
38
+ case 'none':
39
+ case 'custom':
40
+ Object.assign(style, getCustomRadius('normal', radiusValue.normal, device));
41
+ break;
42
+ }
43
+ switch(radiusValue?.hover?.radiusType){
44
+ case 'medium':
45
+ case 'large':
46
+ case 'small':
47
+ Object.assign(style, getRadiusCSSFromGlobal('hover', radiusValue?.hover?.radiusType, device));
48
+ break;
49
+ case 'circle':
50
+ case 'none':
51
+ case 'custom':
52
+ Object.assign(style, getCustomRadius('hover', radiusValue.hover, device));
53
+ break;
54
+ }
55
+ switch(radiusValue?.focus?.radiusType){
56
+ case 'medium':
57
+ case 'large':
58
+ case 'small':
59
+ Object.assign(style, getRadiusCSSFromGlobal('focus', radiusValue?.focus?.radiusType, device));
60
+ break;
61
+ case 'circle':
62
+ case 'none':
63
+ case 'custom':
64
+ Object.assign(style, getCustomRadius('focus', radiusValue.focus, device));
65
+ break;
66
+ }
67
+ return style;
68
+ };
69
+ const composeRadiusResponsiveState = (radiusValue)=>{
70
+ const style = {};
71
+ Object.assign(style, composeRadiusState(radiusValue?.desktop, 'desktop'));
72
+ Object.assign(style, composeRadiusState(radiusValue?.tablet, 'tablet'));
73
+ Object.assign(style, composeRadiusState(radiusValue?.mobile, 'mobile'));
74
+ return style;
75
+ };
76
+ const getRadiusStyleActiveState = (radiusValue)=>{
77
+ if (radiusValue?.active?.radiusType === 'custom') {
78
+ return getCustomRadius('normal', radiusValue?.active);
79
+ }
80
+ return getRadiusCSSFromGlobal('normal', radiusValue?.active?.radiusType);
84
81
  };
85
82
 
86
83
  export { composeRadius, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState };
@@ -1,59 +1,59 @@
1
- const RenderIf = (c, t, f) => (c ? (typeof t === 'string' ? t : t()) : (typeof f === 'string' ? f : f?.()) ?? '');
2
- const isObject = (obj) => {
3
- if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) {
4
- return true;
5
- }
6
- return false;
7
- };
8
- const props = (strings, ...keys) => {
9
- const props = keys[0];
10
- const propsArr = [];
11
- for (const attr in props) {
12
- if (Object.hasOwnProperty.call(props, attr)) {
13
- const val = props[attr];
14
- if (!['symbol', 'object', 'function'].includes(typeof val)) {
15
- if (val) {
16
- propsArr.push(`${attr}="${val}"`);
17
- }
18
- else {
19
- propsArr.push(`${attr}`);
20
- }
21
- }
22
- }
23
- }
24
- return propsArr.join(' ');
25
- };
26
- const styles = (strings, ...keys) => {
27
- const styles = keys[0];
28
- const styleArr = [];
29
- for (const attr in styles) {
30
- if (Object.hasOwnProperty.call(styles, attr)) {
31
- const val = styles[attr];
32
- if (val !== undefined)
33
- styleArr.push(`${attr}:${val}`);
34
- }
35
- }
36
- return styleArr.join(';');
37
- };
38
- const template = (strings, ...keys) => {
39
- let str = '';
40
- strings.forEach((item, index) => {
41
- str += item;
42
- if (keys[index] !== undefined) {
43
- if (isObject(keys[index])) {
44
- if (/style=["|']/.test(item)) {
45
- str += styles `${keys[index]}`;
46
- }
47
- else {
48
- str += props `${keys[index]}`;
49
- }
50
- }
51
- else {
52
- str += keys[index];
53
- }
54
- }
55
- });
56
- return str;
1
+ const RenderIf = (c, t, f)=>c ? typeof t === 'string' ? t : t() : (typeof f === 'string' ? f : f?.()) ?? '';
2
+ const isObject = (obj)=>{
3
+ if (typeof obj === 'object' && !Array.isArray(obj) && obj !== null) {
4
+ return true;
5
+ }
6
+ return false;
7
+ };
8
+ const props = (strings, ...keys)=>{
9
+ const props = keys[0];
10
+ const propsArr = [];
11
+ for(const attr in props){
12
+ if (Object.hasOwnProperty.call(props, attr)) {
13
+ const val = props[attr];
14
+ if (![
15
+ 'symbol',
16
+ 'object',
17
+ 'function'
18
+ ].includes(typeof val)) {
19
+ if (val) {
20
+ propsArr.push(`${attr}="${val}"`);
21
+ } else {
22
+ propsArr.push(`${attr}`);
23
+ }
24
+ }
25
+ }
26
+ }
27
+ return propsArr.join(' ');
28
+ };
29
+ const styles = (strings, ...keys)=>{
30
+ const styles = keys[0];
31
+ const styleArr = [];
32
+ for(const attr in styles){
33
+ if (Object.hasOwnProperty.call(styles, attr)) {
34
+ const val = styles[attr];
35
+ if (val !== undefined) 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
+ } else {
49
+ str += props`${keys[index]}`;
50
+ }
51
+ } else {
52
+ str += keys[index];
53
+ }
54
+ }
55
+ });
56
+ return str;
57
57
  };
58
58
 
59
59
  export { RenderIf, props, styles, template };
@@ -2,44 +2,44 @@ import { getSingleColorVariable } from './colors.js';
2
2
  import { stateMapping } from './constant.js';
3
3
  import { getShortName } from './get-shortname.js';
4
4
 
5
- const parseValueWithUnit = (valueWithUnit) => {
6
- const matches = valueWithUnit.match(/(\d+)(.+)/);
7
- if (matches && matches.length === 3) {
8
- const value = Number(matches[1] ?? 0);
9
- const unit = matches[2];
10
- return { value, unit: unit ?? 'px' };
11
- }
12
- return { value: 0, unit: 'px' };
13
- };
14
- const getStyleShadow = (shadowStyle, isActiveState = false) => {
15
- const { styleAppliedFor, value, isEnableShadow } = shadowStyle || {};
16
- let { state } = shadowStyle || {};
17
- if (!state)
18
- state = 'normal';
19
- if (!styleAppliedFor || !value)
20
- return {};
21
- if (typeof value.distance == 'undefined')
22
- return {};
23
- const { value: distance, unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
24
- return {
25
- [`-${!isActiveState ? stateMapping?.[state] : ''}-${getShortName(styleAppliedFor)}`]: isEnableShadow
26
- ? `${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 + ' ' : ''}${getSingleColorVariable(value?.color)}`
27
- : 'none',
28
- };
29
- };
30
- const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow) => {
31
- if (!shadow || !styleAppliedFor)
32
- return {};
33
- const style = {};
34
- for (const [key, value] of Object.entries(shadow)) {
35
- Object.assign(style, getStyleShadow({
36
- value: value,
37
- state: key,
38
- styleAppliedFor,
39
- isEnableShadow: isEnableShadow?.[key],
40
- }));
41
- }
42
- return style;
5
+ const parseValueWithUnit = (valueWithUnit)=>{
6
+ const matches = valueWithUnit.match(/(\d+)(.+)/);
7
+ if (matches && matches.length === 3) {
8
+ const value = Number(matches[1] ?? 0);
9
+ const unit = matches[2];
10
+ return {
11
+ value,
12
+ unit: unit ?? 'px'
13
+ };
14
+ }
15
+ return {
16
+ value: 0,
17
+ unit: 'px'
18
+ };
19
+ };
20
+ const getStyleShadow = (shadowStyle, isActiveState = false)=>{
21
+ const { styleAppliedFor , value , isEnableShadow } = shadowStyle || {};
22
+ let { state } = shadowStyle || {};
23
+ if (!state) state = 'normal';
24
+ if (!styleAppliedFor || !value) return {};
25
+ if (typeof value.distance == 'undefined') return {};
26
+ const { value: distance , unit: unitDistance } = parseValueWithUnit(`${value?.distance}`);
27
+ return {
28
+ [`-${!isActiveState ? stateMapping?.[state] : ''}-${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 + ' ' : ''}${getSingleColorVariable(value?.color)}` : 'none'
29
+ };
30
+ };
31
+ const getStyleShadowState = (shadow, styleAppliedFor, isEnableShadow)=>{
32
+ if (!shadow || !styleAppliedFor) return {};
33
+ const style = {};
34
+ for (const [key, value] of Object.entries(shadow)){
35
+ Object.assign(style, getStyleShadow({
36
+ value: value,
37
+ state: key,
38
+ styleAppliedFor,
39
+ isEnableShadow: isEnableShadow?.[key]
40
+ }));
41
+ }
42
+ return style;
43
43
  };
44
44
 
45
45
  export { getStyleShadow, getStyleShadowState };