@number-flow/react 0.2.0 → 0.2.2

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 Maxwell Barvian
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,10 +1,11 @@
1
+ [![NumberFlow for React](https://number-flow.barvian.me/preview.webp)](https://number-flow.barvian.me)
2
+
1
3
  # Number Flow for React
2
4
 
3
5
  A React component to transition & format numbers.
4
6
 
5
- [![NumberFlow for React](https://number-flow.barvian.me/preview.webp)](https://number-flow.barvian.me)
6
-
7
7
  [![NPM Version](https://img.shields.io/npm/v/@number-flow/react.svg)](https://npmjs.com/package/@number-flow/react)
8
+ [![Bundle size](https://badgen.net/bundlephobia/minzip/@number-flow/react@latest)](https://bundlephobia.com/package/@number-flow/react@latest)
8
9
  [![Follow @mbarvian](https://img.shields.io/twitter/follow/mbarvian.svg?style=social&label=Follow)](https://x.com/mbarvian)
9
10
 
10
11
  ---
package/dist/index.d.mts CHANGED
@@ -19,6 +19,7 @@ type NumberFlowProps = React.HTMLAttributes<NumberFlowElement> & {
19
19
  onAnimationsStart?: () => void;
20
20
  onAnimationsFinish?: () => void;
21
21
  trend?: (typeof NumberFlowElement)['prototype']['trend'];
22
+ continuous?: (typeof NumberFlowElement)['prototype']['continuous'];
22
23
  opacityTiming?: (typeof NumberFlowElement)['prototype']['opacityTiming'];
23
24
  transformTiming?: (typeof NumberFlowElement)['prototype']['transformTiming'];
24
25
  spinTiming?: (typeof NumberFlowElement)['prototype']['spinTiming'];
@@ -34,6 +35,7 @@ declare const NumberFlow: React.ForwardRefExoticComponent<React.HTMLAttributes<N
34
35
  onAnimationsStart?: () => void;
35
36
  onAnimationsFinish?: () => void;
36
37
  trend?: (typeof NumberFlowElement)["prototype"]["trend"];
38
+ continuous?: (typeof NumberFlowElement)["prototype"]["continuous"];
37
39
  opacityTiming?: (typeof NumberFlowElement)["prototype"]["opacityTiming"];
38
40
  transformTiming?: (typeof NumberFlowElement)["prototype"]["transformTiming"];
39
41
  spinTiming?: (typeof NumberFlowElement)["prototype"]["spinTiming"];
package/dist/index.d.ts CHANGED
@@ -19,6 +19,7 @@ type NumberFlowProps = React.HTMLAttributes<NumberFlowElement> & {
19
19
  onAnimationsStart?: () => void;
20
20
  onAnimationsFinish?: () => void;
21
21
  trend?: (typeof NumberFlowElement)['prototype']['trend'];
22
+ continuous?: (typeof NumberFlowElement)['prototype']['continuous'];
22
23
  opacityTiming?: (typeof NumberFlowElement)['prototype']['opacityTiming'];
23
24
  transformTiming?: (typeof NumberFlowElement)['prototype']['transformTiming'];
24
25
  spinTiming?: (typeof NumberFlowElement)['prototype']['spinTiming'];
@@ -34,6 +35,7 @@ declare const NumberFlow: React.ForwardRefExoticComponent<React.HTMLAttributes<N
34
35
  onAnimationsStart?: () => void;
35
36
  onAnimationsFinish?: () => void;
36
37
  trend?: (typeof NumberFlowElement)["prototype"]["trend"];
38
+ continuous?: (typeof NumberFlowElement)["prototype"]["continuous"];
37
39
  opacityTiming?: (typeof NumberFlowElement)["prototype"]["opacityTiming"];
38
40
  transformTiming?: (typeof NumberFlowElement)["prototype"]["transformTiming"];
39
41
  spinTiming?: (typeof NumberFlowElement)["prototype"]["spinTiming"];
package/dist/index.js CHANGED
@@ -45,6 +45,7 @@ __export(src_exports, {
45
45
  module.exports = __toCommonJS(src_exports);
46
46
  var React = __toESM(require("react"));
47
47
  var import_number_flow = require("number-flow");
48
+ var isReact19 = React.version.startsWith("19.");
48
49
  var OBSERVED_ATTRIBUTES = ["parts"];
49
50
  var NumberFlowElement = class extends import_number_flow.NumberFlowLite {
50
51
  attributeChangedCallback(attr, _oldValue, newValue) {
@@ -54,6 +55,7 @@ var NumberFlowElement = class extends import_number_flow.NumberFlowLite {
54
55
  NumberFlowElement.observedAttributes = OBSERVED_ATTRIBUTES;
55
56
  NumberFlowElement.define();
56
57
  var formatters = {};
58
+ var serializeParts = isReact19 ? (p) => p : JSON.stringify;
57
59
  var _el;
58
60
  var NumberFlowImpl = class extends React.Component {
59
61
  constructor(props) {
@@ -70,6 +72,7 @@ var NumberFlowImpl = class extends React.Component {
70
72
  if (this.props.respectMotionPreference != null)
71
73
  __privateGet(this, _el).respectMotionPreference = this.props.respectMotionPreference;
72
74
  if (this.props.trend != null) __privateGet(this, _el).trend = this.props.trend;
75
+ if (this.props.continuous != null) __privateGet(this, _el).continuous = this.props.continuous;
73
76
  if (this.props.opacityTiming) __privateGet(this, _el).opacityTiming = this.props.opacityTiming;
74
77
  if (this.props.transformTiming) __privateGet(this, _el).transformTiming = this.props.transformTiming;
75
78
  if (this.props.spinTiming) __privateGet(this, _el).spinTiming = this.props.spinTiming;
@@ -84,14 +87,19 @@ var NumberFlowImpl = class extends React.Component {
84
87
  }
85
88
  componentDidMount() {
86
89
  this.updateNonPartsProps();
90
+ if (isReact19 && __privateGet(this, _el)) {
91
+ __privateGet(this, _el).parts = this.props.parts;
92
+ }
87
93
  }
88
94
  getSnapshotBeforeUpdate(prevProps) {
89
95
  this.updateNonPartsProps(prevProps);
90
- if (!this.props.isolate && prevProps.parts !== this.props.parts) __privateGet(this, _el)?.willUpdate();
91
- return null;
96
+ if (this.props.isolate) return false;
97
+ if (prevProps.parts === this.props.parts) return false;
98
+ __privateGet(this, _el)?.willUpdate();
99
+ return true;
92
100
  }
93
- componentDidUpdate(prevProps) {
94
- if (!this.props.isolate && prevProps.parts !== this.props.parts) __privateGet(this, _el)?.didUpdate();
101
+ componentDidUpdate(_, __, snapshot) {
102
+ if (snapshot) __privateGet(this, _el)?.didUpdate();
95
103
  }
96
104
  handleRef(el) {
97
105
  if (this.props.innerRef) this.props.innerRef.current = el;
@@ -108,6 +116,7 @@ var NumberFlowImpl = class extends React.Component {
108
116
  respectMotionPreference,
109
117
  isolate,
110
118
  trend,
119
+ continuous,
111
120
  opacityTiming,
112
121
  transformTiming,
113
122
  spinTiming,
@@ -122,7 +131,7 @@ var NumberFlowImpl = class extends React.Component {
122
131
  "data-will-change": willChange ? "" : void 0,
123
132
  class: className,
124
133
  ...rest,
125
- parts: JSON.stringify(parts)
134
+ parts: serializeParts(parts)
126
135
  },
127
136
  /* @__PURE__ */ React.createElement(import_number_flow.SlottedTag, { style: (0, import_number_flow.slottedStyles)({ willChange }) }, parts.formatted)
128
137
  )
package/dist/index.mjs CHANGED
@@ -17,6 +17,7 @@ import {
17
17
  prefersReducedMotion,
18
18
  canAnimate as _canAnimate
19
19
  } from "number-flow";
20
+ var isReact19 = React.version.startsWith("19.");
20
21
  var OBSERVED_ATTRIBUTES = ["parts"];
21
22
  var NumberFlowElement = class extends NumberFlowLite {
22
23
  attributeChangedCallback(attr, _oldValue, newValue) {
@@ -26,6 +27,7 @@ var NumberFlowElement = class extends NumberFlowLite {
26
27
  NumberFlowElement.observedAttributes = OBSERVED_ATTRIBUTES;
27
28
  NumberFlowElement.define();
28
29
  var formatters = {};
30
+ var serializeParts = isReact19 ? (p) => p : JSON.stringify;
29
31
  var _el;
30
32
  var NumberFlowImpl = class extends React.Component {
31
33
  constructor(props) {
@@ -42,6 +44,7 @@ var NumberFlowImpl = class extends React.Component {
42
44
  if (this.props.respectMotionPreference != null)
43
45
  __privateGet(this, _el).respectMotionPreference = this.props.respectMotionPreference;
44
46
  if (this.props.trend != null) __privateGet(this, _el).trend = this.props.trend;
47
+ if (this.props.continuous != null) __privateGet(this, _el).continuous = this.props.continuous;
45
48
  if (this.props.opacityTiming) __privateGet(this, _el).opacityTiming = this.props.opacityTiming;
46
49
  if (this.props.transformTiming) __privateGet(this, _el).transformTiming = this.props.transformTiming;
47
50
  if (this.props.spinTiming) __privateGet(this, _el).spinTiming = this.props.spinTiming;
@@ -56,14 +59,19 @@ var NumberFlowImpl = class extends React.Component {
56
59
  }
57
60
  componentDidMount() {
58
61
  this.updateNonPartsProps();
62
+ if (isReact19 && __privateGet(this, _el)) {
63
+ __privateGet(this, _el).parts = this.props.parts;
64
+ }
59
65
  }
60
66
  getSnapshotBeforeUpdate(prevProps) {
61
67
  this.updateNonPartsProps(prevProps);
62
- if (!this.props.isolate && prevProps.parts !== this.props.parts) __privateGet(this, _el)?.willUpdate();
63
- return null;
68
+ if (this.props.isolate) return false;
69
+ if (prevProps.parts === this.props.parts) return false;
70
+ __privateGet(this, _el)?.willUpdate();
71
+ return true;
64
72
  }
65
- componentDidUpdate(prevProps) {
66
- if (!this.props.isolate && prevProps.parts !== this.props.parts) __privateGet(this, _el)?.didUpdate();
73
+ componentDidUpdate(_, __, snapshot) {
74
+ if (snapshot) __privateGet(this, _el)?.didUpdate();
67
75
  }
68
76
  handleRef(el) {
69
77
  if (this.props.innerRef) this.props.innerRef.current = el;
@@ -80,6 +88,7 @@ var NumberFlowImpl = class extends React.Component {
80
88
  respectMotionPreference,
81
89
  isolate,
82
90
  trend,
91
+ continuous,
83
92
  opacityTiming,
84
93
  transformTiming,
85
94
  spinTiming,
@@ -94,7 +103,7 @@ var NumberFlowImpl = class extends React.Component {
94
103
  "data-will-change": willChange ? "" : void 0,
95
104
  class: className,
96
105
  ...rest,
97
- parts: JSON.stringify(parts)
106
+ parts: serializeParts(parts)
98
107
  },
99
108
  /* @__PURE__ */ React.createElement(SlottedTag, { style: slottedStyles({ willChange }) }, parts.formatted)
100
109
  )
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.2.0",
6
+ "version": "0.2.2",
7
7
  "author": {
8
8
  "name": "Maxwell Barvian",
9
9
  "email": "max@barvian.me",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "dependencies": {
51
51
  "esm-env": "^1.0.0",
52
- "number-flow": "0.3.0"
52
+ "number-flow": "0.3.1"
53
53
  },
54
54
  "devDependencies": {
55
55
  "@types/react": "^18.3.3",
@@ -59,14 +59,12 @@
59
59
  "tsup": "^8.2.4"
60
60
  },
61
61
  "peerDependencies": {
62
- "@types/react": "^18.3.3",
63
- "@types/react-dom": "^18.3.0",
64
- "react": "^18.3.1",
65
- "react-dom": "^18.3.1"
62
+ "react": "^18 || ^19.0.0-rc-915b914b3a-20240515",
63
+ "react-dom": "^18"
66
64
  },
67
65
  "scripts": {
68
66
  "build": "tsup --tsconfig tsconfig.build.json",
69
67
  "dev": "tsup --watch",
70
- "test": "pnpm -r --workspace-concurrency 1 --filter=\"./test\" test"
68
+ "test": "pnpm -r --workspace-concurrency 1 --filter=\"./test/apps/*\" test"
71
69
  }
72
70
  }