@veritone-ce/design-system 2.8.7 → 2.8.9
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/Accordion/Accordion.js +111 -0
- package/dist/cjs/Accordion/AccordionGroup.js +61 -0
- package/dist/cjs/Accordion/Context.js +39 -0
- package/dist/cjs/Accordion/styles.module.scss.js +7 -0
- package/dist/cjs/Badge/index.js +12 -3
- package/dist/cjs/bundled_modules/@react-spring/animated/dist/react-spring_animated.modern.js +338 -0
- package/dist/cjs/bundled_modules/@react-spring/core/dist/react-spring_core.modern.js +1799 -0
- package/dist/cjs/bundled_modules/@react-spring/rafz/dist/react-spring_rafz.modern.js +160 -0
- package/dist/cjs/bundled_modules/@react-spring/shared/dist/react-spring_shared.modern.js +775 -0
- package/dist/cjs/bundled_modules/@react-spring/web/dist/react-spring_web.modern.js +382 -0
- package/dist/cjs/index.js +9 -0
- package/dist/cjs/styles.css +1 -1
- package/dist/cjs/utils/isNil.js +8 -0
- package/dist/esm/Accordion/Accordion.js +107 -0
- package/dist/esm/Accordion/AccordionGroup.js +57 -0
- package/dist/esm/Accordion/Context.js +33 -0
- package/dist/esm/Accordion/styles.module.scss.js +3 -0
- package/dist/esm/Badge/index.js +12 -3
- package/dist/esm/bundled_modules/@react-spring/animated/dist/react-spring_animated.modern.js +308 -0
- package/dist/esm/bundled_modules/@react-spring/core/dist/react-spring_core.modern.js +1765 -0
- package/dist/esm/bundled_modules/@react-spring/rafz/dist/react-spring_rafz.modern.js +158 -0
- package/dist/esm/bundled_modules/@react-spring/shared/dist/react-spring_shared.modern.js +730 -0
- package/dist/esm/bundled_modules/@react-spring/web/dist/react-spring_web.modern.js +365 -0
- package/dist/esm/index.js +3 -0
- package/dist/esm/styles.css +1 -1
- package/dist/esm/utils/isNil.js +6 -0
- package/dist/types/Accordion/index.d.ts +3 -0
- package/dist/types/Badge/index.d.ts +6 -1
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/isNil.d.ts +1 -0
- package/package.json +1 -1
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
|
+
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var styles_module = require('./styles.module.scss.js');
|
|
10
|
+
var cx = require('../styles/cx.js');
|
|
11
|
+
require('../styles/defaultThemeOptions.js');
|
|
12
|
+
require('@capsizecss/core');
|
|
13
|
+
require('color2k');
|
|
14
|
+
var defaultTheme = require('../styles/defaultTheme.js');
|
|
15
|
+
require('../styles/provider.client.js');
|
|
16
|
+
require('../styles/css-vars.js');
|
|
17
|
+
var iconsMaterial = require('@mui/icons-material');
|
|
18
|
+
var wrappers = require('../Icon/wrappers.js');
|
|
19
|
+
require('../Icon/factory.js');
|
|
20
|
+
var Context = require('./Context.js');
|
|
21
|
+
var reactSpring_web_modern = require('../bundled_modules/@react-spring/web/dist/react-spring_web.modern.js');
|
|
22
|
+
var reactSpring_core_modern = require('../bundled_modules/@react-spring/core/dist/react-spring_core.modern.js');
|
|
23
|
+
|
|
24
|
+
const ExpandLessIcon = wrappers.adaptMuiSvgIcon(iconsMaterial.ExpandLess);
|
|
25
|
+
const Accordion = React.forwardRef(
|
|
26
|
+
({
|
|
27
|
+
title,
|
|
28
|
+
palette = defaultTheme.defaultThemeCssVariableUsages.palette.background.primary,
|
|
29
|
+
defaultExpanded = false,
|
|
30
|
+
id: providedId,
|
|
31
|
+
children,
|
|
32
|
+
"data-testid": dataTestId,
|
|
33
|
+
className,
|
|
34
|
+
style,
|
|
35
|
+
...props
|
|
36
|
+
}, ref) => {
|
|
37
|
+
const generatedId = React.useId();
|
|
38
|
+
const id = providedId || generatedId;
|
|
39
|
+
const { isExpanded, toggleAccordion } = Context.useAccordionState(
|
|
40
|
+
id,
|
|
41
|
+
defaultExpanded
|
|
42
|
+
);
|
|
43
|
+
const contentRef = React.useRef(null);
|
|
44
|
+
const contentAnimation = reactSpring_core_modern.useSpring({
|
|
45
|
+
from: {
|
|
46
|
+
height: 0,
|
|
47
|
+
opacity: 0,
|
|
48
|
+
overflow: "hidden"
|
|
49
|
+
},
|
|
50
|
+
to: {
|
|
51
|
+
height: isExpanded ? contentRef.current?.scrollHeight || "auto" : 0,
|
|
52
|
+
opacity: isExpanded ? 1 : 0,
|
|
53
|
+
overflow: "hidden"
|
|
54
|
+
},
|
|
55
|
+
config: {
|
|
56
|
+
tension: 250,
|
|
57
|
+
friction: 25
|
|
58
|
+
},
|
|
59
|
+
// When animation completes and content is expanded, remove height constraint
|
|
60
|
+
onRest: () => {
|
|
61
|
+
if (isExpanded && contentRef.current) {
|
|
62
|
+
contentRef.current.style.height = "auto";
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
});
|
|
66
|
+
const iconAnimation = reactSpring_core_modern.useSpring({
|
|
67
|
+
transform: isExpanded ? "rotate(0deg)" : "rotate(180deg)",
|
|
68
|
+
config: {
|
|
69
|
+
tension: 300,
|
|
70
|
+
friction: 20
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
74
|
+
"div",
|
|
75
|
+
{
|
|
76
|
+
...props,
|
|
77
|
+
ref,
|
|
78
|
+
"data-testid": dataTestId,
|
|
79
|
+
className: cx.cx(styles_module.default["accordion"], className),
|
|
80
|
+
children: [
|
|
81
|
+
/* @__PURE__ */ jsxRuntime.jsxs(
|
|
82
|
+
"div",
|
|
83
|
+
{
|
|
84
|
+
className: styles_module.default["accordion-header"],
|
|
85
|
+
onClick: toggleAccordion,
|
|
86
|
+
style: {
|
|
87
|
+
backgroundColor: palette,
|
|
88
|
+
...style
|
|
89
|
+
},
|
|
90
|
+
"data-expanded": isExpanded,
|
|
91
|
+
children: [
|
|
92
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: styles_module.default["accordion-title"], children: title }),
|
|
93
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
94
|
+
reactSpring_web_modern.a.span,
|
|
95
|
+
{
|
|
96
|
+
className: styles_module.default["accordion-icon"],
|
|
97
|
+
style: iconAnimation,
|
|
98
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(ExpandLessIcon, {})
|
|
99
|
+
}
|
|
100
|
+
)
|
|
101
|
+
]
|
|
102
|
+
}
|
|
103
|
+
),
|
|
104
|
+
/* @__PURE__ */ jsxRuntime.jsx(reactSpring_web_modern.a.div, { style: contentAnimation, children: /* @__PURE__ */ jsxRuntime.jsx("div", { ref: contentRef, className: styles_module.default["accordion-content"], children }) })
|
|
105
|
+
]
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
|
|
111
|
+
exports.default = Accordion;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
|
+
|
|
7
|
+
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var React = require('react');
|
|
9
|
+
var styles_module = require('./styles.module.scss.js');
|
|
10
|
+
var cx = require('../styles/cx.js');
|
|
11
|
+
require('../styles/defaultThemeOptions.js');
|
|
12
|
+
require('@capsizecss/core');
|
|
13
|
+
require('color2k');
|
|
14
|
+
require('../styles/defaultTheme.js');
|
|
15
|
+
require('../styles/provider.client.js');
|
|
16
|
+
require('../styles/css-vars.js');
|
|
17
|
+
var Context = require('./Context.js');
|
|
18
|
+
|
|
19
|
+
const AccordionGroup = React.forwardRef(
|
|
20
|
+
({
|
|
21
|
+
defaultActiveId = null,
|
|
22
|
+
allowAllClosed = true,
|
|
23
|
+
children,
|
|
24
|
+
"data-testid": dataTestId,
|
|
25
|
+
className,
|
|
26
|
+
...props
|
|
27
|
+
}, ref) => {
|
|
28
|
+
const [activeAccordionId, setActiveAccordionId] = React.useState(
|
|
29
|
+
defaultActiveId
|
|
30
|
+
);
|
|
31
|
+
const handleSetActiveAccordion = (id) => {
|
|
32
|
+
setActiveAccordionId((prevId) => {
|
|
33
|
+
if (id === prevId && allowAllClosed) {
|
|
34
|
+
return null;
|
|
35
|
+
}
|
|
36
|
+
return id;
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
40
|
+
Context.AccordionGroupContext.Provider,
|
|
41
|
+
{
|
|
42
|
+
value: {
|
|
43
|
+
activeAccordionId,
|
|
44
|
+
setActiveAccordionId: handleSetActiveAccordion
|
|
45
|
+
},
|
|
46
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
47
|
+
"div",
|
|
48
|
+
{
|
|
49
|
+
...props,
|
|
50
|
+
ref,
|
|
51
|
+
"data-testid": dataTestId,
|
|
52
|
+
className: cx.cx(styles_module.default["accordion-group"], className),
|
|
53
|
+
children
|
|
54
|
+
}
|
|
55
|
+
)
|
|
56
|
+
}
|
|
57
|
+
);
|
|
58
|
+
}
|
|
59
|
+
);
|
|
60
|
+
|
|
61
|
+
exports.default = AccordionGroup;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
'use client';
|
|
3
|
+
'use strict';
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
|
|
7
|
+
const defaultContextValue = {
|
|
8
|
+
activeAccordionId: null,
|
|
9
|
+
setActiveAccordionId: () => {
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const AccordionGroupContext = React.createContext(defaultContextValue);
|
|
13
|
+
const useAccordionGroup = () => {
|
|
14
|
+
return React.useContext(AccordionGroupContext);
|
|
15
|
+
};
|
|
16
|
+
const useIsInsideAccordionGroup = () => {
|
|
17
|
+
const context = React.useContext(AccordionGroupContext);
|
|
18
|
+
return context !== defaultContextValue;
|
|
19
|
+
};
|
|
20
|
+
const useAccordionState = (id, defaultExpanded = false) => {
|
|
21
|
+
const accordionGroup = useAccordionGroup();
|
|
22
|
+
const isInGroup = useIsInsideAccordionGroup();
|
|
23
|
+
const [localExpanded, setLocalExpanded] = React.useState(defaultExpanded);
|
|
24
|
+
const isExpanded = isInGroup ? accordionGroup?.activeAccordionId === id : localExpanded;
|
|
25
|
+
const toggleAccordion = () => {
|
|
26
|
+
if (isInGroup && accordionGroup) {
|
|
27
|
+
accordionGroup.setActiveAccordionId(isExpanded ? null : id);
|
|
28
|
+
} else {
|
|
29
|
+
setLocalExpanded(!localExpanded);
|
|
30
|
+
}
|
|
31
|
+
};
|
|
32
|
+
return { isExpanded, toggleAccordion };
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
exports.AccordionGroupContext = AccordionGroupContext;
|
|
36
|
+
exports.defaultContextValue = defaultContextValue;
|
|
37
|
+
exports.useAccordionGroup = useAccordionGroup;
|
|
38
|
+
exports.useAccordionState = useAccordionState;
|
|
39
|
+
exports.useIsInsideAccordionGroup = useIsInsideAccordionGroup;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var styles = {"accordion-group":"vt_ce_Accordion_accordion-group__8bbf5326","accordion":"vt_ce_Accordion_accordion__dd9538a7","accordion-header":"vt_ce_Accordion_accordion-header__364b94af","accordion-title":"vt_ce_Accordion_accordion-title__5880129b","accordion-icon":"vt_ce_Accordion_accordion-icon__36646438","accordion-content":"vt_ce_Accordion_accordion-content__19b0322a"};
|
|
6
|
+
|
|
7
|
+
exports.default = styles;
|
package/dist/cjs/Badge/index.js
CHANGED
|
@@ -5,6 +5,7 @@
|
|
|
5
5
|
Object.defineProperty(exports, '__esModule', { value: true });
|
|
6
6
|
|
|
7
7
|
var jsxRuntime = require('react/jsx-runtime');
|
|
8
|
+
var React = require('react');
|
|
8
9
|
var cx = require('../styles/cx.js');
|
|
9
10
|
require('../styles/defaultThemeOptions.js');
|
|
10
11
|
require('@capsizecss/core');
|
|
@@ -12,8 +13,9 @@ require('color2k');
|
|
|
12
13
|
var defaultTheme = require('../styles/defaultTheme.js');
|
|
13
14
|
require('../styles/provider.client.js');
|
|
14
15
|
require('../styles/css-vars.js');
|
|
15
|
-
var
|
|
16
|
+
var isNil = require('../utils/isNil.js');
|
|
16
17
|
var index = require('../Typography/index.js');
|
|
18
|
+
var styles_module = require('./styles.module.scss.js');
|
|
17
19
|
|
|
18
20
|
function Badge({
|
|
19
21
|
palette = defaultTheme.defaultThemeCssVariableUsages.palette.indicator.info.base,
|
|
@@ -22,6 +24,13 @@ function Badge({
|
|
|
22
24
|
...props
|
|
23
25
|
}) {
|
|
24
26
|
const variantCn = styles_module.default[`variant-${variant}`];
|
|
27
|
+
const displayLabel = React.useMemo(() => {
|
|
28
|
+
if (typeof props.label === "number" && typeof props.max === "number") {
|
|
29
|
+
return props.label > props.max ? `${props.max}+` : props.label;
|
|
30
|
+
}
|
|
31
|
+
return props.label;
|
|
32
|
+
}, [props.label, props.max]);
|
|
33
|
+
const hasLabel = !isNil.isNil(displayLabel);
|
|
25
34
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
26
35
|
"span",
|
|
27
36
|
{
|
|
@@ -29,7 +38,7 @@ function Badge({
|
|
|
29
38
|
className: cx.cx(styles_module.default["badge-anchor"], props.className),
|
|
30
39
|
children: [
|
|
31
40
|
props.children,
|
|
32
|
-
/* @__PURE__ */ jsxRuntime.jsx("div", { className: styles_module.default["badge-wrapper"], "data-disabled": disabled, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
41
|
+
hasLabel && /* @__PURE__ */ jsxRuntime.jsx("div", { className: styles_module.default["badge-wrapper"], "data-disabled": disabled, children: /* @__PURE__ */ jsxRuntime.jsx(
|
|
33
42
|
"div",
|
|
34
43
|
{
|
|
35
44
|
className: cx.cx(styles_module.default["badge"], variantCn),
|
|
@@ -45,7 +54,7 @@ function Badge({
|
|
|
45
54
|
variant: "paragraph3",
|
|
46
55
|
leadingTrim: true,
|
|
47
56
|
className: styles_module.default["badge-text"],
|
|
48
|
-
children:
|
|
57
|
+
children: displayLabel
|
|
49
58
|
}
|
|
50
59
|
)
|
|
51
60
|
}
|
|
@@ -0,0 +1,338 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var reactSpring_shared_modern = require('../../shared/dist/react-spring_shared.modern.js');
|
|
4
|
+
var React = require('react');
|
|
5
|
+
var reactSpring_rafz_modern = require('../../rafz/dist/react-spring_rafz.modern.js');
|
|
6
|
+
|
|
7
|
+
function _interopNamespaceDefault(e) {
|
|
8
|
+
var n = Object.create(null);
|
|
9
|
+
if (e) {
|
|
10
|
+
Object.keys(e).forEach(function (k) {
|
|
11
|
+
if (k !== 'default') {
|
|
12
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
13
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
14
|
+
enumerable: true,
|
|
15
|
+
get: function () { return e[k]; }
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
}
|
|
20
|
+
n.default = e;
|
|
21
|
+
return Object.freeze(n);
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
var React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
|
|
25
|
+
|
|
26
|
+
// src/Animated.ts
|
|
27
|
+
var $node = Symbol.for("Animated:node");
|
|
28
|
+
var isAnimated = (value) => !!value && value[$node] === value;
|
|
29
|
+
var getAnimated = (owner) => owner && owner[$node];
|
|
30
|
+
var setAnimated = (owner, node) => reactSpring_shared_modern.defineHidden(owner, $node, node);
|
|
31
|
+
var getPayload = (owner) => owner && owner[$node] && owner[$node].getPayload();
|
|
32
|
+
var Animated = class {
|
|
33
|
+
constructor() {
|
|
34
|
+
setAnimated(this, this);
|
|
35
|
+
}
|
|
36
|
+
/** Get every `AnimatedValue` used by this node. */
|
|
37
|
+
getPayload() {
|
|
38
|
+
return this.payload || [];
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
var AnimatedValue = class _AnimatedValue extends Animated {
|
|
42
|
+
constructor(_value) {
|
|
43
|
+
super();
|
|
44
|
+
this._value = _value;
|
|
45
|
+
this.done = true;
|
|
46
|
+
this.durationProgress = 0;
|
|
47
|
+
if (reactSpring_shared_modern.is.num(this._value)) {
|
|
48
|
+
this.lastPosition = this._value;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
/** @internal */
|
|
52
|
+
static create(value) {
|
|
53
|
+
return new _AnimatedValue(value);
|
|
54
|
+
}
|
|
55
|
+
getPayload() {
|
|
56
|
+
return [this];
|
|
57
|
+
}
|
|
58
|
+
getValue() {
|
|
59
|
+
return this._value;
|
|
60
|
+
}
|
|
61
|
+
setValue(value, step) {
|
|
62
|
+
if (reactSpring_shared_modern.is.num(value)) {
|
|
63
|
+
this.lastPosition = value;
|
|
64
|
+
if (step) {
|
|
65
|
+
value = Math.round(value / step) * step;
|
|
66
|
+
if (this.done) {
|
|
67
|
+
this.lastPosition = value;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (this._value === value) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
this._value = value;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
reset() {
|
|
78
|
+
const { done } = this;
|
|
79
|
+
this.done = false;
|
|
80
|
+
if (reactSpring_shared_modern.is.num(this._value)) {
|
|
81
|
+
this.elapsedTime = 0;
|
|
82
|
+
this.durationProgress = 0;
|
|
83
|
+
this.lastPosition = this._value;
|
|
84
|
+
if (done) this.lastVelocity = null;
|
|
85
|
+
this.v0 = null;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
var AnimatedString = class _AnimatedString extends AnimatedValue {
|
|
90
|
+
constructor(value) {
|
|
91
|
+
super(0);
|
|
92
|
+
this._string = null;
|
|
93
|
+
this._toString = reactSpring_shared_modern.createInterpolator({
|
|
94
|
+
output: [value, value]
|
|
95
|
+
});
|
|
96
|
+
}
|
|
97
|
+
/** @internal */
|
|
98
|
+
static create(value) {
|
|
99
|
+
return new _AnimatedString(value);
|
|
100
|
+
}
|
|
101
|
+
getValue() {
|
|
102
|
+
const value = this._string;
|
|
103
|
+
return value == null ? this._string = this._toString(this._value) : value;
|
|
104
|
+
}
|
|
105
|
+
setValue(value) {
|
|
106
|
+
if (reactSpring_shared_modern.is.str(value)) {
|
|
107
|
+
if (value == this._string) {
|
|
108
|
+
return false;
|
|
109
|
+
}
|
|
110
|
+
this._string = value;
|
|
111
|
+
this._value = 1;
|
|
112
|
+
} else if (super.setValue(value)) {
|
|
113
|
+
this._string = null;
|
|
114
|
+
} else {
|
|
115
|
+
return false;
|
|
116
|
+
}
|
|
117
|
+
return true;
|
|
118
|
+
}
|
|
119
|
+
reset(goal) {
|
|
120
|
+
if (goal) {
|
|
121
|
+
this._toString = reactSpring_shared_modern.createInterpolator({
|
|
122
|
+
output: [this.getValue(), goal]
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
this._value = 0;
|
|
126
|
+
super.reset();
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
// src/context.ts
|
|
131
|
+
var TreeContext = { dependencies: null };
|
|
132
|
+
|
|
133
|
+
// src/AnimatedObject.ts
|
|
134
|
+
var AnimatedObject = class extends Animated {
|
|
135
|
+
constructor(source) {
|
|
136
|
+
super();
|
|
137
|
+
this.source = source;
|
|
138
|
+
this.setValue(source);
|
|
139
|
+
}
|
|
140
|
+
getValue(animated) {
|
|
141
|
+
const values = {};
|
|
142
|
+
reactSpring_shared_modern.eachProp(this.source, (source, key) => {
|
|
143
|
+
if (isAnimated(source)) {
|
|
144
|
+
values[key] = source.getValue(animated);
|
|
145
|
+
} else if (reactSpring_shared_modern.hasFluidValue(source)) {
|
|
146
|
+
values[key] = reactSpring_shared_modern.getFluidValue(source);
|
|
147
|
+
} else if (!animated) {
|
|
148
|
+
values[key] = source;
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
return values;
|
|
152
|
+
}
|
|
153
|
+
/** Replace the raw object data */
|
|
154
|
+
setValue(source) {
|
|
155
|
+
this.source = source;
|
|
156
|
+
this.payload = this._makePayload(source);
|
|
157
|
+
}
|
|
158
|
+
reset() {
|
|
159
|
+
if (this.payload) {
|
|
160
|
+
reactSpring_shared_modern.each(this.payload, (node) => node.reset());
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
/** Create a payload set. */
|
|
164
|
+
_makePayload(source) {
|
|
165
|
+
if (source) {
|
|
166
|
+
const payload = /* @__PURE__ */ new Set();
|
|
167
|
+
reactSpring_shared_modern.eachProp(source, this._addToPayload, payload);
|
|
168
|
+
return Array.from(payload);
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
/** Add to a payload set. */
|
|
172
|
+
_addToPayload(source) {
|
|
173
|
+
if (TreeContext.dependencies && reactSpring_shared_modern.hasFluidValue(source)) {
|
|
174
|
+
TreeContext.dependencies.add(source);
|
|
175
|
+
}
|
|
176
|
+
const payload = getPayload(source);
|
|
177
|
+
if (payload) {
|
|
178
|
+
reactSpring_shared_modern.each(payload, (node) => this.add(node));
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
};
|
|
182
|
+
|
|
183
|
+
// src/AnimatedArray.ts
|
|
184
|
+
var AnimatedArray = class _AnimatedArray extends AnimatedObject {
|
|
185
|
+
constructor(source) {
|
|
186
|
+
super(source);
|
|
187
|
+
}
|
|
188
|
+
/** @internal */
|
|
189
|
+
static create(source) {
|
|
190
|
+
return new _AnimatedArray(source);
|
|
191
|
+
}
|
|
192
|
+
getValue() {
|
|
193
|
+
return this.source.map((node) => node.getValue());
|
|
194
|
+
}
|
|
195
|
+
setValue(source) {
|
|
196
|
+
const payload = this.getPayload();
|
|
197
|
+
if (source.length == payload.length) {
|
|
198
|
+
return payload.map((node, i) => node.setValue(source[i])).some(Boolean);
|
|
199
|
+
}
|
|
200
|
+
super.setValue(source.map(makeAnimated));
|
|
201
|
+
return true;
|
|
202
|
+
}
|
|
203
|
+
};
|
|
204
|
+
function makeAnimated(value) {
|
|
205
|
+
const nodeType = reactSpring_shared_modern.isAnimatedString(value) ? AnimatedString : AnimatedValue;
|
|
206
|
+
return nodeType.create(value);
|
|
207
|
+
}
|
|
208
|
+
function getAnimatedType(value) {
|
|
209
|
+
const parentNode = getAnimated(value);
|
|
210
|
+
return parentNode ? parentNode.constructor : reactSpring_shared_modern.is.arr(value) ? AnimatedArray : reactSpring_shared_modern.isAnimatedString(value) ? AnimatedString : AnimatedValue;
|
|
211
|
+
}
|
|
212
|
+
var withAnimated = (Component, host) => {
|
|
213
|
+
const hasInstance = (
|
|
214
|
+
// Function components must use "forwardRef" to avoid being
|
|
215
|
+
// re-rendered on every animation frame.
|
|
216
|
+
!reactSpring_shared_modern.is.fun(Component) || Component.prototype && Component.prototype.isReactComponent
|
|
217
|
+
);
|
|
218
|
+
return React.forwardRef((givenProps, givenRef) => {
|
|
219
|
+
const instanceRef = React.useRef(null);
|
|
220
|
+
const ref = hasInstance && // eslint-disable-next-line react-hooks/rules-of-hooks
|
|
221
|
+
React.useCallback(
|
|
222
|
+
(value) => {
|
|
223
|
+
instanceRef.current = updateRef(givenRef, value);
|
|
224
|
+
},
|
|
225
|
+
[givenRef]
|
|
226
|
+
);
|
|
227
|
+
const [props, deps] = getAnimatedState(givenProps, host);
|
|
228
|
+
const forceUpdate = reactSpring_shared_modern.useForceUpdate();
|
|
229
|
+
const callback = () => {
|
|
230
|
+
const instance = instanceRef.current;
|
|
231
|
+
if (hasInstance && !instance) {
|
|
232
|
+
return;
|
|
233
|
+
}
|
|
234
|
+
const didUpdate = instance ? host.applyAnimatedValues(instance, props.getValue(true)) : false;
|
|
235
|
+
if (didUpdate === false) {
|
|
236
|
+
forceUpdate();
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
const observer = new PropsObserver(callback, deps);
|
|
240
|
+
const observerRef = React.useRef(void 0);
|
|
241
|
+
reactSpring_shared_modern.useIsomorphicLayoutEffect(() => {
|
|
242
|
+
observerRef.current = observer;
|
|
243
|
+
reactSpring_shared_modern.each(deps, (dep) => reactSpring_shared_modern.addFluidObserver(dep, observer));
|
|
244
|
+
return () => {
|
|
245
|
+
if (observerRef.current) {
|
|
246
|
+
reactSpring_shared_modern.each(
|
|
247
|
+
observerRef.current.deps,
|
|
248
|
+
(dep) => reactSpring_shared_modern.removeFluidObserver(dep, observerRef.current)
|
|
249
|
+
);
|
|
250
|
+
reactSpring_rafz_modern.raf.cancel(observerRef.current.update);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
React.useEffect(callback, []);
|
|
255
|
+
reactSpring_shared_modern.useOnce(() => () => {
|
|
256
|
+
const observer2 = observerRef.current;
|
|
257
|
+
reactSpring_shared_modern.each(observer2.deps, (dep) => reactSpring_shared_modern.removeFluidObserver(dep, observer2));
|
|
258
|
+
});
|
|
259
|
+
const usedProps = host.getComponentProps(props.getValue());
|
|
260
|
+
return /* @__PURE__ */ React__namespace.createElement(Component, { ...usedProps, ref });
|
|
261
|
+
});
|
|
262
|
+
};
|
|
263
|
+
var PropsObserver = class {
|
|
264
|
+
constructor(update, deps) {
|
|
265
|
+
this.update = update;
|
|
266
|
+
this.deps = deps;
|
|
267
|
+
}
|
|
268
|
+
eventObserved(event) {
|
|
269
|
+
if (event.type == "change") {
|
|
270
|
+
reactSpring_rafz_modern.raf.write(this.update);
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
};
|
|
274
|
+
function getAnimatedState(props, host) {
|
|
275
|
+
const dependencies = /* @__PURE__ */ new Set();
|
|
276
|
+
TreeContext.dependencies = dependencies;
|
|
277
|
+
if (props.style)
|
|
278
|
+
props = {
|
|
279
|
+
...props,
|
|
280
|
+
style: host.createAnimatedStyle(props.style)
|
|
281
|
+
};
|
|
282
|
+
props = new AnimatedObject(props);
|
|
283
|
+
TreeContext.dependencies = null;
|
|
284
|
+
return [props, dependencies];
|
|
285
|
+
}
|
|
286
|
+
function updateRef(ref, value) {
|
|
287
|
+
if (ref) {
|
|
288
|
+
if (reactSpring_shared_modern.is.fun(ref)) ref(value);
|
|
289
|
+
else ref.current = value;
|
|
290
|
+
}
|
|
291
|
+
return value;
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
// src/createHost.ts
|
|
295
|
+
var cacheKey = Symbol.for("AnimatedComponent");
|
|
296
|
+
var createHost = (components, {
|
|
297
|
+
applyAnimatedValues = () => false,
|
|
298
|
+
createAnimatedStyle = (style) => new AnimatedObject(style),
|
|
299
|
+
getComponentProps = (props) => props
|
|
300
|
+
} = {}) => {
|
|
301
|
+
const hostConfig = {
|
|
302
|
+
applyAnimatedValues,
|
|
303
|
+
createAnimatedStyle,
|
|
304
|
+
getComponentProps
|
|
305
|
+
};
|
|
306
|
+
const animated = (Component) => {
|
|
307
|
+
const displayName = getDisplayName(Component) || "Anonymous";
|
|
308
|
+
if (reactSpring_shared_modern.is.str(Component)) {
|
|
309
|
+
Component = animated[Component] || (animated[Component] = withAnimated(Component, hostConfig));
|
|
310
|
+
} else {
|
|
311
|
+
Component = Component[cacheKey] || (Component[cacheKey] = withAnimated(Component, hostConfig));
|
|
312
|
+
}
|
|
313
|
+
Component.displayName = `Animated(${displayName})`;
|
|
314
|
+
return Component;
|
|
315
|
+
};
|
|
316
|
+
reactSpring_shared_modern.eachProp(components, (Component, key) => {
|
|
317
|
+
if (reactSpring_shared_modern.is.arr(components)) {
|
|
318
|
+
key = getDisplayName(Component);
|
|
319
|
+
}
|
|
320
|
+
animated[key] = animated(Component);
|
|
321
|
+
});
|
|
322
|
+
return {
|
|
323
|
+
animated
|
|
324
|
+
};
|
|
325
|
+
};
|
|
326
|
+
var getDisplayName = (arg) => reactSpring_shared_modern.is.str(arg) ? arg : arg && reactSpring_shared_modern.is.str(arg.displayName) ? arg.displayName : reactSpring_shared_modern.is.fun(arg) && arg.name || null;
|
|
327
|
+
|
|
328
|
+
exports.Animated = Animated;
|
|
329
|
+
exports.AnimatedArray = AnimatedArray;
|
|
330
|
+
exports.AnimatedObject = AnimatedObject;
|
|
331
|
+
exports.AnimatedString = AnimatedString;
|
|
332
|
+
exports.AnimatedValue = AnimatedValue;
|
|
333
|
+
exports.createHost = createHost;
|
|
334
|
+
exports.getAnimated = getAnimated;
|
|
335
|
+
exports.getAnimatedType = getAnimatedType;
|
|
336
|
+
exports.getPayload = getPayload;
|
|
337
|
+
exports.isAnimated = isAnimated;
|
|
338
|
+
exports.setAnimated = setAnimated;
|