1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.MotionLinearGradient = void 0;
|
7 | exports.setLinearGradientComponent = setLinearGradientComponent;
|
8 | var _tools = require("@legendapp/tools");
|
9 | var _react = require("@legendapp/tools/react");
|
10 | var _react2 = _interopRequireWildcard(require("react"));
|
11 | var _createMotionComponent = require("./createMotionComponent");
|
12 | function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
13 | function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
14 | function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
15 | let LinearGradient;
|
16 | function setLinearGradientComponent(linearGradient) {
|
17 | LinearGradient = linearGradient;
|
18 | }
|
19 | class GradientHelper extends _react2.Component {
|
20 | render() {
|
21 | const {
|
22 | numColors,
|
23 | startX,
|
24 | startY,
|
25 | endX,
|
26 | endY,
|
27 | ...rest
|
28 | } = this.props;
|
29 |
|
30 |
|
31 | let start;
|
32 | if (startX !== undefined || startY !== undefined) {
|
33 | start = {
|
34 | x: startX,
|
35 | y: startY
|
36 | };
|
37 | }
|
38 | let end;
|
39 | if (endX !== undefined || endY !== undefined) {
|
40 | end = {
|
41 | x: endX,
|
42 | y: endY
|
43 | };
|
44 | }
|
45 |
|
46 |
|
47 | const colors = [];
|
48 | for (let i = 0; i < numColors; i++) {
|
49 | colors.push(rest['color' + i]);
|
50 | delete rest['color' + i];
|
51 | }
|
52 | return _react2.default.createElement(LinearGradient, _extends({
|
53 | colors: colors,
|
54 | start: start,
|
55 | end: end
|
56 | }, rest));
|
57 | }
|
58 | }
|
59 | const AnimatedGradientHelper = (0, _createMotionComponent.createMotionAnimatedComponent)(GradientHelper);
|
60 | function pointToXY(props, point, name) {
|
61 | if (point) {
|
62 | props[name + 'X'] = (0, _tools.isArray)(point) ? point[0] : point.x;
|
63 | props[name + 'Y'] = (0, _tools.isArray)(point) ? point[1] : point.y;
|
64 | }
|
65 | }
|
66 |
|
67 |
|
68 |
|
69 | const MotionLinearGradient = (0, _react.MemoFnComponent)(function (props) {
|
70 | const {
|
71 | colors,
|
72 | animateProps,
|
73 | start,
|
74 | end,
|
75 | initialProps,
|
76 | ...propsOut
|
77 | } = props;
|
78 | const {
|
79 | colors: colorsAnimate,
|
80 | start: startAnimate,
|
81 | end: endAnimate,
|
82 | ...animatePropsOut
|
83 | } = animateProps;
|
84 |
|
85 |
|
86 | colors === null || colors === void 0 ? void 0 : colors.forEach((color, i) => propsOut['color' + i] = color);
|
87 | colorsAnimate === null || colorsAnimate === void 0 ? void 0 : colorsAnimate.forEach((color, i) => animatePropsOut['color' + i] = color);
|
88 |
|
89 |
|
90 | pointToXY(propsOut, start, 'start');
|
91 | pointToXY(propsOut, end, 'end');
|
92 | pointToXY(animatePropsOut, startAnimate, 'start');
|
93 | pointToXY(animatePropsOut, endAnimate, 'end');
|
94 | let numColors = (colors === null || colors === void 0 ? void 0 : colors.length) || (colorsAnimate === null || colorsAnimate === void 0 ? void 0 : colorsAnimate.length) || 0;
|
95 |
|
96 |
|
97 | const initialPropsOut = {};
|
98 | if (initialProps) {
|
99 | const {
|
100 | colors: colorsInitial,
|
101 | start: startInitial,
|
102 | end: endInitial
|
103 | } = animateProps;
|
104 | colorsInitial === null || colorsInitial === void 0 ? void 0 : colorsInitial.forEach((color, i) => initialPropsOut['color' + i] = color);
|
105 | pointToXY(initialPropsOut, startInitial, 'start');
|
106 | pointToXY(initialPropsOut, endInitial, 'end');
|
107 | if (colorsInitial) {
|
108 | numColors = colorsInitial.length;
|
109 | }
|
110 | }
|
111 |
|
112 |
|
113 | return _react2.default.createElement(AnimatedGradientHelper, _extends({
|
114 | numColors: numColors
|
115 | }, propsOut, {
|
116 | initialProps: initialPropsOut,
|
117 | animateProps: animatePropsOut
|
118 | }));
|
119 | });
|
120 | exports.MotionLinearGradient = MotionLinearGradient;
|
121 |
|
\ | No newline at end of file |