@number-flow/react 0.5.3 → 0.5.5
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/NumberFlow-client-CHWbu7lx.mjs +179 -0
- package/dist/NumberFlow-client-CMnZwURp.js +201 -0
- package/dist/index.d.mts +39 -3
- package/dist/index.d.ts +39 -3
- package/dist/index.js +43 -252
- package/dist/index.mjs +14 -38
- package/package.json +6 -6
- package/dist/NumberFlow.d.mts +0 -40
- package/dist/NumberFlow.d.ts +0 -40
- package/dist/NumberFlow.js +0 -225
- package/dist/NumberFlow.mjs +0 -11
- package/dist/chunk-44AMDIF5.mjs +0 -194
package/dist/NumberFlow.js
DELETED
|
@@ -1,225 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
"use client";
|
|
3
|
-
var __create = Object.create;
|
|
4
|
-
var __defProp = Object.defineProperty;
|
|
5
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
8
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
9
|
-
var __export = (target, all) => {
|
|
10
|
-
for (var name in all)
|
|
11
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
-
};
|
|
13
|
-
var __copyProps = (to, from, except, desc) => {
|
|
14
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
-
for (let key of __getOwnPropNames(from))
|
|
16
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
-
}
|
|
19
|
-
return to;
|
|
20
|
-
};
|
|
21
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
22
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
23
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
24
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
25
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
26
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
27
|
-
mod
|
|
28
|
-
));
|
|
29
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
30
|
-
|
|
31
|
-
// src/NumberFlow.tsx
|
|
32
|
-
var NumberFlow_exports = {};
|
|
33
|
-
__export(NumberFlow_exports, {
|
|
34
|
-
NumberFlowElement: () => NumberFlowElement,
|
|
35
|
-
NumberFlowGroup: () => NumberFlowGroup,
|
|
36
|
-
default: () => NumberFlow_default
|
|
37
|
-
});
|
|
38
|
-
module.exports = __toCommonJS(NumberFlow_exports);
|
|
39
|
-
var React = __toESM(require("react"));
|
|
40
|
-
var import_number_flow = require("number-flow");
|
|
41
|
-
var import_esm_env = require("esm-env");
|
|
42
|
-
var REACT_MAJOR = parseInt(React.version.match(/^(\d+)\./)?.[1]);
|
|
43
|
-
var isReact19 = REACT_MAJOR >= 19;
|
|
44
|
-
var OBSERVED_ATTRIBUTES = ["data", "digits"];
|
|
45
|
-
var NumberFlowElement = class extends import_number_flow.NumberFlowLite {
|
|
46
|
-
attributeChangedCallback(attr, _oldValue, newValue) {
|
|
47
|
-
this[attr] = JSON.parse(newValue);
|
|
48
|
-
}
|
|
49
|
-
};
|
|
50
|
-
NumberFlowElement.observedAttributes = isReact19 ? [] : OBSERVED_ATTRIBUTES;
|
|
51
|
-
(0, import_number_flow.define)("number-flow-react", NumberFlowElement);
|
|
52
|
-
var formatters = {};
|
|
53
|
-
var serialize = isReact19 ? (p) => p : JSON.stringify;
|
|
54
|
-
function splitProps(props) {
|
|
55
|
-
const {
|
|
56
|
-
transformTiming,
|
|
57
|
-
spinTiming,
|
|
58
|
-
opacityTiming,
|
|
59
|
-
animated,
|
|
60
|
-
respectMotionPreference,
|
|
61
|
-
trend,
|
|
62
|
-
plugins,
|
|
63
|
-
...rest
|
|
64
|
-
} = props;
|
|
65
|
-
return [
|
|
66
|
-
{
|
|
67
|
-
transformTiming,
|
|
68
|
-
spinTiming,
|
|
69
|
-
opacityTiming,
|
|
70
|
-
animated,
|
|
71
|
-
respectMotionPreference,
|
|
72
|
-
trend,
|
|
73
|
-
plugins
|
|
74
|
-
},
|
|
75
|
-
rest
|
|
76
|
-
];
|
|
77
|
-
}
|
|
78
|
-
var NumberFlowImpl = class extends React.Component {
|
|
79
|
-
constructor(props) {
|
|
80
|
-
super(props);
|
|
81
|
-
this.handleRef = this.handleRef.bind(this);
|
|
82
|
-
}
|
|
83
|
-
// Update the non-`data` props to avoid JSON serialization
|
|
84
|
-
// Data needs to be set in render still:
|
|
85
|
-
updateProperties(prevProps) {
|
|
86
|
-
if (!this.el) return;
|
|
87
|
-
this.el.manual = !this.props.isolate;
|
|
88
|
-
const [nonData] = splitProps(this.props);
|
|
89
|
-
Object.entries(nonData).forEach(([k, v]) => {
|
|
90
|
-
this.el[k] = v ?? NumberFlowElement.defaultProps[k];
|
|
91
|
-
});
|
|
92
|
-
if (prevProps?.onAnimationsStart)
|
|
93
|
-
this.el.removeEventListener("animationsstart", prevProps.onAnimationsStart);
|
|
94
|
-
if (this.props.onAnimationsStart)
|
|
95
|
-
this.el.addEventListener("animationsstart", this.props.onAnimationsStart);
|
|
96
|
-
if (prevProps?.onAnimationsFinish)
|
|
97
|
-
this.el.removeEventListener("animationsfinish", prevProps.onAnimationsFinish);
|
|
98
|
-
if (this.props.onAnimationsFinish)
|
|
99
|
-
this.el.addEventListener("animationsfinish", this.props.onAnimationsFinish);
|
|
100
|
-
}
|
|
101
|
-
componentDidMount() {
|
|
102
|
-
this.updateProperties();
|
|
103
|
-
if (isReact19 && this.el) {
|
|
104
|
-
this.el.digits = this.props.digits;
|
|
105
|
-
this.el.data = this.props.data;
|
|
106
|
-
}
|
|
107
|
-
}
|
|
108
|
-
getSnapshotBeforeUpdate(prevProps) {
|
|
109
|
-
this.updateProperties(prevProps);
|
|
110
|
-
if (prevProps.data !== this.props.data) {
|
|
111
|
-
if (this.props.group) {
|
|
112
|
-
this.props.group.willUpdate();
|
|
113
|
-
return () => this.props.group?.didUpdate();
|
|
114
|
-
}
|
|
115
|
-
if (!this.props.isolate) {
|
|
116
|
-
this.el?.willUpdate();
|
|
117
|
-
return () => this.el?.didUpdate();
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
componentDidUpdate(_, __, didUpdate) {
|
|
123
|
-
didUpdate?.();
|
|
124
|
-
}
|
|
125
|
-
handleRef(el) {
|
|
126
|
-
if (this.props.innerRef) this.props.innerRef.current = el;
|
|
127
|
-
this.el = el;
|
|
128
|
-
}
|
|
129
|
-
render() {
|
|
130
|
-
const [
|
|
131
|
-
_,
|
|
132
|
-
{
|
|
133
|
-
innerRef,
|
|
134
|
-
className,
|
|
135
|
-
data,
|
|
136
|
-
willChange,
|
|
137
|
-
isolate,
|
|
138
|
-
group,
|
|
139
|
-
digits,
|
|
140
|
-
onAnimationsStart,
|
|
141
|
-
onAnimationsFinish,
|
|
142
|
-
...rest
|
|
143
|
-
}
|
|
144
|
-
] = splitProps(this.props);
|
|
145
|
-
return (
|
|
146
|
-
// @ts-expect-error missing types
|
|
147
|
-
/* @__PURE__ */ React.createElement(
|
|
148
|
-
"number-flow-react",
|
|
149
|
-
{
|
|
150
|
-
ref: this.handleRef,
|
|
151
|
-
"data-will-change": willChange ? "" : void 0,
|
|
152
|
-
class: className,
|
|
153
|
-
"aria-label": data.valueAsString,
|
|
154
|
-
...rest,
|
|
155
|
-
role: "img",
|
|
156
|
-
dangerouslySetInnerHTML: { __html: import_esm_env.BROWSER ? "" : (0, import_number_flow.renderInnerHTML)(data) },
|
|
157
|
-
suppressHydrationWarning: true,
|
|
158
|
-
digits: serialize(digits),
|
|
159
|
-
data: serialize(data)
|
|
160
|
-
}
|
|
161
|
-
)
|
|
162
|
-
);
|
|
163
|
-
}
|
|
164
|
-
};
|
|
165
|
-
var NumberFlow = React.forwardRef(function NumberFlow2({ value, locales, format, prefix, suffix, ...props }, _ref) {
|
|
166
|
-
React.useImperativeHandle(_ref, () => ref.current, []);
|
|
167
|
-
const ref = React.useRef();
|
|
168
|
-
const group = React.useContext(NumberFlowGroupContext);
|
|
169
|
-
group?.useRegister(ref);
|
|
170
|
-
const localesString = React.useMemo(() => locales ? JSON.stringify(locales) : "", [locales]);
|
|
171
|
-
const formatString = React.useMemo(() => format ? JSON.stringify(format) : "", [format]);
|
|
172
|
-
const data = React.useMemo(() => {
|
|
173
|
-
const formatter = formatters[`${localesString}:${formatString}`] ??= new Intl.NumberFormat(
|
|
174
|
-
locales,
|
|
175
|
-
format
|
|
176
|
-
);
|
|
177
|
-
return (0, import_number_flow.formatToData)(value, formatter, prefix, suffix);
|
|
178
|
-
}, [value, localesString, formatString, prefix, suffix]);
|
|
179
|
-
return /* @__PURE__ */ React.createElement(NumberFlowImpl, { ...props, group, data, innerRef: ref });
|
|
180
|
-
});
|
|
181
|
-
var NumberFlow_default = NumberFlow;
|
|
182
|
-
var NumberFlowGroupContext = React.createContext(void 0);
|
|
183
|
-
function NumberFlowGroup({ children }) {
|
|
184
|
-
const flows = React.useRef(/* @__PURE__ */ new Set());
|
|
185
|
-
const updating = React.useRef(false);
|
|
186
|
-
const pending = React.useRef(/* @__PURE__ */ new WeakMap());
|
|
187
|
-
const value = React.useMemo(
|
|
188
|
-
() => ({
|
|
189
|
-
useRegister(ref) {
|
|
190
|
-
React.useEffect(() => {
|
|
191
|
-
flows.current.add(ref);
|
|
192
|
-
return () => {
|
|
193
|
-
flows.current.delete(ref);
|
|
194
|
-
};
|
|
195
|
-
}, []);
|
|
196
|
-
},
|
|
197
|
-
willUpdate() {
|
|
198
|
-
if (updating.current) return;
|
|
199
|
-
updating.current = true;
|
|
200
|
-
flows.current.forEach((ref) => {
|
|
201
|
-
const f = ref.current;
|
|
202
|
-
if (!f || !f.created) return;
|
|
203
|
-
f.willUpdate();
|
|
204
|
-
pending.current.set(f, true);
|
|
205
|
-
});
|
|
206
|
-
},
|
|
207
|
-
didUpdate() {
|
|
208
|
-
flows.current.forEach((ref) => {
|
|
209
|
-
const f = ref.current;
|
|
210
|
-
if (!f || !pending.current.get(f)) return;
|
|
211
|
-
f.didUpdate();
|
|
212
|
-
pending.current.delete(f);
|
|
213
|
-
});
|
|
214
|
-
updating.current = false;
|
|
215
|
-
}
|
|
216
|
-
}),
|
|
217
|
-
[]
|
|
218
|
-
);
|
|
219
|
-
return /* @__PURE__ */ React.createElement(NumberFlowGroupContext.Provider, { value }, children);
|
|
220
|
-
}
|
|
221
|
-
// Annotate the CommonJS export names for ESM import in node:
|
|
222
|
-
0 && (module.exports = {
|
|
223
|
-
NumberFlowElement,
|
|
224
|
-
NumberFlowGroup
|
|
225
|
-
});
|
package/dist/NumberFlow.mjs
DELETED
package/dist/chunk-44AMDIF5.mjs
DELETED
|
@@ -1,194 +0,0 @@
|
|
|
1
|
-
// src/NumberFlow.tsx
|
|
2
|
-
import * as React from "react";
|
|
3
|
-
import {
|
|
4
|
-
renderInnerHTML,
|
|
5
|
-
formatToData,
|
|
6
|
-
NumberFlowLite,
|
|
7
|
-
define
|
|
8
|
-
} from "number-flow";
|
|
9
|
-
import { BROWSER } from "esm-env";
|
|
10
|
-
var REACT_MAJOR = parseInt(React.version.match(/^(\d+)\./)?.[1]);
|
|
11
|
-
var isReact19 = REACT_MAJOR >= 19;
|
|
12
|
-
var OBSERVED_ATTRIBUTES = ["data", "digits"];
|
|
13
|
-
var NumberFlowElement = class extends NumberFlowLite {
|
|
14
|
-
attributeChangedCallback(attr, _oldValue, newValue) {
|
|
15
|
-
this[attr] = JSON.parse(newValue);
|
|
16
|
-
}
|
|
17
|
-
};
|
|
18
|
-
NumberFlowElement.observedAttributes = isReact19 ? [] : OBSERVED_ATTRIBUTES;
|
|
19
|
-
define("number-flow-react", NumberFlowElement);
|
|
20
|
-
var formatters = {};
|
|
21
|
-
var serialize = isReact19 ? (p) => p : JSON.stringify;
|
|
22
|
-
function splitProps(props) {
|
|
23
|
-
const {
|
|
24
|
-
transformTiming,
|
|
25
|
-
spinTiming,
|
|
26
|
-
opacityTiming,
|
|
27
|
-
animated,
|
|
28
|
-
respectMotionPreference,
|
|
29
|
-
trend,
|
|
30
|
-
plugins,
|
|
31
|
-
...rest
|
|
32
|
-
} = props;
|
|
33
|
-
return [
|
|
34
|
-
{
|
|
35
|
-
transformTiming,
|
|
36
|
-
spinTiming,
|
|
37
|
-
opacityTiming,
|
|
38
|
-
animated,
|
|
39
|
-
respectMotionPreference,
|
|
40
|
-
trend,
|
|
41
|
-
plugins
|
|
42
|
-
},
|
|
43
|
-
rest
|
|
44
|
-
];
|
|
45
|
-
}
|
|
46
|
-
var NumberFlowImpl = class extends React.Component {
|
|
47
|
-
constructor(props) {
|
|
48
|
-
super(props);
|
|
49
|
-
this.handleRef = this.handleRef.bind(this);
|
|
50
|
-
}
|
|
51
|
-
// Update the non-`data` props to avoid JSON serialization
|
|
52
|
-
// Data needs to be set in render still:
|
|
53
|
-
updateProperties(prevProps) {
|
|
54
|
-
if (!this.el) return;
|
|
55
|
-
this.el.manual = !this.props.isolate;
|
|
56
|
-
const [nonData] = splitProps(this.props);
|
|
57
|
-
Object.entries(nonData).forEach(([k, v]) => {
|
|
58
|
-
this.el[k] = v ?? NumberFlowElement.defaultProps[k];
|
|
59
|
-
});
|
|
60
|
-
if (prevProps?.onAnimationsStart)
|
|
61
|
-
this.el.removeEventListener("animationsstart", prevProps.onAnimationsStart);
|
|
62
|
-
if (this.props.onAnimationsStart)
|
|
63
|
-
this.el.addEventListener("animationsstart", this.props.onAnimationsStart);
|
|
64
|
-
if (prevProps?.onAnimationsFinish)
|
|
65
|
-
this.el.removeEventListener("animationsfinish", prevProps.onAnimationsFinish);
|
|
66
|
-
if (this.props.onAnimationsFinish)
|
|
67
|
-
this.el.addEventListener("animationsfinish", this.props.onAnimationsFinish);
|
|
68
|
-
}
|
|
69
|
-
componentDidMount() {
|
|
70
|
-
this.updateProperties();
|
|
71
|
-
if (isReact19 && this.el) {
|
|
72
|
-
this.el.digits = this.props.digits;
|
|
73
|
-
this.el.data = this.props.data;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
getSnapshotBeforeUpdate(prevProps) {
|
|
77
|
-
this.updateProperties(prevProps);
|
|
78
|
-
if (prevProps.data !== this.props.data) {
|
|
79
|
-
if (this.props.group) {
|
|
80
|
-
this.props.group.willUpdate();
|
|
81
|
-
return () => this.props.group?.didUpdate();
|
|
82
|
-
}
|
|
83
|
-
if (!this.props.isolate) {
|
|
84
|
-
this.el?.willUpdate();
|
|
85
|
-
return () => this.el?.didUpdate();
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
return null;
|
|
89
|
-
}
|
|
90
|
-
componentDidUpdate(_, __, didUpdate) {
|
|
91
|
-
didUpdate?.();
|
|
92
|
-
}
|
|
93
|
-
handleRef(el) {
|
|
94
|
-
if (this.props.innerRef) this.props.innerRef.current = el;
|
|
95
|
-
this.el = el;
|
|
96
|
-
}
|
|
97
|
-
render() {
|
|
98
|
-
const [
|
|
99
|
-
_,
|
|
100
|
-
{
|
|
101
|
-
innerRef,
|
|
102
|
-
className,
|
|
103
|
-
data,
|
|
104
|
-
willChange,
|
|
105
|
-
isolate,
|
|
106
|
-
group,
|
|
107
|
-
digits,
|
|
108
|
-
onAnimationsStart,
|
|
109
|
-
onAnimationsFinish,
|
|
110
|
-
...rest
|
|
111
|
-
}
|
|
112
|
-
] = splitProps(this.props);
|
|
113
|
-
return (
|
|
114
|
-
// @ts-expect-error missing types
|
|
115
|
-
/* @__PURE__ */ React.createElement(
|
|
116
|
-
"number-flow-react",
|
|
117
|
-
{
|
|
118
|
-
ref: this.handleRef,
|
|
119
|
-
"data-will-change": willChange ? "" : void 0,
|
|
120
|
-
class: className,
|
|
121
|
-
"aria-label": data.valueAsString,
|
|
122
|
-
...rest,
|
|
123
|
-
role: "img",
|
|
124
|
-
dangerouslySetInnerHTML: { __html: BROWSER ? "" : renderInnerHTML(data) },
|
|
125
|
-
suppressHydrationWarning: true,
|
|
126
|
-
digits: serialize(digits),
|
|
127
|
-
data: serialize(data)
|
|
128
|
-
}
|
|
129
|
-
)
|
|
130
|
-
);
|
|
131
|
-
}
|
|
132
|
-
};
|
|
133
|
-
var NumberFlow = React.forwardRef(function NumberFlow2({ value, locales, format, prefix, suffix, ...props }, _ref) {
|
|
134
|
-
React.useImperativeHandle(_ref, () => ref.current, []);
|
|
135
|
-
const ref = React.useRef();
|
|
136
|
-
const group = React.useContext(NumberFlowGroupContext);
|
|
137
|
-
group?.useRegister(ref);
|
|
138
|
-
const localesString = React.useMemo(() => locales ? JSON.stringify(locales) : "", [locales]);
|
|
139
|
-
const formatString = React.useMemo(() => format ? JSON.stringify(format) : "", [format]);
|
|
140
|
-
const data = React.useMemo(() => {
|
|
141
|
-
const formatter = formatters[`${localesString}:${formatString}`] ??= new Intl.NumberFormat(
|
|
142
|
-
locales,
|
|
143
|
-
format
|
|
144
|
-
);
|
|
145
|
-
return formatToData(value, formatter, prefix, suffix);
|
|
146
|
-
}, [value, localesString, formatString, prefix, suffix]);
|
|
147
|
-
return /* @__PURE__ */ React.createElement(NumberFlowImpl, { ...props, group, data, innerRef: ref });
|
|
148
|
-
});
|
|
149
|
-
var NumberFlow_default = NumberFlow;
|
|
150
|
-
var NumberFlowGroupContext = React.createContext(void 0);
|
|
151
|
-
function NumberFlowGroup({ children }) {
|
|
152
|
-
const flows = React.useRef(/* @__PURE__ */ new Set());
|
|
153
|
-
const updating = React.useRef(false);
|
|
154
|
-
const pending = React.useRef(/* @__PURE__ */ new WeakMap());
|
|
155
|
-
const value = React.useMemo(
|
|
156
|
-
() => ({
|
|
157
|
-
useRegister(ref) {
|
|
158
|
-
React.useEffect(() => {
|
|
159
|
-
flows.current.add(ref);
|
|
160
|
-
return () => {
|
|
161
|
-
flows.current.delete(ref);
|
|
162
|
-
};
|
|
163
|
-
}, []);
|
|
164
|
-
},
|
|
165
|
-
willUpdate() {
|
|
166
|
-
if (updating.current) return;
|
|
167
|
-
updating.current = true;
|
|
168
|
-
flows.current.forEach((ref) => {
|
|
169
|
-
const f = ref.current;
|
|
170
|
-
if (!f || !f.created) return;
|
|
171
|
-
f.willUpdate();
|
|
172
|
-
pending.current.set(f, true);
|
|
173
|
-
});
|
|
174
|
-
},
|
|
175
|
-
didUpdate() {
|
|
176
|
-
flows.current.forEach((ref) => {
|
|
177
|
-
const f = ref.current;
|
|
178
|
-
if (!f || !pending.current.get(f)) return;
|
|
179
|
-
f.didUpdate();
|
|
180
|
-
pending.current.delete(f);
|
|
181
|
-
});
|
|
182
|
-
updating.current = false;
|
|
183
|
-
}
|
|
184
|
-
}),
|
|
185
|
-
[]
|
|
186
|
-
);
|
|
187
|
-
return /* @__PURE__ */ React.createElement(NumberFlowGroupContext.Provider, { value }, children);
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
export {
|
|
191
|
-
NumberFlowElement,
|
|
192
|
-
NumberFlow_default,
|
|
193
|
-
NumberFlowGroup
|
|
194
|
-
};
|