@depup/lottie-react 2.4.1-depup.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.
package/build/index.js ADDED
@@ -0,0 +1,667 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var lottie = require('lottie-web');
6
+ var React = require('react');
7
+
8
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
9
+
10
+ var lottie__default = /*#__PURE__*/_interopDefaultLegacy(lottie);
11
+ var React__default = /*#__PURE__*/_interopDefaultLegacy(React);
12
+
13
+ function _arrayLikeToArray(r, a) {
14
+ (null == a || a > r.length) && (a = r.length);
15
+ for (var e = 0, n = Array(a); e < a; e++) n[e] = r[e];
16
+ return n;
17
+ }
18
+ function _arrayWithHoles(r) {
19
+ if (Array.isArray(r)) return r;
20
+ }
21
+ function _defineProperty(e, r, t) {
22
+ return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
23
+ value: t,
24
+ enumerable: !0,
25
+ configurable: !0,
26
+ writable: !0
27
+ }) : e[r] = t, e;
28
+ }
29
+ function _iterableToArrayLimit(r, l) {
30
+ var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"];
31
+ if (null != t) {
32
+ var e,
33
+ n,
34
+ i,
35
+ u,
36
+ a = [],
37
+ f = !0,
38
+ o = !1;
39
+ try {
40
+ if (i = (t = t.call(r)).next, 0 === l) {
41
+ if (Object(t) !== t) return;
42
+ f = !1;
43
+ } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0);
44
+ } catch (r) {
45
+ o = !0, n = r;
46
+ } finally {
47
+ try {
48
+ if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return;
49
+ } finally {
50
+ if (o) throw n;
51
+ }
52
+ }
53
+ return a;
54
+ }
55
+ }
56
+ function _nonIterableRest() {
57
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
+ }
59
+ function ownKeys(e, r) {
60
+ var t = Object.keys(e);
61
+ if (Object.getOwnPropertySymbols) {
62
+ var o = Object.getOwnPropertySymbols(e);
63
+ r && (o = o.filter(function (r) {
64
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
65
+ })), t.push.apply(t, o);
66
+ }
67
+ return t;
68
+ }
69
+ function _objectSpread2(e) {
70
+ for (var r = 1; r < arguments.length; r++) {
71
+ var t = null != arguments[r] ? arguments[r] : {};
72
+ r % 2 ? ownKeys(Object(t), !0).forEach(function (r) {
73
+ _defineProperty(e, r, t[r]);
74
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) {
75
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
76
+ });
77
+ }
78
+ return e;
79
+ }
80
+ function _objectWithoutProperties(e, t) {
81
+ if (null == e) return {};
82
+ var o,
83
+ r,
84
+ i = _objectWithoutPropertiesLoose(e, t);
85
+ if (Object.getOwnPropertySymbols) {
86
+ var s = Object.getOwnPropertySymbols(e);
87
+ for (r = 0; r < s.length; r++) o = s[r], t.includes(o) || {}.propertyIsEnumerable.call(e, o) && (i[o] = e[o]);
88
+ }
89
+ return i;
90
+ }
91
+ function _objectWithoutPropertiesLoose(r, e) {
92
+ if (null == r) return {};
93
+ var t = {};
94
+ for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
95
+ if (e.includes(n)) continue;
96
+ t[n] = r[n];
97
+ }
98
+ return t;
99
+ }
100
+ function _slicedToArray(r, e) {
101
+ return _arrayWithHoles(r) || _iterableToArrayLimit(r, e) || _unsupportedIterableToArray(r, e) || _nonIterableRest();
102
+ }
103
+ function _toPrimitive(t, r) {
104
+ if ("object" != typeof t || !t) return t;
105
+ var e = t[Symbol.toPrimitive];
106
+ if (void 0 !== e) {
107
+ var i = e.call(t, r || "default");
108
+ if ("object" != typeof i) return i;
109
+ throw new TypeError("@@toPrimitive must return a primitive value.");
110
+ }
111
+ return ("string" === r ? String : Number)(t);
112
+ }
113
+ function _toPropertyKey(t) {
114
+ var i = _toPrimitive(t, "string");
115
+ return "symbol" == typeof i ? i : i + "";
116
+ }
117
+ function _unsupportedIterableToArray(r, a) {
118
+ if (r) {
119
+ if ("string" == typeof r) return _arrayLikeToArray(r, a);
120
+ var t = {}.toString.call(r).slice(8, -1);
121
+ return "Object" === t && r.constructor && (t = r.constructor.name), "Map" === t || "Set" === t ? Array.from(r) : "Arguments" === t || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(t) ? _arrayLikeToArray(r, a) : void 0;
122
+ }
123
+ }
124
+
125
+ var _excluded$1 = ["animationData", "loop", "autoplay", "initialSegment", "onComplete", "onLoopComplete", "onEnterFrame", "onSegmentStart", "onConfigReady", "onDataReady", "onDataFailed", "onLoadedImages", "onDOMLoaded", "onDestroy", "lottieRef", "renderer", "name", "assetsPath", "rendererSettings"];
126
+ var useLottie = function useLottie(props, style) {
127
+ var animationData = props.animationData,
128
+ loop = props.loop,
129
+ autoplay = props.autoplay,
130
+ initialSegment = props.initialSegment,
131
+ onComplete = props.onComplete,
132
+ onLoopComplete = props.onLoopComplete,
133
+ onEnterFrame = props.onEnterFrame,
134
+ onSegmentStart = props.onSegmentStart,
135
+ onConfigReady = props.onConfigReady,
136
+ onDataReady = props.onDataReady,
137
+ onDataFailed = props.onDataFailed,
138
+ onLoadedImages = props.onLoadedImages,
139
+ onDOMLoaded = props.onDOMLoaded,
140
+ onDestroy = props.onDestroy;
141
+ props.lottieRef;
142
+ props.renderer;
143
+ props.name;
144
+ props.assetsPath;
145
+ props.rendererSettings;
146
+ var rest = _objectWithoutProperties(props, _excluded$1);
147
+ var _useState = React.useState(false),
148
+ _useState2 = _slicedToArray(_useState, 2),
149
+ animationLoaded = _useState2[0],
150
+ setAnimationLoaded = _useState2[1];
151
+ var animationInstanceRef = React.useRef();
152
+ var animationContainer = React.useRef(null);
153
+ /*
154
+ ======================================
155
+ INTERACTION METHODS
156
+ ======================================
157
+ */
158
+ /**
159
+ * Play
160
+ */
161
+ var play = function play() {
162
+ var _a;
163
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.play();
164
+ };
165
+ /**
166
+ * Stop
167
+ */
168
+ var stop = function stop() {
169
+ var _a;
170
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.stop();
171
+ };
172
+ /**
173
+ * Pause
174
+ */
175
+ var pause = function pause() {
176
+ var _a;
177
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.pause();
178
+ };
179
+ /**
180
+ * Set animation speed
181
+ * @param speed
182
+ */
183
+ var setSpeed = function setSpeed(speed) {
184
+ var _a;
185
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setSpeed(speed);
186
+ };
187
+ /**
188
+ * Got to frame and play
189
+ * @param value
190
+ * @param isFrame
191
+ */
192
+ var goToAndPlay = function goToAndPlay(value, isFrame) {
193
+ var _a;
194
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.goToAndPlay(value, isFrame);
195
+ };
196
+ /**
197
+ * Got to frame and stop
198
+ * @param value
199
+ * @param isFrame
200
+ */
201
+ var goToAndStop = function goToAndStop(value, isFrame) {
202
+ var _a;
203
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.goToAndStop(value, isFrame);
204
+ };
205
+ /**
206
+ * Set animation direction
207
+ * @param direction
208
+ */
209
+ var setDirection = function setDirection(direction) {
210
+ var _a;
211
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setDirection(direction);
212
+ };
213
+ /**
214
+ * Play animation segments
215
+ * @param segments
216
+ * @param forceFlag
217
+ */
218
+ var playSegments = function playSegments(segments, forceFlag) {
219
+ var _a;
220
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.playSegments(segments, forceFlag);
221
+ };
222
+ /**
223
+ * Set sub frames
224
+ * @param useSubFrames
225
+ */
226
+ var setSubframe = function setSubframe(useSubFrames) {
227
+ var _a;
228
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.setSubframe(useSubFrames);
229
+ };
230
+ /**
231
+ * Get animation duration
232
+ * @param inFrames
233
+ */
234
+ var getDuration = function getDuration(inFrames) {
235
+ var _a;
236
+ return (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.getDuration(inFrames);
237
+ };
238
+ /**
239
+ * Destroy animation
240
+ */
241
+ var destroy = function destroy() {
242
+ var _a;
243
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
244
+ // Removing the reference to the animation so separate cleanups are skipped.
245
+ // Without it the internal `lottie-react` instance throws exceptions as it already cleared itself on destroy.
246
+ animationInstanceRef.current = undefined;
247
+ };
248
+ /*
249
+ ======================================
250
+ LOTTIE
251
+ ======================================
252
+ */
253
+ /**
254
+ * Load a new animation, and if it's the case, destroy the previous one
255
+ * @param {Object} forcedConfigs
256
+ */
257
+ var loadAnimation = function loadAnimation() {
258
+ var forcedConfigs = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
259
+ var _a;
260
+ // Return if the container ref is null
261
+ if (!animationContainer.current) {
262
+ return;
263
+ }
264
+ // Destroy any previous instance
265
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
266
+ // Build the animation configuration
267
+ var config = _objectSpread2(_objectSpread2(_objectSpread2({}, props), forcedConfigs), {}, {
268
+ container: animationContainer.current
269
+ });
270
+ // Save the animation instance
271
+ animationInstanceRef.current = lottie__default["default"].loadAnimation(config);
272
+ setAnimationLoaded(!!animationInstanceRef.current);
273
+ // Return a function that will clean up
274
+ return function () {
275
+ var _a;
276
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.destroy();
277
+ animationInstanceRef.current = undefined;
278
+ };
279
+ };
280
+ /**
281
+ * (Re)Initialize when animation data changed
282
+ */
283
+ React.useEffect(function () {
284
+ var onUnmount = loadAnimation();
285
+ // Clean up on unmount
286
+ return function () {
287
+ return onUnmount === null || onUnmount === void 0 ? void 0 : onUnmount();
288
+ };
289
+ // eslint-disable-next-line react-hooks/exhaustive-deps
290
+ }, [animationData, loop]);
291
+ // Update the autoplay state
292
+ React.useEffect(function () {
293
+ if (!animationInstanceRef.current) {
294
+ return;
295
+ }
296
+ animationInstanceRef.current.autoplay = !!autoplay;
297
+ }, [autoplay]);
298
+ // Update the initial segment state
299
+ React.useEffect(function () {
300
+ if (!animationInstanceRef.current) {
301
+ return;
302
+ }
303
+ // When null should reset to default animation length
304
+ if (!initialSegment) {
305
+ animationInstanceRef.current.resetSegments(true);
306
+ return;
307
+ }
308
+ // If it's not a valid segment, do nothing
309
+ if (!Array.isArray(initialSegment) || !initialSegment.length) {
310
+ return;
311
+ }
312
+ // If the current position it's not in the new segment
313
+ // set the current position to start
314
+ if (animationInstanceRef.current.currentRawFrame < initialSegment[0] || animationInstanceRef.current.currentRawFrame > initialSegment[1]) {
315
+ animationInstanceRef.current.currentRawFrame = initialSegment[0];
316
+ }
317
+ // Update the segment
318
+ animationInstanceRef.current.setSegment(initialSegment[0], initialSegment[1]);
319
+ }, [initialSegment]);
320
+ /*
321
+ ======================================
322
+ EVENTS
323
+ ======================================
324
+ */
325
+ /**
326
+ * Reinitialize listener on change
327
+ */
328
+ React.useEffect(function () {
329
+ var partialListeners = [{
330
+ name: "complete",
331
+ handler: onComplete
332
+ }, {
333
+ name: "loopComplete",
334
+ handler: onLoopComplete
335
+ }, {
336
+ name: "enterFrame",
337
+ handler: onEnterFrame
338
+ }, {
339
+ name: "segmentStart",
340
+ handler: onSegmentStart
341
+ }, {
342
+ name: "config_ready",
343
+ handler: onConfigReady
344
+ }, {
345
+ name: "data_ready",
346
+ handler: onDataReady
347
+ }, {
348
+ name: "data_failed",
349
+ handler: onDataFailed
350
+ }, {
351
+ name: "loaded_images",
352
+ handler: onLoadedImages
353
+ }, {
354
+ name: "DOMLoaded",
355
+ handler: onDOMLoaded
356
+ }, {
357
+ name: "destroy",
358
+ handler: onDestroy
359
+ }];
360
+ var listeners = partialListeners.filter(function (listener) {
361
+ return listener.handler != null;
362
+ });
363
+ if (!listeners.length) {
364
+ return;
365
+ }
366
+ var deregisterList = listeners.map(
367
+ /**
368
+ * Handle the process of adding an event listener
369
+ * @param {Listener} listener
370
+ * @return {Function} Function that deregister the listener
371
+ */
372
+ function (listener) {
373
+ var _a;
374
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.addEventListener(listener.name, listener.handler);
375
+ // Return a function to deregister this listener
376
+ return function () {
377
+ var _a;
378
+ (_a = animationInstanceRef.current) === null || _a === void 0 ? void 0 : _a.removeEventListener(listener.name, listener.handler);
379
+ };
380
+ });
381
+ // Deregister listeners on unmount
382
+ return function () {
383
+ deregisterList.forEach(function (deregister) {
384
+ return deregister();
385
+ });
386
+ };
387
+ }, [onComplete, onLoopComplete, onEnterFrame, onSegmentStart, onConfigReady, onDataReady, onDataFailed, onLoadedImages, onDOMLoaded, onDestroy]);
388
+ /**
389
+ * Build the animation view
390
+ */
391
+ var View = /*#__PURE__*/React__default["default"].createElement("div", _objectSpread2({
392
+ style: style,
393
+ ref: animationContainer
394
+ }, rest));
395
+ return {
396
+ View: View,
397
+ play: play,
398
+ stop: stop,
399
+ pause: pause,
400
+ setSpeed: setSpeed,
401
+ goToAndStop: goToAndStop,
402
+ goToAndPlay: goToAndPlay,
403
+ setDirection: setDirection,
404
+ playSegments: playSegments,
405
+ setSubframe: setSubframe,
406
+ getDuration: getDuration,
407
+ destroy: destroy,
408
+ animationContainerRef: animationContainer,
409
+ animationLoaded: animationLoaded,
410
+ animationItem: animationInstanceRef.current
411
+ };
412
+ };
413
+
414
+ // helpers
415
+ function getContainerVisibility(container) {
416
+ var _container$getBoundin = container.getBoundingClientRect(),
417
+ top = _container$getBoundin.top,
418
+ height = _container$getBoundin.height;
419
+ var current = window.innerHeight - top;
420
+ var max = window.innerHeight + height;
421
+ return current / max;
422
+ }
423
+ function getContainerCursorPosition(container, cursorX, cursorY) {
424
+ var _container$getBoundin2 = container.getBoundingClientRect(),
425
+ top = _container$getBoundin2.top,
426
+ left = _container$getBoundin2.left,
427
+ width = _container$getBoundin2.width,
428
+ height = _container$getBoundin2.height;
429
+ var x = (cursorX - left) / width;
430
+ var y = (cursorY - top) / height;
431
+ return {
432
+ x: x,
433
+ y: y
434
+ };
435
+ }
436
+ var useInitInteractivity = function useInitInteractivity(_ref) {
437
+ var wrapperRef = _ref.wrapperRef,
438
+ animationItem = _ref.animationItem,
439
+ mode = _ref.mode,
440
+ actions = _ref.actions;
441
+ React.useEffect(function () {
442
+ var wrapper = wrapperRef.current;
443
+ if (!wrapper || !animationItem || !actions.length) {
444
+ return;
445
+ }
446
+ animationItem.stop();
447
+ var scrollModeHandler = function scrollModeHandler() {
448
+ var assignedSegment = null;
449
+ var scrollHandler = function scrollHandler() {
450
+ var currentPercent = getContainerVisibility(wrapper);
451
+ // Find the first action that satisfies the current position conditions
452
+ var action = actions.find(function (_ref2) {
453
+ var visibility = _ref2.visibility;
454
+ return visibility && currentPercent >= visibility[0] && currentPercent <= visibility[1];
455
+ });
456
+ // Skip if no matching action was found!
457
+ if (!action) {
458
+ return;
459
+ }
460
+ if (action.type === "seek" && action.visibility && action.frames.length === 2) {
461
+ // Seek: Go to a frame based on player scroll position action
462
+ var frameToGo = action.frames[0] + Math.ceil((currentPercent - action.visibility[0]) / (action.visibility[1] - action.visibility[0]) * action.frames[1]);
463
+ //! goToAndStop must be relative to the start of the current segment
464
+ animationItem.goToAndStop(frameToGo - animationItem.firstFrame - 1, true);
465
+ }
466
+ if (action.type === "loop") {
467
+ // Loop: Loop a given frames
468
+ if (assignedSegment === null) {
469
+ // if not playing any segments currently. play those segments and save to state
470
+ animationItem.playSegments(action.frames, true);
471
+ assignedSegment = action.frames;
472
+ } else {
473
+ // if playing any segments currently.
474
+ //check if segments in state are equal to the frames selected by action
475
+ if (assignedSegment !== action.frames) {
476
+ // if they are not equal. new segments are to be loaded
477
+ animationItem.playSegments(action.frames, true);
478
+ assignedSegment = action.frames;
479
+ } else if (animationItem.isPaused) {
480
+ // if they are equal the play method must be called only if lottie is paused
481
+ animationItem.playSegments(action.frames, true);
482
+ assignedSegment = action.frames;
483
+ }
484
+ }
485
+ }
486
+ if (action.type === "play" && animationItem.isPaused) {
487
+ // Play: Reset segments and continue playing full animation from current position
488
+ animationItem.resetSegments(true);
489
+ animationItem.play();
490
+ }
491
+ if (action.type === "stop") {
492
+ // Stop: Stop playback
493
+ animationItem.goToAndStop(action.frames[0] - animationItem.firstFrame - 1, true);
494
+ }
495
+ };
496
+ document.addEventListener("scroll", scrollHandler);
497
+ return function () {
498
+ document.removeEventListener("scroll", scrollHandler);
499
+ };
500
+ };
501
+ var cursorModeHandler = function cursorModeHandler() {
502
+ var handleCursor = function handleCursor(_x, _y) {
503
+ var x = _x;
504
+ var y = _y;
505
+ // Resolve cursor position if cursor is inside container
506
+ if (x !== -1 && y !== -1) {
507
+ // Get container cursor position
508
+ var pos = getContainerCursorPosition(wrapper, x, y);
509
+ // Use the resolved position
510
+ x = pos.x;
511
+ y = pos.y;
512
+ }
513
+ // Find the first action that satisfies the current position conditions
514
+ var action = actions.find(function (_ref3) {
515
+ var position = _ref3.position;
516
+ if (position && Array.isArray(position.x) && Array.isArray(position.y)) {
517
+ return x >= position.x[0] && x <= position.x[1] && y >= position.y[0] && y <= position.y[1];
518
+ }
519
+ if (position && !Number.isNaN(position.x) && !Number.isNaN(position.y)) {
520
+ return x === position.x && y === position.y;
521
+ }
522
+ return false;
523
+ });
524
+ // Skip if no matching action was found!
525
+ if (!action) {
526
+ return;
527
+ }
528
+ // Process action types:
529
+ if (action.type === "seek" && action.position && Array.isArray(action.position.x) && Array.isArray(action.position.y) && action.frames.length === 2) {
530
+ // Seek: Go to a frame based on player scroll position action
531
+ var xPercent = (x - action.position.x[0]) / (action.position.x[1] - action.position.x[0]);
532
+ var yPercent = (y - action.position.y[0]) / (action.position.y[1] - action.position.y[0]);
533
+ animationItem.playSegments(action.frames, true);
534
+ animationItem.goToAndStop(Math.ceil((xPercent + yPercent) / 2 * (action.frames[1] - action.frames[0])), true);
535
+ }
536
+ if (action.type === "loop") {
537
+ animationItem.playSegments(action.frames, true);
538
+ }
539
+ if (action.type === "play") {
540
+ // Play: Reset segments and continue playing full animation from current position
541
+ if (animationItem.isPaused) {
542
+ animationItem.resetSegments(false);
543
+ }
544
+ animationItem.playSegments(action.frames);
545
+ }
546
+ if (action.type === "stop") {
547
+ animationItem.goToAndStop(action.frames[0], true);
548
+ }
549
+ };
550
+ var mouseMoveHandler = function mouseMoveHandler(ev) {
551
+ handleCursor(ev.clientX, ev.clientY);
552
+ };
553
+ var mouseOutHandler = function mouseOutHandler() {
554
+ handleCursor(-1, -1);
555
+ };
556
+ wrapper.addEventListener("mousemove", mouseMoveHandler);
557
+ wrapper.addEventListener("mouseout", mouseOutHandler);
558
+ return function () {
559
+ wrapper.removeEventListener("mousemove", mouseMoveHandler);
560
+ wrapper.removeEventListener("mouseout", mouseOutHandler);
561
+ };
562
+ };
563
+ switch (mode) {
564
+ case "scroll":
565
+ return scrollModeHandler();
566
+ case "cursor":
567
+ return cursorModeHandler();
568
+ }
569
+ // eslint-disable-next-line react-hooks/exhaustive-deps
570
+ }, [mode, animationItem]);
571
+ };
572
+ var useLottieInteractivity = function useLottieInteractivity(_ref4) {
573
+ var actions = _ref4.actions,
574
+ mode = _ref4.mode,
575
+ lottieObj = _ref4.lottieObj;
576
+ var animationItem = lottieObj.animationItem,
577
+ View = lottieObj.View,
578
+ animationContainerRef = lottieObj.animationContainerRef;
579
+ useInitInteractivity({
580
+ actions: actions,
581
+ animationItem: animationItem,
582
+ mode: mode,
583
+ wrapperRef: animationContainerRef
584
+ });
585
+ return View;
586
+ };
587
+
588
+ var _excluded = ["style", "interactivity"];
589
+ var Lottie = function Lottie(props) {
590
+ var _a, _b, _c;
591
+ var style = props.style,
592
+ interactivity = props.interactivity,
593
+ lottieProps = _objectWithoutProperties(props, _excluded);
594
+ /**
595
+ * Initialize the 'useLottie' hook
596
+ */
597
+ var _useLottie = useLottie(lottieProps, style),
598
+ View = _useLottie.View,
599
+ play = _useLottie.play,
600
+ stop = _useLottie.stop,
601
+ pause = _useLottie.pause,
602
+ setSpeed = _useLottie.setSpeed,
603
+ goToAndStop = _useLottie.goToAndStop,
604
+ goToAndPlay = _useLottie.goToAndPlay,
605
+ setDirection = _useLottie.setDirection,
606
+ playSegments = _useLottie.playSegments,
607
+ setSubframe = _useLottie.setSubframe,
608
+ getDuration = _useLottie.getDuration,
609
+ destroy = _useLottie.destroy,
610
+ animationContainerRef = _useLottie.animationContainerRef,
611
+ animationLoaded = _useLottie.animationLoaded,
612
+ animationItem = _useLottie.animationItem;
613
+ /**
614
+ * Make the hook variables/methods available through the provided 'lottieRef'
615
+ */
616
+ React.useEffect(function () {
617
+ if (props.lottieRef) {
618
+ props.lottieRef.current = {
619
+ play: play,
620
+ stop: stop,
621
+ pause: pause,
622
+ setSpeed: setSpeed,
623
+ goToAndPlay: goToAndPlay,
624
+ goToAndStop: goToAndStop,
625
+ setDirection: setDirection,
626
+ playSegments: playSegments,
627
+ setSubframe: setSubframe,
628
+ getDuration: getDuration,
629
+ destroy: destroy,
630
+ animationContainerRef: animationContainerRef,
631
+ animationLoaded: animationLoaded,
632
+ animationItem: animationItem
633
+ };
634
+ }
635
+ // eslint-disable-next-line react-hooks/exhaustive-deps
636
+ }, [(_a = props.lottieRef) === null || _a === void 0 ? void 0 : _a.current]);
637
+ return useLottieInteractivity({
638
+ lottieObj: {
639
+ View: View,
640
+ play: play,
641
+ stop: stop,
642
+ pause: pause,
643
+ setSpeed: setSpeed,
644
+ goToAndStop: goToAndStop,
645
+ goToAndPlay: goToAndPlay,
646
+ setDirection: setDirection,
647
+ playSegments: playSegments,
648
+ setSubframe: setSubframe,
649
+ getDuration: getDuration,
650
+ destroy: destroy,
651
+ animationContainerRef: animationContainerRef,
652
+ animationLoaded: animationLoaded,
653
+ animationItem: animationItem
654
+ },
655
+ actions: (_b = interactivity === null || interactivity === void 0 ? void 0 : interactivity.actions) !== null && _b !== void 0 ? _b : [],
656
+ mode: (_c = interactivity === null || interactivity === void 0 ? void 0 : interactivity.mode) !== null && _c !== void 0 ? _c : "scroll"
657
+ });
658
+ };
659
+
660
+ Object.defineProperty(exports, 'LottiePlayer', {
661
+ enumerable: true,
662
+ get: function () { return lottie__default["default"]; }
663
+ });
664
+ exports["default"] = Lottie;
665
+ exports.useLottie = useLottie;
666
+ exports.useLottieInteractivity = useLottieInteractivity;
667
+ //# sourceMappingURL=index.js.map