@gem-sdk/core 1.31.0 → 1.31.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/ComponentWrapper.js +18 -21
- package/dist/cjs/components/Render.js +43 -40
- package/dist/cjs/components/Render.liquid.js +1 -2
- package/dist/esm/components/ComponentWrapper.js +18 -21
- package/dist/esm/components/Render.js +43 -40
- package/dist/esm/components/Render.liquid.js +1 -2
- package/dist/types/index.d.ts +1 -1
- package/package.json +1 -1
- package/dist/cjs/components/animation/AnimationWrapper.js +0 -50
- package/dist/cjs/hooks/animation/animations.js +0 -227
- package/dist/cjs/hooks/animation/useLivePageAnimation.js +0 -230
- package/dist/esm/components/animation/AnimationWrapper.js +0 -46
- package/dist/esm/hooks/animation/animations.js +0 -225
- package/dist/esm/hooks/animation/useLivePageAnimation.js +0 -228
|
@@ -7,32 +7,25 @@ var react = require('react');
|
|
|
7
7
|
var composeAdvanceStyle = require('../helpers/compose-advance-style.js');
|
|
8
8
|
var constant = require('./constant.js');
|
|
9
9
|
var RenderCustomCode = require('./RenderCustomCode.js');
|
|
10
|
-
var AnimationWrapper = require('./animation/AnimationWrapper.js');
|
|
11
10
|
|
|
12
11
|
const ComponentWrapper = ({ children, ...props })=>{
|
|
13
12
|
if (props.type === 'section') return null;
|
|
14
13
|
const style = composeAdvanceStyle.composeAdvanceStyle(props.advanced, props.tag);
|
|
15
14
|
const advanced = props.advanced;
|
|
16
|
-
const { animation } = advanced ?? {};
|
|
17
|
-
const enableAnimation = animation?.desktop?.enabled || animation?.tablet?.enabled || animation?.mobile?.enabled;
|
|
18
|
-
let dynamicChildren = /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
19
|
-
style: style,
|
|
20
|
-
className: `${props.uid} ${advanced?.cssClass}`,
|
|
21
|
-
children: children
|
|
22
|
-
});
|
|
23
15
|
if (constant.disableWrap.includes(props.tag) && /*#__PURE__*/ react.isValidElement(children)) {
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
16
|
+
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
17
|
+
children: [
|
|
18
|
+
/*#__PURE__*/ jsxRuntime.jsx(RenderCustomCode.default, {
|
|
19
|
+
uid: props.uid,
|
|
20
|
+
advanced: advanced
|
|
21
|
+
}),
|
|
22
|
+
/*#__PURE__*/ jsxRuntime.jsx(children.type, {
|
|
23
|
+
className: advanced?.cssClass,
|
|
24
|
+
...children.props,
|
|
25
|
+
style,
|
|
26
|
+
advanced
|
|
27
|
+
})
|
|
28
|
+
]
|
|
36
29
|
});
|
|
37
30
|
}
|
|
38
31
|
return /*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
@@ -41,7 +34,11 @@ const ComponentWrapper = ({ children, ...props })=>{
|
|
|
41
34
|
uid: props.uid,
|
|
42
35
|
advanced: advanced
|
|
43
36
|
}),
|
|
44
|
-
|
|
37
|
+
/*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
38
|
+
style: style,
|
|
39
|
+
className: `${props.uid} ${advanced?.cssClass}`,
|
|
40
|
+
children: children
|
|
41
|
+
})
|
|
45
42
|
]
|
|
46
43
|
});
|
|
47
44
|
};
|
|
@@ -14,47 +14,50 @@ const Render = ({ uid, ...passProps })=>{
|
|
|
14
14
|
const item = BuilderContext.useBuilderStore((s)=>s.getItem(uid));
|
|
15
15
|
const Component = BuilderComponent.useBuilderComponent(item?.tag);
|
|
16
16
|
if (!item) return null;
|
|
17
|
-
if (item?.type === 'section')
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
children:
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
17
|
+
if (item?.type === 'section') {
|
|
18
|
+
return /*#__PURE__*/ jsxRuntime.jsx(RenderSection.default, {
|
|
19
|
+
sectionId: item.uid
|
|
20
|
+
});
|
|
21
|
+
} else {
|
|
22
|
+
return /*#__PURE__*/ jsxRuntime.jsx(reactErrorBoundary.ErrorBoundary, {
|
|
23
|
+
fallbackRender: ({ error, resetErrorBoundary })=>/*#__PURE__*/ jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
24
|
+
children: [
|
|
25
|
+
/*#__PURE__*/ jsxRuntime.jsx("span", {
|
|
26
|
+
"aria-label": "Error message",
|
|
27
|
+
children: error.message
|
|
28
|
+
}),
|
|
29
|
+
/*#__PURE__*/ jsxRuntime.jsx("button", {
|
|
30
|
+
type: "button",
|
|
31
|
+
onClick: resetErrorBoundary,
|
|
32
|
+
children: "Try again"
|
|
33
|
+
})
|
|
34
|
+
]
|
|
35
|
+
}),
|
|
36
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(ComponentWrapper.default, {
|
|
37
|
+
...item,
|
|
38
|
+
children: item?.childrens?.length ? /*#__PURE__*/ jsxRuntime.jsx(Component, {
|
|
39
|
+
builderProps: {
|
|
40
|
+
uid,
|
|
41
|
+
builderData: item
|
|
42
|
+
},
|
|
43
|
+
styles: item.styles,
|
|
44
|
+
setting: item.settings,
|
|
45
|
+
...passProps,
|
|
46
|
+
children: item.childrens.map((id)=>/*#__PURE__*/ jsxRuntime.jsx(RenderMemo, {
|
|
47
|
+
uid: id
|
|
48
|
+
}, id))
|
|
49
|
+
}) : /*#__PURE__*/ jsxRuntime.jsx(Component, {
|
|
50
|
+
builderProps: {
|
|
51
|
+
uid,
|
|
52
|
+
builderData: item
|
|
53
|
+
},
|
|
54
|
+
styles: item.styles,
|
|
55
|
+
setting: item.settings,
|
|
56
|
+
...passProps
|
|
57
|
+
})
|
|
55
58
|
})
|
|
56
|
-
})
|
|
57
|
-
}
|
|
59
|
+
}, item.uid);
|
|
60
|
+
}
|
|
58
61
|
};
|
|
59
62
|
const RenderMemo = /*#__PURE__*/ react.memo(Render);
|
|
60
63
|
RenderMemo.displayName = 'RenderMemo';
|
|
@@ -225,8 +225,7 @@ const appendAnimation = (props, liquid)=>{
|
|
|
225
225
|
mobile: getInitOpacity('mobile')
|
|
226
226
|
};
|
|
227
227
|
const inheritParentStyle = {
|
|
228
|
-
all: tag === 'Section' ? '' : 'inherit'
|
|
229
|
-
position: 'static'
|
|
228
|
+
all: tag === 'Section' ? '' : 'inherit'
|
|
230
229
|
};
|
|
231
230
|
return render.template`
|
|
232
231
|
${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>`)}
|
|
@@ -3,32 +3,25 @@ import { isValidElement } from 'react';
|
|
|
3
3
|
import { composeAdvanceStyle } from '../helpers/compose-advance-style.js';
|
|
4
4
|
import { disableWrap } from './constant.js';
|
|
5
5
|
import RenderCustomCode from './RenderCustomCode.js';
|
|
6
|
-
import AnimationWrapper from './animation/AnimationWrapper.js';
|
|
7
6
|
|
|
8
7
|
const ComponentWrapper = ({ children, ...props })=>{
|
|
9
8
|
if (props.type === 'section') return null;
|
|
10
9
|
const style = composeAdvanceStyle(props.advanced, props.tag);
|
|
11
10
|
const advanced = props.advanced;
|
|
12
|
-
const { animation } = advanced ?? {};
|
|
13
|
-
const enableAnimation = animation?.desktop?.enabled || animation?.tablet?.enabled || animation?.mobile?.enabled;
|
|
14
|
-
let dynamicChildren = /*#__PURE__*/ jsx("div", {
|
|
15
|
-
style: style,
|
|
16
|
-
className: `${props.uid} ${advanced?.cssClass}`,
|
|
17
|
-
children: children
|
|
18
|
-
});
|
|
19
11
|
if (disableWrap.includes(props.tag) && /*#__PURE__*/ isValidElement(children)) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
12
|
+
return /*#__PURE__*/ jsxs(Fragment, {
|
|
13
|
+
children: [
|
|
14
|
+
/*#__PURE__*/ jsx(RenderCustomCode, {
|
|
15
|
+
uid: props.uid,
|
|
16
|
+
advanced: advanced
|
|
17
|
+
}),
|
|
18
|
+
/*#__PURE__*/ jsx(children.type, {
|
|
19
|
+
className: advanced?.cssClass,
|
|
20
|
+
...children.props,
|
|
21
|
+
style,
|
|
22
|
+
advanced
|
|
23
|
+
})
|
|
24
|
+
]
|
|
32
25
|
});
|
|
33
26
|
}
|
|
34
27
|
return /*#__PURE__*/ jsxs(Fragment, {
|
|
@@ -37,7 +30,11 @@ const ComponentWrapper = ({ children, ...props })=>{
|
|
|
37
30
|
uid: props.uid,
|
|
38
31
|
advanced: advanced
|
|
39
32
|
}),
|
|
40
|
-
|
|
33
|
+
/*#__PURE__*/ jsx("div", {
|
|
34
|
+
style: style,
|
|
35
|
+
className: `${props.uid} ${advanced?.cssClass}`,
|
|
36
|
+
children: children
|
|
37
|
+
})
|
|
41
38
|
]
|
|
42
39
|
});
|
|
43
40
|
};
|
|
@@ -10,47 +10,50 @@ const Render = ({ uid, ...passProps })=>{
|
|
|
10
10
|
const item = useBuilderStore((s)=>s.getItem(uid));
|
|
11
11
|
const Component = useBuilderComponent(item?.tag);
|
|
12
12
|
if (!item) return null;
|
|
13
|
-
if (item?.type === 'section')
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
children:
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
13
|
+
if (item?.type === 'section') {
|
|
14
|
+
return /*#__PURE__*/ jsx(RenderSectionMemo, {
|
|
15
|
+
sectionId: item.uid
|
|
16
|
+
});
|
|
17
|
+
} else {
|
|
18
|
+
return /*#__PURE__*/ jsx(ErrorBoundary, {
|
|
19
|
+
fallbackRender: ({ error, resetErrorBoundary })=>/*#__PURE__*/ jsxs(Fragment, {
|
|
20
|
+
children: [
|
|
21
|
+
/*#__PURE__*/ jsx("span", {
|
|
22
|
+
"aria-label": "Error message",
|
|
23
|
+
children: error.message
|
|
24
|
+
}),
|
|
25
|
+
/*#__PURE__*/ jsx("button", {
|
|
26
|
+
type: "button",
|
|
27
|
+
onClick: resetErrorBoundary,
|
|
28
|
+
children: "Try again"
|
|
29
|
+
})
|
|
30
|
+
]
|
|
31
|
+
}),
|
|
32
|
+
children: /*#__PURE__*/ jsx(ComponentWrapper, {
|
|
33
|
+
...item,
|
|
34
|
+
children: item?.childrens?.length ? /*#__PURE__*/ jsx(Component, {
|
|
35
|
+
builderProps: {
|
|
36
|
+
uid,
|
|
37
|
+
builderData: item
|
|
38
|
+
},
|
|
39
|
+
styles: item.styles,
|
|
40
|
+
setting: item.settings,
|
|
41
|
+
...passProps,
|
|
42
|
+
children: item.childrens.map((id)=>/*#__PURE__*/ jsx(RenderMemo, {
|
|
43
|
+
uid: id
|
|
44
|
+
}, id))
|
|
45
|
+
}) : /*#__PURE__*/ jsx(Component, {
|
|
46
|
+
builderProps: {
|
|
47
|
+
uid,
|
|
48
|
+
builderData: item
|
|
49
|
+
},
|
|
50
|
+
styles: item.styles,
|
|
51
|
+
setting: item.settings,
|
|
52
|
+
...passProps
|
|
53
|
+
})
|
|
51
54
|
})
|
|
52
|
-
})
|
|
53
|
-
}
|
|
55
|
+
}, item.uid);
|
|
56
|
+
}
|
|
54
57
|
};
|
|
55
58
|
const RenderMemo = /*#__PURE__*/ memo(Render);
|
|
56
59
|
RenderMemo.displayName = 'RenderMemo';
|
|
@@ -221,8 +221,7 @@ const appendAnimation = (props, liquid)=>{
|
|
|
221
221
|
mobile: getInitOpacity('mobile')
|
|
222
222
|
};
|
|
223
223
|
const inheritParentStyle = {
|
|
224
|
-
all: tag === 'Section' ? '' : 'inherit'
|
|
225
|
-
position: 'static'
|
|
224
|
+
all: tag === 'Section' ? '' : 'inherit'
|
|
226
225
|
};
|
|
227
226
|
return template`
|
|
228
227
|
${RenderIf(isLocalEnv, `<script src="{{ 'gp-animation.js' | asset_url }}" defer="defer"></script>`, `<script src="${baseAssetURL}/assets/gp-animation.js" defer="defer"></script>`)}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -155,7 +155,7 @@ type ObjectLayoutValue = {
|
|
|
155
155
|
keepCol?: boolean;
|
|
156
156
|
};
|
|
157
157
|
type ProductReviewsWidgetType = 'reviews' | 'badge';
|
|
158
|
-
type TrustooWidgetType = 'starRating' | 'reviews';
|
|
158
|
+
type TrustooWidgetType = 'starRatingInList' | 'starRating' | 'reviews';
|
|
159
159
|
type WiserWidgetType = 'related' | 'recommended' | 'alsobought' | 'recentview' | 'newarrivals' | 'featured' | 'topselling' | 'trending' | 'recent_related';
|
|
160
160
|
type InstantJudgeMeReviewsWidgetType = 'single_product_preview_badge' | 'review_widget' | 'reviews_carousel' | 'floating_reviews_tab' | 'all_reviews_widget' | 'verified_reviews_count_badge' | 'medals' | 'media_grid' | 'all_reviews_text';
|
|
161
161
|
type InstantLooxReviewsWidgetType = 'product_reviews_widget' | 'reviews_widget_all_stores' | 'product_star_ratings_widget' | 'carousel_widget';
|
package/package.json
CHANGED
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
|
-
var jsxRuntime = require('react/jsx-runtime');
|
|
6
|
-
var makeStyle = require('../../helpers/make-style.js');
|
|
7
|
-
var react = require('react');
|
|
8
|
-
require('zustand');
|
|
9
|
-
require('swr');
|
|
10
|
-
require('@gem-sdk/adapter-shopify');
|
|
11
|
-
require('swr/mutation');
|
|
12
|
-
require('vanilla-lazyload');
|
|
13
|
-
require('../../hooks/useCartUI.js');
|
|
14
|
-
require('react-transition-group');
|
|
15
|
-
require('@gem-sdk/core');
|
|
16
|
-
require('../../helpers/convert.js');
|
|
17
|
-
var useLivePageAnimation = require('../../hooks/animation/useLivePageAnimation.js');
|
|
18
|
-
|
|
19
|
-
const AnimationWrapper = ({ children, settings, tag })=>{
|
|
20
|
-
const wrapperRef = react.useRef(null);
|
|
21
|
-
const getAnimationType = (settings, type)=>{
|
|
22
|
-
return settings?.triggerConfig?.[type]?.animation ?? 'none';
|
|
23
|
-
};
|
|
24
|
-
const getSettingsByDevice = (device)=>{
|
|
25
|
-
if (device === 'desktop') return settings?.desktop;
|
|
26
|
-
else if (device === 'tablet') return settings?.tablet ?? settings?.desktop;
|
|
27
|
-
else if (device === 'mobile') return settings?.mobile ?? settings?.tablet ?? settings?.desktop;
|
|
28
|
-
return settings?.desktop;
|
|
29
|
-
};
|
|
30
|
-
const getInitOpacity = (device)=>+!(getSettingsByDevice(device)?.enabled && ![
|
|
31
|
-
'shake',
|
|
32
|
-
'none'
|
|
33
|
-
].includes(getAnimationType(getSettingsByDevice(device), 'appear')));
|
|
34
|
-
const opacityObject = {
|
|
35
|
-
desktop: getInitOpacity('desktop'),
|
|
36
|
-
tablet: getInitOpacity('tablet'),
|
|
37
|
-
mobile: getInitOpacity('mobile')
|
|
38
|
-
};
|
|
39
|
-
// const inheritParentStyle = { all: tag === 'Section' ? '' : 'inherit' };
|
|
40
|
-
useLivePageAnimation.useLivePageAnimation(wrapperRef, settings, tag);
|
|
41
|
-
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
42
|
-
ref: wrapperRef,
|
|
43
|
-
style: {
|
|
44
|
-
...makeStyle.makeStyleResponsive('op', opacityObject)
|
|
45
|
-
},
|
|
46
|
-
children: children
|
|
47
|
-
});
|
|
48
|
-
};
|
|
49
|
-
|
|
50
|
-
exports.default = AnimationWrapper;
|
|
@@ -1,227 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
// Any logic changes made to this file must also be applied to
|
|
4
|
-
// packages/web-components/src/helpers/animations.ts, and vice versa.
|
|
5
|
-
const EASING = {
|
|
6
|
-
ease: 'cubic-bezier(0.46,0.03,0.52,0.96)',
|
|
7
|
-
'ease-in': 'cubic-bezier(0.55,0.08,0.68,0.53)',
|
|
8
|
-
'ease-out': 'cubic-bezier(0.46,0.03,0.52,0.96)',
|
|
9
|
-
linear: 'linear'
|
|
10
|
-
};
|
|
11
|
-
const animations = ()=>{
|
|
12
|
-
const normalizeOptions = (options)=>{
|
|
13
|
-
const cloneOptions = JSON.parse(JSON.stringify(options));
|
|
14
|
-
const numberMember = [
|
|
15
|
-
'delay',
|
|
16
|
-
'speed',
|
|
17
|
-
'scale',
|
|
18
|
-
'intensity'
|
|
19
|
-
];
|
|
20
|
-
numberMember.forEach((keyName)=>{
|
|
21
|
-
if (!cloneOptions?.[keyName]) return;
|
|
22
|
-
if (keyName === 'scale') {
|
|
23
|
-
if (!cloneOptions?.zoomDirection) throw new TypeError(`zoomDirection not found on zoom preset`);
|
|
24
|
-
const [i1, i2] = cloneOptions?.scale?.in ?? [
|
|
25
|
-
1,
|
|
26
|
-
1
|
|
27
|
-
];
|
|
28
|
-
const [o1, o2] = cloneOptions?.scale?.out ?? [
|
|
29
|
-
1,
|
|
30
|
-
1
|
|
31
|
-
];
|
|
32
|
-
cloneOptions[keyName] = {
|
|
33
|
-
in: [
|
|
34
|
-
Number(i1) / 100,
|
|
35
|
-
Number(i2) / 100
|
|
36
|
-
],
|
|
37
|
-
out: [
|
|
38
|
-
Number(o1) / 100,
|
|
39
|
-
Number(o2) / 100
|
|
40
|
-
]
|
|
41
|
-
};
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
44
|
-
const num = Number(cloneOptions?.[keyName]);
|
|
45
|
-
if (keyName === 'delay') cloneOptions[keyName] = num * 1000;
|
|
46
|
-
else cloneOptions[keyName] = num;
|
|
47
|
-
if (!isFinite(num)) throw new TypeError(`${keyName} must be a number`);
|
|
48
|
-
});
|
|
49
|
-
return cloneOptions;
|
|
50
|
-
};
|
|
51
|
-
const slide = (target, options)=>{
|
|
52
|
-
const normalizedOptions = normalizeOptions(options);
|
|
53
|
-
const { direction, distance } = normalizedOptions;
|
|
54
|
-
const coordinate = [
|
|
55
|
-
'left',
|
|
56
|
-
'right'
|
|
57
|
-
].includes(direction ?? '') ? 'X' : 'Y';
|
|
58
|
-
const isNeg = [
|
|
59
|
-
'left',
|
|
60
|
-
'down'
|
|
61
|
-
].includes(direction ?? '') ? '-' : '';
|
|
62
|
-
const preset = [
|
|
63
|
-
{
|
|
64
|
-
opacity: 0,
|
|
65
|
-
transform: `translate${coordinate}(${isNeg}${distance ?? 50}%)`
|
|
66
|
-
},
|
|
67
|
-
{
|
|
68
|
-
opacity: 1,
|
|
69
|
-
transform: `translate${coordinate}(0)`
|
|
70
|
-
}
|
|
71
|
-
];
|
|
72
|
-
return generateAnimationInstance(target, preset, {
|
|
73
|
-
...generateOptions(normalizedOptions, 500),
|
|
74
|
-
fill: 'forwards'
|
|
75
|
-
});
|
|
76
|
-
};
|
|
77
|
-
const fade = (target, options)=>{
|
|
78
|
-
const normalizedOptions = normalizeOptions(options);
|
|
79
|
-
const preset = [
|
|
80
|
-
{
|
|
81
|
-
opacity: 0
|
|
82
|
-
},
|
|
83
|
-
{
|
|
84
|
-
opacity: 1
|
|
85
|
-
}
|
|
86
|
-
];
|
|
87
|
-
return generateAnimationInstance(target, preset, {
|
|
88
|
-
...generateOptions(normalizedOptions, 500)
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
const generateOptions = (options, defaultDuration)=>{
|
|
92
|
-
const convertSpeedToDuration = (speed)=>{
|
|
93
|
-
if (!speed) return defaultDuration;
|
|
94
|
-
return 1.5 / speed * 1000;
|
|
95
|
-
};
|
|
96
|
-
const { loop, delay, speed, easing } = options ?? {};
|
|
97
|
-
const duration = convertSpeedToDuration(speed);
|
|
98
|
-
const actualDelay = delay ?? 0;
|
|
99
|
-
const actualDuration = loop ? duration + actualDelay : duration;
|
|
100
|
-
return {
|
|
101
|
-
iterations: loop ? Infinity : 1,
|
|
102
|
-
duration: actualDuration,
|
|
103
|
-
delay: actualDelay,
|
|
104
|
-
easing: EASING[easing ?? 'linear']
|
|
105
|
-
};
|
|
106
|
-
};
|
|
107
|
-
const zoom = (target, options)=>{
|
|
108
|
-
const normalizedOptions = normalizeOptions(options);
|
|
109
|
-
const { scale, zoomDirection, isFade } = normalizedOptions;
|
|
110
|
-
const [i1, i2] = scale.in;
|
|
111
|
-
const [o1, o2] = scale.out;
|
|
112
|
-
const zoomInPreset = [
|
|
113
|
-
{
|
|
114
|
-
transform: `scale(${i1}, ${i1})`,
|
|
115
|
-
opacity: isFade ? 0 : 1
|
|
116
|
-
},
|
|
117
|
-
{
|
|
118
|
-
transform: `scale(${i2 ?? 1.2}, ${i2 ?? 1.2})`,
|
|
119
|
-
opacity: 1
|
|
120
|
-
}
|
|
121
|
-
];
|
|
122
|
-
const zoomOutPreset = [
|
|
123
|
-
{
|
|
124
|
-
transform: `scale(${o1}, ${o1})`,
|
|
125
|
-
opacity: isFade ? 0 : 1
|
|
126
|
-
},
|
|
127
|
-
{
|
|
128
|
-
transform: `scale(${o2 ?? 0.8}, ${o2 ?? 0.8})`,
|
|
129
|
-
opacity: 1
|
|
130
|
-
}
|
|
131
|
-
];
|
|
132
|
-
const zoomPreset = zoomDirection === 'in' ? zoomInPreset : zoomOutPreset;
|
|
133
|
-
return generateAnimationInstance(target, zoomPreset, {
|
|
134
|
-
...generateOptions(normalizedOptions, 700),
|
|
135
|
-
fill: 'forwards'
|
|
136
|
-
});
|
|
137
|
-
};
|
|
138
|
-
const generateLoopDelayEffect = (keyframes, delay, duration)=>{
|
|
139
|
-
if (!delay) return keyframes;
|
|
140
|
-
const offset = delay / duration;
|
|
141
|
-
const keyframe = [
|
|
142
|
-
...keyframes
|
|
143
|
-
].pop();
|
|
144
|
-
return [
|
|
145
|
-
...keyframes,
|
|
146
|
-
{
|
|
147
|
-
...keyframe,
|
|
148
|
-
offset: 1 - offset
|
|
149
|
-
}
|
|
150
|
-
];
|
|
151
|
-
};
|
|
152
|
-
const shake = (target, options)=>{
|
|
153
|
-
const normalizedOptions = normalizeOptions(options);
|
|
154
|
-
const { intensity } = normalizedOptions ?? {};
|
|
155
|
-
const zeroIntensity = [
|
|
156
|
-
{
|
|
157
|
-
transform: 'translate3d(0, 0, 0)',
|
|
158
|
-
opacity: 1
|
|
159
|
-
}
|
|
160
|
-
];
|
|
161
|
-
const unitIntensity = [
|
|
162
|
-
{
|
|
163
|
-
transform: 'translate3d(4px, 0, 0)',
|
|
164
|
-
opacity: 1
|
|
165
|
-
},
|
|
166
|
-
{
|
|
167
|
-
transform: 'translate3d(-4px, 0, 0)',
|
|
168
|
-
opacity: 1
|
|
169
|
-
},
|
|
170
|
-
{
|
|
171
|
-
transform: 'translate3d(4px, 0, 0)',
|
|
172
|
-
opacity: 1
|
|
173
|
-
}
|
|
174
|
-
];
|
|
175
|
-
let keyframes = [];
|
|
176
|
-
Array.from(Array(intensity ?? 1).keys()).forEach(()=>{
|
|
177
|
-
keyframes = [
|
|
178
|
-
...keyframes,
|
|
179
|
-
...unitIntensity
|
|
180
|
-
];
|
|
181
|
-
});
|
|
182
|
-
const shakePreset = [
|
|
183
|
-
{
|
|
184
|
-
transform: 'translate3d(-1px, 0, 0)',
|
|
185
|
-
opacity: 1
|
|
186
|
-
},
|
|
187
|
-
{
|
|
188
|
-
transform: 'translate3d(2px, 0, 0)',
|
|
189
|
-
opacity: 1
|
|
190
|
-
},
|
|
191
|
-
{
|
|
192
|
-
transform: 'translate3d(-4px, 0, 0)',
|
|
193
|
-
opacity: 1
|
|
194
|
-
},
|
|
195
|
-
...keyframes,
|
|
196
|
-
{
|
|
197
|
-
transform: 'translate3d(-4px, 0, 0)',
|
|
198
|
-
opacity: 1
|
|
199
|
-
},
|
|
200
|
-
{
|
|
201
|
-
transform: 'translate3d(2px, 0, 0)',
|
|
202
|
-
opacity: 1
|
|
203
|
-
},
|
|
204
|
-
{
|
|
205
|
-
transform: 'translate3d(-1px, 0, 0)',
|
|
206
|
-
opacity: 1
|
|
207
|
-
}
|
|
208
|
-
];
|
|
209
|
-
return generateAnimationInstance(target, intensity ? shakePreset : zeroIntensity, {
|
|
210
|
-
...generateOptions(normalizedOptions ?? {}, 820)
|
|
211
|
-
});
|
|
212
|
-
};
|
|
213
|
-
const generateAnimationInstance = (target, effectPreset, options)=>{
|
|
214
|
-
const effect = new KeyframeEffect(target, options.iterations && options.iterations === 1 ? effectPreset : generateLoopDelayEffect(effectPreset, options?.delay ?? 0, (options?.duration) ?? 0), {
|
|
215
|
-
...options
|
|
216
|
-
});
|
|
217
|
-
return new Animation(effect, document.timeline);
|
|
218
|
-
};
|
|
219
|
-
return {
|
|
220
|
-
zoom,
|
|
221
|
-
shake,
|
|
222
|
-
fade,
|
|
223
|
-
slide
|
|
224
|
-
};
|
|
225
|
-
};
|
|
226
|
-
|
|
227
|
-
exports.animations = animations;
|