@gem-sdk/core 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (214) hide show
  1. package/dist/cjs/components/AddOn.js +18 -0
  2. package/dist/cjs/components/ComponentWrapper.js +45 -0
  3. package/dist/cjs/components/ComponentWrapperPreview.js +58 -0
  4. package/dist/cjs/components/Empty.js +7 -0
  5. package/dist/cjs/components/Render.js +28 -0
  6. package/dist/cjs/components/RenderBlock.js +21 -0
  7. package/dist/cjs/components/RenderPreview.js +28 -0
  8. package/dist/cjs/components/RenderSection.js +19 -0
  9. package/dist/cjs/contexts/AddonContext.js +25 -0
  10. package/dist/cjs/contexts/BuilderComponent.js +30 -0
  11. package/dist/cjs/contexts/BuilderContext.js +29 -0
  12. package/dist/cjs/contexts/BuilderPreviewContext.js +353 -0
  13. package/dist/cjs/contexts/CartLineContext.js +24 -0
  14. package/dist/cjs/contexts/CollectionContext.js +24 -0
  15. package/dist/cjs/contexts/ProductContext.js +126 -0
  16. package/dist/cjs/contexts/ProductListContext.js +24 -0
  17. package/dist/cjs/contexts/SectionContext.js +49 -0
  18. package/dist/cjs/contexts/ShopContext.js +43 -0
  19. package/dist/cjs/graphql/fragments/analytic.generated.js +11 -0
  20. package/dist/cjs/graphql/fragments/collection-detail.generated.js +13 -0
  21. package/dist/cjs/graphql/fragments/collection-product.generated.js +26 -0
  22. package/dist/cjs/graphql/fragments/data-seo.generated.js +11 -0
  23. package/dist/cjs/graphql/fragments/media.generated.js +14 -0
  24. package/dist/cjs/graphql/fragments/product-little.generated.js +25 -0
  25. package/dist/cjs/graphql/fragments/product-option-value.generated.js +13 -0
  26. package/dist/cjs/graphql/fragments/product-option.generated.js +14 -0
  27. package/dist/cjs/graphql/fragments/product.generated.js +33 -0
  28. package/dist/cjs/graphql/fragments/published-custom-section.generated.js +12 -0
  29. package/dist/cjs/graphql/fragments/published-page-section.generated.js +11 -0
  30. package/dist/cjs/graphql/fragments/published-theme-page.generated.js +27 -0
  31. package/dist/cjs/graphql/fragments/published-theme-style.generated.js +11 -0
  32. package/dist/cjs/graphql/fragments/selected-option.generated.js +11 -0
  33. package/dist/cjs/graphql/fragments/variant.generated.js +35 -0
  34. package/dist/cjs/graphql/queries/collection-detail-filter.generated.js +34 -0
  35. package/dist/cjs/graphql/queries/collection.generated.js +52 -0
  36. package/dist/cjs/graphql/queries/preview-page.generated.js +23 -0
  37. package/dist/cjs/graphql/queries/product-little-detail.generated.js +24 -0
  38. package/dist/cjs/graphql/queries/product-medias.generated.js +29 -0
  39. package/dist/cjs/graphql/queries/product-variants.generated.js +33 -0
  40. package/dist/cjs/graphql/queries/products.generated.js +41 -0
  41. package/dist/cjs/graphql/queries/published-theme-pages.generated.js +23 -0
  42. package/dist/cjs/graphql/queries/storeProperty.generated.js +12 -0
  43. package/dist/cjs/helpers/GlobalEvent.js +17 -0
  44. package/dist/cjs/helpers/background.js +104 -0
  45. package/dist/cjs/helpers/borders.js +138 -0
  46. package/dist/cjs/helpers/clone-deep.js +5 -0
  47. package/dist/cjs/helpers/cls.js +20 -0
  48. package/dist/cjs/helpers/colors.js +157 -0
  49. package/dist/cjs/helpers/compose-advance-style.js +132 -0
  50. package/dist/cjs/helpers/constant.js +17 -0
  51. package/dist/cjs/helpers/css-variable.js +7 -0
  52. package/dist/cjs/helpers/email.js +11 -0
  53. package/dist/cjs/helpers/flatten-connection.js +10 -0
  54. package/dist/cjs/helpers/fpixel.js +29 -0
  55. package/dist/cjs/helpers/get-resonsive-value.js +32 -0
  56. package/dist/cjs/helpers/get-shortname.js +92 -0
  57. package/dist/cjs/helpers/gtag.js +48 -0
  58. package/dist/cjs/helpers/is-browser.js +9 -0
  59. package/dist/cjs/helpers/is-defined.js +7 -0
  60. package/dist/cjs/helpers/is-empty-children.js +12 -0
  61. package/dist/cjs/helpers/layout.js +17 -0
  62. package/dist/cjs/helpers/load-script.js +32 -0
  63. package/dist/cjs/helpers/make-style.js +99 -0
  64. package/dist/cjs/helpers/normalize-builder-data.js +17 -0
  65. package/dist/cjs/helpers/prefetch-queries.js +68 -0
  66. package/dist/cjs/helpers/product.js +35 -0
  67. package/dist/cjs/helpers/queries/get-collection.js +173 -0
  68. package/dist/cjs/helpers/queries/get-product-by-slug.js +99 -0
  69. package/dist/cjs/helpers/queries/get-product.js +113 -0
  70. package/dist/cjs/helpers/queries/get-products.js +135 -0
  71. package/dist/cjs/helpers/radius.js +91 -0
  72. package/dist/cjs/helpers/shadow.js +48 -0
  73. package/dist/cjs/helpers/size.js +20 -0
  74. package/dist/cjs/helpers/spacing.js +45 -0
  75. package/dist/cjs/helpers/tiktokpixel.js +17 -0
  76. package/dist/cjs/helpers/typography.js +7 -0
  77. package/dist/cjs/hooks/cart/use-add-to-cart.js +20 -0
  78. package/dist/cjs/hooks/cart/use-cart-data.js +26 -0
  79. package/dist/cjs/hooks/cart/use-cart-discount-codes-update.js +20 -0
  80. package/dist/cjs/hooks/cart/use-cart-note-update.js +20 -0
  81. package/dist/cjs/hooks/cart/use-create-cart.js +22 -0
  82. package/dist/cjs/hooks/cart/use-remove-cart-item.js +20 -0
  83. package/dist/cjs/hooks/cart/use-update-cart-item.js +20 -0
  84. package/dist/cjs/hooks/shop/use-collection-query.js +16 -0
  85. package/dist/cjs/hooks/shop/use-product-query.js +16 -0
  86. package/dist/cjs/hooks/shop/use-products-query.js +16 -0
  87. package/dist/cjs/hooks/shop.js +80 -0
  88. package/dist/cjs/hooks/use-current-device.js +23 -0
  89. package/dist/cjs/hooks/use-lazy-video.js +15 -0
  90. package/dist/cjs/hooks/useCartId.js +36 -0
  91. package/dist/cjs/hooks/useCartLine.js +11 -0
  92. package/dist/cjs/hooks/useCartUI.js +42 -0
  93. package/dist/cjs/hooks/useCollection.js +9 -0
  94. package/dist/cjs/hooks/useFetchHandle.js +13 -0
  95. package/dist/cjs/hooks/useFormatMoney.js +17 -0
  96. package/dist/cjs/hooks/useIsomorphicLayoutEffect.js +10 -0
  97. package/dist/cjs/hooks/useLoadScript.js +30 -0
  98. package/dist/cjs/hooks/useMoney.js +52 -0
  99. package/dist/cjs/hooks/usePrevious.js +17 -0
  100. package/dist/cjs/hooks/useProduct.js +90 -0
  101. package/dist/cjs/hooks/useProductList.js +21 -0
  102. package/dist/cjs/hooks/useSuspenseFetch.js +24 -0
  103. package/dist/cjs/hooks/useSwatchesOptions.js +39 -0
  104. package/dist/cjs/index.js +229 -0
  105. package/dist/cjs/types/global-style.js +7 -0
  106. package/dist/cjs/types/shop.js +2 -0
  107. package/dist/esm/components/AddOn.js +14 -0
  108. package/dist/esm/components/ComponentWrapper.js +40 -0
  109. package/dist/esm/components/ComponentWrapperPreview.js +54 -0
  110. package/dist/esm/components/Empty.js +3 -0
  111. package/dist/esm/components/Render.js +24 -0
  112. package/dist/esm/components/RenderBlock.js +17 -0
  113. package/dist/esm/components/RenderPreview.js +24 -0
  114. package/dist/esm/components/RenderSection.js +15 -0
  115. package/dist/esm/contexts/AddonContext.js +21 -0
  116. package/dist/esm/contexts/BuilderComponent.js +27 -0
  117. package/dist/esm/contexts/BuilderContext.js +26 -0
  118. package/dist/esm/contexts/BuilderPreviewContext.js +350 -0
  119. package/dist/esm/contexts/CartLineContext.js +21 -0
  120. package/dist/esm/contexts/CollectionContext.js +20 -0
  121. package/dist/esm/contexts/ProductContext.js +123 -0
  122. package/dist/esm/contexts/ProductListContext.js +20 -0
  123. package/dist/esm/contexts/SectionContext.js +45 -0
  124. package/dist/esm/contexts/ShopContext.js +40 -0
  125. package/dist/esm/graphql/fragments/analytic.generated.js +9 -0
  126. package/dist/esm/graphql/fragments/collection-detail.generated.js +11 -0
  127. package/dist/esm/graphql/fragments/collection-product.generated.js +24 -0
  128. package/dist/esm/graphql/fragments/data-seo.generated.js +9 -0
  129. package/dist/esm/graphql/fragments/media.generated.js +12 -0
  130. package/dist/esm/graphql/fragments/product-little.generated.js +23 -0
  131. package/dist/esm/graphql/fragments/product-option-value.generated.js +11 -0
  132. package/dist/esm/graphql/fragments/product-option.generated.js +12 -0
  133. package/dist/esm/graphql/fragments/product.generated.js +31 -0
  134. package/dist/esm/graphql/fragments/published-custom-section.generated.js +10 -0
  135. package/dist/esm/graphql/fragments/published-page-section.generated.js +9 -0
  136. package/dist/esm/graphql/fragments/published-theme-page.generated.js +25 -0
  137. package/dist/esm/graphql/fragments/published-theme-style.generated.js +9 -0
  138. package/dist/esm/graphql/fragments/selected-option.generated.js +9 -0
  139. package/dist/esm/graphql/fragments/variant.generated.js +33 -0
  140. package/dist/esm/graphql/queries/collection-detail-filter.generated.js +32 -0
  141. package/dist/esm/graphql/queries/collection.generated.js +50 -0
  142. package/dist/esm/graphql/queries/preview-page.generated.js +21 -0
  143. package/dist/esm/graphql/queries/product-little-detail.generated.js +22 -0
  144. package/dist/esm/graphql/queries/product-medias.generated.js +27 -0
  145. package/dist/esm/graphql/queries/product-variants.generated.js +31 -0
  146. package/dist/esm/graphql/queries/products.generated.js +38 -0
  147. package/dist/esm/graphql/queries/published-theme-pages.generated.js +21 -0
  148. package/dist/esm/graphql/queries/storeProperty.generated.js +10 -0
  149. package/dist/esm/helpers/GlobalEvent.js +13 -0
  150. package/dist/esm/helpers/background.js +102 -0
  151. package/dist/esm/helpers/borders.js +133 -0
  152. package/dist/esm/helpers/clone-deep.js +3 -0
  153. package/dist/esm/helpers/cls.js +18 -0
  154. package/dist/esm/helpers/colors.js +145 -0
  155. package/dist/esm/helpers/compose-advance-style.js +130 -0
  156. package/dist/esm/helpers/constant.js +13 -0
  157. package/dist/esm/helpers/css-variable.js +5 -0
  158. package/dist/esm/helpers/email.js +6 -0
  159. package/dist/esm/helpers/flatten-connection.js +8 -0
  160. package/dist/esm/helpers/fpixel.js +25 -0
  161. package/dist/esm/helpers/get-resonsive-value.js +28 -0
  162. package/dist/esm/helpers/get-shortname.js +90 -0
  163. package/dist/esm/helpers/gtag.js +45 -0
  164. package/dist/esm/helpers/is-browser.js +5 -0
  165. package/dist/esm/helpers/is-defined.js +5 -0
  166. package/dist/esm/helpers/is-empty-children.js +7 -0
  167. package/dist/esm/helpers/layout.js +15 -0
  168. package/dist/esm/helpers/load-script.js +30 -0
  169. package/dist/esm/helpers/make-style.js +91 -0
  170. package/dist/esm/helpers/normalize-builder-data.js +15 -0
  171. package/dist/esm/helpers/prefetch-queries.js +66 -0
  172. package/dist/esm/helpers/product.js +32 -0
  173. package/dist/esm/helpers/queries/get-collection.js +170 -0
  174. package/dist/esm/helpers/queries/get-product-by-slug.js +97 -0
  175. package/dist/esm/helpers/queries/get-product.js +109 -0
  176. package/dist/esm/helpers/queries/get-products.js +133 -0
  177. package/dist/esm/helpers/radius.js +86 -0
  178. package/dist/esm/helpers/shadow.js +45 -0
  179. package/dist/esm/helpers/size.js +18 -0
  180. package/dist/esm/helpers/spacing.js +42 -0
  181. package/dist/esm/helpers/tiktokpixel.js +15 -0
  182. package/dist/esm/helpers/typography.js +5 -0
  183. package/dist/esm/hooks/cart/use-add-to-cart.js +18 -0
  184. package/dist/esm/hooks/cart/use-cart-data.js +24 -0
  185. package/dist/esm/hooks/cart/use-cart-discount-codes-update.js +18 -0
  186. package/dist/esm/hooks/cart/use-cart-note-update.js +18 -0
  187. package/dist/esm/hooks/cart/use-create-cart.js +20 -0
  188. package/dist/esm/hooks/cart/use-remove-cart-item.js +18 -0
  189. package/dist/esm/hooks/cart/use-update-cart-item.js +18 -0
  190. package/dist/esm/hooks/shop/use-collection-query.js +14 -0
  191. package/dist/esm/hooks/shop/use-product-query.js +14 -0
  192. package/dist/esm/hooks/shop/use-products-query.js +14 -0
  193. package/dist/esm/hooks/shop.js +68 -0
  194. package/dist/esm/hooks/use-current-device.js +21 -0
  195. package/dist/esm/hooks/use-lazy-video.js +13 -0
  196. package/dist/esm/hooks/useCartId.js +32 -0
  197. package/dist/esm/hooks/useCartLine.js +7 -0
  198. package/dist/esm/hooks/useCartUI.js +38 -0
  199. package/dist/esm/hooks/useCollection.js +7 -0
  200. package/dist/esm/hooks/useFetchHandle.js +11 -0
  201. package/dist/esm/hooks/useFormatMoney.js +13 -0
  202. package/dist/esm/hooks/useIsomorphicLayoutEffect.js +6 -0
  203. package/dist/esm/hooks/useLoadScript.js +26 -0
  204. package/dist/esm/hooks/useMoney.js +48 -0
  205. package/dist/esm/hooks/usePrevious.js +15 -0
  206. package/dist/esm/hooks/useProduct.js +78 -0
  207. package/dist/esm/hooks/useProductList.js +16 -0
  208. package/dist/esm/hooks/useSuspenseFetch.js +20 -0
  209. package/dist/esm/hooks/useSwatchesOptions.js +35 -0
  210. package/dist/esm/index.js +82 -0
  211. package/dist/esm/types/global-style.js +4 -0
  212. package/dist/esm/types/shop.js +1 -0
  213. package/dist/types/index.d.ts +7393 -0
  214. package/package.json +50 -0
@@ -0,0 +1,133 @@
1
+ import { ProductsDocument } from '../../graphql/queries/products.generated.js';
2
+ import { calculateFirstProduct } from './get-collection.js';
3
+ import { fetchVariants, fetchMedias } from './get-product.js';
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 { ...mergedMedias, ...mergedVariant };
15
+ };
16
+ const fetchProducts = async (fetcher, variables) => {
17
+ return fetcher([ProductsDocument, variables]);
18
+ };
19
+ const loopFetchProducts = async (fetcher, { ids, isSample }) => {
20
+ const numberOfProducts = (ids?.length == 0 ? 4 : ids?.length) ?? 4;
21
+ const productsPerPage = 8; // number of products per page
22
+ let variables; // variables of collection query
23
+ let productAfterFetcher; // product after of collection query
24
+ let dataProducts; // data of collection query
25
+ let hasNextPage; //
26
+ let firstProducts;
27
+ let currentPage = 1;
28
+ // counter number of queries
29
+ const pages = Math.ceil(numberOfProducts / productsPerPage);
30
+ while (currentPage <= pages && hasNextPage !== false) {
31
+ variables = {
32
+ first: calculateFirstProduct(numberOfProducts, currentPage, productsPerPage),
33
+ firstMedia: 1,
34
+ firstVariant: 1,
35
+ orderBy: {
36
+ direction: 'DESC',
37
+ field: 'UPDATED_AT',
38
+ },
39
+ where: {
40
+ isStorefront: true,
41
+ isSample: isSample,
42
+ ...(ids?.length ? { baseIDIn: ids.sort() } : {}),
43
+ },
44
+ after: productAfterFetcher,
45
+ };
46
+ const pageData = await fetchProducts(fetcher, variables);
47
+ productAfterFetcher = pageData?.products?.pageInfo?.endCursor;
48
+ if (currentPage === 1) {
49
+ dataProducts = pageData; // set data of first page
50
+ firstProducts = pageData;
51
+ }
52
+ else if (firstProducts?.products && pageData?.products?.edges.length) {
53
+ // concat new values to the old ones
54
+ firstProducts.products = {
55
+ edges: firstProducts.products.edges.concat(pageData?.products?.edges),
56
+ pageInfo: pageData?.products?.pageInfo,
57
+ };
58
+ }
59
+ currentPage++;
60
+ // hasNextPage = false if there is no more pages then break the loop
61
+ if (!firstProducts) {
62
+ hasNextPage = false;
63
+ break;
64
+ }
65
+ }
66
+ return dataProducts;
67
+ };
68
+ const mergeVariantsToProducts = async (fetcher, products, isSample) => {
69
+ const productsWithVariants = await Promise.all(products?.products?.edges?.map(async (product) => {
70
+ return fetchVariants(fetcher, { id: product?.node?.baseID, isSample }).then((variants) => {
71
+ const res = {
72
+ ...product,
73
+ ...(product.node
74
+ ? {
75
+ node: {
76
+ ...product.node,
77
+ variants: variants.length ? { edges: variants } : undefined,
78
+ },
79
+ }
80
+ : {}),
81
+ };
82
+ return res;
83
+ });
84
+ }) ?? []).then((res) => {
85
+ return {
86
+ products: {
87
+ edges: res,
88
+ pageInfo: products?.products?.pageInfo,
89
+ },
90
+ };
91
+ });
92
+ return productsWithVariants;
93
+ };
94
+ const mergeMediasToProducts = async (fetcher, products, isSample) => {
95
+ const productsWithMedias = await Promise.all(products?.products?.edges?.map(async (product) => {
96
+ return fetchMedias(fetcher, { id: product?.node?.baseID, isSample }).then((media) => {
97
+ const res = {
98
+ ...product,
99
+ ...(product.node
100
+ ? {
101
+ node: {
102
+ ...product.node,
103
+ medias: media.length ? { edges: media } : undefined,
104
+ },
105
+ }
106
+ : {}),
107
+ };
108
+ return res;
109
+ });
110
+ }) ?? []).then((res) => {
111
+ return {
112
+ products: {
113
+ edges: res,
114
+ pageInfo: products?.products?.pageInfo,
115
+ },
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
+ // };
132
+
133
+ export { getProducts };
@@ -0,0 +1,86 @@
1
+ import { devicesMapping, stateMapping } from './constant.js';
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);
84
+ };
85
+
86
+ export { composeRadius, getCustomRadius, getRadiusCSSFromGlobal, getRadiusStyleActiveState };
@@ -0,0 +1,45 @@
1
+ import { getSingleColorVariable } from './colors.js';
2
+ import { stateMapping } from './constant.js';
3
+ import { getShortName } from './get-shortname.js';
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;
43
+ };
44
+
45
+ export { getStyleShadow, getStyleShadowState };
@@ -0,0 +1,18 @@
1
+ import { devicesMapping } from './constant.js';
2
+
3
+ function getCustomSizeCSSByDevice(size, device) {
4
+ if (!size || !device)
5
+ return {};
6
+ const suffix = devicesMapping[device] ?? '';
7
+ return {
8
+ [`--pl${suffix}`]: size?.[device]?.horizontal,
9
+ [`--pr${suffix}`]: size?.[device]?.horizontal,
10
+ [`--pt${suffix}`]: size?.[device]?.vertical,
11
+ [`--pb${suffix}`]: size?.[device]?.vertical,
12
+ };
13
+ }
14
+ const composeSize = (size) => {
15
+ return Object.assign({}, getCustomSizeCSSByDevice(size, 'desktop'), getCustomSizeCSSByDevice(size, 'tablet'), getCustomSizeCSSByDevice(size, 'mobile'));
16
+ };
17
+
18
+ export { composeSize };
@@ -0,0 +1,42 @@
1
+ import { devicesMapping } from './constant.js';
2
+
3
+ function getSpacingCSSByType(key, device) {
4
+ if (!key)
5
+ return {};
6
+ const suffix = device ? devicesMapping?.[device] ?? '' : '';
7
+ return {
8
+ [`--p${suffix}`]: `var(--g-s-${key})`,
9
+ };
10
+ }
11
+ function getSpacingVariable(key) {
12
+ if (!key)
13
+ return '';
14
+ return `var(--g-s-${key})`;
15
+ }
16
+ const composeSpacing = (spacingValue) => {
17
+ const style = {};
18
+ switch (spacingValue?.desktop) {
19
+ case 'm':
20
+ case 'l':
21
+ case 's':
22
+ Object.assign(style, getSpacingCSSByType(spacingValue.desktop));
23
+ break;
24
+ }
25
+ switch (spacingValue?.tablet) {
26
+ case 'm':
27
+ case 'l':
28
+ case 's':
29
+ Object.assign(style, getSpacingCSSByType(spacingValue.tablet, 'tablet'));
30
+ break;
31
+ }
32
+ switch (spacingValue?.mobile) {
33
+ case 'm':
34
+ case 'l':
35
+ case 's':
36
+ Object.assign(style, getSpacingCSSByType(spacingValue.mobile, 'mobile'));
37
+ break;
38
+ }
39
+ return style;
40
+ };
41
+
42
+ export { composeSpacing, getSpacingVariable };
@@ -0,0 +1,15 @@
1
+ const addToCart = (product) => {
2
+ if (!window?.ttq?.track)
3
+ return;
4
+ window.ttq.track('AddToCart', {
5
+ content_id: product.id,
6
+ content_type: 'product',
7
+ content_name: product.name,
8
+ quantity: product.quantity,
9
+ price: product.price,
10
+ value: (product.price ?? 0) * (product.quantity ?? 0),
11
+ currency: product.currency,
12
+ });
13
+ };
14
+
15
+ export { addToCart };
@@ -0,0 +1,5 @@
1
+ const genTypoClass = (name) => {
2
+ return `g-${name}`;
3
+ };
4
+
5
+ export { genTypoClass };
@@ -0,0 +1,18 @@
1
+ import { addToCartOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useAddToCart = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('add-to-cart', (_, { arg }) => addToCartOperation(shop)(arg), {
10
+ ...options,
11
+ onSuccess: (result, key, config) => {
12
+ mutate('cart', result, false);
13
+ options?.onSuccess?.(result, key, config);
14
+ },
15
+ });
16
+ };
17
+
18
+ export { useAddToCart };
@@ -0,0 +1,24 @@
1
+ import { getCartOperation } from '@gem-sdk/adapter-shopify';
2
+ import useSWR from 'swr';
3
+ import { useStoreFront } from '../shop.js';
4
+ import useCartId from '../useCartId.js';
5
+
6
+ const useCartData = (options) => {
7
+ const { cartId, clearCartId } = useCartId();
8
+ const shop = useStoreFront();
9
+ return useSWR(cartId ? 'cart' : null, () => getCartOperation(shop)({ cartId: cartId }), {
10
+ revalidateOnMount: true,
11
+ revalidateOnFocus: true,
12
+ keepPreviousData: false,
13
+ dedupingInterval: 2000,
14
+ ...options,
15
+ onSuccess(data, key, config) {
16
+ if (!data) {
17
+ clearCartId();
18
+ }
19
+ options?.onSuccess?.(data, key, config);
20
+ },
21
+ });
22
+ };
23
+
24
+ export { useCartData };
@@ -0,0 +1,18 @@
1
+ import { cartDiscountCodesUpdateOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useCartDiscountCodesUpdate = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('cart-discount-codes-update', (_, { arg }) => cartDiscountCodesUpdateOperation(shop)(arg), {
10
+ ...options,
11
+ onSuccess: (result, key, config) => {
12
+ mutate('cart', result, false);
13
+ options?.onSuccess?.(result, key, config);
14
+ },
15
+ });
16
+ };
17
+
18
+ export { useCartDiscountCodesUpdate };
@@ -0,0 +1,18 @@
1
+ import { cartNoteUpdateOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useCartNoteUpdate = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('cart-note-update', (_, { arg }) => cartNoteUpdateOperation(shop)(arg), {
10
+ ...options,
11
+ onSuccess: (result, key, config) => {
12
+ mutate('cart', result, false);
13
+ options?.onSuccess?.(result, key, config);
14
+ },
15
+ });
16
+ };
17
+
18
+ export { useCartNoteUpdate };
@@ -0,0 +1,20 @@
1
+ import { createCartOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useCreateCart = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('create-cart', (_, { arg }) => {
10
+ return createCartOperation(shop)(arg);
11
+ }, {
12
+ ...options,
13
+ onSuccess: (result, key, config) => {
14
+ mutate('cart', result, false);
15
+ options?.onSuccess?.(result, key, config);
16
+ },
17
+ });
18
+ };
19
+
20
+ export { useCreateCart };
@@ -0,0 +1,18 @@
1
+ import { removeCartItemOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useRemoveCartItem = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('remove-cart-item', (_, { arg }) => removeCartItemOperation(shop)(arg), {
10
+ ...options,
11
+ onSuccess: (result, key, config) => {
12
+ mutate('cart', result, false);
13
+ options?.onSuccess?.(result, key, config);
14
+ },
15
+ });
16
+ };
17
+
18
+ export { useRemoveCartItem };
@@ -0,0 +1,18 @@
1
+ import { updateCartLineOperation } from '@gem-sdk/adapter-shopify';
2
+ import { useSWRConfig } from 'swr';
3
+ import useSWRMutation from 'swr/mutation';
4
+ import { useStoreFront } from '../shop.js';
5
+
6
+ const useUpdateCartItem = (options) => {
7
+ const shop = useStoreFront();
8
+ const { mutate } = useSWRConfig();
9
+ return useSWRMutation('update-cart-item', (_, { arg }) => updateCartLineOperation(shop)(arg), {
10
+ ...options,
11
+ onSuccess: (result, key, config) => {
12
+ mutate('cart', result, false);
13
+ options?.onSuccess?.(result, key, config);
14
+ },
15
+ });
16
+ };
17
+
18
+ export { useUpdateCartItem };
@@ -0,0 +1,14 @@
1
+ import useSWR from 'swr';
2
+ import { getCollection } from '../../helpers/queries/get-collection.js';
3
+ import { useIsSampleProduct } from '../shop.js';
4
+ import { useFetchHandle } from '../useFetchHandle.js';
5
+
6
+ const useCollectionQuery = (args, options) => {
7
+ const fetcher = useFetchHandle();
8
+ const isSample = useIsSampleProduct();
9
+ return useSWR(['query/collection', { ...args, isSample }], ([, arg]) => {
10
+ return getCollection(fetcher, arg);
11
+ }, options);
12
+ };
13
+
14
+ export { useCollectionQuery };
@@ -0,0 +1,14 @@
1
+ import useSWR from 'swr';
2
+ import { getProduct } from '../../helpers/queries/get-product.js';
3
+ import { useIsSampleProduct } from '../shop.js';
4
+ import { useFetchHandle } from '../useFetchHandle.js';
5
+
6
+ const useProductQuery = (productId, options) => {
7
+ const fetcher = useFetchHandle();
8
+ const isSample = useIsSampleProduct();
9
+ return useSWR(productId ? ['query/product', { id: productId ?? 'latest', isSample }] : null, async ([, arg]) => {
10
+ return getProduct(fetcher, arg);
11
+ }, options);
12
+ };
13
+
14
+ export { useProductQuery };
@@ -0,0 +1,14 @@
1
+ import useSWR from 'swr';
2
+ import { getProducts } from '../../helpers/queries/get-products.js';
3
+ import { useIsSampleProduct } from '../shop.js';
4
+ import { useFetchHandle } from '../useFetchHandle.js';
5
+
6
+ const useProductsQuery = (ids, options) => {
7
+ const fetcher = useFetchHandle();
8
+ const isSample = useIsSampleProduct();
9
+ return useSWR(['query/products', { ids, isSample }], async ([, arg]) => {
10
+ return getProducts(fetcher, arg);
11
+ }, options);
12
+ };
13
+
14
+ export { useProductsQuery };
@@ -0,0 +1,68 @@
1
+ import { useMemo } from 'react';
2
+ import { useSWRConfig } from 'swr';
3
+ import { useShopStore } from '../contexts/ShopContext.js';
4
+
5
+ const useLocale = () => {
6
+ const locale = useShopStore((state) => state.locale);
7
+ const changeLocale = useShopStore((state) => state.changeLocale);
8
+ return useMemo(() => ({ locale, changeLocale }), [locale, changeLocale]);
9
+ };
10
+ const useCurrency = () => {
11
+ const currency = useShopStore((state) => state.currency);
12
+ const changeCurrency = useShopStore((state) => state.changeCurrency);
13
+ return useMemo(() => ({ currency, changeCurrency }), [currency, changeCurrency]);
14
+ };
15
+ const useSwatches = () => {
16
+ const swatches = useShopStore((state) => state.swatches);
17
+ const changeSwatches = useShopStore((state) => state.changeSwatches);
18
+ return useMemo(() => ({ swatches, changeSwatches }), [swatches, changeSwatches]);
19
+ };
20
+ const usePageType = () => {
21
+ const pageType = useShopStore((state) => state.pageType);
22
+ return useMemo(() => pageType || 'STATIC', [pageType]);
23
+ };
24
+ const useStoreFront = () => {
25
+ const provider = useShopStore((state) => state.provider);
26
+ const storefrontToken = useShopStore((state) => state.storefrontToken);
27
+ const storefrontUrl = useShopStore((state) => state.storefrontUrl);
28
+ return {
29
+ provider,
30
+ storefrontToken,
31
+ storefrontUrl,
32
+ };
33
+ };
34
+ const usePluginEnable = () => {
35
+ return useShopStore((state) => state.plugins);
36
+ };
37
+ const useEditorMode = () => {
38
+ return useShopStore((state) => state.mode);
39
+ };
40
+ const useMobileOnly = () => {
41
+ return useShopStore((state) => state.mobileOnly);
42
+ };
43
+ const useMatchMutate = () => {
44
+ const { cache, mutate } = useSWRConfig();
45
+ return (matcher, ...args) => {
46
+ if (!(cache instanceof Map)) {
47
+ throw new Error('matchMutate requires the cache provider to be a Map instance');
48
+ }
49
+ const keys = [];
50
+ cache.forEach((_, key) => {
51
+ if (matcher.test(key)) {
52
+ keys.push(key);
53
+ }
54
+ });
55
+ const mutations = keys.map((key) => mutate(key, ...args));
56
+ return Promise.all(mutations);
57
+ };
58
+ };
59
+ function useConnectedShopify() {
60
+ const { storefrontToken } = useStoreFront();
61
+ return !!storefrontToken;
62
+ }
63
+ function useIsSampleProduct() {
64
+ const { storefrontToken } = useStoreFront();
65
+ return !storefrontToken;
66
+ }
67
+
68
+ export { useConnectedShopify, useCurrency, useEditorMode, useIsSampleProduct, useLocale, useMatchMutate, useMobileOnly, usePageType, usePluginEnable, useStoreFront, useSwatches };
@@ -0,0 +1,21 @@
1
+ import { useSyncExternalStore } from 'react';
2
+
3
+ function subscribe(callback) {
4
+ window.addEventListener('resize', callback);
5
+ return () => window.removeEventListener('resize', callback);
6
+ }
7
+ const useCurrentDevice = () => {
8
+ return useSyncExternalStore(subscribe, () => {
9
+ if (window.innerWidth < 768) {
10
+ return 'mobile';
11
+ }
12
+ else if (window.innerWidth >= 768 && window.innerWidth < 1024) {
13
+ return 'tablet';
14
+ }
15
+ else {
16
+ return 'desktop';
17
+ }
18
+ }, () => 'desktop');
19
+ };
20
+
21
+ export { useCurrentDevice };
@@ -0,0 +1,13 @@
1
+ import { useEffect } from 'react';
2
+ import LazyLoad from 'vanilla-lazyload';
3
+
4
+ const useLazyVideo = () => {
5
+ useEffect(() => {
6
+ const lazyLoadInstance = new LazyLoad({
7
+ use_native: true,
8
+ });
9
+ lazyLoadInstance.update();
10
+ }, []);
11
+ };
12
+
13
+ export { useLazyVideo };