@depup/lottie-react 2.4.1-depup.0 → 3.0.0-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/LICENSE.md +9 -0
- package/README.md +4 -10
- package/build/_virtual/_rolldown/runtime.cjs +23 -0
- package/build/animation/Lottie.cjs +39 -0
- package/build/animation/Lottie.d.cts +47 -0
- package/build/animation/Lottie.d.ts +47 -0
- package/build/animation/Lottie.js +37 -0
- package/build/animation/LottieDisplay.cjs +55 -0
- package/build/animation/LottieDisplay.d.cts +46 -0
- package/build/animation/LottieDisplay.d.ts +46 -0
- package/build/animation/LottieDisplay.js +53 -0
- package/build/animation/LottieInstanceContext.cjs +16 -0
- package/build/animation/LottieInstanceContext.js +17 -0
- package/build/animation/LottieLight.cjs +19 -0
- package/build/animation/LottieLight.d.cts +23 -0
- package/build/animation/LottieLight.d.ts +23 -0
- package/build/animation/LottieLight.js +17 -0
- package/build/animation/LottieRegistryContext.cjs +36 -0
- package/build/animation/LottieRegistryContext.js +35 -0
- package/build/animation/LottieSvg.cjs +20 -0
- package/build/animation/LottieSvg.d.cts +24 -0
- package/build/animation/LottieSvg.d.ts +24 -0
- package/build/animation/LottieSvg.js +18 -0
- package/build/animation/collectMarkerCrossings.cjs +38 -0
- package/build/animation/collectMarkerCrossings.js +38 -0
- package/build/animation/createLottieComponent.cjs +131 -0
- package/build/animation/createLottieComponent.d.cts +45 -0
- package/build/animation/createLottieComponent.d.ts +45 -0
- package/build/animation/createLottieComponent.js +131 -0
- package/build/animation/hasExpressions.cjs +25 -0
- package/build/animation/hasExpressions.js +25 -0
- package/build/animation/normalizeAnimationSource.cjs +38 -0
- package/build/animation/normalizeAnimationSource.js +38 -0
- package/build/animation/polymorphicForwardRef.cjs +18 -0
- package/build/animation/polymorphicForwardRef.js +19 -0
- package/build/animation/renderStyledElement.cjs +31 -0
- package/build/animation/renderStyledElement.js +31 -0
- package/build/animation/resolveSeekTarget.cjs +97 -0
- package/build/animation/resolveSeekTarget.js +95 -0
- package/build/animation/styleLayer.cjs +24 -0
- package/build/animation/styleLayer.js +24 -0
- package/build/animation/stylePrecedence.cjs +12 -0
- package/build/animation/stylePrecedence.js +12 -0
- package/build/animation/types.cjs +71 -0
- package/build/animation/types.d.cts +461 -0
- package/build/animation/types.d.ts +461 -0
- package/build/animation/types.js +68 -0
- package/build/animation/useLottie.cjs +40 -0
- package/build/animation/useLottie.d.cts +36 -0
- package/build/animation/useLottie.d.ts +36 -0
- package/build/animation/useLottie.js +38 -0
- package/build/animation/useLottieAnimation.cjs +434 -0
- package/build/animation/useLottieAnimation.d.cts +40 -0
- package/build/animation/useLottieAnimation.d.ts +40 -0
- package/build/animation/useLottieAnimation.js +434 -0
- package/build/animation/useLottieInstance.cjs +20 -0
- package/build/animation/useLottieInstance.d.cts +14 -0
- package/build/animation/useLottieInstance.d.ts +14 -0
- package/build/animation/useLottieInstance.js +20 -0
- package/build/animation/useLottieLight.cjs +20 -0
- package/build/animation/useLottieLight.d.cts +16 -0
- package/build/animation/useLottieLight.d.ts +16 -0
- package/build/animation/useLottieLight.js +18 -0
- package/build/animation/useLottieSvg.cjs +18 -0
- package/build/animation/useLottieSvg.d.cts +14 -0
- package/build/animation/useLottieSvg.d.ts +14 -0
- package/build/animation/useLottieSvg.js +16 -0
- package/build/controls/LottieControls.cjs +180 -0
- package/build/controls/LottieControls.d.cts +58 -0
- package/build/controls/LottieControls.d.ts +58 -0
- package/build/controls/LottieControls.js +178 -0
- package/build/controls/LottieDirectionButton.cjs +36 -0
- package/build/controls/LottieDirectionButton.js +35 -0
- package/build/controls/LottieFullscreenButton.cjs +35 -0
- package/build/controls/LottieFullscreenButton.js +34 -0
- package/build/controls/LottieLoopButton.cjs +32 -0
- package/build/controls/LottieLoopButton.js +31 -0
- package/build/controls/LottiePlayButton.cjs +34 -0
- package/build/controls/LottiePlayButton.js +33 -0
- package/build/controls/LottieReadout.cjs +61 -0
- package/build/controls/LottieReadout.d.cts +13 -0
- package/build/controls/LottieReadout.d.ts +13 -0
- package/build/controls/LottieReadout.js +60 -0
- package/build/controls/LottieSeekBar.cjs +87 -0
- package/build/controls/LottieSeekBar.js +86 -0
- package/build/controls/LottieSpeedSelect.cjs +51 -0
- package/build/controls/LottieSpeedSelect.js +50 -0
- package/build/controls/LottieStopButton.cjs +29 -0
- package/build/controls/LottieStopButton.js +28 -0
- package/build/controls/controlIcon.cjs +25 -0
- package/build/controls/controlIcon.js +25 -0
- package/build/controls/useFullscreen.cjs +46 -0
- package/build/controls/useFullscreen.js +46 -0
- package/build/controls/useShortcuts.cjs +70 -0
- package/build/controls/useShortcuts.js +70 -0
- package/build/index.cjs +36 -0
- package/build/index.d.cts +19 -0
- package/build/index.d.ts +19 -80
- package/build/index.js +17 -667
- package/build/interactions/LottieInteractions.cjs +41 -0
- package/build/interactions/LottieInteractions.d.cts +37 -0
- package/build/interactions/LottieInteractions.d.ts +37 -0
- package/build/interactions/LottieInteractions.js +41 -0
- package/build/interactions/coverProgress.cjs +55 -0
- package/build/interactions/coverProgress.js +53 -0
- package/build/interactions/lottieInView.cjs +109 -0
- package/build/interactions/lottieInView.d.cts +44 -0
- package/build/interactions/lottieInView.d.ts +44 -0
- package/build/interactions/lottieInView.js +109 -0
- package/build/interactions/lottieScrollScrub.cjs +152 -0
- package/build/interactions/lottieScrollScrub.d.cts +47 -0
- package/build/interactions/lottieScrollScrub.d.ts +47 -0
- package/build/interactions/lottieScrollScrub.js +152 -0
- package/build/interactions/types.d.cts +46 -0
- package/build/interactions/types.d.ts +46 -0
- package/build/interactions/useInteractionsRunner.cjs +142 -0
- package/build/interactions/useInteractionsRunner.js +141 -0
- package/build/interactions/useLottieInteractions.cjs +21 -0
- package/build/interactions/useLottieInteractions.d.cts +19 -0
- package/build/interactions/useLottieInteractions.d.ts +19 -0
- package/build/interactions/useLottieInteractions.js +21 -0
- package/build/overlays/LottieError.cjs +74 -0
- package/build/overlays/LottieError.d.cts +40 -0
- package/build/overlays/LottieError.d.ts +40 -0
- package/build/overlays/LottieError.js +72 -0
- package/build/overlays/LottieLoading.cjs +89 -0
- package/build/overlays/LottieLoading.d.cts +45 -0
- package/build/overlays/LottieLoading.d.ts +45 -0
- package/build/overlays/LottieLoading.js +87 -0
- package/build/overlays/overlayStyles.cjs +33 -0
- package/build/overlays/overlayStyles.js +33 -0
- package/build/utils/SubscriptionManager.cjs +42 -0
- package/build/utils/SubscriptionManager.d.cts +30 -0
- package/build/utils/SubscriptionManager.d.ts +30 -0
- package/build/utils/SubscriptionManager.js +42 -0
- package/build/utils/createLogger.cjs +25 -0
- package/build/utils/createLogger.js +25 -0
- package/build/utils/isSameJson.cjs +37 -0
- package/build/utils/isSameJson.js +37 -0
- package/build/utils/mergeRefs.cjs +37 -0
- package/build/utils/mergeRefs.js +37 -0
- package/build/utils/useStableValue.cjs +26 -0
- package/build/utils/useStableValue.js +26 -0
- package/changes.json +3 -8
- package/package.json +144 -89
- package/LICENSE +0 -46
- package/build/index.es.js +0 -653
- package/build/index.es.js.map +0 -1
- package/build/index.es.min.js +0 -3
- package/build/index.js.map +0 -1
- package/build/index.min.js +0 -3
- package/build/index.umd.js +0 -670
- package/build/index.umd.js.map +0 -1
- package/build/index.umd.min.js +0 -3
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { forwardRef } from "react";
|
|
2
|
+
//#region src/animation/polymorphicForwardRef.ts
|
|
3
|
+
/**
|
|
4
|
+
* `forwardRef`, with the render function's own type parameters kept.
|
|
5
|
+
*
|
|
6
|
+
* A component that chooses its element through `as` is generic in that tag, and
|
|
7
|
+
* React's `forwardRef` is not: its signature settles the props at one type, so
|
|
8
|
+
* the tag is lost and `as="button" type="button"` stops typechecking while
|
|
9
|
+
* invented props start passing. Handing the same runtime function a signature
|
|
10
|
+
* that carries the parameters through is what restores per-element props.
|
|
11
|
+
*
|
|
12
|
+
* The assertion lives here, alone, so that there is one of it and so that what
|
|
13
|
+
* removes it is written beside it. React 18 is the whole reason it exists,
|
|
14
|
+
* because a function component receives a `ref` only through `forwardRef`
|
|
15
|
+
* there.
|
|
16
|
+
*/
|
|
17
|
+
const polymorphicForwardRef = forwardRef;
|
|
18
|
+
//#endregion
|
|
19
|
+
export { polymorphicForwardRef };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const require_styleLayer = require("./styleLayer.cjs");
|
|
2
|
+
const require_stylePrecedence = require("./stylePrecedence.cjs");
|
|
3
|
+
let react = require("react");
|
|
4
|
+
let react_jsx_runtime = require("react/jsx-runtime");
|
|
5
|
+
//#region src/animation/renderStyledElement.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Renders one element carrying a library class, together with the stylesheet
|
|
8
|
+
* that class names.
|
|
9
|
+
*
|
|
10
|
+
* The class and the `href` are one string, so React deduplicates the rules by
|
|
11
|
+
* the same name the rules are scoped to: two components can only collide in the
|
|
12
|
+
* document if they already collide in CSS, which is visible rather than silent.
|
|
13
|
+
*
|
|
14
|
+
* Built through `createElement` rather than as JSX, because JSX cannot take an
|
|
15
|
+
* element type that is still generic: `<Tag />` where the tag comes from `as`
|
|
16
|
+
* is `TS2604, no construct or call signatures`. Narrowing to one concrete tag
|
|
17
|
+
* instead needs an assertion, which this does not.
|
|
18
|
+
*/
|
|
19
|
+
function renderStyledElement({ tag, styleClass, styles, className, attributes, ref, children }) {
|
|
20
|
+
return /* @__PURE__ */ (0, react_jsx_runtime.jsxs)(react_jsx_runtime.Fragment, { children: [(0, react.createElement)(tag, {
|
|
21
|
+
...attributes,
|
|
22
|
+
className: className ? `${styleClass} ${className}` : styleClass,
|
|
23
|
+
ref
|
|
24
|
+
}, children), /* @__PURE__ */ (0, react_jsx_runtime.jsx)("style", {
|
|
25
|
+
href: styleClass,
|
|
26
|
+
precedence: require_stylePrecedence.stylePrecedence,
|
|
27
|
+
children: `@layer ${require_styleLayer.styleLayer}{${styles}}`
|
|
28
|
+
})] });
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
exports.renderStyledElement = renderStyledElement;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { styleLayer } from "./styleLayer.js";
|
|
2
|
+
import { stylePrecedence } from "./stylePrecedence.js";
|
|
3
|
+
import { createElement } from "react";
|
|
4
|
+
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
|
+
//#region src/animation/renderStyledElement.tsx
|
|
6
|
+
/**
|
|
7
|
+
* Renders one element carrying a library class, together with the stylesheet
|
|
8
|
+
* that class names.
|
|
9
|
+
*
|
|
10
|
+
* The class and the `href` are one string, so React deduplicates the rules by
|
|
11
|
+
* the same name the rules are scoped to: two components can only collide in the
|
|
12
|
+
* document if they already collide in CSS, which is visible rather than silent.
|
|
13
|
+
*
|
|
14
|
+
* Built through `createElement` rather than as JSX, because JSX cannot take an
|
|
15
|
+
* element type that is still generic: `<Tag />` where the tag comes from `as`
|
|
16
|
+
* is `TS2604, no construct or call signatures`. Narrowing to one concrete tag
|
|
17
|
+
* instead needs an assertion, which this does not.
|
|
18
|
+
*/
|
|
19
|
+
function renderStyledElement({ tag, styleClass, styles, className, attributes, ref, children }) {
|
|
20
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [createElement(tag, {
|
|
21
|
+
...attributes,
|
|
22
|
+
className: className ? `${styleClass} ${className}` : styleClass,
|
|
23
|
+
ref
|
|
24
|
+
}, children), /* @__PURE__ */ jsx("style", {
|
|
25
|
+
href: styleClass,
|
|
26
|
+
precedence: stylePrecedence,
|
|
27
|
+
children: `@layer ${styleLayer}{${styles}}`
|
|
28
|
+
})] });
|
|
29
|
+
}
|
|
30
|
+
//#endregion
|
|
31
|
+
export { renderStyledElement };
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
//#region src/animation/resolveSeekTarget.ts
|
|
2
|
+
/**
|
|
3
|
+
* Narrows an unknown value to a marker we can use.
|
|
4
|
+
*
|
|
5
|
+
* A marker whose After Effects comment parsed as JSON without a `name` fails
|
|
6
|
+
* here, which matches the engine: such a marker cannot be addressed by name at
|
|
7
|
+
* all, so a designer can label something the code has no way to reach.
|
|
8
|
+
*/
|
|
9
|
+
function isMarker(value) {
|
|
10
|
+
if (typeof value !== "object" || value === null) return false;
|
|
11
|
+
if (!("time" in value) || typeof value.time !== "number") return false;
|
|
12
|
+
if ("duration" in value) {
|
|
13
|
+
const { duration } = value;
|
|
14
|
+
if (duration !== void 0 && typeof duration !== "number") return false;
|
|
15
|
+
}
|
|
16
|
+
if (!("payload" in value)) return false;
|
|
17
|
+
const { payload } = value;
|
|
18
|
+
if (typeof payload !== "object" || payload === null) return false;
|
|
19
|
+
return "name" in payload && typeof payload.name === "string";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The animation's markers, or an empty list when it has none we can read.
|
|
23
|
+
*
|
|
24
|
+
* The `in` check is what makes the undeclared property readable without a cast:
|
|
25
|
+
* it narrows to a record whose value is `unknown`, which the guard above then
|
|
26
|
+
* takes the rest of the way.
|
|
27
|
+
*/
|
|
28
|
+
function readMarkers(item) {
|
|
29
|
+
if (!("markers" in item)) return [];
|
|
30
|
+
const { markers } = item;
|
|
31
|
+
if (!Array.isArray(markers)) return [];
|
|
32
|
+
return markers.filter(isMarker);
|
|
33
|
+
}
|
|
34
|
+
function findMarker(item, name) {
|
|
35
|
+
for (const marker of readMarkers(item)) if (marker.payload.name === name) return marker;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** The frame a target asks for, before it is held inside the playable range. */
|
|
39
|
+
function requestedFrame(item, target) {
|
|
40
|
+
if (typeof target === "number") return target;
|
|
41
|
+
const { frame, percent, seconds, marker } = target;
|
|
42
|
+
if (frame !== void 0) return frame;
|
|
43
|
+
if (percent !== void 0) return item.totalFrames * percent / 100;
|
|
44
|
+
if (seconds !== void 0) return seconds * item.frameRate;
|
|
45
|
+
const found = marker === void 0 ? null : findMarker(item, marker);
|
|
46
|
+
return found === null ? null : found.time - item.firstFrame;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Turns a seek target into a frame inside the playable range.
|
|
50
|
+
*
|
|
51
|
+
* Returns `null` when the target names nothing the animation has, which is an
|
|
52
|
+
* unknown marker or a number that is not finite. `requested` is what was asked
|
|
53
|
+
* for and `frame` is what is reachable, so a caller can tell that a position
|
|
54
|
+
* was pulled back to the range without this having to say anything about it.
|
|
55
|
+
*/
|
|
56
|
+
function resolveSeekTarget(item, target) {
|
|
57
|
+
const requested = requestedFrame(item, target);
|
|
58
|
+
if (requested === null || !Number.isFinite(requested)) return null;
|
|
59
|
+
const last = Math.max(item.totalFrames - .001, 0);
|
|
60
|
+
return {
|
|
61
|
+
frame: Math.min(Math.max(requested, 0), last),
|
|
62
|
+
requested
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Distinguishes one range from a list of them, which share an array type. */
|
|
66
|
+
function isSingleRange(segments) {
|
|
67
|
+
return typeof segments[0] === "number";
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Turns what a caller passed into the list of ranges the engine takes.
|
|
71
|
+
*
|
|
72
|
+
* Returns `null` when nothing playable was described: a range whose ends are
|
|
73
|
+
* equal or not finite, an empty list, an unknown marker, or a marker carrying
|
|
74
|
+
* no duration. That last one is a labelled position rather than a labelled
|
|
75
|
+
* span, and the engine would respond to it by playing the entire animation.
|
|
76
|
+
*
|
|
77
|
+
* A marker's frames are used as they are. Unlike a seek, a range endpoint is
|
|
78
|
+
* absolute, so the correction that seeking needs would be wrong here.
|
|
79
|
+
*
|
|
80
|
+
* The result is always freshly built, never the caller's own arrays, because
|
|
81
|
+
* the engine queues whatever it is handed and the input is typed `readonly`.
|
|
82
|
+
*/
|
|
83
|
+
function resolveSegments(item, segments) {
|
|
84
|
+
if ("marker" in segments) {
|
|
85
|
+
const marker = findMarker(item, segments.marker);
|
|
86
|
+
if (marker === null || !marker.duration) return null;
|
|
87
|
+
return [[marker.time, marker.time + marker.duration]];
|
|
88
|
+
}
|
|
89
|
+
const ranges = isSingleRange(segments) ? [segments] : segments;
|
|
90
|
+
if (ranges.length === 0) return null;
|
|
91
|
+
for (const [start, end] of ranges) if (!Number.isFinite(start) || !Number.isFinite(end) || start === end) return null;
|
|
92
|
+
return ranges.map(([start, end]) => [start, end]);
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
exports.readMarkers = readMarkers;
|
|
96
|
+
exports.resolveSeekTarget = resolveSeekTarget;
|
|
97
|
+
exports.resolveSegments = resolveSegments;
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
//#region src/animation/resolveSeekTarget.ts
|
|
2
|
+
/**
|
|
3
|
+
* Narrows an unknown value to a marker we can use.
|
|
4
|
+
*
|
|
5
|
+
* A marker whose After Effects comment parsed as JSON without a `name` fails
|
|
6
|
+
* here, which matches the engine: such a marker cannot be addressed by name at
|
|
7
|
+
* all, so a designer can label something the code has no way to reach.
|
|
8
|
+
*/
|
|
9
|
+
function isMarker(value) {
|
|
10
|
+
if (typeof value !== "object" || value === null) return false;
|
|
11
|
+
if (!("time" in value) || typeof value.time !== "number") return false;
|
|
12
|
+
if ("duration" in value) {
|
|
13
|
+
const { duration } = value;
|
|
14
|
+
if (duration !== void 0 && typeof duration !== "number") return false;
|
|
15
|
+
}
|
|
16
|
+
if (!("payload" in value)) return false;
|
|
17
|
+
const { payload } = value;
|
|
18
|
+
if (typeof payload !== "object" || payload === null) return false;
|
|
19
|
+
return "name" in payload && typeof payload.name === "string";
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* The animation's markers, or an empty list when it has none we can read.
|
|
23
|
+
*
|
|
24
|
+
* The `in` check is what makes the undeclared property readable without a cast:
|
|
25
|
+
* it narrows to a record whose value is `unknown`, which the guard above then
|
|
26
|
+
* takes the rest of the way.
|
|
27
|
+
*/
|
|
28
|
+
function readMarkers(item) {
|
|
29
|
+
if (!("markers" in item)) return [];
|
|
30
|
+
const { markers } = item;
|
|
31
|
+
if (!Array.isArray(markers)) return [];
|
|
32
|
+
return markers.filter(isMarker);
|
|
33
|
+
}
|
|
34
|
+
function findMarker(item, name) {
|
|
35
|
+
for (const marker of readMarkers(item)) if (marker.payload.name === name) return marker;
|
|
36
|
+
return null;
|
|
37
|
+
}
|
|
38
|
+
/** The frame a target asks for, before it is held inside the playable range. */
|
|
39
|
+
function requestedFrame(item, target) {
|
|
40
|
+
if (typeof target === "number") return target;
|
|
41
|
+
const { frame, percent, seconds, marker } = target;
|
|
42
|
+
if (frame !== void 0) return frame;
|
|
43
|
+
if (percent !== void 0) return item.totalFrames * percent / 100;
|
|
44
|
+
if (seconds !== void 0) return seconds * item.frameRate;
|
|
45
|
+
const found = marker === void 0 ? null : findMarker(item, marker);
|
|
46
|
+
return found === null ? null : found.time - item.firstFrame;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Turns a seek target into a frame inside the playable range.
|
|
50
|
+
*
|
|
51
|
+
* Returns `null` when the target names nothing the animation has, which is an
|
|
52
|
+
* unknown marker or a number that is not finite. `requested` is what was asked
|
|
53
|
+
* for and `frame` is what is reachable, so a caller can tell that a position
|
|
54
|
+
* was pulled back to the range without this having to say anything about it.
|
|
55
|
+
*/
|
|
56
|
+
function resolveSeekTarget(item, target) {
|
|
57
|
+
const requested = requestedFrame(item, target);
|
|
58
|
+
if (requested === null || !Number.isFinite(requested)) return null;
|
|
59
|
+
const last = Math.max(item.totalFrames - .001, 0);
|
|
60
|
+
return {
|
|
61
|
+
frame: Math.min(Math.max(requested, 0), last),
|
|
62
|
+
requested
|
|
63
|
+
};
|
|
64
|
+
}
|
|
65
|
+
/** Distinguishes one range from a list of them, which share an array type. */
|
|
66
|
+
function isSingleRange(segments) {
|
|
67
|
+
return typeof segments[0] === "number";
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Turns what a caller passed into the list of ranges the engine takes.
|
|
71
|
+
*
|
|
72
|
+
* Returns `null` when nothing playable was described: a range whose ends are
|
|
73
|
+
* equal or not finite, an empty list, an unknown marker, or a marker carrying
|
|
74
|
+
* no duration. That last one is a labelled position rather than a labelled
|
|
75
|
+
* span, and the engine would respond to it by playing the entire animation.
|
|
76
|
+
*
|
|
77
|
+
* A marker's frames are used as they are. Unlike a seek, a range endpoint is
|
|
78
|
+
* absolute, so the correction that seeking needs would be wrong here.
|
|
79
|
+
*
|
|
80
|
+
* The result is always freshly built, never the caller's own arrays, because
|
|
81
|
+
* the engine queues whatever it is handed and the input is typed `readonly`.
|
|
82
|
+
*/
|
|
83
|
+
function resolveSegments(item, segments) {
|
|
84
|
+
if ("marker" in segments) {
|
|
85
|
+
const marker = findMarker(item, segments.marker);
|
|
86
|
+
if (marker === null || !marker.duration) return null;
|
|
87
|
+
return [[marker.time, marker.time + marker.duration]];
|
|
88
|
+
}
|
|
89
|
+
const ranges = isSingleRange(segments) ? [segments] : segments;
|
|
90
|
+
if (ranges.length === 0) return null;
|
|
91
|
+
for (const [start, end] of ranges) if (!Number.isFinite(start) || !Number.isFinite(end) || start === end) return null;
|
|
92
|
+
return ranges.map(([start, end]) => [start, end]);
|
|
93
|
+
}
|
|
94
|
+
//#endregion
|
|
95
|
+
export { readMarkers, resolveSeekTarget, resolveSegments };
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/animation/styleLayer.ts
|
|
2
|
+
/**
|
|
3
|
+
* The cascade layer every library stylesheet is wrapped in.
|
|
4
|
+
*
|
|
5
|
+
* The wrapper exists for consumers whose own CSS lives in cascade layers,
|
|
6
|
+
* Tailwind 4 being the common case. Unlayered rules outrank all layered rules,
|
|
7
|
+
* so without a layer of our own even a zero-specificity default beats every
|
|
8
|
+
* utility class. Inside a layer, the defaults can be ranked below the
|
|
9
|
+
* consumer's layers with one declaration written before their own styles load:
|
|
10
|
+
*
|
|
11
|
+
* ```css
|
|
12
|
+
* @layer lottie-react;
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* A consumer whose CSS is unlayered needs nothing: unlayered rules beat
|
|
16
|
+
* layered ones, so their styles keep winning as before.
|
|
17
|
+
*
|
|
18
|
+
* Named after the package, like the style precedence, because a name a
|
|
19
|
+
* consumer already associates with the library cannot collide with a layer
|
|
20
|
+
* ladder of their own.
|
|
21
|
+
*/
|
|
22
|
+
const styleLayer = "lottie-react";
|
|
23
|
+
//#endregion
|
|
24
|
+
exports.styleLayer = styleLayer;
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
//#region src/animation/styleLayer.ts
|
|
2
|
+
/**
|
|
3
|
+
* The cascade layer every library stylesheet is wrapped in.
|
|
4
|
+
*
|
|
5
|
+
* The wrapper exists for consumers whose own CSS lives in cascade layers,
|
|
6
|
+
* Tailwind 4 being the common case. Unlayered rules outrank all layered rules,
|
|
7
|
+
* so without a layer of our own even a zero-specificity default beats every
|
|
8
|
+
* utility class. Inside a layer, the defaults can be ranked below the
|
|
9
|
+
* consumer's layers with one declaration written before their own styles load:
|
|
10
|
+
*
|
|
11
|
+
* ```css
|
|
12
|
+
* @layer lottie-react;
|
|
13
|
+
* ```
|
|
14
|
+
*
|
|
15
|
+
* A consumer whose CSS is unlayered needs nothing: unlayered rules beat
|
|
16
|
+
* layered ones, so their styles keep winning as before.
|
|
17
|
+
*
|
|
18
|
+
* Named after the package, like the style precedence, because a name a
|
|
19
|
+
* consumer already associates with the library cannot collide with a layer
|
|
20
|
+
* ladder of their own.
|
|
21
|
+
*/
|
|
22
|
+
const styleLayer = "lottie-react";
|
|
23
|
+
//#endregion
|
|
24
|
+
export { styleLayer };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/animation/stylePrecedence.ts
|
|
2
|
+
/**
|
|
3
|
+
* How React ranks every stylesheet this library renders.
|
|
4
|
+
*
|
|
5
|
+
* One value for all of them, so they sit together in a block a consumer can
|
|
6
|
+
* rank their own CSS against as a unit. It names the package rather than a
|
|
7
|
+
* position, because React treats a precedence it meets first as lower, so a
|
|
8
|
+
* position would only be right by accident of render order.
|
|
9
|
+
*/
|
|
10
|
+
const stylePrecedence = "lottie-react";
|
|
11
|
+
//#endregion
|
|
12
|
+
exports.stylePrecedence = stylePrecedence;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
//#region src/animation/stylePrecedence.ts
|
|
2
|
+
/**
|
|
3
|
+
* How React ranks every stylesheet this library renders.
|
|
4
|
+
*
|
|
5
|
+
* One value for all of them, so they sit together in a block a consumer can
|
|
6
|
+
* rank their own CSS against as a unit. It names the package rather than a
|
|
7
|
+
* position, because React treats a precedence it meets first as lower, so a
|
|
8
|
+
* position would only be right by accident of render order.
|
|
9
|
+
*/
|
|
10
|
+
const stylePrecedence = "lottie-react";
|
|
11
|
+
//#endregion
|
|
12
|
+
export { stylePrecedence };
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
//#region src/animation/types.ts
|
|
2
|
+
/**
|
|
3
|
+
* The renderers lottie-web can draw an animation with.
|
|
4
|
+
*
|
|
5
|
+
* `svg` is the default and the only one the smaller builds contain. `canvas`
|
|
6
|
+
* draws to a bitmap, and `html` builds real DOM nodes, which is the only
|
|
7
|
+
* renderer that puts block content inside the display.
|
|
8
|
+
*/
|
|
9
|
+
const LottieRenderer = {
|
|
10
|
+
svg: "svg",
|
|
11
|
+
canvas: "canvas",
|
|
12
|
+
html: "html"
|
|
13
|
+
};
|
|
14
|
+
/**
|
|
15
|
+
* What the animation is doing.
|
|
16
|
+
*
|
|
17
|
+
* `paused` means a person asked it to stop; `frozen` means the library stopped
|
|
18
|
+
* it on the animation's behalf and will start it again. Nothing sets `frozen`
|
|
19
|
+
* yet, and it is declared because adding a member to a union later breaks an
|
|
20
|
+
* exhaustive `switch` in a consumer's code.
|
|
21
|
+
*/
|
|
22
|
+
const LottieState = {
|
|
23
|
+
loading: "loading",
|
|
24
|
+
playing: "playing",
|
|
25
|
+
paused: "paused",
|
|
26
|
+
stopped: "stopped",
|
|
27
|
+
frozen: "frozen",
|
|
28
|
+
error: "error"
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Which way the animation plays.
|
|
32
|
+
*
|
|
33
|
+
* lottie-web works in `1` and `-1`, which say nothing to a reader; the
|
|
34
|
+
* translation happens once, where the engine is called.
|
|
35
|
+
*/
|
|
36
|
+
const LottieDirection = {
|
|
37
|
+
forward: "forward",
|
|
38
|
+
reverse: "reverse"
|
|
39
|
+
};
|
|
40
|
+
/**
|
|
41
|
+
* Everything a consumer can subscribe to.
|
|
42
|
+
*
|
|
43
|
+
* `frame` is the only one that fires per frame, and it is deliberately the only
|
|
44
|
+
* route to the current frame, because a value that changes sixty times a second
|
|
45
|
+
* cannot be a value without re-rendering at that rate.
|
|
46
|
+
*
|
|
47
|
+
* `marker` announces the playhead passing a marker the animation's designer
|
|
48
|
+
* placed, while it is travelling: a seek or a scrub puts the playhead somewhere
|
|
49
|
+
* without passing anything, so it announces nothing.
|
|
50
|
+
*
|
|
51
|
+
* `ready` carries no payload. Everything that can subscribe already holds the
|
|
52
|
+
* instance, either as the hook's return value or through `useLottieInstance`,
|
|
53
|
+
* so the values it announces are read from there.
|
|
54
|
+
*/
|
|
55
|
+
const LottieSubscription = {
|
|
56
|
+
ready: "ready",
|
|
57
|
+
play: "play",
|
|
58
|
+
pause: "pause",
|
|
59
|
+
stop: "stop",
|
|
60
|
+
complete: "complete",
|
|
61
|
+
loopCompleted: "loopCompleted",
|
|
62
|
+
frame: "frame",
|
|
63
|
+
marker: "marker",
|
|
64
|
+
newState: "newState",
|
|
65
|
+
error: "error"
|
|
66
|
+
};
|
|
67
|
+
//#endregion
|
|
68
|
+
exports.LottieDirection = LottieDirection;
|
|
69
|
+
exports.LottieRenderer = LottieRenderer;
|
|
70
|
+
exports.LottieState = LottieState;
|
|
71
|
+
exports.LottieSubscription = LottieSubscription;
|