@gem-sdk/core 1.29.4 → 1.30.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.
@@ -8,6 +8,7 @@ var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
8
8
  var constant = require('./constant.js');
9
9
  var RenderCustomCode = require('./RenderCustomCode.js');
10
10
  var ComponentToolbarPreview = require('./ComponentToolbarPreview.js');
11
+ var useApplyAnimation = require('../hooks/animation/useApplyAnimation.js');
11
12
 
12
13
  const ComponentWrapperPreview = ({ children, ...props })=>{
13
14
  react.useEffect(()=>{
@@ -21,6 +22,9 @@ const ComponentWrapperPreview = ({ children, ...props })=>{
21
22
  }, [
22
23
  props.uid
23
24
  ]);
25
+ useApplyAnimation.default({
26
+ props
27
+ });
24
28
  if (props.type === 'section') {
25
29
  return null;
26
30
  }
@@ -2,6 +2,7 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
+ var makeStyle = require('../helpers/make-style.js');
5
6
  require('react');
6
7
  require('react/jsx-runtime');
7
8
  require('zustand');
@@ -13,7 +14,7 @@ require('../hooks/useCartUI.js');
13
14
  require('react-transition-group');
14
15
  require('@gem-sdk/core');
15
16
  var render = require('../helpers/render.js');
16
- require('../helpers/convert.js');
17
+ var convert = require('../helpers/convert.js');
17
18
  var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
18
19
  var constant = require('./constant.js');
19
20
 
@@ -170,6 +171,7 @@ const Render = ({ uid, builder, components, parentId, extraFiles = {}, pageConte
170
171
  const { cssCode, jsCode } = RenderCustomCode(item);
171
172
  if (cssCode) liquid += cssCode;
172
173
  if (jsCode) liquid += jsCode;
174
+ liquid = appendAnimation(item, liquid);
173
175
  return {
174
176
  liquid,
175
177
  extraFiles: customProps.extraFiles
@@ -199,13 +201,52 @@ const RenderCustomCode = (item)=>{
199
201
  jsCode
200
202
  };
201
203
  };
204
+ const appendAnimation = (props, liquid)=>{
205
+ const { advanced, tag } = props;
206
+ const { animation } = advanced ?? {};
207
+ const enableAnimation = animation?.desktop?.enabled || animation?.tablet?.enabled || animation?.mobile?.enabled;
208
+ if (!enableAnimation || !animation?.desktop?.triggerConfig) return liquid;
209
+ const getAnimationType = (settings, type)=>{
210
+ return settings?.triggerConfig?.[type]?.animation ?? 'none';
211
+ };
212
+ const getSettingsByDevice = (device)=>{
213
+ if (device === 'desktop') return animation?.desktop;
214
+ else if (device === 'tablet') return animation?.tablet ?? animation?.desktop;
215
+ else if (device === 'mobile') return animation?.mobile ?? animation?.tablet ?? animation?.desktop;
216
+ return animation?.desktop;
217
+ };
218
+ const getInitOpacity = (device)=>+!(getSettingsByDevice(device)?.enabled && getAnimationType(getSettingsByDevice(device), 'appear') !== 'none');
219
+ const opacityObject = {
220
+ desktop: getInitOpacity('desktop'),
221
+ tablet: getInitOpacity('tablet'),
222
+ mobile: getInitOpacity('mobile')
223
+ };
224
+ const inheritParentStyle = {
225
+ all: tag === 'Section' ? '' : 'inherit'
226
+ };
227
+ return render.template`
228
+ ${render.RenderIf(convert.isLocalEnv, `<script src="{{ 'gp-animation.js' | asset_url }}" defer="defer"></script>`, `<script src="${convert.baseAssetURL}/assets/gp-animation.js" defer="defer"></script>`)}
229
+ <gp-animation
230
+ gp-data='${JSON.stringify({
231
+ config: animation,
232
+ tag
233
+ })}'
234
+ style="${{
235
+ ...inheritParentStyle
236
+ }}"
237
+ >
238
+ <div style="${{
239
+ ...makeStyle.makeStyleResponsive('op', opacityObject)
240
+ }}">${liquid}</div>
241
+ </gp-animation>
242
+ `;
243
+ };
202
244
  const RenderChildren = (props)=>{
203
245
  const data = Render(props);
204
246
  // Append to prop parent
205
247
  for(const key in data.extraFiles){
206
248
  if (Object.prototype.hasOwnProperty.call(data.extraFiles, key)) {
207
- const value = data.extraFiles[key];
208
- props.customProps.extraFiles[key] = value;
249
+ props.customProps.extraFiles[key] = data.extraFiles[key];
209
250
  }
210
251
  }
211
252
  // Fix limit 256kb
@@ -214,7 +255,7 @@ const RenderChildren = (props)=>{
214
255
  if (Math.ceil(size / 1024) >= 180) {
215
256
  const fileName = `gp-section-snippet-${props.uid}`;
216
257
  props.customProps.extraFiles[fileName] = data.liquid;
217
- return `{% render '${fileName}', product: product, variant: variant, product_form_id: product_form_id, productSelectedVariant: productSelectedVariant %}`;
258
+ return `{% render '${fileName}', product: product, variant: variant, product_form_id: product_form_id, productSelectedVariant: productSelectedVariant, form: form %}`;
218
259
  }
219
260
  return data.liquid;
220
261
  };
@@ -231,7 +272,7 @@ const WrapRenderChildren = ({ uid, customProps }, codes)=>{
231
272
  if (Math.ceil(size / 1024) >= 180) {
232
273
  const fileName = `gp-section-snippet-${uid + i}`;
233
274
  customProps.extraFiles[fileName] = code;
234
- liquid += `{% render '${fileName}', product: product, variant: variant, product_form_id: product_form_id, productSelectedVariant: productSelectedVariant %}`;
275
+ liquid += `{% render '${fileName}', product: product, variant: variant, product_form_id: product_form_id, productSelectedVariant: productSelectedVariant, form: form %}`;
235
276
  } else {
236
277
  liquid += code;
237
278
  }
@@ -34,7 +34,8 @@ const disableWrap = [
34
34
  'Product',
35
35
  'ProductImages',
36
36
  'ProductImagesV2',
37
- 'Sticky'
37
+ 'Sticky',
38
+ 'Heading'
38
39
  ];
39
40
  const customRenderChildren = [
40
41
  'Accordion',
@@ -0,0 +1,213 @@
1
+ 'use strict';
2
+
3
+ const EASING = {
4
+ ease: 'cubic-bezier(0.46,0.03,0.52,0.96)',
5
+ 'ease-in': 'cubic-bezier(0.55,0.08,0.68,0.53)',
6
+ 'ease-out': 'cubic-bezier(0.46,0.03,0.52,0.96)',
7
+ linear: 'linear'
8
+ };
9
+ const animations = ()=>{
10
+ const normalizeOptions = (options)=>{
11
+ const cloneOptions = JSON.parse(JSON.stringify(options));
12
+ const numberMember = [
13
+ 'delay',
14
+ 'speed',
15
+ 'scale',
16
+ 'intensity'
17
+ ];
18
+ numberMember.forEach((keyName)=>{
19
+ if (!cloneOptions?.[keyName]) return;
20
+ if (keyName === 'scale') {
21
+ if (!cloneOptions?.zoomDirection) throw new TypeError(`zoomDirection not found on zoom preset`);
22
+ const [i1, i2] = cloneOptions?.scale?.in ?? [
23
+ 1,
24
+ 1
25
+ ];
26
+ const [o1, o2] = cloneOptions?.scale?.out ?? [
27
+ 1,
28
+ 1
29
+ ];
30
+ cloneOptions[keyName] = {
31
+ in: [
32
+ Number(i1) / 100,
33
+ Number(i2) / 100
34
+ ],
35
+ out: [
36
+ Number(o1) / 100,
37
+ Number(o2) / 100
38
+ ]
39
+ };
40
+ return;
41
+ }
42
+ const num = Number(cloneOptions?.[keyName]);
43
+ if (keyName === 'delay') cloneOptions[keyName] = num * 1000;
44
+ else cloneOptions[keyName] = num;
45
+ if (!isFinite(num)) throw new TypeError(`${keyName} must be a number`);
46
+ });
47
+ return cloneOptions;
48
+ };
49
+ const slide = (target, options)=>{
50
+ const normalizedOptions = normalizeOptions(options);
51
+ const { direction, distance } = normalizedOptions;
52
+ const coordinate = [
53
+ 'left',
54
+ 'right'
55
+ ].includes(direction ?? '') ? 'X' : 'Y';
56
+ const isNeg = [
57
+ 'left',
58
+ 'down'
59
+ ].includes(direction ?? '') ? '-' : '';
60
+ const preset = [
61
+ {
62
+ opacity: 0,
63
+ transform: `translate${coordinate}(${isNeg}${distance ?? 50}%)`
64
+ },
65
+ {
66
+ opacity: 1,
67
+ transform: `translate${coordinate}(0)`
68
+ }
69
+ ];
70
+ return generateAnimationInstance(target, preset, {
71
+ ...generateOptions(normalizedOptions, 500)
72
+ });
73
+ };
74
+ const fade = (target, options)=>{
75
+ const normalizedOptions = normalizeOptions(options);
76
+ const preset = [
77
+ {
78
+ opacity: 0
79
+ },
80
+ {
81
+ opacity: 1
82
+ }
83
+ ];
84
+ return generateAnimationInstance(target, preset, {
85
+ ...generateOptions(normalizedOptions, 500)
86
+ });
87
+ };
88
+ const generateOptions = (options, defaultDuration)=>{
89
+ const convertSpeedToDuration = (speed)=>{
90
+ if (!speed) return defaultDuration;
91
+ return 1.5 / speed * 1000;
92
+ };
93
+ const { loop, delay, speed, easing } = options ?? {};
94
+ const duration = convertSpeedToDuration(speed);
95
+ const actualDelay = delay ?? 0;
96
+ const actualDuration = loop ? duration + actualDelay : duration;
97
+ return {
98
+ iterations: loop ? Infinity : 1,
99
+ duration: actualDuration,
100
+ delay: actualDelay,
101
+ easing: EASING[easing ?? 'linear']
102
+ };
103
+ };
104
+ const zoom = (target, options)=>{
105
+ const normalizedOptions = normalizeOptions(options);
106
+ const { scale, zoomDirection, isFade } = normalizedOptions;
107
+ const [i1, i2] = scale.in;
108
+ const [o1, o2] = scale.out;
109
+ const zoomInPreset = [
110
+ {
111
+ transform: `scale(${i1}, ${i1})`,
112
+ opacity: isFade ? 0 : 1
113
+ },
114
+ {
115
+ transform: `scale(${i2 ?? 1.2}, ${i2 ?? 1.2})`,
116
+ opacity: 1
117
+ }
118
+ ];
119
+ const zoomOutPreset = [
120
+ {
121
+ transform: `scale(${o1}, ${o1})`,
122
+ opacity: isFade ? 0 : 1
123
+ },
124
+ {
125
+ transform: `scale(${o2 ?? 0.8}, ${o2 ?? 0.8})`,
126
+ opacity: 1
127
+ }
128
+ ];
129
+ const zoomPreset = zoomDirection === 'in' ? zoomInPreset : zoomOutPreset;
130
+ return generateAnimationInstance(target, zoomPreset, {
131
+ ...generateOptions(normalizedOptions, 700)
132
+ });
133
+ };
134
+ const generateLoopDelayEffect = (keyframes, delay, duration)=>{
135
+ if (!delay) return keyframes;
136
+ const offset = delay / duration;
137
+ const keyframe = [
138
+ ...keyframes
139
+ ].pop();
140
+ return [
141
+ ...keyframes,
142
+ {
143
+ ...keyframe,
144
+ offset: 1 - offset
145
+ }
146
+ ];
147
+ };
148
+ const shake = (target, options)=>{
149
+ const normalizedOptions = normalizeOptions(options);
150
+ const { intensity } = normalizedOptions ?? {};
151
+ const zeroIntensity = [
152
+ {
153
+ transform: 'translate3d(0, 0, 0)'
154
+ }
155
+ ];
156
+ const unitIntensity = [
157
+ {
158
+ transform: 'translate3d(4px, 0, 0)'
159
+ },
160
+ {
161
+ transform: 'translate3d(-4px, 0, 0)'
162
+ },
163
+ {
164
+ transform: 'translate3d(4px, 0, 0)'
165
+ }
166
+ ];
167
+ let keyframes = [];
168
+ Array.from(Array(intensity ?? 1).keys()).forEach(()=>{
169
+ keyframes = [
170
+ ...keyframes,
171
+ ...unitIntensity
172
+ ];
173
+ });
174
+ const shakePreset = [
175
+ {
176
+ transform: 'translate3d(-1px, 0, 0)'
177
+ },
178
+ {
179
+ transform: 'translate3d(2px, 0, 0)'
180
+ },
181
+ {
182
+ transform: 'translate3d(-4px, 0, 0)'
183
+ },
184
+ ...keyframes,
185
+ {
186
+ transform: 'translate3d(-4px, 0, 0)'
187
+ },
188
+ {
189
+ transform: 'translate3d(2px, 0, 0)'
190
+ },
191
+ {
192
+ transform: 'translate3d(-1px, 0, 0)'
193
+ }
194
+ ];
195
+ return generateAnimationInstance(target, intensity ? shakePreset : zeroIntensity, {
196
+ ...generateOptions(normalizedOptions ?? {}, 820)
197
+ });
198
+ };
199
+ const generateAnimationInstance = (target, effectPreset, options)=>{
200
+ const effect = new KeyframeEffect(target, options.iterations && options.iterations === 1 ? effectPreset : generateLoopDelayEffect(effectPreset, options?.delay ?? 0, (options?.duration) ?? 0), {
201
+ ...options
202
+ });
203
+ return new Animation(effect, document.timeline);
204
+ };
205
+ return {
206
+ zoom,
207
+ shake,
208
+ fade,
209
+ slide
210
+ };
211
+ };
212
+
213
+ exports.animations = animations;
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ const useAnimationActions = ()=>{
6
+ const listAnimations = react.useRef();
7
+ const setAnimation = react.useCallback((newListAnimations)=>{
8
+ listAnimations.current = newListAnimations;
9
+ }, [
10
+ listAnimations
11
+ ]);
12
+ const playAnimation = react.useCallback(()=>{
13
+ if (!listAnimations.current) return;
14
+ for (const animation of listAnimations.current){
15
+ animation.play();
16
+ }
17
+ }, []);
18
+ const cancelAnimation = react.useCallback(()=>{
19
+ if (!listAnimations.current) return;
20
+ for (const animation of listAnimations.current){
21
+ animation.cancel();
22
+ }
23
+ }, []);
24
+ const setAnimationOnFinish = react.useCallback((onFinish)=>{
25
+ if (!listAnimations.current) return;
26
+ for (const animation of listAnimations.current){
27
+ animation.onfinish = onFinish;
28
+ }
29
+ }, []);
30
+ return {
31
+ currentAnimation: listAnimations.current,
32
+ setAnimation,
33
+ playAnimation,
34
+ cancelAnimation,
35
+ setAnimationOnFinish
36
+ };
37
+ };
38
+
39
+ exports.useAnimationActions = useAnimationActions;
@@ -0,0 +1,29 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var useCurrentDevice = require('../use-current-device.js');
5
+
6
+ const useAnimationConfig = (props)=>{
7
+ const currentDevice = useCurrentDevice.useCurrentDevice();
8
+ const configByDevices = react.useMemo(()=>props?.advanced?.animation?.[currentDevice], [
9
+ currentDevice,
10
+ props?.advanced?.animation
11
+ ]);
12
+ const getAnimationConfig = react.useCallback(()=>{
13
+ const { trigger, triggerConfig } = configByDevices;
14
+ const { animation, setting } = triggerConfig[trigger];
15
+ return {
16
+ type: animation,
17
+ setting: setting[animation]
18
+ };
19
+ }, [
20
+ configByDevices
21
+ ]);
22
+ const isEnabledAnimation = configByDevices?.enabled;
23
+ return {
24
+ isEnabledAnimation,
25
+ getAnimationConfig
26
+ };
27
+ };
28
+
29
+ exports.useAnimationConfig = useAnimationConfig;
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+
5
+ const useAnimationPreview = ({ props, playAnimation, cancelAnimation, setAnimationOnFinish, setToolbarActive })=>{
6
+ const previewAnimation = react.useCallback((e)=>{
7
+ const { uid, isCancel } = e.detail;
8
+ if (props.uid !== uid) return;
9
+ cancelAnimation();
10
+ if (isCancel) {
11
+ setToolbarActive(true);
12
+ return;
13
+ }
14
+ playAnimation();
15
+ setToolbarActive(false);
16
+ setAnimationOnFinish(()=>{
17
+ setToolbarActive(true);
18
+ });
19
+ }, [
20
+ props.uid,
21
+ cancelAnimation,
22
+ playAnimation,
23
+ setToolbarActive,
24
+ setAnimationOnFinish
25
+ ]);
26
+ return {
27
+ previewAnimation
28
+ };
29
+ };
30
+
31
+ exports.useAnimationPreview = useAnimationPreview;
@@ -0,0 +1,120 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var useAnimationConfig = require('./useAnimationConfig.js');
5
+
6
+ const SPACING_ACTIVE_ATTRIBUTE = 'data-spacing';
7
+ const TOOLBAR_ACTIVE_ATTRIBUTE = 'data-toolbar-active';
8
+ const OUTLINE_ACTIVE_ATTRIBUTE = 'data-outline-active';
9
+ const TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE = 'data-toolbar-add-active';
10
+ const useAnimationTarget = (props)=>{
11
+ const { isEnabledAnimation } = useAnimationConfig.useAnimationConfig(props);
12
+ const componentTag = props.tag;
13
+ const componentUid = props.uid;
14
+ const targets = react.useRef(null);
15
+ const targetObjects = react.useRef([]);
16
+ const setToolbarActive = (isActive)=>{
17
+ if (!targetObjects.current) return;
18
+ for (const item of targetObjects.current){
19
+ if (isActive) {
20
+ item.toolbar?.setAttribute(TOOLBAR_ACTIVE_ATTRIBUTE, 'true');
21
+ item.outline?.setAttribute(OUTLINE_ACTIVE_ATTRIBUTE, 'true');
22
+ item.spacing?.setAttribute(SPACING_ACTIVE_ATTRIBUTE, 'true');
23
+ item.addSectionTop?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE, 'true');
24
+ item.addSectionBottom?.setAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE, 'true');
25
+ } else {
26
+ item.toolbar?.removeAttribute(TOOLBAR_ACTIVE_ATTRIBUTE);
27
+ item.outline?.removeAttribute(OUTLINE_ACTIVE_ATTRIBUTE);
28
+ item.spacing?.removeAttribute(SPACING_ACTIVE_ATTRIBUTE);
29
+ item.addSectionTop?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE);
30
+ item.addSectionBottom?.removeAttribute(TOOLBAR_ADD_SECTION_ACTIVE_ATTRIBUTE);
31
+ }
32
+ }
33
+ };
34
+ const getSectionProperties = (target)=>{
35
+ const sectionAddTop = target.querySelector('[data-toolbar-add-top]');
36
+ const sectionAddBottom = target.querySelector('[data-toolbar-add-bottom]');
37
+ const sectionChild = Array.from(target.children);
38
+ const sectionToolbar = sectionChild.find((child)=>child.getAttribute('data-toolbar') !== null);
39
+ const sectionOutline = sectionChild.find((child)=>child.getAttribute('data-outline') !== null);
40
+ return {
41
+ sectionToolbar,
42
+ sectionOutline,
43
+ sectionAddTop,
44
+ sectionAddBottom
45
+ };
46
+ };
47
+ const getUpdatedTargetObjects = react.useCallback((targets)=>{
48
+ return targets.reduce((accumulator, $rootTarget)=>{
49
+ let addSectionTop = null;
50
+ let addSectionBottom = null;
51
+ let target = $rootTarget;
52
+ let toolbar = $rootTarget.querySelector('[data-toolbar][data-toolbar-active]');
53
+ let outline = $rootTarget.querySelector('[data-outline][data-outline-active]');
54
+ const targetChild = Array.from(target.children);
55
+ const spacing = targetChild.find((child)=>child.getAttribute('data-spacing') !== null);
56
+ switch(componentTag){
57
+ case 'Button':
58
+ case 'SubmitButton':
59
+ case 'ProductButton':
60
+ case 'DynamicCheckout':
61
+ target = $rootTarget.querySelector('.gp-button-base');
62
+ break;
63
+ case 'ProductProperties':
64
+ target = $rootTarget.querySelector('input');
65
+ break;
66
+ case 'Icon':
67
+ target = $rootTarget.firstElementChild;
68
+ break;
69
+ case 'ProductTag':
70
+ target = $rootTarget?.children[0]?.children[0];
71
+ break;
72
+ case 'Section':
73
+ {
74
+ target = $rootTarget;
75
+ const { sectionOutline, sectionToolbar, sectionAddTop, sectionAddBottom } = getSectionProperties(target);
76
+ outline = sectionOutline;
77
+ toolbar = sectionToolbar;
78
+ addSectionTop = sectionAddTop;
79
+ addSectionBottom = sectionAddBottom;
80
+ break;
81
+ }
82
+ default:
83
+ target = $rootTarget;
84
+ }
85
+ const newTargetObject = {
86
+ target,
87
+ toolbar,
88
+ outline,
89
+ spacing,
90
+ addSectionTop,
91
+ addSectionBottom
92
+ };
93
+ accumulator.push(newTargetObject);
94
+ return accumulator;
95
+ }, []);
96
+ }, [
97
+ componentTag
98
+ ]);
99
+ const initListOfTargets = react.useCallback(()=>{
100
+ if (!isEnabledAnimation) return;
101
+ if (!targets.current) {
102
+ targets.current = document.querySelectorAll(`[data-uid="${componentUid}"]`);
103
+ }
104
+ const targetsArray = Array.from(targets.current);
105
+ if (!targetsArray.length) return;
106
+ const updatedTargetObjects = getUpdatedTargetObjects(targetsArray);
107
+ targetObjects.current = updatedTargetObjects;
108
+ }, [
109
+ componentUid,
110
+ getUpdatedTargetObjects,
111
+ isEnabledAnimation
112
+ ]);
113
+ return {
114
+ targetObjects,
115
+ setToolbarActive,
116
+ initListOfTargets
117
+ };
118
+ };
119
+
120
+ exports.useAnimationTarget = useAnimationTarget;
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var useAnimations = require('../useAnimations.js');
7
+ var useAnimationTarget = require('./useAnimationTarget.js');
8
+ var useAnimationConfig = require('./useAnimationConfig.js');
9
+ var useAnimationActions = require('./useAnimationActions.js');
10
+ var useAnimationPreview = require('./useAnimationPreview.js');
11
+ var animations = require('../../types/animations.js');
12
+
13
+ const useApplyAnimation = ({ props })=>{
14
+ const currentProps = props;
15
+ const { uid: componentUid } = currentProps;
16
+ const animation = useAnimations.useAnimations();
17
+ const { initListOfTargets, targetObjects, setToolbarActive } = useAnimationTarget.useAnimationTarget(currentProps);
18
+ const { isEnabledAnimation, getAnimationConfig } = useAnimationConfig.useAnimationConfig(currentProps);
19
+ const { setAnimation, cancelAnimation, playAnimation, setAnimationOnFinish } = useAnimationActions.useAnimationActions();
20
+ const { previewAnimation } = useAnimationPreview.useAnimationPreview({
21
+ props: currentProps,
22
+ playAnimation,
23
+ cancelAnimation,
24
+ setAnimationOnFinish,
25
+ setToolbarActive
26
+ });
27
+ const generateAnimation = react.useCallback(({ target, setting, type })=>{
28
+ return animation[type](target, setting);
29
+ }, [
30
+ animation
31
+ ]);
32
+ const initListAnimations = react.useCallback(()=>{
33
+ const { type, setting } = getAnimationConfig();
34
+ if (!type || type === animations.AnimationType.None || !targetObjects.current.length) {
35
+ cancelAnimation();
36
+ return;
37
+ }
38
+ const listAnimations = targetObjects.current.map((item)=>generateAnimation({
39
+ type,
40
+ setting,
41
+ target: item.target
42
+ }));
43
+ cancelAnimation();
44
+ setAnimation(listAnimations);
45
+ }, [
46
+ getAnimationConfig,
47
+ targetObjects,
48
+ cancelAnimation,
49
+ setAnimation,
50
+ generateAnimation
51
+ ]);
52
+ react.useEffect(()=>{
53
+ if (isEnabledAnimation) {
54
+ initListOfTargets();
55
+ initListAnimations();
56
+ } else {
57
+ cancelAnimation();
58
+ }
59
+ return ()=>{
60
+ cancelAnimation();
61
+ };
62
+ }, [
63
+ componentUid,
64
+ initListAnimations,
65
+ cancelAnimation,
66
+ isEnabledAnimation,
67
+ initListOfTargets
68
+ ]);
69
+ react.useEffect(()=>{
70
+ window.addEventListener('preview-animation', previewAnimation);
71
+ return ()=>{
72
+ window.removeEventListener('preview-animation', previewAnimation);
73
+ };
74
+ }, [
75
+ previewAnimation
76
+ ]);
77
+ react.useEffect(()=>{
78
+ window.addEventListener('init-animation-target', initListOfTargets);
79
+ return ()=>{
80
+ window.removeEventListener('init-animation-target', initListOfTargets);
81
+ };
82
+ }, [
83
+ initListOfTargets
84
+ ]);
85
+ };
86
+
87
+ exports.default = useApplyAnimation;
@@ -0,0 +1,26 @@
1
+ 'use strict';
2
+
3
+ require('react');
4
+ require('react/jsx-runtime');
5
+ require('zustand');
6
+ require('swr');
7
+ require('@gem-sdk/adapter-shopify');
8
+ require('swr/mutation');
9
+ require('vanilla-lazyload');
10
+ require('./useCartUI.js');
11
+ require('react-transition-group');
12
+ require('@gem-sdk/core');
13
+ var animations = require('../helpers/animations.js');
14
+ require('../helpers/convert.js');
15
+
16
+ const useAnimations = ()=>{
17
+ const { zoom, shake, fade, slide } = animations.animations();
18
+ return {
19
+ zoom,
20
+ shake,
21
+ fade,
22
+ slide
23
+ };
24
+ };
25
+
26
+ exports.useAnimations = useAnimations;